[rkward-cvs] SF.net SVN: rkward: [2187] branches/KDE4_port/rkward/dataeditor

tfry at users.sourceforge.net tfry at users.sourceforge.net
Thu Nov 8 13:04:54 UTC 2007


Revision: 2187
          http://rkward.svn.sourceforge.net/rkward/?rev=2187&view=rev
Author:   tfry
Date:     2007-11-08 05:04:53 -0800 (Thu, 08 Nov 2007)

Log Message:
-----------
More on copy / paste (work in progress)

Modified Paths:
--------------
    branches/KDE4_port/rkward/dataeditor/CMakeLists.txt
    branches/KDE4_port/rkward/dataeditor/editlabelsdialog.cpp
    branches/KDE4_port/rkward/dataeditor/editlabelsdialog.h
    branches/KDE4_port/rkward/dataeditor/rkeditordataframe.cpp
    branches/KDE4_port/rkward/dataeditor/rkeditordataframe.h
    branches/KDE4_port/rkward/dataeditor/rkeditordataframepart.cpp
    branches/KDE4_port/rkward/dataeditor/twintable.cpp
    branches/KDE4_port/rkward/dataeditor/twintable.h
    branches/KDE4_port/rkward/dataeditor/twintablemember.cpp
    branches/KDE4_port/rkward/dataeditor/twintablemember.h

Added Paths:
-----------
    branches/KDE4_port/rkward/dataeditor/rktextmatrix.cpp
    branches/KDE4_port/rkward/dataeditor/rktextmatrix.h

Modified: branches/KDE4_port/rkward/dataeditor/CMakeLists.txt
===================================================================
--- branches/KDE4_port/rkward/dataeditor/CMakeLists.txt	2007-11-08 00:25:40 UTC (rev 2186)
+++ branches/KDE4_port/rkward/dataeditor/CMakeLists.txt	2007-11-08 13:04:53 UTC (rev 2187)
@@ -16,6 +16,7 @@
    editformatdialog.cpp
    rkeditordataframepart.cpp
    rkvareditmodel.cpp
+   rktextmatrix.cpp
    )
 
 QT4_AUTOMOC(${dataeditor_STAT_SRCS})

Modified: branches/KDE4_port/rkward/dataeditor/editlabelsdialog.cpp
===================================================================
--- branches/KDE4_port/rkward/dataeditor/editlabelsdialog.cpp	2007-11-08 00:25:40 UTC (rev 2186)
+++ branches/KDE4_port/rkward/dataeditor/editlabelsdialog.cpp	2007-11-08 13:04:53 UTC (rev 2187)
@@ -73,17 +73,6 @@
 	blankSelected ();
 }
 
-void LevelsTable::copy () {
-	RK_TRACE (EDITOR);
-
-#warning copy functionality should be move to TwinTableMember directly. See also RKEditorDataFramePart
-	QString text = getSelectionText ();
-	QMimeData* data = new QMimeData ();
-	data->setText (text);
-	data->setData ("text/tab-separated-values", text.toLocal8Bit ());
-	QApplication::clipboard()->setMimeData (data);
-}
-
 void LevelsTable::paste () {
 	RK_TRACE (EDITOR);
 

Modified: branches/KDE4_port/rkward/dataeditor/editlabelsdialog.h
===================================================================
--- branches/KDE4_port/rkward/dataeditor/editlabelsdialog.h	2007-11-08 00:25:40 UTC (rev 2186)
+++ branches/KDE4_port/rkward/dataeditor/editlabelsdialog.h	2007-11-08 13:04:53 UTC (rev 2187)
@@ -48,8 +48,6 @@
 public slots:
 /** cut */
 	void cut();
-/** copy */
-	void copy();
 /** paste */
 	void paste();
 protected:

Modified: branches/KDE4_port/rkward/dataeditor/rkeditordataframe.cpp
===================================================================
--- branches/KDE4_port/rkward/dataeditor/rkeditordataframe.cpp	2007-11-08 00:25:40 UTC (rev 2186)
+++ branches/KDE4_port/rkward/dataeditor/rkeditordataframe.cpp	2007-11-08 13:04:53 UTC (rev 2187)
@@ -171,28 +171,6 @@
 	RKGlobals::tracker ()->removeObject (obj);
 }
 
