[rkward-cvs] SF.net SVN: rkward: [2103] branches/KDE4_port/rkward

tfry at users.sourceforge.net tfry at users.sourceforge.net
Mon Oct 22 16:54:58 UTC 2007


Revision: 2103
          http://rkward.svn.sourceforge.net/rkward/?rev=2103&view=rev
Author:   tfry
Date:     2007-10-22 09:54:58 -0700 (Mon, 22 Oct 2007)

Log Message:
-----------
Finish implementing (and documenting) the RControlWindow related classes

Modified Paths:
--------------
    branches/KDE4_port/rkward/rbackend/rcommand.h
    branches/KDE4_port/rkward/rbackend/rcommandstack.cpp
    branches/KDE4_port/rkward/rbackend/rcommandstack.h
    branches/KDE4_port/rkward/rbackend/rinterface.cpp
    branches/KDE4_port/rkward/windows/rcontrolwindow.cpp
    branches/KDE4_port/rkward/windows/rcontrolwindow.h

Modified: branches/KDE4_port/rkward/rbackend/rcommand.h
===================================================================
--- branches/KDE4_port/rkward/rbackend/rcommand.h	2007-10-22 16:19:56 UTC (rev 2102)
+++ branches/KDE4_port/rkward/rbackend/rcommand.h	2007-10-22 16:54:58 UTC (rev 2103)
@@ -31,14 +31,15 @@
 
 /** Base class for RCommand and RCommandChain, to make it possible to store both in the same list */
 class RCommandBase {
-protected:
-friend class RCommandStack;
-friend class RCommandStackModel;
-	RCommandBase (bool is_chain);
+public:
 /** Returns the casted pointer, if this is a command, else 0 */
 	RCommand* commandPointer ();
 /** Returns the casted pointer, if this is a chain, else 0 */
 	RCommandChain* chainPointer ();
+protected:
+friend class RCommandStack;
+friend class RCommandStackModel;
+	RCommandBase (bool is_chain);
 	RCommandChain *parent;
 private:
 	bool is_command_chain;
@@ -50,8 +51,6 @@
 @see RInterface::closeChain */
 class RCommandChain : public RCommandBase {
 protected:
-friend class RControlWindow;
-friend class RControlWindowListViewItem;
 friend class RCommandStack;
 friend class RCommandStackModel;
 	RCommandChain () : RCommandBase (true) {};

Modified: branches/KDE4_port/rkward/rbackend/rcommandstack.cpp
===================================================================
--- branches/KDE4_port/rkward/rbackend/rcommandstack.cpp	2007-10-22 16:19:56 UTC (rev 2102)
+++ branches/KDE4_port/rkward/rbackend/rcommandstack.cpp	2007-10-22 16:54:58 UTC (rev 2103)
@@ -374,6 +374,21 @@
 	return (QVariant ());
 }
 
+Qt::ItemFlags RCommandStackModel::flags (const QModelIndex& index) const {
+	RK_ASSERT (listeners);
+	RK_TRACE (RBACKEND);
+	lockMutex ();
+
+	if (!index.isValid ()) return 0;
+	RK_ASSERT (index.model () == this);
+
+	RCommandBase* index_data = static_cast<RCommandBase*> (index.internalPointer ());
+	RK_ASSERT (index_data);
+
+	if (index_data->commandPointer ()) return (Qt::ItemIsSelectable | Qt::ItemIsEnabled);
+	return Qt::ItemIsEnabled;
+}
+
 QVariant RCommandStackModel::headerData (int section, Qt::Orientation orientation, int role) const {
 	RK_ASSERT (listeners);
 	RK_TRACE (RBACKEND);

Modified: branches/KDE4_port/rkward/rbackend/rcommandstack.h
===================================================================
--- branches/KDE4_port/rkward/rbackend/rcommandstack.h	2007-10-22 16:19:56 UTC (rev 2102)
+++ branches/KDE4_port/rkward/rbackend/rcommandstack.h	2007-10-22 16:54:58 UTC (rev 2103)
@@ -77,7 +77,7 @@
 /** The model used to fetch a representation of and signal changes in the RCommandStack. Used for RKControlWindow.
 
 - All insertions / removals are signalled to the (single) model
-- it is ok for the model to be slow. It will simply walk the entire stack to find the corresponding indices
+- it is ok for the model to be slow.
 - the model keeps track of (the number of) listeners, and does not do anything unless there are any listeners (including walking the stack)
 - RControlWindow will only be constructed on show, and destructed on hide, so as not to eat ressources
 
@@ -99,39 +99,66 @@
 	int columnCount (const QModelIndex& parent = QModelIndex ()) const;
 	/** implements QAbstractItemModel::data() */
 	QVariant data (const QModelIndex& index, int role = Qt::DisplayRole) const;
+	/** reimplemented from  QAbstractItemModel::headerData() to make only commands (not chains/stacks) selectable */
+	Qt::ItemFlags flags (const QModelIndex& index) const;
 	/** reimplemented from  QAbstractItemModel::headerData() to provide column names */
 	QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
 
 	/** static pointer to the model. Only one model will ever be around. */
 	static RCommandStackModel* getModel () { return static_model; };
 
+	/** add a listener. The model will do nothing, if there are no listeners. Remember to remove the listener again as soon as possible. @see removeListener() */
 	void addListener ();
+	/** @see addListener() */
 	void removeListener ();
 
+	/** call this, when you are about to remove an item from a command stack/chain, *before* you actually remove the item. When done, call popComplete().
+	@param parent The parent of the item to be removed */
 	void aboutToPop (RCommandBase* parent);
+	/** @see aboutToPop () */
 	void popComplete ();
+	/** call this, when you are about to add an item to a command stack/chain, *before* you actually add the item. When done, call addComplete().
+	@param parent The parent of the item to be removed */
 	void aboutToAdd (RCommandBase* parent);
+	/** @see aboutToAdd () */
 	void addComplete ();
+	/** call this, when you have made changes to an item, that should be reflected in RControlWindow
+	@param item The item that was changed */
 	void itemChange (RCommandBase* item);
 private slots:
+	/** compagnon to lockMutex () */
 	void unlockMutex ();
+	/** the purpose of these signals and slots is to make sure the aboutToPop(), popComplete(), aboutToAdd(), addComplete(), and itemChange() methods are *always* dealt with in the main (GUI) thread. */
 	void relayItemAboutToBeAdded (RCommandBase* parent);
+	/** @see relayItemAboutToBeAdded() */
 	void relayItemAdded ();
+	/** @see relayItemAboutToBeAdded() */
 	void relayItemAboutToBeRemoved (RCommandBase* parent);
+	/** @see relayItemAboutToBeAdded() */
 	void relayItemRemoved ();
+	/** @see relayItemAboutToBeAdded() */
 	void relayItemChanged (RCommandBase* item);
 signals:
+	/** @see relayItemAboutToBeAdded() */
 	void itemAboutToBeAdded (RCommandBase* parent);
+	/** @see relayItemAboutToBeAdded() */
 	void itemAdded ();
+	/** @see relayItemAboutToBeAdded() */
 	void itemAboutToBeRemoved (RCommandBase* parent);
+	/** @see relayItemAboutToBeAdded() */
 	void itemRemoved ();
+	/** @see relayItemAboutToBeAdded() */
 	void itemChanged (RCommandBase* item);
 private:
+	/** locks the mutex temporarily (until the event loop is next entered again), and only, if not already locked */
 	void lockMutex () const;
+	/** number of listeners. If there are no listeners, the model will do almost nothing at all */
 	int listeners;
 	static RCommandStackModel* static_model;
+	/** @see lockMutex() */
 	bool have_mutex_lock;
 
+	/** create a model index for the given item */
 	QModelIndex indexFor (RCommandBase *item);
 };
 

Modified: branches/KDE4_port/rkward/rbackend/rinterface.cpp
===================================================================
--- branches/KDE4_port/rkward/rbackend/rinterface.cpp	2007-10-22 16:19:56 UTC (rev 2102)
+++ branches/KDE4_port/rkward/rbackend/rinterface.cpp	2007-10-22 16:54:58 UTC (rev 2103)
@@ -82,7 +82,7 @@
 	r_thread = new RThread ();
 
 	// create a fake init command
-	issueCommand (new RCommand (i18n ("R Startup"), RCommand::App, i18n ("R Startup")));
+	issueCommand (new RCommand (i18n ("R Startup"), RCommand::App | RCommand::Sync, i18n ("R Startup")));
 
 	flush_timer = new QTimer (this);
 	connect (flush_timer, SIGNAL (timeout ()), this, SLOT (flushOutput ()));
@@ -261,8 +261,7 @@
 		RK_ASSERT (false);
 	}
 
