Procházet zdrojové kódy

Merge branch 'fix-qt5-cmdline-build-error'

* fix-qt5-cmdline-build-error:
  CommandLineModules: Fix build error related to ambiguous call to QStringRef::compare
  CommandLineModules: Fix Qt5 build error related to ResultStore
Jean-Christophe Fillion-Robin před 7 roky
rodič
revize
9604eda05c

+ 8 - 1
Libs/CommandLineModules/Core/ctkCmdLineModuleFutureInterface.cpp

@@ -112,9 +112,12 @@ QFutureInterface<ctkCmdLineModuleResult>::~QFutureInterface()
 #if QT_VERSION < QT_VERSION_CHECK(5,0,0)
   if (referenceCountIsOne())
     resultStore().clear();
-#else
+#elif QT_VERSION < QT_VERSION_CHECK(5,9,0)
   if (!derefT())
     resultStore().clear();
+#else
+  if (!derefT())
+    resultStore().clear<ctkCmdLineModuleResult>();
 #endif
 
   if (!d->RefCount.deref())
@@ -139,7 +142,11 @@ QFutureInterface<ctkCmdLineModuleResult>::operator=(const QFutureInterface& othe
   other.refT();
   if (!derefT())
 #endif
+#if QT_VERSION < QT_VERSION_CHECK(5,9,0)
     resultStore().clear();
+#else
+    resultStore().clear<ctkCmdLineModuleResult>();
+#endif
 
   QFutureInterfaceBase::operator=(other);
 

+ 32 - 9
Libs/CommandLineModules/Core/ctkCmdLineModuleFutureInterface.h

@@ -27,7 +27,7 @@
 #include "ctkCmdLineModuleResult.h"
 
 #include <QFutureInterface>
-#if (QT_VERSION < 0x50000)
+#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
 #include <QtCore>
 #else
 #include <QtConcurrent>
@@ -88,16 +88,21 @@ private:
 
   friend struct ctkCmdLineModuleFutureWatcherPrivate;
 
-#if (QT_VERSION < 0x50000)
+#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
   QtConcurrent::ResultStore<ctkCmdLineModuleResult> &resultStore()
   { return static_cast<QtConcurrent::ResultStore<ctkCmdLineModuleResult> &>(resultStoreBase()); }
   const QtConcurrent::ResultStore<ctkCmdLineModuleResult> &resultStore() const
   { return static_cast<const QtConcurrent::ResultStore<ctkCmdLineModuleResult> &>(resultStoreBase()); }
-#else
+#elif (QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
   QtPrivate::ResultStore<ctkCmdLineModuleResult> &resultStore()
   { return static_cast<QtPrivate::ResultStore<ctkCmdLineModuleResult> &>(resultStoreBase()); }
   const QtPrivate::ResultStore<ctkCmdLineModuleResult> &resultStore() const
   { return static_cast<const QtPrivate::ResultStore<ctkCmdLineModuleResult> &>(resultStoreBase()); }
+#else
+  QtPrivate::ResultStoreBase &resultStore()
+  { return static_cast<QtPrivate::ResultStoreBase &>(resultStoreBase()); }
+  const QtPrivate::ResultStoreBase &resultStore() const
+  { return static_cast<const QtPrivate::ResultStoreBase &>(resultStoreBase()); }
 #endif
 
   ctkCmdLineModuleFutureInterfacePrivate* d;
@@ -110,10 +115,12 @@ inline void QFutureInterface<ctkCmdLineModuleResult>::reportResult(const ctkCmdL
         return;
     }
 
-#if (QT_VERSION < 0x50000)
+#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
     QtConcurrent::ResultStore<ctkCmdLineModuleResult> &store = resultStore();
-#else
+#elif (QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
     QtPrivate::ResultStore<ctkCmdLineModuleResult> &store = resultStore();
+#else
+    QtPrivate::ResultStoreBase &store = resultStore();
 #endif
 
     if (store.filterMode()) {
@@ -138,10 +145,12 @@ inline void QFutureInterface<ctkCmdLineModuleResult>::reportResults(const QVecto
         return;
     }
 
-#if (QT_VERSION < 0x50000)
+#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
     QtConcurrent::ResultStore<ctkCmdLineModuleResult> &store = resultStore();
-#else
+#elif (QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
     QtPrivate::ResultStore<ctkCmdLineModuleResult> &store = resultStore();
+#else
+    QtPrivate::ResultStoreBase &store = resultStore();
 #endif
 
     if (store.filterMode()) {
@@ -164,13 +173,21 @@ inline void QFutureInterface<ctkCmdLineModuleResult>::reportFinished(const ctkCm
 inline const ctkCmdLineModuleResult &QFutureInterface<ctkCmdLineModuleResult>::resultReference(int index) const
 {
     QMutexLocker lock(mutex());
+#if (QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
     return resultStore().resultAt(index).value();
+#else
+    return resultStore().resultAt(index).value<ctkCmdLineModuleResult>();
+#endif
 }
 
 inline const ctkCmdLineModuleResult *QFutureInterface<ctkCmdLineModuleResult>::resultPointer(int index) const
 {
     QMutexLocker lock(mutex());
+#if (QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
     return resultStore().resultAt(index).pointer();
+#else
+    return resultStore().resultAt(index).pointer<ctkCmdLineModuleResult>();
+#endif
 }
 
 inline QList<ctkCmdLineModuleResult> QFutureInterface<ctkCmdLineModuleResult>::results()
@@ -184,13 +201,19 @@ inline QList<ctkCmdLineModuleResult> QFutureInterface<ctkCmdLineModuleResult>::r
     QList<ctkCmdLineModuleResult> res;
     QMutexLocker lock(mutex());
 
-#if (QT_VERSION <= 0x50000)
+#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
     QtConcurrent::ResultIterator<ctkCmdLineModuleResult> it = resultStore().begin();
-#else
+#elif (QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
     QtPrivate::ResultIterator<ctkCmdLineModuleResult> it = resultStore().begin();
+#else
+    QtPrivate::ResultIteratorBase it = resultStore().begin();
 #endif
     while (it != resultStore().end()) {
+#if (QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
         res.append(it.value());
+#else
+        res.append(it.value<ctkCmdLineModuleResult>());
+#endif
         ++it;
     }
 

+ 21 - 16
Libs/CommandLineModules/Core/ctkCmdLineModuleParameterParsers_p.h

@@ -29,10 +29,15 @@
 
 namespace {
 
+static int compare(const QStringRef& value1, const char* value2, Qt::CaseSensitivity cs = Qt::CaseSensitive)
+{
+  return value1.compare(QLatin1String(value2), cs);
+}
+
 static bool parseBooleanAttribute(const QStringRef& attrValue)
 {
-  if (attrValue.compare("true", Qt::CaseInsensitive) == 0 ||
-      attrValue.compare("1") == 0)
+  if (compare(attrValue, "true", Qt::CaseInsensitive) == 0 ||
+      compare(attrValue, "1") == 0)
   {
     return true;
   }
@@ -79,23 +84,23 @@ protected:
 
     QStringRef name = xmlReader.name();
 
-    if (name.compare("name", Qt::CaseInsensitive) == 0)
+    if (compare(name, "name", Qt::CaseInsensitive) == 0)
     {
       moduleParamPrivate->Name = xmlReader.readElementText().trimmed();
     }
-    else if (name.compare("description", Qt::CaseInsensitive) == 0)
+    else if (compare(name, "description", Qt::CaseInsensitive) == 0)
     {
       moduleParamPrivate->Description = xmlReader.readElementText().trimmed();
     }
-    else if (name.compare("label", Qt::CaseInsensitive) == 0)
+    else if (compare(name, "label", Qt::CaseInsensitive) == 0)
     {
       moduleParamPrivate->Label = xmlReader.readElementText().trimmed();
     }
-    else if (name.compare("default", Qt::CaseInsensitive) == 0)
+    else if (compare(name, "default", Qt::CaseInsensitive) == 0)
     {
       moduleParamPrivate->Default = xmlReader.readElementText().trimmed();
     }
-    else if (name.compare("flag", Qt::CaseInsensitive) == 0)
+    else if (compare(name, "flag", Qt::CaseInsensitive) == 0)
     {
       QString flag = xmlReader.readElementText().trimmed();
       if (flag.startsWith('-')) flag = flag.remove(0, 1);
@@ -103,7 +108,7 @@ protected:
       moduleParamPrivate->FlagAliasesAsString = xmlReader.attributes().value("alias").toString();
       moduleParamPrivate->DeprecatedFlagAliasesAsString = xmlReader.attributes().value("deprecatedalias").toString();
     }
-    else if (name.compare("longflag", Qt::CaseInsensitive) == 0)
+    else if (compare(name, "longflag", Qt::CaseInsensitive) == 0)
     {
       QString longFlag = xmlReader.readElementText().trimmed();
       if (longFlag.startsWith('-')) longFlag = longFlag.remove(0, 1);
@@ -111,11 +116,11 @@ protected:
       moduleParamPrivate->LongFlagAliasesAsString = xmlReader.attributes().value("alias").toString();
       moduleParamPrivate->DeprecatedLongFlagAliasesAsString = xmlReader.attributes().value("deprecatedalias").toString();
     }
-    else if (name.compare("index", Qt::CaseInsensitive) == 0)
+    else if (compare(name, "index", Qt::CaseInsensitive) == 0)
     {
       moduleParamPrivate->Index = xmlReader.readElementText().toInt();
     }
-    else if (name.compare("channel", Qt::CaseInsensitive) == 0)
+    else if (compare(name, "channel", Qt::CaseInsensitive) == 0)
     {
       moduleParamPrivate->Channel = xmlReader.readElementText().trimmed();
     }
@@ -134,15 +139,15 @@ protected:
     while(xmlReader.readNextStartElement())
     {
       QStringRef constraintElem = xmlReader.name();
-      if (constraintElem.compare("minimum", Qt::CaseInsensitive) == 0)
+      if (compare(constraintElem, "minimum", Qt::CaseInsensitive) == 0)
       {
         moduleParamPrivate->Minimum = xmlReader.readElementText().trimmed();
       }
-      else if (constraintElem.compare("maximum", Qt::CaseInsensitive) == 0)
+      else if (compare(constraintElem, "maximum", Qt::CaseInsensitive) == 0)
       {
         moduleParamPrivate->Maximum = xmlReader.readElementText().trimmed();
       }
-      else if (constraintElem.compare("step", Qt::CaseInsensitive) == 0)
+      else if (compare(constraintElem, "step", Qt::CaseInsensitive) == 0)
       {
         moduleParamPrivate->Step = xmlReader.readElementText().trimmed();
       }
@@ -177,7 +182,7 @@ protected:
   {
     QStringRef name = xmlReader.name();
 
-    if (name.compare("constraints", Qt::CaseInsensitive) == 0)
+    if (compare(name, "constraints", Qt::CaseInsensitive) == 0)
     {
       return handleConstraintsElement(moduleParamPrivate, xmlReader);
     }
@@ -197,7 +202,7 @@ protected:
   {
     QStringRef name = xmlReader.name();
 
-    if (name.compare("constraints", Qt::CaseInsensitive) == 0)
+    if (compare(name, "constraints", Qt::CaseInsensitive) == 0)
     {
       return handleConstraintsElement(moduleParamPrivate, xmlReader);
     }
@@ -217,7 +222,7 @@ protected:
   {
     QStringRef name = xmlReader.name();
 
-    if (name.compare("element", Qt::CaseInsensitive) == 0)
+    if (compare(name, "element", Qt::CaseInsensitive) == 0)
     {
       moduleParamPrivate->Elements.push_back(xmlReader.readElementText().trimmed());
       return true;

+ 11 - 11
Libs/CommandLineModules/Core/ctkCmdLineModuleXmlParser.cpp

@@ -103,39 +103,39 @@ void ctkCmdLineModuleXmlParser::handleExecutableElement()
   {
     QStringRef name = _xmlReader.name();
 
-    if (name.compare("category", Qt::CaseInsensitive) == 0)
+    if (compare(name, "category", Qt::CaseInsensitive) == 0)
     {
       _md->d->Category = _xmlReader.readElementText().trimmed();
     }
-    else if (name.compare("title", Qt::CaseInsensitive) == 0)
+    else if (compare(name, "title", Qt::CaseInsensitive) == 0)
     {
       _md->d->Title = _xmlReader.readElementText().trimmed();
     }
-    else if (name.compare("version", Qt::CaseInsensitive) == 0)
+    else if (compare(name, "version", Qt::CaseInsensitive) == 0)
     {
       _md->d->Version = _xmlReader.readElementText().trimmed();
     }
-    else if (name.compare("documentation-url", Qt::CaseInsensitive) == 0)
+    else if (compare(name, "documentation-url", Qt::CaseInsensitive) == 0)
     {
       _md->d->DocumentationURL = _xmlReader.readElementText().trimmed();
     }
-    else if (name.compare("license", Qt::CaseInsensitive) == 0)
+    else if (compare(name, "license", Qt::CaseInsensitive) == 0)
     {
       _md->d->License = _xmlReader.readElementText().trimmed();
     }
-    else if (name.compare("acknowledgements", Qt::CaseInsensitive) == 0)
+    else if (compare(name, "acknowledgements", Qt::CaseInsensitive) == 0)
     {
       _md->d->Acknowledgements = _xmlReader.readElementText().trimmed();
     }
-    else if (name.compare("contributor", Qt::CaseInsensitive) == 0)
+    else if (compare(name, "contributor", Qt::CaseInsensitive) == 0)
     {
       _md->d->Contributor = _xmlReader.readElementText().trimmed();
     }
-    else if (name.compare("description", Qt::CaseInsensitive) == 0)
+    else if (compare(name, "description", Qt::CaseInsensitive) == 0)
     {
       _md->d->Description = _xmlReader.readElementText().trimmed();
     }
-    else if (name.compare("parameters", Qt::CaseInsensitive) == 0)
+    else if (compare(name, "parameters", Qt::CaseInsensitive) == 0)
     {
       this->handleParametersElement();
     }
@@ -159,11 +159,11 @@ void ctkCmdLineModuleXmlParser::handleParametersElement()
   {
     QStringRef name = _xmlReader.name();
 
-    if (name.compare("label", Qt::CaseInsensitive) == 0)
+    if (compare(name, "label", Qt::CaseInsensitive) == 0)
     {
       group.d->Label = _xmlReader.readElementText().trimmed();
     }
-    else if (name.compare("description", Qt::CaseInsensitive) == 0)
+    else if (compare(name, "description", Qt::CaseInsensitive) == 0)
     {
       group.d->Description = _xmlReader.readElementText().trimmed();
     }

+ 2 - 2
Libs/CommandLineModules/Core/ctkCmdLineModuleXmlProgressWatcher.cpp

@@ -129,7 +129,7 @@ public:
         QString parent;
         if (!stack.empty()) parent = stack.back();
 
-        if (name.compare("module-root") != 0 && name.compare("module-snippet") != 0)
+        if (name.compare(QLatin1String("module-root")) != 0 && name.compare(QLatin1String("module-snippet")) != 0)
         {
           stack.push_back(name.toString());
         }
@@ -177,7 +177,7 @@ public:
           if (!stack.empty()) parent = stack.back();
         }
 
-        if (parent.isEmpty() && name.compare("module-snippet") != 0)
+        if (parent.isEmpty() && name.compare(QLatin1String("module-snippet")) != 0)
         {
           if (name.compare(FILTER_START, Qt::CaseInsensitive) == 0)
           {