From 1678ca89198313c39bddaf0eb8bb75a8666cd307 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 27 Oct 2016 01:03:36 +0200 Subject: [PATCH] refs #780, improved model string completion * added signatures for completer string (when send via context size matters) * support of all instaled models in completer * added BLACKMISC_EXPORT in model cache classes --- src/blackcore/context/contextsimulator.h | 3 ++ src/blackcore/context/contextsimulatorempty.h | 8 ++++ .../context/contextsimulatorimpl.cpp | 8 +++- src/blackcore/context/contextsimulatorimpl.h | 1 + .../context/contextsimulatorproxy.cpp | 5 +++ src/blackcore/context/contextsimulatorproxy.h | 1 + src/blackcore/webdataservices.cpp | 6 +++ src/blackcore/webdataservices.h | 4 ++ .../aircraftmodelstringcompleter.cpp | 38 +++++++++++-------- .../components/aircraftmodelstringcompleter.h | 13 +++++-- src/blackmisc/simulation/data/modelcaches.h | 7 ++-- 11 files changed, 70 insertions(+), 24 deletions(-) diff --git a/src/blackcore/context/contextsimulator.h b/src/blackcore/context/contextsimulator.h index cf668914c..cb71e7d66 100644 --- a/src/blackcore/context/contextsimulator.h +++ b/src/blackcore/context/contextsimulator.h @@ -150,6 +150,9 @@ namespace BlackCore //! Model strings virtual QStringList getModelSetStrings() const = 0; + //! Model set completer string + virtual QStringList getModelSetCompleterStrings(bool sorted) const = 0; + //! Set time synchronization between simulator and user's computer time //! \remarks not all drivers implement this, e.g. if it is an intrinsic simulator feature virtual bool setTimeSynchronization(bool enable, const BlackMisc::PhysicalQuantities::CTime &offset) = 0; diff --git a/src/blackcore/context/contextsimulatorempty.h b/src/blackcore/context/contextsimulatorempty.h index e36724629..6e8ccf71b 100644 --- a/src/blackcore/context/contextsimulatorempty.h +++ b/src/blackcore/context/contextsimulatorempty.h @@ -87,6 +87,14 @@ namespace BlackCore return QStringList(); } + //! \copydoc IContextSimulator::getModelSetStrings + virtual QStringList getModelSetCompleterStrings(bool sorted) const override + { + Q_UNUSED(sorted); + logEmptyContextWarning(Q_FUNC_INFO); + return QStringList(); + } + //! \copydoc IContextSimulator::getModelSetModelsStartingWith virtual BlackMisc::Simulation::CAircraftModelList getModelSetModelsStartingWith(const QString modelString) const override { diff --git a/src/blackcore/context/contextsimulatorimpl.cpp b/src/blackcore/context/contextsimulatorimpl.cpp index aec927026..1c11674d0 100644 --- a/src/blackcore/context/contextsimulatorimpl.cpp +++ b/src/blackcore/context/contextsimulatorimpl.cpp @@ -162,6 +162,12 @@ namespace BlackCore return this->getModelSet().getModelStringList(false); } + QStringList CContextSimulator::getModelSetCompleterStrings(bool sorted) const + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << sorted; } + return this->getModelSet().toCompleterStrings(sorted); + } + int CContextSimulator::getModelSetCount() const { if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } @@ -396,7 +402,7 @@ namespace BlackCore Q_ASSERT(this->getIContextApplication()->isUsingImplementingObject()); Q_ASSERT(!simulatorInfo.isUnspecified()); - ISimulator::SimulatorStatus simStatus = getSimulatorStatusEnum(); + const ISimulator::SimulatorStatus simStatus = getSimulatorStatusEnum(); if (!m_simulatorPlugin.first.isUnspecified() && m_simulatorPlugin.first == simulatorInfo && simStatus.testFlag(ISimulator::Connected)) { diff --git a/src/blackcore/context/contextsimulatorimpl.h b/src/blackcore/context/contextsimulatorimpl.h index 75febc48c..f0694e274 100644 --- a/src/blackcore/context/contextsimulatorimpl.h +++ b/src/blackcore/context/contextsimulatorimpl.h @@ -82,6 +82,7 @@ namespace BlackCore virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const override; virtual BlackMisc::Simulation::CAircraftModelList getModelSet() const override; virtual QStringList getModelSetStrings() const override; + virtual QStringList getModelSetCompleterStrings(bool sorted) const override; virtual int getModelSetCount() const override; virtual BlackMisc::Simulation::CAircraftModelList getModelSetModelsStartingWith(const QString modelString) const override; virtual bool setTimeSynchronization(bool enable, const BlackMisc::PhysicalQuantities::CTime &offset) override; diff --git a/src/blackcore/context/contextsimulatorproxy.cpp b/src/blackcore/context/contextsimulatorproxy.cpp index ac23b6871..ed6fbdd21 100644 --- a/src/blackcore/context/contextsimulatorproxy.cpp +++ b/src/blackcore/context/contextsimulatorproxy.cpp @@ -94,6 +94,11 @@ namespace BlackCore return m_dBusInterface->callDBusRet(QLatin1Literal("getModelSetStrings")); } + QStringList CContextSimulatorProxy::getModelSetCompleterStrings(bool sorted) const + { + return m_dBusInterface->callDBusRet(QLatin1Literal("getModelSetCompleterStrings"), sorted); + } + CAircraftModelList CContextSimulatorProxy::getModelSetModelsStartingWith(const QString modelString) const { return m_dBusInterface->callDBusRet(QLatin1Literal("getModelSetModelsStartingWith"), modelString); diff --git a/src/blackcore/context/contextsimulatorproxy.h b/src/blackcore/context/contextsimulatorproxy.h index 8a760496a..86378bbdf 100644 --- a/src/blackcore/context/contextsimulatorproxy.h +++ b/src/blackcore/context/contextsimulatorproxy.h @@ -61,6 +61,7 @@ namespace BlackCore virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const override; virtual BlackMisc::Simulation::CAircraftModelList getModelSet() const override; virtual QStringList getModelSetStrings() const override; + virtual QStringList getModelSetCompleterStrings(bool sorted) const override; virtual BlackMisc::Simulation::CAircraftModelList getModelSetModelsStartingWith(const QString modelString) const override; virtual int getModelSetCount() const override; virtual BlackMisc::Simulation::CSimulatorSetup getSimulatorSetup() const override; diff --git a/src/blackcore/webdataservices.cpp b/src/blackcore/webdataservices.cpp index 50c4c7ac7..b9294c594 100644 --- a/src/blackcore/webdataservices.cpp +++ b/src/blackcore/webdataservices.cpp @@ -419,6 +419,12 @@ namespace BlackCore return QStringList(); } + QStringList CWebDataServices::getModelCompleterStrings(bool sorted) const + { + if (m_modelDataReader) { return m_modelDataReader->getModels().toCompleterStrings(sorted); } + return QStringList(); + } + CAircraftModelList CWebDataServices::getModelsForAircraftDesignatorAndLiveryCombinedCode(const QString &aircraftDesignator, const QString &combinedCode) const { if (m_modelDataReader) { return m_modelDataReader->getModelsForAircraftDesignatorAndLiveryCombinedCode(aircraftDesignator, combinedCode); } diff --git a/src/blackcore/webdataservices.h b/src/blackcore/webdataservices.h index a46fe1b96..6622ab2c0 100644 --- a/src/blackcore/webdataservices.h +++ b/src/blackcore/webdataservices.h @@ -215,6 +215,10 @@ namespace BlackCore //! \threadsafe QStringList getModelStrings() const; + //! Model completer string + //! \threadsafe + QStringList getModelCompleterStrings(bool sorted = true) const; + //! Models for combined code and aircraft designator //! \threadsafe BlackMisc::Simulation::CAircraftModelList getModelsForAircraftDesignatorAndLiveryCombinedCode(const QString &aircraftDesignator, const QString &combinedCode) const; diff --git a/src/blackgui/components/aircraftmodelstringcompleter.cpp b/src/blackgui/components/aircraftmodelstringcompleter.cpp index d819a9ab9..2b2e61ac6 100644 --- a/src/blackgui/components/aircraftmodelstringcompleter.cpp +++ b/src/blackgui/components/aircraftmodelstringcompleter.cpp @@ -18,6 +18,8 @@ using namespace BlackCore; using namespace BlackCore::Context; +using namespace BlackMisc::Simulation; +using namespace BlackMisc::Simulation::Data; namespace BlackGui { @@ -42,6 +44,15 @@ namespace BlackGui if (sGui->getIContextSimulator()) { connect(sGui->getIContextSimulator(), &IContextSimulator::simulatorStatusChanged, this, &CAircraftModelStringCompleter::ps_simulatorConnected); + const CSimulatorInfo sim(sGui->getIContextSimulator()->getSimulatorPluginInfo().getSimulator()); + if (sim.isSingleSimulator()) + { + this->m_modelCaches.setCurrentSimulator(sim); + } + else + { + this->setSourceVisible(OwnModels, false); + } } } @@ -95,32 +106,27 @@ namespace BlackGui void CAircraftModelStringCompleter::setCompleter() { QStringList modelStrings; + CompleterSourceFlag sourceWithData = None; if (ui->rb_Db->isChecked()) { - modelStrings = sGui->getWebDataServices()->getModelStrings(); + if (this->m_currentSourceWithData == DB) { return; } + modelStrings = sGui->getWebDataServices()->getModelCompleterStrings(); + if (!modelStrings.isEmpty()) { sourceWithData = DB; } } else if (ui->rb_ModelSet->isChecked()) { - if (!this->m_completerOwnModels) - { - const QStringList modelStrings = sGui->getIContextSimulator()->getModelSet().getModelStringList(); - this->m_completerModelSet = new QCompleter(modelStrings, this); - setCompleterParameters(this->m_completerModelSet); - } - ui->le_modelString->setCompleter(this->m_completerOwnModels); + if (this->m_currentSourceWithData == ModelSet) { return; } + modelStrings = sGui->getIContextSimulator()->getModelSetCompleterStrings(true); + if (!modelStrings.isEmpty()) { sourceWithData = ModelSet; } } else if (ui->rb_OwnModels->isChecked()) { - if (!this->m_completerOwnModels) - { - const QStringList modelStrings = sGui->getIContextSimulator()->getModelSet().getModelStringList(); - this->m_completerOwnModels = new QCompleter(modelStrings, this); - setCompleterParameters(this->m_completerOwnModels); - } - ui->le_modelString->setCompleter(this->m_completerOwnModels); - modelStrings = sGui->getIContextSimulator()->getModelSet().getModelStringList(); + if (this->m_currentSourceWithData == OwnModels) { return; } + modelStrings = this->m_modelCaches.getCurrentCachedModels().toCompleterStrings(); + if (!modelStrings.isEmpty()) { sourceWithData = OwnModels; } } + this->m_currentSourceWithData = sourceWithData; ui->le_modelString->setCompleter(new QCompleter(modelStrings, this)); ui->le_modelString->setPlaceholderText(QString("model strings (%1)").arg(modelStrings.size())); } diff --git a/src/blackgui/components/aircraftmodelstringcompleter.h b/src/blackgui/components/aircraftmodelstringcompleter.h index 4fb945413..48a812325 100644 --- a/src/blackgui/components/aircraftmodelstringcompleter.h +++ b/src/blackgui/components/aircraftmodelstringcompleter.h @@ -12,6 +12,7 @@ #ifndef BLACKGUI_COMPLETER_AIRCRAFTMODELSTRINGCOMPLETER_H #define BLACKGUI_COMPLETER_AIRCRAFTMODELSTRINGCOMPLETER_H +#include "blackmisc/simulation/data/modelcaches.h" #include "blackmisc/simulation/aircraftmodel.h" #include #include @@ -33,10 +34,12 @@ namespace BlackGui public: //! Sources for string completion - enum CompleterSourceFlag { - DB, - ModelSet, - OwnModels + enum CompleterSourceFlag + { + None = 0, //!< normally used to indicate nothing was loaded + DB = 1 << 0, + ModelSet = 1 << 1, + OwnModels = 1 << 2 }; Q_DECLARE_FLAGS(CompleterSource, CompleterSourceFlag) @@ -93,6 +96,8 @@ namespace BlackGui private: QScopedPointer ui; + BlackMisc::Simulation::Data::CModelCaches m_modelCaches { false, this }; //!< all models, works locally only + CompleterSourceFlag m_currentSourceWithData = None; }; } // ns } // ns diff --git a/src/blackmisc/simulation/data/modelcaches.h b/src/blackmisc/simulation/data/modelcaches.h index a37217fb4..5832f1039 100644 --- a/src/blackmisc/simulation/data/modelcaches.h +++ b/src/blackmisc/simulation/data/modelcaches.h @@ -12,6 +12,7 @@ #ifndef BLACKMISC_SIMULATION_DATA_MODELCACHES #define BLACKMISC_SIMULATION_DATA_MODELCACHES +#include "blackmisc/blackmiscexport.h" #include "blackmisc/datacache.h" #include "blackmisc/simulation/aircraftmodelinterfaces.h" #include "blackmisc/simulation/aircraftmodellist.h" @@ -140,7 +141,7 @@ namespace BlackMisc }; //! Cache for multiple simulators specified by BlackMisc::Simulation::CSimulatorInfo - class IMultiSimulatorModelCaches : + class BLACKMISC_EXPORT IMultiSimulatorModelCaches : public QObject, public IModelsPerSimulatorSetable { @@ -224,7 +225,7 @@ namespace BlackMisc //! Bundle of caches for all simulators //! \remark remembers its last simulator selection - class CModelCaches : public IMultiSimulatorModelCaches + class BLACKMISC_EXPORT CModelCaches : public IMultiSimulatorModelCaches { Q_OBJECT @@ -255,7 +256,7 @@ namespace BlackMisc //! Bundle of caches for model sets of all simulators //! \remark remembers its last simulator selection - class CModelSetCaches : public IMultiSimulatorModelCaches + class BLACKMISC_EXPORT CModelSetCaches : public IMultiSimulatorModelCaches { Q_OBJECT