diff --git a/Configuration.hpp b/Configuration.hpp index 099d31e69..1f7a7fc8d 100644 --- a/Configuration.hpp +++ b/Configuration.hpp @@ -54,8 +54,8 @@ class QHostAddress; class Configuration final : public QObject { - Q_OBJECT; - Q_ENUMS (DataMode Type2MsgGen); + Q_OBJECT + Q_ENUMS (DataMode Type2MsgGen) public: using MODE = Transceiver::MODE; @@ -64,7 +64,9 @@ public: using port_type = quint16; enum DataMode {data_mode_none, data_mode_USB, data_mode_data}; + Q_ENUM (DataMode) enum Type2MsgGen {type_2_msg_1_full, type_2_msg_3_full, type_2_msg_5_only}; + Q_ENUM (Type2MsgGen) explicit Configuration (QSettings * settings, QWidget * parent = nullptr); ~Configuration (); @@ -219,9 +221,10 @@ private: pimpl m_; }; - +#if QT_VERSION < 0x050500 Q_DECLARE_METATYPE (Configuration::DataMode); Q_DECLARE_METATYPE (Configuration::Type2MsgGen); +#endif #if !defined (QT_NO_DEBUG_STREAM) ENUM_QDEBUG_OPS_DECL (Configuration, DataMode); diff --git a/FrequencyList.cpp b/FrequencyList.cpp index e05d5382b..764110504 100644 --- a/FrequencyList.cpp +++ b/FrequencyList.cpp @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include "Bands.hpp" #include "pimpl_impl.hpp" @@ -105,10 +107,11 @@ namespace #if !defined (QT_NO_DEBUG_STREAM) QDebug operator << (QDebug debug, FrequencyList::Item const& item) { + QDebugStateSaver saver {debug}; debug.nospace () << "FrequencyItem(" << item.frequency_ << ", " << item.mode_ << ')'; - return debug.space (); + return debug; } #endif diff --git a/MetaDataRegistry.cpp b/MetaDataRegistry.cpp index 8876397c4..49a56a680 100644 --- a/MetaDataRegistry.cpp +++ b/MetaDataRegistry.cpp @@ -32,7 +32,7 @@ void register_types () // later versions. qRegisterMetaTypeStreamOperators ("Frequencies"); - item_editor_factory ()->registerEditor (frequency_type_id, new QStandardItemEditorCreator ()); + item_editor_factory ()->registerEditor (frequency_type_id, new QStandardItemEditorCreator ()); auto frequency_delta_type_id = qRegisterMetaType ("FrequencyDelta"); item_editor_factory ()->registerEditor (frequency_delta_type_id, new QStandardItemEditorCreator ()); @@ -46,33 +46,39 @@ void register_types () qRegisterMetaType ("AudioDevice::Channel"); // Configuration +#if QT_VERSION < 0x050500 qRegisterMetaType ("Configuration::DataMode"); - qRegisterMetaTypeStreamOperators ("Configuration::DataMode"); qRegisterMetaType ("Configuration::Type2MsgGen"); +#endif + qRegisterMetaTypeStreamOperators ("Configuration::DataMode"); qRegisterMetaTypeStreamOperators ("Configuration::Type2MsgGen"); // Station details qRegisterMetaType ("Station"); - qRegisterMetaTypeStreamOperators ("Station"); qRegisterMetaType ("Stations"); + qRegisterMetaTypeStreamOperators ("Station"); qRegisterMetaTypeStreamOperators ("Stations"); // Transceiver qRegisterMetaType ("Transceiver::TransceiverState"); +#if QT_VERSION < 0x050500 qRegisterMetaType ("Transceiver::MODE"); +#endif // Transceiver factory +#if QT_VERSION < 0x050500 qRegisterMetaType ("TransceiverFactory::DataBits"); - qRegisterMetaTypeStreamOperators ("TransceiverFactory::DataBits"); qRegisterMetaType ("TransceiverFactory::StopBits"); - qRegisterMetaTypeStreamOperators ("TransceiverFactory::StopBits"); qRegisterMetaType ("TransceiverFactory::Handshake"); - qRegisterMetaTypeStreamOperators ("TransceiverFactory::Handshake"); qRegisterMetaType ("TransceiverFactory::PTTMethod"); - qRegisterMetaTypeStreamOperators ("TransceiverFactory::PTTMethod"); qRegisterMetaType ("TransceiverFactory::TXAudioSource"); - qRegisterMetaTypeStreamOperators ("TransceiverFactory::TXAudioSource"); qRegisterMetaType ("TransceiverFactory::SplitMode"); +#endif + qRegisterMetaTypeStreamOperators ("TransceiverFactory::DataBits"); + qRegisterMetaTypeStreamOperators ("TransceiverFactory::StopBits"); + qRegisterMetaTypeStreamOperators ("TransceiverFactory::Handshake"); + qRegisterMetaTypeStreamOperators ("TransceiverFactory::PTTMethod"); + qRegisterMetaTypeStreamOperators ("TransceiverFactory::TXAudioSource"); qRegisterMetaTypeStreamOperators ("TransceiverFactory::SplitMode"); // Waterfall palette diff --git a/Modes.hpp b/Modes.hpp index 149a2e3b1..36a0f29ae 100644 --- a/Modes.hpp +++ b/Modes.hpp @@ -8,8 +8,8 @@ class Modes final : public QAbstractListModel { - Q_OBJECT; - Q_ENUMS (Mode); + Q_OBJECT + Q_ENUMS (Mode) public: enum Mode @@ -23,6 +23,7 @@ public: ISCAT, JTMSK, }; + Q_ENUM (Mode) explicit Modes (QObject * parent = nullptr); @@ -38,7 +39,9 @@ public: QVariant headerData (int section, Qt::Orientation, int = Qt::DisplayRole) const override; }; +#if QT_VERSION < 0x050500 Q_DECLARE_METATYPE (Modes::Mode); +#endif #if !defined (QT_NO_DEBUG_STREAM) ENUM_QDEBUG_OPS_DECL (Modes, Mode); diff --git a/StationList.cpp b/StationList.cpp index baa6f8179..8965525dc 100644 --- a/StationList.cpp +++ b/StationList.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include "pimpl_impl.hpp" @@ -23,11 +24,12 @@ #if !defined (QT_NO_DEBUG_STREAM) QDebug operator << (QDebug debug, StationList::Station const& station) { + QDebugStateSaver saver {debug}; debug.nospace () << "Station(" << station.band_name_ << ", " << station.offset_ << ", " << station.antenna_description_ << ')'; - return debug.space (); + return debug; } #endif diff --git a/Transceiver.hpp b/Transceiver.hpp index 067608d44..f84215693 100644 --- a/Transceiver.hpp +++ b/Transceiver.hpp @@ -51,8 +51,8 @@ class QString; class Transceiver : public QObject { - Q_OBJECT; - Q_ENUMS (MODE); + Q_OBJECT + Q_ENUMS (MODE) public: using Frequency = Radio::Frequency; @@ -68,6 +68,7 @@ public: } enum MODE {UNK, CW, CW_R, USB, LSB, FSK, FSK_R, DIG_U, DIG_L, AM, FM, DIG_FM}; + Q_ENUM (MODE) // // Aggregation of all of the rig and PTT state accessible via this @@ -153,7 +154,9 @@ public: }; Q_DECLARE_METATYPE (Transceiver::TransceiverState); +#if QT_VERSION < 0x050500 Q_DECLARE_METATYPE (Transceiver::MODE); +#endif #if !defined (QT_NO_DEBUG_STREAM) ENUM_QDEBUG_OPS_DECL (Transceiver, MODE); @@ -162,7 +165,6 @@ QDebug operator << (QDebug, Transceiver::TransceiverState const&); #endif ENUM_QDATASTREAM_OPS_DECL (Transceiver, MODE); - ENUM_CONVERSION_OPS_DECL (Transceiver, MODE); bool operator != (Transceiver::TransceiverState const&, Transceiver::TransceiverState const&); diff --git a/TransceiverFactory.hpp b/TransceiverFactory.hpp index f8395e3f5..ec1b16ea6 100644 --- a/TransceiverFactory.hpp +++ b/TransceiverFactory.hpp @@ -20,8 +20,8 @@ class QDir; class TransceiverFactory : public QObject { - Q_OBJECT; - Q_ENUMS (DataBits StopBits Handshake PTTMethod TXAudioSource SplitMode); + Q_OBJECT + Q_ENUMS (DataBits StopBits Handshake PTTMethod TXAudioSource SplitMode) public: // @@ -65,11 +65,17 @@ public: // various Transceiver parameters // enum DataBits {seven_data_bits = 7, eight_data_bits}; + Q_ENUM (DataBits) enum StopBits {one_stop_bit = 1, two_stop_bits}; + Q_ENUM (StopBits) enum Handshake {handshake_none, handshake_XonXoff, handshake_hardware}; + Q_ENUM (Handshake) enum PTTMethod {PTT_method_VOX, PTT_method_CAT, PTT_method_DTR, PTT_method_RTS}; + Q_ENUM (PTTMethod) enum TXAudioSource {TX_audio_source_front, TX_audio_source_rear}; + Q_ENUM (TXAudioSource) enum SplitMode {split_mode_none, split_mode_rig, split_mode_emulate}; + Q_ENUM (SplitMode) TransceiverFactory (); @@ -157,12 +163,14 @@ bool operator != (TransceiverFactory::ParameterPack const& lhs, TransceiverFacto // boilerplate routines to make enum types useable and debuggable in // Qt // +#if QT_VERSION < 0x050500 Q_DECLARE_METATYPE (TransceiverFactory::DataBits); Q_DECLARE_METATYPE (TransceiverFactory::StopBits); Q_DECLARE_METATYPE (TransceiverFactory::Handshake); Q_DECLARE_METATYPE (TransceiverFactory::PTTMethod); Q_DECLARE_METATYPE (TransceiverFactory::TXAudioSource); Q_DECLARE_METATYPE (TransceiverFactory::SplitMode); +#endif #if !defined (QT_NO_DEBUG_STREAM) ENUM_QDEBUG_OPS_DECL (TransceiverFactory, DataBits); diff --git a/qt_helpers.hpp b/qt_helpers.hpp index 847731ce2..bc3ce74d3 100644 --- a/qt_helpers.hpp +++ b/qt_helpers.hpp @@ -2,24 +2,20 @@ #define QT_HELPERS_HPP_ #include -#include -#include +#include #include +#include +#include #include #include -#include -#include -#include - -class QVariant; #define ENUM_QDATASTREAM_OPS_DECL(CLASS, ENUM) \ - QDataStream& operator << (QDataStream&, CLASS::ENUM); \ + QDataStream& operator << (QDataStream&, CLASS::ENUM const&); \ QDataStream& operator >> (QDataStream&, CLASS::ENUM&); #define ENUM_QDATASTREAM_OPS_IMPL(CLASS, ENUM) \ - QDataStream& operator << (QDataStream& os, CLASS::ENUM v) \ + QDataStream& operator << (QDataStream& os, CLASS::ENUM const& v) \ { \ auto const& mo = CLASS::staticMetaObject; \ return os << mo.enumerator (mo.indexOfEnumerator (#ENUM)).valueToKey (v); \ @@ -31,7 +27,7 @@ class QVariant; is >> buffer; \ bool ok {false}; \ auto const& mo = CLASS::staticMetaObject; \ - auto const& me = mo.enumerator (mo.indexOfEnumerator (#ENUM)); \ + auto const& me = mo.enumerator (mo.indexOfEnumerator (#ENUM)); \ if (buffer) \ { \ v = static_cast (me.keyToValue (buffer, &ok)); \ @@ -44,25 +40,41 @@ class QVariant; return is; \ } +#define ENUM_CONVERSION_OPS_DECL(CLASS, ENUM) \ + QString enum_to_qstring (CLASS::ENUM const&); + +#define ENUM_CONVERSION_OPS_IMPL(CLASS, ENUM) \ + QString enum_to_qstring (CLASS::ENUM const& m) \ + { \ + auto const& mo = CLASS::staticMetaObject; \ + return QString {mo.enumerator (mo.indexOfEnumerator (#ENUM)).valueToKey (m)}; \ + } + +#if QT_VERSION >= 0x050500 + +// Qt 5.5 now has Q_ENUM which registers enumns better +#define ENUM_QDEBUG_OPS_DECL(CLASS, ENUM) +#define ENUM_QDEBUG_OPS_IMPL(CLASS, ENUM) + +#else + +#define Q_ENUM(E) + +#include + +class QVariant; + #define ENUM_QDEBUG_OPS_DECL(CLASS, ENUM) \ - QDebug operator << (QDebug, CLASS::ENUM); + QDebug operator << (QDebug, CLASS::ENUM const&); #define ENUM_QDEBUG_OPS_IMPL(CLASS, ENUM) \ - QDebug operator << (QDebug d, CLASS::ENUM m) \ + QDebug operator << (QDebug d, CLASS::ENUM const& m) \ { \ auto const& mo = CLASS::staticMetaObject; \ return d << mo.enumerator (mo.indexOfEnumerator (#ENUM)).valueToKey (m); \ } -#define ENUM_CONVERSION_OPS_DECL(CLASS, ENUM) \ - QString enum_to_qstring (CLASS::ENUM); - -#define ENUM_CONVERSION_OPS_IMPL(CLASS, ENUM) \ - QString enum_to_qstring (CLASS::ENUM m) \ - { \ - auto const& mo = CLASS::staticMetaObject; \ - return QString {mo.enumerator (mo.indexOfEnumerator (#ENUM)).valueToKey (m)}; \ - } +#endif inline void throw_qstring (QString const& qs)