mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 12:55:33 +08:00
refs #768, improved selectors
* added focus proxy * using &QLineEdit::editingFinished as signal (changes value also when focus is lost) * use enum to set how values are displayed * search for DB values by leveraging the smart selector functions * added isSet functions * minor renamings/formatting
This commit is contained in:
@@ -45,10 +45,11 @@ namespace BlackGui
|
||||
ui(new Ui::CDbAircraftIcaoSelectorComponent)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->setFocusProxy(ui->le_Aircraft);
|
||||
this->setAcceptDrops(true);
|
||||
this->setAcceptedMetaTypeIds({qMetaTypeId<CAircraftIcaoCode>(), qMetaTypeId<CAircraftIcaoCodeList>()});
|
||||
ui->le_Aircraft->setValidator(new CUpperCaseValidator(this));
|
||||
connect(ui->le_Aircraft, &QLineEdit::returnPressed, this, &CDbAircraftIcaoSelectorComponent::ps_dataChanged);
|
||||
connect(ui->le_Aircraft, &QLineEdit::editingFinished, this, &CDbAircraftIcaoSelectorComponent::ps_dataChanged);
|
||||
connect(sApp->getWebDataServices(), &CWebDataServices::dataRead, this, &CDbAircraftIcaoSelectorComponent::ps_codesRead);
|
||||
this->ps_codesRead(CEntityFlags::AircraftIcaoEntity, CEntityFlags::ReadFinished, sApp->getWebDataServices()->getAircraftIcaoCodesCount());
|
||||
}
|
||||
@@ -58,19 +59,26 @@ namespace BlackGui
|
||||
|
||||
void CDbAircraftIcaoSelectorComponent::setAircraftIcao(const CAircraftIcaoCode &icao)
|
||||
{
|
||||
QString icaoStr(icao.getDesignator());
|
||||
ui->le_Aircraft->setText(icaoStr);
|
||||
ui->lbl_Description->setText(icao.getManufacturer());
|
||||
if (icao != m_currentIcao)
|
||||
CAircraftIcaoCode setIcao(icao);
|
||||
if (!icao.isLoadedFromDb())
|
||||
{
|
||||
m_currentIcao = icao;
|
||||
emit changedAircraftIcao(icao);
|
||||
// resolve against DB
|
||||
setIcao = sGui->getWebDataServices()->smartAircraftIcaoSelector(icao);
|
||||
}
|
||||
|
||||
const QString icaoStr(this->m_display == DisplayIcaoAndId ? setIcao.getDesignatorDbKey() : setIcao.getCombinedIcaoStringWithKey());
|
||||
ui->le_Aircraft->setText(icaoStr);
|
||||
ui->lbl_Description->setText(setIcao.getManufacturer());
|
||||
if (setIcao != m_currentIcao)
|
||||
{
|
||||
m_currentIcao = setIcao;
|
||||
emit changedAircraftIcao(setIcao);
|
||||
}
|
||||
}
|
||||
|
||||
void CDbAircraftIcaoSelectorComponent::setAircraftIcao(int key)
|
||||
{
|
||||
CAircraftIcaoCode icao(sGui->getWebDataServices()->getAircraftIcaoCodeForDbKey(key));
|
||||
const CAircraftIcaoCode icao(sGui->getWebDataServices()->getAircraftIcaoCodeForDbKey(key));
|
||||
ui->lbl_Description->setText("");
|
||||
if (icao.hasCompleteData())
|
||||
{
|
||||
@@ -84,6 +92,7 @@ namespace BlackGui
|
||||
int key = CDatastoreUtility::extractIntegerKey(text);
|
||||
if (key < 0)
|
||||
{
|
||||
if (this->m_currentIcao.getDesignator() == text) { return this->m_currentIcao; }
|
||||
return CAircraftIcaoCode(text);
|
||||
}
|
||||
CAircraftIcaoCode icao(sGui->getWebDataServices()->getAircraftIcaoCodeForDbKey(key));
|
||||
@@ -100,14 +109,15 @@ namespace BlackGui
|
||||
return stripDesignatorFromCompleterString(ui->le_Aircraft->text());
|
||||
}
|
||||
|
||||
void CDbAircraftIcaoSelectorComponent::withIcaoDescription(bool description)
|
||||
void CDbAircraftIcaoSelectorComponent::displayWithIcaoDescription(bool description)
|
||||
{
|
||||
ui->lbl_Description->setVisible(description);
|
||||
}
|
||||
|
||||
bool CDbAircraftIcaoSelectorComponent::isSet() const
|
||||
{
|
||||
return this->getAircraftIcao().hasCompleteData();
|
||||
const CAircraftIcaoCode icao(this->getAircraftIcao());
|
||||
return icao.isLoadedFromDb() || icao.hasCompleteData();
|
||||
}
|
||||
|
||||
void CDbAircraftIcaoSelectorComponent::clear()
|
||||
@@ -155,17 +165,27 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
const QStringList &CDbAircraftIcaoSelectorComponent::completerStrings()
|
||||
{
|
||||
// done for performance reasons
|
||||
// init only once, future instance can share thte list
|
||||
// only to be called when data are read!
|
||||
static const QStringList cs(sGui->getWebDataServices()->getAircraftIcaoCodes().toCompleterStrings(true, true, true));
|
||||
return cs;
|
||||
}
|
||||
|
||||
void CDbAircraftIcaoSelectorComponent::ps_codesRead(CEntityFlags::Entity entity, CEntityFlags::ReadState readState, int count)
|
||||
{
|
||||
if (!sGui) { return; }
|
||||
if (!sGui || !sGui->hasWebDataServices()) { return; }
|
||||
if (entity.testFlag(CEntityFlags::AircraftIcaoEntity) && readState == CEntityFlags::ReadFinished)
|
||||
{
|
||||
if (count > 0)
|
||||
{
|
||||
QCompleter *c = new QCompleter(sGui->getWebDataServices()->getAircraftIcaoCodes().toCompleterStrings(true, true, true), this);
|
||||
QCompleter *c = new QCompleter(completerStrings(), this);
|
||||
c->setCaseSensitivity(Qt::CaseInsensitive);
|
||||
c->setCompletionMode(QCompleter::PopupCompletion);
|
||||
c->setMaxVisibleItems(10);
|
||||
c->popup()->setMinimumWidth(175);
|
||||
this->connect(c, static_cast<void (QCompleter::*)(const QString &)>(&QCompleter::activated), this, &CDbAircraftIcaoSelectorComponent::ps_completerActivated);
|
||||
|
||||
ui->le_Aircraft->setCompleter(c);
|
||||
@@ -182,18 +202,27 @@ namespace BlackGui
|
||||
|
||||
void CDbAircraftIcaoSelectorComponent::ps_dataChanged()
|
||||
{
|
||||
if (!sGui) { return; }
|
||||
int key = CDatastoreUtility::extractIntegerKey(ui->le_Aircraft->text());
|
||||
CAircraftIcaoCode icao(sGui->getWebDataServices()->getAircraftIcaoCodeForDbKey(key));
|
||||
if (!sGui || !sGui->hasWebDataServices()) { return; }
|
||||
const int key = CDatastoreUtility::extractIntegerKey(ui->le_Aircraft->text());
|
||||
CAircraftIcaoCode icao;
|
||||
if (key >= 0)
|
||||
{
|
||||
// with valid key
|
||||
icao = sGui->getWebDataServices()->getAircraftIcaoCodeForDbKey(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
const QString designator(this->getRawDesignator());
|
||||
icao = sGui->getWebDataServices()->smartAircraftIcaoSelector(CAircraftIcaoCode(designator));
|
||||
}
|
||||
this->setAircraftIcao(icao);
|
||||
}
|
||||
|
||||
void CDbAircraftIcaoSelectorComponent::ps_completerActivated(const QString &icaoString)
|
||||
{
|
||||
int dbKey = CDatastoreUtility::extractIntegerKey(icaoString);
|
||||
const int dbKey = CDatastoreUtility::extractIntegerKey(icaoString);
|
||||
if (dbKey < 0) { return; }
|
||||
this->setAircraftIcao(dbKey);
|
||||
}
|
||||
|
||||
}// class
|
||||
} // ns
|
||||
|
||||
Reference in New Issue
Block a user