From 4a6457c3464dc0b39090a3fc6ee4c1cdb74150b1 Mon Sep 17 00:00:00 2001 From: Doc West Date: Thu, 5 Jul 2018 00:37:19 +0200 Subject: [PATCH] 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 --- apps/opencs/model/world/columnimp.hpp | 4 ++-- apps/opencs/model/world/commands.cpp | 20 +++++--------------- apps/opencs/model/world/commands.hpp | 1 + apps/opencs/model/world/record.hpp | 12 +++++++++++- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/apps/opencs/model/world/columnimp.hpp b/apps/opencs/model/world/columnimp.hpp index 4ad447b0a..cd2a4c79e 100644 --- a/apps/opencs/model/world/columnimp.hpp +++ b/apps/opencs/model/world/columnimp.hpp @@ -136,7 +136,7 @@ namespace CSMWorld struct VarTypeColumn : public Column { VarTypeColumn (ColumnBase::Display display) - : Column (Columns::ColumnId_ValueType, display) + : Column (Columns::ColumnId_ValueType, display, ColumnBase::Flag_Table | ColumnBase::Flag_Dialogue | ColumnBase::Flag_Dialogue_Refresh) {} virtual QVariant get (const Record& record) const @@ -161,7 +161,7 @@ namespace CSMWorld template struct VarValueColumn : public Column { - VarValueColumn() : Column (Columns::ColumnId_Value, ColumnBase::Display_Var) {} + VarValueColumn() : Column (Columns::ColumnId_Value, ColumnBase::Display_Var, ColumnBase::Flag_Table | ColumnBase::Flag_Dialogue | ColumnBase::Flag_Dialogue_Refresh) {} virtual QVariant get (const Record& record) const { diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index c67de6350..ff4bab989 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -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 (RecordBase::State_BaseOnly)); } } diff --git a/apps/opencs/model/world/commands.hpp b/apps/opencs/model/world/commands.hpp index 58a1b1d1c..46fa6d8a0 100644 --- a/apps/opencs/model/world/commands.hpp +++ b/apps/opencs/model/world/commands.hpp @@ -201,6 +201,7 @@ namespace CSMWorld IdTable& mModel; std::string mId; RecordBase *mOld; + RecordBase *mNew; // not implemented RevertCommand (const RevertCommand&); diff --git a/apps/opencs/model/world/record.hpp b/apps/opencs/model/world/record.hpp index 0313f2e41..db5822c97 100644 --- a/apps/opencs/model/world/record.hpp +++ b/apps/opencs/model/world/record.hpp @@ -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 (*this); } + template + void Record::revert() + { + mModified = mBase; + } + template void Record::assign (const RecordBase& record) { @@ -156,4 +166,4 @@ namespace CSMWorld } } -#endif \ No newline at end of file +#endif