Commit Graph

61 Commits

Author SHA1 Message Date
Kai Köhne dc82c835ef documentviewer: Add linking to imageviewer plugin
Pick-to: 6.10
Change-Id: Icaaaa6e39ff0da8bc041f117ccf524ebc9cae78a
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2025-07-29 15:06:15 +02:00
Kai Köhne 36ab8aafb0 documentviewer: Fix documentviewer_de.ts file
0ef5057f45 did remove the local project() for
app/CMakeLists.txt. As a side-effect, update_translations
now did search _all_ source files in the project for translatable
strings, including the plugin directory.

Avoid this by being explicit about the SOURCE_TARGETS.

Pick-to: 6.10
Change-Id: I0fad07b5aa8a89dfe8475faafc8c88acf55433cf
Reviewed-by: Masoud Jami <masoud.jami@qt.io>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2025-07-16 12:50:04 +02:00
Kai Köhne e31802fb15 documentviewer: Fix deployment for macOS, Windows, Linux
Adapt the logic to install and detect especially the
plugins libs:

* Do not just compile them into the app build folder, but
  keep the libs separate under the 'plugins' direcory
* At installation time, follow the logic of *deployqt
  for Qt plugins, and store them in CMAKE_INSTALL_PREFIX/plugins
  (Linux, Windows) or Document Viewer.app/Contents/Plugins
  (macOS).

Unfortunately, this all requires different look ups at runtime for
all operating systems. For macOS and Windows, we furthermore need
to check both for valid paths with an installed build, and an
un-installed build.

While at it, move the install logic to app/CMakeLists.txt, so that
there is less repetition.

An alternative approach would be to calculate the relative paths
at configure time, and either pass on command line or in a created
header file. Anyhow, the current approach is more compact.

Pick-to: 6.10
Fixes: QTBUG-138476
Change-Id: I467d3bd4e14ef6b8b747bceb7177837e2edd3b8c
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2025-07-15 16:49:02 +02:00
Kai Köhne a5deebcd48 documentviewer: Provide macOS bundle metadata
Name the bundle 'Document Viewer.app', and provide more
metadata for the Info.plist file.

Pick-to: 6.10
Change-Id: I4de88c1b272477b67c645a682b756d6b134a5a19
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2025-07-11 20:03:25 +02:00
Kai Köhne a825ec0103 documentviewer: Structure app/CMakeLists.txt file
Clearly separate the parts dealing with the abstractviewer,
documentviewer targets, as well as the installation step.

Pick-to: 6.10
Change-Id: Ia824d7ca10d9a3810a185578c48b2bacc8fe3394
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2025-07-11 20:03:08 +02:00
Kai Köhne a1ca013bb6 documentviewer: Clean up used Qt modules
We don't use svg's anymore in the example. Also, the official place
to look for qt_add_translations is Qt6LinguistTools, not Qt6Linguist.

Pick-to: 6.10
Change-Id: I5a4d8e9af739b2e8cb14e69a84f4127e520b3a50
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2025-07-10 14:21:21 +02:00
Kai Köhne 0ef5057f45 documentviewer: Centralize projects
The included CMakeLists.txt files are _not_ standalone projects,
so remove any project() as well as duplicated find_package() calls.

Pick-to: 6.10
Change-Id: Ia56128e19588d38eb3c91fac7e9a188f82146515
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2025-07-10 12:21:13 +00:00
Kai Köhne d2c0a7f76c documentviewer: Set include directory for abstractviewer target
This is a cleaner approach then manually tweaking the dependent targets
include directories.

Pick-to: 6.10
Change-Id: I8382f5556c950398e8a553a77f380922ed14ae9b
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2025-07-10 14:21:06 +02:00
Kai Köhne 8f3d743da9 documentviewer: Clean up use of printsupport macro
* Do not use the QT_ prefix, as that is reserved for Qt itself,
  not client code (which an example is).
* Do not define the define on a global level, but as a PUBLIC
  target definition for the abstractviewer library.

