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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Mon Nov 27 15:16:56 UTC 2006


Revision: 948
          http://svn.sourceforge.net/rkward/?rev=948&view=rev
Author:   tfry
Date:     2006-11-27 07:16:55 -0800 (Mon, 27 Nov 2006)

Log Message:
-----------
Implement storing x11 device to R object

Modified Paths:
--------------
    trunk/rkward/rkward/core/rcontainerobject.cpp
    trunk/rkward/rkward/core/rcontainerobject.h
    trunk/rkward/rkward/core/robjectlist.cpp
    trunk/rkward/rkward/core/robjectlist.h
    trunk/rkward/rkward/misc/Makefile.am
    trunk/rkward/rkward/windows/rkwindowcatcher.cpp

Added Paths:
-----------
    trunk/rkward/rkward/misc/rksaveobjectchooser.cpp
    trunk/rkward/rkward/misc/rksaveobjectchooser.h

Modified: trunk/rkward/rkward/core/rcontainerobject.cpp
===================================================================
--- trunk/rkward/rkward/core/rcontainerobject.cpp	2006-11-27 13:59:58 UTC (rev 947)
+++ trunk/rkward/rkward/core/rcontainerobject.cpp	2006-11-27 15:16:55 UTC (rev 948)
@@ -353,16 +353,18 @@
 	return false;
 }
 
-QString RContainerObject::validizeName (const QString &child_name) {
+QString RContainerObject::validizeName (const QString &child_name, bool unique) {
 	RK_TRACE (OBJECTS);
 	QString ret = child_name;
 	ret = ret.replace (QRegExp ("[^a-zA-Z0-9]"), ".");
 	ret = ret.replace (QRegExp ("^\\.*[0-9]+"), ".");
 	if (ret.isEmpty ()) ret = "var";
 	int i=-1;
+
+	if (!unique) return ret;
 	QString postfix;
 	while (childmap.contains (ret + postfix)) {
 		postfix.setNum (++i);
 	}
-	return (ret +postfix);
+	return (ret + postfix);
 }

Modified: trunk/rkward/rkward/core/rcontainerobject.h
===================================================================
--- trunk/rkward/rkward/core/rcontainerobject.h	2006-11-27 13:59:58 UTC (rev 947)
+++ trunk/rkward/rkward/core/rcontainerobject.h	2006-11-27 15:16:55 UTC (rev 948)
@@ -59,7 +59,7 @@
 	bool isEmpty () { return childmap.isEmpty (); };
 
 	/** given child_name, constructs a name which is as close as possible to the orginial but valid (i.e. not alreay in use, not contaning illegal characters */
-	virtual QString validizeName (const QString &child_name);
+	virtual QString validizeName (const QString &child_name, bool unique=true);
 
 	/** reimplemented from RObject to actually search for the object */
 	virtual RObject *findObject (const QString &name, bool is_canonified=false);

Modified: trunk/rkward/rkward/core/robjectlist.cpp
===================================================================
--- trunk/rkward/rkward/core/robjectlist.cpp	2006-11-27 13:59:58 UTC (rev 947)
+++ trunk/rkward/rkward/core/robjectlist.cpp	2006-11-27 15:16:55 UTC (rev 948)
@@ -231,10 +231,10 @@
 	return (getGlobalEnv ()->createNewChild (name, creator, container, data_frame));
 }
 
