[rkward-cvs] SF.net SVN: rkward: [2202] branches/KDE4_port/rkward
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Mon Nov 12 00:18:42 UTC 2007
Revision: 2202
http://rkward.svn.sourceforge.net/rkward/?rev=2202&view=rev
Author: tfry
Date: 2007-11-11 16:18:41 -0800 (Sun, 11 Nov 2007)
Log Message:
-----------
Make copy / paste work
Modified Paths:
--------------
branches/KDE4_port/rkward/core/rkvariable.cpp
branches/KDE4_port/rkward/dataeditor/rktextmatrix.cpp
branches/KDE4_port/rkward/dataeditor/rktextmatrix.h
branches/KDE4_port/rkward/dataeditor/rkvareditmodel.cpp
branches/KDE4_port/rkward/dataeditor/rkvareditmodel.h
branches/KDE4_port/rkward/dataeditor/twintablemember.cpp
Modified: branches/KDE4_port/rkward/core/rkvariable.cpp
===================================================================
--- branches/KDE4_port/rkward/core/rkvariable.cpp 2007-11-11 23:09:49 UTC (rev 2201)
+++ branches/KDE4_port/rkward/core/rkvariable.cpp 2007-11-12 00:18:41 UTC (rev 2202)
@@ -53,8 +53,9 @@
void RKVariable::setVarType (RObject::RDataType new_type, bool sync) {
RK_TRACE (OBJECTS);
- if (getDataType () == new_type) {
- return;
+ if (getDataType () == new_type) return;
+ if ((new_type < RObject::MinKnownDataType) || (new_type > RObject::MaxKnownDataType)) {
+ new_type = RObject::DataCharacter;
}
// if the variable is currently opened for editing, all values need to be rechecked / resynced
Modified: branches/KDE4_port/rkward/dataeditor/rktextmatrix.cpp
===================================================================
--- branches/KDE4_port/rkward/dataeditor/rktextmatrix.cpp 2007-11-11 23:09:49 UTC (rev 2201)
+++ branches/KDE4_port/rkward/dataeditor/rktextmatrix.cpp 2007-11-12 00:18:41 UTC (rev 2202)
@@ -65,6 +65,7 @@
RK_TRACE (EDITOR);
RKTextMatrix ret;
+ if (tsv.isEmpty ()) return ret;
QChar tab ('\t');
QChar brk ('\n');
@@ -77,17 +78,17 @@
for (int pos = 0; pos < buffer_len; ++pos) {
QChar c = tsv.at (pos);
if (c == tab) {
- ret.columns[col][row] = current_word;
- ret.upsize (++row, col);
+ ret.setText (row, col++, current_word);
current_word.clear ();
} else if (c == brk) {
- ret.columns[col][row] = current_word;
- ret.upsize (row, ++col);
+ ret.setText (row++, col, current_word);
+ col = 0;
current_word.clear ();
} else {
current_word.append (c);
}
}
+ ret.setText (row, col, current_word);
return ret;
}
@@ -97,15 +98,13 @@
QString ret;
RK_ASSERT (columns.size () == colcount);
- for (int col = 0; col < colcount; ++col) {
- TextColumn column = columns[col];
- RK_ASSERT (column.size () == rowcount);
+ for (int row = 0; row < rowcount; ++row) {
+ if (row) ret.append ('\n');
- if (col) ret.append ('\n');
-
- for (int row = 0; row < rowcount; ++row) {
- if (row) ret.append ('\t');
- ret.append (column[row]);
+ for (int col = 0; col < colcount; ++col) {
+ if (col) ret.append ('\t');
+ if (!row) RK_ASSERT (columns[col].size () == rowcount);
+ ret.append (columns[col][row]);
}
}
return ret;
@@ -131,7 +130,7 @@
void RKTextMatrix::setColumn (int column, const QString* textarray, int length) {
RK_TRACE (EDITOR);
- upsize (length, column);
+ upsize (length - 1, column);
for (int i = 0; i < length; ++i) {
columns[column][i] = textarray[i];
}
@@ -174,18 +173,22 @@
return false;
}
-void RKTextMatrix::upsize (int newrowcount, int newcolcount) {
+void RKTextMatrix::upsize (int newmaxrow, int newmaxcol) {
// RK_TRACE (EDITOR);
- if (newcolcount > colcount) {
- columns.resize (newcolcount);
- colcount = newcolcount;
+ if (newmaxcol >= colcount) {
+ for (; colcount <= newmaxcol; ++colcount) {
+ TextColumn column;
+ column.resize (rowcount);
+ columns.append (column);
+ }
RK_ASSERT (colcount == columns.size ());
}
- if (newrowcount > rowcount) {
+ if (newmaxrow >= rowcount) {
for (int i = 0; i < colcount; ++i) {
- columns[i].resize (newrowcount);
+ columns[i].resize (newmaxrow + 1);
}
+ rowcount = newmaxrow + 1;
}
}
Modified: branches/KDE4_port/rkward/dataeditor/rktextmatrix.h
===================================================================
--- branches/KDE4_port/rkward/dataeditor/rktextmatrix.h 2007-11-11 23:09:49 UTC (rev 2201)
+++ branches/KDE4_port/rkward/dataeditor/rktextmatrix.h 2007-11-12 00:18:41 UTC (rev 2202)
@@ -55,7 +55,7 @@
typedef QVector<QString> TextColumn;
QVector<TextColumn> columns;
- inline void upsize (int newrowcount, int newcolcount);
+ inline void upsize (int newmaxrow, int newmaxcol);
int colcount;
int rowcount;
Modified: branches/KDE4_port/rkward/dataeditor/rkvareditmodel.cpp
===================================================================
--- branches/KDE4_port/rkward/dataeditor/rkvareditmodel.cpp 2007-11-11 23:09:49 UTC (rev 2201)
+++ branches/KDE4_port/rkward/dataeditor/rkvareditmodel.cpp 2007-11-12 00:18:41 UTC (rev 2202)
@@ -93,7 +93,7 @@
if (cindex < 0) return; // none of our buisiness
emit (dataChanged (index (0, cindex), index (trueRows (), cindex)));
-#warning TODO notify the meta model
+ if (meta_model) meta_model->objectMetaChanged (cindex);
}
void RKVarEditModel::objectDataChanged (RObject* object, const RObject::ChangeSet *changes) {
@@ -130,7 +130,7 @@
if (row > trueRows ()) row = trueRows ();
int lastrow = row+count - 1;
RK_ASSERT (row >= 0);
- RK_ASSERT (lastrow <= row);
+ RK_ASSERT (lastrow >= row);
beginInsertRows (QModelIndex (), row, row+count-1);
for (int i=0; i < objects.size (); ++i) {
@@ -317,7 +317,7 @@
for (int col = left; col <= right; ++col) {
QString* data = objects[col]->getCharacter (top, bottom);
RK_ASSERT (data);
- ret.setColumn (tcol, data, top - bottom + 1);
+ ret.setColumn (tcol, data, bottom - top + 1);
delete [] data;
++tcol;
}
@@ -423,6 +423,12 @@
endRemoveColumns ();
}
+void RKVarEditMetaModel::objectMetaChanged (int atcolumn) {
+ RK_TRACE (EDITOR);
+
+ emit (dataChanged (index (0, atcolumn), index (RowCount - 1, atcolumn)));
+}
+
int RKVarEditMetaModel::rowCount (const QModelIndex& parent) const {
RK_TRACE (EDITOR);
Modified: branches/KDE4_port/rkward/dataeditor/rkvareditmodel.h
===================================================================
--- branches/KDE4_port/rkward/dataeditor/rkvareditmodel.h 2007-11-11 23:09:49 UTC (rev 2201)
+++ branches/KDE4_port/rkward/dataeditor/rkvareditmodel.h 2007-11-12 00:18:41 UTC (rev 2202)
@@ -156,6 +156,7 @@
void endAddDataObject ();
void beginRemoveDataObject (int index);
void endRemoveDataObject ();
+ void objectMetaChanged (int atcolumn);
RKVarEditModel* data_model;
};
Modified: branches/KDE4_port/rkward/dataeditor/twintablemember.cpp
===================================================================
--- branches/KDE4_port/rkward/dataeditor/twintablemember.cpp 2007-11-11 23:09:49 UTC (rev 2201)
+++ branches/KDE4_port/rkward/dataeditor/twintablemember.cpp 2007-11-12 00:18:41 UTC (rev 2202)
@@ -104,6 +104,9 @@
void TwinTableMember::stopEditing () {
RK_TRACE (EDITOR);
+ // I wonder why Qt 4.3 doe not provide a function like this...
+ if (state () != QAbstractItemView::EditingState) return;
+
QModelIndex current = currentIndex ();
setCurrentIndex (QModelIndex ());
setCurrentIndex (current);
@@ -130,13 +133,14 @@
RK_TRACE (EDITOR);
RKTextMatrix pasted = RKTextMatrix::matrixFromClipboard ();
- QItemSelectionRange range;
+ QItemSelectionRange selrange = getSelectionBoundaries ();
+ QItemSelectionRange limrange;
if (mode == RKEditor::PasteToSelection) {
- range = getSelectionBoundaries ();
+ limrange = selrange;
} else if (mode == RKEditor::PasteToTable) {
- range = QItemSelectionRange (mymodel->index (0, 0), mymodel->index (mymodel->trueRows (), mymodel->trueCols ()));
+ limrange = QItemSelectionRange (mymodel->index (0, 0), mymodel->index (mymodel->trueRows () - 1, mymodel->trueCols () - 1));
} // else: range not set means not confined = PasteAnywhere
- mymodel->setTextMatrix (currentIndex (), pasted, range);
+ mymodel->setTextMatrix (selrange.topLeft (), pasted, limrange);
}
QItemSelectionRange TwinTableMember::getSelectionBoundaries () {
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