2015-04-09 09:29:03 +00:00
|
|
|
#ifndef CSM_WOLRD_IDADAPTERIMP_H
|
|
|
|
#define CSM_WOLRD_IDADAPTERIMP_H
|
|
|
|
|
|
|
|
#include <QVariant>
|
|
|
|
|
|
|
|
#include <components/esm/loadpgrd.hpp>
|
2015-04-11 05:55:26 +00:00
|
|
|
#include <components/esm/loadregn.hpp>
|
2015-04-11 07:51:30 +00:00
|
|
|
#include <components/esm/loadfact.hpp>
|
2015-04-09 09:29:03 +00:00
|
|
|
|
|
|
|
#include "idadapter.hpp"
|
2015-04-11 03:54:05 +00:00
|
|
|
#include "nestedtablewrapper.hpp"
|
2015-04-09 09:29:03 +00:00
|
|
|
|
|
|
|
namespace CSMWorld
|
|
|
|
{
|
|
|
|
template<typename ESXRecordT>
|
|
|
|
class PathgridPointListAdapter : public NestedIdAdapter<ESXRecordT>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PathgridPointListAdapter () {}
|
|
|
|
|
|
|
|
virtual void addNestedRow(Record<ESXRecordT>& record, int position) const
|
|
|
|
{
|
|
|
|
ESXRecordT pathgrid = record.get();
|
|
|
|
|
2015-04-09 10:15:38 +00:00
|
|
|
ESM::Pathgrid::PointList& points = pathgrid.mPoints;
|
2015-04-09 09:29:03 +00:00
|
|
|
|
|
|
|
// blank row
|
|
|
|
ESM::Pathgrid::Point point;
|
|
|
|
point.mX = 0;
|
|
|
|
point.mY = 0;
|
|
|
|
point.mZ = 0;
|
|
|
|
point.mAutogenerated = 0;
|
|
|
|
point.mConnectionNum = 0;
|
|
|
|
point.mUnknown = 0;
|
|
|
|
|
2015-04-09 11:23:02 +00:00
|
|
|
// inserting a point should trigger re-indexing of the edges
|
2015-04-09 21:31:01 +00:00
|
|
|
//
|
|
|
|
// FIXME: undo does not restore edges table view
|
|
|
|
// FIXME: does not auto refresh edges table view
|
2015-04-09 11:23:02 +00:00
|
|
|
std::vector<ESM::Pathgrid::Edge>::iterator iter = pathgrid.mEdges.begin();
|
|
|
|
for (;iter != pathgrid.mEdges.end(); ++iter)
|
|
|
|
{
|
2015-04-09 11:41:46 +00:00
|
|
|
if ((*iter).mV0 >= position)
|
2015-04-09 11:23:02 +00:00
|
|
|
(*iter).mV0++;
|
2015-04-09 11:41:46 +00:00
|
|
|
if ((*iter).mV1 >= position)
|
2015-04-09 11:23:02 +00:00
|
|
|
(*iter).mV1++;
|
|
|
|
}
|
|
|
|
|
2015-04-09 09:29:03 +00:00
|
|
|
points.insert(points.begin()+position, point);
|
|
|
|
pathgrid.mData.mS2 += 1; // increment the number of points
|
|
|
|
|
|
|
|
record.setModified (pathgrid);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void removeNestedRow(Record<ESXRecordT>& record, int rowToRemove) const
|
|
|
|
{
|
|
|
|
ESXRecordT pathgrid = record.get();
|
|
|
|
|
2015-04-09 10:15:38 +00:00
|
|
|
ESM::Pathgrid::PointList& points = pathgrid.mPoints;
|
2015-04-09 09:29:03 +00:00
|
|
|
|
|
|
|
if (rowToRemove < 0 || rowToRemove >= static_cast<int> (points.size()))
|
|
|
|
throw std::runtime_error ("index out of range");
|
|
|
|
|
2015-04-09 11:23:02 +00:00
|
|
|
// deleting a point should trigger re-indexing of the edges
|
|
|
|
// dangling edges are not allowed and hence removed
|
2015-04-09 21:31:01 +00:00
|
|
|
//
|
|
|
|
// FIXME: undo does not restore edges table view
|
|
|
|
// FIXME: does not auto refresh edges table view
|
2015-04-09 11:23:02 +00:00
|
|
|
std::vector<ESM::Pathgrid::Edge>::iterator iter = pathgrid.mEdges.begin();
|
2015-04-09 21:31:01 +00:00
|
|
|
for (; iter != pathgrid.mEdges.end();)
|
2015-04-09 11:23:02 +00:00
|
|
|
{
|
|
|
|
if (((*iter).mV0 == rowToRemove) || ((*iter).mV1 == rowToRemove))
|
2015-04-09 21:31:01 +00:00
|
|
|
iter = pathgrid.mEdges.erase(iter);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((*iter).mV0 > rowToRemove)
|
|
|
|
(*iter).mV0--;
|
2015-04-09 11:23:02 +00:00
|
|
|
|
2015-04-09 21:31:01 +00:00
|
|
|
if ((*iter).mV1 > rowToRemove)
|
|
|
|
(*iter).mV1--;
|
2015-04-09 11:23:02 +00:00
|
|
|
|
2015-04-09 21:31:01 +00:00
|
|
|
++iter;
|
|
|
|
}
|
2015-04-09 11:23:02 +00:00
|
|
|
}
|
2015-04-09 09:29:03 +00:00
|
|
|
points.erase(points.begin()+rowToRemove);
|
|
|
|
pathgrid.mData.mS2 -= 1; // decrement the number of points
|
|
|
|
|
|
|
|
record.setModified (pathgrid);
|
|
|
|
}
|
|
|
|
|
2015-04-10 05:28:09 +00:00
|
|
|
struct PathgridPointsWrap : public NestedTableWrapperBase
|
|
|
|
{
|
|
|
|
ESM::Pathgrid mRecord;
|
|
|
|
|
|
|
|
PathgridPointsWrap(ESM::Pathgrid pathgrid)
|
|
|
|
: mRecord(pathgrid) {}
|
|
|
|
|
|
|
|
virtual ~PathgridPointsWrap() {}
|
|
|
|
|
|
|
|
virtual int size() const
|
|
|
|
{
|
|
|
|
return mRecord.mPoints.size(); // used in IdTree::setNestedTable()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-04-11 01:26:29 +00:00
|
|
|
virtual void setNestedTable(Record<ESXRecordT>& record, const NestedTableWrapperBase& nestedTable) const
|
2015-04-09 09:29:03 +00:00
|
|
|
{
|
|
|
|
record.get().mPoints =
|
2015-04-10 05:28:09 +00:00
|
|
|
static_cast<const PathgridPointsWrap &>(nestedTable).mRecord.mPoints;
|
|
|
|
record.get().mData.mS2 =
|
|
|
|
static_cast<const PathgridPointsWrap &>(nestedTable).mRecord.mData.mS2;
|
|
|
|
// also update edges in case points were added/removed
|
|
|
|
record.get().mEdges =
|
|
|
|
static_cast<const PathgridPointsWrap &>(nestedTable).mRecord.mEdges;
|
2015-04-09 09:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual NestedTableWrapperBase* nestedTable(const Record<ESXRecordT>& record) const
|
|
|
|
{
|
|
|
|
// deleted by dtor of NestedTableStoring
|
2015-04-10 05:28:09 +00:00
|
|
|
return new PathgridPointsWrap(record.get());
|
2015-04-09 09:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual QVariant getNestedData(const Record<ESXRecordT>& record, int subRowIndex, int subColIndex) const
|
|
|
|
{
|
|
|
|
ESM::Pathgrid::Point point = record.get().mPoints[subRowIndex];
|
|
|
|
switch (subColIndex)
|
|
|
|
{
|
2015-04-09 21:31:01 +00:00
|
|
|
case 0: return subRowIndex;
|
|
|
|
case 1: return point.mX;
|
|
|
|
case 2: return point.mY;
|
|
|
|
case 3: return point.mZ;
|
2015-04-11 05:55:26 +00:00
|
|
|
default: throw std::runtime_error("Pathgrid point subcolumn index out of range");
|
2015-04-09 09:29:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void setNestedData(Record<ESXRecordT>& record, const QVariant& value,
|
|
|
|
int subRowIndex, int subColIndex) const
|
|
|
|
{
|
|
|
|
ESXRecordT pathgrid = record.get();
|
|
|
|
ESM::Pathgrid::Point point = pathgrid.mPoints[subRowIndex];
|
|
|
|
switch (subColIndex)
|
|
|
|
{
|
2015-04-09 21:31:01 +00:00
|
|
|
case 0: break;
|
|
|
|
case 1: point.mX = value.toInt(); break;
|
|
|
|
case 2: point.mY = value.toInt(); break;
|
|
|
|
case 3: point.mZ = value.toInt(); break;
|
2015-04-11 05:55:26 +00:00
|
|
|
default: throw std::runtime_error("Pathgrid point subcolumn index out of range");
|
2015-04-09 09:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pathgrid.mPoints[subRowIndex] = point;
|
|
|
|
|
|
|
|
record.setModified (pathgrid);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int getNestedColumnsCount(const Record<ESXRecordT>& record) const
|
|
|
|
{
|
2015-04-09 21:31:01 +00:00
|
|
|
return 4;
|
2015-04-09 09:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual int getNestedRowsCount(const Record<ESXRecordT>& record) const
|
|
|
|
{
|
|
|
|
return static_cast<int>(record.get().mPoints.size());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename ESXRecordT>
|
|
|
|
class PathgridEdgeListAdapter : public NestedIdAdapter<ESXRecordT>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PathgridEdgeListAdapter () {}
|
|
|
|
|
|
|
|
// FIXME: seems to be auto-sorted in the dialog table display after insertion
|
|
|
|
virtual void addNestedRow(Record<ESXRecordT>& record, int position) const
|
|
|
|
{
|
|
|
|
ESXRecordT pathgrid = record.get();
|
|
|
|
|
2015-04-09 10:15:38 +00:00
|
|
|
ESM::Pathgrid::EdgeList& edges = pathgrid.mEdges;
|
2015-04-09 09:29:03 +00:00
|
|
|
|
|
|
|
// blank row
|
|
|
|
ESM::Pathgrid::Edge edge;
|
|
|
|
edge.mV0 = 0;
|
|
|
|
edge.mV1 = 0;
|
|
|
|
|
2015-04-09 21:31:01 +00:00
|
|
|
// NOTE: inserting a blank edge does not really make sense, perhaps this should be a
|
2015-04-09 09:29:03 +00:00
|
|
|
// logic_error exception
|
2015-04-09 21:31:01 +00:00
|
|
|
//
|
|
|
|
// Currently the code assumes that the end user to know what he/she is doing.
|
|
|
|
// e.g. Edges come in pairs, from points a->b and b->a
|
2015-04-09 09:29:03 +00:00
|
|
|
edges.insert(edges.begin()+position, edge);
|
|
|
|
|
|
|
|
record.setModified (pathgrid);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void removeNestedRow(Record<ESXRecordT>& record, int rowToRemove) const
|
|
|
|
{
|
|
|
|
ESXRecordT pathgrid = record.get();
|
|
|
|
|
2015-04-09 10:15:38 +00:00
|
|
|
ESM::Pathgrid::EdgeList& edges = pathgrid.mEdges;
|
2015-04-09 09:29:03 +00:00
|
|
|
|
|
|
|
if (rowToRemove < 0 || rowToRemove >= static_cast<int> (edges.size()))
|
|
|
|
throw std::runtime_error ("index out of range");
|
|
|
|
|
|
|
|
edges.erase(edges.begin()+rowToRemove);
|
|
|
|
|
|
|
|
record.setModified (pathgrid);
|
|
|
|
}
|
|
|
|
|
2015-04-11 01:26:29 +00:00
|
|
|
virtual void setNestedTable(Record<ESXRecordT>& record, const NestedTableWrapperBase& nestedTable) const
|
2015-04-09 09:29:03 +00:00
|
|
|
{
|
|
|
|
record.get().mEdges =
|
2015-04-09 10:15:38 +00:00
|
|
|
static_cast<const NestedTableWrapper<ESM::Pathgrid::EdgeList> &>(nestedTable).mNestedTable;
|
2015-04-09 09:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual NestedTableWrapperBase* nestedTable(const Record<ESXRecordT>& record) const
|
|
|
|
{
|
|
|
|
// deleted by dtor of NestedTableStoring
|
2015-04-09 10:15:38 +00:00
|
|
|
return new NestedTableWrapper<ESM::Pathgrid::EdgeList>(record.get().mEdges);
|
2015-04-09 09:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual QVariant getNestedData(const Record<ESXRecordT>& record, int subRowIndex, int subColIndex) const
|
|
|
|
{
|
2015-04-11 07:51:30 +00:00
|
|
|
ESXRecordT pathgrid = record.get();
|
|
|
|
|
|
|
|
if (subRowIndex < 0 || subRowIndex >= static_cast<int> (pathgrid.mEdges.size()))
|
|
|
|
throw std::runtime_error ("index out of range");
|
|
|
|
|
|
|
|
ESM::Pathgrid::Edge edge = pathgrid.mEdges[subRowIndex];
|
2015-04-09 09:29:03 +00:00
|
|
|
switch (subColIndex)
|
|
|
|
{
|
2015-04-09 21:31:01 +00:00
|
|
|
case 0: return subRowIndex;
|
|
|
|
case 1: return edge.mV0;
|
|
|
|
case 2: return edge.mV1;
|
2015-04-11 05:55:26 +00:00
|
|
|
default: throw std::runtime_error("Pathgrid edge subcolumn index out of range");
|
2015-04-09 09:29:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-09 21:31:01 +00:00
|
|
|
// FIXME: detect duplicates in mEdges
|
2015-04-09 09:29:03 +00:00
|
|
|
virtual void setNestedData(Record<ESXRecordT>& record, const QVariant& value,
|
|
|
|
int subRowIndex, int subColIndex) const
|
|
|
|
{
|
|
|
|
ESXRecordT pathgrid = record.get();
|
2015-04-11 07:51:30 +00:00
|
|
|
|
|
|
|
if (subRowIndex < 0 || subRowIndex >= static_cast<int> (pathgrid.mEdges.size()))
|
|
|
|
throw std::runtime_error ("index out of range");
|
|
|
|
|
2015-04-09 09:29:03 +00:00
|
|
|
ESM::Pathgrid::Edge edge = pathgrid.mEdges[subRowIndex];
|
|
|
|
switch (subColIndex)
|
|
|
|
{
|
2015-04-09 21:31:01 +00:00
|
|
|
case 0: break;
|
|
|
|
case 1: edge.mV0 = value.toInt(); break;
|
|
|
|
case 2: edge.mV1 = value.toInt(); break;
|
2015-04-11 05:55:26 +00:00
|
|
|
default: throw std::runtime_error("Pathgrid edge subcolumn index out of range");
|
2015-04-09 09:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pathgrid.mEdges[subRowIndex] = edge;
|
|
|
|
|
|
|
|
record.setModified (pathgrid);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int getNestedColumnsCount(const Record<ESXRecordT>& record) const
|
|
|
|
{
|
2015-04-09 21:31:01 +00:00
|
|
|
return 3;
|
2015-04-09 09:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual int getNestedRowsCount(const Record<ESXRecordT>& record) const
|
|
|
|
{
|
|
|
|
return static_cast<int>(record.get().mEdges.size());
|
|
|
|
}
|
|
|
|
};
|
2015-04-11 05:55:26 +00:00
|
|
|
|
2015-04-11 07:51:30 +00:00
|
|
|
template<typename ESXRecordT>
|
|
|
|
class FactionReactionsAdapter : public NestedIdAdapter<ESXRecordT>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FactionReactionsAdapter () {}
|
|
|
|
|
|
|
|
virtual void addNestedRow(Record<ESXRecordT>& record, int position) const
|
|
|
|
{
|
|
|
|
ESXRecordT faction = record.get();
|
|
|
|
|
|
|
|
std::map<std::string, int>& reactions = faction.mReactions;
|
|
|
|
|
|
|
|
// blank row
|
|
|
|
reactions.insert(std::make_pair("", 0));
|
|
|
|
|
|
|
|
record.setModified (faction);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void removeNestedRow(Record<ESXRecordT>& record, int rowToRemove) const
|
|
|
|
{
|
|
|
|
ESXRecordT faction = record.get();
|
|
|
|
|
|
|
|
std::map<std::string, int>& reactions = faction.mReactions;
|
|
|
|
|
|
|
|
if (rowToRemove < 0 || rowToRemove >= static_cast<int> (reactions.size()))
|
|
|
|
throw std::runtime_error ("index out of range");
|
|
|
|
|
|
|
|
// FIXME: how to ensure that the map entries correspond to table indicies?
|
|
|
|
// WARNING: Assumed that the table view has the same order as std::map
|
2015-04-11 08:21:08 +00:00
|
|
|
std::map<std::string, int>::iterator iter = reactions.begin();
|
2015-04-11 07:51:30 +00:00
|
|
|
for(int i = 0; i < rowToRemove; ++i)
|
|
|
|
iter++;
|
|
|
|
reactions.erase(iter);
|
|
|
|
|
|
|
|
record.setModified (faction);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void setNestedTable(Record<ESXRecordT>& record, const NestedTableWrapperBase& nestedTable) const
|
|
|
|
{
|
|
|
|
record.get().mReactions =
|
|
|
|
static_cast<const NestedTableWrapper<std::map<std::string, int> >&>(nestedTable).mNestedTable;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual NestedTableWrapperBase* nestedTable(const Record<ESXRecordT>& record) const
|
|
|
|
{
|
|
|
|
// deleted by dtor of NestedTableStoring
|
|
|
|
return new NestedTableWrapper<std::map<std::string, int> >(record.get().mReactions);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual QVariant getNestedData(const Record<ESXRecordT>& record, int subRowIndex, int subColIndex) const
|
|
|
|
{
|
|
|
|
ESXRecordT faction = record.get();
|
|
|
|
|
|
|
|
std::map<std::string, int>& reactions = faction.mReactions;
|
|
|
|
|
|
|
|
if (subRowIndex < 0 || subRowIndex >= static_cast<int> (reactions.size()))
|
|
|
|
throw std::runtime_error ("index out of range");
|
|
|
|
|
|
|
|
// FIXME: how to ensure that the map entries correspond to table indicies?
|
|
|
|
// WARNING: Assumed that the table view has the same order as std::map
|
|
|
|
std::map<std::string, int>::const_iterator iter = reactions.begin();
|
|
|
|
for(int i = 0; i < subRowIndex; ++i)
|
|
|
|
iter++;
|
|
|
|
switch (subColIndex)
|
|
|
|
{
|
|
|
|
case 0: return QString((*iter).first.c_str());
|
|
|
|
case 1: return (*iter).second;
|
|
|
|
default: throw std::runtime_error("Faction reactions subcolumn index out of range");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void setNestedData(Record<ESXRecordT>& record, const QVariant& value,
|
|
|
|
int subRowIndex, int subColIndex) const
|
|
|
|
{
|
|
|
|
ESXRecordT faction = record.get();
|
|
|
|
|
|
|
|
std::map<std::string, int>& reactions = faction.mReactions;
|
|
|
|
|
|
|
|
if (subRowIndex < 0 || subRowIndex >= static_cast<int> (reactions.size()))
|
|
|
|
throw std::runtime_error ("index out of range");
|
|
|
|
|
|
|
|
// FIXME: how to ensure that the map entries correspond to table indicies?
|
|
|
|
// WARNING: Assumed that the table view has the same order as std::map
|
2015-04-11 08:21:08 +00:00
|
|
|
std::map<std::string, int>::iterator iter = reactions.begin();
|
2015-04-11 07:51:30 +00:00
|
|
|
for(int i = 0; i < subRowIndex; ++i)
|
|
|
|
iter++;
|
|
|
|
|
|
|
|
std::string factionId = (*iter).first;
|
|
|
|
int reaction = (*iter).second;
|
|
|
|
|
|
|
|
switch (subColIndex)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
reactions.erase(iter);
|
|
|
|
reactions.insert(std::make_pair(value.toString().toUtf8().constData(), reaction));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
reactions[factionId] = value.toInt();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: throw std::runtime_error("Faction reactions subcolumn index out of range");
|
|
|
|
}
|
|
|
|
|
|
|
|
record.setModified (faction);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int getNestedColumnsCount(const Record<ESXRecordT>& record) const
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int getNestedRowsCount(const Record<ESXRecordT>& record) const
|
|
|
|
{
|
|
|
|
return static_cast<int>(record.get().mReactions.size());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-04-11 05:55:26 +00:00
|
|
|
template<typename ESXRecordT>
|
|
|
|
class RegionSoundListAdapter : public NestedIdAdapter<ESXRecordT>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RegionSoundListAdapter () {}
|
|
|
|
|
|
|
|
virtual void addNestedRow(Record<ESXRecordT>& record, int position) const
|
|
|
|
{
|
|
|
|
ESXRecordT region = record.get();
|
|
|
|
|
2015-04-11 07:51:30 +00:00
|
|
|
std::vector<typename ESXRecordT::SoundRef>& soundList = region.mSoundList;
|
2015-04-11 05:55:26 +00:00
|
|
|
|
|
|
|
// blank row
|
2015-04-11 07:51:30 +00:00
|
|
|
typename ESXRecordT::SoundRef soundRef;
|
2015-04-11 05:55:26 +00:00
|
|
|
soundRef.mSound.assign("");
|
|
|
|
soundRef.mChance = 0;
|
|
|
|
|
|
|
|
soundList.insert(soundList.begin()+position, soundRef);
|
|
|
|
|
|
|
|
record.setModified (region);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void removeNestedRow(Record<ESXRecordT>& record, int rowToRemove) const
|
|
|
|
{
|
|
|
|
ESXRecordT region = record.get();
|
|
|
|
|
2015-04-11 07:51:30 +00:00
|
|
|
std::vector<typename ESXRecordT::SoundRef>& soundList = region.mSoundList;
|
2015-04-11 05:55:26 +00:00
|
|
|
|
|
|
|
if (rowToRemove < 0 || rowToRemove >= static_cast<int> (soundList.size()))
|
|
|
|
throw std::runtime_error ("index out of range");
|
|
|
|
|
|
|
|
soundList.erase(soundList.begin()+rowToRemove);
|
|
|
|
|
|
|
|
record.setModified (region);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void setNestedTable(Record<ESXRecordT>& record, const NestedTableWrapperBase& nestedTable) const
|
|
|
|
{
|
|
|
|
record.get().mSoundList =
|
2015-04-11 07:51:30 +00:00
|
|
|
static_cast<const NestedTableWrapper<std::vector<typename ESXRecordT::SoundRef> >&>(nestedTable).mNestedTable;
|
2015-04-11 05:55:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual NestedTableWrapperBase* nestedTable(const Record<ESXRecordT>& record) const
|
|
|
|
{
|
|
|
|
// deleted by dtor of NestedTableStoring
|
2015-04-11 07:51:30 +00:00
|
|
|
return new NestedTableWrapper<std::vector<typename ESXRecordT::SoundRef> >(record.get().mSoundList);
|
2015-04-11 05:55:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual QVariant getNestedData(const Record<ESXRecordT>& record, int subRowIndex, int subColIndex) const
|
|
|
|
{
|
2015-04-11 07:51:30 +00:00
|
|
|
ESXRecordT region = record.get();
|
|
|
|
|
|
|
|
std::vector<typename ESXRecordT::SoundRef>& soundList = region.mSoundList;
|
|
|
|
|
|
|
|
if (subRowIndex < 0 || subRowIndex >= static_cast<int> (soundList.size()))
|
|
|
|
throw std::runtime_error ("index out of range");
|
|
|
|
|
|
|
|
typename ESXRecordT::SoundRef soundRef = soundList[subRowIndex];
|
2015-04-11 05:55:26 +00:00
|
|
|
switch (subColIndex)
|
|
|
|
{
|
|
|
|
case 0: return QString(soundRef.mSound.toString().c_str());
|
|
|
|
case 1: return soundRef.mChance;
|
|
|
|
default: throw std::runtime_error("Region sounds subcolumn index out of range");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void setNestedData(Record<ESXRecordT>& record, const QVariant& value,
|
|
|
|
int subRowIndex, int subColIndex) const
|
|
|
|
{
|
|
|
|
ESXRecordT region = record.get();
|
2015-04-11 07:51:30 +00:00
|
|
|
|
|
|
|
std::vector<typename ESXRecordT::SoundRef>& soundList = region.mSoundList;
|
|
|
|
|
|
|
|
if (subRowIndex < 0 || subRowIndex >= static_cast<int> (soundList.size()))
|
|
|
|
throw std::runtime_error ("index out of range");
|
|
|
|
|
|
|
|
typename ESXRecordT::SoundRef soundRef = soundList[subRowIndex];
|
2015-04-11 05:55:26 +00:00
|
|
|
switch (subColIndex)
|
|
|
|
{
|
|
|
|
case 0: soundRef.mSound.assign(value.toString().toUtf8().constData()); break;
|
|
|
|
case 1: soundRef.mChance = static_cast<unsigned char>(value.toInt()); break;
|
|
|
|
default: throw std::runtime_error("Region sounds subcolumn index out of range");
|
|
|
|
}
|
|
|
|
|
|
|
|
region.mSoundList[subRowIndex] = soundRef;
|
|
|
|
|
|
|
|
record.setModified (region);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int getNestedColumnsCount(const Record<ESXRecordT>& record) const
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int getNestedRowsCount(const Record<ESXRecordT>& record) const
|
|
|
|
{
|
|
|
|
return static_cast<int>(record.get().mSoundList.size());
|
|
|
|
}
|
|
|
|
};
|
2015-04-09 09:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // CSM_WOLRD_IDADAPTERIMP_H
|