From f92d801fafa64ea3cabd78886a3d6dae2760b5af Mon Sep 17 00:00:00 2001 From: cc9cii Date: Fri, 15 May 2015 12:32:29 +1000 Subject: [PATCH] Jump to the added/cloned record (or undeleted record in case of undo). Should resolve Feature #2541. Controlled by radio buttons on user preferences settings. --- apps/opencs/model/settings/usersettings.cpp | 8 +++ apps/opencs/view/world/table.cpp | 54 +++++++++++++++++++-- apps/opencs/view/world/table.hpp | 4 ++ 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/apps/opencs/model/settings/usersettings.cpp b/apps/opencs/model/settings/usersettings.cpp index 9e00b7d1aa..41ce593b75 100644 --- a/apps/opencs/model/settings/usersettings.cpp +++ b/apps/opencs/model/settings/usersettings.cpp @@ -206,6 +206,14 @@ void CSMSettings::UserSettings::buildSettingModelDefaults() shiftCtrlDoubleClick->setDeclaredValues (values); shiftCtrlDoubleClick->setDefaultValue (editRecordAndClose); shiftCtrlDoubleClick->setToolTip ("Action on shift control double click in table:

" + toolTip); + + QString defaultValue = "Jump and Select"; + QStringList jumpValues = QStringList() << defaultValue << "Jump Only" << "No Jump"; + + Setting *jumpToAdded = createSetting (Type_RadioButton, "jump-to-added", + "Jump to the added or cloned record."); + jumpToAdded->setDefaultValue (defaultValue); + jumpToAdded->setDeclaredValues (jumpValues); } declareSection ("search", "Search & Replace"); diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index 5a650f98a1..44150bbc6a 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -21,6 +21,7 @@ #include "../../model/world/tablemimedata.hpp" #include "../../model/world/tablemimedata.hpp" #include "../../model/world/commanddispatcher.hpp" +#include "../../model/settings/usersettings.hpp" #include "recordstatusdelegate.hpp" #include "util.hpp" @@ -255,6 +256,24 @@ CSVWorld::Table::Table (const CSMWorld::UniversalId& id, : mCreateAction (0), mCloneAction(0), mRecordStatusDisplay (0), DragRecordTable(document) { + CSMSettings::UserSettings &settings = CSMSettings::UserSettings::instance(); + QString jumpSetting = settings.settingValue ("table-input/jump-to-added"); + if (jumpSetting.isEmpty() || jumpSetting == "Jump and Select") // default + { + mJumpToAddedRecord = true; + mUnselectAfterJump = false; + } + else if(jumpSetting == "Jump Only") + { + mJumpToAddedRecord = true; + mUnselectAfterJump = true; + } + else + { + mJumpToAddedRecord = false; + mUnselectAfterJump = false; + } + mModel = &dynamic_cast (*mDocument.getData().getTableModel (id)); mProxyModel = new CSMWorld::IdTableProxyModel (this); @@ -346,7 +365,7 @@ CSVWorld::Table::Table (const CSMWorld::UniversalId& id, addAction (mExtendedRevertAction); connect (mProxyModel, SIGNAL (rowsInserted (const QModelIndex&, int, int)), - this, SLOT (tableSizeUpdate())); + this, SLOT (rowsInsertedEvent(const QModelIndex&, int, int))); /// \note This signal could instead be connected to a slot that filters out changes not affecting /// the records status column (for permanence reasons) @@ -517,9 +536,27 @@ void CSVWorld::Table::previewRecord() } } -void CSVWorld::Table::updateUserSetting - (const QString &name, const QStringList &list) +void CSVWorld::Table::updateUserSetting (const QString &name, const QStringList &list) { + if (name=="table-input/jump-to-added") + { + if(list.isEmpty() || list.at(0) == "Jump and Select") // default + { + mJumpToAddedRecord = true; + mUnselectAfterJump = false; + } + else if(list.at(0) == "Jump Only") + { + mJumpToAddedRecord = true; + mUnselectAfterJump = true; + } + else // No Jump + { + mJumpToAddedRecord = false; + mUnselectAfterJump = false; + } + } + if (name=="records/type-format" || name=="records/status-format") { int columns = mModel->columnCount(); @@ -700,3 +737,14 @@ std::vector< CSMWorld::UniversalId > CSVWorld::Table::getDraggedRecords() const return idToDrag; } +void CSVWorld::Table::rowsInsertedEvent(const QModelIndex& parent, int start, int end) +{ + tableSizeUpdate(); + if(mJumpToAddedRecord) + { + selectRow(end); + + if(mUnselectAfterJump) + clearSelection(); + } +} diff --git a/apps/opencs/view/world/table.hpp b/apps/opencs/view/world/table.hpp index 75161b8b65..becb21f65d 100644 --- a/apps/opencs/view/world/table.hpp +++ b/apps/opencs/view/world/table.hpp @@ -67,6 +67,8 @@ namespace CSVWorld CSMWorld::CommandDispatcher *mDispatcher; CSMWorld::UniversalId mEditCellId; std::map mDoubleClickActions; + bool mJumpToAddedRecord; + bool mUnselectAfterJump; private: @@ -139,6 +141,8 @@ namespace CSVWorld void recordFilterChanged (boost::shared_ptr filter); void updateUserSetting (const QString &name, const QStringList &list); + + void rowsInsertedEvent(const QModelIndex& parent, int start, int end); }; }