1
0
mirror of https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git synced 2025-03-16 02:59:51 +08:00

Corrected constness of some functions, changed signatur of setCentralWidget function

This commit is contained in:
Uwe Kindler 2020-08-24 10:22:12 +02:00
parent d383ade03c
commit 835a532e75
10 changed files with 77 additions and 58 deletions

View File

@ -968,12 +968,14 @@ CDockAreaTitleBar* CDockAreaWidget::titleBar() const
//============================================================================ //============================================================================
bool CDockAreaWidget::isCentralWidgetArea() bool CDockAreaWidget::isCentralWidgetArea() const
{ {
if(dockWidgetsCount()!=1) if (dockWidgetsCount()!= 1)
{
return false; return false;
}
return dockManager()->centralWidget()==dockWidgets()[0]; return dockManager()->centralWidget() == dockWidgets()[0];
} }

View File

@ -310,7 +310,7 @@ public:
/** /**
* Returns true if the area contains the central widget of it's manager. * Returns true if the area contains the central widget of it's manager.
*/ */
bool isCentralWidgetArea(); bool isCentralWidgetArea() const;
public slots: public slots:
/** /**

View File

@ -323,14 +323,15 @@ public:
} }
/** /**
* This finction forces the dock container widget to update handles of splitters * This function forces the dock container widget to update handles of splitters
* based on resize modes of dock widgets aontained in the container. * based if a central widget exists.
*/ */
void updateSplitterHandles(QSplitter* splitter); void updateSplitterHandles(QSplitter* splitter);
/** /**
* This function returns true if the area is not allowed to resize in the direstion * If no central widget exists, the widgets resize with the container.
* of the splitter. Otherwise returns true. * If a central widget exists, the widgets surrounding the central widget
* do not resize its height or width.
*/ */
bool widgetResizesWithContainer(QWidget* widget); bool widgetResizesWithContainer(QWidget* widget);
@ -711,15 +712,14 @@ void DockContainerWidgetPrivate::moveToNewSection(QWidget* Widget, CDockAreaWidg
//============================================================================ //============================================================================
void DockContainerWidgetPrivate::updateSplitterHandles( QSplitter* splitter ) void DockContainerWidgetPrivate::updateSplitterHandles( QSplitter* splitter )
{ {
if(DockManager->centralWidget()) if (!DockManager->centralWidget() || !splitter)
{
return;
}
for (int i = 0; i < splitter->count(); ++i)
{ {
if( splitter ) splitter->setStretchFactor(i, widgetResizesWithContainer(splitter->widget(i)) ? 1 : 0);
{
for( int index = 0; index < splitter->count(); index++ )
{
splitter->setStretchFactor(index, widgetResizesWithContainer(splitter->widget(index)) ? 1 : 0);
}
}
} }
} }
@ -727,19 +727,21 @@ void DockContainerWidgetPrivate::updateSplitterHandles( QSplitter* splitter )
//============================================================================ //============================================================================
bool DockContainerWidgetPrivate::widgetResizesWithContainer(QWidget* widget) bool DockContainerWidgetPrivate::widgetResizesWithContainer(QWidget* widget)
{ {
if(!DockManager->centralWidget()) if (!DockManager->centralWidget())
{
return true; return true;
}
CDockAreaWidget* Area = dynamic_cast< CDockAreaWidget* >( widget ); auto Area = qobject_cast<CDockAreaWidget*>(widget);
if(Area) if(Area)
{ {
return Area->isCentralWidgetArea(); return Area->isCentralWidgetArea();
} }
CDockSplitter* innerSplitter = dynamic_cast< CDockSplitter* >( widget ); auto innerSplitter = qobject_cast<CDockSplitter*>(widget);
if(innerSplitter) if (innerSplitter)
{ {
return innerSplitter->resizeWithContainer(); return innerSplitter->isResizingWithContainer();
} }
return false; return false;

View File

@ -156,8 +156,8 @@ protected:
QList<CDockWidget*> dockWidgets() const; QList<CDockWidget*> dockWidgets() const;
/** /**
* This finction forces the dock container widget to update handles of splitters * This function forces the dock container widget to update handles of splitters
* based on resize modes of dock widgets aontained in the container. * based on resize modes of dock widgets contained in the container.
*/ */
void updateSplitterHandles(QSplitter* splitter); void updateSplitterHandles(QSplitter* splitter);

View File

@ -831,31 +831,38 @@ void CDockManager::loadPerspectives(QSettings& Settings)
Settings.endArray(); Settings.endArray();
} }
CDockWidget* CDockManager::centralWidget()
//============================================================================
CDockWidget* CDockManager::centralWidget() const
{ {
return d->CentralWidget; return d->CentralWidget;
} }
//============================================================================
CDockAreaWidget* CDockManager::setCentralWidget(CDockWidget* widget, CDockWidget* oldCentralWidget, DockWidgetArea oldCentralWidgetArea)
{
oldCentralWidget = d->CentralWidget;
if(oldCentralWidget)
{
addDockWidget(oldCentralWidgetArea, oldCentralWidget);
}
if(widget) //============================================================================
{ CDockAreaWidget* CDockManager::setCentralWidget(CDockWidget* widget)
widget->setFeature(CDockWidget::DockWidgetClosable, false); {
widget->setFeature(CDockWidget::DockWidgetMovable, false); if (!widget)
widget->setFeature(CDockWidget::DockWidgetFloatable, false); {
d->CentralWidget = widget; d->CentralWidget = nullptr;
CDockAreaWidget* CentralArea = addDockWidget(CenterDockWidgetArea, widget); return nullptr;
CentralArea->setDockAreaFlag(CDockAreaWidget::eDockAreaFlag::HideSingleWidgetTitleBar, true); }
return CentralArea;
} // Setting a new central widget is now allowed if there is alread a central
return nullptr; // widget
if (d->CentralWidget)
{
return nullptr;
}
widget->setFeature(CDockWidget::DockWidgetClosable, false);
widget->setFeature(CDockWidget::DockWidgetMovable, false);
widget->setFeature(CDockWidget::DockWidgetFloatable, false);
d->CentralWidget = widget;
CDockAreaWidget* CentralArea = addDockWidget(CenterDockWidgetArea, widget);
CentralArea->setDockAreaFlag(CDockAreaWidget::eDockAreaFlag::HideSingleWidgetTitleBar, true);
return CentralArea;
} }
//============================================================================ //============================================================================

View File

@ -381,16 +381,23 @@ public:
/** /**
* This function returns managers central widget or nullptr if no central widget is set. * This function returns managers central widget or nullptr if no central widget is set.
*/ */
CDockWidget* centralWidget(); CDockWidget* centralWidget() const;
/** /**
* Adds dockwidget into the central area and marks it as central widget. * Adds dockwidget widget into the central area and marks it as central widget.
* If central widget is set, it will be the only dock widget * If central widget is set, it will be the only dock widget
* that will resize with the dock container. * that will resize with the dock container. A central widget if not
* If a central widget does exist, it will be docked to oldCentralWidgetArea * movable, floatable or closable and the titlebar of the central
* and returned in oldCentralWidget. * dock area is not visible.
* If the given widget could be set as central widget, the function returns
* the created cok area. If the widget could not be set, because there
* is already a central widget, this function returns a nullptr.
* To clear the central widget, pass a nullptr to the function.
* \retval != 0 The dock area that contains the central widget
* \retval nullptr Indicates that the given widget can not be set as central
* widget because there is already a central widget.
*/ */
CDockAreaWidget* setCentralWidget(CDockWidget* widget, CDockWidget* oldCentralWidget = nullptr, DockWidgetArea oldCentralWidgetArea = DockWidgetArea::RightDockWidgetArea); CDockAreaWidget* setCentralWidget(CDockWidget* widget);
/** /**
* Adds a toggle view action to the the internal view menu. * Adds a toggle view action to the the internal view menu.

View File

@ -103,16 +103,16 @@ QWidget* CDockSplitter::lastWidget() const
} }
//============================================================================ //============================================================================
bool CDockSplitter::resizeWithContainer() bool CDockSplitter::isResizingWithContainer() const
{ {
QList<CDockAreaWidget *> areas = findChildren<CDockAreaWidget *>(); for (auto area : findChildren<CDockAreaWidget*>())
for(int i=0; i<areas.size(); i++)
{ {
CDockAreaWidget* area = areas.at(i);
if(area->isCentralWidgetArea()) if(area->isCentralWidgetArea())
{
return true; return true;
}
} }
return false; return false;
} }

View File

@ -75,7 +75,7 @@ public:
/** /**
* Returns true if the splitter contains central widget of dock manager. * Returns true if the splitter contains central widget of dock manager.
*/ */
bool resizeWithContainer(); bool isResizingWithContainer() const;
}; // class CDockSplitter }; // class CDockSplitter
} // namespace ads } // namespace ads

View File

@ -463,7 +463,8 @@ void CDockWidget::setMinimumSizeHintMode(eMinimumSizeHintMode Mode)
} }
bool CDockWidget::isCentralWidget() //============================================================================
bool CDockWidget::isCentralWidget() const
{ {
return dockManager()->centralWidget() == this; return dockManager()->centralWidget() == this;
} }

View File

@ -361,9 +361,9 @@ public:
void setMinimumSizeHintMode(eMinimumSizeHintMode Mode); void setMinimumSizeHintMode(eMinimumSizeHintMode Mode);
/** /**
* Returns true if the dock wisget is set as central widget of it's dock manager * Returns true if the dock widget is set as central widget of it's dock manager
*/ */
bool isCentralWidget(); bool isCentralWidget() const;
/** /**
* Sets the dock widget icon that is shown in tabs and in toggle view * Sets the dock widget icon that is shown in tabs and in toggle view