mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-20 08:23:51 +00:00
Id to the coordinates with the boost and explicit specialisations of template member functions.
This commit is contained in:
parent
f390c7f4b0
commit
01be9386d6
4 changed files with 45 additions and 3 deletions
|
@ -7,10 +7,13 @@
|
|||
#include <cctype>
|
||||
#include <stdexcept>
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#include <QVariant>
|
||||
|
||||
#include <components/misc/stringops.hpp>
|
||||
#include <components/esm/loadcell.hpp>
|
||||
|
||||
#include "columnbase.hpp"
|
||||
|
||||
|
@ -50,6 +53,8 @@ namespace CSMWorld
|
|||
// not implemented
|
||||
Collection (const Collection&);
|
||||
Collection& operator= (const Collection&);
|
||||
|
||||
void idToCoordiantes(Record<ESXRecordT>& record, const std::string& destination) {} //dose nothing
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -150,7 +155,24 @@ namespace CSMWorld
|
|||
void setRecord (int index, const Record<ESXRecordT>& record);
|
||||
///< \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>
|
||||
const std::map<std::string, int>& Collection<ESXRecordT, IdAccessorT>::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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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:
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue