refs #289, simulator component GUI for time sync

This commit is contained in:
Klaus Basan
2014-07-09 19:59:20 +02:00
parent af17c2c4e6
commit fceea61e4c
3 changed files with 164 additions and 20 deletions

View File

@@ -10,6 +10,7 @@
using namespace BlackMisc; using namespace BlackMisc;
using namespace BlackMisc::Settings; using namespace BlackMisc::Settings;
using namespace BlackMisc::PhysicalQuantities;
using namespace BlackSim; using namespace BlackSim;
using namespace BlackSim::Settings; using namespace BlackSim::Settings;
using namespace BlackCore; using namespace BlackCore;
@@ -31,11 +32,12 @@ namespace BlackGui
void CSettingsSimulatorComponent::runtimeHasBeenSet() void CSettingsSimulatorComponent::runtimeHasBeenSet()
{ {
Q_ASSERT(this->getIContextSimulator()); Q_ASSERT(this->getIContextSimulator());
Q_ASSERT(this->getIContextSettings());
if (this->getIContextSimulator()) if (this->getIContextSimulator())
{ {
QStringList plugins = this->getIContextSimulator()->getAvailableSimulatorPlugins().toStringList(true); QStringList plugins = this->getIContextSimulator()->getAvailableSimulatorPlugins().toStringList(true);
CSimulatorInfo currentDriver = this->getIContextSimulator()->getSimulatorInfo(); CSimulatorInfo currentDriver = this->getIContextSimulator()->getSimulatorInfo();
this->ui->cb_SimulatorDriver->addItems(plugins); this->ui->cb_Plugins->addItems(plugins);
this->setCurrentPlugin(currentDriver); this->setCurrentPlugin(currentDriver);
// disable / enable driver specific GUI parts // disable / enable driver specific GUI parts
@@ -43,14 +45,38 @@ namespace BlackGui
this->getIContextSimulator()->getAvailableSimulatorPlugins().supportsSimulator(CSimulatorInfo::FSX()); this->getIContextSimulator()->getAvailableSimulatorPlugins().supportsSimulator(CSimulatorInfo::FSX());
this->ui->comp_SettingsSimulatorFsx->setVisible(fsxDriver); this->ui->comp_SettingsSimulatorFsx->setVisible(fsxDriver);
// only with set GUI values // only with simulator context set GUI values
bool connected = this->connect(this->ui->cb_SimulatorDriver, SIGNAL(currentIndexChanged(int)), this, SLOT(pluginHasChanged(int))); bool connected = this->connect(this->ui->cb_Plugins, SIGNAL(currentIndexChanged(int)), this, SLOT(ps_pluginHasChanged(int)));
Q_ASSERT(connected); Q_ASSERT(connected);
Q_UNUSED(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->getIContextSimulator());
Q_ASSERT(this->getIContextSettings()); 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; Q_ASSERT(this->getIContextSettings());
const QString searchFor = driver.getShortName(); IContextSettings::SettingsType type = static_cast<IContextSettings::SettingsType>(settingsType);
for (int i = 0; i < this->ui->cb_SimulatorDriver->count(); ++i) 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); bool timeSync = this->ui->cb_TimeSync->isChecked();
if (t.indexOf(searchFor, 0, Qt::CaseInsensitive) >= 0) 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; ost.parseFromString(os);
this->ui->cb_SimulatorDriver->setCurrentIndex(i);
break;
} }
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);
} }
} }

View File

@@ -28,13 +28,19 @@ namespace BlackGui
private slots: private slots:
//! Driver changed //! 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: private:
Ui::CSettingsSimulatorComponent *ui; //!< UI Ui::CSettingsSimulatorComponent *ui; //!< UI
//! Smarter way to set current driver, avoids unnecessary signals and less formatting dependend //! 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);
}; };

View File

@@ -39,23 +39,101 @@
<layout class="QGridLayout" name="ql_SettingsSimulatorsAll"> <layout class="QGridLayout" name="ql_SettingsSimulatorsAll">
<item row="0" column="0"> <item row="0" column="0">
<layout class="QFormLayout" name="fl_SettingsSimulatorsAll"> <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>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-size:10pt; font-weight:600;&quot;&gt;All simulators&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="lbl_SimulatorDriver"> <widget class="QLabel" name="lbl_Plugin">
<property name="text"> <property name="text">
<string>Driver</string> <string>Driver</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QComboBox" name="cb_SimulatorDriver"/> <widget class="QComboBox" name="cb_Plugins"/>
</item> </item>
<item row="0" column="0" colspan="2"> <item row="2" column="0">
<widget class="QLabel" name="lbl_SettingsSimulatorAllHeader"> <widget class="QLabel" name="lbl_TimeSync">
<property name="text"> <property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-size:10pt; font-weight:600;&quot;&gt;All simulators&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> <string>Time synchronization</string>
</property> </property>
</widget> </widget>
</item> </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> </layout>
</item> </item>
</layout> </layout>