summaryrefslogtreecommitdiff
path: root/columnlistmodel.cpp
diff options
context:
space:
mode:
authorLukáš Lalinský <lalinsky@gmail.com>2008-11-29 23:26:18 +0100
committerLukáš Lalinský <lalinsky@gmail.com>2008-11-29 23:26:18 +0100
commit3458318f785ba66b65e7a3c831368d58321e10e5 (patch)
tree89ce2f16b379c5891fc583d88c8a44912e926fb4 /columnlistmodel.cpp
parent38c64d01f173989e3bc2172f6989e587480bd83e (diff)
downloaddbmodel-3458318f785ba66b65e7a3c831368d58321e10e5.tar.xz
Convert column edits to undo-able commands
Diffstat (limited to 'columnlistmodel.cpp')
-rw-r--r--columnlistmodel.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/columnlistmodel.cpp b/columnlistmodel.cpp
index 948ff1c..f2c8a99 100644
--- a/columnlistmodel.cpp
+++ b/columnlistmodel.cpp
@@ -16,7 +16,9 @@
#include <QDebug>
#include "columnlistmodel.h"
+#include "databasemodel.h"
#include "databasetable.h"
+#include "commands.h"
#include "column.h"
#define COLUMN_COUNT 5
@@ -87,26 +89,36 @@ ColumnListModel::setData(const QModelIndex &index, const QVariant &value, int ro
if (role == Qt::DisplayRole || role == Qt::EditRole) {
QString text = value.toString();
if (index.column() == 0) {
- column->setName(text);
+ column->table()->model()->undoStack()->push(
+ new ChangeColumnPropertyCommand(column, Column::NameProperty, text));
goto OK;
}
if (index.column() == 1) {
- column->setDataType(text);
+ column->table()->model()->undoStack()->push(
+ new ChangeColumnPropertyCommand(column, Column::DataTypeProperty, text));
goto OK;
}
if (index.column() == 4) {
- column->setNotes(text);
+ column->table()->model()->undoStack()->push(
+ new ChangeColumnPropertyCommand(column, Column::NotesProperty, text));
goto OK;
}
}
if (role == Qt::CheckStateRole) {
bool checked = value.toInt() == Qt::Checked ? true : false;
if (index.column() == 2) {
- column->setRequired(checked);
+ column->table()->model()->undoStack()->push(
+ new ChangeColumnPropertyCommand(column, Column::RequiredProperty, checked));
goto OK;
}
if (index.column() == 3) {
- column->setPrimaryKey(checked);
+ column->table()->model()->undoStack()->push(
+ new ChangeColumnPropertyCommand(column, Column::PrimaryKeyProperty, checked));
+ if (!column->isRequired()) {
+ // TODO is there a simple way to group this with the previous command?
+ column->table()->model()->undoStack()->push(
+ new ChangeColumnPropertyCommand(column, Column::RequiredProperty, true));
+ }
goto OK;
}
}