From 624eb7ca93c8b2b5fef856920ae526bbd6e1775c Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 19 Mar 2018 21:07:00 +0100 Subject: [PATCH] Ref T259, Ref T243 interpolation component and setup component --- .../components/interpolationcomponent.cpp | 30 +++ .../components/interpolationcomponent.h | 46 +++++ .../components/interpolationcomponent.ui | 98 ++++++++++ .../interpolationsetupcomponent.cpp | 164 ++++++++++++++++ .../components/interpolationsetupcomponent.h | 87 +++++++++ .../components/interpolationsetupcomponent.ui | 181 ++++++++++++++++++ 6 files changed, 606 insertions(+) create mode 100644 src/blackgui/components/interpolationcomponent.cpp create mode 100644 src/blackgui/components/interpolationcomponent.h create mode 100644 src/blackgui/components/interpolationcomponent.ui create mode 100644 src/blackgui/components/interpolationsetupcomponent.cpp create mode 100644 src/blackgui/components/interpolationsetupcomponent.h create mode 100644 src/blackgui/components/interpolationsetupcomponent.ui diff --git a/src/blackgui/components/interpolationcomponent.cpp b/src/blackgui/components/interpolationcomponent.cpp new file mode 100644 index 000000000..39fe3805c --- /dev/null +++ b/src/blackgui/components/interpolationcomponent.cpp @@ -0,0 +1,30 @@ +/* Copyright (C) 2018 + * 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 "interpolationcomponent.h" +#include "ui_interpolationcomponent.h" + +namespace BlackGui +{ + namespace Components + { + CInterpolationComponent::CInterpolationComponent(QWidget *parent) : + QFrame(parent), + ui(new Ui::CInterpolationComponent) + { + ui->setupUi(this); + ui->tw_InterpolationSetup->setCurrentIndex(0); + + connect(ui->comp_InterpolationSetup, &CInterpolationSetupComponent::requestRenderingRestrictionsWidget, this, &CInterpolationComponent::requestRenderingRestrictionsWidget); + } + + CInterpolationComponent::~CInterpolationComponent() + { } + } // ns +} // ns diff --git a/src/blackgui/components/interpolationcomponent.h b/src/blackgui/components/interpolationcomponent.h new file mode 100644 index 000000000..2b2fd7965 --- /dev/null +++ b/src/blackgui/components/interpolationcomponent.h @@ -0,0 +1,46 @@ +/* Copyright (C) 2018 + * 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_COMPONENTS_INTERPOLATIONCOMPONENT_H +#define BLACKGUI_COMPONENTS_INTERPOLATIONCOMPONENT_H + +#include +#include +#include "blackgui/blackguiexport.h" + +namespace Ui { class CInterpolationComponent; } +namespace BlackGui +{ + namespace Components + { + //! Interpolation + class BLACKGUI_EXPORT CInterpolationComponent : public QFrame + { + Q_OBJECT + + public: + //! Constructor + explicit CInterpolationComponent(QWidget *parent = nullptr); + + //! Destructor + virtual ~CInterpolationComponent(); + + signals: + //! Request redering restrictions widget + void requestRenderingRestrictionsWidget(); + + private: + QScopedPointer ui; + }; + } // ns +} // ns + +#endif // guard diff --git a/src/blackgui/components/interpolationcomponent.ui b/src/blackgui/components/interpolationcomponent.ui new file mode 100644 index 000000000..882ec2503 --- /dev/null +++ b/src/blackgui/components/interpolationcomponent.ui @@ -0,0 +1,98 @@ + + + CInterpolationComponent + + + + 0 + 0 + 640 + 480 + + + + Frame + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + + Setup + + + + 2 + + + 2 + + + 2 + + + 2 + + + + + + + + + Aircraft parts log + + + + 2 + + + 2 + + + 2 + + + 2 + + + + + + + + + + + + + BlackGui::Components::CAircraftPartsHistory + QFrame +
blackgui/components/aircraftpartshistory.h
+ 1 +
+ + BlackGui::Components::CInterpolationSetupComponent + QFrame +
blackgui/components/interpolationsetupcomponent.h
+ 1 +
+
+ + +
diff --git a/src/blackgui/components/interpolationsetupcomponent.cpp b/src/blackgui/components/interpolationsetupcomponent.cpp new file mode 100644 index 000000000..428f598da --- /dev/null +++ b/src/blackgui/components/interpolationsetupcomponent.cpp @@ -0,0 +1,164 @@ +/* Copyright (C) 2018 + * 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 "interpolationsetupcomponent.h" +#include "ui_interpolationsetupcomponent.h" +#include "blackgui/views/interpolationsetupview.h" +#include "blackgui/guiapplication.h" +#include "blackcore/context/contextsimulator.h" +#include "blackmisc/simulation/interpolationsetuplist.h" +#include "blackmisc/statusmessage.h" + +using namespace BlackGui::Views; +using namespace BlackMisc; +using namespace BlackMisc::Aviation; +using namespace BlackMisc::Simulation; + +namespace BlackGui +{ + namespace Components + { + CInterpolationSetupComponent::CInterpolationSetupComponent(QWidget *parent) : + COverlayMessagesFrame(parent), + ui(new Ui::CInterpolationSetupComponent) + { + ui->setupUi(this); + ui->tvp_InterpolationSetup->menuAddItems(CInterpolationSetupView::MenuRemoveSelectedRows); + + connect(ui->pb_RenderingSetup, &QPushButton::clicked, this, &CInterpolationSetupComponent::requestRenderingRestrictionsWidget); + connect(ui->pb_Save, &QPushButton::clicked, this, &CInterpolationSetupComponent::saveSetup); + connect(ui->pb_Delete, &QPushButton::clicked, this, &CInterpolationSetupComponent::removeSetup); + connect(ui->tvp_InterpolationSetup, &CInterpolationSetupView::doubleClicked, this, &CInterpolationSetupComponent::onRowDoubleClicked); + connect(ui->tvp_InterpolationSetup, &CInterpolationSetupView::modelChanged, this, &CInterpolationSetupComponent::onModelChanged); + + connect(ui->rb_Callsign, &QRadioButton::released, this, &CInterpolationSetupComponent::onModeChanged); + connect(ui->rb_Global, &QRadioButton::released, this, &CInterpolationSetupComponent::onModeChanged); + + ui->rb_Global->setChecked(true); + QTimer::singleShot(250, this, &CInterpolationSetupComponent::onModeChanged); + } + + CInterpolationSetupComponent::~CInterpolationSetupComponent() + { } + + CInterpolationSetupComponent::Mode CInterpolationSetupComponent::getSetupMode() const + { + return ui->rb_Callsign->isChecked() ? CInterpolationSetupComponent::PerCallsign : CInterpolationSetupComponent::Global; + } + + void CInterpolationSetupComponent::onRowDoubleClicked(const QModelIndex &index) + { + if (!index.isValid()) { return; } + const CInterpolationAndRenderingSetupPerCallsign setup = ui->tvp_InterpolationSetup->at(index); + ui->form_InterpolationSetup->setValue(setup); + ui->comp_CallsignCompleter->setCallsign(setup.getCallsign()); + ui->comp_CallsignCompleter->setReadOnly(false); + ui->rb_Callsign->setChecked(true); + } + + void CInterpolationSetupComponent::onModeChanged() + { + bool enableCallsign = false; + if (this->getSetupMode() == CInterpolationSetupComponent::Global) + { + this->setUiValuesFromGlobal(); + } + else + { + this->displaySetupsPerCallsign(); + enableCallsign = true; + } + ui->comp_CallsignCompleter->setReadOnly(!enableCallsign); + ui->pb_Delete->setEnabled(enableCallsign); + } + + void CInterpolationSetupComponent::onModelChanged() + { + const CInterpolationSetupList setups = ui->tvp_InterpolationSetup->container(); + this->setSetupsToContext(setups); + } + + void CInterpolationSetupComponent::saveSetup() + { + if (!this->checkPrerequisites()) { return; } + CInterpolationAndRenderingSetupPerCallsign setup = ui->form_InterpolationSetup->getValue(); + if (this->getSetupMode() == CInterpolationSetupComponent::Global) + { + CInterpolationAndRenderingSetupGlobal gs = sGui->getIContextSimulator()->getInterpolationAndRenderingSetupGlobal(); + gs.setBaseValues(setup); + sGui->getIContextSimulator()->setInterpolationAndRenderingSetupGlobal(gs); + } + else + { + const CCallsign cs = ui->comp_CallsignCompleter->getCallsign(false); + if (!cs.isValid()) { return; } + setup.setCallsign(cs); + CInterpolationSetupList setups = ui->tvp_InterpolationSetup->container(); + const int replaced = setups.replaceOrAddObjectByCallsign(setup); + if (replaced < 1) { return; } + const bool set = this->setSetupsToContext(setups); + if (!set) { return; } + QTimer::singleShot(250, this, &CInterpolationSetupComponent::displaySetupsPerCallsign); + } + } + + void CInterpolationSetupComponent::removeSetup() + { + if (!this->checkPrerequisites()) { return; } + if (this->getSetupMode() == CInterpolationSetupComponent::Global) { return; } + const CCallsign cs = ui->comp_CallsignCompleter->getCallsign(false); + CInterpolationSetupList setups = ui->tvp_InterpolationSetup->container(); + const int removed = setups.removeByCallsign(cs); + if (removed < 1) { return; } // nothing done + const bool set = this->setSetupsToContext(setups); + if (!set) { return; } + QTimer::singleShot(100, this, &CInterpolationSetupComponent::displaySetupsPerCallsign); + } + + void CInterpolationSetupComponent::setUiValuesFromGlobal() + { + Q_ASSERT_X(sGui, Q_FUNC_INFO, "Missing sGui"); + const CInterpolationAndRenderingSetupGlobal setup = sGui->getIContextSimulator()->getInterpolationAndRenderingSetupGlobal(); + ui->form_InterpolationSetup->setValue(setup); + } + + void CInterpolationSetupComponent::displaySetupsPerCallsign() + { + Q_ASSERT_X(sGui, Q_FUNC_INFO, "Missing sGui"); + const CInterpolationSetupList setups = sGui->getIContextSimulator()->getInterpolationAndRenderingSetupsPerCallsign(); + ui->tvp_InterpolationSetup->updateContainerMaybeAsync(setups); + } + + bool CInterpolationSetupComponent::checkPrerequisites() + { + if (!sGui || !sGui->getIContextSimulator()) + { + const CStatusMessage m = CStatusMessage(this).validationError("No context"); + this->showOverlayMessage(m); + return false; + } + if (!sGui->getIContextSimulator()->isSimulatorAvailable()) + { + const CStatusMessage m = CStatusMessage(this).validationError("No simulator avialable"); + this->showOverlayMessage(m); + return false; + } + return true; + } + + bool CInterpolationSetupComponent::setSetupsToContext(const CInterpolationSetupList &setups) + { + if (!sGui || !sGui->getIContextSimulator()) { return false; } + if (setups == m_lastSetSetups) { return false; } + sGui->getIContextSimulator()->setInterpolationAndRenderingSetupsPerCallsign(setups); + m_lastSetSetups = setups; + return true; + } + } // ns +} // ns diff --git a/src/blackgui/components/interpolationsetupcomponent.h b/src/blackgui/components/interpolationsetupcomponent.h new file mode 100644 index 000000000..0ac28a764 --- /dev/null +++ b/src/blackgui/components/interpolationsetupcomponent.h @@ -0,0 +1,87 @@ +/* Copyright (C) 2018 + * 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_COMPONENTS_INTERPOLATIONSETUPCOMPONENT_H +#define BLACKGUI_COMPONENTS_INTERPOLATIONSETUPCOMPONENT_H + +#include "blackmisc/simulation/interpolationsetuplist.h" +#include "blackgui/overlaymessagesframe.h" +#include +#include +#include + +namespace Ui { class CInterpolationSetupComponent; } +namespace BlackGui +{ + namespace Components + { + //! Setup component + class CInterpolationSetupComponent : public COverlayMessagesFrame + { + Q_OBJECT + + public: + //! Mode of setup + enum Mode + { + Global, + PerCallsign + }; + + //! Constructor + explicit CInterpolationSetupComponent(QWidget *parent = nullptr); + + //! Destructor + virtual ~CInterpolationSetupComponent(); + + //! Setup mode + Mode getSetupMode() const; + + signals: + //! Request restrictions UI + void requestRenderingRestrictionsWidget(); + + private: + QScopedPointer ui; + + //! Double clicked in view + void onRowDoubleClicked(const QModelIndex &index); + + //! Mode has been changed + void onModeChanged(); + + //! View has been changed + void onModelChanged(); + + //! Save a setup + void saveSetup(); + + //! Delete a setup + void removeSetup(); + + //! Values from global setup + void setUiValuesFromGlobal(); + + //! Values per callsign + void displaySetupsPerCallsign(); + + //! Check prerequisites before saving etc. + bool checkPrerequisites(); + + //! Send to context + bool setSetupsToContext(const BlackMisc::Simulation::CInterpolationSetupList &setups); + + BlackMisc::Simulation::CInterpolationSetupList m_lastSetSetups; //!< last setups set to context + }; + } // ns +}// ns + +#endif // guard diff --git a/src/blackgui/components/interpolationsetupcomponent.ui b/src/blackgui/components/interpolationsetupcomponent.ui new file mode 100644 index 000000000..8ef4a05d9 --- /dev/null +++ b/src/blackgui/components/interpolationsetupcomponent.ui @@ -0,0 +1,181 @@ + + + CInterpolationSetupComponent + + + + 0 + 0 + 260 + 276 + + + + Interpolation setup + + + + 2 + + + 2 + + + 2 + + + 2 + + + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + false + + + false + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + + + + callsign + + + true + + + + + + + global + + + + + + + + + + + 0 + 80 + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + rendering setup + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + delete + + + + + + + save + + + + + + + + + + + BlackGui::Components::CCallsignCompleter + QFrame +
blackgui/components/callsigncompleter.h
+ 1 +
+ + BlackGui::Views::CInterpolationSetupView + QTableView +
blackgui/views/interpolationsetupview.h
+
+ + BlackGui::Editors::CInterpolationSetupForm + QFrame +
blackgui/editors/interpolationsetupform.h
+ 1 +
+
+ + +