refs #641, distributor preferences GUI and formatting setting component (for distributor preferences)

This commit is contained in:
Klaus Basan
2016-04-23 02:53:51 +02:00
parent 7d43af343e
commit ec8e747d53
4 changed files with 418 additions and 54 deletions

View File

@@ -7,79 +7,98 @@
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<height>364</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>400</width>
<height>0</height>
</size>
</property>
<property name="windowTitle">
<string>Frame</string>
<string>Settings</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="1">
<widget class="QFrame" name="fr_Foo">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
<layout class="QGridLayout" name="gl_DataSettingsComponent">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item row="0" column="0">
<widget class="BlackGui::Components::CDbLoginComponent" name="comp_LoginComponent">
<property name="minimumSize">
<size>
<width>0</width>
<height>150</height>
</size>
</property>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<item row="2" column="0" colspan="2">
<widget class="QGroupBox" name="gb_DistributorPreferences">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeHint" stdset="0">
<property name="minimumSize">
<size>
<width>40</width>
<height>20</height>
<width>0</width>
<height>200</height>
</size>
</property>
</spacer>
<property name="title">
<string>Distributor preferences</string>
</property>
<layout class="QVBoxLayout" name="vl_DistributorPreferencesGroupBox">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<widget class="BlackGui::Components::CDistributorPreferencesComponent" name="comp_DistributorPreferences">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="1">
<widget class="BlackGui::Components::CDbDebugDatabaseSetup" name="comp_DebugDb">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<width>0</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0">
<widget class="BlackGui::Components::CDbLoginComponent" name="comp_LoginComponent">
<property name="minimumSize">
<size>
<width>200</width>
<height>100</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
@@ -103,6 +122,12 @@
<header>blackgui/components/dbdebugdatabasesetup.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>BlackGui::Components::CDistributorPreferencesComponent</class>
<extends>QFrame</extends>
<header>blackgui/components/distributorpreferencescomponent.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>

View File

