refs #614, use interfaces from last step to reuse mergeWithDb data in multiple components

* adjusted menus
* adjusted loaders and components
This commit is contained in:
Klaus Basan
2016-04-08 14:11:40 +02:00
parent 43c69d2ed0
commit abca1fde52
12 changed files with 115 additions and 47 deletions

View File

@@ -16,6 +16,7 @@
#include "blackgui/guiutility.h"
#include "blackgui/shortcut.h"
#include "blackmisc/simulation/fscommon/aircraftcfgparser.h"
#include "blackmisc/simulation/aircraftmodelutils.h"
#include "blackmisc/logmessage.h"
#include <QFile>
#include <QShortcut>
@@ -579,7 +580,7 @@ namespace BlackGui
Q_UNUSED(withFilter);
int i = this->ui->tw_ModelsToBeMapped->indexOf(this->ui->tab_OwnModelSet);
QString o = "Model set " + ui->comp_OwnModelSet->getModelSetSimulator().toQString(true);
const QString f = this->ui->comp_StashAircraft->view()->hasFilter() ? "F" : "";
const QString f = this->ui->comp_OwnModelSet->view()->hasFilter() ? "F" : "";
o = CGuiUtility::replaceTabCountValue(o, this->ui->comp_OwnModelSet->view()->rowCount()) + f;
this->ui->tw_ModelsToBeMapped->setTabText(i, o);
}

View File

@@ -20,7 +20,6 @@
#include <QScopedPointer>
namespace Ui { class CDbOwnModelsComponent; }
namespace BlackGui
{
namespace Views { class CAircraftModelView; }

View File

@@ -8,8 +8,9 @@
*/
#include "dbownmodelsetcomponent.h"
#include "blackmisc/simulation/aircraftmodellist.h"
#include "blackgui/models/aircrafticaolistmodel.h"
#include "blackgui/menus/aircraftmodelmenus.h"
#include "blackmisc/simulation/aircraftmodellist.h"
#include "blackmisc/logmessage.h"
#include "dbmappingcomponent.h"
#include "dbownmodelsetdialog.h"
@@ -18,6 +19,7 @@
using namespace BlackMisc;
using namespace BlackMisc::Simulation;
using namespace BlackGui::Models;
using namespace BlackGui::Menus;
using namespace BlackGui::Views;
namespace BlackGui
@@ -36,6 +38,7 @@ namespace BlackGui
ui->tvp_OwnModelSet->addFilterDialog();
ui->tvp_OwnModelSet->setCustomMenu(new CLoadModelsMenu(this));
ui->tvp_OwnModelSet->setJsonLoad(CAircraftModelView::AllowOnlySingleSimulator | CAircraftModelView::ReduceToOneSimulator);
ui->tvp_OwnModelSet->setCustomMenu(new CMergeWithDbDataMenu(ui->tvp_OwnModelSet, this, false));
connect(ui->pb_CreateNewSet, &QPushButton::clicked, this, &CDbOwnModelSetComponent::ps_buttonClicked);
connect(ui->pb_LoadExistingSet, &QPushButton::clicked, this, &CDbOwnModelSetComponent::ps_buttonClicked);
@@ -72,11 +75,27 @@ namespace BlackGui
const int diff = models.size() - cleanModelList.size();
if (diff > 0)
{
CLogMessage(this).warning("Removed models from set because not matching " + simulator.toQString(true));
CLogMessage(this).warning("Removed %1 models from set because not matching %2") << diff << simulator.toQString(true);
}
this->ui->tvp_OwnModelSet->updateContainerMaybeAsync(cleanModelList);
}
void CDbOwnModelSetComponent::replaceOrAddModelSet(const CAircraftModelList &models, const CSimulatorInfo &simulator)
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator");
if (models.isEmpty()) { return; }
CAircraftModelList cleanModelList(models.matchesSimulator(simulator)); // remove those not matching the simulator
const int diff = models.size() - cleanModelList.size();
if (diff > 0)
{
CLogMessage(this).warning("Removed %1 models from set because not matching %2") << diff << simulator.toQString(true);
}
if (cleanModelList.isEmpty()) { return; }
CAircraftModelList updatedModels(this->ui->tvp_OwnModelSet->container());
updatedModels.replaceOrAddModelsWithString(cleanModelList, Qt::CaseInsensitive);
this->ui->tvp_OwnModelSet->updateContainerMaybeAsync(updatedModels);
}
const CAircraftModelList &CDbOwnModelSetComponent::getModelSet() const
{
return ui->tvp_OwnModelSet->container();
@@ -167,7 +186,7 @@ namespace BlackGui
const CAircraftModelList ml(ui->tvp_OwnModelSet->container());
if (!ml.isEmpty())
{
const CStatusMessage m = this->m_modelSetLoader.setModelsInCache(ml);
const CStatusMessage m = this->m_modelSetLoader.setCachedModels(ml);
CLogMessage::preformatted(m);
}
}

View File

@@ -34,9 +34,17 @@ namespace BlackGui
*/
class CDbOwnModelSetComponent :
public QFrame,
public CDbMappingComponentAware
public CDbMappingComponentAware,
public BlackMisc::Simulation::IModelsSetable,
public BlackMisc::Simulation::IModelsUpdatable,
public BlackMisc::Simulation::IModelsPerSimulatorSetable,
public BlackMisc::Simulation::IModelsPerSimulatorUpdatable
{
Q_OBJECT
Q_INTERFACES(BlackMisc::Simulation::IModelsSetable)
Q_INTERFACES(BlackMisc::Simulation::IModelsUpdatable)
Q_INTERFACES(BlackMisc::Simulation::IModelsPerSimulatorSetable)
Q_INTERFACES(BlackMisc::Simulation::IModelsPerSimulatorUpdatable)
public:
//! Constructor
@@ -63,10 +71,21 @@ namespace BlackGui
//! \copydoc CDbMappingComponentAware::setMappingComponent
virtual void setMappingComponent(CDbMappingComponent *component) override;
//! \name Implementations of the models interfaces
//! @{
virtual void setModels(const BlackMisc::Simulation::CAircraftModelList &models) override { this->setModelSet(models, this->m_simulator); }
virtual void updateModels(const BlackMisc::Simulation::CAircraftModelList &models) override { this->replaceOrAddModelSet(models, this->m_simulator); }
virtual void setModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) override { this->setModelSet(models, simulator); }
virtual void updateModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) override { this->replaceOrAddModelSet(models, simulator); }
//! @}
public slots:
//! Set the model set
void setModelSet(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator);
//! Replace or add models provided
void replaceOrAddModelSet(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator);
private slots:
//! Tab has been changed
void ps_tabIndexChanged(int index);