Miss Engineer
14th May 2014, 11:32
Hello,
I have a TableView that uses an SqlQueryModel. I want some of the cells in the table to be editable but the edits should not affect the original database. I subclassed SqlQueryModel with ItemFlags that allow it to be editiable. Because I do not want the changes to affect the database, I can't re implement the setData function, and so any edits get ignored as soon as I hit enter. Any ideas on how I can get the data entered in the view to stay there without affecting the model? Also, how can I tell the subclassed SqlQueryModel that I only want the cells in the second column that do not contain data to be editable?
The following is my subclass:
#include "editablesqlmodel.h"
class EditableSQLModel;
EditableSQLModel::EditableSQLModel(QObject *parent):
QSqlQueryModel(parent)
{
}
Qt::ItemFlags EditableSQLModel::flags(const QModelIndex &index) const
{
Qt::ItemFlags flags = QSqlQueryModel::flags(index);
if (index.column() == 1) flags |= Qt::ItemIsEditable;
return flags;
}
I have a TableView that uses an SqlQueryModel. I want some of the cells in the table to be editable but the edits should not affect the original database. I subclassed SqlQueryModel with ItemFlags that allow it to be editiable. Because I do not want the changes to affect the database, I can't re implement the setData function, and so any edits get ignored as soon as I hit enter. Any ideas on how I can get the data entered in the view to stay there without affecting the model? Also, how can I tell the subclassed SqlQueryModel that I only want the cells in the second column that do not contain data to be editable?
The following is my subclass:
#include "editablesqlmodel.h"
class EditableSQLModel;
EditableSQLModel::EditableSQLModel(QObject *parent):
QSqlQueryModel(parent)
{
}
Qt::ItemFlags EditableSQLModel::flags(const QModelIndex &index) const
{
Qt::ItemFlags flags = QSqlQueryModel::flags(index);
if (index.column() == 1) flags |= Qt::ItemIsEditable;
return flags;
}