From e5e4873576fa89f11e19ee568e3969fc3a4a03a7 Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Thu, 1 May 2025 21:59:51 +0200 Subject: [PATCH] tdf#130857 qt: Let QtAccessibleWidget subclass QObject This will allow to pass it in a QVariant, which will be used to support custom accessible implementations for QtInstanceDrawingArea in QtInstanceBuilder::weld_drawing_area in an upcoming commit. At least the Qt 5 moc does not process Qt version checks like #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) which would result in failures like In file included from /home/michi/development/git/libreoffice/vcl/qt5/QtAccessibleWidget.cxx:21: /home/michi/development/git/libreoffice/workdir/CustomTarget/vcl/qt5/QtAccessibleWidget.moc:91:29: error: unknown type name 'QAccessibleAttributesInterface'; did you mean 'QAccessibleActionInterface'? 91 | return static_cast< QAccessibleAttributesInterface*>(this); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | QAccessibleActionInterface /usr/include/x86_64-linux-gnu/qt5/QtGui/qaccessible.h:627:20: note: 'QAccessibleActionInterface' declared here 627 | class Q_GUI_EXPORT QAccessibleActionInterface | ^ In file included from /home/michi/development/git/libreoffice/vcl/qt5/QtAccessibleWidget.cxx:21: /home/michi/development/git/libreoffice/workdir/CustomTarget/vcl/qt5/QtAccessibleWidget.moc:97:29: error: unknown type name 'QAccessibleSelectionInterface'; did you mean 'QAccessibleActionInterface'? 97 | return static_cast< QAccessibleSelectionInterface*>(this); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | QAccessibleActionInterface /usr/include/x86_64-linux-gnu/qt5/QtGui/qaccessible.h:627:20: note: 'QAccessibleActionInterface' declared here 627 | class Q_GUI_EXPORT QAccessibleActionInterface | ^ 2 errors generated. Explicitly exclude the Qt >= 6.x specific code in the header from the moc run by making it conditional on #ifndef Q_MOC_RUN to make that work. Change-Id: I1ea3c37d0041dac89d632970d810ae951ff4afbb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184876 Tested-by: Jenkins Reviewed-by: Michael Weghorn --- vcl/CustomTarget_qt5_moc.mk | 1 + vcl/CustomTarget_qt6_moc.mk | 1 + vcl/inc/qt5/QtAccessibleWidget.hxx | 11 ++++++++++- vcl/qt5/QtAccessibleWidget.cxx | 1 + 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/vcl/CustomTarget_qt5_moc.mk b/vcl/CustomTarget_qt5_moc.mk index 7e04d5756fbc..4a10cfd2b0f5 100644 --- a/vcl/CustomTarget_qt5_moc.mk +++ b/vcl/CustomTarget_qt5_moc.mk @@ -10,6 +10,7 @@ $(eval $(call gb_CustomTarget_CustomTarget,vcl/qt5)) $(call gb_CustomTarget_get_target,vcl/qt5) : \ + $(gb_CustomTarget_workdir)/vcl/qt5/QtAccessibleWidget.moc \ $(gb_CustomTarget_workdir)/vcl/qt5/QtClipboard.moc \ $(gb_CustomTarget_workdir)/vcl/qt5/QtDoubleSpinBox.moc \ $(gb_CustomTarget_workdir)/vcl/qt5/QtExpander.moc \ diff --git a/vcl/CustomTarget_qt6_moc.mk b/vcl/CustomTarget_qt6_moc.mk index 79b203ea70a1..9dee1cbb298e 100644 --- a/vcl/CustomTarget_qt6_moc.mk +++ b/vcl/CustomTarget_qt6_moc.mk @@ -10,6 +10,7 @@ $(eval $(call gb_CustomTarget_CustomTarget,vcl/qt6)) $(call gb_CustomTarget_get_target,vcl/qt6) : \ + $(gb_CustomTarget_workdir)/vcl/qt6/QtAccessibleWidget.moc \ $(gb_CustomTarget_workdir)/vcl/qt6/QtClipboard.moc \ $(gb_CustomTarget_workdir)/vcl/qt6/QtDoubleSpinBox.moc \ $(gb_CustomTarget_workdir)/vcl/qt6/QtExpander.moc \ diff --git a/vcl/inc/qt5/QtAccessibleWidget.hxx b/vcl/inc/qt5/QtAccessibleWidget.hxx index c02411ba2556..bc1ab406fe70 100644 --- a/vcl/inc/qt5/QtAccessibleWidget.hxx +++ b/vcl/inc/qt5/QtAccessibleWidget.hxx @@ -36,20 +36,27 @@ class XAccessibleTable; class QtFrame; class QtWidget; -class QtAccessibleWidget final : public QAccessibleInterface, +class QtAccessibleWidget final : public QObject, + public QAccessibleInterface, public QAccessibleActionInterface, +#ifndef Q_MOC_RUN #if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) public QAccessibleAttributesInterface, +#endif #endif public QAccessibleTextInterface, public QAccessibleEditableTextInterface, +#ifndef Q_MOC_RUN #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) public QAccessibleSelectionInterface, +#endif #endif public QAccessibleTableCellInterface, public QAccessibleTableInterface, public QAccessibleValueInterface { + Q_OBJECT + public: QtAccessibleWidget(const css::uno::Reference& xAccessible, QObject* pObject); @@ -88,6 +95,7 @@ public: void doAction(const QString& actionName) override; QStringList keyBindingsForAction(const QString& actionName) const override; +#ifndef Q_MOC_RUN #if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) // helper method for QAccessibleAttributesInterface QHash attributes() const; @@ -95,6 +103,7 @@ public: // QAccessibleAttributesInterface QList attributeKeys() const override; QVariant attributeValue(QAccessible::Attribute key) const override; +#endif #endif // QAccessibleTextInterface diff --git a/vcl/qt5/QtAccessibleWidget.cxx b/vcl/qt5/QtAccessibleWidget.cxx index 03feffda5794..d5febb36aaeb 100644 --- a/vcl/qt5/QtAccessibleWidget.cxx +++ b/vcl/qt5/QtAccessibleWidget.cxx @@ -18,6 +18,7 @@ */ #include +#include #include