Ref T472, style

This commit is contained in:
Klaus Basan
2019-01-31 22:29:56 +01:00
committed by Mat Sutcliffe
parent d713e8a264
commit bada0c2f59
5 changed files with 31 additions and 43 deletions

View File

@@ -33,6 +33,7 @@
#include <QNetworkReply> #include <QNetworkReply>
#include <QReadLocker> #include <QReadLocker>
#include <QUrl> #include <QUrl>
#include <QStringBuilder>
#include <QWriteLocker> #include <QWriteLocker>
using namespace BlackMisc; using namespace BlackMisc;
@@ -47,7 +48,7 @@ namespace BlackCore
namespace Db namespace Db
{ {
CDatabaseReader::CDatabaseReader(QObject *owner, const CDatabaseReaderConfigList &config, const QString &name) : CDatabaseReader::CDatabaseReader(QObject *owner, const CDatabaseReaderConfigList &config, const QString &name) :
BlackCore::CThreadedReader(owner, name), m_config(config) CThreadedReader(owner, name), m_config(config)
{ } { }
void CDatabaseReader::readInBackgroundThread(CEntityFlags::Entity entities, const QDateTime &newerThan) void CDatabaseReader::readInBackgroundThread(CEntityFlags::Entity entities, const QDateTime &newerThan)
@@ -724,7 +725,7 @@ namespace BlackCore
QString CDatabaseReader::queryLatestTimestamp(const QDateTime &ts) QString CDatabaseReader::queryLatestTimestamp(const QDateTime &ts)
{ {
if (!ts.isValid()) return {}; if (!ts.isValid()) return {};
const QString q = parameterLatestTimestamp() + "=" + dateTimeToDbLatestTs(ts); const QString q = parameterLatestTimestamp() % u"=" % dateTimeToDbLatestTs(ts);
return q; return q;
} }

View File

@@ -131,10 +131,10 @@ namespace BlackMisc
const ColumnIndex i = index.frontCasted<ColumnIndex>(); const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i) switch (i)
{ {
case IndexName: return m_name.compare(compareValue.getName(), Qt::CaseInsensitive); case IndexName: return m_name.compare(compareValue.getName(), Qt::CaseInsensitive);
case IndexPath: return m_description.compare(compareValue.getPath(), Qt::CaseInsensitive); case IndexPath: return m_description.compare(compareValue.getPath(), Qt::CaseInsensitive);
case IndexDescription: return m_path.compare(compareValue.getDescription(), Qt::CaseInsensitive); case IndexDescription: return m_path.compare(compareValue.getDescription(), Qt::CaseInsensitive);
case IndexAssignable: return Compare::compare(this->isAssignable(), compareValue.isAssignable()); case IndexAssignable: return Compare::compare(this->isAssignable(), compareValue.isAssignable());
default: return CValueObject::comparePropertyByIndex(index, *this); default: return CValueObject::comparePropertyByIndex(index, *this);
} }
Q_ASSERT_X(false, Q_FUNC_INFO, "No comparison"); Q_ASSERT_X(false, Q_FUNC_INFO, "No comparison");

View File

@@ -13,8 +13,8 @@
#define BLACKMISC_AVIATION_AIRCRAFTCATEGORYLIST_H #define BLACKMISC_AVIATION_AIRCRAFTCATEGORYLIST_H
#include "aircraftcategory.h" #include "aircraftcategory.h"
#include "blackmisc/collection.h"
#include "blackmisc/db/datastoreobjectlist.h" #include "blackmisc/db/datastoreobjectlist.h"
#include "blackmisc/collection.h"
#include "blackmisc/sequence.h" #include "blackmisc/sequence.h"
#include "blackmisc/variant.h" #include "blackmisc/variant.h"
#include "blackmisc/blackmiscexport.h" #include "blackmisc/blackmiscexport.h"

View File

@@ -9,7 +9,7 @@
#include "dbinfo.h" #include "dbinfo.h"
#include "blackmisc/comparefunctions.h" #include "blackmisc/comparefunctions.h"
#include <QPainter> #include <QStringBuilder>
using namespace BlackMisc::Network; using namespace BlackMisc::Network;
@@ -22,17 +22,17 @@ namespace BlackMisc
m_tableName(tableName.trimmed().toLower()), m_entries(entries) m_tableName(tableName.trimmed().toLower()), m_entries(entries)
{ {
this->setEntity(this->getEntity()); this->setEntity(this->getEntity());
Q_ASSERT_X(tableName.isEmpty() || this->m_entity != CEntityFlags::NoEntity, Q_FUNC_INFO, "Wrong entity"); Q_ASSERT_X(tableName.isEmpty() || m_entity != CEntityFlags::NoEntity, Q_FUNC_INFO, "Wrong entity");
} }
bool CDbInfo::isValid() const bool CDbInfo::isValid() const
{ {
return this->m_entity != CEntityFlags::NoEntity && !this->m_tableName.isEmpty(); return m_entity != CEntityFlags::NoEntity && !m_tableName.isEmpty();
} }
CEntityFlags::Entity CDbInfo::getEntity() const CEntityFlags::Entity CDbInfo::getEntity() const
{ {
if (this->m_entity != CEntityFlags::NoEntity) { return this->m_entity; } if (m_entity != CEntityFlags::NoEntity) { return m_entity; }
const QString tn(this->getTableName()); const QString tn(this->getTableName());
return CEntityFlags::singleEntityByName(tn); return CEntityFlags::singleEntityByName(tn);
} }
@@ -51,7 +51,7 @@ namespace BlackMisc
void CDbInfo::setEntity(CEntityFlags::Entity entity) void CDbInfo::setEntity(CEntityFlags::Entity entity)
{ {
this->m_entity = entity; m_entity = entity;
} }
bool CDbInfo::matchesEntity(CEntityFlags::Entity entity) const bool CDbInfo::matchesEntity(CEntityFlags::Entity entity) const
@@ -62,27 +62,24 @@ namespace BlackMisc
void CDbInfo::setTableName(const QString &tableName) void CDbInfo::setTableName(const QString &tableName)
{ {
m_tableName = tableName.trimmed().toLower(); m_tableName = tableName.trimmed().toLower();
this->m_entity = this->getEntity(); m_entity = this->getEntity();
} }
QString CDbInfo::convertToQString(bool i18n) const QString CDbInfo::convertToQString(bool i18n) const
{ {
Q_UNUSED(i18n); Q_UNUSED(i18n);
return QStringLiteral("Table %1 with entries %1").arg(this->m_tableName).arg(this->m_entries); return QStringLiteral("Table %1 with entries %1").arg(m_tableName).arg(m_entries);
} }
CVariant CDbInfo::propertyByIndex(const BlackMisc::CPropertyIndex &index) const CVariant CDbInfo::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
{ {
if (index.isMyself()) { return CVariant::from(*this); } if (index.isMyself()) { return CVariant::from(*this); }
ColumnIndex i = index.frontCasted<ColumnIndex>(); const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i) switch (i)
{ {
case IndexTableName: case IndexTableName: return CVariant::fromValue(m_tableName);
return CVariant::fromValue(m_tableName); case IndexEntries: return CVariant::fromValue(m_entries);
case IndexEntries: case IndexEntity: return CVariant::fromValue(m_entity);
return CVariant::fromValue(m_entries);
case IndexEntity:
return CVariant::fromValue(m_entity);
default: default:
return (IDatastoreObjectWithIntegerKey::canHandleIndex(index)) ? return (IDatastoreObjectWithIntegerKey::canHandleIndex(index)) ?
IDatastoreObjectWithIntegerKey::propertyByIndex(index) : IDatastoreObjectWithIntegerKey::propertyByIndex(index) :
@@ -93,18 +90,12 @@ namespace BlackMisc
void CDbInfo::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant) void CDbInfo::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
{ {
if (index.isMyself()) { (*this) = variant.to<CDbInfo>(); return; } if (index.isMyself()) { (*this) = variant.to<CDbInfo>(); return; }
ColumnIndex i = index.frontCasted<ColumnIndex>(); const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i) switch (i)
{ {
case IndexTableName: case IndexTableName: this->setTableName(variant.toQString()); break;
this->setTableName(variant.toQString()); case IndexEntries: this->setTableName(variant.toQString()); break;
break; case IndexEntity: this->setEntity(static_cast<CEntityFlags::Entity>(variant.toInt())); break;
case IndexEntries:
this->setTableName(variant.toQString());
break;
case IndexEntity:
this->setEntity(static_cast<CEntityFlags::Entity>(variant.toInt()));
break;
default: default:
if (IDatastoreObjectWithIntegerKey::canHandleIndex(index)) if (IDatastoreObjectWithIntegerKey::canHandleIndex(index))
{ {
@@ -122,15 +113,12 @@ namespace BlackMisc
{ {
if (index.isMyself()) { return getTableName().compare(compareValue.getTableName(), Qt::CaseInsensitive); } if (index.isMyself()) { return getTableName().compare(compareValue.getTableName(), Qt::CaseInsensitive); }
if (IDatastoreObjectWithIntegerKey::canHandleIndex(index)) { return IDatastoreObjectWithIntegerKey::comparePropertyByIndex(index, compareValue);} if (IDatastoreObjectWithIntegerKey::canHandleIndex(index)) { return IDatastoreObjectWithIntegerKey::comparePropertyByIndex(index, compareValue);}
ColumnIndex i = index.frontCasted<ColumnIndex>(); const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i) switch (i)
{ {
case IndexTableName: case IndexTableName: return this->getTableName().compare(compareValue.getTableName(), Qt::CaseInsensitive);
return getTableName().compare(compareValue.getTableName(), Qt::CaseInsensitive); case IndexEntries: return Compare::compare(this->getEntries(), compareValue.getEntries());
case IndexEntries: case IndexEntity: return Compare::compare(this->getEntity(), compareValue.getEntity());
return Compare::compare(this->getEntries(), compareValue.getEntries());
case IndexEntity:
return Compare::compare(this->getEntity(), compareValue.getEntity());
default: default:
Q_ASSERT_X(false, Q_FUNC_INFO, "No comparison possible"); Q_ASSERT_X(false, Q_FUNC_INFO, "No comparison possible");
} }
@@ -144,9 +132,9 @@ namespace BlackMisc
// when using relationship, this can be null // when using relationship, this can be null
return CDbInfo(); return CDbInfo();
} }
const int id(json.value(prefix + "id").toInt()); const int id(json.value(prefix % u"id").toInt());
const int entries(json.value(prefix + "entries").toInt()); const int entries(json.value(prefix % u"entries").toInt());
const QString tableName(json.value(prefix + "tablename").toString()); const QString tableName(json.value(prefix % u"tablename").toString());
CDbInfo dbInfo(id, tableName, entries); CDbInfo dbInfo(id, tableName, entries);
dbInfo.setKeyVersionTimestampFromDatabaseJson(json, prefix); dbInfo.setKeyVersionTimestampFromDatabaseJson(json, prefix);
return dbInfo; return dbInfo;

View File

@@ -16,7 +16,6 @@
#include "blackmisc/network/entityflags.h" #include "blackmisc/network/entityflags.h"
#include "blackmisc/valueobject.h" #include "blackmisc/valueobject.h"
#include "blackmisc/blackmiscexport.h" #include "blackmisc/blackmiscexport.h"
#include <QColor>
namespace BlackMisc namespace BlackMisc
{ {
@@ -33,7 +32,7 @@ namespace BlackMisc
//! Properties by index //! Properties by index
enum ColumnIndex enum ColumnIndex
{ {
IndexTableName = BlackMisc::CPropertyIndex::GlobalIndexCDbInfo, IndexTableName = CPropertyIndex::GlobalIndexCDbInfo,
IndexEntries, IndexEntries,
IndexEntity IndexEntity
}; };
@@ -107,7 +106,7 @@ namespace BlackMisc
private: private:
QString m_tableName; //!< table name QString m_tableName; //!< table name
int m_entries; //!< number of entries int m_entries; //!< number of entries
BlackMisc::Network::CEntityFlags::Entity m_entity = BlackMisc::Network::CEntityFlags::NoEntity; //!< lazy initialized entity Network::CEntityFlags::Entity m_entity = Network::CEntityFlags::NoEntity; //!< lazy initialized entity
BLACK_METACLASS( BLACK_METACLASS(
CDbInfo, CDbInfo,