diff --git a/apps/opencs/model/world/commands.hpp b/apps/opencs/model/world/commands.hpp index 02d042487..2d63b66c9 100644 --- a/apps/opencs/model/world/commands.hpp +++ b/apps/opencs/model/world/commands.hpp @@ -12,7 +12,6 @@ #include #include "universalid.hpp" -//#include "nestedtablewrapper.hpp" class QModelIndex; class QAbstractItemModel; diff --git a/apps/opencs/model/world/pathgridcommands.cpp b/apps/opencs/model/world/pathgridcommands.cpp index 356806dcd..193ab4457 100644 --- a/apps/opencs/model/world/pathgridcommands.cpp +++ b/apps/opencs/model/world/pathgridcommands.cpp @@ -1,6 +1,7 @@ #include "pathgridcommands.hpp" #include "../../view/render/cell.hpp" + #include "idtree.hpp" #include "nestedtablewrapper.hpp" @@ -43,6 +44,5 @@ CSMWorld::SignalHandler::SignalHandler (CSVRender::Cell *parent) : mParent(paren void CSMWorld::SignalHandler::connectToCommand(const CSMWorld::ModifyPathgridCommand *command) { - connect (command, SIGNAL(undoActioned()), - this, SLOT(rebuildPathgrid())); + connect (command, SIGNAL(undoActioned()), this, SLOT(rebuildPathgrid())); } diff --git a/apps/opencs/model/world/pathgridcommands.hpp b/apps/opencs/model/world/pathgridcommands.hpp index 335e3a893..3acf0865b 100644 --- a/apps/opencs/model/world/pathgridcommands.hpp +++ b/apps/opencs/model/world/pathgridcommands.hpp @@ -53,7 +53,7 @@ namespace CSMWorld void connectToCommand(const ModifyPathgridCommand *command); - private slots: + public slots: void rebuildPathgrid(); diff --git a/apps/opencs/view/render/cell.cpp b/apps/opencs/view/render/cell.cpp index 7976fd55e..f7ec24a56 100644 --- a/apps/opencs/view/render/cell.cpp +++ b/apps/opencs/view/render/cell.cpp @@ -307,9 +307,34 @@ float CSVRender::Cell::getTerrainHeightAt(const Ogre::Vector3 &pos) const return -std::numeric_limits::max(); } +void CSVRender::Cell::pathgridDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight) +{ + CSMWorld::IdTree *pathgrids = dynamic_cast( + mDocument.getData().getTableModel(CSMWorld::UniversalId::Type_Pathgrid)); + + int idColumn = pathgrids->findColumnIndex(CSMWorld::Columns::ColumnId_Id); + int colPaths = pathgrids->findColumnIndex(CSMWorld::Columns::ColumnId_PathgridPoints); + //int colEdges = pathgrids->findColumnIndex(CSMWorld::Columns::ColumnId_PathgridEdges); + + // FIXME: how to detect adds/deletes/modifies? + + for (int i=topLeft.row(); i<=bottomRight.row(); ++i) + { + std::string cell = Misc::StringUtils::lowerCase (pathgrids->data ( + pathgrids->index (i, idColumn)).toString().toUtf8().constData()); + + if (cell==mId && colPaths >= topLeft.column() && colPaths <= bottomRight.column()) + { + if (!mModel) + setupPathgrid(); + + mHandler->rebuildPathgrid(); + } + } +} + // FIXME: // - adding edges (need the ability to select a pathgrid and highlight) -// - save to document & signals // - repainting edges while moving void CSVRender::Cell::setupPathgrid() { @@ -434,7 +459,7 @@ void CSVRender::Cell::pathgridPointAdded(const Ogre::Vector3 &pos, bool interior pathgrid.mData.mS2 += 1; // increment the number of points - // FIXME: possible issue if this cell is deleted and undo() is actioned afterwards + // TODO: check for 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)); @@ -493,7 +518,7 @@ void CSVRender::Cell::pathgridPointRemoved(const std::string &name) << pathgridId + "_" + QString::number(index).toStdString() << std::endl; } - // FIXME: possible issue if this cell is deleted and undo() is actioned afterwards + // TODO: check for 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)); @@ -536,7 +561,7 @@ void CSVRender::Cell::pathgridPointMoved(const std::string &name, pathgrid.mPoints[index].mY = y; pathgrid.mPoints[index].mZ = newPos.z; - // FIXME: possible issue if this cell is deleted and undo() is actioned afterwards + // TODO: check for 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)); diff --git a/apps/opencs/view/render/cell.hpp b/apps/opencs/view/render/cell.hpp index cc00ee1c8..dbf680dd4 100644 --- a/apps/opencs/view/render/cell.hpp +++ b/apps/opencs/view/render/cell.hpp @@ -111,6 +111,8 @@ namespace CSVRender const Ogre::Vector3 &newPos, bool interior = false); void pathgridPointRemoved(const std::string &name); + void pathgridDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight); + private: // for drawing pathgrid points & lines diff --git a/apps/opencs/view/render/pagedworldspacewidget.cpp b/apps/opencs/view/render/pagedworldspacewidget.cpp index 130f5c409..799dd1e7f 100644 --- a/apps/opencs/view/render/pagedworldspacewidget.cpp +++ b/apps/opencs/view/render/pagedworldspacewidget.cpp @@ -330,23 +330,13 @@ void CSVRender::PagedWorldspaceWidget::referenceAdded (const QModelIndex& parent flagAsModified(); } -//void CSVRender::PagedWorldspaceWidget::pathgridAdded (const QModelIndex& parent, -// int start, int end) -//{ -// // FIXME: -//} -// -//void CSVRender::PagedWorldspaceWidget::pathgridDataChanged (const QModelIndex& topLeft, -// const QModelIndex& bottomRight) -//{ -// // FIXME: -//} -// -//void CSVRender::PagedWorldspaceWidget::pathgridAboutToBeRemoved (const QModelIndex& parent, -// int start, int end) -//{ -// // FIXME: -//} +void CSVRender::PagedWorldspaceWidget::pathgridDataChanged (const QModelIndex& topLeft, + const QModelIndex& bottomRight) +{ + for (std::map::iterator iter (mCells.begin()); + iter!=mCells.end(); ++iter) + iter->second->pathgridDataChanged (topLeft, bottomRight); +} CSVRender::Cell *CSVRender::PagedWorldspaceWidget::findCell(const std::string &cellId) { diff --git a/apps/opencs/view/render/pagedworldspacewidget.hpp b/apps/opencs/view/render/pagedworldspacewidget.hpp index 099b4db25..ea9449b2f 100644 --- a/apps/opencs/view/render/pagedworldspacewidget.hpp +++ b/apps/opencs/view/render/pagedworldspacewidget.hpp @@ -53,12 +53,6 @@ namespace CSVRender virtual void referenceAdded (const QModelIndex& index, int start, int end); - //virtual void pathgridAdded (const QModelIndex& parent, int start, int end); - - //virtual void pathgridDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight); - - //virtual void pathgridAboutToBeRemoved (const QModelIndex& parent, int start, int end); - virtual std::string getStartupInstruction(); Cell *findCell(const std::string &cellId); @@ -103,7 +97,6 @@ namespace CSVRender virtual void mouseDoubleClickEvent (QMouseEvent *event); - // FIXME: temporary only until signals from the document is implemented virtual void pathgridInserted (const std::string &referenceId, const Ogre::Vector3 &pos); virtual void pathgridMoved (const std::string &pgName, const Ogre::Vector3 &pos); virtual void pathgridAboutToBeRemoved (const std::string &pgName); @@ -121,6 +114,8 @@ namespace CSVRender virtual void cellAdded (const QModelIndex& index, int start, int end); virtual void flagAsModSlot(); + + virtual void pathgridDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight); }; } diff --git a/apps/opencs/view/render/unpagedworldspacewidget.cpp b/apps/opencs/view/render/unpagedworldspacewidget.cpp index c95a87d03..af121ec19 100644 --- a/apps/opencs/view/render/unpagedworldspacewidget.cpp +++ b/apps/opencs/view/render/unpagedworldspacewidget.cpp @@ -166,23 +166,11 @@ void CSVRender::UnpagedWorldspaceWidget::addVisibilitySelectorButtons ( tool->addButton (Element_Fog, "Fog"); } -//void CSVRender::UnpagedWorldspaceWidget::pathgridAdded (const QModelIndex& parent, -// int start, int end) -//{ -// // FIXME: -//} -// -//void CSVRender::UnpagedWorldspaceWidget::pathgridDataChanged (const QModelIndex& topLeft, -// const QModelIndex& bottomRight) -//{ -// // FIXME: -//} -// -//void CSVRender::UnpagedWorldspaceWidget::pathgridAboutToBeRemoved (const QModelIndex& parent, -// int start, int end) -//{ -// // FIXME: -//} +void CSVRender::UnpagedWorldspaceWidget::pathgridDataChanged (const QModelIndex& topLeft, + const QModelIndex& bottomRight) +{ + // FIXME: +} std::string CSVRender::UnpagedWorldspaceWidget::getStartupInstruction() { diff --git a/apps/opencs/view/render/unpagedworldspacewidget.hpp b/apps/opencs/view/render/unpagedworldspacewidget.hpp index 468c48739..4e19efbf0 100644 --- a/apps/opencs/view/render/unpagedworldspacewidget.hpp +++ b/apps/opencs/view/render/unpagedworldspacewidget.hpp @@ -58,12 +58,6 @@ namespace CSVRender virtual void referenceAdded (const QModelIndex& index, int start, int end); - //virtual void pathgridAdded (const QModelIndex& index, int start, int end); - - //virtual void pathgridDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight); - - //virtual void pathgridAboutToBeRemoved (const QModelIndex& parent, int start, int end); - virtual std::string getStartupInstruction(); protected: @@ -78,6 +72,8 @@ namespace CSVRender virtual void flagAsModSlot(); + virtual void pathgridDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight); + signals: void cellChanged(const CSMWorld::UniversalId& id); diff --git a/apps/opencs/view/render/worldspacewidget.cpp b/apps/opencs/view/render/worldspacewidget.cpp index 8418a32a6..2d690303c 100644 --- a/apps/opencs/view/render/worldspacewidget.cpp +++ b/apps/opencs/view/render/worldspacewidget.cpp @@ -56,15 +56,11 @@ CSVRender::WorldspaceWidget::WorldspaceWidget (CSMDoc::Document& document, QWidg connect (debugProfiles, SIGNAL (rowsAboutToBeRemoved (const QModelIndex&, int, int)), this, SLOT (debugProfileAboutToBeRemoved (const QModelIndex&, int, int))); - //QAbstractItemModel *pathgrids = - //document.getData().getTableModel (CSMWorld::UniversalId::Type_Pathgrid); + QAbstractItemModel *pathgrids = + document.getData().getTableModel (CSMWorld::UniversalId::Type_Pathgrid); - //connect (pathgrids, SIGNAL (rowsInserted (const QModelIndex&, int, int)), - //this, SLOT (pathgridAdded (const QModelIndex&, int, int))); - //connect (pathgrids, SIGNAL (dataChanged (const QModelIndex&, const QModelIndex&)), - //this, SLOT (pathgridDataChanged (const QModelIndex&, const QModelIndex&))); - //connect (pathgrids, SIGNAL (rowsAboutToBeRemoved (const QModelIndex&, int, int)), - //this, SLOT (pathgridAboutToBeRemoved (const QModelIndex&, int, int))); + connect (pathgrids, SIGNAL (dataChanged (const QModelIndex&, const QModelIndex&)), + this, SLOT (pathgridDataChanged (const QModelIndex&, const QModelIndex&))); mPhysics = document.getPhysics(); // create physics if one doesn't exist mPhysics->addSceneManager(getSceneManager(), this); @@ -460,17 +456,14 @@ void CSVRender::WorldspaceWidget::keyPressEvent (QKeyEvent *event) SceneWidget::keyPressEvent(event); } -// FIXME: temporary until signals from the document are implemented void CSVRender::WorldspaceWidget::pathgridAboutToBeRemoved (const std::string &pgName) { } -// FIXME: temporary until signals from the document are implemented void CSVRender::WorldspaceWidget::pathgridMoved (const std::string &pgName, const Ogre::Vector3 &newPos) { } -// FIXME: temporary until signals from the document are implemented void CSVRender::WorldspaceWidget::pathgridInserted (const std::string &name, const Ogre::Vector3 &pos) { } diff --git a/apps/opencs/view/render/worldspacewidget.hpp b/apps/opencs/view/render/worldspacewidget.hpp index efd2ee8c0..a250547b3 100644 --- a/apps/opencs/view/render/worldspacewidget.hpp +++ b/apps/opencs/view/render/worldspacewidget.hpp @@ -163,11 +163,7 @@ namespace CSVRender void debugProfileAboutToBeRemoved (const QModelIndex& parent, int start, int end); - //virtual void pathgridAdded (const QModelIndex& index, int start, int end) = 0; - - //virtual void pathgridDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight) = 0; - - //virtual void pathgridAboutToBeRemoved (const QModelIndex& parent, int start, int end) = 0; + virtual void pathgridDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight) = 0; protected slots: