summaryrefslogtreecommitdiffstats
path: root/src/printsupport
diff options
context:
space:
mode:
authorAlbert Astals Cid <albert.astals.cid@kdab.com>2017-12-21 16:37:14 +0100
committerAlbert Astals Cid <albert.astals.cid@kdab.com>2018-01-04 13:01:17 +0000
commit6efbd4381ade816515bbde59f9d31df0241e1340 (patch)
tree068e00efb6f06e3b59d4d9a6070151bc7741129b /src/printsupport
parent030d815eb8c5b6506178141da391594482c2e733 (diff)
CUPS: Fix advanced options cancel of the print properties dialog
When the user changes the advanced settings we call setProperty PDPK_PpdOption so if the user cancels we need to set them back to what they were originally Change-Id: Idd0cb413fb1e68dd28cf66f7f66f7e0afb38393e Reviewed-by: Michael Weghorn <m.weghorn@posteo.de> Reviewed-by: Kevin Ottens <kevin.ottens@kdab.com> Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
Diffstat (limited to 'src/printsupport')
-rw-r--r--src/printsupport/dialogs/qprintdialog_unix.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/printsupport/dialogs/qprintdialog_unix.cpp b/src/printsupport/dialogs/qprintdialog_unix.cpp
index a9745d72e2..3b1c492fca 100644
--- a/src/printsupport/dialogs/qprintdialog_unix.cpp
+++ b/src/printsupport/dialogs/qprintdialog_unix.cpp
@@ -139,6 +139,9 @@ public:
void showEvent(QShowEvent *event) override;
+private slots:
+ void reject() override;
+
private:
friend class QUnixPrintWidgetPrivate;
QPrinter *m_printer;
@@ -270,6 +273,7 @@ public:
}
int selected;
+ int originallySelected;
const char *selDescription;
};
@@ -289,6 +293,7 @@ public:
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
void setCupsOptionsFromItems(QPrinter *printer) const;
+ void reject();
QPrintDevice *currentPrintDevice() const;
QTextCodec *cupsCodec() const;
@@ -299,6 +304,7 @@ private:
void parseChoices(QOptionTreeItemOption *parent);
void setCupsOptionsFromItems(QPrinter *printer, QOptionTreeItem *parent) const;
+ void reject(QOptionTreeItem *item);
QPrintDevice *m_currentPrintDevice;
QTextCodec *m_cupsCodec;
@@ -399,6 +405,14 @@ void QPrintPropertiesDialog::showEvent(QShowEvent *event)
QDialog::showEvent(event);
}
+void QPrintPropertiesDialog::reject()
+{
+#if QT_CONFIG(cups)
+ m_cupsOptionsModel->reject();
+#endif
+ QDialog::reject();
+}
+
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
@@ -1297,6 +1311,7 @@ void QPPDOptionsModel::parseChoices(QOptionTreeItemOption *parent)
parent->selected = i;
parent->selDescription = option->choices[i].text;
}
+ parent->originallySelected = parent->selected;
parent->childItems.append(choice);
}
}
@@ -1316,6 +1331,27 @@ QVariant QPPDOptionsModel::headerData(int section, Qt::Orientation, int role) co
return QVariant();
}
+void QPPDOptionsModel::reject()
+{
+ reject(m_rootItem);
+}
+
+void QPPDOptionsModel::reject(QOptionTreeItem *item)
+{
+ if (item->type == QOptionTreeItem::Option) {
+ QOptionTreeItemOption *itemOption = static_cast<QOptionTreeItemOption *>(item);
+
+ const ppd_option_t *option = static_cast<const ppd_option_t*>(item->ptr);
+ const char *choice = itemOption->originallySelected != -1 ? option->choices[itemOption->originallySelected].choice
+ : option->defchoice;
+ const auto values = QStringList{} << QString::fromLatin1(option->keyword) << QString::fromLatin1(choice);
+ m_currentPrintDevice->setProperty(PDPK_PpdOption, values);
+ }
+
+ for (QOptionTreeItem *child : qAsConst(item->childItems))
+ reject(child);
+}
+
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////