Merge lp:~mterry/lightdm/qt-get into lp:lightdm

Proposed by Michael Terry
Status: Rejected
Rejected by: Michael Terry
Proposed branch: lp:~mterry/lightdm/qt-get
Merge into: lp:lightdm
Diff against target: 70 lines (+27/-0)
4 files modified
liblightdm-qt/QLightDM/sessionsmodel.h (+1/-0)
liblightdm-qt/QLightDM/usersmodel.h (+1/-0)
liblightdm-qt/sessionsmodel.cpp (+13/-0)
liblightdm-qt/usersmodel.cpp (+12/-0)
To merge this branch: bzr merge lp:~mterry/lightdm/qt-get
Reviewer Review Type Date Requested Status
Robert Ancell Abstain
PS Jenkins bot continuous-integration Approve
David Edmundson Disapprove
Review via email: mp+149119@code.launchpad.net

Commit message

Add get() methods to the Qt models, to emulate what ListModel does in Qml

Description of the change

Add get() methods to the two Qt models. This makes it possible to get data from arbitrary rows of the model (otherwise, Qml only exposes the currently selected row).

To post a comment you must log in.
Revision history for this message
David Edmundson (david.edmundson) wrote :

That's not true, use itemAt() in your repeater in QML, then you have access to all the properties in your delegate (and thus model)

Show me your QML and I can take a look if you like.

Revision history for this message
Michael Terry (mterry) wrote :

I thought itemAt took x,y coordinates, so was only good if (A) you had x,y and (B) the item was on the screen. So not quite the same as access-by-row, right?

Revision history for this message
David Edmundson (david.edmundson) wrote :

No, that's Item::ChildAt
Repeater::itemAt takes an index.

http://doc.qt.digia.com/stable/qml-repeater.html#itemAt-method

Revision history for this message
Michael Terry (mterry) wrote :

OK. But Repeater seems uncommon? I'm used to having my models be part of a PathView or ListView or something. And those use the x,y version of itemAt.

So when using liblightdm-qt's models with such widgets, get() would still be useful, no?

Revision history for this message
David Edmundson (david.edmundson) wrote :

In "normal" C++ code one would do model->index(rowNumber,0).data(Qt::DisplayRole) that's quite common. Quite often one passes round QPersistantModelIndexes anyway so you can just call data() on that.

From a C++ QWidget perspective this would be really wrong and pointless, however I do see why you want to do it to work round QML's limitations. I hate making bad Qt libraries with duplication for the sake of QML, which is what this comes down to.

If you don't have a itemAt() method you can still call pathView.children[index].property.
What I'll do is check with some other Qt devs and get their opinion and report back.

Revision history for this message
David Edmundson (david.edmundson) wrote :

So I don't have any outstanding reviews I'm going to close this on the grounds that this is a Qt library and not a QML one.

You need to write helper code to call qmlRegisterType anyway so any other QML or greeter specific code should be done in your code and not in here which is shared in many projects.

For this particular case it's probably worth having a helper method in Ubuntu globally, rather than trying to update every existing model. KDE, for example, uses this: http://api.kde.org/4.x-api/kde-runtime-apidocs/plasma/declarativeimports/core/html/classPlasma_1_1SortFilterModel.html

(BTW, If you do go with this approach, call itemData() once on the model then loop through that rather than calling data() for each role which is a much slower operation performing a list lookup each time)

review: Disapprove
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:1597
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~mterry/lightdm/qt-get/+merge/149119/+edit-commit-message

http://jenkins.qa.ubuntu.com/job/lightdm-ci/3/
Executed test runs:
    FAILURE: http://jenkins.qa.ubuntu.com/job/lightdm-quantal-amd64-ci/3/console

Click here to trigger a rebuild:
http://s-jenkins:8080/job/lightdm-ci/3/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:1597
http://jenkins.qa.ubuntu.com/job/lightdm-ci/9/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/lightdm-raring-amd64-ci/3

Click here to trigger a rebuild:
http://s-jenkins:8080/job/lightdm-ci/9/rebuild

review: Approve (continuous-integration)
Revision history for this message
Robert Ancell (robert-ancell) wrote :

Outside my Qt knowledge.

review: Abstain
Revision history for this message
Michael Terry (mterry) wrote :

I'm fine without this. I'll close it.

Unmerged revisions

1597. By Michael Terry

Add get() methods to the Qt models, to emulate what ListModel does in Qml

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'liblightdm-qt/QLightDM/sessionsmodel.h'
2--- liblightdm-qt/QLightDM/sessionsmodel.h 2013-01-31 20:56:09 +0000
3+++ liblightdm-qt/QLightDM/sessionsmodel.h 2013-02-18 18:19:24 +0000
4@@ -38,6 +38,7 @@
5
6 int rowCount(const QModelIndex &parent) const;
7 QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const;
8+ Q_INVOKABLE QVariantMap get(int row) const;
9
10 protected:
11 SessionsModelPrivate *d_ptr;
12
13=== modified file 'liblightdm-qt/QLightDM/usersmodel.h'
14--- liblightdm-qt/QLightDM/usersmodel.h 2013-01-31 20:56:09 +0000
15+++ liblightdm-qt/QLightDM/usersmodel.h 2013-02-18 18:19:24 +0000
16@@ -38,6 +38,7 @@
17
18 int rowCount(const QModelIndex &parent) const;
19 QVariant data(const QModelIndex &index, int role) const;
20+ Q_INVOKABLE QVariantMap get(int row) const;
21
22 protected:
23
24
25=== modified file 'liblightdm-qt/sessionsmodel.cpp'
26--- liblightdm-qt/sessionsmodel.cpp 2013-02-06 14:08:25 +0000
27+++ liblightdm-qt/sessionsmodel.cpp 2013-02-18 18:19:24 +0000
28@@ -146,6 +146,19 @@
29 return QVariant();
30 }
31
32+QVariantMap SessionsModel::get(int row) const
33+{
34+ QVariantMap result;
35+ QHashIterator<int, QByteArray> i(roleNames());
36+ while (i.hasNext()) {
37+ i.next();
38+ QModelIndex modelIndex = index(row, 0);
39+ QVariant data = modelIndex.data(i.key());
40+ result[i.value()] = data;
41+ }
42+ return result;
43+}
44+
45 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
46 #include "sessionsmodel_moc5.cpp"
47 #else
48
49=== modified file 'liblightdm-qt/usersmodel.cpp'
50--- liblightdm-qt/usersmodel.cpp 2013-02-07 14:26:19 +0000
51+++ liblightdm-qt/usersmodel.cpp 2013-02-18 18:19:24 +0000
52@@ -242,6 +242,18 @@
53 return QVariant();
54 }
55
56+QVariantMap UsersModel::get(int row) const
57+{
58+ QVariantMap result;
59+ QHashIterator<int, QByteArray> i(roleNames());
60+ while (i.hasNext()) {
61+ i.next();
62+ QModelIndex modelIndex = index(row, 0);
63+ QVariant data = modelIndex.data(i.key());
64+ result[i.value()] = data;
65+ }
66+ return result;
67+}
68
69 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
70 #include "usersmodel_moc5.cpp"

Subscribers

People subscribed via source and target branches