[education/rkward] rkward: Fix clazy warning.

Thomas Friedrichsmeier null at kde.org
Sun Mar 27 15:32:21 BST 2022


Git commit 6593672861c8b01baa25bf2fceb3d0f71a554796 by Thomas Friedrichsmeier.
Committed on 27/03/2022 at 14:25.
Pushed by tfry into branch 'master'.

Fix clazy warning.

Trying to be too generic WRT to adding windows to named areas does not really help, anyway, as
arbitrary widgets will not support having a window reparented into them. So rather special case
RKXMLGUIPreviewArea (which is the only special case to handle, after all).

M  +18   -25   rkward/misc/rkxmlguipreviewarea.cpp
M  +3    -5    rkward/misc/rkxmlguipreviewarea.h
M  +1    -1    rkward/plugin/rkstandardcomponentgui.cpp
M  +8    -2    rkward/windows/rkworkplace.cpp

https://invent.kde.org/education/rkward/commit/6593672861c8b01baa25bf2fceb3d0f71a554796

diff --git a/rkward/misc/rkxmlguipreviewarea.cpp b/rkward/misc/rkxmlguipreviewarea.cpp
index 7617acf4..89c138ab 100644
--- a/rkward/misc/rkxmlguipreviewarea.cpp
+++ b/rkward/misc/rkxmlguipreviewarea.cpp
@@ -2,7 +2,7 @@
                           rkxmlguipreviewarea  -  description
                              -------------------
     begin                : Wed Feb 03 2016
-    copyright            : (C) 2016 by Thomas Friedrichsmeier
+    copyright            : (C) 2016-2022 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -56,6 +56,7 @@ RKXMLGUIPreviewArea::~RKXMLGUIPreviewArea () {
 		removeChildClient (current);
 		current->setFactory (0);
 	}
