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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Wed Jun 16 19:02:29 UTC 2010


Revision: 2884
          http://rkward.svn.sourceforge.net/rkward/?rev=2884&view=rev
Author:   tfry
Date:     2010-06-16 19:02:28 +0000 (Wed, 16 Jun 2010)

Log Message:
-----------
Port the data.frame-editor to KXMLGUI.
Add support for showing / hiding the rownames column.

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/rkward/dataeditor/CMakeLists.txt
    trunk/rkward/rkward/dataeditor/rkeditordataframe.cpp
    trunk/rkward/rkward/dataeditor/rkeditordataframepart.rc
    trunk/rkward/rkward/dataeditor/rkvareditmodel.cpp
    trunk/rkward/rkward/dataeditor/twintable.cpp
    trunk/rkward/rkward/dataeditor/twintable.h
    trunk/rkward/rkward/dataeditor/twintablemember.cpp
    trunk/rkward/rkward/dataeditor/twintablemember.h
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/ver.R
    trunk/rkward/rkward/resource.ver
    trunk/rkward/rkward/version.h

Removed Paths:
-------------
    trunk/rkward/rkward/dataeditor/rkeditordataframepart.cpp
    trunk/rkward/rkward/dataeditor/rkeditordataframepart.h

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2010-06-16 18:59:46 UTC (rev 2883)
+++ trunk/rkward/ChangeLog	2010-06-16 19:02:28 UTC (rev 2884)
@@ -1,5 +1,6 @@
 TODO: Do not use SmartInterface for KDE 4.5 and above
 
+- Support row names in the data.frame-editor
 - Fixed: When starting with an empty table, RKWard would sometimes claim that this object has been removed
 - Fixed: Would crash when trying to configure toolbars under certain circumstances (workaround for bug in kdelibs)
 - Fixed: Crash while analysing some objects returned by XML::xmlParseTree() for invalid XML

Modified: trunk/rkward/rkward/dataeditor/CMakeLists.txt
===================================================================
--- trunk/rkward/rkward/dataeditor/CMakeLists.txt	2010-06-16 18:59:46 UTC (rev 2883)
+++ trunk/rkward/rkward/dataeditor/CMakeLists.txt	2010-06-16 19:02:28 UTC (rev 2884)
@@ -11,7 +11,6 @@
    celleditor.cpp
    editlabelsdialog.cpp
    editformatdialog.cpp
-   rkeditordataframepart.cpp
    rkvareditmodel.cpp
    rktextmatrix.cpp
    )

Modified: trunk/rkward/rkward/dataeditor/rkeditordataframe.cpp
===================================================================
--- trunk/rkward/rkward/dataeditor/rkeditordataframe.cpp	2010-06-16 18:59:46 UTC (rev 2883)
+++ trunk/rkward/rkward/dataeditor/rkeditordataframe.cpp	2010-06-16 19:02:28 UTC (rev 2884)
@@ -2,7 +2,7 @@
                           rkeditordataframe  -  description
                              -------------------
     begin                : Fri Aug 20 2004
-    copyright            : (C) 2004, 2006 by Thomas Friedrichsmeier
+    copyright            : (C) 2004, 2006, 2010 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -28,7 +28,7 @@
 #include "../core/robjectlist.h"
 #include "../core/renvironmentobject.h"
 #include "../core/rcontainerobject.h"
-#include "rkeditordataframepart.h"
+#include "../misc/rkdummypart.h"
 #include "../windows/rkworkplace.h"
 
 #include "../debug.h"
@@ -75,7 +75,8 @@
 void RKEditorDataFrame::commonInit () {
 	RK_TRACE (EDITOR);
 
-	setPart (new RKEditorDataFramePart (this));
+	setPart (new RKDummyPart (this, this));
+	getPart ()->insertChildClient (this);
 	initializeActivationSignals ();
 
 	open_chain = RKGlobals::rInterface ()->startChain (0);

Deleted: trunk/rkward/rkward/dataeditor/rkeditordataframepart.cpp
===================================================================
--- trunk/rkward/rkward/dataeditor/rkeditordataframepart.cpp	2010-06-16 18:59:46 UTC (rev 2883)
+++ trunk/rkward/rkward/dataeditor/rkeditordataframepart.cpp	2010-06-16 19:02:28 UTC (rev 2884)
@@ -1,120 +0,0 @@
-/***************************************************************************
-                          rkeditordataframepart  -  description
-                             -------------------
-    begin                : Wed Sep 14 2005
-    copyright            : (C) 2005, 2006, 2007, 2009 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 "rkeditordataframepart.h"
-
-#include <qclipboard.h>
-
-#include <kaction.h>
-#include <kactioncollection.h>
-#include <klocale.h>
-
-#include "rkeditordataframe.h"
-#include "../misc/rkstandardicons.h"
-#include "../rkward.h"
-#include "../debug.h"
-
-RKEditorDataFramePart::RKEditorDataFramePart (RKEditorDataFrame* editor) : KParts::Part () {
-	RK_TRACE (EDITOR);
-
-	setComponentData (KGlobal::mainComponent ());
-	RKEditorDataFramePart::editor = editor;
-	setWidget (editor);
-
-	setXMLFile ("rkeditordataframepart.rc");
-
-	initializeActions ();
-}
-
-RKEditorDataFramePart::~RKEditorDataFramePart () {
-	RK_TRACE (EDITOR);
-}
-
-void RKEditorDataFramePart::initializeActions () {
-	RK_TRACE (EDITOR);
-
-	editCut = actionCollection ()->addAction (KStandardAction::Cut, "cut", this, SLOT(slotEditCut()));
-	editor->editActions ()->addAction (editCut);
-	editCopy = actionCollection ()->addAction (KStandardAction::Copy, "copy", this, SLOT(slotEditCopy()));
-//	editor->editActions ()->addAction (editCopy);	// this is a read-only action, not an "edit" action
-	editPaste = actionCollection ()->addAction (KStandardAction::Paste, "paste", this, SLOT(slotEditPaste()));
-	editor->editActions ()->addAction (editPaste);
-
-	editPasteToTable = actionCollection ()->addAction ("paste_to_table", this, SLOT(slotEditPasteToTable()));
-	editPasteToTable->setText (i18n("Paste inside table"));
-	editPasteToTable->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionPasteInsideTable));
-	editor->editActions ()->addAction (editPasteToTable);
-
-	editPasteToSelection = actionCollection ()->addAction ("paste_to_selection", this, SLOT(slotEditPasteToSelection()));
-	editPasteToSelection->setText (i18n("Paste inside selection"));
-	editPasteToSelection->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionPasteInsideSelection));
-	editor->editActions ()->addAction (editPasteToSelection);
-
-	editCut->setStatusTip (i18n("Cuts the selected section and puts it to the clipboard"));
-	editCopy->setStatusTip (i18n("Copies the selected section to the clipboard"));
-	editPaste->setStatusTip (i18n("Pastes the clipboard contents to actual position"));
-	editPasteToTable->setStatusTip (i18n("Pastes the clipboard contents to actual position, but not beyond the table's boundaries"));
-	editPasteToSelection->setStatusTip (i18n("Pastes the clipboard contents to actual position, but not beyond the boundaries of the current selection"));
-}
-
-void RKEditorDataFramePart::slotEditCut () {
-	RK_TRACE (EDITOR);
-	
-	RKWardMainWindow::getMain ()->slotSetStatusBarText (i18n ("Cutting selection..."));
-	slotEditCopy ();
-	editor->clearSelected ();
-	RKWardMainWindow::getMain ()->slotSetStatusReady ();
-}
-
-void RKEditorDataFramePart::slotEditCopy() {
-	RK_TRACE (EDITOR);
-	
-	RKWardMainWindow::getMain ()->slotSetStatusBarText (i18n ("Copying selection to clipboard..."));
-	editor->copy ();
-	RKWardMainWindow::getMain ()->slotSetStatusReady ();
-}
-
-
-void RKEditorDataFramePart::slotEditPaste() {
-	RK_TRACE (EDITOR);
-	
-	doPaste (RKEditor::PasteEverywhere);
-}
-
-void RKEditorDataFramePart::slotEditPasteToTable() {
-	RK_TRACE (EDITOR);
-	
-	doPaste (RKEditor::PasteToTable);
-}
-
-void RKEditorDataFramePart::slotEditPasteToSelection() {
-	RK_TRACE (EDITOR);
-	
-	doPaste (RKEditor::PasteToSelection);
-}
-
-void RKEditorDataFramePart::doPaste (RKEditor::PasteMode mode) {
-	RK_TRACE (EDITOR);
-
-	RKWardMainWindow::getMain ()->slotSetStatusBarText (i18n ("Inserting clipboard contents..."));
-
-	editor->paste (mode);
-
-	RKWardMainWindow::getMain ()->slotSetStatusReady ();
-}
-
-#include "rkeditordataframepart.moc"

Deleted: trunk/rkward/rkward/dataeditor/rkeditordataframepart.h
===================================================================
--- trunk/rkward/rkward/dataeditor/rkeditordataframepart.h	2010-06-16 18:59:46 UTC (rev 2883)
+++ trunk/rkward/rkward/dataeditor/rkeditordataframepart.h	2010-06-16 19:02:28 UTC (rev 2884)
@@ -1,69 +0,0 @@
-/***************************************************************************
-                          rkeditordataframepart  -  description
-                             -------------------
-    begin                : Wed Sep 14 2005
-    copyright            : (C) 2005, 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 RKEDITORDATAFRAMEPART_H
-#define RKEDITORDATAFRAMEPART_H
-
-#include <kparts/part.h>
-
-#include "rkeditor.h"
-
-class RKEditorDataFrame;
-class KAction;
-
-/** This class provides a KPart interface to RKEditorDataFrame. Basically, it is responsible for creating the menu-entries the RKEditorDataFrame provides, and keeps the corresponding Actions. The reason to use this, is so the required menus/menu-items can be merged in on the fly.
-
- at author Thomas Friedrichsmeier
-*/
-class RKEditorDataFramePart : public KParts::Part {
-	Q_OBJECT
-protected:
-friend class RKEditorDataFrame;
-/** ctor. Protected, as this should only be created by an RKEditorDataFrame */
-	RKEditorDataFramePart (RKEditorDataFrame* editor);
-/** dtor */
-	~RKEditorDataFramePart ();
-public slots:
-/** put the marked cells into the clipboard and remove them from the table */
-	void slotEditCut();
-/** put the marked cells into the clipboard */
-	void slotEditCopy();
-/** paste the clipboard into the table, expanding the table as necessary */
-	void slotEditPaste();
-/** paste the clipboard into the table, but not beyond table boundaries */
-	void slotEditPasteToTable();
-/** paste the clipboard into the table, but not beyond selection boundaries	*/
-	void slotEditPasteToSelection();
-/** return a pointer to the underlying editor widget */
-	RKEditorDataFrame *getEditor () const { return editor; };
-private:
-	QAction* editCut;
-	QAction* editCopy;
-	QAction* editPaste;
-	QAction* editPasteToSelection;
-	QAction* editPasteToTable;
-
-/** we could always use static_cast<RKEditorDataFrame*> (widget ()) instead of keeping this pointer. This saves some typing, though */
-	RKEditorDataFrame *editor;
-
-	void initializeActions ();
-
-/** Does pasting (called from the respective slots) */
-	void doPaste (RKEditor::PasteMode mode);
-};
-
-#endif

Modified: trunk/rkward/rkward/dataeditor/rkeditordataframepart.rc
===================================================================
--- trunk/rkward/rkward/dataeditor/rkeditordataframepart.rc	2010-06-16 18:59:46 UTC (rev 2883)
+++ trunk/rkward/rkward/dataeditor/rkeditordataframepart.rc	2010-06-16 19:02:28 UTC (rev 2884)
@@ -1,5 +1,5 @@
 <!DOCTYPE kpartgui>
-<kpartgui name="rkeditordataframepart" version="50">
+<kpartgui name="rkeditordataframepart" version="54">
 	<MenuBar>
 		<Menu name="edit"><text>&Edit</text>
 			<Action name="cut"/>
@@ -8,12 +8,35 @@
 			<Action name="paste_to_selection"/>
 			<Action name="paste_to_table"/>
 			<Separator/>
-			<Merge/> 
+			<Action name="show_rownames"/>
+			<Action name="enable_editing"/>
 		</Menu>
-<!--		<Menu name="windows"><text>&Windows</text>
-			<Action name="window_close"/>
-		</Menu>-->
 	</MenuBar>
+	<Menu name="top_header_menu">
+		<Action name="insert_col_left"/>
+		<Action name="delete_col"/>
+		<Separator/>
+		<Action name="show_rownames"/>
+		<Action name="enable_editing"/>
+	</Menu>
+	<Menu name="left_header_menu">
+		<Action name="insert_row_above"/>
+		<Action name="delete_row"/>
+		<Action name="delete_rows"/>
+		<Separator/>
+		<Action name="show_rownames"/>
+		<Action name="enable_editing"/>
+	</Menu>
+	<Menu name="general_context_menu">
+		<Action name="cut"/>
+		<Action name="copy"/>
+		<Action name="paste"/>
+		<Action name="paste_to_selection"/>
+		<Action name="paste_to_table"/>
+		<Separator/>
+		<Action name="show_rownames"/>
+		<Action name="enable_editing"/>
+	</Menu>
 	<ToolBar fullWidth="true" name="mdiToolBar">
 		<Action name="cut"/>
 		<Action name="copy"/>

Modified: trunk/rkward/rkward/dataeditor/rkvareditmodel.cpp
===================================================================
--- trunk/rkward/rkward/dataeditor/rkvareditmodel.cpp	2010-06-16 18:59:46 UTC (rev 2883)
+++ trunk/rkward/rkward/dataeditor/rkvareditmodel.cpp	2010-06-16 19:02:28 UTC (rev 2884)
@@ -396,6 +396,7 @@
 			var->setText (row, text.getText (trow, tcol));
 			++trow;
 		}