-void RKEditorDataFrame::removeObject (RObject *object) {
-	RK_TRACE (EDITOR);
-	if (object == getObject ()) {
-		// self destruct
-		delete this;
-		return;
-	}
-	
-	int col = getObjectCol (object);
-	RK_ASSERT (col >= 0);
-	// for now:
-	if (col < 0) return;
-
-//	object->setObjectOpened (this, false);
-	
-	for (int i=(col+1); i < numTrueCols (); ++i) {
-		setColObject (i-1, getColObject (i));
-	}
-	setColObject (numTrueCols () - 1, 0);
-	deleteColumn (col);
-}
-
 void RKEditorDataFrame::restoreObject (RObject *object) {
 	RK_TRACE (EDITOR);
 	// for now, simply sync the whole table unconditionally.
@@ -204,18 +182,6 @@
 	}
 }
 
-void RKEditorDataFrame::renameObject (RObject *object) {
-	RK_TRACE (EDITOR);
-	
-	if (object == getObject ()) {
-		setCaption (object->getShortName ());
-		return;
-	}
-
-	int col = getObjectCol (object);
-	varview->updateCell (NAME_ROW, col);
-}
-
 void RKEditorDataFrame::updateObjectMeta (RObject *object) {
 	RK_TRACE (EDITOR);
 	if (object == getObject ()) return;	// for now: can't update meta on the table itself

Modified: branches/KDE4_port/rkward/dataeditor/rkeditordataframe.h
===================================================================
--- branches/KDE4_port/rkward/dataeditor/rkeditordataframe.h	2007-11-08 00:25:40 UTC (rev 2186)
+++ branches/KDE4_port/rkward/dataeditor/rkeditordataframe.h	2007-11-08 13:04:53 UTC (rev 2187)
@@ -49,12 +49,8 @@
 	//void objectDeleted (RObject *object);
 	//void objectMetaModified (RObject *object);
 
-/** Tells the editor to (unconditionally!) remove the object from its list. */
-	void removeObject (RObject *object);
 /** Tells the editor to restore the given object in the R-workspace from its copy of the data */
 	void restoreObject (RObject *object);
-/** Tells the editor to (unconditionally!) rename the object (the object already carries the new name, so the editor can read the new name from the object). */
-	void renameObject (RObject *object);
 /** Tell the editor to (unconditionally) update its representation of the object meta data */
 	void updateObjectMeta (RObject *object);
 /** Tell the editor to (unconditionally) update its representation of the object data (in the range given in the ChangeSet) */

Modified: branches/KDE4_port/rkward/dataeditor/rkeditordataframepart.cpp
===================================================================
--- branches/KDE4_port/rkward/dataeditor/rkeditordataframepart.cpp	2007-11-08 00:25:40 UTC (rev 2186)
+++ branches/KDE4_port/rkward/dataeditor/rkeditordataframepart.cpp	2007-11-08 13:04:53 UTC (rev 2187)
@@ -75,11 +75,7 @@
 	RK_TRACE (EDITOR);
 	
 	RKWardMainWindow::getMain ()->slotSetStatusBarText (i18n ("Copying selection to clipboard..."));
-	QString text = editor->getSelectedText ();
-	QMimeData* data = new QMimeData ();
-	data->setText (text);
-	data->setData ("text/tab-separated-values", text.toLocal8Bit ());
-	QApplication::clipboard ()->setMimeData (data);
+	editor->copy ();
 	RKWardMainWindow::getMain ()->slotSetStatusReady ();
 }
 

