Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Partially revert #42365, and make
the new panel sizing behavior opt-in
  • Loading branch information
nyalldawson committed Jun 9, 2021
1 parent 3a4d437 commit 8466988
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 4 deletions.
10 changes: 10 additions & 0 deletions python/gui/auto_generated/qgspanelwidget.sip.in
Expand Up @@ -66,6 +66,16 @@ Set the widget in dock mode which tells the widget to emit panel
widgets and not open dialogs

:param dockMode: ``True`` to enable dock mode.
%End

virtual bool applySizeConstraintsToStack() const;
%Docstring
Returns ``True`` if the size constraints and hints for the panel widget should be
applied to the parent :py:class:`QgsPanelWidgetStack` which this panel is shown in.

The default behavior is to return ``False``.

.. versionadded:: 3.20
%End

bool dockMode();
Expand Down
3 changes: 3 additions & 0 deletions python/gui/auto_generated/qgstemporalcontrollerwidget.sip.in
Expand Up @@ -36,6 +36,9 @@ Returns the temporal controller object used by this object in navigation.
The dock widget retains ownership of the returned object.
%End

virtual bool applySizeConstraintsToStack() const;



protected:

Expand Down
5 changes: 5 additions & 0 deletions src/gui/qgspanelwidget.cpp
Expand Up @@ -46,6 +46,11 @@ void QgsPanelWidget::setDockMode( bool dockMode )
mDockMode = dockMode;
}

bool QgsPanelWidget::applySizeConstraintsToStack() const
{
return false;
}

QgsPanelWidget *QgsPanelWidget::findParentPanel( QWidget *widget )
{
QWidget *p = widget;
Expand Down
10 changes: 10 additions & 0 deletions src/gui/qgspanelwidget.h
Expand Up @@ -74,6 +74,16 @@ class GUI_EXPORT QgsPanelWidget : public QWidget
*/
virtual void setDockMode( bool dockMode );

/**
* Returns TRUE if the size constraints and hints for the panel widget should be
* applied to the parent QgsPanelWidgetStack which this panel is shown in.
*
* The default behavior is to return FALSE.
*
* \since QGIS 3.20
*/
virtual bool applySizeConstraintsToStack() const;

/**
* Returns the dock mode state.
* \returns TRUE if in dock mode. If in dock mode the widget
Expand Down
15 changes: 11 additions & 4 deletions src/gui/qgspanelwidgetstack.cpp
Expand Up @@ -92,15 +92,22 @@ QgsPanelWidget *QgsPanelWidgetStack::currentPanel()

QSize QgsPanelWidgetStack::sizeHint() const
{
if ( QWidget *widget = mStackedWidget->currentWidget() )
return widget->sizeHint();
if ( const QgsPanelWidget *widget = qobject_cast<const QgsPanelWidget *>( mStackedWidget->currentWidget() ) )
{
if ( widget->applySizeConstraintsToStack() )
return widget->sizeHint();
}
return QWidget::sizeHint();
}

QSize QgsPanelWidgetStack::minimumSizeHint() const
{
if ( QWidget *widget = mStackedWidget->currentWidget() )
return widget->minimumSizeHint();
if ( const QgsPanelWidget *widget = qobject_cast<const QgsPanelWidget *>( mStackedWidget->currentWidget() ) )
{
if ( widget->applySizeConstraintsToStack() )
return widget->minimumSizeHint();
}

return QWidget::minimumSizeHint();
}

Expand Down
5 changes: 5 additions & 0 deletions src/gui/qgstemporalcontrollerwidget.cpp
Expand Up @@ -176,6 +176,11 @@ QgsTemporalControllerWidget::QgsTemporalControllerWidget( QWidget *parent )
connect( QgsProject::instance(), &QgsProject::cleared, this, &QgsTemporalControllerWidget::onProjectCleared );
}

bool QgsTemporalControllerWidget::applySizeConstraintsToStack() const
{
return true;
}

void QgsTemporalControllerWidget::keyPressEvent( QKeyEvent *e )
{
if ( mSlider->hasFocus() && e->key() == Qt::Key_Space )
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgstemporalcontrollerwidget.h
Expand Up @@ -53,6 +53,8 @@ class GUI_EXPORT QgsTemporalControllerWidget : public QgsPanelWidget, private Ui
*/
QgsTemporalNavigationObject *temporalController();

bool applySizeConstraintsToStack() const override;

#ifndef SIP_RUN

signals:
Expand Down

0 comments on commit 8466988

Please sign in to comment.