From daa3c9be8144f637801dc236ba2ded27a6c5cbe6 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 1 Feb 2016 03:15:20 +0100 Subject: [PATCH] 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 --- .../components/dbliveryselectorcomponent.cpp | 35 +++++++++++++++---- .../components/dbliveryselectorcomponent.h | 3 ++ src/blackgui/editors/liveryform.cpp | 6 ++++ src/blackgui/filters/liveryfilterbar.cpp | 2 ++ src/blackmisc/aviation/livery.cpp | 11 ++++-- 5 files changed, 49 insertions(+), 8 deletions(-) diff --git a/src/blackgui/components/dbliveryselectorcomponent.cpp b/src/blackgui/components/dbliveryselectorcomponent.cpp index 9b6a901ad..fda1f5a29 100644 --- a/src/blackgui/components/dbliveryselectorcomponent.cpp +++ b/src/blackgui/components/dbliveryselectorcomponent.cpp @@ -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 diff --git a/src/blackgui/components/dbliveryselectorcomponent.h b/src/blackgui/components/dbliveryselectorcomponent.h index 19e6c3fe2..9f1b69c76 100644 --- a/src/blackgui/components/dbliveryselectorcomponent.h +++ b/src/blackgui/components/dbliveryselectorcomponent.h @@ -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; QScopedPointer m_completerLiveries; QMetaObject::Connection m_signalConnection; diff --git a/src/blackgui/editors/liveryform.cpp b/src/blackgui/editors/liveryform.cpp index 5cb1cb882..5bf5b1850 100644 --- a/src/blackgui/editors/liveryform.cpp +++ b/src/blackgui/editors/liveryform.cpp @@ -53,6 +53,12 @@ namespace BlackGui CLivery CLiveryForm::getValue() const { CLivery livery(this->ui->livery_Selector->getLivery()); + if (livery.hasCompleteData() && livery.hasValidDbKey()) + { + // already complete data from selector + return livery; + } + CAirlineIcaoCode airline(this->ui->editor_AirlineIcao->getValue()); livery.setAirlineIcaoCode(airline); livery.setDescription(this->ui->le_Description->text()); diff --git a/src/blackgui/filters/liveryfilterbar.cpp b/src/blackgui/filters/liveryfilterbar.cpp index 11fa2222e..3bcdc6a81 100644 --- a/src/blackgui/filters/liveryfilterbar.cpp +++ b/src/blackgui/filters/liveryfilterbar.cpp @@ -96,6 +96,8 @@ namespace BlackGui ui->color_Fuselage->clear(); ui->color_Tail->clear(); ui->hs_ColorDistance->setValue(0.25 * 100.0); + ui->cb_Airlines->setChecked(true); + ui->cb_Colors->setChecked(true); } void CLiveryFilterBar::ps_colorChanged(const BlackMisc::CRgbColor &color) diff --git a/src/blackmisc/aviation/livery.cpp b/src/blackmisc/aviation/livery.cpp index f54abc3ad..03f2311c5 100644 --- a/src/blackmisc/aviation/livery.cpp +++ b/src/blackmisc/aviation/livery.cpp @@ -175,8 +175,15 @@ namespace BlackMisc bool CLivery::isValidCombinedCode(const QString &candidate) { if (candidate.isEmpty()) { return false; } - if (candidate.count('.') != 1) { return false; } - return candidate.length() > 2; + if (candidate.startsWith(colorLiveryMarker())) + { + return candidate.length() > colorLiveryMarker().length() + 1; + } + else + { + if (candidate.count('.') != 1) { return false; } + return candidate.length() > 2; + } } const QString &CLivery::standardLiveryMarker()