swift
dbairlinenameselectorcomponent.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 <QCompleter>
7 #include <QLineEdit>
8 #include <QString>
9 #include <Qt>
10 
11 #include "ui_dbairlinenameselectorcomponent.h"
12 
13 #include "core/webdataservices.h"
14 #include "gui/guiapplication.h"
17 
18 using namespace swift::core;
19 using namespace swift::gui;
20 using namespace swift::misc;
21 using namespace swift::misc::aviation;
22 using namespace swift::misc::db;
23 
24 namespace swift::gui::components
25 {
26  CDbAirlineNameSelectorComponent::CDbAirlineNameSelectorComponent(QWidget *parent)
28  {
29  ui->setupUi(this);
30  this->setFocusProxy(ui->le_AirlineName);
31  connect(ui->le_AirlineName, &QLineEdit::editingFinished, this,
32  &CDbAirlineNameSelectorComponent::ps_dataChanged);
33  }
34 
36  {
37  // no inline destructor, read QScopedPointer Forward Declared Pointers
38  }
39 
41  {
42  if (!CDbAirlineIcaoSelectorBase::setAirlineIcao(icao)) { return false; }
43  const QString name(icao.getName());
44  ui->le_AirlineName->setText(name);
45  return true;
46  }
47 
48  void CDbAirlineNameSelectorComponent::clear() { ui->le_AirlineName->clear(); }
49 
50  void CDbAirlineNameSelectorComponent::setReadOnly(bool readOnly) { ui->le_AirlineName->setReadOnly(readOnly); }
51 
53  {
54  QCompleter *c =
56  c->setCaseSensitivity(Qt::CaseInsensitive);
57  c->setCompletionMode(QCompleter::PopupCompletion);
58  c->setMaxVisibleItems(10);
59  const int w5chars = c->popup()->fontMetrics().size(Qt::TextSingleLine, "FooBa").width();
60  c->popup()->setMinimumWidth(w5chars * 10);
61  ui->le_AirlineName->setCompleter(c);
62  return c;
63  }
64 
65  void CDbAirlineNameSelectorComponent::ps_dataChanged()
66  {
67  if (!sGui) { return; }
68  QString s(ui->le_AirlineName->text());
69  if (s.isEmpty()) { return; }
70  int dbKey = CDatastoreUtility::extractIntegerKey(s);
71  if (dbKey >= 0)
72  {
74  this->setAirlineIcao(icao);
75  }
76  }
77 } // namespace swift::gui::components
CWebDataServices * getWebDataServices() const
Get the web data services.
swift::misc::aviation::CAirlineIcaoCode getAirlineIcaoCodeForDbKey(int id) const
ICAO code for id.
swift::misc::aviation::CAirlineIcaoCodeList getAirlineIcaoCodes() const
Airline ICAO codes.
virtual bool setAirlineIcao(const swift::misc::aviation::CAirlineIcaoCode &icao)
Current airline ICAO.
virtual QCompleter * createCompleter()
Create a new completer.
virtual bool setAirlineIcao(const swift::misc::aviation::CAirlineIcaoCode &icao)
Current airline ICAO.
Value object for ICAO classification.
const QString & getName() const
Get name, e.g. "Lufthansa".
QStringList toNameCompleterStrings(bool sort=true) const
String list for completion by name.
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.
Definition: actionbind.cpp:7
High level reusable GUI components.
Definition: aboutdialog.cpp:13
GUI related classes.
Free functions in swift::misc.