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");
23 bool CDbInfo::isValid()
const {
return m_entity != CEntityFlags::NoEntity && !m_tableName.isEmpty(); }
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()));
53 m_tableName = tableName.trimmed().toLower();
60 return QStringLiteral(
"Table %1 with entries %1").arg(m_tableName).arg(m_entries);
65 if (index.
isMyself()) {
return QVariant::fromValue(*
this); }
69 case IndexTableName:
return QVariant::fromValue(m_tableName);
70 case IndexEntries:
return QVariant::fromValue(m_entries);
71 case IndexEntity:
return QVariant::fromValue(m_entity);
83 (*this) = variant.value<
CDbInfo>();
89 case IndexTableName: this->
setTableName(variant.toString());
break;
90 case IndexEntries: this->
setTableName(variant.toString());
break;
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());
129 const QString tableName(json.value(prefix % u
"tablename").toString());
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" });
159 static const QString empty;
169 case CEntityFlags::AircraftCategoryEntity:
return sharedFileNames().at(7);
177 static const QString empty;
180 case CEntityFlags::AircraftIcaoEntity:
return serviceNames().at(0);
181 case CEntityFlags::AirlineIcaoEntity:
return serviceNames().at(1);
182 case CEntityFlags::AirportEntity:
return serviceNames().at(2);
183 case CEntityFlags::CountryEntity:
return serviceNames().at(3);
184 case CEntityFlags::DistributorEntity:
return serviceNames().at(4);
185 case CEntityFlags::LiveryEntity:
return serviceNames().at(5);
186 case CEntityFlags::ModelEntity:
return serviceNames().at(6);
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.
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.
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.