From f41f08c352962a2e00ce809027f6715748597c5f Mon Sep 17 00:00:00 2001 From: gus Date: Thu, 5 Dec 2013 14:00:50 +0100 Subject: [PATCH 01/61] Wrong logic... should improve performances --- apps/openmw/mwmechanics/aicombat.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwmechanics/aicombat.cpp b/apps/openmw/mwmechanics/aicombat.cpp index 32b0063b63..3ca522dc7b 100644 --- a/apps/openmw/mwmechanics/aicombat.cpp +++ b/apps/openmw/mwmechanics/aicombat.cpp @@ -77,13 +77,14 @@ namespace MWMechanics mPathFinder.buildPath(start, dest, pathgrid, xCell, yCell, true); else { - mPathFinder2.buildPath(start, dest, pathgrid, xCell, yCell, true); - ESM::Pathgrid::Point lastPt = mPathFinder.getPath().back(); - if((mTimer2 > 0.25)&&(mPathFinder2.getPathSize() < mPathFinder.getPathSize() || - (dest.mX - lastPt.mX)*(dest.mX - lastPt.mX)+(dest.mY - lastPt.mY)*(dest.mY - lastPt.mY)+(dest.mZ - lastPt.mZ)*(dest.mZ - lastPt.mZ) > 200*200)) + if(mTimer2 > 0.25) { mTimer2 = 0; - mPathFinder = mPathFinder2; + mPathFinder2.buildPath(start, dest, pathgrid, xCell, yCell, true); + ESM::Pathgrid::Point lastPt = mPathFinder.getPath().back(); + if(mPathFinder2.getPathSize() < mPathFinder.getPathSize() || + (dest.mX - lastPt.mX)*(dest.mX - lastPt.mX)+(dest.mY - lastPt.mY)*(dest.mY - lastPt.mY)+(dest.mZ - lastPt.mZ)*(dest.mZ - lastPt.mZ) > 200*200) + mPathFinder = mPathFinder2; } } From 2d66b2c4fa7ca03a096a3be54fc6e19d6cdc8f83 Mon Sep 17 00:00:00 2001 From: gus Date: Sat, 11 Jan 2014 12:06:36 +0100 Subject: [PATCH 02/61] AiFollow. Npc get stuck often (no stuck dtection yet) --- apps/openmw/mwmechanics/aicombat.cpp | 3 +- apps/openmw/mwmechanics/aifollow.cpp | 44 ++++++++++++++++++++++++++-- apps/openmw/mwmechanics/aifollow.hpp | 7 +++++ 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwmechanics/aicombat.cpp b/apps/openmw/mwmechanics/aicombat.cpp index 3ca522dc7b..6a1ab68d86 100644 --- a/apps/openmw/mwmechanics/aicombat.cpp +++ b/apps/openmw/mwmechanics/aicombat.cpp @@ -3,7 +3,7 @@ #include "movement.hpp" #include "../mwworld/class.hpp" -#include "../mwworld/timestamp.hpp" + #include "../mwbase/world.hpp" #include "../mwbase/environment.hpp" #include "../mwbase/mechanicsmanager.hpp" @@ -87,6 +87,7 @@ namespace MWMechanics mPathFinder = mPathFinder2; } } + ESM::Pathgrid::Point lastPt = mPathFinder.getPath().back(); mPathFinder.checkPathCompleted(pos.pos[0],pos.pos[1],pos.pos[2]); diff --git a/apps/openmw/mwmechanics/aifollow.cpp b/apps/openmw/mwmechanics/aifollow.cpp index 73bf9259af..2f9a7a8430 100644 --- a/apps/openmw/mwmechanics/aifollow.cpp +++ b/apps/openmw/mwmechanics/aifollow.cpp @@ -1,12 +1,16 @@ #include "aifollow.hpp" #include +#include "../mwbase/world.hpp" +#include "../mwbase/environment.hpp" +#include "../mwworld/class.hpp" +#include "movement.hpp" MWMechanics::AiFollow::AiFollow(const std::string &actorId,float duration, float x, float y, float z) : mDuration(duration), mX(x), mY(y), mZ(z), mActorId(actorId) { } MWMechanics::AiFollow::AiFollow(const std::string &actorId,const std::string &cellId,float duration, float x, float y, float z) -: mDuration(duration), mX(x), mY(y), mZ(z), mActorId(actorId), mCellId(cellId) +: mDuration(duration), mX(x), mY(y), mZ(z), mActorId(actorId), mCellId(cellId), mTimer(0), mStuckTimer(0) { } @@ -17,8 +21,44 @@ MWMechanics::AiFollow *MWMechanics::AiFollow::clone() const bool MWMechanics::AiFollow::execute (const MWWorld::Ptr& actor,float duration) { + const MWWorld::Ptr target = MWBase::Environment::get().getWorld()->getPtr(mActorId, false); + + mTimer = mTimer + duration; + mStuckTimer = mStuckTimer + duration; + mTotalTime = mTotalTime + duration; + + if(mTotalTime > mDuration) return true; + + ESM::Pathgrid::Point dest; + dest.mX = target.getRefData().getPosition().pos[0]; + dest.mY = target.getRefData().getPosition().pos[1]; + dest.mZ = target.getRefData().getPosition().pos[2]; + + if(mTimer > 0.25) + { + ESM::Pathgrid::Point lastPos = mPathFinder.getPath().back(); + + if((dest.mX - lastPos.mX)*(dest.mX - lastPos.mX) + +(dest.mY - lastPos.mY)*(dest.mY - lastPos.mY) + +(dest.mZ - lastPos.mZ)*(dest.mZ - lastPos.mZ) + > 100*100) + mPathFinder.getPath().push_back(dest); + + mTimer = 0; + } + + ESM::Position pos = actor.getRefData().getPosition(); + float zAngle = mPathFinder.getZAngleToNext(pos.pos[0], pos.pos[1]); + MWBase::Environment::get().getWorld()->rotateObject(actor, 0, 0, zAngle, false); + + if((dest.mX - pos.pos[0])*(dest.mX - pos.pos[0])+(dest.mY - pos.pos[1])*(dest.mY - pos.pos[1])+(dest.mZ - pos.pos[2])*(dest.mZ - pos.pos[2]) + < 100*100) + MWWorld::Class::get(actor).getMovementSettings(actor).mPosition[1] = 0; + else + MWWorld::Class::get(actor).getMovementSettings(actor).mPosition[1] = 1; + std::cout << "AiFollow completed.\n"; - return true; + return false; } int MWMechanics::AiFollow::getTypeId() const diff --git a/apps/openmw/mwmechanics/aifollow.hpp b/apps/openmw/mwmechanics/aifollow.hpp index 39df024e4b..b149c55f52 100644 --- a/apps/openmw/mwmechanics/aifollow.hpp +++ b/apps/openmw/mwmechanics/aifollow.hpp @@ -3,6 +3,7 @@ #include "aipackage.hpp" #include +#include "pathfinding.hpp" namespace MWMechanics { @@ -24,6 +25,12 @@ namespace MWMechanics float mZ; std::string mActorId; std::string mCellId; + + float mTimer; + float mStuckTimer; + float mTotalTime; + + PathFinder mPathFinder; }; } #endif From ccf07f940662daf2ebbf5498293202d6f178a13d Mon Sep 17 00:00:00 2001 From: gus Date: Tue, 7 Jan 2014 21:10:57 +0100 Subject: [PATCH 03/61] Bugfix --- apps/openmw/mwmechanics/aifollow.cpp | 63 +++++++++++++++++++++---- apps/openmw/mwmechanics/aifollow.hpp | 3 ++ apps/openmw/mwmechanics/pathfinding.hpp | 5 ++ 3 files changed, 61 insertions(+), 10 deletions(-) diff --git a/apps/openmw/mwmechanics/aifollow.cpp b/apps/openmw/mwmechanics/aifollow.cpp index 2f9a7a8430..b2c3223313 100644 --- a/apps/openmw/mwmechanics/aifollow.cpp +++ b/apps/openmw/mwmechanics/aifollow.cpp @@ -6,7 +6,7 @@ #include "movement.hpp" MWMechanics::AiFollow::AiFollow(const std::string &actorId,float duration, float x, float y, float z) -: mDuration(duration), mX(x), mY(y), mZ(z), mActorId(actorId) +: mDuration(duration), mX(x), mY(y), mZ(z), mActorId(actorId), mTimer(0), mStuckTimer(0) { } MWMechanics::AiFollow::AiFollow(const std::string &actorId,const std::string &cellId,float duration, float x, float y, float z) @@ -34,22 +34,66 @@ MWMechanics::AiFollow *MWMechanics::AiFollow::clone() const dest.mY = target.getRefData().getPosition().pos[1]; dest.mZ = target.getRefData().getPosition().pos[2]; + //std::cout << dest.mX; + + ESM::Position pos = actor.getRefData().getPosition(); + if(mTimer > 0.25) { - ESM::Pathgrid::Point lastPos = mPathFinder.getPath().back(); + if(!mPathFinder.getPath().empty()) + { + ESM::Pathgrid::Point lastPos = mPathFinder.getPath().back(); - if((dest.mX - lastPos.mX)*(dest.mX - lastPos.mX) - +(dest.mY - lastPos.mY)*(dest.mY - lastPos.mY) - +(dest.mZ - lastPos.mZ)*(dest.mZ - lastPos.mZ) + if((dest.mX - lastPos.mX)*(dest.mX - lastPos.mX) + +(dest.mY - lastPos.mY)*(dest.mY - lastPos.mY) + +(dest.mZ - lastPos.mZ)*(dest.mZ - lastPos.mZ) > 100*100) - mPathFinder.getPath().push_back(dest); + mPathFinder.addPointToPath(dest); + } + else + mPathFinder.addPointToPath(dest); mTimer = 0; } - ESM::Position pos = actor.getRefData().getPosition(); - float zAngle = mPathFinder.getZAngleToNext(pos.pos[0], pos.pos[1]); - MWBase::Environment::get().getWorld()->rotateObject(actor, 0, 0, zAngle, false); + if(mStuckTimer>0.5) + { + if((mStuckPos.pos[0] - pos.pos[0])*(mStuckPos.pos[0] - pos.pos[0]) + +(mStuckPos.pos[1] - pos.pos[1])*(mStuckPos.pos[1] - pos.pos[1]) + +(mStuckPos.pos[2] - pos.pos[2])*(mStuckPos.pos[2] - pos.pos[2]) + < 100) //NPC is stuck + { + std::cout << "stck\n"; + ESM::Pathgrid::Point start; + start.mX = pos.pos[0]; + start.mY = pos.pos[1]; + start.mZ = pos.pos[2]; + + const ESM::Pathgrid *pathgrid = + MWBase::Environment::get().getWorld()->getStore().get().search(*actor.getCell()->mCell); + + float xCell = 0; + float yCell = 0; + + if (actor.getCell()->mCell->isExterior()) + { + xCell = actor.getCell()->mCell->mData.mX * ESM::Land::REAL_SIZE; + yCell = actor.getCell()->mCell->mData.mY * ESM::Land::REAL_SIZE; + } + mPathFinder.buildPath(start, dest, pathgrid, xCell, yCell, true); + } + mStuckTimer = 0; + mStuckPos = pos; + } + + if(mPathFinder.getPath().empty()) + mPathFinder.addPointToPath(dest); + + if(!mPathFinder.checkPathCompleted(pos.pos[0],pos.pos[1],pos.pos[2])) + { + float zAngle = mPathFinder.getZAngleToNext(pos.pos[0], pos.pos[1]); + MWBase::Environment::get().getWorld()->rotateObject(actor, 0, 0, zAngle, false); + } if((dest.mX - pos.pos[0])*(dest.mX - pos.pos[0])+(dest.mY - pos.pos[1])*(dest.mY - pos.pos[1])+(dest.mZ - pos.pos[2])*(dest.mZ - pos.pos[2]) < 100*100) @@ -57,7 +101,6 @@ MWMechanics::AiFollow *MWMechanics::AiFollow::clone() const else MWWorld::Class::get(actor).getMovementSettings(actor).mPosition[1] = 1; - std::cout << "AiFollow completed.\n"; return false; } diff --git a/apps/openmw/mwmechanics/aifollow.hpp b/apps/openmw/mwmechanics/aifollow.hpp index b149c55f52..135ba9aac4 100644 --- a/apps/openmw/mwmechanics/aifollow.hpp +++ b/apps/openmw/mwmechanics/aifollow.hpp @@ -4,6 +4,7 @@ #include "aipackage.hpp" #include #include "pathfinding.hpp" +#include "../../../components/esm/defs.hpp" namespace MWMechanics { @@ -30,6 +31,8 @@ namespace MWMechanics float mStuckTimer; float mTotalTime; + ESM::Position mStuckPos; + PathFinder mPathFinder; }; } diff --git a/apps/openmw/mwmechanics/pathfinding.hpp b/apps/openmw/mwmechanics/pathfinding.hpp index 916df850b5..f9c2c5cc77 100644 --- a/apps/openmw/mwmechanics/pathfinding.hpp +++ b/apps/openmw/mwmechanics/pathfinding.hpp @@ -37,6 +37,11 @@ namespace MWMechanics return mPath; } + void addPointToPath(ESM::Pathgrid::Point &point) + { + mPath.push_back(point); + } + private: std::list mPath; bool mIsPathConstructed; From 051d7141be83e13d7f53a0f9987de5bf350a6713 Mon Sep 17 00:00:00 2001 From: gus Date: Sat, 11 Jan 2014 20:32:38 +0100 Subject: [PATCH 04/61] check position to stop AIFollow --- apps/openmw/mwmechanics/aifollow.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwmechanics/aifollow.cpp b/apps/openmw/mwmechanics/aifollow.cpp index b2c3223313..e9495f859a 100644 --- a/apps/openmw/mwmechanics/aifollow.cpp +++ b/apps/openmw/mwmechanics/aifollow.cpp @@ -27,17 +27,19 @@ MWMechanics::AiFollow *MWMechanics::AiFollow::clone() const mStuckTimer = mStuckTimer + duration; mTotalTime = mTotalTime + duration; - if(mTotalTime > mDuration) return true; + ESM::Position pos = actor.getRefData().getPosition(); + + if(mTotalTime > mDuration || + (pos.pos[0]-mX)*(pos.pos[0]-mX) + + (pos.pos[1]-mY)*(pos.pos[1]-mY) + + (pos.pos[2]-mZ)*(pos.pos[2]-mZ) < 100*100) + return true; ESM::Pathgrid::Point dest; dest.mX = target.getRefData().getPosition().pos[0]; dest.mY = target.getRefData().getPosition().pos[1]; dest.mZ = target.getRefData().getPosition().pos[2]; - //std::cout << dest.mX; - - ESM::Position pos = actor.getRefData().getPosition(); - if(mTimer > 0.25) { if(!mPathFinder.getPath().empty()) @@ -63,7 +65,6 @@ MWMechanics::AiFollow *MWMechanics::AiFollow::clone() const +(mStuckPos.pos[2] - pos.pos[2])*(mStuckPos.pos[2] - pos.pos[2]) < 100) //NPC is stuck { - std::cout << "stck\n"; ESM::Pathgrid::Point start; start.mX = pos.pos[0]; start.mY = pos.pos[1]; From 7066844e52f10752ca77db00f8e1dbaaa20b0d43 Mon Sep 17 00:00:00 2001 From: gus Date: Sun, 12 Jan 2014 11:38:58 +0100 Subject: [PATCH 05/61] Follow you until a certain cell is reached --- apps/openmw/mwmechanics/aifollow.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwmechanics/aifollow.cpp b/apps/openmw/mwmechanics/aifollow.cpp index e9495f859a..6e19cc1824 100644 --- a/apps/openmw/mwmechanics/aifollow.cpp +++ b/apps/openmw/mwmechanics/aifollow.cpp @@ -6,7 +6,7 @@ #include "movement.hpp" MWMechanics::AiFollow::AiFollow(const std::string &actorId,float duration, float x, float y, float z) -: mDuration(duration), mX(x), mY(y), mZ(z), mActorId(actorId), mTimer(0), mStuckTimer(0) +: mDuration(duration), mX(x), mY(y), mZ(z), mActorId(actorId), mCellId(""), mTimer(0), mStuckTimer(0) { } MWMechanics::AiFollow::AiFollow(const std::string &actorId,const std::string &cellId,float duration, float x, float y, float z) @@ -19,7 +19,7 @@ MWMechanics::AiFollow *MWMechanics::AiFollow::clone() const return new AiFollow(*this); } - bool MWMechanics::AiFollow::execute (const MWWorld::Ptr& actor,float duration) +bool MWMechanics::AiFollow::execute (const MWWorld::Ptr& actor,float duration) { const MWWorld::Ptr target = MWBase::Environment::get().getWorld()->getPtr(mActorId, false); @@ -29,11 +29,24 @@ MWMechanics::AiFollow *MWMechanics::AiFollow::clone() const ESM::Position pos = actor.getRefData().getPosition(); - if(mTotalTime > mDuration || - (pos.pos[0]-mX)*(pos.pos[0]-mX) + + if(mTotalTime > mDuration) + return true; + + if((pos.pos[0]-mX)*(pos.pos[0]-mX) + (pos.pos[1]-mY)*(pos.pos[1]-mY) + (pos.pos[2]-mZ)*(pos.pos[2]-mZ) < 100*100) - return true; + { + if(actor.getCell()->isExterior()) + { + if(mCellId == "") + return true; + } + else + { + if(mCellId == actor.getCell()->mCell->mName) + return true; + } + } ESM::Pathgrid::Point dest; dest.mX = target.getRefData().getPosition().pos[0]; From 7e96a391da79df0fa4ea5e71e766e6d7140b6d26 Mon Sep 17 00:00:00 2001 From: gus Date: Sun, 12 Jan 2014 11:39:42 +0100 Subject: [PATCH 06/61] FollowCell duration = 0 -> infinite time --- apps/openmw/mwmechanics/aifollow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwmechanics/aifollow.cpp b/apps/openmw/mwmechanics/aifollow.cpp index 6e19cc1824..61994a8650 100644 --- a/apps/openmw/mwmechanics/aifollow.cpp +++ b/apps/openmw/mwmechanics/aifollow.cpp @@ -29,7 +29,7 @@ bool MWMechanics::AiFollow::execute (const MWWorld::Ptr& actor,float duration) ESM::Position pos = actor.getRefData().getPosition(); - if(mTotalTime > mDuration) + if(mTotalTime > mDuration && mDuration != 0) return true; if((pos.pos[0]-mX)*(pos.pos[0]-mX) + From 2446abe07633675a8cf3180b187a6bc1812abb45 Mon Sep 17 00:00:00 2001 From: gus Date: Sun, 12 Jan 2014 14:01:54 +0100 Subject: [PATCH 07/61] Allow getting current active package --- apps/openmw/mwmechanics/aisequence.cpp | 8 ++++++++ apps/openmw/mwmechanics/aisequence.hpp | 3 +++ 2 files changed, 11 insertions(+) diff --git a/apps/openmw/mwmechanics/aisequence.cpp b/apps/openmw/mwmechanics/aisequence.cpp index 139f544898..616e54bd8f 100644 --- a/apps/openmw/mwmechanics/aisequence.cpp +++ b/apps/openmw/mwmechanics/aisequence.cpp @@ -102,6 +102,14 @@ void MWMechanics::AiSequence::queue (const AiPackage& package) mPackages.push_back (package.clone()); } +MWMechanics::AiPackage* MWMechanics::AiSequence::getActivePackage() +{ + if(mPackages.empty()) + throw std::runtime_error(std::string("No AI Package!")); + else + return mPackages.front(); +} + void MWMechanics::AiSequence::fill(const ESM::AIPackageList &list) { for (std::vector::const_iterator it = list.mList.begin(); it != list.mList.end(); ++it) diff --git a/apps/openmw/mwmechanics/aisequence.hpp b/apps/openmw/mwmechanics/aisequence.hpp index 0976ef0995..d44a4975e6 100644 --- a/apps/openmw/mwmechanics/aisequence.hpp +++ b/apps/openmw/mwmechanics/aisequence.hpp @@ -52,6 +52,9 @@ namespace MWMechanics ///< Add \a package to the end of the sequence (executed after all other packages have been /// completed) + AiPackage* getActivePackage(); + ///< return the current active package. If there is no active package, throw an exeption + void fill (const ESM::AIPackageList& list); }; } From dd870e35dbd19463d7f16af7216b80be9f8d1abd Mon Sep 17 00:00:00 2001 From: gus Date: Sun, 12 Jan 2014 14:02:15 +0100 Subject: [PATCH 08/61] get all actors following a given actor --- apps/openmw/mwbase/mechanicsmanager.hpp | 4 ++++ apps/openmw/mwmechanics/actors.cpp | 19 +++++++++++++++++++ apps/openmw/mwmechanics/actors.hpp | 3 +++ .../mwmechanics/mechanicsmanagerimp.cpp | 5 +++++ .../mwmechanics/mechanicsmanagerimp.hpp | 2 ++ 5 files changed, 33 insertions(+) diff --git a/apps/openmw/mwbase/mechanicsmanager.hpp b/apps/openmw/mwbase/mechanicsmanager.hpp index 24e955cdf1..ce5c62ee4f 100644 --- a/apps/openmw/mwbase/mechanicsmanager.hpp +++ b/apps/openmw/mwbase/mechanicsmanager.hpp @@ -3,6 +3,7 @@ #include #include +#include namespace Ogre { @@ -151,6 +152,9 @@ namespace MWBase virtual void toggleAI() = 0; virtual bool isAIActive() = 0; + + ///return the list of actors which are following the given actor (ie AiFollow is active and the target is the actor) + virtual std::list getActorsFollowing(const MWWorld::Ptr& actor) = 0; }; } diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index 0a4adb6e2f..a019aeb303 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -27,6 +27,7 @@ #include "../mwbase/mechanicsmanager.hpp" #include "aicombat.hpp" +#include "aifollow.hpp" namespace { @@ -877,4 +878,22 @@ namespace MWMechanics return iter->second->isAnimPlaying(groupName); return false; } + + std::list Actors::getActorsFollowing(const MWWorld::Ptr& actor) + { + std::list list; + for(PtrControllerMap::iterator iter(mActors.begin());iter != mActors.end();iter++) + { + const MWWorld::Class &cls = MWWorld::Class::get(iter->first); + CreatureStats &stats = cls.getCreatureStats(iter->first); + + if(stats.getAiSequence().getTypeId() == 3) + { + MWMechanics::AiFollow* package = static_cast(stats.getAiSequence().getActivePackage()); + if(package->getFollowedActor() == actor.getCellRef().mRefID) + list.push_front(iter->first); + } + } + return list; + } } diff --git a/apps/openmw/mwmechanics/actors.hpp b/apps/openmw/mwmechanics/actors.hpp index 7046543e6a..c8abd35251 100644 --- a/apps/openmw/mwmechanics/actors.hpp +++ b/apps/openmw/mwmechanics/actors.hpp @@ -91,6 +91,9 @@ namespace MWMechanics void skipAnimation(const MWWorld::Ptr& ptr); bool checkAnimationPlaying(const MWWorld::Ptr& ptr, const std::string& groupName); + std::list getActorsFollowing(const MWWorld::Ptr& actor); + ///= target); } + + std::list MechanicsManager::getActorsFollowing(const MWWorld::Ptr& actor) + { + return mActors.getActorsFollowing(actor); + } } diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp index cec08fa92d..50d9289cc7 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp @@ -129,6 +129,8 @@ namespace MWMechanics virtual void toggleAI(); virtual bool isAIActive(); + + virtual std::list getActorsFollowing(const MWWorld::Ptr& actor); }; } From 1ae62665d65472507a21a2aa91e582f71547899f Mon Sep 17 00:00:00 2001 From: gus Date: Sun, 12 Jan 2014 14:02:40 +0100 Subject: [PATCH 09/61] get all actors following a given actor --- apps/openmw/mwmechanics/aifollow.cpp | 5 +++++ apps/openmw/mwmechanics/aifollow.hpp | 2 ++ 2 files changed, 7 insertions(+) diff --git a/apps/openmw/mwmechanics/aifollow.cpp b/apps/openmw/mwmechanics/aifollow.cpp index 61994a8650..399504ff1d 100644 --- a/apps/openmw/mwmechanics/aifollow.cpp +++ b/apps/openmw/mwmechanics/aifollow.cpp @@ -122,3 +122,8 @@ bool MWMechanics::AiFollow::execute (const MWWorld::Ptr& actor,float duration) { return 3; } + +std::string MWMechanics::AiFollow::getFollowedActor() +{ + return mActorId; +} diff --git a/apps/openmw/mwmechanics/aifollow.hpp b/apps/openmw/mwmechanics/aifollow.hpp index 135ba9aac4..9d77b903de 100644 --- a/apps/openmw/mwmechanics/aifollow.hpp +++ b/apps/openmw/mwmechanics/aifollow.hpp @@ -19,6 +19,8 @@ namespace MWMechanics ///< \return Package completed? virtual int getTypeId() const; + std::string getFollowedActor(); + private: float mDuration; float mX; From 0e46c40cb5812bb40dfa454db9fab4167c1a9c25 Mon Sep 17 00:00:00 2001 From: gus Date: Sun, 12 Jan 2014 14:03:11 +0100 Subject: [PATCH 10/61] Make ACtionTeleport non player specific and teleport actors following the teleporting actor --- apps/openmw/mwworld/actionteleport.cpp | 33 ++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwworld/actionteleport.cpp b/apps/openmw/mwworld/actionteleport.cpp index 773fde81e3..b4c572ba94 100644 --- a/apps/openmw/mwworld/actionteleport.cpp +++ b/apps/openmw/mwworld/actionteleport.cpp @@ -3,6 +3,7 @@ #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" +#include "../mwbase/mechanicsmanager.hpp" #include "player.hpp" namespace MWWorld @@ -16,11 +17,35 @@ namespace MWWorld void ActionTeleport::executeImp (const Ptr& actor) { MWBase::World* world = MWBase::Environment::get().getWorld(); - world->getPlayer().setTeleported(true); - if (mCellName.empty()) - world->changeToExteriorCell (mPosition); + //find any NPC that is following the actor and teleport him too + std::list followers = MWBase::Environment::get().getMechanicsManager()->getActorsFollowing(actor); + for(std::list::iterator it = followers.begin();it != followers.end();it++) + { + std::cout << "teleporting someone!" << (*it).getCellRef().mRefID; + executeImp(*it); + } + + if(actor == world->getPlayerPtr()) + { + world->getPlayer().setTeleported(true); + if (mCellName.empty()) + world->changeToExteriorCell (mPosition); + else + world->changeToInteriorCell (mCellName, mPosition); + } else - world->changeToInteriorCell (mCellName, mPosition); + { + if (mCellName.empty()) + { + int cellX; + int cellY; + world->positionToIndex(mPosition.pos[0],mPosition.pos[1],cellX,cellY); + world->moveObject(actor,*world->getExterior(cellX,cellY), + mPosition.pos[0],mPosition.pos[1],mPosition.pos[2]); + } + else + world->moveObject(actor,*world->getInterior(mCellName),mPosition.pos[0],mPosition.pos[1],mPosition.pos[2]); + } } } From 5d038423ec8936b0a84eb469c2cca93b5b78887a Mon Sep 17 00:00:00 2001 From: gus Date: Sun, 12 Jan 2014 18:42:31 +0100 Subject: [PATCH 11/61] attempt to solve Bug #1009 by not building graph every frame --- apps/openmw/mwmechanics/aicombat.cpp | 7 ++---- apps/openmw/mwmechanics/aiescort.cpp | 4 +--- apps/openmw/mwmechanics/aifollow.cpp | 7 ++---- apps/openmw/mwmechanics/aitravel.cpp | 3 +-- apps/openmw/mwmechanics/aiwander.cpp | 2 +- apps/openmw/mwmechanics/pathfinding.cpp | 29 ++++++++++++++++++++----- apps/openmw/mwmechanics/pathfinding.hpp | 19 ++++++++++++++-- 7 files changed, 48 insertions(+), 23 deletions(-) diff --git a/apps/openmw/mwmechanics/aicombat.cpp b/apps/openmw/mwmechanics/aicombat.cpp index 6a1ab68d86..19c3fa2f3a 100644 --- a/apps/openmw/mwmechanics/aicombat.cpp +++ b/apps/openmw/mwmechanics/aicombat.cpp @@ -49,8 +49,6 @@ namespace MWMechanics //MWWorld::Class::get(actor).getCreatureStats(actor).setAttackingOrSpell(true); } ESM::Position pos = actor.getRefData().getPosition(); - const ESM::Pathgrid *pathgrid = - MWBase::Environment::get().getWorld()->getStore().get().search(*actor.getCell()->mCell); float xCell = 0; float yCell = 0; @@ -74,20 +72,19 @@ namespace MWMechanics mTimer2 = mTimer2 + duration; if(!mPathFinder.isPathConstructed()) - mPathFinder.buildPath(start, dest, pathgrid, xCell, yCell, true); + mPathFinder.buildPath(start, dest, actor.getCell(), true); else { if(mTimer2 > 0.25) { mTimer2 = 0; - mPathFinder2.buildPath(start, dest, pathgrid, xCell, yCell, true); + mPathFinder2.buildPath(start, dest, actor.getCell(), true); ESM::Pathgrid::Point lastPt = mPathFinder.getPath().back(); if(mPathFinder2.getPathSize() < mPathFinder.getPathSize() || (dest.mX - lastPt.mX)*(dest.mX - lastPt.mX)+(dest.mY - lastPt.mY)*(dest.mY - lastPt.mY)+(dest.mZ - lastPt.mZ)*(dest.mZ - lastPt.mZ) > 200*200) mPathFinder = mPathFinder2; } } - ESM::Pathgrid::Point lastPt = mPathFinder.getPath().back(); mPathFinder.checkPathCompleted(pos.pos[0],pos.pos[1],pos.pos[2]); diff --git a/apps/openmw/mwmechanics/aiescort.cpp b/apps/openmw/mwmechanics/aiescort.cpp index 35f9f19932..0d44dd6fce 100644 --- a/apps/openmw/mwmechanics/aiescort.cpp +++ b/apps/openmw/mwmechanics/aiescort.cpp @@ -85,8 +85,6 @@ namespace MWMechanics MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); ESM::Position pos = actor.getRefData().getPosition(); bool cellChange = actor.getCell()->mCell->mData.mX != cellX || actor.getCell()->mCell->mData.mY != cellY; - const ESM::Pathgrid *pathgrid = - MWBase::Environment::get().getWorld()->getStore().get().search(*actor.getCell()->mCell); if(actor.getCell()->mCell->mData.mX != player.getCell()->mCell->mData.mX) { @@ -136,7 +134,7 @@ namespace MWMechanics start.mY = pos.pos[1]; start.mZ = pos.pos[2]; - mPathFinder.buildPath(start, dest, pathgrid, xCell, yCell, true); + mPathFinder.buildPath(start, dest, actor.getCell(), true); } if(mPathFinder.checkPathCompleted(pos.pos[0],pos.pos[1],pos.pos[2])) diff --git a/apps/openmw/mwmechanics/aifollow.cpp b/apps/openmw/mwmechanics/aifollow.cpp index 399504ff1d..a711ebe7cd 100644 --- a/apps/openmw/mwmechanics/aifollow.cpp +++ b/apps/openmw/mwmechanics/aifollow.cpp @@ -81,10 +81,7 @@ bool MWMechanics::AiFollow::execute (const MWWorld::Ptr& actor,float duration) ESM::Pathgrid::Point start; start.mX = pos.pos[0]; start.mY = pos.pos[1]; - start.mZ = pos.pos[2]; - - const ESM::Pathgrid *pathgrid = - MWBase::Environment::get().getWorld()->getStore().get().search(*actor.getCell()->mCell); + start.mZ = pos.pos[2]; float xCell = 0; float yCell = 0; @@ -94,7 +91,7 @@ bool MWMechanics::AiFollow::execute (const MWWorld::Ptr& actor,float duration) xCell = actor.getCell()->mCell->mData.mX * ESM::Land::REAL_SIZE; yCell = actor.getCell()->mCell->mData.mY * ESM::Land::REAL_SIZE; } - mPathFinder.buildPath(start, dest, pathgrid, xCell, yCell, true); + mPathFinder.buildPath(start, dest, actor.getCell(), true); } mStuckTimer = 0; mStuckPos = pos; diff --git a/apps/openmw/mwmechanics/aitravel.cpp b/apps/openmw/mwmechanics/aitravel.cpp index 73b38dd130..24a61310b0 100644 --- a/apps/openmw/mwmechanics/aitravel.cpp +++ b/apps/openmw/mwmechanics/aitravel.cpp @@ -61,7 +61,6 @@ namespace MWMechanics } } - const ESM::Pathgrid *pathgrid = world->getStore().get().search(*cell); bool cellChange = cell->mData.mX != cellX || cell->mData.mY != cellY; if(!mPathFinder.isPathConstructed() || cellChange) { @@ -86,7 +85,7 @@ namespace MWMechanics start.mY = pos.pos[1]; start.mZ = pos.pos[2]; - mPathFinder.buildPath(start, dest, pathgrid, xCell, yCell, true); + mPathFinder.buildPath(start, dest, actor.getCell(), true); } if(mPathFinder.checkPathCompleted(pos.pos[0], pos.pos[1], pos.pos[2])) diff --git a/apps/openmw/mwmechanics/aiwander.cpp b/apps/openmw/mwmechanics/aiwander.cpp index 7df88c076b..353121a3ec 100644 --- a/apps/openmw/mwmechanics/aiwander.cpp +++ b/apps/openmw/mwmechanics/aiwander.cpp @@ -213,7 +213,7 @@ namespace MWMechanics start.mY = pos.pos[1]; start.mZ = pos.pos[2]; - mPathFinder.buildPath(start, dest, mPathgrid, mXCell, mYCell, false); + mPathFinder.buildPath(start, dest, actor.getCell(), false); if(mPathFinder.isPathConstructed()) { diff --git a/apps/openmw/mwmechanics/pathfinding.cpp b/apps/openmw/mwmechanics/pathfinding.cpp index c8bc9b49cf..86019fe549 100644 --- a/apps/openmw/mwmechanics/pathfinding.cpp +++ b/apps/openmw/mwmechanics/pathfinding.cpp @@ -6,7 +6,6 @@ #include "OgreMath.h" #include -#include namespace { @@ -136,8 +135,8 @@ namespace namespace MWMechanics { PathFinder::PathFinder() + :mIsPathConstructed(false),mIsGraphConstructed(false) { - mIsPathConstructed = false; } void PathFinder::clearPath() @@ -147,10 +146,19 @@ namespace MWMechanics mIsPathConstructed = false; } + void PathFinder::buildPathgridGraph(const ESM::Pathgrid* pathGrid,float xCell, float yCell) + { + mGraph = buildGraph(pathGrid, xCell, yCell); + mIsGraphConstructed = true; + } + void PathFinder::buildPath(const ESM::Pathgrid::Point &startPoint, const ESM::Pathgrid::Point &endPoint, - const ESM::Pathgrid *pathGrid, float xCell, float yCell, bool allowShortcuts) + const MWWorld::CellStore* cell, bool allowShortcuts) { mPath.clear(); + if(mCell != cell) mIsGraphConstructed = false; + mCell = cell; + if(allowShortcuts) { if(MWBase::Environment::get().getWorld()->castRay(startPoint.mX, startPoint.mY, startPoint.mZ, @@ -160,13 +168,24 @@ namespace MWMechanics if(!allowShortcuts) { + const ESM::Pathgrid *pathGrid = + MWBase::Environment::get().getWorld()->getStore().get().search(*mCell->mCell); + float xCell = 0; + float yCell = 0; + + if (mCell->isExterior()) + { + xCell = mCell->mCell->mData.mX * ESM::Land::REAL_SIZE; + yCell = mCell->mCell->mData.mY * ESM::Land::REAL_SIZE; + } int startNode = getClosestPoint(pathGrid, startPoint.mX - xCell, startPoint.mY - yCell,startPoint.mZ); int endNode = getClosestPoint(pathGrid, endPoint.mX - xCell, endPoint.mY - yCell, endPoint.mZ); if(startNode != -1 && endNode != -1) { - PathGridGraph graph = buildGraph(pathGrid, xCell, yCell); - mPath = findPath(startNode, endNode, graph); + if(!mIsGraphConstructed) buildPathgridGraph(pathGrid, xCell, yCell); + + mPath = findPath(startNode, endNode, mGraph); if(!mPath.empty()) { diff --git a/apps/openmw/mwmechanics/pathfinding.hpp b/apps/openmw/mwmechanics/pathfinding.hpp index f9c2c5cc77..6870314910 100644 --- a/apps/openmw/mwmechanics/pathfinding.hpp +++ b/apps/openmw/mwmechanics/pathfinding.hpp @@ -3,6 +3,12 @@ #include #include +#include + +namespace MWWorld +{ + class CellStore; +} namespace MWMechanics { @@ -12,9 +18,11 @@ namespace MWMechanics PathFinder(); void clearPath(); + + void buildPathgridGraph(const ESM::Pathgrid* pathGrid,float xCell = 0, float yCell = 0); + void buildPath(const ESM::Pathgrid::Point &startPoint, const ESM::Pathgrid::Point &endPoint, - const ESM::Pathgrid* pathGrid, float xCell = 0, float yCell = 0, - bool allowShortcuts = true); + const MWWorld::CellStore* cell, bool allowShortcuts = true); bool checkPathCompleted(float x, float y, float z); ///< \Returns true if the last point of the path has been reached. @@ -45,6 +53,13 @@ namespace MWMechanics private: std::list mPath; bool mIsPathConstructed; + + typedef boost::adjacency_list< boost::vecS, boost::vecS, boost::undirectedS, + boost::property, boost::property > + PathGridGraph; + PathGridGraph mGraph; + bool mIsGraphConstructed; + const MWWorld::CellStore* mCell; }; } From 5d4e148063c6e5480d571355872d5fb410f48074 Mon Sep 17 00:00:00 2001 From: gus Date: Sun, 12 Jan 2014 22:47:22 +0100 Subject: [PATCH 12/61] some clean up --- apps/openmw/mwmechanics/aicombat.cpp | 9 --------- apps/openmw/mwmechanics/aiescort.cpp | 21 +++++++-------------- apps/openmw/mwmechanics/aiescort.hpp | 4 ++-- apps/openmw/mwmechanics/aifollow.cpp | 10 +--------- apps/openmw/mwmechanics/pathfinding.cpp | 2 +- 5 files changed, 11 insertions(+), 35 deletions(-) diff --git a/apps/openmw/mwmechanics/aicombat.cpp b/apps/openmw/mwmechanics/aicombat.cpp index 19c3fa2f3a..b9dc2f7db0 100644 --- a/apps/openmw/mwmechanics/aicombat.cpp +++ b/apps/openmw/mwmechanics/aicombat.cpp @@ -50,15 +50,6 @@ namespace MWMechanics } ESM::Position pos = actor.getRefData().getPosition(); - float xCell = 0; - float yCell = 0; - - if (actor.getCell()->mCell->isExterior()) - { - xCell = actor.getCell()->mCell->mData.mX * ESM::Land::REAL_SIZE; - yCell = actor.getCell()->mCell->mData.mY * ESM::Land::REAL_SIZE; - } - ESM::Pathgrid::Point dest; dest.mX = target.getRefData().getPosition().pos[0]; dest.mY = target.getRefData().getPosition().pos[1]; diff --git a/apps/openmw/mwmechanics/aiescort.cpp b/apps/openmw/mwmechanics/aiescort.cpp index 0d44dd6fce..f31d861408 100644 --- a/apps/openmw/mwmechanics/aiescort.cpp +++ b/apps/openmw/mwmechanics/aiescort.cpp @@ -28,8 +28,8 @@ namespace MWMechanics { AiEscort::AiEscort(const std::string &actorId, int duration, float x, float y, float z) : mActorId(actorId), mX(x), mY(y), mZ(z), mDuration(duration) - , cellX(std::numeric_limits::max()) - , cellY(std::numeric_limits::max()) + , mCellX(std::numeric_limits::max()) + , mCellY(std::numeric_limits::max()) { mMaxDist = 470; @@ -47,8 +47,8 @@ namespace MWMechanics AiEscort::AiEscort(const std::string &actorId, const std::string &cellId,int duration, float x, float y, float z) : mActorId(actorId), mCellId(cellId), mX(x), mY(y), mZ(z), mDuration(duration) - , cellX(std::numeric_limits::max()) - , cellY(std::numeric_limits::max()) + , mCellX(std::numeric_limits::max()) + , mCellY(std::numeric_limits::max()) { mMaxDist = 470; @@ -84,7 +84,7 @@ namespace MWMechanics MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); ESM::Position pos = actor.getRefData().getPosition(); - bool cellChange = actor.getCell()->mCell->mData.mX != cellX || actor.getCell()->mCell->mData.mY != cellY; + bool cellChange = actor.getCell()->mCell->mData.mX != mCellX || actor.getCell()->mCell->mData.mY != mCellY; if(actor.getCell()->mCell->mData.mX != player.getCell()->mCell->mData.mX) { @@ -114,15 +114,8 @@ namespace MWMechanics if(!mPathFinder.isPathConstructed() || cellChange) { - cellX = actor.getCell()->mCell->mData.mX; - cellY = actor.getCell()->mCell->mData.mY; - float xCell = 0; - float yCell = 0; - if (actor.getCell()->mCell->isExterior()) - { - xCell = actor.getCell()->mCell->mData.mX * ESM::Land::REAL_SIZE; - yCell = actor.getCell()->mCell->mData.mY * ESM::Land::REAL_SIZE; - } + mCellX = actor.getCell()->mCell->mData.mX; + mCellY = actor.getCell()->mCell->mData.mY; ESM::Pathgrid::Point dest; dest.mX = mX; diff --git a/apps/openmw/mwmechanics/aiescort.hpp b/apps/openmw/mwmechanics/aiescort.hpp index f3f6d2bd9b..53b57c0580 100644 --- a/apps/openmw/mwmechanics/aiescort.hpp +++ b/apps/openmw/mwmechanics/aiescort.hpp @@ -34,8 +34,8 @@ namespace MWMechanics unsigned int mDuration; PathFinder mPathFinder; - int cellX; - int cellY; + int mCellX; + int mCellY; }; } #endif diff --git a/apps/openmw/mwmechanics/aifollow.cpp b/apps/openmw/mwmechanics/aifollow.cpp index a711ebe7cd..898f91e7c5 100644 --- a/apps/openmw/mwmechanics/aifollow.cpp +++ b/apps/openmw/mwmechanics/aifollow.cpp @@ -82,15 +82,7 @@ bool MWMechanics::AiFollow::execute (const MWWorld::Ptr& actor,float duration) start.mX = pos.pos[0]; start.mY = pos.pos[1]; start.mZ = pos.pos[2]; - - float xCell = 0; - float yCell = 0; - - if (actor.getCell()->mCell->isExterior()) - { - xCell = actor.getCell()->mCell->mData.mX * ESM::Land::REAL_SIZE; - yCell = actor.getCell()->mCell->mData.mY * ESM::Land::REAL_SIZE; - } + mPathFinder.buildPath(start, dest, actor.getCell(), true); } mStuckTimer = 0; diff --git a/apps/openmw/mwmechanics/pathfinding.cpp b/apps/openmw/mwmechanics/pathfinding.cpp index 86019fe549..f8908fbd95 100644 --- a/apps/openmw/mwmechanics/pathfinding.cpp +++ b/apps/openmw/mwmechanics/pathfinding.cpp @@ -106,7 +106,7 @@ namespace return graph; } - std::list findPath(PointID start, PointID end, PathGridGraph graph) + std::list findPath(PointID start, PointID end,const PathGridGraph& graph) { std::vector p(boost::num_vertices(graph)); std::vector d(boost::num_vertices(graph)); From 6397d9d40e4716f1e93886c6ad9e55fea92191c2 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Tue, 14 Jan 2014 13:12:15 +0100 Subject: [PATCH 13/61] Added mCloneAction member --- apps/opencs/view/world/table.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index 71bdb9000e..9bc5ef038c 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -199,6 +199,9 @@ CSVWorld::Table::Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, Q mCreateAction = new QAction (tr ("Add Record"), this); connect (mCreateAction, SIGNAL (triggered()), this, SIGNAL (createRequest())); addAction (mCreateAction); + + mCloneAction = new QAction(tr("Clone Record"), this); + addAction(mCloneAction); } mRevertAction = new QAction (tr ("Revert Record"), this); From 344cae8f993d0ae4c52552fafd832f26090cd6bc Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Tue, 14 Jan 2014 15:44:04 +0100 Subject: [PATCH 14/61] added new entry to the context menu --- apps/opencs/view/world/table.cpp | 20 ++++++++++++++++++-- apps/opencs/view/world/table.hpp | 4 ++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index 9bc5ef038c..31a7d8b588 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -28,7 +28,11 @@ void CSVWorld::Table::contextMenuEvent (QContextMenuEvent *event) if (!mEditLock) { if (selectedRows.size()==1) + { menu.addAction (mEditAction); + if (mCreateAction) + menu.addAction(mCloneAction); + } if (mCreateAction) menu.addAction (mCreateAction); @@ -155,7 +159,7 @@ std::vector CSVWorld::Table::listDeletableSelectedIds() const CSVWorld::Table::Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, QUndoStack& undoStack, bool createAndDelete, bool sorting) - : mUndoStack (undoStack), mCreateAction (0), mEditLock (false), mRecordStatusDisplay (0) + : mUndoStack (undoStack), mCreateAction (0), mCloneAction(0), mEditLock (false), mRecordStatusDisplay (0) { mModel = &dynamic_cast (*data.getTableModel (id)); @@ -200,7 +204,8 @@ CSVWorld::Table::Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, Q connect (mCreateAction, SIGNAL (triggered()), this, SIGNAL (createRequest())); addAction (mCreateAction); - mCloneAction = new QAction(tr("Clone Record"), this); + mCloneAction = new QAction (tr ("Clone Record"), this); + connect(mCloneAction, SIGNAL (triggered()), this, SLOT (cloneRecord())); addAction(mCloneAction); } @@ -298,6 +303,17 @@ void CSVWorld::Table::editRecord() } } +void CSVWorld::Table::cloneRecord() +{ + if (!mEditLock) + { + QModelIndexList selectedRows = selectionModel()->selectedRows(); + + if (selectedRows.size()==1) + emit cloneRequest (selectedRows.begin()->row()); + } +} + void CSVWorld::Table::moveUpRecord() { QModelIndexList selectedRows = selectionModel()->selectedRows(); diff --git a/apps/opencs/view/world/table.hpp b/apps/opencs/view/world/table.hpp index 889e2847ac..f4a5d3c9e9 100644 --- a/apps/opencs/view/world/table.hpp +++ b/apps/opencs/view/world/table.hpp @@ -32,6 +32,7 @@ namespace CSVWorld QUndoStack& mUndoStack; QAction *mEditAction; QAction *mCreateAction; + QAction *mCloneAction; QAction *mRevertAction; QAction *mDeleteAction; QAction *mMoveUpAction; @@ -73,6 +74,7 @@ namespace CSVWorld /// \param modified Number of added and modified records void createRequest(); + void cloneRequest(int row); private slots: @@ -82,6 +84,8 @@ namespace CSVWorld void editRecord(); + void cloneRecord(); + void moveUpRecord(); void moveDownRecord(); From b3e45c55bcfc45d4fe4ee4f9b10d989c32b15a72 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Sun, 19 Jan 2014 11:44:47 +0100 Subject: [PATCH 15/61] progressing with the cloning --- apps/opencs/view/world/creator.hpp | 3 +++ apps/opencs/view/world/genericcreator.cpp | 32 +++++++++++++++++------ apps/opencs/view/world/genericcreator.hpp | 6 +++++ apps/opencs/view/world/tablebottombox.cpp | 11 +++++++- apps/opencs/view/world/tablebottombox.hpp | 2 ++ apps/opencs/view/world/tablesubview.cpp | 15 +++++++++-- apps/opencs/view/world/tablesubview.hpp | 4 +++ 7 files changed, 62 insertions(+), 11 deletions(-) diff --git a/apps/opencs/view/world/creator.hpp b/apps/opencs/view/world/creator.hpp index df9b116eed..58a5e21ad2 100644 --- a/apps/opencs/view/world/creator.hpp +++ b/apps/opencs/view/world/creator.hpp @@ -2,6 +2,7 @@ #define CSV_WORLD_CREATOR_H #include +#include "../../model/world/universalid.hpp" class QUndoStack; @@ -23,6 +24,8 @@ namespace CSVWorld virtual ~Creator(); virtual void reset() = 0; + + virtual void cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type) = 0; virtual void setEditLock (bool locked) = 0; diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index ba2b3665a9..b89c2dccfb 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -2,6 +2,7 @@ #include "genericcreator.hpp" #include +#include #include #include @@ -58,7 +59,7 @@ const CSMWorld::UniversalId& CSVWorld::GenericCreator::getCollectionId() const CSVWorld::GenericCreator::GenericCreator (CSMWorld::Data& data, QUndoStack& undoStack, const CSMWorld::UniversalId& id, bool relaxedIdRules) -: mData (data), mUndoStack (undoStack), mListId (id), mLocked (false) +: mData (data), mUndoStack (undoStack), mListId (id), mLocked (false), mCloneMode(false), mClonedType(CSMWorld::UniversalId::Type_None) { mLayout = new QHBoxLayout; mLayout->setContentsMargins (0, 0, 0, 0); @@ -89,6 +90,7 @@ void CSVWorld::GenericCreator::setEditLock (bool locked) void CSVWorld::GenericCreator::reset() { + mCloneMode = false; mId->setText (""); update(); } @@ -120,16 +122,30 @@ void CSVWorld::GenericCreator::create() { if (!mLocked) { - std::string id = getId(); + if (mCloneMode) + { + std::string id = getId(); + } else { + std::string id = getId(); - std::auto_ptr command (new CSMWorld::CreateCommand ( + std::auto_ptr command (new CSMWorld::CreateCommand ( dynamic_cast (*mData.getTableModel (mListId)), id)); - configureCreateCommand (*command); + configureCreateCommand (*command); - mUndoStack.push (command.release()); + mUndoStack.push (command.release()); - emit done(); - emit requestFocus (id); + emit done(); + emit requestFocus (id); + } } -} \ No newline at end of file +} + +void CSVWorld::GenericCreator::cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type) +{ + mCloneMode = true; + mClonedId = originid; + mClonedType = type; + + mId->setText(QString::fromStdString(mClonedId)); +} diff --git a/apps/opencs/view/world/genericcreator.hpp b/apps/opencs/view/world/genericcreator.hpp index 8dd2ca911c..a1acb2e792 100644 --- a/apps/opencs/view/world/genericcreator.hpp +++ b/apps/opencs/view/world/genericcreator.hpp @@ -1,6 +1,7 @@ #ifndef CSV_WORLD_GENERICCREATOR_H #define CSV_WORLD_GENERICCREATOR_H +class QString; class QPushButton; class QLineEdit; class QHBoxLayout; @@ -28,6 +29,9 @@ namespace CSVWorld std::string mErrors; QHBoxLayout *mLayout; bool mLocked; + bool mCloneMode; + std::string mClonedId; + CSMWorld::UniversalId::Type mClonedType; protected: @@ -57,6 +61,8 @@ namespace CSVWorld virtual void reset(); + virtual void cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type); + virtual std::string getErrors() const; ///< Return formatted error descriptions for the current state of the creator. if an empty /// string is returned, there is no error. diff --git a/apps/opencs/view/world/tablebottombox.cpp b/apps/opencs/view/world/tablebottombox.cpp index 3edf9af317..b89f5180bf 100644 --- a/apps/opencs/view/world/tablebottombox.cpp +++ b/apps/opencs/view/world/tablebottombox.cpp @@ -156,4 +156,13 @@ void CSVWorld::TableBottomBox::createRequest() mLayout->setCurrentWidget (mCreator); setVisible (true); mCreating = true; -} \ No newline at end of file +} + +void CSVWorld::TableBottomBox::cloneRequest(const std::string& id, const CSMWorld::UniversalId::Type type) +{ + mCreator->reset(); + mCreator->cloneMode(id, type); + mLayout->setCurrentWidget(mCreator); + setVisible (true); + mCreating = true; +} diff --git a/apps/opencs/view/world/tablebottombox.hpp b/apps/opencs/view/world/tablebottombox.hpp index a5ae5e0bd9..58a6a5a2f3 100644 --- a/apps/opencs/view/world/tablebottombox.hpp +++ b/apps/opencs/view/world/tablebottombox.hpp @@ -2,6 +2,7 @@ #define CSV_WORLD_BOTTOMBOX_H #include +#include class QLabel; class QStackedLayout; @@ -76,6 +77,7 @@ namespace CSVWorld /// \param modified Number of added and modified records void createRequest(); + void cloneRequest(const std::string& id, const CSMWorld::UniversalId::Type type); }; } diff --git a/apps/opencs/view/world/tablesubview.cpp b/apps/opencs/view/world/tablesubview.cpp index 55ded09de2..36200dbbcb 100644 --- a/apps/opencs/view/world/tablesubview.cpp +++ b/apps/opencs/view/world/tablesubview.cpp @@ -46,8 +46,13 @@ CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMDoc::D mTable->selectionSizeUpdate(); if (mBottom->canCreateAndDelete()) + { connect (mTable, SIGNAL (createRequest()), mBottom, SLOT (createRequest())); - + + connect (mTable, SIGNAL (cloneRequest(int)), this, SLOT(cloneRequest(int))); + connect (this, SIGNAL(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type)), + mBottom, SLOT(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type))); + } connect (mBottom, SIGNAL (requestFocus (const std::string&)), mTable, SLOT (requestFocus (const std::string&))); @@ -75,4 +80,10 @@ void CSVWorld::TableSubView::updateEditorSetting(const QString &settingName, con void CSVWorld::TableSubView::setStatusBar (bool show) { mBottom->setStatusBar (show); -} \ No newline at end of file +} + +void CSVWorld::TableSubView::cloneRequest(int row) +{ + const CSMWorld::UniversalId& toClone(mTable->getUniversalId(row)); + emit cloneRequest(toClone.getId(), toClone.getType()); +} diff --git a/apps/opencs/view/world/tablesubview.hpp b/apps/opencs/view/world/tablesubview.hpp index 56a441a4d5..5b19110b6b 100644 --- a/apps/opencs/view/world/tablesubview.hpp +++ b/apps/opencs/view/world/tablesubview.hpp @@ -33,10 +33,14 @@ namespace CSVWorld virtual void updateEditorSetting (const QString& key, const QString& value); virtual void setStatusBar (bool show); + + signals: + void cloneRequest(const std::string& id, const CSMWorld::UniversalId::Type type); private slots: void editRequest (int row); + void cloneRequest (int row); }; } From 0ea2bb7c4cc835f969fdfe92bba153fd9f3bebdc Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Sun, 19 Jan 2014 16:49:39 +0100 Subject: [PATCH 16/61] Working on commands --- apps/opencs/model/world/commands.cpp | 21 +++++++++++++++++++++ apps/opencs/model/world/commands.hpp | 20 ++++++++++++++++++++ apps/opencs/model/world/idtable.cpp | 8 ++++++++ apps/opencs/model/world/idtable.hpp | 2 ++ apps/opencs/view/world/genericcreator.cpp | 2 ++ 5 files changed, 53 insertions(+) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 21feb14be6..281afb15ff 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -25,6 +25,27 @@ void CSMWorld::ModifyCommand::undo() mModel.setData (mIndex, mOld); } +CSMWorld::CloneCommand::CloneCommand (CSMWorld::IdTable& model, + const std::string& idOrigin, + const std::string& IdDestination, + CSMWorld::UniversalId::Type type, + QUndoCommand* parent) : + QUndoCommand(parent), + mModel(model), + mIdOrigin(idOrigin), + mIdDestination(IdDestination), + mType(type) +{ + setText (("Clone record " + idOrigin + " to the " + IdDestination).c_str()); +} + + +void CSMWorld::CloneCommand::redo() +{ + mModel.cloneRecord(mIdOrigin, mIdDestination, mType); +} + + CSMWorld::CreateCommand::CreateCommand (IdTable& model, const std::string& id, QUndoCommand *parent) : QUndoCommand (parent), mModel (model), mId (id), mType (UniversalId::Type_None) { diff --git a/apps/opencs/model/world/commands.hpp b/apps/opencs/model/world/commands.hpp index f0480a369d..1af4bd919f 100644 --- a/apps/opencs/model/world/commands.hpp +++ b/apps/opencs/model/world/commands.hpp @@ -39,6 +39,26 @@ namespace CSMWorld virtual void undo(); }; + class CloneCommand : public QUndoCommand + { + IdTable& mModel; + std::string mIdOrigin; + std::string mIdDestination; + UniversalId::Type mType; + std::map mValues; + + public: + + CloneCommand (IdTable& model, const std::string& idOrigin, + const std::string& IdDestination, + UniversalId::Type type, + QUndoCommand* parent = 0); + + virtual void redo(); + +// virtual void undo(); + }; + class CreateCommand : public QUndoCommand { IdTable& mModel; diff --git a/apps/opencs/model/world/idtable.cpp b/apps/opencs/model/world/idtable.cpp index 809d64339c..b90bf1a9bb 100644 --- a/apps/opencs/model/world/idtable.cpp +++ b/apps/opencs/model/world/idtable.cpp @@ -124,6 +124,14 @@ void CSMWorld::IdTable::addRecord (const std::string& id, UniversalId::Type type endInsertRows(); } +void CSMWorld::IdTable::cloneRecord(const std::string& origin, + const std::string& destination, + CSMWorld::UniversalId::Type type) +{ + +} + + QModelIndex CSMWorld::IdTable::getModelIndex (const std::string& id, int column) const { return index (mIdCollection->getIndex (id), column); diff --git a/apps/opencs/model/world/idtable.hpp b/apps/opencs/model/world/idtable.hpp index e4ae58fd04..dfbc04134f 100644 --- a/apps/opencs/model/world/idtable.hpp +++ b/apps/opencs/model/world/idtable.hpp @@ -63,6 +63,8 @@ namespace CSMWorld void addRecord (const std::string& id, UniversalId::Type type = UniversalId::Type_None); ///< \param type Will be ignored, unless the collection supports multiple record types + void cloneRecord(const std::string& origin, const std::string& destination, UniversalId::Type type = UniversalId::Type_None); + QModelIndex getModelIndex (const std::string& id, int column) const; void setRecord (const std::string& id, const RecordBase& record); diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index b89c2dccfb..f21a62d979 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -125,6 +125,8 @@ void CSVWorld::GenericCreator::create() if (mCloneMode) { std::string id = getId(); + std::auto_ptr command (new CSMWorld::CloneCommand ( + dynamic_cast (*mData.getTableModel(mListId)), mClonedId, id, mClonedType)); } else { std::string id = getId(); From 33620a001b802ed8c8ae8c61db9afcc4619ad20b Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 20 Jan 2014 13:59:00 +0100 Subject: [PATCH 17/61] Cloning works for single record type tables. Well, kinda. --- apps/opencs/model/world/collection.hpp | 27 ++++- apps/opencs/model/world/collectionbase.hpp | 5 + apps/opencs/model/world/commands.cpp | 126 +++++++++++--------- apps/opencs/model/world/commands.hpp | 6 +- apps/opencs/model/world/idtable.cpp | 5 +- apps/opencs/model/world/idtable.hpp | 5 +- apps/opencs/model/world/refidcollection.cpp | 8 ++ apps/opencs/model/world/refidcollection.hpp | 5 + apps/opencs/view/world/creator.hpp | 2 +- apps/opencs/view/world/genericcreator.cpp | 15 ++- apps/opencs/view/world/genericcreator.hpp | 6 +- apps/opencs/view/world/tablebottombox.cpp | 6 +- apps/opencs/view/world/tablebottombox.hpp | 2 +- apps/opencs/view/world/tablesubview.cpp | 6 +- apps/opencs/view/world/tablesubview.hpp | 4 +- 15 files changed, 150 insertions(+), 78 deletions(-) diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index df144ba7bf..0b9b44fa9a 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -97,7 +97,12 @@ namespace CSMWorld virtual void appendBlankRecord (const std::string& id, UniversalId::Type type = UniversalId::Type_None); ///< \param type Will be ignored, unless the collection supports multiple record types - + + virtual void cloneRecord(const std::string& origin, + const std::string& destination, + const UniversalId::Type type, + const UniversalId::ArgumentType argumentType); + virtual int searchId (const std::string& id) const; ////< Search record with \a id. /// \return index of record (if found) or -1 (not found) @@ -193,6 +198,26 @@ namespace CSMWorld return true; } + template + void Collection::cloneRecord(const std::string& origin, + const std::string& destination, + const UniversalId::Type type, + const UniversalId::ArgumentType argumentType) + { + Record copy = getRecord(origin); + if (copy.isDeleted()) + { + return; + } + + if (argumentType == UniversalId::ArgumentType_Id) + { + copy.get().mId = Misc::StringUtils::lowerCase(destination); + } + + insertRecord(copy, getAppendIndex(destination, type)); + } + template Collection::Collection() {} diff --git a/apps/opencs/model/world/collectionbase.hpp b/apps/opencs/model/world/collectionbase.hpp index ab7a9ebecb..d32847490b 100644 --- a/apps/opencs/model/world/collectionbase.hpp +++ b/apps/opencs/model/world/collectionbase.hpp @@ -74,6 +74,11 @@ namespace CSMWorld UniversalId::Type type = UniversalId::Type_None) = 0; ///< If the record type does not match, an exception is thrown. + virtual void cloneRecord(const std::string& origin, + const std::string& destination, + const UniversalId::Type type, + const UniversalId::ArgumentType argumentType) = 0; + virtual const RecordBase& getRecord (const std::string& id) const = 0; virtual const RecordBase& getRecord (int index) const = 0; diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 281afb15ff..75b88766aa 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -6,81 +6,88 @@ #include "idtable.hpp" #include "idtable.hpp" -CSMWorld::ModifyCommand::ModifyCommand (QAbstractItemModel& model, const QModelIndex& index, - const QVariant& new_, QUndoCommand *parent) -: QUndoCommand (parent), mModel (model), mIndex (index), mNew (new_) +CSMWorld::ModifyCommand::ModifyCommand(QAbstractItemModel& model, const QModelIndex& index, + const QVariant& new_, QUndoCommand* parent) + : QUndoCommand(parent), mModel(model), mIndex(index), mNew(new_) { - mOld = mModel.data (mIndex, Qt::EditRole); + mOld = mModel.data(mIndex, Qt::EditRole); - setText ("Modify " + mModel.headerData (mIndex.column(), Qt::Horizontal, Qt::DisplayRole).toString()); + setText("Modify " + mModel.headerData(mIndex.column(), Qt::Horizontal, Qt::DisplayRole).toString()); } void CSMWorld::ModifyCommand::redo() { - mModel.setData (mIndex, mNew); + mModel.setData(mIndex, mNew); } void CSMWorld::ModifyCommand::undo() { - mModel.setData (mIndex, mOld); + mModel.setData(mIndex, mOld); } -CSMWorld::CloneCommand::CloneCommand (CSMWorld::IdTable& model, - const std::string& idOrigin, - const std::string& IdDestination, - CSMWorld::UniversalId::Type type, - QUndoCommand* parent) : - QUndoCommand(parent), - mModel(model), - mIdOrigin(idOrigin), +CSMWorld::CloneCommand::CloneCommand(CSMWorld::IdTable& model, + const std::string& idOrigin, + const std::string& IdDestination, + const CSMWorld::UniversalId::Type type, + const CSMWorld::UniversalId::ArgumentType argumentType, + QUndoCommand* parent) : + QUndoCommand(parent), + mModel(model), + mIdOrigin(idOrigin), mIdDestination(IdDestination), + mArgumentType(argumentType), mType(type) { - setText (("Clone record " + idOrigin + " to the " + IdDestination).c_str()); + setText(("Clone record " + idOrigin + " to the " + IdDestination).c_str()); } void CSMWorld::CloneCommand::redo() { - mModel.cloneRecord(mIdOrigin, mIdDestination, mType); + mModel.cloneRecord(mIdOrigin, mIdDestination, mArgumentType, mType); } - -CSMWorld::CreateCommand::CreateCommand (IdTable& model, const std::string& id, QUndoCommand *parent) -: QUndoCommand (parent), mModel (model), mId (id), mType (UniversalId::Type_None) +void CSMWorld::CloneCommand::undo() { - setText (("Create record " + id).c_str()); + mModel.removeRow(mModel.getModelIndex(mIdDestination, 0).row()); } -void CSMWorld::CreateCommand::addValue (int column, const QVariant& value) + +CSMWorld::CreateCommand::CreateCommand(IdTable& model, const std::string& id, QUndoCommand* parent) + : QUndoCommand(parent), mModel(model), mId(id), mType(UniversalId::Type_None) +{ + setText(("Create record " + id).c_str()); +} + +void CSMWorld::CreateCommand::addValue(int column, const QVariant& value) { mValues[column] = value; } -void CSMWorld::CreateCommand::setType (UniversalId::Type type) +void CSMWorld::CreateCommand::setType(UniversalId::Type type) { mType = type; } void CSMWorld::CreateCommand::redo() { - mModel.addRecord (mId, mType); + mModel.addRecord(mId, mType); - for (std::map::const_iterator iter (mValues.begin()); iter!=mValues.end(); ++iter) - mModel.setData (mModel.getModelIndex (mId, iter->first), iter->second); + for (std::map::const_iterator iter(mValues.begin()); iter != mValues.end(); ++iter) + mModel.setData(mModel.getModelIndex(mId, iter->first), iter->second); } void CSMWorld::CreateCommand::undo() { - mModel.removeRow (mModel.getModelIndex (mId, 0).row()); + mModel.removeRow(mModel.getModelIndex(mId, 0).row()); } -CSMWorld::RevertCommand::RevertCommand (IdTable& model, const std::string& id, QUndoCommand *parent) -: QUndoCommand (parent), mModel (model), mId (id), mOld (0) +CSMWorld::RevertCommand::RevertCommand(IdTable& model, const std::string& id, QUndoCommand* parent) + : QUndoCommand(parent), mModel(model), mId(id), mOld(0) { - setText (("Revert record " + id).c_str()); + setText(("Revert record " + id).c_str()); - mOld = model.getRecord (id).clone(); + mOld = model.getRecord(id).clone(); } CSMWorld::RevertCommand::~RevertCommand() @@ -90,32 +97,32 @@ CSMWorld::RevertCommand::~RevertCommand() void CSMWorld::RevertCommand::redo() { - int column = mModel.findColumnIndex (Columns::ColumnId_Modification); + int column = mModel.findColumnIndex(Columns::ColumnId_Modification); - QModelIndex index = mModel.getModelIndex (mId, column); - RecordBase::State state = static_cast (mModel.data (index).toInt()); + QModelIndex index = mModel.getModelIndex(mId, column); + RecordBase::State state = static_cast(mModel.data(index).toInt()); - if (state==RecordBase::State_ModifiedOnly) + if (state == RecordBase::State_ModifiedOnly) { - mModel.removeRows (index.row(), 1); + mModel.removeRows(index.row(), 1); } else { - mModel.setData (index, static_cast (RecordBase::State_BaseOnly)); + mModel.setData(index, static_cast(RecordBase::State_BaseOnly)); } } void CSMWorld::RevertCommand::undo() { - mModel.setRecord (mId, *mOld); + mModel.setRecord(mId, *mOld); } -CSMWorld::DeleteCommand::DeleteCommand (IdTable& model, const std::string& id, QUndoCommand *parent) -: QUndoCommand (parent), mModel (model), mId (id), mOld (0) +CSMWorld::DeleteCommand::DeleteCommand(IdTable& model, const std::string& id, QUndoCommand* parent) + : QUndoCommand(parent), mModel(model), mId(id), mOld(0) { - setText (("Delete record " + id).c_str()); + setText(("Delete record " + id).c_str()); - mOld = model.getRecord (id).clone(); + mOld = model.getRecord(id).clone(); } CSMWorld::DeleteCommand::~DeleteCommand() @@ -125,44 +132,45 @@ CSMWorld::DeleteCommand::~DeleteCommand() void CSMWorld::DeleteCommand::redo() { - int column = mModel.findColumnIndex (Columns::ColumnId_Modification); + int column = mModel.findColumnIndex(Columns::ColumnId_Modification); - QModelIndex index = mModel.getModelIndex (mId, column); - RecordBase::State state = static_cast (mModel.data (index).toInt()); + QModelIndex index = mModel.getModelIndex(mId, column); + RecordBase::State state = static_cast(mModel.data(index).toInt()); - if (state==RecordBase::State_ModifiedOnly) + if (state == RecordBase::State_ModifiedOnly) { - mModel.removeRows (index.row(), 1); + mModel.removeRows(index.row(), 1); } else { - mModel.setData (index, static_cast (RecordBase::State_Deleted)); + mModel.setData(index, static_cast(RecordBase::State_Deleted)); } } void CSMWorld::DeleteCommand::undo() { - mModel.setRecord (mId, *mOld); + mModel.setRecord(mId, *mOld); } -CSMWorld::ReorderRowsCommand::ReorderRowsCommand (IdTable& model, int baseIndex, - const std::vector& newOrder) -: mModel (model), mBaseIndex (baseIndex), mNewOrder (newOrder) +CSMWorld::ReorderRowsCommand::ReorderRowsCommand(IdTable& model, int baseIndex, + const std::vector& newOrder) + : mModel(model), mBaseIndex(baseIndex), mNewOrder(newOrder) {} void CSMWorld::ReorderRowsCommand::redo() { - mModel.reorderRows (mBaseIndex, mNewOrder); + mModel.reorderRows(mBaseIndex, mNewOrder); } void CSMWorld::ReorderRowsCommand::undo() { - int size = static_cast (mNewOrder.size()); - std::vector reverse (size); + int size = static_cast(mNewOrder.size()); + std::vector reverse(size); - for (int i=0; i mValues; public: CloneCommand (IdTable& model, const std::string& idOrigin, const std::string& IdDestination, - UniversalId::Type type, + const UniversalId::Type type, + const UniversalId::ArgumentType argumentType, QUndoCommand* parent = 0); virtual void redo(); -// virtual void undo(); + virtual void undo(); }; class CreateCommand : public QUndoCommand diff --git a/apps/opencs/model/world/idtable.cpp b/apps/opencs/model/world/idtable.cpp index b90bf1a9bb..daa6bc51b3 100644 --- a/apps/opencs/model/world/idtable.cpp +++ b/apps/opencs/model/world/idtable.cpp @@ -124,11 +124,12 @@ void CSMWorld::IdTable::addRecord (const std::string& id, UniversalId::Type type endInsertRows(); } -void CSMWorld::IdTable::cloneRecord(const std::string& origin, +void CSMWorld::IdTable::cloneRecord(const std::string& origin, const std::string& destination, + CSMWorld::UniversalId::ArgumentType argumentType, CSMWorld::UniversalId::Type type) { - + mIdCollection->cloneRecord(origin, destination, type, argumentType); } diff --git a/apps/opencs/model/world/idtable.hpp b/apps/opencs/model/world/idtable.hpp index dfbc04134f..ce47307e3c 100644 --- a/apps/opencs/model/world/idtable.hpp +++ b/apps/opencs/model/world/idtable.hpp @@ -63,7 +63,10 @@ namespace CSMWorld void addRecord (const std::string& id, UniversalId::Type type = UniversalId::Type_None); ///< \param type Will be ignored, unless the collection supports multiple record types - void cloneRecord(const std::string& origin, const std::string& destination, UniversalId::Type type = UniversalId::Type_None); + void cloneRecord(const std::string& origin, + const std::string& destination, + UniversalId::ArgumentType argumentType, + UniversalId::Type type = UniversalId::Type_None); QModelIndex getModelIndex (const std::string& id, int column) const; diff --git a/apps/opencs/model/world/refidcollection.cpp b/apps/opencs/model/world/refidcollection.cpp index 86a542c5c3..896ee90101 100644 --- a/apps/opencs/model/world/refidcollection.cpp +++ b/apps/opencs/model/world/refidcollection.cpp @@ -449,6 +449,14 @@ void CSMWorld::RefIdCollection::replace (int index, const RecordBase& record) mData.getRecord (mData.globalToLocalIndex (index)).assign (record); } +void CSMWorld::RefIdCollection::cloneRecord(const std::string& origin, + const std::string& destination, + const CSMWorld::UniversalId::Type type, + const CSMWorld::UniversalId::ArgumentType argumentType) +{ + +} + void CSMWorld::RefIdCollection::appendRecord (const RecordBase& record, UniversalId::Type type) { diff --git a/apps/opencs/model/world/refidcollection.hpp b/apps/opencs/model/world/refidcollection.hpp index 5ff4a70bf2..4ad181004f 100644 --- a/apps/opencs/model/world/refidcollection.hpp +++ b/apps/opencs/model/world/refidcollection.hpp @@ -69,6 +69,11 @@ namespace CSMWorld virtual void removeRows (int index, int count); + virtual void cloneRecord(const std::string& origin, + const std::string& destination, + const UniversalId::Type type, + const UniversalId::ArgumentType argumentType); + virtual void appendBlankRecord (const std::string& id, UniversalId::Type type); ///< \param type Will be ignored, unless the collection supports multiple record types diff --git a/apps/opencs/view/world/creator.hpp b/apps/opencs/view/world/creator.hpp index 58a5e21ad2..5eaf3e1781 100644 --- a/apps/opencs/view/world/creator.hpp +++ b/apps/opencs/view/world/creator.hpp @@ -25,7 +25,7 @@ namespace CSVWorld virtual void reset() = 0; - virtual void cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type) = 0; + virtual void cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type, const CSMWorld::UniversalId::ArgumentType argumentType) = 0; virtual void setEditLock (bool locked) = 0; diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index f21a62d979..efdd9ecafb 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -59,7 +59,8 @@ const CSMWorld::UniversalId& CSVWorld::GenericCreator::getCollectionId() const CSVWorld::GenericCreator::GenericCreator (CSMWorld::Data& data, QUndoStack& undoStack, const CSMWorld::UniversalId& id, bool relaxedIdRules) -: mData (data), mUndoStack (undoStack), mListId (id), mLocked (false), mCloneMode(false), mClonedType(CSMWorld::UniversalId::Type_None) +: mData (data), mUndoStack (undoStack), mListId (id), mLocked (false), mCloneMode(false), mClonedType(CSMWorld::UniversalId::Type_None), +mArgumentType(CSMWorld::UniversalId::ArgumentType_None) { mLayout = new QHBoxLayout; mLayout->setContentsMargins (0, 0, 0, 0); @@ -126,7 +127,12 @@ void CSVWorld::GenericCreator::create() { std::string id = getId(); std::auto_ptr command (new CSMWorld::CloneCommand ( - dynamic_cast (*mData.getTableModel(mListId)), mClonedId, id, mClonedType)); + dynamic_cast (*mData.getTableModel(mListId)), mClonedId, id, mClonedType, mArgumentType)); + + mUndoStack.push(command.release()); + + emit done(); + emit requestFocus(id); } else { std::string id = getId(); @@ -143,11 +149,14 @@ void CSVWorld::GenericCreator::create() } } -void CSVWorld::GenericCreator::cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type) +void CSVWorld::GenericCreator::cloneMode(const std::string& originid, + const CSMWorld::UniversalId::Type type, + const CSMWorld::UniversalId::ArgumentType argumentType) { mCloneMode = true; mClonedId = originid; mClonedType = type; + mArgumentType = argumentType; mId->setText(QString::fromStdString(mClonedId)); } diff --git a/apps/opencs/view/world/genericcreator.hpp b/apps/opencs/view/world/genericcreator.hpp index a1acb2e792..867595bb55 100644 --- a/apps/opencs/view/world/genericcreator.hpp +++ b/apps/opencs/view/world/genericcreator.hpp @@ -32,6 +32,7 @@ namespace CSVWorld bool mCloneMode; std::string mClonedId; CSMWorld::UniversalId::Type mClonedType; + CSMWorld::UniversalId::ArgumentType mArgumentType; protected: @@ -61,13 +62,14 @@ namespace CSVWorld virtual void reset(); - virtual void cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type); + virtual void cloneMode(const std::string& originid, + const CSMWorld::UniversalId::Type type, + const CSMWorld::UniversalId::ArgumentType argumentType); virtual std::string getErrors() const; ///< Return formatted error descriptions for the current state of the creator. if an empty /// string is returned, there is no error. - private slots: void textChanged (const QString& text); diff --git a/apps/opencs/view/world/tablebottombox.cpp b/apps/opencs/view/world/tablebottombox.cpp index b89f5180bf..60a206d0c2 100644 --- a/apps/opencs/view/world/tablebottombox.cpp +++ b/apps/opencs/view/world/tablebottombox.cpp @@ -158,10 +158,12 @@ void CSVWorld::TableBottomBox::createRequest() mCreating = true; } -void CSVWorld::TableBottomBox::cloneRequest(const std::string& id, const CSMWorld::UniversalId::Type type) +void CSVWorld::TableBottomBox::cloneRequest(const std::string& id, + const CSMWorld::UniversalId::Type type, + const CSMWorld::UniversalId::ArgumentType argumnetType) { mCreator->reset(); - mCreator->cloneMode(id, type); + mCreator->cloneMode(id, type, argumnetType); mLayout->setCurrentWidget(mCreator); setVisible (true); mCreating = true; diff --git a/apps/opencs/view/world/tablebottombox.hpp b/apps/opencs/view/world/tablebottombox.hpp index 58a6a5a2f3..29afa22772 100644 --- a/apps/opencs/view/world/tablebottombox.hpp +++ b/apps/opencs/view/world/tablebottombox.hpp @@ -77,7 +77,7 @@ namespace CSVWorld /// \param modified Number of added and modified records void createRequest(); - void cloneRequest(const std::string& id, const CSMWorld::UniversalId::Type type); + void cloneRequest(const std::string& id, const CSMWorld::UniversalId::Type type, const CSMWorld::UniversalId::ArgumentType argumentType); }; } diff --git a/apps/opencs/view/world/tablesubview.cpp b/apps/opencs/view/world/tablesubview.cpp index 36200dbbcb..7bb852cbe5 100644 --- a/apps/opencs/view/world/tablesubview.cpp +++ b/apps/opencs/view/world/tablesubview.cpp @@ -50,8 +50,8 @@ CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMDoc::D connect (mTable, SIGNAL (createRequest()), mBottom, SLOT (createRequest())); connect (mTable, SIGNAL (cloneRequest(int)), this, SLOT(cloneRequest(int))); - connect (this, SIGNAL(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type)), - mBottom, SLOT(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type))); + connect (this, SIGNAL(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type, const CSMWorld::UniversalId::ArgumentType)), + mBottom, SLOT(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type, const CSMWorld::UniversalId::ArgumentType))); } connect (mBottom, SIGNAL (requestFocus (const std::string&)), mTable, SLOT (requestFocus (const std::string&))); @@ -85,5 +85,5 @@ void CSVWorld::TableSubView::setStatusBar (bool show) void CSVWorld::TableSubView::cloneRequest(int row) { const CSMWorld::UniversalId& toClone(mTable->getUniversalId(row)); - emit cloneRequest(toClone.getId(), toClone.getType()); + emit cloneRequest(toClone.getId(), toClone.getType(), toClone.getArgumentType()); } diff --git a/apps/opencs/view/world/tablesubview.hpp b/apps/opencs/view/world/tablesubview.hpp index 5b19110b6b..01df204def 100644 --- a/apps/opencs/view/world/tablesubview.hpp +++ b/apps/opencs/view/world/tablesubview.hpp @@ -35,7 +35,9 @@ namespace CSVWorld virtual void setStatusBar (bool show); signals: - void cloneRequest(const std::string& id, const CSMWorld::UniversalId::Type type); + void cloneRequest(const std::string& id, + const CSMWorld::UniversalId::Type type, + const CSMWorld::UniversalId::ArgumentType argumentType); private slots: From a45339bbe6ecd68ab2d5704649582ad3e3cd06b1 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 20 Jan 2014 14:14:59 +0100 Subject: [PATCH 18/61] lower case in command, not in the collection --- apps/opencs/model/world/collection.hpp | 2 +- apps/opencs/model/world/commands.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index 0b9b44fa9a..091496926d 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -212,7 +212,7 @@ namespace CSMWorld if (argumentType == UniversalId::ArgumentType_Id) { - copy.get().mId = Misc::StringUtils::lowerCase(destination); + copy.get().mId = destination; } insertRecord(copy, getAppendIndex(destination, type)); diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 75b88766aa..f161170195 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -2,7 +2,7 @@ #include "commands.hpp" #include - +#include #include "idtable.hpp" #include "idtable.hpp" @@ -34,7 +34,7 @@ CSMWorld::CloneCommand::CloneCommand(CSMWorld::IdTable& model, QUndoCommand(parent), mModel(model), mIdOrigin(idOrigin), - mIdDestination(IdDestination), + mIdDestination(Misc::StringUtils::lowerCase(IdDestination)), mArgumentType(argumentType), mType(type) { From 38636fab9a60a442fce8f04de170827675194f6f Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 20 Jan 2014 14:29:47 +0100 Subject: [PATCH 19/61] added setId to adapter --- apps/opencs/model/world/commands.cpp | 3 +++ apps/opencs/model/world/refidadapter.hpp | 1 + apps/opencs/model/world/refidadapterimp.hpp | 8 ++++++++ 3 files changed, 12 insertions(+) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index f161170195..b7c88e872c 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -45,6 +45,9 @@ CSMWorld::CloneCommand::CloneCommand(CSMWorld::IdTable& model, void CSMWorld::CloneCommand::redo() { mModel.cloneRecord(mIdOrigin, mIdDestination, mArgumentType, mType); + + for (std::map::const_iterator iter(mValues.begin()); iter != mValues.end(); ++iter) + mModel.setData(mModel.getModelIndex(mIdDestination, iter->first), iter->second); } void CSMWorld::CloneCommand::undo() diff --git a/apps/opencs/model/world/refidadapter.hpp b/apps/opencs/model/world/refidadapter.hpp index df0ceae706..0870a2d3e6 100644 --- a/apps/opencs/model/world/refidadapter.hpp +++ b/apps/opencs/model/world/refidadapter.hpp @@ -31,6 +31,7 @@ namespace CSMWorld ///< If the data type does not match an exception is thrown. virtual std::string getId (const RecordBase& record) const = 0; + virtual void setId(RecordBase& record, const std::string& id) = 0; }; } diff --git a/apps/opencs/model/world/refidadapterimp.hpp b/apps/opencs/model/world/refidadapterimp.hpp index d5d84a8f7e..bd509a86b6 100644 --- a/apps/opencs/model/world/refidadapterimp.hpp +++ b/apps/opencs/model/world/refidadapterimp.hpp @@ -34,6 +34,8 @@ namespace CSMWorld BaseRefIdAdapter (UniversalId::Type type, const BaseColumns& base); virtual std::string getId (const RecordBase& record) const; + + virtual void setId (RecordBase& record, const std::string& id); virtual QVariant getData (const RefIdColumn *column, const RefIdData& data, int index) const; @@ -50,6 +52,12 @@ namespace CSMWorld : mType (type), mBase (base) {} + template + void BaseRefIdAdapter::setId (RecordBase& record, const std::string& id) + { + (dynamic_cast&> (record).get().mId) = id; + } + template std::string BaseRefIdAdapter::getId (const RecordBase& record) const { From 5a527157013f97bec71790f7bbbedc29e92779c5 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 20 Jan 2014 15:58:19 +0100 Subject: [PATCH 20/61] implemented check for deletion. But it seems flawed. --- apps/opencs/model/world/data.cpp | 21 +++++++++++++++++++++ apps/opencs/model/world/data.hpp | 2 ++ apps/opencs/view/world/genericcreator.cpp | 7 +++++-- apps/opencs/view/world/table.cpp | 3 ++- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index 04e35cdaaf..8a7dc3971a 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -657,6 +657,27 @@ int CSMWorld::Data::count (RecordBase::State state) const count (state, mReferenceables); } +bool CSMWorld::Data::recordDeleted(const std::string& id) const +{ + return + getGlobals().getRecord(id).isDeleted() || + getGmsts().getRecord(id).isDeleted() || + getSkills().getRecord(id).isDeleted() || + getClasses().getRecord(id).isDeleted() || + getFactions().getRecord(id).isDeleted() || + getRaces().getRecord(id).isDeleted() || + getSounds().getRecord(id).isDeleted() || + getScripts().getRecord(id).isDeleted() || + getRegions().getRecord(id).isDeleted() || + getBirthsigns().getRecord(id).isDeleted() || + getSpells().getRecord(id).isDeleted() || + getTopics().getRecord(id).isDeleted() || + getJournals().getRecord(id).isDeleted() || + getCells().getRecord(id).isDeleted() || + getReferenceables().getRecord(id).isDeleted(); +} + + void CSMWorld::Data::setDescription (const std::string& description) { mDescription = description; diff --git a/apps/opencs/model/world/data.hpp b/apps/opencs/model/world/data.hpp index 152c3ac419..df51c936a4 100644 --- a/apps/opencs/model/world/data.hpp +++ b/apps/opencs/model/world/data.hpp @@ -189,6 +189,8 @@ namespace CSMWorld void setAuthor (const std::string& author); std::string getAuthor() const; + + bool recordDeleted(const std::string& id) const; signals: diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index efdd9ecafb..16bd04ece4 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -125,10 +125,13 @@ void CSVWorld::GenericCreator::create() { if (mCloneMode) { - std::string id = getId(); + const std::string id = getId(); + if (mData.recordDeleted(id)) + { + return; + } std::auto_ptr command (new CSMWorld::CloneCommand ( dynamic_cast (*mData.getTableModel(mListId)), mClonedId, id, mClonedType, mArgumentType)); - mUndoStack.push(command.release()); emit done(); diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index 31a7d8b588..4577c40dc8 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -308,9 +308,10 @@ void CSVWorld::Table::cloneRecord() if (!mEditLock) { QModelIndexList selectedRows = selectionModel()->selectedRows(); - if (selectedRows.size()==1) + { emit cloneRequest (selectedRows.begin()->row()); + } } } From d82f272e0546c9cb270dcc7f0951a7ead0489903 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 20 Jan 2014 16:17:49 +0100 Subject: [PATCH 21/61] Properly check if clone is deleted. --- apps/opencs/view/world/table.cpp | 2 +- apps/opencs/view/world/table.hpp | 2 +- apps/opencs/view/world/tablesubview.cpp | 11 +++++++---- apps/opencs/view/world/tablesubview.hpp | 7 ++++++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index 4577c40dc8..02a93161cf 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -310,7 +310,7 @@ void CSVWorld::Table::cloneRecord() QModelIndexList selectedRows = selectionModel()->selectedRows(); if (selectedRows.size()==1) { - emit cloneRequest (selectedRows.begin()->row()); + emit cloneRequest (selectedRows.begin()->row(), mModel); } } } diff --git a/apps/opencs/view/world/table.hpp b/apps/opencs/view/world/table.hpp index f4a5d3c9e9..118bd3cf20 100644 --- a/apps/opencs/view/world/table.hpp +++ b/apps/opencs/view/world/table.hpp @@ -74,7 +74,7 @@ namespace CSVWorld /// \param modified Number of added and modified records void createRequest(); - void cloneRequest(int row); + void cloneRequest(int row, const CSMWorld::IdTable* table); private slots: diff --git a/apps/opencs/view/world/tablesubview.cpp b/apps/opencs/view/world/tablesubview.cpp index 7bb852cbe5..0cdc57f5f5 100644 --- a/apps/opencs/view/world/tablesubview.cpp +++ b/apps/opencs/view/world/tablesubview.cpp @@ -6,7 +6,7 @@ #include "../../model/doc/document.hpp" #include "../filter/filterbox.hpp" - +#include "../../model/world/idtable.hpp" #include "table.hpp" #include "tablebottombox.hpp" #include "creator.hpp" @@ -49,7 +49,7 @@ CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMDoc::D { connect (mTable, SIGNAL (createRequest()), mBottom, SLOT (createRequest())); - connect (mTable, SIGNAL (cloneRequest(int)), this, SLOT(cloneRequest(int))); + connect (mTable, SIGNAL (cloneRequest(int, CSMWorld::IdTable*)), this, SLOT(cloneRequest(int, CSMWorld::IdTable*))); connect (this, SIGNAL(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type, const CSMWorld::UniversalId::ArgumentType)), mBottom, SLOT(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type, const CSMWorld::UniversalId::ArgumentType))); } @@ -82,8 +82,11 @@ void CSVWorld::TableSubView::setStatusBar (bool show) mBottom->setStatusBar (show); } -void CSVWorld::TableSubView::cloneRequest(int row) +void CSVWorld::TableSubView::cloneRequest(int row, const CSMWorld::IdTable* table) { const CSMWorld::UniversalId& toClone(mTable->getUniversalId(row)); - emit cloneRequest(toClone.getId(), toClone.getType(), toClone.getArgumentType()); + if (!(table->getRecord(toClone.getId()).isDeleted())) + { + emit cloneRequest(toClone.getId(), toClone.getType(), toClone.getArgumentType()); + } } diff --git a/apps/opencs/view/world/tablesubview.hpp b/apps/opencs/view/world/tablesubview.hpp index 01df204def..650a098f6c 100644 --- a/apps/opencs/view/world/tablesubview.hpp +++ b/apps/opencs/view/world/tablesubview.hpp @@ -5,6 +5,11 @@ class QModelIndex; +namespace CSMWorld +{ + class IdTable; +} + namespace CSMDoc { class Document; @@ -42,7 +47,7 @@ namespace CSVWorld private slots: void editRequest (int row); - void cloneRequest (int row); + void cloneRequest (int row, const CSMWorld::IdTable* table); }; } From 92ee252eef54b0e9072a39803087e81ccd7bff62 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 20 Jan 2014 16:23:34 +0100 Subject: [PATCH 22/61] Small correction. --- apps/opencs/model/world/data.cpp | 21 --------------------- apps/opencs/model/world/data.hpp | 2 -- apps/opencs/view/world/genericcreator.cpp | 7 ++----- apps/opencs/view/world/table.cpp | 1 + apps/opencs/view/world/table.hpp | 2 +- apps/opencs/view/world/tablesubview.cpp | 2 +- 6 files changed, 5 insertions(+), 30 deletions(-) diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index 8a7dc3971a..04e35cdaaf 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -657,27 +657,6 @@ int CSMWorld::Data::count (RecordBase::State state) const count (state, mReferenceables); } -bool CSMWorld::Data::recordDeleted(const std::string& id) const -{ - return - getGlobals().getRecord(id).isDeleted() || - getGmsts().getRecord(id).isDeleted() || - getSkills().getRecord(id).isDeleted() || - getClasses().getRecord(id).isDeleted() || - getFactions().getRecord(id).isDeleted() || - getRaces().getRecord(id).isDeleted() || - getSounds().getRecord(id).isDeleted() || - getScripts().getRecord(id).isDeleted() || - getRegions().getRecord(id).isDeleted() || - getBirthsigns().getRecord(id).isDeleted() || - getSpells().getRecord(id).isDeleted() || - getTopics().getRecord(id).isDeleted() || - getJournals().getRecord(id).isDeleted() || - getCells().getRecord(id).isDeleted() || - getReferenceables().getRecord(id).isDeleted(); -} - - void CSMWorld::Data::setDescription (const std::string& description) { mDescription = description; diff --git a/apps/opencs/model/world/data.hpp b/apps/opencs/model/world/data.hpp index df51c936a4..152c3ac419 100644 --- a/apps/opencs/model/world/data.hpp +++ b/apps/opencs/model/world/data.hpp @@ -189,8 +189,6 @@ namespace CSMWorld void setAuthor (const std::string& author); std::string getAuthor() const; - - bool recordDeleted(const std::string& id) const; signals: diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index 16bd04ece4..efdd9ecafb 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -125,13 +125,10 @@ void CSVWorld::GenericCreator::create() { if (mCloneMode) { - const std::string id = getId(); - if (mData.recordDeleted(id)) - { - return; - } + std::string id = getId(); std::auto_ptr command (new CSMWorld::CloneCommand ( dynamic_cast (*mData.getTableModel(mListId)), mClonedId, id, mClonedType, mArgumentType)); + mUndoStack.push(command.release()); emit done(); diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index 02a93161cf..cc1f814ddf 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -308,6 +308,7 @@ void CSVWorld::Table::cloneRecord() if (!mEditLock) { QModelIndexList selectedRows = selectionModel()->selectedRows(); + if (selectedRows.size()==1) { emit cloneRequest (selectedRows.begin()->row(), mModel); diff --git a/apps/opencs/view/world/table.hpp b/apps/opencs/view/world/table.hpp index 118bd3cf20..af2d7877f7 100644 --- a/apps/opencs/view/world/table.hpp +++ b/apps/opencs/view/world/table.hpp @@ -74,7 +74,7 @@ namespace CSVWorld /// \param modified Number of added and modified records void createRequest(); - void cloneRequest(int row, const CSMWorld::IdTable* table); + void cloneRequest(int row, const CSMWorld::IdTable*); private slots: diff --git a/apps/opencs/view/world/tablesubview.cpp b/apps/opencs/view/world/tablesubview.cpp index 0cdc57f5f5..7650556106 100644 --- a/apps/opencs/view/world/tablesubview.cpp +++ b/apps/opencs/view/world/tablesubview.cpp @@ -49,7 +49,7 @@ CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMDoc::D { connect (mTable, SIGNAL (createRequest()), mBottom, SLOT (createRequest())); - connect (mTable, SIGNAL (cloneRequest(int, CSMWorld::IdTable*)), this, SLOT(cloneRequest(int, CSMWorld::IdTable*))); + connect (mTable, SIGNAL (cloneRequest(int, const CSMWorld::IdTable*)), this, SLOT(cloneRequest(int, const CSMWorld::IdTable*))); connect (this, SIGNAL(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type, const CSMWorld::UniversalId::ArgumentType)), mBottom, SLOT(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type, const CSMWorld::UniversalId::ArgumentType))); } From d0a52b7b242e114d39a5fd25720a62a972eebcbe Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 20 Jan 2014 18:28:06 +0100 Subject: [PATCH 23/61] mostly refreshing view. --- apps/opencs/model/world/idtable.cpp | 5 +++++ apps/opencs/model/world/refidcollection.cpp | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/apps/opencs/model/world/idtable.cpp b/apps/opencs/model/world/idtable.cpp index daa6bc51b3..d4008fb878 100644 --- a/apps/opencs/model/world/idtable.cpp +++ b/apps/opencs/model/world/idtable.cpp @@ -129,7 +129,12 @@ void CSMWorld::IdTable::cloneRecord(const std::string& origin, CSMWorld::UniversalId::ArgumentType argumentType, CSMWorld::UniversalId::Type type) { + int index = mIdCollection->getAppendIndex (destination); + beginInsertRows (QModelIndex(), index, index); mIdCollection->cloneRecord(origin, destination, type, argumentType); + endInsertRows(); + emit dataChanged (CSMWorld::IdTable::index (0, 0), + CSMWorld::IdTable::index (mIdCollection->getSize()-1, mIdCollection->getColumns()-1)); } diff --git a/apps/opencs/model/world/refidcollection.cpp b/apps/opencs/model/world/refidcollection.cpp index 896ee90101..74f6f13599 100644 --- a/apps/opencs/model/world/refidcollection.cpp +++ b/apps/opencs/model/world/refidcollection.cpp @@ -454,7 +454,11 @@ void CSMWorld::RefIdCollection::cloneRecord(const std::string& origin, const CSMWorld::UniversalId::Type type, const CSMWorld::UniversalId::ArgumentType argumentType) { - + RecordBase *newRecord = mData.getRecord(mData.searchId(origin)).clone(); + newRecord->mState = RecordBase::State_ModifiedOnly; + mAdapters.find(type)->second->setId(*newRecord, destination); + mData.getAppendIndex(type); + //WIP } void CSMWorld::RefIdCollection::appendRecord (const RecordBase& record, From 7594bcf97aa0813d3517f2f53f2d1d633c22aee6 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Tue, 21 Jan 2014 08:27:29 +0100 Subject: [PATCH 24/61] Small refactoring. --- apps/opencs/view/world/genericcreator.cpp | 2 +- apps/opencs/view/world/table.cpp | 7 ++++--- apps/opencs/view/world/table.hpp | 2 +- apps/opencs/view/world/tablesubview.cpp | 10 +++------- apps/opencs/view/world/tablesubview.hpp | 8 ++++---- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index efdd9ecafb..163842ab81 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -149,7 +149,7 @@ void CSVWorld::GenericCreator::create() } } -void CSVWorld::GenericCreator::cloneMode(const std::string& originid, +void CSVWorld::GenericCreator::cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type, const CSMWorld::UniversalId::ArgumentType argumentType) { diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index cc1f814ddf..d343f9986a 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -16,6 +16,7 @@ #include "recordstatusdelegate.hpp" #include "util.hpp" +#include void CSVWorld::Table::contextMenuEvent (QContextMenuEvent *event) { @@ -308,10 +309,10 @@ void CSVWorld::Table::cloneRecord() if (!mEditLock) { QModelIndexList selectedRows = selectionModel()->selectedRows(); - - if (selectedRows.size()==1) + const CSMWorld::UniversalId& toClone = getUniversalId(selectedRows.begin()->row()); + if (selectedRows.size()==1 && !mModel->getRecord(toClone.getId()).isDeleted()) { - emit cloneRequest (selectedRows.begin()->row(), mModel); + emit cloneRequest (toClone); } } } diff --git a/apps/opencs/view/world/table.hpp b/apps/opencs/view/world/table.hpp index af2d7877f7..d30083333f 100644 --- a/apps/opencs/view/world/table.hpp +++ b/apps/opencs/view/world/table.hpp @@ -74,7 +74,7 @@ namespace CSVWorld /// \param modified Number of added and modified records void createRequest(); - void cloneRequest(int row, const CSMWorld::IdTable*); + void cloneRequest(const CSMWorld::UniversalId&); private slots: diff --git a/apps/opencs/view/world/tablesubview.cpp b/apps/opencs/view/world/tablesubview.cpp index 7650556106..3c71d13708 100644 --- a/apps/opencs/view/world/tablesubview.cpp +++ b/apps/opencs/view/world/tablesubview.cpp @@ -49,7 +49,7 @@ CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMDoc::D { connect (mTable, SIGNAL (createRequest()), mBottom, SLOT (createRequest())); - connect (mTable, SIGNAL (cloneRequest(int, const CSMWorld::IdTable*)), this, SLOT(cloneRequest(int, const CSMWorld::IdTable*))); + connect (mTable, SIGNAL (cloneRequest(const CSMWorld::UniversalId&)), this, SLOT(cloneRequest(const CSMWorld::UniversalId&))); connect (this, SIGNAL(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type, const CSMWorld::UniversalId::ArgumentType)), mBottom, SLOT(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type, const CSMWorld::UniversalId::ArgumentType))); } @@ -82,11 +82,7 @@ void CSVWorld::TableSubView::setStatusBar (bool show) mBottom->setStatusBar (show); } -void CSVWorld::TableSubView::cloneRequest(int row, const CSMWorld::IdTable* table) +void CSVWorld::TableSubView::cloneRequest(const CSMWorld::UniversalId& toClone) { - const CSMWorld::UniversalId& toClone(mTable->getUniversalId(row)); - if (!(table->getRecord(toClone.getId()).isDeleted())) - { - emit cloneRequest(toClone.getId(), toClone.getType(), toClone.getArgumentType()); - } + emit cloneRequest(toClone.getId(), toClone.getType(), toClone.getArgumentType()); } diff --git a/apps/opencs/view/world/tablesubview.hpp b/apps/opencs/view/world/tablesubview.hpp index 650a098f6c..b3a0a51626 100644 --- a/apps/opencs/view/world/tablesubview.hpp +++ b/apps/opencs/view/world/tablesubview.hpp @@ -40,14 +40,14 @@ namespace CSVWorld virtual void setStatusBar (bool show); signals: - void cloneRequest(const std::string& id, - const CSMWorld::UniversalId::Type type, - const CSMWorld::UniversalId::ArgumentType argumentType); + void cloneRequest(const std::string&, + const CSMWorld::UniversalId::Type, + const CSMWorld::UniversalId::ArgumentType); private slots: void editRequest (int row); - void cloneRequest (int row, const CSMWorld::IdTable* table); + void cloneRequest (const CSMWorld::UniversalId& toClone); }; } From 9b56b6585be31d6d8af9573d3e53b3aa4766cc2f Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Tue, 21 Jan 2014 09:43:02 +0100 Subject: [PATCH 25/61] Cloning works for referencables as well. --- apps/opencs/model/world/refidcollection.cpp | 3 ++- apps/opencs/model/world/refiddata.cpp | 17 ++++++++++++++++- apps/opencs/model/world/refiddata.hpp | 13 +++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/apps/opencs/model/world/refidcollection.cpp b/apps/opencs/model/world/refidcollection.cpp index 74f6f13599..75a1b681d2 100644 --- a/apps/opencs/model/world/refidcollection.cpp +++ b/apps/opencs/model/world/refidcollection.cpp @@ -457,7 +457,8 @@ void CSMWorld::RefIdCollection::cloneRecord(const std::string& origin, RecordBase *newRecord = mData.getRecord(mData.searchId(origin)).clone(); newRecord->mState = RecordBase::State_ModifiedOnly; mAdapters.find(type)->second->setId(*newRecord, destination); - mData.getAppendIndex(type); + mData.insertRecord(*newRecord, type, destination); + delete newRecord; //WIP } diff --git a/apps/opencs/model/world/refiddata.cpp b/apps/opencs/model/world/refiddata.cpp index 8f59b0fe74..d4f08eb915 100644 --- a/apps/opencs/model/world/refiddata.cpp +++ b/apps/opencs/model/world/refiddata.cpp @@ -230,4 +230,19 @@ void CSMWorld::RefIdData::save (int index, ESM::ESMWriter& writer) const throw std::logic_error ("invalid local index type"); iter->second->save (localIndex.first, writer); -} \ No newline at end of file +} + + +void CSMWorld::RefIdData::insertRecord(CSMWorld::RecordBase& record, CSMWorld::UniversalId::Type type, const std::string& id) +{ + std::map::iterator iter = + mRecordContainers.find (type); + + if (iter==mRecordContainers.end()) + throw std::logic_error ("invalid local index type"); + + iter->second->insertRecord(record); + + mIndex.insert (std::make_pair (Misc::StringUtils::lowerCase (id), + LocalIndex (iter->second->getSize()-1, type))); +} diff --git a/apps/opencs/model/world/refiddata.hpp b/apps/opencs/model/world/refiddata.hpp index 9595ab23b5..a982f2f975 100644 --- a/apps/opencs/model/world/refiddata.hpp +++ b/apps/opencs/model/world/refiddata.hpp @@ -46,6 +46,8 @@ namespace CSMWorld virtual RecordBase& getRecord (int index)= 0; virtual void appendRecord (const std::string& id) = 0; + + virtual void insertRecord (RecordBase& record) = 0; virtual void load (int index, ESM::ESMReader& reader, bool base) = 0; @@ -68,6 +70,8 @@ namespace CSMWorld virtual RecordBase& getRecord (int index); virtual void appendRecord (const std::string& id); + + virtual void insertRecord (RecordBase& record); virtual void load (int index, ESM::ESMReader& reader, bool base); @@ -78,6 +82,13 @@ namespace CSMWorld virtual void save (int index, ESM::ESMWriter& writer) const; }; + template + void RefIdDataContainer::insertRecord(RecordBase& record) + { + Record& newRecord = dynamic_cast& >(record); + mContainer.push_back(newRecord); + } + template int RefIdDataContainer::getSize() const { @@ -200,6 +211,8 @@ namespace CSMWorld LocalIndex searchId (const std::string& id) const; void erase (int index, int count); + + void insertRecord(CSMWorld::RecordBase& record, CSMWorld::UniversalId::Type type, const std::string& id); const RecordBase& getRecord (const LocalIndex& index) const; From bc0130f8d8451ff75ba73a622033ac0e82499cc6 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Tue, 21 Jan 2014 10:35:08 +0100 Subject: [PATCH 26/61] do not double check if record is deleted --- apps/opencs/model/world/collection.hpp | 5 ----- apps/opencs/view/world/genericcreator.cpp | 5 ++++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index 091496926d..7cc283ce8b 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -205,11 +205,6 @@ namespace CSMWorld const UniversalId::ArgumentType argumentType) { Record copy = getRecord(origin); - if (copy.isDeleted()) - { - return; - } - if (argumentType == UniversalId::ArgumentType_Id) { copy.get().mId = destination; diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index 163842ab81..2fcce91869 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -158,5 +158,8 @@ void CSVWorld::GenericCreator::cloneMode(const std::string& originid, mClonedType = type; mArgumentType = argumentType; - mId->setText(QString::fromStdString(mClonedId)); + if (argumentType == CSMWorld::UniversalId::ArgumentType_Id) + { + mId->setText(QString::fromStdString(mClonedId)); + } } From b3b51992ef8ac49e292787704cdf7ab466f1fbb4 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Tue, 21 Jan 2014 21:37:21 +0100 Subject: [PATCH 27/61] copying references. --- apps/opencs/model/world/collection.hpp | 6 +++--- apps/opencs/model/world/commands.cpp | 1 - apps/opencs/model/world/refcollection.cpp | 15 +++++++++++++++ apps/opencs/model/world/refcollection.hpp | 6 ++++++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index 7cc283ce8b..8ecad816b9 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -200,9 +200,9 @@ namespace CSMWorld template void Collection::cloneRecord(const std::string& origin, - const std::string& destination, - const UniversalId::Type type, - const UniversalId::ArgumentType argumentType) + const std::string& destination, + const UniversalId::Type type, + const UniversalId::ArgumentType argumentType) { Record copy = getRecord(origin); if (argumentType == UniversalId::ArgumentType_Id) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index b7c88e872c..762e4809ca 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -4,7 +4,6 @@ #include #include #include "idtable.hpp" -#include "idtable.hpp" CSMWorld::ModifyCommand::ModifyCommand(QAbstractItemModel& model, const QModelIndex& index, const QVariant& new_, QUndoCommand* parent) diff --git a/apps/opencs/model/world/refcollection.cpp b/apps/opencs/model/world/refcollection.cpp index 696aeefaa2..2ecd3b6630 100644 --- a/apps/opencs/model/world/refcollection.cpp +++ b/apps/opencs/model/world/refcollection.cpp @@ -5,6 +5,8 @@ #include "ref.hpp" #include "cell.hpp" +#include "universalid.hpp" +#include "record.hpp" void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool base) { @@ -34,4 +36,17 @@ std::string CSMWorld::RefCollection::getNewId() std::ostringstream stream; stream << "ref#" << mNextId++; return stream.str(); +} + +void CSMWorld::RefCollection::cloneRecord(const std::string& origin, + const std::string& destination, + const CSMWorld::UniversalId::Type type, + const CSMWorld::UniversalId::ArgumentType argumentType) +{ + Record originRecord = getRecord(origin); + Record *copy = dynamic_cast* >(originRecord.clone()); + copy->mState = CSMWorld::RecordBase::State_ModifiedOnly; + copy->get().mId = getNewId(); + insertRecord(*copy, getAppendIndex(destination, type)); + delete copy; } \ No newline at end of file diff --git a/apps/opencs/model/world/refcollection.hpp b/apps/opencs/model/world/refcollection.hpp index b5f8c8064a..dcfd2036cd 100644 --- a/apps/opencs/model/world/refcollection.hpp +++ b/apps/opencs/model/world/refcollection.hpp @@ -8,6 +8,7 @@ namespace CSMWorld { struct Cell; + struct UniversalId; /// \brief References in cells class RefCollection : public Collection @@ -25,6 +26,11 @@ namespace CSMWorld ///< Load a sequence of references. std::string getNewId(); + + void cloneRecord(const std::string& origin, + const std::string& destination, + const CSMWorld::UniversalId::Type type, + const CSMWorld::UniversalId::ArgumentType argumentType); }; } From 4d9d31b25e9ad56bd35580b35134118e88ea3053 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Thu, 23 Jan 2014 09:40:32 +0100 Subject: [PATCH 28/61] refrences cloning does not work --- apps/opencs/model/world/collection.hpp | 1 + apps/opencs/model/world/data.cpp | 1 + apps/opencs/model/world/idtable.cpp | 2 -- apps/opencs/model/world/refcollection.cpp | 10 ++++------ apps/opencs/view/world/genericcreator.cpp | 7 +------ apps/opencs/view/world/referencecreator.cpp | 2 +- 6 files changed, 8 insertions(+), 15 deletions(-) diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index 8ecad816b9..74019dda75 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -205,6 +205,7 @@ namespace CSMWorld const UniversalId::ArgumentType argumentType) { Record copy = getRecord(origin); + copy.mState = RecordBase::State_ModifiedOnly; if (argumentType == UniversalId::ArgumentType_Id) { copy.get().mId = destination; diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index 04e35cdaaf..69fb4ab1e6 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -194,6 +194,7 @@ CSMWorld::Data::Data() : mRefs (mCells) mRefs.addColumn (new StringIdColumn (true)); mRefs.addColumn (new RecordStateColumn); + mRefs.addColumn (new FixedRecordTypeColumn (UniversalId::Type_Reference)); mRefs.addColumn (new CellColumn); mRefs.addColumn (new IdColumn); mRefs.addColumn (new PosColumn (&CellRef::mPos, 0, false)); diff --git a/apps/opencs/model/world/idtable.cpp b/apps/opencs/model/world/idtable.cpp index d4008fb878..f131f7087a 100644 --- a/apps/opencs/model/world/idtable.cpp +++ b/apps/opencs/model/world/idtable.cpp @@ -133,8 +133,6 @@ void CSMWorld::IdTable::cloneRecord(const std::string& origin, beginInsertRows (QModelIndex(), index, index); mIdCollection->cloneRecord(origin, destination, type, argumentType); endInsertRows(); - emit dataChanged (CSMWorld::IdTable::index (0, 0), - CSMWorld::IdTable::index (mIdCollection->getSize()-1, mIdCollection->getColumns()-1)); } diff --git a/apps/opencs/model/world/refcollection.cpp b/apps/opencs/model/world/refcollection.cpp index 2ecd3b6630..6b00812583 100644 --- a/apps/opencs/model/world/refcollection.cpp +++ b/apps/opencs/model/world/refcollection.cpp @@ -43,10 +43,8 @@ void CSMWorld::RefCollection::cloneRecord(const std::string& origin, const CSMWorld::UniversalId::Type type, const CSMWorld::UniversalId::ArgumentType argumentType) { - Record originRecord = getRecord(origin); - Record *copy = dynamic_cast* >(originRecord.clone()); - copy->mState = CSMWorld::RecordBase::State_ModifiedOnly; - copy->get().mId = getNewId(); - insertRecord(*copy, getAppendIndex(destination, type)); - delete copy; + Record clone(getRecord(origin)); + clone.mState = CSMWorld::RecordBase::State_ModifiedOnly; + clone.get().mId = destination; + insertRecord(clone, getAppendIndex(destination, type), type); } \ No newline at end of file diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index 2fcce91869..ab387393b2 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -157,9 +157,4 @@ void CSVWorld::GenericCreator::cloneMode(const std::string& originid, mClonedId = originid; mClonedType = type; mArgumentType = argumentType; - - if (argumentType == CSMWorld::UniversalId::ArgumentType_Id) - { - mId->setText(QString::fromStdString(mClonedId)); - } -} +} \ No newline at end of file diff --git a/apps/opencs/view/world/referencecreator.cpp b/apps/opencs/view/world/referencecreator.cpp index aef25a81d0..06b3eb76dd 100644 --- a/apps/opencs/view/world/referencecreator.cpp +++ b/apps/opencs/view/world/referencecreator.cpp @@ -40,9 +40,9 @@ CSVWorld::ReferenceCreator::ReferenceCreator (CSMWorld::Data& data, QUndoStack& void CSVWorld::ReferenceCreator::reset() { + GenericCreator::reset(); mCell->setText (""); mId = getData().getReferences().getNewId(); - GenericCreator::reset(); } std::string CSVWorld::ReferenceCreator::getErrors() const From 1b1ecafdd8c68672dd51898ca9f8ccc3878b4f0b Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Thu, 23 Jan 2014 15:13:37 +0100 Subject: [PATCH 29/61] introduced missing columns to data --- apps/opencs/model/world/collection.hpp | 7 ++----- apps/opencs/model/world/data.cpp | 5 +++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index 74019dda75..f97b5f5293 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -204,12 +204,9 @@ namespace CSMWorld const UniversalId::Type type, const UniversalId::ArgumentType argumentType) { - Record copy = getRecord(origin); + Record copy(getRecord(origin)); copy.mState = RecordBase::State_ModifiedOnly; - if (argumentType == UniversalId::ArgumentType_Id) - { - copy.get().mId = destination; - } + copy.get().mId = destination; insertRecord(copy, getAppendIndex(destination, type)); } diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index 69fb4ab1e6..a52821036b 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -154,14 +154,17 @@ CSMWorld::Data::Data() : mRefs (mCells) mTopics.addColumn (new StringIdColumn); mTopics.addColumn (new RecordStateColumn); + mTopics.addColumn (new FixedRecordTypeColumn (UniversalId::Type_Topic)); mTopics.addColumn (new DialogueTypeColumn); mJournals.addColumn (new StringIdColumn); mJournals.addColumn (new RecordStateColumn); + mJournals.addColumn (new FixedRecordTypeColumn (UniversalId::Type_Journal)); mJournals.addColumn (new DialogueTypeColumn (true)); mTopicInfos.addColumn (new StringIdColumn (true)); mTopicInfos.addColumn (new RecordStateColumn); + mTopicInfos.addColumn (new FixedRecordTypeColumn (UniversalId::Type_Journal)); mTopicInfos.addColumn (new TopicColumn (false)); mTopicInfos.addColumn (new ActorColumn); mTopicInfos.addColumn (new RaceColumn); @@ -178,6 +181,7 @@ CSMWorld::Data::Data() : mRefs (mCells) mJournalInfos.addColumn (new StringIdColumn (true)); mJournalInfos.addColumn (new RecordStateColumn); + mJournalInfos.addColumn (new FixedRecordTypeColumn (UniversalId::Type_Journal)); mJournalInfos.addColumn (new TopicColumn (true)); mJournalInfos.addColumn (new QuestStatusTypeColumn); mJournalInfos.addColumn (new QuestIndexColumn); @@ -225,6 +229,7 @@ CSMWorld::Data::Data() : mRefs (mCells) mFilters.addColumn (new StringIdColumn); mFilters.addColumn (new RecordStateColumn); + mFilters.addColumn (new FixedRecordTypeColumn (UniversalId::Type_Filter)); mFilters.addColumn (new FilterColumn); mFilters.addColumn (new DescriptionColumn); mFilters.addColumn (new ScopeColumn); From dda7ddb6f8628b30632833ef2f486b8678aa4351 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Thu, 23 Jan 2014 16:00:44 +0100 Subject: [PATCH 30/61] Disable not needed referencable creator widget when in cloning mode. --- apps/opencs/view/world/creator.hpp | 2 ++ apps/opencs/view/world/genericcreator.cpp | 6 +++++- apps/opencs/view/world/genericcreator.hpp | 4 +++- apps/opencs/view/world/referenceablecreator.cpp | 8 +++++++- apps/opencs/view/world/referenceablecreator.hpp | 1 + apps/opencs/view/world/tablebottombox.cpp | 2 ++ 6 files changed, 20 insertions(+), 3 deletions(-) diff --git a/apps/opencs/view/world/creator.hpp b/apps/opencs/view/world/creator.hpp index 5eaf3e1781..5174232bc2 100644 --- a/apps/opencs/view/world/creator.hpp +++ b/apps/opencs/view/world/creator.hpp @@ -28,6 +28,8 @@ namespace CSVWorld virtual void cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type, const CSMWorld::UniversalId::ArgumentType argumentType) = 0; virtual void setEditLock (bool locked) = 0; + + virtual void toggleWidgets(bool active = true) = 0; signals: diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index ab387393b2..2a93f0e0f9 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -157,4 +157,8 @@ void CSVWorld::GenericCreator::cloneMode(const std::string& originid, mClonedId = originid; mClonedType = type; mArgumentType = argumentType; -} \ No newline at end of file +} + +void CSVWorld::GenericCreator::toggleWidgets(bool active) +{ +} diff --git a/apps/opencs/view/world/genericcreator.hpp b/apps/opencs/view/world/genericcreator.hpp index 867595bb55..e4813594b2 100644 --- a/apps/opencs/view/world/genericcreator.hpp +++ b/apps/opencs/view/world/genericcreator.hpp @@ -48,7 +48,7 @@ namespace CSVWorld virtual std::string getId() const; virtual void configureCreateCommand (CSMWorld::CreateCommand& command) const; - + CSMWorld::Data& getData() const; const CSMWorld::UniversalId& getCollectionId() const; @@ -61,6 +61,8 @@ namespace CSVWorld virtual void setEditLock (bool locked); virtual void reset(); + + virtual void toggleWidgets (bool active = true); virtual void cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type, diff --git a/apps/opencs/view/world/referenceablecreator.cpp b/apps/opencs/view/world/referenceablecreator.cpp index 718fe9ca7c..7a5fca8538 100644 --- a/apps/opencs/view/world/referenceablecreator.cpp +++ b/apps/opencs/view/world/referenceablecreator.cpp @@ -40,4 +40,10 @@ void CSVWorld::ReferenceableCreator::reset() { mType->setCurrentIndex (0); GenericCreator::reset(); -} \ No newline at end of file +} + +void CSVWorld::ReferenceableCreator::toggleWidgets(bool active) +{ + CSVWorld::GenericCreator::toggleWidgets(active); + mType->setEnabled(active); +} diff --git a/apps/opencs/view/world/referenceablecreator.hpp b/apps/opencs/view/world/referenceablecreator.hpp index 06e0e582be..88545575e3 100644 --- a/apps/opencs/view/world/referenceablecreator.hpp +++ b/apps/opencs/view/world/referenceablecreator.hpp @@ -23,6 +23,7 @@ namespace CSVWorld const CSMWorld::UniversalId& id); virtual void reset(); + virtual void toggleWidgets(bool active = true); }; } diff --git a/apps/opencs/view/world/tablebottombox.cpp b/apps/opencs/view/world/tablebottombox.cpp index 60a206d0c2..ef20cf1d47 100644 --- a/apps/opencs/view/world/tablebottombox.cpp +++ b/apps/opencs/view/world/tablebottombox.cpp @@ -153,6 +153,7 @@ void CSVWorld::TableBottomBox::tableSizeChanged (int size, int deleted, int modi void CSVWorld::TableBottomBox::createRequest() { mCreator->reset(); + mCreator->toggleWidgets(true); mLayout->setCurrentWidget (mCreator); setVisible (true); mCreating = true; @@ -163,6 +164,7 @@ void CSVWorld::TableBottomBox::cloneRequest(const std::string& id, const CSMWorld::UniversalId::ArgumentType argumnetType) { mCreator->reset(); + mCreator->toggleWidgets(false); mCreator->cloneMode(id, type, argumnetType); mLayout->setCurrentWidget(mCreator); setVisible (true); From c87d9ff38d67d698f60d0f438b45b99c546a869a Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Thu, 23 Jan 2014 16:17:04 +0100 Subject: [PATCH 31/61] Disable reference creator widget when in the clone mode. --- apps/opencs/view/world/genericcreator.hpp | 6 ++++-- apps/opencs/view/world/referencecreator.cpp | 21 +++++++++++++++++++-- apps/opencs/view/world/referencecreator.hpp | 5 +++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/apps/opencs/view/world/genericcreator.hpp b/apps/opencs/view/world/genericcreator.hpp index e4813594b2..4870ba46c4 100644 --- a/apps/opencs/view/world/genericcreator.hpp +++ b/apps/opencs/view/world/genericcreator.hpp @@ -29,11 +29,13 @@ namespace CSVWorld std::string mErrors; QHBoxLayout *mLayout; bool mLocked; - bool mCloneMode; std::string mClonedId; CSMWorld::UniversalId::Type mClonedType; CSMWorld::UniversalId::ArgumentType mArgumentType; - + + protected: + bool mCloneMode; + protected: void update(); diff --git a/apps/opencs/view/world/referencecreator.cpp b/apps/opencs/view/world/referencecreator.cpp index 06b3eb76dd..6991ecf36d 100644 --- a/apps/opencs/view/world/referencecreator.cpp +++ b/apps/opencs/view/world/referencecreator.cpp @@ -49,8 +49,13 @@ std::string CSVWorld::ReferenceCreator::getErrors() const { std::string errors = GenericCreator::getErrors(); + if (mCloneMode) + { + return errors; + } + std::string cell = mCell->text().toUtf8().constData(); - + if (cell.empty()) { if (!errors.empty()) @@ -72,4 +77,16 @@ std::string CSVWorld::ReferenceCreator::getErrors() const void CSVWorld::ReferenceCreator::cellChanged() { update(); -} \ No newline at end of file +} + +void CSVWorld::ReferenceCreator::toggleWidgets(bool active) +{ + CSVWorld::GenericCreator::toggleWidgets(active); + mCell->setEnabled(active); +} + +void CSVWorld::ReferenceCreator::cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type, const CSMWorld::UniversalId::ArgumentType argumentType) +{ + CSVWorld::GenericCreator::cloneMode(originid, type, argumentType); + cellChanged(); //otherwise ok button will remain disabled +} diff --git a/apps/opencs/view/world/referencecreator.hpp b/apps/opencs/view/world/referencecreator.hpp index 27f81564fd..2f0897026d 100644 --- a/apps/opencs/view/world/referencecreator.hpp +++ b/apps/opencs/view/world/referencecreator.hpp @@ -25,7 +25,12 @@ namespace CSVWorld ReferenceCreator (CSMWorld::Data& data, QUndoStack& undoStack, const CSMWorld::UniversalId& id); + virtual void cloneMode(const std::string& originid, + const CSMWorld::UniversalId::Type type, + const CSMWorld::UniversalId::ArgumentType argumentType); + virtual void reset(); + virtual void toggleWidgets(bool active = true); virtual std::string getErrors() const; ///< Return formatted error descriptions for the current state of the creator. if an empty From f390c7f4b0279cf64981e78dca3bfefe6316cf5b Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Thu, 23 Jan 2014 16:24:03 +0100 Subject: [PATCH 32/61] Disable widgets in the cell creator. --- apps/opencs/view/world/cellcreator.cpp | 8 +++++++- apps/opencs/view/world/cellcreator.hpp | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/opencs/view/world/cellcreator.cpp b/apps/opencs/view/world/cellcreator.cpp index 74fb068700..43af16c82e 100644 --- a/apps/opencs/view/world/cellcreator.cpp +++ b/apps/opencs/view/world/cellcreator.cpp @@ -78,4 +78,10 @@ void CSVWorld::CellCreator::setType (int index) void CSVWorld::CellCreator::valueChanged (int index) { update(); -} \ No newline at end of file +} + +void CSVWorld::CellCreator::toggleWidgets(bool active) +{ + CSVWorld::GenericCreator::toggleWidgets(active); + mType->setEnabled(active); +} diff --git a/apps/opencs/view/world/cellcreator.hpp b/apps/opencs/view/world/cellcreator.hpp index a5473e2c97..4e8705cb02 100644 --- a/apps/opencs/view/world/cellcreator.hpp +++ b/apps/opencs/view/world/cellcreator.hpp @@ -28,6 +28,8 @@ namespace CSVWorld CellCreator (CSMWorld::Data& data, QUndoStack& undoStack, const CSMWorld::UniversalId& id); virtual void reset(); + + virtual void toggleWidgets(bool active = true); private slots: From 01be9386d6521f2878daa7a6b89a319820baaddb Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Fri, 24 Jan 2014 11:22:20 +0100 Subject: [PATCH 33/61] Id to the coordinates with the boost and explicit specialisations of template member functions. --- apps/opencs/model/world/collection.hpp | 27 ++++++++++++++++++++++- apps/opencs/view/world/cellcreator.cpp | 14 +++++++++++- apps/opencs/view/world/cellcreator.hpp | 5 +++++ apps/opencs/view/world/tablebottombox.cpp | 2 +- 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index f97b5f5293..0a8dc5a9db 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -7,10 +7,13 @@ #include #include #include +#include +#include #include #include +#include #include "columnbase.hpp" @@ -50,6 +53,8 @@ namespace CSMWorld // not implemented Collection (const Collection&); Collection& operator= (const Collection&); + + void idToCoordiantes(Record& record, const std::string& destination) {} //dose nothing protected: @@ -150,7 +155,24 @@ namespace CSMWorld void setRecord (int index, const Record& record); ///< \attention This function must not change the ID. }; - + + template<> + class Collection > : public CollectionBase //explicit specialisation + { + void idToCoordiantes(Record& record, const std::string& destination) + { + if (record.get().isExterior()) + { + unsigned separator = destination.find(' '); + assert(separator != std::string::npos); + std::string xPos(destination.substr(0, separator)); + std::string yPos(destination.substr(separator+1, destination.size())); + record.get().mData.mX = boost::lexical_cast(xPos); + record.get().mData.mY = boost::lexical_cast(yPos); + } + } + }; + template const std::map& Collection::getIdMap() const { @@ -208,6 +230,9 @@ namespace CSMWorld copy.mState = RecordBase::State_ModifiedOnly; copy.get().mId = destination; + //the below function has explicit specialization for cells, and does nothing fo other records + idToCoordiantes(copy, destination); + insertRecord(copy, getAppendIndex(destination, type)); } diff --git a/apps/opencs/view/world/cellcreator.cpp b/apps/opencs/view/world/cellcreator.cpp index 43af16c82e..6298e3ba59 100644 --- a/apps/opencs/view/world/cellcreator.cpp +++ b/apps/opencs/view/world/cellcreator.cpp @@ -22,7 +22,7 @@ std::string CSVWorld::CellCreator::getId() const CSVWorld::CellCreator::CellCreator (CSMWorld::Data& data, QUndoStack& undoStack, const CSMWorld::UniversalId& id) -: GenericCreator (data, undoStack, id) +: GenericCreator (data, undoStack, id), mCloningExterior(false) { mY = new QSpinBox (this); mY->setVisible (false); @@ -80,6 +80,18 @@ void CSVWorld::CellCreator::valueChanged (int index) update(); } +void CSVWorld::CellCreator::cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type, const CSMWorld::UniversalId::ArgumentType argumentType) +{ + CSVWorld::GenericCreator::cloneMode(originid, type, argumentType); + if (*(originid.begin()) == '#') //if originid points to the exterior cell + { + setType(1); //enable x and y controls + } else { + setType(0); + } +} + + void CSVWorld::CellCreator::toggleWidgets(bool active) { CSVWorld::GenericCreator::toggleWidgets(active); diff --git a/apps/opencs/view/world/cellcreator.hpp b/apps/opencs/view/world/cellcreator.hpp index 4e8705cb02..521abd1735 100644 --- a/apps/opencs/view/world/cellcreator.hpp +++ b/apps/opencs/view/world/cellcreator.hpp @@ -19,6 +19,7 @@ namespace CSVWorld QLabel *mYLabel; QSpinBox *mY; + bool mCloningExterior; protected: virtual std::string getId() const; @@ -30,6 +31,10 @@ namespace CSVWorld virtual void reset(); virtual void toggleWidgets(bool active = true); + + virtual void cloneMode(const std::string& originid, + const CSMWorld::UniversalId::Type type, + const CSMWorld::UniversalId::ArgumentType argumentType); private slots: diff --git a/apps/opencs/view/world/tablebottombox.cpp b/apps/opencs/view/world/tablebottombox.cpp index ef20cf1d47..a6801b6fcc 100644 --- a/apps/opencs/view/world/tablebottombox.cpp +++ b/apps/opencs/view/world/tablebottombox.cpp @@ -164,9 +164,9 @@ void CSVWorld::TableBottomBox::cloneRequest(const std::string& id, const CSMWorld::UniversalId::ArgumentType argumnetType) { mCreator->reset(); - mCreator->toggleWidgets(false); mCreator->cloneMode(id, type, argumnetType); mLayout->setCurrentWidget(mCreator); + mCreator->toggleWidgets(false); setVisible (true); mCreating = true; } From 5ca59467603edd5f8723a72c47786e63e0012b81 Mon Sep 17 00:00:00 2001 From: gus Date: Fri, 24 Jan 2014 19:13:23 +0100 Subject: [PATCH 34/61] WIP --- apps/openmw/mwmechanics/aicombat.cpp | 3 ++- apps/openmw/mwmechanics/aifollow.cpp | 34 +++++++++++++++------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/apps/openmw/mwmechanics/aicombat.cpp b/apps/openmw/mwmechanics/aicombat.cpp index b9dc2f7db0..0eff943d44 100644 --- a/apps/openmw/mwmechanics/aicombat.cpp +++ b/apps/openmw/mwmechanics/aicombat.cpp @@ -97,7 +97,8 @@ namespace MWMechanics zAngle = Ogre::Radian( Ogre::Math::ACos(directionY / directionResult) * sgn(Ogre::Math::ASin(directionX / directionResult)) ).valueDegrees(); // TODO: use movement settings instead of rotating directly - MWBase::Environment::get().getWorld()->rotateObject(actor, 0, 0, zAngle, false); + //MWBase::Environment::get().getWorld()->rotateObject(actor, 0, 0, zAngle, false); + MWWorld::Class::get(actor).getMovementSettings(actor).mRotation[2] = 10*(Ogre::Degree(zAngle).valueRadians()-pos.rot[2]); mPathFinder.clearPath(); diff --git a/apps/openmw/mwmechanics/aifollow.cpp b/apps/openmw/mwmechanics/aifollow.cpp index 898f91e7c5..21a629d906 100644 --- a/apps/openmw/mwmechanics/aifollow.cpp +++ b/apps/openmw/mwmechanics/aifollow.cpp @@ -4,6 +4,8 @@ #include "../mwbase/environment.hpp" #include "../mwworld/class.hpp" #include "movement.hpp" + +#include MWMechanics::AiFollow::AiFollow(const std::string &actorId,float duration, float x, float y, float z) : mDuration(duration), mX(x), mY(y), mZ(z), mActorId(actorId), mCellId(""), mTimer(0), mStuckTimer(0) @@ -53,6 +55,15 @@ bool MWMechanics::AiFollow::execute (const MWWorld::Ptr& actor,float duration) dest.mY = target.getRefData().getPosition().pos[1]; dest.mZ = target.getRefData().getPosition().pos[2]; + ESM::Pathgrid::Point start; + start.mX = pos.pos[0]; + start.mY = pos.pos[1]; + start.mZ = pos.pos[2]; + + if(mPathFinder.getPath().empty()) + mPathFinder.buildPath(start, dest, actor.getCell(), true); + + if(mTimer > 0.25) { if(!mPathFinder.getPath().empty()) @@ -63,10 +74,8 @@ bool MWMechanics::AiFollow::execute (const MWWorld::Ptr& actor,float duration) +(dest.mY - lastPos.mY)*(dest.mY - lastPos.mY) +(dest.mZ - lastPos.mZ)*(dest.mZ - lastPos.mZ) > 100*100) - mPathFinder.addPointToPath(dest); + mPathFinder.addPointToPath(dest); } - else - mPathFinder.addPointToPath(dest); mTimer = 0; } @@ -75,27 +84,20 @@ bool MWMechanics::AiFollow::execute (const MWWorld::Ptr& actor,float duration) { if((mStuckPos.pos[0] - pos.pos[0])*(mStuckPos.pos[0] - pos.pos[0]) +(mStuckPos.pos[1] - pos.pos[1])*(mStuckPos.pos[1] - pos.pos[1]) - +(mStuckPos.pos[2] - pos.pos[2])*(mStuckPos.pos[2] - pos.pos[2]) - < 100) //NPC is stuck - { - ESM::Pathgrid::Point start; - start.mX = pos.pos[0]; - start.mY = pos.pos[1]; - start.mZ = pos.pos[2]; - + +(mStuckPos.pos[2] - pos.pos[2])*(mStuckPos.pos[2] - pos.pos[2]) < 100) //NPC is stuck mPathFinder.buildPath(start, dest, actor.getCell(), true); - } + mStuckTimer = 0; mStuckPos = pos; } - if(mPathFinder.getPath().empty()) - mPathFinder.addPointToPath(dest); - if(!mPathFinder.checkPathCompleted(pos.pos[0],pos.pos[1],pos.pos[2])) { float zAngle = mPathFinder.getZAngleToNext(pos.pos[0], pos.pos[1]); - MWBase::Environment::get().getWorld()->rotateObject(actor, 0, 0, zAngle, false); + //MWBase::Environment::get().getWorld()->rotateObject(actor, 0, 0, zAngle, false); + MWWorld::Class::get(actor).getMovementSettings(actor).mRotation[2] = 10*(Ogre::Degree(zAngle).valueRadians()-pos.rot[2]); + //std::cout << Ogre::Degree(zAngle).valueDegrees()-Ogre::Radian(actor.getRefData().getPosition().rot[2]).valueDegrees() << " "<< pos.rot[2] << " " << zAngle << "\n"; + //MWWorld::Class::get(actor).get } if((dest.mX - pos.pos[0])*(dest.mX - pos.pos[0])+(dest.mY - pos.pos[1])*(dest.mY - pos.pos[1])+(dest.mZ - pos.pos[2])*(dest.mZ - pos.pos[2]) From 032c542396758e6f71bccdd968476ab8dfa30652 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Fri, 24 Jan 2014 20:34:33 +0100 Subject: [PATCH 35/61] improving the cell cloning. --- apps/opencs/view/world/cellcreator.cpp | 9 +++++++-- apps/opencs/view/world/cellcreator.hpp | 1 - 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/opencs/view/world/cellcreator.cpp b/apps/opencs/view/world/cellcreator.cpp index 6298e3ba59..ebf88122b3 100644 --- a/apps/opencs/view/world/cellcreator.cpp +++ b/apps/opencs/view/world/cellcreator.cpp @@ -22,7 +22,7 @@ std::string CSVWorld::CellCreator::getId() const CSVWorld::CellCreator::CellCreator (CSMWorld::Data& data, QUndoStack& undoStack, const CSMWorld::UniversalId& id) -: GenericCreator (data, undoStack, id), mCloningExterior(false) +: GenericCreator (data, undoStack, id) { mY = new QSpinBox (this); mY->setVisible (false); @@ -61,6 +61,7 @@ void CSVWorld::CellCreator::reset() mX->setValue (0); mY->setValue (0); mType->setCurrentIndex (0); + setType(0); GenericCreator::reset(); } @@ -80,14 +81,18 @@ void CSVWorld::CellCreator::valueChanged (int index) update(); } -void CSVWorld::CellCreator::cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type, const CSMWorld::UniversalId::ArgumentType argumentType) +void CSVWorld::CellCreator::cloneMode(const std::string& originid, + const CSMWorld::UniversalId::Type type, + const CSMWorld::UniversalId::ArgumentType argumentType) { CSVWorld::GenericCreator::cloneMode(originid, type, argumentType); if (*(originid.begin()) == '#') //if originid points to the exterior cell { setType(1); //enable x and y controls + mType->setCurrentIndex(1); } else { setType(0); + mType->setCurrentIndex(0); } } diff --git a/apps/opencs/view/world/cellcreator.hpp b/apps/opencs/view/world/cellcreator.hpp index 521abd1735..3130c13280 100644 --- a/apps/opencs/view/world/cellcreator.hpp +++ b/apps/opencs/view/world/cellcreator.hpp @@ -19,7 +19,6 @@ namespace CSVWorld QLabel *mYLabel; QSpinBox *mY; - bool mCloningExterior; protected: virtual std::string getId() const; From 7cb47aa6350ad49ba7e4954463427a9308c2171c Mon Sep 17 00:00:00 2001 From: gus Date: Sun, 26 Jan 2014 21:26:19 +0100 Subject: [PATCH 36/61] new implementation of pathfinding. Works, but need clean up --- apps/openmw/mwmechanics/aifollow.cpp | 5 -- apps/openmw/mwmechanics/pathfinding.cpp | 110 +++++++++++++++++++++++- 2 files changed, 108 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwmechanics/aifollow.cpp b/apps/openmw/mwmechanics/aifollow.cpp index be57adadc2..10bff8356f 100644 --- a/apps/openmw/mwmechanics/aifollow.cpp +++ b/apps/openmw/mwmechanics/aifollow.cpp @@ -104,11 +104,6 @@ bool MWMechanics::AiFollow::execute (const MWWorld::Ptr& actor,float duration) return false; } - int MWMechanics::AiFollow::getTypeId() const -{ - return 3; -} - std::string MWMechanics::AiFollow::getFollowedActor() { return mActorId; diff --git a/apps/openmw/mwmechanics/pathfinding.cpp b/apps/openmw/mwmechanics/pathfinding.cpp index f8908fbd95..1b42b11a4a 100644 --- a/apps/openmw/mwmechanics/pathfinding.cpp +++ b/apps/openmw/mwmechanics/pathfinding.cpp @@ -6,6 +6,7 @@ #include "OgreMath.h" #include +#include namespace { @@ -132,6 +133,111 @@ namespace } } +namespace +{ + struct Edge + { + int destination; + float cost; + }; + struct Node + { + int label; + std::vector edges; + int parent;//used in pathfinding + }; + + std::list reconstructPath(const std::vector& graph,const ESM::Pathgrid* pathgrid, int lastNode,float xCell, float yCell) + { + std::list path; + while(graph[lastNode].parent != -1) + { + //std::cout << "not empty" << xCell; + ESM::Pathgrid::Point pt = pathgrid->mPoints[lastNode]; + pt.mX += xCell; + pt.mY += yCell; + path.push_front(pt); + lastNode = graph[lastNode].parent; + } + return path; + } + + std::list buildPath2(const ESM::Pathgrid* pathgrid,int start,int goal,float xCell = 0, float yCell = 0) + { + std::vector graph; + for(unsigned int i = 0; i < pathgrid->mPoints.size(); i++) + { + Node node; + node.label = i; + node.parent = -1; + graph.push_back(node); + } + for(unsigned int i = 0; i < pathgrid->mEdges.size(); i++) + { + Edge edge; + edge.destination = pathgrid->mEdges[i].mV1; + edge.cost = distance(pathgrid->mPoints[pathgrid->mEdges[i].mV0],pathgrid->mPoints[pathgrid->mEdges[i].mV1]); + graph[pathgrid->mEdges[i].mV0].edges.push_back(edge); + edge.destination = pathgrid->mEdges[i].mV0; + graph[pathgrid->mEdges[i].mV1].edges.push_back(edge); + } + + std::vector g_score(pathgrid->mPoints.size(),-1.); + std::vector f_score(pathgrid->mPoints.size(),-1.); + + g_score[start] = 0; + f_score[start] = distance(pathgrid->mPoints[start],pathgrid->mPoints[goal]); + + std::list openset; + std::list closedset; + openset.push_back(start); + + int current = -1; + + while(!openset.empty()) + { + current = openset.front(); + openset.pop_front(); + + if(current == goal) break; + + closedset.push_back(current); + + for(int j = 0;jmPoints[dest],pathgrid->mPoints[goal]); + if(!isInOpenSet) + { + std::list::iterator it = openset.begin(); + for(it = openset.begin();it!= openset.end();it++) + { + if(g_score[*it]>g_score[dest]) + break; + } + openset.insert(it,dest); + } + } + } + } + + } + return reconstructPath(graph,pathgrid,current,xCell,yCell); + + } + +} + namespace MWMechanics { PathFinder::PathFinder() @@ -183,9 +289,9 @@ namespace MWMechanics if(startNode != -1 && endNode != -1) { - if(!mIsGraphConstructed) buildPathgridGraph(pathGrid, xCell, yCell); + //if(!mIsGraphConstructed) buildPathgridGraph(pathGrid, xCell, yCell); - mPath = findPath(startNode, endNode, mGraph); + mPath = buildPath2(pathGrid,startNode,endNode,xCell,yCell);//findPath(startNode, endNode, mGraph); if(!mPath.empty()) { From 764011dd1b8a5856fc1a83a892d2fd4754f656e7 Mon Sep 17 00:00:00 2001 From: gus Date: Sun, 26 Jan 2014 21:53:55 +0100 Subject: [PATCH 37/61] clean up --- apps/openmw/mwmechanics/pathfinding.cpp | 201 +++++++++++++----------- apps/openmw/mwmechanics/pathfinding.hpp | 29 +++- 2 files changed, 129 insertions(+), 101 deletions(-) diff --git a/apps/openmw/mwmechanics/pathfinding.cpp b/apps/openmw/mwmechanics/pathfinding.cpp index 1b42b11a4a..dcf47ca337 100644 --- a/apps/openmw/mwmechanics/pathfinding.cpp +++ b/apps/openmw/mwmechanics/pathfinding.cpp @@ -5,30 +5,10 @@ #include "OgreMath.h" -#include #include namespace { - struct found_path {}; - - typedef boost::adjacency_list< boost::vecS, boost::vecS, boost::undirectedS, - boost::property, boost::property > - PathGridGraph; - typedef boost::property_map::type WeightMap; - typedef PathGridGraph::vertex_descriptor PointID; - typedef PathGridGraph::edge_descriptor PointConnectionID; - - class goalVisited : public boost::default_dijkstra_visitor - { - public: - goalVisited(PointID goal) {mGoal = goal;}; - void examine_vertex(PointID u, const PathGridGraph g) {if(u == mGoal) throw found_path();}; - - private: - PointID mGoal; - }; - float distanceZCorrected(ESM::Pathgrid::Point point, float x, float y, float z) { x -= point.mX; @@ -80,74 +60,7 @@ namespace return closestIndex; } - PathGridGraph buildGraph(const ESM::Pathgrid* pathgrid, float xCell = 0, float yCell = 0) - { - PathGridGraph graph; - - for(unsigned int counter = 0; counter < pathgrid->mPoints.size(); counter++) - { - PointID pID = boost::add_vertex(graph); - graph[pID].mX = pathgrid->mPoints[counter].mX + xCell; - graph[pID].mY = pathgrid->mPoints[counter].mY + yCell; - graph[pID].mZ = pathgrid->mPoints[counter].mZ; - } - - for(unsigned int counterTwo = 0; counterTwo < pathgrid->mEdges.size(); counterTwo++) - { - PointID u = pathgrid->mEdges[counterTwo].mV0; - PointID v = pathgrid->mEdges[counterTwo].mV1; - - PointConnectionID edge; - bool done; - boost::tie(edge, done) = boost::add_edge(u, v, graph); - WeightMap weightmap = boost::get(boost::edge_weight, graph); - weightmap[edge] = distance(graph[u], graph[v]); - } - - return graph; - } - - std::list findPath(PointID start, PointID end,const PathGridGraph& graph) - { - std::vector p(boost::num_vertices(graph)); - std::vector d(boost::num_vertices(graph)); - std::list shortest_path; - - try - { - boost::dijkstra_shortest_paths(graph, start, - boost::predecessor_map(&p[0]).distance_map(&d[0]).visitor(goalVisited(end))); - } - - catch(found_path& fg) - { - for(PointID v = end; ; v = p[v]) - { - shortest_path.push_front(graph[v]); - if(p[v] == v) - break; - } - } - - return shortest_path; - } -} - -namespace -{ - struct Edge - { - int destination; - float cost; - }; - struct Node - { - int label; - std::vector edges; - int parent;//used in pathfinding - }; - - std::list reconstructPath(const std::vector& graph,const ESM::Pathgrid* pathgrid, int lastNode,float xCell, float yCell) + /*std::list reconstructPath(const std::vector& graph,const ESM::Pathgrid* pathgrid, int lastNode,float xCell, float yCell) { std::list path; while(graph[lastNode].parent != -1) @@ -160,9 +73,11 @@ namespace lastNode = graph[lastNode].parent; } return path; - } + }*/ - std::list buildPath2(const ESM::Pathgrid* pathgrid,int start,int goal,float xCell = 0, float yCell = 0) + + + /*std::list buildPath2(const ESM::Pathgrid* pathgrid,int start,int goal,float xCell = 0, float yCell = 0) { std::vector graph; for(unsigned int i = 0; i < pathgrid->mPoints.size(); i++) @@ -234,7 +149,7 @@ namespace } return reconstructPath(graph,pathgrid,current,xCell,yCell); - } + }*/ } @@ -252,12 +167,108 @@ namespace MWMechanics mIsPathConstructed = false; } - void PathFinder::buildPathgridGraph(const ESM::Pathgrid* pathGrid,float xCell, float yCell) + void PathFinder::buildPathgridGraph(const ESM::Pathgrid* pathGrid) { - mGraph = buildGraph(pathGrid, xCell, yCell); + mGraph.clear(); + mGScore.resize(pathGrid->mPoints.size(),-1); + mFScore.resize(pathGrid->mPoints.size(),-1); + Node defaultNode; + defaultNode.label = -1; + defaultNode.parent = -1; + mGraph.resize(pathGrid->mPoints.size(),defaultNode); + for(unsigned int i = 0; i < pathGrid->mPoints.size(); i++) + { + Node node; + node.label = i; + node.parent = -1; + mGraph[i] = node; + } + for(unsigned int i = 0; i < pathGrid->mEdges.size(); i++) + { + Edge edge; + edge.destination = pathGrid->mEdges[i].mV1; + edge.cost = distance(pathGrid->mPoints[pathGrid->mEdges[i].mV0],pathGrid->mPoints[pathGrid->mEdges[i].mV1]); + mGraph[pathGrid->mEdges[i].mV0].edges.push_back(edge); + edge.destination = pathGrid->mEdges[i].mV0; + mGraph[pathGrid->mEdges[i].mV1].edges.push_back(edge); + } mIsGraphConstructed = true; } + void PathFinder::cleanUpAStar() + { + for(int i=0;i PathFinder::aStarSearch(const ESM::Pathgrid* pathGrid,int start,int goal,float xCell, float yCell) + { + cleanUpAStar(); + mGScore[start] = 0; + mFScore[start] = distance(pathGrid->mPoints[start],pathGrid->mPoints[goal]); + + std::list openset; + std::list closedset; + openset.push_back(start); + + int current = -1; + + while(!openset.empty()) + { + current = openset.front(); + openset.pop_front(); + + if(current == goal) break; + + closedset.push_back(current); + + for(int j = 0;jmPoints[dest],pathGrid->mPoints[goal]); + if(!isInOpenSet) + { + std::list::iterator it = openset.begin(); + for(it = openset.begin();it!= openset.end();it++) + { + if(mGScore[*it]>mGScore[dest]) + break; + } + openset.insert(it,dest); + } + } + } + } + + } + + std::list path; + while(mGraph[current].parent != -1) + { + //std::cout << "not empty" << xCell; + ESM::Pathgrid::Point pt = pathGrid->mPoints[current]; + pt.mX += xCell; + pt.mY += yCell; + path.push_front(pt); + current = mGraph[current].parent; + } + return path; + } + void PathFinder::buildPath(const ESM::Pathgrid::Point &startPoint, const ESM::Pathgrid::Point &endPoint, const MWWorld::CellStore* cell, bool allowShortcuts) { @@ -289,9 +300,9 @@ namespace MWMechanics if(startNode != -1 && endNode != -1) { - //if(!mIsGraphConstructed) buildPathgridGraph(pathGrid, xCell, yCell); + if(!mIsGraphConstructed) buildPathgridGraph(pathGrid); - mPath = buildPath2(pathGrid,startNode,endNode,xCell,yCell);//findPath(startNode, endNode, mGraph); + mPath = aStarSearch(pathGrid,startNode,endNode,xCell,yCell);//findPath(startNode, endNode, mGraph); if(!mPath.empty()) { diff --git a/apps/openmw/mwmechanics/pathfinding.hpp b/apps/openmw/mwmechanics/pathfinding.hpp index 6870314910..5bc9d7493f 100644 --- a/apps/openmw/mwmechanics/pathfinding.hpp +++ b/apps/openmw/mwmechanics/pathfinding.hpp @@ -19,7 +19,7 @@ namespace MWMechanics void clearPath(); - void buildPathgridGraph(const ESM::Pathgrid* pathGrid,float xCell = 0, float yCell = 0); + void buildPathgridGraph(const ESM::Pathgrid* pathGrid); void buildPath(const ESM::Pathgrid::Point &startPoint, const ESM::Pathgrid::Point &endPoint, const MWWorld::CellStore* cell, bool allowShortcuts = true); @@ -51,13 +51,30 @@ namespace MWMechanics } private: - std::list mPath; + + struct Edge + { + int destination; + float cost; + }; + struct Node + { + int label; + std::vector edges; + int parent;//used in pathfinding + }; + + std::vector mGScore; + std::vector mFScore; + + std::list aStarSearch(const ESM::Pathgrid* pathGrid,int start,int goal,float xCell = 0, float yCell = 0); + void cleanUpAStar(); + + std::vector mGraph; bool mIsPathConstructed; - typedef boost::adjacency_list< boost::vecS, boost::vecS, boost::undirectedS, - boost::property, boost::property > - PathGridGraph; - PathGridGraph mGraph; + + std::list mPath; bool mIsGraphConstructed; const MWWorld::CellStore* mCell; }; From f5d589388ccbb6ec02b22dd6d9d4a8a41627a65e Mon Sep 17 00:00:00 2001 From: gus Date: Sun, 26 Jan 2014 22:06:54 +0100 Subject: [PATCH 38/61] bug fix --- apps/openmw/mwmechanics/pathfinding.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/apps/openmw/mwmechanics/pathfinding.cpp b/apps/openmw/mwmechanics/pathfinding.cpp index dcf47ca337..668b4f2b14 100644 --- a/apps/openmw/mwmechanics/pathfinding.cpp +++ b/apps/openmw/mwmechanics/pathfinding.cpp @@ -266,6 +266,15 @@ namespace MWMechanics path.push_front(pt); current = mGraph[current].parent; } + + if(path.empty()) + { + ESM::Pathgrid::Point pt = pathGrid->mPoints[goal]; + pt.mX += xCell; + pt.mY += yCell; + path.push_front(pt); + } + return path; } From 62c2259c871de8826b83fd239bb4a229f8cc7db3 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 10:10:23 +0100 Subject: [PATCH 39/61] removing coordinates handling --- apps/opencs/model/world/collection.hpp | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index 0a8dc5a9db..d91260a5fa 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -8,7 +8,6 @@ #include #include #include -#include #include @@ -54,8 +53,6 @@ namespace CSMWorld Collection (const Collection&); Collection& operator= (const Collection&); - void idToCoordiantes(Record& record, const std::string& destination) {} //dose nothing - protected: const std::map& getIdMap() const; @@ -156,23 +153,6 @@ namespace CSMWorld ///< \attention This function must not change the ID. }; - template<> - class Collection > : public CollectionBase //explicit specialisation - { - void idToCoordiantes(Record& record, const std::string& destination) - { - if (record.get().isExterior()) - { - unsigned separator = destination.find(' '); - assert(separator != std::string::npos); - std::string xPos(destination.substr(0, separator)); - std::string yPos(destination.substr(separator+1, destination.size())); - record.get().mData.mX = boost::lexical_cast(xPos); - record.get().mData.mY = boost::lexical_cast(yPos); - } - } - }; - template const std::map& Collection::getIdMap() const { @@ -230,9 +210,6 @@ namespace CSMWorld copy.mState = RecordBase::State_ModifiedOnly; copy.get().mId = destination; - //the below function has explicit specialization for cells, and does nothing fo other records - idToCoordiantes(copy, destination); - insertRecord(copy, getAppendIndex(destination, type)); } From be8b978a89b182ada92eb46ae94ac0970c8038c4 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 12:23:03 +0100 Subject: [PATCH 40/61] corrected mistake in data --- apps/opencs/model/world/commands.cpp | 1 - apps/opencs/model/world/data.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 762e4809ca..789e65a21b 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -1,4 +1,3 @@ - #include "commands.hpp" #include diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index a52821036b..8d53c4e53a 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -164,7 +164,7 @@ CSMWorld::Data::Data() : mRefs (mCells) mTopicInfos.addColumn (new StringIdColumn (true)); mTopicInfos.addColumn (new RecordStateColumn); - mTopicInfos.addColumn (new FixedRecordTypeColumn (UniversalId::Type_Journal)); + mTopicInfos.addColumn (new FixedRecordTypeColumn (UniversalId::Type_TopicInfo)); mTopicInfos.addColumn (new TopicColumn (false)); mTopicInfos.addColumn (new ActorColumn); mTopicInfos.addColumn (new RaceColumn); From aa6d1ff4c3b4fa5d490c0a2468212ef9412bf928 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 13:08:14 +0100 Subject: [PATCH 41/61] removed needless argument for cloning --- apps/opencs/model/world/collection.hpp | 6 ++---- apps/opencs/model/world/collectionbase.hpp | 3 +-- apps/opencs/model/world/commands.cpp | 4 +--- apps/opencs/model/world/commands.hpp | 2 -- apps/opencs/model/world/idtable.cpp | 3 +-- apps/opencs/model/world/idtable.hpp | 1 - apps/opencs/model/world/refidcollection.cpp | 4 +--- apps/opencs/model/world/refidcollection.hpp | 3 +-- apps/opencs/view/world/cellcreator.cpp | 5 ++--- apps/opencs/view/world/cellcreator.hpp | 3 +-- apps/opencs/view/world/creator.hpp | 3 ++- apps/opencs/view/world/genericcreator.cpp | 6 ++---- apps/opencs/view/world/genericcreator.hpp | 3 +-- apps/opencs/view/world/referencecreator.cpp | 5 +++-- apps/opencs/view/world/referencecreator.hpp | 3 +-- apps/opencs/view/world/tablebottombox.cpp | 5 ++--- apps/opencs/view/world/tablebottombox.hpp | 3 ++- apps/opencs/view/world/tablesubview.cpp | 10 ++++++---- apps/opencs/view/world/tablesubview.hpp | 3 +-- 19 files changed, 30 insertions(+), 45 deletions(-) diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index d91260a5fa..4bb10c1d84 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -102,8 +102,7 @@ namespace CSMWorld virtual void cloneRecord(const std::string& origin, const std::string& destination, - const UniversalId::Type type, - const UniversalId::ArgumentType argumentType); + const UniversalId::Type type); virtual int searchId (const std::string& id) const; ////< Search record with \a id. @@ -203,8 +202,7 @@ namespace CSMWorld template void Collection::cloneRecord(const std::string& origin, const std::string& destination, - const UniversalId::Type type, - const UniversalId::ArgumentType argumentType) + const UniversalId::Type type) { Record copy(getRecord(origin)); copy.mState = RecordBase::State_ModifiedOnly; diff --git a/apps/opencs/model/world/collectionbase.hpp b/apps/opencs/model/world/collectionbase.hpp index d32847490b..2473ae741b 100644 --- a/apps/opencs/model/world/collectionbase.hpp +++ b/apps/opencs/model/world/collectionbase.hpp @@ -76,8 +76,7 @@ namespace CSMWorld virtual void cloneRecord(const std::string& origin, const std::string& destination, - const UniversalId::Type type, - const UniversalId::ArgumentType argumentType) = 0; + const UniversalId::Type type) = 0; virtual const RecordBase& getRecord (const std::string& id) const = 0; diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 789e65a21b..5eb2e94148 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -27,13 +27,11 @@ CSMWorld::CloneCommand::CloneCommand(CSMWorld::IdTable& model, const std::string& idOrigin, const std::string& IdDestination, const CSMWorld::UniversalId::Type type, - const CSMWorld::UniversalId::ArgumentType argumentType, QUndoCommand* parent) : QUndoCommand(parent), mModel(model), mIdOrigin(idOrigin), mIdDestination(Misc::StringUtils::lowerCase(IdDestination)), - mArgumentType(argumentType), mType(type) { setText(("Clone record " + idOrigin + " to the " + IdDestination).c_str()); @@ -42,7 +40,7 @@ CSMWorld::CloneCommand::CloneCommand(CSMWorld::IdTable& model, void CSMWorld::CloneCommand::redo() { - mModel.cloneRecord(mIdOrigin, mIdDestination, mArgumentType, mType); + mModel.cloneRecord(mIdOrigin, mIdDestination, mType); for (std::map::const_iterator iter(mValues.begin()); iter != mValues.end(); ++iter) mModel.setData(mModel.getModelIndex(mIdDestination, iter->first), iter->second); diff --git a/apps/opencs/model/world/commands.hpp b/apps/opencs/model/world/commands.hpp index 04eb0afbfe..0dedea0122 100644 --- a/apps/opencs/model/world/commands.hpp +++ b/apps/opencs/model/world/commands.hpp @@ -45,7 +45,6 @@ namespace CSMWorld std::string mIdOrigin; std::string mIdDestination; UniversalId::Type mType; - UniversalId::ArgumentType mArgumentType; std::map mValues; public: @@ -53,7 +52,6 @@ namespace CSMWorld CloneCommand (IdTable& model, const std::string& idOrigin, const std::string& IdDestination, const UniversalId::Type type, - const UniversalId::ArgumentType argumentType, QUndoCommand* parent = 0); virtual void redo(); diff --git a/apps/opencs/model/world/idtable.cpp b/apps/opencs/model/world/idtable.cpp index f131f7087a..bea307aa21 100644 --- a/apps/opencs/model/world/idtable.cpp +++ b/apps/opencs/model/world/idtable.cpp @@ -126,12 +126,11 @@ void CSMWorld::IdTable::addRecord (const std::string& id, UniversalId::Type type void CSMWorld::IdTable::cloneRecord(const std::string& origin, const std::string& destination, - CSMWorld::UniversalId::ArgumentType argumentType, CSMWorld::UniversalId::Type type) { int index = mIdCollection->getAppendIndex (destination); beginInsertRows (QModelIndex(), index, index); - mIdCollection->cloneRecord(origin, destination, type, argumentType); + mIdCollection->cloneRecord(origin, destination, type); endInsertRows(); } diff --git a/apps/opencs/model/world/idtable.hpp b/apps/opencs/model/world/idtable.hpp index ce47307e3c..2d620004cd 100644 --- a/apps/opencs/model/world/idtable.hpp +++ b/apps/opencs/model/world/idtable.hpp @@ -65,7 +65,6 @@ namespace CSMWorld void cloneRecord(const std::string& origin, const std::string& destination, - UniversalId::ArgumentType argumentType, UniversalId::Type type = UniversalId::Type_None); QModelIndex getModelIndex (const std::string& id, int column) const; diff --git a/apps/opencs/model/world/refidcollection.cpp b/apps/opencs/model/world/refidcollection.cpp index 75a1b681d2..5e8d381177 100644 --- a/apps/opencs/model/world/refidcollection.cpp +++ b/apps/opencs/model/world/refidcollection.cpp @@ -451,15 +451,13 @@ void CSMWorld::RefIdCollection::replace (int index, const RecordBase& record) void CSMWorld::RefIdCollection::cloneRecord(const std::string& origin, const std::string& destination, - const CSMWorld::UniversalId::Type type, - const CSMWorld::UniversalId::ArgumentType argumentType) + const CSMWorld::UniversalId::Type type) { RecordBase *newRecord = mData.getRecord(mData.searchId(origin)).clone(); newRecord->mState = RecordBase::State_ModifiedOnly; mAdapters.find(type)->second->setId(*newRecord, destination); mData.insertRecord(*newRecord, type, destination); delete newRecord; - //WIP } void CSMWorld::RefIdCollection::appendRecord (const RecordBase& record, diff --git a/apps/opencs/model/world/refidcollection.hpp b/apps/opencs/model/world/refidcollection.hpp index 4ad181004f..ebbf2100d9 100644 --- a/apps/opencs/model/world/refidcollection.hpp +++ b/apps/opencs/model/world/refidcollection.hpp @@ -71,8 +71,7 @@ namespace CSMWorld virtual void cloneRecord(const std::string& origin, const std::string& destination, - const UniversalId::Type type, - const UniversalId::ArgumentType argumentType); + const UniversalId::Type type); virtual void appendBlankRecord (const std::string& id, UniversalId::Type type); ///< \param type Will be ignored, unless the collection supports multiple record types diff --git a/apps/opencs/view/world/cellcreator.cpp b/apps/opencs/view/world/cellcreator.cpp index ebf88122b3..e65501e5f6 100644 --- a/apps/opencs/view/world/cellcreator.cpp +++ b/apps/opencs/view/world/cellcreator.cpp @@ -82,10 +82,9 @@ void CSVWorld::CellCreator::valueChanged (int index) } void CSVWorld::CellCreator::cloneMode(const std::string& originid, - const CSMWorld::UniversalId::Type type, - const CSMWorld::UniversalId::ArgumentType argumentType) + const CSMWorld::UniversalId::Type type) { - CSVWorld::GenericCreator::cloneMode(originid, type, argumentType); + CSVWorld::GenericCreator::cloneMode(originid, type); if (*(originid.begin()) == '#') //if originid points to the exterior cell { setType(1); //enable x and y controls diff --git a/apps/opencs/view/world/cellcreator.hpp b/apps/opencs/view/world/cellcreator.hpp index 3130c13280..472be43b94 100644 --- a/apps/opencs/view/world/cellcreator.hpp +++ b/apps/opencs/view/world/cellcreator.hpp @@ -32,8 +32,7 @@ namespace CSVWorld virtual void toggleWidgets(bool active = true); virtual void cloneMode(const std::string& originid, - const CSMWorld::UniversalId::Type type, - const CSMWorld::UniversalId::ArgumentType argumentType); + const CSMWorld::UniversalId::Type type); private slots: diff --git a/apps/opencs/view/world/creator.hpp b/apps/opencs/view/world/creator.hpp index 5174232bc2..9be619915d 100644 --- a/apps/opencs/view/world/creator.hpp +++ b/apps/opencs/view/world/creator.hpp @@ -25,7 +25,8 @@ namespace CSVWorld virtual void reset() = 0; - virtual void cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type, const CSMWorld::UniversalId::ArgumentType argumentType) = 0; + virtual void cloneMode(const std::string& originid, + const CSMWorld::UniversalId::Type type) = 0; virtual void setEditLock (bool locked) = 0; diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index 2a93f0e0f9..1f74b99540 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -127,7 +127,7 @@ void CSVWorld::GenericCreator::create() { std::string id = getId(); std::auto_ptr command (new CSMWorld::CloneCommand ( - dynamic_cast (*mData.getTableModel(mListId)), mClonedId, id, mClonedType, mArgumentType)); + dynamic_cast (*mData.getTableModel(mListId)), mClonedId, id, mClonedType)); mUndoStack.push(command.release()); @@ -150,13 +150,11 @@ void CSVWorld::GenericCreator::create() } void CSVWorld::GenericCreator::cloneMode(const std::string& originid, - const CSMWorld::UniversalId::Type type, - const CSMWorld::UniversalId::ArgumentType argumentType) + const CSMWorld::UniversalId::Type type) { mCloneMode = true; mClonedId = originid; mClonedType = type; - mArgumentType = argumentType; } void CSVWorld::GenericCreator::toggleWidgets(bool active) diff --git a/apps/opencs/view/world/genericcreator.hpp b/apps/opencs/view/world/genericcreator.hpp index 4870ba46c4..06b110b11c 100644 --- a/apps/opencs/view/world/genericcreator.hpp +++ b/apps/opencs/view/world/genericcreator.hpp @@ -67,8 +67,7 @@ namespace CSVWorld virtual void toggleWidgets (bool active = true); virtual void cloneMode(const std::string& originid, - const CSMWorld::UniversalId::Type type, - const CSMWorld::UniversalId::ArgumentType argumentType); + const CSMWorld::UniversalId::Type type); virtual std::string getErrors() const; ///< Return formatted error descriptions for the current state of the creator. if an empty diff --git a/apps/opencs/view/world/referencecreator.cpp b/apps/opencs/view/world/referencecreator.cpp index 6991ecf36d..069300f423 100644 --- a/apps/opencs/view/world/referencecreator.cpp +++ b/apps/opencs/view/world/referencecreator.cpp @@ -85,8 +85,9 @@ void CSVWorld::ReferenceCreator::toggleWidgets(bool active) mCell->setEnabled(active); } -void CSVWorld::ReferenceCreator::cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type, const CSMWorld::UniversalId::ArgumentType argumentType) +void CSVWorld::ReferenceCreator::cloneMode(const std::string& originid, + const CSMWorld::UniversalId::Type type) { - CSVWorld::GenericCreator::cloneMode(originid, type, argumentType); + CSVWorld::GenericCreator::cloneMode(originid, type); cellChanged(); //otherwise ok button will remain disabled } diff --git a/apps/opencs/view/world/referencecreator.hpp b/apps/opencs/view/world/referencecreator.hpp index 2f0897026d..96c1bec27e 100644 --- a/apps/opencs/view/world/referencecreator.hpp +++ b/apps/opencs/view/world/referencecreator.hpp @@ -26,8 +26,7 @@ namespace CSVWorld const CSMWorld::UniversalId& id); virtual void cloneMode(const std::string& originid, - const CSMWorld::UniversalId::Type type, - const CSMWorld::UniversalId::ArgumentType argumentType); + const CSMWorld::UniversalId::Type type); virtual void reset(); virtual void toggleWidgets(bool active = true); diff --git a/apps/opencs/view/world/tablebottombox.cpp b/apps/opencs/view/world/tablebottombox.cpp index a6801b6fcc..239c7410fb 100644 --- a/apps/opencs/view/world/tablebottombox.cpp +++ b/apps/opencs/view/world/tablebottombox.cpp @@ -160,11 +160,10 @@ void CSVWorld::TableBottomBox::createRequest() } void CSVWorld::TableBottomBox::cloneRequest(const std::string& id, - const CSMWorld::UniversalId::Type type, - const CSMWorld::UniversalId::ArgumentType argumnetType) + const CSMWorld::UniversalId::Type type) { mCreator->reset(); - mCreator->cloneMode(id, type, argumnetType); + mCreator->cloneMode(id, type); mLayout->setCurrentWidget(mCreator); mCreator->toggleWidgets(false); setVisible (true); diff --git a/apps/opencs/view/world/tablebottombox.hpp b/apps/opencs/view/world/tablebottombox.hpp index 29afa22772..8f0d851632 100644 --- a/apps/opencs/view/world/tablebottombox.hpp +++ b/apps/opencs/view/world/tablebottombox.hpp @@ -77,7 +77,8 @@ namespace CSVWorld /// \param modified Number of added and modified records void createRequest(); - void cloneRequest(const std::string& id, const CSMWorld::UniversalId::Type type, const CSMWorld::UniversalId::ArgumentType argumentType); + void cloneRequest(const std::string& id, + const CSMWorld::UniversalId::Type type); }; } diff --git a/apps/opencs/view/world/tablesubview.cpp b/apps/opencs/view/world/tablesubview.cpp index 3c71d13708..e4dbb64ed2 100644 --- a/apps/opencs/view/world/tablesubview.cpp +++ b/apps/opencs/view/world/tablesubview.cpp @@ -49,9 +49,11 @@ CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMDoc::D { connect (mTable, SIGNAL (createRequest()), mBottom, SLOT (createRequest())); - connect (mTable, SIGNAL (cloneRequest(const CSMWorld::UniversalId&)), this, SLOT(cloneRequest(const CSMWorld::UniversalId&))); - connect (this, SIGNAL(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type, const CSMWorld::UniversalId::ArgumentType)), - mBottom, SLOT(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type, const CSMWorld::UniversalId::ArgumentType))); + connect (mTable, SIGNAL (cloneRequest(const CSMWorld::UniversalId&)), this, + SLOT(cloneRequest(const CSMWorld::UniversalId&))); + + connect (this, SIGNAL(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type)), + mBottom, SLOT(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type))); } connect (mBottom, SIGNAL (requestFocus (const std::string&)), mTable, SLOT (requestFocus (const std::string&))); @@ -84,5 +86,5 @@ void CSVWorld::TableSubView::setStatusBar (bool show) void CSVWorld::TableSubView::cloneRequest(const CSMWorld::UniversalId& toClone) { - emit cloneRequest(toClone.getId(), toClone.getType(), toClone.getArgumentType()); + emit cloneRequest(toClone.getId(), toClone.getType()); } diff --git a/apps/opencs/view/world/tablesubview.hpp b/apps/opencs/view/world/tablesubview.hpp index b3a0a51626..9d2d005a88 100644 --- a/apps/opencs/view/world/tablesubview.hpp +++ b/apps/opencs/view/world/tablesubview.hpp @@ -41,8 +41,7 @@ namespace CSVWorld signals: void cloneRequest(const std::string&, - const CSMWorld::UniversalId::Type, - const CSMWorld::UniversalId::ArgumentType); + const CSMWorld::UniversalId::Type); private slots: From 71d63647546db1bf0e2b8adb189cbacb1f6ba1d7 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 13:13:39 +0100 Subject: [PATCH 42/61] Chaninging variables name to follow our policy. --- apps/opencs/view/world/cellcreator.cpp | 6 +++--- apps/opencs/view/world/cellcreator.hpp | 2 +- apps/opencs/view/world/creator.hpp | 2 +- apps/opencs/view/world/genericcreator.cpp | 4 ++-- apps/opencs/view/world/genericcreator.hpp | 2 +- apps/opencs/view/world/referencecreator.cpp | 4 ++-- apps/opencs/view/world/referencecreator.hpp | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/apps/opencs/view/world/cellcreator.cpp b/apps/opencs/view/world/cellcreator.cpp index e65501e5f6..cdeee56559 100644 --- a/apps/opencs/view/world/cellcreator.cpp +++ b/apps/opencs/view/world/cellcreator.cpp @@ -81,11 +81,11 @@ void CSVWorld::CellCreator::valueChanged (int index) update(); } -void CSVWorld::CellCreator::cloneMode(const std::string& originid, +void CSVWorld::CellCreator::cloneMode(const std::string& originId, const CSMWorld::UniversalId::Type type) { - CSVWorld::GenericCreator::cloneMode(originid, type); - if (*(originid.begin()) == '#') //if originid points to the exterior cell + CSVWorld::GenericCreator::cloneMode(originId, type); + if (*(originId.begin()) == '#') //if originid points to the exterior cell { setType(1); //enable x and y controls mType->setCurrentIndex(1); diff --git a/apps/opencs/view/world/cellcreator.hpp b/apps/opencs/view/world/cellcreator.hpp index 472be43b94..74bf5f76bf 100644 --- a/apps/opencs/view/world/cellcreator.hpp +++ b/apps/opencs/view/world/cellcreator.hpp @@ -31,7 +31,7 @@ namespace CSVWorld virtual void toggleWidgets(bool active = true); - virtual void cloneMode(const std::string& originid, + virtual void cloneMode(const std::string& originId, const CSMWorld::UniversalId::Type type); private slots: diff --git a/apps/opencs/view/world/creator.hpp b/apps/opencs/view/world/creator.hpp index 9be619915d..2d5e014e2d 100644 --- a/apps/opencs/view/world/creator.hpp +++ b/apps/opencs/view/world/creator.hpp @@ -25,7 +25,7 @@ namespace CSVWorld virtual void reset() = 0; - virtual void cloneMode(const std::string& originid, + virtual void cloneMode(const std::string& originId, const CSMWorld::UniversalId::Type type) = 0; virtual void setEditLock (bool locked) = 0; diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index 1f74b99540..9fb0b4b21f 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -149,11 +149,11 @@ void CSVWorld::GenericCreator::create() } } -void CSVWorld::GenericCreator::cloneMode(const std::string& originid, +void CSVWorld::GenericCreator::cloneMode(const std::string& originId, const CSMWorld::UniversalId::Type type) { mCloneMode = true; - mClonedId = originid; + mClonedId = originId; mClonedType = type; } diff --git a/apps/opencs/view/world/genericcreator.hpp b/apps/opencs/view/world/genericcreator.hpp index 06b110b11c..98dd12ac27 100644 --- a/apps/opencs/view/world/genericcreator.hpp +++ b/apps/opencs/view/world/genericcreator.hpp @@ -66,7 +66,7 @@ namespace CSVWorld virtual void toggleWidgets (bool active = true); - virtual void cloneMode(const std::string& originid, + virtual void cloneMode(const std::string& originId, const CSMWorld::UniversalId::Type type); virtual std::string getErrors() const; diff --git a/apps/opencs/view/world/referencecreator.cpp b/apps/opencs/view/world/referencecreator.cpp index 069300f423..384b59fc4c 100644 --- a/apps/opencs/view/world/referencecreator.cpp +++ b/apps/opencs/view/world/referencecreator.cpp @@ -85,9 +85,9 @@ void CSVWorld::ReferenceCreator::toggleWidgets(bool active) mCell->setEnabled(active); } -void CSVWorld::ReferenceCreator::cloneMode(const std::string& originid, +void CSVWorld::ReferenceCreator::cloneMode(const std::string& originId, const CSMWorld::UniversalId::Type type) { - CSVWorld::GenericCreator::cloneMode(originid, type); + CSVWorld::GenericCreator::cloneMode(originId, type); cellChanged(); //otherwise ok button will remain disabled } diff --git a/apps/opencs/view/world/referencecreator.hpp b/apps/opencs/view/world/referencecreator.hpp index 96c1bec27e..73b0899e54 100644 --- a/apps/opencs/view/world/referencecreator.hpp +++ b/apps/opencs/view/world/referencecreator.hpp @@ -25,7 +25,7 @@ namespace CSVWorld ReferenceCreator (CSMWorld::Data& data, QUndoStack& undoStack, const CSMWorld::UniversalId& id); - virtual void cloneMode(const std::string& originid, + virtual void cloneMode(const std::string& originId, const CSMWorld::UniversalId::Type type); virtual void reset(); From bb62efc3d844171b1b77b517424871fb3f6de73b Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 13:36:01 +0100 Subject: [PATCH 43/61] Removed pointless includes. --- apps/opencs/model/world/commands.cpp | 1 + apps/opencs/view/world/genericcreator.cpp | 1 - apps/opencs/view/world/table.cpp | 1 - 3 files changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 5eb2e94148..789c5d9b85 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -1,3 +1,4 @@ + #include "commands.hpp" #include diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index 9fb0b4b21f..c1faa741d2 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -2,7 +2,6 @@ #include "genericcreator.hpp" #include -#include #include #include diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index d343f9986a..f166171fe2 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -16,7 +16,6 @@ #include "recordstatusdelegate.hpp" #include "util.hpp" -#include void CSVWorld::Table::contextMenuEvent (QContextMenuEvent *event) { From 6a0b5defd78e2e8e38a05c2c16c68c6ba37403d7 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 13:41:37 +0100 Subject: [PATCH 44/61] removed needless member value. --- apps/opencs/model/world/commands.cpp | 3 +-- apps/opencs/view/world/genericcreator.cpp | 12 +++++++++--- apps/opencs/view/world/genericcreator.hpp | 1 - 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 789c5d9b85..d3ef7128f8 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -1,9 +1,8 @@ #include "commands.hpp" - #include -#include #include "idtable.hpp" +#include CSMWorld::ModifyCommand::ModifyCommand(QAbstractItemModel& model, const QModelIndex& index, const QVariant& new_, QUndoCommand* parent) diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index c1faa741d2..447c07424c 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -57,9 +57,15 @@ const CSMWorld::UniversalId& CSVWorld::GenericCreator::getCollectionId() const } CSVWorld::GenericCreator::GenericCreator (CSMWorld::Data& data, QUndoStack& undoStack, - const CSMWorld::UniversalId& id, bool relaxedIdRules) -: mData (data), mUndoStack (undoStack), mListId (id), mLocked (false), mCloneMode(false), mClonedType(CSMWorld::UniversalId::Type_None), -mArgumentType(CSMWorld::UniversalId::ArgumentType_None) + const CSMWorld::UniversalId& id, bool relaxedIdRules): + + mData (data), + mUndoStack (undoStack), + mListId (id), + mLocked (false), + mCloneMode(false), + mClonedType(CSMWorld::UniversalId::Type_None) + { mLayout = new QHBoxLayout; mLayout->setContentsMargins (0, 0, 0, 0); diff --git a/apps/opencs/view/world/genericcreator.hpp b/apps/opencs/view/world/genericcreator.hpp index 98dd12ac27..0f426e1a79 100644 --- a/apps/opencs/view/world/genericcreator.hpp +++ b/apps/opencs/view/world/genericcreator.hpp @@ -31,7 +31,6 @@ namespace CSVWorld bool mLocked; std::string mClonedId; CSMWorld::UniversalId::Type mClonedType; - CSMWorld::UniversalId::ArgumentType mArgumentType; protected: bool mCloneMode; From 2899f04a3f11ab4821143e69ccbd9807c54b0302 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 14:43:12 +0100 Subject: [PATCH 45/61] reformatting --- apps/opencs/model/world/collection.hpp | 3 ++- apps/opencs/model/world/commands.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index 4bb10c1d84..2905589285 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -204,7 +204,8 @@ namespace CSMWorld const std::string& destination, const UniversalId::Type type) { - Record copy(getRecord(origin)); + Record copy; + copy = getRecord(origin); copy.mState = RecordBase::State_ModifiedOnly; copy.get().mId = destination; diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index d3ef7128f8..5ca169fcd1 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -1,7 +1,8 @@ #include "commands.hpp" -#include + #include "idtable.hpp" +#include #include CSMWorld::ModifyCommand::ModifyCommand(QAbstractItemModel& model, const QModelIndex& index, From 4d6fb31610cd65dcf9d7d07d0dfea4118fd299e5 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 14:45:07 +0100 Subject: [PATCH 46/61] reformating --- apps/opencs/model/world/commands.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 5ca169fcd1..3b70f6940b 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -1,8 +1,10 @@ #include "commands.hpp" -#include "idtable.hpp" #include + +#include "idtable.hpp" + #include CSMWorld::ModifyCommand::ModifyCommand(QAbstractItemModel& model, const QModelIndex& index, @@ -38,7 +40,6 @@ CSMWorld::CloneCommand::CloneCommand(CSMWorld::IdTable& model, setText(("Clone record " + idOrigin + " to the " + IdDestination).c_str()); } - void CSMWorld::CloneCommand::redo() { mModel.cloneRecord(mIdOrigin, mIdDestination, mType); From 316debb8277d6e4b851dc8a85be6efb1c0d248bc Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 14:46:58 +0100 Subject: [PATCH 47/61] reformating --- apps/opencs/model/world/commands.cpp | 56 ++++++++++++++-------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 3b70f6940b..9159b1f162 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -26,34 +26,6 @@ void CSMWorld::ModifyCommand::undo() mModel.setData(mIndex, mOld); } -CSMWorld::CloneCommand::CloneCommand(CSMWorld::IdTable& model, - const std::string& idOrigin, - const std::string& IdDestination, - const CSMWorld::UniversalId::Type type, - QUndoCommand* parent) : - QUndoCommand(parent), - mModel(model), - mIdOrigin(idOrigin), - mIdDestination(Misc::StringUtils::lowerCase(IdDestination)), - mType(type) -{ - setText(("Clone record " + idOrigin + " to the " + IdDestination).c_str()); -} - -void CSMWorld::CloneCommand::redo() -{ - mModel.cloneRecord(mIdOrigin, mIdDestination, mType); - - for (std::map::const_iterator iter(mValues.begin()); iter != mValues.end(); ++iter) - mModel.setData(mModel.getModelIndex(mIdDestination, iter->first), iter->second); -} - -void CSMWorld::CloneCommand::undo() -{ - mModel.removeRow(mModel.getModelIndex(mIdDestination, 0).row()); -} - - CSMWorld::CreateCommand::CreateCommand(IdTable& model, const std::string& id, QUndoCommand* parent) : QUndoCommand(parent), mModel(model), mId(id), mType(UniversalId::Type_None) { @@ -174,4 +146,32 @@ void CSMWorld::ReorderRowsCommand::undo() mModel.reorderRows(mBaseIndex, reverse); } + +CSMWorld::CloneCommand::CloneCommand(CSMWorld::IdTable& model, + const std::string& idOrigin, + const std::string& IdDestination, + const CSMWorld::UniversalId::Type type, + QUndoCommand* parent) : + QUndoCommand(parent), + mModel(model), + mIdOrigin(idOrigin), + mIdDestination(Misc::StringUtils::lowerCase(IdDestination)), + mType(type) +{ + setText(("Clone record " + idOrigin + " to the " + IdDestination).c_str()); +} + +void CSMWorld::CloneCommand::redo() +{ + mModel.cloneRecord(mIdOrigin, mIdDestination, mType); + + for (std::map::const_iterator iter(mValues.begin()); iter != mValues.end(); ++iter) + mModel.setData(mModel.getModelIndex(mIdDestination, iter->first), iter->second); +} + +void CSMWorld::CloneCommand::undo() +{ + mModel.removeRow(mModel.getModelIndex(mIdDestination, 0).row()); +} + // kate: indent-mode cstyle; indent-width 4; replace-tabs on; From 2b71568bb65b9e7f80cb4d43c813dbeb50bb0cb6 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 14:50:36 +0100 Subject: [PATCH 48/61] still reformating --- apps/opencs/model/world/commands.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 9159b1f162..9a9e246f5a 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -3,6 +3,7 @@ #include + #include "idtable.hpp" #include From 52176d6435baee3b092fe21e72be85dcdbe089cf Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 14:51:57 +0100 Subject: [PATCH 49/61] reforfucking --- apps/opencs/model/world/commands.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 9a9e246f5a..80a751ac6e 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -3,9 +3,7 @@ #include - #include "idtable.hpp" - #include CSMWorld::ModifyCommand::ModifyCommand(QAbstractItemModel& model, const QModelIndex& index, From c91ae86084df5f86af4734ec7617e5d09dc180dd Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 14:53:39 +0100 Subject: [PATCH 50/61] is there something that can generate diff from two git branches? Using github for this is kinda annoying. --- apps/opencs/model/world/commands.cpp | 118 +++++++++++++-------------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 80a751ac6e..4b36b1b638 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -6,60 +6,60 @@ #include "idtable.hpp" #include -CSMWorld::ModifyCommand::ModifyCommand(QAbstractItemModel& model, const QModelIndex& index, - const QVariant& new_, QUndoCommand* parent) - : QUndoCommand(parent), mModel(model), mIndex(index), mNew(new_) +CSMWorld::ModifyCommand::ModifyCommand (QAbstractItemModel& model, const QModelIndex& index, + const QVariant& new_, QUndoCommand* parent) + : QUndoCommand (parent), mModel (model), mIndex (index), mNew (new_) { - mOld = mModel.data(mIndex, Qt::EditRole); + mOld = mModel.data (mIndex, Qt::EditRole); - setText("Modify " + mModel.headerData(mIndex.column(), Qt::Horizontal, Qt::DisplayRole).toString()); + setText ("Modify " + mModel.headerData (mIndex.column(), Qt::Horizontal, Qt::DisplayRole).toString()); } void CSMWorld::ModifyCommand::redo() { - mModel.setData(mIndex, mNew); + mModel.setData (mIndex, mNew); } void CSMWorld::ModifyCommand::undo() { - mModel.setData(mIndex, mOld); + mModel.setData (mIndex, mOld); } -CSMWorld::CreateCommand::CreateCommand(IdTable& model, const std::string& id, QUndoCommand* parent) - : QUndoCommand(parent), mModel(model), mId(id), mType(UniversalId::Type_None) +CSMWorld::CreateCommand::CreateCommand (IdTable& model, const std::string& id, QUndoCommand* parent) + : QUndoCommand (parent), mModel (model), mId (id), mType (UniversalId::Type_None) { - setText(("Create record " + id).c_str()); + setText ( ("Create record " + id).c_str()); } -void CSMWorld::CreateCommand::addValue(int column, const QVariant& value) +void CSMWorld::CreateCommand::addValue (int column, const QVariant& value) { mValues[column] = value; } -void CSMWorld::CreateCommand::setType(UniversalId::Type type) +void CSMWorld::CreateCommand::setType (UniversalId::Type type) { mType = type; } void CSMWorld::CreateCommand::redo() { - mModel.addRecord(mId, mType); + mModel.addRecord (mId, mType); - for (std::map::const_iterator iter(mValues.begin()); iter != mValues.end(); ++iter) - mModel.setData(mModel.getModelIndex(mId, iter->first), iter->second); + for (std::map::const_iterator iter (mValues.begin()); iter != mValues.end(); ++iter) + mModel.setData (mModel.getModelIndex (mId, iter->first), iter->second); } void CSMWorld::CreateCommand::undo() { - mModel.removeRow(mModel.getModelIndex(mId, 0).row()); + mModel.removeRow (mModel.getModelIndex (mId, 0).row()); } -CSMWorld::RevertCommand::RevertCommand(IdTable& model, const std::string& id, QUndoCommand* parent) - : QUndoCommand(parent), mModel(model), mId(id), mOld(0) +CSMWorld::RevertCommand::RevertCommand (IdTable& model, const std::string& id, QUndoCommand* parent) + : QUndoCommand (parent), mModel (model), mId (id), mOld (0) { - setText(("Revert record " + id).c_str()); + setText ( ("Revert record " + id).c_str()); - mOld = model.getRecord(id).clone(); + mOld = model.getRecord (id).clone(); } CSMWorld::RevertCommand::~RevertCommand() @@ -69,32 +69,32 @@ CSMWorld::RevertCommand::~RevertCommand() void CSMWorld::RevertCommand::redo() { - int column = mModel.findColumnIndex(Columns::ColumnId_Modification); + int column = mModel.findColumnIndex (Columns::ColumnId_Modification); - QModelIndex index = mModel.getModelIndex(mId, column); - RecordBase::State state = static_cast(mModel.data(index).toInt()); + QModelIndex index = mModel.getModelIndex (mId, column); + RecordBase::State state = static_cast (mModel.data (index).toInt()); if (state == RecordBase::State_ModifiedOnly) { - mModel.removeRows(index.row(), 1); + mModel.removeRows (index.row(), 1); } else { - mModel.setData(index, static_cast(RecordBase::State_BaseOnly)); + mModel.setData (index, static_cast (RecordBase::State_BaseOnly)); } } void CSMWorld::RevertCommand::undo() { - mModel.setRecord(mId, *mOld); + mModel.setRecord (mId, *mOld); } -CSMWorld::DeleteCommand::DeleteCommand(IdTable& model, const std::string& id, QUndoCommand* parent) - : QUndoCommand(parent), mModel(model), mId(id), mOld(0) +CSMWorld::DeleteCommand::DeleteCommand (IdTable& model, const std::string& id, QUndoCommand* parent) + : QUndoCommand (parent), mModel (model), mId (id), mOld (0) { - setText(("Delete record " + id).c_str()); + setText ( ("Delete record " + id).c_str()); - mOld = model.getRecord(id).clone(); + mOld = model.getRecord (id).clone(); } CSMWorld::DeleteCommand::~DeleteCommand() @@ -104,73 +104,73 @@ CSMWorld::DeleteCommand::~DeleteCommand() void CSMWorld::DeleteCommand::redo() { - int column = mModel.findColumnIndex(Columns::ColumnId_Modification); + int column = mModel.findColumnIndex (Columns::ColumnId_Modification); - QModelIndex index = mModel.getModelIndex(mId, column); - RecordBase::State state = static_cast(mModel.data(index).toInt()); + QModelIndex index = mModel.getModelIndex (mId, column); + RecordBase::State state = static_cast (mModel.data (index).toInt()); if (state == RecordBase::State_ModifiedOnly) { - mModel.removeRows(index.row(), 1); + mModel.removeRows (index.row(), 1); } else { - mModel.setData(index, static_cast(RecordBase::State_Deleted)); + mModel.setData (index, static_cast (RecordBase::State_Deleted)); } } void CSMWorld::DeleteCommand::undo() { - mModel.setRecord(mId, *mOld); + mModel.setRecord (mId, *mOld); } -CSMWorld::ReorderRowsCommand::ReorderRowsCommand(IdTable& model, int baseIndex, +CSMWorld::ReorderRowsCommand::ReorderRowsCommand (IdTable& model, int baseIndex, const std::vector& newOrder) - : mModel(model), mBaseIndex(baseIndex), mNewOrder(newOrder) + : mModel (model), mBaseIndex (baseIndex), mNewOrder (newOrder) {} void CSMWorld::ReorderRowsCommand::redo() { - mModel.reorderRows(mBaseIndex, mNewOrder); + mModel.reorderRows (mBaseIndex, mNewOrder); } void CSMWorld::ReorderRowsCommand::undo() { - int size = static_cast(mNewOrder.size()); - std::vector reverse(size); + int size = static_cast (mNewOrder.size()); + std::vector reverse (size); for (int i = 0; i < size; ++i) - reverse.at(mNewOrder[i]) = i; + reverse.at (mNewOrder[i]) = i; - mModel.reorderRows(mBaseIndex, reverse); + mModel.reorderRows (mBaseIndex, reverse); } -CSMWorld::CloneCommand::CloneCommand(CSMWorld::IdTable& model, - const std::string& idOrigin, - const std::string& IdDestination, - const CSMWorld::UniversalId::Type type, - QUndoCommand* parent) : - QUndoCommand(parent), - mModel(model), - mIdOrigin(idOrigin), - mIdDestination(Misc::StringUtils::lowerCase(IdDestination)), - mType(type) +CSMWorld::CloneCommand::CloneCommand (CSMWorld::IdTable& model, + const std::string& idOrigin, + const std::string& IdDestination, + const CSMWorld::UniversalId::Type type, + QUndoCommand* parent) : + QUndoCommand (parent), + mModel (model), + mIdOrigin (idOrigin), + mIdDestination (Misc::StringUtils::lowerCase (IdDestination)), + mType (type) { - setText(("Clone record " + idOrigin + " to the " + IdDestination).c_str()); + setText ( ("Clone record " + idOrigin + " to the " + IdDestination).c_str()); } void CSMWorld::CloneCommand::redo() { - mModel.cloneRecord(mIdOrigin, mIdDestination, mType); - - for (std::map::const_iterator iter(mValues.begin()); iter != mValues.end(); ++iter) - mModel.setData(mModel.getModelIndex(mIdDestination, iter->first), iter->second); + mModel.cloneRecord (mIdOrigin, mIdDestination, mType); + + for (std::map::const_iterator iter (mValues.begin()); iter != mValues.end(); ++iter) + mModel.setData (mModel.getModelIndex (mIdDestination, iter->first), iter->second); } void CSMWorld::CloneCommand::undo() { - mModel.removeRow(mModel.getModelIndex(mIdDestination, 0).row()); + mModel.removeRow (mModel.getModelIndex (mIdDestination, 0).row()); } // kate: indent-mode cstyle; indent-width 4; replace-tabs on; From 51115fa5be719a1ad02e03ee7d4cc6b78f665382 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 14:56:57 +0100 Subject: [PATCH 51/61] spaces around operators --- apps/opencs/model/world/commands.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 4b36b1b638..1bb1cf2b2c 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -170,7 +170,7 @@ void CSMWorld::CloneCommand::redo() void CSMWorld::CloneCommand::undo() { - mModel.removeRow (mModel.getModelIndex (mIdDestination, 0).row()); + mModel.removeRow (mModel.getModelIndex (mIdDestination, 0).row()); //should be enough } // kate: indent-mode cstyle; indent-width 4; replace-tabs on; From 84e07c95b1d375d0b03d68c6fa1076d39f5e5bf7 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 15:02:29 +0100 Subject: [PATCH 52/61] formatting --- apps/opencs/model/world/commands.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 1bb1cf2b2c..a544baee3d 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -8,7 +8,7 @@ CSMWorld::ModifyCommand::ModifyCommand (QAbstractItemModel& model, const QModelIndex& index, const QVariant& new_, QUndoCommand* parent) - : QUndoCommand (parent), mModel (model), mIndex (index), mNew (new_) +: QUndoCommand (parent), mModel (model), mIndex (index), mNew (new_) { mOld = mModel.data (mIndex, Qt::EditRole); @@ -26,9 +26,9 @@ void CSMWorld::ModifyCommand::undo() } CSMWorld::CreateCommand::CreateCommand (IdTable& model, const std::string& id, QUndoCommand* parent) - : QUndoCommand (parent), mModel (model), mId (id), mType (UniversalId::Type_None) +: QUndoCommand (parent), mModel (model), mId (id), mType (UniversalId::Type_None) { - setText ( ("Create record " + id).c_str()); + setText (("Create record " + id).c_str()); } void CSMWorld::CreateCommand::addValue (int column, const QVariant& value) @@ -45,7 +45,7 @@ void CSMWorld::CreateCommand::redo() { mModel.addRecord (mId, mType); - for (std::map::const_iterator iter (mValues.begin()); iter != mValues.end(); ++iter) + for (std::map::const_iterator iter (mValues.begin()); iter!=mValues.end(); ++iter) mModel.setData (mModel.getModelIndex (mId, iter->first), iter->second); } @@ -55,9 +55,9 @@ void CSMWorld::CreateCommand::undo() } CSMWorld::RevertCommand::RevertCommand (IdTable& model, const std::string& id, QUndoCommand* parent) - : QUndoCommand (parent), mModel (model), mId (id), mOld (0) +: QUndoCommand (parent), mModel (model), mId (id), mOld (0) { - setText ( ("Revert record " + id).c_str()); + setText (("Revert record " + id).c_str()); mOld = model.getRecord (id).clone(); } @@ -74,7 +74,7 @@ void CSMWorld::RevertCommand::redo() QModelIndex index = mModel.getModelIndex (mId, column); RecordBase::State state = static_cast (mModel.data (index).toInt()); - if (state == RecordBase::State_ModifiedOnly) + if (state==RecordBase::State_ModifiedOnly) { mModel.removeRows (index.row(), 1); } @@ -90,9 +90,9 @@ void CSMWorld::RevertCommand::undo() } CSMWorld::DeleteCommand::DeleteCommand (IdTable& model, const std::string& id, QUndoCommand* parent) - : QUndoCommand (parent), mModel (model), mId (id), mOld (0) +: QUndoCommand (parent), mModel (model), mId (id), mOld (0) { - setText ( ("Delete record " + id).c_str()); + setText (("Delete record " + id).c_str()); mOld = model.getRecord (id).clone(); } @@ -109,7 +109,7 @@ void CSMWorld::DeleteCommand::redo() QModelIndex index = mModel.getModelIndex (mId, column); RecordBase::State state = static_cast (mModel.data (index).toInt()); - if (state == RecordBase::State_ModifiedOnly) + if (state==RecordBase::State_ModifiedOnly) { mModel.removeRows (index.row(), 1); } @@ -127,7 +127,7 @@ void CSMWorld::DeleteCommand::undo() CSMWorld::ReorderRowsCommand::ReorderRowsCommand (IdTable& model, int baseIndex, const std::vector& newOrder) - : mModel (model), mBaseIndex (baseIndex), mNewOrder (newOrder) +: mModel (model), mBaseIndex (baseIndex), mNewOrder (newOrder) {} void CSMWorld::ReorderRowsCommand::redo() @@ -140,7 +140,7 @@ void CSMWorld::ReorderRowsCommand::undo() int size = static_cast (mNewOrder.size()); std::vector reverse (size); - for (int i = 0; i < size; ++i) + for (int i=0; i < size; ++i) reverse.at (mNewOrder[i]) = i; mModel.reorderRows (mBaseIndex, reverse); From 9c579dbd6c4b4fea3dd72bf9e446d6d74d00bfb1 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 15:03:29 +0100 Subject: [PATCH 53/61] ok, that should be enough --- apps/opencs/model/world/commands.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index a544baee3d..5526d74186 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -140,7 +140,7 @@ void CSMWorld::ReorderRowsCommand::undo() int size = static_cast (mNewOrder.size()); std::vector reverse (size); - for (int i=0; i < size; ++i) + for (int i=0; i< size; ++i) reverse.at (mNewOrder[i]) = i; mModel.reorderRows (mBaseIndex, reverse); From ed0ba906cfbfd72a7b41b3dbd48db12b9cc05023 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 15:05:29 +0100 Subject: [PATCH 54/61] removed needless include --- apps/opencs/view/world/tablesubview.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/opencs/view/world/tablesubview.cpp b/apps/opencs/view/world/tablesubview.cpp index e4dbb64ed2..5495c708fc 100644 --- a/apps/opencs/view/world/tablesubview.cpp +++ b/apps/opencs/view/world/tablesubview.cpp @@ -6,7 +6,6 @@ #include "../../model/doc/document.hpp" #include "../filter/filterbox.hpp" -#include "../../model/world/idtable.hpp" #include "table.hpp" #include "tablebottombox.hpp" #include "creator.hpp" From 846276f747c7ff62712e8224ba5c442b2b508c21 Mon Sep 17 00:00:00 2001 From: gus Date: Mon, 27 Jan 2014 15:14:24 +0100 Subject: [PATCH 55/61] clean up --- apps/openmw/mwmechanics/actors.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index ed3c343a5c..38b11c0ac4 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -927,7 +927,7 @@ namespace MWMechanics const MWWorld::Class &cls = MWWorld::Class::get(iter->first); CreatureStats &stats = cls.getCreatureStats(iter->first); - if(stats.getAiSequence().getTypeId() == 3) + if(stats.getAiSequence().getTypeId() == AiPackage::TypeIdFollow) { MWMechanics::AiFollow* package = static_cast(stats.getAiSequence().getActivePackage()); if(package->getFollowedActor() == actor.getCellRef().mRefID) From d0b07de7efd4b77c105112cc495d1040b33261af Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 16:59:18 +0100 Subject: [PATCH 56/61] Corrected bug mentioned by zini. --- apps/opencs/model/world/collection.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index 2905589285..64b950e609 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -205,7 +205,7 @@ namespace CSMWorld const UniversalId::Type type) { Record copy; - copy = getRecord(origin); + copy.mModified = getRecord(origin).get(); copy.mState = RecordBase::State_ModifiedOnly; copy.get().mId = destination; From c82db915f17922d03b68a33de3a85b4e427b0c01 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 19:32:51 +0100 Subject: [PATCH 57/61] Removed needless includes --- apps/opencs/model/world/collection.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index 64b950e609..9fc97d580e 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -7,12 +7,10 @@ #include #include #include -#include #include #include -#include #include "columnbase.hpp" From 62ea0bb06685aefff34329c19486222714a94934 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 19:40:05 +0100 Subject: [PATCH 58/61] Cleared whitespaces. --- apps/opencs/model/world/collection.hpp | 12 ++++++------ apps/opencs/model/world/collectionbase.hpp | 2 +- apps/opencs/model/world/commands.hpp | 4 ++-- apps/opencs/model/world/idtable.hpp | 2 +- apps/opencs/model/world/refidcollection.hpp | 2 +- apps/opencs/view/world/cellcreator.hpp | 4 ++-- apps/opencs/view/world/creator.hpp | 4 ++-- apps/opencs/view/world/genericcreator.cpp | 6 +++--- apps/opencs/view/world/genericcreator.hpp | 6 +++--- apps/opencs/view/world/referencecreator.cpp | 4 ++-- apps/opencs/view/world/referencecreator.hpp | 2 +- apps/opencs/view/world/table.cpp | 2 +- apps/opencs/view/world/tablesubview.cpp | 6 +++--- apps/opencs/view/world/tablesubview.hpp | 4 ++-- 14 files changed, 30 insertions(+), 30 deletions(-) diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index 9fc97d580e..d342e88a47 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -50,7 +50,7 @@ namespace CSMWorld // not implemented Collection (const Collection&); Collection& operator= (const Collection&); - + protected: const std::map& getIdMap() const; @@ -97,11 +97,11 @@ namespace CSMWorld virtual void appendBlankRecord (const std::string& id, UniversalId::Type type = UniversalId::Type_None); ///< \param type Will be ignored, unless the collection supports multiple record types - + virtual void cloneRecord(const std::string& origin, const std::string& destination, const UniversalId::Type type); - + virtual int searchId (const std::string& id) const; ////< Search record with \a id. /// \return index of record (if found) or -1 (not found) @@ -149,7 +149,7 @@ namespace CSMWorld void setRecord (int index, const Record& record); ///< \attention This function must not change the ID. }; - + template const std::map& Collection::getIdMap() const { @@ -206,10 +206,10 @@ namespace CSMWorld copy.mModified = getRecord(origin).get(); copy.mState = RecordBase::State_ModifiedOnly; copy.get().mId = destination; - + insertRecord(copy, getAppendIndex(destination, type)); } - + template Collection::Collection() {} diff --git a/apps/opencs/model/world/collectionbase.hpp b/apps/opencs/model/world/collectionbase.hpp index 2473ae741b..408a89d923 100644 --- a/apps/opencs/model/world/collectionbase.hpp +++ b/apps/opencs/model/world/collectionbase.hpp @@ -77,7 +77,7 @@ namespace CSMWorld virtual void cloneRecord(const std::string& origin, const std::string& destination, const UniversalId::Type type) = 0; - + virtual const RecordBase& getRecord (const std::string& id) const = 0; virtual const RecordBase& getRecord (int index) const = 0; diff --git a/apps/opencs/model/world/commands.hpp b/apps/opencs/model/world/commands.hpp index 0dedea0122..ec6350658f 100644 --- a/apps/opencs/model/world/commands.hpp +++ b/apps/opencs/model/world/commands.hpp @@ -53,12 +53,12 @@ namespace CSMWorld const std::string& IdDestination, const UniversalId::Type type, QUndoCommand* parent = 0); - + virtual void redo(); virtual void undo(); }; - + class CreateCommand : public QUndoCommand { IdTable& mModel; diff --git a/apps/opencs/model/world/idtable.hpp b/apps/opencs/model/world/idtable.hpp index 2d620004cd..74923867d6 100644 --- a/apps/opencs/model/world/idtable.hpp +++ b/apps/opencs/model/world/idtable.hpp @@ -66,7 +66,7 @@ namespace CSMWorld void cloneRecord(const std::string& origin, const std::string& destination, UniversalId::Type type = UniversalId::Type_None); - + QModelIndex getModelIndex (const std::string& id, int column) const; void setRecord (const std::string& id, const RecordBase& record); diff --git a/apps/opencs/model/world/refidcollection.hpp b/apps/opencs/model/world/refidcollection.hpp index ebbf2100d9..5e973b4477 100644 --- a/apps/opencs/model/world/refidcollection.hpp +++ b/apps/opencs/model/world/refidcollection.hpp @@ -72,7 +72,7 @@ namespace CSMWorld virtual void cloneRecord(const std::string& origin, const std::string& destination, const UniversalId::Type type); - + virtual void appendBlankRecord (const std::string& id, UniversalId::Type type); ///< \param type Will be ignored, unless the collection supports multiple record types diff --git a/apps/opencs/view/world/cellcreator.hpp b/apps/opencs/view/world/cellcreator.hpp index 74bf5f76bf..db9fbf8a34 100644 --- a/apps/opencs/view/world/cellcreator.hpp +++ b/apps/opencs/view/world/cellcreator.hpp @@ -28,9 +28,9 @@ namespace CSVWorld CellCreator (CSMWorld::Data& data, QUndoStack& undoStack, const CSMWorld::UniversalId& id); virtual void reset(); - + virtual void toggleWidgets(bool active = true); - + virtual void cloneMode(const std::string& originId, const CSMWorld::UniversalId::Type type); diff --git a/apps/opencs/view/world/creator.hpp b/apps/opencs/view/world/creator.hpp index 2d5e014e2d..88da70330d 100644 --- a/apps/opencs/view/world/creator.hpp +++ b/apps/opencs/view/world/creator.hpp @@ -24,12 +24,12 @@ namespace CSVWorld virtual ~Creator(); virtual void reset() = 0; - + virtual void cloneMode(const std::string& originId, const CSMWorld::UniversalId::Type type) = 0; virtual void setEditLock (bool locked) = 0; - + virtual void toggleWidgets(bool active = true) = 0; signals: diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index 447c07424c..cd7a5fa189 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -57,15 +57,15 @@ const CSMWorld::UniversalId& CSVWorld::GenericCreator::getCollectionId() const } CSVWorld::GenericCreator::GenericCreator (CSMWorld::Data& data, QUndoStack& undoStack, - const CSMWorld::UniversalId& id, bool relaxedIdRules): - + const CSMWorld::UniversalId& id, bool relaxedIdRules): + mData (data), mUndoStack (undoStack), mListId (id), mLocked (false), mCloneMode(false), mClonedType(CSMWorld::UniversalId::Type_None) - + { mLayout = new QHBoxLayout; mLayout->setContentsMargins (0, 0, 0, 0); diff --git a/apps/opencs/view/world/genericcreator.hpp b/apps/opencs/view/world/genericcreator.hpp index 0f426e1a79..6cc39cf23b 100644 --- a/apps/opencs/view/world/genericcreator.hpp +++ b/apps/opencs/view/world/genericcreator.hpp @@ -31,10 +31,10 @@ namespace CSVWorld bool mLocked; std::string mClonedId; CSMWorld::UniversalId::Type mClonedType; - + protected: bool mCloneMode; - + protected: void update(); @@ -49,7 +49,7 @@ namespace CSVWorld virtual std::string getId() const; virtual void configureCreateCommand (CSMWorld::CreateCommand& command) const; - + CSMWorld::Data& getData() const; const CSMWorld::UniversalId& getCollectionId() const; diff --git a/apps/opencs/view/world/referencecreator.cpp b/apps/opencs/view/world/referencecreator.cpp index 384b59fc4c..6b8e02da0d 100644 --- a/apps/opencs/view/world/referencecreator.cpp +++ b/apps/opencs/view/world/referencecreator.cpp @@ -53,9 +53,9 @@ std::string CSVWorld::ReferenceCreator::getErrors() const { return errors; } - + std::string cell = mCell->text().toUtf8().constData(); - + if (cell.empty()) { if (!errors.empty()) diff --git a/apps/opencs/view/world/referencecreator.hpp b/apps/opencs/view/world/referencecreator.hpp index 73b0899e54..12fb12dd90 100644 --- a/apps/opencs/view/world/referencecreator.hpp +++ b/apps/opencs/view/world/referencecreator.hpp @@ -27,7 +27,7 @@ namespace CSVWorld virtual void cloneMode(const std::string& originId, const CSMWorld::UniversalId::Type type); - + virtual void reset(); virtual void toggleWidgets(bool active = true); diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index f166171fe2..8f6fc46a88 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -203,7 +203,7 @@ CSVWorld::Table::Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, Q mCreateAction = new QAction (tr ("Add Record"), this); connect (mCreateAction, SIGNAL (triggered()), this, SIGNAL (createRequest())); addAction (mCreateAction); - + mCloneAction = new QAction (tr ("Clone Record"), this); connect(mCloneAction, SIGNAL (triggered()), this, SLOT (cloneRecord())); addAction(mCloneAction); diff --git a/apps/opencs/view/world/tablesubview.cpp b/apps/opencs/view/world/tablesubview.cpp index 5495c708fc..981faaf591 100644 --- a/apps/opencs/view/world/tablesubview.cpp +++ b/apps/opencs/view/world/tablesubview.cpp @@ -47,11 +47,11 @@ CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMDoc::D if (mBottom->canCreateAndDelete()) { connect (mTable, SIGNAL (createRequest()), mBottom, SLOT (createRequest())); - + connect (mTable, SIGNAL (cloneRequest(const CSMWorld::UniversalId&)), this, SLOT(cloneRequest(const CSMWorld::UniversalId&))); - - connect (this, SIGNAL(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type)), + + connect (this, SIGNAL(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type)), mBottom, SLOT(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type))); } connect (mBottom, SIGNAL (requestFocus (const std::string&)), diff --git a/apps/opencs/view/world/tablesubview.hpp b/apps/opencs/view/world/tablesubview.hpp index 9d2d005a88..d728dc2f38 100644 --- a/apps/opencs/view/world/tablesubview.hpp +++ b/apps/opencs/view/world/tablesubview.hpp @@ -38,9 +38,9 @@ namespace CSVWorld virtual void updateEditorSetting (const QString& key, const QString& value); virtual void setStatusBar (bool show); - + signals: - void cloneRequest(const std::string&, + void cloneRequest(const std::string&, const CSMWorld::UniversalId::Type); private slots: From d3000ce0990a05f89fd212b138107edfb10b20ba Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 19:47:54 +0100 Subject: [PATCH 59/61] whitespaces removed again. --- apps/opencs/view/world/genericcreator.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/opencs/view/world/genericcreator.hpp b/apps/opencs/view/world/genericcreator.hpp index 6cc39cf23b..714853f986 100644 --- a/apps/opencs/view/world/genericcreator.hpp +++ b/apps/opencs/view/world/genericcreator.hpp @@ -62,12 +62,12 @@ namespace CSVWorld virtual void setEditLock (bool locked); virtual void reset(); - + virtual void toggleWidgets (bool active = true); virtual void cloneMode(const std::string& originId, const CSMWorld::UniversalId::Type type); - + virtual std::string getErrors() const; ///< Return formatted error descriptions for the current state of the creator. if an empty /// string is returned, there is no error. From 2bd98a69ab487062ec9d54efccde89ce9b8e6929 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Tue, 28 Jan 2014 11:16:48 +0100 Subject: [PATCH 60/61] Corrections, according to the comments. Thanks for the review. :-) --- apps/opencs/model/world/commands.cpp | 6 ++---- apps/opencs/model/world/refidcollection.cpp | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 5526d74186..b60ffeb29c 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -170,7 +170,5 @@ void CSMWorld::CloneCommand::redo() void CSMWorld::CloneCommand::undo() { - mModel.removeRow (mModel.getModelIndex (mIdDestination, 0).row()); //should be enough -} - -// kate: indent-mode cstyle; indent-width 4; replace-tabs on; + mModel.removeRow (mModel.getModelIndex (mIdDestination, 0).row()); +} \ No newline at end of file diff --git a/apps/opencs/model/world/refidcollection.cpp b/apps/opencs/model/world/refidcollection.cpp index 5e8d381177..5d310208ac 100644 --- a/apps/opencs/model/world/refidcollection.cpp +++ b/apps/opencs/model/world/refidcollection.cpp @@ -2,6 +2,7 @@ #include "refidcollection.hpp" #include +#include #include @@ -453,11 +454,10 @@ void CSMWorld::RefIdCollection::cloneRecord(const std::string& origin, const std::string& destination, const CSMWorld::UniversalId::Type type) { - RecordBase *newRecord = mData.getRecord(mData.searchId(origin)).clone(); + std::auto_ptr newRecord(mData.getRecord(mData.searchId(origin)).clone()); newRecord->mState = RecordBase::State_ModifiedOnly; mAdapters.find(type)->second->setId(*newRecord, destination); mData.insertRecord(*newRecord, type, destination); - delete newRecord; } void CSMWorld::RefIdCollection::appendRecord (const RecordBase& record, From a473c3f6193b311ae84cf963034f144e20795c72 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 28 Jan 2014 12:36:10 +0100 Subject: [PATCH 61/61] some cleanup --- apps/openmw/mwmechanics/aitravel.cpp | 8 -------- apps/openmw/mwmechanics/pathfinding.cpp | 8 ++++---- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/apps/openmw/mwmechanics/aitravel.cpp b/apps/openmw/mwmechanics/aitravel.cpp index ba75cb4186..9a1b98d8ff 100644 --- a/apps/openmw/mwmechanics/aitravel.cpp +++ b/apps/openmw/mwmechanics/aitravel.cpp @@ -66,14 +66,6 @@ namespace MWMechanics { cellX = cell->mData.mX; cellY = cell->mData.mY; - float xCell = 0; - float yCell = 0; - - if(cell->isExterior()) - { - xCell = cell->mData.mX * ESM::Land::REAL_SIZE; - yCell = cell->mData.mY * ESM::Land::REAL_SIZE; - } ESM::Pathgrid::Point dest; dest.mX = mX; diff --git a/apps/openmw/mwmechanics/pathfinding.cpp b/apps/openmw/mwmechanics/pathfinding.cpp index 668b4f2b14..1ead89040a 100644 --- a/apps/openmw/mwmechanics/pathfinding.cpp +++ b/apps/openmw/mwmechanics/pathfinding.cpp @@ -117,7 +117,7 @@ namespace if(current == goal) break; closedset.push_back(current); - + for(int j = 0;j (mGraph.size());i++) { mGraph[i].parent = -1; mGScore[i] = -1; @@ -225,8 +225,8 @@ namespace MWMechanics if(current == goal) break; closedset.push_back(current); - - for(int j = 0;j (mGraph[current].edges.size());j++) { //int next = mGraph[current].edges[j].destination if(std::find(closedset.begin(),closedset.end(),mGraph[current].edges[j].destination) == closedset.end())