Skip to content

Commit

Permalink
Rename Qgis::MessageLevel::None to NoLevel. None is a reserved
Browse files Browse the repository at this point in the history
keyword in Python, so this value was previously inaccessible to PyQGIS
scripts

Also change all references to Qgis::MessageLevel values to their
fully qualified names, to ease a future transition to an enum
class (when sip bugs are fixed)

Fixes #42996
  • Loading branch information
nyalldawson committed May 30, 2021
1 parent 4e73dd9 commit 02266ef
Show file tree
Hide file tree
Showing 155 changed files with 673 additions and 671 deletions.
1 change: 1 addition & 0 deletions python/core/auto_additions/qgis.py
Expand Up @@ -17,6 +17,7 @@
QgsMapLayer.PointCloudLayer.__doc__ = "Added in 3.18"
QgsMapLayerType.__doc__ = 'Types of layers that can be added to a map\n\n.. versionadded:: 3.8\n\n' + '* ``VectorLayer``: ' + QgsMapLayerType.VectorLayer.__doc__ + '\n' + '* ``RasterLayer``: ' + QgsMapLayerType.RasterLayer.__doc__ + '\n' + '* ``PluginLayer``: ' + QgsMapLayerType.PluginLayer.__doc__ + '\n' + '* ``MeshLayer``: ' + QgsMapLayerType.MeshLayer.__doc__ + '\n' + '* ``VectorTileLayer``: ' + QgsMapLayerType.VectorTileLayer.__doc__ + '\n' + '* ``AnnotationLayer``: ' + QgsMapLayerType.AnnotationLayer.__doc__ + '\n' + '* ``PointCloudLayer``: ' + QgsMapLayerType.PointCloudLayer.__doc__
# --
Qgis.MessageLevel.baseClass = Qgis
# monkey patching scoped based enum
Qgis.UnknownDataType = Qgis.DataType.UnknownDataType
Qgis.UnknownDataType.__doc__ = "Unknown or unspecified type"
Expand Down
Expand Up @@ -324,7 +324,7 @@ displays.

signals:

void messageEmitted( const QString &message, Qgis::MessageLevel level = Qgis::Info, int duration = 5 );
void messageEmitted( const QString &message, Qgis::MessageLevel level = Qgis::MessageLevel::Info, int duration = 5 );
%Docstring
Emits a message than can be displayed to the user in a GUI class

Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/locator/qgslocatorfilter.sip.in
Expand Up @@ -310,7 +310,7 @@ custom configuration widget.
:py:func:`~QgsLocatorFilter.hasConfigWidget` must return ``True`` to indicate that the filter supports configuration.
%End

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

Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/qgis.sip.in
Expand Up @@ -81,7 +81,7 @@ The development version
Warning,
Critical,
Success,
None,
NoLevel,
};

enum class DataType
Expand Down
6 changes: 3 additions & 3 deletions python/core/auto_generated/qgsmessagelog.sip.in
Expand Up @@ -35,7 +35,7 @@ window for the user.
Constructor for QgsMessageLog.
%End

static void logMessage( const QString &message, const QString &tag = QString(), Qgis::MessageLevel level = Qgis::Warning, bool notifyUser = true );
static void logMessage( const QString &message, const QString &tag = QString(), Qgis::MessageLevel level = Qgis::MessageLevel::Warning, bool notifyUser = true );
%Docstring
Adds a ``message`` to the log instance (and creates it if necessary).

Expand All @@ -57,7 +57,7 @@ value for the message.

void messageReceived( bool received );
%Docstring
Emitted whenever the log receives a message which is not a Qgis.Info level message
Emitted whenever the log receives a message which is not a Qgis.MessageLevel.Info level message
and which has the ``notifyUser`` flag as ``True``.

If :py:class:`QgsMessageLogNotifyBlocker` objects have been created then this signal may be
Expand Down Expand Up @@ -124,7 +124,7 @@ Constructor for QgsMessageLogConsole.

protected:

QString formatLogMessage( const QString &message, const QString &tag, Qgis::MessageLevel level = Qgis::Info ) const;
QString formatLogMessage( const QString &message, const QString &tag, Qgis::MessageLevel level = Qgis::MessageLevel::Info ) const;
%Docstring
Formats a log message. Used by child classes.

Expand Down
4 changes: 2 additions & 2 deletions python/core/auto_generated/qgsreadwritecontext.sip.in
Expand Up @@ -25,7 +25,7 @@ The class is used as a container of context for various read/write operations on

struct ReadWriteMessage
{
ReadWriteMessage( const QString &message = QString(), Qgis::MessageLevel level = Qgis::Warning, const QStringList &categories = QStringList() );
ReadWriteMessage( const QString &message = QString(), Qgis::MessageLevel level = Qgis::MessageLevel::Warning, const QStringList &categories = QStringList() );
%Docstring
Construct a container for QgsReadWriteContext error or warning messages
%End
Expand Down Expand Up @@ -74,7 +74,7 @@ Returns path resolver for conversion between relative and absolute paths
Sets up path resolver for conversion between relative and absolute paths
%End

void pushMessage( const QString &message, Qgis::MessageLevel level = Qgis::Warning ) const;
void pushMessage( const QString &message, Qgis::MessageLevel level = Qgis::MessageLevel::Warning ) const;
%Docstring
Append a message to the context

Expand Down
Expand Up @@ -148,7 +148,7 @@ Sets the message ``bar`` associated with the scene.
.. seealso:: :py:func:`messageBar`
%End

void showWarning( const QString &shortMessage, const QString &title, const QString &longMessage, Qgis::MessageLevel level = Qgis::Warning ) const;
void showWarning( const QString &shortMessage, const QString &title, const QString &longMessage, Qgis::MessageLevel level = Qgis::MessageLevel::Warning ) const;
%Docstring
Shows a warning message, allowing users to click a button to see the full details (``longMessage``).
%End
Expand Down
2 changes: 1 addition & 1 deletion python/gui/auto_generated/qgsdataitemguiprovider.sip.in
Expand Up @@ -158,7 +158,7 @@ The function is replacement of :py:func:`QgsDataItem.paramWidget()`
.. versionadded:: 3.10
%End

static void notify( const QString &title, const QString &message, QgsDataItemGuiContext context, Qgis::MessageLevel level = Qgis::Info, int duration = -1, QWidget *parent = 0 );
static void notify( const QString &title, const QString &message, QgsDataItemGuiContext context, Qgis::MessageLevel level = Qgis::MessageLevel::Info, int duration = -1, QWidget *parent = 0 );
%Docstring
Notify the user showing a ``message`` with ``title`` and ``level``
If the context has a message bar the message will be shown in the message bar
Expand Down
2 changes: 1 addition & 1 deletion python/gui/auto_generated/qgsmapcanvas.sip.in
Expand Up @@ -1220,7 +1220,7 @@ Emitted when the canvas has been assigned a different map theme.
.. versionadded:: 3.0
%End

void messageEmitted( const QString &title, const QString &message, Qgis::MessageLevel = Qgis::Info );
void messageEmitted( const QString &title, const QString &message, Qgis::MessageLevel = Qgis::MessageLevel::Info );
%Docstring
emit a message (usually to be displayed in a message bar)
%End
Expand Down
2 changes: 1 addition & 1 deletion python/gui/auto_generated/qgsmaptool.sip.in
Expand Up @@ -239,7 +239,7 @@ The default implementation does nothing and returns false.
%End

signals:
void messageEmitted( const QString &message, Qgis::MessageLevel = Qgis::Info );
void messageEmitted( const QString &message, Qgis::MessageLevel = Qgis::MessageLevel::Info );
%Docstring
emit a message
%End
Expand Down
12 changes: 6 additions & 6 deletions python/gui/auto_generated/qgsmessagebar.sip.in
Expand Up @@ -50,13 +50,13 @@ and putting it in a stack.
The message bar will take ownership of ``item``.
%End

QgsMessageBarItem *pushWidget( QWidget *widget /Transfer/, Qgis::MessageLevel level = Qgis::Info, int duration = 0 );
QgsMessageBarItem *pushWidget( QWidget *widget /Transfer/, Qgis::MessageLevel level = Qgis::MessageLevel::Info, int duration = 0 );
%Docstring
Display a ``widget`` as a message on the bar, after hiding the currently visible one
and putting it in a stack.

:param widget: message widget to display
:param level: is Qgis.Info, Warning, Critical or Success
:param level: is Qgis.MessageLevel.Info, Warning, Critical or Success
:param duration: timeout duration of message in seconds, 0 value indicates no timeout (i.e.
the message must be manually cleared by the user).
%End
Expand Down Expand Up @@ -107,7 +107,7 @@ The caller takes ownership of the returned item.
instead.
%End

void pushMessage( const QString &text, Qgis::MessageLevel level = Qgis::Info, int duration = -1 );
void pushMessage( const QString &text, Qgis::MessageLevel level = Qgis::MessageLevel::Info, int duration = -1 );
%Docstring
A convenience method for pushing a message with the specified ``text`` to the bar.

Expand All @@ -119,7 +119,7 @@ is set to 0, then the message must be manually dismissed by the user. Since QGIS
the default timeout for the message ``level`` should be used.
%End

void pushMessage( const QString &title, const QString &text, Qgis::MessageLevel level = Qgis::Info, int duration = -1 );
void pushMessage( const QString &title, const QString &text, Qgis::MessageLevel level = Qgis::MessageLevel::Info, int duration = -1 );
%Docstring
A convenience method for pushing a message with the specified ``title`` and ``text`` to the bar.

Expand All @@ -131,7 +131,7 @@ is set to 0, then the message must be manually dismissed by the user. Since QGIS
the default timeout for the message ``level`` should be used.
%End

void pushMessage( const QString &title, const QString &text, const QString &showMore, Qgis::MessageLevel level = Qgis::Info, int duration = -1 );
void pushMessage( const QString &title, const QString &text, const QString &showMore, Qgis::MessageLevel level = Qgis::MessageLevel::Info, int duration = -1 );
%Docstring
A convenience method for pushing a message with the specified ``title`` and ``text`` to the bar. Additional
message content specified via ``showMore`` will be shown when the user presses a "more" button.
Expand All @@ -156,7 +156,7 @@ Returns a list of all items currently visible or queued for the bar.
.. versionadded:: 3.14
%End

static int defaultMessageTimeout( Qgis::MessageLevel level = Qgis::None );
static int defaultMessageTimeout( Qgis::MessageLevel level = Qgis::MessageLevel::NoLevel );
%Docstring
Returns the default timeout in seconds for timed messages of the specified ``level``.

Expand Down
8 changes: 4 additions & 4 deletions python/gui/auto_generated/qgsmessagebaritem.sip.in
Expand Up @@ -23,7 +23,7 @@ Represents an item shown within a :py:class:`QgsMessageBar` widget.
%End
public:

QgsMessageBarItem( const QString &text, Qgis::MessageLevel level = Qgis::Info, int duration = 0, QWidget *parent /TransferThis/ = 0 );
QgsMessageBarItem( const QString &text, Qgis::MessageLevel level = Qgis::MessageLevel::Info, int duration = 0, QWidget *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsMessageBarItem, containing a message with the specified ``text`` to be displayed on the bar.

Expand All @@ -35,7 +35,7 @@ is set to 0, then the message must be manually dismissed by the user. Since QGIS
the default timeout for the message ``level`` should be used.
%End

QgsMessageBarItem( const QString &title, const QString &text, Qgis::MessageLevel level = Qgis::Info, int duration = 0, QWidget *parent /TransferThis/ = 0 );
QgsMessageBarItem( const QString &title, const QString &text, Qgis::MessageLevel level = Qgis::MessageLevel::Info, int duration = 0, QWidget *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsMessageBarItem, containing a ``title`` and message with the specified ``text`` to be displayed on the bar.

Expand All @@ -47,7 +47,7 @@ is set to 0, then the message must be manually dismissed by the user. Since QGIS
the default timeout for the message ``level`` should be used.
%End

QgsMessageBarItem( const QString &title, const QString &text, QWidget *widget, Qgis::MessageLevel level = Qgis::Info, int duration = 0, QWidget *parent /TransferThis/ = 0 );
QgsMessageBarItem( const QString &title, const QString &text, QWidget *widget, Qgis::MessageLevel level = Qgis::MessageLevel::Info, int duration = 0, QWidget *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsMessageBarItem, containing a ``title``, message with the specified ``text``, and a custom ``widget`` to be displayed on the bar.

Expand All @@ -59,7 +59,7 @@ is set to 0, then the message must be manually dismissed by the user. Since QGIS
the default timeout for the message ``level`` should be used.
%End

QgsMessageBarItem( QWidget *widget, Qgis::MessageLevel level = Qgis::Info, int duration = 0, QWidget *parent /TransferThis/ = 0 );
QgsMessageBarItem( QWidget *widget, Qgis::MessageLevel level = Qgis::MessageLevel::Info, int duration = 0, QWidget *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsMessageBarItem, containing a custom ``widget`` to be displayed on the bar.

Expand Down
2 changes: 1 addition & 1 deletion python/gui/auto_generated/qgspluginmanagerinterface.sip.in
Expand Up @@ -57,7 +57,7 @@ add repository to the repository listWidget
show the Plugin Manager window and optionally open tab tabIndex
%End

virtual void pushMessage( const QString &text, Qgis::MessageLevel level = Qgis::Info, int duration = -1 ) = 0;
virtual void pushMessage( const QString &text, Qgis::MessageLevel level = Qgis::MessageLevel::Info, int duration = -1 ) = 0;
%Docstring
show the given message in the Plugin Manager internal message bar
%End
Expand Down
2 changes: 1 addition & 1 deletion python/server/auto_generated/qgsserversettings.sip.in
Expand Up @@ -131,7 +131,7 @@ Returns ``True`` if profile information has to be added to the logs, default val

.. note::

this flag is only effective when :py:func:`~QgsServerSettings.logLevel` returns Qgis.Info (0)
this flag is only effective when :py:func:`~QgsServerSettings.logLevel` returns Qgis.MessageLevel.Info (0)

.. seealso:: :py:func:`logLevel`

Expand Down
2 changes: 1 addition & 1 deletion src/analysis/processing/qgsalgorithmbuffer.cpp
Expand Up @@ -140,7 +140,7 @@ QVariantMap QgsBufferAlgorithm::processAlgorithm( const QVariantMap &parameters,
QgsGeometry outputGeometry = f.geometry().buffer( distance, segments, endCapStyle, joinStyle, miterLimit );
if ( outputGeometry.isNull() )
{
QgsMessageLog::logMessage( QObject::tr( "Error calculating buffer for feature %1" ).arg( f.id() ), QObject::tr( "Processing" ), Qgis::Warning );
QgsMessageLog::logMessage( QObject::tr( "Error calculating buffer for feature %1" ).arg( f.id() ), QObject::tr( "Processing" ), Qgis::MessageLevel::Warning );
}
if ( dissolve )
bufferedGeometriesForDissolve << outputGeometry;
Expand Down
4 changes: 2 additions & 2 deletions src/analysis/raster/qgsninecellfilter.cpp
Expand Up @@ -60,15 +60,15 @@ int QgsNineCellFilter::processRaster( QgsFeedback *feedback )
catch ( cl::Error &e )
{
QString err = QObject::tr( "Error running OpenCL program: %1 - %2" ).arg( e.what( ), QgsOpenClUtils::errorText( e.err( ) ) );
QgsMessageLog::logMessage( err, QgsOpenClUtils::LOGMESSAGE_TAG, Qgis::Critical );
QgsMessageLog::logMessage( err, QgsOpenClUtils::LOGMESSAGE_TAG, Qgis::MessageLevel::Critical );
throw QgsProcessingException( err );
}
}
else
{
QString err = QObject::tr( "Error loading OpenCL program sources" );
QgsMessageLog::logMessage( err,
QgsOpenClUtils::LOGMESSAGE_TAG, Qgis::Critical );
QgsOpenClUtils::LOGMESSAGE_TAG, Qgis::MessageLevel::Critical );
throw QgsProcessingException( err );
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/3d/qgs3dmapconfigwidget.cpp
Expand Up @@ -452,15 +452,15 @@ void Qgs3DMapConfigWidget::validate()
if ( ! cboTerrainLayer->currentLayer() )
{
valid = false;
mMessageBar->pushMessage( tr( "An elevation layer must be selected for a DEM terrain" ), Qgis::Critical );
mMessageBar->pushMessage( tr( "An elevation layer must be selected for a DEM terrain" ), Qgis::MessageLevel::Critical );
}
break;

case QgsTerrainGenerator::Mesh:
if ( ! cboTerrainLayer->currentLayer() )
{
valid = false;
mMessageBar->pushMessage( tr( "An elevation layer must be selected for a mesh terrain" ), Qgis::Critical );
mMessageBar->pushMessage( tr( "An elevation layer must be selected for a mesh terrain" ), Qgis::MessageLevel::Critical );
}
break;

Expand All @@ -471,7 +471,7 @@ void Qgs3DMapConfigWidget::validate()

if ( valid && widgetLights->directionalLights().empty() && widgetLights->pointLights().empty() )
{
mMessageBar->pushMessage( tr( "No lights exist in the scene" ), Qgis::Warning );
mMessageBar->pushMessage( tr( "No lights exist in the scene" ), Qgis::MessageLevel::Warning );
}

emit isValidChanged( valid );
Expand Down
8 changes: 4 additions & 4 deletions src/app/dwg/qgsdwgimportdialog.cpp
Expand Up @@ -93,7 +93,7 @@ QgsDwgImportDialog::QgsDwgImportDialog( QWidget *parent, Qt::WindowFlags f )

if ( ! QgsVectorFileWriter::supportedFormatExtensions().contains( QStringLiteral( "gpkg" ) ) )
{
bar->pushMessage( tr( "GDAL/OGR not built with GPKG (sqlite3) support. You will not be able to export the DWG in a GPKG." ), Qgis::Critical );
bar->pushMessage( tr( "GDAL/OGR not built with GPKG (sqlite3) support. You will not be able to export the DWG in a GPKG." ), Qgis::MessageLevel::Critical );
}
pbLoadDatabase_clicked();
updateUI();
Expand Down Expand Up @@ -233,7 +233,7 @@ void QgsDwgImportDialog::pbLoadDatabase_clicked()
}
else
{
bar->pushMessage( tr( "Could not open layer list" ), Qgis::Critical );
bar->pushMessage( tr( "Could not open layer list" ), Qgis::MessageLevel::Critical );
}
}

Expand All @@ -260,11 +260,11 @@ void QgsDwgImportDialog::pbImportDrawing_clicked()
QString error;
if ( importer.import( leDrawing->text(), error, cbExpandInserts->isChecked(), cbUseCurves->isChecked(), lblMessage ) )
{
bar->pushMessage( tr( "Drawing import completed." ), Qgis::Info );
bar->pushMessage( tr( "Drawing import completed." ), Qgis::MessageLevel::Info );
}
else
{
bar->pushMessage( tr( "Drawing import failed (%1)" ).arg( error ), Qgis::Critical );
bar->pushMessage( tr( "Drawing import failed (%1)" ).arg( error ), Qgis::MessageLevel::Critical );
}

pbLoadDatabase_clicked();
Expand Down

0 comments on commit 02266ef

Please sign in to comment.