+	if (wrapper_widget) wrapper_widget->deleteLater();  // technically, the wrapper widget is the parent of this, not the other way around
 }
 
 void RKXMLGUIPreviewArea::setLabel (const QString& label) {
@@ -108,31 +109,23 @@ QWidget* RKXMLGUIPreviewArea::wrapperWidget () {
 	return wrapper_widget;
 }
 
-void RKXMLGUIPreviewArea::childEvent (QChildEvent *event) {
-	RK_TRACE (PLUGIN);
-
-	if (event->type () == QEvent::ChildAdded) {
-		RKMDIWindow *child = qobject_cast<RKMDIWindow*> (event->child ());
-		if (child) {
-			if (current) {
-				removeChildClient (current);
-				factory ()->removeClient (current);  // _always_ remove before adding, or the previous child will be leaked in the factory
-			}
-			child->setWindowStyleHint ("preview");
-			current = child->getPart ();
-			insertChildClient (current);
-			setCentralWidget (child);
-			createGUI ("rkwrapper_widgetpart.rc");
-			menuBar ()->hide ();
-			QList<KToolBar*> tbars = toolBars ();
-			for (int i = 0; i < tbars.size (); ++i) tbars[i]->hide ();
-			// avoid shortcut conflicts
-			QList<QAction*> acts = actions ();
-			for (int i = 0; i < acts.size (); ++i) acts[i]->setShortcutContext(Qt::WidgetWithChildrenShortcut);
-			RKWorkplace::mainWorkplace()->setWindowNotManaged(child);
-		}
+void RKXMLGUIPreviewArea::setWindow(RKMDIWindow* window) {
+	if (current) {
+		removeChildClient(current);
+		factory()->removeClient(current);  // _always_ remove before adding, or the previous child will be leaked in the factory
 	}
-	QObject::childEvent (event);
+	window->setWindowStyleHint("preview");
+	current = window->getPart();
+	insertChildClient(current);
+	setCentralWidget(window);
+	createGUI("rkwrapper_widgetpart.rc");
+	menuBar()->hide();
+	QList<KToolBar*> tbars = toolBars();
+	for (int i = 0; i < tbars.size(); ++i) tbars[i]->hide();
+	// avoid shortcut conflicts
+	QList<QAction*> acts = actions();
+	for (int i = 0; i < acts.size (); ++i) acts[i]->setShortcutContext(Qt::WidgetWithChildrenShortcut);
+	RKWorkplace::mainWorkplace()->setWindowNotManaged(window);
 }
 
 void RKXMLGUIPreviewArea::prepareMenu () {
diff --git a/rkward/misc/rkxmlguipreviewarea.h b/rkward/misc/rkxmlguipreviewarea.h
index c185a96e..455f1761 100644
--- a/rkward/misc/rkxmlguipreviewarea.h
+++ b/rkward/misc/rkxmlguipreviewarea.h
@@ -2,7 +2,7 @@
                           rkxmlguipreviewarea  -  description
                              -------------------
     begin                : Wed Feb 03 2016
-    copyright            : (C) 2016-2018 by Thomas Friedrichsmeier
+    copyright            : (C) 2016-2022 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -26,6 +26,7 @@
 class QMenu;
 class QToolButton;
 class QLabel;
+class RKMDIWindow;
 
 class RKXMLGUIPreviewArea : public KXmlGuiWindow {
 	Q_OBJECT
@@ -36,10 +37,7 @@ public:
 	QWidget *wrapperWidget ();
 	QString label () const { return _label; };
 	void setLabel (const QString &label);
-protected:
-	/** build / destroy menu, when child is added removed. Note that we are in the fortunate situation that RKMDIWindow-children only ever get to the
-	 *  preview area via reparenting, i.e. contrary to usual QEvent::ChildAdded semantics, they are always fully constructed, when added. */
-	void childEvent (QChildEvent *event) override;
+	void setWindow(RKMDIWindow* window);
 protected slots:
 	void prepareMenu ();
 signals:
diff --git a/rkward/plugin/rkstandardcomponentgui.cpp b/rkward/plugin/rkstandardcomponentgui.cpp
index 4166e20f..3e5a8a3c 100644
--- a/rkward/plugin/rkstandardcomponentgui.cpp
+++ b/rkward/plugin/rkstandardcomponentgui.cpp
@@ -157,7 +157,7 @@ RKStandardComponentGUI::RKStandardComponentGUI (RKStandardComponent *component,
 		code_display = new RKCommandEditorWindow (0, QUrl (), QString (), RKCommandEditorFlags::DefaultToRHighlighting);
 		code_display->setReadOnly (true);
 		code_display_visibility.setBoolValue (!enslaved && RKSettingsModulePlugins::showCodeByDefault ());
-		code_display->setParent (area);  // hm, mysterious breakage when adding via constructor. Whatever...
+		area->setWindow(code_display);
 
 		KActionCollection *action_collection = new KActionCollection (this);
 		action_collection->addAction (KStandardAction::Copy, this, SLOT (copyCode()));
diff --git a/rkward/windows/rkworkplace.cpp b/rkward/windows/rkworkplace.cpp
index c53c188e..e6824653 100644
--- a/rkward/windows/rkworkplace.cpp
+++ b/rkward/windows/rkworkplace.cpp
@@ -55,6 +55,7 @@
 #include "../rbackend/rcommand.h"
 #include "../misc/rkcommonfunctions.h"
 #include "../misc/rkoutputdirectory.h"
+#include "../misc/rkxmlguipreviewarea.h"
 #include "../rkglobals.h"
 #include "../rkward.h"
 
@@ -296,8 +297,13 @@ void RKWorkplace::addWindow (RKMDIWindow *window, bool attached) {
 		if (nw.parent == RKWardMainWindow::getMain ()) attached = true;
 		else if (nw.parent == 0) attached = false;
 		else { // custom parent
-			window->prepareToBeAttached ();
-			window->setParent (nw.parent);
+			RKXMLGUIPreviewArea* area = qobject_cast<RKXMLGUIPreviewArea*>(nw.parent);
+			if (!area) {
+				RK_ASSERT(area);
+				return;
+			}
+			window->prepareToBeAttached();
+			area->setWindow(window);
 			// TODO: do this is somewhat inconsistent. But such windows are not attached to the main workplace view, which makes them rather behave detached.
 			window->state = RKMDIWindow::Detached;
 			// NOTE: The window is _not_ added to the window list/window history in this case.


More information about the rkward-tracker mailing list