refs #472 Removed static_cast<int> for enums in blackmisc, no longer needed.

This commit is contained in:
Mathew Sutcliffe
2015-09-27 01:41:42 +01:00
parent 9b1e42d71a
commit d13e863218
23 changed files with 104 additions and 35 deletions

View File

@@ -18,6 +18,13 @@ namespace BlackMisc
namespace Aviation
{
void CComSystem::registerMetadata()
{
Mixin::MetaType<CComSystem>::registerMetadata();
qDBusRegisterMetaType<ChannelSpacing>();
qDBusRegisterMetaType<ComUnit>();
}
bool CComSystem::validValues() const
{
if (this->isDefaultValue()) return true; // special case

View File

@@ -49,6 +49,9 @@ namespace BlackMisc
Com2
};
//! \copydoc BlackMisc::CValueObject::registerMetadata
static void registerMetadata();
//! Default constructor
CComSystem() {}
@@ -171,5 +174,7 @@ namespace BlackMisc
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Aviation::CComSystem, (o.m_channelSpacing))
Q_DECLARE_METATYPE(BlackMisc::Aviation::CComSystem)
Q_DECLARE_METATYPE(BlackMisc::Aviation::CComSystem::ChannelSpacing)
Q_DECLARE_METATYPE(BlackMisc::Aviation::CComSystem::ComUnit)
#endif // guard

View File

@@ -17,6 +17,12 @@ namespace BlackMisc
namespace Aviation
{
void CTransponder::registerMetadata()
{
CValueObject<CTransponder>::registerMetadata();
qRegisterMetaType<TransponderMode>();
}
bool CTransponder::validValues() const
{
if (this->isDefaultValue()) return true; // special case
@@ -151,7 +157,7 @@ namespace BlackMisc
switch (i)
{
case IndexMode:
return CVariant::from(static_cast<int>(this->getTransponderMode()));
return CVariant::from(this->getTransponderMode());
case IndexModeAsString:
return CVariant::from(this->getModeAsString());
case IndexTransponderCode:
@@ -176,7 +182,7 @@ namespace BlackMisc
switch (i)
{
case IndexMode:
this->setTransponderMode(static_cast<TransponderMode>(variant.toInt()));
this->setTransponderMode(variant.value<TransponderMode>());
break;
case IndexModeAsString:
this->setTransponderMode(modeFromString(variant.toQString()));

View File

@@ -45,6 +45,9 @@ namespace BlackMisc
IndexTransponderCodeAndModeFormatted
};
//! \copydoc BlackMisc::CValueObject::registerMetadata
static void registerMetadata();
//! Default constructor
CTransponder() : m_transponderCode(0), m_transponderMode(StateStandby) {}
@@ -184,5 +187,6 @@ BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Aviation::CTransponder, (
))
Q_DECLARE_METATYPE(BlackMisc::Aviation::CTransponder)
Q_DECLARE_METATYPE(BlackMisc::Aviation::CTransponder::TransponderMode)
#endif // guard

View File

@@ -54,6 +54,8 @@ void BlackMisc::Audio::registerMetadata()
CAudioDeviceInfoList::registerMetadata();
CVoiceRoom::registerMetadata();
CVoiceRoomList::registerMetadata();
qDBusRegisterMetaType<BlackSound::CNotificationSounds::PlayMode>();
qDBusRegisterMetaType<BlackSound::CNotificationSounds::Notification>();
}
void BlackMisc::Input::registerMetadata()
@@ -65,6 +67,7 @@ void BlackMisc::Input::registerMetadata()
CActionHotkey::registerMetadata();
CActionHotkeyList::registerMetadata();
CHotkeyCombination::registerMetadata();
qDBusRegisterMetaType<KeyCode>();
}
void BlackMisc::registerMetadata()

View File

