mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-01 13:36:48 +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())
|
||||
{
|
||||
logInconsistentData(
|
||||
CStatusMessage(this, CStatusMessage::SeverityInfo, "Inconsistent airports: " + inconsistent.dbKeysAsStrings(", ")),
|
||||
CStatusMessage(this, CStatusMessage::SeverityInfo, "Inconsistent airports: " + inconsistent.dbKeysAsString(", ")),
|
||||
Q_FUNC_INFO);
|
||||
}
|
||||
|
||||
|
||||
@@ -257,7 +257,7 @@ namespace BlackCore
|
||||
if (!inconsistent.isEmpty())
|
||||
{
|
||||
logInconsistentData(
|
||||
CStatusMessage(this, CStatusMessage::SeverityInfo, "Inconsistent aircraft codes: " + inconsistent.dbKeysAsStrings(", ")),
|
||||
CStatusMessage(this, CStatusMessage::SeverityInfo, "Inconsistent aircraft codes: " + inconsistent.dbKeysAsString(", ")),
|
||||
Q_FUNC_INFO);
|
||||
}
|
||||
|
||||
@@ -307,7 +307,7 @@ namespace BlackCore
|
||||
if (!inconsistent.isEmpty())
|
||||
{
|
||||
logInconsistentData(
|
||||
CStatusMessage(this, CStatusMessage::SeverityInfo, "Inconsistent airline codes: " + inconsistent.dbKeysAsStrings(", ")),
|
||||
CStatusMessage(this, CStatusMessage::SeverityInfo, "Inconsistent airline codes: " + inconsistent.dbKeysAsString(", ")),
|
||||
Q_FUNC_INFO);
|
||||
}
|
||||
|
||||
|
||||
@@ -93,10 +93,12 @@ namespace BlackMisc
|
||||
CVariant IDatastoreObjectWithIntegerKey::propertyByIndex(const CPropertyIndex &index) const
|
||||
{
|
||||
if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::propertyByIndex(index); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
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());
|
||||
default: break;
|
||||
}
|
||||
@@ -106,12 +108,14 @@ namespace BlackMisc
|
||||
void IDatastoreObjectWithIntegerKey::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
|
||||
{
|
||||
if (ITimestampBased::canHandleIndex(index)) { ITimestampBased::setPropertyByIndex(index, variant); return; }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexDbIntegerKey:
|
||||
this->m_dbKey = variant.toInt();
|
||||
break;
|
||||
case IndexDbKeyAsString:
|
||||
this->m_dbKey = stringToDbKey(variant.toQString());
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -123,6 +127,7 @@ namespace BlackMisc
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexDbKeyAsString: // fall thru
|
||||
case IndexDbIntegerKey: return Compare::compare(this->m_dbKey, compareValue.getDbKey());
|
||||
case IndexDatabaseIcon: return Compare::compare(this->hasValidDbKey(), compareValue.hasValidDbKey());
|
||||
default: break;
|
||||
@@ -134,7 +139,7 @@ namespace BlackMisc
|
||||
bool IDatastoreObjectWithIntegerKey::canHandleIndex(const BlackMisc::CPropertyIndex &index)
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -145,6 +150,12 @@ namespace BlackMisc
|
||||
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
|
||||
{
|
||||
if (filter == All) { return true; }
|
||||
@@ -178,6 +189,7 @@ namespace BlackMisc
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexDbKeyAsString: // fall thru
|
||||
case IndexDbStringKey: return CVariant::from(this->m_dbKey);
|
||||
case IndexDatabaseIcon: return CVariant::from(this->toDatabaseIcon());
|
||||
case IndexIsLoadedFromDb: return CVariant::from(this->m_loadedFromDb);
|
||||
@@ -194,6 +206,7 @@ namespace BlackMisc
|
||||
switch (i)
|
||||
{
|
||||
case IndexDbStringKey:
|
||||
case IndexDbKeyAsString:
|
||||
this->m_dbKey = variant.value<QString>();
|
||||
break;
|
||||
case IndexIsLoadedFromDb:
|
||||
@@ -210,6 +223,7 @@ namespace BlackMisc
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexDbKeyAsString: // fall thru
|
||||
case IndexDbStringKey: return this->m_dbKey.compare(compareValue.getDbKey());
|
||||
case IndexDatabaseIcon: return Compare::compare(this->hasValidDbKey(), compareValue.hasValidDbKey());
|
||||
default:
|
||||
@@ -223,7 +237,7 @@ namespace BlackMisc
|
||||
{
|
||||
if (index.isEmpty()) { return false; }
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@ namespace BlackMisc
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexDbIntegerKey = CPropertyIndex::GlobalIndexIDatastoreInteger,
|
||||
IndexDbKeyAsString,
|
||||
IndexIsLoadedFromDb,
|
||||
IndexDatabaseIcon
|
||||
};
|
||||
|
||||
@@ -61,7 +63,7 @@ namespace BlackMisc
|
||||
//! Key as JSON value, or null
|
||||
QJsonValue getDbKeyAsJsonValue() const;
|
||||
|
||||
//! Db ley in parentheses, e.g. "(3)"
|
||||
//! Db key in parentheses, e.g. "(3)"
|
||||
QString getDbKeyAsStringInParentheses(const QString &prefix = {}) const;
|
||||
|
||||
//! Set the DB key
|
||||
@@ -130,6 +132,7 @@ namespace BlackMisc
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexDbStringKey = CPropertyIndex::GlobalIndexIDatastoreString,
|
||||
IndexDbKeyAsString,
|
||||
IndexIsLoadedFromDb,
|
||||
IndexDatabaseIcon
|
||||
};
|
||||
@@ -137,9 +140,15 @@ namespace BlackMisc
|
||||
//! Get DB key.
|
||||
const QString &getDbKey() const { return m_dbKey; }
|
||||
|
||||
//! DB key as string
|
||||
QString getDbKeyAsString() const { return getDbKey(); }
|
||||
|
||||
//! Key as JSON value, or null
|
||||
QJsonValue getDbKeyAsJsonValue() const;
|
||||
|
||||
//! Db key in parentheses, e.g. "(3)"
|
||||
QString getDbKeyAsStringInParentheses(const QString &prefix = {}) const;
|
||||
|
||||
//! Set the DB key
|
||||
void setDbKey(const QString &key) { m_dbKey = key.trimmed().toUpper(); }
|
||||
|
||||
|
||||
@@ -80,15 +80,33 @@ namespace BlackMisc
|
||||
}
|
||||
|
||||
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 ""; }
|
||||
const QSet<KEYTYPE> keys = IDatastoreObjectList<OBJ, CONTAINER, KEYTYPE>::toDbKeySet();
|
||||
const QSet<QString> keys = IDatastoreObjectList<OBJ, CONTAINER, KEYTYPE>::toDbKeyStringSet();
|
||||
QString s;
|
||||
for (const KEYTYPE &k : keys)
|
||||
for (const QString &k : keys)
|
||||
{
|
||||
if (!s.isEmpty()) { s += separator; }
|
||||
s = s.append(k); // append works with string and int
|
||||
if (s.isEmpty())
|
||||
{
|
||||
s += k;
|
||||
}
|
||||
else
|
||||
{
|
||||
s += separator + k;
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -35,11 +35,14 @@ namespace BlackMisc
|
||||
//! Sort by timestamp
|
||||
void sortByKey();
|
||||
|
||||
//! All keys as list
|
||||
//! All keys as set
|
||||
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
|
||||
QString dbKeysAsStrings(const QString &separator) const;
|
||||
QString dbKeysAsString(const QString &separator) const;
|
||||
|
||||
//! Max.key value (making sense with integer key)
|
||||
KEYTYPE getMaxKey(bool *ok = nullptr) const;
|
||||
|
||||
Reference in New Issue
Block a user