uistyle: Fix weird way of registering Qt types
authorManuel Nickschas <sputnick@quassel-irc.org>
Wed, 7 Mar 2018 00:38:53 +0000 (01:38 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Thu, 8 Mar 2018 01:10:28 +0000 (02:10 +0100)
Well, maybe it didn't seem so weird a decade ago, but these days
we can do type registration in a nicer way.

src/uisupport/uistyle.cpp

index 714fe91..d839aef 100644 (file)
@@ -72,13 +72,12 @@ UiStyle::UiStyle(QObject *parent)
     _opIconLimit(UserCategoryItem::categoryFromModes("o")),
     _voiceIconLimit(UserCategoryItem::categoryFromModes("v"))
 {
     _opIconLimit(UserCategoryItem::categoryFromModes("o")),
     _voiceIconLimit(UserCategoryItem::categoryFromModes("v"))
 {
-    // register FormatList if that hasn't happened yet
-    // FIXME I don't think this actually avoids double registration... then again... does it hurt?
-    if (QVariant::nameToType("UiStyle::FormatList") == QVariant::Invalid) {
-        qRegisterMetaType<FormatList>("UiStyle::FormatList");
-        qRegisterMetaTypeStreamOperators<FormatList>("UiStyle::FormatList");
-        Q_ASSERT(QVariant::nameToType("UiStyle::FormatList") != QVariant::Invalid);
-    }
+    static bool registered = []() {
+        qRegisterMetaType<FormatList>();
+        qRegisterMetaTypeStreamOperators<FormatList>();
+        return true;
+    }();
+    Q_UNUSED(registered)
 
     _uiStylePalette = QVector<QBrush>(static_cast<int>(ColorRole::NumRoles), QBrush());
 
 
     _uiStylePalette = QVector<QBrush>(static_cast<int>(ColorRole::NumRoles), QBrush());