13 #include "ui_distributorpreferencescomponent.h"
32 using namespace swift::misc::simulation;
33 using namespace swift::misc::simulation::data;
34 using namespace swift::misc::network;
40 CDistributorPreferencesComponent::CDistributorPreferencesComponent(QWidget *parent)
45 ui->comp_SimulatorSelector->setRememberSelectionAndSetToLastSelection();
47 connect(ui->pb_All, &QPushButton::pressed,
this, &CDistributorPreferencesComponent::loadAllDistributors);
48 connect(ui->pb_AllForSimulator, &QPushButton::pressed,
this,
49 &CDistributorPreferencesComponent::loadDistributorsForSimulator);
50 connect(ui->pb_AllInSet, &QPushButton::pressed,
this,
51 &CDistributorPreferencesComponent::loadDistributorsFromSet);
52 connect(ui->pb_Save, &QPushButton::pressed,
this, &CDistributorPreferencesComponent::save);
54 &CDistributorPreferencesComponent::onSimulatorChanged);
56 ui->tvp_Distributors->setDistributorMode(CDistributorListModel::NormalWithOrder);
57 ui->tvp_Distributors->menuRemoveItems(CDistributorView::MenuBackend |
58 CDistributorView::MenuDisplayAutomaticallyAndRefresh |
59 CDistributorView::MenuLoadAndSave);
60 ui->tvp_Distributors->menuAddItems(CDistributorView::MenuClear | CDistributorView::MenuOrderable |
61 CDistributorView::MenuRemoveSelectedRows);
62 ui->tvp_Distributors->initAsOrderable();
64 this->triggerDeferredSimulatorChange();
69 void CDistributorPreferencesComponent::onPreferencesChanged()
74 this->updateContainerMaybeAsync(distributors);
77 void CDistributorPreferencesComponent::loadAllDistributors()
79 Q_ASSERT_X(
sGui, Q_FUNC_INFO,
"Missing application");
87 this->updateContainerMaybeAsync(distributors);
90 void CDistributorPreferencesComponent::loadDistributorsForSimulator()
101 this->updateContainerMaybeAsync(distributors);
104 void CDistributorPreferencesComponent::loadDistributorsFromSet()
108 CCentralMultiSimulatorModelSetCachesProvider::modelCachesInstance().getCachedModels(sim);
122 this->updateContainerMaybeAsync(distributors);
125 void CDistributorPreferencesComponent::save()
127 using namespace std::chrono_literals;
129 const CSimulatorInfo simulator = ui->comp_SimulatorSelector->getValue();
132 const CStatusMessage m = m_distributorPreferences.setAndSave(preferences);
133 CLogMessage::preformatted(m);
138 void CDistributorPreferencesComponent::onSimulatorChanged(
const CSimulatorInfo &simulator)
140 Q_ASSERT_X(simulator.
isSingleSimulator(), Q_FUNC_INFO,
"Expect single simulator");
142 ui->tvp_Distributors->updateContainerMaybeAsync(distributors);
145 void CDistributorPreferencesComponent::triggerDeferredSimulatorChange()
147 QPointer<CDistributorPreferencesComponent> myself(
this);
149 if (!myself) {
return; }
151 const CSimulatorInfo sim = ui->comp_SimulatorSelector->getValue();
152 this->onSimulatorChanged(sim);
156 void CDistributorPreferencesComponent::updateContainerMaybeAsync(
const CDistributorList &models,
bool sortByOrder)
158 if (sortByOrder) { ui->tvp_Distributors->setSorting(CDistributor::IndexOrder, Qt::AscendingOrder); }
159 ui->tvp_Distributors->updateContainerMaybeAsync(models);
SWIFT_CORE_EXPORT swift::core::CApplication * sApp
Single instance of application object.
bool isShuttingDown() const
Is application shutting down?
CWebDataServices * getWebDataServices() const
Get the web data services.
swift::misc::simulation::CDistributorList getDistributors() const
Distributors.
bool showOverlayHTMLMessage(const QString &htmlMessage, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
HTML message.
bool showOverlayMessage(const swift::misc::CStatusMessage &message, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
Show single message.
Using this class provides a QFrame with the overlay functionality already integrated.
Set and order distributors (to be used for model set)
virtual ~CDistributorPreferencesComponent()
Destructor.
void changed(const swift::misc::simulation::CSimulatorInfo &simulator)
Value has been changed.
const T & getThreadLocal() const
Read the current value.
Derived & error(const char16_t(&format)[N])
Set the severity to error, providing a format string.
bool isEmpty() const
Synonym for empty.
Streamable status message, e.g.
bool isSuccess() const
Operation considered successful.
QString toQString(bool i18n=false) const
Cast as QString.
Value object encapsulating a list of aircraft models.
CDistributorList getDistributors(bool onlyDbDistributors=true) const
All distributors used with models of this list.
Value object encapsulating a list of distributors.
CDistributorList matchesSimulator(const CSimulatorInfo &simulator) const
Find for given simulator.
Preferences for distributors.
void setDistributors(const CDistributorList &distributors, const CSimulatorInfo &simulator)
Get distributors.
Simple hardcoded info about the corresponding simulator.
bool isSingleSimulator() const
Single simulator selected.
SWIFT_GUI_EXPORT swift::gui::CGuiApplication * sGui
Single instance of GUI application object.
High level reusable GUI components.
Models to be used with views, mainly QTableView.
Views, mainly QTableView.
Free functions in swift::misc.
auto singleShot(int msec, QObject *target, F &&task)
Starts a single-shot timer which will call a task in the thread of the given object when it times out...