Repeater & itemviews: fix setModel() JS array handling
QVariant comparison in setModel() started failing because JS arrays are now passed as a QJSValue. Re-assigning the same array content should not trigger a model change. This change restores the old behavior it had before, when JS arrays were passed as QVariantLists. Change-Id: I1882b3531f2893b116dbd817edeecab1ae812ce8 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
This commit is contained in:
parent
4b7dc1cf59
commit
cf959b4b4e
|
@ -273,9 +273,13 @@ QVariant QQuickItemView::model() const
|
|||
return d->modelVariant;
|
||||
}
|
||||
|
||||
void QQuickItemView::setModel(const QVariant &model)
|
||||
void QQuickItemView::setModel(const QVariant &m)
|
||||
{
|
||||
Q_D(QQuickItemView);
|
||||
QVariant model = m;
|
||||
if (model.userType() == qMetaTypeId<QJSValue>())
|
||||
model = model.value<QJSValue>().toVariant();
|
||||
|
||||
if (d->modelVariant == model)
|
||||
return;
|
||||
if (d->model) {
|
||||
|
|
|
@ -607,9 +607,13 @@ QVariant QQuickPathView::model() const
|
|||
return d->modelVariant;
|
||||
}
|
||||
|
||||
void QQuickPathView::setModel(const QVariant &model)
|
||||
void QQuickPathView::setModel(const QVariant &m)
|
||||
{
|
||||
Q_D(QQuickPathView);
|
||||
QVariant model = m;
|
||||
if (model.userType() == qMetaTypeId<QJSValue>())
|
||||
model = model.value<QJSValue>().toVariant();
|
||||
|
||||
if (d->modelVariant == model)
|
||||
return;
|
||||
|
||||
|
|
|
@ -183,9 +183,13 @@ QVariant QQuickRepeater::model() const
|
|||
return d->dataSource;
|
||||
}
|
||||
|
||||
void QQuickRepeater::setModel(const QVariant &model)
|
||||
void QQuickRepeater::setModel(const QVariant &m)
|
||||
{
|
||||
Q_D(QQuickRepeater);
|
||||
QVariant model = m;
|
||||
if (model.userType() == qMetaTypeId<QJSValue>())
|
||||
model = model.value<QJSValue>().toVariant();
|
||||
|
||||
if (d->dataSource == model)
|
||||
return;
|
||||
|
||||
|
|
|
@ -204,6 +204,8 @@ private slots:
|
|||
void displayMargin();
|
||||
void negativeDisplayMargin();
|
||||
|
||||
void jsArrayChange();
|
||||
|
||||
private:
|
||||
QList<int> toIntList(const QVariantList &list);
|
||||
void matchIndexLists(const QVariantList &indexLists, const QList<int> &expectedIndexes);
|
||||
|
@ -6430,6 +6432,33 @@ void tst_QQuickGridView::negativeDisplayMargin()
|
|||
delete window;
|
||||
}
|
||||
|
||||
void tst_QQuickGridView::jsArrayChange()
|
||||
{
|
||||
QQmlEngine engine;
|
||||
QQmlComponent component(&engine);
|
||||
component.setData("import QtQuick 2.4; GridView {}", QUrl());
|
||||
|
||||
QScopedPointer<QQuickGridView> view(qobject_cast<QQuickGridView *>(component.create()));
|
||||
QVERIFY(!view.isNull());
|
||||
|
||||
QSignalSpy spy(view.data(), SIGNAL(modelChanged()));
|
||||
QVERIFY(spy.isValid());
|
||||
|
||||
QJSValue array1 = engine.newArray(3);
|
||||
QJSValue array2 = engine.newArray(3);
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
array1.setProperty(i, i);
|
||||
array2.setProperty(i, i);
|
||||
}
|
||||
|
||||
view->setModel(QVariant::fromValue(array1));
|
||||
QCOMPARE(spy.count(), 1);
|
||||
|
||||
// no change
|
||||
view->setModel(QVariant::fromValue(array2));
|
||||
QCOMPARE(spy.count(), 1);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QQuickGridView)
|
||||
|
||||
#include "tst_qquickgridview.moc"
|
||||
|
|
|
@ -239,6 +239,8 @@ private slots:
|
|||
void QTBUG_39492_data();
|
||||
void QTBUG_39492();
|
||||
|
||||
void jsArrayChange();
|
||||
|
||||
private:
|
||||
template <class T> void items(const QUrl &source);
|
||||
template <class T> void changed(const QUrl &source);
|
||||
|
@ -7945,6 +7947,33 @@ void tst_QQuickListView::QTBUG_39492()
|
|||
releaseView(window);
|
||||
}
|
||||
|
||||
void tst_QQuickListView::jsArrayChange()
|
||||
{
|
||||
QQmlEngine engine;
|
||||
QQmlComponent component(&engine);
|
||||
component.setData("import QtQuick 2.4; ListView {}", QUrl());
|
||||
|
||||
QScopedPointer<QQuickListView> view(qobject_cast<QQuickListView *>(component.create()));
|
||||
QVERIFY(!view.isNull());
|
||||
|
||||
QSignalSpy spy(view.data(), SIGNAL(modelChanged()));
|
||||
QVERIFY(spy.isValid());
|
||||
|
||||
QJSValue array1 = engine.newArray(3);
|
||||
QJSValue array2 = engine.newArray(3);
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
array1.setProperty(i, i);
|
||||
array2.setProperty(i, i);
|
||||
}
|
||||
|
||||
view->setModel(QVariant::fromValue(array1));
|
||||
QCOMPARE(spy.count(), 1);
|
||||
|
||||
// no change
|
||||
view->setModel(QVariant::fromValue(array2));
|
||||
QCOMPARE(spy.count(), 1);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QQuickListView)
|
||||
|
||||
#include "tst_qquicklistview.moc"
|
||||
|
|
|
@ -139,6 +139,7 @@ private slots:
|
|||
void changePathDuringRefill();
|
||||
void nestedinFlickable();
|
||||
void flickableDelegate();
|
||||
void jsArrayChange();
|
||||
};
|
||||
|
||||
class TestObject : public QObject
|
||||
|
@ -2290,6 +2291,33 @@ void tst_QQuickPathView::flickableDelegate()
|
|||
QCOMPARE(moveStartedSpy.count(), 0);
|
||||
}
|
||||
|
||||
void tst_QQuickPathView::jsArrayChange()
|
||||
{
|
||||
QQmlEngine engine;
|
||||
QQmlComponent component(&engine);
|
||||
component.setData("import QtQuick 2.4; PathView {}", QUrl());
|
||||
|
||||
QScopedPointer<QQuickPathView> view(qobject_cast<QQuickPathView *>(component.create()));
|
||||
QVERIFY(!view.isNull());
|
||||
|
||||
QSignalSpy spy(view.data(), SIGNAL(modelChanged()));
|
||||
QVERIFY(spy.isValid());
|
||||
|
||||
QJSValue array1 = engine.newArray(3);
|
||||
QJSValue array2 = engine.newArray(3);
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
array1.setProperty(i, i);
|
||||
array2.setProperty(i, i);
|
||||
}
|
||||
|
||||
view->setModel(QVariant::fromValue(array1));
|
||||
QCOMPARE(spy.count(), 1);
|
||||
|
||||
// no change
|
||||
view->setModel(QVariant::fromValue(array2));
|
||||
QCOMPARE(spy.count(), 1);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QQuickPathView)
|
||||
|
||||
#include "tst_qquickpathview.moc"
|
||||
|
|
|
@ -72,6 +72,7 @@ private slots:
|
|||
void dynamicModelCrash();
|
||||
void visualItemModelCrash();
|
||||
void invalidContextCrash();
|
||||
void jsArrayChange();
|
||||
};
|
||||
|
||||
class TestObject : public QObject
|
||||
|
@ -779,6 +780,33 @@ void tst_QQuickRepeater::invalidContextCrash()
|
|||
root.reset(0);
|
||||
}
|
||||
|
||||
void tst_QQuickRepeater::jsArrayChange()
|
||||
{
|
||||
QQmlEngine engine;
|
||||
QQmlComponent component(&engine);
|
||||
component.setData("import QtQuick 2.4; Repeater {}", QUrl());
|
||||
|
||||
QScopedPointer<QQuickRepeater> repeater(qobject_cast<QQuickRepeater *>(component.create()));
|
||||
QVERIFY(!repeater.isNull());
|
||||
|
||||
QSignalSpy spy(repeater.data(), SIGNAL(modelChanged()));
|
||||
QVERIFY(spy.isValid());
|
||||
|
||||
QJSValue array1 = engine.newArray(3);
|
||||
QJSValue array2 = engine.newArray(3);
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
array1.setProperty(i, i);
|
||||
array2.setProperty(i, i);
|
||||
}
|
||||
|
||||
repeater->setModel(QVariant::fromValue(array1));
|
||||
QCOMPARE(spy.count(), 1);
|
||||
|
||||
// no change
|
||||
repeater->setModel(QVariant::fromValue(array2));
|
||||
QCOMPARE(spy.count(), 1);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QQuickRepeater)
|
||||
|
||||
#include "tst_qquickrepeater.moc"
|
||||
|
|
Loading…
Reference in New Issue