forked from mirror/openmw-tes3mp
Added delete nested rows command (undo still needs to be done)
This commit is contained in:
parent
c45061614b
commit
7430e1e1bb
2 changed files with 65 additions and 4 deletions
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
#include "commands.hpp"
|
#include "commands.hpp"
|
||||||
|
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
|
@ -171,4 +170,44 @@ void CSMWorld::CloneCommand::redo()
|
||||||
void CSMWorld::CloneCommand::undo()
|
void CSMWorld::CloneCommand::undo()
|
||||||
{
|
{
|
||||||
mModel.removeRow (mModel.getModelIndex (mIdDestination, 0).row());
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QUndoCommand>
|
#include <QUndoCommand>
|
||||||
#include <QModelIndex>
|
#include <QModelIndex>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
#include "universalid.hpp"
|
#include "universalid.hpp"
|
||||||
|
|
||||||
|
@ -49,7 +50,7 @@ namespace CSMWorld
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
CloneCommand (IdTable& model, const std::string& idOrigin,
|
CloneCommand (IdTable& model, const std::string& idOrigin,
|
||||||
const std::string& IdDestination,
|
const std::string& IdDestination,
|
||||||
const UniversalId::Type type,
|
const UniversalId::Type type,
|
||||||
QUndoCommand* parent = 0);
|
QUndoCommand* parent = 0);
|
||||||
|
@ -135,6 +136,27 @@ namespace CSMWorld
|
||||||
|
|
||||||
virtual void undo();
|
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
|
||||||
|
|
Loading…
Reference in a new issue