Ref T259, Ref T243 interpolation component and setup component

This commit is contained in:
Klaus Basan
2018-03-19 21:07:00 +01:00
parent 0ff3b68d5c
commit 624eb7ca93
6 changed files with 606 additions and 0 deletions

View File

@@ -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

View File

@@ -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 <QFrame>
#include <QScopedPointer>
#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::CInterpolationComponent> ui;
};
} // ns
} // ns
#endif // guard

View File

@@ -0,0 +1,98 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CInterpolationComponent</class>
<widget class="QFrame" name="CInterpolationComponent">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>640</width>
<height>480</height>
</rect>
</property>
<property name="windowTitle">
<string>Frame</string>
</property>
<layout class="QVBoxLayout" name="vl_InterpolationComponent">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QTabWidget" name="tw_InterpolationSetup">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tb_InterpolationSetup">
<attribute name="title">
<string>Setup</string>
</attribute>
<layout class="QVBoxLayout" name="vl_InterpolationSetup">
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<widget class="BlackGui::Components::CInterpolationSetupComponent" name="comp_InterpolationSetup"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="tb_PartsHistory">
<attribute name="title">
<string>Aircraft parts log</string>
</attribute>
<layout class="QVBoxLayout" name="vl_PartsLog">
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<widget class="BlackGui::Components::CAircraftPartsHistory" name="PartsHistory"/>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>BlackGui::Components::CAircraftPartsHistory</class>
<extends>QFrame</extends>
<header>blackgui/components/aircraftpartshistory.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>BlackGui::Components::CInterpolationSetupComponent</class>
<extends>QFrame</extends>
<header>blackgui/components/interpolationsetupcomponent.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@@ -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

View File

@@ -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 <QFrame>
#include <QScopedPointer>
#include <QModelIndex>
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::CInterpolationSetupComponent> 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

View File

@@ -0,0 +1,181 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CInterpolationSetupComponent</class>
<widget class="QFrame" name="CInterpolationSetupComponent">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>260</width>
<height>276</height>
</rect>
</property>
<property name="windowTitle">
<string>Interpolation setup</string>
</property>
<layout class="QVBoxLayout" name="vl_InterpolationSetup">
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<widget class="BlackGui::Views::CInterpolationSetupView" name="tvp_InterpolationSetup">
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="showGrid">
<bool>false</bool>
</property>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
<item>
<widget class="QFrame" name="fr_Mode">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="hl_Mode">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="BlackGui::Components::CCallsignCompleter" name="comp_CallsignCompleter">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rb_Callsign">
<property name="text">
<string>callsign</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rb_Global">
<property name="text">
<string>global</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="BlackGui::Editors::CInterpolationSetupForm" name="form_InterpolationSetup">
<property name="minimumSize">
<size>
<width>0</width>
<height>80</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="fr_Buttons">
<layout class="QHBoxLayout" name="hl_Buttons">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="pb_RenderingSetup">
<property name="text">
<string> rendering setup </string>
</property>
</widget>
</item>
<item>
<spacer name="hs_Buttons">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pb_Delete">
<property name="text">
<string>delete</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pb_Save">
<property name="text">
<string>save</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>BlackGui::Components::CCallsignCompleter</class>
<extends>QFrame</extends>
<header>blackgui/components/callsigncompleter.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>BlackGui::Views::CInterpolationSetupView</class>
<extends>QTableView</extends>
<header>blackgui/views/interpolationsetupview.h</header>
</customwidget>
<customwidget>
<class>BlackGui::Editors::CInterpolationSetupForm</class>
<extends>QFrame</extends>
<header>blackgui/editors/interpolationsetupform.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>