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)
44 this->setAcceptDrops(
true);
49 connect(ui->le_Livery, &QLineEdit::returnPressed,
this, &CDbLiverySelectorComponent::onDataChanged);
50 connect(ui->le_Livery, &QLineEdit::editingFinished,
this, &CDbLiverySelectorComponent::onDataChanged);
53 &CDbLiverySelectorComponent::onLiveriesRead, Qt::QueuedConnection);
54 this->onLiveriesRead(CEntityFlags::LiveryEntity, CEntityFlags::ReadFinished,
67 ui->le_Livery->clear();
71 if (livery != m_currentLivery)
74 m_currentLivery = livery;
82 const int dbKey = CDatastoreUtility::extractIntegerKey(code);
89 const QString liveryCode = this->stripExtraInfo(code.toUpper().trimmed());
97 ui->lbl_Description->setText(
"");
98 ui->le_Livery->setText(code);
106 const QString raw = ui->le_Livery->text();
107 const int dbKey = CDatastoreUtility::extractIntegerKey(raw);
113 const QString liveryCode(this->stripExtraInfo(ui->le_Livery->text()));
123 return m_currentLivery;
128 const QString cc(ui->le_Livery->text().trimmed().toUpper());
136 ui->lbl_Description->setVisible(description);
145 if (!event || !
acceptDrop(event->mimeData())) {
return; }
146 this->setBackgroundRole(QPalette::Highlight);
147 event->acceptProposedAction();
152 if (!event || !
acceptDrop(event->mimeData())) {
return; }
153 event->acceptProposedAction();
158 if (!event) {
return; }
164 if (!event || !
acceptDrop(event->mimeData())) {
return; }
177 if (liveries.
isEmpty()) {
return; }
183 void CDbLiverySelectorComponent::onLiveriesRead(CEntityFlags::Entity entity,
CEntityFlags::ReadState readState,
184 int count,
const QUrl &url)
189 if (entity.testFlag(CEntityFlags::LiveryEntity) && CEntityFlags::isFinishedReadState(readState))
194 QCompleter *c =
new QCompleter(codes,
this);
195 c->setCaseSensitivity(Qt::CaseInsensitive);
196 c->setCompletionMode(QCompleter::PopupCompletion);
197 c->setMaxVisibleItems(10);
198 connect(c, qOverload<const QString &>(&QCompleter::activated),
this,
199 &CDbLiverySelectorComponent::onCompleterActivated);
201 ui->le_Livery->setCompleter(c);
202 m_completerLiveries.reset(c);
204 else { m_completerLiveries.reset(
nullptr); }
208 void CDbLiverySelectorComponent::onDataChanged()
211 const QString raw = ui->le_Livery->text();
215 void CDbLiverySelectorComponent::onCompleterActivated(
const QString &liveryCode) { this->
setLivery(liveryCode); }
217 QString CDbLiverySelectorComponent::stripExtraInfo(
const QString &liveryCode)
const
219 if (liveryCode.isEmpty()) {
return {}; }
220 const QString l(liveryCode.trimmed().toUpper());
221 int is = l.indexOf(
' ');
222 int ib = l.indexOf(
'(');
223 int i = qMin(is, ib);
224 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.
virtual void dragMoveEvent(QDragMoveEvent *event)
swift::misc::aviation::CLivery getLivery() const
Livery.
virtual void dragEnterEvent(QDragEnterEvent *event)
virtual ~CDbLiverySelectorComponent()
Destructor.
void withLiveryDescription(bool description)
Show description.
bool isSet() const
Set with valid Livery.
virtual 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.
virtual void dragLeaveEvent(QDragLeaveEvent *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 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.