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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Mon Sep 25 13:13:23 UTC 2006


Revision: 760
          http://svn.sourceforge.net/rkward/?rev=760&view=rev
Author:   tfry
Date:     2006-09-25 06:13:16 -0700 (Mon, 25 Sep 2006)

Log Message:
-----------
First implementation of RKWorkplace. Does not compile, yet, some changes in other classes needed

Modified Paths:
--------------
    trunk/rkward/rkward/misc/rkworkplace.cpp
    trunk/rkward/rkward/misc/rkworkplace.h

Modified: trunk/rkward/rkward/misc/rkworkplace.cpp
===================================================================
--- trunk/rkward/rkward/misc/rkworkplace.cpp	2006-09-24 19:42:52 UTC (rev 759)
+++ trunk/rkward/rkward/misc/rkworkplace.cpp	2006-09-25 13:13:16 UTC (rev 760)
@@ -17,5 +17,254 @@
 
 #include "rkworkplace.h"
 
+#include <kparts/partmanager.h>
+#include <kmessagebox.h>
+#include <klocale.h>
+#include <kiconloader.h>
 
+#include "../windows/detachedwindowcontainer.h"
+#include "../windows/rkcommandeditorwindow.h"
+#include "../windows/rkhtmlwindow.h"
+#include "../core/robject.h"
+#include "../core/rcontainerobject.h"
+#include "../core/robjectlist.h"
+#include "../dataeditor/rkeditor.h"
+#include "../dataeditor/rkeditordataframe.h"
+#include "../dataeditor/rkeditordataframepart.h"
+
+#include "../debug.h"
+
+
+RKWorkplace::RKWorkplace (QWidget *parent) : QObject (parent) {
+	RK_TRACE (APP);
+
+	wview = new RKWorkplaceView (parent);
+	connect (wview, SIGNAL (currentChanged (QWidget *)), this, SLOT (activeAttachedChanged (QWidget *)));
+	part_manager = new KParts::PartManager (view ());
+}
+
+RKWorkplace::~RKWorkplace () {
+	RK_TRACE (APP);
+
+	closeAll ();
+}
+
+void RKWorkplace::attachWindow (QWidget *window) {
+	RK_TRACE (APP);
+	RK_ASSERT (windows.find (window) != windows.end ());		// This should not happen for now.
+
+	RKWorkplaceObjectInfo *info = windows[window];
+	info->state = Attached;
+
+	window->reparent (view (), QPoint (0, 0));
+	view ()->addTab (window, window->caption ());
+	RK_ASSERT (info->part);
+	part_manager->addPart (info->part);
+}
+
+void RKWorkplace::detachWindow (QWidget *window) {
+	RK_TRACE (APP);
+	RK_ASSERT (windows.find (window) != windows.end ());		// Can't detach a window that is not attached
+
+	RKWorkplaceObjectInfo *info = windows[window];
+	info->state = Detached;
+
+	RK_ASSERT (info->part);
+	part_manager->removePart (info->part);
+	view ()->removePage (window);
+
+	DetachedWindowContainer *detached = new DetachedWindowContainer (info->part, window);
+	detached->show ();
+}
+
+void RKWorkplace::addWindow (QWidget *window, RKWorkplaceObjectType type) {
+	RK_TRACE (APP);
+
+	connect (window, SIGNAL (destroyed (QWidget *)), this, SLOT (windowDestroyed (QWidget *)));
+	// TODO: most views do not emit that signal, yet
+	connect (window, SIGNAL (captionChanged (QWidget *)), this, SLOT (updateWindowCaption (QWidget *)));
+
+	RKWorkplaceObjectInfo *info = new RKWorkplaceObjectInfo;
+	info->part = 0;
+	info->state = Attached;
+	info->type = type;
+	windows.insert (window, info);
+
+	view ()->addTab (window, window->caption ());
+}
+
+bool RKWorkplace::openScriptEditor (const KURL &url) {
+	RK_TRACE (APP);
+
+	RKCommandEditorWindow *editor = new RKCommandEditorWindow (view ());
+
+	if (!url.isEmpty ()) {
+		if (!editor->openURL (url)) {
+			delete editor;
+			KMessageBox::messageBox (view (), KMessageBox::Error, i18n ("Unable to open \"%1\"").arg (url.prettyURL ()), i18n ("Could not open command file"));
+			return false;
+		}
+	}
+
+	addWindow (editor, CommandEditorWindow);
+	return true;
+}
+
+void RKWorkplace::openHelpWindow (const KURL &url) {
+	RK_TRACE (APP);
+
+	RKHelpWindow *hw = new RKHelpWindow (view ());
+	if (!url.isEmpty ()) {
+		hw->openURL (url);
+	}
+
+	addWindow (hw, HelpWindow);
+}
+
+void RKWorkplace::openOutputWindow (const KURL &url) {
+	RK_TRACE (APP);
+
+	RKOutputWindow::refreshOutput (true, true);
+	if (windows.find (RKOutputWindow::getCurrentOutput ()) == windows.end ()) {
+		addWindow (RKOutputWindow::getCurrentOutput (), OutputWindow);
+	}
+}
+
+bool RKWorkplace::canEditObject (RObject *object) {
+	RK_TRACE (APP);
+	
+	if (object->isDataFrame ()) {
+		return true;
+	} else if (object->isVariable () && object->getContainer ()->isDataFrame ()) {
+		return true;
+	}
+	return false;
+}
+
+RKEditor *RKWorkplace::editObject (RObject *object, bool initialize_to_empty) {
+	RK_TRACE (APP);
+
+	RObject *iobj = object;
+	RKEditor *ed = 0;
+	RKEditorDataFramePart *part = 0;
+	if (!object->objectOpened ()) {
+		if (object->isDataFrame ()) {
+			part = new RKEditorDataFramePart (0);		// TODO: reverse creation logic, just as in the other classes!
+			ed = part->getEditor ();
+			// TODO: add child objects, too?
+			ed->openObject (object, initialize_to_empty);
+		} else if (object->isVariable () && object->getContainer ()->isDataFrame ()) {
+			if (!object->getContainer ()->objectOpened ()) { 
+				iobj = object->getContainer ();
+				part = new RKEditorDataFramePart (0);
+				ed = part->getEditor ();
+				// TODO: add child objects, too?
+				ed->openObject (iobj, initialize_to_empty);
+				// ed->focusObject (obj);
+			} else {
+				if (object->getContainer ()->objectOpened ()) {
+					object->getContainer ()->objectOpened ()->show ();
+					object->getContainer ()->objectOpened ()->raise ();
+				}
+			}
+		}
+
+		if (ed) {
+			ed->setCaption (iobj->getShortName ());		// TODO: move to editor
+			addWindow (ed, DataEditorWindow);
+			ed->setIcon (SmallIcon ("spreadsheet"));
+			ed->setFocus ();		// somehow we need to call this explicitely
+			registerPart (ed, part);
+		}
+	} else {
+		object->objectOpened ()->show ();
+		object->objectOpened ()->raise ();
+	}
+	
+	return ed;
+}
+
+void RKWorkplace::flushAllData () {
+	RK_TRACE (APP);
+
+	for (RKWorkplaceObjectMap::const_iterator it = windows.constBegin (); it != windows.constEnd (); ++it) {
+		if (it.data ()->type == DataEditorWindow) {
+			static_cast<RKEditor *> (it.key ())->flushChanges ();
+		}
+	}
+}
+
+void RKWorkplace::closeWindow (QWidget *window) {
+	RK_TRACE (APP);
+	RK_ASSERT (windows.find (window) != windows.end ());
+
+	delete window;		// all the rest should happen in windowDestroyed ()
+}
+
+void RKWorkplace::closeAll (int type, int state) {
+	RK_TRACE (APP);
+
+	QValueList<QWidget *> list_to_close;
+	for (RKWorkplaceObjectMap::const_iterator it = windows.constBegin (); it != windows.constEnd (); ++it) {
+		if ((it.data ()->type & type) && (it.data ()->state & state)) {
+			list_to_close.append (it.key ());		// can't inline deletion
+		}
+	}
+
+	for (QValueList<QWidget *>::const_iterator it = list_to_close.constBegin (); it != list_to_close.constEnd (); ++it) {
+		closeWindow (*it);
+	}
+}
+
+void RKWorkplace::windowDestroyed (QWidget *window) {
+	RK_TRACE (APP);
+
+	RK_ASSERT (windows.find (window) != windows.end ());
+	delete windows[window];
+	windows.remove (window);
+}
+
+void RKWorkplace::updateWindowCaption (QWidget *window) {
+	RK_TRACE (APP);
+
+	RK_ASSERT (windows.find (window) != windows.end ());
+	view ()->changeTab (window, window->caption ());
+	if (window == activeAttachedWindow ()) emit (changeCaption (window->caption ()));
+}
+
+void RKWorkplace::activeAttachedChanged (QWidget *window) {
+	RK_TRACE (APP);
+	RK_ASSERT (window);
+
+	emit (changeCaption (window->caption ()));
+}
+
+QWidget *RKWorkplace::activeAttachedWindow () {
+	RK_TRACE (APP);
+
+	return (view ()->currentPage ());
+}
+
+void RKWorkplace::activateWindow (QWidget *window) {
+	RK_TRACE (APP);
+
+	window->raise ();		// Does this do the trick?
+}
+
+
+void RKWorkplace::saveWorkplace (RCommandChain *chain) {
+	RK_TRACE (APP);
+
+	// TODO
+}
+
+void RKWorkplace::restoreWorkplace (RCommandChain *chain) {
+	RK_TRACE (APP);
+
+	// TODO
+}
+
+void RKWorkplace::rCommandDone (RCommand *command) {
+}
+
 #include "rkworkplace.moc"

