refs #289, settings for simulator

This commit is contained in:
Klaus Basan
2014-07-09 19:57:12 +02:00
parent cd88c79f7c
commit 76cbb5348c
4 changed files with 103 additions and 16 deletions

View File

@@ -21,14 +21,39 @@ namespace BlackMisc
return rp;
}
/*
* Wrong cmd message
*/
BlackMisc::CStatusMessage CSettingUtilities::wrongCommandMessage(const QString &command)
{
QString msg = "wrong command";
if (!command.isEmpty())
{
msg.append(": ").append(command);
}
BlackMisc::CStatusMessage rc(BlackMisc::CStatusMessage::TypeValidation,
BlackMisc::CStatusMessage::SeverityError, msg);
return rc;
}
/*
* Wrong path name messages
*/
CStatusMessageList CSettingUtilities::wrongPathMessages(const QString &path)
{
BlackMisc::CStatusMessageList rps;
rps.push_back(CSettingUtilities::wrongPathMessage(path));
return rps;
BlackMisc::CStatusMessageList wrongPath;
wrongPath.push_back(CSettingUtilities::wrongPathMessage(path));
return wrongPath;
}
/*
* Wrong command message
*/
CStatusMessageList CSettingUtilities::wrongCommandMessages(const QString &command)
{
BlackMisc::CStatusMessageList wrongCmds;
wrongCmds.push_back(CSettingUtilities::wrongCommandMessage(command));
return wrongCmds;
}
/*

View File

@@ -63,6 +63,12 @@ namespace BlackMisc
//! Wrong path messages
static BlackMisc::CStatusMessageList wrongPathMessages(const QString &path = "");
//! Wrong command message
static BlackMisc::CStatusMessage wrongCommandMessage(const QString &command);
//! Wrong command messages
static BlackMisc::CStatusMessageList wrongCommandMessages(const QString &command);
//! Value not changed message
static BlackMisc::CStatusMessage valueNotChangedMessage(const QString &valueName);

View File

@@ -2,6 +2,7 @@
using namespace BlackMisc;
using namespace BlackMisc::Settings;
using namespace BlackMisc::PhysicalQuantities;
namespace BlackSim
{
@@ -98,7 +99,7 @@ namespace BlackSim
*/
QJsonObject CSettingsSimulator::toJson() const
{
return BlackMisc::serializeJson(CSettingsSimulator::jsonMembers(), TupleConverter<CSettingsSimulator>::toTuple(*this));
return BlackMisc::serializeJson(TupleConverter<CSettingsSimulator>::toMetaTuple(*this));
}
/*
@@ -106,7 +107,7 @@ namespace BlackSim
*/
void CSettingsSimulator::fromJson(const QJsonObject &json)
{
BlackMisc::deserializeJson(json, CSettingsSimulator::jsonMembers(), TupleConverter<CSettingsSimulator>::toTuple(*this));
BlackMisc::deserializeJson(json, TupleConverter<CSettingsSimulator>::toMetaTuple(*this));
}
/*
@@ -123,6 +124,8 @@ namespace BlackSim
void CSettingsSimulator::initDefaultValues()
{
this->m_selectedPlugin = CSimulatorInfo::FSX();
this->m_timeSyncOffset = CTime(0, CTimeUnit::hrmin());
this->m_timeSync = false;
}
/*
@@ -146,18 +149,42 @@ namespace BlackSim
{
if (command == CSettingUtilities::CmdAdd() || command == CSettingUtilities::CmdUpdate())
{
if (command == CSettingUtilities::CmdUpdate())
{
CSimulatorInfo v = value.value<CSimulatorInfo>();
changedFlag = (v != this->m_selectedPlugin);
msgs.push_back(CSettingUtilities::valueChangedMessage(changedFlag, "selected driver"));
this->m_selectedPlugin = v;
return msgs;
}
CSimulatorInfo v = value.value<CSimulatorInfo>();
changedFlag = (v != this->m_selectedPlugin);
msgs.push_back(CSettingUtilities::valueChangedMessage(changedFlag, "selected driver"));
this->m_selectedPlugin = v;
return msgs;
}
return CSettingUtilities::wrongCommandMessages(command);
}
else if (path == CSettingsSimulator::ValueSyncTime())
{
if (command == CSettingUtilities::CmdAdd() || command == CSettingUtilities::CmdUpdate())
{
bool v = value.value<bool>();
changedFlag = (v != this->m_timeSync);
msgs.push_back(CSettingUtilities::valueChangedMessage(changedFlag, "time synchronization"));
this->m_timeSync = v;
return msgs;
}
return CSettingUtilities::wrongCommandMessages(command);
}
else if (path == CSettingsSimulator::ValueSyncTimeOffset())
{
if (command == CSettingUtilities::CmdAdd() || command == CSettingUtilities::CmdUpdate())
{
CTime v = value.value<CTime>();
changedFlag = (v != this->m_timeSyncOffset);
msgs.push_back(CSettingUtilities::valueChangedMessage(changedFlag, "time synchronization offset"));
this->m_timeSyncOffset = v;
return msgs;
}
return CSettingUtilities::wrongCommandMessages(command);
}
else
{
return CSettingUtilities::wrongPathMessages(path);
}
return CSettingUtilities::wrongPathMessages(path);
}
} // namespace
} // namespace

View File

@@ -11,6 +11,7 @@
#include "blackmisc/valueobject.h"
#include "blackmisc/statusmessagelist.h"
#include "blackmisc/settingutilities.h"
#include "blackmisc/pqtime.h"
#include "simulatorinfo.h"
namespace BlackSim
@@ -34,15 +35,41 @@ namespace BlackSim
return value;
}
//! Path
static const QString &ValueSyncTimeOffset()
{
static const QString value("synctimeoffset");
return value;
}
//! Path
static const QString &ValueSyncTime()
{
static const QString value("synctime");
return value;
}
//! \copydoc CValueObject::toQVariant()
virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); }
//! Selected driver
BlackSim::CSimulatorInfo getSelectedPlugin() const { return this->m_selectedPlugin; }
const BlackSim::CSimulatorInfo &getSelectedPlugin() const { return this->m_selectedPlugin; }
//! Selected driver
void setSelectedPlugin(const BlackSim::CSimulatorInfo &plugin) { this->m_selectedPlugin = plugin; }
//! Time synchronization offset time
const BlackMisc::PhysicalQuantities::CTime &getSyncTimeOffset() const { return this->m_timeSyncOffset;}
//! Set time synchronization offset time
void setSyncTimeOffset(const BlackMisc::PhysicalQuantities::CTime &offset) { this->m_timeSyncOffset = offset; this->m_timeSyncOffset.switchUnit(BlackMisc::PhysicalQuantities::CTimeUnit::hrmin());}
//! Time syncronization enabled?
bool isTimeSyncEnabled() const { return this->m_timeSync;}
//! Set time synchronization
void setTimeSyncEnabled(bool enabled) { this->m_timeSync = enabled; }
//! Equal operator ==
bool operator ==(const CSettingsSimulator &other) const;
@@ -92,12 +119,14 @@ namespace BlackSim
private:
BLACK_ENABLE_TUPLE_CONVERSION(CSettingsSimulator)
BlackSim::CSimulatorInfo m_selectedPlugin;
bool m_timeSync = false;
BlackMisc::PhysicalQuantities::CTime m_timeSyncOffset;
};
} // namespace
} // namespace
Q_DECLARE_METATYPE(BlackSim::Settings::CSettingsSimulator)
BLACK_DECLARE_TUPLE_CONVERSION(BlackSim::Settings::CSettingsSimulator, (o.m_selectedPlugin))
BLACK_DECLARE_TUPLE_CONVERSION(BlackSim::Settings::CSettingsSimulator, (o.m_selectedPlugin, o.m_timeSync, o.m_timeSyncOffset))
#endif // guard