Pick-to: 6.10
Change-Id: I01a001b0c0706e9f951118472fe1a62ff68a2e4e
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2025-07-10 14:20:55 +02:00
Kai Köhne e8ab457dd6 documentviewer: Don't translate object names
Pick-to: 6.10
Change-Id: I8d5639ceadb500f95266f5efdbab78ca4660ffcf
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2025-07-09 16:15:01 +02:00
Kai Köhne 3ab0520c28 documentviewer: Remove unused AbstractViewer::fileMenu()
Pick-to: 6.10
Change-Id: Ia610b43d1dec7ea1cb2061eabbf234dd7aa5b436
Reviewed-by: Masoud Jami <masoud.jami@qt.io>
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2025-07-09 15:50:07 +02:00
Kai Köhne 44d7c2b25c documentviewer: Fix plugin translation when switching languages
When switching languages in the UI, plugin texts were not correctly
translated because only the main window translator was updated with
the new language. Plugin translators kept their original language.

Fixes: QTBUG-138344
Pick-to: 6.10
Change-Id: Ie1d2e7947b9125b1889d40ed4e6e1c8adff21249
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Reviewed-by: Masoud Jami <masoud.jami@qt.io>
2025-07-09 15:28:34 +02:00
Kai Köhne a840679625 documentviewer: Improve main menu
* Use 'Exit' instead of 'Quit'. This is more common on Windows,
  and on macOS we adapt to the system menu, anyhow.
* Use Keyboard shortcuts where it makes sense.

Pick-to: 6.10
Change-Id: Ied972bccef685b97cd01ca3fa41c7e6507eda041
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2025-07-09 14:29:57 +02:00
Kai Köhne f7bda9f2fa documentviewer: Remove search functionality for JSON
The toolbar was broken in that the pixmap path to magnifier.png was
wrong. With the path enabled, the magnifier looked alien between the
other icons that are retrieved from the system style.

While this could be fixed easily, the acutal search functionality
would've required much more work. As is, the search via
QTV::keybardSearch() is quite limited:
* Only the first columns with the JSON keys are searched
* The text is matched only to the beginning of the column
  text, you cannot search for texts in between or at the end of the
  key.
* Only expanded rows are searched.

All in all, this makes the search appear rather broken. Let's just
remove it.

Pick-to: 6.10
Change-Id: Ie58b88e2ff6327d703094f108eab94b083012e16
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2025-07-09 14:29:47 +02:00
Kai Köhne 6b79faa1e6 documentviewer: Fix crash when switching language
If you switch languages before any file has been opened,
the example did crash.

Pick-to: 6.10
Change-Id: Ib4675b428026a3c12c165a4b458de2c527cd1fbd
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2025-07-07 13:43:44 +02:00
Masoud Jami 1c322a834c documentviewer demo: Fix SVG warnings
This patch replaces the SVG icons with Qt minimalistic icons and
resolves the warnings about the non-supported SVG properties.

Fixes: QTBUG-138169
Pick-to: 6.10 6.9 6.8
Change-Id: Ib290c15d1498945149ba4425062268619bfe2a33
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2025-07-07 13:43:36 +02:00
Morten Sørvig 5eaaee105a Don't use static QLocale instance
Avoid creating and initializing the QLocale instance
in a global constructor. This is generally not recommended
for non-constinit types, and additionally causes a crash
on WebAssembly in the QLocale backend implementation.

Pick-to: 6.10
Change-Id: I720c60bf89d39434022f61e8d71de7b4e8610d8e
Reviewed-by: Masoud Jami <masoud.jami@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Piotr Wierciński <piotr.wiercinski@qt.io>
2025-07-03 16:15:42 +02:00
Friedemann Kleint a810615dd0 documentviewer demo: Fix resource warnings
Reverts the removal of set(CMAKE_AUTORCC ON) by
600dfd439f, fixing:

qt.svg: Cannot open file ':/demos/documentviewer/images/go-next.svgz'

Pick-to: 6.10 6.9 6.8
Fixes: QTBUG-138169
Change-Id: I11615ebee7ee4aa54e473aec0a2f9a15ab664ef2
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2025-07-02 22:49:12 +02:00
Kai Köhne 8ccc066721 documentviewer: Simplify qt_add_translation setup
* Define i18n languages centrally
* Use canonical :/i18n directory (default)

Change-Id: I7e8d9c57512418c51843464622ec270dea1b3456
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2025-05-15 09:50:55 +02:00
Masoud Jami b743a98270 qtdoc: Extend documentviewer demo to use translations
This patch extends the documentviewer demo to use
text based translation for English and German, as follows:

- Add AbstractView::addTranslation(fileName) for inheriting
  plugin classes to optionally load own translations.

- Implement runtime translation switching. Provide option for
  plugins to benefit, if they implement their own runtime
  switching functionality.

Task-number: QTBUG-71856
Change-Id: Ic7782b7fa38d1121b140351f5eaa88ac027a6bcd
Reviewed-by: Kai Köhne <kai.koehne@qt.io>
2025-05-15 09:50:51 +02:00
Masoud Jami 600dfd439f qtdoc: Fix loading svg icons and txtviewer plugin in documentviewer demo
Apply a couple of fixes to load icons correctly and preventing seg fault
in loading txt files in the documentviewer demo.

Change-Id: I5c3e8694abe37140d73da8b40204bc05aaf37e9c
Pick-to: 6.9 6.8
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2025-04-23 10:54:29 +00:00
Alexey Edelev d6e636b7a1 Use the correct Q3Dviewer target name when adding dependencies
Task-number: QTBUG-129080
Pick-to: 6.8 6.7
Change-Id: I15bb5b63612ba81f13813508497d533823672b7d
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2024-09-18 17:02:49 +02:00
Axel Spoerl 94548822fe Documentviewer: Handle absence of QtQuick3D.AssetUtils
The documentviewer demo assumed, that Quick3D always comes with
AssetUtils installed. It attempted to create a RuntimeLoader instance
and asserted the result. This lead to a crash, when case AssetUtils were
not installed.

Don't assert, when no RuntimeLoader object can be instantiated. Return
an empty list of MIME types instead. Ignore plugins that don't support
any MIME types.

Fixes: QTBUG-128673
Pick-to: 6.8 6.8.0 6.7
Change-Id: Ib4771ba93dac2e0aab3a89b7e3cd7e64c97e4e5d
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2024-09-18 13:55:31 +02:00
Axel Spoerl 7f9ff2d5cf Documentviewer demo: Exit application when no plugins were found
When building viewer plugins failed, the application could still be
launched and documents opened. This would crash the application with
a nullptr dereference.

Print a qWarning and exit application in MainWindow c'tor, when no
plugins were found.

Fixes: QTBUG-122041
Pick-to: 6.7 6.8
Change-Id: I92cd1678fdc3f88edc0f35347bd15c3e7c43f122
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2024-08-30 10:02:58 +00:00
Alexandru Croitor cde9cfb96c CMake: Add deployment API to our examples
Projects were modified using the tool at:
https://git.qt.io/alcroito/cmake_refactor

Some examples had to be adapted manually, mostly those that build
additional qml modules / plugins.

documentviewer did not get the deployment api, because it's trickier.

Pick-to: 6.7
Task-number: QTBUG-101340
Task-number: QTBUG-102056
Task-number: QTBUG-102057
Change-Id: I76322185fc824c112d77e077ee39e7ccbc193a4c
Reviewed-by:  Alexey Edelev <alexey.edelev@qt.io>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2024-05-13 09:44:04 +02:00
Axel Spoerl 59c784dff2 Documentviewer demo: Reset AbstractView::m_printingEnabled in cleanup
m_printingEnabled wasn't reset in AbstractViewer::cleanup().
That prevented the printingEnabledChanged() signal from being fired,
when a viewer displayed a printable document from the 2nd time onward.

Always disable printing in the cleanup() method.

Fixes: QTBUG-125057
Pick-to: 6.7
Change-Id: I7d237a27a3547103ef0ce099a0735b2444bc0248
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2024-05-08 09:45:55 +02:00
Axel Spoerl 1857297f60 Documentviewer demo: Disconnect print related connections
The documentviewer demo re-uses its viewer plugins. It connects its
print button to the viewers' print functionalities, without keeping
track of the connections. That leads to double connects and crashes.

Store relevant connections in an array and disconnect them.

Fixes: QTBUG-121940
Pick-to: 6.7
Change-Id: Ifcef2097d874d6d37c7891bafc1805264282e984
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2024-02-15 09:39:58 +01:00
Axel Spoerl 57b2d37b47 Documentviewer: Add q3dviewer as a conditional plugin target
q3dviewer was missing as a plugin target in the example's
CMakeLists.txt.

