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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Tue Jan 30 00:10:18 UTC 2007


Revision: 1250
          http://svn.sourceforge.net/rkward/?rev=1250&view=rev
Author:   tfry
Date:     2007-01-29 16:10:18 -0800 (Mon, 29 Jan 2007)

Log Message:
-----------
Started working on import filter plugins. No useful state so far, but basic concepts seem to work ok

Modified Paths:
--------------
    trunk/rkward/rkward/plugin/rkcomponentcontext.h
    trunk/rkward/rkward/plugin/rkcomponentmap.cpp
    trunk/rkward/rkward/plugin/rkcomponentmap.h
    trunk/rkward/rkward/plugins/under_development.pluginmap
    trunk/rkward/rkward/rkward.cpp
    trunk/rkward/rkward/rkward.h
    trunk/rkward/rkward/rkwardui.rc

Added Paths:
-----------
    trunk/rkward/rkward/plugins/00saveload/import/
    trunk/rkward/rkward/plugins/00saveload/import/import_spss.php
    trunk/rkward/rkward/plugins/00saveload/import/import_spss.xml

Modified: trunk/rkward/rkward/plugin/rkcomponentcontext.h
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponentcontext.h	2007-01-29 23:40:57 UTC (rev 1249)
+++ trunk/rkward/rkward/plugin/rkcomponentcontext.h	2007-01-30 00:10:18 UTC (rev 1250)
@@ -41,6 +41,7 @@
 	int create (const QDomElement &context_element, const QString &component_namespace);
 /** Create a context handler for this context. */
 	RKContextHandler *makeContextHandler (QObject *parent);
+	QStringList components () { return component_ids; };
 protected:
 	void addedEntry (const QString &id, RKComponentHandle * /* handle */);
 private:

Modified: trunk/rkward/rkward/plugin/rkcomponentmap.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponentmap.cpp	2007-01-29 23:40:57 UTC (rev 1249)
+++ trunk/rkward/rkward/plugin/rkcomponentmap.cpp	2007-01-30 00:10:18 UTC (rev 1250)
@@ -252,7 +252,13 @@
 		} else if (!QFileInfo (filename).isReadable ()) {
 			RK_DO (qDebug ("Specified file '%s' for component id \"%s\" does not exist or is not readable. Ignoring.", filename.latin1 (), id.latin1 ()), PLUGIN, DL_ERROR);
 		} else {
-			components.insert (id, new RKComponentHandle (filename, label, (RKComponentType) type));
+			// create and initialize component handle
+			RKComponentHandle *handle = new RKComponentHandle (filename, label, (RKComponentType) type);
+			XMLChildList attributes_list = xml->getChildElements (*it, "attribute", DL_DEBUG);
+			for (XMLChildList::const_iterator ait=attributes_list.begin (); ait != attributes_list.end (); ++ait) {
+				handle->addAttribute (xml->getStringAttribute (*ait, "id", "noid", DL_WARNING), xml->getStringAttribute (*ait, "value", QString::null, DL_ERROR), xml->getStringAttribute (*ait, "label", QString::null, DL_ERROR));
+			}
+			components.insert (id, handle);
 		}
 	}
 
@@ -311,6 +317,8 @@
 	RKComponentHandle::type = type;
 	RKComponentHandle::filename = filename;
 	RKComponentHandle::label = label;
+
+	attributes = 0;
 }
 
 RKComponentHandle::~RKComponentHandle () {
@@ -337,6 +345,41 @@
 	invoke (0, 0);
 }
 
+QString RKComponentHandle::getAttributeValue (const QString &attribute_id) {
+	RK_TRACE (PLUGIN);
+
+	if (!attributes) return QString ();
+	AttributeMap::const_iterator it = attributes->find (attribute_id);
+	if (it == attributes->constEnd ()) return QString ();
+	return ((*it).first);
+}
+
+QString RKComponentHandle::getAttributeLabel (const QString &attribute_id) {
+	RK_TRACE (PLUGIN);
+
+	if (!attributes) return QString ();
+	AttributeMap::const_iterator it = attributes->find (attribute_id);
+	if (it == attributes->constEnd ()) return QString ();
+	return ((*it).second);
+}
+
+bool RKComponentHandle::hasAttribute (const QString &attribute_id) {
+	RK_TRACE (PLUGIN);
+
+	if (!attributes) return false;
+	return (attributes->contains (attribute_id));
+}
+
+void RKComponentHandle::addAttribute (const QString &id, const QString &value, const QString &label) {
+	RK_TRACE (PLUGIN);
+
+	if (!attributes) {
+		attributes = new AttributeMap;
+	}
+	AttributeValue value_p (value, label);
+	attributes->insert (id, value_p);
+}
+
 ///########################### END RKComponentHandle ###############################
 
 #include "rkcomponentmap.moc"

Modified: trunk/rkward/rkward/plugin/rkcomponentmap.h
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponentmap.h	2007-01-29 23:40:57 UTC (rev 1249)
+++ trunk/rkward/rkward/plugin/rkcomponentmap.h	2007-01-30 00:10:18 UTC (rev 1250)
@@ -47,6 +47,11 @@
 	bool isPlugin ();
 
 	RKComponent *invoke (RKComponent *parent_component, QWidget *parent_widget);
