diff --git a/src/blackgui/components/datasettingscomponent.ui b/src/blackgui/components/datasettingscomponent.ui
index 216e2b69c..f63ca3300 100644
--- a/src/blackgui/components/datasettingscomponent.ui
+++ b/src/blackgui/components/datasettingscomponent.ui
@@ -7,79 +7,98 @@
0
0
400
- 300
+ 364
+
+
+ 400
+ 0
+
+
- Frame
+ Settings
-
- QFrame::StyledPanel
-
-
- QFrame::Raised
-
-
- -
-
-
- QFrame::StyledPanel
-
-
- QFrame::Raised
+
+
+ 4
+
+
+ 4
+
+
+ 4
+
+
+ 4
+
+
-
+
+
+
+ 0
+ 150
+
- -
-
-
- Qt::Horizontal
+
-
+
+
+
+ 0
+ 0
+
-
+
- 40
- 20
+ 0
+ 200
-
+
+ Distributor preferences
+
+
+
+ 4
+
+
+ 4
+
+
+ 4
+
+
+ 4
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ QFrame::StyledPanel
+
+
+ QFrame::Raised
+
+
+
+
+
-
- 150
- 0
-
-
-
- QFrame::StyledPanel
-
-
- QFrame::Raised
-
-
-
- -
-
-
- Qt::Vertical
-
-
-
- 20
+ 0
40
-
-
- -
-
-
-
- 200
- 100
-
-
QFrame::StyledPanel
@@ -103,6 +122,12 @@
blackgui/components/dbdebugdatabasesetup.h
1
+
+ BlackGui::Components::CDistributorPreferencesComponent
+ QFrame
+ blackgui/components/distributorpreferencescomponent.h
+ 1
+
diff --git a/src/blackgui/components/distributorpreferencescomponent.cpp b/src/blackgui/components/distributorpreferencescomponent.cpp
new file mode 100644
index 000000000..ee6e5ba79
--- /dev/null
+++ b/src/blackgui/components/distributorpreferencescomponent.cpp
@@ -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
diff --git a/src/blackgui/components/distributorpreferencescomponent.h b/src/blackgui/components/distributorpreferencescomponent.h
new file mode 100644
index 000000000..708e7d237
--- /dev/null
+++ b/src/blackgui/components/distributorpreferencescomponent.h
@@ -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
+#include
+
+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;
+ BlackMisc::Simulation::CAircraftModelSetLoader m_modelSetLoader { BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FSX), this };
+ BlackMisc::CSetting m_distributorPreferences { this, &CDistributorPreferencesComponent::ps_preferencesChanged };
+
+ void updateContainerMaybeAsync(const BlackMisc::Simulation::CDistributorList &models, bool sortByOrder = true);
+ };
+ } // ns
+} // ns
+
+#endif // guard
diff --git a/src/blackgui/components/distributorpreferencescomponent.ui b/src/blackgui/components/distributorpreferencescomponent.ui
new file mode 100644
index 000000000..ef06d6ce2
--- /dev/null
+++ b/src/blackgui/components/distributorpreferencescomponent.ui
@@ -0,0 +1,127 @@
+
+
+ CDistributorPreferencesComponent
+
+
+
+ 0
+ 0
+ 400
+ 300
+
+
+
+ Frame
+
+
+ QFrame::StyledPanel
+
+
+ QFrame::Raised
+
+
+
+ 4
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
-
+
+
+ true
+
+
+ QAbstractItemView::InternalMove
+
+
+ Qt::MoveAction
+
+
+ QAbstractItemView::SingleSelection
+
+
+ QAbstractItemView::SelectRows
+
+
+ false
+
+
+
+ -
+
+
+ QFrame::StyledPanel
+
+
+ QFrame::Raised
+
+
+
-
+
+
+ QFrame::StyledPanel
+
+
+ QFrame::Raised
+
+
+
+ -
+
+
+ all
+
+
+
+ -
+
+
+ all for sim.
+
+
+
+ -
+
+
+ all in set
+
+
+
+ -
+
+
+ save
+
+
+
+
+
+
+
+
+
+
+ BlackGui::Views::CDistributorView
+ QTableView
+ blackgui/views/distributorview.h
+
+
+ BlackGui::Components::CSimulatorSelector
+ QFrame
+ blackgui/components/simulatorselector.h
+ 1
+
+
+
+
+