summaryrefslogtreecommitdiff
path: root/columnlistmodel.cpp
diff options
context:
space:
mode:
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;
}
}