diff options
author | Marc Mutz <marc.mutz@qt.io> | 2023-08-14 16:28:34 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2023-08-23 17:00:41 +0200 |
commit | 8b20e0636a89dc3e6b06d174286ee16aa427887a (patch) | |
tree | 2a189ba753932d2f0775f8ef808b634df1cc4a06 /src/core/web_contents_adapter.cpp | |
parent | 4fd60a8f7477ba56ac603d89aaffb6e3967d14b3 (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.
Pick-to: 6.6
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>
Diffstat (limited to 'src/core/web_contents_adapter.cpp')
0 files changed, 0 insertions, 0 deletions