Skip to content

Commit

Permalink
allow to pick the widgets with multiple action in customization
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterPetrik authored and nyalldawson committed Oct 6, 2020
1 parent 2e94888 commit 982e4ea
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/app/qgscustomization.cpp
Expand Up @@ -440,6 +440,26 @@ QTreeWidgetItem *QgsCustomizationDialog::readWidgetsXmlNode( const QDomNode &nod
return myItem;
}

QAction *QgsCustomizationDialog::findAction( QToolButton *toolbutton )
{
if ( !toolbutton->parent() )
return toolbutton->defaultAction();

// We need to find the QAction that was returned from the call of "QToolBar::addWidget".
// This is a defaultAction in most cases. But when QToolButton is composed of multiple actions,
// (e.g. "Select Features by ..." button) we need to go through the parent widget to search for the
// parent action name.
const QList<QWidgetAction *> tbWidgetActions = toolbutton->parent()->findChildren<QWidgetAction *>( QString(), Qt::FindDirectChildrenOnly );
for ( QWidgetAction *act : tbWidgetActions )
{
QWidget *widget = act->defaultWidget();
if ( widget == toolbutton )
return act;
}

return toolbutton->defaultAction();
}

bool QgsCustomizationDialog::switchWidget( QWidget *widget, QMouseEvent *e )
{
Q_UNUSED( e )
Expand All @@ -465,7 +485,7 @@ bool QgsCustomizationDialog::switchWidget( QWidget *widget, QMouseEvent *e )
else if ( widget->inherits( "QToolButton" ) )
{
QToolButton *toolbutton = qobject_cast<QToolButton *>( widget );
QAction *action = toolbutton->defaultAction();
QAction *action = findAction( toolbutton );
if ( !action )
return false;
QString toolbarName = widget->parent()->objectName();
Expand Down
1 change: 1 addition & 0 deletions src/app/qgscustomization.h
Expand Up @@ -100,6 +100,7 @@ class APP_EXPORT QgsCustomizationDialog : public QMainWindow, private Ui::QgsCus
void init();
QTreeWidgetItem *createTreeItemWidgets();
QTreeWidgetItem *readWidgetsXmlNode( const QDomNode &node );
QAction *findAction( QToolButton *toolbutton );

QString mLastDirSettingsName;
QSettings *mSettings = nullptr;
Expand Down

0 comments on commit 982e4ea

Please sign in to comment.