mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 09:15:34 +08:00
Distributor value object improvements
This commit is contained in:
committed by
Mat Sutcliffe
parent
09d86aceb5
commit
12403700ea
@@ -10,6 +10,7 @@
|
|||||||
#include "blackmisc/logcategorylist.h"
|
#include "blackmisc/logcategorylist.h"
|
||||||
#include "blackmisc/simulation/distributor.h"
|
#include "blackmisc/simulation/distributor.h"
|
||||||
#include "blackmisc/statusmessage.h"
|
#include "blackmisc/statusmessage.h"
|
||||||
|
#include "blackmisc/stringutils.h"
|
||||||
|
|
||||||
#include <QJsonValue>
|
#include <QJsonValue>
|
||||||
#include <Qt>
|
#include <Qt>
|
||||||
@@ -24,13 +25,13 @@ namespace BlackMisc
|
|||||||
|
|
||||||
CDistributor::CDistributor(const QString &key)
|
CDistributor::CDistributor(const QString &key)
|
||||||
{
|
{
|
||||||
this->setDbKey(key);
|
this->setDbKey(unifyKeyOrAlias(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
CDistributor::CDistributor(const QString &id, const QString &description, const QString &alias1, const QString &alias2, const CSimulatorInfo &simulator) :
|
CDistributor::CDistributor(const QString &id, const QString &description, const QString &alias1, const QString &alias2, const CSimulatorInfo &simulator) :
|
||||||
m_description(description), m_alias1(alias1.trimmed().toUpper()), m_alias2(alias2.trimmed().toUpper()), m_simulator(simulator)
|
m_description(description), m_alias1(alias1), m_alias2(alias2), m_simulator(simulator)
|
||||||
{
|
{
|
||||||
this->setDbKey(id);
|
this->setDbKey(unifyKeyOrAlias(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString CDistributor::getIdAndDescription() const
|
const QString CDistributor::getIdAndDescription() const
|
||||||
@@ -53,7 +54,7 @@ namespace BlackMisc
|
|||||||
bool CDistributor::matchesKeyOrAlias(const CDistributor &distributor) const
|
bool CDistributor::matchesKeyOrAlias(const CDistributor &distributor) const
|
||||||
{
|
{
|
||||||
if (distributor.hasValidDbKey() && this->matchesKeyOrAlias(distributor.getDbKey())) { return true; }
|
if (distributor.hasValidDbKey() && this->matchesKeyOrAlias(distributor.getDbKey())) { return true; }
|
||||||
if (distributor.hasAlias1() && this->matchesKeyOrAlias(distributor.getAlias1())) { return true; }
|
if (distributor.hasAlias1() && this->matchesKeyOrAlias(distributor.getAlias1())) { return true; }
|
||||||
return (distributor.hasAlias2() && this->matchesKeyOrAlias(distributor.getAlias2()));
|
return (distributor.hasAlias2() && this->matchesKeyOrAlias(distributor.getAlias2()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,7 +93,7 @@ namespace BlackMisc
|
|||||||
case IndexAlias1: m_alias1 = variant.value<QString>(); break;
|
case IndexAlias1: m_alias1 = variant.value<QString>(); break;
|
||||||
case IndexAlias2: m_alias2 = variant.value<QString>(); break;
|
case IndexAlias2: m_alias2 = variant.value<QString>(); break;
|
||||||
case IndexDescription: m_description = variant.value<QString>(); break;
|
case IndexDescription: m_description = variant.value<QString>(); break;
|
||||||
case IndexSimulator: m_simulator.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
|
case IndexSimulator: m_simulator.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
|
||||||
default: CValueObject::setPropertyByIndex(index, variant); break;
|
default: CValueObject::setPropertyByIndex(index, variant); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,7 +109,7 @@ namespace BlackMisc
|
|||||||
case IndexAlias1: return m_alias1.compare(compareValue.m_alias1, Qt::CaseInsensitive);
|
case IndexAlias1: return m_alias1.compare(compareValue.m_alias1, Qt::CaseInsensitive);
|
||||||
case IndexAlias2: return m_alias2.compare(compareValue.m_alias2, Qt::CaseInsensitive);
|
case IndexAlias2: return m_alias2.compare(compareValue.m_alias2, Qt::CaseInsensitive);
|
||||||
case IndexDescription: return m_description.compare(compareValue.getDescription(), Qt::CaseInsensitive);
|
case IndexDescription: return m_description.compare(compareValue.getDescription(), Qt::CaseInsensitive);
|
||||||
case IndexSimulator: return m_simulator.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.m_simulator);
|
case IndexSimulator: return m_simulator.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.m_simulator);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -118,7 +119,7 @@ namespace BlackMisc
|
|||||||
|
|
||||||
QString CDistributor::convertToQString(bool i18n) const
|
QString CDistributor::convertToQString(bool i18n) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(i18n);
|
Q_UNUSED(i18n)
|
||||||
QString s = QStringLiteral("Id: '%1'").arg(m_dbKey);
|
QString s = QStringLiteral("Id: '%1'").arg(m_dbKey);
|
||||||
if (this->hasAlias1()) { s.append(" ").append(m_alias1); }
|
if (this->hasAlias1()) { s.append(" ").append(m_alias1); }
|
||||||
if (this->hasAlias2()) { s.append(" ").append(m_alias2); }
|
if (this->hasAlias2()) { s.append(" ").append(m_alias2); }
|
||||||
@@ -237,5 +238,10 @@ namespace BlackMisc
|
|||||||
return k;
|
return k;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString CDistributor::unifyKeyOrAlias(const QString &value)
|
||||||
|
{
|
||||||
|
return removeChars(value.trimmed().toUpper(), [](QChar c) { return !c.isLetterOrNumber(); });
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -75,10 +75,10 @@ namespace BlackMisc
|
|||||||
const QString &getAlias2() const { return m_alias2;}
|
const QString &getAlias2() const { return m_alias2;}
|
||||||
|
|
||||||
//! Set alias1
|
//! Set alias1
|
||||||
void setAlias1(const QString &alias) { m_alias1 = alias.trimmed().toUpper(); }
|
void setAlias1(const QString &alias) { m_alias1 = alias; }
|
||||||
|
|
||||||
//! Set alias2
|
//! Set alias2
|
||||||
void setAlias2(const QString &alias) { m_alias2 = alias.trimmed().toUpper(); }
|
void setAlias2(const QString &alias) { m_alias2 = alias; }
|
||||||
|
|
||||||
//! Alias 1?
|
//! Alias 1?
|
||||||
bool hasAlias1() const { return !m_alias1.isEmpty(); }
|
bool hasAlias1() const { return !m_alias1.isEmpty(); }
|
||||||
@@ -107,7 +107,7 @@ namespace BlackMisc
|
|||||||
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
|
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
|
||||||
void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const CVariant &variant);
|
void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const CVariant &variant);
|
||||||
|
|
||||||
//! Compare for index
|
//! \copydoc Mixin::Index::comparePropertyByIndex
|
||||||
int comparePropertyByIndex(const CPropertyIndex &index, const CDistributor &compareValue) const;
|
int comparePropertyByIndex(const CPropertyIndex &index, const CDistributor &compareValue) const;
|
||||||
|
|
||||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||||
@@ -143,6 +143,9 @@ namespace BlackMisc
|
|||||||
QString m_alias2; //!< alias name
|
QString m_alias2; //!< alias name
|
||||||
BlackMisc::Simulation::CSimulatorInfo m_simulator; //!< simulator
|
BlackMisc::Simulation::CSimulatorInfo m_simulator; //!< simulator
|
||||||
|
|
||||||
|
//! "Clean up" the keys, like X-CSL => XCSL
|
||||||
|
static QString unifyKeyOrAlias(const QString &value);
|
||||||
|
|
||||||
BLACK_METACLASS(
|
BLACK_METACLASS(
|
||||||
CDistributor,
|
CDistributor,
|
||||||
BLACK_METAMEMBER(dbKey, 0, CaseInsensitiveComparison),
|
BLACK_METAMEMBER(dbKey, 0, CaseInsensitiveComparison),
|
||||||
|
|||||||
Reference in New Issue
Block a user