From 87e3777e37181ab91794628a691e3166d8b6e776 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Sun, 2 Dec 2018 12:09:31 +0100 Subject: [PATCH] Fixed hiding and showing of close button for tab group, added support for removing perspectives --- demo/demo.pro | 8 ++++++-- src/DockContainerWidget.cpp | 3 +++ src/DockManager.cpp | 36 +++++++++++++++++++++++++++++++++++- src/DockManager.h | 18 +++++++++++++++++- 4 files changed, 61 insertions(+), 4 deletions(-) diff --git a/demo/demo.pro b/demo/demo.pro index 21fa8db..4ff4b43 100644 --- a/demo/demo.pro +++ b/demo/demo.pro @@ -9,11 +9,15 @@ CONFIG *= c++14 SOURCES += \ main.cpp \ - MainWindow.cpp + MainWindow.cpp \ + mhtabbar.cpp \ + mhtabwidget.cpp HEADERS += \ - MainWindow.h + MainWindow.h \ + mhtabbar.h \ + mhtabwidget.h FORMS += \ mainwindow.ui diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index 8a73147..d86225f 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -261,10 +261,12 @@ void DockContainerWidgetPrivate::onVisibleDockAreaCountChanged() { this->TopLevelDockArea = TopLevelDockArea; TopLevelDockArea->titleBarButton(TitleBarButtonUndock)->setVisible(false || !_this->isFloating()); + TopLevelDockArea->titleBarButton(TitleBarButtonClose)->setVisible(false || !_this->isFloating()); } else if (this->TopLevelDockArea) { this->TopLevelDockArea->titleBarButton(TitleBarButtonUndock)->setVisible(true); + this->TopLevelDockArea->titleBarButton(TitleBarButtonClose)->setVisible(true); this->TopLevelDockArea = nullptr; } } @@ -416,6 +418,7 @@ void DockContainerWidgetPrivate::addDockAreasToList(const QListtitleBarButton(TitleBarButtonUndock)->setVisible(true); + DockArea->titleBarButton(TitleBarButtonClose)->setVisible(true); } // We need to ensure, that the dock area title bar is visible. The title bar diff --git a/src/DockManager.cpp b/src/DockManager.cpp index f03bdef..ee07c64 100644 --- a/src/DockManager.cpp +++ b/src/DockManager.cpp @@ -515,6 +515,7 @@ QByteArray CDockManager::saveState(eXmlMode XmlMode, int version) const //============================================================================ bool CDockManager::restoreState(const QByteArray &state, int version) { + std::cout << "CDockManager::restoreState-----------------------" << std::endl; QElapsedTimer Timer; Timer.start(); @@ -586,12 +587,19 @@ CDockAreaWidget* CDockManager::addDockWidgetTabToArea(CDockWidget* Dockwidget, //============================================================================ -CDockWidget* CDockManager::findDockWidget(const QString& ObjectName) +CDockWidget* CDockManager::findDockWidget(const QString& ObjectName) const { return d->DockWidgetsMap.value(ObjectName, nullptr); } +//============================================================================ +QMap CDockManager::dockWidgetsMap() const +{ + return d->DockWidgetsMap; +} + + //============================================================================ void CDockManager::addPerspective(const QString& UniquePrespectiveName) { @@ -600,6 +608,32 @@ void CDockManager::addPerspective(const QString& UniquePrespectiveName) } +//============================================================================ +void CDockManager::removePerspective(const QString& Name) +{ + if (d->Perspectives.remove(Name)) + { + emit perspectiveListChanged(); + } +} + + +//============================================================================ +void CDockManager::removePerspectives(const QStringList& Names) +{ + int Count = 0; + for (auto Name : Names) + { + Count += d->Perspectives.remove(Name); + } + + if (Count) + { + emit perspectiveListChanged(); + } +} + + //============================================================================ QStringList CDockManager::perspectiveNames() const { diff --git a/src/DockManager.h b/src/DockManager.h index 4f1837f..0eb25d1 100644 --- a/src/DockManager.h +++ b/src/DockManager.h @@ -189,7 +189,13 @@ public: * \return Return the found dock widget or nullptr if a dock widget with the * given name is not registered */ - CDockWidget* findDockWidget(const QString& ObjectName); + CDockWidget* findDockWidget(const QString& ObjectName) const; + + /** + * This function returns a readable reference to the internal dock + * widgets map so that it is possible to iterate over all dock widgets + */ + QMap dockWidgetsMap() const; /** * Returns the list of all active and visible dock containers @@ -237,6 +243,16 @@ public: */ void addPerspective(const QString& UniquePrespectiveName); + /** + * Removes the perspective with the given name from the list of perspectives + */ + void removePerspective(const QString& Name); + + /** + * Removes the given perspectives from the dock manager + */ + void removePerspectives(const QStringList& Names); + /** * Returns the names of all available perspectives */