[rkward-cvs] SF.net SVN: rkward: [1252] trunk/rkward/rkward

tfry at users.sourceforge.net tfry at users.sourceforge.net
Tue Jan 30 14:40:43 UTC 2007


Revision: 1252
          http://svn.sourceforge.net/rkward/?rev=1252&view=rev
Author:   tfry
Date:     2007-01-30 06:40:42 -0800 (Tue, 30 Jan 2007)

Log Message:
-----------
More work on import plugins. The basics are done, now. Now we just need some import plugins...

Modified Paths:
--------------
    trunk/rkward/rkward/dialogs/Makefile.am
    trunk/rkward/rkward/plugin/rkcomponentcontext.cpp
    trunk/rkward/rkward/plugin/rkcomponentcontext.h
    trunk/rkward/rkward/plugin/rkcomponentmap.cpp
    trunk/rkward/rkward/plugins/00saveload/import/import_spss.php
    trunk/rkward/rkward/plugins/00saveload/import/import_spss.xml
    trunk/rkward/rkward/plugins/under_development.pluginmap
    trunk/rkward/rkward/rkward.cpp
    trunk/rkward/rkward/rkward.h

Added Paths:
-----------
    trunk/rkward/rkward/dialogs/rkimportdialog.cpp
    trunk/rkward/rkward/dialogs/rkimportdialog.h

Modified: trunk/rkward/rkward/dialogs/Makefile.am
===================================================================
--- trunk/rkward/rkward/dialogs/Makefile.am	2007-01-30 07:14:28 UTC (rev 1251)
+++ trunk/rkward/rkward/dialogs/Makefile.am	2007-01-30 14:40:42 UTC (rev 1252)
@@ -1,5 +1,5 @@
 INCLUDES = $(all_includes)
 METASOURCES = AUTO
 noinst_LIBRARIES =  libdialogs.a
-noinst_HEADERS = startupdialog.h rkloadlibsdialog.h rkreadlinedialog.h
-libdialogs_a_SOURCES = startupdialog.cpp rkloadlibsdialog.cpp rkreadlinedialog.cpp
+noinst_HEADERS = startupdialog.h rkloadlibsdialog.h rkreadlinedialog.h rkimportdialog.h
+libdialogs_a_SOURCES = startupdialog.cpp rkloadlibsdialog.cpp rkreadlinedialog.cpp rkimportdialog.cpp

