Merge lp:~jonas-drange/ubuntu-system-settings/displays-stub into lp:ubuntu-system-settings

Proposed by Jonas G. Drange
Status: Work in progress
Proposed branch: lp:~jonas-drange/ubuntu-system-settings/displays-stub
Merge into: lp:ubuntu-system-settings
Prerequisite: lp:~jonas-drange/ubuntu-system-settings/brightness-qml-testing
Diff against target: 1289 lines (+897/-38)
18 files modified
plugins/brightness/CMakeLists.txt (+4/-0)
plugins/brightness/PageComponent.qml (+138/-8)
plugins/brightness/brightness.cpp (+17/-0)
plugins/brightness/brightness.h (+13/-0)
plugins/brightness/displays/display.cpp (+141/-0)
plugins/brightness/displays/display.h (+112/-0)
plugins/brightness/displays/displaymodel.cpp (+190/-0)
plugins/brightness/displays/displaymodel.h (+82/-0)
plugins/brightness/plugin.cpp (+6/-0)
tests/mocks/Ubuntu/SystemSettings/Brightness/CMakeLists.txt (+8/-0)
tests/mocks/Ubuntu/SystemSettings/Brightness/MockAethercastDisplays.cpp (+20/-20)
tests/mocks/Ubuntu/SystemSettings/Brightness/MockAethercastDisplays.h (+3/-3)
tests/mocks/Ubuntu/SystemSettings/Brightness/MockBrightness.cpp (+36/-0)
tests/mocks/Ubuntu/SystemSettings/Brightness/MockBrightness.h (+21/-6)
tests/mocks/Ubuntu/SystemSettings/Brightness/MockDisplay.h (+52/-0)
tests/mocks/Ubuntu/SystemSettings/Brightness/MockDisplayModel.h (+26/-0)
tests/mocks/Ubuntu/SystemSettings/Brightness/plugin.cpp (+7/-1)
tests/plugins/brightness/tst_BrightnessPageComponent.qml (+21/-0)
To merge this branch: bzr merge lp:~jonas-drange/ubuntu-system-settings/displays-stub
Reviewer Review Type Date Requested Status
system-apps-ci-bot continuous-integration Needs Fixing
Ubuntu Touch System Settings Pending
Review via email: mp+309349@code.launchpad.net

This proposal supersedes a proposal from 2016-10-26.

Commit message

* adds display configuration UI
* adds display and displaymodel to serve as backend for new config UI (stubbed out for now)
* tests new UI (minimally)

Description of the change

This branch introduces most of the display configuration UI and some parts of the display and displaymodel API.

The idea is that the displaymodel will contain all configurable displays. The user the modifies a display element and then the displaymodel (or possibly a new class) asks Mir to configure the displays.

To post a comment you must log in.
1734. By Jonas G. Drange

remove the rest of the kbd jazz

1735. By Jonas G. Drange

make one test for when all new things are hidden, and one where a display config is shown

1736. By Jonas G. Drange

drop unecessary whitespace changes

Revision history for this message
system-apps-ci-bot (system-apps-ci-bot) wrote :

FAILED: Continuous integration, rev:1734
https://jenkins.canonical.com/system-apps/job/lp-ubuntu-system-settings-ci/218/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/system-apps/job/build/1908/console
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-0-fetch/1909
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=vivid+overlay/1748
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=vivid+overlay/1748/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1748
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1748/artifact/output/*zip*/output.zip
    FAILURE: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=yakkety/1748/console
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=vivid+overlay/1748
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=vivid+overlay/1748/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1748
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1748/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=yakkety/1748
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=yakkety/1748/artifact/output/*zip*/output.zip
    FAILURE: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=vivid+overlay/1748/console
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=xenial+overlay/1748
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=xenial+overlay/1748/artifact/output/*zip*/output.zip
    FAILURE: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=yakkety/1748/console

Click here to trigger a rebuild:
https://jenkins.canonical.com/system-apps/job/lp-ubuntu-system-settings-ci/218/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
system-apps-ci-bot (system-apps-ci-bot) wrote :

FAILED: Continuous integration, rev:1736
https://jenkins.canonical.com/system-apps/job/lp-ubuntu-system-settings-ci/219/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/system-apps/job/build/1909/console
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-0-fetch/1910
    FAILURE: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=vivid+overlay/1749/console
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1749
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1749/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=yakkety/1749
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=yakkety/1749/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=vivid+overlay/1749
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=vivid+overlay/1749/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1749
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1749/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=yakkety/1749
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=yakkety/1749/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=vivid+overlay/1749
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=vivid+overlay/1749/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=xenial+overlay/1749
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=xenial+overlay/1749/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=yakkety/1749
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=yakkety/1749/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/system-apps/job/lp-ubuntu-system-settings-ci/219/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Jonas G. Drange (jonas-drange) wrote :

The test failures should be addressed by silo 2066.

Unmerged revisions

1736. By Jonas G. Drange

drop unecessary whitespace changes

1735. By Jonas G. Drange

make one test for when all new things are hidden, and one where a display config is shown

1734. By Jonas G. Drange

remove the rest of the kbd jazz

1733. By Jonas G. Drange

add setData to display model

1732. By Jonas G. Drange

undo the kbd rectangle, move api forward

1731. By Jonas G. Drange

move api forward

1730. By Jonas G. Drange

merge prereq

1729. By Jonas G. Drange

