From 6397d9d40e4716f1e93886c6ad9e55fea92191c2 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Tue, 14 Jan 2014 13:12:15 +0100 Subject: [PATCH 01/43] Added mCloneAction member --- apps/opencs/view/world/table.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index 71bdb9000e..9bc5ef038c 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -199,6 +199,9 @@ CSVWorld::Table::Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, Q mCreateAction = new QAction (tr ("Add Record"), this); connect (mCreateAction, SIGNAL (triggered()), this, SIGNAL (createRequest())); addAction (mCreateAction); + + mCloneAction = new QAction(tr("Clone Record"), this); + addAction(mCloneAction); } mRevertAction = new QAction (tr ("Revert Record"), this); From 344cae8f993d0ae4c52552fafd832f26090cd6bc Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Tue, 14 Jan 2014 15:44:04 +0100 Subject: [PATCH 02/43] added new entry to the context menu --- apps/opencs/view/world/table.cpp | 20 ++++++++++++++++++-- apps/opencs/view/world/table.hpp | 4 ++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index 9bc5ef038c..31a7d8b588 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -28,7 +28,11 @@ void CSVWorld::Table::contextMenuEvent (QContextMenuEvent *event) if (!mEditLock) { if (selectedRows.size()==1) + { menu.addAction (mEditAction); + if (mCreateAction) + menu.addAction(mCloneAction); + } if (mCreateAction) menu.addAction (mCreateAction); @@ -155,7 +159,7 @@ std::vector CSVWorld::Table::listDeletableSelectedIds() const CSVWorld::Table::Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, QUndoStack& undoStack, bool createAndDelete, bool sorting) - : mUndoStack (undoStack), mCreateAction (0), mEditLock (false), mRecordStatusDisplay (0) + : mUndoStack (undoStack), mCreateAction (0), mCloneAction(0), mEditLock (false), mRecordStatusDisplay (0) { mModel = &dynamic_cast (*data.getTableModel (id)); @@ -200,7 +204,8 @@ CSVWorld::Table::Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, Q connect (mCreateAction, SIGNAL (triggered()), this, SIGNAL (createRequest())); addAction (mCreateAction); - mCloneAction = new QAction(tr("Clone Record"), this); + mCloneAction = new QAction (tr ("Clone Record"), this); + connect(mCloneAction, SIGNAL (triggered()), this, SLOT (cloneRecord())); addAction(mCloneAction); } @@ -298,6 +303,17 @@ void CSVWorld::Table::editRecord() } } +void CSVWorld::Table::cloneRecord() +{ + if (!mEditLock) + { + QModelIndexList selectedRows = selectionModel()->selectedRows(); + + if (selectedRows.size()==1) + emit cloneRequest (selectedRows.begin()->row()); + } +} + void CSVWorld::Table::moveUpRecord() { QModelIndexList selectedRows = selectionModel()->selectedRows(); diff --git a/apps/opencs/view/world/table.hpp b/apps/opencs/view/world/table.hpp index 889e2847ac..f4a5d3c9e9 100644 --- a/apps/opencs/view/world/table.hpp +++ b/apps/opencs/view/world/table.hpp @@ -32,6 +32,7 @@ namespace CSVWorld QUndoStack& mUndoStack; QAction *mEditAction; QAction *mCreateAction; + QAction *mCloneAction; QAction *mRevertAction; QAction *mDeleteAction; QAction *mMoveUpAction; @@ -73,6 +74,7 @@ namespace CSVWorld /// \param modified Number of added and modified records void createRequest(); + void cloneRequest(int row); private slots: @@ -82,6 +84,8 @@ namespace CSVWorld void editRecord(); + void cloneRecord(); + void moveUpRecord(); void moveDownRecord(); From b3e45c55bcfc45d4fe4ee4f9b10d989c32b15a72 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Sun, 19 Jan 2014 11:44:47 +0100 Subject: [PATCH 03/43] progressing with the cloning --- apps/opencs/view/world/creator.hpp | 3 +++ apps/opencs/view/world/genericcreator.cpp | 32 +++++++++++++++++------ apps/opencs/view/world/genericcreator.hpp | 6 +++++ apps/opencs/view/world/tablebottombox.cpp | 11 +++++++- apps/opencs/view/world/tablebottombox.hpp | 2 ++ apps/opencs/view/world/tablesubview.cpp | 15 +++++++++-- apps/opencs/view/world/tablesubview.hpp | 4 +++ 7 files changed, 62 insertions(+), 11 deletions(-) diff --git a/apps/opencs/view/world/creator.hpp b/apps/opencs/view/world/creator.hpp index df9b116eed..58a5e21ad2 100644 --- a/apps/opencs/view/world/creator.hpp +++ b/apps/opencs/view/world/creator.hpp @@ -2,6 +2,7 @@ #define CSV_WORLD_CREATOR_H #include +#include "../../model/world/universalid.hpp" class QUndoStack; @@ -23,6 +24,8 @@ namespace CSVWorld virtual ~Creator(); virtual void reset() = 0; + + virtual void cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type) = 0; virtual void setEditLock (bool locked) = 0; diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index ba2b3665a9..b89c2dccfb 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -2,6 +2,7 @@ #include "genericcreator.hpp" #include +#include #include #include @@ -58,7 +59,7 @@ const CSMWorld::UniversalId& CSVWorld::GenericCreator::getCollectionId() const CSVWorld::GenericCreator::GenericCreator (CSMWorld::Data& data, QUndoStack& undoStack, const CSMWorld::UniversalId& id, bool relaxedIdRules) -: mData (data), mUndoStack (undoStack), mListId (id), mLocked (false) +: mData (data), mUndoStack (undoStack), mListId (id), mLocked (false), mCloneMode(false), mClonedType(CSMWorld::UniversalId::Type_None) { mLayout = new QHBoxLayout; mLayout->setContentsMargins (0, 0, 0, 0); @@ -89,6 +90,7 @@ void CSVWorld::GenericCreator::setEditLock (bool locked) void CSVWorld::GenericCreator::reset() { + mCloneMode = false; mId->setText (""); update(); } @@ -120,16 +122,30 @@ void CSVWorld::GenericCreator::create() { if (!mLocked) { - std::string id = getId(); + if (mCloneMode) + { + std::string id = getId(); + } else { + std::string id = getId(); - std::auto_ptr command (new CSMWorld::CreateCommand ( + std::auto_ptr command (new CSMWorld::CreateCommand ( dynamic_cast (*mData.getTableModel (mListId)), id)); - configureCreateCommand (*command); + configureCreateCommand (*command); - mUndoStack.push (command.release()); + mUndoStack.push (command.release()); - emit done(); - emit requestFocus (id); + emit done(); + emit requestFocus (id); + } } -} \ No newline at end of file +} + +void CSVWorld::GenericCreator::cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type) +{ + mCloneMode = true; + mClonedId = originid; + mClonedType = type; + + mId->setText(QString::fromStdString(mClonedId)); +} diff --git a/apps/opencs/view/world/genericcreator.hpp b/apps/opencs/view/world/genericcreator.hpp index 8dd2ca911c..a1acb2e792 100644 --- a/apps/opencs/view/world/genericcreator.hpp +++ b/apps/opencs/view/world/genericcreator.hpp @@ -1,6 +1,7 @@ #ifndef CSV_WORLD_GENERICCREATOR_H #define CSV_WORLD_GENERICCREATOR_H +class QString; class QPushButton; class QLineEdit; class QHBoxLayout; @@ -28,6 +29,9 @@ namespace CSVWorld std::string mErrors; QHBoxLayout *mLayout; bool mLocked; + bool mCloneMode; + std::string mClonedId; + CSMWorld::UniversalId::Type mClonedType; protected: @@ -57,6 +61,8 @@ namespace CSVWorld virtual void reset(); + virtual void cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type); + virtual std::string getErrors() const; ///< Return formatted error descriptions for the current state of the creator. if an empty /// string is returned, there is no error. diff --git a/apps/opencs/view/world/tablebottombox.cpp b/apps/opencs/view/world/tablebottombox.cpp index 3edf9af317..b89f5180bf 100644 --- a/apps/opencs/view/world/tablebottombox.cpp +++ b/apps/opencs/view/world/tablebottombox.cpp @@ -156,4 +156,13 @@ void CSVWorld::TableBottomBox::createRequest() mLayout->setCurrentWidget (mCreator); setVisible (true); mCreating = true; -} \ No newline at end of file +} + +void CSVWorld::TableBottomBox::cloneRequest(const std::string& id, const CSMWorld::UniversalId::Type type) +{ + mCreator->reset(); + mCreator->cloneMode(id, type); + mLayout->setCurrentWidget(mCreator); + setVisible (true); + mCreating = true; +} diff --git a/apps/opencs/view/world/tablebottombox.hpp b/apps/opencs/view/world/tablebottombox.hpp index a5ae5e0bd9..58a6a5a2f3 100644 --- a/apps/opencs/view/world/tablebottombox.hpp +++ b/apps/opencs/view/world/tablebottombox.hpp @@ -2,6 +2,7 @@ #define CSV_WORLD_BOTTOMBOX_H #include +#include class QLabel; class QStackedLayout; @@ -76,6 +77,7 @@ namespace CSVWorld /// \param modified Number of added and modified records void createRequest(); + void cloneRequest(const std::string& id, const CSMWorld::UniversalId::Type type); }; } diff --git a/apps/opencs/view/world/tablesubview.cpp b/apps/opencs/view/world/tablesubview.cpp index 55ded09de2..36200dbbcb 100644 --- a/apps/opencs/view/world/tablesubview.cpp +++ b/apps/opencs/view/world/tablesubview.cpp @@ -46,8 +46,13 @@ CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMDoc::D mTable->selectionSizeUpdate(); if (mBottom->canCreateAndDelete()) + { connect (mTable, SIGNAL (createRequest()), mBottom, SLOT (createRequest())); - + + connect (mTable, SIGNAL (cloneRequest(int)), this, SLOT(cloneRequest(int))); + connect (this, SIGNAL(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type)), + mBottom, SLOT(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type))); + } connect (mBottom, SIGNAL (requestFocus (const std::string&)), mTable, SLOT (requestFocus (const std::string&))); @@ -75,4 +80,10 @@ void CSVWorld::TableSubView::updateEditorSetting(const QString &settingName, con void CSVWorld::TableSubView::setStatusBar (bool show) { mBottom->setStatusBar (show); -} \ No newline at end of file +} + +void CSVWorld::TableSubView::cloneRequest(int row) +{ + const CSMWorld::UniversalId& toClone(mTable->getUniversalId(row)); + emit cloneRequest(toClone.getId(), toClone.getType()); +} diff --git a/apps/opencs/view/world/tablesubview.hpp b/apps/opencs/view/world/tablesubview.hpp index 56a441a4d5..5b19110b6b 100644 --- a/apps/opencs/view/world/tablesubview.hpp +++ b/apps/opencs/view/world/tablesubview.hpp @@ -33,10 +33,14 @@ namespace CSVWorld virtual void updateEditorSetting (const QString& key, const QString& value); virtual void setStatusBar (bool show); + + signals: + void cloneRequest(const std::string& id, const CSMWorld::UniversalId::Type type); private slots: void editRequest (int row); + void cloneRequest (int row); }; } From 0ea2bb7c4cc835f969fdfe92bba153fd9f3bebdc Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Sun, 19 Jan 2014 16:49:39 +0100 Subject: [PATCH 04/43] Working on commands --- apps/opencs/model/world/commands.cpp | 21 +++++++++++++++++++++ apps/opencs/model/world/commands.hpp | 20 ++++++++++++++++++++ apps/opencs/model/world/idtable.cpp | 8 ++++++++ apps/opencs/model/world/idtable.hpp | 2 ++ apps/opencs/view/world/genericcreator.cpp | 2 ++ 5 files changed, 53 insertions(+) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 21feb14be6..281afb15ff 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -25,6 +25,27 @@ void CSMWorld::ModifyCommand::undo() mModel.setData (mIndex, mOld); } +CSMWorld::CloneCommand::CloneCommand (CSMWorld::IdTable& model, + const std::string& idOrigin, + const std::string& IdDestination, + CSMWorld::UniversalId::Type type, + QUndoCommand* parent) : + QUndoCommand(parent), + mModel(model), + mIdOrigin(idOrigin), + mIdDestination(IdDestination), + mType(type) +{ + setText (("Clone record " + idOrigin + " to the " + IdDestination).c_str()); +} + + +void CSMWorld::CloneCommand::redo() +{ + mModel.cloneRecord(mIdOrigin, mIdDestination, mType); +} + + CSMWorld::CreateCommand::CreateCommand (IdTable& model, const std::string& id, QUndoCommand *parent) : QUndoCommand (parent), mModel (model), mId (id), mType (UniversalId::Type_None) { diff --git a/apps/opencs/model/world/commands.hpp b/apps/opencs/model/world/commands.hpp index f0480a369d..1af4bd919f 100644 --- a/apps/opencs/model/world/commands.hpp +++ b/apps/opencs/model/world/commands.hpp @@ -39,6 +39,26 @@ namespace CSMWorld virtual void undo(); }; + class CloneCommand : public QUndoCommand + { + IdTable& mModel; + std::string mIdOrigin; + std::string mIdDestination; + UniversalId::Type mType; + std::map mValues; + + public: + + CloneCommand (IdTable& model, const std::string& idOrigin, + const std::string& IdDestination, + UniversalId::Type type, + QUndoCommand* parent = 0); + + virtual void redo(); + +// virtual void undo(); + }; + class CreateCommand : public QUndoCommand { IdTable& mModel; diff --git a/apps/opencs/model/world/idtable.cpp b/apps/opencs/model/world/idtable.cpp index 809d64339c..b90bf1a9bb 100644 --- a/apps/opencs/model/world/idtable.cpp +++ b/apps/opencs/model/world/idtable.cpp @@ -124,6 +124,14 @@ void CSMWorld::IdTable::addRecord (const std::string& id, UniversalId::Type type endInsertRows(); } +void CSMWorld::IdTable::cloneRecord(const std::string& origin, + const std::string& destination, + CSMWorld::UniversalId::Type type) +{ + +} + + QModelIndex CSMWorld::IdTable::getModelIndex (const std::string& id, int column) const { return index (mIdCollection->getIndex (id), column); diff --git a/apps/opencs/model/world/idtable.hpp b/apps/opencs/model/world/idtable.hpp index e4ae58fd04..dfbc04134f 100644 --- a/apps/opencs/model/world/idtable.hpp +++ b/apps/opencs/model/world/idtable.hpp @@ -63,6 +63,8 @@ namespace CSMWorld void addRecord (const std::string& id, UniversalId::Type type = UniversalId::Type_None); ///< \param type Will be ignored, unless the collection supports multiple record types + void cloneRecord(const std::string& origin, const std::string& destination, UniversalId::Type type = UniversalId::Type_None); + QModelIndex getModelIndex (const std::string& id, int column) const; void setRecord (const std::string& id, const RecordBase& record); diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index b89c2dccfb..f21a62d979 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -125,6 +125,8 @@ void CSVWorld::GenericCreator::create() if (mCloneMode) { std::string id = getId(); + std::auto_ptr command (new CSMWorld::CloneCommand ( + dynamic_cast (*mData.getTableModel(mListId)), mClonedId, id, mClonedType)); } else { std::string id = getId(); From 33620a001b802ed8c8ae8c61db9afcc4619ad20b Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 20 Jan 2014 13:59:00 +0100 Subject: [PATCH 05/43] Cloning works for single record type tables. Well, kinda. --- apps/opencs/model/world/collection.hpp | 27 ++++- apps/opencs/model/world/collectionbase.hpp | 5 + apps/opencs/model/world/commands.cpp | 126 +++++++++++--------- apps/opencs/model/world/commands.hpp | 6 +- apps/opencs/model/world/idtable.cpp | 5 +- apps/opencs/model/world/idtable.hpp | 5 +- apps/opencs/model/world/refidcollection.cpp | 8 ++ apps/opencs/model/world/refidcollection.hpp | 5 + apps/opencs/view/world/creator.hpp | 2 +- apps/opencs/view/world/genericcreator.cpp | 15 ++- apps/opencs/view/world/genericcreator.hpp | 6 +- apps/opencs/view/world/tablebottombox.cpp | 6 +- apps/opencs/view/world/tablebottombox.hpp | 2 +- apps/opencs/view/world/tablesubview.cpp | 6 +- apps/opencs/view/world/tablesubview.hpp | 4 +- 15 files changed, 150 insertions(+), 78 deletions(-) diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index df144ba7bf..0b9b44fa9a 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -97,7 +97,12 @@ namespace CSMWorld virtual void appendBlankRecord (const std::string& id, UniversalId::Type type = UniversalId::Type_None); ///< \param type Will be ignored, unless the collection supports multiple record types - + + virtual void cloneRecord(const std::string& origin, + const std::string& destination, + const UniversalId::Type type, + const UniversalId::ArgumentType argumentType); + virtual int searchId (const std::string& id) const; ////< Search record with \a id. /// \return index of record (if found) or -1 (not found) @@ -193,6 +198,26 @@ namespace CSMWorld return true; } + template + void Collection::cloneRecord(const std::string& origin, + const std::string& destination, + const UniversalId::Type type, + const UniversalId::ArgumentType argumentType) + { + Record copy = getRecord(origin); + if (copy.isDeleted()) + { + return; + } + + if (argumentType == UniversalId::ArgumentType_Id) + { + copy.get().mId = Misc::StringUtils::lowerCase(destination); + } + + insertRecord(copy, getAppendIndex(destination, type)); + } + template Collection::Collection() {} diff --git a/apps/opencs/model/world/collectionbase.hpp b/apps/opencs/model/world/collectionbase.hpp index ab7a9ebecb..d32847490b 100644 --- a/apps/opencs/model/world/collectionbase.hpp +++ b/apps/opencs/model/world/collectionbase.hpp @@ -74,6 +74,11 @@ namespace CSMWorld UniversalId::Type type = UniversalId::Type_None) = 0; ///< If the record type does not match, an exception is thrown. + virtual void cloneRecord(const std::string& origin, + const std::string& destination, + const UniversalId::Type type, + const UniversalId::ArgumentType argumentType) = 0; + virtual const RecordBase& getRecord (const std::string& id) const = 0; virtual const RecordBase& getRecord (int index) const = 0; diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 281afb15ff..75b88766aa 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -6,81 +6,88 @@ #include "idtable.hpp" #include "idtable.hpp" -CSMWorld::ModifyCommand::ModifyCommand (QAbstractItemModel& model, const QModelIndex& index, - const QVariant& new_, QUndoCommand *parent) -: QUndoCommand (parent), mModel (model), mIndex (index), mNew (new_) +CSMWorld::ModifyCommand::ModifyCommand(QAbstractItemModel& model, const QModelIndex& index, + const QVariant& new_, QUndoCommand* parent) + : QUndoCommand(parent), mModel(model), mIndex(index), mNew(new_) { - mOld = mModel.data (mIndex, Qt::EditRole); + mOld = mModel.data(mIndex, Qt::EditRole); - setText ("Modify " + mModel.headerData (mIndex.column(), Qt::Horizontal, Qt::DisplayRole).toString()); + setText("Modify " + mModel.headerData(mIndex.column(), Qt::Horizontal, Qt::DisplayRole).toString()); } void CSMWorld::ModifyCommand::redo() { - mModel.setData (mIndex, mNew); + mModel.setData(mIndex, mNew); } void CSMWorld::ModifyCommand::undo() { - mModel.setData (mIndex, mOld); + mModel.setData(mIndex, mOld); } -CSMWorld::CloneCommand::CloneCommand (CSMWorld::IdTable& model, - const std::string& idOrigin, - const std::string& IdDestination, - CSMWorld::UniversalId::Type type, - QUndoCommand* parent) : - QUndoCommand(parent), - mModel(model), - mIdOrigin(idOrigin), +CSMWorld::CloneCommand::CloneCommand(CSMWorld::IdTable& model, + const std::string& idOrigin, + const std::string& IdDestination, + const CSMWorld::UniversalId::Type type, + const CSMWorld::UniversalId::ArgumentType argumentType, + QUndoCommand* parent) : + QUndoCommand(parent), + mModel(model), + mIdOrigin(idOrigin), mIdDestination(IdDestination), + mArgumentType(argumentType), mType(type) { - setText (("Clone record " + idOrigin + " to the " + IdDestination).c_str()); + setText(("Clone record " + idOrigin + " to the " + IdDestination).c_str()); } void CSMWorld::CloneCommand::redo() { - mModel.cloneRecord(mIdOrigin, mIdDestination, mType); + mModel.cloneRecord(mIdOrigin, mIdDestination, mArgumentType, mType); } - -CSMWorld::CreateCommand::CreateCommand (IdTable& model, const std::string& id, QUndoCommand *parent) -: QUndoCommand (parent), mModel (model), mId (id), mType (UniversalId::Type_None) +void CSMWorld::CloneCommand::undo() { - setText (("Create record " + id).c_str()); + mModel.removeRow(mModel.getModelIndex(mIdDestination, 0).row()); } -void CSMWorld::CreateCommand::addValue (int column, const QVariant& value) + +CSMWorld::CreateCommand::CreateCommand(IdTable& model, const std::string& id, QUndoCommand* parent) + : QUndoCommand(parent), mModel(model), mId(id), mType(UniversalId::Type_None) +{ + setText(("Create record " + id).c_str()); +} + +void CSMWorld::CreateCommand::addValue(int column, const QVariant& value) { mValues[column] = value; } -void CSMWorld::CreateCommand::setType (UniversalId::Type type) +void CSMWorld::CreateCommand::setType(UniversalId::Type type) { mType = type; } void CSMWorld::CreateCommand::redo() { - mModel.addRecord (mId, mType); + mModel.addRecord(mId, mType); - for (std::map::const_iterator iter (mValues.begin()); iter!=mValues.end(); ++iter) - mModel.setData (mModel.getModelIndex (mId, iter->first), iter->second); + for (std::map::const_iterator iter(mValues.begin()); iter != mValues.end(); ++iter) + mModel.setData(mModel.getModelIndex(mId, iter->first), iter->second); } void CSMWorld::CreateCommand::undo() { - mModel.removeRow (mModel.getModelIndex (mId, 0).row()); + mModel.removeRow(mModel.getModelIndex(mId, 0).row()); } -CSMWorld::RevertCommand::RevertCommand (IdTable& model, const std::string& id, QUndoCommand *parent) -: QUndoCommand (parent), mModel (model), mId (id), mOld (0) +CSMWorld::RevertCommand::RevertCommand(IdTable& model, const std::string& id, QUndoCommand* parent) + : QUndoCommand(parent), mModel(model), mId(id), mOld(0) { - setText (("Revert record " + id).c_str()); + setText(("Revert record " + id).c_str()); - mOld = model.getRecord (id).clone(); + mOld = model.getRecord(id).clone(); } CSMWorld::RevertCommand::~RevertCommand() @@ -90,32 +97,32 @@ CSMWorld::RevertCommand::~RevertCommand() void CSMWorld::RevertCommand::redo() { - int column = mModel.findColumnIndex (Columns::ColumnId_Modification); + int column = mModel.findColumnIndex(Columns::ColumnId_Modification); - QModelIndex index = mModel.getModelIndex (mId, column); - RecordBase::State state = static_cast (mModel.data (index).toInt()); + QModelIndex index = mModel.getModelIndex(mId, column); + RecordBase::State state = static_cast(mModel.data(index).toInt()); - if (state==RecordBase::State_ModifiedOnly) + if (state == RecordBase::State_ModifiedOnly) { - mModel.removeRows (index.row(), 1); + mModel.removeRows(index.row(), 1); } else { - mModel.setData (index, static_cast (RecordBase::State_BaseOnly)); + mModel.setData(index, static_cast(RecordBase::State_BaseOnly)); } } void CSMWorld::RevertCommand::undo() { - mModel.setRecord (mId, *mOld); + mModel.setRecord(mId, *mOld); } -CSMWorld::DeleteCommand::DeleteCommand (IdTable& model, const std::string& id, QUndoCommand *parent) -: QUndoCommand (parent), mModel (model), mId (id), mOld (0) +CSMWorld::DeleteCommand::DeleteCommand(IdTable& model, const std::string& id, QUndoCommand* parent) + : QUndoCommand(parent), mModel(model), mId(id), mOld(0) { - setText (("Delete record " + id).c_str()); + setText(("Delete record " + id).c_str()); - mOld = model.getRecord (id).clone(); + mOld = model.getRecord(id).clone(); } CSMWorld::DeleteCommand::~DeleteCommand() @@ -125,44 +132,45 @@ CSMWorld::DeleteCommand::~DeleteCommand() void CSMWorld::DeleteCommand::redo() { - int column = mModel.findColumnIndex (Columns::ColumnId_Modification); + int column = mModel.findColumnIndex(Columns::ColumnId_Modification); - QModelIndex index = mModel.getModelIndex (mId, column); - RecordBase::State state = static_cast (mModel.data (index).toInt()); + QModelIndex index = mModel.getModelIndex(mId, column); + RecordBase::State state = static_cast(mModel.data(index).toInt()); - if (state==RecordBase::State_ModifiedOnly) + if (state == RecordBase::State_ModifiedOnly) { - mModel.removeRows (index.row(), 1); + mModel.removeRows(index.row(), 1); } else { - mModel.setData (index, static_cast (RecordBase::State_Deleted)); + mModel.setData(index, static_cast(RecordBase::State_Deleted)); } } void CSMWorld::DeleteCommand::undo() { - mModel.setRecord (mId, *mOld); + mModel.setRecord(mId, *mOld); } -CSMWorld::ReorderRowsCommand::ReorderRowsCommand (IdTable& model, int baseIndex, - const std::vector& newOrder) -: mModel (model), mBaseIndex (baseIndex), mNewOrder (newOrder) +CSMWorld::ReorderRowsCommand::ReorderRowsCommand(IdTable& model, int baseIndex, + const std::vector& newOrder) + : mModel(model), mBaseIndex(baseIndex), mNewOrder(newOrder) {} void CSMWorld::ReorderRowsCommand::redo() { - mModel.reorderRows (mBaseIndex, mNewOrder); + mModel.reorderRows(mBaseIndex, mNewOrder); } void CSMWorld::ReorderRowsCommand::undo() { - int size = static_cast (mNewOrder.size()); - std::vector reverse (size); + int size = static_cast(mNewOrder.size()); + std::vector reverse(size); - for (int i=0; i mValues; public: CloneCommand (IdTable& model, const std::string& idOrigin, const std::string& IdDestination, - UniversalId::Type type, + const UniversalId::Type type, + const UniversalId::ArgumentType argumentType, QUndoCommand* parent = 0); virtual void redo(); -// virtual void undo(); + virtual void undo(); }; class CreateCommand : public QUndoCommand diff --git a/apps/opencs/model/world/idtable.cpp b/apps/opencs/model/world/idtable.cpp index b90bf1a9bb..daa6bc51b3 100644 --- a/apps/opencs/model/world/idtable.cpp +++ b/apps/opencs/model/world/idtable.cpp @@ -124,11 +124,12 @@ void CSMWorld::IdTable::addRecord (const std::string& id, UniversalId::Type type endInsertRows(); } -void CSMWorld::IdTable::cloneRecord(const std::string& origin, +void CSMWorld::IdTable::cloneRecord(const std::string& origin, const std::string& destination, + CSMWorld::UniversalId::ArgumentType argumentType, CSMWorld::UniversalId::Type type) { - + mIdCollection->cloneRecord(origin, destination, type, argumentType); } diff --git a/apps/opencs/model/world/idtable.hpp b/apps/opencs/model/world/idtable.hpp index dfbc04134f..ce47307e3c 100644 --- a/apps/opencs/model/world/idtable.hpp +++ b/apps/opencs/model/world/idtable.hpp @@ -63,7 +63,10 @@ namespace CSMWorld void addRecord (const std::string& id, UniversalId::Type type = UniversalId::Type_None); ///< \param type Will be ignored, unless the collection supports multiple record types - void cloneRecord(const std::string& origin, const std::string& destination, UniversalId::Type type = UniversalId::Type_None); + void cloneRecord(const std::string& origin, + const std::string& destination, + UniversalId::ArgumentType argumentType, + UniversalId::Type type = UniversalId::Type_None); QModelIndex getModelIndex (const std::string& id, int column) const; diff --git a/apps/opencs/model/world/refidcollection.cpp b/apps/opencs/model/world/refidcollection.cpp index 86a542c5c3..896ee90101 100644 --- a/apps/opencs/model/world/refidcollection.cpp +++ b/apps/opencs/model/world/refidcollection.cpp @@ -449,6 +449,14 @@ void CSMWorld::RefIdCollection::replace (int index, const RecordBase& record) mData.getRecord (mData.globalToLocalIndex (index)).assign (record); } +void CSMWorld::RefIdCollection::cloneRecord(const std::string& origin, + const std::string& destination, + const CSMWorld::UniversalId::Type type, + const CSMWorld::UniversalId::ArgumentType argumentType) +{ + +} + void CSMWorld::RefIdCollection::appendRecord (const RecordBase& record, UniversalId::Type type) { diff --git a/apps/opencs/model/world/refidcollection.hpp b/apps/opencs/model/world/refidcollection.hpp index 5ff4a70bf2..4ad181004f 100644 --- a/apps/opencs/model/world/refidcollection.hpp +++ b/apps/opencs/model/world/refidcollection.hpp @@ -69,6 +69,11 @@ namespace CSMWorld virtual void removeRows (int index, int count); + virtual void cloneRecord(const std::string& origin, + const std::string& destination, + const UniversalId::Type type, + const UniversalId::ArgumentType argumentType); + virtual void appendBlankRecord (const std::string& id, UniversalId::Type type); ///< \param type Will be ignored, unless the collection supports multiple record types diff --git a/apps/opencs/view/world/creator.hpp b/apps/opencs/view/world/creator.hpp index 58a5e21ad2..5eaf3e1781 100644 --- a/apps/opencs/view/world/creator.hpp +++ b/apps/opencs/view/world/creator.hpp @@ -25,7 +25,7 @@ namespace CSVWorld virtual void reset() = 0; - virtual void cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type) = 0; + virtual void cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type, const CSMWorld::UniversalId::ArgumentType argumentType) = 0; virtual void setEditLock (bool locked) = 0; diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index f21a62d979..efdd9ecafb 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -59,7 +59,8 @@ const CSMWorld::UniversalId& CSVWorld::GenericCreator::getCollectionId() const CSVWorld::GenericCreator::GenericCreator (CSMWorld::Data& data, QUndoStack& undoStack, const CSMWorld::UniversalId& id, bool relaxedIdRules) -: mData (data), mUndoStack (undoStack), mListId (id), mLocked (false), mCloneMode(false), mClonedType(CSMWorld::UniversalId::Type_None) +: mData (data), mUndoStack (undoStack), mListId (id), mLocked (false), mCloneMode(false), mClonedType(CSMWorld::UniversalId::Type_None), +mArgumentType(CSMWorld::UniversalId::ArgumentType_None) { mLayout = new QHBoxLayout; mLayout->setContentsMargins (0, 0, 0, 0); @@ -126,7 +127,12 @@ void CSVWorld::GenericCreator::create() { std::string id = getId(); std::auto_ptr command (new CSMWorld::CloneCommand ( - dynamic_cast (*mData.getTableModel(mListId)), mClonedId, id, mClonedType)); + dynamic_cast (*mData.getTableModel(mListId)), mClonedId, id, mClonedType, mArgumentType)); + + mUndoStack.push(command.release()); + + emit done(); + emit requestFocus(id); } else { std::string id = getId(); @@ -143,11 +149,14 @@ void CSVWorld::GenericCreator::create() } } -void CSVWorld::GenericCreator::cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type) +void CSVWorld::GenericCreator::cloneMode(const std::string& originid, + const CSMWorld::UniversalId::Type type, + const CSMWorld::UniversalId::ArgumentType argumentType) { mCloneMode = true; mClonedId = originid; mClonedType = type; + mArgumentType = argumentType; mId->setText(QString::fromStdString(mClonedId)); } diff --git a/apps/opencs/view/world/genericcreator.hpp b/apps/opencs/view/world/genericcreator.hpp index a1acb2e792..867595bb55 100644 --- a/apps/opencs/view/world/genericcreator.hpp +++ b/apps/opencs/view/world/genericcreator.hpp @@ -32,6 +32,7 @@ namespace CSVWorld bool mCloneMode; std::string mClonedId; CSMWorld::UniversalId::Type mClonedType; + CSMWorld::UniversalId::ArgumentType mArgumentType; protected: @@ -61,13 +62,14 @@ namespace CSVWorld virtual void reset(); - virtual void cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type); + virtual void cloneMode(const std::string& originid, + const CSMWorld::UniversalId::Type type, + const CSMWorld::UniversalId::ArgumentType argumentType); virtual std::string getErrors() const; ///< Return formatted error descriptions for the current state of the creator. if an empty /// string is returned, there is no error. - private slots: void textChanged (const QString& text); diff --git a/apps/opencs/view/world/tablebottombox.cpp b/apps/opencs/view/world/tablebottombox.cpp index b89f5180bf..60a206d0c2 100644 --- a/apps/opencs/view/world/tablebottombox.cpp +++ b/apps/opencs/view/world/tablebottombox.cpp @@ -158,10 +158,12 @@ void CSVWorld::TableBottomBox::createRequest() mCreating = true; } -void CSVWorld::TableBottomBox::cloneRequest(const std::string& id, const CSMWorld::UniversalId::Type type) +void CSVWorld::TableBottomBox::cloneRequest(const std::string& id, + const CSMWorld::UniversalId::Type type, + const CSMWorld::UniversalId::ArgumentType argumnetType) { mCreator->reset(); - mCreator->cloneMode(id, type); + mCreator->cloneMode(id, type, argumnetType); mLayout->setCurrentWidget(mCreator); setVisible (true); mCreating = true; diff --git a/apps/opencs/view/world/tablebottombox.hpp b/apps/opencs/view/world/tablebottombox.hpp index 58a6a5a2f3..29afa22772 100644 --- a/apps/opencs/view/world/tablebottombox.hpp +++ b/apps/opencs/view/world/tablebottombox.hpp @@ -77,7 +77,7 @@ namespace CSVWorld /// \param modified Number of added and modified records void createRequest(); - void cloneRequest(const std::string& id, const CSMWorld::UniversalId::Type type); + void cloneRequest(const std::string& id, const CSMWorld::UniversalId::Type type, const CSMWorld::UniversalId::ArgumentType argumentType); }; } diff --git a/apps/opencs/view/world/tablesubview.cpp b/apps/opencs/view/world/tablesubview.cpp index 36200dbbcb..7bb852cbe5 100644 --- a/apps/opencs/view/world/tablesubview.cpp +++ b/apps/opencs/view/world/tablesubview.cpp @@ -50,8 +50,8 @@ CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMDoc::D connect (mTable, SIGNAL (createRequest()), mBottom, SLOT (createRequest())); connect (mTable, SIGNAL (cloneRequest(int)), this, SLOT(cloneRequest(int))); - connect (this, SIGNAL(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type)), - mBottom, SLOT(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type))); + connect (this, SIGNAL(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type, const CSMWorld::UniversalId::ArgumentType)), + mBottom, SLOT(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type, const CSMWorld::UniversalId::ArgumentType))); } connect (mBottom, SIGNAL (requestFocus (const std::string&)), mTable, SLOT (requestFocus (const std::string&))); @@ -85,5 +85,5 @@ void CSVWorld::TableSubView::setStatusBar (bool show) void CSVWorld::TableSubView::cloneRequest(int row) { const CSMWorld::UniversalId& toClone(mTable->getUniversalId(row)); - emit cloneRequest(toClone.getId(), toClone.getType()); + emit cloneRequest(toClone.getId(), toClone.getType(), toClone.getArgumentType()); } diff --git a/apps/opencs/view/world/tablesubview.hpp b/apps/opencs/view/world/tablesubview.hpp index 5b19110b6b..01df204def 100644 --- a/apps/opencs/view/world/tablesubview.hpp +++ b/apps/opencs/view/world/tablesubview.hpp @@ -35,7 +35,9 @@ namespace CSVWorld virtual void setStatusBar (bool show); signals: - void cloneRequest(const std::string& id, const CSMWorld::UniversalId::Type type); + void cloneRequest(const std::string& id, + const CSMWorld::UniversalId::Type type, + const CSMWorld::UniversalId::ArgumentType argumentType); private slots: From a45339bbe6ecd68ab2d5704649582ad3e3cd06b1 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 20 Jan 2014 14:14:59 +0100 Subject: [PATCH 06/43] lower case in command, not in the collection --- apps/opencs/model/world/collection.hpp | 2 +- apps/opencs/model/world/commands.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index 0b9b44fa9a..091496926d 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -212,7 +212,7 @@ namespace CSMWorld if (argumentType == UniversalId::ArgumentType_Id) { - copy.get().mId = Misc::StringUtils::lowerCase(destination); + copy.get().mId = destination; } insertRecord(copy, getAppendIndex(destination, type)); diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 75b88766aa..f161170195 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -2,7 +2,7 @@ #include "commands.hpp" #include - +#include #include "idtable.hpp" #include "idtable.hpp" @@ -34,7 +34,7 @@ CSMWorld::CloneCommand::CloneCommand(CSMWorld::IdTable& model, QUndoCommand(parent), mModel(model), mIdOrigin(idOrigin), - mIdDestination(IdDestination), + mIdDestination(Misc::StringUtils::lowerCase(IdDestination)), mArgumentType(argumentType), mType(type) { From 38636fab9a60a442fce8f04de170827675194f6f Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 20 Jan 2014 14:29:47 +0100 Subject: [PATCH 07/43] added setId to adapter --- apps/opencs/model/world/commands.cpp | 3 +++ apps/opencs/model/world/refidadapter.hpp | 1 + apps/opencs/model/world/refidadapterimp.hpp | 8 ++++++++ 3 files changed, 12 insertions(+) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index f161170195..b7c88e872c 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -45,6 +45,9 @@ CSMWorld::CloneCommand::CloneCommand(CSMWorld::IdTable& model, void CSMWorld::CloneCommand::redo() { mModel.cloneRecord(mIdOrigin, mIdDestination, mArgumentType, mType); + + for (std::map::const_iterator iter(mValues.begin()); iter != mValues.end(); ++iter) + mModel.setData(mModel.getModelIndex(mIdDestination, iter->first), iter->second); } void CSMWorld::CloneCommand::undo() diff --git a/apps/opencs/model/world/refidadapter.hpp b/apps/opencs/model/world/refidadapter.hpp index df0ceae706..0870a2d3e6 100644 --- a/apps/opencs/model/world/refidadapter.hpp +++ b/apps/opencs/model/world/refidadapter.hpp @@ -31,6 +31,7 @@ namespace CSMWorld ///< If the data type does not match an exception is thrown. virtual std::string getId (const RecordBase& record) const = 0; + virtual void setId(RecordBase& record, const std::string& id) = 0; }; } diff --git a/apps/opencs/model/world/refidadapterimp.hpp b/apps/opencs/model/world/refidadapterimp.hpp index d5d84a8f7e..bd509a86b6 100644 --- a/apps/opencs/model/world/refidadapterimp.hpp +++ b/apps/opencs/model/world/refidadapterimp.hpp @@ -34,6 +34,8 @@ namespace CSMWorld BaseRefIdAdapter (UniversalId::Type type, const BaseColumns& base); virtual std::string getId (const RecordBase& record) const; + + virtual void setId (RecordBase& record, const std::string& id); virtual QVariant getData (const RefIdColumn *column, const RefIdData& data, int index) const; @@ -50,6 +52,12 @@ namespace CSMWorld : mType (type), mBase (base) {} + template + void BaseRefIdAdapter::setId (RecordBase& record, const std::string& id) + { + (dynamic_cast&> (record).get().mId) = id; + } + template std::string BaseRefIdAdapter::getId (const RecordBase& record) const { From 5a527157013f97bec71790f7bbbedc29e92779c5 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 20 Jan 2014 15:58:19 +0100 Subject: [PATCH 08/43] implemented check for deletion. But it seems flawed. --- apps/opencs/model/world/data.cpp | 21 +++++++++++++++++++++ apps/opencs/model/world/data.hpp | 2 ++ apps/opencs/view/world/genericcreator.cpp | 7 +++++-- apps/opencs/view/world/table.cpp | 3 ++- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index 04e35cdaaf..8a7dc3971a 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -657,6 +657,27 @@ int CSMWorld::Data::count (RecordBase::State state) const count (state, mReferenceables); } +bool CSMWorld::Data::recordDeleted(const std::string& id) const +{ + return + getGlobals().getRecord(id).isDeleted() || + getGmsts().getRecord(id).isDeleted() || + getSkills().getRecord(id).isDeleted() || + getClasses().getRecord(id).isDeleted() || + getFactions().getRecord(id).isDeleted() || + getRaces().getRecord(id).isDeleted() || + getSounds().getRecord(id).isDeleted() || + getScripts().getRecord(id).isDeleted() || + getRegions().getRecord(id).isDeleted() || + getBirthsigns().getRecord(id).isDeleted() || + getSpells().getRecord(id).isDeleted() || + getTopics().getRecord(id).isDeleted() || + getJournals().getRecord(id).isDeleted() || + getCells().getRecord(id).isDeleted() || + getReferenceables().getRecord(id).isDeleted(); +} + + void CSMWorld::Data::setDescription (const std::string& description) { mDescription = description; diff --git a/apps/opencs/model/world/data.hpp b/apps/opencs/model/world/data.hpp index 152c3ac419..df51c936a4 100644 --- a/apps/opencs/model/world/data.hpp +++ b/apps/opencs/model/world/data.hpp @@ -189,6 +189,8 @@ namespace CSMWorld void setAuthor (const std::string& author); std::string getAuthor() const; + + bool recordDeleted(const std::string& id) const; signals: diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index efdd9ecafb..16bd04ece4 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -125,10 +125,13 @@ void CSVWorld::GenericCreator::create() { if (mCloneMode) { - std::string id = getId(); + const std::string id = getId(); + if (mData.recordDeleted(id)) + { + return; + } std::auto_ptr command (new CSMWorld::CloneCommand ( dynamic_cast (*mData.getTableModel(mListId)), mClonedId, id, mClonedType, mArgumentType)); - mUndoStack.push(command.release()); emit done(); diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index 31a7d8b588..4577c40dc8 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -308,9 +308,10 @@ void CSVWorld::Table::cloneRecord() if (!mEditLock) { QModelIndexList selectedRows = selectionModel()->selectedRows(); - if (selectedRows.size()==1) + { emit cloneRequest (selectedRows.begin()->row()); + } } } From d82f272e0546c9cb270dcc7f0951a7ead0489903 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 20 Jan 2014 16:17:49 +0100 Subject: [PATCH 09/43] Properly check if clone is deleted. --- apps/opencs/view/world/table.cpp | 2 +- apps/opencs/view/world/table.hpp | 2 +- apps/opencs/view/world/tablesubview.cpp | 11 +++++++---- apps/opencs/view/world/tablesubview.hpp | 7 ++++++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index 4577c40dc8..02a93161cf 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -310,7 +310,7 @@ void CSVWorld::Table::cloneRecord() QModelIndexList selectedRows = selectionModel()->selectedRows(); if (selectedRows.size()==1) { - emit cloneRequest (selectedRows.begin()->row()); + emit cloneRequest (selectedRows.begin()->row(), mModel); } } } diff --git a/apps/opencs/view/world/table.hpp b/apps/opencs/view/world/table.hpp index f4a5d3c9e9..118bd3cf20 100644 --- a/apps/opencs/view/world/table.hpp +++ b/apps/opencs/view/world/table.hpp @@ -74,7 +74,7 @@ namespace CSVWorld /// \param modified Number of added and modified records void createRequest(); - void cloneRequest(int row); + void cloneRequest(int row, const CSMWorld::IdTable* table); private slots: diff --git a/apps/opencs/view/world/tablesubview.cpp b/apps/opencs/view/world/tablesubview.cpp index 7bb852cbe5..0cdc57f5f5 100644 --- a/apps/opencs/view/world/tablesubview.cpp +++ b/apps/opencs/view/world/tablesubview.cpp @@ -6,7 +6,7 @@ #include "../../model/doc/document.hpp" #include "../filter/filterbox.hpp" - +#include "../../model/world/idtable.hpp" #include "table.hpp" #include "tablebottombox.hpp" #include "creator.hpp" @@ -49,7 +49,7 @@ CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMDoc::D { connect (mTable, SIGNAL (createRequest()), mBottom, SLOT (createRequest())); - connect (mTable, SIGNAL (cloneRequest(int)), this, SLOT(cloneRequest(int))); + connect (mTable, SIGNAL (cloneRequest(int, CSMWorld::IdTable*)), this, SLOT(cloneRequest(int, CSMWorld::IdTable*))); connect (this, SIGNAL(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type, const CSMWorld::UniversalId::ArgumentType)), mBottom, SLOT(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type, const CSMWorld::UniversalId::ArgumentType))); } @@ -82,8 +82,11 @@ void CSVWorld::TableSubView::setStatusBar (bool show) mBottom->setStatusBar (show); } -void CSVWorld::TableSubView::cloneRequest(int row) +void CSVWorld::TableSubView::cloneRequest(int row, const CSMWorld::IdTable* table) { const CSMWorld::UniversalId& toClone(mTable->getUniversalId(row)); - emit cloneRequest(toClone.getId(), toClone.getType(), toClone.getArgumentType()); + if (!(table->getRecord(toClone.getId()).isDeleted())) + { + emit cloneRequest(toClone.getId(), toClone.getType(), toClone.getArgumentType()); + } } diff --git a/apps/opencs/view/world/tablesubview.hpp b/apps/opencs/view/world/tablesubview.hpp index 01df204def..650a098f6c 100644 --- a/apps/opencs/view/world/tablesubview.hpp +++ b/apps/opencs/view/world/tablesubview.hpp @@ -5,6 +5,11 @@ class QModelIndex; +namespace CSMWorld +{ + class IdTable; +} + namespace CSMDoc { class Document; @@ -42,7 +47,7 @@ namespace CSVWorld private slots: void editRequest (int row); - void cloneRequest (int row); + void cloneRequest (int row, const CSMWorld::IdTable* table); }; } From 92ee252eef54b0e9072a39803087e81ccd7bff62 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 20 Jan 2014 16:23:34 +0100 Subject: [PATCH 10/43] Small correction. --- apps/opencs/model/world/data.cpp | 21 --------------------- apps/opencs/model/world/data.hpp | 2 -- apps/opencs/view/world/genericcreator.cpp | 7 ++----- apps/opencs/view/world/table.cpp | 1 + apps/opencs/view/world/table.hpp | 2 +- apps/opencs/view/world/tablesubview.cpp | 2 +- 6 files changed, 5 insertions(+), 30 deletions(-) diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index 8a7dc3971a..04e35cdaaf 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -657,27 +657,6 @@ int CSMWorld::Data::count (RecordBase::State state) const count (state, mReferenceables); } -bool CSMWorld::Data::recordDeleted(const std::string& id) const -{ - return - getGlobals().getRecord(id).isDeleted() || - getGmsts().getRecord(id).isDeleted() || - getSkills().getRecord(id).isDeleted() || - getClasses().getRecord(id).isDeleted() || - getFactions().getRecord(id).isDeleted() || - getRaces().getRecord(id).isDeleted() || - getSounds().getRecord(id).isDeleted() || - getScripts().getRecord(id).isDeleted() || - getRegions().getRecord(id).isDeleted() || - getBirthsigns().getRecord(id).isDeleted() || - getSpells().getRecord(id).isDeleted() || - getTopics().getRecord(id).isDeleted() || - getJournals().getRecord(id).isDeleted() || - getCells().getRecord(id).isDeleted() || - getReferenceables().getRecord(id).isDeleted(); -} - - void CSMWorld::Data::setDescription (const std::string& description) { mDescription = description; diff --git a/apps/opencs/model/world/data.hpp b/apps/opencs/model/world/data.hpp index df51c936a4..152c3ac419 100644 --- a/apps/opencs/model/world/data.hpp +++ b/apps/opencs/model/world/data.hpp @@ -189,8 +189,6 @@ namespace CSMWorld void setAuthor (const std::string& author); std::string getAuthor() const; - - bool recordDeleted(const std::string& id) const; signals: diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index 16bd04ece4..efdd9ecafb 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -125,13 +125,10 @@ void CSVWorld::GenericCreator::create() { if (mCloneMode) { - const std::string id = getId(); - if (mData.recordDeleted(id)) - { - return; - } + std::string id = getId(); std::auto_ptr command (new CSMWorld::CloneCommand ( dynamic_cast (*mData.getTableModel(mListId)), mClonedId, id, mClonedType, mArgumentType)); + mUndoStack.push(command.release()); emit done(); diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index 02a93161cf..cc1f814ddf 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -308,6 +308,7 @@ void CSVWorld::Table::cloneRecord() if (!mEditLock) { QModelIndexList selectedRows = selectionModel()->selectedRows(); + if (selectedRows.size()==1) { emit cloneRequest (selectedRows.begin()->row(), mModel); diff --git a/apps/opencs/view/world/table.hpp b/apps/opencs/view/world/table.hpp index 118bd3cf20..af2d7877f7 100644 --- a/apps/opencs/view/world/table.hpp +++ b/apps/opencs/view/world/table.hpp @@ -74,7 +74,7 @@ namespace CSVWorld /// \param modified Number of added and modified records void createRequest(); - void cloneRequest(int row, const CSMWorld::IdTable* table); + void cloneRequest(int row, const CSMWorld::IdTable*); private slots: diff --git a/apps/opencs/view/world/tablesubview.cpp b/apps/opencs/view/world/tablesubview.cpp index 0cdc57f5f5..7650556106 100644 --- a/apps/opencs/view/world/tablesubview.cpp +++ b/apps/opencs/view/world/tablesubview.cpp @@ -49,7 +49,7 @@ CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMDoc::D { connect (mTable, SIGNAL (createRequest()), mBottom, SLOT (createRequest())); - connect (mTable, SIGNAL (cloneRequest(int, CSMWorld::IdTable*)), this, SLOT(cloneRequest(int, CSMWorld::IdTable*))); + connect (mTable, SIGNAL (cloneRequest(int, const CSMWorld::IdTable*)), this, SLOT(cloneRequest(int, const CSMWorld::IdTable*))); connect (this, SIGNAL(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type, const CSMWorld::UniversalId::ArgumentType)), mBottom, SLOT(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type, const CSMWorld::UniversalId::ArgumentType))); } From d0a52b7b242e114d39a5fd25720a62a972eebcbe Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 20 Jan 2014 18:28:06 +0100 Subject: [PATCH 11/43] mostly refreshing view. --- apps/opencs/model/world/idtable.cpp | 5 +++++ apps/opencs/model/world/refidcollection.cpp | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/apps/opencs/model/world/idtable.cpp b/apps/opencs/model/world/idtable.cpp index daa6bc51b3..d4008fb878 100644 --- a/apps/opencs/model/world/idtable.cpp +++ b/apps/opencs/model/world/idtable.cpp @@ -129,7 +129,12 @@ void CSMWorld::IdTable::cloneRecord(const std::string& origin, CSMWorld::UniversalId::ArgumentType argumentType, CSMWorld::UniversalId::Type type) { + int index = mIdCollection->getAppendIndex (destination); + beginInsertRows (QModelIndex(), index, index); mIdCollection->cloneRecord(origin, destination, type, argumentType); + endInsertRows(); + emit dataChanged (CSMWorld::IdTable::index (0, 0), + CSMWorld::IdTable::index (mIdCollection->getSize()-1, mIdCollection->getColumns()-1)); } diff --git a/apps/opencs/model/world/refidcollection.cpp b/apps/opencs/model/world/refidcollection.cpp index 896ee90101..74f6f13599 100644 --- a/apps/opencs/model/world/refidcollection.cpp +++ b/apps/opencs/model/world/refidcollection.cpp @@ -454,7 +454,11 @@ void CSMWorld::RefIdCollection::cloneRecord(const std::string& origin, const CSMWorld::UniversalId::Type type, const CSMWorld::UniversalId::ArgumentType argumentType) { - + RecordBase *newRecord = mData.getRecord(mData.searchId(origin)).clone(); + newRecord->mState = RecordBase::State_ModifiedOnly; + mAdapters.find(type)->second->setId(*newRecord, destination); + mData.getAppendIndex(type); + //WIP } void CSMWorld::RefIdCollection::appendRecord (const RecordBase& record, From 7594bcf97aa0813d3517f2f53f2d1d633c22aee6 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Tue, 21 Jan 2014 08:27:29 +0100 Subject: [PATCH 12/43] Small refactoring. --- apps/opencs/view/world/genericcreator.cpp | 2 +- apps/opencs/view/world/table.cpp | 7 ++++--- apps/opencs/view/world/table.hpp | 2 +- apps/opencs/view/world/tablesubview.cpp | 10 +++------- apps/opencs/view/world/tablesubview.hpp | 8 ++++---- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index efdd9ecafb..163842ab81 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -149,7 +149,7 @@ void CSVWorld::GenericCreator::create() } } -void CSVWorld::GenericCreator::cloneMode(const std::string& originid, +void CSVWorld::GenericCreator::cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type, const CSMWorld::UniversalId::ArgumentType argumentType) { diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index cc1f814ddf..d343f9986a 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -16,6 +16,7 @@ #include "recordstatusdelegate.hpp" #include "util.hpp" +#include void CSVWorld::Table::contextMenuEvent (QContextMenuEvent *event) { @@ -308,10 +309,10 @@ void CSVWorld::Table::cloneRecord() if (!mEditLock) { QModelIndexList selectedRows = selectionModel()->selectedRows(); - - if (selectedRows.size()==1) + const CSMWorld::UniversalId& toClone = getUniversalId(selectedRows.begin()->row()); + if (selectedRows.size()==1 && !mModel->getRecord(toClone.getId()).isDeleted()) { - emit cloneRequest (selectedRows.begin()->row(), mModel); + emit cloneRequest (toClone); } } } diff --git a/apps/opencs/view/world/table.hpp b/apps/opencs/view/world/table.hpp index af2d7877f7..d30083333f 100644 --- a/apps/opencs/view/world/table.hpp +++ b/apps/opencs/view/world/table.hpp @@ -74,7 +74,7 @@ namespace CSVWorld /// \param modified Number of added and modified records void createRequest(); - void cloneRequest(int row, const CSMWorld::IdTable*); + void cloneRequest(const CSMWorld::UniversalId&); private slots: diff --git a/apps/opencs/view/world/tablesubview.cpp b/apps/opencs/view/world/tablesubview.cpp index 7650556106..3c71d13708 100644 --- a/apps/opencs/view/world/tablesubview.cpp +++ b/apps/opencs/view/world/tablesubview.cpp @@ -49,7 +49,7 @@ CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMDoc::D { connect (mTable, SIGNAL (createRequest()), mBottom, SLOT (createRequest())); - connect (mTable, SIGNAL (cloneRequest(int, const CSMWorld::IdTable*)), this, SLOT(cloneRequest(int, const CSMWorld::IdTable*))); + connect (mTable, SIGNAL (cloneRequest(const CSMWorld::UniversalId&)), this, SLOT(cloneRequest(const CSMWorld::UniversalId&))); connect (this, SIGNAL(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type, const CSMWorld::UniversalId::ArgumentType)), mBottom, SLOT(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type, const CSMWorld::UniversalId::ArgumentType))); } @@ -82,11 +82,7 @@ void CSVWorld::TableSubView::setStatusBar (bool show) mBottom->setStatusBar (show); } -void CSVWorld::TableSubView::cloneRequest(int row, const CSMWorld::IdTable* table) +void CSVWorld::TableSubView::cloneRequest(const CSMWorld::UniversalId& toClone) { - const CSMWorld::UniversalId& toClone(mTable->getUniversalId(row)); - if (!(table->getRecord(toClone.getId()).isDeleted())) - { - emit cloneRequest(toClone.getId(), toClone.getType(), toClone.getArgumentType()); - } + emit cloneRequest(toClone.getId(), toClone.getType(), toClone.getArgumentType()); } diff --git a/apps/opencs/view/world/tablesubview.hpp b/apps/opencs/view/world/tablesubview.hpp index 650a098f6c..b3a0a51626 100644 --- a/apps/opencs/view/world/tablesubview.hpp +++ b/apps/opencs/view/world/tablesubview.hpp @@ -40,14 +40,14 @@ namespace CSVWorld virtual void setStatusBar (bool show); signals: - void cloneRequest(const std::string& id, - const CSMWorld::UniversalId::Type type, - const CSMWorld::UniversalId::ArgumentType argumentType); + void cloneRequest(const std::string&, + const CSMWorld::UniversalId::Type, + const CSMWorld::UniversalId::ArgumentType); private slots: void editRequest (int row); - void cloneRequest (int row, const CSMWorld::IdTable* table); + void cloneRequest (const CSMWorld::UniversalId& toClone); }; } From 9b56b6585be31d6d8af9573d3e53b3aa4766cc2f Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Tue, 21 Jan 2014 09:43:02 +0100 Subject: [PATCH 13/43] Cloning works for referencables as well. --- apps/opencs/model/world/refidcollection.cpp | 3 ++- apps/opencs/model/world/refiddata.cpp | 17 ++++++++++++++++- apps/opencs/model/world/refiddata.hpp | 13 +++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/apps/opencs/model/world/refidcollection.cpp b/apps/opencs/model/world/refidcollection.cpp index 74f6f13599..75a1b681d2 100644 --- a/apps/opencs/model/world/refidcollection.cpp +++ b/apps/opencs/model/world/refidcollection.cpp @@ -457,7 +457,8 @@ void CSMWorld::RefIdCollection::cloneRecord(const std::string& origin, RecordBase *newRecord = mData.getRecord(mData.searchId(origin)).clone(); newRecord->mState = RecordBase::State_ModifiedOnly; mAdapters.find(type)->second->setId(*newRecord, destination); - mData.getAppendIndex(type); + mData.insertRecord(*newRecord, type, destination); + delete newRecord; //WIP } diff --git a/apps/opencs/model/world/refiddata.cpp b/apps/opencs/model/world/refiddata.cpp index 8f59b0fe74..d4f08eb915 100644 --- a/apps/opencs/model/world/refiddata.cpp +++ b/apps/opencs/model/world/refiddata.cpp @@ -230,4 +230,19 @@ void CSMWorld::RefIdData::save (int index, ESM::ESMWriter& writer) const throw std::logic_error ("invalid local index type"); iter->second->save (localIndex.first, writer); -} \ No newline at end of file +} + + +void CSMWorld::RefIdData::insertRecord(CSMWorld::RecordBase& record, CSMWorld::UniversalId::Type type, const std::string& id) +{ + std::map::iterator iter = + mRecordContainers.find (type); + + if (iter==mRecordContainers.end()) + throw std::logic_error ("invalid local index type"); + + iter->second->insertRecord(record); + + mIndex.insert (std::make_pair (Misc::StringUtils::lowerCase (id), + LocalIndex (iter->second->getSize()-1, type))); +} diff --git a/apps/opencs/model/world/refiddata.hpp b/apps/opencs/model/world/refiddata.hpp index 9595ab23b5..a982f2f975 100644 --- a/apps/opencs/model/world/refiddata.hpp +++ b/apps/opencs/model/world/refiddata.hpp @@ -46,6 +46,8 @@ namespace CSMWorld virtual RecordBase& getRecord (int index)= 0; virtual void appendRecord (const std::string& id) = 0; + + virtual void insertRecord (RecordBase& record) = 0; virtual void load (int index, ESM::ESMReader& reader, bool base) = 0; @@ -68,6 +70,8 @@ namespace CSMWorld virtual RecordBase& getRecord (int index); virtual void appendRecord (const std::string& id); + + virtual void insertRecord (RecordBase& record); virtual void load (int index, ESM::ESMReader& reader, bool base); @@ -78,6 +82,13 @@ namespace CSMWorld virtual void save (int index, ESM::ESMWriter& writer) const; }; + template + void RefIdDataContainer::insertRecord(RecordBase& record) + { + Record& newRecord = dynamic_cast& >(record); + mContainer.push_back(newRecord); + } + template int RefIdDataContainer::getSize() const { @@ -200,6 +211,8 @@ namespace CSMWorld LocalIndex searchId (const std::string& id) const; void erase (int index, int count); + + void insertRecord(CSMWorld::RecordBase& record, CSMWorld::UniversalId::Type type, const std::string& id); const RecordBase& getRecord (const LocalIndex& index) const; From bc0130f8d8451ff75ba73a622033ac0e82499cc6 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Tue, 21 Jan 2014 10:35:08 +0100 Subject: [PATCH 14/43] do not double check if record is deleted --- apps/opencs/model/world/collection.hpp | 5 ----- apps/opencs/view/world/genericcreator.cpp | 5 ++++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index 091496926d..7cc283ce8b 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -205,11 +205,6 @@ namespace CSMWorld const UniversalId::ArgumentType argumentType) { Record copy = getRecord(origin); - if (copy.isDeleted()) - { - return; - } - if (argumentType == UniversalId::ArgumentType_Id) { copy.get().mId = destination; diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index 163842ab81..2fcce91869 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -158,5 +158,8 @@ void CSVWorld::GenericCreator::cloneMode(const std::string& originid, mClonedType = type; mArgumentType = argumentType; - mId->setText(QString::fromStdString(mClonedId)); + if (argumentType == CSMWorld::UniversalId::ArgumentType_Id) + { + mId->setText(QString::fromStdString(mClonedId)); + } } From b3b51992ef8ac49e292787704cdf7ab466f1fbb4 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Tue, 21 Jan 2014 21:37:21 +0100 Subject: [PATCH 15/43] copying references. --- apps/opencs/model/world/collection.hpp | 6 +++--- apps/opencs/model/world/commands.cpp | 1 - apps/opencs/model/world/refcollection.cpp | 15 +++++++++++++++ apps/opencs/model/world/refcollection.hpp | 6 ++++++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index 7cc283ce8b..8ecad816b9 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -200,9 +200,9 @@ namespace CSMWorld template void Collection::cloneRecord(const std::string& origin, - const std::string& destination, - const UniversalId::Type type, - const UniversalId::ArgumentType argumentType) + const std::string& destination, + const UniversalId::Type type, + const UniversalId::ArgumentType argumentType) { Record copy = getRecord(origin); if (argumentType == UniversalId::ArgumentType_Id) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index b7c88e872c..762e4809ca 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -4,7 +4,6 @@ #include #include #include "idtable.hpp" -#include "idtable.hpp" CSMWorld::ModifyCommand::ModifyCommand(QAbstractItemModel& model, const QModelIndex& index, const QVariant& new_, QUndoCommand* parent) diff --git a/apps/opencs/model/world/refcollection.cpp b/apps/opencs/model/world/refcollection.cpp index 696aeefaa2..2ecd3b6630 100644 --- a/apps/opencs/model/world/refcollection.cpp +++ b/apps/opencs/model/world/refcollection.cpp @@ -5,6 +5,8 @@ #include "ref.hpp" #include "cell.hpp" +#include "universalid.hpp" +#include "record.hpp" void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool base) { @@ -34,4 +36,17 @@ std::string CSMWorld::RefCollection::getNewId() std::ostringstream stream; stream << "ref#" << mNextId++; return stream.str(); +} + +void CSMWorld::RefCollection::cloneRecord(const std::string& origin, + const std::string& destination, + const CSMWorld::UniversalId::Type type, + const CSMWorld::UniversalId::ArgumentType argumentType) +{ + Record originRecord = getRecord(origin); + Record *copy = dynamic_cast* >(originRecord.clone()); + copy->mState = CSMWorld::RecordBase::State_ModifiedOnly; + copy->get().mId = getNewId(); + insertRecord(*copy, getAppendIndex(destination, type)); + delete copy; } \ No newline at end of file diff --git a/apps/opencs/model/world/refcollection.hpp b/apps/opencs/model/world/refcollection.hpp index b5f8c8064a..dcfd2036cd 100644 --- a/apps/opencs/model/world/refcollection.hpp +++ b/apps/opencs/model/world/refcollection.hpp @@ -8,6 +8,7 @@ namespace CSMWorld { struct Cell; + struct UniversalId; /// \brief References in cells class RefCollection : public Collection @@ -25,6 +26,11 @@ namespace CSMWorld ///< Load a sequence of references. std::string getNewId(); + + void cloneRecord(const std::string& origin, + const std::string& destination, + const CSMWorld::UniversalId::Type type, + const CSMWorld::UniversalId::ArgumentType argumentType); }; } From 4d9d31b25e9ad56bd35580b35134118e88ea3053 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Thu, 23 Jan 2014 09:40:32 +0100 Subject: [PATCH 16/43] refrences cloning does not work --- apps/opencs/model/world/collection.hpp | 1 + apps/opencs/model/world/data.cpp | 1 + apps/opencs/model/world/idtable.cpp | 2 -- apps/opencs/model/world/refcollection.cpp | 10 ++++------ apps/opencs/view/world/genericcreator.cpp | 7 +------ apps/opencs/view/world/referencecreator.cpp | 2 +- 6 files changed, 8 insertions(+), 15 deletions(-) diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index 8ecad816b9..74019dda75 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -205,6 +205,7 @@ namespace CSMWorld const UniversalId::ArgumentType argumentType) { Record copy = getRecord(origin); + copy.mState = RecordBase::State_ModifiedOnly; if (argumentType == UniversalId::ArgumentType_Id) { copy.get().mId = destination; diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index 04e35cdaaf..69fb4ab1e6 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -194,6 +194,7 @@ CSMWorld::Data::Data() : mRefs (mCells) mRefs.addColumn (new StringIdColumn (true)); mRefs.addColumn (new RecordStateColumn); + mRefs.addColumn (new FixedRecordTypeColumn (UniversalId::Type_Reference)); mRefs.addColumn (new CellColumn); mRefs.addColumn (new IdColumn); mRefs.addColumn (new PosColumn (&CellRef::mPos, 0, false)); diff --git a/apps/opencs/model/world/idtable.cpp b/apps/opencs/model/world/idtable.cpp index d4008fb878..f131f7087a 100644 --- a/apps/opencs/model/world/idtable.cpp +++ b/apps/opencs/model/world/idtable.cpp @@ -133,8 +133,6 @@ void CSMWorld::IdTable::cloneRecord(const std::string& origin, beginInsertRows (QModelIndex(), index, index); mIdCollection->cloneRecord(origin, destination, type, argumentType); endInsertRows(); - emit dataChanged (CSMWorld::IdTable::index (0, 0), - CSMWorld::IdTable::index (mIdCollection->getSize()-1, mIdCollection->getColumns()-1)); } diff --git a/apps/opencs/model/world/refcollection.cpp b/apps/opencs/model/world/refcollection.cpp index 2ecd3b6630..6b00812583 100644 --- a/apps/opencs/model/world/refcollection.cpp +++ b/apps/opencs/model/world/refcollection.cpp @@ -43,10 +43,8 @@ void CSMWorld::RefCollection::cloneRecord(const std::string& origin, const CSMWorld::UniversalId::Type type, const CSMWorld::UniversalId::ArgumentType argumentType) { - Record originRecord = getRecord(origin); - Record *copy = dynamic_cast* >(originRecord.clone()); - copy->mState = CSMWorld::RecordBase::State_ModifiedOnly; - copy->get().mId = getNewId(); - insertRecord(*copy, getAppendIndex(destination, type)); - delete copy; + Record clone(getRecord(origin)); + clone.mState = CSMWorld::RecordBase::State_ModifiedOnly; + clone.get().mId = destination; + insertRecord(clone, getAppendIndex(destination, type), type); } \ No newline at end of file diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index 2fcce91869..ab387393b2 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -157,9 +157,4 @@ void CSVWorld::GenericCreator::cloneMode(const std::string& originid, mClonedId = originid; mClonedType = type; mArgumentType = argumentType; - - if (argumentType == CSMWorld::UniversalId::ArgumentType_Id) - { - mId->setText(QString::fromStdString(mClonedId)); - } -} +} \ No newline at end of file diff --git a/apps/opencs/view/world/referencecreator.cpp b/apps/opencs/view/world/referencecreator.cpp index aef25a81d0..06b3eb76dd 100644 --- a/apps/opencs/view/world/referencecreator.cpp +++ b/apps/opencs/view/world/referencecreator.cpp @@ -40,9 +40,9 @@ CSVWorld::ReferenceCreator::ReferenceCreator (CSMWorld::Data& data, QUndoStack& void CSVWorld::ReferenceCreator::reset() { + GenericCreator::reset(); mCell->setText (""); mId = getData().getReferences().getNewId(); - GenericCreator::reset(); } std::string CSVWorld::ReferenceCreator::getErrors() const From 1b1ecafdd8c68672dd51898ca9f8ccc3878b4f0b Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Thu, 23 Jan 2014 15:13:37 +0100 Subject: [PATCH 17/43] introduced missing columns to data --- apps/opencs/model/world/collection.hpp | 7 ++----- apps/opencs/model/world/data.cpp | 5 +++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index 74019dda75..f97b5f5293 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -204,12 +204,9 @@ namespace CSMWorld const UniversalId::Type type, const UniversalId::ArgumentType argumentType) { - Record copy = getRecord(origin); + Record copy(getRecord(origin)); copy.mState = RecordBase::State_ModifiedOnly; - if (argumentType == UniversalId::ArgumentType_Id) - { - copy.get().mId = destination; - } + copy.get().mId = destination; insertRecord(copy, getAppendIndex(destination, type)); } diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index 69fb4ab1e6..a52821036b 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -154,14 +154,17 @@ CSMWorld::Data::Data() : mRefs (mCells) mTopics.addColumn (new StringIdColumn); mTopics.addColumn (new RecordStateColumn); + mTopics.addColumn (new FixedRecordTypeColumn (UniversalId::Type_Topic)); mTopics.addColumn (new DialogueTypeColumn); mJournals.addColumn (new StringIdColumn); mJournals.addColumn (new RecordStateColumn); + mJournals.addColumn (new FixedRecordTypeColumn (UniversalId::Type_Journal)); mJournals.addColumn (new DialogueTypeColumn (true)); mTopicInfos.addColumn (new StringIdColumn (true)); mTopicInfos.addColumn (new RecordStateColumn); + mTopicInfos.addColumn (new FixedRecordTypeColumn (UniversalId::Type_Journal)); mTopicInfos.addColumn (new TopicColumn (false)); mTopicInfos.addColumn (new ActorColumn); mTopicInfos.addColumn (new RaceColumn); @@ -178,6 +181,7 @@ CSMWorld::Data::Data() : mRefs (mCells) mJournalInfos.addColumn (new StringIdColumn (true)); mJournalInfos.addColumn (new RecordStateColumn); + mJournalInfos.addColumn (new FixedRecordTypeColumn (UniversalId::Type_Journal)); mJournalInfos.addColumn (new TopicColumn (true)); mJournalInfos.addColumn (new QuestStatusTypeColumn); mJournalInfos.addColumn (new QuestIndexColumn); @@ -225,6 +229,7 @@ CSMWorld::Data::Data() : mRefs (mCells) mFilters.addColumn (new StringIdColumn); mFilters.addColumn (new RecordStateColumn); + mFilters.addColumn (new FixedRecordTypeColumn (UniversalId::Type_Filter)); mFilters.addColumn (new FilterColumn); mFilters.addColumn (new DescriptionColumn); mFilters.addColumn (new ScopeColumn); From dda7ddb6f8628b30632833ef2f486b8678aa4351 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Thu, 23 Jan 2014 16:00:44 +0100 Subject: [PATCH 18/43] Disable not needed referencable creator widget when in cloning mode. --- apps/opencs/view/world/creator.hpp | 2 ++ apps/opencs/view/world/genericcreator.cpp | 6 +++++- apps/opencs/view/world/genericcreator.hpp | 4 +++- apps/opencs/view/world/referenceablecreator.cpp | 8 +++++++- apps/opencs/view/world/referenceablecreator.hpp | 1 + apps/opencs/view/world/tablebottombox.cpp | 2 ++ 6 files changed, 20 insertions(+), 3 deletions(-) diff --git a/apps/opencs/view/world/creator.hpp b/apps/opencs/view/world/creator.hpp index 5eaf3e1781..5174232bc2 100644 --- a/apps/opencs/view/world/creator.hpp +++ b/apps/opencs/view/world/creator.hpp @@ -28,6 +28,8 @@ namespace CSVWorld virtual void cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type, const CSMWorld::UniversalId::ArgumentType argumentType) = 0; virtual void setEditLock (bool locked) = 0; + + virtual void toggleWidgets(bool active = true) = 0; signals: diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index ab387393b2..2a93f0e0f9 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -157,4 +157,8 @@ void CSVWorld::GenericCreator::cloneMode(const std::string& originid, mClonedId = originid; mClonedType = type; mArgumentType = argumentType; -} \ No newline at end of file +} + +void CSVWorld::GenericCreator::toggleWidgets(bool active) +{ +} diff --git a/apps/opencs/view/world/genericcreator.hpp b/apps/opencs/view/world/genericcreator.hpp index 867595bb55..e4813594b2 100644 --- a/apps/opencs/view/world/genericcreator.hpp +++ b/apps/opencs/view/world/genericcreator.hpp @@ -48,7 +48,7 @@ namespace CSVWorld virtual std::string getId() const; virtual void configureCreateCommand (CSMWorld::CreateCommand& command) const; - + CSMWorld::Data& getData() const; const CSMWorld::UniversalId& getCollectionId() const; @@ -61,6 +61,8 @@ namespace CSVWorld virtual void setEditLock (bool locked); virtual void reset(); + + virtual void toggleWidgets (bool active = true); virtual void cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type, diff --git a/apps/opencs/view/world/referenceablecreator.cpp b/apps/opencs/view/world/referenceablecreator.cpp index 718fe9ca7c..7a5fca8538 100644 --- a/apps/opencs/view/world/referenceablecreator.cpp +++ b/apps/opencs/view/world/referenceablecreator.cpp @@ -40,4 +40,10 @@ void CSVWorld::ReferenceableCreator::reset() { mType->setCurrentIndex (0); GenericCreator::reset(); -} \ No newline at end of file +} + +void CSVWorld::ReferenceableCreator::toggleWidgets(bool active) +{ + CSVWorld::GenericCreator::toggleWidgets(active); + mType->setEnabled(active); +} diff --git a/apps/opencs/view/world/referenceablecreator.hpp b/apps/opencs/view/world/referenceablecreator.hpp index 06e0e582be..88545575e3 100644 --- a/apps/opencs/view/world/referenceablecreator.hpp +++ b/apps/opencs/view/world/referenceablecreator.hpp @@ -23,6 +23,7 @@ namespace CSVWorld const CSMWorld::UniversalId& id); virtual void reset(); + virtual void toggleWidgets(bool active = true); }; } diff --git a/apps/opencs/view/world/tablebottombox.cpp b/apps/opencs/view/world/tablebottombox.cpp index 60a206d0c2..ef20cf1d47 100644 --- a/apps/opencs/view/world/tablebottombox.cpp +++ b/apps/opencs/view/world/tablebottombox.cpp @@ -153,6 +153,7 @@ void CSVWorld::TableBottomBox::tableSizeChanged (int size, int deleted, int modi void CSVWorld::TableBottomBox::createRequest() { mCreator->reset(); + mCreator->toggleWidgets(true); mLayout->setCurrentWidget (mCreator); setVisible (true); mCreating = true; @@ -163,6 +164,7 @@ void CSVWorld::TableBottomBox::cloneRequest(const std::string& id, const CSMWorld::UniversalId::ArgumentType argumnetType) { mCreator->reset(); + mCreator->toggleWidgets(false); mCreator->cloneMode(id, type, argumnetType); mLayout->setCurrentWidget(mCreator); setVisible (true); From c87d9ff38d67d698f60d0f438b45b99c546a869a Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Thu, 23 Jan 2014 16:17:04 +0100 Subject: [PATCH 19/43] Disable reference creator widget when in the clone mode. --- apps/opencs/view/world/genericcreator.hpp | 6 ++++-- apps/opencs/view/world/referencecreator.cpp | 21 +++++++++++++++++++-- apps/opencs/view/world/referencecreator.hpp | 5 +++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/apps/opencs/view/world/genericcreator.hpp b/apps/opencs/view/world/genericcreator.hpp index e4813594b2..4870ba46c4 100644 --- a/apps/opencs/view/world/genericcreator.hpp +++ b/apps/opencs/view/world/genericcreator.hpp @@ -29,11 +29,13 @@ namespace CSVWorld std::string mErrors; QHBoxLayout *mLayout; bool mLocked; - bool mCloneMode; std::string mClonedId; CSMWorld::UniversalId::Type mClonedType; CSMWorld::UniversalId::ArgumentType mArgumentType; - + + protected: + bool mCloneMode; + protected: void update(); diff --git a/apps/opencs/view/world/referencecreator.cpp b/apps/opencs/view/world/referencecreator.cpp index 06b3eb76dd..6991ecf36d 100644 --- a/apps/opencs/view/world/referencecreator.cpp +++ b/apps/opencs/view/world/referencecreator.cpp @@ -49,8 +49,13 @@ std::string CSVWorld::ReferenceCreator::getErrors() const { std::string errors = GenericCreator::getErrors(); + if (mCloneMode) + { + return errors; + } + std::string cell = mCell->text().toUtf8().constData(); - + if (cell.empty()) { if (!errors.empty()) @@ -72,4 +77,16 @@ std::string CSVWorld::ReferenceCreator::getErrors() const void CSVWorld::ReferenceCreator::cellChanged() { update(); -} \ No newline at end of file +} + +void CSVWorld::ReferenceCreator::toggleWidgets(bool active) +{ + CSVWorld::GenericCreator::toggleWidgets(active); + mCell->setEnabled(active); +} + +void CSVWorld::ReferenceCreator::cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type, const CSMWorld::UniversalId::ArgumentType argumentType) +{ + CSVWorld::GenericCreator::cloneMode(originid, type, argumentType); + cellChanged(); //otherwise ok button will remain disabled +} diff --git a/apps/opencs/view/world/referencecreator.hpp b/apps/opencs/view/world/referencecreator.hpp index 27f81564fd..2f0897026d 100644 --- a/apps/opencs/view/world/referencecreator.hpp +++ b/apps/opencs/view/world/referencecreator.hpp @@ -25,7 +25,12 @@ namespace CSVWorld ReferenceCreator (CSMWorld::Data& data, QUndoStack& undoStack, const CSMWorld::UniversalId& id); + virtual void cloneMode(const std::string& originid, + const CSMWorld::UniversalId::Type type, + const CSMWorld::UniversalId::ArgumentType argumentType); + virtual void reset(); + virtual void toggleWidgets(bool active = true); virtual std::string getErrors() const; ///< Return formatted error descriptions for the current state of the creator. if an empty From f390c7f4b0279cf64981e78dca3bfefe6316cf5b Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Thu, 23 Jan 2014 16:24:03 +0100 Subject: [PATCH 20/43] Disable widgets in the cell creator. --- apps/opencs/view/world/cellcreator.cpp | 8 +++++++- apps/opencs/view/world/cellcreator.hpp | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/opencs/view/world/cellcreator.cpp b/apps/opencs/view/world/cellcreator.cpp index 74fb068700..43af16c82e 100644 --- a/apps/opencs/view/world/cellcreator.cpp +++ b/apps/opencs/view/world/cellcreator.cpp @@ -78,4 +78,10 @@ void CSVWorld::CellCreator::setType (int index) void CSVWorld::CellCreator::valueChanged (int index) { update(); -} \ No newline at end of file +} + +void CSVWorld::CellCreator::toggleWidgets(bool active) +{ + CSVWorld::GenericCreator::toggleWidgets(active); + mType->setEnabled(active); +} diff --git a/apps/opencs/view/world/cellcreator.hpp b/apps/opencs/view/world/cellcreator.hpp index a5473e2c97..4e8705cb02 100644 --- a/apps/opencs/view/world/cellcreator.hpp +++ b/apps/opencs/view/world/cellcreator.hpp @@ -28,6 +28,8 @@ namespace CSVWorld CellCreator (CSMWorld::Data& data, QUndoStack& undoStack, const CSMWorld::UniversalId& id); virtual void reset(); + + virtual void toggleWidgets(bool active = true); private slots: From 01be9386d6521f2878daa7a6b89a319820baaddb Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Fri, 24 Jan 2014 11:22:20 +0100 Subject: [PATCH 21/43] Id to the coordinates with the boost and explicit specialisations of template member functions. --- apps/opencs/model/world/collection.hpp | 27 ++++++++++++++++++++++- apps/opencs/view/world/cellcreator.cpp | 14 +++++++++++- apps/opencs/view/world/cellcreator.hpp | 5 +++++ apps/opencs/view/world/tablebottombox.cpp | 2 +- 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index f97b5f5293..0a8dc5a9db 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -7,10 +7,13 @@ #include #include #include +#include +#include #include #include +#include #include "columnbase.hpp" @@ -50,6 +53,8 @@ namespace CSMWorld // not implemented Collection (const Collection&); Collection& operator= (const Collection&); + + void idToCoordiantes(Record& record, const std::string& destination) {} //dose nothing protected: @@ -150,7 +155,24 @@ namespace CSMWorld void setRecord (int index, const Record& record); ///< \attention This function must not change the ID. }; - + + template<> + class Collection > : public CollectionBase //explicit specialisation + { + void idToCoordiantes(Record& record, const std::string& destination) + { + if (record.get().isExterior()) + { + unsigned separator = destination.find(' '); + assert(separator != std::string::npos); + std::string xPos(destination.substr(0, separator)); + std::string yPos(destination.substr(separator+1, destination.size())); + record.get().mData.mX = boost::lexical_cast(xPos); + record.get().mData.mY = boost::lexical_cast(yPos); + } + } + }; + template const std::map& Collection::getIdMap() const { @@ -208,6 +230,9 @@ namespace CSMWorld copy.mState = RecordBase::State_ModifiedOnly; copy.get().mId = destination; + //the below function has explicit specialization for cells, and does nothing fo other records + idToCoordiantes(copy, destination); + insertRecord(copy, getAppendIndex(destination, type)); } diff --git a/apps/opencs/view/world/cellcreator.cpp b/apps/opencs/view/world/cellcreator.cpp index 43af16c82e..6298e3ba59 100644 --- a/apps/opencs/view/world/cellcreator.cpp +++ b/apps/opencs/view/world/cellcreator.cpp @@ -22,7 +22,7 @@ std::string CSVWorld::CellCreator::getId() const CSVWorld::CellCreator::CellCreator (CSMWorld::Data& data, QUndoStack& undoStack, const CSMWorld::UniversalId& id) -: GenericCreator (data, undoStack, id) +: GenericCreator (data, undoStack, id), mCloningExterior(false) { mY = new QSpinBox (this); mY->setVisible (false); @@ -80,6 +80,18 @@ void CSVWorld::CellCreator::valueChanged (int index) update(); } +void CSVWorld::CellCreator::cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type, const CSMWorld::UniversalId::ArgumentType argumentType) +{ + CSVWorld::GenericCreator::cloneMode(originid, type, argumentType); + if (*(originid.begin()) == '#') //if originid points to the exterior cell + { + setType(1); //enable x and y controls + } else { + setType(0); + } +} + + void CSVWorld::CellCreator::toggleWidgets(bool active) { CSVWorld::GenericCreator::toggleWidgets(active); diff --git a/apps/opencs/view/world/cellcreator.hpp b/apps/opencs/view/world/cellcreator.hpp index 4e8705cb02..521abd1735 100644 --- a/apps/opencs/view/world/cellcreator.hpp +++ b/apps/opencs/view/world/cellcreator.hpp @@ -19,6 +19,7 @@ namespace CSVWorld QLabel *mYLabel; QSpinBox *mY; + bool mCloningExterior; protected: virtual std::string getId() const; @@ -30,6 +31,10 @@ namespace CSVWorld virtual void reset(); virtual void toggleWidgets(bool active = true); + + virtual void cloneMode(const std::string& originid, + const CSMWorld::UniversalId::Type type, + const CSMWorld::UniversalId::ArgumentType argumentType); private slots: diff --git a/apps/opencs/view/world/tablebottombox.cpp b/apps/opencs/view/world/tablebottombox.cpp index ef20cf1d47..a6801b6fcc 100644 --- a/apps/opencs/view/world/tablebottombox.cpp +++ b/apps/opencs/view/world/tablebottombox.cpp @@ -164,9 +164,9 @@ void CSVWorld::TableBottomBox::cloneRequest(const std::string& id, const CSMWorld::UniversalId::ArgumentType argumnetType) { mCreator->reset(); - mCreator->toggleWidgets(false); mCreator->cloneMode(id, type, argumnetType); mLayout->setCurrentWidget(mCreator); + mCreator->toggleWidgets(false); setVisible (true); mCreating = true; } From 032c542396758e6f71bccdd968476ab8dfa30652 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Fri, 24 Jan 2014 20:34:33 +0100 Subject: [PATCH 22/43] improving the cell cloning. --- apps/opencs/view/world/cellcreator.cpp | 9 +++++++-- apps/opencs/view/world/cellcreator.hpp | 1 - 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/opencs/view/world/cellcreator.cpp b/apps/opencs/view/world/cellcreator.cpp index 6298e3ba59..ebf88122b3 100644 --- a/apps/opencs/view/world/cellcreator.cpp +++ b/apps/opencs/view/world/cellcreator.cpp @@ -22,7 +22,7 @@ std::string CSVWorld::CellCreator::getId() const CSVWorld::CellCreator::CellCreator (CSMWorld::Data& data, QUndoStack& undoStack, const CSMWorld::UniversalId& id) -: GenericCreator (data, undoStack, id), mCloningExterior(false) +: GenericCreator (data, undoStack, id) { mY = new QSpinBox (this); mY->setVisible (false); @@ -61,6 +61,7 @@ void CSVWorld::CellCreator::reset() mX->setValue (0); mY->setValue (0); mType->setCurrentIndex (0); + setType(0); GenericCreator::reset(); } @@ -80,14 +81,18 @@ void CSVWorld::CellCreator::valueChanged (int index) update(); } -void CSVWorld::CellCreator::cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type, const CSMWorld::UniversalId::ArgumentType argumentType) +void CSVWorld::CellCreator::cloneMode(const std::string& originid, + const CSMWorld::UniversalId::Type type, + const CSMWorld::UniversalId::ArgumentType argumentType) { CSVWorld::GenericCreator::cloneMode(originid, type, argumentType); if (*(originid.begin()) == '#') //if originid points to the exterior cell { setType(1); //enable x and y controls + mType->setCurrentIndex(1); } else { setType(0); + mType->setCurrentIndex(0); } } diff --git a/apps/opencs/view/world/cellcreator.hpp b/apps/opencs/view/world/cellcreator.hpp index 521abd1735..3130c13280 100644 --- a/apps/opencs/view/world/cellcreator.hpp +++ b/apps/opencs/view/world/cellcreator.hpp @@ -19,7 +19,6 @@ namespace CSVWorld QLabel *mYLabel; QSpinBox *mY; - bool mCloningExterior; protected: virtual std::string getId() const; From 62c2259c871de8826b83fd239bb4a229f8cc7db3 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 10:10:23 +0100 Subject: [PATCH 23/43] removing coordinates handling --- apps/opencs/model/world/collection.hpp | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index 0a8dc5a9db..d91260a5fa 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -8,7 +8,6 @@ #include #include #include -#include #include @@ -54,8 +53,6 @@ namespace CSMWorld Collection (const Collection&); Collection& operator= (const Collection&); - void idToCoordiantes(Record& record, const std::string& destination) {} //dose nothing - protected: const std::map& getIdMap() const; @@ -156,23 +153,6 @@ namespace CSMWorld ///< \attention This function must not change the ID. }; - template<> - class Collection > : public CollectionBase //explicit specialisation - { - void idToCoordiantes(Record& record, const std::string& destination) - { - if (record.get().isExterior()) - { - unsigned separator = destination.find(' '); - assert(separator != std::string::npos); - std::string xPos(destination.substr(0, separator)); - std::string yPos(destination.substr(separator+1, destination.size())); - record.get().mData.mX = boost::lexical_cast(xPos); - record.get().mData.mY = boost::lexical_cast(yPos); - } - } - }; - template const std::map& Collection::getIdMap() const { @@ -230,9 +210,6 @@ namespace CSMWorld copy.mState = RecordBase::State_ModifiedOnly; copy.get().mId = destination; - //the below function has explicit specialization for cells, and does nothing fo other records - idToCoordiantes(copy, destination); - insertRecord(copy, getAppendIndex(destination, type)); } From be8b978a89b182ada92eb46ae94ac0970c8038c4 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 12:23:03 +0100 Subject: [PATCH 24/43] corrected mistake in data --- apps/opencs/model/world/commands.cpp | 1 - apps/opencs/model/world/data.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 762e4809ca..789e65a21b 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -1,4 +1,3 @@ - #include "commands.hpp" #include diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index a52821036b..8d53c4e53a 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -164,7 +164,7 @@ CSMWorld::Data::Data() : mRefs (mCells) mTopicInfos.addColumn (new StringIdColumn (true)); mTopicInfos.addColumn (new RecordStateColumn); - mTopicInfos.addColumn (new FixedRecordTypeColumn (UniversalId::Type_Journal)); + mTopicInfos.addColumn (new FixedRecordTypeColumn (UniversalId::Type_TopicInfo)); mTopicInfos.addColumn (new TopicColumn (false)); mTopicInfos.addColumn (new ActorColumn); mTopicInfos.addColumn (new RaceColumn); From aa6d1ff4c3b4fa5d490c0a2468212ef9412bf928 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 13:08:14 +0100 Subject: [PATCH 25/43] removed needless argument for cloning --- apps/opencs/model/world/collection.hpp | 6 ++---- apps/opencs/model/world/collectionbase.hpp | 3 +-- apps/opencs/model/world/commands.cpp | 4 +--- apps/opencs/model/world/commands.hpp | 2 -- apps/opencs/model/world/idtable.cpp | 3 +-- apps/opencs/model/world/idtable.hpp | 1 - apps/opencs/model/world/refidcollection.cpp | 4 +--- apps/opencs/model/world/refidcollection.hpp | 3 +-- apps/opencs/view/world/cellcreator.cpp | 5 ++--- apps/opencs/view/world/cellcreator.hpp | 3 +-- apps/opencs/view/world/creator.hpp | 3 ++- apps/opencs/view/world/genericcreator.cpp | 6 ++---- apps/opencs/view/world/genericcreator.hpp | 3 +-- apps/opencs/view/world/referencecreator.cpp | 5 +++-- apps/opencs/view/world/referencecreator.hpp | 3 +-- apps/opencs/view/world/tablebottombox.cpp | 5 ++--- apps/opencs/view/world/tablebottombox.hpp | 3 ++- apps/opencs/view/world/tablesubview.cpp | 10 ++++++---- apps/opencs/view/world/tablesubview.hpp | 3 +-- 19 files changed, 30 insertions(+), 45 deletions(-) diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index d91260a5fa..4bb10c1d84 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -102,8 +102,7 @@ namespace CSMWorld virtual void cloneRecord(const std::string& origin, const std::string& destination, - const UniversalId::Type type, - const UniversalId::ArgumentType argumentType); + const UniversalId::Type type); virtual int searchId (const std::string& id) const; ////< Search record with \a id. @@ -203,8 +202,7 @@ namespace CSMWorld template void Collection::cloneRecord(const std::string& origin, const std::string& destination, - const UniversalId::Type type, - const UniversalId::ArgumentType argumentType) + const UniversalId::Type type) { Record copy(getRecord(origin)); copy.mState = RecordBase::State_ModifiedOnly; diff --git a/apps/opencs/model/world/collectionbase.hpp b/apps/opencs/model/world/collectionbase.hpp index d32847490b..2473ae741b 100644 --- a/apps/opencs/model/world/collectionbase.hpp +++ b/apps/opencs/model/world/collectionbase.hpp @@ -76,8 +76,7 @@ namespace CSMWorld virtual void cloneRecord(const std::string& origin, const std::string& destination, - const UniversalId::Type type, - const UniversalId::ArgumentType argumentType) = 0; + const UniversalId::Type type) = 0; virtual const RecordBase& getRecord (const std::string& id) const = 0; diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 789e65a21b..5eb2e94148 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -27,13 +27,11 @@ CSMWorld::CloneCommand::CloneCommand(CSMWorld::IdTable& model, const std::string& idOrigin, const std::string& IdDestination, const CSMWorld::UniversalId::Type type, - const CSMWorld::UniversalId::ArgumentType argumentType, QUndoCommand* parent) : QUndoCommand(parent), mModel(model), mIdOrigin(idOrigin), mIdDestination(Misc::StringUtils::lowerCase(IdDestination)), - mArgumentType(argumentType), mType(type) { setText(("Clone record " + idOrigin + " to the " + IdDestination).c_str()); @@ -42,7 +40,7 @@ CSMWorld::CloneCommand::CloneCommand(CSMWorld::IdTable& model, void CSMWorld::CloneCommand::redo() { - mModel.cloneRecord(mIdOrigin, mIdDestination, mArgumentType, mType); + mModel.cloneRecord(mIdOrigin, mIdDestination, mType); for (std::map::const_iterator iter(mValues.begin()); iter != mValues.end(); ++iter) mModel.setData(mModel.getModelIndex(mIdDestination, iter->first), iter->second); diff --git a/apps/opencs/model/world/commands.hpp b/apps/opencs/model/world/commands.hpp index 04eb0afbfe..0dedea0122 100644 --- a/apps/opencs/model/world/commands.hpp +++ b/apps/opencs/model/world/commands.hpp @@ -45,7 +45,6 @@ namespace CSMWorld std::string mIdOrigin; std::string mIdDestination; UniversalId::Type mType; - UniversalId::ArgumentType mArgumentType; std::map mValues; public: @@ -53,7 +52,6 @@ namespace CSMWorld CloneCommand (IdTable& model, const std::string& idOrigin, const std::string& IdDestination, const UniversalId::Type type, - const UniversalId::ArgumentType argumentType, QUndoCommand* parent = 0); virtual void redo(); diff --git a/apps/opencs/model/world/idtable.cpp b/apps/opencs/model/world/idtable.cpp index f131f7087a..bea307aa21 100644 --- a/apps/opencs/model/world/idtable.cpp +++ b/apps/opencs/model/world/idtable.cpp @@ -126,12 +126,11 @@ void CSMWorld::IdTable::addRecord (const std::string& id, UniversalId::Type type void CSMWorld::IdTable::cloneRecord(const std::string& origin, const std::string& destination, - CSMWorld::UniversalId::ArgumentType argumentType, CSMWorld::UniversalId::Type type) { int index = mIdCollection->getAppendIndex (destination); beginInsertRows (QModelIndex(), index, index); - mIdCollection->cloneRecord(origin, destination, type, argumentType); + mIdCollection->cloneRecord(origin, destination, type); endInsertRows(); } diff --git a/apps/opencs/model/world/idtable.hpp b/apps/opencs/model/world/idtable.hpp index ce47307e3c..2d620004cd 100644 --- a/apps/opencs/model/world/idtable.hpp +++ b/apps/opencs/model/world/idtable.hpp @@ -65,7 +65,6 @@ namespace CSMWorld void cloneRecord(const std::string& origin, const std::string& destination, - UniversalId::ArgumentType argumentType, UniversalId::Type type = UniversalId::Type_None); QModelIndex getModelIndex (const std::string& id, int column) const; diff --git a/apps/opencs/model/world/refidcollection.cpp b/apps/opencs/model/world/refidcollection.cpp index 75a1b681d2..5e8d381177 100644 --- a/apps/opencs/model/world/refidcollection.cpp +++ b/apps/opencs/model/world/refidcollection.cpp @@ -451,15 +451,13 @@ void CSMWorld::RefIdCollection::replace (int index, const RecordBase& record) void CSMWorld::RefIdCollection::cloneRecord(const std::string& origin, const std::string& destination, - const CSMWorld::UniversalId::Type type, - const CSMWorld::UniversalId::ArgumentType argumentType) + const CSMWorld::UniversalId::Type type) { RecordBase *newRecord = mData.getRecord(mData.searchId(origin)).clone(); newRecord->mState = RecordBase::State_ModifiedOnly; mAdapters.find(type)->second->setId(*newRecord, destination); mData.insertRecord(*newRecord, type, destination); delete newRecord; - //WIP } void CSMWorld::RefIdCollection::appendRecord (const RecordBase& record, diff --git a/apps/opencs/model/world/refidcollection.hpp b/apps/opencs/model/world/refidcollection.hpp index 4ad181004f..ebbf2100d9 100644 --- a/apps/opencs/model/world/refidcollection.hpp +++ b/apps/opencs/model/world/refidcollection.hpp @@ -71,8 +71,7 @@ namespace CSMWorld virtual void cloneRecord(const std::string& origin, const std::string& destination, - const UniversalId::Type type, - const UniversalId::ArgumentType argumentType); + const UniversalId::Type type); virtual void appendBlankRecord (const std::string& id, UniversalId::Type type); ///< \param type Will be ignored, unless the collection supports multiple record types diff --git a/apps/opencs/view/world/cellcreator.cpp b/apps/opencs/view/world/cellcreator.cpp index ebf88122b3..e65501e5f6 100644 --- a/apps/opencs/view/world/cellcreator.cpp +++ b/apps/opencs/view/world/cellcreator.cpp @@ -82,10 +82,9 @@ void CSVWorld::CellCreator::valueChanged (int index) } void CSVWorld::CellCreator::cloneMode(const std::string& originid, - const CSMWorld::UniversalId::Type type, - const CSMWorld::UniversalId::ArgumentType argumentType) + const CSMWorld::UniversalId::Type type) { - CSVWorld::GenericCreator::cloneMode(originid, type, argumentType); + CSVWorld::GenericCreator::cloneMode(originid, type); if (*(originid.begin()) == '#') //if originid points to the exterior cell { setType(1); //enable x and y controls diff --git a/apps/opencs/view/world/cellcreator.hpp b/apps/opencs/view/world/cellcreator.hpp index 3130c13280..472be43b94 100644 --- a/apps/opencs/view/world/cellcreator.hpp +++ b/apps/opencs/view/world/cellcreator.hpp @@ -32,8 +32,7 @@ namespace CSVWorld virtual void toggleWidgets(bool active = true); virtual void cloneMode(const std::string& originid, - const CSMWorld::UniversalId::Type type, - const CSMWorld::UniversalId::ArgumentType argumentType); + const CSMWorld::UniversalId::Type type); private slots: diff --git a/apps/opencs/view/world/creator.hpp b/apps/opencs/view/world/creator.hpp index 5174232bc2..9be619915d 100644 --- a/apps/opencs/view/world/creator.hpp +++ b/apps/opencs/view/world/creator.hpp @@ -25,7 +25,8 @@ namespace CSVWorld virtual void reset() = 0; - virtual void cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type, const CSMWorld::UniversalId::ArgumentType argumentType) = 0; + virtual void cloneMode(const std::string& originid, + const CSMWorld::UniversalId::Type type) = 0; virtual void setEditLock (bool locked) = 0; diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index 2a93f0e0f9..1f74b99540 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -127,7 +127,7 @@ void CSVWorld::GenericCreator::create() { std::string id = getId(); std::auto_ptr command (new CSMWorld::CloneCommand ( - dynamic_cast (*mData.getTableModel(mListId)), mClonedId, id, mClonedType, mArgumentType)); + dynamic_cast (*mData.getTableModel(mListId)), mClonedId, id, mClonedType)); mUndoStack.push(command.release()); @@ -150,13 +150,11 @@ void CSVWorld::GenericCreator::create() } void CSVWorld::GenericCreator::cloneMode(const std::string& originid, - const CSMWorld::UniversalId::Type type, - const CSMWorld::UniversalId::ArgumentType argumentType) + const CSMWorld::UniversalId::Type type) { mCloneMode = true; mClonedId = originid; mClonedType = type; - mArgumentType = argumentType; } void CSVWorld::GenericCreator::toggleWidgets(bool active) diff --git a/apps/opencs/view/world/genericcreator.hpp b/apps/opencs/view/world/genericcreator.hpp index 4870ba46c4..06b110b11c 100644 --- a/apps/opencs/view/world/genericcreator.hpp +++ b/apps/opencs/view/world/genericcreator.hpp @@ -67,8 +67,7 @@ namespace CSVWorld virtual void toggleWidgets (bool active = true); virtual void cloneMode(const std::string& originid, - const CSMWorld::UniversalId::Type type, - const CSMWorld::UniversalId::ArgumentType argumentType); + const CSMWorld::UniversalId::Type type); virtual std::string getErrors() const; ///< Return formatted error descriptions for the current state of the creator. if an empty diff --git a/apps/opencs/view/world/referencecreator.cpp b/apps/opencs/view/world/referencecreator.cpp index 6991ecf36d..069300f423 100644 --- a/apps/opencs/view/world/referencecreator.cpp +++ b/apps/opencs/view/world/referencecreator.cpp @@ -85,8 +85,9 @@ void CSVWorld::ReferenceCreator::toggleWidgets(bool active) mCell->setEnabled(active); } -void CSVWorld::ReferenceCreator::cloneMode(const std::string& originid, const CSMWorld::UniversalId::Type type, const CSMWorld::UniversalId::ArgumentType argumentType) +void CSVWorld::ReferenceCreator::cloneMode(const std::string& originid, + const CSMWorld::UniversalId::Type type) { - CSVWorld::GenericCreator::cloneMode(originid, type, argumentType); + CSVWorld::GenericCreator::cloneMode(originid, type); cellChanged(); //otherwise ok button will remain disabled } diff --git a/apps/opencs/view/world/referencecreator.hpp b/apps/opencs/view/world/referencecreator.hpp index 2f0897026d..96c1bec27e 100644 --- a/apps/opencs/view/world/referencecreator.hpp +++ b/apps/opencs/view/world/referencecreator.hpp @@ -26,8 +26,7 @@ namespace CSVWorld const CSMWorld::UniversalId& id); virtual void cloneMode(const std::string& originid, - const CSMWorld::UniversalId::Type type, - const CSMWorld::UniversalId::ArgumentType argumentType); + const CSMWorld::UniversalId::Type type); virtual void reset(); virtual void toggleWidgets(bool active = true); diff --git a/apps/opencs/view/world/tablebottombox.cpp b/apps/opencs/view/world/tablebottombox.cpp index a6801b6fcc..239c7410fb 100644 --- a/apps/opencs/view/world/tablebottombox.cpp +++ b/apps/opencs/view/world/tablebottombox.cpp @@ -160,11 +160,10 @@ void CSVWorld::TableBottomBox::createRequest() } void CSVWorld::TableBottomBox::cloneRequest(const std::string& id, - const CSMWorld::UniversalId::Type type, - const CSMWorld::UniversalId::ArgumentType argumnetType) + const CSMWorld::UniversalId::Type type) { mCreator->reset(); - mCreator->cloneMode(id, type, argumnetType); + mCreator->cloneMode(id, type); mLayout->setCurrentWidget(mCreator); mCreator->toggleWidgets(false); setVisible (true); diff --git a/apps/opencs/view/world/tablebottombox.hpp b/apps/opencs/view/world/tablebottombox.hpp index 29afa22772..8f0d851632 100644 --- a/apps/opencs/view/world/tablebottombox.hpp +++ b/apps/opencs/view/world/tablebottombox.hpp @@ -77,7 +77,8 @@ namespace CSVWorld /// \param modified Number of added and modified records void createRequest(); - void cloneRequest(const std::string& id, const CSMWorld::UniversalId::Type type, const CSMWorld::UniversalId::ArgumentType argumentType); + void cloneRequest(const std::string& id, + const CSMWorld::UniversalId::Type type); }; } diff --git a/apps/opencs/view/world/tablesubview.cpp b/apps/opencs/view/world/tablesubview.cpp index 3c71d13708..e4dbb64ed2 100644 --- a/apps/opencs/view/world/tablesubview.cpp +++ b/apps/opencs/view/world/tablesubview.cpp @@ -49,9 +49,11 @@ CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMDoc::D { connect (mTable, SIGNAL (createRequest()), mBottom, SLOT (createRequest())); - connect (mTable, SIGNAL (cloneRequest(const CSMWorld::UniversalId&)), this, SLOT(cloneRequest(const CSMWorld::UniversalId&))); - connect (this, SIGNAL(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type, const CSMWorld::UniversalId::ArgumentType)), - mBottom, SLOT(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type, const CSMWorld::UniversalId::ArgumentType))); + connect (mTable, SIGNAL (cloneRequest(const CSMWorld::UniversalId&)), this, + SLOT(cloneRequest(const CSMWorld::UniversalId&))); + + connect (this, SIGNAL(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type)), + mBottom, SLOT(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type))); } connect (mBottom, SIGNAL (requestFocus (const std::string&)), mTable, SLOT (requestFocus (const std::string&))); @@ -84,5 +86,5 @@ void CSVWorld::TableSubView::setStatusBar (bool show) void CSVWorld::TableSubView::cloneRequest(const CSMWorld::UniversalId& toClone) { - emit cloneRequest(toClone.getId(), toClone.getType(), toClone.getArgumentType()); + emit cloneRequest(toClone.getId(), toClone.getType()); } diff --git a/apps/opencs/view/world/tablesubview.hpp b/apps/opencs/view/world/tablesubview.hpp index b3a0a51626..9d2d005a88 100644 --- a/apps/opencs/view/world/tablesubview.hpp +++ b/apps/opencs/view/world/tablesubview.hpp @@ -41,8 +41,7 @@ namespace CSVWorld signals: void cloneRequest(const std::string&, - const CSMWorld::UniversalId::Type, - const CSMWorld::UniversalId::ArgumentType); + const CSMWorld::UniversalId::Type); private slots: From 71d63647546db1bf0e2b8adb189cbacb1f6ba1d7 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 13:13:39 +0100 Subject: [PATCH 26/43] Chaninging variables name to follow our policy. --- apps/opencs/view/world/cellcreator.cpp | 6 +++--- apps/opencs/view/world/cellcreator.hpp | 2 +- apps/opencs/view/world/creator.hpp | 2 +- apps/opencs/view/world/genericcreator.cpp | 4 ++-- apps/opencs/view/world/genericcreator.hpp | 2 +- apps/opencs/view/world/referencecreator.cpp | 4 ++-- apps/opencs/view/world/referencecreator.hpp | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/apps/opencs/view/world/cellcreator.cpp b/apps/opencs/view/world/cellcreator.cpp index e65501e5f6..cdeee56559 100644 --- a/apps/opencs/view/world/cellcreator.cpp +++ b/apps/opencs/view/world/cellcreator.cpp @@ -81,11 +81,11 @@ void CSVWorld::CellCreator::valueChanged (int index) update(); } -void CSVWorld::CellCreator::cloneMode(const std::string& originid, +void CSVWorld::CellCreator::cloneMode(const std::string& originId, const CSMWorld::UniversalId::Type type) { - CSVWorld::GenericCreator::cloneMode(originid, type); - if (*(originid.begin()) == '#') //if originid points to the exterior cell + CSVWorld::GenericCreator::cloneMode(originId, type); + if (*(originId.begin()) == '#') //if originid points to the exterior cell { setType(1); //enable x and y controls mType->setCurrentIndex(1); diff --git a/apps/opencs/view/world/cellcreator.hpp b/apps/opencs/view/world/cellcreator.hpp index 472be43b94..74bf5f76bf 100644 --- a/apps/opencs/view/world/cellcreator.hpp +++ b/apps/opencs/view/world/cellcreator.hpp @@ -31,7 +31,7 @@ namespace CSVWorld virtual void toggleWidgets(bool active = true); - virtual void cloneMode(const std::string& originid, + virtual void cloneMode(const std::string& originId, const CSMWorld::UniversalId::Type type); private slots: diff --git a/apps/opencs/view/world/creator.hpp b/apps/opencs/view/world/creator.hpp index 9be619915d..2d5e014e2d 100644 --- a/apps/opencs/view/world/creator.hpp +++ b/apps/opencs/view/world/creator.hpp @@ -25,7 +25,7 @@ namespace CSVWorld virtual void reset() = 0; - virtual void cloneMode(const std::string& originid, + virtual void cloneMode(const std::string& originId, const CSMWorld::UniversalId::Type type) = 0; virtual void setEditLock (bool locked) = 0; diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index 1f74b99540..9fb0b4b21f 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -149,11 +149,11 @@ void CSVWorld::GenericCreator::create() } } -void CSVWorld::GenericCreator::cloneMode(const std::string& originid, +void CSVWorld::GenericCreator::cloneMode(const std::string& originId, const CSMWorld::UniversalId::Type type) { mCloneMode = true; - mClonedId = originid; + mClonedId = originId; mClonedType = type; } diff --git a/apps/opencs/view/world/genericcreator.hpp b/apps/opencs/view/world/genericcreator.hpp index 06b110b11c..98dd12ac27 100644 --- a/apps/opencs/view/world/genericcreator.hpp +++ b/apps/opencs/view/world/genericcreator.hpp @@ -66,7 +66,7 @@ namespace CSVWorld virtual void toggleWidgets (bool active = true); - virtual void cloneMode(const std::string& originid, + virtual void cloneMode(const std::string& originId, const CSMWorld::UniversalId::Type type); virtual std::string getErrors() const; diff --git a/apps/opencs/view/world/referencecreator.cpp b/apps/opencs/view/world/referencecreator.cpp index 069300f423..384b59fc4c 100644 --- a/apps/opencs/view/world/referencecreator.cpp +++ b/apps/opencs/view/world/referencecreator.cpp @@ -85,9 +85,9 @@ void CSVWorld::ReferenceCreator::toggleWidgets(bool active) mCell->setEnabled(active); } -void CSVWorld::ReferenceCreator::cloneMode(const std::string& originid, +void CSVWorld::ReferenceCreator::cloneMode(const std::string& originId, const CSMWorld::UniversalId::Type type) { - CSVWorld::GenericCreator::cloneMode(originid, type); + CSVWorld::GenericCreator::cloneMode(originId, type); cellChanged(); //otherwise ok button will remain disabled } diff --git a/apps/opencs/view/world/referencecreator.hpp b/apps/opencs/view/world/referencecreator.hpp index 96c1bec27e..73b0899e54 100644 --- a/apps/opencs/view/world/referencecreator.hpp +++ b/apps/opencs/view/world/referencecreator.hpp @@ -25,7 +25,7 @@ namespace CSVWorld ReferenceCreator (CSMWorld::Data& data, QUndoStack& undoStack, const CSMWorld::UniversalId& id); - virtual void cloneMode(const std::string& originid, + virtual void cloneMode(const std::string& originId, const CSMWorld::UniversalId::Type type); virtual void reset(); From bb62efc3d844171b1b77b517424871fb3f6de73b Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 13:36:01 +0100 Subject: [PATCH 27/43] Removed pointless includes. --- apps/opencs/model/world/commands.cpp | 1 + apps/opencs/view/world/genericcreator.cpp | 1 - apps/opencs/view/world/table.cpp | 1 - 3 files changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 5eb2e94148..789c5d9b85 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -1,3 +1,4 @@ + #include "commands.hpp" #include diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index 9fb0b4b21f..c1faa741d2 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -2,7 +2,6 @@ #include "genericcreator.hpp" #include -#include #include #include diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index d343f9986a..f166171fe2 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -16,7 +16,6 @@ #include "recordstatusdelegate.hpp" #include "util.hpp" -#include void CSVWorld::Table::contextMenuEvent (QContextMenuEvent *event) { From 6a0b5defd78e2e8e38a05c2c16c68c6ba37403d7 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 13:41:37 +0100 Subject: [PATCH 28/43] removed needless member value. --- apps/opencs/model/world/commands.cpp | 3 +-- apps/opencs/view/world/genericcreator.cpp | 12 +++++++++--- apps/opencs/view/world/genericcreator.hpp | 1 - 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 789c5d9b85..d3ef7128f8 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -1,9 +1,8 @@ #include "commands.hpp" - #include -#include #include "idtable.hpp" +#include CSMWorld::ModifyCommand::ModifyCommand(QAbstractItemModel& model, const QModelIndex& index, const QVariant& new_, QUndoCommand* parent) diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index c1faa741d2..447c07424c 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -57,9 +57,15 @@ const CSMWorld::UniversalId& CSVWorld::GenericCreator::getCollectionId() const } CSVWorld::GenericCreator::GenericCreator (CSMWorld::Data& data, QUndoStack& undoStack, - const CSMWorld::UniversalId& id, bool relaxedIdRules) -: mData (data), mUndoStack (undoStack), mListId (id), mLocked (false), mCloneMode(false), mClonedType(CSMWorld::UniversalId::Type_None), -mArgumentType(CSMWorld::UniversalId::ArgumentType_None) + const CSMWorld::UniversalId& id, bool relaxedIdRules): + + mData (data), + mUndoStack (undoStack), + mListId (id), + mLocked (false), + mCloneMode(false), + mClonedType(CSMWorld::UniversalId::Type_None) + { mLayout = new QHBoxLayout; mLayout->setContentsMargins (0, 0, 0, 0); diff --git a/apps/opencs/view/world/genericcreator.hpp b/apps/opencs/view/world/genericcreator.hpp index 98dd12ac27..0f426e1a79 100644 --- a/apps/opencs/view/world/genericcreator.hpp +++ b/apps/opencs/view/world/genericcreator.hpp @@ -31,7 +31,6 @@ namespace CSVWorld bool mLocked; std::string mClonedId; CSMWorld::UniversalId::Type mClonedType; - CSMWorld::UniversalId::ArgumentType mArgumentType; protected: bool mCloneMode; From 2899f04a3f11ab4821143e69ccbd9807c54b0302 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 14:43:12 +0100 Subject: [PATCH 29/43] reformatting --- apps/opencs/model/world/collection.hpp | 3 ++- apps/opencs/model/world/commands.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index 4bb10c1d84..2905589285 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -204,7 +204,8 @@ namespace CSMWorld const std::string& destination, const UniversalId::Type type) { - Record copy(getRecord(origin)); + Record copy; + copy = getRecord(origin); copy.mState = RecordBase::State_ModifiedOnly; copy.get().mId = destination; diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index d3ef7128f8..5ca169fcd1 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -1,7 +1,8 @@ #include "commands.hpp" -#include + #include "idtable.hpp" +#include #include CSMWorld::ModifyCommand::ModifyCommand(QAbstractItemModel& model, const QModelIndex& index, From 4d6fb31610cd65dcf9d7d07d0dfea4118fd299e5 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 14:45:07 +0100 Subject: [PATCH 30/43] reformating --- apps/opencs/model/world/commands.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 5ca169fcd1..3b70f6940b 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -1,8 +1,10 @@ #include "commands.hpp" -#include "idtable.hpp" #include + +#include "idtable.hpp" + #include CSMWorld::ModifyCommand::ModifyCommand(QAbstractItemModel& model, const QModelIndex& index, @@ -38,7 +40,6 @@ CSMWorld::CloneCommand::CloneCommand(CSMWorld::IdTable& model, setText(("Clone record " + idOrigin + " to the " + IdDestination).c_str()); } - void CSMWorld::CloneCommand::redo() { mModel.cloneRecord(mIdOrigin, mIdDestination, mType); From 316debb8277d6e4b851dc8a85be6efb1c0d248bc Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 14:46:58 +0100 Subject: [PATCH 31/43] reformating --- apps/opencs/model/world/commands.cpp | 56 ++++++++++++++-------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 3b70f6940b..9159b1f162 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -26,34 +26,6 @@ void CSMWorld::ModifyCommand::undo() mModel.setData(mIndex, mOld); } -CSMWorld::CloneCommand::CloneCommand(CSMWorld::IdTable& model, - const std::string& idOrigin, - const std::string& IdDestination, - const CSMWorld::UniversalId::Type type, - QUndoCommand* parent) : - QUndoCommand(parent), - mModel(model), - mIdOrigin(idOrigin), - mIdDestination(Misc::StringUtils::lowerCase(IdDestination)), - mType(type) -{ - setText(("Clone record " + idOrigin + " to the " + IdDestination).c_str()); -} - -void CSMWorld::CloneCommand::redo() -{ - mModel.cloneRecord(mIdOrigin, mIdDestination, mType); - - for (std::map::const_iterator iter(mValues.begin()); iter != mValues.end(); ++iter) - mModel.setData(mModel.getModelIndex(mIdDestination, iter->first), iter->second); -} - -void CSMWorld::CloneCommand::undo() -{ - mModel.removeRow(mModel.getModelIndex(mIdDestination, 0).row()); -} - - CSMWorld::CreateCommand::CreateCommand(IdTable& model, const std::string& id, QUndoCommand* parent) : QUndoCommand(parent), mModel(model), mId(id), mType(UniversalId::Type_None) { @@ -174,4 +146,32 @@ void CSMWorld::ReorderRowsCommand::undo() mModel.reorderRows(mBaseIndex, reverse); } + +CSMWorld::CloneCommand::CloneCommand(CSMWorld::IdTable& model, + const std::string& idOrigin, + const std::string& IdDestination, + const CSMWorld::UniversalId::Type type, + QUndoCommand* parent) : + QUndoCommand(parent), + mModel(model), + mIdOrigin(idOrigin), + mIdDestination(Misc::StringUtils::lowerCase(IdDestination)), + mType(type) +{ + setText(("Clone record " + idOrigin + " to the " + IdDestination).c_str()); +} + +void CSMWorld::CloneCommand::redo() +{ + mModel.cloneRecord(mIdOrigin, mIdDestination, mType); + + for (std::map::const_iterator iter(mValues.begin()); iter != mValues.end(); ++iter) + mModel.setData(mModel.getModelIndex(mIdDestination, iter->first), iter->second); +} + +void CSMWorld::CloneCommand::undo() +{ + mModel.removeRow(mModel.getModelIndex(mIdDestination, 0).row()); +} + // kate: indent-mode cstyle; indent-width 4; replace-tabs on; From 2b71568bb65b9e7f80cb4d43c813dbeb50bb0cb6 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 14:50:36 +0100 Subject: [PATCH 32/43] still reformating --- apps/opencs/model/world/commands.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 9159b1f162..9a9e246f5a 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -3,6 +3,7 @@ #include + #include "idtable.hpp" #include From 52176d6435baee3b092fe21e72be85dcdbe089cf Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 14:51:57 +0100 Subject: [PATCH 33/43] reforfucking --- apps/opencs/model/world/commands.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 9a9e246f5a..80a751ac6e 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -3,9 +3,7 @@ #include - #include "idtable.hpp" - #include CSMWorld::ModifyCommand::ModifyCommand(QAbstractItemModel& model, const QModelIndex& index, From c91ae86084df5f86af4734ec7617e5d09dc180dd Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 14:53:39 +0100 Subject: [PATCH 34/43] is there something that can generate diff from two git branches? Using github for this is kinda annoying. --- apps/opencs/model/world/commands.cpp | 118 +++++++++++++-------------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 80a751ac6e..4b36b1b638 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -6,60 +6,60 @@ #include "idtable.hpp" #include -CSMWorld::ModifyCommand::ModifyCommand(QAbstractItemModel& model, const QModelIndex& index, - const QVariant& new_, QUndoCommand* parent) - : QUndoCommand(parent), mModel(model), mIndex(index), mNew(new_) +CSMWorld::ModifyCommand::ModifyCommand (QAbstractItemModel& model, const QModelIndex& index, + const QVariant& new_, QUndoCommand* parent) + : QUndoCommand (parent), mModel (model), mIndex (index), mNew (new_) { - mOld = mModel.data(mIndex, Qt::EditRole); + mOld = mModel.data (mIndex, Qt::EditRole); - setText("Modify " + mModel.headerData(mIndex.column(), Qt::Horizontal, Qt::DisplayRole).toString()); + setText ("Modify " + mModel.headerData (mIndex.column(), Qt::Horizontal, Qt::DisplayRole).toString()); } void CSMWorld::ModifyCommand::redo() { - mModel.setData(mIndex, mNew); + mModel.setData (mIndex, mNew); } void CSMWorld::ModifyCommand::undo() { - mModel.setData(mIndex, mOld); + mModel.setData (mIndex, mOld); } -CSMWorld::CreateCommand::CreateCommand(IdTable& model, const std::string& id, QUndoCommand* parent) - : QUndoCommand(parent), mModel(model), mId(id), mType(UniversalId::Type_None) +CSMWorld::CreateCommand::CreateCommand (IdTable& model, const std::string& id, QUndoCommand* parent) + : QUndoCommand (parent), mModel (model), mId (id), mType (UniversalId::Type_None) { - setText(("Create record " + id).c_str()); + setText ( ("Create record " + id).c_str()); } -void CSMWorld::CreateCommand::addValue(int column, const QVariant& value) +void CSMWorld::CreateCommand::addValue (int column, const QVariant& value) { mValues[column] = value; } -void CSMWorld::CreateCommand::setType(UniversalId::Type type) +void CSMWorld::CreateCommand::setType (UniversalId::Type type) { mType = type; } void CSMWorld::CreateCommand::redo() { - mModel.addRecord(mId, mType); + mModel.addRecord (mId, mType); - for (std::map::const_iterator iter(mValues.begin()); iter != mValues.end(); ++iter) - mModel.setData(mModel.getModelIndex(mId, iter->first), iter->second); + for (std::map::const_iterator iter (mValues.begin()); iter != mValues.end(); ++iter) + mModel.setData (mModel.getModelIndex (mId, iter->first), iter->second); } void CSMWorld::CreateCommand::undo() { - mModel.removeRow(mModel.getModelIndex(mId, 0).row()); + mModel.removeRow (mModel.getModelIndex (mId, 0).row()); } -CSMWorld::RevertCommand::RevertCommand(IdTable& model, const std::string& id, QUndoCommand* parent) - : QUndoCommand(parent), mModel(model), mId(id), mOld(0) +CSMWorld::RevertCommand::RevertCommand (IdTable& model, const std::string& id, QUndoCommand* parent) + : QUndoCommand (parent), mModel (model), mId (id), mOld (0) { - setText(("Revert record " + id).c_str()); + setText ( ("Revert record " + id).c_str()); - mOld = model.getRecord(id).clone(); + mOld = model.getRecord (id).clone(); } CSMWorld::RevertCommand::~RevertCommand() @@ -69,32 +69,32 @@ CSMWorld::RevertCommand::~RevertCommand() void CSMWorld::RevertCommand::redo() { - int column = mModel.findColumnIndex(Columns::ColumnId_Modification); + int column = mModel.findColumnIndex (Columns::ColumnId_Modification); - QModelIndex index = mModel.getModelIndex(mId, column); - RecordBase::State state = static_cast(mModel.data(index).toInt()); + QModelIndex index = mModel.getModelIndex (mId, column); + RecordBase::State state = static_cast (mModel.data (index).toInt()); if (state == RecordBase::State_ModifiedOnly) { - mModel.removeRows(index.row(), 1); + mModel.removeRows (index.row(), 1); } else { - mModel.setData(index, static_cast(RecordBase::State_BaseOnly)); + mModel.setData (index, static_cast (RecordBase::State_BaseOnly)); } } void CSMWorld::RevertCommand::undo() { - mModel.setRecord(mId, *mOld); + mModel.setRecord (mId, *mOld); } -CSMWorld::DeleteCommand::DeleteCommand(IdTable& model, const std::string& id, QUndoCommand* parent) - : QUndoCommand(parent), mModel(model), mId(id), mOld(0) +CSMWorld::DeleteCommand::DeleteCommand (IdTable& model, const std::string& id, QUndoCommand* parent) + : QUndoCommand (parent), mModel (model), mId (id), mOld (0) { - setText(("Delete record " + id).c_str()); + setText ( ("Delete record " + id).c_str()); - mOld = model.getRecord(id).clone(); + mOld = model.getRecord (id).clone(); } CSMWorld::DeleteCommand::~DeleteCommand() @@ -104,73 +104,73 @@ CSMWorld::DeleteCommand::~DeleteCommand() void CSMWorld::DeleteCommand::redo() { - int column = mModel.findColumnIndex(Columns::ColumnId_Modification); + int column = mModel.findColumnIndex (Columns::ColumnId_Modification); - QModelIndex index = mModel.getModelIndex(mId, column); - RecordBase::State state = static_cast(mModel.data(index).toInt()); + QModelIndex index = mModel.getModelIndex (mId, column); + RecordBase::State state = static_cast (mModel.data (index).toInt()); if (state == RecordBase::State_ModifiedOnly) { - mModel.removeRows(index.row(), 1); + mModel.removeRows (index.row(), 1); } else { - mModel.setData(index, static_cast(RecordBase::State_Deleted)); + mModel.setData (index, static_cast (RecordBase::State_Deleted)); } } void CSMWorld::DeleteCommand::undo() { - mModel.setRecord(mId, *mOld); + mModel.setRecord (mId, *mOld); } -CSMWorld::ReorderRowsCommand::ReorderRowsCommand(IdTable& model, int baseIndex, +CSMWorld::ReorderRowsCommand::ReorderRowsCommand (IdTable& model, int baseIndex, const std::vector& newOrder) - : mModel(model), mBaseIndex(baseIndex), mNewOrder(newOrder) + : mModel (model), mBaseIndex (baseIndex), mNewOrder (newOrder) {} void CSMWorld::ReorderRowsCommand::redo() { - mModel.reorderRows(mBaseIndex, mNewOrder); + mModel.reorderRows (mBaseIndex, mNewOrder); } void CSMWorld::ReorderRowsCommand::undo() { - int size = static_cast(mNewOrder.size()); - std::vector reverse(size); + int size = static_cast (mNewOrder.size()); + std::vector reverse (size); for (int i = 0; i < size; ++i) - reverse.at(mNewOrder[i]) = i; + reverse.at (mNewOrder[i]) = i; - mModel.reorderRows(mBaseIndex, reverse); + mModel.reorderRows (mBaseIndex, reverse); } -CSMWorld::CloneCommand::CloneCommand(CSMWorld::IdTable& model, - const std::string& idOrigin, - const std::string& IdDestination, - const CSMWorld::UniversalId::Type type, - QUndoCommand* parent) : - QUndoCommand(parent), - mModel(model), - mIdOrigin(idOrigin), - mIdDestination(Misc::StringUtils::lowerCase(IdDestination)), - mType(type) +CSMWorld::CloneCommand::CloneCommand (CSMWorld::IdTable& model, + const std::string& idOrigin, + const std::string& IdDestination, + const CSMWorld::UniversalId::Type type, + QUndoCommand* parent) : + QUndoCommand (parent), + mModel (model), + mIdOrigin (idOrigin), + mIdDestination (Misc::StringUtils::lowerCase (IdDestination)), + mType (type) { - setText(("Clone record " + idOrigin + " to the " + IdDestination).c_str()); + setText ( ("Clone record " + idOrigin + " to the " + IdDestination).c_str()); } void CSMWorld::CloneCommand::redo() { - mModel.cloneRecord(mIdOrigin, mIdDestination, mType); - - for (std::map::const_iterator iter(mValues.begin()); iter != mValues.end(); ++iter) - mModel.setData(mModel.getModelIndex(mIdDestination, iter->first), iter->second); + mModel.cloneRecord (mIdOrigin, mIdDestination, mType); + + for (std::map::const_iterator iter (mValues.begin()); iter != mValues.end(); ++iter) + mModel.setData (mModel.getModelIndex (mIdDestination, iter->first), iter->second); } void CSMWorld::CloneCommand::undo() { - mModel.removeRow(mModel.getModelIndex(mIdDestination, 0).row()); + mModel.removeRow (mModel.getModelIndex (mIdDestination, 0).row()); } // kate: indent-mode cstyle; indent-width 4; replace-tabs on; From 51115fa5be719a1ad02e03ee7d4cc6b78f665382 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 14:56:57 +0100 Subject: [PATCH 35/43] spaces around operators --- apps/opencs/model/world/commands.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 4b36b1b638..1bb1cf2b2c 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -170,7 +170,7 @@ void CSMWorld::CloneCommand::redo() void CSMWorld::CloneCommand::undo() { - mModel.removeRow (mModel.getModelIndex (mIdDestination, 0).row()); + mModel.removeRow (mModel.getModelIndex (mIdDestination, 0).row()); //should be enough } // kate: indent-mode cstyle; indent-width 4; replace-tabs on; From 84e07c95b1d375d0b03d68c6fa1076d39f5e5bf7 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 15:02:29 +0100 Subject: [PATCH 36/43] formatting --- apps/opencs/model/world/commands.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 1bb1cf2b2c..a544baee3d 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -8,7 +8,7 @@ CSMWorld::ModifyCommand::ModifyCommand (QAbstractItemModel& model, const QModelIndex& index, const QVariant& new_, QUndoCommand* parent) - : QUndoCommand (parent), mModel (model), mIndex (index), mNew (new_) +: QUndoCommand (parent), mModel (model), mIndex (index), mNew (new_) { mOld = mModel.data (mIndex, Qt::EditRole); @@ -26,9 +26,9 @@ void CSMWorld::ModifyCommand::undo() } CSMWorld::CreateCommand::CreateCommand (IdTable& model, const std::string& id, QUndoCommand* parent) - : QUndoCommand (parent), mModel (model), mId (id), mType (UniversalId::Type_None) +: QUndoCommand (parent), mModel (model), mId (id), mType (UniversalId::Type_None) { - setText ( ("Create record " + id).c_str()); + setText (("Create record " + id).c_str()); } void CSMWorld::CreateCommand::addValue (int column, const QVariant& value) @@ -45,7 +45,7 @@ void CSMWorld::CreateCommand::redo() { mModel.addRecord (mId, mType); - for (std::map::const_iterator iter (mValues.begin()); iter != mValues.end(); ++iter) + for (std::map::const_iterator iter (mValues.begin()); iter!=mValues.end(); ++iter) mModel.setData (mModel.getModelIndex (mId, iter->first), iter->second); } @@ -55,9 +55,9 @@ 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) { - setText ( ("Revert record " + id).c_str()); + setText (("Revert record " + id).c_str()); mOld = model.getRecord (id).clone(); } @@ -74,7 +74,7 @@ void CSMWorld::RevertCommand::redo() QModelIndex index = mModel.getModelIndex (mId, column); RecordBase::State state = static_cast (mModel.data (index).toInt()); - if (state == RecordBase::State_ModifiedOnly) + if (state==RecordBase::State_ModifiedOnly) { mModel.removeRows (index.row(), 1); } @@ -90,9 +90,9 @@ void CSMWorld::RevertCommand::undo() } CSMWorld::DeleteCommand::DeleteCommand (IdTable& model, const std::string& id, QUndoCommand* parent) - : QUndoCommand (parent), mModel (model), mId (id), mOld (0) +: QUndoCommand (parent), mModel (model), mId (id), mOld (0) { - setText ( ("Delete record " + id).c_str()); + setText (("Delete record " + id).c_str()); mOld = model.getRecord (id).clone(); } @@ -109,7 +109,7 @@ void CSMWorld::DeleteCommand::redo() QModelIndex index = mModel.getModelIndex (mId, column); RecordBase::State state = static_cast (mModel.data (index).toInt()); - if (state == RecordBase::State_ModifiedOnly) + if (state==RecordBase::State_ModifiedOnly) { mModel.removeRows (index.row(), 1); } @@ -127,7 +127,7 @@ void CSMWorld::DeleteCommand::undo() CSMWorld::ReorderRowsCommand::ReorderRowsCommand (IdTable& model, int baseIndex, const std::vector& newOrder) - : mModel (model), mBaseIndex (baseIndex), mNewOrder (newOrder) +: mModel (model), mBaseIndex (baseIndex), mNewOrder (newOrder) {} void CSMWorld::ReorderRowsCommand::redo() @@ -140,7 +140,7 @@ void CSMWorld::ReorderRowsCommand::undo() int size = static_cast (mNewOrder.size()); std::vector reverse (size); - for (int i = 0; i < size; ++i) + for (int i=0; i < size; ++i) reverse.at (mNewOrder[i]) = i; mModel.reorderRows (mBaseIndex, reverse); From 9c579dbd6c4b4fea3dd72bf9e446d6d74d00bfb1 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 15:03:29 +0100 Subject: [PATCH 37/43] ok, that should be enough --- apps/opencs/model/world/commands.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index a544baee3d..5526d74186 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -140,7 +140,7 @@ void CSMWorld::ReorderRowsCommand::undo() int size = static_cast (mNewOrder.size()); std::vector reverse (size); - for (int i=0; i < size; ++i) + for (int i=0; i< size; ++i) reverse.at (mNewOrder[i]) = i; mModel.reorderRows (mBaseIndex, reverse); From ed0ba906cfbfd72a7b41b3dbd48db12b9cc05023 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 15:05:29 +0100 Subject: [PATCH 38/43] removed needless include --- apps/opencs/view/world/tablesubview.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/opencs/view/world/tablesubview.cpp b/apps/opencs/view/world/tablesubview.cpp index e4dbb64ed2..5495c708fc 100644 --- a/apps/opencs/view/world/tablesubview.cpp +++ b/apps/opencs/view/world/tablesubview.cpp @@ -6,7 +6,6 @@ #include "../../model/doc/document.hpp" #include "../filter/filterbox.hpp" -#include "../../model/world/idtable.hpp" #include "table.hpp" #include "tablebottombox.hpp" #include "creator.hpp" From d0b07de7efd4b77c105112cc495d1040b33261af Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 16:59:18 +0100 Subject: [PATCH 39/43] Corrected bug mentioned by zini. --- apps/opencs/model/world/collection.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index 2905589285..64b950e609 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -205,7 +205,7 @@ namespace CSMWorld const UniversalId::Type type) { Record copy; - copy = getRecord(origin); + copy.mModified = getRecord(origin).get(); copy.mState = RecordBase::State_ModifiedOnly; copy.get().mId = destination; From c82db915f17922d03b68a33de3a85b4e427b0c01 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 19:32:51 +0100 Subject: [PATCH 40/43] Removed needless includes --- apps/opencs/model/world/collection.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index 64b950e609..9fc97d580e 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -7,12 +7,10 @@ #include #include #include -#include #include #include -#include #include "columnbase.hpp" From 62ea0bb06685aefff34329c19486222714a94934 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 19:40:05 +0100 Subject: [PATCH 41/43] Cleared whitespaces. --- apps/opencs/model/world/collection.hpp | 12 ++++++------ apps/opencs/model/world/collectionbase.hpp | 2 +- apps/opencs/model/world/commands.hpp | 4 ++-- apps/opencs/model/world/idtable.hpp | 2 +- apps/opencs/model/world/refidcollection.hpp | 2 +- apps/opencs/view/world/cellcreator.hpp | 4 ++-- apps/opencs/view/world/creator.hpp | 4 ++-- apps/opencs/view/world/genericcreator.cpp | 6 +++--- apps/opencs/view/world/genericcreator.hpp | 6 +++--- apps/opencs/view/world/referencecreator.cpp | 4 ++-- apps/opencs/view/world/referencecreator.hpp | 2 +- apps/opencs/view/world/table.cpp | 2 +- apps/opencs/view/world/tablesubview.cpp | 6 +++--- apps/opencs/view/world/tablesubview.hpp | 4 ++-- 14 files changed, 30 insertions(+), 30 deletions(-) diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index 9fc97d580e..d342e88a47 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -50,7 +50,7 @@ namespace CSMWorld // not implemented Collection (const Collection&); Collection& operator= (const Collection&); - + protected: const std::map& getIdMap() const; @@ -97,11 +97,11 @@ namespace CSMWorld virtual void appendBlankRecord (const std::string& id, UniversalId::Type type = UniversalId::Type_None); ///< \param type Will be ignored, unless the collection supports multiple record types - + virtual void cloneRecord(const std::string& origin, const std::string& destination, const UniversalId::Type type); - + virtual int searchId (const std::string& id) const; ////< Search record with \a id. /// \return index of record (if found) or -1 (not found) @@ -149,7 +149,7 @@ namespace CSMWorld void setRecord (int index, const Record& record); ///< \attention This function must not change the ID. }; - + template const std::map& Collection::getIdMap() const { @@ -206,10 +206,10 @@ namespace CSMWorld copy.mModified = getRecord(origin).get(); copy.mState = RecordBase::State_ModifiedOnly; copy.get().mId = destination; - + insertRecord(copy, getAppendIndex(destination, type)); } - + template Collection::Collection() {} diff --git a/apps/opencs/model/world/collectionbase.hpp b/apps/opencs/model/world/collectionbase.hpp index 2473ae741b..408a89d923 100644 --- a/apps/opencs/model/world/collectionbase.hpp +++ b/apps/opencs/model/world/collectionbase.hpp @@ -77,7 +77,7 @@ namespace CSMWorld virtual void cloneRecord(const std::string& origin, const std::string& destination, const UniversalId::Type type) = 0; - + virtual const RecordBase& getRecord (const std::string& id) const = 0; virtual const RecordBase& getRecord (int index) const = 0; diff --git a/apps/opencs/model/world/commands.hpp b/apps/opencs/model/world/commands.hpp index 0dedea0122..ec6350658f 100644 --- a/apps/opencs/model/world/commands.hpp +++ b/apps/opencs/model/world/commands.hpp @@ -53,12 +53,12 @@ namespace CSMWorld const std::string& IdDestination, const UniversalId::Type type, QUndoCommand* parent = 0); - + virtual void redo(); virtual void undo(); }; - + class CreateCommand : public QUndoCommand { IdTable& mModel; diff --git a/apps/opencs/model/world/idtable.hpp b/apps/opencs/model/world/idtable.hpp index 2d620004cd..74923867d6 100644 --- a/apps/opencs/model/world/idtable.hpp +++ b/apps/opencs/model/world/idtable.hpp @@ -66,7 +66,7 @@ namespace CSMWorld void cloneRecord(const std::string& origin, const std::string& destination, UniversalId::Type type = UniversalId::Type_None); - + QModelIndex getModelIndex (const std::string& id, int column) const; void setRecord (const std::string& id, const RecordBase& record); diff --git a/apps/opencs/model/world/refidcollection.hpp b/apps/opencs/model/world/refidcollection.hpp index ebbf2100d9..5e973b4477 100644 --- a/apps/opencs/model/world/refidcollection.hpp +++ b/apps/opencs/model/world/refidcollection.hpp @@ -72,7 +72,7 @@ namespace CSMWorld virtual void cloneRecord(const std::string& origin, const std::string& destination, const UniversalId::Type type); - + virtual void appendBlankRecord (const std::string& id, UniversalId::Type type); ///< \param type Will be ignored, unless the collection supports multiple record types diff --git a/apps/opencs/view/world/cellcreator.hpp b/apps/opencs/view/world/cellcreator.hpp index 74bf5f76bf..db9fbf8a34 100644 --- a/apps/opencs/view/world/cellcreator.hpp +++ b/apps/opencs/view/world/cellcreator.hpp @@ -28,9 +28,9 @@ namespace CSVWorld CellCreator (CSMWorld::Data& data, QUndoStack& undoStack, const CSMWorld::UniversalId& id); virtual void reset(); - + virtual void toggleWidgets(bool active = true); - + virtual void cloneMode(const std::string& originId, const CSMWorld::UniversalId::Type type); diff --git a/apps/opencs/view/world/creator.hpp b/apps/opencs/view/world/creator.hpp index 2d5e014e2d..88da70330d 100644 --- a/apps/opencs/view/world/creator.hpp +++ b/apps/opencs/view/world/creator.hpp @@ -24,12 +24,12 @@ namespace CSVWorld virtual ~Creator(); virtual void reset() = 0; - + virtual void cloneMode(const std::string& originId, const CSMWorld::UniversalId::Type type) = 0; virtual void setEditLock (bool locked) = 0; - + virtual void toggleWidgets(bool active = true) = 0; signals: diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index 447c07424c..cd7a5fa189 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -57,15 +57,15 @@ const CSMWorld::UniversalId& CSVWorld::GenericCreator::getCollectionId() const } CSVWorld::GenericCreator::GenericCreator (CSMWorld::Data& data, QUndoStack& undoStack, - const CSMWorld::UniversalId& id, bool relaxedIdRules): - + const CSMWorld::UniversalId& id, bool relaxedIdRules): + mData (data), mUndoStack (undoStack), mListId (id), mLocked (false), mCloneMode(false), mClonedType(CSMWorld::UniversalId::Type_None) - + { mLayout = new QHBoxLayout; mLayout->setContentsMargins (0, 0, 0, 0); diff --git a/apps/opencs/view/world/genericcreator.hpp b/apps/opencs/view/world/genericcreator.hpp index 0f426e1a79..6cc39cf23b 100644 --- a/apps/opencs/view/world/genericcreator.hpp +++ b/apps/opencs/view/world/genericcreator.hpp @@ -31,10 +31,10 @@ namespace CSVWorld bool mLocked; std::string mClonedId; CSMWorld::UniversalId::Type mClonedType; - + protected: bool mCloneMode; - + protected: void update(); @@ -49,7 +49,7 @@ namespace CSVWorld virtual std::string getId() const; virtual void configureCreateCommand (CSMWorld::CreateCommand& command) const; - + CSMWorld::Data& getData() const; const CSMWorld::UniversalId& getCollectionId() const; diff --git a/apps/opencs/view/world/referencecreator.cpp b/apps/opencs/view/world/referencecreator.cpp index 384b59fc4c..6b8e02da0d 100644 --- a/apps/opencs/view/world/referencecreator.cpp +++ b/apps/opencs/view/world/referencecreator.cpp @@ -53,9 +53,9 @@ std::string CSVWorld::ReferenceCreator::getErrors() const { return errors; } - + std::string cell = mCell->text().toUtf8().constData(); - + if (cell.empty()) { if (!errors.empty()) diff --git a/apps/opencs/view/world/referencecreator.hpp b/apps/opencs/view/world/referencecreator.hpp index 73b0899e54..12fb12dd90 100644 --- a/apps/opencs/view/world/referencecreator.hpp +++ b/apps/opencs/view/world/referencecreator.hpp @@ -27,7 +27,7 @@ namespace CSVWorld virtual void cloneMode(const std::string& originId, const CSMWorld::UniversalId::Type type); - + virtual void reset(); virtual void toggleWidgets(bool active = true); diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index f166171fe2..8f6fc46a88 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -203,7 +203,7 @@ CSVWorld::Table::Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, Q mCreateAction = new QAction (tr ("Add Record"), this); connect (mCreateAction, SIGNAL (triggered()), this, SIGNAL (createRequest())); addAction (mCreateAction); - + mCloneAction = new QAction (tr ("Clone Record"), this); connect(mCloneAction, SIGNAL (triggered()), this, SLOT (cloneRecord())); addAction(mCloneAction); diff --git a/apps/opencs/view/world/tablesubview.cpp b/apps/opencs/view/world/tablesubview.cpp index 5495c708fc..981faaf591 100644 --- a/apps/opencs/view/world/tablesubview.cpp +++ b/apps/opencs/view/world/tablesubview.cpp @@ -47,11 +47,11 @@ CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMDoc::D if (mBottom->canCreateAndDelete()) { connect (mTable, SIGNAL (createRequest()), mBottom, SLOT (createRequest())); - + connect (mTable, SIGNAL (cloneRequest(const CSMWorld::UniversalId&)), this, SLOT(cloneRequest(const CSMWorld::UniversalId&))); - - connect (this, SIGNAL(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type)), + + connect (this, SIGNAL(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type)), mBottom, SLOT(cloneRequest(const std::string&, const CSMWorld::UniversalId::Type))); } connect (mBottom, SIGNAL (requestFocus (const std::string&)), diff --git a/apps/opencs/view/world/tablesubview.hpp b/apps/opencs/view/world/tablesubview.hpp index 9d2d005a88..d728dc2f38 100644 --- a/apps/opencs/view/world/tablesubview.hpp +++ b/apps/opencs/view/world/tablesubview.hpp @@ -38,9 +38,9 @@ namespace CSVWorld virtual void updateEditorSetting (const QString& key, const QString& value); virtual void setStatusBar (bool show); - + signals: - void cloneRequest(const std::string&, + void cloneRequest(const std::string&, const CSMWorld::UniversalId::Type); private slots: From d3000ce0990a05f89fd212b138107edfb10b20ba Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 27 Jan 2014 19:47:54 +0100 Subject: [PATCH 42/43] whitespaces removed again. --- apps/opencs/view/world/genericcreator.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/opencs/view/world/genericcreator.hpp b/apps/opencs/view/world/genericcreator.hpp index 6cc39cf23b..714853f986 100644 --- a/apps/opencs/view/world/genericcreator.hpp +++ b/apps/opencs/view/world/genericcreator.hpp @@ -62,12 +62,12 @@ namespace CSVWorld virtual void setEditLock (bool locked); virtual void reset(); - + virtual void toggleWidgets (bool active = true); virtual void cloneMode(const std::string& originId, const CSMWorld::UniversalId::Type type); - + virtual std::string getErrors() const; ///< Return formatted error descriptions for the current state of the creator. if an empty /// string is returned, there is no error. From 2bd98a69ab487062ec9d54efccde89ce9b8e6929 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Tue, 28 Jan 2014 11:16:48 +0100 Subject: [PATCH 43/43] Corrections, according to the comments. Thanks for the review. :-) --- apps/opencs/model/world/commands.cpp | 6 ++---- apps/opencs/model/world/refidcollection.cpp | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 5526d74186..b60ffeb29c 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -170,7 +170,5 @@ void CSMWorld::CloneCommand::redo() void CSMWorld::CloneCommand::undo() { - mModel.removeRow (mModel.getModelIndex (mIdDestination, 0).row()); //should be enough -} - -// kate: indent-mode cstyle; indent-width 4; replace-tabs on; + mModel.removeRow (mModel.getModelIndex (mIdDestination, 0).row()); +} \ No newline at end of file diff --git a/apps/opencs/model/world/refidcollection.cpp b/apps/opencs/model/world/refidcollection.cpp index 5e8d381177..5d310208ac 100644 --- a/apps/opencs/model/world/refidcollection.cpp +++ b/apps/opencs/model/world/refidcollection.cpp @@ -2,6 +2,7 @@ #include "refidcollection.hpp" #include +#include #include @@ -453,11 +454,10 @@ void CSMWorld::RefIdCollection::cloneRecord(const std::string& origin, const std::string& destination, const CSMWorld::UniversalId::Type type) { - RecordBase *newRecord = mData.getRecord(mData.searchId(origin)).clone(); + std::auto_ptr newRecord(mData.getRecord(mData.searchId(origin)).clone()); newRecord->mState = RecordBase::State_ModifiedOnly; mAdapters.find(type)->second->setId(*newRecord, destination); mData.insertRecord(*newRecord, type, destination); - delete newRecord; } void CSMWorld::RefIdCollection::appendRecord (const RecordBase& record,