7#include <QStringBuilder>
14namespace swift::misc::db
21 QString timestampString(json.value(prefix % u
"lastupdated").toString());
24 timestampString = json.value(prefix % u
"tsLastUpdated").toString();
54 const int k = key.
toInt(&ok);
67 return (validKey && filter.testFlag(Valid)) || (!validKey && filter.testFlag(Invalid));
72 static const CIcon empty;
87 int k = candidate.
toInt(&ok);
104 const int dbKey = json.value(prefix % u
"id").
toInt(-1);
111 const QJsonValue jv(json.value(prefix % u
"id"));
144 case IndexDbIntegerKey:
m_dbKey = variant.
toInt();
break;
161 case IndexDbKeyAsString:
167 Q_ASSERT_X(
false, Q_FUNC_INFO,
"Compare failed");
178 return (i >=
static_cast<int>(IndexDbIntegerKey)) && (i < static_cast<int>(
IndexEndMarker));
197 return prefix %
'(' %
m_dbKey %
')';
211 static const CIcon empty;
222 QString dbKey = json.value(prefix % u
"id").toString();
229 const QJsonValue jv(json.value(prefix % u
"id"));
242 case IndexDbKeyAsString:
262 case IndexDbStringKey:
280 case IndexDbKeyAsString:
281 case IndexDbStringKey:
return m_dbKey.compare(compareValue.
getDbKey());
286 Q_ASSERT_X(
false, Q_FUNC_INFO,
"Compare failed");
301 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.
const QString & getVersion() const
Version info.
QVersionNumber getQVersion() const
Version as QVersion.
void setTimestampVersionFromDatabaseJson(const QJsonObject &json, const QString &prefix=QString())
Set versionn and timestamp values.
void setVersion(const QString &version)
Version info.
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.
IDatastoreObjectWithIntegerKey()
Constructor.
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.
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.
IDatastoreObjectWithStringKey()
Constructor.
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.
const QString & getDbKey() const
Get DB key.
QJsonValue getDbKeyAsJsonValue() const
Key as JSON value, or null.
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.
int compare(T a, T b)
Compare arithmetic values.
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)