Revert "Fix data corruption issues."

This reverts commit 6199663bd8.
coverity_scan^2
Aesylwinn 9 years ago
parent 9a567b3712
commit 239727531f

@ -301,40 +301,6 @@ void CSMWorld::UpdateCellCommand::undo()
mModel.setData (mIndex, mOld);
}
CSMWorld::ModifyNestedCommand::ModifyNestedCommand (IdTree& model, const std::string& id, int nestedRow,
int nestedColumn, int parentColumn, const QVariant& new_, QUndoCommand* parent)
: QUndoCommand(parent)
, NestedTableStoring(model, id, parentColumn)
, mModel(model)
, mId(id)
, mNestedRow(nestedRow)
, mNestedColumn(nestedColumn)
, mParentColumn(parentColumn)
, mNew(new_)
{
std::string title = model.headerData(parentColumn, Qt::Horizontal, Qt::DisplayRole).toString().toUtf8().constData();
setText (("Modify " + title + " sub-table of " + mId).c_str());
QModelIndex parentIndex = mModel.getModelIndex(mId, mParentColumn);
mModifyParentCommand = new ModifyCommand(mModel, parentIndex, parentIndex.data(Qt::EditRole), this);
}
void CSMWorld::ModifyNestedCommand::redo()
{
QModelIndex parentIndex = mModel.getModelIndex(mId, mParentColumn);
QModelIndex nestedIndex = mModel.index(mNestedRow, mNestedColumn, parentIndex);
mModel.setData(nestedIndex, mNew);
mModifyParentCommand->redo();
}
void CSMWorld::ModifyNestedCommand::undo()
{
QModelIndex parentIndex = mModel.getModelIndex(mId, mParentColumn);
mModel.setNestedTable(parentIndex, getOld());
mModifyParentCommand->undo();
}
CSMWorld::DeleteNestedCommand::DeleteNestedCommand (IdTree& model,
const std::string& id,

@ -199,33 +199,6 @@ namespace CSMWorld
const NestedTableWrapperBase& getOld() const;
};
class ModifyNestedCommand : public QUndoCommand, private NestedTableStoring
{
IdTree& mModel;
std::string mId;
int mNestedRow;
int mNestedColumn;
int mParentColumn;
QVariant mNew;
// The command to redo/undo the Modified status of a record
ModifyCommand *mModifyParentCommand;
public:
ModifyNestedCommand (IdTree& model, const std::string& id, int nestedRow, int nestedColumn,
int parentColumn, const QVariant& new_, QUndoCommand* parent = 0);
virtual void redo();
virtual void undo();
};
class DeleteNestedCommand : public QUndoCommand, private NestedTableStoring
{
IdTree& mModel;

@ -33,10 +33,10 @@ namespace CSMWorld
std::vector<ESM::Pathgrid::Edge>::iterator iter = pathgrid.mEdges.begin();
for (;iter != pathgrid.mEdges.end(); ++iter)
{
if (iter->mV0 >= position)
++iter->mV0;
if (iter->mV1 >= position)
++iter->mV1;
if ((*iter).mV0 >= position)
(*iter).mV0++;
if ((*iter).mV1 >= position)
(*iter).mV1++;
}
points.insert(points.begin()+position, point);
@ -61,20 +61,15 @@ namespace CSMWorld
std::vector<ESM::Pathgrid::Edge>::iterator iter = pathgrid.mEdges.begin();
for (; iter != pathgrid.mEdges.end();)
{
if (iter->mV0 == rowToRemove || iter->mV1 == rowToRemove)
{
if (static_cast<size_t>(iter->mV0) < points.size())
--points[iter->mV0].mConnectionNum;
if (((*iter).mV0 == rowToRemove) || ((*iter).mV1 == rowToRemove))
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;
}
@ -157,13 +152,8 @@ namespace CSMWorld
{
Pathgrid pathgrid = record.get();
ESM::Pathgrid::PointList& points = pathgrid.mPoints;
ESM::Pathgrid::EdgeList& edges = pathgrid.mEdges;
// Can only add valid point indices
if (points.empty())
return;
// blank row
ESM::Pathgrid::Edge edge;
edge.mV0 = 0;
@ -174,12 +164,7 @@ namespace CSMWorld
//
// 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
// Even edges between the same node and itself need to be counted
++points[edge.mV0].mConnectionNum;
// Edge needs to be ordered, since edge.mV0 is 0, add at start
edges.insert(edges.begin(), edge);
edges.insert(edges.begin()+position, edge);
record.setModified (pathgrid);
}
@ -188,16 +173,11 @@ namespace CSMWorld
{
Pathgrid pathgrid = record.get();
ESM::Pathgrid::PointList& points = pathgrid.mPoints;
ESM::Pathgrid::EdgeList& edges = pathgrid.mEdges;
if (rowToRemove < 0 || rowToRemove >= static_cast<int> (edges.size()))
throw std::runtime_error ("index out of range");
ESM::Pathgrid::Edge& edge = edges[rowToRemove];
if (static_cast<size_t>(edge.mV0) < points.size())
--pathgrid.mPoints[edge.mV0].mConnectionNum;
edges.erase(edges.begin()+rowToRemove);
record.setModified (pathgrid);
@ -208,13 +188,8 @@ namespace CSMWorld
{
Pathgrid pathgrid = record.get();
// Set points because point data (edge count) is tied to edges
pathgrid.mPoints =
static_cast<const PathgridPointsWrap &>(nestedTable).mRecord.mPoints;
pathgrid.mData.mS2 =
static_cast<const PathgridPointsWrap &>(nestedTable).mRecord.mData.mS2;
pathgrid.mEdges =
static_cast<const PathgridPointsWrap &>(nestedTable).mRecord.mEdges;
static_cast<const NestedTableWrapper<ESM::Pathgrid::EdgeList> &>(nestedTable).mNestedTable;
record.setModified (pathgrid);
}
@ -222,7 +197,7 @@ namespace CSMWorld
NestedTableWrapperBase* PathgridEdgeListAdapter::table(const Record<Pathgrid>& record) const
{
// deleted by dtor of NestedTableStoring
return new PathgridPointsWrap(record.get());
return new NestedTableWrapper<ESM::Pathgrid::EdgeList>(record.get().mEdges);
}
QVariant PathgridEdgeListAdapter::getData(const Record<Pathgrid>& record,
@ -249,57 +224,20 @@ namespace CSMWorld
{
Pathgrid pathgrid = record.get();
ESM::Pathgrid::PointList& points = pathgrid.mPoints;
ESM::Pathgrid::EdgeList& edges = pathgrid.mEdges;
if (subRowIndex < 0 || subRowIndex >= static_cast<int> (edges.size()))
if (subRowIndex < 0 || subRowIndex >= static_cast<int> (pathgrid.mEdges.size()))
throw std::runtime_error ("index out of range");
// Point indices must exist
if (value.toInt() < 0 || value.toUInt() >= points.size())
return;
ESM::Pathgrid::Edge edge = pathgrid.mEdges[subRowIndex];
switch (subColIndex)
{
case 0: return; // return without saving
case 1:
{
edges.erase(edges.begin()+subRowIndex);
if (static_cast<size_t>(edge.mV0) < points.size())
--points[edge.mV0].mConnectionNum;
edge.mV0 = value.toInt();
// Place in correct order
if (static_cast<size_t>(edge.mV0) < points.size())
++points[edge.mV0].mConnectionNum;
ESM::Pathgrid::EdgeList::iterator it = edges.begin();
for (; it != edges.end(); ++it)
{
if (edge.mV0 <= it->mV0)
{
edges.insert(it, edge);
break;
}
}
if (it == edges.end())
edges.push_back(edge);
break;
}
case 2:
edge.mV1 = value.toInt();
edges[subRowIndex] = edge;
break;
case 1: edge.mV0 = value.toInt(); break;
case 2: edge.mV1 = value.toInt(); break;
default: throw std::runtime_error("Pathgrid edge subcolumn index out of range");
}
pathgrid.mEdges[subRowIndex] = edge;
record.setModified (pathgrid);
}

@ -254,6 +254,7 @@ namespace CSVRender
int posY = clampToCell(static_cast<int>(localCoords.y()));
int posZ = clampToCell(static_cast<int>(localCoords.z()));
int recordIndex = mPathgridCollection.getIndex (mId);
int parentColumn = mPathgridCollection.findColumnIndex(CSMWorld::Columns::ColumnId_PathgridPoints);
int posXColumn = mPathgridCollection.searchNestedColumnIndex(parentColumn,
@ -265,13 +266,14 @@ namespace CSVRender
int posZColumn = mPathgridCollection.searchNestedColumnIndex(parentColumn,
CSMWorld::Columns::ColumnId_PathgridPosZ);
QModelIndex parent = model->index(recordIndex, parentColumn);
int row = static_cast<int>(source->mPoints.size());
// Add node
commands.push(new CSMWorld::AddNestedCommand(*model, mId, row, parentColumn));
commands.push(new CSMWorld::ModifyNestedCommand(*model, mId, row, posXColumn, parentColumn, posX));
commands.push(new CSMWorld::ModifyNestedCommand(*model, mId, row, posYColumn, parentColumn, posY));
commands.push(new CSMWorld::ModifyNestedCommand(*model, mId, row, posZColumn, parentColumn, posZ));
commands.push(new CSMWorld::ModifyCommand(*model, model->index(row, posXColumn, parent), posX));
commands.push(new CSMWorld::ModifyCommand(*model, model->index(row, posYColumn, parent), posY));
commands.push(new CSMWorld::ModifyCommand(*model, model->index(row, posZColumn, parent), posZ));
}
else
{
@ -291,9 +293,9 @@ namespace CSVRender
int offsetY = static_cast<int>(localCoords.y());
int offsetZ = static_cast<int>(localCoords.z());
CSMWorld::IdTree* model = dynamic_cast<CSMWorld::IdTree*>(mData.getTableModel(
CSMWorld::UniversalId::Type_Pathgrids));
QAbstractItemModel* model = mData.getTableModel(CSMWorld::UniversalId::Type_Pathgrids);
int recordIndex = mPathgridCollection.getIndex(mId);
int parentColumn = mPathgridCollection.findColumnIndex(CSMWorld::Columns::ColumnId_PathgridPoints);
int posXColumn = mPathgridCollection.searchNestedColumnIndex(parentColumn,
@ -305,18 +307,20 @@ namespace CSVRender
int posZColumn = mPathgridCollection.searchNestedColumnIndex(parentColumn,
CSMWorld::Columns::ColumnId_PathgridPosZ);
QModelIndex parent = model->index(recordIndex, parentColumn);
for (size_t i = 0; i < mSelected.size(); ++i)
{
const CSMWorld::Pathgrid::Point& point = source->mPoints[mSelected[i]];
int row = static_cast<int>(mSelected[i]);
commands.push(new CSMWorld::ModifyNestedCommand(*model, mId, row, posXColumn, parentColumn,
commands.push(new CSMWorld::ModifyCommand(*model, model->index(row, posXColumn, parent),
clampToCell(point.mX + offsetX)));
commands.push(new CSMWorld::ModifyNestedCommand(*model, mId, row, posYColumn, parentColumn,
commands.push(new CSMWorld::ModifyCommand(*model, model->index(row, posYColumn, parent),
clampToCell(point.mY + offsetY)));
commands.push(new CSMWorld::ModifyNestedCommand(*model, mId, row, posZColumn, parentColumn,
commands.push(new CSMWorld::ModifyCommand(*model, model->index(row, posZColumn, parent),
clampToCell(point.mZ + offsetZ)));
}
}
@ -560,6 +564,7 @@ namespace CSVRender
CSMWorld::IdTree* model = dynamic_cast<CSMWorld::IdTree*>(mData.getTableModel(
CSMWorld::UniversalId::Type_Pathgrids));
int recordIndex = mPathgridCollection.getIndex(mId);
int parentColumn = mPathgridCollection.findColumnIndex(CSMWorld::Columns::ColumnId_PathgridEdges);
int edge0Column = mPathgridCollection.searchNestedColumnIndex(parentColumn,
@ -568,19 +573,22 @@ namespace CSVRender
int edge1Column = mPathgridCollection.searchNestedColumnIndex(parentColumn,
CSMWorld::Columns::ColumnId_PathgridEdge1);
QModelIndex parent = model->index(recordIndex, parentColumn);
int row = static_cast<int>(source.mEdges.size());
if (edgeExists(source, node1, node2) == -1)
{
// Set first edge last since that reorders the edge list
commands.push(new CSMWorld::AddNestedCommand(*model, mId, 0, parentColumn));
commands.push(new CSMWorld::ModifyNestedCommand(*model, mId, 0, edge1Column, parentColumn, node2));
commands.push(new CSMWorld::ModifyNestedCommand(*model, mId, 0, edge0Column, parentColumn, node1));
commands.push(new CSMWorld::AddNestedCommand(*model, mId, row, parentColumn));
commands.push(new CSMWorld::ModifyCommand(*model, model->index(row, edge0Column, parent), node1));
commands.push(new CSMWorld::ModifyCommand(*model, model->index(row, edge1Column, parent), node2));
++row;
}
if (edgeExists(source, node2, node1) == -1)
{
commands.push(new CSMWorld::AddNestedCommand(*model, mId, 0, parentColumn));
commands.push(new CSMWorld::ModifyNestedCommand(*model, mId, 0, edge1Column, parentColumn, node1));
commands.push(new CSMWorld::ModifyNestedCommand(*model, mId, 0, edge0Column, parentColumn, node2));
commands.push(new CSMWorld::AddNestedCommand(*model, mId, row, parentColumn));
commands.push(new CSMWorld::ModifyCommand(*model, model->index(row, edge0Column, parent), node2));
commands.push(new CSMWorld::ModifyCommand(*model, model->index(row, edge1Column, parent), node1));
}
}

Loading…
Cancel
Save