refs #576, fixed livery filtering and editing

* fixed selector by stripping extra info before selecting
* correct reset of filter UI
* return livery object directly from form if already valid DB object
This commit is contained in:
Klaus Basan
2016-02-01 03:15:20 +01:00
parent 2498a1ad71
commit daa3c9be81
5 changed files with 49 additions and 8 deletions

View File

@@ -91,9 +91,19 @@ namespace BlackGui
CLivery CDbLiverySelectorComponent::getLivery() const
{
if (!hasProvider()) { return CLivery(); }
QString liveryCode(this->ui->le_Livery->text().trimmed().toUpper());
CLivery d(getLiveries().findByCombinedCode(liveryCode));
return d;
const QString liveryCode(
this->stripExtraInfo(this->ui->le_Livery->text())
);
const CLivery liv(getLiveries().findByCombinedCode(liveryCode));
if (liv.hasCompleteData() && liv.hasValidDbKey())
{
// full data fetched
return liv;
}
else
{
return this->m_currentLivery;
}
}
void CDbLiverySelectorComponent::setReadOnly(bool readOnly)
@@ -183,10 +193,12 @@ namespace BlackGui
void CDbLiverySelectorComponent::ps_dataChanged()
{
if (!hasProvider()) { return; }
QString code(this->ui->le_Livery->text().trimmed().toUpper());
const QString code(
this->stripExtraInfo(this->ui->le_Livery->text())
);
if (code.isEmpty()) { return; }
CLivery d(this->getLiveries().findByCombinedCode(code));
this->setLivery(d);
const CLivery livery(this->getLiveries().findByCombinedCode(code));
this->setLivery(livery);
}
void CDbLiverySelectorComponent::ps_completerActivated(const QString &liveryCode)
@@ -194,5 +206,16 @@ namespace BlackGui
this->setlivery(liveryCode);
}
QString CDbLiverySelectorComponent::stripExtraInfo(const QString &liveryCode) const
{
if (liveryCode.isEmpty()) { return ""; }
const QString l(liveryCode.trimmed().toUpper());
int is = l.indexOf(' ');
int ib = l.indexOf('(');
int i = qMin(is, ib);
if (i < 0) { return l; }
return l.left(i);
}
} // ns
} // ns

View File

@@ -96,6 +96,9 @@ namespace BlackGui
void ps_completerActivated(const QString &liveryCode);
private:
//! Strip extra info from livery code
QString stripExtraInfo(const QString &liveryCode) const;
QScopedPointer<Ui::CDbLiverySelectorComponent> ui;
QScopedPointer<QCompleter> m_completerLiveries;
QMetaObject::Connection m_signalConnection;