From e00b8105bfcf3d4e36275dea6355705ec5fdbc40 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 20 May 2011 10:10:32 +0200 Subject: [PATCH] Designer: Extend container extension. Make it possible to disable adding/removing pages by adding respective bool virtual functions. Useful for implementing containers with fixed, single children like QScrollArea, QDockWidget, which require a container extension to work properly in Qt Designer. Previously, the problem was that the add/remove page context menu actions were enabled for them, leading to crashes und undesired behaviour. Reviewed-by: Jarek Kobus --- tools/uilib/container.h | 7 +++++++ tools/uilib/container.qdoc | 27 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/tools/uilib/container.h b/tools/uilib/container.h index 89df461e02..f0d89faa08 100644 --- a/tools/uilib/container.h +++ b/tools/uilib/container.h @@ -65,6 +65,13 @@ public: virtual void addWidget(QWidget *widget) = 0; virtual void insertWidget(int index, QWidget *widget) = 0; virtual void remove(int index) = 0; + + virtual bool canAddWidget() const + // ### Qt6 remove body, provided in Qt5 for source compatibility to Qt4. + { return true; } + virtual bool canRemove(int index) const + // ### Qt6 remove body, provided in Qt5 for source compatibility to Qt4. + { Q_UNUSED(index); return true; } }; Q_DECLARE_EXTENSION_INTERFACE(QDesignerContainerExtension, "com.trolltech.Qt.Designer.Container") diff --git a/tools/uilib/container.qdoc b/tools/uilib/container.qdoc index d9310515d3..f8e0670811 100644 --- a/tools/uilib/container.qdoc +++ b/tools/uilib/container.qdoc @@ -170,3 +170,30 @@ \sa addWidget(), insertWidget() */ + +/*! + \fn bool QDesignerContainerExtension::canAddWidget() const + + Returns whether a widget can be added. This determines whether + the context menu options to add or insert pages are enabled. + + This should return false for containers that have a single, fixed + page, for example QScrollArea or QDockWidget. + + \since 5.0 + \sa addWidget(), canRemove() +*/ + +/*! + \fn bool QDesignerContainerExtension::canRemove(int index) const + + Returns whether the widget at the given \a index can be removed. + This determines whether the context menu option to remove the current + page is enabled. + + This should return false for containers that have a single, fixed + page, for example QScrollArea or QDockWidget. + + \since 5.0 + \sa remove(), canAddWidget() +*/