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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Thu Jun 7 15:15:06 UTC 2007


Revision: 1927
          http://svn.sourceforge.net/rkward/?rev=1927&view=rev
Author:   tfry
Date:     2007-06-07 08:15:05 -0700 (Thu, 07 Jun 2007)

Log Message:
-----------
Beef up object viewer a bit, and fix a crash when closing

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/rkward/misc/rkobjectlistview.cpp
    trunk/rkward/rkward/rbackend/rcommandreceiver.cpp
    trunk/rkward/rkward/rbackend/rcommandreceiver.h
    trunk/rkward/rkward/robjectbrowser.cpp
    trunk/rkward/rkward/robjectviewer.cpp
    trunk/rkward/rkward/robjectviewer.h
    trunk/rkward/rkward/windows/rkmdiwindow.h
    trunk/rkward/rkward/windows/rkworkplace.cpp
    trunk/rkward/rkward/windows/rkworkplace.h

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2007-06-05 18:25:52 UTC (rev 1926)
+++ trunk/rkward/ChangeLog	2007-06-07 15:15:05 UTC (rev 1927)
@@ -1,3 +1,4 @@
+- object viewer also shows summary information, gains an update button, and MDI integration
 - CLT plugins allow drawing grid
 - add max.print option to R-Backend settings dialog
 - syntax highlighting is minimally faster for long outputs

Modified: trunk/rkward/rkward/misc/rkobjectlistview.cpp
===================================================================
--- trunk/rkward/rkward/misc/rkobjectlistview.cpp	2007-06-05 18:25:52 UTC (rev 1926)
+++ trunk/rkward/rkward/misc/rkobjectlistview.cpp	2007-06-07 15:15:05 UTC (rev 1927)
@@ -519,9 +519,6 @@
 	RObject *object = view->findItemObject (item);
 	if (!object) return;
 
-	// TODO: move all this to RObject::getDescription () or something similar (and complete it)
-	// merge with age-old code in RObjectViewer
-
 	tip (view->itemRect (item), object->getObjectDescription ());
 }
 

Modified: trunk/rkward/rkward/rbackend/rcommandreceiver.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rcommandreceiver.cpp	2007-06-05 18:25:52 UTC (rev 1926)
+++ trunk/rkward/rkward/rbackend/rcommandreceiver.cpp	2007-06-07 15:15:05 UTC (rev 1927)
@@ -2,7 +2,7 @@
                           rcommandreceiver  -  description
                              -------------------
     begin                : Thu Aug 19 2004
-    copyright            : (C) 2004, 2006 by Thomas Friedrichsmeier
+    copyright            : (C) 2004, 2006, 2007 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -16,6 +16,9 @@
  ***************************************************************************/
 #include "rcommandreceiver.h"
 
+#include "../rkglobals.h"
+#include "rinterface.h"
+
 #include "../debug.h"
 
 RCommandReceiver::RCommandReceiver () {
@@ -40,6 +43,14 @@
 	RK_TRACE (RBACKEND);
 }
 
