7 #include <QStringBuilder>
14 namespace swift::misc::db
22 if (timestampString.
isEmpty()) { timestampString = json.
value(prefix % u
"tsLastUpdated").
toString(); }
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);
83 const int dbKey = json.
value(prefix % u
"id").
toInt(-1);
120 case IndexDbIntegerKey:
m_dbKey = variant.
toInt();
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));
164 return prefix %
'(' %
m_dbKey %
')';
169 if (filter == All) {
return true; }
175 static const CIcon empty;
200 case IndexDbKeyAsString:
220 case IndexDbStringKey:
238 case IndexDbKeyAsString:
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.
QJsonValue value(QLatin1StringView key) const const
bool isNull() const const
bool isUndefined() const const
int toInt(int defaultValue) const const
QString toString() const const
int compare(QLatin1StringView s1, const QString &s2, Qt::CaseSensitivity cs)
bool isEmpty() const const
QString number(double n, char format, int precision)
int toInt(bool *ok, int base) const const
QVariant fromValue(T &&value)
bool toBool() const const
int toInt(bool *ok) const const
QString toString() const const
QVersionNumber fromString(QAnyStringView string, qsizetype *suffixIndex)