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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Wed Apr 25 18:56:36 UTC 2007


Revision: 1850
          http://svn.sourceforge.net/rkward/?rev=1850&view=rev
Author:   tfry
Date:     2007-04-25 11:56:35 -0700 (Wed, 25 Apr 2007)

Log Message:
-----------
Instead of <include>ing pluginmaps into each other, they can now <require> each other.
The difference is, that the required file will only be loaded once, even if required from many places.

Modified Paths:
--------------
    trunk/rkward/doc/en/writing_plugins_introduction.docbook
    trunk/rkward/rkward/plugin/rkcomponentmap.cpp
    trunk/rkward/rkward/plugin/rkcomponentmap.h
    trunk/rkward/rkward/plugins/Makefile.am
    trunk/rkward/rkward/plugins/all.pluginmap
    trunk/rkward/rkward/plugins/plots.pluginmap
    trunk/rkward/rkward/plugins/x11device.pluginmap

Modified: trunk/rkward/doc/en/writing_plugins_introduction.docbook
===================================================================
--- trunk/rkward/doc/en/writing_plugins_introduction.docbook	2007-04-25 16:37:35 UTC (rev 1849)
+++ trunk/rkward/doc/en/writing_plugins_introduction.docbook	2007-04-25 18:56:35 UTC (rev 1850)
@@ -41,8 +41,8 @@
      and in the FDL itself on how to use it. -->
 <legalnotice>&FDLNotice;</legalnotice>
 
-<date>2007-03-30</date>
-<releaseinfo>0.4.7.00</releaseinfo>
+<date>2007-04-25</date>
+<releaseinfo>0.4.8.00</releaseinfo>
 
 <abstract>
 <para>
@@ -63,7 +63,7 @@
 <title>Introduction</title>
 
 <para>
-Documentation as of &kapp; release 0.4.7.
+Documentation as of &kapp; release 0.4.8.
 </para>
 <para>
 This document describes how to write your own plugins. Note, that at the time of this writing, none of the concepts are set it stone. Therefore, this document should be regarded as an introduction to the current approach, and as a basis for discussion. All sorts of comments are welcome.
@@ -2020,8 +2020,8 @@
 	</variablelist></listitem>
 </varlistentry>
 <varlistentry>
-<term><include></term>
-<listitem>Include another .pluginmap file. The most important use case is to provide a "default" selection of plugins in the &kapp; distribution, even if these plugins are defined in several separate .pluginmap files (see all.pluginmap). <include>-elements are only allowed as direct children of the <document>-node. Attributes:
+<term><require></term>
+<listitem>Include another .pluginmap file. This .pluginmap file is only loaded once, even if it is <require>d from several other files. The most important use case is to include a pluginmap file, which declares some comopnents, which are embedded by components declared in this .pluginmap. <require>-elements are only allowed as direct children of the <document>-node. Attributes:
 	<variablelist>
 	<varlistentry>
 	<term>file</term>

Modified: trunk/rkward/rkward/plugin/rkcomponentmap.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponentmap.cpp	2007-04-25 16:37:35 UTC (rev 1849)
+++ trunk/rkward/rkward/plugin/rkcomponentmap.cpp	2007-04-25 18:56:35 UTC (rev 1850)
@@ -18,6 +18,7 @@
 #include "rkcomponentmap.h"
 
 #include <qfileinfo.h>
+#include <qdir.h>
 
 #include <klocale.h>
 
@@ -27,6 +28,10 @@
 #include "../rkglobals.h"
 #include "../rkward.h"
 
+QString RKPluginMapFile::makeFileName (const QString &filename) {
+	return QDir (basedir).filePath (filename);
+}
+
 RKComponentGUIXML::RKComponentGUIXML () {
 	RK_TRACE (PLUGIN);
 
@@ -153,6 +158,11 @@
 	}
 	components.clear ();
 
+	for (PluginMapFileMap::const_iterator it = pluginmapfiles.constBegin (); it != pluginmapfiles.constEnd (); ++it) {
+		delete (it.data ());
+	}
+	pluginmapfiles.clear ();
+
 	clearGUIDescription ();
 
 	setXMLGUIBuildDocument (gui_xml);
