Skip to content

Commit 835a532

Browse files
Corrected constness of some functions, changed signatur of setCentralWidget function
1 parent d383ade commit 835a532

10 files changed

+75
-56
lines changed

src/DockAreaWidget.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -968,12 +968,14 @@ CDockAreaTitleBar* CDockAreaWidget::titleBar() const
968968

969969

970970
//============================================================================
971-
bool CDockAreaWidget::isCentralWidgetArea()
971+
bool CDockAreaWidget::isCentralWidgetArea() const
972972
{
973-
if(dockWidgetsCount()!=1)
973+
if (dockWidgetsCount()!= 1)
974+
{
974975
return false;
976+
}
975977

976-
return dockManager()->centralWidget()==dockWidgets()[0];
978+
return dockManager()->centralWidget() == dockWidgets()[0];
977979
}
978980

979981

src/DockAreaWidget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ protected slots:
310310
/**
311311
* Returns true if the area contains the central widget of it's manager.
312312
*/
313-
bool isCentralWidgetArea();
313+
bool isCentralWidgetArea() const;
314314

315315
public slots:
316316
/**

src/DockContainerWidget.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -323,14 +323,15 @@ class DockContainerWidgetPrivate
323323
}
324324

325325
/**
326-
* This finction forces the dock container widget to update handles of splitters
327-
* based on resize modes of dock widgets aontained in the container.
326+
* This function forces the dock container widget to update handles of splitters
327+
* based if a central widget exists.
328328
*/
329329
void updateSplitterHandles(QSplitter* splitter);
330330

331331
/**
332-
* This function returns true if the area is not allowed to resize in the direstion
333-
* of the splitter. Otherwise returns true.
332+
* If no central widget exists, the widgets resize with the container.
333+
* If a central widget exists, the widgets surrounding the central widget
334+
* do not resize its height or width.
334335
*/
335336
bool widgetResizesWithContainer(QWidget* widget);
336337

