Changes as per feedback comments.

test
cc9cii 10 years ago
parent 7990fab708
commit 1220369da3

@ -120,8 +120,6 @@ namespace CSMWorld
virtual const Record<ESXRecordT>& getRecord (int index) const;
virtual Record<ESXRecordT>& getRecord (int index);
virtual int getAppendIndex (const std::string& id,
UniversalId::Type type = UniversalId::Type_None) const;
///< \param type Will be ignored, unless the collection supports multiple record types
@ -151,7 +149,7 @@ namespace CSMWorld
void setRecord (int index, const Record<ESXRecordT>& record);
///< \attention This function must not change the ID.
NestableColumn *getNestableColumn (int column);
NestableColumn *getNestableColumn (int column) const;
};
template<typename ESXRecordT, typename IdAccessorT>
@ -294,7 +292,7 @@ namespace CSMWorld
}
template<typename ESXRecordT, typename IdAccessorT>
NestableColumn *Collection<ESXRecordT, IdAccessorT>::getNestableColumn (int column)
NestableColumn *Collection<ESXRecordT, IdAccessorT>::getNestableColumn (int column) const
{
if (column < 0 || column >= static_cast<int>(mColumns.size()))
throw std::runtime_error("column index out of range");
@ -435,12 +433,6 @@ namespace CSMWorld
return mRecords.at (index);
}
template<typename ESXRecordT, typename IdAccessorT>
Record<ESXRecordT>& Collection<ESXRecordT, IdAccessorT>::getRecord (int index)
{
return mRecords.at (index);
}
template<typename ESXRecordT, typename IdAccessorT>
void Collection<ESXRecordT, IdAccessorT>::insertRecord (const RecordBase& record, int index,
UniversalId::Type type)

