mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-01 06:35:41 +08:00
Ref T109, datastore object and list
* unified properties in int/string DB objects * fixed typo dbKeysAsString
This commit is contained in:
committed by
Mathew Sutcliffe
parent
03a551d016
commit
dfb6b05e9d
@@ -175,7 +175,7 @@ namespace BlackCore
|
|||||||
if (!inconsistent.isEmpty())
|
if (!inconsistent.isEmpty())
|
||||||
{
|
{
|
||||||
logInconsistentData(
|
logInconsistentData(
|
||||||
CStatusMessage(this, CStatusMessage::SeverityInfo, "Inconsistent airports: " + inconsistent.dbKeysAsStrings(", ")),
|
CStatusMessage(this, CStatusMessage::SeverityInfo, "Inconsistent airports: " + inconsistent.dbKeysAsString(", ")),
|
||||||
Q_FUNC_INFO);
|
Q_FUNC_INFO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -257,7 +257,7 @@ namespace BlackCore
|
|||||||
if (!inconsistent.isEmpty())
|
if (!inconsistent.isEmpty())
|
||||||
{
|
{
|
||||||
logInconsistentData(
|
logInconsistentData(
|
||||||
CStatusMessage(this, CStatusMessage::SeverityInfo, "Inconsistent aircraft codes: " + inconsistent.dbKeysAsStrings(", ")),
|
CStatusMessage(this, CStatusMessage::SeverityInfo, "Inconsistent aircraft codes: " + inconsistent.dbKeysAsString(", ")),
|
||||||
Q_FUNC_INFO);
|
Q_FUNC_INFO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,7 +307,7 @@ namespace BlackCore
|
|||||||
if (!inconsistent.isEmpty())
|
if (!inconsistent.isEmpty())
|
||||||
{
|
{
|
||||||
logInconsistentData(
|
logInconsistentData(
|
||||||
CStatusMessage(this, CStatusMessage::SeverityInfo, "Inconsistent airline codes: " + inconsistent.dbKeysAsStrings(", ")),
|
CStatusMessage(this, CStatusMessage::SeverityInfo, "Inconsistent airline codes: " + inconsistent.dbKeysAsString(", ")),
|
||||||
Q_FUNC_INFO);
|
Q_FUNC_INFO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -93,10 +93,12 @@ namespace BlackMisc
|
|||||||
CVariant IDatastoreObjectWithIntegerKey::propertyByIndex(const CPropertyIndex &index) const
|
CVariant IDatastoreObjectWithIntegerKey::propertyByIndex(const CPropertyIndex &index) const
|
||||||
{
|
{
|
||||||
if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::propertyByIndex(index); }
|
if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::propertyByIndex(index); }
|
||||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||||
switch (i)
|
switch (i)
|
||||||
{
|
{
|
||||||
case IndexDbIntegerKey: return CVariant::from(this->m_dbKey);
|
case IndexDbIntegerKey: return CVariant::from(this->m_dbKey);
|
||||||
|
case IndexDbKeyAsString: return CVariant::from(this->getDbKeyAsString());
|
||||||
|
case IndexIsLoadedFromDb: return CVariant::from(this->hasValidDbKey());
|
||||||
case IndexDatabaseIcon: return CVariant::from(this->toDatabaseIcon());
|
case IndexDatabaseIcon: return CVariant::from(this->toDatabaseIcon());
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
@@ -106,12 +108,14 @@ namespace BlackMisc
|
|||||||
void IDatastoreObjectWithIntegerKey::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
|
void IDatastoreObjectWithIntegerKey::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
|
||||||
{
|
{
|
||||||
if (ITimestampBased::canHandleIndex(index)) { ITimestampBased::setPropertyByIndex(index, variant); return; }
|
if (ITimestampBased::canHandleIndex(index)) { ITimestampBased::setPropertyByIndex(index, variant); return; }
|
||||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||||
switch (i)
|
switch (i)
|
||||||
{
|
{
|
||||||
case IndexDbIntegerKey:
|
case IndexDbIntegerKey:
|
||||||
this->m_dbKey = variant.toInt();
|
this->m_dbKey = variant.toInt();
|
||||||
break;
|
break;
|
||||||
|
case IndexDbKeyAsString:
|
||||||
|
this->m_dbKey = stringToDbKey(variant.toQString());
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -123,6 +127,7 @@ namespace BlackMisc
|
|||||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||||
switch (i)
|
switch (i)
|
||||||
{
|
{
|
||||||
|
case IndexDbKeyAsString: // fall thru
|
||||||
case IndexDbIntegerKey: return Compare::compare(this->m_dbKey, compareValue.getDbKey());
|
case IndexDbIntegerKey: return Compare::compare(this->m_dbKey, compareValue.getDbKey());
|
||||||
case IndexDatabaseIcon: return Compare::compare(this->hasValidDbKey(), compareValue.hasValidDbKey());
|
case IndexDatabaseIcon: return Compare::compare(this->hasValidDbKey(), compareValue.hasValidDbKey());
|
||||||
default: break;
|
default: break;
|
||||||
@@ -134,7 +139,7 @@ namespace BlackMisc
|
|||||||
bool IDatastoreObjectWithIntegerKey::canHandleIndex(const BlackMisc::CPropertyIndex &index)
|
bool IDatastoreObjectWithIntegerKey::canHandleIndex(const BlackMisc::CPropertyIndex &index)
|
||||||
{
|
{
|
||||||
if (ITimestampBased::canHandleIndex(index)) { return true;}
|
if (ITimestampBased::canHandleIndex(index)) { return true;}
|
||||||
int i = index.frontCasted<int>();
|
const int i = index.frontCasted<int>();
|
||||||
return (i >= static_cast<int>(IndexDbIntegerKey)) && (i <= static_cast<int>(IndexDatabaseIcon));
|
return (i >= static_cast<int>(IndexDbIntegerKey)) && (i <= static_cast<int>(IndexDatabaseIcon));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,6 +150,12 @@ namespace BlackMisc
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString IDatastoreObjectWithStringKey::getDbKeyAsStringInParentheses(const QString &prefix) const
|
||||||
|
{
|
||||||
|
if (this->m_dbKey.isEmpty()) { return ""; }
|
||||||
|
return prefix + "(" + m_dbKey + ")";
|
||||||
|
}
|
||||||
|
|
||||||
bool IDatastoreObjectWithStringKey::matchesDbKeyState(Db::DbKeyStateFilter filter) const
|
bool IDatastoreObjectWithStringKey::matchesDbKeyState(Db::DbKeyStateFilter filter) const
|
||||||
{
|
{
|
||||||
if (filter == All) { return true; }
|
if (filter == All) { return true; }
|
||||||
@@ -178,6 +189,7 @@ namespace BlackMisc
|
|||||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||||
switch (i)
|
switch (i)
|
||||||
{
|
{
|
||||||
|
case IndexDbKeyAsString: // fall thru
|
||||||
case IndexDbStringKey: return CVariant::from(this->m_dbKey);
|
case IndexDbStringKey: return CVariant::from(this->m_dbKey);
|
||||||
case IndexDatabaseIcon: return CVariant::from(this->toDatabaseIcon());
|
case IndexDatabaseIcon: return CVariant::from(this->toDatabaseIcon());
|
||||||
case IndexIsLoadedFromDb: return CVariant::from(this->m_loadedFromDb);
|
case IndexIsLoadedFromDb: return CVariant::from(this->m_loadedFromDb);
|
||||||
@@ -194,6 +206,7 @@ namespace BlackMisc
|
|||||||
switch (i)
|
switch (i)
|
||||||
{
|
{
|
||||||
case IndexDbStringKey:
|
case IndexDbStringKey:
|
||||||
|
case IndexDbKeyAsString:
|
||||||
this->m_dbKey = variant.value<QString>();
|
this->m_dbKey = variant.value<QString>();
|
||||||
break;
|
break;
|
||||||
case IndexIsLoadedFromDb:
|
case IndexIsLoadedFromDb:
|
||||||
@@ -210,6 +223,7 @@ namespace BlackMisc
|
|||||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||||
switch (i)
|
switch (i)
|
||||||
{
|
{
|
||||||
|
case IndexDbKeyAsString: // fall thru
|
||||||
case IndexDbStringKey: return this->m_dbKey.compare(compareValue.getDbKey());
|
case IndexDbStringKey: return this->m_dbKey.compare(compareValue.getDbKey());
|
||||||
case IndexDatabaseIcon: return Compare::compare(this->hasValidDbKey(), compareValue.hasValidDbKey());
|
case IndexDatabaseIcon: return Compare::compare(this->hasValidDbKey(), compareValue.hasValidDbKey());
|
||||||
default:
|
default:
|
||||||
@@ -223,7 +237,7 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
if (index.isEmpty()) { return false; }
|
if (index.isEmpty()) { return false; }
|
||||||
if (ITimestampBased::canHandleIndex(index)) { return true;}
|
if (ITimestampBased::canHandleIndex(index)) { return true;}
|
||||||
int i = index.frontCasted<int>();
|
const int i = index.frontCasted<int>();
|
||||||
return (i >= static_cast<int>(IndexDbStringKey)) && (i <= static_cast<int>(IndexDatabaseIcon));
|
return (i >= static_cast<int>(IndexDbStringKey)) && (i <= static_cast<int>(IndexDatabaseIcon));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ namespace BlackMisc
|
|||||||
enum ColumnIndex
|
enum ColumnIndex
|
||||||
{
|
{
|
||||||
IndexDbIntegerKey = CPropertyIndex::GlobalIndexIDatastoreInteger,
|
IndexDbIntegerKey = CPropertyIndex::GlobalIndexIDatastoreInteger,
|
||||||
|
IndexDbKeyAsString,
|
||||||
|
IndexIsLoadedFromDb,
|
||||||
IndexDatabaseIcon
|
IndexDatabaseIcon
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -61,7 +63,7 @@ namespace BlackMisc
|
|||||||
//! Key as JSON value, or null
|
//! Key as JSON value, or null
|
||||||
QJsonValue getDbKeyAsJsonValue() const;
|
QJsonValue getDbKeyAsJsonValue() const;
|
||||||
|
|
||||||
//! Db ley in parentheses, e.g. "(3)"
|
//! Db key in parentheses, e.g. "(3)"
|
||||||
QString getDbKeyAsStringInParentheses(const QString &prefix = {}) const;
|
QString getDbKeyAsStringInParentheses(const QString &prefix = {}) const;
|
||||||
|
|
||||||
//! Set the DB key
|
//! Set the DB key
|
||||||
@@ -130,6 +132,7 @@ namespace BlackMisc
|
|||||||
enum ColumnIndex
|
enum ColumnIndex
|
||||||
{
|
{
|
||||||
IndexDbStringKey = CPropertyIndex::GlobalIndexIDatastoreString,
|
IndexDbStringKey = CPropertyIndex::GlobalIndexIDatastoreString,
|
||||||
|
IndexDbKeyAsString,
|
||||||
IndexIsLoadedFromDb,
|
IndexIsLoadedFromDb,
|
||||||
IndexDatabaseIcon
|
IndexDatabaseIcon
|
||||||
};
|
};
|
||||||
@@ -137,9 +140,15 @@ namespace BlackMisc
|
|||||||
//! Get DB key.
|
//! Get DB key.
|
||||||
const QString &getDbKey() const { return m_dbKey; }
|
const QString &getDbKey() const { return m_dbKey; }
|
||||||
|
|
||||||
|
//! DB key as string
|
||||||
|
QString getDbKeyAsString() const { return getDbKey(); }
|
||||||
|
|
||||||
//! Key as JSON value, or null
|
//! Key as JSON value, or null
|
||||||
QJsonValue getDbKeyAsJsonValue() const;
|
QJsonValue getDbKeyAsJsonValue() const;
|
||||||
|
|
||||||
|
//! Db key in parentheses, e.g. "(3)"
|
||||||
|
QString getDbKeyAsStringInParentheses(const QString &prefix = {}) const;
|
||||||
|
|
||||||
//! Set the DB key
|
//! Set the DB key
|
||||||
void setDbKey(const QString &key) { m_dbKey = key.trimmed().toUpper(); }
|
void setDbKey(const QString &key) { m_dbKey = key.trimmed().toUpper(); }
|
||||||
|
|
||||||
|
|||||||
@@ -80,15 +80,33 @@ namespace BlackMisc
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<class OBJ, class CONTAINER, typename KEYTYPE>
|
template<class OBJ, class CONTAINER, typename KEYTYPE>
|
||||||
QString IDatastoreObjectList<OBJ, CONTAINER, KEYTYPE>::dbKeysAsStrings(const QString &separator) const
|
QSet<QString> IDatastoreObjectList<OBJ, CONTAINER, KEYTYPE>::toDbKeyStringSet() const
|
||||||
|
{
|
||||||
|
QSet<QString> keys;
|
||||||
|
for (const OBJ &obj : ITimestampObjectList<OBJ, CONTAINER>::container())
|
||||||
|
{
|
||||||
|
if (!obj.hasValidDbKey()) { continue; }
|
||||||
|
keys.insert(obj.getDbKeyAsString());
|
||||||
|
}
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class OBJ, class CONTAINER, typename KEYTYPE>
|
||||||
|
QString IDatastoreObjectList<OBJ, CONTAINER, KEYTYPE>::dbKeysAsString(const QString &separator) const
|
||||||
{
|
{
|
||||||
if (ITimestampObjectList<OBJ, CONTAINER>::container().isEmpty()) { return ""; }
|
if (ITimestampObjectList<OBJ, CONTAINER>::container().isEmpty()) { return ""; }
|
||||||
const QSet<KEYTYPE> keys = IDatastoreObjectList<OBJ, CONTAINER, KEYTYPE>::toDbKeySet();
|
const QSet<QString> keys = IDatastoreObjectList<OBJ, CONTAINER, KEYTYPE>::toDbKeyStringSet();
|
||||||
QString s;
|
QString s;
|
||||||
for (const KEYTYPE &k : keys)
|
for (const QString &k : keys)
|
||||||
{
|
{
|
||||||
if (!s.isEmpty()) { s += separator; }
|
if (s.isEmpty())
|
||||||
s = s.append(k); // append works with string and int
|
{
|
||||||
|
s += k;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
s += separator + k;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,11 +35,14 @@ namespace BlackMisc
|
|||||||
//! Sort by timestamp
|
//! Sort by timestamp
|
||||||
void sortByKey();
|
void sortByKey();
|
||||||
|
|
||||||
//! All keys as list
|
//! All keys as set
|
||||||
QSet<KEYTYPE> toDbKeySet() const;
|
QSet<KEYTYPE> toDbKeySet() const;
|
||||||
|
|
||||||
|
//! All keys as string set (also int keys will be converted to string)
|
||||||
|
QSet<QString> toDbKeyStringSet() const;
|
||||||
|
|
||||||
//! The DB keys as string
|
//! The DB keys as string
|
||||||
QString dbKeysAsStrings(const QString &separator) const;
|
QString dbKeysAsString(const QString &separator) const;
|
||||||
|
|
||||||
//! Max.key value (making sense with integer key)
|
//! Max.key value (making sense with integer key)
|
||||||
KEYTYPE getMaxKey(bool *ok = nullptr) const;
|
KEYTYPE getMaxKey(bool *ok = nullptr) const;
|
||||||
|
|||||||
Reference in New Issue
Block a user