[education/rkward/kf5] /: Fix some warnings

Thomas Friedrichsmeier null at kde.org
Wed Apr 10 16:12:08 BST 2024


Git commit 30fffdf3b8f6ff7e3482a04f4e33830c44978daf by Thomas Friedrichsmeier.
Committed on 08/04/2024 at 20:39.
Pushed by tfry into branch 'kf5'.

Fix some warnings

M  +1    -1    .kde-ci.yml
M  +20   -13   rkward/agents/rkprintagent.cpp
M  +2    -2    rkward/autotests/core_test.cpp
M  +1    -1    rkward/debug.h
M  +2    -2    rkward/misc/rkprogresscontrol.cpp
M  +7    -1    rkward/misc/rkspecialactions.cpp
M  +1    -1    rkward/misc/rkxmlguipreviewarea.cpp
M  +2    -0    rkward/rkward.cpp
M  +1    -1    rkward/windows/robjectbrowser.cpp

https://invent.kde.org/education/rkward/-/commit/30fffdf3b8f6ff7e3482a04f4e33830c44978daf

diff --git a/.kde-ci.yml b/.kde-ci.yml
index 9f103c8d5..cb71b77f9 100644
--- a/.kde-ci.yml
+++ b/.kde-ci.yml
@@ -22,4 +22,4 @@ Options:
   require-passing-tests-on: [ 'Linux', 'FreeBSD', 'Windows' ]
   tests-load-sensitve: True
   per-test-timeout: 90
-  cppcheck-arguments: '--enable=warning,style,performance --inline-suppr -DRKWARD_VERSION="dummy" -DCPPCHECK=1'
+  cppcheck-arguments: '--enable=warning,style,performance --inline-suppr -DRKWARD_VERSION="dummy" -DCPPCHECK_ONLY=1'
diff --git a/rkward/agents/rkprintagent.cpp b/rkward/agents/rkprintagent.cpp
index b031623c3..036f713e9 100644
--- a/rkward/agents/rkprintagent.cpp
+++ b/rkward/agents/rkprintagent.cpp
@@ -1,6 +1,6 @@
 /*
 rkprintagent - This file is part of RKWard (https://rkward.kde.org). Created: Mon Aug 01 2011
-SPDX-FileCopyrightText: 2011-2018 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
+SPDX-FileCopyrightText: 2011-2024 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
 SPDX-FileContributor: The RKWard Team <rkward-devel at kde.org>
 SPDX-License-Identifier: GPL-2.0-or-later
 */
@@ -38,22 +38,26 @@ RKPrintAgent::~RKPrintAgent () {
 	if (provider) provider->deleteLater ();
 }
 
+void fallbackToGeneric(const QString &file, bool delete_file) {
+	KMessageBox::error(RKWardMainWindow::getMain(), i18n("No service was found to provide a KDE print dialog for PostScript files. We will try to open a generic PostScript viewer (if any), instead.<br><br>Consider installing 'okular', or configure RKWard not to attempt to print using a KDE print dialog."), i18n("Unable to open KDE print dialog"));
+
+	// fallback: If we can't find a proper part, try to invoke a standalone PS reader, instead
+	auto *job = new KIO::OpenUrlJob(QUrl::fromLocalFile(file), QStringLiteral("application/postscript"));
+	job->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, RKWardMainWindow::getMain()));
+	job->setDeleteTemporaryFile(delete_file);
+	job->start();
+}
+
 void RKPrintAgent::printPostscript (const QString &file, bool delete_file) {
 	RK_TRACE (APP)
 
-    const KPluginMetaData okularPart(QStringLiteral(OKULAR_LIBRARY_NAME));
-    const QVariantList args {"ViewerWidget"};
-    auto result = KPluginFactory::instantiatePlugin<KParts::ReadOnlyPart>(okularPart, nullptr, args);
+	const KPluginMetaData okularPart(QStringLiteral(OKULAR_LIBRARY_NAME));
+	const QVariantList args {"ViewerWidget"};
+	auto result = KPluginFactory::instantiatePlugin<KParts::ReadOnlyPart>(okularPart, nullptr, args);
 
-    if(!result) {
-		RK_DEBUG (APP, DL_WARNING, "No valid postscript provider was found");
-		KMessageBox::error(RKWardMainWindow::getMain(), i18n("No service was found to provide a KDE print dialog for PostScript files. We will try to open a generic PostScript viewer (if any), instead.<br><br>Consider installing 'okular', or configure RKWard not to attempt to print using a KDE print dialog."), i18n("Unable to open KDE print dialog"));
-
-		// fallback: If we can't find a proper part, try to invoke a standalone PS reader, instead
-		auto *job = new KIO::OpenUrlJob(QUrl::fromLocalFile(file), QStringLiteral("application/postscript"));
-		job->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, RKWardMainWindow::getMain()));
-		job->setDeleteTemporaryFile(delete_file);
-		job->start();
+	if(!result) {
+		RK_DEBUG(APP, DL_WARNING, "No valid postscript provider was found");
+		fallbackToGeneric(file, delete_file);
 		return;
 	}
 
