Skip to content

Commit

Permalink
[api] Add api to allow panel widgets to show a "hamburger" style
Browse files Browse the repository at this point in the history
menu in the top right of the panel

This gives the panel a place to add menu actions like help links
for the panel.
  • Loading branch information
nyalldawson committed Dec 22, 2019
1 parent 16b981c commit d5821fe
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 6 deletions.
1 change: 1 addition & 0 deletions images/images.qrc
Expand Up @@ -809,6 +809,7 @@
<file>themes/default/mActionHandleStoreFilterExpressionUnchecked.svg</file>
<file>themes/default/stacked-bar.svg</file>
<file>themes/default/mIconHtml.svg</file>
<file>themes/default/mIconHamburgerMenu.svg</file>
</qresource>
<qresource prefix="/images/tips">
<file alias="symbol_levels.png">qgis_tips/symbol_levels.png</file>
Expand Down
18 changes: 18 additions & 0 deletions python/gui/auto_generated/qgspanelwidget.sip.in
Expand Up @@ -7,6 +7,7 @@
************************************************************************/



class QgsPanelWidget : QWidget
{
%Docstring
Expand Down Expand Up @@ -104,6 +105,23 @@ widget.
:return: parent panel widget if found, otherwise ``None``

.. versionadded:: 3.0
%End

virtual QString menuButtonTooltip() const;
%Docstring
Returns the (translated) tooltip text to use for the menu button for this panel.

This is only used when the panel returns a menuButtonMenu().

.. versionadded:: 3.12
%End

virtual QMenu *menuButtonMenu();
%Docstring
Returns the menu to use for the menu button for this panel, or ``None`` if
no menu button is required.

.. versionadded:: 3.12
%End

signals:
Expand Down
10 changes: 10 additions & 0 deletions src/gui/qgspanelwidget.cpp
Expand Up @@ -66,6 +66,16 @@ QgsPanelWidget *QgsPanelWidget::findParentPanel( QWidget *widget )
return nullptr;
}

QString QgsPanelWidget::menuButtonTooltip() const
{
return QString();
}

QMenu *QgsPanelWidget::menuButtonMenu()
{
return nullptr;
}

void QgsPanelWidget::openPanel( QgsPanelWidget *panel )
{
//panel dock mode inherits from this panel
Expand Down
19 changes: 19 additions & 0 deletions src/gui/qgspanelwidget.h
Expand Up @@ -20,6 +20,8 @@
#include <QStack>
#include "qgis_gui.h"

class QMenu;

/**
* \ingroup gui
* \brief Base class for any widget that can be shown as a inline panel
Expand Down Expand Up @@ -105,6 +107,23 @@ class GUI_EXPORT QgsPanelWidget : public QWidget
*/
static QgsPanelWidget *findParentPanel( QWidget *widget );

/**
* Returns the (translated) tooltip text to use for the menu button for this panel.
*
* This is only used when the panel returns a menuButtonMenu().
*
* \since QGIS 3.12
*/
virtual QString menuButtonTooltip() const;

/**
* Returns the menu to use for the menu button for this panel, or NULLPTR if
* no menu button is required.
*
* \since QGIS 3.12
*/
virtual QMenu *menuButtonMenu();

signals:

/**
Expand Down
27 changes: 25 additions & 2 deletions src/gui/qgspanelwidgetstack.cpp
Expand Up @@ -29,7 +29,9 @@ QgsPanelWidgetStack::QgsPanelWidgetStack( QWidget *parent )
setupUi( this );
clear();

connect( mBackButton, &QAbstractButton::pressed, this, &QgsPanelWidgetStack::acceptCurrentPanel );
connect( mBackButton, &QAbstractButton::clicked, this, &QgsPanelWidgetStack::acceptCurrentPanel );

mMenuButton->setStyleSheet( QStringLiteral( "QToolButton::menu-indicator { image: none; }" ) );
}

void QgsPanelWidgetStack::setMainPanel( QgsPanelWidget *panel )
Expand Down Expand Up @@ -79,6 +81,7 @@ void QgsPanelWidgetStack::clear()
mTitles.clear();
mTitleText->hide();
mBackButton->hide();
mMenuButton->hide();
this->updateBreadcrumb();
}

Expand Down Expand Up @@ -126,7 +129,8 @@ void QgsPanelWidgetStack::showPanel( QgsPanelWidget *panel )
mBackButton->show();
mTitleText->show();

this->updateBreadcrumb();
updateMenuButton();
updateBreadcrumb();
}

void QgsPanelWidgetStack::closePanel( QgsPanelWidget *panel )
Expand All @@ -143,6 +147,11 @@ void QgsPanelWidgetStack::closePanel( QgsPanelWidget *panel )
{
mBackButton->hide();
mTitleText->hide();
mMenuButton->hide();
}
else
{
updateMenuButton();
}
this->updateBreadcrumb();
}
Expand Down Expand Up @@ -175,3 +184,17 @@ void QgsPanelWidgetStack::updateBreadcrumb()
breadcrumb.chop( 1 );
mTitleText->setText( breadcrumb );
}

void QgsPanelWidgetStack::updateMenuButton()
{
if ( QMenu *menu = currentPanel()->menuButtonMenu() )
{
mMenuButton->setVisible( true );
mMenuButton->setToolTip( currentPanel()->menuButtonTooltip() );
mMenuButton->setMenu( menu );
}
else
{
mMenuButton->setVisible( false );
}
}
1 change: 1 addition & 0 deletions src/gui/qgspanelwidgetstack.h
Expand Up @@ -130,6 +130,7 @@ class GUI_EXPORT QgsPanelWidgetStack : public QWidget, private Ui::QgsRendererWi

private:
void updateBreadcrumb();
void updateMenuButton();
QStack<QString> mTitles;
};

Expand Down
1 change: 1 addition & 0 deletions src/gui/qgsrelationeditorwidget.cpp
Expand Up @@ -39,6 +39,7 @@
#include <QHBoxLayout>
#include <QLabel>
#include <QMessageBox>
#include <QPushButton>

/// @cond PRIVATE
///
Expand Down
3 changes: 0 additions & 3 deletions src/gui/symbology/qgsrendererpropertiesdialog.cpp
Expand Up @@ -316,15 +316,12 @@ void QgsRendererPropertiesDialog::onOK()

void QgsRendererPropertiesDialog::openPanel( QgsPanelWidget *panel )
{
QgsDebugMsg( QStringLiteral( "Open panel!!!" ) );
if ( mDockMode )
{
QgsDebugMsg( QStringLiteral( "DOCK MODE" ) );
emit showPanel( panel );
}
else
{
QgsDebugMsg( QStringLiteral( "DIALOG MODE" ) );
// Show the dialog version if no one is connected
QDialog *dlg = new QDialog();
QString key = QStringLiteral( "/UI/paneldialog/%1" ).arg( panel->panelTitle() );
Expand Down
31 changes: 30 additions & 1 deletion src/ui/styledock/qgsrenderercontainerbase.ui
Expand Up @@ -20,7 +20,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="mBackButton">
<widget class="QToolButton" name="mBackButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
Expand All @@ -40,6 +40,9 @@
<property name="autoRepeat">
<bool>false</bool>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
</widget>
</item>
<item>
Expand All @@ -55,6 +58,32 @@
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="mMenuButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Go back</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset>
<normaloff>:/images/themes/default/mIconHamburgerMenu.svg</normaloff>:/images/themes/default/mIconHamburgerMenu.svg</iconset>
</property>
<property name="autoRepeat">
<bool>false</bool>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand Down

0 comments on commit d5821fe

Please sign in to comment.