7 #include <QDragEnterEvent>
8 #include <QDragLeaveEvent>
9 #include <QDragMoveEvent>
15 #include <QStringList>
19 #include "ui_dbliveryselectorcomponent.h"
34 using namespace swift::misc::aviation;
35 using namespace swift::misc::db;
36 using namespace swift::misc::network;
40 CDbLiverySelectorComponent::CDbLiverySelectorComponent(
QWidget *parent)
54 this->onLiveriesRead(CEntityFlags::LiveryEntity, CEntityFlags::ReadFinished,
64 ui->le_Livery->clear();
68 if (livery != m_currentLivery)
71 m_currentLivery = livery;
79 const int dbKey = CDatastoreUtility::extractIntegerKey(code);
94 ui->lbl_Description->setText(
"");
95 ui->le_Livery->setText(code);
103 const QString raw = ui->le_Livery->text();
104 const int dbKey = CDatastoreUtility::extractIntegerKey(raw);
110 const QString liveryCode(this->stripExtraInfo(ui->le_Livery->text()));
120 return m_currentLivery;
125 const QString cc(ui->le_Livery->text().trimmed().toUpper());
133 ui->lbl_Description->setVisible(description);
144 event->acceptProposedAction();
150 event->acceptProposedAction();
155 if (!
event) {
return; }
168 if (!livery.hasValidDbKey()) {
return; }
174 if (liveries.isEmpty()) {
return; }
180 void CDbLiverySelectorComponent::onLiveriesRead(CEntityFlags::Entity entity,
CEntityFlags::ReadState readState,
181 int count,
const QUrl &url)
186 if (entity.testFlag(CEntityFlags::LiveryEntity) && CEntityFlags::isFinishedReadState(readState))
194 c->setMaxVisibleItems(10);
196 &CDbLiverySelectorComponent::onCompleterActivated);
198 ui->le_Livery->setCompleter(c);
199 m_completerLiveries.
reset(c);
201 else { m_completerLiveries.
reset(
nullptr); }
205 void CDbLiverySelectorComponent::onDataChanged()
208 const QString raw = ui->le_Livery->text();
212 void CDbLiverySelectorComponent::onCompleterActivated(
const QString &liveryCode) { this->
setLivery(liveryCode); }
214 QString CDbLiverySelectorComponent::stripExtraInfo(
const QString &liveryCode)
const
216 if (liveryCode.
isEmpty()) {
return {}; }
218 int is = l.indexOf(
' ');
219 int ib = l.indexOf(
'(');
220 int i = qMin(is, ib);
221 if (i < 0) {
return l; }
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::CLiveryList getLiveries() const
Liveries.
swift::misc::aviation::CLivery getLiveryForDbKey(int id) const
Livery for id.
int getLiveriesCount() const
Liveries count.
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 getRawCombinedCode() const
Livery combined code.
void setLivery(const swift::misc::aviation::CLivery &livery)
Current livery.
void dragMoveEvent(QDragMoveEvent *event)
swift::misc::aviation::CLivery getLivery() const
Livery.
void dragEnterEvent(QDragEnterEvent *event)
~CDbLiverySelectorComponent()
Destructor.
void withLiveryDescription(bool description)
Show description.
bool isSet() const
Set with valid Livery.
void dropEvent(QDropEvent *event)
void clear()
Clear selection.
void changedLivery(const swift::misc::aviation::CLivery &livery)
Distributor was changed.
void setReadOnly(bool readOnly)
Read only.
void dragLeaveEvent(QDragLeaveEvent *event)
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 encapsulating information about an airpot.
bool matchesCombinedCode(const QString &candidate) const
Matches combined code.
bool hasCompleteData() const
Complete data?
QString getCombinedCodePlusId() const
Combined code plus id.
bool hasCombinedCode() const
Livery combined code available?
Value object for a list of airports.
QStringList getCombinedCodesPlusInfoAndId(bool sort=false) const
All combined codes plus more info.
CLivery findByCombinedCode(const QString &combinedCode) const
Find livery by combined code.
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.
void activated(const QModelIndex &index)
virtual bool event(QEvent *e) override
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool isEmpty() const const
QString toUpper() const const
QString trimmed() const const