[rkward-cvs] rkward/rkward/dataeditor editlabelsdialog.cpp,1.4,1.5 editlabelsdialog.h,1.2,1.3 rkdrag.cpp,1.2,1.3 rkdrag.h,1.1,1.2 rkeditor.h,1.6,1.7 rkeditordataframe.cpp,1.32,1.33 rkeditordataframe.h,1.8,1.9 rkeditordataframepart.cpp,1.6,1.7 twintable.cpp,1.29,1.30 twintable.h,1.11,1.12 twintablemember.cpp,1.17,1.18 twintablemember.h,1.15,1.16

Thomas Friedrichsmeier tfry at users.sourceforge.net
Fri Apr 7 13:02:46 UTC 2006


Update of /cvsroot/rkward/rkward/rkward/dataeditor
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29081

Modified Files:
	editlabelsdialog.cpp editlabelsdialog.h rkdrag.cpp rkdrag.h 
	rkeditor.h rkeditordataframe.cpp rkeditordataframe.h 
	rkeditordataframepart.cpp twintable.cpp twintable.h 
	twintablemember.cpp twintablemember.h 
Log Message:
Use only only column in Levels editor. Make pasting work in Levels editor. Refactoring of old paste code in TwinTable

Index: twintablemember.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/dataeditor/twintablemember.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** twintablemember.cpp	6 Apr 2006 19:40:46 -0000	1.17
--- twintablemember.cpp	7 Apr 2006 13:02:44 -0000	1.18
***************
*** 3,7 ****
                               -------------------
      begin                : Tue Oct 29 2002
!     copyright            : (C) 2002 by Thomas Friedrichsmeier
      email                : tfry at users.sourceforge.net
   ***************************************************************************/
--- 3,7 ----
                               -------------------
      begin                : Tue Oct 29 2002
!     copyright            : (C) 2002, 2006 by Thomas Friedrichsmeier
      email                : tfry at users.sourceforge.net
   ***************************************************************************/
***************
*** 33,36 ****
--- 33,37 ----
  	horizontalHeader()->installEventFilter (this);
  	verticalHeader()->installEventFilter (this);
+ 	setSelectionMode (QTable::Single);
  	
  	TwinTableMember::trailing_cols = trailing_cols;
***************
*** 166,168 ****
--- 167,228 ----
  }
  
+ QCString TwinTableMember::encodeSelection () {
+ 	RK_TRACE (EDITOR);
+ 
+ 	int top_row, left_col, bottom_row, right_col;
+ 	getSelectionBoundaries (&top_row, &left_col, &bottom_row, &right_col);
+ 
+ 	QString data;
+ 	for (int row=top_row; row <= bottom_row; ++row) {
+ 		for (int col=left_col; col <= right_col; ++col) {
+ 			data.append (text (row, col));
+ 			if (col != right_col) {
+ 				data.append ("\t");
+ 			}
+ 		}
+ 		if (row != bottom_row) {
+ 			data.append ("\n");
+ 		}
+ 	}
+ 
+ 	return data.local8Bit ();
+ }
+ 
+ void TwinTableMember::blankSelected () {
+ 	RK_TRACE (EDITOR);
+ 
+ 	int top_row, left_col, bottom_row, right_col;
+ 	getSelectionBoundaries (&top_row, &left_col, &bottom_row, &right_col);
+ 
+ 	for (int row=top_row; row <= bottom_row; ++row) {
+ 		for (int col=left_col; col <= right_col; ++col) {
+ 			clearCell (row, col);
+ 		}
+ 	}
+ }
+ 
+ void TwinTableMember::getSelectionBoundaries (int *top_row, int *left_col, int *bottom_row, int *right_col) {
+ 	RK_TRACE (EDITOR);
+ 
+ 	RK_ASSERT (top_row);
+ 	RK_ASSERT (bottom_row);
+ 	RK_ASSERT (left_col);
+ 	RK_ASSERT (right_col);
+ 
+ 	int selnum = -1;
+ 	if (currentSelection () >= 0) selnum = currentSelection ();
+ 	else if (numSelections () >= 1) selnum = 0;		// this is the one and only selection, as we only allow one single selection. Unfortunately, QTable does not regard a selection as current, if it was added programatically, instead of user-selected.
+ 	if (selnum >= 0) {
+ 		QTableSelection sel = selection (selnum);
+ 		*top_row = sel.topRow ();
+ 		*left_col = sel.leftCol ();
+ 		*bottom_row = sel.bottomRow ();
+ 		*right_col = sel.rightCol ();
+ 	} else {
+ 		// Nothing selected. Set current cell coordinates
+ 		*top_row = *bottom_row = currentRow ();
+ 		*left_col = *right_col = currentColumn ();
+ 	}
+ }
+ 
  #include "twintablemember.moc"

