[rkward/frameworks] /: Further removal of KDELibs4 support code.

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Thu Feb 11 21:19:50 UTC 2016


Git commit f2f5e837dbf0111d4541d82a6cc26f761dfd1920 by Thomas Friedrichsmeier.
Committed on 11/02/2016 at 20:17.
Pushed by tfry into branch 'frameworks'.

Further removal of KDELibs4 support code.

M  +2    -1    TODO
M  +1    -17   rkward/dialogs/CMakeLists.txt
M  +11   -44   rkward/dialogs/rkimportdialog.cpp
M  +2    -21   rkward/dialogs/rkimportdialog.h
M  +2    -3    rkward/dialogs/rkloadlibsdialog.cpp
M  +24   -16   rkward/dialogs/rkreadlinedialog.cpp
M  +2    -2    rkward/dialogs/rkreadlinedialog.h
M  +27   -17   rkward/dialogs/rkselectlistdialog.cpp
M  +4    -3    rkward/dialogs/rkselectlistdialog.h
M  +1    -0    rkward/rbackend/rinterface.cpp

http://commits.kde.org/rkward/f2f5e837dbf0111d4541d82a6cc26f761dfd1920

diff --git a/TODO b/TODO
index 25dcc4c..6537a6f 100644
--- a/TODO
+++ b/TODO
@@ -13,7 +13,8 @@ Things to test at the end:
   - Moved installations, moved workspaces.
 - Window embedding
 Knwon issues to fix:
-- Initial window placement for plugins with previews is borked
+- Initial window placement for plugins is completely borked. One way around this seems to be to inherit RKStandardComponentGUI from QDialog.
+- Initial window placement for plots is always 0, 0 on screen 1, apparently. The above workaround may not be available, here?
 
 Upcoming porting efforts: Port from QtScript to QJSEngine:
 - Unforunately, QJSEngine lacks support for pre-compiled JS (QScriptProgram), ATM (Qt 5.5). We'll need some other optimization.
diff --git a/rkward/dialogs/CMakeLists.txt b/rkward/dialogs/CMakeLists.txt
index 13e39c7..5baf039 100644
--- a/rkward/dialogs/CMakeLists.txt
+++ b/rkward/dialogs/CMakeLists.txt
@@ -1,8 +1,5 @@
 INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}    )
 
