vcl/CustomTarget_qt5_moc.mk | 1 + vcl/CustomTarget_qt6_moc.mk | 1 + vcl/inc/qt5/QtTransferable.hxx | 2 ++ vcl/qt5/QtClipboard.cxx | 4 ++-- vcl/qt5/QtFrame.cxx | 6 +++--- vcl/qt5/QtInstanceMessageDialog.cxx | 2 +- vcl/qt5/QtTransferable.cxx | 1 + vcl/qt5/QtWidget.cxx | 2 +- 8 files changed, 12 insertions(+), 7 deletions(-)
New commits: commit 4722174f2132b1f0d29ab491d687fee6274d216f Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Thu Sep 19 11:13:24 2024 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Thu Sep 19 15:36:49 2024 +0200 qt: Use more qobject_cast instead of dynamic_cast Change-Id: I236d016dd51f219b63a7d7fb6b0cb83a06b960c6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173661 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/vcl/qt5/QtFrame.cxx b/vcl/qt5/QtFrame.cxx index 4b2ffe26e506..52fe03543c9a 100644 --- a/vcl/qt5/QtFrame.cxx +++ b/vcl/qt5/QtFrame.cxx @@ -1551,7 +1551,7 @@ void QtFrame::handleDrop(QDropEvent* pEvent) // inform the drag source of the drag-origin frame of the drop result if (pEvent->source()) { - QtWidget* pWidget = dynamic_cast<QtWidget*>(pEvent->source()); + QtWidget* pWidget = qobject_cast<QtWidget*>(pEvent->source()); assert(pWidget); // AFAIK there shouldn't be any non-Qt5Widget as source in LO itself if (pWidget) pWidget->frame().m_pDragSource->fire_dragEnd(nDropAction, bDropSuccessful); diff --git a/vcl/qt5/QtInstanceMessageDialog.cxx b/vcl/qt5/QtInstanceMessageDialog.cxx index 76903fc5c63c..7b17c106fa65 100644 --- a/vcl/qt5/QtInstanceMessageDialog.cxx +++ b/vcl/qt5/QtInstanceMessageDialog.cxx @@ -263,7 +263,7 @@ QPushButton* QtInstanceMessageDialog::buttonForResponseCode(int nResponse) { if (pAbstractButton->property(PROPERTY_VCL_RESPONSE_CODE).toInt() == nResponse) { - QPushButton* pButton = dynamic_cast<QPushButton*>(pAbstractButton); + QPushButton* pButton = qobject_cast<QPushButton*>(pAbstractButton); assert(pButton); return pButton; } commit be113bcfef5a411af43bcbcc7e51fc959eb4bcae Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Thu Sep 19 11:02:48 2024 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Thu Sep 19 15:36:41 2024 +0200 qt: Use qobject_cast to cast to QtMimeData Use `qobject_cast` instead of `dynamic_cast` to cast to QtMimeData. Add the `Q_OBJECT` macro to the class, as the the qobject_cast doc [1] says: > Warning: If T isn't declared with the Q_OBJECT macro, this function's > return value is undefined. Change-Id: I5de2d8dbf62ed1293f3660acae44e3b13ab5df71 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173660 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/vcl/CustomTarget_qt5_moc.mk b/vcl/CustomTarget_qt5_moc.mk index 466767d7c075..deddf68a74b1 100644 --- a/vcl/CustomTarget_qt5_moc.mk +++ b/vcl/CustomTarget_qt5_moc.mk @@ -17,6 +17,7 @@ $(call gb_CustomTarget_get_target,vcl/qt5) : \ $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceMessageDialog.moc \ $(gb_CustomTarget_workdir)/vcl/qt5/QtMainWindow.moc \ $(gb_CustomTarget_workdir)/vcl/qt5/QtMenu.moc \ + $(gb_CustomTarget_workdir)/vcl/qt5/QtTransferable.moc \ $(gb_CustomTarget_workdir)/vcl/qt5/QtObject.moc \ $(gb_CustomTarget_workdir)/vcl/qt5/QtTimer.moc \ $(gb_CustomTarget_workdir)/vcl/qt5/QtWidget.moc \ diff --git a/vcl/CustomTarget_qt6_moc.mk b/vcl/CustomTarget_qt6_moc.mk index 7dd7ace45a93..b8103a12e787 100644 --- a/vcl/CustomTarget_qt6_moc.mk +++ b/vcl/CustomTarget_qt6_moc.mk @@ -17,6 +17,7 @@ $(call gb_CustomTarget_get_target,vcl/qt6) : \ $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceMessageDialog.moc \ $(gb_CustomTarget_workdir)/vcl/qt6/QtMainWindow.moc \ $(gb_CustomTarget_workdir)/vcl/qt6/QtMenu.moc \ + $(gb_CustomTarget_workdir)/vcl/qt6/QtTransferable.moc \ $(gb_CustomTarget_workdir)/vcl/qt6/QtObject.moc \ $(gb_CustomTarget_workdir)/vcl/qt6/QtTimer.moc \ $(gb_CustomTarget_workdir)/vcl/qt6/QtWidget.moc \ diff --git a/vcl/inc/qt5/QtTransferable.hxx b/vcl/inc/qt5/QtTransferable.hxx index 5687fa06df52..6b37d65e7e87 100644 --- a/vcl/inc/qt5/QtTransferable.hxx +++ b/vcl/inc/qt5/QtTransferable.hxx @@ -114,6 +114,8 @@ typedef QtTransferable QtDnDTransferable; **/ class QtMimeData final : public QMimeData { + Q_OBJECT + friend class QtClipboardTransferable; const css::uno::Reference<css::datatransfer::XTransferable> m_aContents; diff --git a/vcl/qt5/QtClipboard.cxx b/vcl/qt5/QtClipboard.cxx index f49a51710fc5..2181079a1988 100644 --- a/vcl/qt5/QtClipboard.cxx +++ b/vcl/qt5/QtClipboard.cxx @@ -67,7 +67,7 @@ void QtClipboard::flushClipboard() QClipboard* pClipboard = QApplication::clipboard(); const QtMimeData* pQtMimeData - = dynamic_cast<const QtMimeData*>(pClipboard->mimeData(m_aClipboardMode)); + = qobject_cast<const QtMimeData*>(pClipboard->mimeData(m_aClipboardMode)); assert(pQtMimeData); QMimeData* pMimeCopy = nullptr; @@ -164,7 +164,7 @@ void QtClipboard::handleChanged(QClipboard::Mode aMode) // it. So ignore any signal, which still delivers the internal QtMimeData // as the clipboard content and is no "advertised" change. if (!m_bOwnClipboardChange && isOwner(aMode) - && dynamic_cast<const QtMimeData*>(QApplication::clipboard()->mimeData(aMode))) + && qobject_cast<const QtMimeData*>(QApplication::clipboard()->mimeData(aMode))) return; css::uno::Reference<css::datatransfer::clipboard::XClipboardOwner> xOldOwner(m_aOwner); diff --git a/vcl/qt5/QtFrame.cxx b/vcl/qt5/QtFrame.cxx index 4d9c12891cdf..4b2ffe26e506 100644 --- a/vcl/qt5/QtFrame.cxx +++ b/vcl/qt5/QtFrame.cxx @@ -1425,7 +1425,7 @@ static css::uno::Reference<css::datatransfer::XTransferable> lcl_getXTransferable(const QMimeData* pMimeData) { css::uno::Reference<css::datatransfer::XTransferable> xTransferable; - const QtMimeData* pQtMimeData = dynamic_cast<const QtMimeData*>(pMimeData); + const QtMimeData* pQtMimeData = qobject_cast<const QtMimeData*>(pMimeData); if (!pQtMimeData) xTransferable = new QtDnDTransferable(pMimeData); else @@ -1457,7 +1457,7 @@ static sal_Int8 lcl_getUserDropAction(const QDropEvent* pEvent, const sal_Int8 n if (0 == nUserDropAction) { // default LO internal action is move, but default external action is copy - nUserDropAction = dynamic_cast<const QtMimeData*>(pMimeData) + nUserDropAction = qobject_cast<const QtMimeData*>(pMimeData) ? css::datatransfer::dnd::DNDConstants::ACTION_MOVE : css::datatransfer::dnd::DNDConstants::ACTION_COPY; nUserDropAction &= nSourceActions; diff --git a/vcl/qt5/QtTransferable.cxx b/vcl/qt5/QtTransferable.cxx index 1aec5da27843..ce989da2aa5a 100644 --- a/vcl/qt5/QtTransferable.cxx +++ b/vcl/qt5/QtTransferable.cxx @@ -9,6 +9,7 @@ */ #include <QtTransferable.hxx> +#include <QtTransferable.moc> #include <comphelper/sequence.hxx> #include <sal/log.hxx> diff --git a/vcl/qt5/QtWidget.cxx b/vcl/qt5/QtWidget.cxx index 43adcdf384dc..4ee96c1dbf8c 100644 --- a/vcl/qt5/QtWidget.cxx +++ b/vcl/qt5/QtWidget.cxx @@ -275,7 +275,7 @@ void QtWidget::wheelEvent(QWheelEvent* pEvent) void QtWidget::dragEnterEvent(QDragEnterEvent* event) { - if (dynamic_cast<const QtMimeData*>(event->mimeData())) + if (qobject_cast<const QtMimeData*>(event->mimeData())) event->accept(); else event->acceptProposedAction();