Index: editlabelsdialog.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/dataeditor/editlabelsdialog.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** editlabelsdialog.cpp	6 Apr 2006 19:50:39 -0000	1.4
--- editlabelsdialog.cpp	7 Apr 2006 13:02:44 -0000	1.5
***************
*** 3,7 ****
                               -------------------
      begin                : Tue Sep 21 2004
!     copyright            : (C) 2004 by Thomas Friedrichsmeier
      email                : tfry at users.sourceforge.net
   ***************************************************************************/
--- 3,7 ----
                               -------------------
      begin                : Tue Sep 21 2004
!     copyright            : (C) 2004, 2006 by Thomas Friedrichsmeier
      email                : tfry at users.sourceforge.net
   ***************************************************************************/
***************
*** 19,23 ****
--- 19,26 ----
  #include <klocale.h>
  #include <kdialogbase.h>
+ #include <kaction.h>
  
+ #include <qapplication.h>
+ #include <qclipboard.h>
  #include <qlabel.h>
  #include <qlayout.h>
***************
*** 29,32 ****
--- 32,36 ----
  
  #include "../core/rkvariable.h"
+ #include "rkdrag.h"
  #include "celleditor.h"
  
***************
*** 39,49 ****
  	storage = labels;
  
! 	setNumCols (2);
  	setNumRows (storage->count () + 1);
! 	horizontalHeader ()->setLabel (0, i18n ("Index"));
! 	horizontalHeader ()->setLabel (1, i18n ("Label"));
! 	verticalHeader ()->hide ();
! 	setLeftMargin (0);
! 	setColumnReadOnly (0, true);
  }
  
--- 43,59 ----
  	storage = labels;
  
! 	updating_size = false;
! 
! 	setNumCols (1);
  	setNumRows (storage->count () + 1);
! 	horizontalHeader ()->setLabel (0, i18n ("Label"));
! 	setHScrollBarMode (QScrollView::AlwaysOff);
! 	setLeftMargin (40);
! 	setMinimumWidth (80);
! 
! 	KActionCollection *ac = new KActionCollection (this);
! 	KStdAction::cut (this, SLOT (cut ()), ac);
! 	KStdAction::copy (this, SLOT (copy ()), ac);
! 	KStdAction::paste (this, SLOT (paste ()), ac);
  }
  
***************
*** 52,58 ****
  }
  
  void LevelsTable::setText (int row, int col, const QString &text) {
  	RK_TRACE (EDITOR);
! 	RK_ASSERT (col == 1);
  
  	storage->insert (QString::number (row+1), text);
--- 62,129 ----
  }
  
+ void LevelsTable::cut () {
+ 	RK_TRACE (EDITOR);
+ 
+ 	copy ();
+ 	blankSelected ();
+ }
+ 
+ void LevelsTable::copy () {
+ 	RK_TRACE (EDITOR);
+ 
+ 	QApplication::clipboard()->setData (new RKDrag (this));
+ }
+ 
+ void LevelsTable::paste () {
+ 	RK_TRACE (EDITOR);
+ 
+ // Unfortunately, we need to duplicate some of TwinTable::paste () and RKEditorDataFramPart::doPaste. Those are not easy to reconcile.
+ 
+ 	// 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.
+ 	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"));
+ 	}
+ 
+ 	int content_offset = 0;
+ 	int content_length = pasted.length ();
+ 	bool look_for_tabs;			// break on tabs or on lines?
+ 	int next_delim;
+ 
+ 	int first_tab = pasted.find ('\t', 0);
+ 	if (first_tab < 0) first_tab = content_length;
+ 	int first_line = pasted.find ('\n', 0);
+ 	if (first_line < 0) first_line = content_length;
+ 	if (first_tab < first_line) {
+ 		look_for_tabs = true;
+ 		next_delim = first_tab;
+ 	} else {
+ 		look_for_tabs = false;
+ 		next_delim = first_line;
+ 	}
+ 
+ 	int row = currentRow ();
+ 	do {
+ 		if (row >= numTrueRows ()) insertRows (row);
+ 		setText (row, 0, pasted.mid (content_offset, next_delim - content_offset));
+ 
+ 		++row;
+ 		content_offset = next_delim + 1;
+ 		if (look_for_tabs) {
+ 			next_delim = pasted.find ('\t', content_offset);
+ 		} else {
+ 			next_delim = pasted.find ('\n', content_offset);
+ 		}
+ 		if (next_delim < 0) next_delim = content_length;
+ 	} while (content_offset < content_length);
+ }
+ 
  void LevelsTable::setText (int row, int col, const QString &text) {
  	RK_TRACE (EDITOR);
! 	RK_ASSERT (col == 0);
  
  	storage->insert (QString::number (row+1), text);
***************
*** 65,73 ****
  		setNumRows (maxrow + 2);
  	}
  }
  
  QString LevelsTable::text (int row, int col) const {
  	RK_TRACE (EDITOR);
! 	RK_ASSERT (col == 1);
  	RK_ASSERT (row < numTrueRows ());
  
--- 136,146 ----
  		setNumRows (maxrow + 2);
  	}
