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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Tue Jun 15 20:29:46 UTC 2010


Revision: 2881
          http://rkward.svn.sourceforge.net/rkward/?rev=2881&view=rev
Author:   tfry
Date:     2010-06-15 20:29:46 +0000 (Tue, 15 Jun 2010)

Log Message:
-----------
Insert row names as a new special column on the left (unfinished, will add GUI support to hide/lock this column)

Modified Paths:
--------------
    trunk/rkward/rkward/dataeditor/rkvareditmodel.cpp
    trunk/rkward/rkward/dataeditor/rkvareditmodel.h

Modified: trunk/rkward/rkward/dataeditor/rkvareditmodel.cpp
===================================================================
--- trunk/rkward/rkward/dataeditor/rkvareditmodel.cpp	2010-06-15 16:25:12 UTC (rev 2880)
+++ trunk/rkward/rkward/dataeditor/rkvareditmodel.cpp	2010-06-15 20:29:46 UTC (rev 2881)
@@ -34,8 +34,10 @@
 
 	meta_model = 0;
 	trailing_rows = trailing_cols = 0;
+	var_col_offset = 0;
 	edit_blocks = 0;
 	rownames = 0;
+	header_locked = false;
 
 	addNotificationType (RObjectListener::ObjectRemoved);
 	addNotificationType (RObjectListener::MetaChanged);
@@ -77,7 +79,10 @@
 	RK_TRACE (EDITOR);
 
 	int index = objects.indexOf (static_cast<RKVariable*> (object));	// no check for isVariable needed. we only need to look up, if we have this object, and where.
-	if (index < 0) return;	// none of our buisiness
+	if (index < var_col_offset) {
+		RK_ASSERT (index < 0);	// some unrelated object
+		return;
+	}
 
 	beginRemoveColumns (QModelIndex (), index, index);
 	if (meta_model) meta_model->beginRemoveDataObject (index);
@@ -85,7 +90,7 @@
 	if (meta_model) meta_model->endRemoveDataObject ();
 	endRemoveColumns ();
 
-	if (objects.isEmpty ()) emit (modelDepleted ());	// editor may or may want to auto-destruct
+	if (objects.size () <= var_col_offset) emit (modelDepleted ());	// editor may or may want to auto-destruct
 }
 
 void RKVarEditModel::objectMetaChanged (RObject* changed) {
@@ -101,12 +106,6 @@
 void RKVarEditModel::objectDataChanged (RObject* object, const RObject::ChangeSet *changes) {
 	RK_TRACE (EDITOR);
 
-	if (object == rownames) {
-		RK_ASSERT (changes);
-		emit (headerDataChanged (Qt::Vertical, changes->from_index, changes->to_index));
-		return;
-	}
-
 	int cindex = objects.indexOf (static_cast<RKVariable*> (object));	// no check for isVariable needed. we only need to look up, if we have this object, and where.
 	if (cindex < 0) return;	// none of our buisiness
 
@@ -146,7 +145,6 @@
 // TODO: this does not emit any data change notifications to other editors
 		objects[i]->insertRows (row, count);
 	}
-	rownames->insertRows (row, count);
 	endInsertRows ();
 
 	return true;
@@ -170,7 +168,6 @@
 // TODO: this does not emit any data change notifications to other editors
 		objects[i]->removeRows (row, lastrow);
 	}
-	rownames->removeRows (row, lastrow);
 	endRemoveRows ();
 
 	return true;
@@ -219,6 +216,11 @@
 		return QVariant ();
 	}
 
+	if (col < var_col_offset) {
+		// TODO: make this look more like a normal header
+		if (role == Qt::ForegroundRole) return (Qt::blue);
+	}
+
 	// on a trailing row / col
 	if ((col >= objects.size ()) || (row >= objects[0]->getLength ())) {
 		if (role == Qt::BackgroundRole) return (Qt::gray);
@@ -239,7 +241,6 @@
 	RKVariable::Status status = var->cellStatus (row);
 	if ((role == Qt::BackgroundRole)) {
 		if (status == RKVariable::ValueInvalid) return (Qt::red);
-		if (row % 2) return (QColor (240, 255, 240));	// very light green
 	}
 	if ((role == Qt::ForegroundRole) && (status == RKVariable::ValueUnknown)) return (Qt::lightGray);
 	if (role == Qt::TextAlignmentRole) {
@@ -263,6 +264,8 @@
 		return flags;
 	}
 
+	if ((col < var_col_offset) && header_locked) return flags;
+
 	if (!edit_blocks) flags |= Qt::ItemIsEditable | Qt::ItemIsEnabled;
 	if ((col < objects.size ()) && (row < objects[0]->getLength ())) flags |= Qt::ItemIsSelectable;
 
@@ -313,6 +316,7 @@
 	if (section < rownames->getLength ()) {
 		return rownames->getText (section);
 	}
+
 	return QVariant ();
 }
 
@@ -469,6 +473,11 @@
 		return QVariant ();
 	}
 
+	if (col < var_col_offset) {
+	  	if (role == Qt::BackgroundRole) return (Qt::lightGray);
+		return QVariant ();
+	}
+
 	// on a trailing col
 	if (col >= data_model->objects.size ()) {
 		if (role == Qt::BackgroundRole) return (Qt::gray);
@@ -506,6 +515,7 @@
 		return flags;
 	}
 
+	if (col < var_col_offset) return flags;
 	if (!data_model->edit_blocks) flags |= Qt::ItemIsEditable | Qt::ItemIsEnabled;
 	if ((col < data_model->objects.size ()) && (row < RowCount)) flags |= Qt::ItemIsSelectable;
 
