summaryrefslogtreecommitdiffstats
path: root/examples
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 /examples
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 'examples')
-rw-r--r--examples/pdfwidgets/pdfviewer/mainwindow.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/examples/pdfwidgets/pdfviewer/mainwindow.cpp b/examples/pdfwidgets/pdfviewer/mainwindow.cpp
index 5c4554ca2..ce19359fc 100644
--- a/examples/pdfwidgets/pdfviewer/mainwindow.cpp
+++ b/examples/pdfwidgets/pdfviewer/mainwindow.cpp
@@ -38,10 +38,10 @@ MainWindow::MainWindow(QWidget *parent)
ui->mainToolBar->insertWidget(ui->actionZoom_In, m_zoomSelector);
ui->mainToolBar->insertWidget(ui->actionForward, m_pageSelector);
- connect(m_pageSelector, &QPdfPageSelector::valueChanged, this, &MainWindow::pageSelected);
+ connect(m_pageSelector, &QPdfPageSelector::currentPageChanged, this, &MainWindow::pageSelected);
m_pageSelector->setDocument(m_document);
auto nav = ui->pdfView->pageNavigator();
- connect(nav, &QPdfPageNavigator::currentPageChanged, m_pageSelector, &QPdfPageSelector::setValue);
+ connect(nav, &QPdfPageNavigator::currentPageChanged, m_pageSelector, &QPdfPageSelector::setCurrentPage);
connect(nav, &QPdfPageNavigator::backAvailableChanged, ui->actionBack, &QAction::setEnabled);
connect(nav, &QPdfPageNavigator::forwardAvailableChanged, ui->actionForward, &QAction::setEnabled);
@@ -116,7 +116,7 @@ void MainWindow::pageSelected(int page)
setWindowTitle(!documentTitle.isEmpty() ? documentTitle : QStringLiteral("PDF Viewer"));
setWindowTitle(tr("%1: page %2 (%3 of %4)")
.arg(documentTitle.isEmpty() ? u"PDF Viewer"_qs : documentTitle,
- m_pageSelector->text(), QString::number(page + 1), QString::number(m_document->pageCount())));
+ m_pageSelector->currentPageLabel(), QString::number(page + 1), QString::number(m_document->pageCount())));
}
void MainWindow::searchResultSelected(const QModelIndex &current, const QModelIndex &previous)