Added dockWidgets() function to DockContainerWidget.h because invisible dock widgets are no children of a dock area and therefore FindChildrenRecursively() does not work

This commit is contained in:
Uwe Kindler 2018-10-11 08:54:32 +02:00
parent 272bbe275e
commit b3b6d20d96
7 changed files with 59 additions and 7 deletions

View File

@ -235,10 +235,10 @@ void MainWindowPrivate::saveState()
//============================================================================ //============================================================================
void MainWindowPrivate::restoreState() void MainWindowPrivate::restoreState()
{ {
QSettings Settings("Settings.ini", QSettings::IniFormat); /*QSettings Settings("Settings.ini", QSettings::IniFormat);
_this->restoreGeometry(Settings.value("mainWindow/Geometry").toByteArray()); _this->restoreGeometry(Settings.value("mainWindow/Geometry").toByteArray());
_this->restoreState(Settings.value("mainWindow/State").toByteArray()); _this->restoreState(Settings.value("mainWindow/State").toByteArray());
DockManager->restoreState(Settings.value("mainWindow/DockingState").toByteArray()); DockManager->restoreState(Settings.value("mainWindow/DockingState").toByteArray());*/
} }

View File

@ -14,6 +14,7 @@
#include <QScrollBar> #include <QScrollBar>
#include <QDebug> #include <QDebug>
#include <QBoxLayout> #include <QBoxLayout>
#include <QMenu>
#include "FloatingDockContainer.h" #include "FloatingDockContainer.h"
#include "DockAreaWidget.h" #include "DockAreaWidget.h"
@ -38,6 +39,8 @@ struct DockAreaTabBarPrivate
QWidget* TabsContainerWidget; QWidget* TabsContainerWidget;
QBoxLayout* TabsLayout; QBoxLayout* TabsLayout;
int CurrentIndex = -1; int CurrentIndex = -1;
bool MenuOutdated = true;
QMenu* TabsMenu;
/** /**
* Private data constructor * Private data constructor
@ -102,6 +105,7 @@ void CDockAreaTabBar::wheelEvent(QWheelEvent* Event)
//============================================================================ //============================================================================
void CDockAreaTabBar::mousePressEvent(QMouseEvent* ev) void CDockAreaTabBar::mousePressEvent(QMouseEvent* ev)
{ {
std::cout << "CDockAreaTabBar::mousePressEvent" << std::endl;
if (ev->button() == Qt::LeftButton) if (ev->button() == Qt::LeftButton)
{ {
ev->accept(); ev->accept();
@ -252,6 +256,7 @@ void CDockAreaTabBar::insertTab(int Index, CDockWidgetTab* Tab)
{ {
d->TabsLayout->insertWidget(Index, Tab); d->TabsLayout->insertWidget(Index, Tab);
connect(Tab, SIGNAL(clicked()), this, SLOT(onTabClicked())); connect(Tab, SIGNAL(clicked()), this, SLOT(onTabClicked()));
d->MenuOutdated = true;
} }
@ -260,6 +265,7 @@ void CDockAreaTabBar::removeTab(CDockWidgetTab* Tab)
{ {
d->TabsLayout->removeWidget(Tab); d->TabsLayout->removeWidget(Tab);
disconnect(Tab, SIGNAL(clicked()), this, SLOT(onTabClicked())); disconnect(Tab, SIGNAL(clicked()), this, SLOT(onTabClicked()));
d->MenuOutdated = true;
} }
@ -293,9 +299,14 @@ void CDockAreaTabBar::onTabClicked()
} }
void CDockAreaTabBar::closeTabe(int Index) //===========================================================================
void CDockAreaTabBar::closeTab(int Index)
{ {
if (Index < 0 || Index >= d->TabsLayout->count())
{
return;
}
emit tabCloseRequested(Index);
} }
} // namespace ads } // namespace ads

View File

@ -107,7 +107,7 @@ public slots:
* This function will close the tab given in Index param. * This function will close the tab given in Index param.
* Closing a tab means, the tab will be hidden, it will not be removed * Closing a tab means, the tab will be hidden, it will not be removed
*/ */
void closeTabe(int Index); void closeTab(int Index);
signals: signals:
/** /**
@ -126,6 +126,12 @@ signals:
* This signal is emitted when user clicks on a tab at an index. * This signal is emitted when user clicks on a tab at an index.
*/ */
void tabBarClicked(int index); void tabBarClicked(int index);
/**
* This signal is emitted when the close button on a tab is clicked.
* The index is the index that should be closed.
*/
void tabCloseRequested(int index);
}; // class CDockAreaTabBar }; // class CDockAreaTabBar
} // namespace ads } // namespace ads
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@ -254,8 +254,7 @@ void DockContainerWidgetPrivate::dropIntoSection(CFloatingDockContainer* Floatin
CDockContainerWidget* FloatingContainer = FloatingWidget->dockContainer(); CDockContainerWidget* FloatingContainer = FloatingWidget->dockContainer();
if (area == CenterDockWidgetArea) if (area == CenterDockWidgetArea)
{ {
auto NewDockWidgets = FloatingContainer->findChildren<CDockWidget*>( auto NewDockWidgets = FloatingContainer->dockWidgets();
QString(), Qt::FindChildrenRecursively);
for (auto DockWidget : NewDockWidgets) for (auto DockWidget : NewDockWidgets)
{ {
TargetArea->insertDockWidget(0, DockWidget, false); TargetArea->insertDockWidget(0, DockWidget, false);
@ -1141,6 +1140,19 @@ CDockWidget* CDockContainerWidget::topLevelDockWidget() const
} }
//============================================================================
QList<CDockWidget*> CDockContainerWidget::dockWidgets() const
{
QList<CDockWidget*> Result;
for (const auto DockArea : d->DockAreas)
{
Result.append(DockArea->dockWidgets());
}
return Result;
}
} // namespace ads } // namespace ads

View File

@ -126,6 +126,16 @@ protected:
*/ */
CDockWidget* topLevelDockWidget() const; CDockWidget* topLevelDockWidget() const;
/**
* This function returns a list of all dock widgets in this floating widget.
* It may be possible, depending on the implementation, that dock widgets,
* that are not visible to the user have no parent widget. Therefore simply
* calling findChildren() would not work here. Therefore this function
* iterates over all dock areas and creates a list that contains all
* dock widgets returned from all dock areas.
*/
QList<CDockWidget*> dockWidgets() const;
public: public:
/** /**
* Default Constructor * Default Constructor

View File

@ -533,6 +533,12 @@ CDockWidget* CFloatingDockContainer::topLevelDockWidget() const
return d->DockContainer->topLevelDockWidget(); return d->DockContainer->topLevelDockWidget();
} }
//============================================================================
QList<CDockWidget*> CFloatingDockContainer::dockWidgets() const
{
return d->DockContainer->dockWidgets();
}
} // namespace ads } // namespace ads

View File

@ -147,6 +147,13 @@ public:
* returns this single dock widget. * returns this single dock widget.
*/ */
CDockWidget* topLevelDockWidget() const; CDockWidget* topLevelDockWidget() const;
/**
* This function returns a list of all dock widget in this floating widget.
* This is a simple convenience function that simply calls the dockWidgets()
* function of the internal container widget.
*/
QList<CDockWidget*> dockWidgets() const;
}; // class FloatingDockContainer }; // class FloatingDockContainer
} }
// namespace ads // namespace ads