Added: branches/KDE4_port/rkward/dataeditor/rktextmatrix.cpp
===================================================================
--- branches/KDE4_port/rkward/dataeditor/rktextmatrix.cpp	                        (rev 0)
+++ branches/KDE4_port/rkward/dataeditor/rktextmatrix.cpp	2007-11-08 13:04:53 UTC (rev 2187)
@@ -0,0 +1,194 @@
+/***************************************************************************
+                          rktextmatrix  -  description
+                             -------------------
+    begin                : Thu Nov 08 2007
+    copyright            : (C) 2007 by Thomas Friedrichsmeier
+    email                : tfry at users.sourceforge.net
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#include "rktextmatrix.h"
+
+#include <QApplication>
+#include <QClipboard>
+#include <QMimeData>
+
+#include "../debug.h"
+
+RKTextMatrix::RKTextMatrix () {
+	RK_TRACE (EDITOR);
+
+	clear ();
+}
+
+RKTextMatrix::RKTextMatrix (const RKTextMatrix& copy) {
+	RK_TRACE (EDITOR);
+
+	rowcount = copy.rowcount;
+	colcount = copy.colcount;
+	columns = copy.columns;
+}
+
+RKTextMatrix::~RKTextMatrix () {
+	RK_TRACE (EDITOR);
+}
+
+// static
+RKTextMatrix RKTextMatrix::matrixFromClipboard () {
+	RK_TRACE (EDITOR);
+
+	const QMimeData* data = QApplication::clipboard ()->mimeData ();
+	// actually, we don't care, whether tsv or plain gets pasted - it's both
+	// treated the same. We should however encourage external senders to
+	// provided the two in order.
+	if (data->hasFormat ("text/tab-separated-values")) {
+		RK_DO (qDebug ("paste tsv"), EDITOR, DL_DEBUG);
+		return (matrixFromTabSeparatedValues (QString::fromLocal8Bit (data->data ("text/tab-separated-values"))));
+	} else if (data->hasText ()) {
+		RK_DO (qDebug ("paste plain text"), EDITOR, DL_DEBUG);
+		return (matrixFromTabSeparatedValues (data->text ()));
+	}
+
+	return RKTextMatrix ();
+}
+
+// static
+RKTextMatrix RKTextMatrix::matrixFromTabSeparatedValues (const QString& tsv) {
+	RK_TRACE (EDITOR);
+
+	RKTextMatrix ret;
+
+	QChar tab ('\t');
+	QChar brk ('\n');
+
+	int buffer_len = tsv.length ();
+	int row = 0;
+	int col = 0;
+
+	QString current_word;
+	for (int pos = 0; pos < buffer_len; ++pos) {
+		QChar c = tsv.at (pos);
+		if (c == tab) {
+			ret.columns[col][row] = current_word;
+			ret.upsize (++row, col);
+			current_word.clear ();
+		} else if (c == brk) {
+			ret.columns[col][row] = current_word;
+			ret.upsize (row, ++col);
+			current_word.clear ();
+		} else {
+			current_word.append (c);
+		}
+	}
+
+	return ret;
+}
+
+QString RKTextMatrix::toTabSeparatedValues () const {
+	RK_TRACE (EDITOR);
+
+	QString ret;
+	RK_ASSERT (columns.size () == colcount);
+	for (int col = 0; col < colcount; ++col) {
+		TextColumn column = columns[col];
+		RK_ASSERT (column.size () == rowcount);
+
+		if (col) ret.append ('\n');
+
+		for (int row = 0; row < rowcount; ++row) {
+			if (row) ret.append ('\t');
+			ret.append (column[row]);
+		}
+	}
+	return ret;
+}
+
+void RKTextMatrix::copyToClipboard () const {
+	RK_TRACE (EDITOR);
+
+	QString text = toTabSeparatedValues ();
+	QMimeData* data = new QMimeData ();
+	data->setText (text);
+	data->setData ("text/tab-separated-values", text.toLocal8Bit ());
+	QApplication::clipboard()->setMimeData (data);
+}
+
+void RKTextMatrix::setText (int row, int col, const QString& text) {
+//	RK_TRACE (EDITOR);
+
+	upsize (row, col);
+	columns[col][row] = text;
+}
+
+void RKTextMatrix::setColumn (int column, const QString* textarray, int length) {
+	RK_TRACE (EDITOR);
+
+	upsize (length, column);
+	for (int i = 0; i < length; ++i) {
+		columns[column][i] = textarray[i];
+	}
+}
+
+QString RKTextMatrix::getText (int row, int col) const {
+//	RK_TRACE (EDITOR);
+
+	if ((row > rowcount) || (col > colcount)) return QString ();
+	return (columns[col][row]);
+}
+
+QString* RKTextMatrix::getColumn (int col, int* col_length) const {
+	RK_TRACE (EDITOR);
+
+	if (col > colcount) {
+		*col_length = 0;
+		return 0;
+	}
+
+	TextColumn column = columns[col];
+	QString* ret = new QString[column.size ()];
+	*col_length = column.size ();
+	RK_ASSERT (*col_length == rowcount);
+	for (int i = 0; i < column.size (); ++i) {
+		ret[i] = column[i];
+	}
+	return ret;
+}
+
+void RKTextMatrix::clear () {
+	RK_TRACE (EDITOR);
+
+	columns.clear ();
+	rowcount = colcount = 0;
+}
+
+bool RKTextMatrix::isEmpty () const {
+	RK_TRACE (EDITOR);
+
+	if ((rowcount == 0) || (colcount == 0)) return true;
+	RK_ASSERT (!columns.isEmpty ());
+	return false;
+}
+
+void RKTextMatrix::upsize (int newrowcount, int newcolcount) {
+//	RK_TRACE (EDITOR);
+
+	if (newcolcount > colcount) {
+		columns.resize (newcolcount);
+		colcount = newcolcount;
+		RK_ASSERT (colcount == columns.size ());
+	}
+
+	if (newrowcount > rowcount) {
+		for (int i = 0; i < colcount; ++i) {
+			columns[i].resize (newrowcount);
+		}
+	}
+}

Added: branches/KDE4_port/rkward/dataeditor/rktextmatrix.h
===================================================================
--- branches/KDE4_port/rkward/dataeditor/rktextmatrix.h	                        (rev 0)
+++ branches/KDE4_port/rkward/dataeditor/rktextmatrix.h	2007-11-08 13:04:53 UTC (rev 2187)
@@ -0,0 +1,59 @@
+/***************************************************************************
+                          rktextmatrix  -  description
+                             -------------------
+    begin                : Thu Nov 08 2007
+    copyright            : (C) 2007 by Thomas Friedrichsmeier
+    email                : tfry at users.sourceforge.net
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#ifndef RKTEXTMATRIX_H
+#define RKTEXTMATRIX_H
+
+#include <QVector>
+#include <QString>
+
+/** This class is meant to assist paste operations in tables. Most importantly, it provides methods to map
+to and from text/tab-separated-values format.
+
+ at author Thomas Friedrichsmeier */
+class RKTextMatrix {
+public:
+	RKTextMatrix ();
+/** copy constructor. Since we're mostly just copying a QVector (which is implicitely shared) and two ints, this is pretty fast. */
+	RKTextMatrix (const RKTextMatrix& copy);
+	~RKTextMatrix ();
+
+	static RKTextMatrix matrixFromClipboard ();
+	static RKTextMatrix matrixFromTabSeparatedValues (const QString& tsv);
+
+	QString toTabSeparatedValues () const;
+	void copyToClipboard () const;
+
+	void setText (int row, int col, const QString& text);
+	void setColumn (int column, const QString* textarray, int length);
+
+	QString getText (int row, int col) const;
+	QString* getColumn (int col, int* col_length) const;
+
+	void clear ();
+	bool isEmpty () const;
+private:
+	typedef QVector<QString> TextColumn;
+	QVector<TextColumn> columns;
+
+	inline void upsize (int newrowcount, int newcolcount);
+
+	int colcount;
+	int rowcount;
+};
+
+#endif

