mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 19:05:31 +08:00
refs #527, JSON reading of value objects
* renamed simkey to modelstring * allow parsing of stub objects (only foreign keys, not denormalized)
This commit is contained in:
@@ -143,12 +143,17 @@ namespace BlackMisc
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString combinedCode(json.value(prefix + "combinedcode").toString());
|
QString combinedCode(json.value(prefix + "combinedcode").toString());
|
||||||
|
if (combinedCode.isEmpty()) {
|
||||||
|
CLivery liveryStub; // only consists of id, maybe id and timestamp
|
||||||
|
liveryStub.setKeyAndTimestampFromDatabaseJson(json, prefix);
|
||||||
|
return liveryStub;
|
||||||
|
}
|
||||||
|
|
||||||
QString description(json.value(prefix + "description").toString());
|
QString description(json.value(prefix + "description").toString());
|
||||||
CRgbColor colorFuselage(json.value(prefix + "colorfuselage").toString());
|
CRgbColor colorFuselage(json.value(prefix + "colorfuselage").toString());
|
||||||
CRgbColor colorTail(json.value(prefix + "colortail").toString());
|
CRgbColor colorTail(json.value(prefix + "colortail").toString());
|
||||||
bool military = CDatastoreUtility::dbBoolStringToBool(json.value(prefix + "military").toString());
|
bool military = CDatastoreUtility::dbBoolStringToBool(json.value(prefix + "military").toString());
|
||||||
CAirlineIcaoCode airline(CAirlineIcaoCode::fromDatabaseJson(json, "al_"));
|
CAirlineIcaoCode airline(CAirlineIcaoCode::fromDatabaseJson(json, "al_"));
|
||||||
Q_ASSERT_X(description.length() > 0, Q_FUNC_INFO, "require description");
|
|
||||||
CLivery livery(combinedCode, airline, description, colorFuselage, colorTail, military);
|
CLivery livery(combinedCode, airline, description, colorFuselage, colorTail, military);
|
||||||
livery.setKeyAndTimestampFromDatabaseJson(json, prefix);
|
livery.setKeyAndTimestampFromDatabaseJson(json, prefix);
|
||||||
return livery;
|
return livery;
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ namespace BlackMisc
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
CAircraftModel::CAircraftModel(const QString &model, CAircraftModel::ModelType type, CSimulatorInfo &simulator, const QString &name, const QString &description, const CAircraftIcaoCode &icao, const CLivery &livery) :
|
CAircraftModel::CAircraftModel(const QString &model, CAircraftModel::ModelType type, CSimulatorInfo &simulator, const QString &name, const QString &description, const CAircraftIcaoCode &icao, const CLivery &livery) :
|
||||||
m_aircraftIcao(icao), m_livery(livery), m_simulator(simulator), m_modelString(model.trimmed().toUpper()), m_modelName(name.trimmed()), m_description(description.trimmed()), m_modelType(type)
|
m_aircraftIcao(icao), m_livery(livery), m_simulator(simulator), m_modelString(model.trimmed().toUpper()), m_name(name.trimmed()), m_description(description.trimmed()), m_modelType(type)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
QString CAircraftModel::convertToQString(bool i18n) const
|
QString CAircraftModel::convertToQString(bool i18n) const
|
||||||
@@ -61,7 +61,7 @@ namespace BlackMisc
|
|||||||
|
|
||||||
// filename not in DB
|
// filename not in DB
|
||||||
obj.insert("id", this->getDbKeyAsJsonValue());
|
obj.insert("id", this->getDbKeyAsJsonValue());
|
||||||
obj.insert("simkey", QJsonValue(this->m_modelString));
|
obj.insert("modelstring", QJsonValue(this->m_modelString));
|
||||||
obj.insert("description", QJsonValue(this->m_description));
|
obj.insert("description", QJsonValue(this->m_description));
|
||||||
obj.insert("mode", QJsonValue(getModelModeAsString().left(1).toUpper()));
|
obj.insert("mode", QJsonValue(getModelModeAsString().left(1).toUpper()));
|
||||||
|
|
||||||
@@ -118,7 +118,7 @@ namespace BlackMisc
|
|||||||
case IndexDescription:
|
case IndexDescription:
|
||||||
return CVariant(this->m_description);
|
return CVariant(this->m_description);
|
||||||
case IndexName:
|
case IndexName:
|
||||||
return CVariant(this->m_modelName);
|
return CVariant(this->m_name);
|
||||||
case IndexFileName:
|
case IndexFileName:
|
||||||
return CVariant(this->m_fileName);
|
return CVariant(this->m_fileName);
|
||||||
case IndexAircraftIcaoCode:
|
case IndexAircraftIcaoCode:
|
||||||
@@ -159,7 +159,7 @@ namespace BlackMisc
|
|||||||
this->m_simulator.setPropertyByIndex(variant, index.copyFrontRemoved());
|
this->m_simulator.setPropertyByIndex(variant, index.copyFrontRemoved());
|
||||||
break;
|
break;
|
||||||
case IndexName:
|
case IndexName:
|
||||||
this->m_modelName = variant.toQString();
|
this->m_name = variant.toQString();
|
||||||
break;
|
break;
|
||||||
case IndexCallsign:
|
case IndexCallsign:
|
||||||
this->m_callsign.setPropertyByIndex(variant, index.copyFrontRemoved());
|
this->m_callsign.setPropertyByIndex(variant, index.copyFrontRemoved());
|
||||||
@@ -207,7 +207,7 @@ namespace BlackMisc
|
|||||||
case IndexSimulatorInfo:
|
case IndexSimulatorInfo:
|
||||||
return this->m_simulator.comparePropertyByIndex(compareValue.getSimulatorInfo(), index.copyFrontRemoved());
|
return this->m_simulator.comparePropertyByIndex(compareValue.getSimulatorInfo(), index.copyFrontRemoved());
|
||||||
case IndexName:
|
case IndexName:
|
||||||
return this->m_modelName.compare(compareValue.getName(), Qt::CaseInsensitive);
|
return this->m_name.compare(compareValue.getName(), Qt::CaseInsensitive);
|
||||||
case IndexCallsign:
|
case IndexCallsign:
|
||||||
break;
|
break;
|
||||||
case IndexFileName:
|
case IndexFileName:
|
||||||
@@ -369,7 +369,7 @@ namespace BlackMisc
|
|||||||
|
|
||||||
CAircraftModel CAircraftModel::fromDatabaseJson(const QJsonObject &json, const QString prefix)
|
CAircraftModel CAircraftModel::fromDatabaseJson(const QJsonObject &json, const QString prefix)
|
||||||
{
|
{
|
||||||
QString modelString(json.value(prefix + "simkey").toString());
|
QString modelString(json.value(prefix + "modelstring").toString());
|
||||||
QString modelDescription(json.value(prefix + "description").toString());
|
QString modelDescription(json.value(prefix + "description").toString());
|
||||||
QString modelName(json.value(prefix + "name").toString());
|
QString modelName(json.value(prefix + "name").toString());
|
||||||
QString modelMode(json.value(prefix + "mode").toString());
|
QString modelMode(json.value(prefix + "mode").toString());
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ namespace BlackMisc
|
|||||||
//! Callsign empty
|
//! Callsign empty
|
||||||
bool isCallsignEmpty() const { return this->m_callsign.isEmpty(); }
|
bool isCallsignEmpty() const { return this->m_callsign.isEmpty(); }
|
||||||
|
|
||||||
//! Model string, either queried or loaded from simulator model
|
//! Model key, either queried or loaded from simulator model
|
||||||
const QString &getModelString() const { return this->m_modelString; }
|
const QString &getModelString() const { return this->m_modelString; }
|
||||||
|
|
||||||
//! Model string
|
//! Model string
|
||||||
@@ -171,10 +171,10 @@ namespace BlackMisc
|
|||||||
void setDistributor(const CDistributor &distributor) { m_distributor = distributor; }
|
void setDistributor(const CDistributor &distributor) { m_distributor = distributor; }
|
||||||
|
|
||||||
//! Name
|
//! Name
|
||||||
const QString &getName() const { return this->m_modelName; }
|
const QString &getName() const { return this->m_name; }
|
||||||
|
|
||||||
//! Name
|
//! Name
|
||||||
void setName(const QString &name) { this->m_modelName = name.trimmed(); }
|
void setName(const QString &name) { this->m_name = name.trimmed(); }
|
||||||
|
|
||||||
//! Model type
|
//! Model type
|
||||||
ModelType getModelType() const { return m_modelType; }
|
ModelType getModelType() const { return m_modelType; }
|
||||||
@@ -264,8 +264,8 @@ namespace BlackMisc
|
|||||||
BlackMisc::Aviation::CLivery m_livery; //!< livery information
|
BlackMisc::Aviation::CLivery m_livery; //!< livery information
|
||||||
CSimulatorInfo m_simulator; //!< model for given simulator
|
CSimulatorInfo m_simulator; //!< model for given simulator
|
||||||
CDistributor m_distributor; //!< who designed or distributed the model
|
CDistributor m_distributor; //!< who designed or distributed the model
|
||||||
QString m_modelString; //!< Simulator model string
|
QString m_modelString; //!< Simulator model key, unique
|
||||||
QString m_modelName; //!< Model name
|
QString m_name; //!< Model name
|
||||||
QString m_description; //!< descriptive text
|
QString m_description; //!< descriptive text
|
||||||
QString m_fileName; //!< file name
|
QString m_fileName; //!< file name
|
||||||
ModelType m_modelType = TypeUnknown; //!< model string is coming representing ...?
|
ModelType m_modelType = TypeUnknown; //!< model string is coming representing ...?
|
||||||
@@ -284,7 +284,7 @@ BLACK_DECLARE_TUPLE_CONVERSION(
|
|||||||
attr(o.m_simulator),
|
attr(o.m_simulator),
|
||||||
attr(o.m_distributor),
|
attr(o.m_distributor),
|
||||||
attr(o.m_modelString, flags<CaseInsensitiveComparison>()),
|
attr(o.m_modelString, flags<CaseInsensitiveComparison>()),
|
||||||
attr(o.m_modelName),
|
attr(o.m_name),
|
||||||
attr(o.m_description, flags<DisabledForComparison>()),
|
attr(o.m_description, flags<DisabledForComparison>()),
|
||||||
attr(o.m_fileName, flags <DisabledForComparison> ()),
|
attr(o.m_fileName, flags <DisabledForComparison> ()),
|
||||||
attr(o.m_modelType),
|
attr(o.m_modelType),
|
||||||
|
|||||||
@@ -190,6 +190,7 @@ namespace BlackMisc
|
|||||||
CStatusMessage msgDb(CStatusMessage::SeverityError, subMsgs.join(", "));
|
CStatusMessage msgDb(CStatusMessage::SeverityError, subMsgs.join(", "));
|
||||||
|
|
||||||
CStatusMessage singleMsg(CStatusMessageList({msgModel, msgDb}).toSingleMessage());
|
CStatusMessage singleMsg(CStatusMessageList({msgModel, msgDb}).toSingleMessage());
|
||||||
|
if (!singleMsg.isWarningOrAbove()) { continue; }
|
||||||
if (model.hasModelString())
|
if (model.hasModelString())
|
||||||
{
|
{
|
||||||
singleMsg.prependMessage(model.getModelString() + ": ");
|
singleMsg.prependMessage(model.getModelString() + ": ");
|
||||||
|
|||||||
@@ -129,6 +129,13 @@ namespace BlackMisc
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString description(json.value(prefix + "description").toString());
|
QString description(json.value(prefix + "description").toString());
|
||||||
|
if (description.isEmpty()) {
|
||||||
|
// stub, only key, maybe also timestamps
|
||||||
|
CDistributor distributorStub;
|
||||||
|
distributorStub.setKeyAndTimestampFromDatabaseJson(json, prefix);
|
||||||
|
return distributorStub;
|
||||||
|
}
|
||||||
|
|
||||||
QString alias1(json.value(prefix + "alias1").toString());
|
QString alias1(json.value(prefix + "alias1").toString());
|
||||||
QString alias2(json.value(prefix + "alias2").toString());
|
QString alias2(json.value(prefix + "alias2").toString());
|
||||||
Q_ASSERT_X(!description.isEmpty(), Q_FUNC_INFO, "Missing description");
|
Q_ASSERT_X(!description.isEmpty(), Q_FUNC_INFO, "Missing description");
|
||||||
|
|||||||
Reference in New Issue
Block a user