diff --git a/src/blackgui/components/aircraftmodelstringcompleter.cpp b/src/blackgui/components/aircraftmodelstringcompleter.cpp new file mode 100644 index 000000000..ea592ca06 --- /dev/null +++ b/src/blackgui/components/aircraftmodelstringcompleter.cpp @@ -0,0 +1,158 @@ +/* Copyright (C) 2016 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "aircraftmodelstringcompleter.h" +#include "ui_aircraftmodelstringcompleter.h" +#include "blackgui/guiapplication.h" +#include "blackgui/uppercasevalidator.h" +#include "blackcore/webdataservices.h" +#include "blackcore/context/contextsimulator.h" +#include +#include + +using namespace BlackCore; +using namespace BlackCore::Context; + +namespace BlackGui +{ + namespace Components + { + CAircraftModelStringCompleter::CAircraftModelStringCompleter(QWidget *parent) : + QFrame(parent), + ui(new Ui::CAircraftModelStringCompleter) + { + Q_ASSERT_X(sGui, Q_FUNC_INFO, "missing sGui"); + Q_ASSERT_X(sGui->hasWebDataServices(), Q_FUNC_INFO, "missing web services"); + + ui->setupUi(this); + ui->le_modelString->setValidator(new CUpperCaseValidator(ui->le_modelString)); + + connect(ui->le_modelString, &QLineEdit::editingFinished, this, &CAircraftModelStringCompleter::ps_textChanged); + connect(sGui->getWebDataServices(), &CWebDataServices::allSwiftDbDataRead, this, &CAircraftModelStringCompleter::ps_swiftWebDataRead); + connect(ui->rb_Db, &QRadioButton::clicked, this, &CAircraftModelStringCompleter::ps_initGui); + connect(ui->rb_ModelSet, &QRadioButton::clicked, this, &CAircraftModelStringCompleter::ps_initGui); + connect(ui->rb_OwnModels, &QRadioButton::clicked, this, &CAircraftModelStringCompleter::ps_initGui); + + if (sGui->getIContextSimulator()) + { + connect(sGui->getIContextSimulator(), &IContextSimulator::simulatorStatusChanged, this, &CAircraftModelStringCompleter::ps_simulatorConnected); + } + } + + CAircraftModelStringCompleter::~CAircraftModelStringCompleter() + { } + + QString CAircraftModelStringCompleter::getModelString() const + { + return ui->le_modelString->text(); + } + + void CAircraftModelStringCompleter::showSourceSelection(bool show) + { + ui->wi_SourceSelection->setVisible(!show); + } + + void CAircraftModelStringCompleter::setText(const QString &completersString) + { + if (ui->le_modelString->text() == completersString) { return; } + ui->le_modelString->setText(completersString); + } + + void CAircraftModelStringCompleter::setModel(const BlackMisc::Simulation::CAircraftModel &model) + { + this->setText(model.getModelString()); + } + + void CAircraftModelStringCompleter::setSourceVisible(CompleterSource source, bool visible) + { + if (source.testFlag(DB)) { ui->rb_Db->setVisible(visible); } + if (source.testFlag(ModelSet)) { ui->rb_ModelSet->setVisible(visible); } + if (source.testFlag(OwnModels)) { ui->rb_OwnModels->setVisible(visible); } + } + + void CAircraftModelStringCompleter::selectSource(CAircraftModelStringCompleter::CompleterSourceFlag source) + { + switch (source) + { + case DB: ui->rb_Db->setChecked(true); break; + case ModelSet: ui->rb_ModelSet->setChecked(true); break; + case OwnModels: ui->rb_OwnModels->setChecked(true); break; + default: ui->rb_ModelSet->setChecked(true); break; + } + } + + void CAircraftModelStringCompleter::clear() + { + ui->le_modelString->clear(); + } + + void CAircraftModelStringCompleter::setCompleter() + { + QStringList modelStrings; + if (ui->rb_Db->isChecked()) + { + modelStrings = sGui->getWebDataServices()->getModelStrings(); + } + else if (ui->rb_ModelSet->isChecked()) + { + if (!this->m_completerOwnModels) + { + const QStringList modelStrings = sGui->getIContextSimulator()->getInstalledModels().getModelStringList(); + this->m_completerModelSet = new QCompleter(modelStrings, this); + setCompleterParameters(this->m_completerModelSet); + } + ui->le_modelString->setCompleter(this->m_completerOwnModels); + } + else if (ui->rb_OwnModels->isChecked()) + { + if (!this->m_completerOwnModels) + { + const QStringList modelStrings = sGui->getIContextSimulator()->getInstalledModels().getModelStringList(); + this->m_completerOwnModels = new QCompleter(modelStrings, this); + setCompleterParameters(this->m_completerOwnModels); + } + ui->le_modelString->setCompleter(this->m_completerOwnModels); + modelStrings = sGui->getIContextSimulator()->getModelSet().getModelStringList(); + } + + ui->le_modelString->setCompleter(new QCompleter(modelStrings, this)); + ui->le_modelString->setPlaceholderText(QString("model strings (%1)").arg(modelStrings.size())); + } + + void CAircraftModelStringCompleter::setCompleterParameters(QCompleter *completer) + { + completer->setCaseSensitivity(Qt::CaseInsensitive); + completer->setWrapAround(true); + completer->setModelSorting(QCompleter::CaseInsensitivelySortedModel); + completer->setCompletionMode(QCompleter::InlineCompletion); + } + + void CAircraftModelStringCompleter::ps_textChanged() + { + emit this->modelStringChanged(); + } + + void CAircraftModelStringCompleter::ps_initGui() + { + this->setCompleter(); + } + + void CAircraftModelStringCompleter::ps_simulatorConnected(int status) + { + // reinit because sim changed + Q_UNUSED(status); + this->ps_initGui(); + } + + void CAircraftModelStringCompleter::ps_swiftWebDataRead() + { + this->ps_initGui(); + } + } // ns +} // ns diff --git a/src/blackgui/components/aircraftmodelstringcompleter.h b/src/blackgui/components/aircraftmodelstringcompleter.h new file mode 100644 index 000000000..4fb945413 --- /dev/null +++ b/src/blackgui/components/aircraftmodelstringcompleter.h @@ -0,0 +1,100 @@ +/* Copyright (C) 2016 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKGUI_COMPLETER_AIRCRAFTMODELSTRINGCOMPLETER_H +#define BLACKGUI_COMPLETER_AIRCRAFTMODELSTRINGCOMPLETER_H + +#include "blackmisc/simulation/aircraftmodel.h" +#include +#include +#include +#include + +namespace Ui { class CAircraftModelStringCompleter; } +namespace BlackGui +{ + namespace Components + { + /*! + * Completer for model strings + */ + class CAircraftModelStringCompleter : public QFrame + { + Q_OBJECT + + public: + + //! Sources for string completion + enum CompleterSourceFlag { + DB, + ModelSet, + OwnModels + }; + Q_DECLARE_FLAGS(CompleterSource, CompleterSourceFlag) + + //! Constructor + explicit CAircraftModelStringCompleter(QWidget *parent = nullptr); + + //! Destructor + ~CAircraftModelStringCompleter(); + + //! The model string + QString getModelString() const; + + //! Show the selection buttons + void showSourceSelection(bool show); + + //! Set text + void setText(const QString &completersString); + + //! Set model + void setModel(const BlackMisc::Simulation::CAircraftModel &model); + + //! Show/hide radio buttons + void setSourceVisible(CompleterSource source, bool visible); + + //! Set the currently selected source + void selectSource(CompleterSourceFlag source); + + //! Clear + void clear(); + + signals: + //! Model has been changed + void modelStringChanged(); + + private: + //! Set the completer + void setCompleter(); + + //! How completer behaves + static void setCompleterParameters(QCompleter *completer); + + private slots: + //! Value has been changed + void ps_textChanged(); + + //! Init the GUI + void ps_initGui(); + + //! Simulator connected + void ps_simulatorConnected(int status); + + //! All swift data have been read + void ps_swiftWebDataRead(); + + private: + QScopedPointer ui; + }; + } // ns +} // ns + +#endif // guard diff --git a/src/blackgui/components/aircraftmodelstringcompleter.ui b/src/blackgui/components/aircraftmodelstringcompleter.ui new file mode 100644 index 000000000..b990b6d72 --- /dev/null +++ b/src/blackgui/components/aircraftmodelstringcompleter.ui @@ -0,0 +1,94 @@ + + + CAircraftModelStringCompleter + + + + 0 + 0 + 301 + 22 + + + + Frame + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 150 + 0 + + + + model string + + + + + + + + 4 + + + 0 + + + 4 + + + 0 + + + + + DB + + + true + + + + + + + own model set + + + set + + + + + + + all installed models + + + inst. + + + + + + + + + + + diff --git a/src/blackgui/components/mappingcomponent.cpp b/src/blackgui/components/mappingcomponent.cpp index a010bc75c..3d44efce5 100644 --- a/src/blackgui/components/mappingcomponent.cpp +++ b/src/blackgui/components/mappingcomponent.cpp @@ -196,21 +196,21 @@ namespace BlackGui const CSimulatedAircraft simAircraft = ui->tvp_SimulatedAircraft->at(index); ui->cb_AircraftEnabled->setChecked(simAircraft.isEnabled()); ui->le_Callsign->setText(simAircraft.getCallsign().asString()); - ui->le_AircraftModel->setText(simAircraft.getModel().getModelString()); + ui->completer_ModelStrings->setModel(simAircraft.getModel()); } void CMappingComponent::ps_onModelSelectedInView(const QModelIndex &index) { const CAircraftModel model = ui->tvp_AircraftModels->at(index); - ui->le_AircraftModel->setText(model.getModelString()); + ui->completer_ModelStrings->setModel(model); if (ui->cb_AircraftIconDisplayed->isChecked()) { const int MaxHeight = 125; ui->lbl_AircraftIconDisplayed->setText(""); ui->lbl_AircraftIconDisplayed->setToolTip(model.getDescription()); - QString modelString(model.getModelString()); - CPixmap pm = sGui->getIContextSimulator()->iconForModel(modelString); + const QString modelString(model.getModelString()); + CPixmap pm = sGui->getIContextSimulator()->iconForModel(modelString); if (pm.isNull()) { ui->lbl_AircraftIconDisplayed->setPixmap(CIcons::crossWhite16()); @@ -233,7 +233,7 @@ namespace BlackGui void CMappingComponent::ps_onSaveAircraft() { - QString cs = ui->le_Callsign->text().trimmed(); + const QString cs = ui->le_Callsign->text().trimmed(); if (!CCallsign::isValidAircraftCallsign(cs)) { CLogMessage(this).validationError("Invalid callsign for mapping"); @@ -248,7 +248,7 @@ namespace BlackGui return; } - QString modelString = ui->le_AircraftModel->text().trimmed(); + const QString modelString = ui->completer_ModelStrings->getModelString(); if (modelString.isEmpty()) { CLogMessage(this).validationError("Missing model for mapping"); @@ -320,16 +320,8 @@ namespace BlackGui void CMappingComponent::ps_onModelsUpdateRequested() { - CAircraftModelList ml(sGui->getIContextSimulator()->getInstalledModels()); + const CAircraftModelList ml(sGui->getIContextSimulator()->getInstalledModels()); ui->tvp_AircraftModels->updateContainer(ml); - - // model completer - this->m_modelCompleter->setModel(new QStringListModel(ml.getModelStringList(), this->m_modelCompleter)); - this->m_modelCompleter->setModelSorting(QCompleter::CaseInsensitivelySortedModel); - this->m_modelCompleter->setCaseSensitivity(Qt::CaseInsensitive); - this->m_modelCompleter->setWrapAround(true); - this->m_modelCompleter->setCompletionMode(QCompleter::InlineCompletion); - ui->le_AircraftModel->setCompleter(this->m_modelCompleter); } void CMappingComponent::ps_onRemoteAircraftModelChanged(const CSimulatedAircraft &aircraft, const CIdentifier &originator) diff --git a/src/blackgui/components/mappingcomponent.ui b/src/blackgui/components/mappingcomponent.ui index fd71b3d4f..65b2030ce 100644 --- a/src/blackgui/components/mappingcomponent.ui +++ b/src/blackgui/components/mappingcomponent.ui @@ -13,13 +13,7 @@ Mapping component - - QFrame::StyledPanel - - - QFrame::Raised - - + 0 @@ -32,44 +26,8 @@ 0 - - 3 - - - - - Icon - - - - - - - aircraft icon will go here - - - - - - - show / hide icon - - - - - - false - - - - + - - - 0 - 0 - - 0 @@ -130,12 +88,6 @@ - - - 0 - 0 - - QAbstractItemView::SingleSelection @@ -149,43 +101,140 @@ + + + Matching log + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + - - - - - - - 15 - - - true - - - - - - - Aircraft - - - - - - - Save - - - - - - - enabled / disable - - - + + + + + 0 + 75 + + + + 3 + + + 3 + + + 3 + + + 3 + + + + + 15 + + + true + + + callsign + + + + + + + save + + + + + + + show / hide icon + + + + + + false + + + + + + + Aircraft + + + + + + + enabled / disable + + + + + + + + + + Icon + + + + + + + reset + + + + + + + icon will go here + + + + + + + + 0 + 20 + + + + + @@ -201,6 +250,18 @@ QTableView
blackgui/views/simulatedaircraftview.h
+ + BlackGui::Components::CModelMatcherLogComponent + QFrame +
blackgui/components/modelmatcherlogcomponent.h
+ 1 +
+ + BlackGui::Components::CAircraftModelStringCompleter + QFrame +
blackgui/components/aircraftmodelstringcompleter.h
+ 1 +