Skip to content

Commit

Permalink
Double clicking only expands/contracts history nodes which
Browse files Browse the repository at this point in the history
don't handle double-clicks in another way
  • Loading branch information
nyalldawson committed Apr 26, 2023
1 parent ddef849 commit 29b3919
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
5 changes: 4 additions & 1 deletion python/gui/auto_generated/history/qgshistoryentrynode.sip.in
Expand Up @@ -65,9 +65,12 @@ create the node's content.
.. seealso:: :py:func:`html`
%End

virtual void doubleClicked( const QgsHistoryWidgetContext &context );
virtual bool doubleClicked( const QgsHistoryWidgetContext &context );
%Docstring
Called when the node is double-clicked. The default implementation does nothing.

Returns ``True`` if the node handled the double click event and it should not
be further processed.
%End

virtual void populateContextMenu( QMenu *menu, const QgsHistoryWidgetContext &context );
Expand Down
4 changes: 2 additions & 2 deletions src/gui/history/qgshistoryentrynode.cpp
Expand Up @@ -36,9 +36,9 @@ QWidget *QgsHistoryEntryNode::createWidget( const QgsHistoryWidgetContext & )
return nullptr;
}

void QgsHistoryEntryNode::doubleClicked( const QgsHistoryWidgetContext & )
bool QgsHistoryEntryNode::doubleClicked( const QgsHistoryWidgetContext & )
{

return false;
}

void QgsHistoryEntryNode::populateContextMenu( QMenu *, const QgsHistoryWidgetContext & )
Expand Down
5 changes: 4 additions & 1 deletion src/gui/history/qgshistoryentrynode.h
Expand Up @@ -90,8 +90,11 @@ class GUI_EXPORT QgsHistoryEntryNode

/**
* Called when the node is double-clicked. The default implementation does nothing.
*
* Returns TRUE if the node handled the double click event and it should not
* be further processed.
*/
virtual void doubleClicked( const QgsHistoryWidgetContext &context );
virtual bool doubleClicked( const QgsHistoryWidgetContext &context );

/**
* Allows the node to populate a context \a menu before display to the user.
Expand Down
10 changes: 9 additions & 1 deletion src/gui/history/qgshistorywidget.cpp
Expand Up @@ -40,6 +40,7 @@ QgsHistoryWidget::QgsHistoryWidget( const QString &providerId, Qgis::HistoryProv
connect( mFilterEdit, &QLineEdit::textChanged, mProxyModel, &QgsHistoryEntryProxyModel::setFilter );
connect( mTreeView->selectionModel(), &QItemSelectionModel::currentChanged, this, &QgsHistoryWidget::currentItemChanged );
connect( mTreeView, &QTreeView::doubleClicked, this, &QgsHistoryWidget::nodeDoubleClicked );
mTreeView->setExpandsOnDoubleClick( false );

mTreeView->setContextMenuPolicy( Qt::CustomContextMenu );
connect( mTreeView, &QWidget::customContextMenuRequested, this, &QgsHistoryWidget::showNodeContextMenu );
Expand Down Expand Up @@ -97,8 +98,15 @@ void QgsHistoryWidget::nodeDoubleClicked( const QModelIndex &index )
{
if ( QgsHistoryEntryNode *node = mModel->index2node( mProxyModel->mapToSource( index ) ) )
{
node->doubleClicked( mContext );
if ( node->doubleClicked( mContext ) )
return; // double click handled
}

// otherwise double-clicks expands/collapses the node
if ( mTreeView->isExpanded( index ) )
mTreeView->collapse( index );
else
mTreeView->expand( index );
}

void QgsHistoryWidget::showNodeContextMenu( const QPoint &pos )
Expand Down
5 changes: 3 additions & 2 deletions src/gui/processing/qgsprocessinghistoryprovider.cpp
Expand Up @@ -161,10 +161,10 @@ class ProcessingHistoryNode : public QgsHistoryEntryGroup
return codeEditor;
}

void doubleClicked( const QgsHistoryWidgetContext & ) override
bool doubleClicked( const QgsHistoryWidgetContext & ) override
{
if ( mPythonCommand.isEmpty() )
return;
return true;

QString execAlgorithmDialogCommand = mPythonCommand;
execAlgorithmDialogCommand.replace( QStringLiteral( "processing.run(" ), QStringLiteral( "processing.execAlgorithmDialog(" ) );
Expand All @@ -180,6 +180,7 @@ class ProcessingHistoryNode : public QgsHistoryEntryGroup
};

mProvider->emitExecute( script.join( '\n' ) );
return true;
}

void populateContextMenu( QMenu *menu, const QgsHistoryWidgetContext & ) override
Expand Down

0 comments on commit 29b3919

Please sign in to comment.