mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-24 10:53:51 +00:00
Undo now working via signals.
This commit is contained in:
parent
1a31aecc2f
commit
e7bd298739
11 changed files with 169 additions and 75 deletions
|
@ -18,7 +18,8 @@ opencs_hdrs_noqt (model/doc
|
|||
|
||||
|
||||
opencs_units (model/world
|
||||
idtable idtableproxymodel regionmap data commanddispatcher idtablebase resourcetable nestedtableproxymodel idtree
|
||||
idtable idtableproxymodel regionmap data commanddispatcher idtablebase resourcetable
|
||||
nestedtableproxymodel idtree pathgridcommands
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#include "idtree.hpp"
|
||||
#include <components/misc/stringops.hpp>
|
||||
#include "nestedtablewrapper.hpp"
|
||||
#include "../../view/render/cell.hpp"
|
||||
|
||||
CSMWorld::ModifyCommand::ModifyCommand (QAbstractItemModel& model, const QModelIndex& index,
|
||||
const QVariant& new_, QUndoCommand* parent)
|
||||
|
@ -245,31 +244,3 @@ const CSMWorld::NestedTableWrapperBase& CSMWorld::NestedTableStoring::getOld() c
|
|||
{
|
||||
return *mOld;
|
||||
}
|
||||
|
||||
// Current interface does not allow adding a non-blank row, so we're forced to modify
|
||||
// the whole record.
|
||||
CSMWorld::ModifyPathgridCommand::ModifyPathgridCommand(IdTree& model,
|
||||
const std::string& id, int parentColumn, CSVRender::Cell *cell,
|
||||
NestedTableWrapperBase* newRecord, QUndoCommand* parent)
|
||||
: mModel(model), mId(id), mParentColumn(parentColumn), mRecord(newRecord), mCell(cell)
|
||||
, QUndoCommand(parent), NestedTableStoring(model, id, parentColumn)
|
||||
{
|
||||
setText (("Modify Pathgrid record " + mId).c_str()); // FIXME: better description
|
||||
}
|
||||
|
||||
void CSMWorld::ModifyPathgridCommand::redo()
|
||||
{
|
||||
const QModelIndex& parentIndex = mModel.getModelIndex(mId, mParentColumn);
|
||||
|
||||
mModel.setNestedTable(parentIndex, *mRecord);
|
||||
}
|
||||
|
||||
void CSMWorld::ModifyPathgridCommand::undo()
|
||||
{
|
||||
const QModelIndex& parentIndex = mModel.getModelIndex(mId, mParentColumn);
|
||||
|
||||
mModel.setNestedTable(parentIndex, getOld());
|
||||
|
||||
mCell->clearPathgrid();
|
||||
mCell->buildPathgrid();
|
||||
}
|
||||
|
|
|
@ -12,16 +12,11 @@
|
|||
#include <QModelIndex>
|
||||
|
||||
#include "universalid.hpp"
|
||||
#include "nestedtablewrapper.hpp"
|
||||
//#include "nestedtablewrapper.hpp"
|
||||
|
||||
class QModelIndex;
|
||||
class QAbstractItemModel;
|
||||
|
||||
namespace CSVRender
|
||||
{
|
||||
class Cell;
|
||||
}
|
||||
|
||||
namespace CSMWorld
|
||||
{
|
||||
class IdTable;
|
||||
|
@ -200,28 +195,6 @@ namespace CSMWorld
|
|||
|
||||
virtual void undo();
|
||||
};
|
||||
|
||||
class ModifyPathgridCommand : public QUndoCommand, private NestedTableStoring
|
||||
{
|
||||
IdTree& mModel;
|
||||
std::string mId;
|
||||
|
||||
int mParentColumn;
|
||||
|
||||
NestedTableWrapperBase* mRecord;
|
||||
CSVRender::Cell *mCell;
|
||||
|
||||
public:
|
||||
|
||||
// if newEdges is NULL, only the paths are updated
|
||||
ModifyPathgridCommand(IdTree& model,
|
||||
const std::string& id, int parentColumn, CSVRender::Cell *cell,
|
||||
NestedTableWrapperBase* newRecord, QUndoCommand* parent = 0);
|
||||
|
||||
virtual void redo();
|
||||
|
||||
virtual void undo();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
48
apps/opencs/model/world/pathgridcommands.cpp
Normal file
48
apps/opencs/model/world/pathgridcommands.cpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
#include "pathgridcommands.hpp"
|
||||
|
||||
#include "../../view/render/cell.hpp"
|
||||
#include "idtree.hpp"
|
||||
#include "nestedtablewrapper.hpp"
|
||||
|
||||
// Current interface does not allow adding a non-blank row, so we're forced to modify
|
||||
// the whole record.
|
||||
CSMWorld::ModifyPathgridCommand::ModifyPathgridCommand(IdTree& model,
|
||||
const std::string& id, int parentColumn, NestedTableWrapperBase* newRecord, QUndoCommand* parent)
|
||||
: mModel(model), mId(id), mParentColumn(parentColumn), mRecord(newRecord)
|
||||
, QUndoCommand(parent), NestedTableStoring(model, id, parentColumn)
|
||||
{
|
||||
setText (("Modify Pathgrid record " + mId).c_str()); // FIXME: better description
|
||||
}
|
||||
|
||||
void CSMWorld::ModifyPathgridCommand::redo()
|
||||
{
|
||||
const QModelIndex& parentIndex = mModel.getModelIndex(mId, mParentColumn);
|
||||
|
||||
mModel.setNestedTable(parentIndex, *mRecord);
|
||||
}
|
||||
|
||||
void CSMWorld::ModifyPathgridCommand::undo()
|
||||
{
|
||||
const QModelIndex& parentIndex = mModel.getModelIndex(mId, mParentColumn);
|
||||
|
||||
mModel.setNestedTable(parentIndex, getOld());
|
||||
|
||||
emit undoActioned();
|
||||
}
|
||||
|
||||
void CSMWorld::SignalHandler::rebuildPathgrid()
|
||||
{
|
||||
mParent->clearPathgrid();
|
||||
mParent->buildPathgrid();
|
||||
|
||||
emit flagAsModified();
|
||||
}
|
||||
|
||||
CSMWorld::SignalHandler::SignalHandler (CSVRender::Cell *parent) : mParent(parent)
|
||||
{}
|
||||
|
||||
void CSMWorld::SignalHandler::connectToCommand(const CSMWorld::ModifyPathgridCommand *command)
|
||||
{
|
||||
connect (command, SIGNAL(undoActioned()),
|
||||
this, SLOT(rebuildPathgrid()));
|
||||
}
|
65
apps/opencs/model/world/pathgridcommands.hpp
Normal file
65
apps/opencs/model/world/pathgridcommands.hpp
Normal file
|
@ -0,0 +1,65 @@
|
|||
#ifndef CSM_WOLRD_PATHGRIDCOMMANDS_H
|
||||
#define CSM_WOLRD_PATHGRIDCOMMANDS_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "commands.hpp"
|
||||
|
||||
namespace CSVRender
|
||||
{
|
||||
class Cell;
|
||||
}
|
||||
|
||||
namespace CSMWorld
|
||||
{
|
||||
class IdTree;
|
||||
class NestedTableWrapperBase;
|
||||
|
||||
class ModifyPathgridCommand : public QObject, public QUndoCommand, private NestedTableStoring
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
IdTree& mModel;
|
||||
std::string mId;
|
||||
|
||||
int mParentColumn;
|
||||
|
||||
NestedTableWrapperBase* mRecord;
|
||||
|
||||
public:
|
||||
|
||||
ModifyPathgridCommand(IdTree& model,
|
||||
const std::string& id, int parentColumn, NestedTableWrapperBase* newRecord,
|
||||
QUndoCommand* parent = 0);
|
||||
|
||||
virtual void redo();
|
||||
|
||||
virtual void undo();
|
||||
|
||||
signals:
|
||||
|
||||
void undoActioned();
|
||||
};
|
||||
|
||||
class SignalHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
CSVRender::Cell *mParent;
|
||||
|
||||
public:
|
||||
|
||||
SignalHandler (CSVRender::Cell *parent);
|
||||
|
||||
void connectToCommand(const ModifyPathgridCommand *command);
|
||||
|
||||
private slots:
|
||||
|
||||
void rebuildPathgrid();
|
||||
|
||||
signals:
|
||||
|
||||
void flagAsModified();
|
||||
};
|
||||
}
|
||||
#endif // CSM_WOLRD_PATHGRIDCOMMANDS_H
|
|
@ -16,6 +16,7 @@
|
|||
#include "../../model/world/refcollection.hpp"
|
||||
#include "../../model/world/pathgrid.hpp"
|
||||
#include "../../model/world/commands.hpp"
|
||||
#include "../../model/world/pathgridcommands.hpp"
|
||||
#include "../../model/world/pathgridpointswrap.hpp"
|
||||
#include "../../model/world/nestedtableproxymodel.hpp"
|
||||
#include "../world/physicssystem.hpp"
|
||||
|
@ -121,6 +122,7 @@ CSVRender::Cell::Cell (CSMDoc::Document& document, Ogre::SceneManager *sceneMana
|
|||
const std::string& id, boost::shared_ptr<CSVWorld::PhysicsSystem> physics, const Ogre::Vector3& origin)
|
||||
: mDocument (document), mId (Misc::StringUtils::lowerCase (id)), mSceneMgr(sceneManager)
|
||||
, mPhysics(physics), mX(0), mY(0), mPgIndex(-1), mModel(0), mProxyModel(0)
|
||||
, mHandler(new CSMWorld::SignalHandler(this))
|
||||
{
|
||||
mCellNode = sceneManager->getRootSceneNode()->createChildSceneNode();
|
||||
mCellNode->setPosition (origin);
|
||||
|
@ -163,6 +165,7 @@ CSVRender::Cell::~Cell()
|
|||
destroyGridMaterials();
|
||||
|
||||
delete mProxyModel;
|
||||
delete mHandler;
|
||||
|
||||
if (mTerrain.get())
|
||||
mPhysics->removeHeightField(mSceneMgr, mX, mY);
|
||||
|
@ -431,10 +434,12 @@ void CSVRender::Cell::pathgridPointAdded(const Ogre::Vector3 &pos, bool interior
|
|||
|
||||
pathgrid.mData.mS2 += 1; // increment the number of points
|
||||
|
||||
// FIXME: probably will crash if this cell is deleted and undo() is actioned afterwards
|
||||
mDocument.getUndoStack().push(new CSMWorld::ModifyPathgridCommand(*mModel,
|
||||
mProxyModel->getParentId(), mProxyModel->getParentColumn(), this,
|
||||
new CSMWorld::PathgridPointsWrap(pathgrid)));
|
||||
// FIXME: possible issue if this cell is deleted and undo() is actioned afterwards
|
||||
CSMWorld::ModifyPathgridCommand *cmd = new CSMWorld::ModifyPathgridCommand(*mModel,
|
||||
mProxyModel->getParentId(), mProxyModel->getParentColumn(),
|
||||
new CSMWorld::PathgridPointsWrap(pathgrid));
|
||||
mHandler->connectToCommand(cmd);
|
||||
mDocument.getUndoStack().push(cmd);
|
||||
// emit signal here?
|
||||
}
|
||||
|
||||
|
@ -488,10 +493,12 @@ void CSVRender::Cell::pathgridPointRemoved(const std::string &name)
|
|||
<< pathgridId + "_" + QString::number(index).toStdString() << std::endl;
|
||||
}
|
||||
|
||||
// FIXME: probably will crash if this cell is deleted and undo() is actioned afterwards
|
||||
mDocument.getUndoStack().push(new CSMWorld::ModifyPathgridCommand(*mModel,
|
||||
mProxyModel->getParentId(), mProxyModel->getParentColumn(), this,
|
||||
new CSMWorld::PathgridPointsWrap(pathgrid)));
|
||||
// FIXME: possible issue if this cell is deleted and undo() is actioned afterwards
|
||||
CSMWorld::ModifyPathgridCommand *cmd = new CSMWorld::ModifyPathgridCommand(*mModel,
|
||||
mProxyModel->getParentId(), mProxyModel->getParentColumn(),
|
||||
new CSMWorld::PathgridPointsWrap(pathgrid));
|
||||
mHandler->connectToCommand(cmd);
|
||||
mDocument.getUndoStack().push(cmd);
|
||||
|
||||
clearPathgrid();
|
||||
buildPathgrid();
|
||||
|
@ -529,10 +536,12 @@ void CSVRender::Cell::pathgridPointMoved(const std::string &name,
|
|||
pathgrid.mPoints[index].mY = y;
|
||||
pathgrid.mPoints[index].mZ = newPos.z;
|
||||
|
||||
// FIXME: probably will crash if this cell is deleted and undo() is actioned afterwards
|
||||
mDocument.getUndoStack().push(new CSMWorld::ModifyPathgridCommand(*mModel,
|
||||
mProxyModel->getParentId(), mProxyModel->getParentColumn(), this,
|
||||
new CSMWorld::PathgridPointsWrap(pathgrid)));
|
||||
// FIXME: possible issue if this cell is deleted and undo() is actioned afterwards
|
||||
CSMWorld::ModifyPathgridCommand *cmd = new CSMWorld::ModifyPathgridCommand(*mModel,
|
||||
mProxyModel->getParentId(), mProxyModel->getParentColumn(),
|
||||
new CSMWorld::PathgridPointsWrap(pathgrid));
|
||||
mHandler->connectToCommand(cmd);
|
||||
mDocument.getUndoStack().push(cmd);
|
||||
|
||||
clearPathgrid();
|
||||
buildPathgrid();
|
||||
|
@ -551,3 +560,8 @@ void CSVRender::Cell::addPathgridEdge()
|
|||
void CSVRender::Cell::removePathgridEdge()
|
||||
{
|
||||
}
|
||||
|
||||
CSMWorld::SignalHandler *CSVRender::Cell::getSignalHandler()
|
||||
{
|
||||
return mHandler;
|
||||
}
|
||||
|
|
|
@ -31,10 +31,10 @@ namespace CSMDoc
|
|||
|
||||
namespace CSMWorld
|
||||
{
|
||||
//class Data;
|
||||
class Pathgrid;
|
||||
class NestedTableProxyModel;
|
||||
class IdTree;
|
||||
class SignalHandler;
|
||||
}
|
||||
|
||||
namespace CSVWorld
|
||||
|
@ -58,6 +58,7 @@ namespace CSVRender
|
|||
CSMWorld::NestedTableProxyModel *mProxyModel;
|
||||
CSMWorld::IdTree *mModel;
|
||||
int mPgIndex;
|
||||
CSMWorld::SignalHandler *mHandler;
|
||||
|
||||
std::auto_ptr<Terrain::TerrainGrid> mTerrain;
|
||||
boost::shared_ptr<CSVWorld::PhysicsSystem> mPhysics;
|
||||
|
@ -126,6 +127,7 @@ namespace CSVRender
|
|||
|
||||
void clearPathgrid();
|
||||
void buildPathgrid();
|
||||
CSMWorld::SignalHandler *getSignalHandler();
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include "../../model/world/tablemimedata.hpp"
|
||||
#include "../../model/world/idtable.hpp"
|
||||
#include "../../model/world/pathgridcommands.hpp"
|
||||
|
||||
#include "../widget/scenetooltoggle.hpp"
|
||||
#include "../widget/scenetoolmode.hpp"
|
||||
|
@ -115,6 +116,7 @@ bool CSVRender::PagedWorldspaceWidget::adjustCells()
|
|||
{
|
||||
Cell *cell = new Cell (mDocument, getSceneManager(),
|
||||
iter->getId (mWorldspace), mDocument.getPhysics());
|
||||
connect (cell->getSignalHandler(), SIGNAL(flagAsModified()), this, SLOT(flagAsModSlot()));
|
||||
mCells.insert (std::make_pair (*iter, cell));
|
||||
|
||||
float height = cell->getTerrainHeightAt(Ogre::Vector3(
|
||||
|
@ -637,3 +639,8 @@ void CSVRender::PagedWorldspaceWidget::cellAdded (const QModelIndex& index, int
|
|||
if (adjustCells())
|
||||
flagAsModified();
|
||||
}
|
||||
|
||||
void CSVRender::PagedWorldspaceWidget::flagAsModSlot ()
|
||||
{
|
||||
flagAsModified();
|
||||
}
|
||||
|
|
|
@ -120,6 +120,7 @@ namespace CSVRender
|
|||
|
||||
virtual void cellAdded (const QModelIndex& index, int start, int end);
|
||||
|
||||
virtual void flagAsModSlot();
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "../../model/world/data.hpp"
|
||||
#include "../../model/world/idtable.hpp"
|
||||
#include "../../model/world/tablemimedata.hpp"
|
||||
#include "../../model/world/pathgridcommands.hpp"
|
||||
|
||||
#include "../widget/scenetooltoggle.hpp"
|
||||
#include "../widget/scenetooltoggle2.hpp"
|
||||
|
@ -49,7 +50,9 @@ CSVRender::UnpagedWorldspaceWidget::UnpagedWorldspaceWidget (const std::string&
|
|||
|
||||
update();
|
||||
|
||||
mCell.reset (new Cell (document, getSceneManager(), mCellId, document.getPhysics()));
|
||||
Cell *cell = new Cell (document, getSceneManager(), mCellId, document.getPhysics());
|
||||
connect (cell->getSignalHandler(), SIGNAL(flagAsModified()), this, SLOT(flagAsModSlot()));
|
||||
mCell.reset (cell);
|
||||
}
|
||||
|
||||
void CSVRender::UnpagedWorldspaceWidget::cellDataChanged (const QModelIndex& topLeft,
|
||||
|
@ -91,7 +94,9 @@ bool CSVRender::UnpagedWorldspaceWidget::handleDrop (const std::vector<CSMWorld:
|
|||
return false;
|
||||
|
||||
mCellId = data.begin()->getId();
|
||||
mCell.reset (new Cell (getDocument(), getSceneManager(), mCellId, getDocument().getPhysics()));
|
||||
Cell *cell = new Cell (getDocument(), getSceneManager(), mCellId, getDocument().getPhysics());
|
||||
connect (cell->getSignalHandler(), SIGNAL(flagAsModified()), this, SLOT(flagAsModSlot()));
|
||||
mCell.reset (cell);
|
||||
|
||||
update();
|
||||
emit cellChanged(*data.begin());
|
||||
|
@ -212,3 +217,8 @@ CSVRender::WorldspaceWidget::dropRequirments CSVRender::UnpagedWorldspaceWidget:
|
|||
return ignored;
|
||||
}
|
||||
}
|
||||
|
||||
void CSVRender::UnpagedWorldspaceWidget::flagAsModSlot ()
|
||||
{
|
||||
flagAsModified();
|
||||
}
|
||||
|
|
|
@ -76,6 +76,8 @@ namespace CSVRender
|
|||
|
||||
void cellRowsAboutToBeRemoved (const QModelIndex& parent, int start, int end);
|
||||
|
||||
virtual void flagAsModSlot();
|
||||
|
||||
signals:
|
||||
|
||||
void cellChanged(const CSMWorld::UniversalId& id);
|
||||
|
|
Loading…
Reference in a new issue