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>bb10
parent
94abcf9817
commit
7f3e3c1099
|
|
@ -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); }
|
||||
|
|
|
|||
Binary file not shown.
|
After Width: | Height: | Size: 697 B |
Binary file not shown.
|
After Width: | Height: | Size: 697 B |
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
<!DOCTYPE RCC><RCC version="1.0">
|
||||
<qresource prefix="/">
|
||||
<file>black.png</file>
|
||||
<file>black2.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue