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 <cctype>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
|
@ -92,7 +93,7 @@ namespace CSMWorld
|
||||||
|
|
||||||
virtual void setData (int index, int column, const QVariant& data);
|
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);
|
virtual void setNestedTable(int row, int column, const NestedTableWrapperBase& nestedTable);
|
||||||
|
|
||||||
|
@ -308,9 +309,10 @@ namespace CSMWorld
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename ESXRecordT, typename IdAccessorT>
|
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>
|
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 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;
|
virtual void setNestedTable(int row, int column, const NestedTableWrapperBase& nestedTable) = 0;
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "idtable.hpp"
|
#include "idtable.hpp"
|
||||||
#include <components/misc/stringops.hpp>
|
#include <components/misc/stringops.hpp>
|
||||||
|
#include "nestedtablewrapper.hpp"
|
||||||
|
|
||||||
CSMWorld::ModifyCommand::ModifyCommand (QAbstractItemModel& model, const QModelIndex& index,
|
CSMWorld::ModifyCommand::ModifyCommand (QAbstractItemModel& model, const QModelIndex& index,
|
||||||
const QVariant& new_, QUndoCommand* parent)
|
const QVariant& new_, QUndoCommand* parent)
|
||||||
|
@ -178,7 +179,7 @@ CSMWorld::DeleteNestedCommand::DeleteNestedCommand (IdTable& model, const std::s
|
||||||
mParentColumn(parentColumn),
|
mParentColumn(parentColumn),
|
||||||
QUndoCommand(parent),
|
QUndoCommand(parent),
|
||||||
mNestedRow(nestedRow),
|
mNestedRow(nestedRow),
|
||||||
mOld(model.nestedTable(model.getModelIndex(id, parentColumn)))
|
mOld (model.nestedTable(model.getModelIndex(id, parentColumn)))
|
||||||
{
|
{
|
||||||
setText (("Delete nested row in " + mId).c_str());
|
setText (("Delete nested row in " + mId).c_str());
|
||||||
}
|
}
|
||||||
|
@ -195,7 +196,12 @@ void CSMWorld::DeleteNestedCommand::undo()
|
||||||
{
|
{
|
||||||
const QModelIndex& parentIndex = mModel.getModelIndex(mId, mParentColumn);
|
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)
|
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),
|
mNewRow(nestedRow),
|
||||||
mParentColumn(parentColumn),
|
mParentColumn(parentColumn),
|
||||||
QUndoCommand(parent),
|
QUndoCommand(parent),
|
||||||
mOld(model.nestedTable(model.getModelIndex(id, parentColumn)))
|
mOld (model.nestedTable(model.getModelIndex(id, parentColumn)))
|
||||||
{
|
{
|
||||||
setText (("Added nested row in " + mId).c_str());
|
setText (("Added nested row in " + mId).c_str());
|
||||||
}
|
}
|
||||||
|
@ -220,5 +226,10 @@ void CSMWorld::AddNestedCommand::undo()
|
||||||
{
|
{
|
||||||
const QModelIndex& parentIndex = mModel.getModelIndex(mId, mParentColumn);
|
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;
|
std::string mId;
|
||||||
|
|
||||||
NestedTableWrapperBase mOld;
|
NestedTableWrapperBase* mOld;
|
||||||
|
|
||||||
int mParentColumn;
|
int mParentColumn;
|
||||||
|
|
||||||
|
@ -155,6 +155,8 @@ namespace CSMWorld
|
||||||
|
|
||||||
DeleteNestedCommand (IdTable& model, const std::string& id, int nestedRow, int parentColumn, QUndoCommand* parent = 0);
|
DeleteNestedCommand (IdTable& model, const std::string& id, int nestedRow, int parentColumn, QUndoCommand* parent = 0);
|
||||||
|
|
||||||
|
~DeleteNestedCommand();
|
||||||
|
|
||||||
virtual void redo();
|
virtual void redo();
|
||||||
|
|
||||||
virtual void undo();
|
virtual void undo();
|
||||||
|
@ -166,7 +168,7 @@ namespace CSMWorld
|
||||||
|
|
||||||
std::string mId;
|
std::string mId;
|
||||||
|
|
||||||
NestedTableWrapperBase mOld;
|
NestedTableWrapperBase* mOld;
|
||||||
|
|
||||||
int mNewRow;
|
int mNewRow;
|
||||||
|
|
||||||
|
@ -176,6 +178,8 @@ namespace CSMWorld
|
||||||
|
|
||||||
AddNestedCommand(IdTable& model, const std::string& id, int nestedRow, int parentColumn, QUndoCommand* parent = 0);
|
AddNestedCommand(IdTable& model, const std::string& id, int nestedRow, int parentColumn, QUndoCommand* parent = 0);
|
||||||
|
|
||||||
|
~AddNestedCommand();
|
||||||
|
|
||||||
virtual void redo();
|
virtual void redo();
|
||||||
|
|
||||||
virtual void undo();
|
virtual void undo();
|
||||||
|
|
|
@ -367,9 +367,12 @@ void CSMWorld::IdTable::setNestedTable(const QModelIndex& index, const CSMWorld:
|
||||||
}
|
}
|
||||||
|
|
||||||
mIdCollection->setNestedTable(index.row(), index.column(), nestedTable);
|
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))
|
if (!hasChildren(index))
|
||||||
{
|
{
|
||||||
|
|
|
@ -53,7 +53,7 @@ namespace CSMWorld
|
||||||
|
|
||||||
QVariant nestedHeaderData(int section, int subSection, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
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);
|
void setNestedTable(const QModelIndex &index, const NestedTableWrapperBase& nestedTable);
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
#ifndef CSM_WOLRD_NESTEDTABLEWRAPPER_H
|
#ifndef CSM_WOLRD_NESTEDTABLEWRAPPER_H
|
||||||
#define CSM_WOLRD_NESTEDTABLEWRAPPER_H
|
#define CSM_WOLRD_NESTEDTABLEWRAPPER_H
|
||||||
|
|
||||||
#include <components/esm/loadcont.hpp>
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
namespace CSMWorld
|
namespace CSMWorld
|
||||||
{
|
{
|
||||||
struct NestedTableWrapperBase
|
struct NestedTableWrapperBase
|
||||||
|
@ -14,20 +11,13 @@ namespace CSMWorld
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename NestedTable>
|
template<typename NestedTable>
|
||||||
class NestedTableWrapper : public NestedTableWrapperBase
|
struct NestedTableWrapper : public NestedTableWrapperBase
|
||||||
{
|
{
|
||||||
NestedTable mNestedTable;
|
NestedTable mNestedTable;
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
NestedTableWrapper(const NestedTable& nestedTable)
|
NestedTableWrapper(const NestedTable& nestedTable)
|
||||||
: mNestedTable(nestedTable) {}
|
: mNestedTable(nestedTable) {}
|
||||||
|
|
||||||
NestedTable getNestedTable() const
|
|
||||||
{
|
|
||||||
return mNestedTable;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~NestedTableWrapper() {}
|
virtual ~NestedTableWrapper() {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ namespace CSMWorld
|
||||||
|
|
||||||
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) = 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;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -316,17 +316,17 @@ void CSMWorld::ContainerRefIdAdapter::setNestedTable(const RefIdColumn* column,
|
||||||
Record<ESM::Container>& record = dynamic_cast<Record<ESM::Container>&> (
|
Record<ESM::Container>& record = dynamic_cast<Record<ESM::Container>&> (
|
||||||
data.getRecord (RefIdData::LocalIndex (index, UniversalId::Type_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,
|
CSMWorld::NestedTableWrapperBase* CSMWorld::ContainerRefIdAdapter::nestedTable (const RefIdColumn* column,
|
||||||
const RefIdData& data,
|
const RefIdData& data,
|
||||||
int index) const
|
int index) const
|
||||||
{
|
{
|
||||||
const Record<ESM::Container>& record = dynamic_cast<const Record<ESM::Container>&> (
|
const Record<ESM::Container>& record = dynamic_cast<const Record<ESM::Container>&> (
|
||||||
data.getRecord (RefIdData::LocalIndex (index, UniversalId::Type_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,
|
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 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);
|
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);
|
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);
|
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 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);
|
virtual void setNestedTable(int row, int column, const NestedTableWrapperBase& nestedTable);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue