mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-03 13:49:40 +00:00
Undo for delete operation in referenceables table. Implemented by saving UniversalId::Type in DeleteCommand.
This commit is contained in:
parent
a6925683c6
commit
8aaa74a983
7 changed files with 41 additions and 10 deletions
|
@ -8,6 +8,7 @@
|
||||||
#include "../doc/document.hpp"
|
#include "../doc/document.hpp"
|
||||||
|
|
||||||
#include "idtable.hpp"
|
#include "idtable.hpp"
|
||||||
|
#include "idtree.hpp"
|
||||||
#include "record.hpp"
|
#include "record.hpp"
|
||||||
#include "commands.hpp"
|
#include "commands.hpp"
|
||||||
|
|
||||||
|
@ -153,7 +154,15 @@ void CSMWorld::CommandDispatcher::executeDelete()
|
||||||
std::string id = model.data (model.getModelIndex (*iter, columnIndex)).
|
std::string id = model.data (model.getModelIndex (*iter, columnIndex)).
|
||||||
toString().toUtf8().constData();
|
toString().toUtf8().constData();
|
||||||
|
|
||||||
mDocument.getUndoStack().push (new CSMWorld::DeleteCommand (model, id));
|
if (mId.getType() == UniversalId::Type_Referenceables)
|
||||||
|
{
|
||||||
|
IdTree& tree = dynamic_cast<IdTree&> (*mDocument.getData().getTableModel (mId));
|
||||||
|
std::pair<int, UniversalId::Type> localIndex = tree.searchId (id);
|
||||||
|
|
||||||
|
mDocument.getUndoStack().push (new CSMWorld::DeleteCommand (model, id, localIndex.second));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
mDocument.getUndoStack().push (new CSMWorld::DeleteCommand (model, id));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rows.size()>1)
|
if (rows.size()>1)
|
||||||
|
@ -219,8 +228,17 @@ void CSMWorld::CommandDispatcher::executeExtendedDelete()
|
||||||
Misc::StringUtils::lowerCase (record.get().mCell)))
|
Misc::StringUtils::lowerCase (record.get().mCell)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
mDocument.getUndoStack().push (
|
if (mId.getType() == UniversalId::Type_Referenceables)
|
||||||
new CSMWorld::DeleteCommand (model, record.get().mId));
|
{
|
||||||
|
IdTree& tree = dynamic_cast<IdTree&> (*mDocument.getData().getTableModel (mId));
|
||||||
|
std::pair<int, UniversalId::Type> localIndex = tree.searchId (record.get().mId);
|
||||||
|
|
||||||
|
mDocument.getUndoStack().push (
|
||||||
|
new CSMWorld::DeleteCommand (model, record.get().mId, localIndex.second));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
mDocument.getUndoStack().push (
|
||||||
|
new CSMWorld::DeleteCommand (model, record.get().mId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,8 +103,9 @@ void CSMWorld::RevertCommand::undo()
|
||||||
mModel.setRecord (mId, *mOld);
|
mModel.setRecord (mId, *mOld);
|
||||||
}
|
}
|
||||||
|
|
||||||
CSMWorld::DeleteCommand::DeleteCommand (IdTable& model, const std::string& id, QUndoCommand* parent)
|
CSMWorld::DeleteCommand::DeleteCommand (IdTable& model,
|
||||||
: QUndoCommand (parent), mModel (model), mId (id), mOld (0)
|
const std::string& id, CSMWorld::UniversalId::Type type, QUndoCommand* parent)
|
||||||
|
: QUndoCommand (parent), mModel (model), mId (id), mOld (0), mType(type)
|
||||||
{
|
{
|
||||||
setText (("Delete record " + id).c_str());
|
setText (("Delete record " + id).c_str());
|
||||||
|
|
||||||
|
@ -135,7 +136,7 @@ void CSMWorld::DeleteCommand::redo()
|
||||||
|
|
||||||
void CSMWorld::DeleteCommand::undo()
|
void CSMWorld::DeleteCommand::undo()
|
||||||
{
|
{
|
||||||
mModel.setRecord (mId, *mOld);
|
mModel.setRecord (mId, *mOld, mType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -111,6 +111,7 @@ namespace CSMWorld
|
||||||
IdTable& mModel;
|
IdTable& mModel;
|
||||||
std::string mId;
|
std::string mId;
|
||||||
RecordBase *mOld;
|
RecordBase *mOld;
|
||||||
|
UniversalId::Type mType;
|
||||||
|
|
||||||
// not implemented
|
// not implemented
|
||||||
DeleteCommand (const DeleteCommand&);
|
DeleteCommand (const DeleteCommand&);
|
||||||
|
@ -118,7 +119,8 @@ namespace CSMWorld
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
DeleteCommand (IdTable& model, const std::string& id, QUndoCommand *parent = 0);
|
DeleteCommand (IdTable& model, const std::string& id,
|
||||||
|
UniversalId::Type type = UniversalId::Type_None, QUndoCommand *parent = 0);
|
||||||
|
|
||||||
virtual ~DeleteCommand();
|
virtual ~DeleteCommand();
|
||||||
|
|
||||||
|
|
|
@ -145,7 +145,7 @@ QModelIndex CSMWorld::IdTable::getModelIndex (const std::string& id, int column)
|
||||||
return index(mIdCollection->getIndex (id), column);
|
return index(mIdCollection->getIndex (id), column);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSMWorld::IdTable::setRecord (const std::string& id, const RecordBase& record)
|
void CSMWorld::IdTable::setRecord (const std::string& id, const RecordBase& record, CSMWorld::UniversalId::Type type)
|
||||||
{
|
{
|
||||||
int index = mIdCollection->searchId (id);
|
int index = mIdCollection->searchId (id);
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ void CSMWorld::IdTable::setRecord (const std::string& id, const RecordBase& reco
|
||||||
|
|
||||||
beginInsertRows (QModelIndex(), index, index);
|
beginInsertRows (QModelIndex(), index, index);
|
||||||
|
|
||||||
mIdCollection->appendRecord (record);
|
mIdCollection->appendRecord (record, type);
|
||||||
|
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,8 @@ namespace CSMWorld
|
||||||
|
|
||||||
virtual QModelIndex getModelIndex (const std::string& id, int column) const;
|
virtual QModelIndex getModelIndex (const std::string& id, int column) const;
|
||||||
|
|
||||||
void setRecord (const std::string& id, const RecordBase& record);
|
void setRecord (const std::string& id, const RecordBase& record,
|
||||||
|
UniversalId::Type type = UniversalId::Type_None);
|
||||||
///< Add record or overwrite existing recrod.
|
///< Add record or overwrite existing recrod.
|
||||||
|
|
||||||
const RecordBase& getRecord (const std::string& id) const;
|
const RecordBase& getRecord (const std::string& id) const;
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "collectionbase.hpp"
|
#include "collectionbase.hpp"
|
||||||
#include "nestedcollection.hpp"
|
#include "nestedcollection.hpp"
|
||||||
|
#include "refidcollection.hpp" // HACK: for searchId() only
|
||||||
#include "columnbase.hpp"
|
#include "columnbase.hpp"
|
||||||
|
|
||||||
// NOTE: parent class still needs idCollection
|
// NOTE: parent class still needs idCollection
|
||||||
|
@ -257,3 +258,9 @@ CSMWorld::NestedTableWrapperBase* CSMWorld::IdTree::nestedTable(const QModelInde
|
||||||
|
|
||||||
return mNestedCollection->nestedTable(index.row(), index.column());
|
return mNestedCollection->nestedTable(index.row(), index.column());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HACK: to get the UniversalId::Type associated with a particular record
|
||||||
|
std::pair<int, CSMWorld::UniversalId::Type> CSMWorld::IdTree::searchId (const std::string& id) const
|
||||||
|
{
|
||||||
|
return dynamic_cast<CSMWorld::RefIdCollection*>(idCollection())->getDataSet().searchId(id);
|
||||||
|
}
|
||||||
|
|
|
@ -73,6 +73,8 @@ namespace CSMWorld
|
||||||
|
|
||||||
virtual bool hasChildren (const QModelIndex& index) const;
|
virtual bool hasChildren (const QModelIndex& index) const;
|
||||||
|
|
||||||
|
std::pair<int, UniversalId::Type> searchId (const std::string& id) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
void resetStart(const QString& id);
|
void resetStart(const QString& id);
|
||||||
|
|
Loading…
Reference in a new issue