summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2023-12-12 15:56:42 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2024-02-06 19:28:53 +0000
commit6650ae43376b0e248c11b44cf89626b60ad4327c (patch)
treec013150248eb5750a715cdb6687a7848d49e0bcb
parentd3b019f2a1da2ec1c33f179daafd88b5023a153f (diff)
Designer: Change the icon/pixmap caches to use QHash
Instead of making PropertySheetPixmap/IconValue 3-way comparable types, change the maps to hashes. Task-number: QTBUG-103757 Task-number: QTBUG-121823 Change-Id: I6b494da682ee4c065dcd86339dd4cb7c7591b829 Reviewed-by: Marc Mutz <marc.mutz@qt.io> (cherry picked from commit 9b130f43b39e8bd0412530ab5b531d21eedaa4a4) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/designer/src/lib/shared/qdesigner_utils.cpp54
-rw-r--r--src/designer/src/lib/shared/qdesigner_utils_p.h36
2 files changed, 43 insertions, 47 deletions
diff --git a/src/designer/src/lib/shared/qdesigner_utils.cpp b/src/designer/src/lib/shared/qdesigner_utils.cpp
index 75d3d223b..7d02f73c1 100644
--- a/src/designer/src/lib/shared/qdesigner_utils.cpp
+++ b/src/designer/src/lib/shared/qdesigner_utils.cpp
@@ -274,11 +274,6 @@ namespace qdesigner_internal
return path.startsWith(u':') ? ResourcePixmap : FilePixmap;
}
- int PropertySheetPixmapValue::compare(const PropertySheetPixmapValue &other) const
- {
- return m_path.compare(other.m_path);
- }
-
QString PropertySheetPixmapValue::path() const
{
return m_path;
@@ -324,35 +319,26 @@ namespace qdesigner_internal
return *this;
}
- bool PropertySheetIconValue::equals(const PropertySheetIconValue &rhs) const
- {
- return m_data->m_theme == rhs.m_data->m_theme && m_data->m_paths == rhs.m_data->m_paths;
- }
-
- bool PropertySheetIconValue::operator<(const PropertySheetIconValue &other) const
- {
- if (const int themeCmp = m_data->m_theme.compare(other.m_data->m_theme))
- return themeCmp < 0;
- auto itThis = m_data->m_paths.cbegin();
- auto itThisEnd = m_data->m_paths.cend();
- auto itOther = other.m_data->m_paths.cbegin();
- auto itOtherEnd = other.m_data->m_paths.cend();
- while (itThis != itThisEnd && itOther != itOtherEnd) {
- const ModeStateKey thisPair = itThis.key();
- const ModeStateKey otherPair = itOther.key();
- if (thisPair < otherPair)
- return true;
- if (otherPair < thisPair)
- return false;
- const int crc = itThis.value().compare(itOther.value());
- if (crc < 0)
- return true;
- if (crc > 0)
- return false;
- ++itThis;
- ++itOther;
- }
- return itOther != itOtherEnd;
+} // namespace qdesigner_internal
+
+namespace qdesigner_internal {
+
+ size_t qHash(const PropertySheetIconValue &p, size_t seed) noexcept
+ {
+ // qHash for paths making use of the existing QPair hash functions.
+ const auto *d = p.m_data.constData();
+ return qHashMulti(qHashRange(d->m_paths.constKeyValueBegin(),
+ d->m_paths.constKeyValueEnd(), seed),
+ d->m_theme);
+ }
+
+ bool comparesEqual(const PropertySheetIconValue &lhs,
+ const PropertySheetIconValue &rhs) noexcept
+ {
+ const auto *lhsd = lhs.m_data.constData();
+ const auto *rhsd = rhs.m_data.constData();
+ return lhsd == rhsd
+ || (lhsd->m_theme == rhsd->m_theme && lhsd->m_paths == rhsd->m_paths);
}
bool PropertySheetIconValue::isEmpty() const
diff --git a/src/designer/src/lib/shared/qdesigner_utils_p.h b/src/designer/src/lib/shared/qdesigner_utils_p.h
index 6a6625211..1766705ca 100644
--- a/src/designer/src/lib/shared/qdesigner_utils_p.h
+++ b/src/designer/src/lib/shared/qdesigner_utils_p.h
@@ -20,6 +20,7 @@
#include <QtDesigner/abstractformwindow.h>
#include <QtCore/qcompare.h>
+#include <QtCore/qhash.h>
#include <QtCore/qvariant.h>
#include <QtCore/qshareddata.h>
#include <QtWidgets/qmainwindow.h>
@@ -210,10 +211,6 @@ public:
PropertySheetPixmapValue(const QString &path);
PropertySheetPixmapValue();
- bool operator==(const PropertySheetPixmapValue &other) const { return compare(other) == 0; }
- bool operator!=(const PropertySheetPixmapValue &other) const { return compare(other) != 0; }
- bool operator<(const PropertySheetPixmapValue &other) const { return compare(other) < 0; }
-
// Check where a pixmap comes from
enum PixmapSource { LanguageResourcePixmap , ResourcePixmap, FilePixmap };
static PixmapSource getPixmapSource(QDesignerFormEditorInterface *core, const QString & path);
@@ -223,9 +220,18 @@ public:
QString path() const;
void setPath(const QString &path); // passing the empty path resets the pixmap
- int compare(const PropertySheetPixmapValue &other) const;
-
private:
+ friend size_t qHash(const PropertySheetPixmapValue &p, size_t seed = 0) noexcept
+ {
+ return qHash(p.m_path, seed);
+ }
+ friend bool comparesEqual(const PropertySheetPixmapValue &lhs,
+ const PropertySheetPixmapValue &rhs) noexcept
+ {
+ return lhs.m_path == rhs.m_path;
+ }
+ Q_DECLARE_EQUALITY_COMPARABLE(PropertySheetPixmapValue)
+
QString m_path;
};
@@ -242,10 +248,6 @@ class QDESIGNER_SHARED_EXPORT PropertySheetIconValue
PropertySheetIconValue(const PropertySheetIconValue &);
PropertySheetIconValue &operator=(const PropertySheetIconValue &);
- bool operator==(const PropertySheetIconValue &other) const { return equals(other); }
- bool operator!=(const PropertySheetIconValue &other) const { return !equals(other); }
- bool operator<(const PropertySheetIconValue &other) const;
-
bool isEmpty() const;
QString theme() const;
@@ -268,7 +270,15 @@ class QDESIGNER_SHARED_EXPORT PropertySheetIconValue
const ModeStateToPixmapMap &paths() const;
private:
- bool equals(const PropertySheetIconValue &rhs) const;
+ friend QDESIGNER_SHARED_EXPORT
+ size_t qHash(const PropertySheetIconValue &p, size_t seed) noexcept;
+ friend size_t qHash(const PropertySheetIconValue &p) noexcept
+ { return qHash(p, 0); }
+ friend QDESIGNER_SHARED_EXPORT
+ bool comparesEqual(const PropertySheetIconValue &lhs,
+ const PropertySheetIconValue &rhs) noexcept;
+ Q_DECLARE_EQUALITY_COMPARABLE(PropertySheetIconValue)
+
QSharedDataPointer<PropertySheetIconValueData> m_data;
};
@@ -284,7 +294,7 @@ public:
signals:
void reloaded();
private:
- mutable QMap<PropertySheetPixmapValue, QPixmap> m_cache;
+ mutable QHash<PropertySheetPixmapValue, QPixmap> m_cache;
friend class FormWindowBase;
};
@@ -298,7 +308,7 @@ public:
signals:
void reloaded();
private:
- mutable QMap<PropertySheetIconValue, QIcon> m_cache;
+ mutable QHash<PropertySheetIconValue, QIcon> m_cache;
DesignerPixmapCache *m_pixmapCache;
friend class FormWindowBase;
};