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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Thu Nov 8 09:52:25 UTC 2012


Revision: 4420
          http://rkward.svn.sourceforge.net/rkward/?rev=4420&view=rev
Author:   tfry
Date:     2012-11-08 09:52:24 +0000 (Thu, 08 Nov 2012)
Log Message:
-----------
Add column-wise highlighting of invalid fields to data.frame editor

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/rkward/core/rkvariable.cpp
    trunk/rkward/rkward/core/rkvariable.h
    trunk/rkward/rkward/core/robject.h
    trunk/rkward/rkward/dataeditor/rkvareditmodel.cpp
    trunk/rkward/rkward/dataeditor/rkvareditmodel.h
    trunk/rkward/rkward/misc/rktableview.cpp

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2012-11-07 14:40:58 UTC (rev 4419)
+++ trunk/rkward/ChangeLog	2012-11-08 09:52:24 UTC (rev 4420)
@@ -1,3 +1,4 @@
+- In the data.frame editor, columns containing invalid values are now highlighted in red
 - Fixed: If none of the previous plugin maps could be found on startup, re-add the default
 - Added GUI element for entering matrix or vector data in plugins
 - Improve key handling while editing factor levels in a data.frame

Modified: trunk/rkward/rkward/core/rkvariable.cpp
===================================================================
--- trunk/rkward/rkward/core/rkvariable.cpp	2012-11-07 14:40:58 UTC (rev 4419)
+++ trunk/rkward/rkward/core/rkvariable.cpp	2012-11-08 09:52:24 UTC (rev 4420)
@@ -2,7 +2,7 @@
                           rkvariable  -  description
                              -------------------
     begin                : Thu Aug 12 2004
-    copyright            : (C) 2004, 2007, 2008, 2010, 2011 by Thomas Friedrichsmeier
+    copyright            : (C) 2004, 2007, 2008, 2010, 2011, 2012 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -185,11 +185,10 @@
 				}
 			}
 		}
+		data->previously_valid = data->invalid_fields.isEmpty ();
 		data->formatting_options = parseFormattingOptionsString (getMetaProperty ("format"));
 
-		ChangeSet *set = new ChangeSet;
-		set->from_index = 0;
-		set->to_index = getLength ();
+		ChangeSet *set = new ChangeSet (0, getLength (), true);
 		RKGlobals::tracker ()->objectDataChanged (this, set);
 		RKGlobals::tracker ()->objectMetaChanged (this);
 		type -= (type & NeedDataUpdate);
@@ -349,6 +348,10 @@
 		RKGlobals::rInterface ()->issueCommand (".rk.set.invalid.field (" + getFullName () + ", " + QString::number (row+1) + ", NULL)", RCommand::App | RCommand::Sync, QString (), 0,0, chain);
 	}
 	data->cell_states[row] -= (data->cell_states[row] & RKVarEditData::UnsyncedInvalidState);
+	if (data->previously_valid != data->invalid_fields.isEmpty ()) {
+		data->previously_valid = data->invalid_fields.isEmpty ();
+		RKGlobals::tracker ()->objectMetaChanged (this);
+	}
 }
 
 void RKVariable::writeData (int from_row, int to_row, RCommandChain *chain) {
@@ -373,9 +376,7 @@
 		RKGlobals::rInterface ()->issueCommand (getFullName () + '[' + QString::number (from_row + 1) + ':' + QString::number (to_row + 1) + "] <- " + data_string, RCommand::App | RCommand::Sync, QString::null, 0,0, chain);
 	}
 
-	ChangeSet *set = new ChangeSet;
-	set->from_index = from_row;
-	set->to_index = to_row;
+	ChangeSet *set = new ChangeSet (from_row, to_row);
 	RKGlobals::tracker ()->objectDataChanged (this, set);
 }
 
@@ -407,6 +408,11 @@
 	dimensions[0] = length;
 }
 
