mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-05 01:35:45 +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)
|
void CDbDistributorSelectorComponent::setDistributor(const CDistributor &distributor)
|
||||||
{
|
{
|
||||||
this->ui->le_Distributor->setText(distributor.getId());
|
QString key(distributor.getDbKey());
|
||||||
ui->lbl_Description->setText(distributor.getDescription());
|
if (key.isEmpty()) { return; }
|
||||||
if (distributor != m_currentDistributor)
|
if (distributor != m_currentDistributor)
|
||||||
{
|
{
|
||||||
|
this->ui->le_Distributor->setText(key);
|
||||||
m_currentDistributor = distributor;
|
m_currentDistributor = distributor;
|
||||||
emit changedDistributor(distributor);
|
emit changedDistributor(distributor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDbDistributorSelectorComponent::setDistributor(const QString &distributorKey)
|
void CDbDistributorSelectorComponent::setDistributor(const QString &distributorKeyOrAlias)
|
||||||
{
|
{
|
||||||
QString key(distributorKey.toUpper().trimmed());
|
QString keyOrAlias(distributorKeyOrAlias.toUpper().trimmed());
|
||||||
CDistributor d(getDistributors().findByKey(key));
|
if (this->m_currentDistributor.matchesKeyOrAlias(keyOrAlias)) { return; }
|
||||||
ui->lbl_Description->setText("");
|
CDistributor d(getDistributors().findByKeyOrAlias(keyOrAlias));
|
||||||
if (d.hasCompleteData())
|
if (d.hasCompleteData())
|
||||||
{
|
{
|
||||||
this->setDistributor(d);
|
this->setDistributor(d);
|
||||||
}
|
}
|
||||||
else
|
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)
|
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->setCaseSensitivity(Qt::CaseInsensitive);
|
||||||
c->setCompletionMode(QCompleter::PopupCompletion);
|
c->setCompletionMode(QCompleter::PopupCompletion);
|
||||||
c->setMaxVisibleItems(10);
|
c->setMaxVisibleItems(10);
|
||||||
@@ -175,13 +179,14 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
if (!hasProvider()) { return; }
|
if (!hasProvider()) { return; }
|
||||||
QString key(this->ui->le_Distributor->text().trimmed().toUpper());
|
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);
|
this->setDistributor(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDbDistributorSelectorComponent::ps_completerActivated(const QString &distributorKey)
|
void CDbDistributorSelectorComponent::ps_completerActivated(const QString &distributorKeyOrAlias)
|
||||||
{
|
{
|
||||||
this->setDistributor(distributorKey);
|
this->setDistributor(distributorKeyOrAlias);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ namespace BlackGui
|
|||||||
void setDistributor(const BlackMisc::Simulation::CDistributor &distributor);
|
void setDistributor(const BlackMisc::Simulation::CDistributor &distributor);
|
||||||
|
|
||||||
//! Current Distributor
|
//! Current Distributor
|
||||||
void setDistributor(const QString &distributorKey);
|
void setDistributor(const QString &distributorKeyOrAlias);
|
||||||
|
|
||||||
//! Distributor
|
//! Distributor
|
||||||
BlackMisc::Simulation::CDistributor getDistributor() const;
|
BlackMisc::Simulation::CDistributor getDistributor() const;
|
||||||
@@ -92,7 +92,7 @@ namespace BlackGui
|
|||||||
void ps_dataChanged();
|
void ps_dataChanged();
|
||||||
|
|
||||||
//! Data have been changed
|
//! Data have been changed
|
||||||
void ps_completerActivated(const QString &distributorKey);
|
void ps_completerActivated(const QString &distributorKeyOrAlias);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QScopedPointer<Ui::CDbDistributorSelectorComponent> ui;
|
QScopedPointer<Ui::CDbDistributorSelectorComponent> ui;
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
CDistributor::CDistributor() { }
|
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) :
|
CDistributor::CDistributor(const QString &id, const QString &description, const QString &alias1, const QString &alias2) :
|
||||||
@@ -27,11 +27,11 @@ namespace BlackMisc
|
|||||||
this->setDbKey(id);
|
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; }
|
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
|
CVariant CDistributor::propertyByIndex(const CPropertyIndex &index) const
|
||||||
|
|||||||
@@ -40,14 +40,11 @@ namespace BlackMisc
|
|||||||
CDistributor();
|
CDistributor();
|
||||||
|
|
||||||
//! Constructor
|
//! Constructor
|
||||||
CDistributor(const QString &id);
|
CDistributor(const QString &key);
|
||||||
|
|
||||||
//! Constructor
|
//! Constructor
|
||||||
CDistributor(const QString &id, const QString &description, const QString &alias1, const QString &alias2);
|
CDistributor(const QString &id, const QString &description, const QString &alias1, const QString &alias2);
|
||||||
|
|
||||||
//! Id
|
|
||||||
const QString &getId() const { return this->getDbKey(); }
|
|
||||||
|
|
||||||
//! Get description
|
//! Get description
|
||||||
const QString &getDescription() const { return this->m_description;}
|
const QString &getDescription() const { return this->m_description;}
|
||||||
|
|
||||||
@@ -76,7 +73,7 @@ namespace BlackMisc
|
|||||||
bool hasAlias2() const { return !this->m_alias2.isEmpty(); }
|
bool hasAlias2() const { return !this->m_alias2.isEmpty(); }
|
||||||
|
|
||||||
//! Matches id or alias
|
//! Matches id or alias
|
||||||
bool matchesIdOrAlias(const QString &idOrAlias) const;
|
bool matchesKeyOrAlias(const QString &keyOrAlias) const;
|
||||||
|
|
||||||
//! \copydoc CValueObject::propertyByIndex
|
//! \copydoc CValueObject::propertyByIndex
|
||||||
CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
|
CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
|
||||||
|
|||||||
@@ -20,12 +20,12 @@ namespace BlackMisc
|
|||||||
CSequence<CDistributor>(other)
|
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))
|
for (const CDistributor &distributor : (*this))
|
||||||
{
|
{
|
||||||
if (distributor.matchesIdOrAlias(idOrAlias)) { return distributor; }
|
if (distributor.matchesKeyOrAlias(keyOrAlias)) { return distributor; }
|
||||||
}
|
}
|
||||||
return CDistributor();
|
return CDistributor();
|
||||||
}
|
}
|
||||||
@@ -39,10 +39,30 @@ namespace BlackMisc
|
|||||||
if (d.hasCompleteData()) { return d; }
|
if (d.hasCompleteData()) { return d; }
|
||||||
|
|
||||||
// more lenient search
|
// more lenient search
|
||||||
return this->findByIdOrAlias(k);
|
return this->findByKeyOrAlias(k);
|
||||||
}
|
}
|
||||||
return CDistributor();
|
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
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -41,10 +41,13 @@ namespace BlackMisc
|
|||||||
CDistributorList(const CSequence<CDistributor> &other);
|
CDistributorList(const CSequence<CDistributor> &other);
|
||||||
|
|
||||||
//! Find by id or alias
|
//! Find by id or alias
|
||||||
CDistributor findByIdOrAlias(const QString &name);
|
CDistributor findByKeyOrAlias(const QString &keyOrAlias);
|
||||||
|
|
||||||
//! Best match by given pattern
|
//! Best match by given pattern
|
||||||
CDistributor smartDistributorSelector(const CDistributor &distributorPattern);
|
CDistributor smartDistributorSelector(const CDistributor &distributorPattern);
|
||||||
|
|
||||||
|
//! All DB keys and aliases
|
||||||
|
QStringList getDbKeysAndAliases() const;
|
||||||
};
|
};
|
||||||
} //namespace
|
} //namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
Reference in New Issue
Block a user