From a50e45e451e0e084139f2b8250f8e603bf93b46d Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 19 Mar 2015 03:39:33 +0100 Subject: [PATCH] Fixed updates of view when simulated aircraft values are updated. * renamed view to simulated aircraft view * utility function for bool -> on/off --- src/blackcore/context_network_impl.cpp | 10 +++- src/blackgui/components/mappingcomponent.cpp | 58 ++++++++++--------- src/blackgui/components/mappingcomponent.h | 5 +- src/blackgui/components/mappingcomponent.ui | 2 +- src/blackgui/views/simulatedaircraftview.cpp | 2 +- src/blackmisc/blackmiscfreefunctions.cpp | 18 +++++- src/blackmisc/blackmiscfreefunctions.h | 6 ++ .../simulation/simulatedaircraft.cpp | 4 +- src/swiftcore/tool.cpp | 2 +- 9 files changed, 69 insertions(+), 38 deletions(-) diff --git a/src/blackcore/context_network_impl.cpp b/src/blackcore/context_network_impl.cpp index 5f14a719d..bb820d197 100644 --- a/src/blackcore/context_network_impl.cpp +++ b/src/blackcore/context_network_impl.cpp @@ -521,7 +521,8 @@ namespace BlackCore bool c = this->m_airspace->updateAircraftEnabled(callsign, enabledForRedering, originator); if (c) { - emit this->changedAircraftEnabled(this->remoteAircraft().findFirstByCallsign(callsign), originator); + CSimulatedAircraft aircraft(this->remoteAircraft().findFirstByCallsign(callsign)); + emit this->changedAircraftEnabled(aircraft, originator); } return c; } @@ -532,7 +533,8 @@ namespace BlackCore bool c = this->m_airspace->updateAircraftModel(callsign, model, originator); if (c) { - emit this->changedRenderedAircraftModel(this->remoteAircraft().findFirstByCallsign(callsign), originator); + CSimulatedAircraft aircraft(this->remoteAircraft().findFirstByCallsign(callsign)); + emit this->changedRenderedAircraftModel(aircraft, originator); } return c; } @@ -543,7 +545,9 @@ namespace BlackCore bool c = this->m_airspace->updateFastPositionUpdates(callsign, enableFastPositonUpdates, originator); if (c) { - emit this->changedFastPositionUpdates(this->remoteAircraft().findFirstByCallsign(callsign), originator); + CSimulatedAircraft aircraft(this->remoteAircraft().findFirstByCallsign(callsign)); + CLogMessage(this).info("Callsign %1 sets fast positions ") << aircraft.getCallsign() << BlackMisc::boolToOnOff(aircraft.fastPositionUpdates()); + emit this->changedFastPositionUpdates(aircraft, originator); } return c; } diff --git a/src/blackgui/components/mappingcomponent.cpp b/src/blackgui/components/mappingcomponent.cpp index d6d668aca..cc6b3ad1e 100644 --- a/src/blackgui/components/mappingcomponent.cpp +++ b/src/blackgui/components/mappingcomponent.cpp @@ -39,26 +39,26 @@ namespace BlackGui { ui->setupUi(this); this->ui->tvp_AircraftModels->setAircraftModelMode(CAircraftModelListModel::ModelOnly); - this->ui->tvp_CurrentMappings->setAircraftMode(CSimulatedAircraftListModel::ModelMode); - this->ui->tvp_CurrentMappings->setResizeMode(CAircraftModelView::ResizingOnce); + this->ui->tvp_SimulatedAircraft->setAircraftMode(CSimulatedAircraftListModel::ModelMode); + this->ui->tvp_SimulatedAircraft->setResizeMode(CAircraftModelView::ResizingOnce); this->ui->tvp_AircraftModels->setResizeMode(CAircraftModelView::ResizingOff); connect(this->ui->tvp_AircraftModels, &CAircraftModelView::requestUpdate, this, &CMappingComponent::ps_onModelsUpdateRequested); connect(this->ui->tvp_AircraftModels, &CAircraftModelView::rowCountChanged, this, &CMappingComponent::ps_onRowCountChanged); connect(this->ui->tvp_AircraftModels, &CAircraftModelView::clicked, this, &CMappingComponent::ps_onModelSelectedInView); - connect(this->ui->tvp_CurrentMappings, &CSimulatedAircraftView::rowCountChanged, this, &CMappingComponent::ps_onRowCountChanged); - connect(this->ui->tvp_CurrentMappings, &CSimulatedAircraftView::clicked, this, &CMappingComponent::ps_onAircraftSelectedInView); - connect(this->ui->tvp_CurrentMappings, &CSimulatedAircraftView::requestUpdate, this, &CMappingComponent::ps_onMappingsUpdateRequested); - connect(this->ui->tvp_CurrentMappings, &CSimulatedAircraftView::requestTextMessageWidget, this, &CMappingComponent::requestTextMessageWidget); - connect(this->ui->tvp_CurrentMappings, &CSimulatedAircraftView::requestEnableAircraft, this, &CMappingComponent::ps_onMenuEnableAircraft); - connect(this->ui->tvp_CurrentMappings, &CSimulatedAircraftView::requestFastPositionUpdates, this, &CMappingComponent::ps_onMenuChangeFastPositionUpdates); + connect(this->ui->tvp_SimulatedAircraft, &CSimulatedAircraftView::rowCountChanged, this, &CMappingComponent::ps_onRowCountChanged); + connect(this->ui->tvp_SimulatedAircraft, &CSimulatedAircraftView::clicked, this, &CMappingComponent::ps_onAircraftSelectedInView); + connect(this->ui->tvp_SimulatedAircraft, &CSimulatedAircraftView::requestUpdate, this, &CMappingComponent::ps_onSimulatedAircraftUpdateRequested); + connect(this->ui->tvp_SimulatedAircraft, &CSimulatedAircraftView::requestTextMessageWidget, this, &CMappingComponent::requestTextMessageWidget); + connect(this->ui->tvp_SimulatedAircraft, &CSimulatedAircraftView::requestEnableAircraft, this, &CMappingComponent::ps_onMenuEnableAircraft); + connect(this->ui->tvp_SimulatedAircraft, &CSimulatedAircraftView::requestFastPositionUpdates, this, &CMappingComponent::ps_onMenuChangeFastPositionUpdates); connect(this->ui->pb_SaveAircraft, &QPushButton::clicked, this, &CMappingComponent::ps_onSaveAircraft); this->m_modelCompleter = new QCompleter(this); this->m_currentMappingsViewDelegate = new CCheckBoxDelegate(":/diagona/icons/diagona/icons/tick.png", ":/diagona/icons/diagona/icons/cross.png", this); - this->ui->tvp_CurrentMappings->setItemDelegateForColumn(0, this->m_currentMappingsViewDelegate); + this->ui->tvp_SimulatedAircraft->setItemDelegateForColumn(0, this->m_currentMappingsViewDelegate); //! Aircraft previews connect(this->ui->cb_AircraftIconDisplayed, &QCheckBox::stateChanged, this, &CMappingComponent::ps_onModelPreviewChanged); @@ -70,8 +70,8 @@ namespace BlackGui int CMappingComponent::countCurrentMappings() const { - Q_ASSERT(this->ui->tvp_CurrentMappings); - return this->ui->tvp_CurrentMappings->rowCount(); + Q_ASSERT(this->ui->tvp_SimulatedAircraft); + return this->ui->tvp_SimulatedAircraft->rowCount(); } int CMappingComponent::countAircraftModels() const @@ -94,10 +94,11 @@ namespace BlackGui connect(getIContextSimulator(), &IContextSimulator::modelMatchingCompleted, this, &CMappingComponent::ps_onModelMatchingCompleted); connect(getIContextNetwork(), &IContextNetwork::changedRenderedAircraftModel, this, &CMappingComponent::ps_onRenderedAircraftModelChanged); connect(getIContextNetwork(), &IContextNetwork::changedAircraftEnabled, this, &CMappingComponent::ps_onChangedAircraftEnabled); + connect(getIContextNetwork(), &IContextNetwork::changedFastPositionUpdates, this, &CMappingComponent::ps_onFastPositionUpdatesEnabled); connect(getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CMappingComponent::ps_onConnectionStatusChanged); // requires simulator context - connect(this->ui->tvp_CurrentMappings, &CAircraftModelView::objectChanged, this, &CMappingComponent::ps_onChangedSimulatedAircraftInView); + connect(this->ui->tvp_SimulatedAircraft, &CAircraftModelView::objectChanged, this, &CMappingComponent::ps_onChangedSimulatedAircraftInView); // with external core models might be already available this->ps_onAircraftModelsLoaded(); @@ -111,7 +112,7 @@ namespace BlackGui void CMappingComponent::ps_onModelMatchingCompleted(const BlackMisc::Simulation::CSimulatedAircraft &aircraft) { Q_UNUSED(aircraft); - this->ps_onMappingsUpdateRequested(); + this->ps_onSimulatedAircraftUpdateRequested(); } void CMappingComponent::ps_onRowCountChanged(int count, bool withFilter) @@ -149,7 +150,7 @@ namespace BlackGui void CMappingComponent::ps_onAircraftSelectedInView(const QModelIndex &index) { - const CSimulatedAircraft simAircraft = this->ui->tvp_CurrentMappings->at(index); + const CSimulatedAircraft simAircraft = this->ui->tvp_SimulatedAircraft->at(index); this->ui->cb_AircraftEnabled->setChecked(simAircraft.isEnabled()); this->ui->le_Callsign->setText(simAircraft.getCallsign().asString()); this->ui->le_AircraftModel->setText(simAircraft.getModel().getModelString()); @@ -198,7 +199,7 @@ namespace BlackGui } const CCallsign callsign(cs); - bool hasCallsign = this->ui->tvp_CurrentMappings->getContainer().containsCallsign(callsign); + bool hasCallsign = this->ui->tvp_SimulatedAircraft->getContainer().containsCallsign(callsign); if (!hasCallsign) { CLogMessage(this).validationError("Unmapped callsign %1 for mapping") << callsign.asString(); @@ -270,11 +271,9 @@ namespace BlackGui } } - void CMappingComponent::ps_onMappingsUpdateRequested() + void CMappingComponent::ps_onSimulatedAircraftUpdateRequested() { - Q_ASSERT(getIContextSimulator()); - const CSimulatedAircraftList aircraft = getIContextNetwork()->getAircraftInRange(); - this->ui->tvp_CurrentMappings->updateContainer(aircraft); + this->updateSimulatedAircraftView(); } void CMappingComponent::ps_onModelsUpdateRequested() @@ -294,22 +293,22 @@ namespace BlackGui void CMappingComponent::ps_onRenderedAircraftModelChanged(const CSimulatedAircraft &aircraft, const QString &originator) { - if (originator == mappingtOriginator()) { return; } - this->ps_onMappingsUpdateRequested(); + this->updateSimulatedAircraftView(); + Q_UNUSED(originator); Q_UNUSED(aircraft); } void CMappingComponent::ps_onChangedAircraftEnabled(const CSimulatedAircraft &aircraft, const QString &originator) { - if (originator == mappingtOriginator()) { return; } - this->ps_onMappingsUpdateRequested(); + this->updateSimulatedAircraftView(); + Q_UNUSED(originator); Q_UNUSED(aircraft); } void CMappingComponent::ps_onFastPositionUpdatesEnabled(const CSimulatedAircraft &aircraft, const QString &originator) { - if (originator == mappingtOriginator()) { return; } - this->ps_onMappingsUpdateRequested(); + this->updateSimulatedAircraftView(); + Q_UNUSED(originator); Q_UNUSED(aircraft); } @@ -320,7 +319,7 @@ namespace BlackGui Q_UNUSED(fromStatus); if (INetwork::isDisconnectedStatus(toStatus)) { - this->ui->tvp_CurrentMappings->clear(); + this->ui->tvp_SimulatedAircraft->clear(); } } @@ -348,5 +347,12 @@ namespace BlackGui return o; } + void CMappingComponent::updateSimulatedAircraftView() + { + Q_ASSERT_X(getIContextNetwork(), "updateSimulatedAircraftView", "missing network context"); + const CSimulatedAircraftList aircraft = getIContextNetwork()->getAircraftInRange(); + this->ui->tvp_SimulatedAircraft->updateContainer(aircraft); + } + } // namespace } // namespace diff --git a/src/blackgui/components/mappingcomponent.h b/src/blackgui/components/mappingcomponent.h index f5c1d4827..1bd808bb4 100644 --- a/src/blackgui/components/mappingcomponent.h +++ b/src/blackgui/components/mappingcomponent.h @@ -69,7 +69,7 @@ namespace BlackGui //! Changed count void ps_onRowCountChanged(int count, bool withFilter); - //! Simulated aircraft did change in model + //! Simulated aircraft did change in view //! \sa CViewBaseNonTemplate::objectChanged void ps_onChangedSimulatedAircraftInView(const BlackMisc::CVariant &simulatedAircraft, const BlackMisc::CPropertyIndex &index); @@ -86,7 +86,7 @@ namespace BlackGui void ps_onModelPreviewChanged(int state); //! Request update for mappings from backend - void ps_onMappingsUpdateRequested(); + void ps_onSimulatedAircraftUpdateRequested(); //! Request update for models from backend void ps_onModelsUpdateRequested(); @@ -111,6 +111,7 @@ namespace BlackGui private: static const QString &mappingtOriginator(); + void updateSimulatedAircraftView(); QScopedPointer ui; QCompleter *m_modelCompleter = nullptr; BlackGui::Views::CCheckBoxDelegate *m_currentMappingsViewDelegate = nullptr; diff --git a/src/blackgui/components/mappingcomponent.ui b/src/blackgui/components/mappingcomponent.ui index e19faa7ff..10f64163f 100644 --- a/src/blackgui/components/mappingcomponent.ui +++ b/src/blackgui/components/mappingcomponent.ui @@ -85,7 +85,7 @@ 0 - + QAbstractItemView::SingleSelection diff --git a/src/blackgui/views/simulatedaircraftview.cpp b/src/blackgui/views/simulatedaircraftview.cpp index 49830e16f..768c57cf5 100644 --- a/src/blackgui/views/simulatedaircraftview.cpp +++ b/src/blackgui/views/simulatedaircraftview.cpp @@ -61,7 +61,7 @@ namespace BlackGui CSimulatedAircraft aircraft(selectedObject()); if (aircraft.getCallsign().isEmpty()) { return; } aircraft.setEnabled(!aircraft.isEnabled()); - emit requestFastPositionUpdates(aircraft); + emit requestEnableAircraft(aircraft); } void CSimulatedAircraftView::ps_fastPositionUpdates() diff --git a/src/blackmisc/blackmiscfreefunctions.cpp b/src/blackmisc/blackmiscfreefunctions.cpp index 98e83848e..18e74c910 100644 --- a/src/blackmisc/blackmiscfreefunctions.cpp +++ b/src/blackmisc/blackmiscfreefunctions.cpp @@ -396,12 +396,12 @@ QJsonObject BlackMisc::getIncrementalObject(const QJsonObject &previousObject, c QJsonObject BlackMisc::applyIncrementalObject(const QJsonObject &previousObject, const QJsonObject &incrementalObject) { QJsonObject currentObject = previousObject; - for(const auto &key : incrementalObject.keys()) + for (const auto &key : incrementalObject.keys()) { // If it is not an object, just insert the value if (!incrementalObject.value(key).isObject()) { - currentObject.insert(key,incrementalObject.value(key)); + currentObject.insert(key, incrementalObject.value(key)); } else { @@ -411,3 +411,17 @@ QJsonObject BlackMisc::applyIncrementalObject(const QJsonObject &previousObject, } return currentObject; } + + +QString BlackMisc::boolToOnOff(bool v, bool i18n) +{ + Q_UNUSED(i18n); + return v ? "on" : "off"; +} + + +QString BlackMisc::boolToYesNo(bool v, bool i18n) +{ + Q_UNUSED(i18n); + return v ? "yes" : "no"; +} diff --git a/src/blackmisc/blackmiscfreefunctions.h b/src/blackmisc/blackmiscfreefunctions.h index 3e6f0748f..3bee391d6 100644 --- a/src/blackmisc/blackmiscfreefunctions.h +++ b/src/blackmisc/blackmiscfreefunctions.h @@ -171,6 +171,12 @@ namespace BlackMisc //! A map converted to string template QString qmapToString(const QMap &map); + //! Bool to on/off + QString boolToOnOff(bool v, bool i18n = false); + + //! Bool to yes / no + QString boolToYesNo(bool v, bool i18n = false); + //! Get local host name const QString &localHostName(); diff --git a/src/blackmisc/simulation/simulatedaircraft.cpp b/src/blackmisc/simulation/simulatedaircraft.cpp index 7c33cdda3..d4f753793 100644 --- a/src/blackmisc/simulation/simulatedaircraft.cpp +++ b/src/blackmisc/simulation/simulatedaircraft.cpp @@ -154,10 +154,10 @@ namespace BlackMisc { QString s = CAircraft::convertToQString(i18n); s += " enabled: "; - s += this->isEnabled() ? "yes" : "no"; + s += BlackMisc::boolToYesNo(this->isEnabled()); s += " "; s += " rendered: "; - s += this->isRendered() ? "yes" : "no"; + s += BlackMisc::boolToYesNo(this->isRendered()); s += " "; s += this->m_model.toQString(i18n); s += " "; diff --git a/src/swiftcore/tool.cpp b/src/swiftcore/tool.cpp index 532cfeed3..a06697767 100644 --- a/src/swiftcore/tool.cpp +++ b/src/swiftcore/tool.cpp @@ -58,7 +58,7 @@ namespace BlackMiscTest while (line != "x" && runtime) { qtout << "-------------" << endl; - qtout << "Connected with network: " << (runtime->getIContextNetwork()->isConnected() ? "yes" : "no") << endl; + qtout << "Connected with network: " << BlackMisc::boolToYesNo(runtime->getIContextNetwork()->isConnected()) << endl; qtout << "Thread id: " << QThread::currentThreadId() << endl; qtout << "-------------" << endl; qtout << "x .. to exit" << endl;