@@ -14,24 +14,24 @@
namespace BlackMisc
{
CIcon::CIcon(CIcons::IconIndex index, const QString &descriptiveText) :
m_index(static_cast<int>(index)), m_descriptiveText(descriptiveText) {}
m_index(index), m_descriptiveText(descriptiveText) {}
CIcon::CIcon(const QPixmap &pixmap, const QString &descriptiveText) :
m_index(static_cast<int>(CIcons::IconIsGenerated)), m_descriptiveText(descriptiveText), m_pixmap(pixmap)
m_index(CIcons::IconIsGenerated), m_descriptiveText(descriptiveText), m_pixmap(pixmap)
{ }
CIcon::CIcon(const QString &resourceFilePath, const QString &descriptiveText) :
m_index(static_cast<int>(CIcons::IconIsFile)), m_descriptiveText(descriptiveText), m_pixmap(CIcons::pixmapByResourceFileName(resourceFilePath))
m_index(CIcons::IconIsFile), m_descriptiveText(descriptiveText), m_pixmap(CIcons::pixmapByResourceFileName(resourceFilePath))
{}
CIcons::IconIndex CIcon::getIndex() const
{
return static_cast<CIcons::IconIndex>(this->m_index);
return this->m_index;
}
bool CIcon::isIndexBased() const
{
return m_index >= 0 && m_index < static_cast<int>(CIcons::IconIsGenerated);
return m_index >= 0 && m_index < CIcons::IconIsGenerated;
}
bool CIcon::isGenerated() const
@@ -46,7 +46,7 @@ namespace BlackMisc
bool CIcon::isSet() const
{
return (this->m_index != static_cast<int>(CIcons::NotSet));
return (this->m_index != CIcons::NotSet);
}
QPixmap CIcon::toPixmap() const

View File

@@ -130,7 +130,7 @@ namespace BlackMisc
private:
BLACK_ENABLE_TUPLE_CONVERSION(CIcon)
int m_index = static_cast<int>(CIcons::NotSet);
CIcons::IconIndex m_index = CIcons::NotSet;
int m_rotateDegrees = 0; //!< Rotation
QString m_descriptiveText; //!< what does it represent?
QPixmap m_pixmap; //!< Used with generated pixmaps, when not used with index

View File

@@ -642,4 +642,7 @@ namespace BlackMisc
static QMap<QString, QPixmap> &getResourceFileCache();
};
}
Q_DECLARE_METATYPE(BlackMisc::CIcons::IconIndex)
#endif // guard

View File

@@ -75,7 +75,7 @@ namespace BlackMisc
switch (i)
{
case IndexKey:
return CVariant::from(static_cast<int>(this->m_keyCode));
return CVariant::from(this->m_keyCode);
case IndexKeyAsString:
return CVariant::from(getKeyAsString());
default:

View File

@@ -12,6 +12,8 @@
#ifndef BLACKMISC_INPUT_KEYCODES_H
#define BLACKMISC_INPUT_KEYCODES_H
#include <QMetaType>
namespace BlackMisc
{
namespace Input
@@ -70,4 +72,6 @@ namespace BlackMisc
} //namespace
} // namespace
Q_DECLARE_METATYPE(BlackMisc::Input::KeyCode)
#endif //guard

View File

