From aad13e6bffa332e4a497c42e61f4837e2e9fca2d Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 25 Oct 2014 18:13:56 +0200 Subject: [PATCH] close view when closing last sub-view unless this view is the last view --- apps/opencs/view/doc/subview.cpp | 5 +++++ apps/opencs/view/doc/subview.hpp | 6 ++++++ apps/opencs/view/doc/view.cpp | 12 +++++++++++- apps/opencs/view/doc/view.hpp | 2 ++ apps/opencs/view/world/previewsubview.cpp | 5 ----- apps/opencs/view/world/previewsubview.hpp | 2 -- apps/opencs/view/world/scenesubview.cpp | 5 ----- apps/opencs/view/world/scenesubview.hpp | 2 -- apps/opencs/view/world/scriptsubview.cpp | 2 +- apps/opencs/view/world/tablesubview.cpp | 4 ---- apps/opencs/view/world/tablesubview.hpp | 2 -- 11 files changed, 25 insertions(+), 22 deletions(-) diff --git a/apps/opencs/view/doc/subview.cpp b/apps/opencs/view/doc/subview.cpp index ab4325cfc..1af6a7a2f 100644 --- a/apps/opencs/view/doc/subview.cpp +++ b/apps/opencs/view/doc/subview.cpp @@ -35,3 +35,8 @@ void CSVDoc::SubView::closeEvent (QCloseEvent *event) if(mParent) mParent->updateSubViewIndicies(this); } + +void CSVDoc::SubView::closeRequest() +{ + emit closeRequest (this); +} \ No newline at end of file diff --git a/apps/opencs/view/doc/subview.hpp b/apps/opencs/view/doc/subview.hpp index 6a3ddd8bd..60478f0bc 100644 --- a/apps/opencs/view/doc/subview.hpp +++ b/apps/opencs/view/doc/subview.hpp @@ -57,6 +57,12 @@ namespace CSVDoc void focusId (const CSMWorld::UniversalId& universalId, const std::string& hint); + void closeRequest (SubView *subView); + + protected slots: + + void closeRequest(); + public slots: virtual void updateUserSetting (const QString &, const QStringList &); diff --git a/apps/opencs/view/doc/view.cpp b/apps/opencs/view/doc/view.cpp index d36e01901..299c07805 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -323,7 +323,7 @@ void CSVDoc::View::updateSubViewIndicies(SubView *view) if(view && mSubViews.contains(view)) mSubViews.removeOne(view); - if(mSubViews.size() == 1) + if (mSubViews.size() == 1) { if(!mSubViews.at(0)->isFloating()) { @@ -518,6 +518,8 @@ void CSVDoc::View::addSubView (const CSMWorld::UniversalId& id, const std::strin view, SLOT (updateUserSetting (const QString &, const QStringList &))); + connect (view, SIGNAL (closeRequest (SubView *)), this, SLOT (closeRequest (SubView *))); + view->show(); } @@ -761,3 +763,11 @@ void CSVDoc::View::stop() { mDocument->stopRunning(); } + +void CSVDoc::View::closeRequest (SubView *subView) +{ + if (mSubViews.size()>1 || mViewTotal<=1) + subView->deleteLater(); + else if (mViewManager.closeRequest (this)) + mViewManager.removeDocAndView (mDocument); +} \ No newline at end of file diff --git a/apps/opencs/view/doc/view.hpp b/apps/opencs/view/doc/view.hpp index e3ada1f2e..32ef8071d 100644 --- a/apps/opencs/view/doc/view.hpp +++ b/apps/opencs/view/doc/view.hpp @@ -222,6 +222,8 @@ namespace CSVDoc void run (const std::string& profile, const std::string& startupInstruction = ""); void stop(); + + void closeRequest (SubView *subView); }; } diff --git a/apps/opencs/view/world/previewsubview.cpp b/apps/opencs/view/world/previewsubview.cpp index 1e106c69f..dd94a00e0 100644 --- a/apps/opencs/view/world/previewsubview.cpp +++ b/apps/opencs/view/world/previewsubview.cpp @@ -52,11 +52,6 @@ CSVWorld::PreviewSubView::PreviewSubView (const CSMWorld::UniversalId& id, CSMDo void CSVWorld::PreviewSubView::setEditLock (bool locked) {} -void CSVWorld::PreviewSubView::closeRequest() -{ - deleteLater(); -} - void CSVWorld::PreviewSubView::referenceableIdChanged (const std::string& id) { if (id.empty()) diff --git a/apps/opencs/view/world/previewsubview.hpp b/apps/opencs/view/world/previewsubview.hpp index 4ca25c3cb..fb57ce7a3 100644 --- a/apps/opencs/view/world/previewsubview.hpp +++ b/apps/opencs/view/world/previewsubview.hpp @@ -29,8 +29,6 @@ namespace CSVWorld private slots: - void closeRequest(); - void referenceableIdChanged (const std::string& id); }; } diff --git a/apps/opencs/view/world/scenesubview.cpp b/apps/opencs/view/world/scenesubview.cpp index d10eebb30..4cb6088cc 100644 --- a/apps/opencs/view/world/scenesubview.cpp +++ b/apps/opencs/view/world/scenesubview.cpp @@ -150,11 +150,6 @@ void CSVWorld::SceneSubView::useHint (const std::string& hint) mScene->useViewHint (hint); } -void CSVWorld::SceneSubView::closeRequest() -{ - deleteLater(); -} - void CSVWorld::SceneSubView::cellSelectionChanged (const CSMWorld::UniversalId& id) { setUniversalId(id); diff --git a/apps/opencs/view/world/scenesubview.hpp b/apps/opencs/view/world/scenesubview.hpp index c0905f0d6..acb7944d8 100644 --- a/apps/opencs/view/world/scenesubview.hpp +++ b/apps/opencs/view/world/scenesubview.hpp @@ -75,8 +75,6 @@ namespace CSVWorld private slots: - void closeRequest(); - void cellSelectionChanged (const CSMWorld::CellSelection& selection); void cellSelectionChanged (const CSMWorld::UniversalId& id); diff --git a/apps/opencs/view/world/scriptsubview.cpp b/apps/opencs/view/world/scriptsubview.cpp index df3fd87be..22d8e7e51 100644 --- a/apps/opencs/view/world/scriptsubview.cpp +++ b/apps/opencs/view/world/scriptsubview.cpp @@ -81,6 +81,6 @@ void CSVWorld::ScriptSubView::rowsAboutToBeRemoved (const QModelIndex& parent, i QModelIndex index = mModel->getModelIndex (getUniversalId().getId(), mColumn); if (!parent.isValid() && index.row()>=start && index.row()<=end) - deleteLater(); + emit closeRequest(); } diff --git a/apps/opencs/view/world/tablesubview.cpp b/apps/opencs/view/world/tablesubview.cpp index 8374da35d..54518023b 100644 --- a/apps/opencs/view/world/tablesubview.cpp +++ b/apps/opencs/view/world/tablesubview.cpp @@ -153,7 +153,3 @@ bool CSVWorld::TableSubView::eventFilter (QObject* object, QEvent* event) return false; } -void CSVWorld::TableSubView::closeRequest() -{ - deleteLater(); -} diff --git a/apps/opencs/view/world/tablesubview.hpp b/apps/opencs/view/world/tablesubview.hpp index ad5f334bf..9d86c32e4 100644 --- a/apps/opencs/view/world/tablesubview.hpp +++ b/apps/opencs/view/world/tablesubview.hpp @@ -63,8 +63,6 @@ namespace CSVWorld void cloneRequest (const CSMWorld::UniversalId& toClone); void createFilterRequest(std::vector< CSMWorld::UniversalId >& types, Qt::DropAction action); - - void closeRequest(); }; }