+
+	QString getAttributeValue (const QString &attribute_id);
+	QString getAttributeLabel (const QString &attribute_id);
+	bool hasAttribute (const QString &attribute_id);
+	void addAttribute (const QString &id, const QString &value, const QString &label);
 public slots:
 /** Slot called, when the menu-item for this component is selected. Responsible for creating the GUI. */
 	void activated ();
@@ -55,6 +60,10 @@
 	QString filename;
 	QString label;
 	RKComponentType type;
+
+	typedef QPair<QString, QString> AttributeValue;
+	typedef QMap<QString, AttributeValue> AttributeMap;
+	AttributeMap *attributes;
 };
 
 #include <qmap.h>

Added: trunk/rkward/rkward/plugins/00saveload/import/import_spss.php
===================================================================

Added: trunk/rkward/rkward/plugins/00saveload/import/import_spss.xml
===================================================================

Modified: trunk/rkward/rkward/plugins/under_development.pluginmap
===================================================================
--- trunk/rkward/rkward/plugins/under_development.pluginmap	2007-01-29 23:40:57 UTC (rev 1249)
+++ trunk/rkward/rkward/plugins/under_development.pluginmap	2007-01-30 00:10:18 UTC (rev 1250)
@@ -3,6 +3,10 @@
 <document base_prefix="" namespace="rkward">
 	<components>
 		<component type="standard" id="export_x11_device" file="x11device/export.xml" label="Export..." />
+		<!-- The entry below is bogus for now, still testing some concepts with it -->
+		<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="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" />
@@ -68,5 +72,11 @@
 			<entry component="export_x11_device" />
 		</menu>
 	</context>
+
+	<context id="import">
+		<menu id="import" label="Import">
+			<entry component="import_spss"/>
+		</menu>
+	</context>
 </document>
  

Modified: trunk/rkward/rkward/rkward.cpp
===================================================================
--- trunk/rkward/rkward/rkward.cpp	2007-01-29 23:40:57 UTC (rev 1249)
+++ trunk/rkward/rkward/rkward.cpp	2007-01-30 00:10:18 UTC (rev 1250)
@@ -53,6 +53,7 @@
 #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"
@@ -310,7 +311,8 @@
 	fileOpen = KStdAction::open(this, SLOT(slotOpenCommandEditor()), actionCollection(), "file_openy");
 	fileOpen->setText (i18n ("Open R Script File"));
 	fileOpenRecent = KStdAction::openRecent(this, SLOT(slotOpenCommandEditor (const KURL&)), actionCollection(), "file_open_recenty");
-	
+	KAction *import_data = new KAction (i18n ("Import Data"), 0, 0, this, SLOT (importData ()), actionCollection (), "import_data");
+
 	fileOpenWorkspace = KStdAction::open(this, SLOT(slotFileOpenWorkspace()), actionCollection(), "file_openx");
 	fileOpenWorkspace->setText (i18n ("Open Workspace"));
 	fileOpenWorkspace->setShortcut (KShortcut ("Ctrl+Shift+O"));
@@ -337,6 +339,7 @@
 	makeRKWardHelpMenu (this, actionCollection ());
 
 	new_data_frame->setStatusText (i18n ("Creates new empty dataset and opens it for editing"));
+	import_data->setStatusText (i18n ("Import data from a variety of file formats"));
 	fileOpenWorkspace->setStatusText(i18n("Opens an existing document"));
 	fileOpenRecentWorkspace->setStatusText(i18n("Opens a recently used file"));
 	fileSaveWorkspace->setStatusText(i18n("Saves the actual document"));
@@ -711,7 +714,32 @@
 	}
 }
 
+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
+}
+
 void RKWardMainWindow::slotNewCommandEditor () {
 	RK_TRACE (APP);
 

Modified: trunk/rkward/rkward/rkward.h
===================================================================
--- trunk/rkward/rkward/rkward.h	2007-01-29 23:40:57 UTC (rev 1249)
+++ trunk/rkward/rkward/rkward.h	2007-01-30 00:10:18 UTC (rev 1250)
@@ -150,6 +150,8 @@
 	void slotFileSaveWorkspaceAs();
 	/** shows the dialog to install/load/unload packages */
 	void slotFileLoadLibs ();
+	/** shows the dialog to import data */
+	void importData ();
 	/** close all editor windows */
 	void slotCloseAllEditors ();
 	/** Reimplemented from KParts::MainWindow to be more pretty

Modified: trunk/rkward/rkward/rkwardui.rc
===================================================================
--- trunk/rkward/rkward/rkwardui.rc	2007-01-29 23:40:57 UTC (rev 1249)
+++ trunk/rkward/rkward/rkwardui.rc	2007-01-30 00:10:18 UTC (rev 1250)
@@ -1,5 +1,5 @@
 <!DOCTYPE kpartgui>
-<kpartgui name="rkward" version="0.4.0">
+<kpartgui name="rkward" version="0.4.6">
 <MenuBar>
 	<Menu name="file"><text>&File</text>
 		<Menu name="new_data"><text>&New</text>
@@ -9,7 +9,12 @@
 		<Action name="file_openy"/>
 		<Action name="file_open_recenty"/>
 		<Separator/>
-		<Merge/> 
+		<Menu name="import"><text>&Import</text>
+			<Action name="import_data"/>
+			<Separator/>
+			<Merge/>
+		</Menu>
+		<Merge/>
 		<Separator/>
 		<Action name="file_quitx"/>
 	</Menu>


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