-// KDE4 TODO: deal with this one
-//	RControlWindow::getControl ()->updateCommand (command);
+	RCommandStackModel::getModel ()->itemChange (command);
 	MUTEX_UNLOCK;
 }
 

Modified: branches/KDE4_port/rkward/windows/rcontrolwindow.cpp
===================================================================
--- branches/KDE4_port/rkward/windows/rcontrolwindow.cpp	2007-10-22 16:19:56 UTC (rev 2102)
+++ branches/KDE4_port/rkward/windows/rcontrolwindow.cpp	2007-10-22 16:54:58 UTC (rev 2103)
@@ -84,7 +84,7 @@
 	if (!commands_view->model ()) {
 		RCommandStackModel::getModel ()->addListener ();
 		commands_view->setModel (RCommandStackModel::getModel ());
-		commands_view->header ()->setResizeMode (0, QHeaderView::Stretch);
+		commands_view->header ()->setResizeMode (0, QHeaderView::Stretch);	// can't do this in the ctor, as column 0 does not yet exist
 		commands_view->expandAll ();
 	}
 
@@ -102,39 +102,21 @@
 	RKMDIWindow::hideEvent (e);
 }
 
-void RControlWindow::commandSelectionChanged () {
-	RK_TRACE (APP);
-/*
-	// we will make some modifications to the selection in here, so disconnect the SIGNAL first.
-	disconnect (commands_view, SIGNAL (selectionChanged ()), this, SLOT (commandSelectionChanged ()));
-
-	bool have_selection = false;
-	// if a chain is selected, select all of its child items
-	Q3ListViewItemIterator itemit (commands_view, Q3ListViewItemIterator::Selected);
-	while (itemit.current ()) {
-		Q3ListViewItem *item = itemit.current ()->firstChild ();
-		while (item) {
-			item->setSelected (true);
-			item = item->nextSibling ();
-		}
-		have_selection = true;
-		++itemit;
-	}
-
-	cancel_button->setEnabled (have_selection);
-
-	connect (commands_view, SIGNAL (selectionChanged ()), this, SLOT (commandSelectionChanged ())); */
-}
-
 void RControlWindow::cancelButtonClicked () {
 	RK_TRACE (APP);
-/*
+	RCommandStackModel::getModel ()->index (0, 0, QModelIndex ());		// side-effect of locking the mutex
+
+	QModelIndexList list = commands_view->selectionModel ()->selectedIndexes ();
 	bool some_not_cancelable = false;
+
 	// find out all the RCommands selected (not the chains)
-	for (QMap <RCommand *, RControlWindowListViewItem *>::const_iterator it = command_map.begin (); it != command_map.end (); ++it) {
-		if (it.data ()->isSelected ()) {
-			if (!(it.key ()->type () & RCommand::Sync)) {
-				RKGlobals::rInterface ()->cancelCommand (it.key ());
+	for (QModelIndexList::const_iterator it = list.constBegin (); it != list.constEnd (); ++it) {
+		RCommandBase* coc = static_cast<RCommandBase*> ((*it).internalPointer ());
+		RK_ASSERT (coc);
+		RCommand* command = coc->commandPointer ();
+		if (command) {
+			if (!(command->type () & RCommand::Sync)) {
+				RKGlobals::rInterface ()->cancelCommand (command);
 			} else {
 				some_not_cancelable = true;
 			}
@@ -143,7 +125,7 @@
 
 	if (some_not_cancelable) {
 		KMessageBox::information (this, i18n ("Some of the commands you were trying to cancel are marked as \"sync\" (letter 'S' in the type column). Cancelling such commands could lead to loss of data. These commands have _not_ been cancelled."), i18n ("Some commands not cancelled"), "cancel_sync");
-	} */
+	}
 }
 
 void RControlWindow::pauseButtonClicked () {
@@ -171,6 +153,9 @@
 
 RControlWindowPart::RControlWindowPart (RControlWindow *widget) : KParts::Part () {
 	RK_TRACE (APP);
+
+	setComponentData (KGlobal::mainComponent ());
+
 	setWidget (widget);
 }
 
@@ -178,83 +163,4 @@
 	RK_TRACE (APP);
 }
 