+void RCommandReceiver::cancelOutstandingCommands () {
+	RK_TRACE (RBACKEND);
+
+	for (RCommandList::const_iterator it = outstanding_commands.begin (); it != outstanding_commands.end (); ++it) {
+		RKGlobals::rInterface()->cancelCommand (*it);
+	}
+}
+
 void RCommandReceiver::addCommand (RCommand *command) {
 	RK_TRACE (RBACKEND);
 	outstanding_commands.append (command);

Modified: trunk/rkward/rkward/rbackend/rcommandreceiver.h
===================================================================
--- trunk/rkward/rkward/rbackend/rcommandreceiver.h	2007-06-05 18:25:52 UTC (rev 1926)
+++ trunk/rkward/rkward/rbackend/rcommandreceiver.h	2007-06-07 15:15:05 UTC (rev 1927)
@@ -2,7 +2,7 @@
                           rcommandreceiver  -  description
                              -------------------
     begin                : Thu Aug 19 2004
-    copyright            : (C) 2004, 2006 by Thomas Friedrichsmeier
+    copyright            : (C) 2004, 2006, 2007 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -55,6 +55,7 @@
 	virtual void newOutput (RCommand *, ROutput *);
 protected:
 	RCommandList outstanding_commands;
+	void cancelOutstandingCommands ();
 private:
 	bool delete_when_done;
 	void addCommand (RCommand *command);

Modified: trunk/rkward/rkward/robjectbrowser.cpp
===================================================================
--- trunk/rkward/rkward/robjectbrowser.cpp	2007-06-05 18:25:52 UTC (rev 1926)
+++ trunk/rkward/rkward/robjectbrowser.cpp	2007-06-07 15:15:05 UTC (rev 1927)
@@ -41,7 +41,6 @@
 #include "misc/rkdummypart.h"
 #include "windows/rkworkplace.h"
 #include "dataeditor/rkeditor.h"
-#include "robjectviewer.h"
 
 #include "debug.h"
 
@@ -190,7 +189,7 @@
 void RObjectBrowserInternal::popupView () {
 	RK_TRACE (APP);
 	RKWorkplace::mainWorkplace ()->flushAllData ();
-	new RObjectViewer (0, list_view->menuObject ());
+	RKWorkplace::mainWorkplace ()->newObjectViewer (list_view->menuObject ());
 }
 
 void RObjectBrowserInternal::popupDelete () {

Modified: trunk/rkward/rkward/robjectviewer.cpp
===================================================================
--- trunk/rkward/rkward/robjectviewer.cpp	2007-06-05 18:25:52 UTC (rev 1926)
+++ trunk/rkward/rkward/robjectviewer.cpp	2007-06-07 15:15:05 UTC (rev 1927)
@@ -17,7 +17,10 @@
 #include "robjectviewer.h"
 
 #include <qlayout.h>
-
+#include <qscrollview.h>
+#include <qvbox.h>
+#include <qhbox.h>
+#include <qlabel.h>
 #include <qtextedit.h>
 #include <qfont.h>
 
@@ -27,64 +30,129 @@
 #include "rkglobals.h"
 #include "core/robject.h"
 #include "core/rcontainerobject.h"
+#include "misc/rkdummypart.h"
+#include "core/rkmodificationtracker.h"
 
-RObjectViewer::RObjectViewer (QWidget *parent, RObject *object) : QWidget (parent) {
-	QGridLayout *grid = new QGridLayout (this, 1, 1);
-	
-	view_area = new QTextEdit (this);
-	view_area->setTextFormat (PlainText);
-	view_area->setReadOnly (true);
-	view_area->setText (QString::null);
+#include "debug.h"
+
+#define SUMMARY_COMMAND 1
+#define PRINT_COMMAND 2
+
+RObjectViewer::RObjectViewer (QWidget *parent, RObject *object) : RKMDIWindow (parent, RKMDIWindow::ObjectWindow, false) {
+	RK_TRACE (APP);
+	RK_ASSERT (object);
+	_object = object;
+
+	QVBoxLayout *layout = new QVBoxLayout (this);
+	QScrollView *wrapper = new QScrollView (this);
+	wrapper->setResizePolicy (QScrollView::AutoOneFit);
+	QVBox *box = new QVBox (wrapper->viewport ());
+	wrapper->addChild (box);
+	layout->addWidget (wrapper);
+
+	wrapper->setFocusPolicy (QWidget::StrongFocus);
+	setPart (new RKDummyPart (this, wrapper));
+	initializeActivationSignals ();
+
 	QFont font ("Courier");
-	view_area->setCurrentFont (font);
-	view_area->setWordWrap (QTextEdit::NoWrap);
-	grid->addWidget (view_area, 0, 0);
-	
-	view_area->append (i18n("Object name: ") + object->getShortName ());
-	view_area->append (i18n("\nFull location: ") + object->getFullName ());
-	view_area->append (i18n("\nClass(es): ") + object->makeClassString (", "));
-	if (object->isContainer ()) {
-		RContainerObject *cobj = static_cast<RContainerObject*> (object);		// for convenience only
-		if (cobj->numDimensions ()) {
-			QString dummy = i18n("\nDimensions: ") + QString ().setNum (cobj->getDimension (0));
-			for (unsigned int i=1; i < cobj->numDimensions (); ++i) {
-				dummy.append (", " + QString ().setNum (cobj->getDimension (i)));
-			}
-			view_area->append (dummy);
-		}
-	}
-	view_area->append (i18n("\nResult of 'print (") + object->getFullName () + i18n(")':\n"));
 
+	QHBox *toprow = new QHBox (box);
+	description_label = new QLabel (toprow);
+	QVBox *statusbox = new QVBox (toprow);
+	statusbox->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
+	status_label = new QLabel (statusbox);
+	update_button = new QPushButton (i18n ("Update"), statusbox);
+	cancel_button = new QPushButton (i18n ("Cancel"), statusbox);
+	connect (update_button, SIGNAL (clicked ()), this, SLOT (update ()));
+	connect (cancel_button, SIGNAL (clicked ()), this, SLOT (cancel ()));
+
+	new QLabel (i18n("\nResult of 'summary (%1)':\n").arg (object->getFullName ()), box);
+	summary_area = new QTextEdit (box);
+	summary_area->setTextFormat (PlainText);
+	summary_area->setReadOnly (true);
+	summary_area->setCurrentFont (font);
+	summary_area->setWordWrap (QTextEdit::NoWrap);
+
+	new QLabel (i18n("\nResult of 'print (%1)':\n").arg (object->getFullName ()), box);
+	print_area = new QTextEdit (box);
+	print_area->setTextFormat (PlainText);
+	print_area->setReadOnly (true);
+	print_area->setCurrentFont (font);
+	print_area->setWordWrap (QTextEdit::NoWrap);
+
+	setCaption (i18n("Object Viewer: ") + object->getShortName ());
+	//resize (minimumSizeHint ().expandedTo (QSize (640, 480)));
+	update ();
+	connect (RKGlobals::tracker (), SIGNAL (objectRemoved(RObject*)), this, SLOT (objectRemoved(RObject*)));
+	show ();
+}
+
+RObjectViewer::~RObjectViewer () {
+	RK_TRACE (APP);
+}
+
+void RObjectViewer::cancel () {
+	RK_TRACE (APP);
+
+	cancel_button->setEnabled (false);
+	update_button->setEnabled (true);
+	cancelOutstandingCommands ();
+}
+
+void RObjectViewer::update () {
+	RK_TRACE (APP);
+
+	status_label->setText (i18n ("Fetching information"));
+	cancel_button->setEnabled (true);
+	update_button->setEnabled (false);
+	description_label->setText (_object->getObjectDescription ());
+
+	summary_area->setText (QString::null);
+	print_area->setText (QString::null);
+
+	RCommand *command = new RCommand ("print(summary(" + _object->getFullName () + "))", RCommand::App, QString::null, this, SUMMARY_COMMAND);
+	RKGlobals::rInterface ()->issueCommand (command, 0);
+
 	// make sure to print as wide as possible
-	RCommand *command = new RCommand ("local({\n"
+	command = new RCommand ("local({\n"
 	                                  "\trk.temp.width.save <- getOption(\"width\")\n"
 	                                  "\toptions(width=10000)\n"
 	                                  "\ton.exit(options(width=rk.temp.width.save))\n"
-	                                  "\tprint(" + object->getFullName () + ")\n"
-	                                  "})", RCommand::App, QString::null, this);
+	                                  "\tprint(" + _object->getFullName () + ")\n"
+	                                  "})", RCommand::App, QString::null, this, PRINT_COMMAND);
 	RKGlobals::rInterface ()->issueCommand (command, 0);
-	
-	caption = i18n("Object Viewer: ") + object->getShortName ();
-	setCaption (caption + i18n(" - Waiting for results from R..."));
-	resize (minimumSizeHint ().expandedTo (QSize (640, 480)));
-	show ();
 }
 
-RObjectViewer::~RObjectViewer () {
+void RObjectViewer::objectRemoved (RObject *object) {
+	RK_TRACE (APP);
+
+	if (object == _object) {
+		status_label->setText (i18n ("<b>Object was deleted!</b>"));
+		update_button->setEnabled (false);
+	}
 }
 
 void RObjectViewer::rCommandDone (RCommand *command) {
-	setCaption (caption);
-	
-	view_area->append (command->output ());
-	if (command->hasError ()) {
-		view_area->append (i18n("\nSome errors occurred: ") + command->error ());
+	RK_TRACE (APP);
+	RK_ASSERT (command);
+
+	if (command->getFlags () == SUMMARY_COMMAND) {
+		summary_area->append (command->fullOutput ());
+	} else if (command->getFlags () == PRINT_COMMAND) {
+		print_area->append (command->fullOutput ());
+		status_label->setText (i18n ("Ready"));
+		update_button->setEnabled (true);
+		cancel_button->setEnabled (false);
+	} else {
+		RK_ASSERT (false);
 	}
+
 }
 
 void RObjectViewer::closeEvent (QCloseEvent *e) {
+	hide ();
 	e->accept ();
-	delete this;
+	deleteLater ();
 }
 
 #include "robjectviewer.moc"

Modified: trunk/rkward/rkward/robjectviewer.h
===================================================================
--- trunk/rkward/rkward/robjectviewer.h	2007-06-05 18:25:52 UTC (rev 1926)
+++ trunk/rkward/rkward/robjectviewer.h	2007-06-07 15:15:05 UTC (rev 1927)
@@ -2,7 +2,7 @@
                           robjectviewer  -  description
                              -------------------
     begin                : Tue Aug 24 2004
-    copyright            : (C) 2004 by Thomas Friedrichsmeier
+    copyright            : (C) 2004, 2007 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -21,28 +21,45 @@
 #include <qstring.h>
 
 #include "rbackend/rcommandreceiver.h"
+#include "windows/rkmdiwindow.h"
 
 class RObject;
 class QTextEdit;
 class QCloseEvent;
+class QLabel;
+class QPushButton;
 
 /**
 An extremely simple object viewer. You pass it an object in the constructor. It will extract some information and display that as text, then call R "print (object)" and display the result. You don't need to store a pointer. The window will self-destruct when closed.
 
 @author Thomas Friedrichsmeier
 */
-class RObjectViewer : public QWidget, public RCommandReceiver {
+class RObjectViewer : public RKMDIWindow, public RCommandReceiver {
 Q_OBJECT
 public:
-    RObjectViewer(QWidget *parent, RObject *object);
+	~RObjectViewer ();
 
-    ~RObjectViewer();
+	RObject *object () { return _object; };
+public slots:
+	void cancel ();
+	void update ();
+	void objectRemoved (RObject *object);
 protected:
+	friend class RKWorkplace;
+	RObjectViewer (QWidget *parent, RObject *object);
+
 	void rCommandDone (RCommand *command);
 	void closeEvent (QCloseEvent *e);
 private:
-	QTextEdit *view_area;
+	QLabel *status_label;
+	QLabel *description_label;
+	QPushButton *update_button;
+	QPushButton *cancel_button;
+	QTextEdit *print_area;
+	QTextEdit *summary_area;
 	QString caption;
+
+	RObject *_object;
 };
 
 #endif

Modified: trunk/rkward/rkward/windows/rkmdiwindow.h
===================================================================
--- trunk/rkward/rkward/windows/rkmdiwindow.h	2007-06-05 18:25:52 UTC (rev 1926)
+++ trunk/rkward/rkward/windows/rkmdiwindow.h	2007-06-07 15:15:05 UTC (rev 1927)
@@ -30,20 +30,21 @@
 	Q_OBJECT
 public:
 	enum Type {
-		DataEditorWindow=1,
-		CommandEditorWindow=2,
-		OutputWindow=4,
-		HelpWindow=8,
-		X11Window=16,
-		ConsoleWindow=32,
-		CommandLogWindow=64,
-		WorkspaceBrowserWindow=128,
-		SearchHelpWindow=256,
-		PendingJobsWindow=512,
-		FileBrowserWindow=1024,
+		DataEditorWindow=1 << 0,
+		CommandEditorWindow=1 << 1,
+		OutputWindow=1 << 2,
+		HelpWindow=1 << 3,
+		X11Window=1 << 4,
+		ObjectWindow=1 << 5,
+		ConsoleWindow=1 << 10,
+		CommandLogWindow=1 << 11,
+		WorkspaceBrowserWindow=1 << 12,
+		SearchHelpWindow=1 << 13,
+		PendingJobsWindow=1 << 14,
+		FileBrowserWindow=1 << 15,
 
-		DocumentWindow=2048,
-		ToolWindow=4096,
+		DocumentWindow=1 << 20,
+		ToolWindow=1 << 21,
 		AnyType=DocumentWindow | ToolWindow
 	};
 

Modified: trunk/rkward/rkward/windows/rkworkplace.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkworkplace.cpp	2007-06-05 18:25:52 UTC (rev 1926)
+++ trunk/rkward/rkward/windows/rkworkplace.cpp	2007-06-07 15:15:05 UTC (rev 1927)
@@ -32,6 +32,7 @@
 #include "../dataeditor/rkeditor.h"
 #include "../dataeditor/rkeditordataframe.h"
 #include "../dataeditor/rkeditordataframepart.h"
+#include "../robjectviewer.h"
 #include "../settings/rksettingsmoduleoutput.h"
 #include "../settings/rksettingsmodulegeneral.h"
 #include "../rbackend/rinterface.h"
@@ -112,7 +113,6 @@
 	windows.append (window);
 	connect (window, SIGNAL (destroyed (QObject *)), this, SLOT (windowDestroyed (QObject *)));
 	connect (window, SIGNAL (windowActivated(RKMDIWindow*)), history, SLOT (windowActivated(RKMDIWindow*)));
-	connect (window, SIGNAL (destroyed (QObject *)), history, SLOT (windowDestroyed (QObject *)));
 	if (attached) attachWindow (window);
 	else detachWindow (window, false);
 }
@@ -205,6 +205,22 @@
 	addWindow (window, false);
 }
 
+void RKWorkplace::newObjectViewer (RObject *object) {
+	RK_TRACE (APP);
+	RK_ASSERT (object);
+
+	RKWorkplaceObjectList object_windows = getObjectList (RKMDIWindow::ObjectWindow, RKMDIWindow::AnyWindowState);
+	for (RKWorkplaceObjectList::const_iterator it = object_windows.constBegin (); it != object_windows.constEnd (); ++it) {
+		if (static_cast<RObjectViewer *> (*it)->object () == object) {
+			(*it)->activate ();
+			return;
+		}
+	}
+
+	RObjectViewer *ov = new RObjectViewer (view (), object);
+	addWindow (ov);
+}
+
 bool RKWorkplace::canEditObject (RObject *object) {
 	RK_TRACE (APP);
 	
@@ -318,6 +334,9 @@
 	RK_TRACE (APP);
 	RKMDIWindow *window = static_cast<RKMDIWindow *> (object);
 
+	// remove from history first (otherwise, we might find it there, when trying to activate a new window)
+	history->windowDestroyed (window);
+
 	// WARNING: the window is dead. Don't call any functions on it.
 
 	RK_ASSERT (windows.find (window) != windows.end ());
@@ -513,7 +532,7 @@
 	RK_TRACE (APP);
 
 	if (!haveNext ()) return;
-	back_list.append (current);
+	if (current) back_list.append (current);
 	current = forward_list.first ();
 	forward_list.pop_front ();
 
@@ -527,7 +546,7 @@
 	RK_TRACE (APP);
 
 	if (!havePrev ()) return;
-	forward_list.push_front (current);
+	if (current) forward_list.push_front (current);
 	current = back_list.last ();
 	back_list.pop_back ();
 

Modified: trunk/rkward/rkward/windows/rkworkplace.h
===================================================================
--- trunk/rkward/rkward/windows/rkworkplace.h	2007-06-05 18:25:52 UTC (rev 1926)
+++ trunk/rkward/rkward/windows/rkworkplace.h	2007-06-07 15:15:05 UTC (rev 1927)
@@ -44,11 +44,11 @@
 	void initActions (KActionCollection *ac, const char *prev_id, const char *next_id);
 	bool haveNext ();
 	bool havePrev ();
+	void windowDestroyed (QObject *window);
 public slots:
 	void next ();
 	void prev ();
 	void windowActivated (RKMDIWindow *window);
-	void windowDestroyed (QObject *window);
 private:
 	void updateActions ();
 
@@ -106,6 +106,7 @@
 	void newOutput (bool only_if_modified);
 
 	void newX11Window (WId window_to_embed, int device_number);
+	void newObjectViewer (RObject *object);
 
 /** @returns true if there is a known editor for this type of object, false otherwise */
 	bool canEditObject (RObject *object);


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