Skip to content
Permalink
Browse files

allow to pick the widgets with multiple action in customization

  • Loading branch information
PeterPetrik authored and nyalldawson committed Oct 6, 2020
1 parent 2e94888 commit 982e4eadbd0f540aae35a9a12be062bd01d5fcde
Showing with 22 additions and 1 deletion.
  1. +21 −1 src/app/qgscustomization.cpp
  2. +1 −0 src/app/qgscustomization.h
@@ -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 )
@@ -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();
@@ -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;

0 comments on commit 982e4ea

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