diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index f97b5f529..0a8dc5a9d 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 43af16c82..6298e3ba5 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 4e8705cb0..521abd173 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 ef20cf1d4..a6801b6fc 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; }