Merge lp:~fboucault/unity-2d/qsortfilter_rolenames_propagation into lp:unity-2d/3.0

Proposed by Florian Boucault
Status: Merged
Approved by: Gerry Boland
Approved revision: 634
Merged at revision: 643
Proposed branch: lp:~fboucault/unity-2d/qsortfilter_rolenames_propagation
Merge into: lp:unity-2d/3.0
Diff against target: 57 lines (+19/-8)
2 files modified
libunity-2d-private/Unity2d/qsortfilterproxymodelqml.cpp (+15/-6)
libunity-2d-private/Unity2d/qsortfilterproxymodelqml.h (+4/-2)
To merge this branch: bzr merge lp:~fboucault/unity-2d/qsortfilter_rolenames_propagation
Reviewer Review Type Date Requested Status
Gerry Boland (community) Approve
Review via email: mp+68072@code.launchpad.net

Description of the change

[backend] QSortFilterProxyModel: workaround for lack of roleNames change propagation.

To post a comment you must log in.
Revision history for this message
Florian Boucault (fboucault) wrote :

This change depends on a newer libqtdee available from the PPA.

634. By Florian Boucault

Added warning.

Revision history for this message
Gerry Boland (gerboland) wrote :

Looks good, accepted.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libunity-2d-private/Unity2d/qsortfilterproxymodelqml.cpp'
2--- libunity-2d-private/Unity2d/qsortfilterproxymodelqml.cpp 2011-04-28 13:09:25 +0000
3+++ libunity-2d-private/Unity2d/qsortfilterproxymodelqml.cpp 2011-07-15 10:59:29 +0000
4@@ -22,10 +22,10 @@
5 {
6 }
7
8-void
9-QSortFilterProxyModelQML::updateRoleNames()
10+void QSortFilterProxyModelQML::setRoleNames(const QHash<int,QByteArray> &roleNames)
11 {
12- setRoleNames(((QAbstractItemModel*)sourceModel())->roleNames());
13+ QSortFilterProxyModel::setRoleNames(roleNames);
14+ Q_EMIT roleNamesChanged(roleNames);
15 }
16
17 QObject*
18@@ -51,10 +51,19 @@
19 sourceModel()->disconnect(this);
20 }
21
22+ /* Workaround for limitation of QAbstractProxyModel: if sourceModel's
23+ roleNames changes, the QAbstractProxyModel's roleNames are not updated
24+ to reflect that change.
25+ As a consequence it works around Qt bug http://bugreports.qt.nokia.com/browse/QTBUG-20405
26+ */
27+ bool hasRoleNamesChangedSignal;
28+ hasRoleNamesChangedSignal = connect(itemModel, SIGNAL(roleNamesChanged(QHash<int,QByteArray>)), SLOT(setRoleNames(QHash<int,QByteArray>)));
29+ if (!hasRoleNamesChangedSignal) {
30+ UQ_WARNING << "received a sourceModel that does not notify of changes of its roleNames";
31+ }
32+ setRoleNames(itemModel->roleNames());
33+
34 setSourceModel(itemModel);
35-
36- connect(itemModel, SIGNAL(modelAboutToBeReset()), SLOT(updateRoleNames()));
37- connect(itemModel, SIGNAL(modelReset()), SLOT(updateRoleNames()));
38 }
39
40 QVariantMap
41
42=== modified file 'libunity-2d-private/Unity2d/qsortfilterproxymodelqml.h'
43--- libunity-2d-private/Unity2d/qsortfilterproxymodelqml.h 2011-03-23 14:04:23 +0000
44+++ libunity-2d-private/Unity2d/qsortfilterproxymodelqml.h 2011-07-15 10:59:29 +0000
45@@ -37,8 +37,10 @@
46 /* setters */
47 void setSourceModelQObject(QObject *model);
48
49-private Q_SLOTS:
50- void updateRoleNames();
51+ Q_SLOT void setRoleNames(const QHash<int,QByteArray> &roleNames);
52+
53+Q_SIGNALS:
54+ void roleNamesChanged(const QHash<int,QByteArray> &);
55 };
56
57 #endif // QSORTFILTERPROXYMODELQML_H

Subscribers

People subscribed via source and target branches