-
-########### next target ###############
-
 SET(dialogs_STAT_SRCS
    startupdialog.cpp
    rkloadlibsdialog.cpp
@@ -14,17 +11,4 @@ SET(dialogs_STAT_SRCS
    )
 
 ADD_LIBRARY(dialogs STATIC ${dialogs_STAT_SRCS})
-TARGET_LINK_LIBRARIES(dialogs Qt5::Widgets KF5::KDELibs4Support)
-
-########### install files ###############
-
-
-
-
-#original Makefile.am contents follow:
-
-#INCLUDES = $(all_includes)
-#METASOURCES = AUTO
-#noinst_LIBRARIES =  libdialogs.a
-#noinst_HEADERS = startupdialog.h rkloadlibsdialog.h rkreadlinedialog.h rkimportdialog.h
-#libdialogs_a_SOURCES = startupdialog.cpp rkloadlibsdialog.cpp rkreadlinedialog.cpp rkimportdialog.cpp
+TARGET_LINK_LIBRARIES(dialogs Qt5::Widgets KF5::ConfigWidgets KF5::KDELibs4Support)
diff --git a/rkward/dialogs/rkimportdialog.cpp b/rkward/dialogs/rkimportdialog.cpp
index df0b186..f690a7b 100644
--- a/rkward/dialogs/rkimportdialog.cpp
+++ b/rkward/dialogs/rkimportdialog.cpp
@@ -18,7 +18,6 @@
 #include "rkimportdialog.h"
 
 #include <kmessagebox.h>
-#include <kfilefiltercombo.h>
 #include <klocale.h>
 
 #include <qcombobox.h>
@@ -29,14 +28,7 @@
 
 #include "../debug.h"
 
-RKImportDialogFormatSelector::RKImportDialogFormatSelector () : KHBox () {
-	RK_TRACE (DIALOGS);
-
-	new QLabel (i18n ("File format:"), this);
-	combo = new QComboBox (this);
-}
-
-RKImportDialog::RKImportDialog (const QString &context_id, QWidget *parent) : KFileDialog (QUrl (), QString (), parent, format_selector=new RKImportDialogFormatSelector ()) {
+RKImportDialog::RKImportDialog (const QString &context_id, QWidget *parent) : QFileDialog (parent) {
 	RK_TRACE (DIALOGS);
 
 	setModal (false);
@@ -48,11 +40,8 @@ RKImportDialog::RKImportDialog (const QString &context_id, QWidget *parent) : KF
 	}
 
 	component_ids = context->components ();
-	QString formats = "*|" + i18n ("All Files") + " (*)\n";
 	int format_count = 0;
 	for (QStringList::const_iterator it = component_ids.constBegin (); it != component_ids.constEnd (); ++it) {
-		if (format_count++) formats.append ('\n');
-
 		RKComponentHandle *handle = RKComponentMap::getComponentHandle (*it);
 		if (!handle) {
 			RK_ASSERT (false);
@@ -63,22 +52,14 @@ RKImportDialog::RKImportDialog (const QString &context_id, QWidget *parent) : KF
 		QString label = handle->getAttributeLabel ("format");
 
 		QString elabel = label;
-		elabel.replace ('/', "\\/");
-		elabel.replace ('|', "\\|");
-		formats.append (filter + '|' + elabel + " (" + filter + ')');
-
-		format_labels.append (label);
-		filters.append (filter);
+		elabel.replace ('(', "[");
+		elabel.replace (')', "]");
+		filters.append (elabel + " [" + filter + "] (" + filter + ')');
 	}
 
-	// file format selection box
-	format_selector->combo->insertItems (0, format_labels);
-
 	// initialize
-	setMode (KFile::File | KFile::ExistingOnly | KFile::LocalOnly);
-	setFilter (formats);
-	connect (this, &KFileDialog::filterChanged, this, &RKImportDialog::filterWasChanged);
-	filterWasChanged (QString ());
+	setFileMode (QFileDialog::ExistingFile);
+	setNameFilters (filters);
 	show ();
 }
 
@@ -86,26 +67,11 @@ RKImportDialog::~RKImportDialog () {
 	RK_TRACE (DIALOGS);
 }
 
-void RKImportDialog::filterWasChanged (const QString &) {
-	RK_TRACE (DIALOGS);
-
-	int index = filters.indexOf (filterWidget ()->currentFilter ());
-
-	if (index < 0) {		// All files
-		format_selector->combo->setEnabled (true);
-	} else {
-		format_selector->combo->setEnabled (false);
-		format_selector->combo->setCurrentIndex (index);
-	}
-}
-
 void RKImportDialog::accept () {
 	RK_TRACE (DIALOGS);
 
-	KFileDialog::accept ();
-
-	int index = format_selector->combo->currentIndex ();
-	QString cid = component_ids[index];
+	int index = filters.indexOf (selectedNameFilter ());
+	QString cid = component_ids.value (index);
 	RKComponentHandle *handle = RKComponentMap::getComponentHandle (cid);
 	RKContextHandler *chandler = context->makeContextHandler (this, false);
 
@@ -113,19 +79,20 @@ void RKImportDialog::accept () {
 		RK_ASSERT (false);
 	} else {
 		RKComponentPropertyBase *filename = new RKComponentPropertyBase (chandler, false);
-		filename->setValue (selectedFile ());
+		filename->setValue (selectedFiles ().value (0));
 		chandler->addChild ("filename", filename);
 
 		chandler->invokeComponent (handle);
 	}
 
+	QFileDialog::accept ();
 	deleteLater ();
 }
 
 void RKImportDialog::reject () {
 	RK_TRACE (DIALOGS);
 
-	KFileDialog::reject ();
+	QFileDialog::reject ();
 	deleteLater ();
 }
 
diff --git a/rkward/dialogs/rkimportdialog.h b/rkward/dialogs/rkimportdialog.h
index cb36e86..bddaee3 100644
--- a/rkward/dialogs/rkimportdialog.h
+++ b/rkward/dialogs/rkimportdialog.h
@@ -18,19 +18,15 @@
 #ifndef RKIMPORTDIALOG_H
 #define RKIMPORTDIALOG_H
 
-#include <kfiledialog.h>
-
 #include <qstringlist.h>
-
-#include <khbox.h>
+#include <QFileDialog>
 
 class QComboBox;
 class RKComponentGUIXML;
-class RKImportDialogFormatSelector;
 
 /** 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 KFileDialog {
+class RKImportDialog : public QFileDialog {
 	Q_OBJECT
 public:
 /** constructor
@@ -39,9 +35,6 @@ public:
 	RKImportDialog (const QString &context_id, QWidget *parent);
 /** dtor */
 	~RKImportDialog ();
-public slots:
-/** The currently selected file extension filter was changed. Update the file format selection box accordingly. */
-	void filterWasChanged (const QString &);
 protected:
 /** reimplemented to a) invoke the relevant plugin, b) trigger self-destruction of the dialog */
 	void accept () override;
@@ -49,21 +42,9 @@ protected:
 	void reject () override;
 private:
 	int format_count;
-	RKImportDialogFormatSelector *format_selector;
-	QStringList format_labels;
 	QStringList filters;
 	QStringList component_ids;
 	RKComponentGUIXML *context;
 };
 
-/** Internal helper class to RKImportDialog. Needed solely to work around a design flaw in the KFileDialog API */
-class RKImportDialogFormatSelector : public KHBox {
-friend class RKImportDialog;
-private:
-	RKImportDialogFormatSelector ();
-	~RKImportDialogFormatSelector () {};
-
-	QComboBox *combo;
-};
-
 #endif
diff --git a/rkward/dialogs/rkloadlibsdialog.cpp b/rkward/dialogs/rkloadlibsdialog.cpp
index d2e8aea..f17b1c8 100644
--- a/rkward/dialogs/rkloadlibsdialog.cpp
+++ b/rkward/dialogs/rkloadlibsdialog.cpp
@@ -33,9 +33,7 @@
 
 #include <klocale.h>
 #include <kmessagebox.h>
-#include <kvbox.h>
 #include <kuser.h>
-#include <kstandarddirs.h>
 
 #include "../rkglobals.h"
 #include "../rbackend/rinterface.h"
@@ -335,7 +333,8 @@ void RKLoadLibsDialog::runInstallationCommand (const QString& command, bool as_r
 	call = R_binary;
 #else
 	if (as_root) {
-		call = KStandardDirs::findExe ("kdesu");
+		call = QStandardPaths::findExecutable ("kdesu");
+		if (call.isEmpty ()) call = QStandardPaths::findExecutable ("kdesudo");
 		params << "-t" << "--" << R_binary;
 	} else {
 		call = R_binary;
diff --git a/rkward/dialogs/rkreadlinedialog.cpp b/rkward/dialogs/rkreadlinedialog.cpp
index 690bc55..771bed1 100644
--- a/rkward/dialogs/rkreadlinedialog.cpp
+++ b/rkward/dialogs/rkreadlinedialog.cpp
@@ -24,11 +24,13 @@
 #include <qdesktopwidget.h>
 #include <QScrollBar>
 #include <QTimer>
+#include <QVBoxLayout>
+#include <QFontDatabase>
+#include <QDialogButtonBox>
+#include <QPushButton>
 
 #include <klocale.h>
-#include <kvbox.h>
 #include <kglobalsettings.h>
-#include <QFontDatabase>
 
 #include "../rbackend/rcommand.h"
 
@@ -36,29 +38,26 @@
 
 QByteArray RKReadLineDialog::stored_geom;
 
-RKReadLineDialog::RKReadLineDialog (QWidget *parent, const QString &caption, const QString &prompt, RCommand *command) : KDialog (parent) {
+RKReadLineDialog::RKReadLineDialog (QWidget *parent, const QString &caption, const QString &prompt, RCommand *command) : QDialog (parent) {
 	RK_TRACE (DIALOGS);
 	RK_ASSERT (command);
 
 	setModal (true);
-	setCaption (caption);
-	setButtons (KDialog::Ok | KDialog::Cancel);
+	setWindowTitle (caption);
+	QVBoxLayout *layout = new QVBoxLayout (this);
 
-	KVBox *page = new KVBox ();
-	setMainWidget (page);
+	layout->addWidget (new QLabel (caption, this));
 
-	new QLabel (caption, page);
-
-	int screen_width = qApp->desktop ()->width () - 2*marginHint() - 2*spacingHint ();		// TODO is this correct on xinerama?
+	int screen_width = qApp->desktop ()->availableGeometry (this).width ();
 
 	QString context = command->fullOutput ();
 	if (!context.isEmpty ()) {
-		new QLabel (i18n ("Context:"), page);
+		layout->addWidget (new QLabel (i18n ("Context:"), this));
 
-		QTextEdit *output = new QTextEdit (page);
+		QTextEdit *output = new QTextEdit (this);
 		output->setUndoRedoEnabled (false);
 		output->setPlainText (QString ());
-		output->setCurrentFont (QFontDatabase::systemFont(QFontDatabase::FixedFont));
+		output->setCurrentFont (QFontDatabase::systemFont (QFontDatabase::FixedFont));
 		output->setLineWrapMode (QTextEdit::NoWrap);
 		output->insertPlainText (context);
 		output->setReadOnly (true);
@@ -67,15 +66,24 @@ RKReadLineDialog::RKReadLineDialog (QWidget *parent, const QString &caption, con
 		output->setMinimumWidth (screen_width < cwidth ? screen_width : cwidth);
 		output->moveCursor (QTextCursor::End);
 		output->setFocusPolicy (Qt::NoFocus);
-		page->setStretchFactor (output, 10);
+		layout->addWidget (output);
+		layout->setStretchFactor (output, 10);
 	}
 
-	QLabel *promptl = new QLabel (prompt, page);
+	QLabel *promptl = new QLabel (prompt, this);
 	promptl->setWordWrap (true);
+	layout->addWidget (promptl);
 
-	input = new QLineEdit (QString (), page);
+	input = new QLineEdit (QString (), this);
 	input->setMinimumWidth (fontMetrics ().maxWidth ()*20);
 	input->setFocus ();
+	layout->addWidget (input);
+
+	QDialogButtonBox *box = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
+	connect (box->button (QDialogButtonBox::Ok), &QPushButton::clicked, this, &QDialog::accept);
+	connect (box->button (QDialogButtonBox::Cancel), &QPushButton::clicked, this, &QDialog::reject);
+	box->button (QDialogButtonBox::Ok)->setShortcut (Qt::CTRL | Qt::Key_Return);
+	layout->addWidget (box);
 }
 
 RKReadLineDialog::~RKReadLineDialog () {
diff --git a/rkward/dialogs/rkreadlinedialog.h b/rkward/dialogs/rkreadlinedialog.h
index 122ed62..6b58cbe 100644
--- a/rkward/dialogs/rkreadlinedialog.h
+++ b/rkward/dialogs/rkreadlinedialog.h
@@ -18,7 +18,7 @@
 #ifndef RKREADLINEDIALOG_H
 #define RKREADLINEDIALOG_H
 
-#include <kdialog.h>
+#include <QDialog>
 
 class QLineEdit;
 class QWidget;
@@ -29,7 +29,7 @@ This dialog displays the question asked, the output context (as often times the
 
 @author Thomas Friedrichsmeier
 */
-class RKReadLineDialog : public KDialog {
+class RKReadLineDialog : public QDialog {
 public:
 	/** Construct and run modal RKReadLineDialog.
 	@param parent QWidget to center the modal dialog on (0 for application)
diff --git a/rkward/dialogs/rkselectlistdialog.cpp b/rkward/dialogs/rkselectlistdialog.cpp
index d972b8c..0af0443 100644
--- a/rkward/dialogs/rkselectlistdialog.cpp
+++ b/rkward/dialogs/rkselectlistdialog.cpp
@@ -19,27 +19,37 @@
 
 #include <QListWidget>
 #include <QLabel>
+#include <QVBoxLayout>
+#include <QDialogButtonBox>
+#include <QPushButton>
+#include <QScrollBar>
 
 #include <klocale.h>
-#include <kvbox.h>
 
 #include "../debug.h"
 
-RKSelectListDialog::RKSelectListDialog (QWidget *parent, const QString &caption, const QStringList& choices, const QStringList& preselected, bool multiple) : KDialog (parent) {
+/** A QListWidget with a sane sizeHint() */
+class RKSelectListDialogListWidget : public QListWidget {
+public:
+	explicit RKSelectListDialogListWidget (QWidget* parent) : QListWidget (parent) {};
+	QSize sizeHint () const override {
+		return (QSize (qMax (50, sizeHintForColumn (0) + verticalScrollBar ()->width ()), qMax (50, sizeHintForRow (0)*(count ()+1))));
+	}
+};
+
+RKSelectListDialog::RKSelectListDialog (QWidget *parent, const QString &caption, const QStringList& choices, const QStringList& preselected, bool multiple) : QDialog (parent) {
 	RK_TRACE (DIALOGS);
 
 	setModal (true);
-	setCaption (caption);
-	setButtons (KDialog::Ok | KDialog::Cancel);
+	setWindowTitle (caption);
 
-	KVBox *page = new KVBox ();
-	setMainWidget (page);
+	QVBoxLayout *layout = new QVBoxLayout (this);
 
-	if (multiple) new QLabel (i18n ("<b>Select one or more:</b>"), page);
-	else new QLabel (i18n ("<b>Select one:</b>"), page);
-	new QLabel (caption, page);
+	if (multiple) layout->addWidget (new QLabel (i18n ("<b>Select one or more:</b>"), this));
+	else layout->addWidget (new QLabel (i18n ("<b>Select one:</b>"), this));
+	layout->addWidget (new QLabel (caption, this));
 
-	input = new QListWidget (page);
+	input = new RKSelectListDialogListWidget (this);
 	input->addItems (choices);
 	if (multiple) input->setSelectionMode (QAbstractItemView::MultiSelection);
 	else input->setSelectionMode (QAbstractItemView::SingleSelection);
@@ -47,12 +57,13 @@ RKSelectListDialog::RKSelectListDialog (QWidget *parent, const QString &caption,
 		int pos = choices.indexOf (preselected[i]);
 		if (pos >= 0) input->item (pos)->setSelected (true);
 	}
+	layout->addWidget (input);
 
-	QSize base_hint = minimumSizeHint ();
-	int other_height = base_hint.height () - input->minimumSizeHint ().height ();	// height of all other things besides the list widget
-	int ideal_height = other_height + qMax (input->sizeHintForRow (0)*input->count (), 50);
-	// KDialog appears to be smart enough to limit this to the available screen geometry
-	setInitialSize (QSize (base_hint.width (), ideal_height));
+	buttons = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
+	connect (buttons->button (QDialogButtonBox::Ok), &QPushButton::clicked, this, &QDialog::accept);
+	connect (buttons->button (QDialogButtonBox::Cancel), &QPushButton::clicked, this, &QDialog::reject);
+	buttons->button (QDialogButtonBox::Ok)->setShortcut (Qt::CTRL | Qt::Key_Return);
+	layout->addWidget (buttons);
 
 	connect (input, &QListWidget::itemSelectionChanged, this, &RKSelectListDialog::updateState);
 	updateState ();
@@ -66,8 +77,7 @@ void RKSelectListDialog::updateState () {
 	RK_TRACE (DIALOGS);
 
 	// TODO is there no QListWidget::hasSelection()?
-	if (input->selectedItems ().isEmpty ()) enableButtonOk (false);
-	else enableButtonOk (true);
+	buttons->button (QDialogButtonBox::Ok)->setEnabled (!input->selectedItems ().isEmpty ());
 }
 
 //static
diff --git a/rkward/dialogs/rkselectlistdialog.h b/rkward/dialogs/rkselectlistdialog.h
index a85c7a8..8af134a 100644
--- a/rkward/dialogs/rkselectlistdialog.h
+++ b/rkward/dialogs/rkselectlistdialog.h
@@ -18,16 +18,16 @@
 #ifndef RKSELECTLISTDIALOG_H
 #define RKSELECTLISTDIALOG_H
 
-#include <kdialog.h>
+#include <QDialog>
 
 class QListWidget;
-class QWidget;
+class QDialogButtonBox;
 
 /** This class represent a dialog asking for a choice among several optiosn. It is used, when the backend calls select.list() / menu().
 
 @author Thomas Friedrichsmeier
 */
-class RKSelectListDialog : public KDialog {
+class RKSelectListDialog : public QDialog {
 	Q_OBJECT
 public:
 	/** Construct and run modal RKSelectListDialog.
@@ -47,6 +47,7 @@ private slots:
 	void updateState ();
 private:
 	QListWidget *input;
+	QDialogButtonBox *buttons;
 };
 
 #endif
diff --git a/rkward/rbackend/rinterface.cpp b/rkward/rbackend/rinterface.cpp
index 1c1402a..4334cb7 100644
--- a/rkward/rbackend/rinterface.cpp
+++ b/rkward/rbackend/rinterface.cpp
@@ -61,6 +61,7 @@ RKWindowCatcher *window_catcher;
 #include <kfiledialog.h>
 #include <klocale.h>
 #include <kstandarddirs.h>
+#include <kdialog.h>
 
 #include <qdir.h>
 #include <qvalidator.h>



More information about the rkward-tracker mailing list