mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-14 00:25:35 +08:00
refs #571, allow to select distributor by key or alias
* removed redundant getId function * functions for completer
This commit is contained in:
@@ -16,9 +16,9 @@ namespace BlackMisc
|
||||
{
|
||||
CDistributor::CDistributor() { }
|
||||
|
||||
CDistributor::CDistributor(const QString &id)
|
||||
CDistributor::CDistributor(const QString &key)
|
||||
{
|
||||
this->setDbKey(id);
|
||||
this->setDbKey(key);
|
||||
}
|
||||
|
||||
CDistributor::CDistributor(const QString &id, const QString &description, const QString &alias1, const QString &alias2) :
|
||||
@@ -27,11 +27,11 @@ namespace BlackMisc
|
||||
this->setDbKey(id);
|
||||
}
|
||||
|
||||
bool CDistributor::matchesIdOrAlias(const QString &idOrAlias) const
|
||||
bool CDistributor::matchesKeyOrAlias(const QString &keyOrAlias) const
|
||||
{
|
||||
QString s(idOrAlias.trimmed().toUpper());
|
||||
QString s(keyOrAlias.trimmed().toUpper());
|
||||
if (s.isEmpty()) { return false; }
|
||||
return (getId() == s || getAlias1() == s || getAlias2() == s);
|
||||
return (getDbKey() == s || getAlias1() == s || getAlias2() == s);
|
||||
}
|
||||
|
||||
CVariant CDistributor::propertyByIndex(const CPropertyIndex &index) const
|
||||
|
||||
@@ -40,14 +40,11 @@ namespace BlackMisc
|
||||
CDistributor();
|
||||
|
||||
//! Constructor
|
||||
CDistributor(const QString &id);
|
||||
CDistributor(const QString &key);
|
||||
|
||||
//! Constructor
|
||||
CDistributor(const QString &id, const QString &description, const QString &alias1, const QString &alias2);
|
||||
|
||||
//! Id
|
||||
const QString &getId() const { return this->getDbKey(); }
|
||||
|
||||
//! Get description
|
||||
const QString &getDescription() const { return this->m_description;}
|
||||
|
||||
@@ -76,7 +73,7 @@ namespace BlackMisc
|
||||
bool hasAlias2() const { return !this->m_alias2.isEmpty(); }
|
||||
|
||||
//! Matches id or alias
|
||||
bool matchesIdOrAlias(const QString &idOrAlias) const;
|
||||
bool matchesKeyOrAlias(const QString &keyOrAlias) const;
|
||||
|
||||
//! \copydoc CValueObject::propertyByIndex
|
||||
CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
|
||||
|
||||
@@ -20,12 +20,12 @@ namespace BlackMisc
|
||||
CSequence<CDistributor>(other)
|
||||
{ }
|
||||
|
||||
CDistributor CDistributorList::findByIdOrAlias(const QString &idOrAlias)
|
||||
CDistributor CDistributorList::findByKeyOrAlias(const QString &keyOrAlias)
|
||||
{
|
||||
if (idOrAlias.isEmpty()) { return CDistributor(); }
|
||||
if (keyOrAlias.isEmpty()) { return CDistributor(); }
|
||||
for (const CDistributor &distributor : (*this))
|
||||
{
|
||||
if (distributor.matchesIdOrAlias(idOrAlias)) { return distributor; }
|
||||
if (distributor.matchesKeyOrAlias(keyOrAlias)) { return distributor; }
|
||||
}
|
||||
return CDistributor();
|
||||
}
|
||||
@@ -39,10 +39,30 @@ namespace BlackMisc
|
||||
if (d.hasCompleteData()) { return d; }
|
||||
|
||||
// more lenient search
|
||||
return this->findByIdOrAlias(k);
|
||||
return this->findByKeyOrAlias(k);
|
||||
}
|
||||
return CDistributor();
|
||||
}
|
||||
|
||||
QStringList CDistributorList::getDbKeysAndAliases() const
|
||||
{
|
||||
if (this->isEmpty()) { return QStringList(); }
|
||||
QStringList sl;
|
||||
for (const CDistributor &d : *this)
|
||||
{
|
||||
if (!d.hasValidDbKey()) { continue; }
|
||||
sl.append(d.getDbKey());
|
||||
if (d.hasAlias1())
|
||||
{
|
||||
sl.append(d.getAlias1());
|
||||
}
|
||||
if (d.hasAlias2())
|
||||
{
|
||||
sl.append(d.getAlias2());
|
||||
}
|
||||
}
|
||||
return sl;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -41,10 +41,13 @@ namespace BlackMisc
|
||||
CDistributorList(const CSequence<CDistributor> &other);
|
||||
|
||||
//! Find by id or alias
|
||||
CDistributor findByIdOrAlias(const QString &name);
|
||||
CDistributor findByKeyOrAlias(const QString &keyOrAlias);
|
||||
|
||||
//! Best match by given pattern
|
||||
CDistributor smartDistributorSelector(const CDistributor &distributorPattern);
|
||||
|
||||
//! All DB keys and aliases
|
||||
QStringList getDbKeysAndAliases() const;
|
||||
};
|
||||
} //namespace
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user