diff --git a/apps/opencs/view/world/creator.hpp b/apps/opencs/view/world/creator.hpp index a5c1991c3..df9b116ee 100644 --- a/apps/opencs/view/world/creator.hpp +++ b/apps/opencs/view/world/creator.hpp @@ -29,6 +29,10 @@ namespace CSVWorld signals: void done(); + + void requestFocus (const std::string& id); + ///< Request owner of this creator to focus the just created \a id. The owner may + /// ignore this request. }; /// \brief Base class for Creator factory diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index ba965bc94..41ae5c90a 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -101,9 +101,12 @@ void CSVWorld::GenericCreator::create() { if (!mLocked) { + std::string id = getId(); + mUndoStack.push (new CSMWorld::CreateCommand ( - dynamic_cast (*mData.getTableModel (mListId)), getId())); + dynamic_cast (*mData.getTableModel (mListId)), id)); emit done(); + emit requestFocus (id); } } \ No newline at end of file diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index c35d7358a..fdbf67e42 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -282,4 +282,12 @@ void CSVWorld::Table::tableSizeUpdate() void CSVWorld::Table::selectionSizeUpdate() { selectionSizeChanged (selectionModel()->selectedRows().size()); +} + +void CSVWorld::Table::requestFocus (const std::string& id) +{ + QModelIndex index = mProxyModel->getModelIndex (id, 0); + + if (index.isValid()) + scrollTo (index, QAbstractItemView::PositionAtTop); } \ No newline at end of file diff --git a/apps/opencs/view/world/table.hpp b/apps/opencs/view/world/table.hpp index 2a59270b8..0c24e7b54 100644 --- a/apps/opencs/view/world/table.hpp +++ b/apps/opencs/view/world/table.hpp @@ -83,6 +83,8 @@ namespace CSVWorld void selectionSizeUpdate(); + void requestFocus (const std::string& id); + }; } diff --git a/apps/opencs/view/world/tablebottombox.cpp b/apps/opencs/view/world/tablebottombox.cpp index 6a5dc83c1..6cf21a132 100644 --- a/apps/opencs/view/world/tablebottombox.cpp +++ b/apps/opencs/view/world/tablebottombox.cpp @@ -66,6 +66,9 @@ CSVWorld::TableBottomBox::TableBottomBox (const CreatorFactoryBase& creatorFacto mLayout->addWidget (mCreator); connect (mCreator, SIGNAL (done()), this, SLOT (createRequestDone())); + + connect (mCreator, SIGNAL (requestFocus (const std::string&)), + this, SIGNAL (requestFocus (const std::string&))); } void CSVWorld::TableBottomBox::setEditLock (bool locked) diff --git a/apps/opencs/view/world/tablebottombox.hpp b/apps/opencs/view/world/tablebottombox.hpp index 21e68f51a..a5ae5e0bd 100644 --- a/apps/opencs/view/world/tablebottombox.hpp +++ b/apps/opencs/view/world/tablebottombox.hpp @@ -55,6 +55,12 @@ namespace CSVWorld /// /// \note The BotomBox does not partake in the deletion of records. + signals: + + void requestFocus (const std::string& id); + ///< Request owner of this box to focus the just created \a id. The owner may + /// ignore this request. + private slots: void createRequestDone(); diff --git a/apps/opencs/view/world/tablesubview.cpp b/apps/opencs/view/world/tablesubview.cpp index fb1a255cb..af3d186e8 100644 --- a/apps/opencs/view/world/tablesubview.cpp +++ b/apps/opencs/view/world/tablesubview.cpp @@ -41,6 +41,9 @@ CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMDoc::D if (mBottom->canCreateAndDelete()) connect (mTable, SIGNAL (createRequest()), mBottom, SLOT (createRequest())); + + connect (mBottom, SIGNAL (requestFocus (const std::string&)), + mTable, SLOT (requestFocus (const std::string&))); } void CSVWorld::TableSubView::setEditLock (bool locked)