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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Mon Feb 12 15:41:59 UTC 2007


Revision: 1382
          http://svn.sourceforge.net/rkward/?rev=1382&view=rev
Author:   tfry
Date:     2007-02-12 07:41:59 -0800 (Mon, 12 Feb 2007)

Log Message:
-----------
Fix crash when changing storage type of a variable in the data editor, then editing
The real problem was will using getLength() for the new lenght, instead of allocated_length.
However, the changes also make the code cleaner (if minimally less efficient)

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

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2007-02-12 15:08:00 UTC (rev 1381)
+++ trunk/rkward/ChangeLog	2007-02-12 15:41:59 UTC (rev 1382)
@@ -1,4 +1,5 @@
 --- Version 0.4.6 - Feb-15-2007
+- fix crash after changing storage type of an object in the data editor
 - single line input fields in plugins no longer accept new-lines
 - support for calculating p-values in correlation matrix plugin
 - fixed: pressing F8 in the console would remove input focus from the console

Modified: trunk/rkward/rkward/core/rkvariable.cpp
===================================================================
--- trunk/rkward/rkward/core/rkvariable.cpp	2007-02-12 15:08:00 UTC (rev 1381)
+++ trunk/rkward/rkward/core/rkvariable.cpp	2007-02-12 15:41:59 UTC (rev 1382)
@@ -63,20 +63,14 @@
 			list.append (getText (i));
 		}
 
-		setDataType (new_type);
-		if (new_type == RObject::DataCharacter) {
-			if (myData ()->cell_strings == 0) {
-				delete [] (myData ()->cell_doubles);
-				myData ()->cell_doubles = 0;
-				myData ()->cell_strings = new QString[getLength ()];
-			}
-		} else {
-			if (myData ()->cell_doubles == 0) {
-				delete [] (myData ()->cell_strings);
-				myData ()->cell_strings = 0;
-				myData ()->cell_doubles = new double[getLength ()];
-			}
+		if (myData ()->changes) {	// all pending changes are moot
+			delete myData ()->changes;
+			myData ()->changes = 0;
 		}
+		RKEditor *editor = myData ()->editor;
+		discardEditData ();
+		setDataType (new_type);
+		allocateEditData (editor);
 
 		int i = 0;
 		for (QStringList::const_iterator it = list.constBegin (); it != list.constEnd (); ++it) {
@@ -194,13 +188,14 @@
 }
 
 // virtual
-void RKVariable::allocateEditData () {
+void RKVariable::allocateEditData (RKEditor *editor) {
 	RK_TRACE (OBJECTS);
 
 	// this assert should stay even when more than one editor is allowed per object. After all, the edit-data should only ever be allocated once!
 	RK_ASSERT (!myData ());
 	
 	data = new RKVarEditData;
+	myData ()->editor = editor;
 	myData ()->cell_strings = 0;
 	myData ()->cell_doubles = 0;
 	myData ()->cell_states = 0;
@@ -212,6 +207,7 @@
 	myData ()->previously_valid = true;
 	myData ()->invalid_fields.setAutoDelete (true);
 	myData ()->dirty = false;
+	myData ()->pending = false;
 
 	extendToLength (getLength ());
 

Modified: trunk/rkward/rkward/core/rkvariable.h
===================================================================
--- trunk/rkward/rkward/core/rkvariable.h	2007-02-12 15:08:00 UTC (rev 1381)
+++ trunk/rkward/rkward/core/rkvariable.h	2007-02-12 15:41:59 UTC (rev 1382)
@@ -168,7 +168,7 @@
 		QIntDict<QString> invalid_fields;
 	};
 /** reimplemented from RObject */
-	void allocateEditData ();
+	void allocateEditData (RKEditor *editor);
 /** reimplemented from RObject */
 	void initializeEditDataToEmpty ();
 /** reimplemented from RObject */

Modified: trunk/rkward/rkward/core/robject.cpp
===================================================================
--- trunk/rkward/rkward/core/robject.cpp	2007-02-12 15:08:00 UTC (rev 1381)
+++ trunk/rkward/rkward/core/robject.cpp	2007-02-12 15:41:59 UTC (rev 1382)
@@ -554,10 +554,9 @@
 
 	if (opened) {
 		if (!data) {
-			allocateEditData ();
+			allocateEditData (editor);
 			updateDataFromR (0);
 		}
-		data->editor = editor;
 	} else {
 		discardEditData ();
 	}
@@ -570,21 +569,21 @@
 	RK_ASSERT (!data);
 
 	if (!data) {
-		allocateEditData ();
+		allocateEditData (editor);
 		initializeEditDataToEmpty ();
 	}
-	data->editor = editor;
 	data->pending = true;
 }
 
 // virtual
-void RObject::allocateEditData () {
+void RObject::allocateEditData (RKEditor *editor) {
 	RK_TRACE (OBJECTS);
 
 	// this assert should stay even when more than one editor is allowed per object. After all, the edit-data should only ever be allocated once!
 	RK_ASSERT (!data);
 	
 	data = new EditData;
+	data->editor = editor;
 	data->dirty = false;
 	data->pending = false;
 }

Modified: trunk/rkward/rkward/core/robject.h
===================================================================
--- trunk/rkward/rkward/core/robject.h	2007-02-12 15:08:00 UTC (rev 1381)
+++ trunk/rkward/rkward/core/robject.h	2007-02-12 15:41:59 UTC (rev 1382)
@@ -240,7 +240,7 @@
 /** see EditData. 0 if the object is not being edited. */
 	EditData *data;
 /** see EditData. Allocates the data member. To be reimplemented in classes that need more information in the EditData struct */
-	virtual void allocateEditData ();
+	virtual void allocateEditData (RKEditor *editor);
 /** companion to allocateEditData (). Initializes the data to empty (NA). Default implementation does nothing. Reimplemented in derived classes. */
 	virtual void initializeEditDataToEmpty ();
 /** see above */


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