+ 
+ 	updateCell (row, col);
  }
  
  QString LevelsTable::text (int row, int col) const {
  	RK_TRACE (EDITOR);
! 	RK_ASSERT (col == 0);
  	RK_ASSERT (row < numTrueRows ());
  
***************
*** 119,131 ****
  	}
  
! 	QString dummy;
! 	if (row < numTrueRows ()) {
! 		if (!col) {
! 			dummy.setNum (row +1);
! 		} else {
! 			dummy = (*storage)[QString::number (row+1)];
! 		}
! 	}
! 	p->drawText (2, 0, cr.width () - 4, cr.height (), Qt::AlignLeft, dummy);
  }
  
--- 192,196 ----
  	}
  
! 	p->drawText (2, 0, cr.width () - 4, cr.height (), Qt::AlignLeft, (*storage)[QString::number (row+1)]);
  }
  
***************
*** 135,139 ****
  	RK_ASSERT (!tted);
  
! 	if (col < 1) return 0;
  
  	if (row >= numTrueRows ()) {
--- 200,204 ----
  	RK_ASSERT (!tted);
  
! 	if (col != 0) return 0;
  
  	if (row >= numTrueRows ()) {
***************
*** 156,159 ****
--- 221,257 ----
  }
  
+ void LevelsTable::resizeEvent (QResizeEvent *e) {
+ 	RK_TRACE (EDITOR);
+ 
+ 	updating_size = true;
+ 	int nwidth = e->size ().width () - leftMargin ();
+ 	if (nwidth < 40) {
+ 		setLeftMargin (e->size ().width () - 40);
+ 		nwidth = 40;
+ 	}
+ 	setColumnWidth (0, nwidth);
+ 	updating_size = false;
+ 
+ 	QTable::resizeEvent (e);
+ }
+ 
+ void LevelsTable::columnWidthChanged (int col) {
+ 	RK_TRACE (EDITOR);
+ 
+ 	if (updating_size) return;
+ 
+ 	updating_size = true;
+ 
+ 	if (columnWidth (0) < 40) {
+ 		setColumnWidth (0, 40);
+ 	}
+ 	setLeftMargin (width () - columnWidth (0));
+ 
+ 	updating_size = false;
+ 
+ 	QTable::columnWidthChanged (col);
+ }
+ 
+ 
  
  EditLabelsDialog::EditLabelsDialog (QWidget *parent, RKVariable *var, int mode) : QDialog (parent) {

Index: rkdrag.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/dataeditor/rkdrag.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** rkdrag.cpp	29 Sep 2005 13:24:48 -0000	1.2
--- rkdrag.cpp	7 Apr 2006 13:02:44 -0000	1.3
***************
*** 3,7 ****
                               -------------------
      begin                : Thu Oct 31 2002
!     copyright            : (C) 2002 by Thomas Friedrichsmeier
      email                : tfry at users.sourceforge.net
   ***************************************************************************/
--- 3,7 ----
                               -------------------
      begin                : Thu Oct 31 2002
!     copyright            : (C) 2002, 2006 by Thomas Friedrichsmeier
      email                : tfry at users.sourceforge.net
   ***************************************************************************/
***************
*** 18,32 ****
  #include "rkdrag.h"
  
! #include "twintable.h"
  
  #include "../debug.h"
  
! RKDrag::RKDrag(TwinTable *dragSource, const char *name) : QDragObject (dragSource, name){
  	RK_TRACE (EDITOR);
  
! 	data = dragSource->encodeSelection ();
  }
  
! RKDrag::~RKDrag(){
  	RK_TRACE (EDITOR);
  }
--- 18,35 ----
  #include "rkdrag.h"
  
! #include "twintablemember.h"
  
  #include "../debug.h"
  
! RKDrag::RKDrag (TwinTableMember *drag_source) : QDragObject (drag_source){
  	RK_TRACE (EDITOR);
  
! 	RK_ASSERT (drag_source);
! 	if (drag_source) {
! 		data = drag_source->encodeSelection ();
! 	}
  }
  
! RKDrag::~RKDrag () {
  	RK_TRACE (EDITOR);
  }
***************
*** 46,57 ****
  	RK_TRACE (EDITOR);
  	QString request = mimeType;
! 	if (request == format (0)) {
! 		return data;
! 	}
! 	if (request == format (1)) {
  		return data;
  	}
! 	return data;
! 	return empty;
  }
  
--- 49,57 ----
  	RK_TRACE (EDITOR);
  	QString request = mimeType;
! 	if ((request == format (0)) || (request == format (1))) {
  		return data;
  	}
! 
! 	return QCString ();
  }
  

Index: editlabelsdialog.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/dataeditor/editlabelsdialog.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** editlabelsdialog.h	6 Apr 2006 19:40:46 -0000	1.2
--- editlabelsdialog.h	7 Apr 2006 13:02:44 -0000	1.3
***************
*** 3,7 ****
                               -------------------
      begin                : Tue Sep 21 2004
!     copyright            : (C) 2004 by Thomas Friedrichsmeier
      email                : tfry at users.sourceforge.net
   ***************************************************************************/
--- 3,7 ----
                               -------------------
      begin                : Tue Sep 21 2004
!     copyright            : (C) 2004, 2006 by Thomas Friedrichsmeier
      email                : tfry at users.sourceforge.net
   ***************************************************************************/
***************
*** 27,34 ****
--- 27,36 ----
  
  /** special mini class provides the table in EditLabelsDialog
+ TODO: make copy/paste work
  
  @author Thomas Friedrichsmeier
  */
  class LevelsTable : public TwinTableMember {
+ 	Q_OBJECT
  public:
  	LevelsTable (QWidget *parent, RObject::ValueLabels *labels);
***************
*** 42,48 ****
--- 44,63 ----
  /** reimplemented form QTable not to work on RObject::ValueLabels instead of QTableItems */
  	QString text (int row, int col) const;
+ public slots:
+ /** cut */
+ 	void cut();
+ /** copy */
+ 	void copy();
+ /** paste */
+ 	void paste();
+ protected:
+ /** reimplemented to resize the table columns so that there's no unused space to the right */
+ 	void resizeEvent (QResizeEvent *e);
+ /** reimplemented to resize the table columns so that there's no unused space to the right */
+ 	void columnWidthChanged (int col);
  private:
  friend class EditLabelsDialog;
  	RObject::ValueLabels *storage;
+ 	bool updating_size;
  };
  

Index: rkeditor.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/dataeditor/rkeditor.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** rkeditor.h	17 Sep 2005 18:04:00 -0000	1.6
--- rkeditor.h	7 Apr 2006 13:02:44 -0000	1.7
***************
*** 48,52 ****
  	virtual void clearSelected () = 0;
  	virtual RKDrag *makeDrag () = 0;
! 	virtual void paste (QByteArray content) = 0;
  	enum PasteMode {PasteEverywhere, PasteToTable, PasteToSelection};
  	virtual void setPasteMode (PasteMode mode) = 0;
--- 48,52 ----
  	virtual void clearSelected () = 0;
  	virtual RKDrag *makeDrag () = 0;
! 	virtual void paste (QByteArray &content) = 0;
  	enum PasteMode {PasteEverywhere, PasteToTable, PasteToSelection};
  	virtual void setPasteMode (PasteMode mode) = 0;

Index: rkdrag.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/dataeditor/rkdrag.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** rkdrag.h	18 Aug 2004 12:14:24 -0000	1.1
--- rkdrag.h	7 Apr 2006 13:02:44 -0000	1.2
***************
*** 3,7 ****
                               -------------------
      begin                : Thu Oct 31 2002
!     copyright            : (C) 2002 by Thomas Friedrichsmeier
      email                : tfry at users.sourceforge.net
   ***************************************************************************/
--- 3,7 ----
                               -------------------
      begin                : Thu Oct 31 2002
!     copyright            : (C) 2002, 2006 by Thomas Friedrichsmeier
      email                : tfry at users.sourceforge.net
   ***************************************************************************/