Pick-to: 6.7 6.6
Change-Id: I1ec6791198551c45cbc1e2efaf4c7d2fd8792bcd
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2024-01-09 22:56:02 +00:00
Samuli Piippo f80bee1a42 documentviewer: fix deployment of abstractviewer library
Amend ba61af0bf3 and install the
abstractviewer library so that demo works after being deployed.

Pick-to: 6.7 6.6
Change-Id: I481b1d655d5666e11eef4d4aee99359750913750
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2024-01-08 17:14:44 +02:00
Axel Spoerl 0e35a8eaf1 Plugin documentation: Refer to Document Viewer Demo
Update code snippets to use JsonViewer as an example.
Add a section about loading plugins.

Task-number: QTBUG-119981
Pick-to: 6.7
Change-Id: Ied3dcba02ad275d16535ab015c49ce03ec0a0e30
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
2023-12-20 11:28:58 +01:00
Axel Spoerl eea2929d84 Documentviewer: Make AbstractViewer shared/static, depending on build
Make the abstract viewer class static if the build is static, shared
otherwise.

Fixes: QTBUG-118754
Fixes: QTBUG-118672
Pick-to: 6.6
Change-Id: Ic98c932b6c91242e79b022a38653f434b108330d
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2023-11-23 14:29:03 +01:00
Axel Spoerl 504e818821 Documentviewer demo: Add quick3d plugin
Add a plugin to show 3d files in QtQuick3D.

Change-Id: I0dcb51f0508a8f677a39f31cdb50f13890a635e5
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-11-02 14:10:25 +00:00
Axel Spoerl 459e09b485 Documentviewer demo: Centralize disconnect
Viewer plugins may connect to the central back/forward buttons.
If they disconnect those explicitly in their cleanup methods, the
buttons are nullptr when the application is closed. This lead to a
warning.

Save the QMetaObject::Connection object in a list in Abstractviewer
and directly disconnect it from AbstractViewer::cleanup. That way,
QObject::disconnect is never called with a nullptr argument.

Amends 1f6505a0cf.

Pick-to: 6.6
Change-Id: I4fee76d507f3329fef31e6c9171694ea82914239
Reviewed-by: Santhosh Kumar <santhosh.kumar.selvaraj@qt.io>
2023-10-20 10:39:09 +02:00
Axel Spoerl 16d096709f Documentviewer demo: Darwin fixes
Remove definitions of onActionOpenTriggered() and
onActionQuitTriggered(), the implementation of which has been removed.

Change the required binary directory from "macOS" to "MacOS", to find
plugins correctly.

Fixes: QTBUG-117694
Pick-to: 6.6
Change-Id: Iba7d7c07e2881d2e8c4dce4b58f34a6441e8b467
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2023-10-04 15:26:39 +02:00
Axel Spoerl f906b6f0e6 Documentviewer Demo: fix plugin search on Windows
The plugin dlls are located in the "app" subdirectory of the
executable's path.

Search there.

Fixes: QTBUG-117691
Pick-to: 6.6 6.6.0
Change-Id: I467e90344e0a85384e8e06393fe41a98f1904bfc
Reviewed-by: Jani Heikkinen <jani.heikkinen@qt.io>
2023-10-02 07:01:58 +00:00
Friedemann Kleint 17e7109f01 Examples: Use consistent organization names and settings paths
Set the organization name to "QtProject".
Set an application name to Hangman to be used by QSettings.
Remove unused QSettings instance from Thermostat.
Let QSettings in Document Viewer use defaults.

Pick-to: 6.6
Change-Id: I8ebaeb444cd18bab95424f0efea670b02d41e657
Reviewed-by: Kai Köhne <kai.koehne@qt.io>
2023-07-04 13:43:26 +00:00
Friedemann Kleint 9c7d96e376 DocumentViewer demo: Remove OpenMode from class RecentFiles
A document viewer typically uses read-only.

Pick-to: 6.6
Change-Id: Ic5a601c0b5af9d0e97a47368d71e8daa9e5e0244
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2023-07-03 16:10:36 +02:00
Friedemann Kleint 07fbbb3bec DocumentViewer demo: Streamline enumerations of class RecentFiles
Remove unused values and introduce Other for a number of RemoveReasons.

