1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-04 03:40:14 +00:00

Id to the coordinates with the boost and explicit specialisations of template member functions.

This commit is contained in:
Marek Kochanowicz 2014-01-24 11:22:20 +01:00
parent f390c7f4b0
commit 01be9386d6
4 changed files with 45 additions and 3 deletions

View File

@ -7,10 +7,13 @@
#include <cctype> #include <cctype>
#include <stdexcept> #include <stdexcept>
#include <functional> #include <functional>
#include <cassert>
#include <boost/lexical_cast.hpp>
#include <QVariant> #include <QVariant>
#include <components/misc/stringops.hpp> #include <components/misc/stringops.hpp>
#include <components/esm/loadcell.hpp>
#include "columnbase.hpp" #include "columnbase.hpp"
@ -50,6 +53,8 @@ namespace CSMWorld
// not implemented // not implemented
Collection (const Collection&); Collection (const Collection&);
Collection& operator= (const Collection&); Collection& operator= (const Collection&);
void idToCoordiantes(Record<ESXRecordT>& record, const std::string& destination) {} //dose nothing
protected: protected:
@ -150,7 +155,24 @@ namespace CSMWorld
void setRecord (int index, const Record<ESXRecordT>& record); void setRecord (int index, const Record<ESXRecordT>& record);
///< \attention This function must not change the ID. ///< \attention This function must not change the ID.
}; };
template<>
class Collection <ESM::Cell, IdAccessor<ESM::Cell> > : public CollectionBase //explicit specialisation
{
void idToCoordiantes(Record<ESM::Cell>& 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<int>(xPos);
record.get().mData.mY = boost::lexical_cast<int>(yPos);
}
}
};
template<typename ESXRecordT, typename IdAccessorT> template<typename ESXRecordT, typename IdAccessorT>
const std::map<std::string, int>& Collection<ESXRecordT, IdAccessorT>::getIdMap() const const std::map<std::string, int>& Collection<ESXRecordT, IdAccessorT>::getIdMap() const
{ {
@ -208,6 +230,9 @@ namespace CSMWorld
copy.mState = RecordBase::State_ModifiedOnly; copy.mState = RecordBase::State_ModifiedOnly;
copy.get().mId = destination; 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)); insertRecord(copy, getAppendIndex(destination, type));
} }

View File

@ -22,7 +22,7 @@ std::string CSVWorld::CellCreator::getId() const
CSVWorld::CellCreator::CellCreator (CSMWorld::Data& data, QUndoStack& undoStack, CSVWorld::CellCreator::CellCreator (CSMWorld::Data& data, QUndoStack& undoStack,
const CSMWorld::UniversalId& id) const CSMWorld::UniversalId& id)
: GenericCreator (data, undoStack, id) : GenericCreator (data, undoStack, id), mCloningExterior(false)
{ {
mY = new QSpinBox (this); mY = new QSpinBox (this);
mY->setVisible (false); mY->setVisible (false);
@ -80,6 +80,18 @@ void CSVWorld::CellCreator::valueChanged (int index)
update(); 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) void CSVWorld::CellCreator::toggleWidgets(bool active)
{ {
CSVWorld::GenericCreator::toggleWidgets(active); CSVWorld::GenericCreator::toggleWidgets(active);

View File

@ -19,6 +19,7 @@ namespace CSVWorld
QLabel *mYLabel; QLabel *mYLabel;
QSpinBox *mY; QSpinBox *mY;
bool mCloningExterior;
protected: protected:
virtual std::string getId() const; virtual std::string getId() const;
@ -30,6 +31,10 @@ namespace CSVWorld
virtual void reset(); virtual void reset();
virtual void toggleWidgets(bool active = true); 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: private slots:

View File

@ -164,9 +164,9 @@ void CSVWorld::TableBottomBox::cloneRequest(const std::string& id,
const CSMWorld::UniversalId::ArgumentType argumnetType) const CSMWorld::UniversalId::ArgumentType argumnetType)
{ {
mCreator->reset(); mCreator->reset();
mCreator->toggleWidgets(false);
mCreator->cloneMode(id, type, argumnetType); mCreator->cloneMode(id, type, argumnetType);
mLayout->setCurrentWidget(mCreator); mLayout->setCurrentWidget(mCreator);
mCreator->toggleWidgets(false);
setVisible (true); setVisible (true);
mCreating = true; mCreating = true;
} }