mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
refs #716, value class / setting
This commit is contained in:
@@ -122,8 +122,9 @@ namespace BlackMisc
|
||||
GlobalIndexCTextMessage = 6900,
|
||||
GlobalIndexCSimulatorSetup = 7000,
|
||||
GlobalIndexCSimulatorSettings = 7100,
|
||||
GlobalIndexCAircraftCfgEntries = 7200,
|
||||
GlobalIndexCDistributor = 7300,
|
||||
GlobalIndexCSimulatorMessageSettings = 7200,
|
||||
GlobalIndexCAircraftCfgEntries = 7300,
|
||||
GlobalIndexCDistributor = 7400,
|
||||
GlobalIndexCVPilotModelRule = 8000,
|
||||
GlobalIndexCVoiceRoom = 9000,
|
||||
GlobalIndexCSettingKeyboardHotkey = 10000,
|
||||
|
||||
@@ -43,6 +43,7 @@ namespace BlackMisc
|
||||
CVPilotModelRule::registerMetadata();
|
||||
CVPilotModelRuleSet::registerMetadata();
|
||||
CSettingsSimulator::registerMetadata();
|
||||
CSettingsSimulatorMessages::registerMetadata();
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -8,12 +8,13 @@
|
||||
*/
|
||||
|
||||
#include "settingssimulator.h"
|
||||
#include "blackmisc/simulation/simulatedaircraft.h"
|
||||
#include "blackmisc/simulation/fscommon/fscommonutil.h"
|
||||
#include "blackmisc/simulation/xplane/xplaneutil.h"
|
||||
#include "blackmisc/stringutils.h"
|
||||
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
using namespace BlackMisc::Simulation::FsCommon;
|
||||
using namespace BlackMisc::Simulation::XPlane;
|
||||
|
||||
@@ -283,6 +284,159 @@ namespace BlackMisc
|
||||
s.resetPaths();
|
||||
this->setAndSaveSettings(s, simulator);
|
||||
}
|
||||
|
||||
CSettingsSimulatorMessages::CSettingsSimulatorMessages()
|
||||
{
|
||||
// void
|
||||
}
|
||||
|
||||
void CSettingsSimulatorMessages::setTechnicalLogSeverity(CStatusMessage::StatusSeverity severity)
|
||||
{
|
||||
this->m_technicalLogLevel = static_cast<int>(severity);
|
||||
}
|
||||
|
||||
void CSettingsSimulatorMessages::disableTechnicalMessages()
|
||||
{
|
||||
this->m_technicalLogLevel = -1;
|
||||
}
|
||||
|
||||
bool CSettingsSimulatorMessages::isRelayedErrorsMessages() const
|
||||
{
|
||||
if (this->m_technicalLogLevel < 0) { return false; }
|
||||
return (this->m_technicalLogLevel <= CStatusMessage::SeverityError);
|
||||
}
|
||||
|
||||
bool CSettingsSimulatorMessages::isRelayedWarningMessages() const
|
||||
{
|
||||
if (this->m_technicalLogLevel < 0) { return false; }
|
||||
return (this->m_technicalLogLevel <= CStatusMessage::SeverityWarning);
|
||||
}
|
||||
|
||||
bool CSettingsSimulatorMessages::isRelayedInfoMessages() const
|
||||
{
|
||||
if (this->m_technicalLogLevel < 0) { return false; }
|
||||
return (this->m_technicalLogLevel <= CStatusMessage::SeverityInfo);
|
||||
}
|
||||
|
||||
bool CSettingsSimulatorMessages::isRelayedTechnicalMessages() const
|
||||
{
|
||||
return (this->m_technicalLogLevel >= 0);
|
||||
}
|
||||
|
||||
void CSettingsSimulatorMessages::setRelayedTextMessages(CSettingsSimulatorMessages::TextMessageType messageType)
|
||||
{
|
||||
this->m_messageType = static_cast<int>(messageType);
|
||||
}
|
||||
|
||||
bool CSettingsSimulatorMessages::isRelayedSupervisorTextMessages() const
|
||||
{
|
||||
return this->getRelayedTextMessageTypes().testFlag(TextMessageSupervisor);
|
||||
}
|
||||
|
||||
bool CSettingsSimulatorMessages::isRelayedPrivateTextMessages() const
|
||||
{
|
||||
return this->getRelayedTextMessageTypes().testFlag(TextMessagePrivate);
|
||||
}
|
||||
|
||||
bool CSettingsSimulatorMessages::isRelayedUnicomTextMessages() const
|
||||
{
|
||||
return this->getRelayedTextMessageTypes().testFlag(TextMessagesUnicom);
|
||||
}
|
||||
|
||||
bool CSettingsSimulatorMessages::isRelayedCom1TextMessages() const
|
||||
{
|
||||
return this->getRelayedTextMessageTypes().testFlag(TextMessagesCom1);
|
||||
}
|
||||
|
||||
bool CSettingsSimulatorMessages::isRelayedCom2TextMessages() const
|
||||
{
|
||||
return this->getRelayedTextMessageTypes().testFlag(TextMessagesCom2);
|
||||
}
|
||||
|
||||
bool CSettingsSimulatorMessages::isRelayedTextMessage(const Network::CTextMessage &msg, const BlackMisc::Simulation::CSimulatedAircraft &aircraft) const
|
||||
{
|
||||
if (msg.isEmpty()) { return false; }
|
||||
if (!this->isGloballyEnabled()) { return false; }
|
||||
if (this->m_messageType == NoTextMessages) { return false; }
|
||||
|
||||
const TextMessageType mt = static_cast<TextMessageType>(this->m_messageType);
|
||||
if (msg.isPrivateMessage() && mt.testFlag(TextMessagePrivate)) { return true; }
|
||||
if (msg.isSupervisorMessage() && (mt.testFlag(TextMessagePrivate) || mt.testFlag(TextMessageSupervisor))) { return true; }
|
||||
if (msg.isSendToUnicom() && mt.testFlag(TextMessagesUnicom)) { return true; }
|
||||
|
||||
if (msg.isRadioMessage())
|
||||
{
|
||||
const CFrequency f(msg.getFrequency());
|
||||
if (mt.testFlag(TextMessagesCom1))
|
||||
{
|
||||
if (aircraft.getCom1System().isActiveFrequencyWithin8_33kHzChannel(f)) { return true; }
|
||||
}
|
||||
if (mt.testFlag(TextMessagesCom2))
|
||||
{
|
||||
if (aircraft.getCom2System().isActiveFrequencyWithin8_33kHzChannel(f)) { return true; }
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
CSettingsSimulatorMessages::TextMessageType CSettingsSimulatorMessages::getRelayedTextMessageTypes() const
|
||||
{
|
||||
return static_cast<CSettingsSimulatorMessages::TextMessageType>(this->m_messageType);
|
||||
}
|
||||
|
||||
QString CSettingsSimulatorMessages::convertToQString(bool i18n) const
|
||||
{
|
||||
Q_UNUSED(i18n);
|
||||
QString s("Enabled %1, text messages: %2, severity: %3");
|
||||
QString severity;
|
||||
if (this->isRelayedTechnicalMessages())
|
||||
{
|
||||
severity = "No tech. msgs";
|
||||
}
|
||||
else
|
||||
{
|
||||
severity = CStatusMessage::severityToString(static_cast<CStatusMessage::StatusSeverity>(this->m_technicalLogLevel));
|
||||
}
|
||||
return s.arg(boolToOnOff(this->m_globallyEnabled)).arg(this->m_messageType).arg(severity);
|
||||
}
|
||||
|
||||
CVariant CSettingsSimulatorMessages::propertyByIndex(const CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexTechnicalLogSeverity:
|
||||
return CVariant::fromValue(this->m_technicalLogLevel);
|
||||
case IndexTextMessageRelay:
|
||||
return CVariant::from(this->m_messageType);
|
||||
case IndexGloballyEnabled:
|
||||
return CVariant::from(this->m_globallyEnabled);
|
||||
default:
|
||||
return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
void CSettingsSimulatorMessages::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
|
||||
{
|
||||
if (index.isMyself()) { (*this) = variant.to<CSettingsSimulatorMessages>(); return; }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexTechnicalLogSeverity:
|
||||
this->setTechnicalLogSeverity(static_cast<CStatusMessage::StatusSeverity>(variant.toInt()));
|
||||
break;
|
||||
case IndexTextMessageRelay:
|
||||
this->setRelayedTextMessages(static_cast<CSettingsSimulatorMessages::TextMessageType>(variant.toInt()));
|
||||
break;
|
||||
case IndexGloballyEnabled:
|
||||
this->setGloballyEnabled(variant.toBool());
|
||||
break;
|
||||
default:
|
||||
CValueObject::setPropertyByIndex(index, variant);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -12,9 +12,11 @@
|
||||
#ifndef BLACKMISC_SIMULATION_SETTINGS_SETTINGSSIMULATOR_H
|
||||
#define BLACKMISC_SIMULATION_SETTINGS_SETTINGSSIMULATOR_H
|
||||
|
||||
#include "blackmisc/settingscache.h"
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/simulation/simulatorinfo.h"
|
||||
#include "blackmisc/network/textmessage.h"
|
||||
#include "blackmisc/settingscache.h"
|
||||
#include "blackmisc/statusmessage.h"
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
|
||||
#include <QStringList>
|
||||
@@ -24,6 +26,8 @@ namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
class CSimulatedAircraft;
|
||||
|
||||
namespace Settings
|
||||
{
|
||||
//! Settings for simulator
|
||||
@@ -174,6 +178,115 @@ namespace BlackMisc
|
||||
BlackMisc::CSetting<BlackMisc::Simulation::Settings::SettingsSimulatorP3D> m_simSettingsP3D {this}; //!< P3D cache
|
||||
BlackMisc::CSetting<BlackMisc::Simulation::Settings::SettingsSimulatorXP> m_simSettingsXP {this}; //!< XP cache
|
||||
};
|
||||
|
||||
//! Settings regarding message handling.
|
||||
//! Driver independent part, related to network
|
||||
class BLACKMISC_EXPORT CSettingsSimulatorMessages :
|
||||
public BlackMisc::CValueObject<CSettingsSimulatorMessages>
|
||||
{
|
||||
public:
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexTechnicalLogSeverity = BlackMisc::CPropertyIndex::GlobalIndexCSimulatorMessageSettings,
|
||||
IndexTextMessageRelay,
|
||||
IndexGloballyEnabled
|
||||
};
|
||||
|
||||
//! Enabled matching mode flags
|
||||
enum TextMessageTypeFlag
|
||||
{
|
||||
NoTextMessages = 0,
|
||||
TextMessagesUnicom = 1 << 0,
|
||||
TextMessagesCom1 = 1 << 1,
|
||||
TextMessagesCom2 = 1 << 2,
|
||||
TextMessagePrivate = 1 << 3,
|
||||
TextMessageSupervisor = 1 << 4,
|
||||
TextMessagesAll = TextMessagesUnicom | TextMessagesCom1 | TextMessagesCom2 | TextMessagePrivate
|
||||
};
|
||||
Q_DECLARE_FLAGS(TextMessageType, TextMessageTypeFlag)
|
||||
|
||||
//! Default constructor
|
||||
CSettingsSimulatorMessages();
|
||||
|
||||
//! Destructor.
|
||||
~CSettingsSimulatorMessages() {}
|
||||
|
||||
//! Log severity
|
||||
void setTechnicalLogSeverity(BlackMisc::CStatusMessage::StatusSeverity severity);
|
||||
|
||||
//! Globally enable / disable
|
||||
void setGloballyEnabled(bool enabled) { this->m_globallyEnabled = enabled; }
|
||||
|
||||
//! Globally enabled?
|
||||
bool isGloballyEnabled() const { return this->m_globallyEnabled; }
|
||||
|
||||
//! No technical messages
|
||||
void disableTechnicalMessages();
|
||||
|
||||
//! Relay (technical) error messages
|
||||
bool isRelayedErrorsMessages() const;
|
||||
|
||||
//! Relay (technical) warning messages
|
||||
bool isRelayedWarningMessages() const;
|
||||
|
||||
//! Relay (technical) info messages
|
||||
bool isRelayedInfoMessages() const;
|
||||
|
||||
//! Relay any message
|
||||
bool isRelayedTechnicalMessages() const;
|
||||
|
||||
//! Relay the following message types
|
||||
void setRelayedTextMessages(BlackMisc::Simulation::Settings::CSettingsSimulatorMessages::TextMessageType messageType);
|
||||
|
||||
//! Relay supervisor messages
|
||||
bool isRelayedSupervisorTextMessages() const;
|
||||
|
||||
//! Relay private messages
|
||||
bool isRelayedPrivateTextMessages() const;
|
||||
|
||||
//! Relay UNICOM messages
|
||||
bool isRelayedUnicomTextMessages() const;
|
||||
|
||||
//! Relay given text message
|
||||
bool isRelayedTextMessage(const BlackMisc::Network::CTextMessage &msg, const BlackMisc::Simulation::CSimulatedAircraft &aircraft) const;
|
||||
|
||||
//! Relay COM1 text message
|
||||
bool isRelayedCom1TextMessages() const;
|
||||
|
||||
//! Relay COM2 text message
|
||||
bool isRelayedCom2TextMessages() const;
|
||||
|
||||
//! Relayed text messages
|
||||
CSettingsSimulatorMessages::TextMessageType getRelayedTextMessageTypes() const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
|
||||
BlackMisc::CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
|
||||
void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const BlackMisc::CVariant &variant);
|
||||
|
||||
private:
|
||||
int m_technicalLogLevel = BlackMisc::CStatusMessage::SeverityError; //!< Simulator directory
|
||||
int m_messageType = static_cast<int>(TextMessagePrivate | TextMessageSupervisor);
|
||||
bool m_globallyEnabled = true; //!< messsage relay enabled to simulator
|
||||
|
||||
BLACK_METACLASS(
|
||||
CSettingsSimulatorMessages,
|
||||
BLACK_METAMEMBER(technicalLogLevel),
|
||||
BLACK_METAMEMBER(messageType)
|
||||
);
|
||||
};
|
||||
|
||||
//! Trait for simulator message settings
|
||||
struct SettingsSimulatorMessages : public BlackMisc::CSettingTrait<CSettingsSimulatorMessages>
|
||||
{
|
||||
//! Key in data cache
|
||||
static const char *key() { return "settingssimulatormessages"; }
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
} // ns
|
||||
@@ -181,5 +294,11 @@ namespace BlackMisc
|
||||
Q_DECLARE_METATYPE(BlackMisc::Simulation::Settings::CSettingsSimulator)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackMisc::Simulation::Settings::CSettingsSimulator>)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackMisc::Simulation::Settings::CSettingsSimulator>)
|
||||
Q_DECLARE_METATYPE(BlackMisc::Simulation::Settings::CSettingsSimulatorMessages)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackMisc::Simulation::Settings::CSettingsSimulatorMessages>)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackMisc::Simulation::Settings::CSettingsSimulatorMessages>)
|
||||
Q_DECLARE_METATYPE(BlackMisc::Simulation::Settings::CSettingsSimulatorMessages::TextMessageTypeFlag)
|
||||
Q_DECLARE_METATYPE(BlackMisc::Simulation::Settings::CSettingsSimulatorMessages::TextMessageType)
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(BlackMisc::Simulation::Settings::CSettingsSimulatorMessages::TextMessageType)
|
||||
|
||||
#endif // guard
|
||||
|
||||
Reference in New Issue
Block a user