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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Fri May 18 13:37:53 UTC 2007


Revision: 1913
          http://svn.sourceforge.net/rkward/?rev=1913&view=rev
Author:   tfry
Date:     2007-05-18 06:37:52 -0700 (Fri, 18 May 2007)

Log Message:
-----------
Correctly move invalid fields, when inserting / deleting rows in the data editor

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/rkward/core/rkvariable.cpp

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2007-05-16 19:07:09 UTC (rev 1912)
+++ trunk/rkward/ChangeLog	2007-05-18 13:37:52 UTC (rev 1913)
@@ -1,3 +1,4 @@
+- fixed: inserting / removing rows in the data editor in the presence of invalid fields in later rows would lead to a crash
 - fix some internal problems with enabledness/disabledness of plugin components
 - some complex plotting plugins now start up noticeably faster
 - fixed: sometimes detecting created X11() windows would fail, esp. under high load

Modified: trunk/rkward/rkward/core/rkvariable.cpp
===================================================================
--- trunk/rkward/rkward/core/rkvariable.cpp	2007-05-16 19:07:09 UTC (rev 1912)
+++ trunk/rkward/rkward/core/rkvariable.cpp	2007-05-18 13:37:52 UTC (rev 1913)
@@ -688,11 +688,18 @@
 
 void RKVariable::removeRows (int from_row, int to_row) {
 	RK_TRACE (OBJECTS);
+	int offset = (to_row - from_row) + 1;
 	for (int row = from_row; row <= to_row; ++row) {
 		myData ()->invalid_fields.remove (row);
 	}
 
 	if (to_row < (myData ()->allocated_length - 1)) {	// not the last rows
+		for (int row = to_row; row < getLength (); ++row) {
+			QString *dummy = myData ()->invalid_fields.take (row);
+			if (dummy) {
+				myData ()->invalid_fields.replace (row - offset, dummy);
+			}
+		}
 		if (myData ()->cell_strings) {
 			qmemmove (&(myData ()->cell_strings[from_row]), &(myData ()->cell_strings[to_row+1]), (myData ()->allocated_length - to_row - 1) * sizeof (QString));
 		} else {
@@ -701,11 +708,11 @@
 		qmemmove (&(myData ()->cell_states[from_row]), &(myData ()->cell_states[to_row+1]), (myData ()->allocated_length - to_row - 1) * sizeof (int));
 	}
 
-	for (int row = (myData ()->allocated_length - 1 - (to_row - from_row)); row < myData ()->allocated_length; ++row) {
+	for (int row = (myData ()->allocated_length - offset); row < myData ()->allocated_length; ++row) {
 		myData ()->cell_states[myData ()->allocated_length - 1] = RKVarEditData::Unknown;
 	}
 
-	dimensions[0] -= (to_row - from_row) + 1;	
+	dimensions[0] -= offset;	
 	downSize ();
 }
 
@@ -717,7 +724,7 @@
 void RKVariable::insertRows (int row, int count) {
 	RK_TRACE (OBJECTS);
 	int old_len = getLength ();
-	extendToLength (getLength () + count);
+	extendToLength (getLength () + count);		// getLength is the new length after this
 
 	for (int i=old_len; i <= row+count; ++i) {
 		myData ()->cell_states[i] = RKVarEditData::NA;
@@ -728,6 +735,12 @@
 		if (myData ()->cell_doubles) myData ()->cell_doubles[row+count] = myData ()->cell_doubles[row];
 		myData ()->cell_states[row+count] = myData ()->cell_states[row];
 	} else {
+		for (int i=getLength () - count; i >= row; --i) {
+			QString *dummy = myData ()->invalid_fields.take (i);
+			if (dummy) {
+				myData ()->invalid_fields.replace (i + count, dummy);
+			}
+		}
 		if (myData ()->cell_strings) qmemmove (&(myData ()->cell_strings[row+count]), &(myData ()->cell_strings[row]), (myData ()->allocated_length - (row + count) - 1) * sizeof (QString));
 		if (myData ()->cell_doubles) qmemmove (&(myData ()->cell_doubles[row+count]), &(myData ()->cell_doubles[row]), (myData ()->allocated_length - (row + count) - 1) * sizeof (double));
 		qmemmove (&(myData ()->cell_states[row+count]), &(myData ()->cell_states[row]), (myData ()->allocated_length - (row + count) - 1) * sizeof (int));


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