***************
*** 21,34 ****
  #include <qdragobject.h>
  
! class TwinTable;
  
! /**
    *@author Thomas Friedrichsmeier
    */
- 
  class RKDrag : public QDragObject  {
  public: 
! 	RKDrag(TwinTable *dragSource=0, const char *name=0);
! 	~RKDrag();
  	const char* format (int i=0) const;
  	QByteArray encodedData (const char * mimeType) const;
--- 21,33 ----
  #include <qdragobject.h>
  
! class TwinTableMember;
  
! /** A QDragObject that gets its data from a TwinTableMember. Used for all copy/paste/drag operations involving TwinTableMembers.
    *@author Thomas Friedrichsmeier
    */
  class RKDrag : public QDragObject  {
  public: 
! 	RKDrag (TwinTableMember *drag_source=0);
! 	~RKDrag ();
  	const char* format (int i=0) const;
  	QByteArray encodedData (const char * mimeType) const;
***************
*** 36,41 ****
  private:
  	QCString data;
- 	QCString empty;
- protected:
  };
  
--- 35,38 ----

Index: twintablemember.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/dataeditor/twintablemember.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** twintablemember.h	6 Apr 2006 19:40:46 -0000	1.15
--- twintablemember.h	7 Apr 2006 13:02:44 -0000	1.16
***************
*** 3,7 ****
                               -------------------
      begin                : Tue Oct 29 2002
!     copyright            : (C) 2002 by Thomas Friedrichsmeier
      email                : tfry at users.sourceforge.net
   ***************************************************************************/
--- 3,7 ----
                               -------------------
      begin                : Tue Oct 29 2002
!     copyright            : (C) 2002, 2006 by Thomas Friedrichsmeier
      email                : tfry at users.sourceforge.net
   ***************************************************************************/
***************
*** 82,85 ****
--- 82,90 ----
  /** actually simply calls QTable::keyPressEvent (). Reimplemented only to allow CellEditor access to this function */
  	void keyPressEvent (QKeyEvent *e) { QTable::keyPressEvent (e); };
+ 	QCString encodeSelection ();
+ /** 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 */
+ 	void getSelectionBoundaries (int *top_row, int *left_col, int *bottom_row, int *right_col);
  signals:
  	void headerRightClick (int row, int col);

Index: rkeditordataframe.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/dataeditor/rkeditordataframe.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** rkeditordataframe.h	20 Oct 2005 18:42:37 -0000	1.8
--- rkeditordataframe.h	7 Apr 2006 13:02:44 -0000	1.9
***************
*** 3,7 ****
                               -------------------
      begin                : Fri Aug 20 2004
!     copyright            : (C) 2004 by Thomas Friedrichsmeier
      email                : tfry at users.sourceforge.net
   ***************************************************************************/
--- 3,7 ----
                               -------------------
      begin                : Fri Aug 20 2004
!     copyright            : (C) 2004, 2006 by Thomas Friedrichsmeier
      email                : tfry at users.sourceforge.net
   ***************************************************************************/
***************
*** 45,50 ****
  	//void objectMetaModified (RObject *object);
  
- 	void paste (QByteArray content);
- 
  /** Tells the editor to (unconditionally!) remove the object from its list. */
  	void removeObject (RObject *object);
--- 45,48 ----

Index: rkeditordataframe.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/dataeditor/rkeditordataframe.cpp,v
retrieving revision 1.32
retrieving revision 1.33
diff -C2 -d -r1.32 -r1.33
*** rkeditordataframe.cpp	21 Oct 2005 15:23:36 -0000	1.32
--- rkeditordataframe.cpp	7 Apr 2006 13:02:44 -0000	1.33
***************
*** 3,7 ****
                               -------------------
      begin                : Fri Aug 20 2004
!     copyright            : (C) 2004 by Thomas Friedrichsmeier
      email                : tfry at users.sourceforge.net
   ***************************************************************************/
--- 3,7 ----
                               -------------------
      begin                : Fri Aug 20 2004
!     copyright            : (C) 2004, 2006 by Thomas Friedrichsmeier
      email                : tfry at users.sourceforge.net
   ***************************************************************************/
***************
*** 181,190 ****
  }
  
