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 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.
*/
bool isCentralWidgetArea();
bool isCentralWidgetArea() const;
public slots:
/**

View File

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

View File

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

View File

@ -831,31 +831,38 @@ void CDockManager::loadPerspectives(QSettings& Settings)
Settings.endArray();
}
CDockWidget* CDockManager::centralWidget()
//============================================================================
CDockWidget* CDockManager::centralWidget() const
{
return d->CentralWidget;
}
//============================================================================
CDockAreaWidget* CDockManager::setCentralWidget(CDockWidget* widget, CDockWidget* oldCentralWidget, DockWidgetArea oldCentralWidgetArea)
{
oldCentralWidget = d->CentralWidget;
if(oldCentralWidget)
{
addDockWidget(oldCentralWidgetArea, oldCentralWidget);
}
if(widget)
{
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;
}
return nullptr;
//============================================================================
CDockAreaWidget* CDockManager::setCentralWidget(CDockWidget* widget)
{
if (!widget)
{
d->CentralWidget = nullptr;
return nullptr;
}
// Setting a new central widget is now allowed if there is alread a central
// 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.
*/
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
* that will resize with the dock container.
* If a central widget does exist, it will be docked to oldCentralWidgetArea
* and returned in oldCentralWidget.
* that will resize with the dock container. A central widget if not
* movable, floatable or closable and the titlebar of the central
* 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.

View File

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

View File

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

View File

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

View File

@ -361,9 +361,9 @@ public:
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