Skip to content
Permalink
Browse files

[api] Add api to allow panel widgets to show a "hamburger" style

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 d5821feb9f156d1f01d43eacfdcfb3975b6ca655
@@ -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>
@@ -7,6 +7,7 @@
************************************************************************/



class QgsPanelWidget : QWidget
{
%Docstring
@@ -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:
@@ -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
@@ -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
@@ -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:

/**
@@ -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 )
@@ -79,6 +81,7 @@ void QgsPanelWidgetStack::clear()
mTitles.clear();
mTitleText->hide();
mBackButton->hide();
mMenuButton->hide();
this->updateBreadcrumb();
}

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

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

void QgsPanelWidgetStack::closePanel( QgsPanelWidget *panel )
@@ -143,6 +147,11 @@ void QgsPanelWidgetStack::closePanel( QgsPanelWidget *panel )
{
mBackButton->hide();
mTitleText->hide();
mMenuButton->hide();
}
else
{
updateMenuButton();
}
this->updateBreadcrumb();
}
@@ -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 );
}
}
@@ -130,6 +130,7 @@ class GUI_EXPORT QgsPanelWidgetStack : public QWidget, private Ui::QgsRendererWi

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

@@ -39,6 +39,7 @@
#include <QHBoxLayout>
#include <QLabel>
#include <QMessageBox>
#include <QPushButton>

/// @cond PRIVATE
///
@@ -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() );
@@ -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>
@@ -40,6 +40,9 @@
<property name="autoRepeat">
<bool>false</bool>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
</widget>
</item>
<item>
@@ -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>

0 comments on commit d5821fe

Please sign in to comment.
You can’t perform that action at this time.