- void RKEditorDataFrame::paste (QByteArray content) {
- 	RK_TRACE (EDITOR);
- 
- 	pasteEncoded (content);
- }
- 
  void RKEditorDataFrame::columnDeletionRequested (int col) {
  	RK_TRACE (EDITOR);
--- 181,184 ----

Index: rkeditordataframepart.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/dataeditor/rkeditordataframepart.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** rkeditordataframepart.cpp	13 Nov 2005 19:07:40 -0000	1.6
--- rkeditordataframepart.cpp	7 Apr 2006 13:02:44 -0000	1.7
***************
*** 3,7 ****
                               -------------------
      begin                : Wed Sep 14 2005
!     copyright            : (C) 2005 by Thomas Friedrichsmeier
      email                : tfry at users.sourceforge.net
   ***************************************************************************/
--- 3,7 ----
                               -------------------
      begin                : Wed Sep 14 2005
!     copyright            : (C) 2005, 2006 by Thomas Friedrichsmeier
      email                : tfry at users.sourceforge.net
   ***************************************************************************/
***************
*** 92,96 ****
  	
  	editor->setPasteMode (RKEditor::PasteToTable);
! 	doPaste();
  }
  
--- 92,96 ----
  	
  	editor->setPasteMode (RKEditor::PasteToTable);
! 	doPaste ();
  }
  
***************
*** 99,103 ****
  	
  	editor->setPasteMode (RKEditor::PasteToSelection);
! 	doPaste();
  }
  
--- 99,103 ----
  	
  	editor->setPasteMode (RKEditor::PasteToSelection);
! 	doPaste ();
  }
  
***************
*** 112,119 ****
  	if (QApplication::clipboard()->data()->provides ("text/tab-separated-values")) {
  		RK_DO (qDebug ("paste tsv"), EDITOR, DL_DEBUG);
! 		editor->paste (QApplication::clipboard()->data()->encodedData ("text/tab-separated-values"));
  	} else if (QApplication::clipboard()->data()->provides ("text/plain")) {
  		RK_DO (qDebug ("paste plaing"), EDITOR, DL_DEBUG);
! 		editor->paste (QApplication::clipboard()->data()->encodedData ("text/plain"));
  	}
  
--- 112,121 ----
  	if (QApplication::clipboard()->data()->provides ("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);
  	} else if (QApplication::clipboard()->data()->provides ("text/plain")) {
  		RK_DO (qDebug ("paste plaing"), EDITOR, DL_DEBUG);
! 		QByteArray data = QApplication::clipboard()->data()->encodedData ("text/plain");
! 		editor->paste (data);
  	}
  

Index: twintable.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/dataeditor/twintable.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** twintable.h	24 Sep 2004 16:10:58 -0000	1.11
--- twintable.h	7 Apr 2006 13:02:44 -0000	1.12
***************
*** 3,7 ****
                               -------------------
      begin                : Tue Oct 29 2002
!     copyright            : (C) 2002 by Thomas Friedrichsmeier
      email                : tfry at users.sourceforge.net
   ***************************************************************************/
--- 3,7 ----
                               -------------------
      begin                : Tue Oct 29 2002
!     copyright            : (C) 2002, 2006 by Thomas Friedrichsmeier
      email                : tfry at users.sourceforge.net
   ***************************************************************************/
***************
*** 55,61 ****
  /** 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);
! 	QCString encodeSelection ();
! /** Pastes content to the current selection. */
! 	void pasteEncoded (QByteArray content);
  /** Same as above, but flips the data (i.e. row <-> cols) */
  //	void pasteEncodedFlipped (QByteArray content);
--- 55,60 ----
  /** 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);
  /** Same as above, but flips the data (i.e. row <-> cols) */
  //	void pasteEncodedFlipped (QByteArray content);

Index: twintable.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/dataeditor/twintable.cpp,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** twintable.cpp	2 Oct 2005 17:19:02 -0000	1.29
--- twintable.cpp	7 Apr 2006 13:02:44 -0000	1.30
***************
*** 3,7 ****
                               -------------------
      begin                : Tue Oct 29 2002
!     copyright            : (C) 2002 by Thomas Friedrichsmeier
      email                : tfry at users.sourceforge.net
   ***************************************************************************/
--- 3,7 ----
                               -------------------
      begin                : Tue Oct 29 2002
!     copyright            : (C) 2002, 2006 by Thomas Friedrichsmeier
      email                : tfry at users.sourceforge.net
   ***************************************************************************/
***************
*** 205,213 ****
  	RK_TRACE (EDITOR);
  
! 	QTableSelection selection;
! 	selection.init (0, col);
! 	selection.expandTo (dataview->numTrueRows (), col);
! 
! 	dataview->addSelection (selection);
  }
  
--- 205,209 ----
  	RK_TRACE (EDITOR);
  
! 	dataview->selectCells (0, col, dataview->numTrueRows (), col);
  }
  
***************
*** 267,271 ****
  RKDrag *TwinTable::makeDrag () {
  	RK_TRACE (EDITOR);
! 	return (new RKDrag (this));
  }
  
--- 263,267 ----
  RKDrag *TwinTable::makeDrag () {
  	RK_TRACE (EDITOR);
! 	return (new RKDrag (activeTable ()));
  }
  
***************
*** 300,339 ****
  }
  
! QCString TwinTable::encodeSelection () {
! 	RK_TRACE (EDITOR);
! 
! 	QCString encoded_data;
! 	QTable *table = activeTable ();
! 	if (!table) {
! 		// no selection -> return empty
! 		return encoded_data;
! 	}
! 
! 	QTableSelection selection;
! 	if (table->currentSelection () >= 0) {
! 		selection = table->selection (table->currentSelection ());
! 	} else {
! 		// Nothing selected. Copy current cell
! 		selection.init (table->currentRow (), table->currentColumn ());
! 		selection.expandTo (table->currentRow (), table->currentColumn ());
! 	}
! 
! 	QString data;
! 	for (int row=selection.topRow (); row <= selection.bottomRow (); row++) {
! 		for (int col=selection.leftCol (); col <= selection.rightCol (); col++) {
! 			data.append (table->text (row, col));
! 			if (col != selection.rightCol ()) {
! 				data.append ("\t");
! 			}
! 		}
! 		if (row != selection.bottomRow ()) {
! 			data.append ("\n");
! 		}
! 	}
! 	encoded_data = data.local8Bit ();
! 	return encoded_data;
! }
! 
! void TwinTable::pasteEncoded (QByteArray content) {
  	RK_TRACE (EDITOR);
  
--- 296,300 ----
  }
  
