[rkward-cvs] SF.net SVN: rkward:[4417] trunk/rkward
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Wed Nov 7 11:58:41 UTC 2012
Revision: 4417
http://rkward.svn.sourceforge.net/rkward/?rev=4417&view=rev
Author: tfry
Date: 2012-11-07 11:58:41 +0000 (Wed, 07 Nov 2012)
Log Message:
-----------
Merge more common table code into RKTableView. Also use this for EditLabelsDialog.
Modified Paths:
--------------
trunk/rkward/ChangeLog
trunk/rkward/rkward/dataeditor/twintablemember.cpp
trunk/rkward/rkward/dataeditor/twintablemember.h
trunk/rkward/rkward/misc/editlabelsdialog.cpp
trunk/rkward/rkward/misc/editlabelsdialog.h
trunk/rkward/rkward/misc/rktableview.cpp
trunk/rkward/rkward/misc/rktableview.h
trunk/rkward/rkward/plugin/rkmatrixinput.cpp
trunk/rkward/rkward/plugin/rkmatrixinput.h
Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog 2012-11-07 10:11:55 UTC (rev 4416)
+++ trunk/rkward/ChangeLog 2012-11-07 11:58:41 UTC (rev 4417)
@@ -1,5 +1,6 @@
- Fixed: If none of the previous plugin maps could be found on startup, re-add the default
-- Added GUI element for entering matrix or vector data in plugins TODO: cut / copy / paste, cursor placement
+- Added GUI element for entering matrix or vector data in plugins
+- Improve key handling while editing factor levels in a data.frame
- Added utiltity function rk.flush.output() TODO: Output Window->Flush Output should use this
- RKWard is now categorized as Science/Math/Numerical Analysis in its .desktop file
- Fixed: Device history was not working with more recent versions of ggplot2 (TODO: find out, which version broke it, exactly)
Modified: trunk/rkward/rkward/dataeditor/twintablemember.cpp
===================================================================
--- trunk/rkward/rkward/dataeditor/twintablemember.cpp 2012-11-07 10:11:55 UTC (rev 4416)
+++ trunk/rkward/rkward/dataeditor/twintablemember.cpp 2012-11-07 11:58:41 UTC (rev 4417)
@@ -43,6 +43,7 @@
connect (this, SIGNAL (customContextMenuRequested(const QPoint&)), this, SLOT (handleContextMenuRequest(const QPoint&)));
updating_twin = false;
+ connect (this, SIGNAL (blankSelectionRequest()), this, SLOT (blankSelected()));
}
TwinTableMember::~TwinTableMember(){
@@ -128,18 +129,6 @@
mymodel->setTextMatrix (selrange.topLeft (), pasted, limrange);
}
-void TwinTableMember::keyPressEvent (QKeyEvent *e) {
- RK_TRACE (EDITOR);
-
- if ((e->key () == Qt::Key_Delete) || (e->key () == Qt::Key_Backspace)) {
- blankSelected ();
- e->accept ();
- } else {
- QTableView::keyPressEvent (e);
- scrollTo (currentIndex ()); // why oh why isn't this the default behavior?
- }
-}
-
void TwinTableMember::scrollContentsBy (int dx, int dy) {
RK_TRACE (EDITOR);
Modified: trunk/rkward/rkward/dataeditor/twintablemember.h
===================================================================
--- trunk/rkward/rkward/dataeditor/twintablemember.h 2012-11-07 10:11:55 UTC (rev 4416)
+++ trunk/rkward/rkward/dataeditor/twintablemember.h 2012-11-07 11:58:41 UTC (rev 4417)
@@ -40,18 +40,16 @@
TwinTableMember *getTwin () { return twin; };
/** ends editing. Actually it's just a simple wrapper around QTable::endEdit () */
void stopEditing ();
-/** reimplemented to delete cell contents on DEL and BACKSPACE. Placed in public, here, so CellEditor can have access */
- void keyPressEvent (QKeyEvent *e);
void copy ();
void paste (RKEditor::PasteMode mode);
-/** blanks out the currently selected cells (or the currently active cell, if there is no selection) */
- void blankSelected ();
-
void setRKModel (RKVarEditModelBase* model);
int trueRows () const; // re-implemented from RKTableView
int trueColumns () const; // re-implemented from RKTableView
+public slots:
+/** blanks out the currently selected cells (or the currently active cell, if there is no selection) */
+ void blankSelected ();
signals:
void contextMenuRequest (int row, int col, const QPoint& pos);
protected:
Modified: trunk/rkward/rkward/misc/editlabelsdialog.cpp
===================================================================
--- trunk/rkward/rkward/misc/editlabelsdialog.cpp 2012-11-07 10:11:55 UTC (rev 4416)
+++ trunk/rkward/rkward/misc/editlabelsdialog.cpp 2012-11-07 11:58:41 UTC (rev 4417)
@@ -35,7 +35,7 @@
#include "../debug.h"
-RKVarLevelsTable::RKVarLevelsTable (QWidget *parent, const RObject::ValueLabels& labels) : QTableView (parent) {
+RKVarLevelsTable::RKVarLevelsTable (QWidget *parent, const RObject::ValueLabels& labels) : RKTableView (parent) {
RK_TRACE (EDITOR);
setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
@@ -44,59 +44,50 @@
verticalHeader ()->setFixedWidth (40);
setMinimumWidth (80);
- KActionCollection *ac = new KActionCollection (this);
- ac->addAction (KStandardAction::Cut, this, SLOT (cut ()));
- ac->addAction (KStandardAction::Copy, this, SLOT (copy ()));
- ac->addAction (KStandardAction::Paste, this, SLOT (paste ()));
+ addAction (KStandardAction::cut (this, SLOT (cut ()), this));
+ addAction (KStandardAction::copy (this, SLOT (copy ()), this));
+ addAction (KStandardAction::paste (this, SLOT (paste ()), this));
+ setContextMenuPolicy (Qt::ActionsContextMenu);
setModel (lmodel = new RKVarLevelsTableModel (labels, this));
+ connect (this, SIGNAL (blankSelectionRequest()), this, SLOT (blankSelected()));
+ setRKItemDelegate (new RKItemDelegate (this, lmodel, true));
}
RKVarLevelsTable::~RKVarLevelsTable () {
RK_TRACE (EDITOR);
}
-bool RKVarLevelsTable::getSelectionBoundaries (int* top, int* bottom) const {
+void RKVarLevelsTable::blankSelected () {
RK_TRACE (EDITOR);
- RK_ASSERT (selectionModel ());
- QItemSelection sel = selectionModel ()->selection ();
- if (sel.isEmpty ()){
- QModelIndex current = currentIndex ();
- if (!current.isValid ()) return false;
+ QItemSelectionRange range = getSelectionBoundaries ();
+ if (!range.isValid ()) return;
- *top = current.row ();
- *bottom = current.row ();
- } else {
- RK_ASSERT (sel.size () == 1);
- *top = sel[0].top ();
- *bottom = sel[0].bottom ();
+ for (int row = range.top (); row <= range.bottom (); ++row) {
+ lmodel->setData (lmodel->index (row, 0), QString ());
}
- return true;
}
void RKVarLevelsTable::cut () {
RK_TRACE (EDITOR);
- int top;
- int bottom;
- if (!getSelectionBoundaries (&top, &bottom)) return;
+ QItemSelectionRange range = getSelectionBoundaries ();
+ if (!range.isValid ()) return;
copy ();
-
- for (int i = top; i <= bottom; ++i) lmodel->setData (lmodel->index (i, 0), QString ());
+ blankSelected ();
}
void RKVarLevelsTable::copy () {
RK_TRACE (EDITOR);
- int top;
- int bottom;
- if (!getSelectionBoundaries (&top, &bottom)) return;
+ QItemSelectionRange range = getSelectionBoundaries ();
+ if (!range.isValid ()) return;
RKTextMatrix mat;
int trow = 0;
- for (int i = top; i <= bottom; ++i) {
+ for (int i = range.top (); i <= range.bottom (); ++i) {
mat.setText (trow++, 0, lmodel->data (lmodel->index (i, 0)).toString ());
}
mat.copyToClipboard ();
Modified: trunk/rkward/rkward/misc/editlabelsdialog.h
===================================================================
--- trunk/rkward/rkward/misc/editlabelsdialog.h 2012-11-07 10:11:55 UTC (rev 4416)
+++ trunk/rkward/rkward/misc/editlabelsdialog.h 2012-11-07 11:58:41 UTC (rev 4417)
@@ -31,7 +31,7 @@
@author Thomas Friedrichsmeier
*/
-class RKVarLevelsTable : public QTableView {
+class RKVarLevelsTable : public RKTableView {
Q_OBJECT
public:
RKVarLevelsTable (QWidget *parent, const RObject::ValueLabels& labels);
@@ -43,8 +43,8 @@
void copy ();
/** paste */
void paste ();
+ void blankSelected ();
private:
- bool getSelectionBoundaries (int* top, int* bottom) const;
friend class EditLabelsDialogProxy;
RKVarLevelsTableModel* lmodel;
bool updating_size;
Modified: trunk/rkward/rkward/misc/rktableview.cpp
===================================================================
--- trunk/rkward/rkward/misc/rktableview.cpp 2012-11-07 10:11:55 UTC (rev 4416)
+++ trunk/rkward/rkward/misc/rktableview.cpp 2012-11-07 11:58:41 UTC (rev 4417)
@@ -17,6 +17,8 @@
#include "rktableview.h"
+#include <QKeyEvent>
+
#include "../debug.h"
RKTableView::RKTableView (QWidget *parent) : QTableView (parent) {
@@ -96,7 +98,19 @@
connect (delegate, SIGNAL (doCloseEditor(QWidget*,RKItemDelegate::EditorDoneReason)), this, SLOT (editorDone(QWidget*,RKItemDelegate::EditorDoneReason)));
}
+void RKTableView::keyPressEvent (QKeyEvent *e) {
+ RK_TRACE (EDITOR);
+ if ((e->key () == Qt::Key_Delete) || (e->key () == Qt::Key_Backspace)) {
+ emit (blankSelectionRequest ());
+ e->accept ();
+ } else {
+ QTableView::keyPressEvent (e);
+ scrollTo (currentIndex ()); // why oh why isn't this the default behavior?
+ }
+}
+
+
/////////////////// RKItemDelegate /////////////////////
#include "../dataeditor/rkvareditmodel.h"
@@ -104,8 +118,6 @@
#include "editformatdialog.h"
#include "editlabelsdialog.h"
-#include <QKeyEvent>
-
RKItemDelegate::RKItemDelegate (QObject *parent, RKVarEditModel* datamodel) : QItemDelegate (parent) {
RK_TRACE (EDITOR);
Modified: trunk/rkward/rkward/misc/rktableview.h
===================================================================
--- trunk/rkward/rkward/misc/rktableview.h 2012-11-07 10:11:55 UTC (rev 4416)
+++ trunk/rkward/rkward/misc/rktableview.h 2012-11-07 11:58:41 UTC (rev 4417)
@@ -60,7 +60,11 @@
bool locked_for_modal_editor;
};
-/** simple wrapper around QTableView to fix a couple shortcomings */
+/** simple wrapper around QTableView to fix a couple shortcomings.
+ *
+ * TODO: merge cut() and copy() slots from TwinTableMember, RKMatrixInput, and EditLabelsDialog, here.
+ * (for paste() this is probably not possible, though)
+ */
class RKTableView : public QTableView {
Q_OBJECT
public:
@@ -77,6 +81,11 @@
QItemSelectionRange getSelectionBoundaries () const;
int trailing_rows;
int trailing_columns;
+signals:
+ void blankSelectionRequest ();
+protected:
+/** will emit blankSelectionRequest() on DEL and BACKSPACE. Also scrolls to current index on key presses. */
+ void keyPressEvent (QKeyEvent *e);
private slots:
void editorDone (QWidget* editor, RKItemDelegate::EditorDoneReason reason);
};
Modified: trunk/rkward/rkward/plugin/rkmatrixinput.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkmatrixinput.cpp 2012-11-07 10:11:55 UTC (rev 4416)
+++ trunk/rkward/rkward/plugin/rkmatrixinput.cpp 2012-11-07 11:58:41 UTC (rev 4417)
@@ -23,7 +23,6 @@
#include "../misc/rktableview.h"
#include "../dataeditor/rktextmatrix.h"
-#include "../dataeditor/twintablemember.h"
#include "kstandardaction.h"
#include "kaction.h"
#include "klocale.h"
@@ -107,6 +106,7 @@
display->setContextMenuPolicy (Qt::ActionsContextMenu);
display->setRKItemDelegate (new RKItemDelegate (display, model, true));
+ connect (display, SIGNAL (blankSelectionRequest()), this, SLOT (clearSelectedCells()));
}
RKMatrixInput::~RKMatrixInput () {
Modified: trunk/rkward/rkward/plugin/rkmatrixinput.h
===================================================================
--- trunk/rkward/rkward/plugin/rkmatrixinput.h 2012-11-07 10:11:55 UTC (rev 4416)
+++ trunk/rkward/rkward/plugin/rkmatrixinput.h 2012-11-07 11:58:41 UTC (rev 4417)
@@ -28,10 +28,6 @@
class RKTableView;
class RKMatrixInputModel;
-/* TODO:
- * - key-handling: del, backspace
- */
-
/** Provides a table for editing one- or two-dimensional data
*@author Thomas Friedrichsmeier
*/
@@ -47,6 +43,7 @@
void cut ();
void copy ();
void paste ();
+ void clearSelectedCells ();
private slots:
void dimensionPropertyChanged (RKComponentPropertyBase *property);
void tsvPropertyChanged ();
@@ -98,8 +95,6 @@
// to avoid recursion:
bool updating_tsv_data;
-
- void clearSelectedCells ();
};
#include <QAbstractTableModel>
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