diff options
author | Albert Astals Cid <albert.astals@canonical.com> | 2013-10-08 13:43:26 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-10-09 13:15:54 +0200 |
commit | 7f3e3c1099f42cff46bbd267c70587bcf72024fc (patch) | |
tree | 5114cf976cb2466fcd59d0d2ad0b42655b59f0de | |
parent | 94abcf98175d927f8e483c8f207c51034fd3b9fc (diff) |
Compare QIcon QVariants by their cache key
This makes it so that two QVariants created from the same
QIcon (or from QIcons that were assigned one from eachother)
compare to true.
Unfortunately creating two QIcons with the same path and
comparing them still gives false as they have different cacheKeys
Change-Id: Iafe2bc4082a830f9c6469f083c26a7abbe4b35c5
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
-rw-r--r-- | src/gui/kernel/qguivariant.cpp | 2 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qguivariant/test/black.png | bin | 0 -> 697 bytes | |||
-rw-r--r-- | tests/auto/gui/kernel/qguivariant/test/black2.png | bin | 0 -> 697 bytes | |||
-rw-r--r-- | tests/auto/gui/kernel/qguivariant/test/test.pro | 1 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp | 29 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.qrc | 6 | ||||
-rw-r--r-- | tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp | 4 |
7 files changed, 38 insertions, 4 deletions
diff --git a/src/gui/kernel/qguivariant.cpp b/src/gui/kernel/qguivariant.cpp index 2842211e1d..65f57aed84 100644 --- a/src/gui/kernel/qguivariant.cpp +++ b/src/gui/kernel/qguivariant.cpp @@ -164,7 +164,7 @@ public: #ifndef QT_NO_ICON bool delegate(const QIcon *) { - return false; + return v_cast<QIcon>(Base::m_a)->cacheKey() == v_cast<QIcon>(Base::m_b)->cacheKey(); } #endif bool delegate(const void *p) { return Base::delegate(p); } diff --git a/tests/auto/gui/kernel/qguivariant/test/black.png b/tests/auto/gui/kernel/qguivariant/test/black.png Binary files differnew file mode 100644 index 0000000000..6c94085ed5 --- /dev/null +++ b/tests/auto/gui/kernel/qguivariant/test/black.png diff --git a/tests/auto/gui/kernel/qguivariant/test/black2.png b/tests/auto/gui/kernel/qguivariant/test/black2.png Binary files differnew file mode 100644 index 0000000000..6c94085ed5 --- /dev/null +++ b/tests/auto/gui/kernel/qguivariant/test/black2.png diff --git a/tests/auto/gui/kernel/qguivariant/test/test.pro b/tests/auto/gui/kernel/qguivariant/test/test.pro index d47cf7bf6f..86ab17d9cd 100644 --- a/tests/auto/gui/kernel/qguivariant/test/test.pro +++ b/tests/auto/gui/kernel/qguivariant/test/test.pro @@ -2,5 +2,6 @@ CONFIG += testcase CONFIG += parallel_test TARGET = tst_qguivariant SOURCES += tst_qguivariant.cpp +RESOURCES = tst_qguivariant.qrc INCLUDEPATH += $$PWD/../../../../other/qvariant_common QT += testlib diff --git a/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp b/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp index 6fdf3dc843..d5ec9fcfaa 100644 --- a/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp +++ b/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp @@ -124,6 +124,8 @@ private slots: void implicitConstruction(); void guiVariantAtExit(); + + void iconEquality(); }; void tst_QGuiVariant::constructor_invalid_data() @@ -702,5 +704,32 @@ void tst_QGuiVariant::guiVariantAtExit() QVERIFY(true); } +void tst_QGuiVariant::iconEquality() +{ + QIcon i; + QVariant a = i; + QVariant b = i; + QCOMPARE(a, b); + + i = QIcon(":/black.png"); + a = i; + QVERIFY(a != b); + + b = a; + QCOMPARE(a, b); + + i = QIcon(":/black2.png"); + a = i; + QVERIFY(a != b); + + b = i; + QCOMPARE(a, b); + + // This is a "different" QIcon + // even if the contents are the same + b = QIcon(":/black2.png"); + QVERIFY(a != b); +} + QTEST_MAIN(tst_QGuiVariant) #include "tst_qguivariant.moc" diff --git a/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.qrc b/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.qrc new file mode 100644 index 0000000000..15cfde5788 --- /dev/null +++ b/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.qrc @@ -0,0 +1,6 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource prefix="/"> +<file>black.png</file> +<file>black2.png</file> +</qresource> +</RCC> diff --git a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp index 83ba1ddcda..d2625c400a 100644 --- a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp +++ b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp @@ -1758,9 +1758,7 @@ void tst_QTreeWidget::setData() QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item); QCOMPARE(qvariant_cast<int>(args.at(1)), j); item->setIcon(j, icon); - // #### shouldn't cause dataChanged() - QCOMPARE(itemChangedSpy.count(), 1); - itemChangedSpy.clear(); + QCOMPARE(itemChangedSpy.count(), 0); QString toolTip = QString("toolTip %0").arg(i); item->setToolTip(j, toolTip); |