Added: trunk/rkward/rkward/dialogs/rkimportdialog.cpp
===================================================================
--- trunk/rkward/rkward/dialogs/rkimportdialog.cpp	                        (rev 0)
+++ trunk/rkward/rkward/dialogs/rkimportdialog.cpp	2007-01-30 14:40:42 UTC (rev 1252)
@@ -0,0 +1,122 @@
+/***************************************************************************
+                          rkimportdialog  -  description
+                             -------------------
+    begin                : Tue Jan 30 2007
+    copyright            : (C) 2007 by Thomas Friedrichsmeier
+    email                : tfry at users.sourceforge.net
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#include "rkimportdialog.h"
+
+#include <kmessagebox.h>
+#include <kfilefiltercombo.h>
+#include <klocale.h>
+
+#include <qhbox.h>
+#include <qcombobox.h>
+#include <qlabel.h>
+
+#include "../plugin/rkcomponentmap.h"
+#include "../plugin/rkcomponentcontext.h"
+
+#include "../debug.h"
+
+RKImportDialog::RKImportDialog (const QString &context_id, QWidget *parent) : KFileDialog (QString::null, QString::null, parent, 0, false) {
+	RK_TRACE (DIALOGS);
+
+	context = RKComponentMap::getContext (context_id);
+	if (!context) {
+		KMessageBox::sorry (this, i18n ("No plugins defined for context '%1'").arg (context_id));
+		return;
+	}
+
+	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);
+			continue;
+		}
+
+		QString filter = handle->getAttributeValue ("format");
+		QString label = handle->getAttributeLabel ("format");
+		formats.append (filter + '|' + label + " (" + filter + ')');
+		format_labels.append (label);
+		filters.append (filter);
+	}
+
+	// file format selection box
+	format_selection_box = new QHBox ();
+	new QLabel (i18n ("File format: "), format_selection_box);
+	format_combo = new QComboBox (format_selection_box);
+	format_combo->insertStringList (format_labels);
+
+	// initialize
+	setMode (KFile::File | KFile::ExistingOnly | KFile::LocalOnly);
+	init (QString::null, formats, format_selection_box);
+	connect (filterWidget, SIGNAL (filterChanged ()), this, SLOT (filterChanged ()));
+	filterChanged ();
+	show ();
+}
+
+RKImportDialog::~RKImportDialog () {
+	RK_TRACE (DIALOGS);
+}
+
+void RKImportDialog::filterChanged () {
+	RK_TRACE (DIALOGS);
+
+	int index = filters.findIndex (filterWidget->currentFilter ());
+
+	if (index < 0) {		// All files
+		format_combo->setEnabled (true);
+	} else {
+		format_combo->setEnabled (false);
+		format_combo->setCurrentItem (index);
+	}
+}
+
+void RKImportDialog::slotOk () {
+	RK_TRACE (DIALOGS);
+
+	KFileDialog::slotOk ();
+
+	int index = format_combo->currentItem ();
+	QString cid = component_ids[index];
+	RKComponentHandle *handle = RKComponentMap::getComponentHandle (cid);
+	RKContextHandler *chandler = context->makeContextHandler (this, false);
+
+	if (!(handle && chandler)) {
+		RK_ASSERT (false);
+	} else {
+		RKComponentPropertyBase *filename = new RKComponentPropertyBase (chandler, false);
+		filename->setValue (selectedFile ());
+		chandler->addChild ("filename", filename);
+
+		chandler->invokeComponent (handle);
+	}
+
+	deleteLater ();
+}
+
+void RKImportDialog::slotCancel () {
+	RK_TRACE (DIALOGS);
+
+	KFileDialog::slotCancel ();
+	deleteLater ();
+}
+
+#include "rkimportdialog.moc"

Added: trunk/rkward/rkward/dialogs/rkimportdialog.h
===================================================================
--- trunk/rkward/rkward/dialogs/rkimportdialog.h	                        (rev 0)
+++ trunk/rkward/rkward/dialogs/rkimportdialog.h	2007-01-30 14:40:42 UTC (rev 1252)
@@ -0,0 +1,49 @@
+/***************************************************************************
+                          rkimportdialog  -  description
+                             -------------------
+    begin                : Tue Jan 30 2007
+    copyright            : (C) 2007 by Thomas Friedrichsmeier
+    email                : tfry at users.sourceforge.net
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#ifndef RKIMPORTDIALOG_H
+#define RKIMPORTDIALOG_H
+
+#include <kfiledialog.h>
+
+#include <qstringlist.h>
+
+class QHBox;
+class QComboBox;
+class RKContextMap;
+
+class RKImportDialog : public KFileDialog {
+	Q_OBJECT
+public:
+	RKImportDialog (const QString &context_id, QWidget *parent);
+	~RKImportDialog ();
+public slots:
+	void filterChanged ();
+protected:
+	void slotOk ();
+	void slotCancel ();
+private:
+	int format_count;
+	QHBox *format_selection_box;
+	QComboBox *format_combo;
+	QStringList format_labels;
+	QStringList filters;
+	QStringList component_ids;
+	RKContextMap *context;
+};
+
+#endif

Modified: trunk/rkward/rkward/plugin/rkcomponentcontext.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponentcontext.cpp	2007-01-30 07:14:28 UTC (rev 1251)
+++ trunk/rkward/rkward/plugin/rkcomponentcontext.cpp	2007-01-30 14:40:42 UTC (rev 1252)
@@ -41,14 +41,16 @@
 	return (createMenus (element, context_element, component_namespace));
 }
 
-RKContextHandler *RKContextMap::makeContextHandler (QObject *parent) {
+RKContextHandler *RKContextMap::makeContextHandler (QObject *parent, bool create_actions) {
 	RK_TRACE (PLUGIN);
 
 	RKContextHandler *handler = new RKContextHandler (parent, gui_xml, id);
-	for (QStringList::const_iterator it = component_ids.constBegin (); it != component_ids.constEnd (); ++it) {
-		RKComponentHandle *handle = RKComponentMap::getComponentHandle (*it);
-		if (handle->isPlugin ()) {
-			handler->addAction (*it, handle);
+	if (create_actions) {
+		for (QStringList::const_iterator it = component_ids.constBegin (); it != component_ids.constEnd (); ++it) {
+			RKComponentHandle *handle = RKComponentMap::getComponentHandle (*it);
+			if (handle->isPlugin ()) {
+				handler->addAction (*it, handle);
+			}
 		}
 	}
 	return handler;
@@ -95,6 +97,13 @@
 		return;
 	}
 
+	invokeComponent (handle);
+}
+
+void RKContextHandler::invokeComponent (RKComponentHandle *handle) {
+	RK_TRACE (PLUGIN);
+	RK_ASSERT (handle);
+
 	// create component
 	RKComponent *component = handle->invoke (0, 0);
 

Modified: trunk/rkward/rkward/plugin/rkcomponentcontext.h
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponentcontext.h	2007-01-30 07:14:28 UTC (rev 1251)
+++ trunk/rkward/rkward/plugin/rkcomponentcontext.h	2007-01-30 14:40:42 UTC (rev 1252)
@@ -40,7 +40,7 @@
 /** A menu entries to the context map from a .pluginmap file */
 	int create (const QDomElement &context_element, const QString &component_namespace);
 /** Create a context handler for this context. */
