Merge lp:~ahayzen/ubuntu-settings-components/printer-components-is-two-sided into lp:~phablet-team/ubuntu-settings-components/printer-components

Proposed by Andrew Hayzen
Status: Merged
Merged at revision: 218
Proposed branch: lp:~ahayzen/ubuntu-settings-components/printer-components-is-two-sided
Merge into: lp:~phablet-team/ubuntu-settings-components/printer-components
Diff against target: 126 lines (+52/-0)
3 files modified
plugins/Ubuntu/Settings/Printers/printer/printerjob.cpp (+19/-0)
plugins/Ubuntu/Settings/Printers/printer/printerjob.h (+5/-0)
tests/unittests/Printers/tst_printerjob.cpp (+28/-0)
To merge this branch: bzr merge lp:~ahayzen/ubuntu-settings-components/printer-components-is-two-sided
Reviewer Review Type Date Requested Status
Jonas G. Drange (community) Approve
Review via email: mp+315693@code.launchpad.net

Commit message

* Add isTwoSided read-only property to PrinterJob which allows the QML to know if the selected duplexMode is actually going to print double sided

Description of the change

* Add isTwoSided read-only property to PrinterJob which allows the QML to know if the selected duplexMode is actually going to print double sided

To post a comment you must log in.
Revision history for this message
Jonas G. Drange (jonas-drange) wrote :

