on xenial help sign in
We have an isRoot property in departments now

Much better than compariing against ""

commita277802bac7ce4b046e0da859ef59f7c429dd018 authorAlbert Astals <albert.astals@canonical.com> dateWed 28 May 2014, 10:24 (12 years ago) parentbeb9977
3 files changed+11−4
qml/Dash/DashDepartmentsList.qml+3−4 tests/mocks/Unity/fake_department.cpp+5 tests/mocks/Unity/fake_department.h+3
qml/Dash/DashDepartmentsList.qml+3−4
@@ -25,7 +25,6 @@ Item {
2525 signal allDepartmentClicked()
2626
2727 readonly property int itemHeight: units.gu(5)
28− readonly property bool isRoot: department && department.departmentId == ""
2928 implicitHeight: flickable.contentHeight
3029
3130 Rectangle {
@@ -52,14 +51,14 @@ Item {
5251
5352 anchors.fill: parent
5453
55− readonly property int nItems: department && department.loaded ? (department.count + (isRoot ? 0 : 2)) : 0
54+ readonly property int nItems: department && department.loaded ? (department.count + (department.isRoot ? 0 : 2)) : 0
5655 contentHeight: nItems * root.itemHeight
5756 contentWidth: width
5857
5958 AbstractButton {
6059 id: backButton
6160 width: parent.width
62− visible: department && !isRoot
61+ visible: department && !department.isRoot
6362 height: itemHeight
6463
6564 onClicked: root.goBackToParentClicked();
@@ -129,7 +128,7 @@ Item {
129128 delegate: AbstractButton {
130129 height: root.itemHeight
131130 width: root.width
132− y: ((isRoot ? 0 : 2) + index) * root.itemHeight
131+ y: ((department.isRoot ? 0 : 2) + index) * root.itemHeight
133132
134133 onClicked: root.enterDepartment(departmentId, hasChildren)
135134
tests/mocks/Unity/fake_department.cpp+5
@@ -75,6 +75,11 @@ int Department::count() const
7575 return rowCount();
7676}
7777
78+bool Department::isRoot() const
79+{
80+ return m_departmentId == "root";
81+}
82+
7883int Department::rowCount(const QModelIndex & /*parent*/) const
7984{
8085 if (m_departmentId.startsWith("child"))
tests/mocks/Unity/fake_department.h+3
@@ -32,6 +32,7 @@ class Department : public QAbstractListModel
3232 Q_PROPERTY(QString parentLabel READ parentLabel NOTIFY parentLabelChanged)
3333 Q_PROPERTY(bool loaded READ loaded NOTIFY loadedChanged)
3434 Q_PROPERTY(int count READ count NOTIFY countChanged)
35+ Q_PROPERTY(bool isRoot READ isRoot NOTIFY isRootChanged)
3536 // roles: string departmentId, string label, bool hasChildren, bool isActive
3637
3738public:
@@ -51,6 +52,7 @@ public:
5152 QString parentLabel() const;
5253 bool loaded() const;
5354 int count() const;
55+ bool isRoot() const;
5456
5557 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
5658 QHash<int, QByteArray> roleNames() const;
@@ -67,6 +69,7 @@ Q_SIGNALS:
6769 void parentLabelChanged(const QString&);
6870 void loadedChanged(bool);
6971 void countChanged(int);
72+ void isRootChanged(bool);
7073
7174private Q_SLOTS:
7275 void slotLoaded();