@@ -54,11 +54,11 @@ namespace BlackMisc
// special case, handle icon and allow to set it
// doing this in the switch gives gcc warning as IndexIcon is no member of ColumnIndex
if (i == static_cast<int>(IndexIcon))
if (static_cast<int>(i) == static_cast<int>(IndexIcon))
{
if (static_cast<QMetaType::Type>(variant.type()) == QMetaType::Int)
{
CIcons::IconIndex index = static_cast<CIcons::IconIndex>(variant.toInt());
CIcons::IconIndex index = variant.value<CIcons::IconIndex>();
this->m_icon = CIconList::iconByIndex(index);
}
else

View File

@@ -37,16 +37,16 @@ namespace BlackMisc
CVoiceCapabilities() = default;
//! Constructor by callsign
CVoiceCapabilities(VoiceCapabilities capabilities) : m_voiceCapabilities(static_cast<int>(capabilities)) {}
CVoiceCapabilities(VoiceCapabilities capabilities) : m_voiceCapabilities(capabilities) {}
//! Constructor.
CVoiceCapabilities(const QString &flightPlanRemarks);
//! Get capabilities
VoiceCapabilities getCapabilities() const { return static_cast<VoiceCapabilities>(m_voiceCapabilities); }
VoiceCapabilities getCapabilities() const { return m_voiceCapabilities; }
//! Set capabilites
void setCapabilities(VoiceCapabilities capabilites) { m_voiceCapabilities = static_cast<int>(capabilites); }
void setCapabilities(VoiceCapabilities capabilites) { m_voiceCapabilities = capabilites; }
//! Is capability known
bool isUnknown() const { return m_voiceCapabilities == Unknown; }
@@ -71,7 +71,7 @@ namespace BlackMisc
private:
BLACK_ENABLE_TUPLE_CONVERSION(CVoiceCapabilities)
int m_voiceCapabilities = Unknown;
VoiceCapabilities m_voiceCapabilities = Unknown;
//! Capabilites from flight plans remarks such as "/V/"
void setFromFlightPlanRemarks(const QString &flightPlanRemarks);

View File

@@ -12,6 +12,8 @@
#ifndef BLACKMISC_NOTIFICATIONSOUNDS_H
#define BLACKMISC_NOTIFICATIONSOUNDS_H
#include <QMetaType>
namespace BlackSound
{
@@ -44,4 +46,7 @@ namespace BlackSound
};
} // ns
Q_DECLARE_METATYPE(BlackSound::CNotificationSounds::PlayMode)
Q_DECLARE_METATYPE(BlackSound::CNotificationSounds::Notification)
#endif // guard

View File