Modified: trunk/rkward/rkward/misc/rkworkplace.h
===================================================================
--- trunk/rkward/rkward/misc/rkworkplace.h	2006-09-24 19:42:52 UTC (rev 759)
+++ trunk/rkward/rkward/misc/rkworkplace.h	2006-09-25 13:13:16 UTC (rev 760)
@@ -23,16 +23,20 @@
 #include <qtabwidget.h>
 
 #include <kurl.h>
+#include <kparts/part.h>
 
 #include "../rbackend/rcommandreceiver.h"
 
 class RObject;
 class RCommandChain;
 class RKWorkplaceView;
+class KParts::PartManager;
+class RKEditor;
 
 /** This class (only one instance will probably be around) keeps track of which windows are opened in the
 workplace, which are detached, etc. Will replace RKEditorManager.
-It also provides a QWidget (RKWorkplace::view ()), which actually manages the document windows (only those, so far. I.e. this is a half-replacement for KMdi, which will be gone in KDE 4). Currently layout of the document windows is always tabbed. */
+It also provides a QWidget (RKWorkplace::view ()), which actually manages the document windows (only those, so far. I.e. this is a half-replacement for KMdi, which will be gone in KDE 4). Currently layout of the document windows is always tabbed.
+//TODO: move to windows */
 class RKWorkplace : public QObject, public RCommandReceiver {
 	Q_OBJECT
 public:
@@ -57,30 +61,33 @@
 
 	struct RKWorkplaceObjectInfo {
 		RKWorkplaceObjectType type;
-		QString location_or_name;		// do we need this?
-		bool detached;
+		KParts::Part *part;
+		RKWorkplaceObjectState state;
 	};
 
 	typedef QMap<QWidget *, RKWorkplaceObjectInfo *> RKWorkplaceObjectMap;
 
-	RKWorkplaceView *view ();
+	RKWorkplaceView *view () { return wview; };
 
 	RKWorkplaceObjectMap getObjectList () { return windows; };
 
-	void detachWindow (QWidget *window);
 /** Attach an already created window. */
 	void attachWindow (QWidget *window);
+	void detachWindow (QWidget *window);
+	QWidget *activeAttachedWindow ();
+	void activateWindow (QWidget *window);
 
-	void openScriptEditor (const KURL &url=KURL ());
+	bool openScriptEditor (const KURL &url=KURL ());
 	void openHelpWindow (const KURL &url=KURL ());
 	void openOutputWindow (const KURL &url=KURL ());
 
 	bool canEditObject (RObject *object);
-	void editObject (RObject *object, bool initialize_to_empty=false);
+	RKEditor *editObject (RObject *object, bool initialize_to_empty=false);
 
 /** tell all DataEditorWindow s to syncronize changes to the R backend
 // TODO: add RCommandChain parameter */
 	void flushAllData ();
+	void closeWindow (QWidget *window);
 /** Closes all windows of the given type(s). Default call (no arguments) closes all windows
 @param type: A bitwise OR of RKWorkplaceObjectType
 @param state: A bitwise OR of RKWorkplaceObjectState */
@@ -90,17 +97,27 @@
 	void restoreWorkplace (RCommandChain *chain=0);
 signals:
 	void lastWindowClosed ();
+	void changeGUI (KParts::Part *active_part);
+	void changeCaption (const QString &caption);
 public slots:
 	void windowDestroyed (QWidget *window);
+	void updateWindowCaption (QWidget *window);
+	void activeAttachedChanged (QWidget *window);
 
-	void updateWindowCaption (QWidget *window);
+	void registerPart (QWidget *widget, KParts::Part *part);
 protected:
 	void rCommandDone (RCommand *command);
 private:
 	RKWorkplaceObjectMap windows;
+	RKWorkplaceView *wview;
+	void addWindow (QWidget *window, RKWorkplaceObjectType type);
+
+	KParts::PartManager *part_manager;
 };
 
+/** This is a separate class mostly for future extension. right now, it's just a QTabWidget */
 class RKWorkplaceView : public QTabWidget {
+public:
 	RKWorkplaceView (QWidget *parent);
 	~RKWorkplaceView ();
 };


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