@@ -69,6 +73,9 @@ void RKPrintAgent::printPostscript (const QString &file, bool delete_file) {
 		RK_DEBUG (APP, DL_WARNING, "No print action in postscript provider");
 		delete provider;
 		provider = nullptr;
+	} else {
+		fallbackToGeneric(file, delete_file);
+		return;
 	}
 
 	RKPrintAgent *agent = new RKPrintAgent(file, provider, delete_file);
diff --git a/rkward/autotests/core_test.cpp b/rkward/autotests/core_test.cpp
index a0b89b544..4fb1efeaf 100644
--- a/rkward/autotests/core_test.cpp
+++ b/rkward/autotests/core_test.cpp
@@ -195,7 +195,7 @@ private Q_SLOTS:
 		RInterface::whenAllFinished(this, []() {
 			auto a = RObjectList::getGlobalEnv()->findObject("a");
 			QVERIFY(a != nullptr);
-			QVERIFY(a->isContainer());
+			QVERIFY(a && a->isContainer());
 			auto ac = static_cast<RContainerObject*>(a);
 			QCOMPARE(ac->numChildren(), 3);
 			QCOMPARE(ac->findChildByIndex(0)->getDataType(), RObject::DataNumeric);
@@ -219,7 +219,7 @@ private Q_SLOTS:
 		runCommandAsync(new RCommand("dx <- data.frame(a=1:2, b=3:4)", RCommand::User), nullptr, [this, &lock](RCommand *) {
 			auto dx = RObjectList::getGlobalEnv()->findObject("dx");
 			QVERIFY(dx != nullptr);
-			QVERIFY(dx->isContainer());
+			QVERIFY(dx && dx->isContainer());
 			if (dx && dx->isContainer()) {
 			    auto dx_a = static_cast<RContainerObject*>(dx)->findChildByName("a");
 			    QVERIFY(dx_a != nullptr);
diff --git a/rkward/debug.h b/rkward/debug.h
index 61a52ceb6..cd7c2cd7f 100644
--- a/rkward/debug.h
+++ b/rkward/debug.h
@@ -37,7 +37,7 @@ void RKDebug (int flags, int level, const char *fmt, ...);
 // Debug functions 
 #	define RK_DO(expr,flags,level) if ((flags & RK_Debug::RK_Debug_Flags) && (level >= RK_Debug::RK_Debug_Level)) { expr; }
 #	define RK_DEBUG(flags,level,...) { if ((flags & RK_Debug::RK_Debug_Flags) && (level >= RK_Debug::RK_Debug_Level)) RKDebug (flags,level,__VA_ARGS__); }
-#if defined(CPPCHECK)
+#if defined(CPPCHECK_ONLY)
 #	define RK_ASSERT(x) assert(x) /* Keep it from complaining. Supressing nullPointerRedundantCheck does not appear to work. */
 #else
 #	define RK_ASSERT(x) if (!(x)) RK_DEBUG (DEBUG_ALL, DL_FATAL, "Assert '%s' failed at %s - function %s line %d", #x, __FILE__, __FUNCTION__, __LINE__);
diff --git a/rkward/misc/rkprogresscontrol.cpp b/rkward/misc/rkprogresscontrol.cpp
index 2ad36969e..d4c1e9bd5 100644
--- a/rkward/misc/rkprogresscontrol.cpp
+++ b/rkward/misc/rkprogresscontrol.cpp
@@ -151,9 +151,9 @@ void RKProgressControl::addRCommand (RCommand *command, bool done_when_finished)
 	outstanding_commands.append(command);
 	connect(command->notifier(), &RCommandNotifier::commandOutput, this, QOverload<RCommand*, const ROutput*>::of(&RKProgressControl::newOutput));
 	if (done_when_finished) {
-		command->whenFinished(this, [this, done_when_finished](RCommand* command) {
+		command->whenFinished(this, [this](RCommand* command) {
 			outstanding_commands.removeAll(command);
-			if (done_when_finished) done();
+			done();
 		});
 	}
 }
diff --git a/rkward/misc/rkspecialactions.cpp b/rkward/misc/rkspecialactions.cpp
index 89708e19d..419e0b350 100644
--- a/rkward/misc/rkspecialactions.cpp
+++ b/rkward/misc/rkspecialactions.cpp
@@ -29,7 +29,13 @@ void RKPasteSpecialAction::doSpecialPaste() {
 	RK_TRACE(MISC);
 
 	QWidget *pwin = nullptr;
-	if (!associatedWidgets().isEmpty()) pwin = associatedWidgets().at(0);
+	const auto objs = associatedObjects();
+	for(auto obj : objs) {
+		if (qobject_cast<QWidget*>(obj)) {
+			pwin = static_cast<QWidget*>(obj);
+			break;
+		}
+	}
 	RKPasteSpecialDialog* dialog = new RKPasteSpecialDialog(pwin);
 	int res = dialog->exec();
 	if (res == QDialog::Accepted) {
diff --git a/rkward/misc/rkxmlguipreviewarea.cpp b/rkward/misc/rkxmlguipreviewarea.cpp
index 1cf82fa70..779ace79d 100644
--- a/rkward/misc/rkxmlguipreviewarea.cpp
+++ b/rkward/misc/rkxmlguipreviewarea.cpp
@@ -153,7 +153,7 @@ void RKXMLGUIPreviewArea::prepareMenu () {
 		bool menu_empty = true;
 		for (int j = 0; j < subentries.size (); ++j) {
 			QAction *act = subentries[j];
-			if (act->isVisible () && act->isEnabled () && act) {
+			if (act->isVisible () && act->isEnabled()) {
 				entries_to_add.append (act);
 				if (!act->isSeparator ()) menu_empty = false;  // Copy separators, but purge menus with only separators in them.
 			}
diff --git a/rkward/rkward.cpp b/rkward/rkward.cpp
index a527f1a8d..9dad43b1a 100644
--- a/rkward/rkward.cpp
+++ b/rkward/rkward.cpp
@@ -93,6 +93,7 @@ SPDX-License-Identifier: GPL-2.0-or-later
 
 // This nevers gets called. It's needed to trick ld into linking correctly. Nothing else.
 void bogusCalls () {
+#ifndef CCPCHECK_ONLY  // it would rightfully complain about some of these
 	ShowEditTextFileAgent::showEditFiles(nullptr);                                   // TODO: AAAAAAAARGGGH!!!! It won't link without this bogus line!!!
 	RKReadLineDialog::readLine(nullptr, QString(), QString(), nullptr, nullptr);     // TODO: see above
 	RKSelectListDialog::doSelect(nullptr, QString(), QStringList(), QStringList(), false); // TODO: see above
@@ -101,6 +102,7 @@ void bogusCalls () {
 	new RKWorkplaceView(nullptr);
 	new RKEditObjectAgent(QStringList(), nullptr);
 	RKPrintAgent::printPostscript(QString(), false);
+#endif
 }
 
 /** Main window **/
diff --git a/rkward/windows/robjectbrowser.cpp b/rkward/windows/robjectbrowser.cpp
index 7e14b3a2e..ea765a45f 100644
--- a/rkward/windows/robjectbrowser.cpp
+++ b/rkward/windows/robjectbrowser.cpp
@@ -194,7 +194,7 @@ void RObjectBrowserInternal::popupCopy () {
 void RObjectBrowserInternal::popupCopyToGlobalEnv () {
 	RK_TRACE (APP);
 
-	RObject *object = list_view->menuObject ();
+	const RObject *object = list_view->menuObject ();
 	QString name = object->getShortName ();
 
 	QString valid = RObjectList::getGlobalEnv ()->validizeName (name);


More information about the rkward-tracker mailing list