@@ -20,6 +20,12 @@ namespace BlackMisc
{
namespace Simulation
{
void CAircraftModel::registerMetadata()
{
CValueObject<CAircraftModel>::registerMetadata();
qRegisterMetaType<ModelType>();
}
CAircraftModel::CAircraftModel(const QString &model, CAircraftModel::ModelType type) :
m_modelString(model.trimmed().toUpper()), m_modelType(type)
{}
@@ -59,11 +65,11 @@ namespace BlackMisc
case IndexHasQueriedModelString:
return CVariant::fromValue(this->hasQueriedModelString());
case IndexModelType:
return CVariant::fromValue(static_cast<int>(this->m_modelType));
return CVariant::fromValue(this->m_modelType);
case IndexModelTypeAsString:
return CVariant(this->getModelTypeAsString());
case IndexModelMode:
return CVariant::fromValue(static_cast<int>(this->m_modelMode));
return CVariant::fromValue(this->m_modelMode);
case IndexModelModeAsString:
return CVariant(this->getModelModeAsString());
case IndexDistributor:
@@ -123,10 +129,10 @@ namespace BlackMisc
this->m_fileName = variant.toQString();
break;
case IndexModelType:
this->m_modelType = static_cast<ModelType>(variant.toInt());
this->m_modelType = variant.value<ModelType>();
break;
case IndexModelMode:
this->m_modelMode = static_cast<ModelMode>(variant.toInt());
this->m_modelMode = variant.value<ModelMode>();
break;
default:
CValueObject::setPropertyByIndex(variant, index);
@@ -173,7 +179,7 @@ namespace BlackMisc
if (this->m_description.isEmpty()) { this->setDescription(model.getDescription()); }
if (this->m_fileName.isEmpty()) { this->setFileName(model.getFileName()); }
if (this->m_callsign.isEmpty()) { this->setCallsign(model.getCallsign()); }
if (this->m_modelType == static_cast<int>(TypeUnknown)) { this->m_modelType = model.getModelType(); }
if (this->m_modelType == TypeUnknown) { this->m_modelType = model.getModelType(); }
if (this->m_simulator.isUnspecified())
{
this->setSimulatorInfo(model.getSimulatorInfo());

View File

@@ -73,6 +73,9 @@ namespace BlackMisc
IndexHasQueriedModelString
};
//! \copydoc BlackMisc::CValueObject::registerMetadata
static void registerMetadata();
//! Default constructor.
CAircraftModel() {}
@@ -272,5 +275,7 @@ BLACK_DECLARE_TUPLE_CONVERSION(
attr(o.m_modelMode)
))
Q_DECLARE_METATYPE(BlackMisc::Simulation::CAircraftModel)
Q_DECLARE_METATYPE(BlackMisc::Simulation::CAircraftModel::ModelType)
Q_DECLARE_METATYPE(BlackMisc::Simulation::CAircraftModel::ModelMode)
#endif // guard

View File

@@ -54,7 +54,7 @@ namespace BlackMisc
return this->m_ownAircraftProvider->updateCockpit(com1, com2, transponder, originator);
}
bool COwnAircraftAware::updateActiveComFrequency(const CFrequency &frequency, int comUnit, const CIdentifier &originator)
bool COwnAircraftAware::updateActiveComFrequency(const CFrequency &frequency, CComSystem::ComUnit comUnit, const CIdentifier &originator)
{
Q_ASSERT_X(this->m_ownAircraftProvider, Q_FUNC_INFO, "No object available");
return this->m_ownAircraftProvider->updateActiveComFrequency(frequency, comUnit, originator);

View File

@@ -74,7 +74,7 @@ namespace BlackMisc
//! Update cockpit, but send signals when applicable
//! \threadsafe
virtual bool updateActiveComFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency, int comUnit, const BlackMisc::CIdentifier &originator) = 0;
virtual bool updateActiveComFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency, BlackMisc::Aviation::CComSystem::ComUnit comUnit, const BlackMisc::CIdentifier &originator) = 0;
//! Update cockpit, but send signals when applicable
//! \threadsafe
@@ -105,7 +105,7 @@ namespace BlackMisc
virtual bool updateCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder, const BlackMisc::CIdentifier &originator);
//! \copydoc IOwnAircraftProvider::updateComFrequency
virtual bool updateActiveComFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency, int comUnit, const BlackMisc::CIdentifier &originator);
virtual bool updateActiveComFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency, BlackMisc::Aviation::CComSystem::ComUnit comUnit, const BlackMisc::CIdentifier &originator);
//! \copydoc IOwnAircraftProvider::updateSelcal
virtual bool updateSelcal(const BlackMisc::Aviation::CSelcal &selcal, const BlackMisc::CIdentifier &originator);

View File

@@ -46,13 +46,12 @@ namespace BlackMisc
return true;
}
bool COwnAircraftProviderDummy::updateActiveComFrequency(const PhysicalQuantities::CFrequency &frequency, int comUnit, const BlackMisc::CIdentifier &originator)
bool COwnAircraftProviderDummy::updateActiveComFrequency(const PhysicalQuantities::CFrequency &frequency, CComSystem::ComUnit comUnit, const BlackMisc::CIdentifier &originator)
{
if (!CComSystem::isValidComFrequency(frequency)) { return false; }
CComSystem::ComUnit comUnitEnum = static_cast<CComSystem::ComUnit>(comUnit);
CComSystem com = m_ownAircraft.getComSystem(comUnitEnum);
CComSystem com = m_ownAircraft.getComSystem(comUnit);
com.setFrequencyActive(frequency);
m_ownAircraft.setComSystem(com, comUnitEnum);
m_ownAircraft.setComSystem(com, comUnit);
Q_UNUSED(originator);
return true;
}

View File

@@ -53,7 +53,7 @@ namespace BlackMisc
virtual bool updateCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder, const BlackMisc::CIdentifier &originator) override;
//! \copydoc IOwnAircraftProvider::updateComFrequency
virtual bool updateActiveComFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency, int comUnit, const BlackMisc::CIdentifier &originator) override;
virtual bool updateActiveComFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency, BlackMisc::Aviation::CComSystem::ComUnit comUnit, const BlackMisc::CIdentifier &originator) override;
//! \copydoc IOwnAircraftProvider::updateSelcal
virtual bool updateSelcal(const BlackMisc::Aviation::CSelcal &selcal, const BlackMisc::CIdentifier &originator) override;

