From 6efbd4381ade816515bbde59f9d31df0241e1340 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Thu, 21 Dec 2017 16:37:14 +0100 Subject: [PATCH] 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 Reviewed-by: Kevin Ottens Reviewed-by: Frederik Gladhorn --- src/printsupport/dialogs/qprintdialog_unix.cpp | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/printsupport/dialogs/qprintdialog_unix.cpp b/src/printsupport/dialogs/qprintdialog_unix.cpp index a9745d7..3b1c492 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(item); + + const ppd_option_t *option = static_cast(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); +} + //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// -- 2.7.4