@@ -227,33 +237,58 @@
 int RKComponentMap::addPluginMapLocal (const QString& plugin_map_file) {
 	RK_TRACE (PLUGIN);
 
+	QString plugin_map_file_abs = QFileInfo (plugin_map_file).absFilePath ();
+	if (pluginmapfiles.contains (plugin_map_file_abs)) {
+		RK_DO (qDebug ("Plugin map file '%s' already loaded", plugin_map_file.latin1()), PLUGIN, DL_INFO);
+		return 0;
+	}
+
 	XMLHelper* xml = XMLHelper::getStaticHelper ();
 	QDomElement element;
 	XMLChildList list;
 
-	QDomElement document_element = xml->openXMLFile (plugin_map_file, DL_ERROR);
+	QDomElement document_element = xml->openXMLFile (plugin_map_file_abs, DL_ERROR);
 	if (xml->highestError () >= DL_ERROR) return (0);
 
-	QString prefix = QFileInfo (plugin_map_file).dirPath (true) + '/' + xml->getStringAttribute (document_element, "base_prefix", QString::null, DL_INFO);
+	QString prefix = QFileInfo (plugin_map_file_abs).dirPath (true) + '/' + xml->getStringAttribute (document_element, "base_prefix", QString::null, DL_INFO);
 	QString cnamespace = xml->getStringAttribute (document_element, "namespace", "rkward", DL_INFO) + "::";
 
-	// step 1: create (list of) components
+	RKPluginMapFile *pluginmap_file_desc = new RKPluginMapFile (prefix);
+	pluginmapfiles.insert (QFileInfo (plugin_map_file).absFilePath (), pluginmap_file_desc);
+
+	// step 1: include required files
+	int counter;
+	QStringList includelist;
+	list = xml->getChildElements (document_element, "require", DL_INFO);
+	for (XMLChildList::const_iterator it=list.constBegin (); it != list.constEnd (); ++it) {
+		QString file = pluginmap_file_desc->makeFileName (xml->getStringAttribute (*it, "file", QString::null, DL_ERROR));
+		if (QFileInfo (file).isReadable ()) {
+			includelist.append (file);
+		} else {
+			RK_DO (qDebug ("Specified required file '%s' does not exist or is not readable. Ignoring.", file.latin1 ()), PLUGIN, DL_ERROR);
+		}
+	}
+	for (QStringList::const_iterator it = includelist.constBegin (); it != includelist.constEnd (); ++it) {
+		counter += addPluginMapLocal (*it);
+	}
+
+	// step 2: create (list of) components
 	element = xml->getChildElement (document_element, "components", DL_INFO);
 	list = xml->getChildElements (element, "component", DL_INFO);
 
 	for (XMLChildList::const_iterator it=list.begin (); it != list.end (); ++it) {
-		QString filename = prefix + xml->getStringAttribute((*it), "file", QString::null, DL_WARNING);
+		QString filename = xml->getStringAttribute((*it), "file", QString::null, DL_WARNING);
 		QString id = cnamespace + xml->getStringAttribute((*it), "id", QString::null, DL_WARNING);
 		int type = xml->getMultiChoiceAttribute ((*it), "type", "standard", 0, DL_WARNING);
 		QString label = xml->getStringAttribute ((*it), "label", i18n ("(no label)"), DL_WARNING);
 
 		if (components.contains (id)) {
 			RK_DO (qDebug ("RKComponentMap already contains a component with id \"%s\". Ignoring second entry.", id.latin1 ()), PLUGIN, DL_WARNING);
-		} else if (!QFileInfo (filename).isReadable ()) {
+		} else if (!QFileInfo (pluginmap_file_desc->makeFileName (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 {
 			// create and initialize component handle
-			RKComponentHandle *handle = new RKComponentHandle (filename, label, (RKComponentType) type);
+			RKComponentHandle *handle = new RKComponentHandle (pluginmap_file_desc, 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));
@@ -262,11 +297,11 @@
 		}
 	}
 
-	// step 2: create / insert into menus
+	// step 3: create / insert into menus
 	QDomElement xmlgui_menubar_element = xml->getChildElement (gui_xml.documentElement (), "MenuBar", DL_ERROR);
-	int counter = createMenus (xmlgui_menubar_element, xml->getChildElement (document_element, "hierarchy", DL_INFO), cnamespace);
+	counter = createMenus (xmlgui_menubar_element, xml->getChildElement (document_element, "hierarchy", DL_INFO), cnamespace);
 
-	// step 3: create and register contexts
+	// step 4: create and register contexts
 	list = xml->getChildElements (document_element, "context", DL_INFO);
 	for (XMLChildList::const_iterator it=list.constBegin (); it != list.constEnd (); ++it) {
 		QString id = xml->getStringAttribute (*it, "id", QString::null, DL_ERROR);
@@ -279,21 +314,6 @@
 		counter += context->create (*it, cnamespace);
 	}
 
-	// step 4: included files
-	QStringList includelist;
-	list = xml->getChildElements (document_element, "include", DL_INFO);
-	for (XMLChildList::const_iterator it=list.constBegin (); it != list.constEnd (); ++it) {
-		QString file = prefix + xml->getStringAttribute (*it, "file", QString::null, DL_ERROR);
-		if (QFileInfo (file).isReadable ()) {
-			includelist.append (file);
-		} else {
-			RK_DO (qDebug ("Specified include file '%s' does not exist or is not readable. Ignoring.", file.latin1 ()), PLUGIN, DL_ERROR);
-		}
-	}
-	for (QStringList::const_iterator it = includelist.constBegin (); it != includelist.constEnd (); ++it) {
-		counter += addPluginMap (*it);
-	}
-
 	setXMLGUIBuildDocument (gui_xml);
 	return counter;
 }
@@ -311,12 +331,13 @@
 
 #include "rkstandardcomponent.h"
 
-RKComponentHandle::RKComponentHandle (const QString &filename, const QString &label, RKComponentType type) : QObject (RKWardMainWindow::getMain ()) {
+RKComponentHandle::RKComponentHandle (RKPluginMapFile *pluginmap, const QString &rel_filename, const QString &label, RKComponentType type) : QObject (RKWardMainWindow::getMain ()) {
 	RK_TRACE (PLUGIN);
 
 	RKComponentHandle::type = type;
-	RKComponentHandle::filename = filename;
+	RKComponentHandle::filename = rel_filename;
 	RKComponentHandle::label = label;
+	RKComponentHandle::plugin_map = pluginmap;
 
 	attributes = 0;
 }

Modified: trunk/rkward/rkward/plugin/rkcomponentmap.h
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponentmap.h	2007-04-25 16:37:35 UTC (rev 1849)
+++ trunk/rkward/rkward/plugin/rkcomponentmap.h	2007-04-25 18:56:35 UTC (rev 1850)
@@ -18,12 +18,25 @@
 #ifndef RKCOMPONENTMAP_H
 #define RKCOMPONENTMAP_H
 
+#include <qstring.h>
+
+/** very simple helper class to keep track of .pluginmap files */
+class RKPluginMapFile {
+public:
+	RKPluginMapFile (const QString &basedir) { RKPluginMapFile::basedir = basedir; };
+	~RKPluginMapFile () {};
+
+	QString getBaseDir () { return basedir; };
+	QString makeFileName (const QString &filename);
+private:
+	QString basedir;
+};
+
 /** enum of different types of RKComponent */
 enum RKComponentType {
 	Standard=0		/// the only type available so far. Classifies a component that can be used standalone, and is not special in any way. Of course, as long as there is only one category of component, this is fairly meaningless. It's meant for future features.
 };
 
-#include <qstring.h>
 #include <qobject.h>
 
 class RKComponent;
@@ -37,11 +50,11 @@
 class RKComponentHandle : public QObject {
 	Q_OBJECT
 public:
-	RKComponentHandle (const QString &filename, const QString &label, RKComponentType type);
+	RKComponentHandle (RKPluginMapFile *pluginmap, const QString &rel_filename, const QString &label, RKComponentType type);
 
 	virtual ~RKComponentHandle ();
 
-	QString getFilename () { return filename; };
+	QString getFilename () { return plugin_map->makeFileName (filename); };
 	QString getLabel () { return label; };
 	RKComponentType getType () { return type; };
 	bool isPlugin ();
@@ -56,7 +69,9 @@
 /** Slot called, when the menu-item for this component is selected. Responsible for creating the GUI. */
 	void activated ();
 protected:
-/** The filename of the description file for this component */
+/** The plugin map where this component was declared */
+	RKPluginMapFile *plugin_map;
+/** The filename relative to the pluginmap file */
 	QString filename;
 	QString label;
 	RKComponentType type;
@@ -160,6 +175,9 @@
 	typedef QMap<QString, RKContextMap*> RKComponentContextMap;
 	RKComponentContextMap contexts;
 
+	typedef QMap<QString, RKPluginMapFile*> PluginMapFileMap;
+	PluginMapFileMap pluginmapfiles;
+
 	static RKComponentMap *component_map;
 protected:
 	void addedEntry (const QString &id, RKComponentHandle *handle);

Modified: trunk/rkward/rkward/plugins/Makefile.am
===================================================================
--- trunk/rkward/rkward/plugins/Makefile.am	2007-04-25 16:37:35 UTC (rev 1849)
+++ trunk/rkward/rkward/plugins/Makefile.am	2007-04-25 18:56:35 UTC (rev 1850)
@@ -3,6 +3,7 @@
 	all.pluginmap \
 	plots.pluginmap \
 	distributions.pluginmap \
+	embedded.pluginmap \
 	analysis.pluginmap \
 	x11device.pluginmap \
 	import_export.pluginmap \
@@ -30,6 +31,8 @@
 	plots/barplot.rkh \
 	plots/barplot.php \
 	plots/barplot.xml \
+	plots/piechart.xml \
+	plots/piechart.php \
 	plots/plot.php \
 	plots/plot.rkh \
 	plots/plot.xml \
@@ -54,9 +57,7 @@
 	plots/plot_stepfun_options.xml \
 	plots/plot_stepfun_options.php \
 	plots/histogram.rkh \
-	plots/ecdf_plot.rkh \
-	plots/piechart.php \
-	plots/piechart.xml
+	plots/ecdf_plot.rkh
 
 pluginsXdistributionsdir = $(kde_datadir)/rkward/distributions
 dist_pluginsXdistributions_DATA = \
@@ -323,12 +324,12 @@
 dist_pluginsXanalysis_DATA = \
 	analysis/corr_matrix.php \
 	analysis/corr_matrix.xml \
+	analysis/crosstab.xml \
 	analysis/corr_matrix.rkh \
+	analysis/crosstab.php \
 	analysis/t_test_two_vars.rkh \
 	analysis/t_test_two_vars.xml \
-	analysis/t_test_two_vars.php \
-	analysis/crosstab.php \
-	analysis/crosstab.xml
+	analysis/t_test_two_vars.php
 
 pluginsXanalysisXansariUbradleydir = $(kde_datadir)/rkward/analysis/ansari_bradley
 dist_pluginsXanalysisXansariUbradley_DATA = \

Modified: trunk/rkward/rkward/plugins/all.pluginmap
===================================================================
--- trunk/rkward/rkward/plugins/all.pluginmap	2007-04-25 16:37:35 UTC (rev 1849)
+++ trunk/rkward/rkward/plugins/all.pluginmap	2007-04-25 18:56:35 UTC (rev 1850)
@@ -1,9 +1,9 @@
 <!DOCTYPE rkpluginmap>
 
 <document base_prefix="" namespace="rkward">
-	<include file="import_export.pluginmap"/>
-	<include file="analysis.pluginmap"/>
-	<include file="distributions.pluginmap"/>
-	<include file="plots.pluginmap"/>
-	<include file="x11device.pluginmap"/>
+	<require file="import_export.pluginmap"/>
+	<require file="analysis.pluginmap"/>
+	<require file="distributions.pluginmap"/>
+	<require file="plots.pluginmap"/>
+	<require file="x11device.pluginmap"/>
 </document>

Modified: trunk/rkward/rkward/plugins/plots.pluginmap
===================================================================
--- trunk/rkward/rkward/plugins/plots.pluginmap	2007-04-25 16:37:35 UTC (rev 1849)
+++ trunk/rkward/rkward/plugins/plots.pluginmap	2007-04-25 18:56:35 UTC (rev 1850)
@@ -13,12 +13,6 @@
 		<component type="standard" id="scatterplot_matrix" file="scatterplot_matrix.xml" label="Scatterplot Matrix" />
 		<component type="standard" id="stem" file="stem.xml" label="Stem-and-Leaf Plot" />
 		<component type="standard" id="stripchart" file="stripchart_plot.xml" label="Stripchart" />
-
-		<!-- These are meant to be embedded, and are not shown in the menu -->
-		<component type="standard" id="plot_options" file="plot_options.xml" label="Plot Options" />
-		<component type="standard" id="color_chooser" file="color_chooser.xml" label="Color Chooser" />
-		<component type="standard" id="plot_stepfun_options" file="plot_stepfun_options.xml" label="Step Function plot options" />
-		<component type="standard" id="histogram_options" file="histogram_options.xml" label="Histogram Options" />
 	</components>
 
 	<hierarchy>
@@ -36,4 +30,6 @@
 			<entry component="stripchart" />
 		</menu>
 	</hierarchy>
+
+	<require file="../embedded.pluginmap"/>
 </document>

Modified: trunk/rkward/rkward/plugins/x11device.pluginmap
===================================================================
--- trunk/rkward/rkward/plugins/x11device.pluginmap	2007-04-25 16:37:35 UTC (rev 1849)
+++ trunk/rkward/rkward/plugins/x11device.pluginmap	2007-04-25 18:56:35 UTC (rev 1850)
@@ -3,18 +3,16 @@
 <document base_prefix="x11device/" namespace="rkward">
 	<components>
 		<component type="standard" id="export_x11_device" file="export.xml" label="Export..." />
-
-		<!-- This one is slightly misplaced right now. Since it can be embedded in plots, and works standalone as an x11device plugin, it does not really belong to either pluginmap. Fix this after 0.4.7 -->
-		<component type="standard" id="x11grid" file="grid.xml" label="Draw Grid" />
 	</components>
 
 	<context id="x11">
 		<menu id="device" label="Device" index="1">
 			<entry component="export_x11_device" />
 		</menu>
-		<!-- see above -->
 		<menu id="edit" label="Edit" index="3">
 			<entry component="x11grid" />
 		</menu>
 	</context>
+
+	<require file="../embedded.pluginmap"/>
 </document>


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