From e1877338113e4d1300e63984845f6a9280fe17fc Mon Sep 17 00:00:00 2001 From: Doc West Date: Thu, 5 Jul 2018 18:03:55 +0200 Subject: [PATCH] Notify views of changes in all columns when updating the ColumnId_Modification column --- apps/opencs/model/world/commands.cpp | 6 +----- apps/opencs/model/world/commands.hpp | 1 - apps/opencs/model/world/idtable.cpp | 26 ++++++++++++++++++++++---- apps/opencs/model/world/record.hpp | 10 ---------- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index ff4bab989..79900c6c4 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -294,19 +294,16 @@ void CSMWorld::CreateCommand::undo() } CSMWorld::RevertCommand::RevertCommand (IdTable& model, const std::string& id, QUndoCommand* parent) -: QUndoCommand (parent), mModel (model), mId (id), mOld (0), mNew (0) +: QUndoCommand (parent), mModel (model), mId (id), mOld (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() @@ -322,7 +319,6 @@ void CSMWorld::RevertCommand::redo() } else { - mModel.setRecord (mId, *mNew); mModel.setData (index, static_cast (RecordBase::State_BaseOnly)); } } diff --git a/apps/opencs/model/world/commands.hpp b/apps/opencs/model/world/commands.hpp index 46fa6d8a0..58a1b1d1c 100644 --- a/apps/opencs/model/world/commands.hpp +++ b/apps/opencs/model/world/commands.hpp @@ -201,7 +201,6 @@ namespace CSMWorld IdTable& mModel; std::string mId; RecordBase *mOld; - RecordBase *mNew; // not implemented RevertCommand (const RevertCommand&); diff --git a/apps/opencs/model/world/idtable.cpp b/apps/opencs/model/world/idtable.cpp index 7492b6b17..75355116f 100644 --- a/apps/opencs/model/world/idtable.cpp +++ b/apps/opencs/model/world/idtable.cpp @@ -86,12 +86,30 @@ bool CSMWorld::IdTable::setData (const QModelIndex &index, const QVariant &value mIdCollection->setData (index.row(), index.column(), value); emit dataChanged(index, index); - // Modifying a value can also change the Modified status of a record unless . int stateColumn = searchColumnIndex(Columns::ColumnId_Modification); - if (stateColumn != -1 && index.column() != stateColumn) + if (stateColumn != -1) { - QModelIndex stateIndex = this->index(index.row(), stateColumn); - emit dataChanged(stateIndex, stateIndex); + if (index.column() == stateColumn) + { + // modifying the state column can modify other values. we need to tell + // views that the whole row has changed. + + int count = columnCount(index.parent()); + for (int i=0; iindex(index.row(), i); + emit dataChanged(columnIndex, columnIndex); + } + } + + } else + { + // Modifying a value can also change the Modified status of a record unless . + QModelIndex stateIndex = this->index(index.row(), stateColumn); + emit dataChanged(stateIndex, stateIndex); + } } return true; diff --git a/apps/opencs/model/world/record.hpp b/apps/opencs/model/world/record.hpp index db5822c97..3362f9f96 100644 --- a/apps/opencs/model/world/record.hpp +++ b/apps/opencs/model/world/record.hpp @@ -24,8 +24,6 @@ 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. @@ -51,8 +49,6 @@ namespace CSMWorld virtual RecordBase *modifiedCopy() const; - void revert() override; - virtual void assign (const RecordBase& record); const ESXRecordT& get() const; @@ -100,12 +96,6 @@ namespace CSMWorld return new Record (*this); } - template - void Record::revert() - { - mModified = mBase; - } - template void Record::assign (const RecordBase& record) {