+bool RKVariable::hasInvalidFields () const {
+	if (!data) return false;	// should not ever happen, though
+	return (!data->invalid_fields.isEmpty ());
+}
+
 QString RKVariable::getText (int row, bool pretty) const {
 	if (row >= getLength ()) {
 		RK_ASSERT (false);
@@ -699,9 +705,7 @@
 	}
 
 	// also update display of all values:
-	ChangeSet *set = new ChangeSet;
-	set->from_index = 0;
-	set->to_index = getLength () - 1;	
+	ChangeSet *set = new ChangeSet (0, getLength () - 1);
 	RKGlobals::tracker ()->objectDataChanged (this, set);
 
 	// TODO: find out whether the object is valid after the operation and update accordingly!
@@ -782,9 +786,7 @@
 	setMetaProperty ("format", formattingOptionsToString (new_options));
 
 	// also update display of all values:
-	ChangeSet *set = new ChangeSet;
-	set->from_index = 0;
-	set->to_index = getLength () - 1;	
+	ChangeSet *set = new ChangeSet (0, getLength () -1);
 	RKGlobals::tracker ()->objectDataChanged (this, set);
 }
 

Modified: trunk/rkward/rkward/core/rkvariable.h
===================================================================
--- trunk/rkward/rkward/core/rkvariable.h	2012-11-07 14:40:58 UTC (rev 4419)
+++ trunk/rkward/rkward/core/rkvariable.h	2012-11-08 09:52:24 UTC (rev 4420)
@@ -2,7 +2,7 @@
                           rkvariable  -  description
                              -------------------
     begin                : Thu Aug 12 2004
-    copyright            : (C) 2004, 2007, 2010, 2011 by Thomas Friedrichsmeier
+    copyright            : (C) 2004, 2007, 2010, 2011, 2012 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -59,7 +59,9 @@
 	void syncDataToR ();
 /** reimplemented from RObject */
 	void updateDataFromR (RCommandChain *chain);
-	
+
+	bool hasInvalidFields () const;
+
 /** get the value at the given row in text-form - regardless of the storage mode.
 @param pretty: get the text in pretty form, e.g. rounding numbers to a certain number of digits, replacing numeric values with value labels if available, etc. Formatting is done according to the meta-information stored in the RObject and global user preferences */
 	QString getText (int row, bool pretty=false) const;

Modified: trunk/rkward/rkward/core/robject.h
===================================================================
--- trunk/rkward/rkward/core/robject.h	2012-11-07 14:40:58 UTC (rev 4419)
+++ trunk/rkward/rkward/core/robject.h	2012-11-08 09:52:24 UTC (rev 4420)
@@ -203,10 +203,13 @@
 @param levels levels to recurse (0 = only direct children). */
 	void fetchMoreIfNeeded (int levels=1);
 
-/// For now, the ChangeSet only handles RKVariables!
+/** Representation of changes to an edited object (currently for vector data, only) */
 	struct ChangeSet {
-		int from_index;
-		int to_index;
+		ChangeSet (int from = -1, int to = -1, bool reset = false) : 
+					from_index(from), to_index(to), full_reset(reset) {};
+		int from_index;		/**< first changed index */
+		int to_index;		/**< last changed index */
+		bool full_reset;	/**< Model should do a full reset (e.g. dimensions may have changed) */
 	};
 
 /** generates a (full) name for a child of this object with the given name. */

Modified: trunk/rkward/rkward/dataeditor/rkvareditmodel.cpp
===================================================================
--- trunk/rkward/rkward/dataeditor/rkvareditmodel.cpp	2012-11-07 14:40:58 UTC (rev 4419)
+++ trunk/rkward/rkward/dataeditor/rkvareditmodel.cpp	2012-11-08 09:52:24 UTC (rev 4420)
@@ -136,7 +136,11 @@
 	if (cindex < 0) return;	// none of our buisiness
 
 	if (meta_model) meta_model->objectMetaChanged (cindex);
+}
 
