[education/rkward] rkward: Start reworking the (disabled) import dialog into a useful assistant to select the best import method

Thomas Friedrichsmeier null at kde.org
Thu Apr 28 17:35:26 BST 2022


Git commit 61d0afd15bacfff4740fe66d1aa6eaf32b450628 by Thomas Friedrichsmeier.
Committed on 26/04/2022 at 20:59.
Pushed by tfry into branch 'master'.

Start reworking the (disabled) import dialog into a useful assistant to select the best import method

M  +36   -33   rkward/dialogs/rkimportdialog.cpp
M  +11   -10   rkward/dialogs/rkimportdialog.h
M  +2    -0    rkward/plugins/import_export.pluginmap
M  +7    -15   rkward/rkward.cpp

https://invent.kde.org/education/rkward/commit/61d0afd15bacfff4740fe66d1aa6eaf32b450628

diff --git a/rkward/dialogs/rkimportdialog.cpp b/rkward/dialogs/rkimportdialog.cpp
index eaa56c07..767af421 100644
--- a/rkward/dialogs/rkimportdialog.cpp
+++ b/rkward/dialogs/rkimportdialog.cpp
@@ -1,44 +1,43 @@
 /*
 rkimportdialog - This file is part of RKWard (https://rkward.kde.org). Created: Tue Jan 30 2007
-SPDX-FileCopyrightText: 2007-2018 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
+SPDX-FileCopyrightText: 2007-2022 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
 */
 
 #include "rkimportdialog.h"
 
-#include <kmessagebox.h>
 #include <KLocalizedString>
 
-#include <qcombobox.h>
-#include <qlabel.h>
+#include <QLabel>
+#include <QVBoxLayout>
+#include <QGroupBox>
+#include <QRadioButton>
+#include <QButtonGroup>
 
 #include "../plugin/rkcomponentmap.h"
 #include "../plugin/rkcomponentcontext.h"
+#include "../misc/rkcommonfunctions.h"
 
 #include "../debug.h"
 