-QString RObjectList::validizeName (const QString &child_name) {
+QString RObjectList::validizeName (const QString &child_name, bool unique) {
 	RK_TRACE (OBJECTS);
 
-	return (getGlobalEnv ()->validizeName (child_name));
+	return (getGlobalEnv ()->validizeName (child_name, unique));
 }
 
 bool RObjectList::updateStructure (RData *) {

Modified: trunk/rkward/rkward/core/robjectlist.h
===================================================================
--- trunk/rkward/rkward/core/robjectlist.h	2006-11-27 13:59:58 UTC (rev 947)
+++ trunk/rkward/rkward/core/robjectlist.h	2006-11-27 15:16:55 UTC (rev 948)
@@ -62,7 +62,7 @@
 	RObject *createNewChild (const QString &name, RKEditor *creator=0, bool container=false, bool data_frame=false);
 
 	/** reimplemented from RContainerObject to validize the name in .GlobalEnv */
-	QString validizeName (const QString &child_name);
+	QString validizeName (const QString &child_name, bool unique=true);
 
 	KURL getWorkspaceURL () { return current_url; };
 

Modified: trunk/rkward/rkward/misc/Makefile.am
===================================================================
--- trunk/rkward/rkward/misc/Makefile.am	2006-11-27 13:59:58 UTC (rev 947)
+++ trunk/rkward/rkward/misc/Makefile.am	2006-11-27 15:16:55 UTC (rev 948)
@@ -2,9 +2,9 @@
 METASOURCES = AUTO
 noinst_LIBRARIES =  libmisc.a
 libmisc_a_SOURCES = rkerrordialog.cpp rkspinbox.cpp \
-			getfilenamewidget.cpp rkobjectlistview.cpp rkcanceldialog.cpp xmlhelper.cpp \
-	multistringselector.cpp rkcommonfunctions.cpp rkprogresscontrol.cpp
+	getfilenamewidget.cpp rkobjectlistview.cpp rkcanceldialog.cpp xmlhelper.cpp \
+	multistringselector.cpp rkcommonfunctions.cpp rkprogresscontrol.cpp rksaveobjectchooser.cpp
 noinst_HEADERS = rkerrordialog.h rkspinbox.h getfilenamewidget.h \
 	rkobjectlistview.h rkcanceldialog.h xmlhelper.h multistringselector.h \
-	rkcommonfunctions.h rkprogresscontrol.h
+	rkcommonfunctions.h rkprogresscontrol.h rksaveobjectchooser.h
 

Added: trunk/rkward/rkward/misc/rksaveobjectchooser.cpp
===================================================================
--- trunk/rkward/rkward/misc/rksaveobjectchooser.cpp	                        (rev 0)
+++ trunk/rkward/rkward/misc/rksaveobjectchooser.cpp	2006-11-27 15:16:55 UTC (rev 948)
@@ -0,0 +1,106 @@
+/***************************************************************************
+                          rksaveobjectchooser  -  description
+                             -------------------
+    begin                : Mon Nov 27 2006
+    copyright            : (C) 2006 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 "rksaveobjectchooser.h"
+
+#include <qlineedit.h>
+#include <qcheckbox.h>
+#include <qlayout.h>
+#include <qlabel.h>
+
+#include <klocale.h>
+
+#include <../core/robjectlist.h>
+
+#include "../debug.h"
+
+RKSaveObjectChooser::RKSaveObjectChooser (QWidget *parent, bool allow_overwrite, const QString &initial, QString prompt) : QWidget (parent) {
+	RK_TRACE (MISC);
+
+	RKSaveObjectChooser::allow_overwrite = allow_overwrite;
+	prev_ok = true;
+	object_exists = false;
+
+	QVBoxLayout *layout = new QVBoxLayout (this);
+
+	if (prompt.isNull ()) prompt = i18n ("Object name to save to");
+	QLabel *label = new QLabel (prompt, this);
+	layout->addWidget (label);
+
+	name_edit = new QLineEdit (this);
+	name_edit->setText (initial);
+	connect (name_edit, SIGNAL (textChanged (const QString &)), this, SLOT (nameEditChanged (const QString &)));
+	layout->addWidget (name_edit);
+
+	inuse_label = new QLabel (i18n ("The given symbol already exists"), this);
+	inuse_label->hide ();
+	layout->addWidget (inuse_label);
+
+	overwrite_confirm = new QCheckBox (i18n ("Overwrite?"), this);
+	connect (overwrite_confirm, SIGNAL (stateChanged (int)), this, SLOT (overwriteConfirmChanged (int)));
+	overwrite_confirm->hide ();
+	layout->addWidget (overwrite_confirm);
+
+	nameEditChanged (QString ());	// initialize
+}
+
+RKSaveObjectChooser::~RKSaveObjectChooser () {
+	RK_TRACE (MISC);
+}
+
+QString RKSaveObjectChooser::validizedSelectedObjectName () {
+	RK_TRACE (MISC);
+
+	return (RObjectList::getObjectList ()->validizeName (name_edit->text (), false));
+}
+
+bool RKSaveObjectChooser::isOk () const {
+	RK_TRACE (MISC);
+
+	return ((!object_exists) || (allow_overwrite && overwrite_confirm->isChecked ()));
+}
+
+void RKSaveObjectChooser::nameEditChanged (const QString &) {
+	RK_TRACE (MISC);
+
+	RObject *object = RObjectList::getObjectList ()->findObject (validizedSelectedObjectName ());
+	if (object) {
+		object_exists = true;
+		inuse_label->show ();
+		if (allow_overwrite) overwrite_confirm->show ();
+	} else {
+		object_exists = false;
+		inuse_label->hide ();
+		if (allow_overwrite) {
+			overwrite_confirm->hide ();
+			overwrite_confirm->setChecked (false);
+		}
+	}
+
+	if (isOk () != prev_ok) {
+		prev_ok = isOk ();
+		emit (okStatusChanged (isOk ()));
+	}
+}
+
+void RKSaveObjectChooser::overwriteConfirmChanged (int checked) {
+	RK_TRACE (MISC);
+
+	nameEditChanged (QString ());
+}
+
+#include "rksaveobjectchooser.moc"

Added: trunk/rkward/rkward/misc/rksaveobjectchooser.h
===================================================================
--- trunk/rkward/rkward/misc/rksaveobjectchooser.h	                        (rev 0)
+++ trunk/rkward/rkward/misc/rksaveobjectchooser.h	2006-11-27 15:16:55 UTC (rev 948)
@@ -0,0 +1,51 @@
+/***************************************************************************
+                          rksaveobjectchooser  -  description
+                             -------------------
+    begin                : Mon Nov 27 2006
+    copyright            : (C) 2006 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 RKSAVEOBJECTCHOOSER_H
+#define RKSAVEOBJECTCHOOSER_H
+
+#include <qwidget.h>
+
+class QLineEdit;
+class QCheckBox;
+class QLabel;
+
+/** Simple helper widget to select an R symbol name to write something to. */
+class RKSaveObjectChooser : public QWidget {
+	Q_OBJECT
+public:
+	RKSaveObjectChooser (QWidget *parent, bool allow_overwrite, const QString &initial, QString prompt = QString::null);
+	~RKSaveObjectChooser ();
+
+	QString validizedSelectedObjectName ();
+	bool isOk () const;
+public slots:
+	void nameEditChanged (const QString &);
+	void overwriteConfirmChanged (int checked);
+signals:
+	void okStatusChanged (bool);
+private:
+	bool allow_overwrite;
+	bool object_exists;
+	bool prev_ok;
+
+	QLineEdit *name_edit;
+	QCheckBox *overwrite_confirm;
+	QLabel *inuse_label;
+};
+
+#endif

Modified: trunk/rkward/rkward/windows/rkwindowcatcher.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkwindowcatcher.cpp	2006-11-27 13:59:58 UTC (rev 947)
+++ trunk/rkward/rkward/windows/rkwindowcatcher.cpp	2006-11-27 15:16:55 UTC (rev 948)
@@ -79,7 +79,9 @@
 
 #include "../rkglobals.h"
 #include "../rbackend/rinterface.h"
+#include "../core/robject.h"
 #include "../misc/rkerrordialog.h"
+#include "../misc/rksaveobjectchooser.h"
 
 RKCatchedX11Window::RKCatchedX11Window (WId window_to_embed, int device_number) : RKMDIWindow (0, X11Window) {
 	RK_TRACE (MISC);
@@ -236,9 +238,25 @@
 void RKCatchedX11Window::copyDeviceToRObject () {
 	RK_TRACE (MISC);
 
-	KMessageBox::information (0, i18n ("Not yet implemented"), i18n ("Not yet implemented"));
+// TODO: not very pretty, yet
+	KDialogBase *dialog = new KDialogBase (this, 0, true, i18n ("Specify R object"), KDialogBase::Ok|KDialogBase::Cancel);
+	QVBox *page = dialog->makeVBoxMainWidget ();
 
-	#warning implement or deactivate action
+	RKSaveObjectChooser *chooser = new RKSaveObjectChooser (page, true, "my.plot", i18n ("Specify the R object name, you want to save the graph to"));
+	connect (chooser, SIGNAL (okStatusChanged (bool)), dialog, SLOT (enableButtonOK (bool)));
+	if (!chooser->isOk ()) dialog->enableButtonOK (false);
+
+	dialog->exec ();
+
+	if (dialog->result () == QDialog::Accepted) {
+		RK_ASSERT (chooser->isOk ());
+
+		QString name = chooser->validizedSelectedObjectName ();
+
+		RKGlobals::rInterface ()->issueCommand ("dev.set (" + QString::number (device_number) + ")\n" + RObject::rQuote (name) + " <- recordPlot ()", RCommand::App | RCommand::ObjectListUpdate, i18n ("Save contents of graphics device number %1 to object '%2'").arg (QString::number (device_number)).arg (name), error_dialog);
+	}
+
+	delete dialog;
 }
 
 void RKCatchedX11Window::copyDeviceToFile () {


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