From 8afac921f4b9e92a39f8e6a2d9357c07e45091b8 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 27 Aug 2016 01:20:01 +0200 Subject: [PATCH] refs #745, improved own model set dialog * allow to consolidate data * display either preferences or all distributors --- .../components/dbownmodelscomponent.ui | 3 + .../components/dbownmodelsetdialog.cpp | 6 +- src/blackgui/editors/ownmodelsetform.cpp | 71 ++++++-- src/blackgui/editors/ownmodelsetform.h | 22 ++- src/blackgui/editors/ownmodelsetform.ui | 160 +++++++++++------- 5 files changed, 176 insertions(+), 86 deletions(-) diff --git a/src/blackgui/components/dbownmodelscomponent.ui b/src/blackgui/components/dbownmodelscomponent.ui index 4231cf434..2144acd08 100644 --- a/src/blackgui/components/dbownmodelscomponent.ui +++ b/src/blackgui/components/dbownmodelscomponent.ui @@ -40,6 +40,9 @@ false + + false + diff --git a/src/blackgui/components/dbownmodelsetdialog.cpp b/src/blackgui/components/dbownmodelsetdialog.cpp index aee32d578..c4f40a2c2 100644 --- a/src/blackgui/components/dbownmodelsetdialog.cpp +++ b/src/blackgui/components/dbownmodelsetdialog.cpp @@ -118,7 +118,7 @@ namespace BlackGui CAircraftModelList CDbOwnModelSetDialog::buildSet(const CSimulatorInfo &simulator, const CAircraftModelList ¤tSet) { Q_ASSERT_X(this->getMappingComponent(), Q_FUNC_INFO, "missing mapping component"); - const bool selectedProviders = this->ui->form_OwnModelSet->selectedDistributors(); + const bool selectedProviders = this->ui->form_OwnModelSet->useSelectedDistributors(); const bool dbDataOnly = this->ui->form_OwnModelSet->dbDataOnly(); const bool dbIcaoOnly = this->ui->form_OwnModelSet->dbIcaoCodesOnly(); const bool incremnental = this->ui->form_OwnModelSet->incrementalBuild(); @@ -127,13 +127,13 @@ namespace BlackGui this->m_simulatorInfo = this->getMappingComponent()->getOwnModelsSimulator(); const CDistributorList distributors = selectedProviders ? ui->form_OwnModelSet->getSelectedDistributors() : - ui->form_OwnModelSet->getDistributors(); + ui->form_OwnModelSet->getDistributorsFromPreferences(); const CModelSetBuilder builder(this); CModelSetBuilder::Builder options = selectedProviders ? CModelSetBuilder::FilterDistributos : CModelSetBuilder::NoOptions; if (dbDataOnly) { options |= CModelSetBuilder::OnlyDbData; } if (dbIcaoOnly) { options |= CModelSetBuilder::OnlyDbIcaoCodes; } if (incremnental) { options |= CModelSetBuilder::Incremental; } - if (ui->form_OwnModelSet->hasDIstributorPreferences()) { options |= CModelSetBuilder::SortByDistributors; } + if (ui->form_OwnModelSet->hasDistributorPreferences()) { options |= CModelSetBuilder::SortByDistributors; } return builder.buildModelSet(simulator, models, currentSet, options, distributors); } } // ns diff --git a/src/blackgui/editors/ownmodelsetform.cpp b/src/blackgui/editors/ownmodelsetform.cpp index c0f41887d..9debe3613 100644 --- a/src/blackgui/editors/ownmodelsetform.cpp +++ b/src/blackgui/editors/ownmodelsetform.cpp @@ -35,9 +35,12 @@ namespace BlackGui ui->tvp_Distributors->setDistributorMode(CDistributorListModel::Minimal); ui->comp_SimulatorSelector->setMode(CSimulatorSelector::RadioButtons); ui->comp_SimulatorSelector->setLeftMargin(0); - CGuiUtility::checkBoxReadOnly(ui->cb_Preferences, true); connect(ui->comp_SimulatorSelector, &CSimulatorSelector::changed, this, &COwnModelSetForm::ps_simulatorChanged); + connect(ui->rb_DisplayAllDistributors, &QRadioButton::clicked, this, &COwnModelSetForm::ps_changeDistributorDisplay); + connect(ui->rb_DisplayPreferencesDistributors, &QRadioButton::clicked, this, &COwnModelSetForm::ps_changeDistributorDisplay); + + this->ps_simulatorChanged(ui->comp_SimulatorSelector->getValue()); } COwnModelSetForm::~COwnModelSetForm() @@ -47,18 +50,15 @@ namespace BlackGui void COwnModelSetForm::reloadData() { - const CDistributorList distributors(this->getDistributors()); - const bool hasPreferences = this->hasDIstributorPreferences(); - ui->cb_Preferences->setChecked(hasPreferences); + const bool hasPreferences = this->hasDistributorPreferences(); + ui->cb_SortByPreferences->setChecked(hasPreferences); + CGuiUtility::checkBoxReadOnly(ui->cb_SortByPreferences, !hasPreferences); ui->comp_SimulatorSelector->setValue(this->m_simulator); - ui->tvp_Distributors->setDistributorMode(hasPreferences ? CDistributorListModel::MinimalWithOrder : CDistributorListModel::Minimal); - if (!distributors.isEmpty()) - { - this->ui->tvp_Distributors->updateContainerMaybeAsync(distributors); - } + this->setDistributorView(hasPreferences); + this->initDistributorDisplay(); } - bool COwnModelSetForm::selectedDistributors() const + bool COwnModelSetForm::useSelectedDistributors() const { return this->ui->rb_SelectedDistributors->isChecked(); } @@ -85,15 +85,55 @@ namespace BlackGui emit simulatorChanged(simulator); } - CDistributorList COwnModelSetForm::getDistributors() const + void COwnModelSetForm::ps_changeDistributorDisplay() + { + if (ui->rb_DisplayAllDistributors->isChecked()) + { + ui->tvp_Distributors->updateContainerMaybeAsync(this->getAllDistributors()); + ui->cb_SortByPreferences->setChecked(false); + CGuiUtility::checkBoxReadOnly(ui->cb_SortByPreferences, true); + this->setDistributorView(false); + } + else + { + ui->tvp_Distributors->updateContainerMaybeAsync(this->getDistributorsFromPreferences()); + ui->cb_SortByPreferences->setChecked(true); + CGuiUtility::checkBoxReadOnly(ui->cb_SortByPreferences, false); + this->setDistributorView(true); + } + } + + void COwnModelSetForm::initDistributorDisplay() + { + if (this->hasDistributorPreferences()) + { + ui->rb_DisplayPreferencesDistributors->setChecked(true); + } + else + { + ui->rb_DisplayAllDistributors->setChecked(true); + } + this->ps_changeDistributorDisplay(); + } + + void COwnModelSetForm::setDistributorView(bool hasPreferences) + { + ui->tvp_Distributors->setDistributorMode(hasPreferences ? CDistributorListModel::MinimalWithOrder : CDistributorListModel::Minimal); + ui->tvp_Distributors->fullResizeToContents(); + } + + CDistributorList COwnModelSetForm::getDistributorsFromPreferences() const { - Q_ASSERT_X(sGui && sGui->hasWebDataServices(), Q_FUNC_INFO, "Missing web data services"); Q_ASSERT_X(this->m_simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator"); const CDistributorListPreferences prefs(this->m_distributorPreferences.get()); const CDistributorList distributors(prefs.getDistributors(this->m_simulator)); - if (!distributors.isEmpty()) { return distributors; } + return distributors; + } - // no preferences + CDistributorList COwnModelSetForm::getAllDistributors() const + { + Q_ASSERT_X(this->m_simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator"); + Q_ASSERT_X(sGui && sGui->hasWebDataServices(), Q_FUNC_INFO, "Missing web data services"); return sGui->getWebDataServices()->getDistributors().matchesSimulator(this->m_simulator); } @@ -113,11 +153,10 @@ namespace BlackGui m_simulator = simulator; } - bool COwnModelSetForm::hasDIstributorPreferences() const + bool COwnModelSetForm::hasDistributorPreferences() const { const CDistributorListPreferences prefs(this->m_distributorPreferences.get()); return !prefs.getDistributors(this->m_simulator).isEmpty(); } } // ns } // ns - diff --git a/src/blackgui/editors/ownmodelsetform.h b/src/blackgui/editors/ownmodelsetform.h index 9a9988ecd..e0399206c 100644 --- a/src/blackgui/editors/ownmodelsetform.h +++ b/src/blackgui/editors/ownmodelsetform.h @@ -42,7 +42,7 @@ namespace BlackGui void reloadData(); //! Selected providers? - bool selectedDistributors() const; + bool useSelectedDistributors() const; //! Get selected providers BlackMisc::Simulation::CDistributorList getSelectedDistributors() const; @@ -59,11 +59,14 @@ namespace BlackGui //! Request incremental build bool incrementalBuild() const; - //! Distributors (from preferences or web) - BlackMisc::Simulation::CDistributorList getDistributors() const; + //! Distributors from preferences + BlackMisc::Simulation::CDistributorList getDistributorsFromPreferences() const; - //! Preferences for given simulator - bool hasDIstributorPreferences() const; + //! All distributors + BlackMisc::Simulation::CDistributorList getAllDistributors() const; + + //! Preferences for given simulator? + bool hasDistributorPreferences() const; //! \name Form functions, here not used //! \@{ @@ -81,7 +84,16 @@ namespace BlackGui //! Simulator changed void ps_simulatorChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator); + //! Display distributors based on checkboxes + void ps_changeDistributorDisplay(); + private: + //! Init the options which distributors are displayed + void initDistributorDisplay(); + + //! Set mode for view + void setDistributorView(bool hasPreferences); + QScopedPointer ui; BlackMisc::Simulation::CSimulatorInfo m_simulator; BlackMisc::CSetting m_distributorPreferences { this, &COwnModelSetForm::ps_preferencesChanged }; diff --git a/src/blackgui/editors/ownmodelsetform.ui b/src/blackgui/editors/ownmodelsetform.ui index de202b538..af1ef6f3f 100644 --- a/src/blackgui/editors/ownmodelsetform.ui +++ b/src/blackgui/editors/ownmodelsetform.ui @@ -6,19 +6,13 @@ 0 0 - 400 - 300 + 433 + 324 Frame - - QFrame::StyledPanel - - - QFrame::Raised - 3 @@ -35,7 +29,7 @@ - 3 + 6 @@ -50,30 +44,10 @@ - - - - Source set: - - - - - - - default - - - true - - - bg_Distributors - - - - Model has ICAO code + Model has ICAO code, but not necessarily valid data ICAO data @@ -93,10 +67,20 @@ - - + + - selected + Source set: + + + + + + + all + + + true bg_Distributors @@ -110,29 +94,6 @@ - - - - full - - - true - - - bg_Mode - - - - - - - incremental - - - bg_Mode - - - @@ -149,11 +110,43 @@ - - - - preferences + + + + new set, existing data will be deleted + + full + + + true + + + bg_Mode + + + + + + + add to existing set + + + incremental + + + bg_Mode + + + + + + + selected + + + bg_Distributors + @@ -166,6 +159,16 @@ + + + + consolidate with DB + + + true + + + @@ -173,6 +176,39 @@ + + + + from preferences + + + bg_DisplayedDistributors + + + + + + + If checked the distributors from the settings page will be used + + + sort by dist. preferences + + + + + + + all distributors + + + true + + + bg_DisplayedDistributors + + + @@ -210,8 +246,7 @@ rb_DbIcaoCodesOnly rb_WithIcaoData rb_SelectedDistributors - rb_DefaultDistributors - cb_Preferences + rb_AllDistributors tvp_Distributors @@ -220,5 +255,6 @@ +