diff options
author | hjk <hjk@qt.io> | 2019-06-21 08:40:47 +0200 |
---|---|---|
committer | hjk <hjk@qt.io> | 2019-07-02 12:48:54 +0000 |
commit | 36fcd5213667d04008c39c38f9d8787dc6b839fd (patch) | |
tree | aa9c23a7b50221cbda6c3f1aad34fe0ed013e84f /src/libs | |
parent | a6d5da5af2d62e6f4d32ee4fb84e969b8bad0cd9 (diff) |
Utils: Add toSet/toList functions
As replacement for functionality that's being deprecated
in Qt but still useful or needed, or that cannot easily be handled
without resorting to #if QT_VERSION checks in user code.
Change-Id: Id3575a54ff944bf0e89d452d13944fcaee270208
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/libs')
-rw-r--r-- | src/libs/modelinglib/qmt/diagram_scene/items/classitem.cpp | 4 | ||||
-rw-r--r-- | src/libs/modelinglib/qmt/stereotype/stereotypecontroller.cpp | 2 | ||||
-rw-r--r-- | src/libs/qmljs/qmljsplugindumper.cpp | 6 | ||||
-rw-r--r-- | src/libs/utils/algorithm.h | 23 | ||||
-rw-r--r-- | src/libs/utils/codegeneration.cpp | 10 |
5 files changed, 35 insertions, 10 deletions
diff --git a/src/libs/modelinglib/qmt/diagram_scene/items/classitem.cpp b/src/libs/modelinglib/qmt/diagram_scene/items/classitem.cpp index 04b3acd77e..9c5345c417 100644 --- a/src/libs/modelinglib/qmt/diagram_scene/items/classitem.cpp +++ b/src/libs/modelinglib/qmt/diagram_scene/items/classitem.cpp @@ -52,6 +52,8 @@ #include "qmt/tasks/diagramscenecontroller.h" #include "qmt/tasks/ielementtasks.h" +#include <utils/algorithm.h> + #include <QGraphicsScene> #include <QGraphicsRectItem> #include <QGraphicsSimpleTextItem> @@ -346,7 +348,7 @@ void ClassItem::relationDrawn(const QString &id, ObjectItem *targetItem, const Q { CustomRelation::Relationship::Aggregation, MAssociationEnd::Aggregation }, { CustomRelation::Relationship::Composition, MAssociationEnd::Composition } }; diagramSceneController->modelController()->startUpdateRelation(mAssociation); - mAssociation->setStereotypes(customRelation.stereotypes().toList()); + mAssociation->setStereotypes(Utils::toList(customRelation.stereotypes())); mAssociation->setName(customRelation.name()); MAssociationEnd endA; endA.setCardinality(customRelation.endA().cardinality()); diff --git a/src/libs/modelinglib/qmt/stereotype/stereotypecontroller.cpp b/src/libs/modelinglib/qmt/stereotype/stereotypecontroller.cpp index 9d1640ff6a..ae1974717b 100644 --- a/src/libs/modelinglib/qmt/stereotype/stereotypecontroller.cpp +++ b/src/libs/modelinglib/qmt/stereotype/stereotypecontroller.cpp @@ -130,7 +130,7 @@ QList<QString> StereotypeController::knownStereotypes(StereotypeIcon::Element st if (icon.elements().isEmpty() || icon.elements().contains(stereotypeElement)) stereotypes += icon.stereotypes(); } - QList<QString> list = stereotypes.toList(); + QList<QString> list = Utils::toList(stereotypes); std::sort(list.begin(), list.end()); return list; } diff --git a/src/libs/qmljs/qmljsplugindumper.cpp b/src/libs/qmljs/qmljsplugindumper.cpp index aeef89372f..2c6afb61c0 100644 --- a/src/libs/qmljs/qmljsplugindumper.cpp +++ b/src/libs/qmljs/qmljsplugindumper.cpp @@ -29,8 +29,8 @@ #include <qmljs/qmljsinterpreter.h> #include <qmljs/qmljsviewercontext.h> -//#include <projectexplorer/session.h> -//#include <coreplugin/messagemanager.h> + +#include <utils/algorithm.h> #include <utils/filesystemwatcher.h> #include <utils/fileutils.h> #include <utils/hostosinfo.h> @@ -437,7 +437,7 @@ void PluginDumper::loadDependencies(const QStringList &dependencies, } QStringList newDependencies; loadQmlTypeDescription(dependenciesPaths, errors, warnings, objects, 0, &newDependencies); - newDependencies = (newDependencies.toSet() - *visitedPtr).toList(); + newDependencies = Utils::toList(Utils::toSet(newDependencies) - *visitedPtr); if (!newDependencies.isEmpty()) loadDependencies(newDependencies, errors, warnings, objects, visitedPtr.take()); } diff --git a/src/libs/utils/algorithm.h b/src/libs/utils/algorithm.h index 9e80755a3a..5c6d79cb68 100644 --- a/src/libs/utils/algorithm.h +++ b/src/libs/utils/algorithm.h @@ -1243,4 +1243,27 @@ OutputIterator set_union(InputIterator1 first1, return Utils::set_union_impl( first1, last1, first2, last2, result, std::less<typename InputIterator1::value_type>{}); } + +// Replacement for deprecated Qt functionality + +template <class T> +QSet<T> toSet(const QList<T> &list) +{ +#if (QT_VERSION < QT_VERSION_CHECK(5, 13, 0)) + return list.toSet(); +#else + return QSet<T>{list.begin(), list.end()}; +#endif +} + +template <class T> +QList<T> toList(const QSet<T> &set) +{ +#if (QT_VERSION < QT_VERSION_CHECK(5, 13, 0)) + return set.toList(); +#else + return QList<T>{set.begin(), set.end()}; +#endif +} + } // namespace Utils diff --git a/src/libs/utils/codegeneration.cpp b/src/libs/utils/codegeneration.cpp index 5843e843d9..697d876e0b 100644 --- a/src/libs/utils/codegeneration.cpp +++ b/src/libs/utils/codegeneration.cpp @@ -121,23 +121,23 @@ void writeQtIncludeSection(const QStringList &qt4, qt4Only.subtract(common); qt5Only.subtract(common); - qtSection(common.toList(), str); + qtSection(Utils::toList(common), str); if (!qt4Only.isEmpty() || !qt5Only.isEmpty()) { if (addQtVersionCheck) writeBeginQtVersionCheck(str); - qtSection(qt5Only.toList(), str); + qtSection(Utils::toList(qt5Only), str); if (addQtVersionCheck) str << QLatin1String("#else\n"); - qtSection(qt4Only.toList(), str); + qtSection(Utils::toList(qt4Only), str); if (addQtVersionCheck) str << QLatin1String("#endif\n"); } } else { if (!qt5Only.isEmpty()) // default to Qt5 - qtSection(qt5Only.toList(), str); + qtSection(Utils::toList(qt5Only), str); else - qtSection(qt4Only.toList(), str); + qtSection(Utils::toList(qt4Only), str); } } |