6 #include <QStringBuilder>
10 using namespace swift::misc::network;
14 namespace swift::misc::db
16 CDbInfo::CDbInfo(
int key,
const QString &tableName,
int entries)
20 Q_ASSERT_X(tableName.
isEmpty() || m_entity != CEntityFlags::NoEntity, Q_FUNC_INFO,
"Wrong entity");
27 if (m_entity != CEntityFlags::NoEntity) {
return m_entity; }
29 return CEntityFlags::singleEntityByName(tn);
34 const CEntityFlags::Entity entity = CEntityFlags::singleEntityByName(this->
getTableName());
40 const CEntityFlags::Entity entity = CEntityFlags::singleEntityByName(this->
getTableName());
48 return entity.testFlag(CEntityFlags::entityToEntityFlag(this->
getEntity()));
60 return QStringLiteral(
"Table %1 with entries %1").arg(m_tableName).arg(m_entries);
91 case IndexEntity: this->
setEntity(
static_cast<CEntityFlags::Entity
>(variant.
toInt()));
break;
114 case IndexEntity:
return Compare::compare(this->
getEntity(), compareValue.
getEntity());
115 default: Q_ASSERT_X(
false, Q_FUNC_INFO,
"No comparison possible");
127 const int id(json.
value(prefix % u
"id").
toInt());
128 const int entries(json.
value(prefix % u
"entries").
toInt());
130 CDbInfo dbInfo(
id, tableName, entries);
137 static const QStringList names({
"aircrafticao.json",
"airlineicao.json",
"airports.json",
"countries.json",
138 "distributors.json",
"liveries.json",
"models.json",
139 "aircraftcategories.json" });
145 static const QString f(
"dbinfo.json");
151 static const QStringList names({
"jsonaircrafticao.php",
"jsonairlineicao.php",
"jsonairport.php",
152 "jsoncountry.php",
"jsondistributor.php",
"jsonlivery.php",
153 "jsonaircraftmodel.php",
"jsonaircraftcategory.php" });
180 case CEntityFlags::AircraftIcaoEntity:
return serviceNames().
at(0);
181 case CEntityFlags::AirlineIcaoEntity:
return serviceNames().
at(1);
184 case CEntityFlags::DistributorEntity:
return serviceNames().
at(4);
187 case CEntityFlags::AircraftCategoryEntity:
return serviceNames().
at(7);
Non-owning reference to a CPropertyIndex with a subset of its features.
CastType frontCasted() const
First element casted to given type, usually the PropertIndex enum.
bool isMyself() const
Myself index, used with nesting.
Info about the latest models.
CDbInfo()=default
Constructor.
int comparePropertyByIndex(CPropertyIndexRef index, const CDbInfo &compareValue) const
Compare by index.
const QString & getSharedFileName() const
The shared file name such as "airports.json".
static const QString & sharedInfoFileName()
Get shared info file name.
void setEntries(int entries)
Set entries.
const QString & getServiceName() const
Service name such as "jsonairport.php".
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
static const QStringList & sharedFileNames()
The shared file names.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
bool isValid() const
Valid?
static const QStringList & serviceNames()
Service names.
static const QString & entityToSharedName(network::CEntityFlags::Entity entity)
Get shared file name.
bool matchesEntity(network::CEntityFlags::Entity entity) const
Matches given entity.
int getEntries() const
Entry count.
QString convertToQString(bool i18n=false) const
Cast as QString.
const QString & getTableName() const
Table name.
static CDbInfo fromDatabaseJson(const QJsonObject &json, const QString &prefix=QString())
From our database JSON format.
void setEntity(network::CEntityFlags::Entity entity)
Set entity, should be in sync with a corresponding table name.
void setTableName(const QString &tableName)
Set table name.
static const QString & entityToServiceName(network::CEntityFlags::Entity entity)
Get service file name.
network::CEntityFlags::Entity getEntity() const
Get entity (based on table name.
Class from which a derived class can inherit datastore-related functions.
QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const
Property by index.
ColumnIndex
Property index.
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?
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.
void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant)
Set property by index.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
QJsonValue value(QLatin1StringView key) const const
int toInt(int defaultValue) const const
QString toString() const const
QList< T >::const_reference at(qsizetype i) const const
int compare(QLatin1StringView s1, const QString &s2, Qt::CaseSensitivity cs)
bool isEmpty() const const
QString toLower() const const
QString trimmed() const const
QVariant fromValue(T &&value)
int toInt(bool *ok) const const
QString toString() const const
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.