Start to take advantage of Qt 5.5 features like the new way of registering enums

git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@6583 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
Bill Somerville 2016-04-06 17:11:02 +00:00
parent 79a2a65030
commit 49d6ded6dd
8 changed files with 80 additions and 41 deletions

View File

@ -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<impl> 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);

View File

@ -11,6 +11,8 @@
#include <QMimeData>
#include <QDataStream>
#include <QByteArray>
#include <QDebug>
#include <QDebugStateSaver>
#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

View File

@ -32,7 +32,7 @@ void register_types ()
// later versions.
qRegisterMetaTypeStreamOperators<Radio::Frequencies> ("Frequencies");
item_editor_factory ()->registerEditor (frequency_type_id, new QStandardItemEditorCreator<FrequencyLineEdit> ());
item_editor_factory ()->registerEditor (frequency_type_id, new QStandardItemEditorCreator<FrequencyLineEdit> ());
auto frequency_delta_type_id = qRegisterMetaType<Radio::FrequencyDelta> ("FrequencyDelta");
item_editor_factory ()->registerEditor (frequency_delta_type_id, new QStandardItemEditorCreator<FrequencyDeltaLineEdit> ());
@ -46,33 +46,39 @@ void register_types ()
qRegisterMetaType<AudioDevice::Channel> ("AudioDevice::Channel");
// Configuration
#if QT_VERSION < 0x050500
qRegisterMetaType<Configuration::DataMode> ("Configuration::DataMode");
qRegisterMetaTypeStreamOperators<Configuration::DataMode> ("Configuration::DataMode");
qRegisterMetaType<Configuration::Type2MsgGen> ("Configuration::Type2MsgGen");
#endif
qRegisterMetaTypeStreamOperators<Configuration::DataMode> ("Configuration::DataMode");
qRegisterMetaTypeStreamOperators<Configuration::Type2MsgGen> ("Configuration::Type2MsgGen");
// Station details
qRegisterMetaType<StationList::Station> ("Station");
qRegisterMetaTypeStreamOperators<StationList::Station> ("Station");
qRegisterMetaType<StationList::Stations> ("Stations");
qRegisterMetaTypeStreamOperators<StationList::Station> ("Station");
qRegisterMetaTypeStreamOperators<StationList::Stations> ("Stations");
// Transceiver
qRegisterMetaType<Transceiver::TransceiverState> ("Transceiver::TransceiverState");
#if QT_VERSION < 0x050500
qRegisterMetaType<Transceiver::MODE> ("Transceiver::MODE");
#endif
// Transceiver factory
#if QT_VERSION < 0x050500
qRegisterMetaType<TransceiverFactory::DataBits> ("TransceiverFactory::DataBits");
qRegisterMetaTypeStreamOperators<TransceiverFactory::DataBits> ("TransceiverFactory::DataBits");
qRegisterMetaType<TransceiverFactory::StopBits> ("TransceiverFactory::StopBits");
qRegisterMetaTypeStreamOperators<TransceiverFactory::StopBits> ("TransceiverFactory::StopBits");
qRegisterMetaType<TransceiverFactory::Handshake> ("TransceiverFactory::Handshake");
qRegisterMetaTypeStreamOperators<TransceiverFactory::Handshake> ("TransceiverFactory::Handshake");
qRegisterMetaType<TransceiverFactory::PTTMethod> ("TransceiverFactory::PTTMethod");
qRegisterMetaTypeStreamOperators<TransceiverFactory::PTTMethod> ("TransceiverFactory::PTTMethod");
qRegisterMetaType<TransceiverFactory::TXAudioSource> ("TransceiverFactory::TXAudioSource");
qRegisterMetaTypeStreamOperators<TransceiverFactory::TXAudioSource> ("TransceiverFactory::TXAudioSource");
qRegisterMetaType<TransceiverFactory::SplitMode> ("TransceiverFactory::SplitMode");
#endif
qRegisterMetaTypeStreamOperators<TransceiverFactory::DataBits> ("TransceiverFactory::DataBits");
qRegisterMetaTypeStreamOperators<TransceiverFactory::StopBits> ("TransceiverFactory::StopBits");
qRegisterMetaTypeStreamOperators<TransceiverFactory::Handshake> ("TransceiverFactory::Handshake");
qRegisterMetaTypeStreamOperators<TransceiverFactory::PTTMethod> ("TransceiverFactory::PTTMethod");
qRegisterMetaTypeStreamOperators<TransceiverFactory::TXAudioSource> ("TransceiverFactory::TXAudioSource");
qRegisterMetaTypeStreamOperators<TransceiverFactory::SplitMode> ("TransceiverFactory::SplitMode");
// Waterfall palette

View File

@ -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);

View File

@ -14,6 +14,7 @@
#include <QDataStream>
#include <QByteArray>
#include <QDebug>
#include <QDebugStateSaver>
#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

View File

@ -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&);

View File

@ -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);

View File

@ -2,24 +2,20 @@
#define QT_HELPERS_HPP_
#include <stdexcept>
#include <functional>
#include <QDataStream>
#include <QString>
#include <QMetaObject>
#include <QHostAddress>
#include <QDataStream>
#include <QMetaType>
#include <QMetaEnum>
#include <QString>
#include <QDebug>
#include <QHostAddress>
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<CLASS::ENUM> (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 <QDebug>
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)