mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 07:35:48 +08:00
refs #452, adjusted aircraft/aviation classes
* support for loading from datastore * improved timestamp handling * new color and country classes * new attributes * updates for missing parts in CUser
This commit is contained in:
committed by
Mathew Sutcliffe
parent
c5f7179588
commit
ae24700299
@@ -9,6 +9,8 @@
|
||||
|
||||
#include "blackmisc/datastoreutility.h"
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
@@ -19,13 +21,65 @@ namespace BlackMisc
|
||||
|
||||
int CDatastoreUtility::extractIntegerKey(const QString &stringWithKey)
|
||||
{
|
||||
int i1 = stringWithKey.lastIndexOf('(');
|
||||
if (i1 < 0) { return -1; }
|
||||
int i2 = stringWithKey.lastIndexOf(')');
|
||||
if (i2 <= i1 + 1) { return -1;}
|
||||
QString n(stringWithKey.mid(i1 + 1, i2 - i1 - 1));
|
||||
QString ks(stringWithKey.trimmed());
|
||||
if (ks.isEmpty()) { return -1; }
|
||||
bool ok = false;
|
||||
int key = n.toInt(&ok);
|
||||
int key = ks.toInt(&ok);
|
||||
if (ok) { return key; } // only a number
|
||||
|
||||
// key in string with ()
|
||||
int i1 = ks.lastIndexOf('(');
|
||||
if (i1 < 0) { return -1; }
|
||||
int i2 = ks.lastIndexOf(')');
|
||||
if (i2 <= i1 + 1) { return -1;}
|
||||
QString n(ks.mid(i1 + 1, i2 - i1 - 1));
|
||||
ok = false;
|
||||
key = n.toInt(&ok);
|
||||
return ok ? key : -1;
|
||||
}
|
||||
|
||||
QDateTime CDatastoreUtility::parseTimestamp(const QString ×tamp)
|
||||
{
|
||||
Q_ASSERT_X(!timestamp.isEmpty(), Q_FUNC_INFO, "Missing timestamp");
|
||||
if (!timestamp.isEmpty())
|
||||
{
|
||||
QString ts(timestamp.trimmed().remove(' ').remove('-').remove(':')); // normalize
|
||||
QDateTime dt = QDateTime::fromString(ts, "yyyyMMddHHmmss");
|
||||
return dt;
|
||||
}
|
||||
else
|
||||
{
|
||||
return QDateTime();
|
||||
}
|
||||
}
|
||||
|
||||
bool CDatastoreUtility::parseSwiftWriteResponse(const QString &jsonResponse, CStatusMessageList &messages, CVariant &key)
|
||||
{
|
||||
if (jsonResponse.isEmpty()) { return ""; }
|
||||
QJsonDocument jsonDoc(QJsonDocument::fromJson(jsonResponse.toUtf8()));
|
||||
if (!jsonDoc.isObject()) { return ""; }
|
||||
QJsonObject json(jsonDoc.object());
|
||||
Q_ASSERT_X(!json.value("id").isNull(), Q_FUNC_INFO, "malformed response");
|
||||
if (json.value("id").isNull()) { return false; }
|
||||
QString id(json.value("id").toString().trimmed());
|
||||
QJsonArray msgObject(json.value("messages").toArray());
|
||||
messages.push_back(CStatusMessageList::fromDatabaseJson(msgObject));
|
||||
bool success = false;
|
||||
|
||||
int intKey;
|
||||
bool isInt;
|
||||
intKey = id.toInt(&isInt);
|
||||
if (isInt)
|
||||
{
|
||||
key.setValue(intKey);
|
||||
success = (intKey >= 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
key.setValue(id);
|
||||
success = !id.isEmpty();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user