Workaround for improper formatting of vPilot rules

found druing testing of #648
This commit is contained in:
Klaus Basan
2016-05-06 18:22:45 +02:00
parent f3ac18257f
commit 92c638cee4
4 changed files with 42 additions and 20 deletions

View File

@@ -112,11 +112,10 @@ namespace BlackGui
void CDbMappingComponent::initVPilotLoading()
{
const bool canUseVPilot = true; // general flag if vPilot can be used/not used
this->m_withVPilot = canUseVPilot && this->m_swiftDbUser.get().isMappingAdmin();
this->m_vPilotEnabled = vPilotSupport && this->m_swiftDbUser.get().isMappingAdmin();
static const QString tabName(this->ui->tw_ModelsToBeMapped->tabText(TabVPilot));
if (this->m_vPilot1stInit && canUseVPilot)
if (this->m_vPilot1stInit && vPilotSupport)
{
this->m_vPilot1stInit = false;
connect(this->ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected);
@@ -136,9 +135,9 @@ namespace BlackGui
const int noModels = vPilotModels.size();
CLogMessage(this).info("%1 cached vPilot models loaded") << noModels;
}
this->ui->tab_VPilot->setEnabled(this->m_withVPilot);
this->ui->tab_VPilot->setVisible(this->m_withVPilot);
if (this->m_withVPilot)
this->ui->tab_VPilot->setEnabled(this->m_vPilotEnabled);
this->ui->tab_VPilot->setVisible(this->m_vPilotEnabled);
if (this->m_vPilotEnabled)
{
// create / restore tab
this->ui->tw_ModelsToBeMapped->addTab(this->ui->tab_VPilot, tabName);
@@ -148,10 +147,18 @@ namespace BlackGui
}
else
{
this->m_vPilotFormatted = false;
this->ui->tw_ModelsToBeMapped->removeTab(TabVPilot);
}
}
void CDbMappingComponent::formatVPilotView()
{
if (!this->m_vPilotEnabled || this->m_vPilotFormatted) { return; }
this->m_vPilotFormatted = true;
this->ui->tvp_AircraftModelsForVPilot->presizeOrFullResizeToContents();
}
CAircraftModel CDbMappingComponent::getModelFromView(const QModelIndex &index) const
{
if (!index.isValid()) { return CAircraftModel(); }
@@ -190,7 +197,7 @@ namespace BlackGui
bool CDbMappingComponent::hasSelectedModelsToStash() const
{
TabIndex tab = currentTabIndex();
const TabIndex tab = currentTabIndex();
switch (tab)
{
case TabOwnModels:
@@ -205,7 +212,7 @@ namespace BlackGui
CAircraftModelView *CDbMappingComponent::currentModelView() const
{
TabIndex tab = currentTabIndex();
const TabIndex tab = currentTabIndex();
switch (tab)
{
case TabOwnModels:
@@ -223,7 +230,7 @@ namespace BlackGui
QString CDbMappingComponent::currentTabText() const
{
int i = this->ui->tw_ModelsToBeMapped->currentIndex();
const int i = this->ui->tw_ModelsToBeMapped->currentIndex();
return this->ui->tw_ModelsToBeMapped->tabText(i);
}
@@ -265,7 +272,7 @@ namespace BlackGui
CAircraftModelList CDbMappingComponent::getSelectedModelsToStash() const
{
if (!hasSelectedModelsToStash()) { return CAircraftModelList(); }
TabIndex tab = currentTabIndex();
const TabIndex tab = currentTabIndex();
switch (tab)
{
case TabOwnModels:
@@ -291,7 +298,7 @@ namespace BlackGui
CDbMappingComponent::TabIndex CDbMappingComponent::currentTabIndex() const
{
if (!ui->tw_ModelsToBeMapped) { return CDbMappingComponent::NoValidTab; }
int t = ui->tw_ModelsToBeMapped->currentIndex();
const int t = ui->tw_ModelsToBeMapped->currentIndex();
return static_cast<TabIndex>(t);
}
@@ -314,7 +321,7 @@ namespace BlackGui
void CDbMappingComponent::ps_handleStashDropRequest(const CAirlineIcaoCode &code) const
{
CLivery stdLivery(sGui->getWebDataServices()->getStdLiveryForAirlineCode(code));
const CLivery stdLivery(sGui->getWebDataServices()->getStdLiveryForAirlineCode(code));
if (!stdLivery.hasValidDbKey()) { return; }
this->ui->comp_StashAircraft->applyToSelected(stdLivery);
}
@@ -342,7 +349,7 @@ namespace BlackGui
void CDbMappingComponent::ps_removeDbModelsFromView()
{
QStringList modelStrings(sGui->getWebDataServices()->getModelStrings());
const QStringList modelStrings(sGui->getWebDataServices()->getModelStrings());
if (modelStrings.isEmpty()) { return; }
if (currentTabIndex() == TabVPilot || currentTabIndex() == TabOwnModels)
{
@@ -470,7 +477,7 @@ namespace BlackGui
void CDbMappingComponent::ps_onLoadVPilotDataFinished(bool success)
{
if (!m_withVPilot) { return; }
if (!m_vPilotEnabled) { return; }
if (success)
{
CLogMessage(this).info("Loading vPilot ruleset completed");
@@ -524,7 +531,7 @@ namespace BlackGui
void CDbMappingComponent::ps_tabIndexChanged(int index)
{
CDbMappingComponent::TabIndex ti = static_cast<CDbMappingComponent::TabIndex>(index);
const CDbMappingComponent::TabIndex ti = static_cast<CDbMappingComponent::TabIndex>(index);
switch (ti)
{
case CDbMappingComponent::TabOwnModelSet:
@@ -537,6 +544,9 @@ namespace BlackGui
ui->frp_Editors->setVisible(false);
this->resizeForSelect();
break;
case CDbMappingComponent::TabVPilot:
// fall thru intended
this->formatVPilotView();
default:
ui->frp_Editors->setVisible(true);
ui->editor_Model->setVisible(true);

View File

@@ -70,7 +70,7 @@ namespace BlackGui
void gracefulShutdown();
//! With vPilot rules
bool withVPilot() const { return m_withVPilot; }
bool withVPilot() const { return m_vPilotEnabled; }
//! Any models which can be stashed?
bool hasSelectedModelsToStash() const;
@@ -251,13 +251,20 @@ namespace BlackGui
BlackMisc::Simulation::FsCommon::CVPilotRulesReader m_vPilotReader; //!< read vPilot rules
BlackMisc::CData<BlackCore::Data::AuthenticatedDbUser> m_swiftDbUser {this, &CDbMappingComponent::ps_userChanged};
BlackMisc::CDigestSignal m_dsStashedModelsChanged { this, &CDbMappingComponent::ps_digestStashedModelsChanged, &CDbMappingComponent::ps_onStashedModelsChangedDigest, 750, 25 };
const bool vPilotSupport = true; //!< vPilot support
bool m_vPilot1stInit = true; //!< vPilot extensions initaliazed?
bool m_withVPilot = false; //!< use vPilot extensions
bool m_vPilotEnabled = false; //!< use vPilot extensions
bool m_vPilotFormatted = false; //!< vPilot fomratted (workaround)
bool m_autoFilterInDbViews = false; //!< automatically filter the DB view by the current model
//! Init vPilot if rights and suitable
void initVPilotLoading();
//! Workaround to format vPilot view
//! \remark presize does not work properly when data are loaded, reason is not understood. This here does a formatting when tab becomes visible.
//! \todo can be removed whenever a proper formatting is archived with data loading
void formatVPilotView();
//! Model for given index from sender/current view
BlackMisc::Simulation::CAircraftModel getModelFromView(const QModelIndex &index) const;

View File

@@ -525,9 +525,9 @@ namespace BlackGui
void CViewBaseNonTemplate::fullResizeToContents()
{
this->setVisible(false);
// magic trick from:
// http://stackoverflow.com/q/3433664/356726
this->setVisible(false);
const QRect vpOriginal = this->viewport()->geometry();
QRect vpNew = vpOriginal;
vpNew.setWidth(std::numeric_limits<int>::max());
@@ -542,6 +542,9 @@ namespace BlackGui
this->horizontalHeader()->setStretchLastSection(true);
}
this->viewport()->setGeometry(vpOriginal);
// if I store the original visibility and then
// set it back here, the whole view disappears
this->setVisible(true);
}
@@ -1047,7 +1050,8 @@ namespace BlackGui
template <class ModelClass, class ContainerType, class ObjectType>
void CViewBase<ModelClass, ContainerType, ObjectType>::performModeBasedResizeToContent()
{
// small set or large set?
// small set or large set? This only performs real resizing, no presizing
// remark, see also presizeOrFullResizeToContents
if (this->isResizeConditionMet())
{
this->fullResizeToContents();

View File

@@ -297,7 +297,8 @@ namespace BlackGui
virtual void dragLeaveEvent(QDragLeaveEvent *event) override;
//! @}
//! Perform resizing / non slot method for template
//! Perform resizing (no presizing) / non slot method for template
//! \sa CViewBaseNonTemplate::presizeOrFullResizeToContents
virtual void performModeBasedResizeToContent() = 0;
//! Helper method with template free signature