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()
{
QSettings Settings("Settings.ini", QSettings::IniFormat);
/*QSettings Settings("Settings.ini", QSettings::IniFormat);
_this->restoreGeometry(Settings.value("mainWindow/Geometry").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 <QDebug>
#include <QBoxLayout>
#include <QMenu>
#include "FloatingDockContainer.h"
#include "DockAreaWidget.h"
@ -38,6 +39,8 @@ struct DockAreaTabBarPrivate
QWidget* TabsContainerWidget;
QBoxLayout* TabsLayout;
int CurrentIndex = -1;
bool MenuOutdated = true;
QMenu* TabsMenu;
/**
* Private data constructor
@ -102,6 +105,7 @@ void CDockAreaTabBar::wheelEvent(QWheelEvent* Event)
//============================================================================
void CDockAreaTabBar::mousePressEvent(QMouseEvent* ev)
{
std::cout << "CDockAreaTabBar::mousePressEvent" << std::endl;
if (ev->button() == Qt::LeftButton)
{
ev->accept();
@ -252,6 +256,7 @@ void CDockAreaTabBar::insertTab(int Index, CDockWidgetTab* Tab)
{
d->TabsLayout->insertWidget(Index, Tab);
connect(Tab, SIGNAL(clicked()), this, SLOT(onTabClicked()));
d->MenuOutdated = true;
}
@ -260,6 +265,7 @@ void CDockAreaTabBar::removeTab(CDockWidgetTab* Tab)
{
d->TabsLayout->removeWidget(Tab);
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

View File

@ -107,7 +107,7 @@ public slots:
* This function will close the tab given in Index param.
* Closing a tab means, the tab will be hidden, it will not be removed
*/
void closeTabe(int Index);
void closeTab(int Index);
signals:
/**
@ -126,6 +126,12 @@ signals:
* This signal is emitted when user clicks on a tab at an 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
} // namespace ads
//-----------------------------------------------------------------------------

View File

@ -254,8 +254,7 @@ void DockContainerWidgetPrivate::dropIntoSection(CFloatingDockContainer* Floatin
CDockContainerWidget* FloatingContainer = FloatingWidget->dockContainer();
if (area == CenterDockWidgetArea)
{
auto NewDockWidgets = FloatingContainer->findChildren<CDockWidget*>(
QString(), Qt::FindChildrenRecursively);
auto NewDockWidgets = FloatingContainer->dockWidgets();
for (auto DockWidget : NewDockWidgets)
{
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

View File

@ -126,6 +126,16 @@ protected:
*/
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:
/**
* Default Constructor

View File

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

View File

@ -147,6 +147,13 @@ public:
* returns this single dock widget.
*/
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
}
// namespace ads