mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-27 02:55:44 +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
|
||||||
@@ -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