Modified: branches/KDE4_port/rkward/dataeditor/twintable.cpp
===================================================================
--- branches/KDE4_port/rkward/dataeditor/twintable.cpp	2007-11-08 00:25:40 UTC (rev 2186)
+++ branches/KDE4_port/rkward/dataeditor/twintable.cpp	2007-11-08 13:04:53 UTC (rev 2187)
@@ -332,6 +332,15 @@
 	}
 }
 
+void TwinTable::copy () {
+	RK_TRACE (EDITOR);
+
+	flushEdit ();
+	TwinTableMember *table = activeTable ();
+	if (!table) return;
+	table->copy ();
+}
+
 void TwinTable::paste (const QString& pasted, RKEditor::PasteMode paste_mode) {
 	RK_TRACE (EDITOR);
 

Modified: branches/KDE4_port/rkward/dataeditor/twintable.h
===================================================================
--- branches/KDE4_port/rkward/dataeditor/twintable.h	2007-11-08 00:25:40 UTC (rev 2186)
+++ branches/KDE4_port/rkward/dataeditor/twintable.h	2007-11-08 13:04:53 UTC (rev 2187)
@@ -61,6 +61,8 @@
 	void deleteRow (int where, TwinTableMember *table=0);
 /** Pastes content to the current table */
 	void paste (const QString& pasted, RKEditor::PasteMode paste_mode);
+/** Copy selection in the current table to clipboard */
+	void copy ();
 /** Same as above, but flips the data (i.e. row <-> cols) */
 //	void pasteEncodedFlipped (QByteArray content);
 /** Clear the currently selected cells */

Modified: branches/KDE4_port/rkward/dataeditor/twintablemember.cpp
===================================================================
--- branches/KDE4_port/rkward/dataeditor/twintablemember.cpp	2007-11-08 00:25:40 UTC (rev 2186)
+++ branches/KDE4_port/rkward/dataeditor/twintablemember.cpp	2007-11-08 13:04:53 UTC (rev 2187)
@@ -20,6 +20,8 @@
 #include <qevent.h>
 #include <qpainter.h>
 #include <qstyle.h>
+#include <qapplication.h>
+#include <qclipboard.h>
 //Added by qt3to4:
 #include <QMouseEvent>
 #include <QKeyEvent>
@@ -172,6 +174,16 @@
 	viewport ()->setFocus ();
 }
 
+void TwinTableMember::copy () {
+	RK_TRACE (EDITOR);
+
+	QString text = getSelectionText ();
+	QMimeData* data = new QMimeData ();
+	data->setText (text);
+	data->setData ("text/tab-separated-values", text.toLocal8Bit ());
+	QApplication::clipboard()->setMimeData (data);
+}
+
 QString TwinTableMember::getSelectionText () {
 	RK_TRACE (EDITOR);
 

Modified: branches/KDE4_port/rkward/dataeditor/twintablemember.h
===================================================================
--- branches/KDE4_port/rkward/dataeditor/twintablemember.h	2007-11-08 00:25:40 UTC (rev 2186)
+++ branches/KDE4_port/rkward/dataeditor/twintablemember.h	2007-11-08 13:04:53 UTC (rev 2187)
@@ -117,6 +117,7 @@
 	void setTwin (TwinTableMember *new_twin);
 public slots:
 	void editorLostFocus ();
+	void copy ();
 /** called when the current cell is changed. If no selection is in place, will (does not do it yet) pop up the value-list */
 	void currentCellChanged (int row, int col);
 protected slots:


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