Improvements on livery selector and form, also airline form

* use id first to find data
* use id in selector and fields
* based on issue https://discordapp.com/channels/539048679160676382/717493722392297493/717511173146411061
This commit is contained in:
Klaus Basan
2020-06-03 04:46:32 +02:00
committed by Mat Sutcliffe
parent 89c241b2e7
commit 7981815ddf
5 changed files with 92 additions and 42 deletions

View File

@@ -12,6 +12,7 @@
#include "blackgui/guiapplication.h" #include "blackgui/guiapplication.h"
#include "blackgui/uppercasevalidator.h" #include "blackgui/uppercasevalidator.h"
#include "blackmisc/aviation/liverylist.h" #include "blackmisc/aviation/liverylist.h"
#include "blackmisc/db/datastoreutility.h"
#include "blackmisc/compare.h" #include "blackmisc/compare.h"
#include "blackmisc/stringutils.h" #include "blackmisc/stringutils.h"
#include "blackmisc/variant.h" #include "blackmisc/variant.h"
@@ -34,6 +35,7 @@ using namespace BlackGui;
using namespace BlackCore; using namespace BlackCore;
using namespace BlackMisc; using namespace BlackMisc;
using namespace BlackMisc::Aviation; using namespace BlackMisc::Aviation;
using namespace BlackMisc::Db;
using namespace BlackMisc::Network; using namespace BlackMisc::Network;
namespace BlackGui namespace BlackGui
@@ -50,8 +52,8 @@ namespace BlackGui
ui->le_Livery->setValidator(new CUpperCaseValidator(this)); ui->le_Livery->setValidator(new CUpperCaseValidator(this));
connect(ui->le_Livery, &QLineEdit::returnPressed, this, &CDbLiverySelectorComponent::onDataChanged); connect(ui->le_Livery, &QLineEdit::returnPressed, this, &CDbLiverySelectorComponent::onDataChanged);
connect(ui->le_Livery, &QLineEdit::returnPressed, this, &CDbLiverySelectorComponent::onDataChanged); connect(ui->le_Livery, &QLineEdit::editingFinished, this, &CDbLiverySelectorComponent::onDataChanged);
connect(sGui->getWebDataServices(), &CWebDataServices::dataRead, this, &CDbLiverySelectorComponent::onLiveriesRead, Qt::QueuedConnection); connect(sGui->getWebDataServices(), &CWebDataServices::dataRead, this, &CDbLiverySelectorComponent::onLiveriesRead, Qt::QueuedConnection);
this->onLiveriesRead(CEntityFlags::LiveryEntity, CEntityFlags::ReadFinished, sGui->getWebDataServices()->getLiveriesCount(), {}); this->onLiveriesRead(CEntityFlags::LiveryEntity, CEntityFlags::ReadFinished, sGui->getWebDataServices()->getLiveriesCount(), {});
@@ -64,33 +66,41 @@ namespace BlackGui
void CDbLiverySelectorComponent::setLivery(const CLivery &livery) void CDbLiverySelectorComponent::setLivery(const CLivery &livery)
{ {
QString code(livery.getCombinedCode()); if (!livery.hasCombinedCode())
if (code.isEmpty())
{ {
ui->le_Livery->clear(); ui->le_Livery->clear();
return; return;
} }
if (livery != m_currentLivery) if (livery != m_currentLivery)
{ {
ui->le_Livery->setText(code); ui->le_Livery->setText(livery.getCombinedCodePlusId());
m_currentLivery = livery; m_currentLivery = livery;
emit changedLivery(livery); emit changedLivery(livery);
} }
} }
void CDbLiverySelectorComponent::setlivery(const QString &code) void CDbLiverySelectorComponent::setLivery(const QString &code)
{ {
QString liveryCode(code.toUpper().trimmed()); if (!sGui || sGui->isShuttingDown() || !sGui->hasWebDataServices()) { return; }
int s = liveryCode.indexOf(' '); const int dbKey = CDatastoreUtility::extractIntegerKey(code);
if (s >= 1) { liveryCode = liveryCode.left(s); } CLivery livery;
s = liveryCode.indexOf('(');
if (s >= 1) { liveryCode = liveryCode.left(s).trimmed(); }
if (m_currentLivery.matchesCombinedCode(liveryCode)) { return; } if (dbKey >= 0)
CLivery d(sApp->getWebDataServices()->getLiveries().findByCombinedCode(liveryCode));
if (d.hasCompleteData())
{ {
this->setLivery(d); livery = sGui->getWebDataServices()->getLiveryForDbKey(dbKey);
}
if (!livery.hasValidDbKey())
{
const QString liveryCode = this->stripExtraInfo(code.toUpper().trimmed());
if (m_currentLivery.matchesCombinedCode(liveryCode)) { return; }
livery = sGui->getWebDataServices()->getLiveries().findByCombinedCode(liveryCode);
}
if (livery.hasCompleteData())
{
this->setLivery(livery);
} }
else else
{ {
@@ -101,20 +111,29 @@ namespace BlackGui
CLivery CDbLiverySelectorComponent::getLivery() const CLivery CDbLiverySelectorComponent::getLivery() const
{ {
if (!sApp) { return CLivery(); } if (!sGui || sGui->isShuttingDown()) { return CLivery(); }
const QString liveryCode(
this->stripExtraInfo(ui->le_Livery->text()) const QString raw = ui->le_Livery->text();
); const int dbKey = CDatastoreUtility::extractIntegerKey(raw);
const CLivery liv(sApp->getWebDataServices()->getLiveries().findByCombinedCode(liveryCode));
if (liv.hasCompleteData() && liv.hasValidDbKey()) CLivery livery;
if (dbKey >= 0)
{ {
// full data fetched livery = sGui->getWebDataServices()->getLiveryForDbKey(dbKey);
return liv;
} }
else else
{ {
return m_currentLivery; const QString liveryCode(this->stripExtraInfo(ui->le_Livery->text()));
livery = sGui->getWebDataServices()->getLiveries().findByCombinedCode(liveryCode);
} }
if (livery.hasCompleteData() && livery.hasValidDbKey())
{
// full data fetched
return livery;
}
return m_currentLivery;
} }
QString CDbLiverySelectorComponent::getRawCombinedCode() const QString CDbLiverySelectorComponent::getRawCombinedCode() const
@@ -192,7 +211,7 @@ namespace BlackGui
{ {
if (count > 0) if (count > 0)
{ {
const QStringList codes(sApp->getWebDataServices()->getLiveries().getCombinedCodesPlusInfo(true)); const QStringList codes(sGui->getWebDataServices()->getLiveries().getCombinedCodesPlusInfoAndId(true));
QCompleter *c = new QCompleter(codes, this); QCompleter *c = new QCompleter(codes, this);
c->setCaseSensitivity(Qt::CaseInsensitive); c->setCaseSensitivity(Qt::CaseInsensitive);
c->setCompletionMode(QCompleter::PopupCompletion); c->setCompletionMode(QCompleter::PopupCompletion);
@@ -212,17 +231,13 @@ namespace BlackGui
void CDbLiverySelectorComponent::onDataChanged() void CDbLiverySelectorComponent::onDataChanged()
{ {
if (!sGui || sGui->isShuttingDown() || !sGui->hasWebDataServices()) { return; } if (!sGui || sGui->isShuttingDown() || !sGui->hasWebDataServices()) { return; }
const QString code( const QString raw = ui->le_Livery->text();
this->stripExtraInfo(ui->le_Livery->text()) this->setLivery(raw);
);
if (code.isEmpty()) { return; }
const CLivery livery(sApp->getWebDataServices()->getLiveries().findByCombinedCode(code));
this->setLivery(livery);
} }
void CDbLiverySelectorComponent::onCompleterActivated(const QString &liveryCode) void CDbLiverySelectorComponent::onCompleterActivated(const QString &liveryCode)
{ {
this->setlivery(liveryCode); this->setLivery(liveryCode);
} }
QString CDbLiverySelectorComponent::stripExtraInfo(const QString &liveryCode) const QString CDbLiverySelectorComponent::stripExtraInfo(const QString &liveryCode) const

View File

@@ -55,7 +55,7 @@ namespace BlackGui
void setLivery(const BlackMisc::Aviation::CLivery &livery); void setLivery(const BlackMisc::Aviation::CLivery &livery);
//! Current livery //! Current livery
void setlivery(const QString &code); void setLivery(const QString &code);
//! Livery //! Livery
BlackMisc::Aviation::CLivery getLivery() const; BlackMisc::Aviation::CLivery getLivery() const;

View File

@@ -65,10 +65,10 @@ namespace BlackGui
// copy over buttons // copy over buttons
connect(ui->pb_AircraftIcao, &QPushButton::pressed, this, &CDbStashComponent::copyOverValuesToSelectedModels); connect(ui->pb_AircraftIcao, &QPushButton::pressed, this, &CDbStashComponent::copyOverValuesToSelectedModels);
connect(ui->pb_AirlineIcao, &QPushButton::pressed, this, &CDbStashComponent::copyOverValuesToSelectedModels); connect(ui->pb_AirlineIcao, &QPushButton::pressed, this, &CDbStashComponent::copyOverValuesToSelectedModels);
connect(ui->pb_Livery, &QPushButton::pressed, this, &CDbStashComponent::copyOverValuesToSelectedModels); connect(ui->pb_Livery, &QPushButton::pressed, this, &CDbStashComponent::copyOverValuesToSelectedModels);
connect(ui->pb_Distributor, &QPushButton::pressed, this, &CDbStashComponent::copyOverValuesToSelectedModels); connect(ui->pb_Distributor, &QPushButton::pressed, this, &CDbStashComponent::copyOverValuesToSelectedModels);
connect(ui->pb_Model, &QPushButton::pressed, this, &CDbStashComponent::modifyModelDialog); connect(ui->pb_Model, &QPushButton::pressed, this, &CDbStashComponent::modifyModelDialog);
ui->tvp_StashAircraftModels->setAircraftModelMode(CAircraftModelListModel::StashModel); ui->tvp_StashAircraftModels->setAircraftModelMode(CAircraftModelListModel::StashModel);
ui->tvp_StashAircraftModels->allowDragDrop(false, true, true); ui->tvp_StashAircraftModels->allowDragDrop(false, true, true);

View File

@@ -96,7 +96,20 @@ namespace BlackGui
CAirlineIcaoCode CAirlineIcaoForm::getValue() const CAirlineIcaoCode CAirlineIcaoForm::getValue() const
{ {
CAirlineIcaoCode code(m_currentCode); CAirlineIcaoCode code;
const QString id = ui->le_Id->text();
if (sGui && !sGui->isShuttingDown() && sGui->hasWebDataServices())
{
bool ok;
const int dbKey = id.toInt(&ok);
if (ok)
{
code = sGui->getWebDataServices()->getAirlineIcaoCodeForDbKey(dbKey);
}
}
if (code.hasValidDbKey()) { return code; }
code = m_currentCode;
code.setVirtualAirline(ui->cb_Va->isChecked()); code.setVirtualAirline(ui->cb_Va->isChecked());
code.setMilitary(ui->cb_Military->isChecked()); code.setMilitary(ui->cb_Military->isChecked());
code.setCountry(ui->country_Selector->getCountry()); code.setCountry(ui->country_Selector->getCountry());
@@ -210,9 +223,10 @@ namespace BlackGui
{ {
if (!sGui || sGui->isShuttingDown() || !sGui->hasWebDataServices()) { return; } if (!sGui || sGui->isShuttingDown() || !sGui->hasWebDataServices()) { return; }
const int id = ui->le_Id->text().toInt(); bool ok;
const int id = ui->le_Id->text().toInt(&ok);
const CAirlineIcaoCode icao = sGui->getWebDataServices()->getAirlineIcaoCodeForDbKey(id); const CAirlineIcaoCode icao = sGui->getWebDataServices()->getAirlineIcaoCodeForDbKey(id);
if (!icao.isLoadedFromDb()) if (ok && !icao.isLoadedFromDb())
{ {
ui->le_Id->undo(); ui->le_Id->undo();
return; return;

View File

@@ -69,7 +69,24 @@ namespace BlackGui
CLivery CLiveryForm::getValue() const CLivery CLiveryForm::getValue() const
{ {
CLivery livery(ui->comp_LiverySelector->getLivery()); CLivery livery;
const QString id = ui->le_Id->text();
if (!id.isEmpty() && sGui && !sGui->isShuttingDown() && sGui->hasWebDataServices())
{
bool ok;
const int dbKey = id.toInt(&ok);
if (ok)
{
livery = sGui->getWebDataServices()->getLiveryForDbKey(dbKey);
}
}
// fallback
if (!livery.hasValidDbKey())
{
livery = ui->comp_LiverySelector->getLivery();
}
if (livery.hasCompleteData() && livery.hasValidDbKey()) if (livery.hasCompleteData() && livery.hasValidDbKey())
{ {
// already complete data from selector // already complete data from selector
@@ -229,7 +246,11 @@ namespace BlackGui
{ {
if (!sGui || sGui->isShuttingDown() || !sGui->getWebDataServices()) { return; } if (!sGui || sGui->isShuttingDown() || !sGui->getWebDataServices()) { return; }
if (!code.hasCompleteData()) { return; } if (!code.hasCompleteData()) { return; }
if (!code.hasValidDbKey()) { return; } if (!code.hasValidDbKey()) { return; }
// only replace with STD livery if airline does not match
const CLivery currentLivery = this->getValue();
if (currentLivery.getAirlineIcaoCode() == code) { return; }
const CLivery stdLivery(sGui->getWebDataServices()->getLiveries().findStdLiveryByAirlineIcaoVDesignator(code)); const CLivery stdLivery(sGui->getWebDataServices()->getLiveries().findStdLiveryByAirlineIcaoVDesignator(code));
if (stdLivery.hasValidDbKey()) if (stdLivery.hasValidDbKey())