Adding new items to the model can now be made undone/redone.
This commit is contained in:
33
model/commands/insertrowscommand.cpp
Normal file
33
model/commands/insertrowscommand.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include "insertrowscommand.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include "../tablemodel.h"
|
||||
|
||||
InsertRowsCommand::InsertRowsCommand(TableModel* model,
|
||||
int startRow,
|
||||
QList<QHash<int, QVariant> > valueList,
|
||||
QUndoCommand* parent)
|
||||
: QUndoCommand(parent)
|
||||
, m_tableModel(model)
|
||||
, m_startRow(startRow)
|
||||
, m_valueList(valueList) {
|
||||
qInfo() << "New InsertCommand...";
|
||||
const QString commandText =
|
||||
QString("inserting %1 item(s) on row %2").arg(valueList.length()).arg(startRow);
|
||||
setText(commandText);
|
||||
}
|
||||
|
||||
void InsertRowsCommand::undo() {
|
||||
qDebug() << "Undoing the InsertCommand...";
|
||||
if (m_tableModel) {
|
||||
m_tableModel->execRemoveItems(m_startRow, m_valueList.length());
|
||||
}
|
||||
}
|
||||
|
||||
void InsertRowsCommand::redo() {
|
||||
qDebug() << "(Re-)doing the InsertCommand...";
|
||||
if (m_tableModel) {
|
||||
m_tableModel->execInsertItems(m_startRow, m_valueList);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user