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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Thu Nov 8 00:25:41 UTC 2007


Revision: 2186
          http://rkward.svn.sourceforge.net/rkward/?rev=2186&view=rev
Author:   tfry
Date:     2007-11-07 16:25:40 -0800 (Wed, 07 Nov 2007)

Log Message:
-----------
Modernize copy-and-paste internals

Modified Paths:
--------------
    branches/KDE4_port/rkward/dataeditor/editlabelsdialog.cpp
    branches/KDE4_port/rkward/dataeditor/rkdrag.cpp
    branches/KDE4_port/rkward/dataeditor/rkdrag.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

Modified: branches/KDE4_port/rkward/dataeditor/editlabelsdialog.cpp
===================================================================
--- branches/KDE4_port/rkward/dataeditor/editlabelsdialog.cpp	2007-11-07 23:49:48 UTC (rev 2185)
+++ branches/KDE4_port/rkward/dataeditor/editlabelsdialog.cpp	2007-11-08 00:25:40 UTC (rev 2186)
@@ -37,7 +37,6 @@
 #include <Q3VBoxLayout>
 
 #include "../core/rkvariable.h"
-#include "rkdrag.h"
 #include "celleditor.h"
 
 #include "../debug.h"
@@ -77,7 +76,12 @@
 void LevelsTable::copy () {
 	RK_TRACE (EDITOR);
 
-	QApplication::clipboard()->setData (new RKDrag (this));
+#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 () {
@@ -89,10 +93,14 @@
 	// treated the same. We should however encourage external senders to
 	// provided the two in order.
 	QString pasted;
-	if (QApplication::clipboard()->data()->provides ("text/tab-separated-values")) {
-		pasted = QString (QApplication::clipboard ()->data ()->encodedData ("text/tab-separated-values"));
-	} else if (QApplication::clipboard()->data()->provides ("text/plain")) {
-		pasted = QString (QApplication::clipboard ()->data ()->encodedData ("text/plain"));
+	const QMimeData* data = QApplication::clipboard ()->mimeData ();
+	if (data->hasFormat ("text/tab-separated-values")) {
+		pasted = QString::fromLocal8Bit (data->data ("text/tab-separated-values"));
+	} else if (data->hasText ()) {
+		pasted = data->text ();
+	} else {
+		RK_DO (qDebug ("no suitable format for pasting"), EDITOR, DL_INFO);
+		return;
 	}
 
 	int content_offset = 0;

Modified: branches/KDE4_port/rkward/dataeditor/rkdrag.cpp
===================================================================
--- branches/KDE4_port/rkward/dataeditor/rkdrag.cpp	2007-11-07 23:49:48 UTC (rev 2185)
+++ branches/KDE4_port/rkward/dataeditor/rkdrag.cpp	2007-11-08 00:25:40 UTC (rev 2186)
@@ -27,9 +27,9 @@
 	RK_TRACE (EDITOR);
 
 	RK_ASSERT (drag_source);
-	if (drag_source) {
+/*	if (drag_source) {
 		data = drag_source->encodeSelection ();
-	}
+	} */
 }
 
 RKDrag::~RKDrag () {

Modified: branches/KDE4_port/rkward/dataeditor/rkdrag.h
===================================================================
--- branches/KDE4_port/rkward/dataeditor/rkdrag.h	2007-11-07 23:49:48 UTC (rev 2185)
+++ branches/KDE4_port/rkward/dataeditor/rkdrag.h	2007-11-08 00:25:40 UTC (rev 2186)
@@ -24,6 +24,7 @@
 
 class TwinTableMember;
 
+#warning TODO remove. This class is obsolete
 /** A QDragObject that gets its data from a TwinTableMember. Used for all copy/paste/drag operations involving TwinTableMembers.
   *@author Thomas Friedrichsmeier
   */

Modified: branches/KDE4_port/rkward/dataeditor/rkeditordataframepart.cpp
===================================================================
--- branches/KDE4_port/rkward/dataeditor/rkeditordataframepart.cpp	2007-11-07 23:49:48 UTC (rev 2185)
+++ branches/KDE4_port/rkward/dataeditor/rkeditordataframepart.cpp	2007-11-08 00:25:40 UTC (rev 2186)
@@ -24,7 +24,6 @@
 #include <klocale.h>
 
 #include "rkeditordataframe.h"
-#include "rkdrag.h"
 #include "../rkward.h"
 #include "../debug.h"
 
@@ -76,7 +75,11 @@
 	RK_TRACE (EDITOR);
 	
 	RKWardMainWindow::getMain ()->slotSetStatusBarText (i18n ("Copying selection to clipboard..."));
-	QApplication::clipboard()->setData(editor->makeDrag ());
+	QString text = editor->getSelectedText ();
+	QMimeData* data = new QMimeData ();
+	data->setText (text);
+	data->setData ("text/tab-separated-values", text.toLocal8Bit ());
+	QApplication::clipboard ()->setMimeData (data);
 	RKWardMainWindow::getMain ()->slotSetStatusReady ();
 }
 
@@ -102,19 +105,18 @@
 void RKEditorDataFramePart::doPaste (RKEditor::PasteMode mode) {
 	RK_TRACE (EDITOR);
 
-	RKWardMainWindow::getMain ()->slotSetStatusBarText(i18n("Inserting clipboard contents..."));
+	RKWardMainWindow::getMain ()->slotSetStatusBarText (i18n ("Inserting clipboard contents..."));
 
+	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 (QApplication::clipboard()->data()->provides ("text/tab-separated-values")) {
+	if (data->hasFormat ("text/tab-separated-values")) {
 		RK_DO (qDebug ("paste tsv"), EDITOR, DL_DEBUG);
-		QByteArray data = QApplication::clipboard()->data()->encodedData ("text/tab-separated-values");
-		editor->paste (data, mode);
-	} else if (QApplication::clipboard()->data()->provides ("text/plain")) {
+		editor->paste (QString::fromLocal8Bit (data->data ("text/tab-separated-values")), mode);
+	} else if (data->hasText ()) {
 		RK_DO (qDebug ("paste plain text"), EDITOR, DL_DEBUG);
-		QByteArray data = QApplication::clipboard()->data()->encodedData ("text/plain");
-		editor->paste (data, mode);
+		editor->paste (data->text (), mode);
 	}
 
 	RKWardMainWindow::getMain ()->slotSetStatusReady ();

Modified: branches/KDE4_port/rkward/dataeditor/twintable.cpp
===================================================================
--- branches/KDE4_port/rkward/dataeditor/twintable.cpp	2007-11-07 23:49:48 UTC (rev 2185)
+++ branches/KDE4_port/rkward/dataeditor/twintable.cpp	2007-11-08 00:25:40 UTC (rev 2186)
@@ -34,7 +34,6 @@
 #include "twintabledatamember.h"
 #include "twintablemetamember.h"
 #include "twintablemember.h"
-#include "rkdrag.h"
 
 #include "../debug.h"
 
@@ -288,9 +287,9 @@
 	connect (dataview, SIGNAL (selectionChanged ()), this, SLOT (viewClearSelection ()));
 }
 
-RKDrag *TwinTable::makeDrag () {
+QString TwinTable::getSelectedText () {
 	RK_TRACE (EDITOR);
-	return (new RKDrag (activeTable ()));
+	return (activeTable ()->getSelectionText ());
 }
 
 void TwinTable::insertColumnRight () {
@@ -333,7 +332,7 @@
 	}
 }
 
-void TwinTable::paste (QByteArray &content, RKEditor::PasteMode paste_mode) {
+void TwinTable::paste (const QString& pasted, RKEditor::PasteMode paste_mode) {
 	RK_TRACE (EDITOR);
 
 	flushEdit ();
@@ -360,7 +359,6 @@
 
 	Q3ValueList<RKVariable*> col_list;
 
-	QString pasted = QString::fromLocal8Bit (content);
 	int row = top_row;
 	int col = left_col;
 	int content_offset = 0;

Modified: branches/KDE4_port/rkward/dataeditor/twintable.h
===================================================================
--- branches/KDE4_port/rkward/dataeditor/twintable.h	2007-11-07 23:49:48 UTC (rev 2185)
+++ branches/KDE4_port/rkward/dataeditor/twintable.h	2007-11-08 00:25:40 UTC (rev 2186)
@@ -60,12 +60,12 @@
 /** Inserts the row at the given position (or at the end for -1) in the given table. Don't try to do this in the varview, yet! */
 	void deleteRow (int where, TwinTableMember *table=0);
 /** Pastes content to the current table */
-	void paste (QByteArray &content, RKEditor::PasteMode paste_mode);
+	void paste (const QString& pasted, RKEditor::PasteMode paste_mode);
 /** Same as above, but flips the data (i.e. row <-> cols) */
 //	void pasteEncodedFlipped (QByteArray content);
 /** Clear the currently selected cells */
 	void clearSelected ();
-	RKDrag *makeDrag ();
+	QString getSelectedText ();
 
 /** Flushes pending edit-operations */
 	void flushEdit ();

Modified: branches/KDE4_port/rkward/dataeditor/twintablemember.cpp
===================================================================
--- branches/KDE4_port/rkward/dataeditor/twintablemember.cpp	2007-11-07 23:49:48 UTC (rev 2185)
+++ branches/KDE4_port/rkward/dataeditor/twintablemember.cpp	2007-11-08 00:25:40 UTC (rev 2186)
@@ -21,7 +21,6 @@
 #include <qpainter.h>
 #include <qstyle.h>
 //Added by qt3to4:
-#include <Q3CString>
 #include <QMouseEvent>
 #include <QKeyEvent>
 #include <Q3MemArray>
@@ -173,16 +172,15 @@
 	viewport ()->setFocus ();
 }
 
-Q3CString TwinTableMember::encodeSelection () {
+QString TwinTableMember::getSelectionText () {
 	RK_TRACE (EDITOR);
 
 	int top_row, left_col, bottom_row, right_col;
 	getSelectionBoundaries (&top_row, &left_col, &bottom_row, &right_col);
-// QCString uses (explicit) sharing, so we're not being too wasteful, here
-	return (encodeRange (top_row, left_col, bottom_row, right_col));
+	return (getRangeText (top_row, left_col, bottom_row, right_col));
 }
 
-Q3CString TwinTableMember::encodeRange (int top_row, int left_col, int bottom_row, int right_col) {
+QString TwinTableMember::getRangeText (int top_row, int left_col, int bottom_row, int right_col) {
 	RK_TRACE (EDITOR);
 
 	QString data;
@@ -197,8 +195,7 @@
 			data.append ("\n");
 		}
 	}
-
-	return data.local8Bit ();
+	return data;
 }
 
 void TwinTableMember::blankSelected () {

Modified: branches/KDE4_port/rkward/dataeditor/twintablemember.h
===================================================================
--- branches/KDE4_port/rkward/dataeditor/twintablemember.h	2007-11-07 23:49:48 UTC (rev 2185)
+++ branches/KDE4_port/rkward/dataeditor/twintablemember.h	2007-11-08 00:25:40 UTC (rev 2186)
@@ -21,7 +21,6 @@
 #include <q3table.h>
 #include <qpoint.h>
 //Added by qt3to4:
-#include <Q3CString>
 #include <QEvent>
 #include <Q3MemArray>
 #include <QMouseEvent>
@@ -87,8 +86,10 @@
 	bool eventFilter (QObject *object, QEvent *event);
 /** reimplemented to delete cell contents on DEL and BACKSPACE. Placed in public, here, so CellEditor can have access */
 	void keyPressEvent (QKeyEvent *e);
-	Q3CString encodeSelection ();
-	Q3CString encodeRange (int top_row, int left_col, int bottom_row, int right_col);
+/** get contents of current selection as text (tab-separated-values) */
+	QString getSelectionText ();
+/** get contents of the specified range as text (tab-separated-values) */
+	QString getRangeText (int top_row, int left_col, int bottom_row, int right_col);
 /** blanks out the currently selected cells (or the currently active cell, if there is no selection) */
 	void blankSelected ();
 /** shortcut to get the boundaries of the current selection */


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