mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 19:35:32 +08:00
refs #571, allow to select distributor by key or alias
* removed redundant getId function * functions for completer
This commit is contained in:
@@ -54,27 +54,29 @@ namespace BlackGui
|
||||
|
||||
void CDbDistributorSelectorComponent::setDistributor(const CDistributor &distributor)
|
||||
{
|
||||
this->ui->le_Distributor->setText(distributor.getId());
|
||||
ui->lbl_Description->setText(distributor.getDescription());
|
||||
QString key(distributor.getDbKey());
|
||||
if (key.isEmpty()) { return; }
|
||||
if (distributor != m_currentDistributor)
|
||||
{
|
||||
this->ui->le_Distributor->setText(key);
|
||||
m_currentDistributor = distributor;
|
||||
emit changedDistributor(distributor);
|
||||
}
|
||||
}
|
||||
|
||||
void CDbDistributorSelectorComponent::setDistributor(const QString &distributorKey)
|
||||
void CDbDistributorSelectorComponent::setDistributor(const QString &distributorKeyOrAlias)
|
||||
{
|
||||
QString key(distributorKey.toUpper().trimmed());
|
||||
CDistributor d(getDistributors().findByKey(key));
|
||||
ui->lbl_Description->setText("");
|
||||
QString keyOrAlias(distributorKeyOrAlias.toUpper().trimmed());
|
||||
if (this->m_currentDistributor.matchesKeyOrAlias(keyOrAlias)) { return; }
|
||||
CDistributor d(getDistributors().findByKeyOrAlias(keyOrAlias));
|
||||
if (d.hasCompleteData())
|
||||
{
|
||||
this->setDistributor(d);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->ui->le_Distributor->setText(key);
|
||||
this->ui->lbl_Description->setText("");
|
||||
this->ui->le_Distributor->setText(keyOrAlias);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +155,9 @@ namespace BlackGui
|
||||
{
|
||||
if (count > 0)
|
||||
{
|
||||
QCompleter *c = new QCompleter(this->getDistributors().toDbKeyList(), this);
|
||||
QStringList keysAndAliases(this->getDistributors().getDbKeysAndAliases());
|
||||
keysAndAliases.sort(Qt::CaseInsensitive);
|
||||
QCompleter *c = new QCompleter(keysAndAliases, this);
|
||||
c->setCaseSensitivity(Qt::CaseInsensitive);
|
||||
c->setCompletionMode(QCompleter::PopupCompletion);
|
||||
c->setMaxVisibleItems(10);
|
||||
@@ -175,13 +179,14 @@ namespace BlackGui
|
||||
{
|
||||
if (!hasProvider()) { return; }
|
||||
QString key(this->ui->le_Distributor->text().trimmed().toUpper());
|
||||
CDistributor d(this->getDistributors().findByKey(key));
|
||||
if (key.isEmpty()) { return; }
|
||||
CDistributor d(this->getDistributors().findByKeyOrAlias(key));
|
||||
this->setDistributor(d);
|
||||
}
|
||||
|
||||
void CDbDistributorSelectorComponent::ps_completerActivated(const QString &distributorKey)
|
||||
void CDbDistributorSelectorComponent::ps_completerActivated(const QString &distributorKeyOrAlias)
|
||||
{
|
||||
this->setDistributor(distributorKey);
|
||||
this->setDistributor(distributorKeyOrAlias);
|
||||
}
|
||||
|
||||
} // ns
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace BlackGui
|
||||
void setDistributor(const BlackMisc::Simulation::CDistributor &distributor);
|
||||
|
||||
//! Current Distributor
|
||||
void setDistributor(const QString &distributorKey);
|
||||
void setDistributor(const QString &distributorKeyOrAlias);
|
||||
|
||||
//! Distributor
|
||||
BlackMisc::Simulation::CDistributor getDistributor() const;
|
||||
@@ -92,7 +92,7 @@ namespace BlackGui
|
||||
void ps_dataChanged();
|
||||
|
||||
//! Data have been changed
|
||||
void ps_completerActivated(const QString &distributorKey);
|
||||
void ps_completerActivated(const QString &distributorKeyOrAlias);
|
||||
|
||||
private:
|
||||
QScopedPointer<Ui::CDbDistributorSelectorComponent> ui;
|
||||
|
||||
@@ -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