-//############# END RContolWindowPart #######################
-//############# BEGIN RContolWindowListViewItem #################
-/*
-// static
-unsigned int RControlWindowListViewItem::lid = 0;
-
-RControlWindowListViewItem::RControlWindowListViewItem (Q3ListViewItem *parent) : Q3ListViewItem (parent) {
-	chain = 0;
-	chain_closed = false;
-
-	id = ++lid;
-}
-
-RControlWindowListViewItem::RControlWindowListViewItem (Q3ListView *parent) : Q3ListViewItem (parent) {
-	chain = 0;
-	chain_closed = false;
-
-	id = ++lid;
-}
-
-RControlWindowListViewItem::~RControlWindowListViewItem () {
-}
-
-int RControlWindowListViewItem::compare (Q3ListViewItem *i, int, bool ascending) const {
-	unsigned int comp_id = static_cast<RControlWindowListViewItem *> (i)->id;
-	if (ascending) {
-		if (comp_id > id) {
-			return -1;
-		}
-		return 1;
-	} else {
-		if (comp_id > id) {
-			return 1;
-		}
-		return -1;
-	}
-}
-
-void RControlWindowListViewItem::update (RCommand *command) {
-	RK_TRACE (APP);
-	RK_ASSERT (this);
-
-	QString dummy = command->command ().left (40).trimmed ();
-	if (dummy.length () > 37) {
-		dummy = dummy.left (37) + "...";
-	}
-	setText (0, dummy);
-
-	dummy = "";
-	if (command->type () & RCommand::User) dummy += 'U';
-	if (command->type () & RCommand::Plugin) dummy += 'P';
-	if (command->type () & RCommand::PluginCom) dummy += 'C';
-	if (command->type () & RCommand::App) dummy += 'A';
-	if (command->type () & RCommand::Sync) dummy += 'S';
-	if (command->type () & RCommand::EmptyCommand) dummy += 'E';
-	if (command->type () & (RCommand::GetIntVector | RCommand::GetRealVector | RCommand::GetStringVector)) dummy += 'D';
-	if (command->type () & RCommand::DirectToOutput) dummy += 'O';
-	setText (1, dummy);
-
-	if (command->getStatus () & RCommand::Canceled) setText (2, i18n ("Cancelled"));
-
-	setText (3, command->rkEquivalent ());
-}
-
-void RControlWindowListViewItem::update (RCommandChain *cchain) {
-	RK_TRACE (APP);
-	RK_ASSERT (this);
-	
-	chain = cchain;
-	chain_closed = cchain->closed;
-
-	setText (1, i18n ("Chain"));
-	if (chain_closed) {
-		setText (2, i18n ("Closed"));
-	} else {
-		setText (2, i18n ("Open (Waiting)"));
-	}
-}
-*/
 #include "rcontrolwindow.moc"