@ -26,12 +26,11 @@ int CSMWorld::ColumnBase::getId() const
void CSMWorld::NestableColumn::addColumn(CSMWorld::NestableColumn *column)
{
mNestedColumns.push_back(column);
mHasChildren = true;
}
const CSMWorld::ColumnBase& CSMWorld::NestableColumn::nestedColumn(int subColumn) const
{
if (!mHasChildren)
if (mNestedColumns.empty())
throw std::logic_error("Tried to access nested column of the non-nest column");
return *mNestedColumns.at(subColumn);
@ -39,7 +38,7 @@ const CSMWorld::ColumnBase& CSMWorld::NestableColumn::nestedColumn(int subColumn
CSMWorld::NestableColumn::NestableColumn(int columnId, CSMWorld::ColumnBase::Display displayType,
int flag)
: mHasChildren(false), CSMWorld::ColumnBase(columnId, displayType, flag)
: CSMWorld::ColumnBase(columnId, displayType, flag)
{
}
@ -53,5 +52,5 @@ CSMWorld::NestableColumn::~NestableColumn()
bool CSMWorld::NestableColumn::hasChildren() const
{
return mHasChildren;
return !mNestedColumns.empty();
}

@ -137,7 +137,6 @@ namespace CSMWorld
class NestableColumn : public ColumnBase
{
std::vector<NestableColumn *> mNestedColumns;
bool mHasChildren;
public:

@ -2271,64 +2271,39 @@ namespace CSMWorld
PathgridPointListColumn ()
: Column<ESXRecordT> (Columns::ColumnId_PathgridPoints,
ColumnBase::Display_PathgridPointList, ColumnBase::Flag_Dialogue)
{
}
{}
virtual QVariant get (const Record<ESXRecordT>& record) const
{
return true; // required by IdTree::hasChildren()
}
virtual void set (Record<ESXRecordT>& record, const QVariant& data)
{
}
virtual bool isEditable() const
{
return true;
}
};
template<typename ESXRecordT>
struct PathgridIndexColumn : public Column<ESXRecordT>
struct PathgridIndexColumn : public NestableColumn
{
PathgridIndexColumn()
: Column<ESXRecordT> (Columns::ColumnId_PathgridIndex, ColumnBase::Display_Integer)
: NestableColumn (Columns::ColumnId_PathgridIndex,
ColumnBase::Display_Integer, ColumnBase::Flag_Dialogue)
{}
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>
struct PathgridPointColumn : public NestableColumn
{
int mIndex; // 0=PosX, 1=PosY, 2=PosZ
PathgridPointColumn(int index)
: Column<ESXRecordT> (Columns::ColumnId_PathgridPosX+index, ColumnBase::Display_Integer), mIndex(index)
: NestableColumn (Columns::ColumnId_PathgridPosX+index,
ColumnBase::Display_Integer, ColumnBase::Flag_Dialogue)
{}
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 true;
@ -2341,18 +2316,13 @@ namespace CSMWorld
PathgridEdgeListColumn ()
: Column<ESXRecordT> (Columns::ColumnId_PathgridEdges,
ColumnBase::Display_PathgridEdgeList, ColumnBase::Flag_Dialogue)
{
}
{}
virtual QVariant get (const Record<ESXRecordT>& record) const
{
return true; // required by IdTree::hasChildren()
}
virtual void set (Record<ESXRecordT>& record, const QVariant& data)
{
}
virtual bool isEditable() const
{
return true;
@ -2360,46 +2330,25 @@ namespace CSMWorld
};
template<typename ESXRecordT>
struct PathgridEdgeIndexColumn : public Column<ESXRecordT>
struct PathgridEdgeIndexColumn : public NestableColumn
{
PathgridEdgeIndexColumn()
: Column<ESXRecordT> (Columns::ColumnId_PathgridEdgeIndex, ColumnBase::Display_Integer)
: NestableColumn (Columns::ColumnId_PathgridEdgeIndex,
ColumnBase::Display_Integer, ColumnBase::Flag_Dialogue)
{}
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>
struct PathgridEdgeColumn : public NestableColumn
{
int mIndex;
PathgridEdgeColumn (int index)
: Column<ESXRecordT> (Columns::ColumnId_PathgridEdge0+index, ColumnBase::Display_Integer), mIndex(index)
{
}
virtual QVariant get (const Record<ESXRecordT>& record) const
{
return QVariant(); // FIXME
}
virtual void set (Record<ESXRecordT>& record, const QVariant& data)
{
}
: NestableColumn (Columns::ColumnId_PathgridEdge0+index,
ColumnBase::Display_Integer, ColumnBase::Flag_Dialogue)
{}
virtual bool isEditable() const
{

@ -287,11 +287,6 @@ int CSMWorld::Columns::getId (const std::string& name)
namespace
{
static const char *sSkills[] =
{
"Long Blade"
};
static const char *sSpecialisations[] =
{
"Combat", "Magic", "Stealth", 0
@ -394,7 +389,6 @@ namespace
switch (column)
{
case CSMWorld::Columns::ColumnId_Specialisation: return sSpecialisations;
case CSMWorld::Columns::ColumnId_Skill: return sSkills;
case CSMWorld::Columns::ColumnId_Attribute: return sAttributes;
case CSMWorld::Columns::ColumnId_SpellType: return sSpellTypes;
case CSMWorld::Columns::ColumnId_ApparatusType: return sApparatusTypes;

@ -185,7 +185,9 @@ CSMWorld::DeleteNestedCommand::DeleteNestedCommand (IdTree& model,
mNestedRow(nestedRow),
NestedTableStoring(model, id, parentColumn)
{
setText (("Delete nested row in " + mId).c_str());
std::string title =
model.headerData(parentColumn, Qt::Horizontal, Qt::DisplayRole).toString().toUtf8().constData();
setText (("Delete row in " + title + " sub-table of " + mId).c_str());
}
void CSMWorld::DeleteNestedCommand::redo()
@ -211,7 +213,9 @@ CSMWorld::AddNestedCommand::AddNestedCommand(IdTree& model, const std::string& i
QUndoCommand(parent),
NestedTableStoring(model, id, parentColumn)
{
setText (("Added nested row in " + mId).c_str());
std::string title =
model.headerData(parentColumn, Qt::Horizontal, Qt::DisplayRole).toString().toUtf8().constData();
setText (("Add row in " + title + " sub-table of " + mId).c_str());
}
void CSMWorld::AddNestedCommand::redo()

@ -263,17 +263,17 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, const ResourcesManager& resourc
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));
mPathgrids.getNestableColumn(mPathgrids.getColumns()-1)->addColumn(new PathgridIndexColumn ());
mPathgrids.getNestableColumn(mPathgrids.getColumns()-1)->addColumn(new PathgridPointColumn (0));
mPathgrids.getNestableColumn(mPathgrids.getColumns()-1)->addColumn(new PathgridPointColumn (1));
mPathgrids.getNestableColumn(mPathgrids.getColumns()-1)->addColumn(new PathgridPointColumn (2));
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));
mPathgrids.getNestableColumn(mPathgrids.getColumns()-1)->addColumn(new PathgridEdgeIndexColumn ());
mPathgrids.getNestableColumn(mPathgrids.getColumns()-1)->addColumn(new PathgridEdgeColumn (0));
mPathgrids.getNestableColumn(mPathgrids.getColumns()-1)->addColumn(new PathgridEdgeColumn (1));
mStartScripts.addColumn (new StringIdColumn<ESM::StartScript>);
mStartScripts.addColumn (new RecordStateColumn<ESM::StartScript>);

@ -22,7 +22,7 @@ namespace CSMWorld
virtual void removeNestedRow(Record<ESXRecordT>& record, int rowToRemove) const = 0;
virtual void setNestedTable(Record<ESXRecordT>& record, const NestedTableWrapperBase& nestedTable) = 0;
virtual void setNestedTable(Record<ESXRecordT>& record, const NestedTableWrapperBase& nestedTable) const = 0;
virtual NestedTableWrapperBase* nestedTable(const Record<ESXRecordT>& record) const = 0;

@ -102,7 +102,7 @@ namespace CSMWorld
}
};
virtual void setNestedTable(Record<ESXRecordT>& record, const NestedTableWrapperBase& nestedTable)
virtual void setNestedTable(Record<ESXRecordT>& record, const NestedTableWrapperBase& nestedTable) const
{
record.get().mPoints =
static_cast<const PathgridPointsWrap &>(nestedTable).mRecord.mPoints;
@ -204,7 +204,7 @@ namespace CSMWorld
record.setModified (pathgrid);
}
virtual void setNestedTable(Record<ESXRecordT>& record, const NestedTableWrapperBase& nestedTable)
virtual void setNestedTable(Record<ESXRecordT>& record, const NestedTableWrapperBase& nestedTable) const
{
record.get().mEdges =
static_cast<const NestedTableWrapper<ESM::Pathgrid::EdgeList> &>(nestedTable).mNestedTable;

@ -145,8 +145,8 @@ namespace CSMWorld
{
CastableHelper<ESXRecordT>::getRecord(data, index).get().mSpells.mList.at(subRowIndex) = std::string(value.toString().toUtf8());
}
throw std::logic_error("Trying to access non-existing column in the nested table!");
else
throw std::logic_error("Trying to access non-existing column in the nested table!");
}
virtual void addNestedRow (RefIdData& data, int index, int position) const

@ -57,7 +57,7 @@ void CSMWorld::NestedRefIdAdapter::addNestedRow (const RefIdColumn *column, RefI
getHelper(column)->addNestedRow(data, index, position); //This code grows more boring and boring. I would love some macros.
}
void CSMWorld::NestedRefIdAdapter::setNestedTable (const RefIdColumn* column, RefIdData& data, int index, const NestedTableWrapperBase& nestedTable)
void CSMWorld::NestedRefIdAdapter::setNestedTable (const RefIdColumn* column, RefIdData& data, int index, const NestedTableWrapperBase& nestedTable) const
{
getHelper(column)->setNestedTable(data, index, nestedTable);
}

@ -69,7 +69,7 @@ namespace CSMWorld
virtual void addNestedRow (const RefIdColumn *column, RefIdData& data, int index, int position) const = 0;
virtual void setNestedTable (const RefIdColumn* column, RefIdData& data, int index, const NestedTableWrapperBase& nestedTable) = 0;
virtual void setNestedTable (const RefIdColumn* column, RefIdData& data, int index, const NestedTableWrapperBase& nestedTable) const = 0;
virtual NestedTableWrapperBase* nestedTable (const RefIdColumn* column, const RefIdData& data, int index) const = 0;
};
@ -97,7 +97,7 @@ namespace CSMWorld
virtual void addNestedRow (const RefIdColumn *column, RefIdData& data, int index, int position) const;
virtual void setNestedTable (const RefIdColumn* column, RefIdData& data, int index, const NestedTableWrapperBase& nestedTable);
virtual void setNestedTable (const RefIdColumn* column, RefIdData& data, int index, const NestedTableWrapperBase& nestedTable) const;
virtual NestedTableWrapperBase* nestedTable (const RefIdColumn* column, const RefIdData& data, int index) const;

@ -25,8 +25,7 @@ bool CSMWorld::RefIdColumn::isUserEditable() const
return mUserEditable;
}
// FIXME: const problem
/*const*/ CSMWorld::RefIdAdapter& CSMWorld::RefIdCollection::findAdapter (UniversalId::Type type) const
const CSMWorld::RefIdAdapter& CSMWorld::RefIdCollection::findAdapter (UniversalId::Type type) const
{
std::map<UniversalId::Type, RefIdAdapter *>::const_iterator iter = mAdapters.find (type);
@ -684,10 +683,8 @@ void CSMWorld::RefIdCollection::setNestedTable(int row, int column, const CSMWor
{
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row);
// FIXME: const problem
CSMWorld::NestedRefIdAdapter& adaptor = dynamic_cast<CSMWorld::NestedRefIdAdapter&>(findAdapter (localIndex.second));
const CSMWorld::NestedRefIdAdapter& adaptor = dynamic_cast<const CSMWorld::NestedRefIdAdapter&>(findAdapter (localIndex.second));
// FIXME: const problem
adaptor.setNestedTable(&mColumns.at(column), mData, localIndex.first, nestedTable);
}

@ -46,7 +46,7 @@ namespace CSMWorld
private:
/*const*/ RefIdAdapter& findAdapter (UniversalId::Type) const;
const RefIdAdapter& findAdapter (UniversalId::Type) const;
///< Throws an exception if no adaptor for \a Type can be found.
public:

@ -32,7 +32,7 @@ namespace CSMWorld
virtual void loadRecord (ESXRecordT& record, ESM::ESMReader& reader);
NestedIdAdapter<ESXRecordT>* getAdapter(const ColumnBase &column) const;
const NestedIdAdapter<ESXRecordT>& getAdapter(const ColumnBase &column) const;
public:
@ -88,7 +88,7 @@ namespace CSMWorld
}
template<typename ESXRecordT, typename IdAccessorT>
NestedIdAdapter<ESXRecordT>* SubCellCollection<ESXRecordT, IdAccessorT>::getAdapter(const ColumnBase &column) const
const NestedIdAdapter<ESXRecordT>& SubCellCollection<ESXRecordT, IdAccessorT>::getAdapter(const ColumnBase &column) const
{
typename std::map<const ColumnBase *, NestedIdAdapter<ESXRecordT>* >::const_iterator iter =
mAdapters.find (&column);
@ -96,28 +96,36 @@ namespace CSMWorld
if (iter==mAdapters.end())
throw std::logic_error("No such column in the nestedidadapter");
return iter->second;
return *iter->second;
}
template<typename ESXRecordT, typename IdAccessorT>
void SubCellCollection<ESXRecordT, IdAccessorT>::addNestedRow(int row, int column, int position)
{
getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column))->addNestedRow(
Collection<ESXRecordT, IdAccessorT>::getRecord(row), position);
Record<ESXRecordT> record;
record.assign(Collection<ESXRecordT, IdAccessorT>::getRecord(row));
getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).addNestedRow(record, position);
Collection<ESXRecordT, IdAccessorT>::setRecord(row, record);
}
template<typename ESXRecordT, typename IdAccessorT>
void SubCellCollection<ESXRecordT, IdAccessorT>::removeNestedRows(int row, int column, int subRow)
{
getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column))->removeNestedRow(
Collection<ESXRecordT, IdAccessorT>::getRecord(row), subRow);
Record<ESXRecordT> record;
record.assign(Collection<ESXRecordT, IdAccessorT>::getRecord(row));
getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).removeNestedRow(record, subRow);
Collection<ESXRecordT, IdAccessorT>::setRecord(row, record);
}
template<typename ESXRecordT, typename IdAccessorT>
QVariant SubCellCollection<ESXRecordT, IdAccessorT>::getNestedData (int row,
int column, int subRow, int subColumn) const
{
return getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column))->getNestedData(
return getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).getNestedData(
Collection<ESXRecordT, IdAccessorT>::getRecord(row), subRow, subColumn);
}
@ -125,15 +133,20 @@ namespace CSMWorld
void SubCellCollection<ESXRecordT, IdAccessorT>::setNestedData(int row,
int column, const QVariant& data, int subRow, int subColumn)
{
getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column))->setNestedData(
Collection<ESXRecordT, IdAccessorT>::getRecord(row), data, subRow, subColumn);
Record<ESXRecordT> record;
record.assign(Collection<ESXRecordT, IdAccessorT>::getRecord(row));
getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).setNestedData(
record, data, subRow, subColumn);
Collection<ESXRecordT, IdAccessorT>::setRecord(row, record);
}
template<typename ESXRecordT, typename IdAccessorT>
CSMWorld::NestedTableWrapperBase* SubCellCollection<ESXRecordT, IdAccessorT>::nestedTable(int row,
int column) const
{
return getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column))->nestedTable(
return getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).nestedTable(
Collection<ESXRecordT, IdAccessorT>::getRecord(row));
}
@ -141,21 +154,26 @@ namespace CSMWorld
void SubCellCollection<ESXRecordT, IdAccessorT>::setNestedTable(int row,
int column, const CSMWorld::NestedTableWrapperBase& nestedTable)
{
getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column))->setNestedTable(
Collection<ESXRecordT, IdAccessorT>::getRecord(row), nestedTable);
Record<ESXRecordT> record;
record.assign(Collection<ESXRecordT, IdAccessorT>::getRecord(row));
getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).setNestedTable(
record, nestedTable);
Collection<ESXRecordT, IdAccessorT>::setRecord(row, record);
}
template<typename ESXRecordT, typename IdAccessorT>
int SubCellCollection<ESXRecordT, IdAccessorT>::getNestedRowsCount(int row, int column) const
{
return getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column))->getNestedRowsCount(
return getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).getNestedRowsCount(
Collection<ESXRecordT, IdAccessorT>::getRecord(row));
}
template<typename ESXRecordT, typename IdAccessorT>
int SubCellCollection<ESXRecordT, IdAccessorT>::getNestedColumnsCount(int row, int column) const
{
return getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column))->getNestedColumnsCount(
return getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).getNestedColumnsCount(
Collection<ESXRecordT, IdAccessorT>::getRecord(row));
}

Loading…
Cancel
Save