@@ -523,6 +533,11 @@
 		return false;
 	}
 
+	if (col < var_col_offset) {
+		RK_ASSERT (false);
+		return false;
+	}
+
 	if (col >= data_model->objects.size ()) {		// trailing col
 		// somebody should add a column for us
 		data_model->doInsertColumns (data_model->objects.size (), 1);
@@ -732,13 +747,13 @@
 		addObject (i, static_cast<RKVariable*> (obj));
 	}
 	rownames = dataframe->rowNames ();
-	listenForObject (rownames);
+	addObject (0, rownames);
+	getMetaModel ()->var_col_offset = var_col_offset = 1;
 }
 
 RKVarEditDataFrameModel::~RKVarEditDataFrameModel () {
 	RK_TRACE (EDITOR);
 
-	if (rownames) stopListenForObject (rownames);
 	if (dataframe) stopListenForObject (dataframe);
 }
 
@@ -751,6 +766,7 @@
 	}
 
 	if (column > trueCols ()) column = trueCols ();
+	if (column < var_col_offset) column = var_col_offset;
 	for (int col = column; col < (column + count); ++col) {
 		RObject *obj = dataframe->createPendingChild (dataframe->validizeName (QString ()), col);
 		RK_ASSERT (obj->isVariable ());
@@ -770,6 +786,11 @@
 		return false;
 	}
 
+	if (column < var_col_offset) {
+		RK_ASSERT (false);
+		return false;
+	}
+
 	while ((column + count) > objects.size ()) --count;
 	for (int i = column + count - 1; i >= column; --i) {	// we start at the end so that the index remains valid
 		RKGlobals::tracker ()->removeObject (objects[i]);
@@ -800,8 +821,6 @@
 
 	if (object == dataframe) {
 		while (!objects.isEmpty ()) RKVarEditModel::objectRemoved (objects[0]);
-		if (rownames) stopListenForObject (rownames);
-		rownames = 0;
 		stopListenForObject (dataframe);
 		dataframe = 0;
 	}
@@ -820,7 +839,7 @@
 		RObject* child = dataframe->findChildByIndex (index);
 		RK_ASSERT (child);
 
-		if (child->isVariable ()) addObject (index, static_cast<RKVariable*> (child));
+		if (child->isVariable ()) addObject (index + var_col_offset, static_cast<RKVariable*> (child));
 		else RK_ASSERT (false);
 	}
 }
@@ -830,14 +849,14 @@
 
 	if (parent == dataframe) {
 		RObject *child = dataframe->findChildByIndex (new_index);	// it's at the new position, already
-		RK_ASSERT (objects.size () > old_index);
-		RK_ASSERT (child == objects[old_index]);
+		RK_ASSERT (objects.size () > (old_index + var_col_offset));
+		RK_ASSERT (child == objects[old_index + var_col_offset]);
 		// if an object has changed position, there should be at least two objects left. Hence, the objectRemoved-call will never lead to editor destruction
-		RK_ASSERT (objects.size () >= 2);
+		RK_ASSERT (objects.size () >= (var_col_offset + 2));
 		objectRemoved (child);
 
 		RK_ASSERT (child->isVariable ());
-		addObject (new_index, static_cast<RKVariable*> (child));
+		addObject (new_index + var_col_offset, static_cast<RKVariable*> (child));
 	} else {
 		// even though we are listening for the child objects as well, we should see move notifications
 		// only for children of the parent.
@@ -861,8 +880,8 @@
 	RK_ASSERT (objects.size ());
 	RKVariable* child = objects[0];
 	QString na_vector = "=as.numeric (rep (NA, " + QString::number (child->getLength ()) + "))";
-	for (int col=0; col < objects.size (); ++col) {
-		if (col != 0) command.append (", ");
+	for (int col=var_col_offset; col < objects.size (); ++col) {
+		if (col > var_col_offset) command.append (", ");
 		command.append (objects[col]->getShortName () + na_vector);
 	}
 	command.append (")");

Modified: trunk/rkward/rkward/dataeditor/rkvareditmodel.h
===================================================================
--- trunk/rkward/rkward/dataeditor/rkvareditmodel.h	2010-06-15 16:25:12 UTC (rev 2880)
+++ trunk/rkward/rkward/dataeditor/rkvareditmodel.h	2010-06-15 20:29:46 UTC (rev 2881)
@@ -44,6 +44,9 @@
 
 	virtual int trueRows () const = 0;
 	virtual int trueCols () const = 0;
+	int firstRealColumn () const { return var_col_offset; };
+
+	int var_col_offset;
 };
 
 /** This class represents a collection of RKVariables of uniform length (typically a data.frame) suitable for editing in a model/view editor such as QTableView. Probably it will only ever support editing a single RKVariable, though, as it is not possible to ensure uniform length outside of a data.frame. For a data.frame use RKVarEditDataFrameModel . Since the real data storage is in RKVariable, it is ok (and recommended) to create separate models for separate editors/viewers, even if the objects in question are the same. */
@@ -81,6 +84,7 @@
 
 	int trueCols () const { return objects.size (); };
 	int trueRows () const { return (objects.isEmpty () ? 0 : objects[0]->getLength ()); };
+	void lockHeader (bool lock) { header_locked = lock; };
 
 	virtual void restoreObject (RObject* object, RCommandChain* chain);
 
@@ -113,6 +117,7 @@
 	int trailing_cols;
 
 	int edit_blocks;
+	bool header_locked;
 
 	RKVarEditMetaModel* meta_model;
 	RKEditor* myeditor;


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