mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 09:35:28 +00:00
Add index columns and fix edge indexing for point deletion.
This commit is contained in:
parent
330920daa8
commit
bc9dad3ff2
@ -2289,6 +2289,28 @@ namespace CSMWorld
|
||||
}
|
||||
};
|
||||
|
||||
template<typename ESXRecordT>
|
||||
struct PathgridIndexColumn : public Column<ESXRecordT>
|
||||
{
|
||||
PathgridIndexColumn()
|
||||
: Column<ESXRecordT> (Columns::ColumnId_PathgridIndex, ColumnBase::Display_Integer)
|
||||
{}
|
||||
|
||||
virtual QVariant get (const Record<ESXRecordT>& record) const
|
||||
{
|
||||
return QVariant(); // FIXME
|
||||
}
|
||||
|
||||
virtual void set (Record<ESXRecordT>& record, const QVariant& data)
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool isEditable() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename ESXRecordT>
|
||||
struct PathgridPointColumn : public Column<ESXRecordT>
|
||||
{
|
||||
@ -2338,6 +2360,28 @@ namespace CSMWorld
|
||||
|
||||
};
|
||||
|
||||
template<typename ESXRecordT>
|
||||
struct PathgridEdgeIndexColumn : public Column<ESXRecordT>
|
||||
{
|
||||
PathgridEdgeIndexColumn()
|
||||
: Column<ESXRecordT> (Columns::ColumnId_PathgridEdgeIndex, ColumnBase::Display_Integer)
|
||||
{}
|
||||
|
||||
virtual QVariant get (const Record<ESXRecordT>& record) const
|
||||
{
|
||||
return QVariant(); // FIXME
|
||||
}
|
||||
|
||||
virtual void set (Record<ESXRecordT>& record, const QVariant& data)
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool isEditable() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename ESXRecordT>
|
||||
struct PathgridEdgeColumn : public Column<ESXRecordT>
|
||||
{
|
||||
|
@ -224,12 +224,14 @@ namespace CSMWorld
|
||||
{ ColumnId_BoltSound, "Bolt Sound" },
|
||||
|
||||
{ ColumnId_PathgridPoints, "Points"},
|
||||
{ ColumnId_PathgridIndex, "Index"},
|
||||
{ ColumnId_PathgridPosX, "X"},
|
||||
{ ColumnId_PathgridPosY, "Y"},
|
||||
{ ColumnId_PathgridPosZ, "Z"},
|
||||
{ ColumnId_PathgridEdges, "Edges"},
|
||||
{ ColumnId_PathgridEdge0, "Edge 0"},
|
||||
{ ColumnId_PathgridEdge1, "Edge 1"},
|
||||
{ ColumnId_PathgridEdgeIndex, "Index"},
|
||||
{ ColumnId_PathgridEdge0, "Point 0"},
|
||||
{ ColumnId_PathgridEdge1, "Point 1"},
|
||||
|
||||
{ ColumnId_UseValue1, "Use value 1" },
|
||||
{ ColumnId_UseValue2, "Use value 2" },
|
||||
|
@ -213,12 +213,14 @@ namespace CSMWorld
|
||||
ColumnId_BoltSound = 198,
|
||||
|
||||
ColumnId_PathgridPoints = 199,
|
||||
ColumnId_PathgridPosX = 200,
|
||||
ColumnId_PathgridPosY = 201,
|
||||
ColumnId_PathgridPosZ = 202,
|
||||
ColumnId_PathgridEdges = 203,
|
||||
ColumnId_PathgridEdge0 = 204,
|
||||
ColumnId_PathgridEdge1 = 205,
|
||||
ColumnId_PathgridIndex = 200,
|
||||
ColumnId_PathgridPosX = 201,
|
||||
ColumnId_PathgridPosY = 202,
|
||||
ColumnId_PathgridPosZ = 203,
|
||||
ColumnId_PathgridEdges = 204,
|
||||
ColumnId_PathgridEdgeIndex = 205,
|
||||
ColumnId_PathgridEdge0 = 206,
|
||||
ColumnId_PathgridEdge1 = 207,
|
||||
|
||||
// Allocated to a separate value range, so we don't get a collision should we ever need
|
||||
// to extend the number of use values.
|
||||
|
@ -262,6 +262,8 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, const ResourcesManager& resourc
|
||||
// new object deleted in dtor of SubCellCollection<T,A>
|
||||
mPathgrids.addAdapter (std::make_pair(pointList, new PathgridPointListAdapter<Pathgrid> ()));
|
||||
// new objects deleted in dtor of NestableColumn
|
||||
// WARNING: The order of the columns below are assumed in PathgridPointListAdapter
|
||||
mPathgrids.getNestableColumn(mPathgrids.getColumns()-1)->addColumn(new PathgridIndexColumn<Pathgrid> ());
|
||||
mPathgrids.getNestableColumn(mPathgrids.getColumns()-1)->addColumn(new PathgridPointColumn<Pathgrid> (0));
|
||||
mPathgrids.getNestableColumn(mPathgrids.getColumns()-1)->addColumn(new PathgridPointColumn<Pathgrid> (1));
|
||||
mPathgrids.getNestableColumn(mPathgrids.getColumns()-1)->addColumn(new PathgridPointColumn<Pathgrid> (2));
|
||||
@ -269,6 +271,7 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, const ResourcesManager& resourc
|
||||
PathgridEdgeListColumn<Pathgrid> *edgeList = new PathgridEdgeListColumn<Pathgrid> ();
|
||||
mPathgrids.addColumn (edgeList);
|
||||
mPathgrids.addAdapter (std::make_pair(edgeList, new PathgridEdgeListAdapter<Pathgrid> ()));
|
||||
mPathgrids.getNestableColumn(mPathgrids.getColumns()-1)->addColumn(new PathgridEdgeIndexColumn<Pathgrid> ());
|
||||
mPathgrids.getNestableColumn(mPathgrids.getColumns()-1)->addColumn(new PathgridEdgeColumn<Pathgrid> (0));
|
||||
mPathgrids.getNestableColumn(mPathgrids.getColumns()-1)->addColumn(new PathgridEdgeColumn<Pathgrid> (1));
|
||||
|
||||
|
@ -33,6 +33,9 @@ namespace CSMWorld
|
||||
point.mUnknown = 0;
|
||||
|
||||
// inserting a point should trigger re-indexing of the edges
|
||||
//
|
||||
// FIXME: undo does not restore edges table view
|
||||
// FIXME: does not auto refresh edges table view
|
||||
std::vector<ESM::Pathgrid::Edge>::iterator iter = pathgrid.mEdges.begin();
|
||||
for (;iter != pathgrid.mEdges.end(); ++iter)
|
||||
{
|
||||
@ -59,19 +62,25 @@ namespace CSMWorld
|
||||
|
||||
// deleting a point should trigger re-indexing of the edges
|
||||
// dangling edges are not allowed and hence removed
|
||||
//
|
||||
// FIXME: undo does not restore edges table view
|
||||
// FIXME: does not auto refresh edges table view
|
||||
std::vector<ESM::Pathgrid::Edge>::iterator iter = pathgrid.mEdges.begin();
|
||||
for (;iter != pathgrid.mEdges.end(); ++iter)
|
||||
for (; iter != pathgrid.mEdges.end();)
|
||||
{
|
||||
if (((*iter).mV0 == rowToRemove) || ((*iter).mV1 == rowToRemove))
|
||||
pathgrid.mEdges.erase(iter);
|
||||
iter = pathgrid.mEdges.erase(iter);
|
||||
else
|
||||
{
|
||||
if ((*iter).mV0 > rowToRemove)
|
||||
(*iter).mV0--;
|
||||
|
||||
if ((*iter).mV0 >= rowToRemove)
|
||||
(*iter).mV0--;
|
||||
if ((*iter).mV1 > rowToRemove)
|
||||
(*iter).mV1--;
|
||||
|
||||
if ((*iter).mV1 >= rowToRemove)
|
||||
(*iter).mV1--;
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
|
||||
points.erase(points.begin()+rowToRemove);
|
||||
pathgrid.mData.mS2 -= 1; // decrement the number of points
|
||||
|
||||
@ -95,9 +104,10 @@ namespace CSMWorld
|
||||
ESM::Pathgrid::Point point = record.get().mPoints[subRowIndex];
|
||||
switch (subColIndex)
|
||||
{
|
||||
case 0: return point.mX;
|
||||
case 1: return point.mY;
|
||||
case 2: return point.mZ;
|
||||
case 0: return subRowIndex;
|
||||
case 1: return point.mX;
|
||||
case 2: return point.mY;
|
||||
case 3: return point.mZ;
|
||||
default: throw std::logic_error("Pathgrid point subcolumn index out of range");
|
||||
}
|
||||
}
|
||||
@ -109,9 +119,10 @@ namespace CSMWorld
|
||||
ESM::Pathgrid::Point point = pathgrid.mPoints[subRowIndex];
|
||||
switch (subColIndex)
|
||||
{
|
||||
case 0: point.mX = value.toInt(); break;
|
||||
case 1: point.mY = value.toInt(); break;
|
||||
case 2: point.mZ = value.toInt(); break;
|
||||
case 0: break;
|
||||
case 1: point.mX = value.toInt(); break;
|
||||
case 2: point.mY = value.toInt(); break;
|
||||
case 3: point.mZ = value.toInt(); break;
|
||||
default: throw std::logic_error("Pathgrid point subcolumn index out of range");
|
||||
}
|
||||
|
||||
@ -122,7 +133,7 @@ namespace CSMWorld
|
||||
|
||||
virtual int getNestedColumnsCount(const Record<ESXRecordT>& record) const
|
||||
{
|
||||
return 3;
|
||||
return 4;
|
||||
}
|
||||
|
||||
virtual int getNestedRowsCount(const Record<ESXRecordT>& record) const
|
||||
@ -149,8 +160,11 @@ namespace CSMWorld
|
||||
edge.mV0 = 0;
|
||||
edge.mV1 = 0;
|
||||
|
||||
// FIXME: inserting a blank edge does not really make sense, perhaps this should be a
|
||||
// NOTE: inserting a blank edge does not really make sense, perhaps this should be a
|
||||
// logic_error exception
|
||||
//
|
||||
// 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
|
||||
edges.insert(edges.begin()+position, edge);
|
||||
|
||||
record.setModified (pathgrid);
|
||||
@ -187,12 +201,14 @@ namespace CSMWorld
|
||||
ESM::Pathgrid::Edge edge = record.get().mEdges[subRowIndex];
|
||||
switch (subColIndex)
|
||||
{
|
||||
case 0: return edge.mV0;
|
||||
case 1: return edge.mV1;
|
||||
case 0: return subRowIndex;
|
||||
case 1: return edge.mV0;
|
||||
case 2: return edge.mV1;
|
||||
default: throw std::logic_error("Pathgrid edge subcolumn index out of range");
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: detect duplicates in mEdges
|
||||
virtual void setNestedData(Record<ESXRecordT>& record, const QVariant& value,
|
||||
int subRowIndex, int subColIndex) const
|
||||
{
|
||||
@ -200,8 +216,9 @@ namespace CSMWorld
|
||||
ESM::Pathgrid::Edge edge = pathgrid.mEdges[subRowIndex];
|
||||
switch (subColIndex)
|
||||
{
|
||||
case 0: edge.mV0 = value.toInt(); break;
|
||||
case 1: edge.mV1 = value.toInt(); break;
|
||||
case 0: break;
|
||||
case 1: edge.mV0 = value.toInt(); break;
|
||||
case 2: edge.mV1 = value.toInt(); break;
|
||||
default: throw std::logic_error("Pathgrid edge subcolumn index out of range");
|
||||
}
|
||||
|
||||
@ -212,7 +229,7 @@ namespace CSMWorld
|
||||
|
||||
virtual int getNestedColumnsCount(const Record<ESXRecordT>& record) const
|
||||
{
|
||||
return 2;
|
||||
return 3;
|
||||
}
|
||||
|
||||
virtual int getNestedRowsCount(const Record<ESXRecordT>& record) const
|
||||
|
Loading…
x
Reference in New Issue
Block a user