+		++tcol;
 	}
 }
 

Modified: trunk/rkward/rkward/dataeditor/twintable.cpp
===================================================================
--- trunk/rkward/rkward/dataeditor/twintable.cpp	2010-06-16 18:59:46 UTC (rev 2883)
+++ trunk/rkward/rkward/dataeditor/twintable.cpp	2010-06-16 19:02:28 UTC (rev 2884)
@@ -18,6 +18,9 @@
 #include "twintable.h"
 
 #include <klocale.h>
+#include <kaction.h>
+#include <kactioncollection.h>
+#include <kxmlguifactory.h>
 
 #include <qvariant.h>
 #include <qsplitter.h>
@@ -30,10 +33,11 @@
 #include "rkvareditmodel.h"
 #include "../core/rcontainerobject.h"
 #include "../misc/rkstandardicons.h"
+#include "../rkward.h"
 
 #include "../debug.h"
 
-TwinTable::TwinTable (QWidget *parent) : RKEditor (parent), RObjectListener (RObjectListener::Other) {
+TwinTable::TwinTable (QWidget *parent) : RKEditor (parent), RObjectListener (RObjectListener::Other), KXMLGUIClient () {
 	RK_TRACE (EDITOR);
 
 	main_object = 0;
@@ -71,38 +75,14 @@
 	meta_header_anchor_section = -1;
 
 	// catch header context menu requests
-	connect (dataview, SIGNAL (contextMenuRequest(int,int,const QPoint&)), this, SLOT (dataHeaderContextMenu(int,int,const QPoint&)));
-	connect (metaview, SIGNAL (contextMenuRequest(int,int,const QPoint&)), this, SLOT (metaHeaderContextMenu(int,int,const QPoint&)));
-	
-	// which will be reacted upon by the following popup-menus:
-	top_header_menu = new QMenu (this);
-	action_insert_col_left = top_header_menu->addAction (RKStandardIcons::getIcon (RKStandardIcons::ActionInsertVar), QString (), this, SLOT (insertColumn()));
-	action_delete_col = top_header_menu->addAction (RKStandardIcons::getIcon (RKStandardIcons::ActionDeleteVar), QString (), this, SLOT (deleteColumn()));
+	connect (dataview, SIGNAL (contextMenuRequest(int,int,const QPoint&)), this, SLOT (contextMenu(int,int,const QPoint&)));
+	connect (metaview, SIGNAL (contextMenuRequest(int,int,const QPoint&)), this, SLOT (contextMenu(int,int,const QPoint&)));
+	context_menu_table = 0;
+	context_menu_row = context_menu_column = -2;
 
-	left_header_menu = new QMenu (this);
-	action_insert_row_above = left_header_menu->addAction (RKStandardIcons::getIcon (RKStandardIcons::ActionInsertRow), QString (), this, SLOT (insertRow()));
-	action_delete_row = left_header_menu->addAction (RKStandardIcons::getIcon (RKStandardIcons::ActionDeleteRow), QString (), this, SLOT (deleteRow()));
-	action_delete_rows = left_header_menu->addAction (RKStandardIcons::getIcon (RKStandardIcons::ActionDeleteRow), QString (), this, SLOT (deleteSelectedRows()));
+	setXMLFile ("rkeditordataframepart.rc");
+	initActions ();
 
-	// add all actions to a group, so they can be enabled/disabled easily
-	edit_actions = new QActionGroup (this);
-	edit_actions->addAction (action_insert_col_left);
-	edit_actions->addAction (action_delete_col);
-	edit_actions->addAction (action_insert_row_above);
-	edit_actions->addAction (action_delete_row);
-	edit_actions->addAction (action_delete_rows);
-
-	action_enable_editing = new QAction (i18n ("Enable editing"), this);
-	action_enable_editing->setCheckable (true);
-	connect (action_enable_editing, SIGNAL (toggled(bool)), this, SLOT (enableEditing(bool)));
-
-// TODO this action should probably be part of a global context menu
-// ... and of course all actions should be moved from the rkeditordataframepart to this class
-	left_header_menu->addAction (action_enable_editing);
-	top_header_menu->addAction (action_enable_editing);
-
-	enableEditing (true);
-
 	setFocusPolicy (Qt::StrongFocus);
 }
 
@@ -114,6 +94,63 @@
 // TODO: are the models auto-destructed?
 }
 
