refs #720, improved distributor and airline/livery detection

* mark data read from DB (req. for string key where existing key value is not reliable indicator for DB data)
* detect distributors by part of model string
* use a simplified name (no spaces, no special characters) to find a match
* allow to obtain model strings (=keys) as set and list
This commit is contained in:
Klaus Basan
2016-08-09 01:24:47 +02:00
committed by Mathew Sutcliffe
parent 39dae7ed45
commit f9922353c4
21 changed files with 220 additions and 40 deletions

View File

@@ -41,6 +41,18 @@ namespace BlackMisc
this->m_dbKey = k;
}
bool IDatastoreObjectWithIntegerKey::isLoadedFromDb() const
{
return this->hasValidDbKey();
}
bool IDatastoreObjectWithIntegerKey::matchesDbKeyState(Db::DbKeyStateFilter filter) const
{
if (filter == All) { return true; }
const bool validKey = this->hasValidDbKey();
return (validKey && filter.testFlag(Valid)) || (!validKey && filter.testFlag(Invalid));
}
const CIcon &IDatastoreObjectWithIntegerKey::toDatabaseIcon() const
{
static const CIcon empty;
@@ -131,6 +143,12 @@ namespace BlackMisc
return null;
}
bool IDatastoreObjectWithStringKey::matchesDbKeyState(Db::DbKeyStateFilter filter) const
{
if (filter == All) { return true; }
return this->hasValidDbKey() && filter.testFlag(Valid);
}
const CIcon &IDatastoreObjectWithStringKey::toDatabaseIcon() const
{
static const CIcon empty;
@@ -159,6 +177,7 @@ namespace BlackMisc
{
case IndexDbStringKey: return CVariant::from(this->m_dbKey);
case IndexDatabaseIcon: return CVariant::from(this->toDatabaseIcon());
case IndexIsLoadedFromDb: return CVariant::from(this->m_loadedFromDb);
default:
break;
}
@@ -174,6 +193,9 @@ namespace BlackMisc
case IndexDbStringKey:
this->m_dbKey = variant.value<QString>();
break;
case IndexIsLoadedFromDb:
this->m_loadedFromDb = variant.toBool();
break;
default:
break;
}

View File

@@ -25,9 +25,20 @@
namespace BlackMisc
{
class CIcon;
namespace Db
{
//! State of key (in DB, ...?)
enum DbKeyState
{
Undefined = 0,
Valid = 1 << 0,
Invalid = 1 << 1,
All = Valid | Invalid
};
//! Supposed to be used only in filter operations
Q_DECLARE_FLAGS(DbKeyStateFilter, DbKeyState)
/*!
* Class from which a derived class can inherit datastore-related functions.
*/
@@ -62,6 +73,13 @@ namespace BlackMisc
//! Has valid DB key
bool hasValidDbKey() const { return m_dbKey >= 0; }
//! Loaded from DB
//! \remarks here not really needed, but added to have similar signature as IDatastoreObjectWithStringKey
bool isLoadedFromDb() const;
//! Matches filter?
bool matchesDbKeyState(Db::DbKeyStateFilter filter) const;
//! Database icon if this has valid key, otherwise empty
const CIcon &toDatabaseIcon() const;
@@ -109,6 +127,7 @@ namespace BlackMisc
enum ColumnIndex
{
IndexDbStringKey = CPropertyIndex::GlobalIndexIDatastoreString,
IndexIsLoadedFromDb,
IndexDatabaseIcon
};
@@ -124,6 +143,15 @@ namespace BlackMisc
//! Has valid DB key
bool hasValidDbKey() const { return !m_dbKey.isEmpty(); }
//! Loaded from DB
bool isLoadedFromDb() const { return m_loadedFromDb; }
//! Mark as loaded from DB
void setLoadedFromDb(bool loaded) { m_loadedFromDb = loaded; }
//! Matches filter?
bool matchesDbKeyState(Db::DbKeyStateFilter filter) const;
//! Database icon if this has valid key, otherwise empty
const CIcon &toDatabaseIcon() const;
@@ -155,11 +183,15 @@ namespace BlackMisc
//! Can given index be handled
static bool canHandleIndex(const BlackMisc::CPropertyIndex &index);
QString m_dbKey; //!< key
QString m_dbKey; //!< key
bool m_loadedFromDb = false; //!< as we have no artificial key, it can happen key is set, but not loaded from DB
};
} // ns
} // ns
Q_DECLARE_METATYPE(BlackMisc::Db::DbKeyState)
Q_DECLARE_METATYPE(BlackMisc::Db::DbKeyStateFilter)
Q_DECLARE_OPERATORS_FOR_FLAGS(BlackMisc::Db::DbKeyStateFilter)
Q_DECLARE_INTERFACE(BlackMisc::Db::IDatastoreObjectWithIntegerKey, "org.swift-project.blackmisc.db.idatastoreobjectwithintegerkey")
Q_DECLARE_INTERFACE(BlackMisc::Db::IDatastoreObjectWithStringKey, "org.swift-project.blackmisc.db.idatastoreobjectwithstringkey")