summaryrefslogtreecommitdiffstats
path: root/src/pdfwidgets/qpdfpageselector.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2023-08-14 16:28:34 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-08-23 19:48:25 +0000
commitd8ed05127056dd0dfeb0d9617bcbe0c29e3e8d8e (patch)
tree174bba95ab37720cefb957fbc69c909fe806fa3e /src/pdfwidgets/qpdfpageselector.h
parent9c07d9f6eb10977058d7e7e5901be9e78920a0ff (diff)
QPdfPageSelector: port from is-a to has-a QSpinBox
Yes, the class needs to inherit from QSpinBox in order to override the protected virtuals, but that doesn't mean a QPdfPageSelector should model is-a QSpinBox. E.g. the range of the QPdfPageSelector is taken from the QPdfDocument, and no good can come from a user changing it through the use of QSpinBox API, esp. if one thinks about the class being displayed as a native widget in QtDesigner. In a similar vein, the inheritance from QSpinBox leaves users wondering (and the docs didn't do anything to enlighten them) what properties are pertinent to the task at hand. setValue() to set the page index is ... meh, but still somewhat discoverable. But that text() is only QPdfDocument::pageLabel() if no affixes are set takes quite some digging. Part of this could be fixed by providing domain-specific properties like currentPage for value, but that would just increase the confusion, because those two properties would must needs exist on the same object. Instead, fix by moving the old QPdfPageSelector as QPdfPageSelectorSpinBox into qpdfpageselector_p.h, removing its pimpl and having QPdfPageSelector inherit QWidget instead, aggregating a QPdfPageSelectorSpinBox. This involves a few more objects (the widget, the layout), but gives QPdfPageSelector full control over its interface. Add a few salient properties (more can be added if needed, by copying them from QSpinBox or QAbstractSpinBox). Note how well the new API rhymes with QPdfPageNavigator in the connect() in pdfviewer example's MainWindow. Since we still store everything in QPdfPageSelectorSpinBox, but don't pimpl it anymore, QPdfPageSelectorPrivate can lose the q_ptr now, and merely contains the pointer to its QPdfPageSelectorSpinBox. This could be optimized further, by making QPdfPageSelectorSpinBox and QPdfPageSelectorPrivate the same class, but that's neither BC- nor SC-relevant anymore, and can be done later (or never, seeing as this widget is unlikely to be used more than a few times per application). Found in API-review. As a drive-by, port to the std-compatible subset of the QPointer API. Change-Id: I0d82d098d38d5f2fcf7f1c8c9aed6e792a8deb2d Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> (cherry picked from commit 8b20e0636a89dc3e6b06d174286ee16aa427887a) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/pdfwidgets/qpdfpageselector.h')
-rw-r--r--src/pdfwidgets/qpdfpageselector.h21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/pdfwidgets/qpdfpageselector.h b/src/pdfwidgets/qpdfpageselector.h
index a2036be21..d779f54cd 100644
--- a/src/pdfwidgets/qpdfpageselector.h
+++ b/src/pdfwidgets/qpdfpageselector.h
@@ -5,7 +5,8 @@
#define QPDFPAGESELECTOR_H
#include <QtPdfWidgets/qtpdfwidgetsglobal.h>
-#include <QtWidgets/qspinbox.h>
+
+#include <QtWidgets/qwidget.h>
#include <memory>
@@ -14,12 +15,13 @@ QT_BEGIN_NAMESPACE
class QPdfDocument;
class QPdfPageSelectorPrivate;
-class Q_PDF_WIDGETS_EXPORT QPdfPageSelector : public QSpinBox
+class Q_PDF_WIDGETS_EXPORT QPdfPageSelector : public QWidget
{
Q_OBJECT
Q_PROPERTY(QPdfDocument* document READ document WRITE setDocument NOTIFY documentChanged)
-
+ Q_PROPERTY(int currentPage READ currentPage WRITE setCurrentPage NOTIFY currentPageChanged USER true)
+ Q_PROPERTY(QString currentPageLabel READ currentPageLabel NOTIFY currentPageLabelChanged)
public:
QPdfPageSelector() : QPdfPageSelector(nullptr) {}
explicit QPdfPageSelector(QWidget *parent);
@@ -28,13 +30,16 @@ public:
void setDocument(QPdfDocument *document);
QPdfDocument *document() const;
+ int currentPage() const;
+ QString currentPageLabel() const;
+
+public Q_SLOTS:
+ void setCurrentPage(int index);
+
Q_SIGNALS:
void documentChanged(QPdfDocument *document);
-
-protected:
- int valueFromText(const QString &text) const override;
- QString textFromValue(int value) const override;
- QValidator::State validate(QString &text, int &pos) const override;
+ void currentPageChanged(int index);
+ void currentPageLabelChanged(const QString &label);
private:
Q_DECLARE_PRIVATE(QPdfPageSelector)