refs #538, Formatting, minor tweaks, comments

* new slot syntax in ATC station component
* formatting, comments
* tab order
* utility function for severity in status message
* null checks in threadutils
* invalidKey function in datastore
* changed data object keys (cached objets)
* added missing value object compare cases
* renamed timer in context network
* finder function for model list
* renamed getContainer to container (as it is just a reference)
This commit is contained in:
Klaus Basan
2015-12-05 16:39:54 +01:00
parent 66ff1803cf
commit 8f85c54989
24 changed files with 90 additions and 45 deletions

View File

@@ -52,9 +52,9 @@ namespace BlackCore
connect(this->m_network, &INetwork::textMessageSent, this, &CContextNetwork::textMessageSent); connect(this->m_network, &INetwork::textMessageSent, this, &CContextNetwork::textMessageSent);
// 2. Update timer for data (network data such as frequency) // 2. Update timer for data (network data such as frequency)
this->m_dataUpdateTimer = new QTimer(this); this->m_networkDataUpdateTimer = new QTimer(this);
connect(this->m_dataUpdateTimer, &QTimer::timeout, this, &CContextNetwork::requestDataUpdates); connect(this->m_networkDataUpdateTimer, &QTimer::timeout, this, &CContextNetwork::requestDataUpdates);
this->m_dataUpdateTimer->start(30 * 1000); this->m_networkDataUpdateTimer->start(30 * 1000);
// 3. data reader, start reading when setup is synced with xx delay // 3. data reader, start reading when setup is synced with xx delay
this->m_webDataReader = new CWebDataServices(CWebReaderFlags::AllReaders, 1000, this); this->m_webDataReader = new CWebDataServices(CWebReaderFlags::AllReaders, 1000, this);

View File

@@ -241,7 +241,7 @@ namespace BlackCore
CWebDataServices *m_webDataReader = nullptr; //!< web service readers CWebDataServices *m_webDataReader = nullptr; //!< web service readers
QList<QMetaObject::Connection> m_webReaderSignalConnections; QList<QMetaObject::Connection> m_webReaderSignalConnections;
INetwork::ConnectionStatus m_currentStatus = INetwork::Disconnected; //!< used to detect pending connections INetwork::ConnectionStatus m_currentStatus = INetwork::Disconnected; //!< used to detect pending connections
QTimer *m_dataUpdateTimer = nullptr; //!< general updates such as ATIS, frequencies, see requestDataUpdates() QTimer *m_networkDataUpdateTimer = nullptr; //!< general updates such as ATIS, frequencies, see requestDataUpdates()
// Digest signals, only sending after some time // Digest signals, only sending after some time
BlackMisc::CDigestSignal m_dsAtcStationsBookedChanged { this, &IContextNetwork::changedAtcStationsBooked, &IContextNetwork::changedAtcStationsBookedDigest, 750, 2 }; BlackMisc::CDigestSignal m_dsAtcStationsBookedChanged { this, &IContextNetwork::changedAtcStationsBooked, &IContextNetwork::changedAtcStationsBookedDigest, 750, 2 };

View File

@@ -70,7 +70,6 @@ namespace BlackCore
virtual bool updateOwnParts(const BlackMisc::Aviation::CAircraftParts &parts) override; virtual bool updateOwnParts(const BlackMisc::Aviation::CAircraftParts &parts) override;
public slots: public slots:
//! \copydoc IContextOwnAircraft::getOwnAircraft() //! \copydoc IContextOwnAircraft::getOwnAircraft()
//! \ingroup ownaircraftprovider //! \ingroup ownaircraftprovider
virtual BlackMisc::Simulation::CSimulatedAircraft getOwnAircraft() const override; virtual BlackMisc::Simulation::CSimulatedAircraft getOwnAircraft() const override;

View File

