mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +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
|
||||
|
||||
@@ -30,7 +30,6 @@ class QDropEvent;
|
||||
class QWidget;
|
||||
|
||||
namespace Ui { class CDbAircraftIcaoSelectorComponent; }
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Components
|
||||
@@ -45,6 +44,13 @@ namespace BlackGui
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! How to display the info
|
||||
enum Display
|
||||
{
|
||||
DisplayIcaoAndId,
|
||||
DisplayCompleterString
|
||||
};
|
||||
|
||||
//! Constructor
|
||||
explicit CDbAircraftIcaoSelectorComponent(QWidget *parent = nullptr);
|
||||
|
||||
@@ -67,7 +73,10 @@ namespace BlackGui
|
||||
void setReadOnly(bool readOnly);
|
||||
|
||||
//! Display distributor description
|
||||
void withIcaoDescription(bool description);
|
||||
void displayWithIcaoDescription(bool description);
|
||||
|
||||
//! How to display string in text field
|
||||
void displayMode(Display mode) { m_display = mode; }
|
||||
|
||||
//! Set with valid Distributor
|
||||
bool isSet() const;
|
||||
@@ -106,7 +115,12 @@ namespace BlackGui
|
||||
QScopedPointer<Ui::CDbAircraftIcaoSelectorComponent> ui;
|
||||
QScopedPointer<QCompleter> m_completerIcaoDescription;
|
||||
BlackMisc::Aviation::CAircraftIcaoCode m_currentIcao;
|
||||
Display m_display = DisplayIcaoAndId;
|
||||
|
||||
//! Get the completer strings
|
||||
//! \remark shared for performance reasons
|
||||
static const QStringList &completerStrings();
|
||||
};
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
#endif // guard
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>189</width>
|
||||
<height>22</height>
|
||||
<height>24</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -57,6 +57,9 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>le_Aircraft</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
||||
@@ -61,8 +61,15 @@ namespace BlackGui
|
||||
bool CDbAirlineIcaoSelectorBase::setAirlineIcao(const CAirlineIcaoCode &icao)
|
||||
{
|
||||
if (icao == m_currentIcao) { return false; }
|
||||
m_currentIcao = icao;
|
||||
emit changedAirlineIcao(icao);
|
||||
if (icao.isLoadedFromDb())
|
||||
{
|
||||
this->m_currentIcao = icao;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->m_currentIcao = sGui->getWebDataServices()->smartAirlineIcaoSelector(icao);
|
||||
}
|
||||
emit changedAirlineIcao(this->m_currentIcao);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -80,6 +87,12 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
bool CDbAirlineIcaoSelectorBase::isSet() const
|
||||
{
|
||||
const CAirlineIcaoCode icao(this->getAirlineIcao());
|
||||
return icao.isLoadedFromDb() || icao.hasCompleteData();
|
||||
}
|
||||
|
||||
void CDbAirlineIcaoSelectorBase::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
if (!event || !acceptDrop(event->mimeData())) { return; }
|
||||
|
||||
@@ -61,6 +61,9 @@ namespace BlackGui
|
||||
//! Clear selection
|
||||
virtual void clear() = 0;
|
||||
|
||||
//! Set with valid value
|
||||
bool isSet() const;
|
||||
|
||||
signals:
|
||||
//! ICAO was changed
|
||||
void changedAirlineIcao(const BlackMisc::Aviation::CAirlineIcaoCode &icao);
|
||||
|
||||
@@ -36,14 +36,13 @@ namespace BlackGui
|
||||
ui(new Ui::CDbAirlineIcaoSelectorComponent)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->setFocusProxy(ui->le_Airline);
|
||||
ui->le_Airline->setValidator(new CUpperCaseValidator(this));
|
||||
connect(ui->le_Airline, &QLineEdit::returnPressed, this, &CDbAirlineIcaoSelectorComponent::ps_dataChanged);
|
||||
connect(ui->le_Airline, &QLineEdit::editingFinished, this, &CDbAirlineIcaoSelectorComponent::ps_dataChanged);
|
||||
}
|
||||
|
||||
CDbAirlineIcaoSelectorComponent::~CDbAirlineIcaoSelectorComponent()
|
||||
{
|
||||
// no inline destructor, read QScopedPointer Forward Declared Pointers
|
||||
}
|
||||
{ }
|
||||
|
||||
void CDbAirlineIcaoSelectorComponent::setReadOnly(bool readOnly)
|
||||
{
|
||||
@@ -52,14 +51,16 @@ namespace BlackGui
|
||||
|
||||
bool CDbAirlineIcaoSelectorComponent::setAirlineIcao(const CAirlineIcaoCode &icao)
|
||||
{
|
||||
if (!CDbAirlineIcaoSelectorBase::setAirlineIcao(icao)) { return false; }
|
||||
const QString icaoStr(icao.getVDesignator());
|
||||
const bool changed = CDbAirlineIcaoSelectorBase::setAirlineIcao(icao);
|
||||
|
||||
// Always update GUI regardless of changed because of formattimg
|
||||
const QString icaoStr(m_display == DisplayVDesignatorAndId ? this->m_currentIcao.getVDesignatorDbKey() : this->m_currentIcao.getCombinedStringWithKey());
|
||||
ui->le_Airline->setText(icaoStr);
|
||||
ui->lbl_Description->setText(icao.getName());
|
||||
return true;
|
||||
ui->lbl_Description->setText(this->m_currentIcao.getName());
|
||||
return changed;
|
||||
}
|
||||
|
||||
void CDbAirlineIcaoSelectorComponent::withIcaoDescription(bool description)
|
||||
void CDbAirlineIcaoSelectorComponent::displayWithIcaoDescription(bool description)
|
||||
{
|
||||
ui->lbl_Description->setVisible(description);
|
||||
}
|
||||
@@ -75,12 +76,22 @@ namespace BlackGui
|
||||
return stripDesignatorFromCompleterString(ui->le_Airline->text());
|
||||
}
|
||||
|
||||
const QStringList &CDbAirlineIcaoSelectorComponent::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()->getAirlineIcaoCodes().toIcaoDesignatorCompleterStrings(true, true));
|
||||
return cs;
|
||||
}
|
||||
|
||||
QCompleter *CDbAirlineIcaoSelectorComponent::createCompleter()
|
||||
{
|
||||
QCompleter *c = new QCompleter(sGui->getWebDataServices()->getAirlineIcaoCodes().toIcaoDesignatorCompleterStrings(true, true), this);
|
||||
QCompleter *c = new QCompleter(completerStrings(), this);
|
||||
c->setCaseSensitivity(Qt::CaseInsensitive);
|
||||
c->setCompletionMode(QCompleter::PopupCompletion);
|
||||
c->setMaxVisibleItems(10);
|
||||
c->popup()->setMinimumWidth(175);
|
||||
ui->le_Airline->setCompleter(c);
|
||||
return c;
|
||||
}
|
||||
@@ -90,12 +101,18 @@ namespace BlackGui
|
||||
if (!sGui) { return; }
|
||||
QString s(ui->le_Airline->text());
|
||||
if (s.isEmpty()) { return; }
|
||||
CAirlineIcaoCode icao;
|
||||
int dbKey = CDatastoreUtility::extractIntegerKey(s);
|
||||
if (dbKey >= 0)
|
||||
{
|
||||
CAirlineIcaoCode icao(sGui->getWebDataServices()->getAirlineIcaoCodeForDbKey(dbKey));
|
||||
this->setAirlineIcao(icao);
|
||||
icao = sGui->getWebDataServices()->getAirlineIcaoCodeForDbKey(dbKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
const QString designator = this->getRawDesignator();
|
||||
icao = sGui->getWebDataServices()->smartAirlineIcaoSelector(CAirlineIcaoCode(designator));
|
||||
}
|
||||
this->setAirlineIcao(icao);
|
||||
}
|
||||
}// class
|
||||
} // ns
|
||||
|
||||
@@ -19,12 +19,12 @@
|
||||
#include <QObject>
|
||||
#include <QScopedPointer>
|
||||
#include <QString>
|
||||
#include <QScopedPointer>
|
||||
|
||||
class QCompleter;
|
||||
class QWidget;
|
||||
|
||||
namespace Ui { class CDbAirlineIcaoSelectorComponent; }
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Components
|
||||
@@ -37,6 +37,13 @@ namespace BlackGui
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! How to display the info
|
||||
enum Display
|
||||
{
|
||||
DisplayVDesignatorAndId,
|
||||
DisplayCompleterString
|
||||
};
|
||||
|
||||
//! Constructor
|
||||
explicit CDbAirlineIcaoSelectorComponent(QWidget *parent = nullptr);
|
||||
|
||||
@@ -55,7 +62,10 @@ namespace BlackGui
|
||||
QString getRawDesignator() const;
|
||||
|
||||
//! Display ICAO description
|
||||
void withIcaoDescription(bool description);
|
||||
void displayWithIcaoDescription(bool description);
|
||||
|
||||
//! Display mode
|
||||
void displayMode(Display mode) { this->m_display = mode; }
|
||||
|
||||
protected:
|
||||
//! \copydoc CDbAirlineIcaoSelectorBase::createCompleter
|
||||
@@ -67,7 +77,12 @@ namespace BlackGui
|
||||
|
||||
private:
|
||||
QScopedPointer<Ui::CDbAirlineIcaoSelectorComponent> ui;
|
||||
Display m_display = DisplayVDesignatorAndId;
|
||||
|
||||
//! Get the completer strings
|
||||
//! \remark shared for performance reasons
|
||||
static const QStringList &completerStrings();
|
||||
};
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
#endif // guard
|
||||
|
||||
@@ -33,7 +33,8 @@ namespace BlackGui
|
||||
ui(new Ui::CDbAirlineNameSelectorComponent)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
connect(ui->le_AirlineName, &QLineEdit::returnPressed, this, &CDbAirlineNameSelectorComponent::ps_dataChanged);
|
||||
this->setFocusProxy(ui->le_AirlineName);
|
||||
connect(ui->le_AirlineName, &QLineEdit::editingFinished, this, &CDbAirlineNameSelectorComponent::ps_dataChanged);
|
||||
}
|
||||
|
||||
CDbAirlineNameSelectorComponent::~CDbAirlineNameSelectorComponent()
|
||||
@@ -44,7 +45,7 @@ namespace BlackGui
|
||||
bool CDbAirlineNameSelectorComponent::setAirlineIcao(const CAirlineIcaoCode &icao)
|
||||
{
|
||||
if (!CDbAirlineIcaoSelectorBase::setAirlineIcao(icao)) { return false; }
|
||||
QString name(icao.getName());
|
||||
const QString name(icao.getName());
|
||||
ui->le_AirlineName->setText(name);
|
||||
return true;
|
||||
}
|
||||
@@ -65,6 +66,7 @@ namespace BlackGui
|
||||
c->setCaseSensitivity(Qt::CaseInsensitive);
|
||||
c->setCompletionMode(QCompleter::PopupCompletion);
|
||||
c->setMaxVisibleItems(10);
|
||||
c->popup()->setMinimumWidth(175);
|
||||
ui->le_AirlineName->setCompleter(c);
|
||||
return c;
|
||||
}
|
||||
@@ -80,14 +82,6 @@ namespace BlackGui
|
||||
CAirlineIcaoCode icao(sGui->getWebDataServices()->getAirlineIcaoCodeForDbKey(dbKey));
|
||||
this->setAirlineIcao(icao);
|
||||
}
|
||||
else
|
||||
{
|
||||
// second choice, first object found by designator
|
||||
// for name
|
||||
|
||||
// CAirlineIcaoCode icao(getAirlineIcao));
|
||||
// this->setAirlineIcao(icao);
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -42,6 +42,7 @@ namespace BlackGui
|
||||
ui(new Ui::CDbCountrySelectorComponent)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->setFocusProxy(ui->le_CountryIso);
|
||||
this->setAcceptDrops(true);
|
||||
this->setAcceptedMetaTypeIds({qMetaTypeId<CCountry>(), qMetaTypeId<CCountryList>()});
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ namespace BlackGui
|
||||
{
|
||||
Q_ASSERT_X(sGui, Q_FUNC_INFO, "Missing sGui");
|
||||
ui->setupUi(this);
|
||||
this->setFocusProxy(ui->le_Distributor);
|
||||
this->setAcceptDrops(true);
|
||||
this->setAcceptedMetaTypeIds({qMetaTypeId<CDistributor>(), qMetaTypeId<CDistributorList>()});
|
||||
ui->le_Distributor->setValidator(new CUpperCaseValidator(this));
|
||||
|
||||
Reference in New Issue
Block a user