[rkward-cvs] SF.net SVN: rkward: [2254] branches/KDE4_port
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Mon Nov 19 23:47:49 UTC 2007
Revision: 2254
http://rkward.svn.sourceforge.net/rkward/?rev=2254&view=rev
Author: tfry
Date: 2007-11-19 15:47:49 -0800 (Mon, 19 Nov 2007)
Log Message:
-----------
Allow to set data.frame editor to read-only. This is not quite what PK had in mind, yet, but it is a prerequisite
Modified Paths:
--------------
branches/KDE4_port/ChangeLog
branches/KDE4_port/INSTALL
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
Modified: branches/KDE4_port/ChangeLog
===================================================================
--- branches/KDE4_port/ChangeLog 2007-11-19 21:50:11 UTC (rev 2253)
+++ branches/KDE4_port/ChangeLog 2007-11-19 23:47:49 UTC (rev 2254)
@@ -1,3 +1,4 @@
+- data.frame editor can be set to read-only mode
- code completion in script editor shows icons for the different object types
- settings dialog is now shown in "page list" mode
- port to KDE 4 (TODO)
Modified: branches/KDE4_port/INSTALL
===================================================================
--- branches/KDE4_port/INSTALL 2007-11-19 21:50:11 UTC (rev 2253)
+++ branches/KDE4_port/INSTALL 2007-11-19 23:47:49 UTC (rev 2254)
@@ -51,6 +51,7 @@
-DR_INCLUDE
path to R include files. Almost certainly this option is not needed.
+Further generic options are listed on http://www.cmake.org/Wiki/CMake_Useful_Variables .
Installation
==================
Modified: branches/KDE4_port/rkward/dataeditor/rkeditordataframe.cpp
===================================================================
--- branches/KDE4_port/rkward/dataeditor/rkeditordataframe.cpp 2007-11-19 21:50:11 UTC (rev 2253)
+++ branches/KDE4_port/rkward/dataeditor/rkeditordataframe.cpp 2007-11-19 23:47:49 UTC (rev 2254)
@@ -81,16 +81,6 @@
open_chain = RKGlobals::rInterface ()->startChain (0);
}
-void RKEditorDataFrame::enableEditing (bool on) {
- if (on) {
- metaview->setEnabled (true);
- dataview->setEnabled (true);
- } else {
- metaview->setEnabled (false);
- dataview->setEnabled (false);
- }
-}
-
RKEditorDataFrame::~RKEditorDataFrame () {
RK_TRACE (EDITOR);
}
@@ -127,5 +117,3 @@
#warning TODO: this interface should be moved to the model for good.
datamodel->restoreObject (object, 0);
}
-
-#include "rkeditordataframe.moc"
Modified: branches/KDE4_port/rkward/dataeditor/rkeditordataframe.h
===================================================================
--- branches/KDE4_port/rkward/dataeditor/rkeditordataframe.h 2007-11-19 21:50:11 UTC (rev 2253)
+++ branches/KDE4_port/rkward/dataeditor/rkeditordataframe.h 2007-11-19 23:47:49 UTC (rev 2254)
@@ -55,7 +55,6 @@
void pushTable (RCommandChain *sync_chain);
void commonInit ();
RCommandChain *open_chain;
- void enableEditing (bool on);
void waitForLoad ();
protected:
void rCommandDone (RCommand *command);
Modified: branches/KDE4_port/rkward/dataeditor/rkeditordataframepart.cpp
===================================================================
--- branches/KDE4_port/rkward/dataeditor/rkeditordataframepart.cpp 2007-11-19 21:50:11 UTC (rev 2253)
+++ branches/KDE4_port/rkward/dataeditor/rkeditordataframepart.cpp 2007-11-19 23:47:49 UTC (rev 2254)
@@ -44,17 +44,24 @@
}
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 (KIcon ("frame_spreadsheet"));
+ editor->editActions ()->addAction (editPasteToTable);
editPasteToSelection = actionCollection ()->addAction ("paste_to_selection", this, SLOT(slotEditPasteToSelection()));
editPasteToSelection->setText (i18n("Paste inside Selection"));
editPasteToSelection->setIcon (KIcon ("frame-edit"));
+ 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"));
Modified: branches/KDE4_port/rkward/dataeditor/twintable.cpp
===================================================================
--- branches/KDE4_port/rkward/dataeditor/twintable.cpp 2007-11-19 21:50:11 UTC (rev 2253)
+++ branches/KDE4_port/rkward/dataeditor/twintable.cpp 2007-11-19 23:47:49 UTC (rev 2254)
@@ -78,13 +78,34 @@
action_insert_col_left = top_header_menu->addAction (RKStandardIcons::getIcon (RKStandardIcons::ActionInsertVar), QString (), this, SLOT (insertColumn()));
action_insert_col_right = 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()));
-
+
left_header_menu = new QMenu (this);
action_insert_row_above = left_header_menu->addAction (RKStandardIcons::getIcon (RKStandardIcons::ActionInsertRow), QString (), this, SLOT (insertRow()));
action_insert_row_below = 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()));
+ // 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_insert_col_right);
+ edit_actions->addAction (action_delete_col);
+ edit_actions->addAction (action_insert_row_above);
+ edit_actions->addAction (action_insert_row_below);
+ 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);
}
@@ -121,7 +142,9 @@
RK_TRACE (EDITOR);
RK_ASSERT (changed == main_object);
- setCaption (main_object->getShortName ());
+ QString caption = main_object->getShortName ();
+ if (!rw) caption += i18n (" [read-only]");
+ setCaption (caption);
}
void TwinTable::metaHeaderPressed (int section) {
@@ -210,6 +233,7 @@
void TwinTable::deleteColumn () {
RK_TRACE (EDITOR);
+ RK_ASSERT (rw);
QObject *s = sender ();
int col;
@@ -226,6 +250,7 @@
void TwinTable::insertColumn () {
RK_TRACE (EDITOR);
+ RK_ASSERT (rw);
QObject *s = sender ();
int where;
@@ -243,6 +268,7 @@
void TwinTable::deleteRow () {
RK_TRACE (EDITOR);
+ RK_ASSERT (rw);
QObject *s = sender ();
int where;
@@ -259,6 +285,7 @@
void TwinTable::deleteSelectedRows () {
RK_TRACE (EDITOR);
+ RK_ASSERT (rw);
QItemSelectionRange sel = dataview->getSelectionBoundaries ();
if (sel.isValid ()) {
@@ -275,6 +302,7 @@
void TwinTable::insertRow () {
RK_TRACE (EDITOR);
+ RK_ASSERT (rw);
QObject *s = sender ();
int where;
@@ -302,6 +330,8 @@
void TwinTable::paste (RKEditor::PasteMode paste_mode) {
RK_TRACE (EDITOR);
+ if (!rw) return;
+
flushEdit ();
TwinTableMember *table = activeTable ();
@@ -325,6 +355,8 @@
void TwinTable::clearSelected () {
RK_TRACE (EDITOR);
+ if (!rw) return;
+
TwinTableMember *table = activeTable ();
if (!table) return;
@@ -339,4 +371,34 @@
dataview->stopEditing ();
}
+void TwinTable::enableEditing (bool on) {
+ RK_TRACE (EDITOR);
+
+ flushEdit ();
+
+ rw = on;
+ metaview->rw = rw;
+ dataview->rw = rw;
+
+ QPalette palette = metaview->palette ();
+ if (on) palette.setColor (QPalette::Base, QColor (255, 255, 255));
+ else palette.setColor (QPalette::Base, QColor (240, 240, 240));
+ metaview->setPalette (palette);
+ dataview->setPalette (palette);
+
+ metaview->viewport ()->setEnabled (rw);
+ dataview->viewport ()->setEnabled (rw);
+
+ QAbstractItemView::EditTriggers triggers = QAbstractItemView::NoEditTriggers;
+ if (rw) triggers = QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed | QAbstractItemView::AnyKeyPressed;
+
+ metaview->setEditTriggers (triggers);
+ dataview->setEditTriggers (triggers);
+
+ edit_actions->setEnabled (rw);
+ action_enable_editing->setChecked (rw);
+
+ if (main_object) objectMetaChanged (main_object); // update_caption;
+}
+
#include "twintable.moc"
Modified: branches/KDE4_port/rkward/dataeditor/twintable.h
===================================================================
--- branches/KDE4_port/rkward/dataeditor/twintable.h 2007-11-19 21:50:11 UTC (rev 2253)
+++ branches/KDE4_port/rkward/dataeditor/twintable.h 2007-11-19 23:47:49 UTC (rev 2254)
@@ -28,6 +28,7 @@
class TwinTableMember;
class QMenu;
class RKVarEditModel;
+class QActionGroup;
/**
*@author Thomas Friedrichsmeier
@@ -54,6 +55,8 @@
void initTable (RKVarEditModel* model, RObject* object);
RKVarEditModel* datamodel;
+
+ 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);
@@ -61,6 +64,8 @@
void metaHeaderPressed (int section);
void metaHeaderEntered (int section);
void metaHeaderClicked (int section);
+
+ void enableEditing (bool on);
private:
/** PopupMenu shown when top header is right-clicked */
QMenu *top_header_menu;
@@ -68,6 +73,8 @@
QMenu *left_header_menu;
int meta_header_anchor_section;
+/** read-write */
+ bool rw;
protected:
/** Returns the active Table (of the two members), 0 if no table active */
TwinTableMember *activeTable ();
@@ -84,6 +91,10 @@
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);
Modified: branches/KDE4_port/rkward/dataeditor/twintablemember.cpp
===================================================================
--- branches/KDE4_port/rkward/dataeditor/twintablemember.cpp 2007-11-19 21:50:11 UTC (rev 2253)
+++ branches/KDE4_port/rkward/dataeditor/twintablemember.cpp 2007-11-19 23:47:49 UTC (rev 2254)
@@ -33,6 +33,8 @@
TwinTableMember::TwinTableMember (QWidget *parent) : QTableView (parent){
RK_TRACE (EDITOR);
+ rw = true;
+
setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOn);
setSelectionMode (QAbstractItemView::ContiguousSelection);
@@ -133,6 +135,8 @@
void TwinTableMember::blankSelected () {
RK_TRACE (EDITOR);
+ if (!rw) return;
+
QItemSelectionRange range = getSelectionBoundaries ();
if (range.isValid ()) mymodel->blankRange (range);
}
@@ -140,6 +144,8 @@
void TwinTableMember::paste (RKEditor::PasteMode mode) {
RK_TRACE (EDITOR);
+ if (!rw) return;
+
RKTextMatrix pasted = RKTextMatrix::matrixFromClipboard ();
QItemSelectionRange selrange = getSelectionBoundaries ();
QItemSelectionRange limrange;
Modified: branches/KDE4_port/rkward/dataeditor/twintablemember.h
===================================================================
--- branches/KDE4_port/rkward/dataeditor/twintablemember.h 2007-11-19 21:50:11 UTC (rev 2253)
+++ branches/KDE4_port/rkward/dataeditor/twintablemember.h 2007-11-19 23:47:49 UTC (rev 2254)
@@ -101,6 +101,8 @@
void scrollContentsBy (int dx, int dy);
RKVarEditModelBase* mymodel;
+
+ bool rw;
friend class TwinTable;
void setTwin (TwinTableMember *new_twin);
public 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