LGTM! Thanks

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/Ubuntu/Settings/Printers/printer/printerjob.cpp'
2--- plugins/Ubuntu/Settings/Printers/printer/printerjob.cpp 2017-01-25 15:37:42 +0000
3+++ plugins/Ubuntu/Settings/Printers/printer/printerjob.cpp 2017-01-26 16:21:27 +0000
4@@ -38,6 +38,7 @@
5 , m_copies(1)
6 , m_backend(backend)
7 , m_duplex_mode(0)
8+ , m_is_two_sided(false)
9 , m_printer(printer)
10 , m_printer_name(QStringLiteral(""))
11 , m_print_range(QStringLiteral(""))
12@@ -113,6 +114,11 @@
13 }
14 }
15
16+bool PrinterJob::isTwoSided() const
17+{
18+ return m_is_two_sided;
19+}
20+
21 bool PrinterJob::landscape() const
22 {
23 return m_landscape;
24@@ -220,6 +226,19 @@
25
26 Q_EMIT duplexModeChanged();
27 }
28+
29+ // Always try to set the duplexMode as this was an int and the underlying
30+ // model may be in a different order resulting in the same int being given
31+ setIsTwoSided(getDuplexMode() != PrinterEnum::DuplexMode::DuplexNone);
32+}
33+
34+void PrinterJob::setIsTwoSided(const bool isTwoSided)
35+{
36+ if (m_is_two_sided != isTwoSided) {
37+ m_is_two_sided = isTwoSided;
38+
39+ Q_EMIT isTwoSidedChanged();
40+ }
41 }
42
43 void PrinterJob::setLandscape(const bool landscape)
44
45=== modified file 'plugins/Ubuntu/Settings/Printers/printer/printerjob.h'
46--- plugins/Ubuntu/Settings/Printers/printer/printerjob.h 2017-01-25 15:37:42 +0000
47+++ plugins/Ubuntu/Settings/Printers/printer/printerjob.h 2017-01-26 16:21:27 +0000
48@@ -39,6 +39,7 @@
49 Q_PROPERTY(PrinterEnum::ColorModelType colorModelType READ colorModelType NOTIFY colorModelTypeChanged)
50 Q_PROPERTY(int copies READ copies WRITE setCopies NOTIFY copiesChanged)
51 Q_PROPERTY(int duplexMode READ duplexMode WRITE setDuplexMode NOTIFY duplexModeChanged)
52+ Q_PROPERTY(bool isTwoSided READ isTwoSided NOTIFY isTwoSidedChanged)
53 Q_PROPERTY(bool landscape READ landscape WRITE setLandscape NOTIFY landscapeChanged)
54 // Q_PROPERTY(Printer *printer READ printer WRITE setPrinter NOTIFY printerChanged)
55 Q_PROPERTY(QString printerName READ printerName WRITE setPrinterName NOTIFY printerNameChanged)
56@@ -60,6 +61,7 @@
57 PrinterEnum::ColorModelType colorModelType() const;
58 int copies() const;
59 int duplexMode() const;
60+ bool isTwoSided() const;
61 bool landscape() const;
62 // Printer *printer() const;
63 QString printerName() const;
64@@ -89,6 +91,7 @@
65 void setTitle(const QString &title);
66 private Q_SLOTS:
67 void loadDefaults();
68+ void setIsTwoSided(const bool isTwoSided);
69 void setState(const PrinterEnum::State &state);
70 Q_SIGNALS:
71 void collateChanged();
72@@ -96,6 +99,7 @@
73 void colorModelTypeChanged();
74 void copiesChanged();
75 void duplexModeChanged();
76+ void isTwoSidedChanged();
77 void landscapeChanged();
78 // void printerChanged();
79 void printerNameChanged();
80@@ -111,6 +115,7 @@
81 int m_copies;
82 PrinterBackend *m_backend; // TODO: Maybe use the printer's backend?
83 int m_duplex_mode;
84+ bool m_is_two_sided;
85 bool m_landscape;
86 Printer *m_printer;
87 QString m_printer_name;
88
89=== modified file 'tests/unittests/Printers/tst_printerjob.cpp'
90--- tests/unittests/Printers/tst_printerjob.cpp 2017-01-25 15:37:42 +0000
91+++ tests/unittests/Printers/tst_printerjob.cpp 2017-01-26 16:21:27 +0000
92@@ -135,6 +135,34 @@
93 QCOMPARE(m_instance->getDuplexMode(), PrinterEnum::DuplexMode::DuplexLongSide);
94 }
95
96+ void testIsTwoSided()
97+ {
98+ QList<PrinterEnum::DuplexMode> modes = {
99+ PrinterEnum::DuplexMode::DuplexNone,
100+ PrinterEnum::DuplexMode::DuplexLongSide,
101+ PrinterEnum::DuplexMode::DuplexShortSide
102+ };
103+ ((MockPrinterBackend *) m_backend)->m_supportedDuplexModes = modes;
104+
105+ ((MockPrinterBackend *) m_backend)->m_defaultDuplexMode = PrinterEnum::DuplexMode::DuplexNone;
106+ refreshInstance();
107+ QCOMPARE(m_instance->duplexMode(), modes.indexOf(PrinterEnum::DuplexMode::DuplexNone));
108+ QCOMPARE(m_instance->getDuplexMode(), PrinterEnum::DuplexMode::DuplexNone);
109+ QCOMPARE(m_instance->isTwoSided(), false);
110+
111+ m_instance->setDuplexMode(modes.indexOf(PrinterEnum::DuplexMode::DuplexLongSide));
112+
113+ QCOMPARE(m_instance->duplexMode(), modes.indexOf(PrinterEnum::DuplexMode::DuplexLongSide));
114+ QCOMPARE(m_instance->getDuplexMode(), PrinterEnum::DuplexMode::DuplexLongSide);
115+ QCOMPARE(m_instance->isTwoSided(), true);
116+
117+ m_instance->setDuplexMode(modes.indexOf(PrinterEnum::DuplexMode::DuplexShortSide));
118+
119+ QCOMPARE(m_instance->duplexMode(), modes.indexOf(PrinterEnum::DuplexMode::DuplexShortSide));
120+ QCOMPARE(m_instance->getDuplexMode(), PrinterEnum::DuplexMode::DuplexShortSide);
121+ QCOMPARE(m_instance->isTwoSided(), true);
122+ }
123+
124 void testPrintFile()
125 {
126 QSKIP("Not implemented yet!");

Subscribers

People subscribed via source and target branches