-RKImportDialog::RKImportDialog (const QString &context_id, QWidget *parent) : QFileDialog (parent) {
+RKImportDialog::RKImportDialog(const QString &context_id, QWidget *parent) : KAssistantDialog(parent) {
 	RK_TRACE (DIALOGS);
 
-	setModal (false);
-
-	context = RKComponentMap::getContext (context_id);
-	if (!context) {
-		KMessageBox::sorry (this, i18n ("No plugins defined for context '%1'", context_id));
-		return;
+	context = RKComponentMap::getContext(context_id);
+	if (context) {
+		component_ids = context->components();
 	}
 
-	component_ids = context->components ();
-	for (QStringList::const_iterator it = component_ids.constBegin (); it != component_ids.constEnd (); ++it) {
-		RKComponentHandle *handle = RKComponentMap::getComponentHandle (*it);
+	for (auto it = component_ids.constBegin(); it != component_ids.constEnd(); ++it) {
+		RKComponentHandle *handle = RKComponentMap::getComponentHandle(*it);
 		if (!handle) {
 			RK_ASSERT (false);
 			continue;
 		}
 
-		QString filter = handle->getAttributeValue ("format");
-		QString label = handle->getAttributeLabel ("format");
+		QString filter = handle->getAttributeValue("format");
+		QString label = handle->getAttributeLabel("format");
 
 		QString elabel = label;
 		elabel.replace ('(', "[");
@@ -46,16 +45,30 @@ RKImportDialog::RKImportDialog (const QString &context_id, QWidget *parent) : QF
 		filters.append (elabel + " [" + filter + "] (" + filter + ')');
 	}
 
-	// initialize
-	setFileMode (QFileDialog::ExistingFile);
-	setNameFilters (filters);
-	show ();
+	QWidget *page1 = new QWidget();
+	QVBoxLayout *layout = new QVBoxLayout(page1);
+	layout->addWidget(RKCommonFunctions::wordWrappedLabel(i18n("For certain formats, RKWard provides specialized import dialogs, and those generally provide the most options. Is the file you wish to import in one of the following formats?")));
+	QGroupBox *box = new QGroupBox();
+	layout->addWidget(box);
+	select_format_group = new QButtonGroup(this);
+	QVBoxLayout *sublayout = new QVBoxLayout(box);
+	for (int i = 0; i < filters.size(); ++i) {
+		auto *button = new QRadioButton(filters[i]);
+		sublayout->addWidget(button);
+		select_format_group->addButton(button);
+	}
+	auto *button = new QRadioButton("None of the above / try another method");
+	sublayout->addWidget(button);
+	select_format_group->addButton(button);
+	button->setChecked(true);
+	select_format = addPage(page1, i18n("Select format"));
 }
 
-RKImportDialog::~RKImportDialog () {
-	RK_TRACE (DIALOGS);
+RKImportDialog::~RKImportDialog() {
+	RK_TRACE(DIALOGS);
 }
 
+/*
 void RKImportDialog::accept () {
 	RK_TRACE (DIALOGS);
 
@@ -73,15 +86,5 @@ void RKImportDialog::accept () {
 
 		chandler->invokeComponent (handle);
 	}
-
-	QFileDialog::accept ();
-	deleteLater ();
 }
-
-void RKImportDialog::reject () {
-	RK_TRACE (DIALOGS);
-
-	QFileDialog::reject ();
-	deleteLater ();
-}
-
+*/
diff --git a/rkward/dialogs/rkimportdialog.h b/rkward/dialogs/rkimportdialog.h
index 00509456..175a25c4 100644
--- a/rkward/dialogs/rkimportdialog.h
+++ b/rkward/dialogs/rkimportdialog.h
@@ -8,15 +8,16 @@ SPDX-License-Identifier: GPL-2.0-or-later
 #ifndef RKIMPORTDIALOG_H
 #define RKIMPORTDIALOG_H
 
-#include <qstringlist.h>
-#include <QFileDialog>
+#include <QStringList>
+#include <KAssistantDialog>
 
-class QComboBox;
 class RKComponentGUIXML;
+class KPageWidgetitem;
+class QButtonGroup;
 
 /** This dialog is designed to allow the user to select a file, and file format. After that a suitable plugin
 is opened automatically to deal with this type of file . */
-class RKImportDialog : public QFileDialog {
+class RKImportDialog : public KAssistantDialog {
 	Q_OBJECT
 public:
 /** constructor
@@ -25,16 +26,16 @@ public:
 	RKImportDialog (const QString &context_id, QWidget *parent);
 /** dtor */
 	~RKImportDialog ();
-protected:
-/** reimplemented to a) invoke the relevant plugin, b) trigger self-destruction of the dialog */
-	void accept () override;
-/** reimplemented to trigger self-destruction of the dialog */
-	void reject () override;
 private:
-	int format_count;
 	QStringList filters;
 	QStringList component_ids;
 	RKComponentGUIXML *context;
+	KPageWidgetItem *select_format;
+	QButtonGroup *select_format_group;
+	KPageWidgetItem *do_format;
+	KPageWidgetItem *select_rio_or_clipboard;
+	KPageWidgetItem *do_rio;
+	KPageWidgetItem *do_clipboard;
 };
 
 #endif
diff --git a/rkward/plugins/import_export.pluginmap b/rkward/plugins/import_export.pluginmap
index 30772565..635b4bf1 100644
--- a/rkward/plugins/import_export.pluginmap
+++ b/rkward/plugins/import_export.pluginmap
@@ -80,6 +80,8 @@
 			<entry component="import_spss"/>
 			<entry component="import_stata"/>
 			<entry component="import_csv"/>
+			<entry component="import_xls"/>
+			<entry component="import_xls_xlconnect"/>
 		</menu>
 	</context>
 </document>
diff --git a/rkward/rkward.cpp b/rkward/rkward.cpp
index 1567294d..c31264e8 100644
--- a/rkward/rkward.cpp
+++ b/rkward/rkward.cpp
@@ -500,19 +500,10 @@ void RKWardMainWindow::initActions() {
 	connect(fileOpenRecent, &KRecentFilesAction::urlSelected, this, [this](const QUrl &url) { slotOpenCommandEditor(url); });
 	fileOpenRecent->setText(i18n("Open Recent R Script File"));
 
-#if 0
-	// TODO: Fix import dialog and re-enable it: https://mail.kde.org/pipermail/rkward-devel/2015-June/004156.html
-#ifdef Q_OS_WIN
-	// TODO: find the cause and fix it! http://sourceforge.net/p/rkward/bugs/54/
-#	ifdef __GNUC__
-#		warning TODO: import data dialog is disabled on windows due to bug in kdelibs
-#	endif
-#else
-	action = actionCollection ()->addAction ("import_data", this, SLOT (importData()));
-	action->setText (i18n ("Import Data"));
-	action->setWhatsThis(i18n ("Import data from a variety of file formats"));
-#endif
-#endif
+	action = actionCollection()->addAction("import_data");
+	connect(action, &QAction::triggered, this, &RKWardMainWindow::importData);
+	action->setText(i18n("Import Assistant"));
+	action->setWhatsThis(i18n("Assistant to find the best method to import data from a variety of formats"));
 
 	fileOpenWorkspace = actionCollection()->addAction(KStandardAction::Open, "file_openx");
 	connect(fileOpenWorkspace, &QAction::triggered, this, [this](){ askOpenWorkspace(); });
@@ -921,10 +912,11 @@ void RKWardMainWindow::setRStatus (int status) {
 	}
 }
 
-void RKWardMainWindow::importData () {
+void RKWardMainWindow::importData() {
 	RK_TRACE (APP);
 
-	new RKImportDialog ("import", this);
+	RKImportDialog d("import", this);
+	d.exec();
 }
 
 void RKWardMainWindow::slotNewCommandEditor () {



More information about the rkward-tracker mailing list