@@ -0,0 +1,139 @@
/* 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 "distributorpreferencescomponent.h"
#include "ui_distributorpreferencescomponent.h"
#include "blackgui/overlaymessagesframe.h"
#include "blackgui/guiapplication.h"
#include "blackgui/guiutility.h"
#include "blackmisc/logmessage.h"
using namespace BlackMisc;
using namespace BlackMisc::Simulation;
using namespace BlackGui::Views;
using namespace BlackGui::Models;
namespace BlackGui
{
namespace Components
{
CDistributorPreferencesComponent::CDistributorPreferencesComponent(QWidget *parent) :
QFrame(parent),
ui(new Ui::CDistributorPreferencesComponent)
{
ui->setupUi(this);
ui->comp_SimulatorSelector->setMode(CSimulatorSelector::RadioButtons);
connect(ui->pb_All, &QPushButton::pressed, this, &CDistributorPreferencesComponent::ps_loadAll);
connect(ui->pb_AllForSimulator, &QPushButton::pressed, this, &CDistributorPreferencesComponent::ps_loadAllForSimulator);
connect(ui->pb_AllInSet, &QPushButton::pressed, this, &CDistributorPreferencesComponent::ps_loadDistributorsFromSet);
connect(ui->pb_Save, &QPushButton::pressed, this, &CDistributorPreferencesComponent::ps_save);
connect(ui->comp_SimulatorSelector, &CSimulatorSelector::changed, this, &CDistributorPreferencesComponent::ps_simulatorChanged);
this->m_overlayMessageFrame = CGuiUtility::nextOverlayMessageFrame(this);
Q_ASSERT_X(this->m_overlayMessageFrame, Q_FUNC_INFO, "Missing message frame");
ui->tvp_Distributors->setDistributorMode(CDistributorListModel::NormalWithOrder);
ui->tvp_Distributors->menuRemoveItems(CDistributorView::MenuBackend | CDistributorView::MenuDisplayAutomaticallyAndRefresh | CDistributorView::MenuLoadAndSave);
ui->tvp_Distributors->menuAddItems(CDistributorView::MenuClear | CDistributorView::MenuOrderable | CDistributorView::MenuRemoveSelectedRows);
ui->tvp_Distributors->initAsOrderable();
QTimer::singleShot(1000, this, &CDistributorPreferencesComponent::ps_deferredInit);
}
CDistributorPreferencesComponent::~CDistributorPreferencesComponent()
{ }
void CDistributorPreferencesComponent::ps_preferencesChanged()
{
// changed somewhere else
const CSimulatorInfo sim(ui->comp_SimulatorSelector->getValue());
const CDistributorList distributors = this->m_distributorPreferences.get().getDistributors(sim);
this->updateContainerMaybeAsync(distributors);
}
void CDistributorPreferencesComponent::ps_loadAll()
{
Q_ASSERT_X(sGui, Q_FUNC_INFO, "Missing application");
const CDistributorList distributors(sGui->getWebDataServices()->getDistributors());
if (distributors.isEmpty())
{
const CStatusMessage m = CStatusMessage(this).error("No distributors");
this->m_overlayMessageFrame->showOverlayMessage(m);
return;
}
this->updateContainerMaybeAsync(distributors);
}
void CDistributorPreferencesComponent::ps_loadAllForSimulator()
{
const CSimulatorInfo sim(ui->comp_SimulatorSelector->getValue());
const CDistributorList distributors(sGui->getWebDataServices()->getDistributors().matchesSimulator(sim));
if (distributors.isEmpty())
{
const CStatusMessage m = CStatusMessage(this).error("No distributors, or no distributors matching %1") << sim.toQString();
this->m_overlayMessageFrame->showOverlayMessage(m);
return;
}
this->updateContainerMaybeAsync(distributors);
}
void CDistributorPreferencesComponent::ps_loadDistributorsFromSet()
{
const CSimulatorInfo sim(ui->comp_SimulatorSelector->getValue());
this->m_modelSetLoader.changeSimulator(sim);
const CAircraftModelList models = this->m_modelSetLoader.getAircraftModels();
if (models.isEmpty())
{
const CStatusMessage m = CStatusMessage(this).error("No data in model set %1") << sim.toQString();
this->m_overlayMessageFrame->showOverlayMessage(m);
return;
}
const CDistributorList distributors = models.getDistributors();
if (distributors.isEmpty())
{
const CStatusMessage m = CStatusMessage(this).error("No distributors for model set %1") << sim.toQString();
this->m_overlayMessageFrame->showOverlayMessage(m);
return;
}
this->updateContainerMaybeAsync(distributors);
}
void CDistributorPreferencesComponent::ps_save()
{
const CDistributorList distributors(ui->tvp_Distributors->container());
const CSimulatorInfo simulator = ui->comp_SimulatorSelector->getValue();
CDistributorListPreferences preferences = this->m_distributorPreferences.get();
preferences.setDistributors(distributors, simulator);
const CStatusMessage m = this->m_distributorPreferences.setAndSave(preferences);
CLogMessage::preformatted(m);
}
void CDistributorPreferencesComponent::ps_simulatorChanged(const CSimulatorInfo &simulator)
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Expect single simulator");
const CDistributorList distributors(this->m_distributorPreferences.get().getDistributors(simulator));
ui->tvp_Distributors->updateContainerMaybeAsync(distributors);
}
void CDistributorPreferencesComponent::ps_deferredInit()
{
this->ps_simulatorChanged(ui->comp_SimulatorSelector->getValue());
}
void CDistributorPreferencesComponent::updateContainerMaybeAsync(const CDistributorList &models, bool sortByOrder)
{
if (sortByOrder)
{
ui->tvp_Distributors->setSorting(CDistributor::IndexOrder, Qt::AscendingOrder);
}
ui->tvp_Distributors->updateContainerMaybeAsync(models);
}
} // ns
} // ns

View File

@@ -0,0 +1,73 @@
/* 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_COMPONENTS_DISTRIBUTORPREFERENCESCOMPONENT_H
#define BLACKGUI_COMPONENTS_DISTRIBUTORPREFERENCESCOMPONENT_H
#include "blackcore/settings/distributorpreferences.h"
#include "blackmisc/simulation/aircraftmodelsetloader.h"
#include <QFrame>
#include <QScopedPointer>
namespace Ui { class CDistributorPreferencesComponent; }
namespace BlackGui
{
class COverlayMessagesFrame;
namespace Components
{
/*!
* Set and order distributors (to be used for model set)
*/
class CDistributorPreferencesComponent : public QFrame
{
Q_OBJECT
public:
//! Constructor
explicit CDistributorPreferencesComponent(QWidget *parent = nullptr);
//! Destructor
~CDistributorPreferencesComponent();
private slots:
//! Changed preferences
void ps_preferencesChanged();
//! Load all distributors
void ps_loadAll();
//! Load all distributors for current simulator
void ps_loadAllForSimulator();
//! Load distributors from set
void ps_loadDistributorsFromSet();
//! Save the preferences
void ps_save();
//! Simulator has been changed
void ps_simulatorChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator);
// Init
void ps_deferredInit();
private:
BlackGui::COverlayMessagesFrame *m_overlayMessageFrame = nullptr;
QScopedPointer<Ui::CDistributorPreferencesComponent> ui;
BlackMisc::Simulation::CAircraftModelSetLoader m_modelSetLoader { BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FSX), this };
BlackMisc::CSetting<BlackCore::Settings::Simulation::DistributorListPreferences> m_distributorPreferences { this, &CDistributorPreferencesComponent::ps_preferencesChanged };
void updateContainerMaybeAsync(const BlackMisc::Simulation::CDistributorList &models, bool sortByOrder = true);
};
} // ns
} // ns
#endif // guard

View File

@@ -0,0 +1,127 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CDistributorPreferencesComponent</class>
<widget class="QFrame" name="CDistributorPreferencesComponent">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Frame</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="vl_DistributorPreferences">
<property name="spacing">
<number>4</number>
</property>
<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::Views::CDistributorView" name="tvp_Distributors">
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::InternalMove</enum>
</property>
<property name="defaultDropAction">
<enum>Qt::MoveAction</enum>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
<item>
<widget class="QFrame" name="fr_Controls">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="BlackGui::Components::CSimulatorSelector" name="comp_SimulatorSelector">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pb_All">
<property name="text">
<string>all</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pb_AllForSimulator">
<property name="text">
<string>all for sim.</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pb_AllInSet">
<property name="text">
<string>all in set</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::Views::CDistributorView</class>
<extends>QTableView</extends>
<header>blackgui/views/distributorview.h</header>
</customwidget>
<customwidget>
<class>BlackGui::Components::CSimulatorSelector</class>
<extends>QFrame</extends>
<header>blackgui/components/simulatorselector.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>