From d63dd8d081a6fcd0715cd13f26df59fb831769d2 Mon Sep 17 00:00:00 2001 From: "Iain R. Learmonth" Date: Sun, 18 Oct 2015 18:51:00 +0100 Subject: Imported Upstream version 1.5.0 --- qt_helpers.hpp | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 qt_helpers.hpp (limited to 'qt_helpers.hpp') diff --git a/qt_helpers.hpp b/qt_helpers.hpp new file mode 100644 index 00000000..ec417dc3 --- /dev/null +++ b/qt_helpers.hpp @@ -0,0 +1,82 @@ +#ifndef QT_HELPERS_HPP_ +#define QT_HELPERS_HPP_ + +#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&); + +#define ENUM_QDATASTREAM_OPS_IMPL(CLASS, ENUM) \ + QDataStream& operator << (QDataStream& os, CLASS::ENUM v) \ + { \ + auto const& mo = CLASS::staticMetaObject; \ + return os << mo.enumerator (mo.indexOfEnumerator (#ENUM)).valueToKey (v); \ + } \ + \ + QDataStream& operator >> (QDataStream& is, CLASS::ENUM& v) \ + { \ + char * buffer; \ + is >> buffer; \ + bool ok {false}; \ + auto const& mo = CLASS::staticMetaObject; \ + auto const& me = mo.enumerator (mo.indexOfEnumerator (#ENUM)); \ + if (buffer) \ + { \ + v = static_cast (me.keyToValue (buffer, &ok)); \ + delete [] buffer; \ + } \ + if (!ok) \ + { \ + v = static_cast (me.value (0)); \ + } \ + return is; \ + } + +#define ENUM_QDEBUG_OPS_DECL(CLASS, ENUM) \ + QDebug operator << (QDebug, CLASS::ENUM); + +#define ENUM_QDEBUG_OPS_IMPL(CLASS, ENUM) \ + QDebug operator << (QDebug d, CLASS::ENUM 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)}; \ + } + +inline +void throw_qstring (QString const& qs) +{ + throw std::runtime_error {qs.toLocal8Bit ().constData ()}; +} + +QString font_as_stylesheet (QFont const&); + +// do what is necessary to change a dynamic property and trigger any +// conditional style sheet updates +void update_dynamic_property (QWidget *, char const * property, QVariant const& value); + +// Register some useful Qt types with QMetaType +Q_DECLARE_METATYPE (QHostAddress); + +#endif -- cgit v1.2.3