add initial stub of displays code

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'plugins/brightness/CMakeLists.txt'
--- plugins/brightness/CMakeLists.txt 2016-10-26 14:45:41 +0000
+++ plugins/brightness/CMakeLists.txt 2016-10-26 14:45:42 +0000
@@ -16,6 +16,8 @@
16 aethercast/displays.h16 aethercast/displays.h
17 aethercast/freedesktop_properties.h17 aethercast/freedesktop_properties.h
18 aethercast/freedesktop_objectmanager.h18 aethercast/freedesktop_objectmanager.h
19 displays/display.h
20 displays/displaymodel.h
19 plugin.h21 plugin.h
20 brightness.h22 brightness.h
21 aethercast/aethercast_device.cpp23 aethercast/aethercast_device.cpp
@@ -25,6 +27,8 @@
25 aethercast/displays.cpp27 aethercast/displays.cpp
26 aethercast/freedesktop_properties.cpp28 aethercast/freedesktop_properties.cpp
27 aethercast/freedesktop_objectmanager.cpp29 aethercast/freedesktop_objectmanager.cpp
30 displays/display.cpp
31 displays/displaymodel.cpp
28 plugin.cpp32 plugin.cpp
29 brightness.cpp33 brightness.cpp
30 ${QML_SOURCES})34 ${QML_SOURCES})
3135
=== modified file 'plugins/brightness/PageComponent.qml'
--- plugins/brightness/PageComponent.qml 2016-10-26 14:45:41 +0000
+++ plugins/brightness/PageComponent.qml 2016-10-26 14:45:42 +0000
@@ -21,6 +21,7 @@
21import GSettings 1.021import GSettings 1.0
22import QtQuick 2.422import QtQuick 2.4
23import SystemSettings 1.023import SystemSettings 1.0
24import SystemSettings.ListItems 1.0 as SettingsListItems
24import Ubuntu.Components 1.325import Ubuntu.Components 1.3
25import Ubuntu.Components.ListItems 1.3 as ListItem26import Ubuntu.Components.ListItems 1.3 as ListItem
26import Ubuntu.SystemSettings.Brightness 1.027import Ubuntu.SystemSettings.Brightness 1.0
@@ -35,6 +36,14 @@
35 title: brightnessPanel.widiSupported ? i18n.tr("Brightness & Display") : i18n.tr("Brightness")36 title: brightnessPanel.widiSupported ? i18n.tr("Brightness & Display") : i18n.tr("Brightness")
36 flickable: scrollWidget37 flickable: scrollWidget
3738
39 function formatMode(mode) {
40 mode = mode.split("x");
41 /* TRANSLATORS: %1 refer to the amount of horizontal pixels in a
42 display resolution, and %2 to the vertical pixels. E.g. 1200x720.
43 %3 is the refresh rate in hz. */
44 return i18n.tr("%1×%2 @ %3hz").arg(mode[0]).arg(mode[1]).arg(mode[2]);
45 }
46
38 GSettings {47 GSettings {
39 id: gsettings48 id: gsettings
40 schema.id: "com.ubuntu.touch.system"49 schema.id: "com.ubuntu.touch.system"
@@ -68,7 +77,12 @@
6877
69 Flickable {78 Flickable {
70 id: scrollWidget79 id: scrollWidget
71 anchors.fill: parent80 anchors {
81 top: parent.top
82 left: parent.left
83 right: parent.right
84 bottom: applyButtonBackground.top
85 }
72 contentHeight: contentItem.childrenRect.height86 contentHeight: contentItem.childrenRect.height
73 boundsBehavior: (contentHeight > root.height) ?87 boundsBehavior: (contentHeight > root.height) ?
74 Flickable.DragAndOvershootBounds :88 Flickable.DragAndOvershootBounds :
@@ -82,7 +96,7 @@
82 anchors.left: parent.left96 anchors.left: parent.left
83 anchors.right: parent.right97 anchors.right: parent.right
8498
85 ListItem.Standard {99 SettingsListItems.Standard {
86 text: i18n.tr("Display brightness")100 text: i18n.tr("Display brightness")
87 showDivider: false101 showDivider: false
88 }102 }
@@ -113,12 +127,13 @@
113 }127 }
114 }128 }
115129
116 ListItem.Standard {130 SettingsListItems.Standard {
117 id: adjust131 id: adjust
118 text: i18n.tr("Adjust automatically")132 text: i18n.tr("Adjust automatically")
119 visible: brightnessPanel.powerdRunning &&133 visible: brightnessPanel.powerdRunning &&
120 brightnessPanel.autoBrightnessAvailable134 brightnessPanel.autoBrightnessAvailable
121 control: CheckBox {135
136 CheckBox {
122 id: autoAdjustCheck137 id: autoAdjustCheck
123 property bool serverChecked: gsettings.autoBrightness138 property bool serverChecked: gsettings.autoBrightness
124 onServerCheckedChanged: checked = serverChecked139 onServerCheckedChanged: checked = serverChecked
@@ -138,12 +153,13 @@
138 visible: brightnessPanel.widiSupported153 visible: brightnessPanel.widiSupported
139 }154 }
140155
141 ListItem.Standard {156 SettingsListItems.Standard {
142 objectName: "externalDisplayControl"157 objectName: "externalDisplayControl"
143 text: i18n.tr("External display")158 text: i18n.tr("External display")
144 enabled: brightnessPanel.widiSupported159 enabled: brightnessPanel.widiSupported
145 onClicked: enabledCheck.trigger()160 onClicked: enabledCheck.trigger()
146 control: Switch {161
162 Switch {
147 id: enabledCheck163 id: enabledCheck
148 property bool serverChecked: aethercastDisplays.enabled164 property bool serverChecked: aethercastDisplays.enabled
149 onServerCheckedChanged: checked = serverChecked165 onServerCheckedChanged: checked = serverChecked
@@ -154,15 +170,129 @@
154 }170 }
155 }171 }
156172
157 ListItem.SingleValue {173 SettingsListItems.SingleValueProgression {
158 objectName: "displayCasting"174 objectName: "displayCasting"
159 visible: brightnessPanel.widiSupported175 visible: brightnessPanel.widiSupported
160 enabled: aethercastDisplays.enabled176 enabled: aethercastDisplays.enabled
161 text: i18n.tr("Wireless display")177 text: i18n.tr("Wireless display")
162 value: aethercastDisplays.state === "connected" ? i18n.tr("Connected") : i18n.tr("Not connected")178 value: aethercastDisplays.state === "connected" ? i18n.tr("Connected") : i18n.tr("Not connected")
163 progression: true
164 onClicked: pageStack.push(Qt.resolvedUrl("WifiDisplays.qml"))179 onClicked: pageStack.push(Qt.resolvedUrl("WifiDisplays.qml"))
165 }180 }
181
182 Repeater {
183 objectName: "displayConfigurationRepeater"
184 model: brightnessPanel.allDisplays
185
186 Column {
187 objectName: "displayConfiguration_" + displayName
188 anchors {
189 left: parent.left
190 right: parent.right
191 }
192
193 Label {
194 visible: brightnessPanel.allDisplays.count > 1
195 anchors {
196 left: parent.left
197 right: parent.right
198 margins: units.gu(2)
199 }
200
201 text: displayName
202 }
203
204 SettingsItemTitle {
205 text: i18n.tr("Rotation:")
206 }
207
208 OptionSelector {
209 id: rotationSelector
210 objectName: "rotationSelector"
211 property bool _expanded: false
212 anchors {
213 left: parent.left
214 right: parent.right
215 margins: units.gu(2)
216 }
217 containerHeight: itemHeight * 4
218 model: [
219 i18n.tr("None"),
220 i18n.tr("90° clockwise"),
221 i18n.tr("180°"),
222 i18n.tr("270°")
223 ]
224 onDelegateClicked: {
225 expanded = !currentlyExpanded;
226 }
227 }
228
229 SettingsItemTitle {
230 text: availableModes.length > 1 ?
231 i18n.tr("Resolution:") :
232 /* TRANSLATORS: %1 is a display mode, e.g.
233 1200x720x24. */
234 i18n.tr("Resolution: %1").arg(formatMode(mode))
235 }
236
237 OptionSelector {
238 id: resolutionSelector
239 objectName: "resolutionSelector"
240 property bool _expanded: false
241 anchors {
242 left: parent.left
243 right: parent.right
244 margins: units.gu(2)
245 }
246 visible: availableModes.length > 1
247 containerHeight: itemHeight * availableModes.length
248 model: availableModes
249 onDelegateClicked: expanded = !currentlyExpanded
250 delegate: OptionSelectorDelegate {
251 text: formatMode(modelData)
252 }
253 }
254
255 SettingsItemTitle {
256 text: i18n.tr("Scale screen elements:")
257 }
258
259 Menus.SliderMenu {
260 id: scaleSlider
261 objectName: "scaleSlider"
262 minimumValue: 1.0
263 maximumValue: 100.0
264 value: scale
265 minIcon: "image://theme/grip-large"
266 maxIcon: "image://theme/view-grid-symbolic"
267 }
268 }
269 }
270 }
271 }
272
273 Rectangle {
274 id: applyButtonBackground
275 objectName: "applyButtonBackground"
276 anchors {
277 left: parent.left
278 right: parent.right
279 bottom: parent.bottom
280 }
281 color: Theme.palette.selected.background
282
283 visible: brightnessPanel.allDisplays.count > 0
284 height: units.gu(6)
285 Button {
286 id: applyButton
287 objectName: "applyButton"
288 anchors {
289 left: parent.left
290 leftMargin: units.gu(1)
291 verticalCenter: parent.verticalCenter
292 }
293 enabled: brightnessPanel.changedDisplays.count > 0
294 text: i18n.tr("Apply Changes…")
295 onClicked: brightnessPanel.applyDisplayConfiguration()
166 }296 }
167 }297 }
168}298}
169299
=== modified file 'plugins/brightness/brightness.cpp'
--- plugins/brightness/brightness.cpp 2016-04-13 19:21:59 +0000
+++ plugins/brightness/brightness.cpp 2016-10-26 14:45:42 +0000
@@ -25,6 +25,7 @@
25#include <QDBusReply>25#include <QDBusReply>
26#include <QDBusMetaType>26#include <QDBusMetaType>
27#include <QDebug>27#include <QDebug>
28#include <QQmlEngine>
2829
29// Returned data from getBrightnessParams30// Returned data from getBrightnessParams
30struct BrightnessParams {31struct BrightnessParams {
@@ -81,6 +82,8 @@
81 QDBusArgument result(reply.arguments()[0].value<QDBusArgument>());82 QDBusArgument result(reply.arguments()[0].value<QDBusArgument>());
82 BrightnessParams params = qdbus_cast<BrightnessParams>(result);83 BrightnessParams params = qdbus_cast<BrightnessParams>(result);
83 m_autoBrightnessAvailable = params.automatic;84 m_autoBrightnessAvailable = params.automatic;
85 m_changedDisplays.filterOnUncommittedChanges(true);
86 m_changedDisplays.setSourceModel(&m_displays);
84}87}
8588
86bool Brightness::getAutoBrightnessAvailable() const89bool Brightness::getAutoBrightnessAvailable() const
@@ -98,3 +101,17 @@
98 property_get("ubuntu.widi.supported", widi, "0");101 property_get("ubuntu.widi.supported", widi, "0");
99 return (strcmp(widi, "0") > 0);102 return (strcmp(widi, "0") > 0);
100}103}
104
105QAbstractItemModel* Brightness::allDisplays()
106{
107 auto ret = &m_displays;
108 QQmlEngine::setObjectOwnership(ret, QQmlEngine::CppOwnership);
109 return ret;
110}
111
112QAbstractItemModel* Brightness::changedDisplays()
113{
114 auto ret = &m_changedDisplays;
115 QQmlEngine::setObjectOwnership(ret, QQmlEngine::CppOwnership);
116 return ret;
117}
101118
=== modified file 'plugins/brightness/brightness.h'
--- plugins/brightness/brightness.h 2016-04-13 17:12:35 +0000
+++ plugins/brightness/brightness.h 2016-10-26 14:45:42 +0000
@@ -21,6 +21,9 @@
21#ifndef BRIGHTNESS_H21#ifndef BRIGHTNESS_H
22#define BRIGHTNESS_H22#define BRIGHTNESS_H
2323
24#include "displays/displaymodel.h"
25
26#include <QAbstractItemModel>
24#include <QDBusInterface>27#include <QDBusInterface>
25#include <QObject>28#include <QObject>
2629
@@ -36,12 +39,20 @@
36 Q_PROPERTY (bool widiSupported39 Q_PROPERTY (bool widiSupported
37 READ getWidiSupported40 READ getWidiSupported
38 CONSTANT)41 CONSTANT)
42 Q_PROPERTY (QAbstractItemModel* allDisplays
43 READ allDisplays
44 CONSTANT)
45 Q_PROPERTY (QAbstractItemModel* changedDisplays
46 READ changedDisplays
47 CONSTANT)
3948
40public:49public:
41 explicit Brightness(QObject *parent = 0);50 explicit Brightness(QObject *parent = 0);
42 bool getPowerdRunning() const;51 bool getPowerdRunning() const;
43 bool getAutoBrightnessAvailable() const;52 bool getAutoBrightnessAvailable() const;
44 bool getWidiSupported() const;53 bool getWidiSupported() const;
54 QAbstractItemModel* allDisplays();
55 QAbstractItemModel* changedDisplays();
4556
46private:57private:
47 QDBusConnection m_systemBusConnection;58 QDBusConnection m_systemBusConnection;
@@ -49,6 +60,8 @@
49 QDBusInterface m_powerdIface;60 QDBusInterface m_powerdIface;
50 bool m_powerdRunning;61 bool m_powerdRunning;
51 bool m_autoBrightnessAvailable;62 bool m_autoBrightnessAvailable;
63 DisplayModel m_displays;
64 DisplaysFilter m_changedDisplays;
52};65};
5366
54#endif // BRIGHTNESS_H67#endif // BRIGHTNESS_H
5568
=== added directory 'plugins/brightness/displays'
=== added file 'plugins/brightness/displays/display.cpp'
--- plugins/brightness/displays/display.cpp 1970-01-01 00:00:00 +0000
+++ plugins/brightness/displays/display.cpp 2016-10-26 14:45:42 +0000
@@ -0,0 +1,141 @@
1#include "display.h"
2
3Display::Display(QObject *parent)
4 : QObject(parent)
5{
6 QObject::connect(this, SIGNAL(nameChanged()),
7 this, SLOT(changedSlot()));
8 QObject::connect(this, SIGNAL(typeChanged()),
9 this, SLOT(changedSlot()));
10 QObject::connect(this, SIGNAL(mirroredChanged()),
11 this, SLOT(changedSlot()));
12 QObject::connect(this, SIGNAL(connectedChanged()),
13 this, SLOT(changedSlot()));
14 QObject::connect(this, SIGNAL(enabledChanged()),
15 this, SLOT(changedSlot()));
16 QObject::connect(this, SIGNAL(modeChanged()),
17 this, SLOT(changedSlot()));
18 QObject::connect(this, SIGNAL(availableModesChanged()),
19 this, SLOT(changedSlot()));
20 QObject::connect(this, SIGNAL(orientationChanged()),
21 this, SLOT(changedSlot()));
22 QObject::connect(this, SIGNAL(scaleChanged()),
23 this, SLOT(changedSlot()));
24 QObject::connect(this, SIGNAL(uncommittedChangesChanged()),
25 this, SLOT(changedSlot()));
26}
27
28QString Display::name() const
29{
30 return m_name;
31}
32
33QString Display::type() const
34{
35 return m_type;
36}
37
38bool Display::mirrored() const
39{
40 return m_mirrored;
41}
42
43bool Display::connected() const
44{
45 return m_connected;
46}
47
48bool Display::enabled() const
49{
50 return m_enabled;
51}
52
53QString Display::mode() const
54{
55 return m_mode;
56}
57
58QStringList Display::availableModes() const
59{
60 return m_availableModes;
61}
62
63Display::Orientation Display::orientation() const
64{
65 return m_orientation;
66}
67
68double Display::scale() const
69{
70 return m_scale;
71}
72
73bool Display::uncommittedChanges() const
74{
75 return m_uncommittedChanges;
76}
77
78void Display::setName(const QString &name)
79{
80 m_name = name;
81 Q_EMIT nameChanged();
82}
83
84void Display::setType(const QString &type)
85{
86 m_type = type;
87 Q_EMIT typeChanged();
88}
89
90void Display::setMirrored(const bool &mirrored)
91{
92 m_mirrored = mirrored;
93 Q_EMIT mirroredChanged();
94}
95
96void Display::setConnected(const bool &connected)
97{
98 m_connected = connected;
99 Q_EMIT connectedChanged();
100}
101
102void Display::setEnabled(const bool &enabled)
103{
104 m_enabled = enabled;
105 Q_EMIT enabledChanged();
106}
107
108void Display::setMode(const QString &mode)
109{
110 m_mode = mode;
111 Q_EMIT modeChanged();
112}
113
114void Display::setAvailableModes(const QStringList &availableModes)
115{
116 m_availableModes = availableModes;
117 Q_EMIT availableModesChanged();
118}
119
120void Display::setOrientation(const Display::Orientation &orientation)
121{
122 m_orientation = orientation;
123 Q_EMIT orientationChanged();
124}
125
126void Display::setScale(const double &scale)
127{
128 m_scale = scale;
129 Q_EMIT scaleChanged();
130}
131
132void Display::setUncommitedChanges(const bool uncommittedChanges)
133{
134 m_uncommittedChanges = uncommittedChanges;
135 Q_EMIT uncommittedChangesChanged();
136}
137
138void Display::changedSlot()
139{
140 Q_EMIT displayChanged(this);
141}
0142
=== added file 'plugins/brightness/displays/display.h'
--- plugins/brightness/displays/display.h 1970-01-01 00:00:00 +0000
+++ plugins/brightness/displays/display.h 2016-10-26 14:45:42 +0000
@@ -0,0 +1,112 @@
1#ifndef DISPLAY_H
2#define DISPLAY_H
3
4#include <QObject>
5#include <QString>
6#include <QStringList>
7
8class Display : public QObject
9{
10 Q_OBJECT
11 Q_PROPERTY(QString name
12 READ name
13 NOTIFY nameChanged)
14 Q_PROPERTY(QString type
15 READ type
16 NOTIFY typeChanged)
17 Q_PROPERTY(bool mirrored
18 READ mirrored
19 WRITE setMirrored
20 NOTIFY mirroredChanged)
21 Q_PROPERTY(bool connected
22 READ connected
23 NOTIFY connectedChanged)
24 Q_PROPERTY(bool enabled
25 READ enabled
26 WRITE setEnabled
27 NOTIFY enabledChanged)
28 Q_PROPERTY(QString mode
29 READ mode
30 WRITE setMode
31 NOTIFY modeChanged)
32 Q_PROPERTY(QStringList availableModes
33 READ availableModes
34 NOTIFY availableModesChanged)
35 Q_PROPERTY(Orientation orientation
36 READ orientation
37 WRITE setOrientation
38 NOTIFY orientationChanged)
39 Q_PROPERTY(double scale
40 READ scale
41 WRITE setScale
42 NOTIFY scaleChanged)
43 Q_PROPERTY(bool uncommittedChanges
44 READ uncommittedChanges
45 NOTIFY uncommittedChangesChanged)
46
47Q_SIGNALS:
48 void nameChanged();
49 void typeChanged();
50 void mirroredChanged();
51 void connectedChanged();
52 void enabledChanged();
53 void modeChanged();
54 void availableModesChanged();
55 void orientationChanged();
56 void scaleChanged();
57 void uncommittedChangesChanged();
58 void displayChanged(const Display *display);
59
60public:
61 explicit Display(QObject *parent = nullptr);
62 ~Display() {};
63 enum class Orientation : uint {
64 Normal, PortraitMode, LandscapeInvertedMode,
65 PortraitInvertedMode
66 };
67 enum class DisplayType : uint {
68 PhysicalType, AethercastType
69 };
70 Q_ENUMS(Orientation DisplayType)
71
72 QString name() const;
73 QString type() const;
74 bool mirrored() const;
75 bool connected() const;
76 bool enabled() const;
77 QString mode() const;
78 QStringList availableModes() const;
79 Orientation orientation() const;
80 double scale() const;
81 bool uncommittedChanges() const;
82
83 void setMirrored(const bool &mirrored);
84 void setEnabled(const bool &enabled);
85 void setMode(const QString &mode);
86 void setOrientation(const Orientation &orientation);
87 void setScale(const double &scale);
88
89protected:
90 void setName(const QString &name);
91 void setAvailableModes(const QStringList &availableModes);
92 void setConnected(const bool &connected);
93 void setType(const QString &type);
94 void setUncommitedChanges(const bool uncommittedChanges);
95 QString m_name = QString::null;
96 QString m_type = QString::null;
97 bool m_mirrored = false;
98 bool m_connected = false;
99 bool m_enabled = false;
100 QString m_mode = QString::null;
101 QStringList m_availableModes = QStringList();
102 Orientation m_orientation = Orientation::Normal;
103 double m_scale = 1;
104 bool m_uncommittedChanges = false;
105
106private slots:
107 void changedSlot();
108};
109
110Q_DECLARE_METATYPE(Display*)
111
112#endif // DISPLAY_H
0113
=== added file 'plugins/brightness/displays/displaymodel.cpp'
--- plugins/brightness/displays/displaymodel.cpp 1970-01-01 00:00:00 +0000
+++ plugins/brightness/displays/displaymodel.cpp 2016-10-26 14:45:42 +0000
@@ -0,0 +1,190 @@
1#include "displaymodel.h"
2
3#include <QDebug>
4
5DisplayModel::DisplayModel(QObject *parent)
6{
7}
8
9DisplayModel::~DisplayModel()
10{
11}
12
13int DisplayModel::rowCount(const QModelIndex &parent) const
14{
15 return m_displays.count();
16}
17
18QVariant DisplayModel::data(const QModelIndex &index, int role) const
19{
20 QVariant ret;
21
22 if ((0 <= index.row()) && (index.row() < m_displays.size())) {
23
24 auto display = m_displays[index.row()];
25
26 switch (role) {
27 case Qt::DisplayRole:
28 ret = display->name();
29 break;
30 case TypeRole:
31 ret = display->type();
32 break;
33 case MirroredRole:
34 ret = display->mirrored();
35 break;
36 case ConnectedRole:
37 ret = display->connected();
38 break;
39 case EnabledRole:
40 ret = display->enabled();
41 break;
42 case ModeRole:
43 ret = display->mode();
44 break;
45 case AvailableModesRole:
46 ret = display->availableModes();
47 break;
48 case OrientationRole:
49 ret = (uint) display->orientation();
50 break;
51 case ScaleRole:
52 ret = display->scale();
53 break;
54 case UncommittedChangesRole:
55 ret = display->uncommittedChanges();
56 break;
57 }
58 }
59
60 return ret;
61}
62
63bool DisplayModel::setData(const QModelIndex &index, const QVariant &value,
64 int role)
65{
66 if ((0 <= index.row()) && (index.row() < m_displays.size())) {
67
68 auto display = m_displays[index.row()];
69
70 switch (role) {
71
72 case MirroredRole:
73 display->setMirrored(value.toBool());
74 break;
75 case EnabledRole:
76 display->setEnabled(value.toBool());
77 break;
78 case ModeRole:
79 display->setMode(value.toString());
80 break;
81 case OrientationRole:
82 display->setOrientation((Display::Orientation) value.toUInt());
83 break;
84 case ScaleRole:
85 display->setScale(value.toInt());
86 break;
87 case Qt::DisplayRole:
88 case TypeRole:
89 case ConnectedRole:
90 case AvailableModesRole:
91 case UncommittedChangesRole:
92 default:
93 return false;
94 }
95 return true;
96 } else {
97 return false;
98 }
99}
100
101
102QHash<int,QByteArray> DisplayModel::roleNames() const
103{
104 static QHash<int,QByteArray> names;
105 if (Q_UNLIKELY(names.empty())) {
106 names[Qt::DisplayRole] = "displayName";
107 names[MirroredRole] = "mirrored";
108 names[ConnectedRole] = "connected";
109 names[EnabledRole] = "enabled";
110 names[ModeRole] = "mode";
111 names[AvailableModesRole] = "availableModes";
112 names[OrientationRole] = "orientation";
113 names[ScaleRole] = "scale";
114 names[UncommittedChangesRole] = "uncommittedChanges";
115 }
116 return names;
117}
118
119void DisplayModel::addDisplay(const QSharedPointer<Display> &display)
120{
121 // TODO: find display
122 int row = -1;
123
124 if (row >= 0) { // update existing display
125 m_displays[row] = display;
126 emitRowChanged(row);
127 } else { // add new display
128 row = m_displays.size();
129 beginInsertRows(QModelIndex(), row, row);
130 m_displays.append(display);
131 endInsertRows();
132 }
133
134 if (display) {
135 QObject::connect(display.data(), SIGNAL(displayChanged(const Display*)),
136 this, SLOT(displayChangedSlot(const Display*)));
137 }
138
139 Q_EMIT countChanged();
140}
141
142void DisplayModel::emitRowChanged(const int &row)
143{
144 if (0 <= row && row < m_displays.size()) {
145 QModelIndex qmi = index(row, 0);
146 Q_EMIT(dataChanged(qmi, qmi));
147 }
148}
149
150void DisplayModel::displayChangedSlot(const Display *display)
151{
152 // find the row that goes with this display
153 int row = -1;
154 if (display != nullptr)
155 for (int i = 0, n = m_displays.size(); row == -1 && i < n; i++)
156 if (m_displays[i].data() == display)
157 row = i;
158
159 if (row != -1)
160 emitRowChanged(row);
161}
162
163bool DisplaysFilter::lessThan(const QModelIndex &left,
164 const QModelIndex &right) const
165{
166 const QString a = sourceModel()->data(left, Qt::DisplayRole).value<QString>();
167 const QString b = sourceModel()->data(right, Qt::DisplayRole).value<QString>();
168 return a < b;
169}
170
171void DisplaysFilter::filterOnUncommittedChanges(const bool apply)
172{
173 m_uncommittedChanges = apply;
174 m_uncommittedChangesEnabled = true;
175 invalidateFilter();
176}
177
178bool DisplaysFilter::filterAcceptsRow(int sourceRow,
179 const QModelIndex &sourceParent) const
180{
181 bool accepts = true;
182 QModelIndex childIndex = sourceModel()->index(sourceRow, 0, sourceParent);
183
184 if (accepts && m_uncommittedChangesEnabled) {
185 const bool uncommittedChanges = childIndex.model()->data(childIndex, DisplayModel::UncommittedChangesRole).value<bool>();
186 accepts = (m_uncommittedChanges == uncommittedChanges);
187 }
188
189 return accepts;
190}
0191
=== added file 'plugins/brightness/displays/displaymodel.h'
--- plugins/brightness/displays/displaymodel.h 1970-01-01 00:00:00 +0000
+++ plugins/brightness/displays/displaymodel.h 2016-10-26 14:45:42 +0000
@@ -0,0 +1,82 @@
1#ifndef DISPLAY_MODEL_H
2#define DISPLAY_MODEL_H
3
4#include "display.h"
5
6#include <QAbstractListModel>
7#include <QByteArray>
8#include <QHash>
9#include <QList>
10#include <QModelIndex>
11#include <QSharedPointer>
12#include <QSortFilterProxyModel>
13#include <QVariant>
14
15class DisplayModel : public QAbstractListModel
16{
17 Q_OBJECT
18 Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
19public:
20 explicit DisplayModel(QObject *parent = 0);
21 ~DisplayModel();
22
23 enum Roles
24 {
25 // Qt::DisplayRole holds device name
26 TypeRole = Qt::UserRole,
27 MirroredRole,
28 ConnectedRole,
29 EnabledRole,
30 ModeRole,
31 AvailableModesRole,
32 OrientationRole,
33 ScaleRole,
34 UncommittedChangesRole,
35 LastRole = UncommittedChangesRole
36 };
37
38 int rowCount(const QModelIndex &parent = QModelIndex()) const;
39 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
40 bool setData(const QModelIndex &index, const QVariant &value,
41 int role = Qt::EditRole);
42 QHash<int,QByteArray> roleNames() const;
43
44Q_SIGNALS:
45 void countChanged();
46
47protected:
48 void emitRowChanged(const int &row);
49 void addDisplay(const QSharedPointer<Display> &display);
50
51private:
52 QList<QSharedPointer<Display> > m_displays;
53
54private slots:
55 void displayChangedSlot(const Display *display);
56};
57
58class DisplaysFilter : public QSortFilterProxyModel
59{
60 Q_OBJECT
61 Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
62
63public:
64 DisplaysFilter() {}
65 virtual ~DisplaysFilter() {}
66
67 void filterOnUncommittedChanges(const bool apply);
68
69Q_SIGNALS:
70 void countChanged(int count);
71
72protected:
73 virtual bool filterAcceptsRow(int, const QModelIndex&) const;
74 virtual bool lessThan(const QModelIndex&, const QModelIndex&) const;
75
76private:
77 bool m_uncommittedChanges = false;
78 bool m_uncommittedChangesEnabled = false;
79
80};
81
82#endif // DISPLAY_MODEL_H
083
=== modified file 'plugins/brightness/plugin.cpp'
--- plugins/brightness/plugin.cpp 2016-04-13 18:49:49 +0000
+++ plugins/brightness/plugin.cpp 2016-10-26 14:45:42 +0000
@@ -27,6 +27,9 @@
27#include "aethercast/displays.h"27#include "aethercast/displays.h"
28#include "aethercast/device.h"28#include "aethercast/device.h"
2929
30#include "displays/display.h"
31#include "displays/displaymodel.h"
32
3033
31void BackendPlugin::registerTypes(const char *uri)34void BackendPlugin::registerTypes(const char *uri)
32{35{
@@ -39,6 +42,9 @@
39 qmlRegisterType<Brightness>(uri, 1, 0, "UbuntuBrightnessPanel");42 qmlRegisterType<Brightness>(uri, 1, 0, "UbuntuBrightnessPanel");
40 qmlRegisterType<Device>(uri, 1, 0, "AethercastDevice");43 qmlRegisterType<Device>(uri, 1, 0, "AethercastDevice");
41 qmlRegisterType<Displays>(uri, 1, 0, "AethercastDisplays");44 qmlRegisterType<Displays>(uri, 1, 0, "AethercastDisplays");
45
46 qmlRegisterType<DisplayModel>(uri, 1, 0, "DisplayModel");
47 qmlRegisterType<Display>(uri, 1, 0, "Display");
42}48}
4349
44void BackendPlugin::initializeEngine(QQmlEngine *engine, const char *uri)50void BackendPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
4551
=== modified file 'tests/mocks/Ubuntu/SystemSettings/Brightness/CMakeLists.txt'
--- tests/mocks/Ubuntu/SystemSettings/Brightness/CMakeLists.txt 2016-10-26 14:45:41 +0000
+++ tests/mocks/Ubuntu/SystemSettings/Brightness/CMakeLists.txt 2016-10-26 14:45:42 +0000
@@ -1,6 +1,7 @@
1include_directories(1include_directories(
2 ${CMAKE_CURRENT_BINARY_DIR}2 ${CMAKE_CURRENT_BINARY_DIR}
3 ${CMAKE_SOURCE_DIR}/plugins/brightness/3 ${CMAKE_SOURCE_DIR}/plugins/brightness/
4 ${CMAKE_SOURCE_DIR}/plugins/brightness/displays
4)5)
56
6set(MOCK_BRIGHTNESS_SRCS7set(MOCK_BRIGHTNESS_SRCS
@@ -8,6 +9,13 @@
8 MockAethercastDeviceModel.cpp9 MockAethercastDeviceModel.cpp
9 MockAethercastDisplays.cpp10 MockAethercastDisplays.cpp
10 MockBrightness.cpp11 MockBrightness.cpp
12
13 ${CMAKE_SOURCE_DIR}/plugins/brightness/displays/display.h
14 ${CMAKE_SOURCE_DIR}/plugins/brightness/displays/displaymodel.h
15 MockDisplay.h
16 MockDisplayModel.h
17 ${CMAKE_SOURCE_DIR}/plugins/brightness/displays/display.cpp
18 ${CMAKE_SOURCE_DIR}/plugins/brightness/displays/displaymodel.cpp
11 plugin.cpp19 plugin.cpp
12)20)
1321
1422
=== modified file 'tests/mocks/Ubuntu/SystemSettings/Brightness/MockAethercastDisplays.cpp'
--- tests/mocks/Ubuntu/SystemSettings/Brightness/MockAethercastDisplays.cpp 2016-10-26 14:45:41 +0000
+++ tests/mocks/Ubuntu/SystemSettings/Brightness/MockAethercastDisplays.cpp 2016-10-26 14:45:42 +0000
@@ -19,71 +19,71 @@
1919
20#include <QQmlEngine>20#include <QQmlEngine>
2121
22void MockDisplays::connectDevice(const QString &address)22void MockAethercastDisplays::connectDevice(const QString &address)
23{23{
24 Q_UNUSED(address)24 Q_UNUSED(address)
25}25}
2626
27void MockDisplays::disconnectDevice(const QString &address)27void MockAethercastDisplays::disconnectDevice(const QString &address)
28{28{
29 Q_UNUSED(address)29 Q_UNUSED(address)
30}30}
3131
32void MockDisplays::scan()32void MockAethercastDisplays::scan()
33{33{
34 m_scanning = true;34 m_scanning = true;
35 Q_EMIT scanningChanged(m_scanning);35 Q_EMIT scanningChanged(m_scanning);
36}36}
3737
38void MockDisplays::stopScan()38void MockAethercastDisplays::stopScan()
39{39{
40 m_scanning = false;40 m_scanning = false;
41 Q_EMIT scanningChanged(m_scanning);41 Q_EMIT scanningChanged(m_scanning);
42}42}
4343
44void MockDisplays::setProperties(const QMap<QString, QVariant> &properties)44void MockAethercastDisplays::setProperties(const QMap<QString, QVariant> &properties)
45{45{
46 Q_UNUSED(properties)46 Q_UNUSED(properties)
47}47}
4848
49QAbstractItemModel* MockDisplays::devices()49QAbstractItemModel* MockAethercastDisplays::devices()
50{50{
51 auto ret = &m_devices;51 auto ret = &m_devices;
52 QQmlEngine::setObjectOwnership(ret, QQmlEngine::CppOwnership);52 QQmlEngine::setObjectOwnership(ret, QQmlEngine::CppOwnership);
53 return ret;53 return ret;
54}54}
5555
56QAbstractItemModel* MockDisplays::connectedDevices()56QAbstractItemModel* MockAethercastDisplays::connectedDevices()
57{57{
58 auto ret = &m_connectedDevices;58 auto ret = &m_connectedDevices;
59 QQmlEngine::setObjectOwnership(ret, QQmlEngine::CppOwnership);59 QQmlEngine::setObjectOwnership(ret, QQmlEngine::CppOwnership);
60 return ret;60 return ret;
61}61}
6262
63QAbstractItemModel* MockDisplays::disconnectedDevices()63QAbstractItemModel* MockAethercastDisplays::disconnectedDevices()
64{64{
65 auto ret = &m_disconnectedDevices;65 auto ret = &m_disconnectedDevices;
66 QQmlEngine::setObjectOwnership(ret, QQmlEngine::CppOwnership);66 QQmlEngine::setObjectOwnership(ret, QQmlEngine::CppOwnership);
67 return ret;67 return ret;
68}68}
6969
70bool MockDisplays::scanning() const70bool MockAethercastDisplays::scanning() const
71{71{
72 return m_scanning;72 return m_scanning;
73}73}
7474
75bool MockDisplays::enabled() const75bool MockAethercastDisplays::enabled() const
76{76{
77 return m_enabled;77 return m_enabled;
78}78}
7979
80void MockDisplays::setEnabled(const bool enabled)80void MockAethercastDisplays::setEnabled(const bool enabled)
81{81{
82 m_enabled = enabled;82 m_enabled = enabled;
83 Q_EMIT enabledChanged(enabled);83 Q_EMIT enabledChanged(enabled);
84}84}
8585
86QString MockDisplays::state() const86QString MockAethercastDisplays::state() const
87{87{
88 return m_state;88 return m_state;
89}89}
9090
=== modified file 'tests/mocks/Ubuntu/SystemSettings/Brightness/MockAethercastDisplays.h'
--- tests/mocks/Ubuntu/SystemSettings/Brightness/MockAethercastDisplays.h 2016-10-26 14:45:41 +0000
+++ tests/mocks/Ubuntu/SystemSettings/Brightness/MockAethercastDisplays.h 2016-10-26 14:45:42 +0000
@@ -23,7 +23,7 @@
2323
24#include <QObject>24#include <QObject>
2525
26class MockDisplays : public QObject26class MockAethercastDisplays : public QObject
27{27{
28 Q_OBJECT28 Q_OBJECT
29 Q_PROPERTY (QAbstractItemModel* devices29 Q_PROPERTY (QAbstractItemModel* devices
@@ -46,10 +46,10 @@
46 READ state46 READ state
47 NOTIFY stateChanged)47 NOTIFY stateChanged)
48public:48public:
49 explicit MockDisplays(QObject *parent = nullptr) {49 explicit MockAethercastDisplays(QObject *parent = nullptr) {
50 Q_UNUSED(parent)50 Q_UNUSED(parent)
51 };51 };
52 ~MockDisplays() {}52 ~MockAethercastDisplays() {}
5353
54 enum Error {54 enum Error {
55 None,55 None,
5656
=== modified file 'tests/mocks/Ubuntu/SystemSettings/Brightness/MockBrightness.cpp'
--- tests/mocks/Ubuntu/SystemSettings/Brightness/MockBrightness.cpp 2016-10-26 14:45:41 +0000
+++ tests/mocks/Ubuntu/SystemSettings/Brightness/MockBrightness.cpp 2016-10-26 14:45:42 +0000
@@ -15,8 +15,20 @@
15 * You should have received a copy of the GNU General Public License along15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 */17 */
18#include "MockDisplayModel.h"
18#include "MockBrightness.h"19#include "MockBrightness.h"
1920
21#include <QQmlEngine>
22
23MockBrightness::MockBrightness(QObject *parent)
24 : QObject(parent)
25 , m_displays()
26 , m_changedDisplays()
27{
28 m_changedDisplays.filterOnUncommittedChanges(true);
29 m_changedDisplays.setSourceModel(&m_displays);
30}
31
20bool MockBrightness::getPowerdRunning() const32bool MockBrightness::getPowerdRunning() const
21{33{
22 return m_powerdRunning;34 return m_powerdRunning;
@@ -49,3 +61,27 @@
49 m_widiSupported = supported;61 m_widiSupported = supported;
50 Q_EMIT widiSupportedChanged();62 Q_EMIT widiSupportedChanged();
51}63}
64
65QAbstractItemModel* MockBrightness::allDisplays()
66{
67 auto ret = &m_displays;
68 QQmlEngine::setObjectOwnership(ret, QQmlEngine::CppOwnership);
69 return ret;
70}
71
72QAbstractItemModel* MockBrightness::changedDisplays()
73{
74 auto ret = &m_changedDisplays;
75 QQmlEngine::setObjectOwnership(ret, QQmlEngine::CppOwnership);
76 return ret;
77}
78
79void MockBrightness::applyDisplayConfiguration()
80{
81
82}
83
84MockDisplayModel* MockBrightness::displayModel()
85{
86 return (MockDisplayModel*) allDisplays();
87}
5288
=== modified file 'tests/mocks/Ubuntu/SystemSettings/Brightness/MockBrightness.h'
--- tests/mocks/Ubuntu/SystemSettings/Brightness/MockBrightness.h 2016-10-26 14:45:41 +0000
+++ tests/mocks/Ubuntu/SystemSettings/Brightness/MockBrightness.h 2016-10-26 14:45:42 +0000
@@ -19,7 +19,11 @@
19#ifndef MOCK_BRIGHTNESS_H19#ifndef MOCK_BRIGHTNESS_H
20#define MOCK_BRIGHTNESS_H20#define MOCK_BRIGHTNESS_H
2121
22#include "MockDisplayModel.h"
23
24#include <QAbstractItemModel>
22#include <QObject>25#include <QObject>
26#include <QSortFilterProxyModel>
2327
24class MockBrightness : public QObject28class MockBrightness : public QObject
25{29{
@@ -33,16 +37,25 @@
33 Q_PROPERTY (bool widiSupported37 Q_PROPERTY (bool widiSupported
34 READ getWidiSupported38 READ getWidiSupported
35 NOTIFY widiSupportedChanged)39 NOTIFY widiSupportedChanged)
40 Q_PROPERTY (QAbstractItemModel* allDisplays
41 READ allDisplays
42 CONSTANT)
43 Q_PROPERTY (QAbstractItemModel* changedDisplays
44 READ changedDisplays
45 CONSTANT)
46
36public:47public:
37 explicit MockBrightness(QObject *parent = 0) {48 explicit MockBrightness(QObject *parent = 0);
38 Q_UNUSED(parent)
39 };
40 bool getPowerdRunning() const;49 bool getPowerdRunning() const;
41 bool getAutoBrightnessAvailable() const;50 bool getAutoBrightnessAvailable() const;
42 bool getWidiSupported() const;51 bool getWidiSupported() const;
43 Q_INVOKABLE void setPowerdRunning(const bool running); // mock only52 Q_INVOKABLE void setPowerdRunning(const bool running);
44 Q_INVOKABLE void setAutoBrightnessAvailable(const bool available); // mock only53 Q_INVOKABLE void setAutoBrightnessAvailable(const bool available);
45 Q_INVOKABLE void setWidiSupported(const bool supported); // mock only54 Q_INVOKABLE void setWidiSupported(const bool supported);
55 QAbstractItemModel* allDisplays();
56 QAbstractItemModel* changedDisplays();
57 Q_INVOKABLE void applyDisplayConfiguration();
58 Q_INVOKABLE MockDisplayModel* displayModel(); // mock only
4659
47Q_SIGNALS:60Q_SIGNALS:
48 void powerdRunningChanged(); // mock only61 void powerdRunningChanged(); // mock only
@@ -53,6 +66,8 @@
53 bool m_powerdRunning = false;66 bool m_powerdRunning = false;
54 bool m_autoBrightnessAvailable = false;67 bool m_autoBrightnessAvailable = false;
55 bool m_widiSupported = false;68 bool m_widiSupported = false;
69 MockDisplayModel m_displays;
70 DisplaysFilter m_changedDisplays;
56};71};
5772
58#endif // MOCK_BRIGHTNESS_H73#endif // MOCK_BRIGHTNESS_H
5974
=== added file 'tests/mocks/Ubuntu/SystemSettings/Brightness/MockDisplay.h'
--- tests/mocks/Ubuntu/SystemSettings/Brightness/MockDisplay.h 1970-01-01 00:00:00 +0000
+++ tests/mocks/Ubuntu/SystemSettings/Brightness/MockDisplay.h 2016-10-26 14:45:42 +0000
@@ -0,0 +1,52 @@
1#ifndef MOCK_DISPLAY_H
2#define MOCK_DISPLAY_H
3
4#include "display.h"
5
6#include <QObject>
7#include <QDebug>
8
9struct MockDisplay : public Display
10{
11 Q_OBJECT
12public:
13 Q_INVOKABLE void setName(const QString &name) // mock only
14 {
15 m_name = name;
16 Q_EMIT nameChanged();
17 }
18
19 Q_INVOKABLE void setType(const QString &type) // mock only
20 {
21 m_type = type;
22 Q_EMIT typeChanged();
23 }
24
25 Q_INVOKABLE void setConnected(const bool &connected) // mock only
26 {
27 m_connected = connected;
28 Q_EMIT connectedChanged();
29 }
30
31 Q_INVOKABLE void setAvailableModes(const QStringList &availableModes) // mock only
32 {
33 m_availableModes = availableModes;
34 Q_EMIT availableModesChanged();
35 }
36
37 Q_INVOKABLE void setUncommitedChanges(const bool uncommittedChanges) // mock only
38 {
39 m_uncommittedChanges = uncommittedChanges;
40 Q_EMIT uncommittedChangesChanged();
41 }
42
43 Q_INVOKABLE void addMode(const QString &mode) // mock only
44 {
45 m_availableModes.append(mode);
46 Q_EMIT availableModesChanged();
47 }
48};
49
50Q_DECLARE_METATYPE(MockDisplay*)
51
52#endif // MOCK_DISPLAY_H
053
=== added file 'tests/mocks/Ubuntu/SystemSettings/Brightness/MockDisplayModel.h'
--- tests/mocks/Ubuntu/SystemSettings/Brightness/MockDisplayModel.h 1970-01-01 00:00:00 +0000
+++ tests/mocks/Ubuntu/SystemSettings/Brightness/MockDisplayModel.h 2016-10-26 14:45:42 +0000
@@ -0,0 +1,26 @@
1#ifndef MOCK_DISPLAY_MODEL_H
2#define MOCK_DISPLAY_MODEL_H
3
4#include "displaymodel.h"
5#include "MockDisplay.h"
6
7#include <QObject>
8#include <QQmlEngine>
9
10class MockDisplayModel : public DisplayModel
11{
12 Q_OBJECT
13public:
14 MockDisplayModel(QObject *parent = 0) : DisplayModel(parent) {
15 };
16 ~MockDisplayModel() {};
17 Q_INVOKABLE MockDisplay* mockAddDisplay() // mock only
18 {
19 QSharedPointer<MockDisplay> d = QSharedPointer<MockDisplay>(new MockDisplay);
20 addDisplay(d);
21 QQmlEngine::setObjectOwnership(d.data(), QQmlEngine::CppOwnership);
22 return d.data();
23 }
24};
25
26#endif // MOCK_DISPLAY_MODEL_H
027
=== modified file 'tests/mocks/Ubuntu/SystemSettings/Brightness/plugin.cpp'
--- tests/mocks/Ubuntu/SystemSettings/Brightness/plugin.cpp 2016-10-26 14:45:41 +0000
+++ tests/mocks/Ubuntu/SystemSettings/Brightness/plugin.cpp 2016-10-26 14:45:42 +0000
@@ -22,6 +22,9 @@
22#include "MockAethercastDeviceModel.h"22#include "MockAethercastDeviceModel.h"
23#include "MockAethercastDisplays.h"23#include "MockAethercastDisplays.h"
2424
25#include "MockDisplay.h"
26#include "MockDisplayModel.h"
27
25#include <QtQml>28#include <QtQml>
2629
27void BackendPlugin::registerTypes(const char *uri)30void BackendPlugin::registerTypes(const char *uri)
@@ -29,5 +32,8 @@
29 Q_ASSERT(uri == QLatin1String("Ubuntu.SystemSettings.Brightness"));32 Q_ASSERT(uri == QLatin1String("Ubuntu.SystemSettings.Brightness"));
30 qmlRegisterType<MockBrightness>(uri, 1, 0, "UbuntuBrightnessPanel");33 qmlRegisterType<MockBrightness>(uri, 1, 0, "UbuntuBrightnessPanel");
31 qmlRegisterType<MockAethercastDevice>(uri, 1, 0, "AethercastDevice");34 qmlRegisterType<MockAethercastDevice>(uri, 1, 0, "AethercastDevice");
32 qmlRegisterType<MockDisplays>(uri, 1, 0, "AethercastDisplays");35 qmlRegisterType<MockAethercastDisplays>(uri, 1, 0, "AethercastDisplays");
36
37 qmlRegisterUncreatableType<MockDisplay>(uri, 1, 0, "Display", "Not to be instantiated directly.");
38 qmlRegisterType<MockDisplayModel>(uri, 1, 0, "DisplayModel");
33}39}
3440
=== modified file 'tests/plugins/brightness/tst_BrightnessPageComponent.qml'
--- tests/plugins/brightness/tst_BrightnessPageComponent.qml 2016-10-26 14:45:41 +0000
+++ tests/plugins/brightness/tst_BrightnessPageComponent.qml 2016-10-26 14:45:42 +0000
@@ -86,5 +86,26 @@
86 verify(entry.enabled);86 verify(entry.enabled);
87 compare(entry.value, i18n.tr("Not connected"));87 compare(entry.value, i18n.tr("Not connected"));
88 }88 }
89
90 // Test that everything is hidden if only aethercast devices (or none)
91 function test_no_displays() {
92 var repeater = findChild(instance, "displayConfigurationRepeater");
93 compare(repeater.count, 0);
94 }
95
96 // Test that there's a UI when we have some display available.
97 function test_one_display() {
98 var displayModel = get_panel_plugin().displayModel();
99 var display = displayModel.mockAddDisplay();
100 display.setName("Foo")
101 display.addMode("1600x1200x60")
102 display.addMode("1280x1024x60")
103 display.mode = "1600x1200x60"
104
105 var repeater = findChild(instance, "displayConfigurationRepeater");
106 var panel = findChild(instance, "displayConfiguration_" + display.name);
107 verify(panel.visible);
108 compare(repeater.count, 1);
109 }
89 }110 }
90}111}

Subscribers

People subscribed via source and target branches