+void RKVarEditModel::scheduleReset () {
+	RK_TRACE (EDITOR);
+
 	if (!reset_scheduled) {
 		reset_scheduled = true;
 		QTimer::singleShot (0, this, SLOT (doResetNow()));
@@ -166,6 +170,10 @@
 
 	RK_ASSERT (changes);
 
+	if (changes->full_reset) {
+		scheduleReset ();
+		return;
+	}
 	emit (dataChanged (index (changes->from_index, cindex), index (changes->to_index, cindex)));
 }
 
@@ -296,6 +304,8 @@
 	RKVariable::Status status = var->cellStatus (row);
 	if ((role == Qt::BackgroundRole)) {
 		if (status == RKVariable::ValueInvalid) return (Qt::red);
+	} else if (role == Qt::ToolTipRole) {
+		if (status == RKVariable::ValueInvalid) return (i18n ("This value is not allowed, here"));
 	}
 	if ((role == Qt::ForegroundRole) && (status == RKVariable::ValueUnknown)) return (Qt::lightGray);
 	if (role == Qt::TextAlignmentRole) {
@@ -361,18 +371,22 @@
 QVariant RKVarEditModel::headerData (int section, Qt::Orientation orientation, int role) const {
 	RK_TRACE (EDITOR);
 
-	if (role != Qt::DisplayRole) return QVariant ();
-
 	if (orientation == Qt::Horizontal) {
-		if (section >= objects.size ()) return i18n ("#New Variable#");
-		if (section < var_col_offset) return i18n ("Row names");
-		return (QString::number (section - var_col_offset + 1));
+		if (role == Qt::DisplayRole) {
+			if (section >= objects.size ()) return i18n ("#New Variable#");
+			if (section < var_col_offset) return i18n ("Row names");
+			return (QString::number (section - var_col_offset + 1));
+		} else if (role == Qt::BackgroundRole) {
+			if ((section < objects.size  ()) && objects[section]->hasInvalidFields ()) return QVariant (Qt::red);
+		} else if ((role == Qt::ToolTipRole) || (role == Qt::StatusTipRole)) {
+			if ((section < objects.size  ()) && objects[section]->hasInvalidFields ()) return i18n ("This column contains one or more invalid fields");
+		}
+	} else {
+		if ((role == Qt::DisplayRole) && (section < rownames->getLength ())) {
+			return rownames->getText (section);
+		}
 	}
 
-	if (section < rownames->getLength ()) {
-		return rownames->getText (section);
-	}
-
 	return QVariant ();
 }
 
@@ -504,6 +518,7 @@
 	RK_TRACE (EDITOR);
 
 	emit (dataChanged (index (0, atcolumn), index (RowCount - 1, atcolumn)));
+	emit (headerDataChanged (Qt::Horizontal, atcolumn, atcolumn));
 }
 
 int RKVarEditMetaModel::rowCount (const QModelIndex& parent) const {

Modified: trunk/rkward/rkward/dataeditor/rkvareditmodel.h
===================================================================
--- trunk/rkward/rkward/dataeditor/rkvareditmodel.h	2012-11-07 14:40:58 UTC (rev 4419)
+++ trunk/rkward/rkward/dataeditor/rkvareditmodel.h	2012-11-08 09:52:24 UTC (rev 4420)
@@ -100,6 +100,7 @@
 	void doResetNow ();
 private:
 	bool reset_scheduled;
+	void scheduleReset ();
 protected:
 friend class RKVarEditMetaModel;
 	QList<RKVariable*> objects;

Modified: trunk/rkward/rkward/misc/rktableview.cpp
===================================================================
--- trunk/rkward/rkward/misc/rktableview.cpp	2012-11-07 14:40:58 UTC (rev 4419)
+++ trunk/rkward/rkward/misc/rktableview.cpp	2012-11-08 09:52:24 UTC (rev 4420)
@@ -86,9 +86,9 @@
 		if ((reason != RKItemDelegate::EditorExitRight) && (reason != RKItemDelegate::EditorReject)) --col;
 	}
 
-	if ((row < apparentRows ()) && (col < apparentColumns ())) {
-		setCurrentIndex (model ()->index (row, col));
-	}
+	row = qMin (row, apparentRows () - 1);
+	col = qMin (col, apparentColumns () - 1);
+	setCurrentIndex (model ()->index (row, col));
 }
 
 void RKTableView::setRKItemDelegate (RKItemDelegate* delegate) {

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