mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 11:55:35 +08:00
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:
committed by
Mat Sutcliffe
parent
89c241b2e7
commit
7981815ddf
@@ -12,6 +12,7 @@
|
||||
#include "blackgui/guiapplication.h"
|
||||
#include "blackgui/uppercasevalidator.h"
|
||||
#include "blackmisc/aviation/liverylist.h"
|
||||
#include "blackmisc/db/datastoreutility.h"
|
||||
#include "blackmisc/compare.h"
|
||||
#include "blackmisc/stringutils.h"
|
||||
#include "blackmisc/variant.h"
|
||||
@@ -34,6 +35,7 @@ using namespace BlackGui;
|
||||
using namespace BlackCore;
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::Db;
|
||||
using namespace BlackMisc::Network;
|
||||
|
||||
namespace BlackGui
|
||||
@@ -50,8 +52,8 @@ namespace BlackGui
|
||||
|
||||
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);
|
||||
this->onLiveriesRead(CEntityFlags::LiveryEntity, CEntityFlags::ReadFinished, sGui->getWebDataServices()->getLiveriesCount(), {});
|
||||
@@ -64,33 +66,41 @@ namespace BlackGui
|
||||
|
||||
void CDbLiverySelectorComponent::setLivery(const CLivery &livery)
|
||||
{
|
||||
QString code(livery.getCombinedCode());
|
||||
if (code.isEmpty())
|
||||
if (!livery.hasCombinedCode())
|
||||
{
|
||||
ui->le_Livery->clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (livery != m_currentLivery)
|
||||
{
|
||||
ui->le_Livery->setText(code);
|
||||
ui->le_Livery->setText(livery.getCombinedCodePlusId());
|
||||
m_currentLivery = livery;
|
||||
emit changedLivery(livery);
|
||||
}
|
||||
}
|
||||
|
||||
void CDbLiverySelectorComponent::setlivery(const QString &code)
|
||||
void CDbLiverySelectorComponent::setLivery(const QString &code)
|
||||
{
|
||||
QString liveryCode(code.toUpper().trimmed());
|
||||
int s = liveryCode.indexOf(' ');
|
||||
if (s >= 1) { liveryCode = liveryCode.left(s); }
|
||||
s = liveryCode.indexOf('(');
|
||||
if (s >= 1) { liveryCode = liveryCode.left(s).trimmed(); }
|
||||
if (!sGui || sGui->isShuttingDown() || !sGui->hasWebDataServices()) { return; }
|
||||
const int dbKey = CDatastoreUtility::extractIntegerKey(code);
|
||||
CLivery livery;
|
||||
|
||||
if (m_currentLivery.matchesCombinedCode(liveryCode)) { return; }
|
||||
CLivery d(sApp->getWebDataServices()->getLiveries().findByCombinedCode(liveryCode));
|
||||
if (d.hasCompleteData())
|
||||
if (dbKey >= 0)
|
||||
{
|
||||
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
|
||||
{
|
||||
@@ -101,20 +111,29 @@ namespace BlackGui
|
||||
|
||||
CLivery CDbLiverySelectorComponent::getLivery() const
|
||||
{
|
||||
if (!sApp) { return CLivery(); }
|
||||
const QString liveryCode(
|
||||
this->stripExtraInfo(ui->le_Livery->text())
|
||||
);
|
||||
const CLivery liv(sApp->getWebDataServices()->getLiveries().findByCombinedCode(liveryCode));
|
||||
if (liv.hasCompleteData() && liv.hasValidDbKey())
|
||||
if (!sGui || sGui->isShuttingDown()) { return CLivery(); }
|
||||
|
||||
const QString raw = ui->le_Livery->text();
|
||||
const int dbKey = CDatastoreUtility::extractIntegerKey(raw);
|
||||
|
||||
CLivery livery;
|
||||
if (dbKey >= 0)
|
||||
{
|
||||
// full data fetched
|
||||
return liv;
|
||||
livery = sGui->getWebDataServices()->getLiveryForDbKey(dbKey);
|
||||
}
|
||||
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
|
||||
@@ -192,7 +211,7 @@ namespace BlackGui
|
||||
{
|
||||
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);
|
||||
c->setCaseSensitivity(Qt::CaseInsensitive);
|
||||
c->setCompletionMode(QCompleter::PopupCompletion);
|
||||
@@ -212,17 +231,13 @@ namespace BlackGui
|
||||
void CDbLiverySelectorComponent::onDataChanged()
|
||||
{
|
||||
if (!sGui || sGui->isShuttingDown() || !sGui->hasWebDataServices()) { return; }
|
||||
const QString code(
|
||||
this->stripExtraInfo(ui->le_Livery->text())
|
||||
);
|
||||
if (code.isEmpty()) { return; }
|
||||
const CLivery livery(sApp->getWebDataServices()->getLiveries().findByCombinedCode(code));
|
||||
this->setLivery(livery);
|
||||
const QString raw = ui->le_Livery->text();
|
||||
this->setLivery(raw);
|
||||
}
|
||||
|
||||
void CDbLiverySelectorComponent::onCompleterActivated(const QString &liveryCode)
|
||||
{
|
||||
this->setlivery(liveryCode);
|
||||
this->setLivery(liveryCode);
|
||||
}
|
||||
|
||||
QString CDbLiverySelectorComponent::stripExtraInfo(const QString &liveryCode) const
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace BlackGui
|
||||
void setLivery(const BlackMisc::Aviation::CLivery &livery);
|
||||
|
||||
//! Current livery
|
||||
void setlivery(const QString &code);
|
||||
void setLivery(const QString &code);
|
||||
|
||||
//! Livery
|
||||
BlackMisc::Aviation::CLivery getLivery() const;
|
||||
|
||||
@@ -65,10 +65,10 @@ namespace BlackGui
|
||||
|
||||
// copy over buttons
|
||||
connect(ui->pb_AircraftIcao, &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_Distributor, &QPushButton::pressed, this, &CDbStashComponent::copyOverValuesToSelectedModels);
|
||||
connect(ui->pb_Model, &QPushButton::pressed, this, &CDbStashComponent::modifyModelDialog);
|
||||
connect(ui->pb_AirlineIcao, &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_Model, &QPushButton::pressed, this, &CDbStashComponent::modifyModelDialog);
|
||||
|
||||
ui->tvp_StashAircraftModels->setAircraftModelMode(CAircraftModelListModel::StashModel);
|
||||
ui->tvp_StashAircraftModels->allowDragDrop(false, true, true);
|
||||
|
||||
@@ -96,7 +96,20 @@ namespace BlackGui
|
||||
|
||||
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.setMilitary(ui->cb_Military->isChecked());
|
||||
code.setCountry(ui->country_Selector->getCountry());
|
||||
@@ -210,9 +223,10 @@ namespace BlackGui
|
||||
{
|
||||
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);
|
||||
if (!icao.isLoadedFromDb())
|
||||
if (ok && !icao.isLoadedFromDb())
|
||||
{
|
||||
ui->le_Id->undo();
|
||||
return;
|
||||
|
||||
@@ -69,7 +69,24 @@ namespace BlackGui
|
||||
|
||||
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())
|
||||
{
|
||||
// already complete data from selector
|
||||
@@ -229,7 +246,11 @@ namespace BlackGui
|
||||
{
|
||||
if (!sGui || sGui->isShuttingDown() || !sGui->getWebDataServices()) { 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));
|
||||
if (stdLivery.hasValidDbKey())
|
||||
|
||||
Reference in New Issue
Block a user