Skip to content

Commit

Permalink
add logMessage method to locator filter (#7222)
Browse files Browse the repository at this point in the history
to discourage from using Python print()
  • Loading branch information
3nids authored Jun 13, 2018
1 parent 494f7bc commit 3651df0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
13 changes: 13 additions & 0 deletions python/core/auto_generated/locator/qgslocatorfilter.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,19 @@ custom configuration widget.
hasConfigWidget() must return true to indicate that the filter supports configuration.
%End

void logMessage( const QString &message, Qgis::MessageLevel level = Qgis::Info );
%Docstring
Logs a ``message`` to the log panel

.. warning::

in Python, do not use print() method as it might result in crashes
since fetching results does not happen in the main thread.

.. versionadded:: 3.2
%End


signals:

void finished();
Expand Down
6 changes: 6 additions & 0 deletions src/core/locator/qgslocatorfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "qgslocatorfilter.h"
#include "qgsstringutils.h"
#include "qgsfeedback.h"
#include "qgsmessagelog.h"


QgsLocatorFilter::QgsLocatorFilter( QObject *parent )
Expand Down Expand Up @@ -80,3 +81,8 @@ void QgsLocatorFilter::setActivePrefix( const QString &activePrefix )
mActivePrefifx = activePrefix;
}

void QgsLocatorFilter::logMessage( const QString &message, Qgis::MessageLevel level )
{
QgsMessageLog::logMessage( QString( "%1: %2" ).arg( name(), message ), QStringLiteral( "Locator bar" ), level );
}

9 changes: 9 additions & 0 deletions src/core/locator/qgslocatorfilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,15 @@ class CORE_EXPORT QgsLocatorFilter : public QObject
*/
virtual void openConfigWidget( QWidget *parent = nullptr );

/**
* Logs a \a message to the log panel
* \warning in Python, do not use print() method as it might result in crashes
* since fetching results does not happen in the main thread.
* \since QGIS 3.2
*/
void logMessage( const QString &message, Qgis::MessageLevel level = Qgis::Info );


signals:

/**
Expand Down

0 comments on commit 3651df0

Please sign in to comment.