! void TwinTable::paste (QByteArray &content) {
  	RK_TRACE (EDITOR);
  
***************
*** 343,437 ****
  	if (!table) return;
  
! 	QValueList<RKVariable*> col_list;
! 	QTableSelection selection;
! 	if (table->numSelections () <= 0) {
! 		if ((table->currentRow () < 0) || (table->currentColumn () < 0)) return;
! 		selection.init (table->currentRow (), table->currentColumn ());
! 		selection.expandTo (table->currentRow (), table->currentColumn ());
! 		table->addSelection (selection);
  	}
! 	// Unfortunately, selections added via addSelection () don't get "current".
! 	// So for this case, we have to set it explicitely --- what did I mean to say with that comment?
! 	if (table->currentSelection () >= 0) {
! 		selection = table->selection (table->currentSelection ());
! 	} else {
! 		selection = table->selection (0);
  	}
  
  	QString pasted = content;
  
! 	int row=selection.topRow ();
! 	int col=selection.leftCol ();
! 	while (pasted.length ()) {
! 		int next_tab = pasted.find ("\t");	
! 		if (next_tab < 0) next_tab = pasted.length ();
! 		int next_delim = next_tab;
! 		int next_line = pasted.find ("\n");
! 		if (next_line < 0) next_line = pasted.length ();
! 		if (next_line < next_tab) {
! 			next_delim = next_line;
! 		}
! 		if (!col_list.contains (getColObject (col))) {
  			col_list.append (getColObject (col));
  			getColObject (col)->setSyncing (false);
  		}
! 		table->setText (row, col, pasted.left (next_delim));
! 		if (next_delim == next_tab) {
! 			col++;
! 			if (paste_mode == RKEditor::PasteToSelection) {
! 				if (col > selection.rightCol ()) {
! 					next_delim = next_line;
! 					row++;
! 					col = selection.leftCol ();
! 					if (row > selection.bottomRow ()) {
! 						next_delim = pasted.length ();
! 					}
! 				}
! 			}
! 			if (col >= table->numTrueCols ()) {
! 				if (paste_mode == RKEditor::PasteToTable) {
! 					next_delim = next_line;					
! 					row++;
! 					col = selection.leftCol ();
! 					if (row >= table->numTrueRows ()) {
! 						next_delim = pasted.length ();
! 					}
! 				} else {
! 					// the if below only fails, if this is the last line.
! 					// We don't want a new column, then.
! 					// Everything else does not get affected in this situation.
! 					if (next_delim != next_line) {
! 						insertNewColumn ();
! 					}
! 				}
! 			}
! 		} else {
! 			row++;
! 			col=selection.leftCol ();
! 			if (paste_mode == RKEditor::PasteToSelection) {
! 				if (row > selection.bottomRow ()) {
! 					next_delim = pasted.length ();
! 				}
! 			}
! 			if (row >= table->numTrueRows ()) {
! 				if (paste_mode == RKEditor::PasteToTable) {
! 					next_delim = pasted.length ();
! 				} else {
! 					if (next_delim != (pasted.length () -1)) {
! 						insertNewRow (-1, table);
! 					}
! 				}
! 			}
  		}
  
! 		// proceed to the next segment
! 		if (pasted.length () <= (next_delim + 1)) {
! 			// unfortunately QString.right (<=0) does not return an empty string!
! 			pasted = QString::null;
! 		} else {
! 			pasted=pasted.right (pasted.length () - (next_delim + 1));
  		}
! 	}
! 	
  	for (QValueList<RKVariable*>::ConstIterator it = col_list.constBegin (); it != col_list.constEnd (); ++it) {
  		(*it)->syncDataToR ();
--- 304,368 ----
  	if (!table) return;
  
! 	int top_row, left_col, bottom_row, right_col;
! 	table->getSelectionBoundaries (&top_row, &left_col, &bottom_row, &right_col);
! 	if (paste_mode == RKEditor::PasteToSelection) {
! 		// ok, we got our values
! 	} else if (paste_mode == RKEditor::PasteToTable) {
! 		bottom_row = table->numTrueRows () - 1;
! 		right_col = table->numTrueCols () - 1;
! 		if (right_col < left_col) return;			// may happen, if the current cell is in the trailing cols/rows
! 		if (bottom_row < top_row) return;
! 	} else if (paste_mode == RKEditor::PasteEverywhere) {
! 		bottom_row = INT_MAX;
! 		right_col = INT_MAX;
  	}
! 	if (table == varview) {			// do not allow new rows in the varview
! 		if (bottom_row >= varview->numTrueRows ()) bottom_row = varview->numTrueRows () - 1;
  	}
  
+ 	QValueList<RKVariable*> col_list;
+ 
  	QString pasted = content;
+ 	int row = top_row;
+ 	int col = left_col;
+ 	int content_offset = 0;
+ 	int content_length = pasted.length ();
+ 	do {
+ 		// first add new rows/cols if needed. Range check is done below, and on first iteration, we're always inside the valid range
+ 		if (row >= table->numTrueRows ()) insertNewRow (-1, table);
+ 		if (col >= table->numTrueCols ()) insertNewColumn ();
  
! 		if (!col_list.contains (getColObject (col))) {		// avoid syncing while doing the paste
  			col_list.append (getColObject (col));
  			getColObject (col)->setSyncing (false);
  		}
! 
! 		int next_tab = pasted.find ('\t', content_offset);
! 		if (next_tab < 0) next_tab = content_length;
! 		int next_delim = next_tab;
! 		int next_line = pasted.find ('\n', content_offset);
! 		if (next_line < 0) next_line = content_length;
! 		if (next_line < next_tab) next_delim = next_line;
! 
! 		table->setText (row, col, pasted.mid (content_offset, next_delim - content_offset));
! 
! 		if (next_delim == next_tab) {						// move to next row/column
! 			++col;
! 		} else if (next_delim == next_line) {
! 			col = left_col;
! 			++row;
  		}
  
! 		if (col > right_col) {										// check boundaries for next iteration
! 			next_delim = next_line;
! 			col = left_col;
! 			++row;
  		}
! 		if (row > bottom_row) break;
! 
! 		content_offset = next_delim + 1;
! 	} while (content_offset < content_length);
! 
! 	// now do the syncing
  	for (QValueList<RKVariable*>::ConstIterator it = col_list.constBegin (); it != col_list.constEnd (); ++it) {
  		(*it)->syncDataToR ();
***************
*** 455,469 ****
  	RK_TRACE (EDITOR);
  
! 	QTable *table = activeTable ();
   	if (!table) return;
  
! 	QTableSelection selection;
! 	selection = table->selection (table->currentSelection ());
! 
! 	for (int row=selection.topRow (); row <= selection.bottomRow (); row++) {
! 		for (int col=selection.leftCol (); col <= selection.rightCol (); col++) {
! 			table->clearCell (row, col);
! 		}
! 	}
  }
  
--- 386,393 ----
  	RK_TRACE (EDITOR);
  
! 	TwinTableMember *table = activeTable ();
   	if (!table) return;
  
! 	table->blankSelected ();
  }
  





More information about the rkward-tracker mailing list