1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-21 10:23:52 +00:00

Added delete nested rows command (undo still needs to be done)

This commit is contained in:
Marek Kochanowicz 2014-06-24 12:35:26 +02:00
parent c45061614b
commit 7430e1e1bb
2 changed files with 65 additions and 4 deletions

View file

@ -1,4 +1,3 @@
#include "commands.hpp"
#include <QAbstractItemModel>
@ -171,4 +170,44 @@ void CSMWorld::CloneCommand::redo()
void CSMWorld::CloneCommand::undo()
{
mModel.removeRow (mModel.getModelIndex (mIdDestination, 0).row());
}
}
CSMWorld::DeleteNestedCommand::DeleteNestedCommand (IdTable& model, const std::string& id, int nestedRow, int parentColumn, QUndoCommand* parent)
: mId(id),
mModel(model),
mParentColumn(parentColumn),
QUndoCommand(parent),
mNestedRow(nestedRow)
{
setText (("Delete nested row in " + mId).c_str());
const QModelIndex& parentIndex = mModel.getModelIndex(mId, mParentColumn);
const int columnsCount = mModel.columnCount(parentIndex);
for (int i = 0; i < columnsCount; ++i)
{
const QModelIndex& childIndex = mModel.index(nestedRow, i, parentIndex);
QVariant data = childIndex.data();
if (!data.isValid())
{
data = childIndex.data(Qt::DisplayRole);
}
mOld.push_back(data);
}
}
void CSMWorld::DeleteNestedCommand::redo()
{
const QModelIndex& parentIndex = mModel.getModelIndex(mId, mParentColumn);
mModel.removeRows (mNestedRow, 1, parentIndex);
}
void CSMWorld::DeleteNestedCommand::undo()
{
//TODO
}

View file

@ -10,6 +10,7 @@
#include <QVariant>
#include <QUndoCommand>
#include <QModelIndex>
#include <QVariant>
#include "universalid.hpp"
@ -49,7 +50,7 @@ namespace CSMWorld
public:
CloneCommand (IdTable& model, const std::string& idOrigin,
CloneCommand (IdTable& model, const std::string& idOrigin,
const std::string& IdDestination,
const UniversalId::Type type,
QUndoCommand* parent = 0);
@ -135,6 +136,27 @@ namespace CSMWorld
virtual void undo();
};
class DeleteNestedCommand : public QUndoCommand
{
IdTable& mModel;
std::string mId;
std::vector<QVariant> mOld;
int mParentColumn;
int mNestedRow;
public:
DeleteNestedCommand (IdTable& model, const std::string& id, int nestedRow, int parentColumn, QUndoCommand* parent);
virtual void redo();
virtual void undo();
};
}
#endif
#endif