View File

@@ -18,6 +18,12 @@
namespace BlackMisc
{
void CStatusMessage::registerMetadata()
{
CValueObject<CStatusMessage>::registerMetadata();
qRegisterMetaType<StatusSeverity>();
}
CStatusMessage::CStatusMessage(const QString &message)
: m_message(message)
{}
@@ -281,7 +287,7 @@ namespace BlackMisc
case IndexMessage:
return CVariant::from(this->m_message);
case IndexSeverity:
return CVariant::from(static_cast<uint>(this->m_severity));
return CVariant::from(this->m_severity);
case IndexSeverityAsString:
return CVariant::from(this->getSeverityAsString());
case IndexCategories:
@@ -304,7 +310,7 @@ namespace BlackMisc
this->m_message = variant.value<QString>();
break;
case IndexSeverity:
this->m_severity = static_cast<StatusSeverity>(variant.value<uint>());
this->m_severity = variant.value<StatusSeverity>();
break;
case IndexCategories:
this->m_categories = variant.value<CLogCategoryList>();

View File

@@ -50,6 +50,9 @@ namespace BlackMisc
IndexMessage
};
//! \copydoc BlackMisc::CValueObject::registerMetadata
static void registerMetadata();
//! Constructor
CStatusMessage() = default;
@@ -184,5 +187,6 @@ BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::CStatusMessage, (
attr(o.m_handledByObjects, flags < DisabledForHashing | DisabledForJson | DisabledForComparison | DisabledForMarshalling > ())
))
Q_DECLARE_METATYPE(BlackMisc::CStatusMessage)
Q_DECLARE_METATYPE(BlackMisc::CStatusMessage::StatusSeverity)
#endif // guard

View File

@@ -17,6 +17,13 @@ namespace BlackMisc
namespace Weather
{
void CPresentWeather::registerMetadata()
{
CValueObject<CPresentWeather>::registerMetadata();
qRegisterMetaType<Intensity>();
qRegisterMetaType<Descriptor>();
}
CPresentWeather::CPresentWeather(Intensity intensity, Descriptor descriptor, int weatherPhenomena) :
m_intensity(intensity), m_descriptor(descriptor), m_weatherPhenomena(weatherPhenomena)
{ }
@@ -28,9 +35,9 @@ namespace BlackMisc
switch (i)
{
case IndexIntensity:
return CVariant::fromValue<int>(static_cast<int>(m_intensity));
return CVariant::fromValue(m_intensity);
case IndexDescriptor:
return CVariant::fromValue<int>(static_cast<int>(m_descriptor));
return CVariant::fromValue(m_descriptor);
case IndexWeatherPhenomena:
return CVariant::fromValue(m_weatherPhenomena);
default:
@@ -45,10 +52,10 @@ namespace BlackMisc
switch (i)
{
case IndexIntensity:
setIntensity(static_cast<Intensity>(variant.toInt()));
setIntensity(variant.value<Intensity>());
break;
case IndexDescriptor:
setDescriptor(static_cast<Descriptor>(variant.toInt()));
setDescriptor(variant.value<Descriptor>());
break;
case IndexWeatherPhenomena:
setWeatherPhenomena(variant.toInt());

View File

@@ -88,6 +88,9 @@ namespace BlackMisc
IndexWeatherPhenomena
};
//! \copydoc BlackMisc::CValueObject::registerMetadata
static void registerMetadata();
//! Default constructor.
CPresentWeather() = default;
@@ -132,6 +135,8 @@ namespace BlackMisc
} // namespace
Q_DECLARE_METATYPE(BlackMisc::Weather::CPresentWeather)
Q_DECLARE_METATYPE(BlackMisc::Weather::CPresentWeather::Intensity)
Q_DECLARE_METATYPE(BlackMisc::Weather::CPresentWeather::Descriptor)
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Weather::CPresentWeather, (
attr(o.m_intensity),
attr(o.m_descriptor),