mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-11 23:05:34 +08:00
refs #568, specialized lists (timestamp, DB objects, model list)
* remaned to latest/oldestObject * JSON functions with prefix * remove by keys * only add models with model string to QStringList
This commit is contained in:
@@ -46,6 +46,50 @@ namespace BlackMisc
|
||||
this->container().sort(BlackMisc::Predicates::MemberLess(&OBJ::getDbKey));
|
||||
}
|
||||
|
||||
template <class OBJ, class CONTAINER>
|
||||
QList<int> IDatastoreObjectListWithIntegerKey<OBJ, CONTAINER>::toDbKeyList() const
|
||||
{
|
||||
QList<int> keys;
|
||||
for (const OBJ &obj : ITimestampObjectList<OBJ, CONTAINER>::container())
|
||||
{
|
||||
if (!obj.hasValidDbKey()) { continue; }
|
||||
keys.append(obj.getDbKey());
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
template <class OBJ, class CONTAINER>
|
||||
int IDatastoreObjectListWithIntegerKey<OBJ, CONTAINER>::removeObjectsWithKeys(const QList<int> &keys)
|
||||
{
|
||||
if (keys.isEmpty()) { return 0; }
|
||||
if (this->container().isEmpty()) { return 0; }
|
||||
CONTAINER newValues;
|
||||
for (const OBJ &obj : ITimestampObjectList<OBJ, CONTAINER>::container())
|
||||
{
|
||||
if (keys.contains(obj.getDbKey())) { continue; }
|
||||
newValues.push_back(obj);
|
||||
}
|
||||
int delta = this->container().size() - newValues.size();
|
||||
*this = newValues;
|
||||
return delta;
|
||||
}
|
||||
|
||||
template <class OBJ, class CONTAINER>
|
||||
int IDatastoreObjectListWithStringKey<OBJ, CONTAINER>::removeObjectsWithKeys(const QStringList &keys)
|
||||
{
|
||||
if (keys.isEmpty()) { return 0; }
|
||||
if (this->container().isEmpty()) { return 0; }
|
||||
CONTAINER newValues;
|
||||
for (const OBJ &obj : ITimestampObjectList<OBJ, CONTAINER>::container())
|
||||
{
|
||||
if (keys.contains(obj.getDbKey(), Qt::CaseInsensitive)) { continue; }
|
||||
newValues.push_back(obj);
|
||||
}
|
||||
int delta = this->container().size() - newValues.size();
|
||||
*this = newValues;
|
||||
return delta;
|
||||
}
|
||||
|
||||
template <class OBJ, class CONTAINER>
|
||||
void IDatastoreObjectListWithStringKey<OBJ, CONTAINER>::sortByKey()
|
||||
{
|
||||
@@ -58,6 +102,7 @@ namespace BlackMisc
|
||||
QStringList keys;
|
||||
for (const OBJ &obj : ITimestampObjectList<OBJ, CONTAINER>::container())
|
||||
{
|
||||
if (!obj.hasValidDbKey()) { continue; }
|
||||
keys.append(obj.getDbKey());
|
||||
}
|
||||
return keys;
|
||||
@@ -74,6 +119,17 @@ namespace BlackMisc
|
||||
return container;
|
||||
}
|
||||
|
||||
template <class OBJ, class CONTAINER>
|
||||
CONTAINER IDatastoreObjectListWithIntegerKey<OBJ, CONTAINER>::fromDatabaseJson(const QJsonArray &array, const QString &prefix)
|
||||
{
|
||||
CONTAINER container;
|
||||
for (const QJsonValue &value : array)
|
||||
{
|
||||
container.push_back(OBJ::fromDatabaseJson(value.toObject(), prefix));
|
||||
}
|
||||
return container;
|
||||
}
|
||||
|
||||
template <class OBJ, class CONTAINER>
|
||||
CONTAINER IDatastoreObjectListWithStringKey<OBJ, CONTAINER>::fromDatabaseJson(const QJsonArray &array)
|
||||
{
|
||||
@@ -85,6 +141,17 @@ namespace BlackMisc
|
||||
return container;
|
||||
}
|
||||
|
||||
template <class OBJ, class CONTAINER>
|
||||
CONTAINER IDatastoreObjectListWithStringKey<OBJ, CONTAINER>::fromDatabaseJson(const QJsonArray &array, const QString &prefix)
|
||||
{
|
||||
CONTAINER container;
|
||||
for (const QJsonValue &value : array)
|
||||
{
|
||||
container.push_back(OBJ::fromDatabaseJson(value.toObject(), prefix));
|
||||
}
|
||||
return container;
|
||||
}
|
||||
|
||||
// see here for the reason of thess forward instantiations
|
||||
// http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html
|
||||
template class IDatastoreObjectListWithIntegerKey<BlackMisc::Aviation::CLivery, BlackMisc::Aviation::CLiveryList>;
|
||||
|
||||
Reference in New Issue
Block a user