[rkward-cvs] SF.net SVN: rkward: [2201] branches/KDE4_port/rkward
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Sun Nov 11 23:09:50 UTC 2007
Revision: 2201
http://rkward.svn.sourceforge.net/rkward/?rev=2201&view=rev
Author: tfry
Date: 2007-11-11 15:09:49 -0800 (Sun, 11 Nov 2007)
Log Message:
-----------
EditLabelsDialog works again, and a few other fixes to the new data.frame editor
Modified Paths:
--------------
branches/KDE4_port/rkward/core/rkvariable.cpp
branches/KDE4_port/rkward/core/rkvariable.h
branches/KDE4_port/rkward/core/robject.h
branches/KDE4_port/rkward/dataeditor/celleditor.cpp
branches/KDE4_port/rkward/dataeditor/celleditor.h
branches/KDE4_port/rkward/dataeditor/editlabelsdialog.cpp
branches/KDE4_port/rkward/dataeditor/editlabelsdialog.h
branches/KDE4_port/rkward/dataeditor/rkvareditmodel.cpp
branches/KDE4_port/rkward/dataeditor/rkvareditmodel.h
branches/KDE4_port/rkward/dataeditor/twintablemember.cpp
branches/KDE4_port/rkward/dataeditor/twintablemember.h
Modified: branches/KDE4_port/rkward/core/rkvariable.cpp
===================================================================
--- branches/KDE4_port/rkward/core/rkvariable.cpp 2007-11-11 21:28:08 UTC (rev 2200)
+++ branches/KDE4_port/rkward/core/rkvariable.cpp 2007-11-11 23:09:49 UTC (rev 2201)
@@ -789,18 +789,28 @@
}
}
-RObject::ValueLabels *RKVariable::getValueLabels () const {
+RObject::ValueLabels RKVariable::getValueLabels () const {
RK_ASSERT (data);
- return (data->value_labels);
+
+ if (!data->value_labels) return RObject::ValueLabels ();
+ return (*(data->value_labels));
}
-void RKVariable::setValueLabels (ValueLabels *labels) {
+void RKVariable::setValueLabels (const ValueLabels& labels) {
RK_TRACE (OBJECTS);
RK_ASSERT (data);
-
- if (labels != data->value_labels) {
- delete (data->value_labels);
- data->value_labels = labels;
+
+ if (labels.isEmpty ()) {
+ if (!data->value_labels) return; // no change: was empty, is empty
+
+ delete data->value_labels;
+ data->value_labels = 0;
+ } else {
+ if (!(data->value_labels)) data->value_labels = new RObject::ValueLabels;
+ else {
+ if (*(data->value_labels) == labels) return; // old and new lists are the same
+ }
+ *(data->value_labels) = labels;
}
writeValueLabels (0);
@@ -809,11 +819,11 @@
// find out which values got valid / invalid and change those
for (int i=0; i < getLength (); ++i) {
if (cellStatus (i) == ValueInvalid) {
- if (labels && labels->contains (getText (i))) {
+ if (labels.contains (getText (i))) {
setText (i, getText (i));
}
} else {
- if (!(labels && labels->contains (getText (i)))) {
+ if (!(labels.contains (getText (i)))) {
setText (i, getText (i));
}
}
@@ -873,17 +883,12 @@
RK_TRACE (OBJECTS);
RK_ASSERT (data);
+ ValueLabels new_labels;
QStringList list = QStringList::split ("#,#", string);
-
- if (list.empty ()) {
- setValueLabels (0);
- return;
- }
-
+
int i = 1;
- ValueLabels *new_labels = new ValueLabels;
for (QStringList::const_iterator it = list.constBegin (); it != list.constEnd (); ++it) {
- new_labels->insert (QString::number (i), *it);
+ new_labels.insert (QString::number (i), *it);
++i;
}
setValueLabels (new_labels);
@@ -896,7 +901,7 @@
return data->formatting_options;
}
-void RKVariable::setFormattingOptions (FormattingOptions new_options) {
+void RKVariable::setFormattingOptions (const FormattingOptions new_options) {
RK_TRACE (OBJECTS);
RK_ASSERT (data);
Modified: branches/KDE4_port/rkward/core/rkvariable.h
===================================================================
--- branches/KDE4_port/rkward/core/rkvariable.h 2007-11-11 21:28:08 UTC (rev 2200)
+++ branches/KDE4_port/rkward/core/rkvariable.h 2007-11-11 23:09:49 UTC (rev 2201)
@@ -95,10 +95,10 @@
/** Tells the object it has (data) length len. Usually this will only be called directly after creating a new object */
void setLength (int len);
-/** returns the map of value labels for this variable or 0 if no labels/levels are assigned. Does _not_ return a copy, but the real thing. Do not delete! */
- ValueLabels *getValueLabels () const;
-/** assigns a new map of labels. Also takes care of syncing with the backend. Ownership of the ValueLabels is transferred to the variable. Use setValueLabels (0) to remove all labels */
- void setValueLabels (ValueLabels *labels);
+/** returns (a copy of) the map of value labels for this variable or and empty map, if no labels/levels are assigned. */
+ ValueLabels getValueLabels () const;
+/** assigns a new map of labels. Also takes care of syncing with the backend. */
+ void setValueLabels (const ValueLabels& labels);
/** get value labels as string (for display) */
QString getValueLabelString () const;
/** set value labels from string (for paste operations) */
@@ -118,7 +118,7 @@
};
/** assigns new formatting options. Ownership of the FormattingOptions -struct is transferred to the variable. Use setFormatting (0) to remove all options */
- void setFormattingOptions (FormattingOptions new_options);
+ void setFormattingOptions (const FormattingOptions new_options);
/** get the formatting options for this variable */
FormattingOptions getFormattingOptions () const;
/** get formatting options as a string (for display) TODO: redundant -> remove */
@@ -164,7 +164,7 @@
ChangeSet *changes;
/// stores whether there were preivously invalid cells. If so, and there are no longer, now, we may change the mode in the backend.
bool previously_valid;
-/// the value-labels or factor levels assigned to this variable. 0 if no values/levels given
+/** the value-labels or factor levels assigned to this variable. 0 if no values/levels given. TODO: Should this be made a regular (non-pointer) member, or is the saved mem really worth the trouble? */
ValueLabels *value_labels;
/// the formatting options set for this var (see FormattingOptions) */
FormattingOptions formatting_options;
Modified: branches/KDE4_port/rkward/core/robject.h
===================================================================
--- branches/KDE4_port/rkward/core/robject.h 2007-11-11 21:28:08 UTC (rev 2200)
+++ branches/KDE4_port/rkward/core/robject.h 2007-11-11 23:09:49 UTC (rev 2201)
@@ -72,7 +72,10 @@
DataNumeric=1,
DataFactor=2,
DataCharacter=3,
- DataLogical=4
+ DataLogical=4,
+
+ MinKnownDataType = DataNumeric,
+ MaxKnownDataType = DataLogical
};
#define ROBJECT_TYPE_INTERNAL_MASK (RObject::Container | RObject::Variable | RObject::Workspace | RObject::Environment | RObject::Function)
Modified: branches/KDE4_port/rkward/dataeditor/celleditor.cpp
===================================================================
--- branches/KDE4_port/rkward/dataeditor/celleditor.cpp 2007-11-11 21:28:08 UTC (rev 2200)
+++ branches/KDE4_port/rkward/dataeditor/celleditor.cpp 2007-11-11 23:09:49 UTC (rev 2201)
@@ -35,10 +35,11 @@
RK_TRACE (EDITOR);
}
-void CellEditor::setValueLabels (const RObject::ValueLabels *labels) {
+void CellEditor::setValueLabels (const RObject::ValueLabels& labels) {
RK_TRACE (EDITOR);
- RK_ASSERT (labels);
+ if (labels.isEmpty ()) return;
+
// NOTE: not using a QComboBox, as we do not want it to pop up immediately
value_list = new QMenu (this);
value_list->setFont (font ());
@@ -46,7 +47,7 @@
value_list->setFocusProxy (this);
value_list->installEventFilter (this); // somehow setting us as a focus proxy is not enough to continue to receive the key-presses
- for (RObject::ValueLabels::const_iterator it = labels->constBegin (); it != labels->constEnd (); ++it) {
+ for (RObject::ValueLabels::const_iterator it = labels.constBegin (); it != labels.constEnd (); ++it) {
value_list->addAction (it.key () + ": " + it.data ())->setData (it.key ());
}
connect (value_list, SIGNAL (triggered(QAction*)), SLOT (selectedFromList(QAction*)));
@@ -78,7 +79,7 @@
void CellEditor::keyPressEvent (QKeyEvent *e) {
if (!e->state ()) {
- if (e->key () == Qt::Key_Left) {
+ if ((e->key () == Qt::Key_Left) || (e->key () == Qt::Key_Backspace)) {
if (cursorPosition () < 1) {
emit (done (this, RKItemDelegate::EditorExitLeft));
return;
Modified: branches/KDE4_port/rkward/dataeditor/celleditor.h
===================================================================
--- branches/KDE4_port/rkward/dataeditor/celleditor.h 2007-11-11 21:28:08 UTC (rev 2200)
+++ branches/KDE4_port/rkward/dataeditor/celleditor.h 2007-11-11 23:09:49 UTC (rev 2201)
@@ -42,7 +42,7 @@
CellEditor (QWidget* parent);
~CellEditor ();
- void setValueLabels (const RObject::ValueLabels *labels);
+ void setValueLabels (const RObject::ValueLabels& labels);
void setText (const QString& text);
signals:
Modified: branches/KDE4_port/rkward/dataeditor/editlabelsdialog.cpp
===================================================================
--- branches/KDE4_port/rkward/dataeditor/editlabelsdialog.cpp 2007-11-11 21:28:08 UTC (rev 2200)
+++ branches/KDE4_port/rkward/dataeditor/editlabelsdialog.cpp 2007-11-11 23:09:49 UTC (rev 2201)
@@ -25,7 +25,7 @@
#include <qlabel.h>
#include <qlayout.h>
#include <QHeaderView>
-//Added by qt3to4:
+#include <QTimer>
#include <QHBoxLayout>
#include <QVBoxLayout>
@@ -35,11 +35,9 @@
#include "../debug.h"
-RKVarLevelsTable::RKVarLevelsTable (QWidget *parent, RObject::ValueLabels *labels) : QTableView (parent) {
+RKVarLevelsTable::RKVarLevelsTable (QWidget *parent, const RObject::ValueLabels& labels) : QTableView (parent) {
RK_TRACE (EDITOR);
- RK_ASSERT (labels);
-
setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
setSelectionMode (QAbstractItemView::ContiguousSelection);
horizontalHeader ()->setStretchLastSection (true);
@@ -129,7 +127,7 @@
/////////////// RKVarLevelsTableModel /////////////////
-RKVarLevelsTableModel::RKVarLevelsTableModel (RObject::ValueLabels* labels, QObject* parent) : QAbstractTableModel (parent) {
+RKVarLevelsTableModel::RKVarLevelsTableModel (const RObject::ValueLabels& labels, QObject* parent) : QAbstractTableModel (parent) {
RK_TRACE (EDITOR);
RKVarLevelsTableModel::labels = labels;
@@ -143,7 +141,7 @@
RK_TRACE (EDITOR);
if (parent.isValid ()) return 0;
- return labels->count () + 1;
+ return labels.count () + 1;
}
int RKVarLevelsTableModel::columnCount (const QModelIndex& parent) const {
@@ -158,12 +156,12 @@
if (!index.isValid ()) return QVariant ();
if (index.column () != 0) return QVariant ();
- if ((role == Qt::BackgroundRole) && (index.row () == labels->count ())) return QBrush (Qt::gray);
- if (index.row () >= labels->count ()) return QVariant ();
+ if ((role == Qt::BackgroundRole) && (index.row () == labels.count ())) return QBrush (Qt::gray);
+ if (index.row () >= labels.count ()) return QVariant ();
- if ((role != Qt::DisplayRole) || (role != Qt::EditRole)) return QVariant ();
+ if ((role == Qt::DisplayRole) || (role == Qt::EditRole)) return labels.value (QString::number (index.row ()+1));
- return labels->value (QString::number (index.row ()+1));
+ return QVariant ();
}
Qt::ItemFlags RKVarLevelsTableModel::flags (const QModelIndex& index) const {
@@ -171,7 +169,7 @@
if (!index.isValid ()) return 0;
if (index.column () != 0) return 0;
- if (index.row () >= labels->count ()) return (Qt::ItemIsEditable | Qt::ItemIsEnabled);
+ if (index.row () >= labels.count ()) return (Qt::ItemIsEditable | Qt::ItemIsEnabled);
return (Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
}
@@ -182,23 +180,23 @@
if (!index.isValid ()) return false;
if (index.column () != 0) return false;
if (!value.isValid ()) return false;
- if (index.row () > labels->count ()) return false;
+ if (index.row () > labels.count ()) return false;
QString text = value.toString ();
- if (index.row () == labels->count ()) {
+ if (index.row () == labels.count ()) {
beginInsertRows (QModelIndex (), index.row (), index.row ());
- labels->insert (QString::number (index.row () + 1), value.toString ());
+ labels.insert (QString::number (index.row () + 1), text);
endInsertRows ();
} else {
- labels->insert (QString::number (index.row () + 1), value.toString ());
+ labels.insert (QString::number (index.row () + 1), text);
emit (dataChanged (index, index));
}
if (text.isEmpty ()) { // remove trailing empty rows
- while ((!labels->isEmpty ()) && labels->value (QString::number (labels->size ())).isEmpty ()) {
- int row = labels->size () - 1;
+ while ((!labels.isEmpty ()) && labels.value (QString::number (labels.count ())).isEmpty ()) {
+ int row = labels.count () - 1;
beginRemoveRows (QModelIndex (), row, row);
- labels->remove (QString::number (row + 1));
+ labels.remove (QString::number (row + 1));
endRemoveRows ();
}
}
@@ -217,28 +215,18 @@
//////////////// EditLabelsDialog ///////////////////////
-EditLabelsDialog::EditLabelsDialog (QWidget *parent, RKVariable *var, int mode) : KDialog (parent) {
+EditLabelsDialog::EditLabelsDialog (QWidget *parent, const RObject::ValueLabels& labels, const QString& varname) : KDialog (parent) {
RK_TRACE (EDITOR);
- RK_ASSERT (var);
-// RK_ASSERT (var->objectOpened ());
- EditLabelsDialog::var = var;
- EditLabelsDialog::mode = mode;
-
KVBox *mainvbox = new KVBox ();
setMainWidget (mainvbox);
QLabel *label = new QLabel (i18n ("Levels can be assigned only to consecutive integers starting with 1 (the index column is read only). To remove levels at the end of the list, just set them to empty."), mainvbox);
label->setWordWrap (true);
- RObject::ValueLabels *labels = var->getValueLabels ();
- if (!labels) {
- labels = new RObject::ValueLabels;
- }
-
table = new RKVarLevelsTable (mainvbox, labels);
setButtons (KDialog::Ok | KDialog::Cancel);
- setCaption (i18n ("Levels / Value labels for '%1'", var->getShortName ()));
+ setCaption (i18n ("Levels / Value labels for '%1'", varname));
}
EditLabelsDialog::~EditLabelsDialog () {
@@ -248,17 +236,44 @@
void EditLabelsDialog::accept () {
RK_TRACE (EDITOR);
-#warning do we need something like this? how to achieve it?
-// table->stopEditing ();
+ table->setCurrentIndex (QModelIndex ()); // should flush editing
+ KDialog::accept ();
+}
- RObject::ValueLabels *labels = table->lmodel->labels;
- if (labels->isEmpty ()) {
- var->setValueLabels (0);
+////////////////// EditLabelsDialogProxy /////////////////////////
+
+EditLabelsDialogProxy::EditLabelsDialogProxy (QWidget* parent) : QWidget (parent) {
+ RK_TRACE (EDITOR);
+ dialog = 0;
+}
+
+EditLabelsDialogProxy::~EditLabelsDialogProxy () {
+ RK_TRACE (EDITOR);
+}
+
+void EditLabelsDialogProxy::initialize (const RObject::ValueLabels& labels, const QString& varname) {
+ RK_TRACE (EDITOR);
+
+ EditLabelsDialogProxy::labels = labels; // we need to take a copy in case the dialog is rejected
+
+ dialog = new EditLabelsDialog (this, labels, varname);
+ connect (dialog, SIGNAL (finished(int)), this, SLOT (dialogDone(int)));
+ QTimer::singleShot (0, dialog, SLOT (exec()));
+}
+
+void EditLabelsDialogProxy::dialogDone (int result) {
+ RK_TRACE (EDITOR);
+ RK_ASSERT (dialog);
+
+ if (result == QDialog::Accepted) {
+ labels = dialog->table->lmodel->labels;
+ emit (done (this, RKItemDelegate::EditorExit));
} else {
- var->setValueLabels (labels);
+ emit (done (this, RKItemDelegate::EditorReject));
}
-
- QDialog::accept ();
+ dialog->deleteLater ();
+ dialog = 0;
}
+
#include "editlabelsdialog.moc"
Modified: branches/KDE4_port/rkward/dataeditor/editlabelsdialog.h
===================================================================
--- branches/KDE4_port/rkward/dataeditor/editlabelsdialog.h 2007-11-11 21:28:08 UTC (rev 2200)
+++ branches/KDE4_port/rkward/dataeditor/editlabelsdialog.h 2007-11-11 23:09:49 UTC (rev 2201)
@@ -23,19 +23,19 @@
#include <QAbstractTableModel>
#include "../core/robject.h"
+#include "twintablemember.h"
class RKVariable;
class RKVarLevelsTableModel;
/** special mini class provides the table in EditLabelsDialog
-TODO: make copy/paste work
@author Thomas Friedrichsmeier
*/
class RKVarLevelsTable : public QTableView {
Q_OBJECT
public:
- RKVarLevelsTable (QWidget *parent, RObject::ValueLabels *labels);
+ RKVarLevelsTable (QWidget *parent, const RObject::ValueLabels& labels);
~RKVarLevelsTable ();
public slots:
/** cut */
@@ -46,7 +46,7 @@
void paste ();
private:
bool getSelectionBoundaries (int* top, int* bottom) const;
-friend class EditLabelsDialog;
+friend class EditLabelsDialogProxy;
RKVarLevelsTableModel* lmodel;
bool updating_size;
};
@@ -54,7 +54,7 @@
/** Data model for the RKVarLevelsTable */
class RKVarLevelsTableModel : public QAbstractTableModel {
public:
- RKVarLevelsTableModel (RObject::ValueLabels* labels, QObject* parent);
+ RKVarLevelsTableModel (const RObject::ValueLabels& labels, QObject* parent);
~RKVarLevelsTableModel ();
int rowCount (const QModelIndex& parent = QModelIndex()) const;
@@ -64,33 +64,49 @@
bool setData (const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
private:
-friend class EditLabelsDialog;
- RObject::ValueLabels* labels;
+friend class EditLabelsDialogProxy;
+ RObject::ValueLabels labels;
};
/**
-Allows editing of value labels / factor levels for an (edited) RKVariable
+Allows editing of value labels / factor levels for an RKVariable. Use EditLabelsDialogProxy.
@author Thomas Friedrichsmeier
*/
class EditLabelsDialog : public KDialog {
- Q_OBJECT
-public:
+protected:
+friend class EditLabelsDialogProxy;
/** constuctor., the variable to work on.
- at param parent a QWidget parent (usually 0)
- at param var the variable/factor to set labels for
- at param mode not yet used */
- EditLabelsDialog (QWidget *parent, RKVariable *var, int mode=0);
+ at param parent a QWidget parent */
+ EditLabelsDialog (QWidget *parent, const RObject::ValueLabels& labels, const QString& varname);
~EditLabelsDialog ();
-protected:
-/// reimplemented to submit the changes to the backend
+
+/** reimplemented to make sure pending edit operations are not lost */
void accept ();
- void reject ();
private:
- RKVarLevelsTable *table;
- RKVariable *var;
- int mode;
+ RKVarLevelsTable* table;
};
+/**
+Simple proxy / wrapper to allow using a modal EditLabelsDialog in a QTableView
+ at author Thomas Friedrichsmeier */
+class EditLabelsDialogProxy : public QWidget {
+ Q_OBJECT
+public:
+ EditLabelsDialogProxy (QWidget* parent);
+ ~EditLabelsDialogProxy ();
+
+ void initialize (const RObject::ValueLabels& labels, const QString& varname);
+
+ RObject::ValueLabels getLabels () const { return labels; };
+signals:
+ void done (QWidget* widget, RKItemDelegate::EditorDoneReason reason);
+protected slots:
+ void dialogDone (int result);
+private:
+ EditLabelsDialog* dialog;
+ RObject::ValueLabels labels;
+};
+
#endif
Modified: branches/KDE4_port/rkward/dataeditor/rkvareditmodel.cpp
===================================================================
--- branches/KDE4_port/rkward/dataeditor/rkvareditmodel.cpp 2007-11-11 21:28:08 UTC (rev 2200)
+++ branches/KDE4_port/rkward/dataeditor/rkvareditmodel.cpp 2007-11-11 23:09:49 UTC (rev 2201)
@@ -293,7 +293,7 @@
if (role != Qt::DisplayRole) return QVariant ();
if (orientation == Qt::Horizontal) {
- if (section >= objects.size ()) return QVariant ();
+ if (section >= objects.size ()) return i18n ("#New Variable#");
return objects[section]->getShortName ();
}
@@ -534,6 +534,28 @@
return true;
}
+RObject::ValueLabels RKVarEditMetaModel::getValueLabels (int column) const {
+ RK_TRACE (EDITOR);
+
+ if (column >= trueCols ()) return RObject::ValueLabels ();
+ return (getObject (column)->getValueLabels ());
+}
+
+void RKVarEditMetaModel::setValueLabels (int column, const RObject::ValueLabels& labels) {
+ RK_TRACE (EDITOR);
+
+ if (column >= data_model->apparentCols ()) {
+ RK_ASSERT (false);
+ return;
+ }
+ if (column >= trueCols ()) {
+ data_model->doInsertColumns (trueCols (), 1);
+ }
+ RKVariable* var = getObject (column);
+ RK_ASSERT (var);
+ var->setValueLabels (labels);
+}
+
QVariant RKVarEditMetaModel::headerData (int section, Qt::Orientation orientation, int role) const {
RK_TRACE (EDITOR);
Modified: branches/KDE4_port/rkward/dataeditor/rkvareditmodel.h
===================================================================
--- branches/KDE4_port/rkward/dataeditor/rkvareditmodel.h 2007-11-11 21:28:08 UTC (rev 2200)
+++ branches/KDE4_port/rkward/dataeditor/rkvareditmodel.h 2007-11-11 23:09:49 UTC (rev 2201)
@@ -142,6 +142,9 @@
int trueCols () const { return data_model->trueCols (); };
int trueRows () const { return RowCount; };
+ RObject::ValueLabels getValueLabels (int column) const;
+ void setValueLabels (int column, const RObject::ValueLabels& labels);
+
RKVariable* getObject (int index) const { return data_model->getObject (index); };
RKVarEditModel* getDataModel () const { return data_model; };
protected:
Modified: branches/KDE4_port/rkward/dataeditor/twintablemember.cpp
===================================================================
--- branches/KDE4_port/rkward/dataeditor/twintablemember.cpp 2007-11-11 21:28:08 UTC (rev 2200)
+++ branches/KDE4_port/rkward/dataeditor/twintablemember.cpp 2007-11-11 23:09:49 UTC (rev 2201)
@@ -23,6 +23,7 @@
#include "celleditor.h"
#include "editformatdialog.h"
+#include "editlabelsdialog.h"
#include "twintable.h"
#include "rktextmatrix.h"
#include "rkvareditmodel.h"
@@ -33,7 +34,8 @@
RK_TRACE (EDITOR);
twin = 0;
- TwinTableMember::table = table; // TODO: seems unused
+#warning member "table" seems to be unused
+ TwinTableMember::table = table;
setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOn);
setSelectionMode (QAbstractItemView::ContiguousSelection);
@@ -42,14 +44,7 @@
horizontalHeader ()->setContextMenuPolicy (Qt::CustomContextMenu);
connect (horizontalHeader (), SIGNAL (customContextMenuRequested(const QPoint&)), this, SLOT (headerContextMenuRequested(const QPoint&)));
- connect (this, SIGNAL (selectionChanged(const QItemSelection&,const QItemSelection&)), this, SLOT (tableSelectionChanged(const QItemSelection&,const QItemSelection&)));
-
updating_twin = false;
-
-#warning currently unused, but likey will be used.
- tted = 0;
-
- connect (this, SIGNAL (currentChanged (int, int)), this, SLOT (currentCellChanged (int, int)));
}
TwinTableMember::~TwinTableMember(){
@@ -58,8 +53,12 @@
void TwinTableMember::setRKModel (RKVarEditModelBase* model) {
RK_TRACE (EDITOR);
+
mymodel = model;
setModel (model);
+
+ // now we should also have a selectionModel() (but not before)
+ connect (selectionModel (), SIGNAL (selectionChanged(const QItemSelection&,const QItemSelection&)), this, SLOT (tableSelectionChanged(const QItemSelection&,const QItemSelection&)));
}
void TwinTableMember::seRKItemDelegate (RKItemDelegate* delegate) {
@@ -102,47 +101,14 @@
}
}
-void TwinTableMember::editorLostFocus () {
- RK_TRACE (EDITOR);
- stopEditing ();
-}
-
void TwinTableMember::stopEditing () {
RK_TRACE (EDITOR);
-#warning todo
-// if (tted) endEdit (currEditRow (), currEditCol (), true, false);
- RK_ASSERT (!tted);
-}
-#if 0
-void TwinTableMember::endEdit (int row, int col, bool, bool) {
- RK_TRACE (EDITOR);
- if (tted) setCellContentFromEditor (row, col);
- setEditMode (NotEditing, -1, -1);
+ QModelIndex current = currentIndex ();
+ setCurrentIndex (QModelIndex ());
+ setCurrentIndex (current);
}
-#endif
-#if 0
-void TwinTableMember::setCellContentFromEditor (int row, int col) {
- RK_TRACE (EDITOR);
- RK_ASSERT (tted);
-
- QString text_save = tted->text ();
-
- //tted->removeEventFilter (this);
- tted->hide ();
- tted->deleteLater ();
- tted = 0;
-
- if (text (row, col) != text_save) {
- setText (row, col, text_save);
- emit (valueChanged (row, col));
- }
-
- viewport ()->setFocus ();
-}
-#endif
-
void TwinTableMember::copy () {
RK_TRACE (EDITOR);
@@ -211,13 +177,13 @@
updating_twin = false;
}
-void TwinTableMember::updateColWidth (int section, int old_w, int new_w) {
+void TwinTableMember::updateColWidth (int section, int, int new_w) {
RK_TRACE (EDITOR);
if (updating_twin) return;
updating_twin = true;
- RK_ASSERT (columnWidth (section) == old_w);
setColumnWidth (section, new_w);
+ twin->setColumnWidth (section, new_w);
updating_twin = false;
}
@@ -265,9 +231,10 @@
int row = index.row ();
if (row == RKVarEditMetaModel::FormatRow) {
ed = new EditFormatDialogProxy (parent);
+ } else if (row == RKVarEditMetaModel::LevelsRow) {
+ ed = new EditLabelsDialogProxy (parent);
} else {
ed = new CellEditor (parent);
-#warning implement
}
}
@@ -287,24 +254,31 @@
if (!index.isValid ()) return;
if (datamodel) {
- // do nothing. CellEditor will be intialized below
CellEditor* ced = static_cast<CellEditor*> (editor);
ced->setText (datamodel->data (index, Qt::EditRole).toString ());
- RObject::ValueLabels* labels = 0;
if (index.column () < datamodel->trueCols ()) {
- labels = datamodel->getObject (index.column ())->getValueLabels ();
+ ced->setValueLabels (datamodel->getObject (index.column ())->getValueLabels ());
}
- if (labels) ced->setValueLabels (labels);
} else if (metamodel) {
int row = index.row ();
if (row == RKVarEditMetaModel::FormatRow) {
EditFormatDialogProxy* fed = static_cast<EditFormatDialogProxy*> (editor);
- fed->initialize (RKVariable::parseFormattingOptionsString (metamodel->data (index, Qt::EditRole).toString ()), metamodel->data (metamodel->index (RKVarEditMetaModel::FormatRow, index.column ())).toString ());
+ fed->initialize (RKVariable::parseFormattingOptionsString (metamodel->data (index, Qt::EditRole).toString ()), metamodel->headerData (index.column (), Qt::Horizontal).toString ());
+ } else if (row == RKVarEditMetaModel::LevelsRow) {
+ EditLabelsDialogProxy* led = static_cast<EditLabelsDialogProxy*> (editor);
+ led->initialize (metamodel->getValueLabels (index.column ()), metamodel->headerData (index.column (), Qt::Horizontal).toString ());
} else {
-#warning implement
CellEditor* ced = static_cast<CellEditor*> (editor);
ced->setText (metamodel->data (index, Qt::EditRole).toString ());
+
+ if (row == RKVarEditMetaModel::TypeRow) {
+ RObject::ValueLabels labels;
+ for (int i = RObject::MinKnownDataType; i <= RObject::MaxKnownDataType; ++i) {
+ labels.insert (QString::number (i), RObject::typeToText ((RObject::RDataType) i));
+ }
+ ced->setValueLabels (labels);
+ }
}
} else {
RK_ASSERT (false);
@@ -329,9 +303,11 @@
EditFormatDialogProxy* fed = static_cast<EditFormatDialogProxy*> (editor);
model->setData (index, RKVariable::formattingOptionsToString (fed->getOptions ()), Qt::EditRole);
return;
- } else {
-#warning implement
- }
+ } else if (row == RKVarEditMetaModel::LevelsRow) {
+ EditLabelsDialogProxy* led = static_cast<EditLabelsDialogProxy*> (editor);
+ metamodel->setValueLabels (index.column (), led->getLabels ());
+ return;
+ } // else all others use the regular CellEditor
} else {
RK_ASSERT (false);
}
Modified: branches/KDE4_port/rkward/dataeditor/twintablemember.h
===================================================================
--- branches/KDE4_port/rkward/dataeditor/twintablemember.h 2007-11-11 21:28:08 UTC (rev 2200)
+++ branches/KDE4_port/rkward/dataeditor/twintablemember.h 2007-11-11 23:09:49 UTC (rev 2201)
@@ -81,9 +81,6 @@
TwinTableMember *getTwin () { return twin; };
/** ends editing. Actually it's just a simple wrapper around QTable::endEdit () */
void stopEditing ();
-#warning maybe still needed?
-/** needed to detect right mouse clicks in the header and tab-keypresses in the CellEditor */
-// bool eventFilter (QObject *object, QEvent *event);
/** reimplemented to delete cell contents on DEL and BACKSPACE. Placed in public, here, so CellEditor can have access */
void keyPressEvent (QKeyEvent *e);
@@ -104,7 +101,6 @@
TwinTable *table;
bool updating_twin;
- CellEditor *tted;
/** reimplemented from QTableView to also adjust the twin */
void scrollContentsBy (int dx, int dy);
@@ -113,10 +109,6 @@
void setTwin (TwinTableMember *new_twin);
public slots:
void editorDone (QWidget* editor, RKItemDelegate::EditorDoneReason);
-
- void editorLostFocus ();
-/** called when the current cell is changed. If no selection is in place, will (does not do it yet) pop up the value-list */
-// void currentCellChanged (int row, int col);
protected slots:
void headerContextMenuRequested (const QPoint& pos);
void updateColWidth (int section, int old_w, int new_w);
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