Pick-to: 6.6
Change-Id: I6ea170cac0dc04d0b5d9326441be5519ad544ba0
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2023-07-03 16:10:36 +02:00
Friedemann Kleint 7f3ffeee2f DocumentViewer demo: Remove unused signals of class RecentFiles
Pick-to: 6.6
Change-Id: I28c634948b802454e523409d60eafce7e8b9ed20
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2023-07-03 16:10:36 +02:00
Friedemann Kleint d19a179e75 DocumentViewer demo: Remove unused variables
Pick-to: 6.6
Change-Id: I4d94bb8126749468fb28daa593390f1da0da6a7c
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2023-07-03 16:10:36 +02:00
Friedemann Kleint 2378671318 DocumentViewer demo: Do not derive class RecentFiles from QStringList
Inheriting containers is considered bad practice and also not
possible in Python.

As a drive-by, change the loop removing dangling files and duplicates
from range based for to index-based, as actually removing a file
would invalidate end().

Pick-to: 6.6
Change-Id: I826aebe1000d412d94e63a0564db7485b9550ca5
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2023-07-03 16:10:36 +02:00
Friedemann Kleint 01505ae868 DocumentViewer demo: Remove unused <concepts> include
MSVC is complaining about it.

Pick-to: 6.6
Change-Id: Ifd85c48971cef5b62fbac4d1d5901a066c8d511c
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2023-06-29 14:01:59 +02:00
Friedemann Kleint 96fadad46a DocumentViewer demo: Introduce a .qrc file
Add a .qrc file, which can be browsed in Qt Creator.
Remove the hard-coded build paths from the .ui file, which prevents
it from being used for Qt for Python.

Pick-to: 6.6
Task-number: PYSIDE-2206
Change-Id: I4ed7de87c79c964da1d0adaa9330fbab137de1e8
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2023-06-27 15:17:22 +02:00
Axel Spoerl 5682c13aa8 DocumentViewer demo: Replace connect-by-name with explicit connect
Replace autoconnections with old_style_slot_names by explicit connect
statements with camelStyle.

Pick-to: 6.6
Change-Id: I1e1ddee064ee183c4baba3253c69eae7931ad459
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
2023-06-21 21:41:59 +02:00
Friedemann Kleint 6536439d44 DocumentViewer demo: Use modern string literals
This unearthes that JSON should convert from UTF-8.

Pick-to: 6.6
Change-Id: If155b745cac0579232b927a3988588204c31d207
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2023-06-21 15:04:51 +02:00
Friedemann Kleint 818c4b6468 DocumentViewer demo: Improve file dialog handling
Loop in the open dialog until opening the file
succeeds so that the directory is not reset.

Set a suffix for saving.

Pick-to: 6.6
Change-Id: Ic5a83d13148cfc16e5605abed7a2d965b6a6d149
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2023-06-20 16:05:10 +02:00
Friedemann Kleint a212b57f25 DocumentViewer demo: Fix tr() usage
Try to avoid concatenating translated texts and parameters; this may
not work in all languages. Use QDir::toNativeSeparators() for file
names.

Pick-to: 6.6
Change-Id: I00c058a91cab04c04580045229350ba3d9951d5e
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2023-06-20 16:04:37 +02:00
Friedemann Kleint e00a8ad305 DocumentViewer demo: Reorder includes
Remove unused forward declarations and includes; reorder by module.

Pick-to: 6.6
Change-Id: Id9468d1fdb2685df44f2b4a9407c6b12ac2859f3
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2023-06-20 16:04:26 +02:00
Friedemann Kleint c35c18ff2c DocumentViewer demo: Some modernization
Pick-to: 6.6
Change-Id: I2169e8a109f30b6e4f18a4e2bce9d529c0096a5a
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2023-06-20 14:53:55 +02:00
Axel Spoerl 01b7e2d091 DocumentViewer demo: Make plugins re-usable
The DocumentViewer demo was originally developed as a self-contained
application. Its dependency to PdfWidgets has lead to splitting it up
into plugins: ba61af0bf3

The new architecture re-uses the viewer objects, but it doesn't reset
them properly. This is why viewer-specific UI-assets (menus, toolbars
and buttons) get duplicated.

This patch adds cleanup functionality and removes duplications.

Fixes: QTBUG-114615
Fixes: QTBUG-114617
Pick-to: 6.6
Change-Id: I4f123f8a69be978f992531603b15de71069d5a66
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2023-06-20 09:18:32 +02:00