Qt-interest Archive, April 2008
QSqlTableModel insertRecord doesnt work?
Message 1 in thread
Hi all,
I have a QSqlTableModel and am attempting to implement an undo/redo stack.
The problem I'm having at the moment, is when I remove a row (removeRow),
and then undo this action, the row gets added to the end of the table. This
kinda makes sense as the first column is a primary key and it therefor gets
given the next available number. This screws up the row numbering and
undoing cell edits gets applied to the wrong rows.
void TableUndo::undo()
{
m_model.insertRecord(m_row, m_record);
}
void TableUndo::redo()
{
m_model.removeRow(m_row);
}
The problem I'm having is that the insertRecord function takes a row as it's
first parameter, but as far as I can tell, this does nothing!
Can anyone enlighten me on how insertRecord works or maybe if I'm just going
about the whole undo/redo thing wrong?
Thanks
Ryan Winter
--
[ signature omitted ]
Message 2 in thread
I'm not sure if there is a better way, but I would:
- At the first undo save the primary key generated by the insert
- At later undo's, preset the saved primary key in the record.
Acenes
-----Ursprüngliche Nachricht-----
Von: Ryan Winter [mailto:wintered@xxxxxxxxx]
Gesendet: Dienstag, 8. April 2008 15:30
An: qt-interest@xxxxxxxxxxxxx
Betreff: QSqlTableModel insertRecord doesnt work?
Hi all,
I have a QSqlTableModel and am attempting to implement an undo/redo stack.
The problem I'm having at the moment, is when I remove a row (removeRow),
and then undo this action, the row gets added to the end of the table. This
kinda makes sense as the first column is a primary key and it therefor gets
given the next available number. This screws up the row numbering and
undoing cell edits gets applied to the wrong rows.
void TableUndo::undo()
{
m_model.insertRecord(m_row, m_record);
}
void TableUndo::redo()
{
m_model.removeRow(m_row);
}
The problem I'm having is that the insertRecord function takes a row as it's
first parameter, but as far as I can tell, this does nothing!
Can anyone enlighten me on how insertRecord works or maybe if I'm just going
about the whole undo/redo thing wrong?
Thanks
Ryan Winter
--
[ signature omitted ]
Message 3 in thread
Hi Acenes,
This is currently what I'm doing however the database appears to just ignore
this field and generate its own primary key. I have thought about
generating my own keys in which case it should work around this, however it
just seems like such a hack...
Acenes wrote:
> I'm not sure if there is a better way, but I would:
>
> - At the first undo save the primary key generated by the insert
> - At later undo's, preset the saved primary key in the record.
>
> Acenes
>
> -----Ursprüngliche Nachricht-----
> Von: Ryan Winter [mailto:wintered@xxxxxxxxx]
> Gesendet: Dienstag, 8. April 2008 15:30
> An: qt-interest@xxxxxxxxxxxxx
> Betreff: QSqlTableModel insertRecord doesnt work?
>
> Hi all,
>
> I have a QSqlTableModel and am attempting to implement an undo/redo stack.
> The problem I'm having at the moment, is when I remove a row (removeRow),
> and then undo this action, the row gets added to the end of the table.
> This kinda makes sense as the first column is a primary key and it
> therefor gets given the next available number. This screws up the row
> numbering and undoing cell edits gets applied to the wrong rows.
>
> void TableUndo::undo()
> {
> m_model.insertRecord(m_row, m_record);
> }
>
> void TableUndo::redo()
> {
> m_model.removeRow(m_row);
> }
>
> The problem I'm having is that the insertRecord function takes a row as
> it's first parameter, but as far as I can tell, this does nothing!
>
> Can anyone enlighten me on how insertRecord works or maybe if I'm just
> going about the whole undo/redo thing wrong?
--
[ signature omitted ]