-	RKContextHandler *makeContextHandler (QObject *parent);
+	RKContextHandler *makeContextHandler (QObject *parent, bool create_actions=true);
 	QStringList components () { return component_ids; };
 protected:
 	void addedEntry (const QString &id, RKComponentHandle * /* handle */);
@@ -64,6 +64,8 @@
 class RKContextHandler : public QObject, public RKComponentBase, public KXMLGUIClient {
 	Q_OBJECT
 friend class RKContextMap;
+public:
+	void invokeComponent (RKComponentHandle *handle);
 protected:
 /** constructor. Protected. Use RKContextMap::makeContextHandler() instead. */
 	RKContextHandler (QObject *parent, const QDomDocument &gui_xml, const QString &id);

Modified: trunk/rkward/rkward/plugin/rkcomponentmap.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponentmap.cpp	2007-01-30 07:14:28 UTC (rev 1251)
+++ trunk/rkward/rkward/plugin/rkcomponentmap.cpp	2007-01-30 14:40:42 UTC (rev 1252)
@@ -323,6 +323,8 @@
 
 RKComponentHandle::~RKComponentHandle () {
 	RK_TRACE (PLUGIN);
+
+	delete attributes;
 }
 
 bool RKComponentHandle::isPlugin () {

Modified: trunk/rkward/rkward/plugins/00saveload/import/import_spss.php
===================================================================
--- trunk/rkward/rkward/plugins/00saveload/import/import_spss.php	2007-01-30 07:14:28 UTC (rev 1251)
+++ trunk/rkward/rkward/plugins/00saveload/import/import_spss.php	2007-01-30 14:40:42 UTC (rev 1252)
@@ -0,0 +1,19 @@
+<?php
+function preprocess () { ?>
+require (foreign)
+<?
+}
+
+function calculate () {
+?>
+print ("<? getRK ("file"); ?>")
+<?
+}
+	
+function printout () {
+}
+	
+function cleanup () {
+?><?
+}
+?>

Modified: trunk/rkward/rkward/plugins/00saveload/import/import_spss.xml
===================================================================
--- trunk/rkward/rkward/plugins/00saveload/import/import_spss.xml	2007-01-30 07:14:28 UTC (rev 1251)
+++ trunk/rkward/rkward/plugins/00saveload/import/import_spss.xml	2007-01-30 14:40:42 UTC (rev 1252)
@@ -0,0 +1,23 @@
+<!DOCTYPE rkplugin>
+<document>
+	<code file="import_spss.php" />
+	<logic>
+		<external id="filename"/>
+		<connect governor="filename" client="file.selection"/>
+		
+		<connect governor="use_labels.state" client="labels_limit.enabled"/>
+		<connect governor="use_labels.state" client="trim_labels.enabled"/>
+	</logic>
+	<dialog label="Import SPSS file">
+		<browser size="small" id="file" label="File name" />
+		<stretch/>
+		<text>TODO: add selector for object to save to, here</text>
+		<stretch/>
+		<checkbox id="data_frame" checked="true" label="Import as a data.frame"/>
+		<frame label="Labels">
+			<checkbox id="use_labels" checked="true" label="Use value labels"/>
+			<spinbox id="labels_limit" type="integer" initial="1000000" min="1" label="Maximum number of labels per object" />
+			<checkbox id="trim_labels" checked="false" label="Trim white space"/>
+		</frame>
+	</dialog>
+</document>

Modified: trunk/rkward/rkward/plugins/under_development.pluginmap
===================================================================
--- trunk/rkward/rkward/plugins/under_development.pluginmap	2007-01-30 07:14:28 UTC (rev 1251)
+++ trunk/rkward/rkward/plugins/under_development.pluginmap	2007-01-30 14:40:42 UTC (rev 1252)
@@ -7,6 +7,9 @@
 		<component type="standard" id="import_spss" file="00saveload/import/import_spss.xml" label="Import SPSS">
 			<attribute id="format" value="*.sav" label="SPSS data files"/>
 		</component>
+		<component type="standard" id="import_csv" file="00saveload/import/import_spss.xml" label="Import SPSS">
+			<attribute id="format" value="*.txt *.csv" label="Comma Separate Values"/>
+		</component>
 
 		<component type="standard" id="wilcoxon_test" file="analysis/wilcoxon/wilcoxon_test.xml" label="Wilcoxon Test" />
 		<component type="standard" id="wilcoxon_exact_test" file="analysis/wilcoxon/wilcoxon_exact_test.xml" label="Wilcoxon exact test" />
@@ -76,6 +79,7 @@
 	<context id="import">
 		<menu id="import" label="Import">
 			<entry component="import_spss"/>
+			<entry component="import_csv"/>
 		</menu>
 	</context>
 </document>

Modified: trunk/rkward/rkward/rkward.cpp
===================================================================
--- trunk/rkward/rkward/rkward.cpp	2007-01-30 07:14:28 UTC (rev 1251)
+++ trunk/rkward/rkward/rkward.cpp	2007-01-30 14:40:42 UTC (rev 1252)
@@ -53,7 +53,6 @@
 #include "rkward.h"
 #include "core/rkmodificationtracker.h"
 #include "plugin/rkcomponentmap.h"
-#include "plugin/rkcomponentcontext.h"
 #include "settings/rksettings.h"
 #include "settings/rksettingsmoduleplugins.h"
 #include "settings/rksettingsmodulegeneral.h"
@@ -65,6 +64,7 @@
 #include "robjectbrowser.h"
 #include "dialogs/startupdialog.h"
 #include "dialogs/rkloadlibsdialog.h"
+#include "dialogs/rkimportdialog.h"
 #include "agents/rksaveagent.h"
 #include "agents/rkloadagent.h"
 #include "agents/rkquitagent.h"
@@ -717,27 +717,7 @@
 void RKWardMainWindow::importData () {
 	RK_TRACE (APP);
 
-	RKContextMap *import_context = RKComponentMap::getContext ("import");
-	if (!import_context) {
-		KMessageBox::sorry (this, i18n ("No import plugins defined"));
-		return;
-	}
-
-	QStringList ids = import_context->components ();
-	QString formats = "*|" + i18n ("All Files") + " (*)\n";
-	for (QStringList::const_iterator it = ids.constBegin (); it != ids.constEnd (); ++it) {
-		RKComponentHandle *handle = RKComponentMap::getComponentHandle (*it);
-		if (!handle) {
-			RK_ASSERT (false);
-			continue;
-		}
-		QString filter = handle->getAttributeValue ("format");
-		formats.append (filter + '|' + handle->getAttributeLabel ("format") + " (" + filter + ")\n");
-	}
-
-	// this is not correct! we need a customized class for this, as we need to select the import filter to use at the same time
-	QString filename = KFileDialog::getOpenFileName (QString::null, formats, this);
-#warning TODO
+	new RKImportDialog ("import", this);
 }
 
 void RKWardMainWindow::slotNewCommandEditor () {

Modified: trunk/rkward/rkward/rkward.h
===================================================================
--- trunk/rkward/rkward/rkward.h	2007-01-30 07:14:28 UTC (rev 1251)
+++ trunk/rkward/rkward/rkward.h	2007-01-30 14:40:42 UTC (rev 1252)
@@ -2,7 +2,7 @@
 			rkward.h  -  description
 			-------------------
 begin                : Tue Oct 29 20:06:08 CET 2002 
-copyright            : (C) 2002, 2005, 2006 by Thomas Friedrichsmeier 
+copyright            : (C) 2002, 2005, 2006, 2007 by Thomas Friedrichsmeier 
 email                : tfry at users.sourceforge.net
 ***************************************************************************/
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rkward-tracker mailing list