7 #include <QStringBuilder>
14 namespace swift::misc::db
21 QString timestampString(json.value(prefix % u
"lastupdated").toString());
22 if (timestampString.isEmpty()) { timestampString = json.value(prefix % u
"tsLastUpdated").toString(); }
27 this->
setVersion(json.value(prefix % u
"version").toString());
33 return QString::number(
m_dbKey);
39 return prefix % u
'(' % QString::number(
m_dbKey) % u
')';
45 const int k = key.toInt(&ok);
53 if (filter == All) {
return true; }
55 return (validKey && filter.testFlag(Valid)) || (!validKey && filter.testFlag(Invalid));
60 static const CIcon empty;
69 int k = candidate.toInt(&ok);
80 const QString &prefix)
83 const int dbKey = json.value(prefix % u
"id").toInt(-1);
90 const QJsonValue jv(json.value(prefix % u
"id"));
91 return !(jv.isNull() || jv.isUndefined());
100 case IndexDbIntegerKey:
return QVariant::fromValue(
m_dbKey);
101 case IndexDbKeyAsString:
return QVariant::fromValue(this->
getDbKeyAsString());
102 case IndexIsLoadedFromDb:
return QVariant::fromValue(this->
hasValidDbKey());
103 case IndexDatabaseIcon:
return QVariant::fromValue(this->
toDatabaseIcon());
104 case IndexVersion:
return QVariant::fromValue(this->
getVersion());
120 case IndexDbIntegerKey:
m_dbKey = variant.toInt();
break;
122 case IndexVersion: this->
setVersion(variant.toString());
break;
137 case IndexDbKeyAsString:
138 case IndexDbIntegerKey:
return Compare::compare(
m_dbKey, compareValue.
getDbKey());
143 Q_ASSERT_X(
false, Q_FUNC_INFO,
"Compare failed");
151 return (i >=
static_cast<int>(IndexDbIntegerKey)) && (i <
static_cast<int>(
IndexEndMarker));
157 static const QJsonValue
null;
163 if (
m_dbKey.isEmpty()) {
return {}; }
164 return prefix %
'(' %
m_dbKey %
')';
169 if (filter == All) {
return true; }
175 static const CIcon empty;
181 const QString &prefix)
183 QString dbKey = json.value(prefix % u
"id").toString();
190 const QJsonValue jv(json.value(prefix % u
"id"));
191 return !(jv.isNull() || jv.isUndefined());
200 case IndexDbKeyAsString:
201 case IndexDbStringKey:
return QVariant::fromValue(
m_dbKey);
202 case IndexDatabaseIcon:
return QVariant::fromValue(this->
toDatabaseIcon());
203 case IndexIsLoadedFromDb:
return QVariant::fromValue(
m_loadedFromDb);
204 case IndexVersion:
return QVariant::fromValue(this->
getVersion());
220 case IndexDbStringKey:
221 case IndexDbKeyAsString:
m_dbKey = variant.value<QString>();
break;
222 case IndexIsLoadedFromDb:
m_loadedFromDb = variant.toBool();
break;
223 case IndexVersion: this->
setVersion(variant.toString());
break;
238 case IndexDbKeyAsString:
239 case IndexDbStringKey:
return m_dbKey.compare(compareValue.
getDbKey());
244 Q_ASSERT_X(
false, Q_FUNC_INFO,
"Compare failed");
250 if (index.
isEmpty()) {
return false; }
253 return (i >=
static_cast<int>(IndexDbStringKey)) && (i <
static_cast<int>(
IndexEndMarker));
Value object for icons. An icon is stored in the global icon repository and identified by its index....
static const CIcon & iconByIndex(CIcons::IconIndex index)
Icon for given index.
Non-owning reference to a CPropertyIndex with a subset of its features.
bool isEmpty() const
Empty?
CastType frontCasted() const
First element casted to given type, usually the PropertIndex enum.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
int comparePropertyByIndex(CPropertyIndexRef index, const ITimestampBased &compareValue) const
Compare for index.
static bool canHandleIndex(CPropertyIndexRef index)
Can given index be handled.
void setUtcTimestamp(const QDateTime ×tamp)
Set timestamp.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
static QDateTime parseTimestamp(const QString ×tamp)
Parse a timestamp object.
QVersionNumber getQVersion() const
Version as QVersion.
void setTimestampVersionFromDatabaseJson(const QJsonObject &json, const QString &prefix=QString())
Set versionn and timestamp values.
const QString & getVersion() const
Version info.
void setVersion(const QString &version)
Version info.
Class from which a derived class can inherit datastore-related functions.
int getDbKey() const
Get DB key.
static int stringToDbKey(const QString &candidate)
Convert string to DB key.
const CIcon & toDatabaseIcon() const
Database icon if this has valid key, otherwise empty.
QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const
Property by index.
QJsonValue getDbKeyAsJsonValue() const
Key as JSON value, or null.
QString getDbKeyAsString() const
DB key as string.
bool isLoadedFromDb() const
Loaded from DB.
ColumnIndex
Property index.
@ IndexEndMarker
keep as last element
static bool existsKey(const QJsonObject &json, const QString &prefix=QString())
Is a key available?
static bool canHandleIndex(swift::misc::CPropertyIndexRef index)
Can given index be handled?
void setDbKey(int key)
Set the DB key.
static int invalidDbKey()
Invalid key.
QString getDbKeyAsStringInParentheses(const QString &prefix={}) const
Db key in parentheses, e.g. "(3)".
int comparePropertyByIndex(CPropertyIndexRef index, const IDatastoreObjectWithIntegerKey &compareValue) const
Compare for index.
void setKeyVersionTimestampFromDatabaseJson(const QJsonObject &json, const QString &prefix=QString())
Set key and timestamp values.
bool matchesDbKeyState(db::DbKeyStateFilter filter) const
Matches filter?
bool hasValidDbKey() const
Has valid DB key.
void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant)
Set property by index.
Class from which a derived class can inherit datastore-related functions.
bool m_loadedFromDb
as we have no artificial key, it can happen key is set, but not loaded from DB
QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const
Property by index.
void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant)
Set property by index.
static bool existsKey(const QJsonObject &json, const QString &prefix=QString())
Is a key available?
bool hasValidDbKey() const
Has valid DB key.
const CIcon & toDatabaseIcon() const
Database icon if this has valid key, otherwise empty.
static bool canHandleIndex(swift::misc::CPropertyIndexRef index)
Can given index be handled.
QJsonValue getDbKeyAsJsonValue() const
Key as JSON value, or null.
const QString & getDbKey() const
Get DB key.
ColumnIndex
Property index.
@ IndexEndMarker
keep as last element
QString getDbKeyAsStringInParentheses(const QString &prefix={}) const
Db key in parentheses, e.g. "(3)".
void setKeyVersionTimestampFromDatabaseJson(const QJsonObject &json, const QString &prefix=QString())
Set key and timestamp values.
int comparePropertyByIndex(swift::misc::CPropertyIndexRef index, const IDatastoreObjectWithStringKey &compareValue) const
Compare for index.
bool matchesDbKeyState(db::DbKeyStateFilter filter) const
Matches filter?
void setDbKey(const QString &key)
Set the DB key.