[rkward-cvs] SF.net SVN: rkward:[3056] trunk/rkward
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Tue Sep 21 14:45:34 UTC 2010
Revision: 3056
http://rkward.svn.sourceforge.net/rkward/?rev=3056&view=rev
Author: tfry
Date: 2010-09-21 14:45:33 +0000 (Tue, 21 Sep 2010)
Log Message:
-----------
Check editor model for duplicate column names, and warn if any dupes are found.
Modified Paths:
--------------
trunk/rkward/ChangeLog
trunk/rkward/rkward/dataeditor/rkvareditmodel.cpp
trunk/rkward/rkward/dataeditor/rkvareditmodel.h
trunk/rkward/rkward/dataeditor/twintable.cpp
trunk/rkward/rkward/dataeditor/twintable.h
Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog 2010-09-20 11:18:06 UTC (rev 3055)
+++ trunk/rkward/ChangeLog 2010-09-21 14:45:33 UTC (rev 3056)
@@ -1,5 +1,5 @@
- Added full-featured plot history for the onscreen graphics device
-- Fixed: Potential crash when editing data-frame with duplicate column names TODO: warn when editing such a data.frame
+- Fixed: Potential crash when editing data-frame with duplicate column names
- Added option to specify default onscreen graphics dimensions TODO: test on windows
- Fixed: Graphics windows used to assume a minimum size of 640*480 pixels, even if a smaller size was specified / TODO: check on Windows!
- Added option to disable function argument hinting
Modified: trunk/rkward/rkward/dataeditor/rkvareditmodel.cpp
===================================================================
--- trunk/rkward/rkward/dataeditor/rkvareditmodel.cpp 2010-09-20 11:18:06 UTC (rev 3055)
+++ trunk/rkward/rkward/dataeditor/rkvareditmodel.cpp 2010-09-21 14:45:33 UTC (rev 3056)
@@ -20,6 +20,7 @@
#include <klocale.h>
#include <QColor>
+#include <QTimer>
#include "../core/rcontainerobject.h"
#include "../core/rkmodificationtracker.h"
@@ -38,6 +39,7 @@
edit_blocks = 0;
rownames = 0;
header_locked = false;
+ duplicate_check_triggered = false;
addNotificationType (RObjectListener::ObjectRemoved);
addNotificationType (RObjectListener::MetaChanged);
@@ -73,6 +75,8 @@
objects.insert (index, object);
if (meta_model) meta_model->endAddDataObject ();
endInsertColumns ();
+
+ checkDuplicates ();
}
void RKVarEditModel::objectRemoved (RObject* object) {
@@ -94,6 +98,35 @@
if (objects.size () <= var_col_offset) emit (modelDepleted ()); // editor may or may want to auto-destruct
}
+void RKVarEditModel::checkDuplicates () {
+ RK_TRACE (EDITOR);
+
+ if (duplicate_check_triggered) return;
+ duplicate_check_triggered = true;
+ QTimer::singleShot (0, this, SLOT (checkDuplicatesNow()));
+}
+
+void RKVarEditModel::checkDuplicatesNow () {
+ RK_TRACE (EDITOR);
+
+ duplicate_check_triggered = false;
+
+ QStringList dupes;
+ for (int i = var_col_offset; i < objects.size (); ++i) {
+ QString name = objects[i]->getShortName ();
+ for (int j = i+1; j < objects.size (); ++j) {
+ if (objects[j]->getShortName () == name) {
+ if (objects[i]->getFullName () == objects[j]->getFullName ()) {
+ dupes.append (objects[i]->getFullName ());
+ j = objects.size (); // break
+ }
+ }
+ }
+ }
+
+ if (!dupes.isEmpty ()) emit (hasDuplicates (dupes));
+}
+
void RKVarEditModel::objectMetaChanged (RObject* changed) {
RK_TRACE (EDITOR);
Modified: trunk/rkward/rkward/dataeditor/rkvareditmodel.h
===================================================================
--- trunk/rkward/rkward/dataeditor/rkvareditmodel.h 2010-09-20 11:18:06 UTC (rev 3055)
+++ trunk/rkward/rkward/dataeditor/rkvareditmodel.h 2010-09-21 14:45:33 UTC (rev 3056)
@@ -94,6 +94,9 @@
RKVariable* getObject (int index) const;
signals:
void modelDepleted ();
+ void hasDuplicates (const QStringList& dupes);
+private slots:
+ void checkDuplicatesNow ();
protected:
friend class RKVarEditMetaModel;
QList<RKVariable*> objects;
@@ -113,6 +116,10 @@
virtual void doInsertRowsInBackend (int row, int count);
virtual void doRemoveRowsInBackend (int row, int count);
+ /** Check whether there are any duplicate names in the model. Actual check is delayed until the next iteration of the event loop. If a duplicate is found, hasDuplicates(const QStringList&) is emitted. */
+ void checkDuplicates ();
+ bool duplicate_check_triggered;
+
int trailing_rows;
int trailing_cols;
Modified: trunk/rkward/rkward/dataeditor/twintable.cpp
===================================================================
--- trunk/rkward/rkward/dataeditor/twintable.cpp 2010-09-20 11:18:06 UTC (rev 3055)
+++ trunk/rkward/rkward/dataeditor/twintable.cpp 2010-09-21 14:45:33 UTC (rev 3056)
@@ -21,6 +21,7 @@
#include <kaction.h>
#include <kactioncollection.h>
#include <kxmlguifactory.h>
+#include <kmessagebox.h>
#include <qvariant.h>
#include <qsplitter.h>
@@ -171,8 +172,17 @@
addNotificationType (RObjectListener::MetaChanged);
listenForObject (object);
objectMetaChanged (object);
+ connect (model, SIGNAL (hasDuplicates(const QStringList&)), this, SLOT (containsDuplicates(const QStringList&)));
}
+void TwinTable::containsDuplicates (const QStringList& dupes) {
+ RK_TRACE (EDITOR);
+
+ if (!rw) return;
+ KMessageBox::informationList (this, i18n ("The editor '%1' contains the following duplicate columns. Editing this table may not be safe, and has been disabled. You may re-enable editing if you know what you are doing, but you are strongly advised to fix the table, and/or backup your data, first.", windowTitle ()), dupes, i18n ("Duplicate columns detected"));
+ enableEditing (false);
+}
+
void TwinTable::objectMetaChanged (RObject* changed) {
RK_TRACE (EDITOR);
Modified: trunk/rkward/rkward/dataeditor/twintable.h
===================================================================
--- trunk/rkward/rkward/dataeditor/twintable.h 2010-09-20 11:18:06 UTC (rev 3055)
+++ trunk/rkward/rkward/dataeditor/twintable.h 2010-09-21 14:45:33 UTC (rev 3056)
@@ -72,6 +72,8 @@
void pasteToTable();
/** paste the clipboard into the table, but not beyond selection boundaries */
void pasteToSelection();
+/** connected to RKVarEditModel::hasDuplicates() */
+ void containsDuplicates (const QStringList& dupes);
private:
int meta_header_anchor_section;
/** read-write */
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