swift
Loading...
Searching...
No Matches
aircraftcombinedtypeselector.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#include <QComboBox>
7#include <QLineEdit>
8#include <QStringBuilder>
9#include <QtGlobal>
10
11#include "ui_aircraftcombinedtypeselector.h"
12
13#include "gui/guiutility.h"
16
17using namespace swift::misc::aviation;
18
20{
23 {
24 ui->setupUi(this);
25 connect(ui->le_CombinedType, &QLineEdit::editingFinished, this,
26 &CAircraftCombinedTypeSelector::combinedTypeEntered);
27 connect(ui->le_CombinedType, &QLineEdit::returnPressed, this,
28 &CAircraftCombinedTypeSelector::combinedTypeEntered);
29
30 connect(ui->cb_EngineCount, &QComboBox::currentTextChanged, this,
31 &CAircraftCombinedTypeSelector::changedComboBox);
32 connect(ui->cb_EngineType, &QComboBox::currentTextChanged, this,
33 &CAircraftCombinedTypeSelector::changedComboBox);
34 connect(ui->cb_Type, &QComboBox::currentTextChanged, this, &CAircraftCombinedTypeSelector::changedComboBox);
35
36 ui->le_CombinedType->setValidator(new CUpperCaseValidator(this));
37 }
38
40
42 {
43 QString engineCount, engineType, aircraftType;
44 const QString cc(combinedCode.trimmed().toUpper().left(3));
45 if (m_cc == cc)
46 {
47 return;
48 }
49 m_cc = cc;
50
51 if (cc.length() > 0)
52 {
53 aircraftType = cc.at(0);
54 }
55 if (cc.length() > 1)
56 {
57 engineCount = cc.mid(1, 1);
58 }
59 if (cc.length() > 2)
60 {
61 engineType = cc.mid(2, 1);
62 }
63
64 if (this->getCombinedTypeFromComboBoxes() != cc)
65 {
66 CGuiUtility::setComboBoxValueByStartingString(ui->cb_EngineCount, engineCount, "unspecified");
67 CGuiUtility::setComboBoxValueByStartingString(ui->cb_EngineType, engineType, "unspecified");
68 CGuiUtility::setComboBoxValueByStartingString(ui->cb_Type, aircraftType, "unspecified");
69 }
70
71 if (ui->le_CombinedType->text() != cc)
72 {
73 ui->le_CombinedType->setText(cc);
74 }
75 emit this->changedCombinedType(cc);
76 }
77
82
84 {
85 this->setCombinedType("");
86 ui->le_CombinedType->clear();
87 }
88
90 {
91 ui->le_CombinedType->setReadOnly(readOnly);
92 ui->cb_EngineCount->setEnabled(!readOnly);
93 ui->cb_EngineType->setEnabled(!readOnly);
94 ui->cb_Type->setEnabled(!readOnly);
95 }
96
98 {
99 QString ct(ui->le_CombinedType->text().trimmed().toUpper());
100 if (ct.isEmpty() || ct == QStringView(u"---"))
101 {
102 return {};
103 }
105 {
106 return ct;
107 }
108
109 QString ct2(getCombinedTypeFromComboBoxes());
110 return ct2;
111 }
112
113 void CAircraftCombinedTypeSelector::combinedTypeEntered()
114 {
115 const QString cc(ui->le_CombinedType->text().trimmed().toUpper() % u"---");
116 this->setCombinedType(cc.left(3));
117 }
118
119 void CAircraftCombinedTypeSelector::changedComboBox(const QString &text)
120 {
121 Q_UNUSED(text);
122 const QString ct(this->getCombinedTypeFromComboBoxes());
123 if (ui->le_CombinedType->text() == ct)
124 {
125 return;
126 }
127 ui->le_CombinedType->setText(ct);
128 emit this->changedCombinedType(ct);
129 }
130
131 QString CAircraftCombinedTypeSelector::getCombinedTypeFromComboBoxes() const
132 {
133 // try to get from combox boxes instead
134 QString ec = ui->cb_EngineCount->currentText().left(1);
135 QString t = ui->cb_Type->currentText().left(1);
136 QString et = ui->cb_EngineType->currentText().left(1);
137
138 QString ct2(QString(t + ec + et).toUpper());
139 return ct2.replace('U', '-');
140 }
141} // namespace swift::gui::components
static bool setComboBoxValueByStartingString(QComboBox *box, const QString &candidate, const QString &unspecified=QString())
Find best match in comboBox.
void setCombinedType(const QString &combinedCode)
Set comined code, e.g. L1P.
void changedCombinedType(const QString &cominedType)
Combined type has beend changed.
QString getCombinedType() const
Get the combined type, e.g. "L2P".
Value object for ICAO classification.
static bool isValidCombinedType(const QString &combinedType)
Valid combined type.
const QString & getCombinedType() const
Get type, e.g. "L2J".
High level reusable GUI components.
void currentTextChanged(const QString &text)
QFrame(QWidget *parent, Qt::WindowFlags f)
void editingFinished()
void returnPressed()
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
const QChar at(qsizetype position) const const
bool isEmpty() const const
QString left(qsizetype n) &&
qsizetype length() const const
QString mid(qsizetype position, qsizetype n) &&
QString toUpper() const const
QString trimmed() const const
QWidget(QWidget *parent, Qt::WindowFlags f)