Modified: branches/KDE4_port/rkward/windows/rcontrolwindow.h
===================================================================
--- branches/KDE4_port/rkward/windows/rcontrolwindow.h	2007-10-22 16:19:56 UTC (rev 2102)
+++ branches/KDE4_port/rkward/windows/rcontrolwindow.h	2007-10-22 16:54:58 UTC (rev 2103)
@@ -36,11 +36,7 @@
 	\brief Interface to control R command execution
 
 This class provides a GUI interface to inspect, and manipulate the current RCommandStack, and to Pause/Resume the R engine.
-Do create an instance of this class directly. Create a RControlWindowPart instead. Also, probably RInterface should be the only class ever calling
-functions of RControlWindow.
 
-// KDE4 TODO: check, if everything is implemented
-
 @author Thomas Friedrichsmeier
 */
 class RControlWindow : public RKMDIWindow {
@@ -52,14 +48,13 @@
 /** destructor */
 	~RControlWindow ();
 
-/** reimplemented to refresh list of commands when showing. This is needed, as the RControlWindow is only kept up to date as long as it is shown. */
+/** reimplemented to start listening to the RCommandStackModel when showing. */
 	void showEvent (QShowEvent *e);
+/** when hidden, disconnect from the RCommandStackModel to save ressources */
 	void hideEvent (QHideEvent *e);
 /** Static reference to the control window */
 	static RControlWindow* getControl () { return control_window; };
 public slots:
-/** command selection was changed. Automatically select sub-items of selected chains. Enable/disable "Cancel" button */
-	void commandSelectionChanged ();
 /** cancel button was clicked. Cancel selected commands (unless they are RCommand::Sync). */
 	void cancelButtonClicked ();
 /** pause button was clicked. Pause/Resume processing of the stack */
@@ -92,37 +87,5 @@
 /** destructor */
 	~RControlWindowPart ();
 };
-#if 0
-/**
-	\brief ListViewItem used in RControlWindow
 
-A listview-item with a convenience constructor, and storing some additional information. For use in RControlWindow only.
-
-*/
-class RControlWindowListViewItem : public Q3ListViewItem {
-public:
-/** constructor. */
-	explicit RControlWindowListViewItem (Q3ListViewItem *parent);
-/** constructor. */
-	explicit RControlWindowListViewItem (Q3ListView *parent);
-/** destructor */
-	~RControlWindowListViewItem ();
-
-/** initialize/update item according to command flags, status, etc. */
-	void update (RCommand *command);
-/** initialize/update item according to chain flags, status, etc. */
-	void update (RCommandChain *chain);
-
-/** warning! do not try to access members of this pointer! RCommandChains get deleted in the stack when done, without notice. Use this pointer only to check, whether this is a chain, and to remove it from the RControlWindow::chain_map! */
-	RCommandChain *chain;
-	bool chain_closed;
-
-	unsigned int id;
-	static unsigned int lid;
-
-/** reimplemented to always have the top of the stack at the top */
-	int compare (Q3ListViewItem *i, int col, bool ascending) const;
-};
 #endif
-
-#endif


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