mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-15 03:45:41 +08:00
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
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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))
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -94,6 +94,11 @@ namespace BlackCore
|
||||
return m_dBusInterface->callDBusRet<QStringList>(QLatin1Literal("getModelSetStrings"));
|
||||
}
|
||||
|
||||
QStringList CContextSimulatorProxy::getModelSetCompleterStrings(bool sorted) const
|
||||
{
|
||||
return m_dBusInterface->callDBusRet<QStringList>(QLatin1Literal("getModelSetCompleterStrings"), sorted);
|
||||
}
|
||||
|
||||
CAircraftModelList CContextSimulatorProxy::getModelSetModelsStartingWith(const QString modelString) const
|
||||
{
|
||||
return m_dBusInterface->callDBusRet<BlackMisc::Simulation::CAircraftModelList>(QLatin1Literal("getModelSetModelsStartingWith"), modelString);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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); }
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
|
||||
@@ -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 <QFrame>
|
||||
#include <QScopedPointer>
|
||||
@@ -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::CAircraftModelStringCompleter> ui;
|
||||
BlackMisc::Simulation::Data::CModelCaches m_modelCaches { false, this }; //!< all models, works locally only
|
||||
CompleterSourceFlag m_currentSourceWithData = None;
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user