@@ -149,7 +149,7 @@ namespace BlackCore
struct GlobalSetup : public BlackCore::CDataTrait<CGlobalSetup> struct GlobalSetup : public BlackCore::CDataTrait<CGlobalSetup>
{ {
//! Key in data cache //! Key in data cache
static const char *key() { return "readers/global/setup"; } static const char *key() { return "readers/setup"; }
//! Default value //! Default value
static const CGlobalSetup &defaultValue() static const CGlobalSetup &defaultValue()

View File

@@ -106,7 +106,7 @@ namespace BlackCore
struct UpdateInfo : public BlackCore::CDataTrait<CUpdateInfo> struct UpdateInfo : public BlackCore::CDataTrait<CUpdateInfo>
{ {
//! Key in data cache //! Key in data cache
static const char *key() { return "readers/global/updateinfo"; } static const char *key() { return "readers/updateinfo"; }
//! Default value //! Default value
static const CUpdateInfo &defaultValue() static const CUpdateInfo &defaultValue()

View File

@@ -53,21 +53,20 @@ namespace BlackGui
this->ui->tvp_AtcStationsOnlineTree->setHeaderHidden(true); this->ui->tvp_AtcStationsOnlineTree->setHeaderHidden(true);
// Signal / Slots // Signal / Slots
bool connected = this->connect(this->ui->le_AtcStationsOnlineMetar, SIGNAL(returnPressed()), this, SLOT(getMetar())); connect(this->ui->le_AtcStationsOnlineMetar, &QLineEdit::returnPressed, this, &CAtcStationComponent::ps_getMetarAsEntered);
Q_ASSERT(connected); connect(this->ui->pb_AtcStationsLoadMetar, &QPushButton::clicked, this, &CAtcStationComponent::ps_getMetarAsEntered);
connected = this->connect(this->ui->pb_AtcStationsLoadMetar, SIGNAL(clicked()), this, SLOT(getMetar()));
Q_ASSERT(connected);
Q_UNUSED(connected);
connect(this, &QTabWidget::currentChanged, this, &CAtcStationComponent::ps_atcStationsTabChanged); // "local" tab changed (booked, online) connect(this, &QTabWidget::currentChanged, this, &CAtcStationComponent::ps_atcStationsTabChanged); // "local" tab changed (booked, online)
connect(this->ui->tvp_AtcStationsOnline, &QTableView::clicked, this, &CAtcStationComponent::ps_onlineAtcStationSelected); connect(this->ui->tvp_AtcStationsOnline, &QTableView::clicked, this, &CAtcStationComponent::ps_onlineAtcStationSelected);
connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::testRequestDummyAtcOnlineStations, this, &CAtcStationComponent::ps_testCreateDummyOnlineAtcStations); connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::testRequestDummyAtcOnlineStations, this, &CAtcStationComponent::ps_testCreateDummyOnlineAtcStations);
connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::requestUpdate, this, &CAtcStationComponent::ps_requestOnlineStationsUpdate); connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::requestUpdate, this, &CAtcStationComponent::ps_requestOnlineStationsUpdate);
connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::requestNewBackendData, this, &CAtcStationComponent::ps_requestOnlineStationsUpdate);
connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::rowCountChanged, this, &CAtcStationComponent::ps_onCountChanged); connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::rowCountChanged, this, &CAtcStationComponent::ps_onCountChanged);
connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::rowCountChanged, this, &CAtcStationComponent::ps_onCountChanged); connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::rowCountChanged, this, &CAtcStationComponent::ps_onCountChanged);
connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::requestComFrequency, this, &CAtcStationComponent::ps_setComFrequency); connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::requestComFrequency, this, &CAtcStationComponent::ps_setComFrequency);
connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::requestTextMessageWidget, this, &CAtcStationComponent::requestTextMessageWidget); connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::requestTextMessageWidget, this, &CAtcStationComponent::requestTextMessageWidget);
connect(this->ui->tvp_AtcStationsBooked, &CAtcStationView::requestUpdate, this, &CAtcStationComponent::ps_reloadAtcStationsBooked); connect(this->ui->tvp_AtcStationsBooked, &CAtcStationView::requestUpdate, this, &CAtcStationComponent::ps_reloadAtcStationsBooked);
connect(this->ui->tvp_AtcStationsBooked, &CAtcStationView::requestNewBackendData, this, &CAtcStationComponent::ps_reloadAtcStationsBooked);
connect(this->ui->tvp_AtcStationsBooked, &CAtcStationView::rowCountChanged, this, &CAtcStationComponent::ps_onCountChanged); connect(this->ui->tvp_AtcStationsBooked, &CAtcStationView::rowCountChanged, this, &CAtcStationComponent::ps_onCountChanged);
connect(this->ui->pb_AtcStationsAtisReload, &QPushButton::clicked, this, &CAtcStationComponent::ps_requestAtis); connect(this->ui->pb_AtcStationsAtisReload, &QPushButton::clicked, this, &CAtcStationComponent::ps_requestAtis);
@@ -133,7 +132,6 @@ namespace BlackGui
); );
this->m_timestampLastReadOnlineStations = QDateTime::currentDateTimeUtc(); this->m_timestampLastReadOnlineStations = QDateTime::currentDateTimeUtc();
this->m_timestampOnlineStationsChanged = this->m_timestampLastReadOnlineStations; this->m_timestampOnlineStationsChanged = this->m_timestampLastReadOnlineStations;
this->updateTreeView(); this->updateTreeView();
} }
} }
@@ -151,7 +149,7 @@ namespace BlackGui
void CAtcStationComponent::getMetar(const QString &airportIcaoCode) void CAtcStationComponent::getMetar(const QString &airportIcaoCode)
{ {
QString icao = airportIcaoCode.isEmpty() ? this->ui->le_AtcStationsOnlineMetar->text().trimmed().toUpper() : airportIcaoCode.trimmed().toUpper(); QString icao(airportIcaoCode.isEmpty() ? this->ui->le_AtcStationsOnlineMetar->text().trimmed().toUpper() : airportIcaoCode.trimmed().toUpper());
this->ui->le_AtcStationsOnlineMetar->setText(icao); this->ui->le_AtcStationsOnlineMetar->setText(icao);
if (icao.length() != 4) { return; } if (icao.length() != 4) { return; }
CMetar metar(this->getIContextNetwork()->getMetarForAirport(icao)); CMetar metar(this->getIContextNetwork()->getMetarForAirport(icao));
@@ -183,7 +181,7 @@ namespace BlackGui
} }
else else
{ {
this->ui->tvp_AtcStationsBooked->updateContainer(this->getIContextNetwork()->getAtcStationsBooked()); this->ui->tvp_AtcStationsBooked->updateContainerMaybeAsync(this->getIContextNetwork()->getAtcStationsBooked());
this->m_timestampLastReadBookedStations = QDateTime::currentDateTimeUtc(); this->m_timestampLastReadBookedStations = QDateTime::currentDateTimeUtc();
} }
} }
@@ -235,7 +233,7 @@ namespace BlackGui
if (this->isParentDockWidgetFloating()) { return; } if (this->isParentDockWidgetFloating()) { return; }
// here I know I am the selected widget, update, but keep GUI responsive (-> timer) // here I know I am the selected widget, update, but keep GUI responsive (-> timer)
QTimer::singleShot(1000, this, SLOT(update())); QTimer::singleShot(1000, this, &CAtcStationComponent::update);
Q_UNUSED(index); Q_UNUSED(index);
} }
@@ -263,6 +261,7 @@ namespace BlackGui
void CAtcStationComponent::updateTreeView() void CAtcStationComponent::updateTreeView()
{ {
// EXPERIMENTAL CODE // EXPERIMENTAL CODE
//! \todo change model so we can directly use hierarchies
QAbstractItemModel *old = (this->ui->tvp_AtcStationsOnlineTree->model()); QAbstractItemModel *old = (this->ui->tvp_AtcStationsOnlineTree->model());
this->ui->tvp_AtcStationsOnlineTree->setModel( this->ui->tvp_AtcStationsOnlineTree->setModel(
this->ui->tvp_AtcStationsOnline->derivedModel()->toAtcGroupModel() this->ui->tvp_AtcStationsOnline->derivedModel()->toAtcGroupModel()

View File

@@ -66,7 +66,7 @@ namespace BlackGui
void stopTimer() { Q_ASSERT(this->m_updateTimer); this->m_updateTimer->stopTimer(); } void stopTimer() { Q_ASSERT(this->m_updateTimer); this->m_updateTimer->stopTimer(); }
//! Get METAR for given ICAO airport code //! Get METAR for given ICAO airport code
void getMetar(const QString &airportIcaoCode = ""); void getMetar(const QString &airportIcaoCode);
//! \copydoc CAtcStationListModel::changedAtcStationConnectionStatus //! \copydoc CAtcStationListModel::changedAtcStationConnectionStatus
void changedAtcStationOnlineConnectionStatus(const BlackMisc::Aviation::CAtcStation &station, bool added); void changedAtcStationOnlineConnectionStatus(const BlackMisc::Aviation::CAtcStation &station, bool added);
@@ -76,6 +76,9 @@ namespace BlackGui
void runtimeHasBeenSet() override; void runtimeHasBeenSet() override;
private slots: private slots:
//! Get all METARs
void ps_getMetarAsEntered() { this->getMetar(""); }
//! Request new ATIS //! Request new ATIS
void ps_requestAtis(); void ps_requestAtis();

View File

@@ -2,6 +2,14 @@
<ui version="4.0"> <ui version="4.0">
<class>CDbLoginComponent</class> <class>CDbLoginComponent</class>
<widget class="QFrame" name="CDbLoginComponent"> <widget class="QFrame" name="CDbLoginComponent">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>345</width>
<height>325</height>
</rect>
</property>
<property name="windowTitle"> <property name="windowTitle">
<string>DB login</string> <string>DB login</string>
</property> </property>
@@ -73,7 +81,7 @@
<item> <item>
<widget class="QLabel" name="lbl_SwiftDB"> <widget class="QLabel" name="lbl_SwiftDB">
<property name="text"> <property name="text">
<string>DB</string> <string>DB replaced by URL</string>
</property> </property>
</widget> </widget>
</item> </item>
@@ -126,7 +134,7 @@
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="lbl_User"> <widget class="QLabel" name="lbl_User">
<property name="text"> <property name="text">
<string>User:</string> <string>Name:</string>
</property> </property>
</widget> </widget>
</item> </item>

View File

@@ -71,6 +71,7 @@ namespace BlackGui
this->ui->lbl_AircraftIconDisplayed->setText("Icon displayed here"); this->ui->lbl_AircraftIconDisplayed->setText("Icon displayed here");
// Updates // Updates
this->ui->tvp_AircraftModels->setDisplayAutomatically(false);
this->m_updateTimer->setUpdateInterval(10 * 1000); this->m_updateTimer->setUpdateInterval(10 * 1000);
} }
@@ -92,7 +93,7 @@ namespace BlackGui
CAircraftModelList CMappingComponent::findModelsStartingWith(const QString modelName, Qt::CaseSensitivity cs) CAircraftModelList CMappingComponent::findModelsStartingWith(const QString modelName, Qt::CaseSensitivity cs)
{ {
Q_ASSERT(this->ui->tvp_AircraftModels); Q_ASSERT(this->ui->tvp_AircraftModels);
return this->ui->tvp_AircraftModels->getContainer().findModelsStartingWith(modelName, cs); return this->ui->tvp_AircraftModels->container().findModelsStartingWith(modelName, cs);
} }
void CMappingComponent::runtimeHasBeenSet() void CMappingComponent::runtimeHasBeenSet()
@@ -217,7 +218,7 @@ namespace BlackGui
} }
const CCallsign callsign(cs); const CCallsign callsign(cs);
bool hasCallsign = this->ui->tvp_SimulatedAircraft->getContainer().containsCallsign(callsign); bool hasCallsign = this->ui->tvp_SimulatedAircraft->container().containsCallsign(callsign);
if (!hasCallsign) if (!hasCallsign)
{ {
CLogMessage(this).validationError("Unmapped callsign %1 for mapping") << callsign.asString(); CLogMessage(this).validationError("Unmapped callsign %1 for mapping") << callsign.asString();
@@ -231,7 +232,7 @@ namespace BlackGui
return; return;
} }
bool hasModel = this->ui->tvp_AircraftModels->getContainer().containsModelString(modelString); bool hasModel = this->ui->tvp_AircraftModels->container().containsModelString(modelString);
if (!hasModel) if (!hasModel)
{ {
CLogMessage(this).validationError("Invalid model for mapping"); CLogMessage(this).validationError("Invalid model for mapping");
@@ -297,7 +298,7 @@ namespace BlackGui
void CMappingComponent::ps_onModelsUpdateRequested() void CMappingComponent::ps_onModelsUpdateRequested()
{ {
Q_ASSERT(getIContextSimulator()); Q_ASSERT(getIContextSimulator());
CAircraftModelList ml = getIContextSimulator()->getInstalledModels(); CAircraftModelList ml(getIContextSimulator()->getInstalledModels());
this->ui->tvp_AircraftModels->updateContainer(ml); this->ui->tvp_AircraftModels->updateContainer(ml);
// model completer // model completer

View File

@@ -181,6 +181,15 @@
<container>1</container> <container>1</container>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<tabstops>
<tabstop>le_Id</tabstop>
<tabstop>le_ModelKey</tabstop>
<tabstop>le_Name</tabstop>
<tabstop>le_Description</tabstop>
<tabstop>ph_Stash</tabstop>
<tabstop>pb_Save</tabstop>
<tabstop>le_LastUpdated</tabstop>
</tabstops>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>

View File

@@ -20,7 +20,6 @@ namespace BlackGui
{ {
namespace Models namespace Models
{ {
class ActionItem; class ActionItem;
/*! /*!
@@ -31,7 +30,6 @@ namespace BlackGui
Q_OBJECT Q_OBJECT
public: public:
//! User roles //! User roles
enum ItemRole enum ItemRole
{ {
@@ -63,12 +61,12 @@ namespace BlackGui
int columnCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override;
private: private:
//! Init model data
void setupModelData(); void setupModelData();
QScopedPointer<ActionItem> m_rootItem; QScopedPointer<ActionItem> m_rootItem;
}; };
} }
} } // ns
#endif // guard #endif // guard

View File

@@ -94,14 +94,14 @@ namespace BlackGui
QStandardItemModel *model = new QStandardItemModel(); QStandardItemModel *model = new QStandardItemModel();
if (this->isEmpty()) { return model; } if (this->isEmpty()) { return model; }
model->setColumnCount(4); model->setColumnCount(4);
QMap<QString, int> types = this->getContainer().getSuffixes(); QMap<QString, int> types = this->container().getSuffixes();
for (const QString &type : types.keys()) for (const QString &type : types.keys())
{ {
// ownership of QStandardItem is taken by model // ownership of QStandardItem is taken by model
QStandardItem *typeFolderFirstColumn = new QStandardItem(CCallsign::atcSuffixToIcon(type).toQIcon(), type); QStandardItem *typeFolderFirstColumn = new QStandardItem(CCallsign::atcSuffixToIcon(type).toQIcon(), type);
QList<QStandardItem *> typeFolderRow { typeFolderFirstColumn }; QList<QStandardItem *> typeFolderRow { typeFolderFirstColumn };
model->invisibleRootItem()->appendRow(typeFolderRow); model->invisibleRootItem()->appendRow(typeFolderRow);
CAtcStationList stations = this->getContainer().findBySuffix(type); CAtcStationList stations = this->container().findBySuffix(type);
for (const CAtcStation &station : stations) for (const CAtcStation &station : stations)
{ {
QList<QStandardItem *> stationRow; QList<QStandardItem *> stationRow;

View File

@@ -200,7 +200,7 @@ namespace BlackGui
const CDefaultFormatter *CColumns::getFormatter(const QModelIndex &index) const const CDefaultFormatter *CColumns::getFormatter(const QModelIndex &index) const
{ {
if (!isValidColumn(index)) return nullptr; if (!isValidColumn(index)) { return nullptr; }
return this->m_columns.at(index.column()).getFormatter(); return this->m_columns.at(index.column()).getFormatter();
} }

View File

@@ -184,7 +184,7 @@ namespace BlackGui
// check / init // check / init
if (!this->isValidIndex(index)) { return QVariant(); } if (!this->isValidIndex(index)) { return QVariant(); }
const CDefaultFormatter *formatter = this->m_columns.getFormatter(index); const CDefaultFormatter *formatter = this->m_columns.getFormatter(index);
Q_ASSERT(formatter); Q_ASSERT_X(formatter, Q_FUNC_INFO, "Missing formatter");
if (!formatter) { return QVariant(); } if (!formatter) { return QVariant(); }
//! Formatted data //! Formatted data
@@ -372,7 +372,7 @@ namespace BlackGui
} }
template <typename ObjectType, typename ContainerType, bool UseCompare> template <typename ObjectType, typename ContainerType, bool UseCompare>
const ContainerType &CListModelBase<ObjectType, ContainerType, UseCompare>::getContainer() const const ContainerType &CListModelBase<ObjectType, ContainerType, UseCompare>::container() const
{ {
return this->m_container; return this->m_container;
} }
@@ -507,7 +507,7 @@ namespace BlackGui
{ {
this->sort(); // make sure container is sorted this->sort(); // make sure container is sorted
} }
ContainerType container(this->getContainer()); ContainerType container(this->container());
container.truncate(maxNumber); container.truncate(maxNumber);
this->updateContainerMaybeAsync(container, false); this->updateContainerMaybeAsync(container, false);
} }

View File

@@ -138,7 +138,7 @@ namespace BlackGui
virtual bool isValidIndex(const QModelIndex &index) const; virtual bool isValidIndex(const QModelIndex &index) const;
//! Used container data //! Used container data
virtual const ContainerType &getContainer() const; const ContainerType &container() const;
//! \copydoc QAbstractItemModel::data() //! \copydoc QAbstractItemModel::data()
virtual QVariant data(const QModelIndex &index, int role) const override; virtual QVariant data(const QModelIndex &index, int role) const override;
@@ -226,9 +226,7 @@ namespace BlackGui
protected: protected:
std::unique_ptr<IModelFilter<ContainerType> > m_filter; //!< Used filter std::unique_ptr<IModelFilter<ContainerType> > m_filter; //!< Used filter
//! Constructor //! \copydoc CListModelBaseNonTemplate::CListModelBaseNonTemplate
//! \param translationContext I18N context
//! \param parent
CListModelBase(const QString &translationContext, QObject *parent = nullptr) CListModelBase(const QString &translationContext, QObject *parent = nullptr)
: CListModelBaseNonTemplate(translationContext, parent) : CListModelBaseNonTemplate(translationContext, parent)
{ } { }
@@ -268,7 +266,6 @@ namespace BlackGui
BlackMisc::CVariant bQv = b.propertyByIndex(index); BlackMisc::CVariant bQv = b.propertyByIndex(index);
return (order == Qt::AscendingOrder) ? (aQv < bQv) : (bQv < aQv); return (order == Qt::AscendingOrder) ? (aQv < bQv) : (bQv < aQv);
} }
} // namespace } // namespace
} // namespace } // namespace
} // namespace } // namespace

View File

@@ -27,7 +27,6 @@ namespace BlackGui
Q_OBJECT Q_OBJECT
public: public:
//! Constructor //! Constructor
explicit CAtcStationView(QWidget *parent = nullptr); explicit CAtcStationView(QWidget *parent = nullptr);

View File

@@ -302,8 +302,14 @@ namespace BlackMisc
return Compare::compare(m_legacy, compareValue.isLegacyAircraft()); return Compare::compare(m_legacy, compareValue.isLegacyAircraft());
case IndexIsMilitary: case IndexIsMilitary:
return Compare::compare(m_military, compareValue.isMilitary()); return Compare::compare(m_military, compareValue.isMilitary());
case IndexIsVtol:
return Compare::compare(isVtol(), compareValue.isVtol());
case IndexIsRealworld:
return Compare::compare(m_realWorld, compareValue.isRealWorld());
case IndexRank: case IndexRank:
return Compare::compare(m_rank, compareValue.getRank()); return Compare::compare(m_rank, compareValue.getRank());
case IndexDesignatorManufacturer:
return getDesignatorManufacturer().compare(compareValue.getDesignatorManufacturer(), Qt::CaseInsensitive);
default: default:
break; break;
} }

View File

@@ -44,7 +44,7 @@ namespace BlackMisc
IndexIsLegacy, IndexIsLegacy,
IndexIsVtol, IndexIsVtol,
IndexRank, IndexRank,
IndexDesignatorManufacturer IndexDesignatorManufacturer //!< designator and manufacturer
}; };
//! Default constructor. //! Default constructor.

View File

@@ -166,6 +166,8 @@ namespace BlackMisc
return this->m_designator.compare(compareValue.getDesignator()); return this->m_designator.compare(compareValue.getDesignator());
case IndexAirlineCountry: case IndexAirlineCountry:
return this->m_country.comparePropertyByIndex(compareValue.getCountry(), index.copyFrontRemoved()); return this->m_country.comparePropertyByIndex(compareValue.getCountry(), index.copyFrontRemoved());
case IndexDesignatorNameCountry:
return this->m_country.getName().compare(compareValue.getCountry().getName(), Qt::CaseInsensitive);
case IndexAirlineName: case IndexAirlineName:
return this->m_name.compare(compareValue.getName(), Qt::CaseInsensitive); return this->m_name.compare(compareValue.getName(), Qt::CaseInsensitive);
case IndexTelephonyDesignator: case IndexTelephonyDesignator:

View File

@@ -49,6 +49,9 @@ namespace BlackMisc
//! Has valid DB key //! Has valid DB key
bool hasValidDbKey() const { return m_dbKey >= 0; } bool hasValidDbKey() const { return m_dbKey >= 0; }
//! Invalid key
static int invalidDbKey() { return -1; }
protected: protected:
//! Constructor //! Constructor
IDatastoreObjectWithIntegerKey() {} IDatastoreObjectWithIntegerKey() {}
@@ -98,6 +101,9 @@ namespace BlackMisc
//! Has valid DB key //! Has valid DB key
bool hasValidDbKey() const { return !m_dbKey.isEmpty(); } bool hasValidDbKey() const { return !m_dbKey.isEmpty(); }
//! Invalid key
static QString invalidDbKey() { return ""; }
protected: protected:
//! Constructor //! Constructor
IDatastoreObjectWithStringKey() {} IDatastoreObjectWithStringKey() {}

View File

@@ -28,6 +28,16 @@ namespace BlackMisc
return false; return false;
} }
bool CAircraftModelList::containsModelStringOrId(const CAircraftModel &model, Qt::CaseSensitivity sensitivity) const
{
for (const CAircraftModel &m : (*this))
{
if (m.hasValidDbKey() && m.getDbKey() == model.getDbKey()) { return true; }
if (m.matchesModelString(model.getModelString(), sensitivity)) { return true; }
}
return false;
}
CAircraftModelList CAircraftModelList::findByModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const CAircraftModelList CAircraftModelList::findByModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const
{ {
return this->findBy([ = ](const CAircraftModel & model) return this->findBy([ = ](const CAircraftModel & model)

View File

@@ -40,6 +40,9 @@ namespace BlackMisc
//! Contains model string //! Contains model string
bool containsModelString(const QString &modelString, Qt::CaseSensitivity sensitivity = Qt::CaseInsensitive) const; bool containsModelString(const QString &modelString, Qt::CaseSensitivity sensitivity = Qt::CaseInsensitive) const;
//! Contains model with model string or id
bool containsModelStringOrId(const BlackMisc::Simulation::CAircraftModel &model, Qt::CaseSensitivity sensitivity = Qt::CaseInsensitive) const;
//! Find by model string //! Find by model string
CAircraftModelList findByModelString(const QString &modelString, Qt::CaseSensitivity sensitivity = Qt::CaseInsensitive) const; CAircraftModelList findByModelString(const QString &modelString, Qt::CaseSensitivity sensitivity = Qt::CaseInsensitive) const;

View File

@@ -94,15 +94,18 @@ namespace BlackMisc
//! Message severity //! Message severity
StatusSeverity getSeverity() const { return this->m_severity; } StatusSeverity getSeverity() const { return this->m_severity; }
//! Info or debug, no warning or error
bool isSeverityInfoOrLess() const { return this->m_severity == SeverityInfo || this->m_severity == SeverityDebug; }
//! Warning or above
bool isWarningOrAbove() const { return this->m_severity == SeverityWarning || this->m_severity == SeverityError; }
//! Message //! Message
QString getMessage() const { return this->m_message; } QString getMessage() const { return this->m_message; }
//! Message empty //! Message empty
bool isEmpty() const { return this->m_message.isEmpty(); } bool isEmpty() const { return this->m_message.isEmpty(); }
//! Info or debug, no warning or error
bool isSeverityInfoOrLess() const { return this->m_severity == SeverityInfo || this->m_severity == SeverityDebug; }
//! Returns true if this message was sent by an instance of class T. //! Returns true if this message was sent by an instance of class T.
template <class T> template <class T>
bool isFromClass(const T *pointer = nullptr) const bool isFromClass(const T *pointer = nullptr) const

View File

@@ -24,13 +24,15 @@ namespace BlackMisc
bool CThreadUtils::isApplicationThreadObjectThread(QObject *toBeTested) bool CThreadUtils::isApplicationThreadObjectThread(QObject *toBeTested)
{ {
Q_ASSERT_X(toBeTested, Q_FUNC_INFO, "missing QObject"); Q_ASSERT_X(toBeTested, Q_FUNC_INFO, "missing QObject");
if (!toBeTested) { return false; } if (!toBeTested || !toBeTested->thread()) { return false; }
if (!toBeTested->thread()) { return false; } if (!QCoreApplication::instance() || !QCoreApplication::instance()->thread()) { return false; }
return (QCoreApplication::instance()->thread() == toBeTested->thread()); return (QCoreApplication::instance()->thread() == toBeTested->thread());
} }
bool CThreadUtils::isCurrentThreadApplicationThread() bool CThreadUtils::isCurrentThreadApplicationThread()
{ {
if (!QCoreApplication::instance()) { return false; }
if (!QCoreApplication::instance()->thread()) { return false; }
return (QCoreApplication::instance()->thread() == QThread::currentThread()); return (QCoreApplication::instance()->thread() == QThread::currentThread());
} }