7 #include <QDragEnterEvent>
8 #include <QDragLeaveEvent>
9 #include <QDragMoveEvent>
17 #include "ui_dbaircrafticaoselectorcomponent.h"
32 using namespace swift::misc::aviation;
33 using namespace swift::misc::db;
34 using namespace swift::misc::network;
38 CDbAircraftIcaoSelectorComponent::CDbAircraftIcaoSelectorComponent(QWidget *parent)
42 this->setFocusProxy(ui->le_Aircraft);
43 this->setAcceptDrops(
true);
47 connect(ui->le_Aircraft, &QLineEdit::editingFinished,
this, &CDbAircraftIcaoSelectorComponent::onDataChanged);
51 &CDbAircraftIcaoSelectorComponent::onCodesRead, Qt::QueuedConnection);
52 this->onCodesRead(CEntityFlags::AircraftIcaoEntity, CEntityFlags::ReadFinished,
70 ui->le_Aircraft->setText(icaoStr);
72 if (setIcao == m_currentIcao) {
return false; }
74 m_currentIcao = setIcao;
82 ui->lbl_Description->setText(
"");
88 const QString text(ui->le_Aircraft->text().trimmed().toUpper());
89 const int key = CDatastoreUtility::extractIntegerKey(text);
92 const QString icaoOnly = CDatastoreUtility::stripKeyInParentheses(text);
93 if (m_currentIcao.
getDesignator() == icaoOnly) {
return m_currentIcao; }
100 const QString icaoOnly = CDatastoreUtility::stripKeyInParentheses(text);
101 if (m_currentIcao.
getDesignator() == icaoOnly) {
return m_currentIcao; }
116 ui->lbl_Description->setVisible(description);
129 if (!event || !
acceptDrop(event->mimeData())) {
return; }
130 setBackgroundRole(QPalette::Highlight);
131 event->acceptProposedAction();
136 if (!event || !
acceptDrop(event->mimeData())) {
return; }
137 event->acceptProposedAction();
142 if (!event) {
return; }
148 if (!event || !
acceptDrop(event->mimeData())) {
return; }
161 if (icaos.
isEmpty()) {
return; }
167 const QStringList &CDbAircraftIcaoSelectorComponent::completerStrings()
169 static const QStringList empty;
172 if (c != m_completerStrings.size())
175 icaos.removeInvalidCombinedCodes();
176 m_completerStrings = icaos.toCompleterStrings(
true,
true,
true,
true);
178 return m_completerStrings;
181 void CDbAircraftIcaoSelectorComponent::onCodesRead(CEntityFlags::Entity entity,
CEntityFlags::ReadState readState,
185 if (entity.testFlag(CEntityFlags::AircraftIcaoEntity) && CEntityFlags::isFinishedReadState(readState))
189 QCompleter *c =
new QCompleter(this->completerStrings(),
this);
190 c->setCaseSensitivity(Qt::CaseInsensitive);
191 c->setCompletionMode(QCompleter::PopupCompletion);
192 c->setMaxVisibleItems(10);
193 const int w5chars = c->popup()->fontMetrics().size(Qt::TextSingleLine,
"FooBa").width();
194 c->popup()->setMinimumWidth(w5chars * 10);
196 connect(c, qOverload<const QString &>(&QCompleter::activated),
this,
197 &CDbAircraftIcaoSelectorComponent::onCompleterActivated);
199 ui->le_Aircraft->setCompleter(c);
200 m_completerIcaoDescription.reset(c);
203 else { m_completerIcaoDescription.reset(
nullptr); }
207 void CDbAircraftIcaoSelectorComponent::onDataChanged()
210 const int key = CDatastoreUtility::extractIntegerKey(ui->le_Aircraft->text());
225 void CDbAircraftIcaoSelectorComponent::onCompleterActivated(
const QString &icaoString)
227 const int dbKey = CDatastoreUtility::extractIntegerKey(icaoString);
228 if (dbKey < 0) {
return; }
SWIFT_CORE_EXPORT swift::core::CApplication * sApp
Single instance of application object.
bool hasWebDataServices() const
Web data services available?
bool isShuttingDown() const
Is application shutting down?
CWebDataServices * getWebDataServices() const
Get the web data services.
swift::misc::aviation::CAircraftIcaoCode smartAircraftIcaoSelector(const swift::misc::aviation::CAircraftIcaoCode &icao) const
Use an ICAO object to select the best complete ICAO object from DB for it.
swift::misc::aviation::CAircraftIcaoCode getAircraftIcaoCodeForDbKey(int id) const
ICAO code for id.
int getAircraftIcaoCodesCount() const
Aircraft ICAO codes count.
swift::misc::aviation::CAircraftIcaoCodeList getAircraftIcaoCodes() const
Aircraft ICAO codes.
bool acceptDrop(const QMimeData *mime) const
Accept drop?
swift::misc::CVariant toCVariant(const QMimeData *mime) const
Mime data to CVariant (normally encapsulating a value object)
void setAcceptedMetaTypeIds(const QList< int > &ids)
Accepted ids.
QString getRawDesignator() const
Raw designator.
virtual ~CDbAircraftIcaoSelectorComponent()
Destructor.
swift::misc::aviation::CAircraftIcaoCode getAircraftIcao() const
ICAO code.
virtual void dragLeaveEvent(QDragLeaveEvent *event)
void displayWithIcaoDescription(bool description)
Display distributor description.
bool isSet() const
Set with valid Distributor.
void clear()
Clear selection.
void changedAircraftIcao(const swift::misc::aviation::CAircraftIcaoCode &icao)
ICAO was changed.
virtual void dragEnterEvent(QDragEnterEvent *event)
void setReadOnly(bool readOnly)
Read only.
virtual void dragMoveEvent(QDragMoveEvent *event)
bool setAircraftIcao(const swift::misc::aviation::CAircraftIcaoCode &icao)
Current aircraft ICAO.
virtual void dropEvent(QDropEvent *event)
reference front()
Access the first element.
bool isEmpty() const
Synonym for empty.
Wrapper around QVariant which provides transparent access to CValueObject methods of the contained ob...
T value() const
Return the value converted to the type T.
bool isValid() const
True if this variant is valid.
bool canConvert(int typeId) const
True if this variant can be converted to the type with the given metatype ID.
Value object for ICAO classification.
bool isNull() const
Null ICAO?
QString getCombinedIcaoStringWithKey() const
Combined ICAO descriptive string with key.
const QString & getDesignator() const
Get ICAO designator, e.g. "B737".
QString getDesignatorDbKey() const
Designator and DB key.
bool hasCompleteData() const
All data set?
const QString & getManufacturer() const
Get manufacturer, e.g. "Airbus".
Value object encapsulating a list of ICAO codes.
bool isLoadedFromDb() const
Loaded from DB.
bool hasValidDbKey() const
Has valid DB key.
ReadState
State of operation.
SWIFT_GUI_EXPORT swift::gui::CGuiApplication * sGui
Single instance of GUI application object.
Backend services of the swift project, like dealing with the network or the simulators.
High level reusable GUI components.
Free functions in swift::misc.
SWIFT_MISC_EXPORT QString stripDesignatorFromCompleterString(const QString &candidate)
Strip a designator from a combined string.