Changed the way the revert command works: it now clones the changed record and uses the new RecordBase::revert() method to restore the previous value

Added Flag_Dialogue_Refresh to var type and var value columns so that sub views update properly
pull/457/head
Doc West 7 years ago
parent 3cbbbeceb4
commit 9bfa01c579

@ -136,7 +136,7 @@ namespace CSMWorld
struct VarTypeColumn : public Column<ESXRecordT>
{
VarTypeColumn (ColumnBase::Display display)
: Column<ESXRecordT> (Columns::ColumnId_ValueType, display)
: Column<ESXRecordT> (Columns::ColumnId_ValueType, display, ColumnBase::Flag_Table | ColumnBase::Flag_Dialogue | ColumnBase::Flag_Dialogue_Refresh)
{}
virtual QVariant get (const Record<ESXRecordT>& record) const
@ -161,7 +161,7 @@ namespace CSMWorld
template<typename ESXRecordT>
struct VarValueColumn : public Column<ESXRecordT>
{
VarValueColumn() : Column<ESXRecordT> (Columns::ColumnId_Value, ColumnBase::Display_Var) {}
VarValueColumn() : Column<ESXRecordT> (Columns::ColumnId_Value, ColumnBase::Display_Var, ColumnBase::Flag_Table | ColumnBase::Flag_Dialogue | ColumnBase::Flag_Dialogue_Refresh) {}
virtual QVariant get (const Record<ESXRecordT>& record) const
{

@ -294,16 +294,19 @@ void CSMWorld::CreateCommand::undo()
}
CSMWorld::RevertCommand::RevertCommand (IdTable& model, const std::string& id, QUndoCommand* parent)
: QUndoCommand (parent), mModel (model), mId (id), mOld (0)
: QUndoCommand (parent), mModel (model), mId (id), mOld (0), mNew (0)
{
setText (("Revert record " + id).c_str());
mNew = model.getRecord(id).clone();
mNew->revert();
mOld = model.getRecord (id).clone();
}
CSMWorld::RevertCommand::~RevertCommand()
{
delete mOld;
delete mNew;
}
void CSMWorld::RevertCommand::redo()
@ -319,20 +322,7 @@ void CSMWorld::RevertCommand::redo()
}
else
{
// notify view that data has changed, previously only the modified column was
// updated in the view unless the user had selected another item or forced a
// repaint with other means
int count = mModel.columnCount (index.parent ());
for (int i=0; i<count; ++i)
{
if (i != index.column())
{
auto colIndex = mModel.index (index.row (), i, index.parent ());
auto data = mModel.data (colIndex);
mModel.setData (colIndex, data);
}
}
mModel.setRecord (mId, *mNew);
mModel.setData (index, static_cast<int> (RecordBase::State_BaseOnly));
}
}

@ -201,6 +201,7 @@ namespace CSMWorld
IdTable& mModel;
std::string mId;
RecordBase *mOld;
RecordBase *mNew;
// not implemented
RevertCommand (const RevertCommand&);

@ -24,6 +24,8 @@ namespace CSMWorld
virtual RecordBase *modifiedCopy() const = 0;
virtual void revert() = 0;
virtual void assign (const RecordBase& record) = 0;
///< Will throw an exception if the types don't match.
@ -49,6 +51,8 @@ namespace CSMWorld
virtual RecordBase *modifiedCopy() const;
void revert() override;
virtual void assign (const RecordBase& record);
const ESXRecordT& get() const;
@ -96,6 +100,12 @@ namespace CSMWorld
return new Record<ESXRecordT> (*this);
}
template<typename ESXRecordT>
void Record<ESXRecordT>::revert()
{
mModified = mBase;
}
template <typename ESXRecordT>
void Record<ESXRecordT>::assign (const RecordBase& record)
{

Loading…
Cancel
Save