+void TwinTable::initActions () {
+	RK_TRACE (EDITOR);
+
+	editCut = actionCollection ()->addAction (KStandardAction::Cut, "cut", this, SLOT(cut()));
+	editCut->setStatusTip (i18n("Cuts the selected section and puts it to the clipboard"));
+	editCopy = actionCollection ()->addAction (KStandardAction::Copy, "copy", this, SLOT(copy()));
+	editCopy->setStatusTip (i18n("Copies the selected section to the clipboard"));
+//	editor->editActions ()->addAction (editCopy);	// this is a read-only action, not an "edit" action
+	editPaste = actionCollection ()->addAction (KStandardAction::Paste, "paste", this, SLOT(paste()));
+	editPaste->setStatusTip (i18n("Pastes the clipboard contents to current position"));
+
+	editPasteToTable = actionCollection ()->addAction ("paste_to_table", this, SLOT(pasteToTable()));
+	editPasteToTable->setText (i18n("Paste inside table"));
+	editPasteToTable->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionPasteInsideTable));
+	editPasteToTable->setStatusTip (i18n("Pastes the clipboard contents to current position, but not beyond the table's boundaries"));
+
+	editPasteToSelection = actionCollection ()->addAction ("paste_to_selection", this, SLOT(pasteToSelection()));
+	editPasteToSelection->setText (i18n("Paste inside selection"));
+	editPasteToSelection->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionPasteInsideSelection));
+	editPasteToSelection->setStatusTip (i18n("Pastes the clipboard contents to current position, but not beyond the boundaries of the current selection"));
+
+	// header menus
+	action_insert_col_left = actionCollection ()->addAction ("insert_col_left", this, SLOT (insertColumn()));
+	action_insert_col_left->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionInsertVar));
+	action_delete_col = actionCollection ()->addAction ("delete_col", this, SLOT (deleteColumn()));
+	action_delete_col->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionDeleteVar));
+
+	action_insert_row_above = actionCollection ()->addAction ("insert_row_above", this, SLOT (insertRow()));
+	action_insert_row_above->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionInsertRow));
+	action_delete_row = actionCollection ()->addAction ("delete_row", this, SLOT (deleteRow()));
+	action_delete_row->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionDeleteRow));
+	action_delete_rows = actionCollection ()->addAction ("delete_rows", this, SLOT (deleteSelectedRows()));
+	action_delete_rows->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionDeleteRow));
+
+	// global actions
+	action_enable_editing = actionCollection ()->addAction ("enable_editing", this, SLOT (enableEditing(bool)));
+	action_enable_editing->setText ("Enable editing");
+	action_enable_editing->setCheckable (true);
+	action_show_rownames = actionCollection ()->addAction ("show_rownames", this, SLOT (showRownames(bool)));
+	action_show_rownames->setText ("Show / Edit row names");
+	action_show_rownames->setCheckable (true);
+
+	// add all edit-actions to a group, so they can be enabled/disabled easily
+	edit_actions = new QActionGroup (this);
+	edit_actions->addAction (editCut);
+	edit_actions->addAction (editPaste);
+	edit_actions->addAction (editPasteToTable);
+	edit_actions->addAction (editPasteToSelection);
+	edit_actions->addAction (action_insert_col_left);
+	edit_actions->addAction (action_delete_col);
+	edit_actions->addAction (action_insert_row_above);
+	edit_actions->addAction (action_delete_row);
+	edit_actions->addAction (action_delete_rows);
+
+	enableEditing (true);
+}
+
 void TwinTable::initTable (RKVarEditModel* model, RObject* object) {
 	RK_TRACE (EDITOR);
 
@@ -128,6 +165,7 @@
 	metaview->setMinimumHeight (metaview->horizontalHeader ()->height ());
 	metaview->setMaximumHeight (metaview->rowHeight (0) * 5 + metaview->horizontalHeader ()->height () + 5);
 	dataview->verticalHeader ()->setFixedWidth (metaview->verticalHeader ()->width ());
+	showRownames (false);
 
 // init caption
 	addNotificationType (RObjectListener::MetaChanged);
@@ -172,107 +210,126 @@
 }
 
 // TODO: handle situation when several entire cols are selected!
-void TwinTable::metaHeaderContextMenu (int row, int col, const QPoint& pos) {
+void TwinTable::contextMenu (int row, int col, const QPoint& pos) {
 	RK_TRACE (EDITOR);
 
-	if (col >= 0) {
-		RK_ASSERT (row == -1);
-		RK_ASSERT (col <= datamodel->trueCols ());
+	RK_ASSERT (context_menu_table == 0);
+	context_menu_row = row;
+	context_menu_column = col;
+	QString container_name;
 
-		action_insert_col_left->setEnabled (col >= datamodel->firstRealColumn ());
-		action_insert_col_left->setText (i18n ("Insert new variable left"));	// TODO: show name
-		action_insert_col_left->setData (col);
-		action_delete_col->setEnabled ((col >= datamodel->firstRealColumn ()) && (col < datamodel->trueCols ()));
-		action_delete_col->setText (i18n ("Delete this variable"));	// TODO: show name
-		action_delete_col->setData (col);
+	if (sender () == metaview) {
+		context_menu_table = metaview;
 
-		top_header_menu->popup (pos);
-	}
-}
+		if (row == -1) {	// header
+			action_insert_col_left->setEnabled (rw && (col >= datamodel->firstRealColumn ()));
+			action_insert_col_left->setText (i18n ("Insert new variable left"));	// TODO: show name
 
-void TwinTable::dataHeaderContextMenu (int row, int col, const QPoint& pos) {
-	RK_TRACE (EDITOR);
+			action_delete_col->setEnabled (rw && (col >= datamodel->firstRealColumn ()) && (col < datamodel->trueCols ()));
+			action_delete_col->setText (i18n ("Delete this variable"));	// TODO: show name
 
-	RK_ASSERT (col < 0);
-	if (row >= 0) {
-		RK_ASSERT (row <= datamodel->trueRows ());
+			container_name = "top_header_menu";
+		}
+	} else if (sender () == dataview) {
+		context_menu_table = dataview;
 
-		action_insert_row_above->setText (i18n ("Insert new case above (at %1)", row + 1));
-		action_insert_row_above->setData (row);
+		if (col == -1) {
+			if (row >= 0) {
+				RK_ASSERT (row <= datamodel->trueRows ());
 
-		QItemSelectionRange sel = dataview->getSelectionBoundaries ();
-		if (sel.isValid ()) {
-			int top = sel.top ();
-			int bottom = sel.bottom ();
-			if (bottom >= datamodel->trueRows ()) bottom = datamodel->trueRows () - 1;
+				action_insert_row_above->setText (i18n ("Insert new case above (at %1)", row + 1));
 
-			action_delete_rows->setEnabled (top > bottom);
-			if (top > bottom) bottom = top;
-			action_delete_rows->setText (i18n ("Delete marked rows (%1-%2)", (top+1), (bottom+1)));
-		} else {
-			action_delete_rows->setEnabled (false);
+				QItemSelectionRange sel = dataview->getSelectionBoundaries ();
+				if (sel.isValid () && rw) {
+					int top = sel.top ();
+					int bottom = sel.bottom ();
+					if (bottom >= datamodel->trueRows ()) bottom = datamodel->trueRows () - 1;
+
+					action_delete_rows->setEnabled (top > bottom);
+					if (top > bottom) bottom = top;
+					action_delete_rows->setText (i18n ("Delete marked rows (%1-%2)", (top+1), (bottom+1)));
+				} else {
+					action_delete_rows->setEnabled (false);
+				}
+
+				action_delete_row->setEnabled (rw && (row < datamodel->trueRows ()));
+				action_delete_row->setText (i18n ("Delete this row (%1)", (row+1)));
+
+				container_name = "left_header_menu";
+			}
 		}
+	} else {
+		RK_ASSERT (sender () == this);
+	}
 
-		action_delete_row->setEnabled (row < datamodel->trueRows ());
-		action_delete_row->setText (i18n ("Delete this row (%1)", (row+1)));
-		action_delete_row->setData (row);
+	if (container_name.isEmpty ()) {	// none of the headers
+		container_name = "general_context_menu";
+	}
 
-		left_header_menu->popup (pos);
+	RK_ASSERT (factory ());
+	QMenu* menu = dynamic_cast<QMenu*> (factory ()->container (container_name, this));
+
+	if (menu) {
+		menu->exec (pos);
+	} else {
+		RK_ASSERT (false);	// but may happen, if ui.rc-file was not found
 	}
+
+	context_menu_table = 0;
+	context_menu_row = context_menu_column = -2;
 }
 
 void TwinTable::deleteColumn () {
 	RK_TRACE (EDITOR);
 	RK_ASSERT (rw);
 
-	int col;
-	if (sender () == action_delete_col) col = action_delete_col->data ().toInt ();
-	else {
+	if (context_menu_table != metaview) {
 		RK_ASSERT (false);
 		return;
 	}
 
+	RK_ASSERT (context_menu_column >= datamodel->firstRealColumn ());
 	flushEdit ();
-
-	datamodel->removeColumns (col, 1);
+	datamodel->removeColumns (context_menu_column, 1);
 }
 
 void TwinTable::insertColumn () {
 	RK_TRACE (EDITOR);
 	RK_ASSERT (rw);
 
-	int where;
-	if (sender () == action_insert_col_left) where = action_insert_col_left->data ().toInt ();
-	else {
+	if (context_menu_table != metaview) {
 		RK_ASSERT (false);
 		return;
 	}
 
+	RK_ASSERT (context_menu_column >= datamodel->firstRealColumn ());
 	flushEdit ();
-
-	datamodel->insertColumns (where, 1);
+	datamodel->insertColumns (context_menu_column, 1);
 }
 
 void TwinTable::deleteRow () {
 	RK_TRACE (EDITOR);
 	RK_ASSERT (rw);
 
-	int where;
-	if (sender () == action_delete_row) where = action_delete_row->data ().toInt ();
-	else {
+	if (context_menu_table != dataview) {
 		RK_ASSERT (false);
 		return;
 	}
 
+	RK_ASSERT (context_menu_row > 0);
 	flushEdit ();
-
-	datamodel->removeRows (where, 1);
+	datamodel->removeRows (context_menu_row, 1);
 }
 
 void TwinTable::deleteSelectedRows () {
 	RK_TRACE (EDITOR);
 	RK_ASSERT (rw);
 
+	if (context_menu_table != dataview) {
+		RK_ASSERT (false);
+		return;
+	}
+
 	QItemSelectionRange sel = dataview->getSelectionBoundaries ();
 	if (sel.isValid ()) {
 		int top = sel.top ();
@@ -290,16 +347,14 @@
 	RK_TRACE (EDITOR);
 	RK_ASSERT (rw);
 
-	int where;
-	if (sender () == action_insert_row_above) where = action_insert_row_above->data ().toInt ();
-	else {
+	if (context_menu_table != dataview) {
 		RK_ASSERT (false);
 		return;
 	}
 
+	RK_ASSERT (context_menu_row > 0);
 	flushEdit ();
-
-	datamodel->insertRows (where, 1);
+	datamodel->insertRows (context_menu_row, 1);
 }
 
 void TwinTable::copy () {
@@ -317,13 +372,33 @@
 	if (!rw) return;
 
 	flushEdit ();
-	
+
 	TwinTableMember *table = activeTable ();
 	if (!table) return;
 
+	RKWardMainWindow::getMain ()->slotSetStatusBarText (i18n ("Inserting clipboard contents..."));
 	table->paste (paste_mode);
+	RKWardMainWindow::getMain ()->slotSetStatusReady ();
 }
 
+void TwinTable::paste() {
+	RK_TRACE (EDITOR);
+	
+	paste (PasteEverywhere);
+}
+
+void TwinTable::pasteToTable() {
+	RK_TRACE (EDITOR);
+	
+	paste (PasteToTable);
+}
+
+void TwinTable::pasteToSelection() {
+	RK_TRACE (EDITOR);
+	
+	paste (PasteToSelection);
+}
+
 TwinTableMember *TwinTable::activeTable () {
 	RK_TRACE (EDITOR);
 
@@ -347,6 +422,13 @@
 	table->blankSelected ();
 }
 
+void TwinTable::cut () {
+	RK_TRACE (EDITOR);
+
+	copy();
+	clearSelected ();
+}
+
 void TwinTable::flushEdit () {
 	RK_TRACE (EDITOR);
 
@@ -381,4 +463,13 @@
 	if (main_object) objectMetaChanged (main_object);	// update_caption;
 }
 
+void TwinTable::showRownames (bool show) {
+	RK_TRACE (EDITOR);
+	RK_ASSERT (show == action_show_rownames->isChecked ());
+
+	metaview->setColumnHidden (0, !show);
+	dataview->setColumnHidden (0, !show);
+	datamodel->lockHeader (!show);
+}
+
 #include "twintable.moc"

Modified: trunk/rkward/rkward/dataeditor/twintable.h
===================================================================
--- trunk/rkward/rkward/dataeditor/twintable.h	2010-06-16 18:59:46 UTC (rev 2883)
+++ trunk/rkward/rkward/dataeditor/twintable.h	2010-06-16 19:02:28 UTC (rev 2884)
@@ -23,31 +23,28 @@
 #include <qstring.h>
 #include <QItemSelection>
 
+#include <kxmlguiclient.h>
+
 #include "../core/rkmodificationtracker.h"
 
 class TwinTableMember;
-class QMenu;
 class RKVarEditModel;
 class QActionGroup;
+class KAction;
 
 /**
   *@author Thomas Friedrichsmeier
   */
 
-class TwinTable : public RKEditor, public RObjectListener {
+class TwinTable : public RKEditor, public RObjectListener, public KXMLGUIClient {
 	Q_OBJECT
 public: 
 	TwinTable (QWidget *parent=0);
 	~TwinTable ();
 /** Pastes clipboard content to the current table */
 	void paste (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 */
 	void clearSelected ();
-	QString getSelectedText ();
 
 /** Flushes pending edit-operations */
 	void flushEdit ();
@@ -58,23 +55,34 @@
 
 	QActionGroup* editActions () const { return edit_actions; };
 public slots:
-	void dataHeaderContextMenu (int row, int col, const QPoint& pos);
-	void metaHeaderContextMenu (int row, int col, const QPoint& pos);
-
 	void metaHeaderPressed (int section);
 	void metaHeaderEntered (int section);
 	void metaHeaderClicked (int section);
 
 	void enableEditing (bool on);
+	void showRownames (bool show);
+
+/** put the marked cells into the clipboard and remove them from the table */
+	void cut();
+/** Copy selection in the current table to clipboard */
+	void copy();
+/** paste the clipboard into the table, expanding the table as necessary */
+	void paste();
+/** paste the clipboard into the table, but not beyond table boundaries */
+	void pasteToTable();
+/** paste the clipboard into the table, but not beyond selection boundaries	*/
+	void pasteToSelection();
 private:
-/** PopupMenu shown when top header is right-clicked */
-	QMenu *top_header_menu;
-/** PopupMenu shown when top header is right-clicked */
-	QMenu *left_header_menu;
-
 	int meta_header_anchor_section;
 /** read-write */
 	bool rw;
+
+/** If currently in one of the context menus, this holds, which table the mouse was pressed over (or 0) */
+	TwinTableMember* context_menu_table;
+/** Only valid, if context_menu_table != 0. Row of current context menu event. -1 for header row. -2 for no cell. */
+	int context_menu_row;
+/** Only valid, if context_menu_table != 0. Column of current context menu event. -1 for header column. -2 for no cell. */
+	int context_menu_column;
 protected:	
 /** Returns the active Table (of the two members), 0 if no table active */
 	TwinTableMember *activeTable ();
@@ -82,20 +90,26 @@
 	TwinTableMember* metaview;
 	TwinTableMember* dataview;
 
-	QAction* action_insert_col_left;
-	QAction* action_delete_col;
+	KAction* action_insert_col_left;
+	KAction* action_delete_col;
+	KAction* action_insert_row_above;
+	KAction* action_delete_row;
+	KAction* action_delete_rows;
+	KAction* action_enable_editing;
+	KAction* action_show_rownames;
+	KAction* editCut;
+	KAction* editCopy;
+	KAction* editPaste;
+	KAction* editPasteToSelection;
+	KAction* editPasteToTable;
 
-	QAction* action_insert_row_above;
-	QAction* action_delete_row;
-	QAction* action_delete_rows;
-
-	QAction* action_enable_editing;
-
 	QActionGroup* edit_actions;
 
 /** receives object meta change notifications. This updates the caption */
 	void objectMetaChanged (RObject* changed);
 
+	void initActions ();
+
 	RObject* main_object;
 private slots:
 /** inserts a new column (NOTE the action connected to this signal carries the info, where the column is to be inserted) */
@@ -108,6 +122,8 @@
 	void deleteSelectedRows ();
 /** deletes the column at the current header_pos. Actually it does not really delete the column, but requests object-removal from the model, which will pass the request to RKModifcationTracker */
 	void deleteColumn ();
+/** handle context menu requests from the two members */
+	void contextMenu (int row, int col, const QPoint& pos);
 };
 
 #endif

Modified: trunk/rkward/rkward/dataeditor/twintablemember.cpp
===================================================================
--- trunk/rkward/rkward/dataeditor/twintablemember.cpp	2010-06-16 18:59:46 UTC (rev 2883)
+++ trunk/rkward/rkward/dataeditor/twintablemember.cpp	2010-06-16 19:02:28 UTC (rev 2884)
@@ -2,7 +2,7 @@
                           twintablemember.cpp  -  description
                              -------------------
     begin                : Tue Oct 29 2002
-    copyright            : (C) 2002, 2006, 2007, 2009 by Thomas Friedrichsmeier
+    copyright            : (C) 2002, 2006, 2007, 2009, 2010 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -39,9 +39,11 @@
 	setSelectionMode (QAbstractItemView::ContiguousSelection);
 
 	verticalHeader ()->setContextMenuPolicy (Qt::CustomContextMenu);
-	connect (verticalHeader (), SIGNAL (customContextMenuRequested(const QPoint&)), this, SLOT (headerContextMenuRequested(const QPoint&)));
+	connect (verticalHeader (), SIGNAL (customContextMenuRequested(const QPoint&)), this, SLOT (handleContextMenuRequest(const QPoint&)));
 	horizontalHeader ()->setContextMenuPolicy (Qt::CustomContextMenu);
-	connect (horizontalHeader (), SIGNAL (customContextMenuRequested(const QPoint&)), this, SLOT (headerContextMenuRequested(const QPoint&)));
+	connect (horizontalHeader (), SIGNAL (customContextMenuRequested(const QPoint&)), this, SLOT (handleContextMenuRequest(const QPoint&)));
+	setContextMenuPolicy (Qt::CustomContextMenu);
+	connect (this, SIGNAL (customContextMenuRequested(const QPoint&)), this, SLOT (handleContextMenuRequest(const QPoint&)));
 
 	updating_twin = false;
 }
@@ -164,12 +166,18 @@
 	QItemSelection sel = selectionModel ()->selection ();
 	if (sel.isEmpty ()){
 		QModelIndex current = currentIndex ();
-		if (!current.isValid ()) return (QItemSelectionRange ());
+		if ((!current.isValid ()) || isIndexHidden (current)) return (QItemSelectionRange ());
 
 		return (QItemSelectionRange (currentIndex (), currentIndex ()));
 	} else {
 		RK_ASSERT (sel.size () == 1);
-		return (sel[0]);
+
+		QItemSelectionRange range = sel[0];
+		while (isColumnHidden (range.left ())) {
+			// purge hidden leading columns from the range
+			range = QItemSelectionRange (mymodel->index (range.top (), range.left () + 1, rootIndex ()), range.bottomRight ());
+		}
+		return (range);
 	}
 }
 
@@ -206,7 +214,7 @@
 	updating_twin = false;
 }
 
-void TwinTableMember::headerContextMenuRequested (const QPoint& pos) {
+void TwinTableMember::handleContextMenuRequest (const QPoint& pos) {
 	RK_TRACE (EDITOR);
 
 	if (sender () == horizontalHeader ()) {
@@ -216,7 +224,14 @@
 		int row = verticalHeader ()->logicalIndexAt (pos);
 		if (row >= 0) emit (contextMenuRequest (row, -1, verticalHeader ()->mapToGlobal (pos)));
 	} else {
-		RK_ASSERT (false);
+		RK_ASSERT (sender () == this);
+
+		int col = columnAt (pos.x ());
+		int row = rowAt (pos.y ());
+		if ((row < 0) || (col < 0)) {
+			row = col = -2;	// to differentiate from the headers, above
+		}
+		emit (contextMenuRequest (row, col, mapToGlobal (pos)));
 	}
 }
 

Modified: trunk/rkward/rkward/dataeditor/twintablemember.h
===================================================================
--- trunk/rkward/rkward/dataeditor/twintablemember.h	2010-06-16 18:59:46 UTC (rev 2883)
+++ trunk/rkward/rkward/dataeditor/twintablemember.h	2010-06-16 19:02:28 UTC (rev 2884)
@@ -2,7 +2,7 @@
                           twintablemember.h  -  description
                              -------------------
     begin                : Tue Oct 29 2002
-    copyright            : (C) 2002, 2006, 2007 by Thomas Friedrichsmeier
+    copyright            : (C) 2002, 2006, 2007, 2010 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -108,7 +108,7 @@
 public slots:
 	void editorDone (QWidget* editor, RKItemDelegate::EditorDoneReason);
 protected slots:
-	void headerContextMenuRequested (const QPoint& pos);
+	void handleContextMenuRequest (const QPoint& pos);
 	void updateColWidth (int section, int old_w, int new_w);
 	void tableSelectionChanged (const QItemSelection& selected, const QItemSelection& deselected);
 };

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/ver.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/ver.R	2010-06-16 18:59:46 UTC (rev 2883)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/ver.R	2010-06-16 19:02:28 UTC (rev 2884)
@@ -1 +1 @@
-".rk.app.version" <- "0.5.4-test0"
+".rk.app.version" <- "0.5.4-test4"

Modified: trunk/rkward/rkward/resource.ver
===================================================================
--- trunk/rkward/rkward/resource.ver	2010-06-16 18:59:46 UTC (rev 2883)
+++ trunk/rkward/rkward/resource.ver	2010-06-16 19:02:28 UTC (rev 2884)
@@ -1 +1 @@
-0.5.4-test0
+0.5.4-test4

Modified: trunk/rkward/rkward/version.h
===================================================================
--- trunk/rkward/rkward/version.h	2010-06-16 18:59:46 UTC (rev 2883)
+++ trunk/rkward/rkward/version.h	2010-06-16 19:02:28 UTC (rev 2884)
@@ -1,2 +1,2 @@
 /* Version number of package */
-#define VERSION "0.5.4-test0"
+#define VERSION "0.5.4-test4"


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