mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 19:35:32 +08:00
Ref T292, Ref T285 moved setToConnectedSimulator into simulator selector so it can be used elsewhere
This commit is contained in:
@@ -120,13 +120,14 @@ namespace BlackGui
|
||||
|
||||
// Updates
|
||||
connect(&m_updateTimer, &QTimer::timeout, this, &CMappingComponent::timerUpdate);
|
||||
m_updateTimer.setObjectName(this->objectName() + "::updateTimer");
|
||||
ui->tvp_AircraftModels->setDisplayAutomatically(false);
|
||||
this->settingsChanged();
|
||||
|
||||
// selector
|
||||
ui->comp_SimulatorSelector->setRememberSelection(false); // pilot client UI
|
||||
ui->comp_SimulatorSelector->setMode(CSimulatorSelector::RadioButtons);
|
||||
this->setSimulatorSelector();
|
||||
ui->comp_SimulatorSelector->setToConnectedSimulator();
|
||||
connect(ui->comp_SimulatorSelector, &CSimulatorSelector::changed, this, &CMappingComponent::onModelSetSimulatorChanged);
|
||||
|
||||
// connect
|
||||
@@ -146,7 +147,7 @@ namespace BlackGui
|
||||
connect(ui->tw_SpecializedViews, &QTabWidget::currentChanged, this, &CMappingComponent::onTabWidgetChanged);
|
||||
|
||||
// requires simulator context
|
||||
connect(ui->tvp_RenderedAircraft, &CAircraftModelView::objectChanged, this, &CMappingComponent::onChangedSimulatedAircraftInView);
|
||||
connect(ui->tvp_RenderedAircraft, &CAircraftModelView::objectChanged, this, &CMappingComponent::onChangedSimulatedAircraftInView, Qt::QueuedConnection);
|
||||
|
||||
// with external core models might be already available
|
||||
// nevertheless, wait some time to allow to init
|
||||
@@ -279,35 +280,9 @@ namespace BlackGui
|
||||
return callsign;
|
||||
}
|
||||
|
||||
void CMappingComponent::setSimulatorSelector()
|
||||
{
|
||||
if (sGui && sGui->supportsContexts() && sGui->getIContextSimulator())
|
||||
{
|
||||
const CSimulatorPluginInfo pluginInfo = sGui->getIContextSimulator()->getSimulatorPluginInfo();
|
||||
if (pluginInfo.isValid())
|
||||
{
|
||||
ui->comp_SimulatorSelector->setReadOnly(true);
|
||||
ui->comp_SimulatorSelector->setValue(pluginInfo.getSimulator());
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->comp_SimulatorSelector->setReadOnly(false);
|
||||
const CSimulatorInfo simulator = sGui->getIContextSimulator()->getModelSetLoaderSimulator();
|
||||
if (simulator.isSingleSimulator())
|
||||
{
|
||||
ui->comp_SimulatorSelector->setValue(simulator);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->comp_SimulatorSelector->setReadOnly(false);
|
||||
}
|
||||
}
|
||||
|
||||
void CMappingComponent::onModelSetSimulatorChanged(const CSimulatorInfo &simulator)
|
||||
{
|
||||
if (this->isSimulatorAvailable()) { return; }
|
||||
if (!sGui || this->isSimulatorAvailable()) { return; }
|
||||
sGui->getIContextSimulator()->setModelSetLoaderSimulator(simulator);
|
||||
|
||||
// completer will be changed in onModelSetChanged
|
||||
@@ -316,12 +291,7 @@ namespace BlackGui
|
||||
void CMappingComponent::onSimulatorPluginChanged(const CSimulatorPluginInfo &pluginInfo)
|
||||
{
|
||||
Q_UNUSED(pluginInfo);
|
||||
QPointer<CMappingComponent> myself(this);
|
||||
QTimer::singleShot(25, this, [ = ]
|
||||
{
|
||||
if (myself.isNull()) { return; }
|
||||
myself->setSimulatorSelector();
|
||||
});
|
||||
ui->comp_SimulatorSelector->setToConnectedSimulator(50);
|
||||
}
|
||||
|
||||
void CMappingComponent::onSaveAircraft()
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
|
||||
class QCompleter;
|
||||
class QModelIndex;
|
||||
class QWidget;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
@@ -174,9 +173,6 @@ namespace BlackGui
|
||||
//! Check callsign entered
|
||||
BlackMisc::Aviation::CCallsign validateRenderedCallsign();
|
||||
|
||||
//! Set the status of the simulator
|
||||
void setSimulatorSelector();
|
||||
|
||||
//! Changed selector
|
||||
void onModelSetSimulatorChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
|
||||
|
||||
@@ -8,8 +8,10 @@
|
||||
*/
|
||||
|
||||
#include "blackgui/components/simulatorselector.h"
|
||||
#include "blackgui/guiapplication.h"
|
||||
#include "blackgui/guiutility.h"
|
||||
#include "blackmisc/compare.h"
|
||||
#include "blackcore/context/contextsimulator.h"
|
||||
#include "ui_simulatorselector.h"
|
||||
|
||||
#include <QCheckBox>
|
||||
@@ -19,6 +21,7 @@
|
||||
#include <QPointer>
|
||||
|
||||
using namespace BlackMisc::Simulation;
|
||||
using namespace BlackCore::Context;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
@@ -84,7 +87,7 @@ namespace BlackGui
|
||||
|
||||
void CSimulatorSelector::setValue(const CSimulatorInfo &simulator)
|
||||
{
|
||||
const CSimulatorInfo current(getValue());
|
||||
const CSimulatorInfo current(this->getValue());
|
||||
if (simulator == current) { return; } // avoid unnecessary signals
|
||||
|
||||
// checkboxes
|
||||
@@ -108,6 +111,49 @@ namespace BlackGui
|
||||
this->setValue(simulator);
|
||||
}
|
||||
|
||||
void CSimulatorSelector::setToConnectedSimulator(bool makeReadOnly)
|
||||
{
|
||||
if (sGui && sGui->supportsContexts() && sGui->getIContextSimulator())
|
||||
{
|
||||
const CSimulatorPluginInfo pluginInfo = sGui->getIContextSimulator()->getSimulatorPluginInfo();
|
||||
if (pluginInfo.isValid())
|
||||
{
|
||||
this->setMode(RadioButtons);
|
||||
this->setReadOnly(makeReadOnly);
|
||||
this->setValue(pluginInfo.getSimulator());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (makeReadOnly) { this->setReadOnly(false); }
|
||||
const CSimulatorInfo simulator = sGui->getIContextSimulator()->getModelSetLoaderSimulator();
|
||||
if (simulator.isSingleSimulator())
|
||||
{
|
||||
this->setValue(simulator);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (makeReadOnly) { this->setReadOnly(false); }
|
||||
}
|
||||
}
|
||||
|
||||
void CSimulatorSelector::setToConnectedSimulator(int deferredMs, bool makeReadOnly)
|
||||
{
|
||||
if (deferredMs < 1)
|
||||
{
|
||||
this->setToConnectedSimulator(makeReadOnly);
|
||||
return;
|
||||
}
|
||||
|
||||
QPointer<CSimulatorSelector> myself(this);
|
||||
QTimer::singleShot(deferredMs, this, [ = ]
|
||||
{
|
||||
if (!sGui || sGui->isShuttingDown() || !myself) { return; }
|
||||
this->setToConnectedSimulator(makeReadOnly);
|
||||
});
|
||||
}
|
||||
|
||||
void CSimulatorSelector::checkAll()
|
||||
{
|
||||
// checkboxes
|
||||
@@ -204,16 +250,14 @@ namespace BlackGui
|
||||
{
|
||||
if (m_mode != RadioButtons) { return; }
|
||||
if (!checked) { return; } // only the checked ones are relevant, as the unchecked ones are accompanied with checked events
|
||||
this->rememberSelection();
|
||||
emit this->changed(this->getValue());
|
||||
m_digestButtonsChanged.inputSignal();
|
||||
}
|
||||
|
||||
void CSimulatorSelector::checkBoxChanged(bool checked)
|
||||
{
|
||||
if (m_mode != CheckBoxes) { return; }
|
||||
Q_UNUSED(checked);
|
||||
this->rememberSelection();
|
||||
emit this->changed(this->getValue());
|
||||
m_digestButtonsChanged.inputSignal();
|
||||
}
|
||||
|
||||
void CSimulatorSelector::rememberSelection()
|
||||
@@ -258,5 +302,12 @@ namespace BlackGui
|
||||
this->setToLastSelection();
|
||||
});
|
||||
}
|
||||
|
||||
void CSimulatorSelector::emitChangedSignal()
|
||||
{
|
||||
const CSimulatorInfo simulator(this->getValue());
|
||||
this->rememberSelection();
|
||||
emit this->changed(simulator);
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "blackmisc/simulation/simulatorinfo.h"
|
||||
#include "blackmisc/simulation/data/modelcaches.h"
|
||||
#include "blackmisc/digestsignal.h"
|
||||
|
||||
#include <QFrame>
|
||||
#include <QObject>
|
||||
@@ -63,6 +64,12 @@ namespace BlackGui
|
||||
//! Set to last selection
|
||||
void setToLastSelection();
|
||||
|
||||
//! Set to the connected simulator
|
||||
void setToConnectedSimulator(bool makeReadOnly = true);
|
||||
|
||||
//! Set to the connected simulator but deferred
|
||||
void setToConnectedSimulator(int deferredMs, bool makeReadOnly = true);
|
||||
|
||||
//! Set all, only making sense with checkboxes
|
||||
void checkAll();
|
||||
|
||||
@@ -119,10 +126,14 @@ namespace BlackGui
|
||||
//! Trigger CSimulatorSelector::setToLastSelection
|
||||
void triggerSetToLastSelection();
|
||||
|
||||
//! Emit the CSimulatorSelector::changed signal
|
||||
void emitChangedSignal();
|
||||
|
||||
QScopedPointer<Ui::CSimulatorSelector> ui;
|
||||
Mode m_mode = CheckBoxes;
|
||||
bool m_noSelectionMeansAll = false; //!< for filters, no selection means all
|
||||
bool m_rememberSelection = false; //!< remember last selection
|
||||
BlackMisc::CDigestSignal m_digestButtonsChanged { this, &CSimulatorSelector::emitChangedSignal, 250, 3 };
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::TSimulatorLastSelection> m_currentSimulator { this, &CSimulatorSelector::changedLastSelectionRb }; //!< current simulator (used with radio buttons)
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::TSimulatorLastSelections> m_currentSimulators { this, &CSimulatorSelector::changedLastSelectionCb }; //!< current simulators (used with multiple checkboxes)
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user