@@ -711,35 +712,36 @@ void DockContainerWidgetPrivate::moveToNewSection(QWidget* Widget, CDockAreaWidg
711712
//============================================================================
712713
void DockContainerWidgetPrivate::updateSplitterHandles( QSplitter* splitter )
713714
{
714-
if(DockManager->centralWidget())
715+
if (!DockManager->centralWidget() || !splitter)
716+
{
717+
return;
718+
}
719+
720+
for (int i = 0; i < splitter->count(); ++i)
715721
{
716-
if( splitter )
717-
{
718-
for( int index = 0; index < splitter->count(); index++ )
719-
{
720-
splitter->setStretchFactor(index, widgetResizesWithContainer(splitter->widget(index)) ? 1 : 0);
721-
}
722-
}
722+
splitter->setStretchFactor(i, widgetResizesWithContainer(splitter->widget(i)) ? 1 : 0);
723723
}
724724
}
725725

726726

727727
//============================================================================
728728
bool DockContainerWidgetPrivate::widgetResizesWithContainer(QWidget* widget)
729729
{
730-
if(!DockManager->centralWidget())
730+
if (!DockManager->centralWidget())
731+
{
731732
return true;
733+
}
732734

733-
CDockAreaWidget* Area = dynamic_cast< CDockAreaWidget* >( widget );
735+
auto Area = qobject_cast<CDockAreaWidget*>(widget);
734736
if(Area)
735737
{
736738
return Area->isCentralWidgetArea();
737739
}
738740

739-
CDockSplitter* innerSplitter = dynamic_cast< CDockSplitter* >( widget );
740-
if(innerSplitter)
741+
auto innerSplitter = qobject_cast<CDockSplitter*>(widget);
742+
if (innerSplitter)
741743
{
742-
return innerSplitter->resizeWithContainer();
744+
return innerSplitter->isResizingWithContainer();
743745
}
744746

745747
return false;

src/DockContainerWidget.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ class ADS_EXPORT CDockContainerWidget : public QFrame
156156
QList<CDockWidget*> dockWidgets() const;
157157

158158
/**
159-
* This finction forces the dock container widget to update handles of splitters
160-
* based on resize modes of dock widgets aontained in the container.
159+
* This function forces the dock container widget to update handles of splitters
160+
* based on resize modes of dock widgets contained in the container.
161161
*/
162162
void updateSplitterHandles(QSplitter* splitter);
163163

src/DockManager.cpp

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -831,31 +831,38 @@ void CDockManager::loadPerspectives(QSettings& Settings)
831831
Settings.endArray();
832832
}
833833

834-
CDockWidget* CDockManager::centralWidget()
834+
835+
//============================================================================
836+
CDockWidget* CDockManager::centralWidget() const
835837
{
836838
return d->CentralWidget;
837839
}
838840

841+
839842
//============================================================================
840-
CDockAreaWidget* CDockManager::setCentralWidget(CDockWidget* widget, CDockWidget* oldCentralWidget, DockWidgetArea oldCentralWidgetArea)
843+
CDockAreaWidget* CDockManager::setCentralWidget(CDockWidget* widget)
841844
{
842-
oldCentralWidget = d->CentralWidget;
843-
if(oldCentralWidget)
844-
{
845-
addDockWidget(oldCentralWidgetArea, oldCentralWidget);
846-
}
845+
if (!widget)
846+
{
847+
d->CentralWidget = nullptr;
848+
return nullptr;
849+
}
847850

848-
if(widget)
849-
{
850-
widget->setFeature(CDockWidget::DockWidgetClosable, false);
851-
widget->setFeature(CDockWidget::DockWidgetMovable, false);
852-
widget->setFeature(CDockWidget::DockWidgetFloatable, false);
853-
d->CentralWidget = widget;
854-
CDockAreaWidget* CentralArea = addDockWidget(CenterDockWidgetArea, widget);
855-
CentralArea->setDockAreaFlag(CDockAreaWidget::eDockAreaFlag::HideSingleWidgetTitleBar, true);
856-
return CentralArea;
857-
}
858-
return nullptr;
851+
// Setting a new central widget is now allowed if there is alread a central
852+
// widget
853+
if (d->CentralWidget)
854+
{
855+
return nullptr;
856+
}
857+
858+
859+
widget->setFeature(CDockWidget::DockWidgetClosable, false);
860+
widget->setFeature(CDockWidget::DockWidgetMovable, false);
861+
widget->setFeature(CDockWidget::DockWidgetFloatable, false);
862+
d->CentralWidget = widget;
863+
CDockAreaWidget* CentralArea = addDockWidget(CenterDockWidgetArea, widget);
864+
CentralArea->setDockAreaFlag(CDockAreaWidget::eDockAreaFlag::HideSingleWidgetTitleBar, true);
865+
return CentralArea;
859866
}
860867

861868
//============================================================================

src/DockManager.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -381,16 +381,23 @@ class ADS_EXPORT CDockManager : public CDockContainerWidget
381381
/**
382382
* This function returns managers central widget or nullptr if no central widget is set.
383383
*/
384-
CDockWidget* centralWidget();
384+
CDockWidget* centralWidget() const;
385385

386386
/**
387-
* Adds dockwidget into the central area and marks it as central widget.
387+
* Adds dockwidget widget into the central area and marks it as central widget.
388388
* If central widget is set, it will be the only dock widget
389-
* that will resize with the dock container.
390-
* If a central widget does exist, it will be docked to oldCentralWidgetArea
391-
* and returned in oldCentralWidget.
389+
* that will resize with the dock container. A central widget if not
390+
* movable, floatable or closable and the titlebar of the central
391+
* dock area is not visible.
392+
* If the given widget could be set as central widget, the function returns
393+
* the created cok area. If the widget could not be set, because there
394+
* is already a central widget, this function returns a nullptr.
395+
* To clear the central widget, pass a nullptr to the function.
396+
* \retval != 0 The dock area that contains the central widget
397+
* \retval nullptr Indicates that the given widget can not be set as central
398+
* widget because there is already a central widget.
392399
*/
393-
CDockAreaWidget* setCentralWidget(CDockWidget* widget, CDockWidget* oldCentralWidget = nullptr, DockWidgetArea oldCentralWidgetArea = DockWidgetArea::RightDockWidgetArea);
400+
CDockAreaWidget* setCentralWidget(CDockWidget* widget);
394401

395402
/**
396403
* Adds a toggle view action to the the internal view menu.

src/DockSplitter.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,16 @@ QWidget* CDockSplitter::lastWidget() const
103103
}
104104

105105
//============================================================================
106-
bool CDockSplitter::resizeWithContainer()
106+
bool CDockSplitter::isResizingWithContainer() const
107107
{
108-
QList<CDockAreaWidget *> areas = findChildren<CDockAreaWidget *>();
109-
110-
for(int i=0; i<areas.size(); i++)
108+
for (auto area : findChildren<CDockAreaWidget*>())
111109
{
112-
CDockAreaWidget* area = areas.at(i);
113110
if(area->isCentralWidgetArea())
111+
{
114112
return true;
113+
}
115114
}
115+
116116
return false;
117117
}
118118

src/DockSplitter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class ADS_EXPORT CDockSplitter : public QSplitter
7575
/**
7676
* Returns true if the splitter contains central widget of dock manager.
7777
*/
78-
bool resizeWithContainer();
78+
bool isResizingWithContainer() const;
7979
}; // class CDockSplitter
8080

8181
} // namespace ads

src/DockWidget.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,8 @@ void CDockWidget::setMinimumSizeHintMode(eMinimumSizeHintMode Mode)
463463
}
464464

465465

466-
bool CDockWidget::isCentralWidget()
466+
//============================================================================
467+
bool CDockWidget::isCentralWidget() const
467468
{
468469
return dockManager()->centralWidget() == this;
469470
}

src/DockWidget.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,9 @@ private slots:
361361
void setMinimumSizeHintMode(eMinimumSizeHintMode Mode);
362362

363363
/**
364-
* Returns true if the dock wisget is set as central widget of it's dock manager
364+
* Returns true if the dock widget is set as central widget of it's dock manager
365365
*/
366-
bool isCentralWidget();
366+
bool isCentralWidget() const;
367367

368368
/**
369369
* Sets the dock widget icon that is shown in tabs and in toggle view

0 commit comments

Comments
 (0)