mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 11:55:35 +08:00
refs #289, simulator component GUI for time sync
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Settings;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
using namespace BlackSim;
|
||||
using namespace BlackSim::Settings;
|
||||
using namespace BlackCore;
|
||||
@@ -31,11 +32,12 @@ namespace BlackGui
|
||||
void CSettingsSimulatorComponent::runtimeHasBeenSet()
|
||||
{
|
||||
Q_ASSERT(this->getIContextSimulator());
|
||||
Q_ASSERT(this->getIContextSettings());
|
||||
if (this->getIContextSimulator())
|
||||
{
|
||||
QStringList plugins = this->getIContextSimulator()->getAvailableSimulatorPlugins().toStringList(true);
|
||||
CSimulatorInfo currentDriver = this->getIContextSimulator()->getSimulatorInfo();
|
||||
this->ui->cb_SimulatorDriver->addItems(plugins);
|
||||
this->ui->cb_Plugins->addItems(plugins);
|
||||
this->setCurrentPlugin(currentDriver);
|
||||
|
||||
// disable / enable driver specific GUI parts
|
||||
@@ -43,14 +45,38 @@ namespace BlackGui
|
||||
this->getIContextSimulator()->getAvailableSimulatorPlugins().supportsSimulator(CSimulatorInfo::FSX());
|
||||
this->ui->comp_SettingsSimulatorFsx->setVisible(fsxDriver);
|
||||
|
||||
// only with set GUI values
|
||||
bool connected = this->connect(this->ui->cb_SimulatorDriver, SIGNAL(currentIndexChanged(int)), this, SLOT(pluginHasChanged(int)));
|
||||
// only with simulator context set GUI values
|
||||
bool connected = this->connect(this->ui->cb_Plugins, SIGNAL(currentIndexChanged(int)), this, SLOT(ps_pluginHasChanged(int)));
|
||||
Q_ASSERT(connected);
|
||||
Q_UNUSED(connected);
|
||||
}
|
||||
|
||||
if (this->getIContextSettings())
|
||||
{
|
||||
connect(this->getIContextSettings(), &IContextSettings::changedSettings, this, &CSettingsSimulatorComponent::ps_settingsHaveChanged);
|
||||
}
|
||||
|
||||
connect(this->ui->cb_TimeSync, &QCheckBox::released, this, &CSettingsSimulatorComponent::ps_guiValueHasChanged);
|
||||
connect(this->ui->le_TimeSyncOffset, &QLineEdit::returnPressed, this, &CSettingsSimulatorComponent::ps_guiValueHasChanged);
|
||||
}
|
||||
|
||||
void CSettingsSimulatorComponent::pluginHasChanged(int index)
|
||||
void CSettingsSimulatorComponent::setCurrentPlugin(const CSimulatorInfo &plugin)
|
||||
{
|
||||
if (plugin.isUnspecified()) return;
|
||||
const QString searchFor = plugin.getShortName();
|
||||
for (int i = 0; i < this->ui->cb_Plugins->count(); ++i)
|
||||
{
|
||||
const QString t = ui->cb_Plugins->itemText(i);
|
||||
if (t.indexOf(searchFor, 0, Qt::CaseInsensitive) >= 0)
|
||||
{
|
||||
if (i == this->ui->cb_Plugins->currentIndex()) return;
|
||||
this->ui->cb_Plugins->setCurrentIndex(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CSettingsSimulatorComponent::ps_pluginHasChanged(int index)
|
||||
{
|
||||
Q_ASSERT(this->getIContextSimulator());
|
||||
Q_ASSERT(this->getIContextSettings());
|
||||
@@ -76,19 +102,53 @@ namespace BlackGui
|
||||
);
|
||||
}
|
||||
|
||||
void CSettingsSimulatorComponent::setCurrentPlugin(const CSimulatorInfo &driver)
|
||||
void CSettingsSimulatorComponent::ps_settingsHaveChanged(uint settingsType)
|
||||
{
|
||||
if (driver.isUnspecified()) return;
|
||||
const QString searchFor = driver.getShortName();
|
||||
for (int i = 0; i < this->ui->cb_SimulatorDriver->count(); ++i)
|
||||
Q_ASSERT(this->getIContextSettings());
|
||||
IContextSettings::SettingsType type = static_cast<IContextSettings::SettingsType>(settingsType);
|
||||
if (type != IContextSettings::SettingsSimulator || !this->getIContextSettings()) return;
|
||||
CSettingsSimulator simSettings = this->getIContextSettings()->getSimulatorSettings();
|
||||
|
||||
this->setCurrentPlugin(simSettings.getSelectedPlugin());
|
||||
this->ui->le_TimeSyncOffset->setText(simSettings.getSyncTimeOffset().formattedHrsMin());
|
||||
this->ui->cb_TimeSync->setChecked(simSettings.isTimeSyncEnabled());
|
||||
}
|
||||
|
||||
void CSettingsSimulatorComponent::ps_guiValueHasChanged()
|
||||
{
|
||||
Q_ASSERT(this->getIContextSettings());
|
||||
if (!this->getIContextSettings()) return;
|
||||
|
||||
QObject *sender = QObject::sender();
|
||||
if (!sender) return;
|
||||
|
||||
const QString ps = IContextSettings::PathSimulatorSettings();
|
||||
CStatusMessageList msgs;
|
||||
if (sender == this->ui->cb_TimeSync)
|
||||
{
|
||||
const QString t = ui->cb_SimulatorDriver->itemText(i);
|
||||
if (t.indexOf(searchFor, 0, Qt::CaseInsensitive) >= 0)
|
||||
bool timeSync = this->ui->cb_TimeSync->isChecked();
|
||||
msgs = this->getIContextSettings()->value(CSettingUtilities::appendPaths(ps, CSettingsSimulator::ValueSyncTime()), CSettingUtilities::CmdUpdate(), QVariant(timeSync));
|
||||
}
|
||||
else if (sender == this->ui->le_TimeSyncOffset)
|
||||
{
|
||||
const QString os = this->ui->le_TimeSyncOffset->text();
|
||||
CTime ost(0, CTimeUnit::hrmin());
|
||||
if (!os.isEmpty())
|
||||
{
|
||||
if (i == this->ui->cb_SimulatorDriver->currentIndex()) return;
|
||||
this->ui->cb_SimulatorDriver->setCurrentIndex(i);
|
||||
break;
|
||||
ost.parseFromString(os);
|
||||
}
|
||||
if (ost.isNull())
|
||||
{
|
||||
msgs.push_back(CStatusMessage::getValidationError("Invalid offset time"));
|
||||
}
|
||||
else
|
||||
{
|
||||
msgs = this->getIContextSettings()->value(CSettingUtilities::appendPaths(ps, CSettingsSimulator::ValueSyncTimeOffset()), CSettingUtilities::CmdUpdate(), ost.toQVariant());
|
||||
}
|
||||
}
|
||||
if (!msgs.isEmpty())
|
||||
{
|
||||
this->getIContextApplication()->sendStatusMessages(msgs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,13 +28,19 @@ namespace BlackGui
|
||||
|
||||
private slots:
|
||||
//! Driver changed
|
||||
void pluginHasChanged(int index);
|
||||
void ps_pluginHasChanged(int index);
|
||||
|
||||
//! Settings have been changed
|
||||
void ps_settingsHaveChanged(uint settingsType);
|
||||
|
||||
//! A GUI value has been changed
|
||||
void ps_guiValueHasChanged();
|
||||
|
||||
private:
|
||||
Ui::CSettingsSimulatorComponent *ui; //!< UI
|
||||
|
||||
//! Smarter way to set current driver, avoids unnecessary signals and less formatting dependend
|
||||
void setCurrentPlugin(const BlackSim::CSimulatorInfo &driver);
|
||||
void setCurrentPlugin(const BlackSim::CSimulatorInfo &plugin);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -39,23 +39,101 @@
|
||||
<layout class="QGridLayout" name="ql_SettingsSimulatorsAll">
|
||||
<item row="0" column="0">
|
||||
<layout class="QFormLayout" name="fl_SettingsSimulatorsAll">
|
||||
<property name="fieldGrowthPolicy">
|
||||
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
|
||||
</property>
|
||||
<property name="horizontalSpacing">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="verticalSpacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QLabel" name="lbl_SimulatorAllHeader">
|
||||
<property name="text">
|
||||
<string><html><head/><body><p><span style=" font-size:10pt; font-weight:600;">All simulators</span></p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="lbl_SimulatorDriver">
|
||||
<widget class="QLabel" name="lbl_Plugin">
|
||||
<property name="text">
|
||||
<string>Driver</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="cb_SimulatorDriver"/>
|
||||
<widget class="QComboBox" name="cb_Plugins"/>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QLabel" name="lbl_SettingsSimulatorAllHeader">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="lbl_TimeSync">
|
||||
<property name="text">
|
||||
<string><html><head/><body><p><span style=" font-size:10pt; font-weight:600;">All simulators</span></p></body></html></string>
|
||||
<string>Time synchronization</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QWidget" name="wi_TimeSync" native="true">
|
||||
<layout class="QHBoxLayout" name="hl_WidgetTimeSync">
|
||||
<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="QCheckBox" name="cb_TimeSync"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="le_TimeSyncOffset">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>75</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="inputMask">
|
||||
<string>#99:99</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>+00:00</string>
|
||||
</property>
|
||||
<property name="maxLength">
|
||||
<number>6</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="lbl_TimeSyncOffset">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>offset +/-hh:mm</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
|
||||
Reference in New Issue
Block a user