forked from mirror/openmw-tes3mp
correctly handling the nestedTable for undo (but removing and adding
rows in proper QT way is still TODO)
This commit is contained in:
parent
0017fc68ef
commit
4d79034dbf
12 changed files with 47 additions and 37 deletions
|
@ -7,6 +7,7 @@
|
|||
#include <cctype>
|
||||
#include <stdexcept>
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
#include <QVariant>
|
||||
|
||||
|
@ -92,7 +93,7 @@ namespace CSMWorld
|
|||
|
||||
virtual void setData (int index, int column, const QVariant& data);
|
||||
|
||||
virtual NestedTableWrapperBase nestedTable(int row, int column) const;
|
||||
virtual NestedTableWrapperBase* nestedTable(int row, int column) const;
|
||||
|
||||
virtual void setNestedTable(int row, int column, const NestedTableWrapperBase& nestedTable);
|
||||
|
||||
|
@ -308,9 +309,10 @@ namespace CSMWorld
|
|||
}
|
||||
|
||||
template<typename ESXRecordT, typename IdAccessorT>
|
||||
NestedTableWrapperBase Collection<ESXRecordT, IdAccessorT>::nestedTable(int row, int column) const
|
||||
NestedTableWrapperBase* Collection<ESXRecordT, IdAccessorT>::nestedTable(int row, int column) const
|
||||
{
|
||||
return NestedTableWrapperBase();
|
||||
assert(false);
|
||||
return new NestedTableWrapperBase();
|
||||
}
|
||||
|
||||
template<typename ESXRecordT, typename IdAccessorT>
|
||||
|
|
|
@ -51,7 +51,7 @@ namespace CSMWorld
|
|||
|
||||
virtual QVariant getNestedData(int row, int column, int subRow, int subColumn) const = 0;
|
||||
|
||||
virtual NestedTableWrapperBase nestedTable(int row, int column) const = 0;
|
||||
virtual NestedTableWrapperBase* nestedTable(int row, int column) const = 0;
|
||||
|
||||
virtual void setNestedTable(int row, int column, const NestedTableWrapperBase& nestedTable) = 0;
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "idtable.hpp"
|
||||
#include <components/misc/stringops.hpp>
|
||||
#include "nestedtablewrapper.hpp"
|
||||
|
||||
CSMWorld::ModifyCommand::ModifyCommand (QAbstractItemModel& model, const QModelIndex& index,
|
||||
const QVariant& new_, QUndoCommand* parent)
|
||||
|
@ -178,7 +179,7 @@ CSMWorld::DeleteNestedCommand::DeleteNestedCommand (IdTable& model, const std::s
|
|||
mParentColumn(parentColumn),
|
||||
QUndoCommand(parent),
|
||||
mNestedRow(nestedRow),
|
||||
mOld(model.nestedTable(model.getModelIndex(id, parentColumn)))
|
||||
mOld (model.nestedTable(model.getModelIndex(id, parentColumn)))
|
||||
{
|
||||
setText (("Delete nested row in " + mId).c_str());
|
||||
}
|
||||
|
@ -195,7 +196,12 @@ void CSMWorld::DeleteNestedCommand::undo()
|
|||
{
|
||||
const QModelIndex& parentIndex = mModel.getModelIndex(mId, mParentColumn);
|
||||
|
||||
mModel.setNestedTable(parentIndex, mOld);
|
||||
mModel.setNestedTable(parentIndex, *mOld);
|
||||
}
|
||||
|
||||
CSMWorld::DeleteNestedCommand::~DeleteNestedCommand()
|
||||
{
|
||||
delete mOld;
|
||||
}
|
||||
|
||||
CSMWorld::AddNestedCommand::AddNestedCommand(IdTable& model, const std::string& id, int nestedRow, int parentColumn, QUndoCommand* parent)
|
||||
|
@ -204,7 +210,7 @@ CSMWorld::AddNestedCommand::AddNestedCommand(IdTable& model, const std::string&
|
|||
mNewRow(nestedRow),
|
||||
mParentColumn(parentColumn),
|
||||
QUndoCommand(parent),
|
||||
mOld(model.nestedTable(model.getModelIndex(id, parentColumn)))
|
||||
mOld (model.nestedTable(model.getModelIndex(id, parentColumn)))
|
||||
{
|
||||
setText (("Added nested row in " + mId).c_str());
|
||||
}
|
||||
|
@ -220,5 +226,10 @@ void CSMWorld::AddNestedCommand::undo()
|
|||
{
|
||||
const QModelIndex& parentIndex = mModel.getModelIndex(mId, mParentColumn);
|
||||
|
||||
mModel.setNestedTable(parentIndex, mOld);
|
||||
mModel.setNestedTable(parentIndex, *mOld);
|
||||
}
|
||||
|
||||
CSMWorld::AddNestedCommand::~AddNestedCommand()
|
||||
{
|
||||
delete mOld;
|
||||
}
|
||||
|
|
|
@ -145,7 +145,7 @@ namespace CSMWorld
|
|||
|
||||
std::string mId;
|
||||
|
||||
NestedTableWrapperBase mOld;
|
||||
NestedTableWrapperBase* mOld;
|
||||
|
||||
int mParentColumn;
|
||||
|
||||
|
@ -155,6 +155,8 @@ namespace CSMWorld
|
|||
|
||||
DeleteNestedCommand (IdTable& model, const std::string& id, int nestedRow, int parentColumn, QUndoCommand* parent = 0);
|
||||
|
||||
~DeleteNestedCommand();
|
||||
|
||||
virtual void redo();
|
||||
|
||||
virtual void undo();
|
||||
|
@ -166,7 +168,7 @@ namespace CSMWorld
|
|||
|
||||
std::string mId;
|
||||
|
||||
NestedTableWrapperBase mOld;
|
||||
NestedTableWrapperBase* mOld;
|
||||
|
||||
int mNewRow;
|
||||
|
||||
|
@ -175,6 +177,8 @@ namespace CSMWorld
|
|||
public:
|
||||
|
||||
AddNestedCommand(IdTable& model, const std::string& id, int nestedRow, int parentColumn, QUndoCommand* parent = 0);
|
||||
|
||||
~AddNestedCommand();
|
||||
|
||||
virtual void redo();
|
||||
|
||||
|
|
|
@ -367,9 +367,12 @@ void CSMWorld::IdTable::setNestedTable(const QModelIndex& index, const CSMWorld:
|
|||
}
|
||||
|
||||
mIdCollection->setNestedTable(index.row(), index.column(), nestedTable);
|
||||
|
||||
emit dataChanged (CSMWorld::IdTable::index (index.row(), 0),
|
||||
CSMWorld::IdTable::index (index.row(), mIdCollection->getColumns()-1));
|
||||
}
|
||||
|
||||
CSMWorld::NestedTableWrapperBase CSMWorld::IdTable::nestedTable(const QModelIndex& index) const
|
||||
CSMWorld::NestedTableWrapperBase* CSMWorld::IdTable::nestedTable(const QModelIndex& index) const
|
||||
{
|
||||
if (!hasChildren(index))
|
||||
{
|
||||
|
|
|
@ -53,7 +53,7 @@ namespace CSMWorld
|
|||
|
||||
QVariant nestedHeaderData(int section, int subSection, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||
|
||||
NestedTableWrapperBase nestedTable(const QModelIndex &index) const;
|
||||
NestedTableWrapperBase* nestedTable(const QModelIndex &index) const;
|
||||
|
||||
void setNestedTable(const QModelIndex &index, const NestedTableWrapperBase& nestedTable);
|
||||
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
#ifndef CSM_WOLRD_NESTEDTABLEWRAPPER_H
|
||||
#define CSM_WOLRD_NESTEDTABLEWRAPPER_H
|
||||
|
||||
#include <components/esm/loadcont.hpp>
|
||||
|
||||
#include <vector>
|
||||
namespace CSMWorld
|
||||
{
|
||||
struct NestedTableWrapperBase
|
||||
|
@ -14,20 +11,13 @@ namespace CSMWorld
|
|||
};
|
||||
|
||||
template<typename NestedTable>
|
||||
class NestedTableWrapper : public NestedTableWrapperBase
|
||||
struct NestedTableWrapper : public NestedTableWrapperBase
|
||||
{
|
||||
NestedTable mNestedTable;
|
||||
|
||||
public:
|
||||
|
||||
NestedTableWrapper(const NestedTable& nestedTable)
|
||||
NestedTableWrapper(const NestedTable& nestedTable)
|
||||
: mNestedTable(nestedTable) {}
|
||||
|
||||
NestedTable getNestedTable() const
|
||||
{
|
||||
return mNestedTable;
|
||||
}
|
||||
|
||||
virtual ~NestedTableWrapper() {}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ namespace CSMWorld
|
|||
|
||||
virtual void setNestedTable (const RefIdColumn* column, RefIdData& data, int index, const NestedTableWrapperBase& nestedTable) = 0;
|
||||
|
||||
virtual NestedTableWrapperBase nestedTable (const RefIdColumn * column, const RefIdData& data, int index) const = 0;
|
||||
virtual NestedTableWrapperBase* nestedTable (const RefIdColumn* column, const RefIdData& data, int index) const = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -227,24 +227,24 @@ void CSMWorld::ContainerRefIdAdapter::removeNestedRow (const RefIdColumn *column
|
|||
|
||||
std::vector<ESM::ContItem>& list = static_cast<Record<ESM::Container>&> (
|
||||
data.getRecord (RefIdData::LocalIndex (index, UniversalId::Type_Container))).get().mInventory.mList;
|
||||
|
||||
|
||||
list.erase (list.begin () + rowToRemove);
|
||||
}
|
||||
|
||||
void CSMWorld::ContainerRefIdAdapter::addNestedRow (const RefIdColumn *column, RefIdData& data, int index, int position) const
|
||||
{
|
||||
assert(column==mContent);
|
||||
|
||||
|
||||
std::vector<ESM::ContItem>& list = static_cast<Record<ESM::Container>&> (
|
||||
data.getRecord (RefIdData::LocalIndex (index, UniversalId::Type_Container))).get().mInventory.mList;
|
||||
|
||||
|
||||
ESM::ContItem newRow = {0, ""};
|
||||
if (position >= (int)list.size())
|
||||
{
|
||||
list.push_back(newRow);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
list.insert(list.begin()+position, newRow);
|
||||
|
||||
return;
|
||||
|
@ -310,23 +310,23 @@ void CSMWorld::ContainerRefIdAdapter::setNestedData(const RefIdColumn *column,
|
|||
|
||||
void CSMWorld::ContainerRefIdAdapter::setNestedTable(const RefIdColumn* column,
|
||||
RefIdData& data,
|
||||
int index,
|
||||
int index,
|
||||
const NestedTableWrapperBase& nestedTable)
|
||||
{
|
||||
Record<ESM::Container>& record = dynamic_cast<Record<ESM::Container>&> (
|
||||
data.getRecord (RefIdData::LocalIndex (index, UniversalId::Type_Container)));
|
||||
|
||||
record.get().mInventory.mList = (dynamic_cast<const NestedTableWrapper<std::vector<ESM::ContItem> >&>(nestedTable)).getNestedTable();
|
||||
record.get().mInventory.mList = (static_cast<const NestedTableWrapper<std::vector<ESM::ContItem> >&>(nestedTable)).mNestedTable;
|
||||
}
|
||||
|
||||
CSMWorld::NestedTableWrapperBase CSMWorld::ContainerRefIdAdapter::nestedTable (const RefIdColumn* column,
|
||||
const RefIdData& data,
|
||||
CSMWorld::NestedTableWrapperBase* CSMWorld::ContainerRefIdAdapter::nestedTable (const RefIdColumn* column,
|
||||
const RefIdData& data,
|
||||
int index) const
|
||||
{
|
||||
const Record<ESM::Container>& record = dynamic_cast<const Record<ESM::Container>&> (
|
||||
data.getRecord (RefIdData::LocalIndex (index, UniversalId::Type_Container)));
|
||||
|
||||
return NestedTableWrapper<std::vector<ESM::ContItem> >(record.get().mInventory.mList);
|
||||
return new NestedTableWrapper<std::vector<ESM::ContItem> >(record.get().mInventory.mList);
|
||||
}
|
||||
|
||||
QVariant CSMWorld::ContainerRefIdAdapter::getNestedData (const CSMWorld::RefIdColumn* column,
|
||||
|
|
|
@ -640,7 +640,7 @@ namespace CSMWorld
|
|||
|
||||
virtual void addNestedRow (const RefIdColumn *column, RefIdData& data, int index, int position) const;
|
||||
|
||||
virtual NestedTableWrapperBase nestedTable (const RefIdColumn * column, const RefIdData& data, int index) const;
|
||||
virtual NestedTableWrapperBase* nestedTable (const RefIdColumn * column, const RefIdData& data, int index) const;
|
||||
|
||||
virtual void setNestedTable (const RefIdColumn* column, RefIdData& data, int index, const NestedTableWrapperBase& nestedTable);
|
||||
};
|
||||
|
|
|
@ -652,7 +652,7 @@ void CSMWorld::RefIdCollection::setNestedTable(int row, int column, const CSMWor
|
|||
adaptor.setNestedTable(&mColumns.at(column), mData, localIndex.first, nestedTable);
|
||||
}
|
||||
|
||||
CSMWorld::NestedTableWrapperBase CSMWorld::RefIdCollection::nestedTable(int row, int column) const
|
||||
CSMWorld::NestedTableWrapperBase* CSMWorld::RefIdCollection::nestedTable(int row, int column) const
|
||||
{
|
||||
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row);
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ namespace CSMWorld
|
|||
|
||||
virtual QVariant getNestedData(int row, int column, int subRow, int subColumn) const;
|
||||
|
||||
virtual NestedTableWrapperBase nestedTable(int row, int column) const;
|
||||
virtual NestedTableWrapperBase* nestedTable(int row, int column) const;
|
||||
|
||||
virtual void setNestedTable(int row, int column, const NestedTableWrapperBase& nestedTable);
|
||||
|
||||
|
|
Loading…
Reference in a new issue