Skip to content

Commit

Permalink
Make it easier to use the correct timeout for messages in message bars,
Browse files Browse the repository at this point in the history
and ensure that correct timeouts are used for all created messages
  • Loading branch information
nyalldawson committed Nov 21, 2020
1 parent b010d88 commit 13951b2
Show file tree
Hide file tree
Showing 44 changed files with 287 additions and 307 deletions.
22 changes: 16 additions & 6 deletions python/gui/auto_generated/qgsmessagebar.sip.in
Expand Up @@ -107,29 +107,31 @@ The caller takes ownership of the returned item.
instead.
%End

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

The ``level`` argument specifies the desired message level (severity) of the message, which controls
how the message bar is styled.

The optional ``duration`` argument can be used to specify the message timeout in seconds. If ``duration``
is set to 0, then the message must be manually dismissed by the user.
is set to 0, then the message must be manually dismissed by the user. Since QGIS 3.18, a duration of -1 indicates that
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 = 5 );
void pushMessage( const QString &title, const QString &text, Qgis::MessageLevel level = Qgis::Info, int duration = -1 );
%Docstring
A convenience method for pushing a message with the specified ``title`` and ``text`` to the bar.

The ``level`` argument specifies the desired message level (severity) of the message, which controls
how the message bar is styled.

The optional ``duration`` argument can be used to specify the message timeout in seconds. If ``duration``
is set to 0, then the message must be manually dismissed by the user.
is set to 0, then the message must be manually dismissed by the user. Since QGIS 3.18, a duration of -1 indicates that
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 = 5 );
void pushMessage( const QString &title, const QString &text, const QString &showMore, Qgis::MessageLevel level = Qgis::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 @@ -138,7 +140,8 @@ The ``level`` argument specifies the desired message level (severity) of the mes
how the message bar is styled.

The optional ``duration`` argument can be used to specify the message timeout in seconds. If ``duration``
is set to 0, then the message must be manually dismissed by the user.
is set to 0, then the message must be manually dismissed by the user. Since QGIS 3.18, a duration of -1 indicates that
the default timeout for the message ``level`` should be used.
%End

QgsMessageBarItem *currentItem();
Expand All @@ -151,6 +154,13 @@ Returns the current visible item, or ``None`` if no item is shown.
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 );
%Docstring
Returns the default timeout in seconds for timed messages of the specified ``level``.

.. versionadded:: 3.18
%End

signals:
Expand Down
12 changes: 8 additions & 4 deletions python/gui/auto_generated/qgsmessagebaritem.sip.in
Expand Up @@ -31,7 +31,8 @@ The ``level`` argument specifies the desired message level (severity) of the mes
how the message bar is styled when the item is displayed.

The optional ``duration`` argument can be used to specify the message timeout in seconds. If ``duration``
is set to 0, then the message must be manually dismissed by the user.
is set to 0, then the message must be manually dismissed by the user. Since QGIS 3.18, a duration of -1 indicates that
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 );
Expand All @@ -42,7 +43,8 @@ The ``level`` argument specifies the desired message level (severity) of the mes
how the message bar is styled when the item is displayed.

The optional ``duration`` argument can be used to specify the message timeout in seconds. If ``duration``
is set to 0, then the message must be manually dismissed by the user.
is set to 0, then the message must be manually dismissed by the user. Since QGIS 3.18, a duration of -1 indicates that
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 );
Expand All @@ -53,7 +55,8 @@ The ``level`` argument specifies the desired message level (severity) of the mes
how the message bar is styled when the item is displayed.

The optional ``duration`` argument can be used to specify the message timeout in seconds. If ``duration``
is set to 0, then the message must be manually dismissed by the user.
is set to 0, then the message must be manually dismissed by the user. Since QGIS 3.18, a duration of -1 indicates that
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 );
Expand All @@ -64,7 +67,8 @@ The ``level`` argument specifies the desired message level (severity) of the mes
how the message bar is styled when the item is displayed.

The optional ``duration`` argument can be used to specify the message timeout in seconds. If ``duration``
is set to 0, then the message must be manually dismissed by the user.
is set to 0, then the message must be manually dismissed by the user. Since QGIS 3.18, a duration of -1 indicates that
the default timeout for the message ``level`` should be used.
%End

QgsMessageBarItem *setText( const QString &text );
Expand Down
6 changes: 3 additions & 3 deletions src/app/3d/qgs3dmapconfigwidget.cpp
Expand Up @@ -426,15 +426,15 @@ void Qgs3DMapConfigWidget::validate()
if ( ! cboTerrainLayer->currentLayer() )
{
valid = false;
mMessageBar->pushMessage( tr( "An elevation layer must be selected for a DEM terrain" ), Qgis::Critical, 0 );
mMessageBar->pushMessage( tr( "An elevation layer must be selected for a DEM terrain" ), Qgis::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, 0 );
mMessageBar->pushMessage( tr( "An elevation layer must be selected for a mesh terrain" ), Qgis::Critical );
}
break;

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

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

emit isValidChanged( valid );
Expand Down
6 changes: 3 additions & 3 deletions src/app/dwg/qgsdwgimportdialog.cpp
Expand Up @@ -226,7 +226,7 @@ void QgsDwgImportDialog::pbLoadDatabase_clicked()
}
else
{
bar->pushMessage( tr( "Could not open layer list" ), Qgis::Critical, 4 );
bar->pushMessage( tr( "Could not open layer list" ), Qgis::Critical );
}
}

Expand All @@ -253,11 +253,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, 4 );
bar->pushMessage( tr( "Drawing import completed." ), Qgis::Info );
}
else
{
bar->pushMessage( tr( "Drawing import failed (%1)" ).arg( error ), Qgis::Critical, 4 );
bar->pushMessage( tr( "Drawing import failed (%1)" ).arg( error ), Qgis::Critical );
}

pbLoadDatabase_clicked();
Expand Down
31 changes: 13 additions & 18 deletions src/app/georeferencer/qgsgeorefmainwindow.cpp
Expand Up @@ -300,7 +300,7 @@ void QgsGeoreferencerMainWindow::doGeoreference()
{
if ( georeference() )
{
mMessageBar->pushMessage( tr( "Georeference Successful" ), tr( "Raster was successfully georeferenced." ), Qgis::Info, messageTimeout() );
mMessageBar->pushMessage( tr( "Georeference Successful" ), tr( "Raster was successfully georeferenced." ), Qgis::Success );
if ( mLoadInQgis )
{
if ( mModifiedRasterFileName.isEmpty() )
Expand Down Expand Up @@ -393,7 +393,7 @@ void QgsGeoreferencerMainWindow::generateGDALScript()
default:
mMessageBar->pushMessage( tr( "Invalid Transform" ), tr( "GDAL scripting is not supported for %1 transformation." )
.arg( convertTransformEnumToString( mTransformParam ) )
, Qgis::Warning, messageTimeout() );
, Qgis::Critical );
}
}

Expand Down Expand Up @@ -605,19 +605,19 @@ void QgsGeoreferencerMainWindow::loadGCPsDialog()

if ( !loadGCPs() )
{
mMessageBar->pushMessage( tr( "Load GCP Points" ), tr( "Invalid GCP file. File could not be read." ), Qgis::Warning, messageTimeout() );
mMessageBar->pushMessage( tr( "Load GCP Points" ), tr( "Invalid GCP file. File could not be read." ), Qgis::Critical );
}
else
{
mMessageBar->pushMessage( tr( "Load GCP Points" ), tr( "GCP file successfully loaded." ), Qgis::Info, messageTimeout() );
mMessageBar->pushMessage( tr( "Load GCP Points" ), tr( "GCP file successfully loaded." ), Qgis::Success );
}
}

void QgsGeoreferencerMainWindow::saveGCPsDialog()
{
if ( mPoints.isEmpty() )
{
mMessageBar->pushMessage( tr( "Save GCP Points" ), tr( "No GCP points are available to save." ), Qgis::Warning, messageTimeout() );
mMessageBar->pushMessage( tr( "Save GCP Points" ), tr( "No GCP points are available to save." ), Qgis::Warning );
return;
}

Expand All @@ -644,7 +644,7 @@ void QgsGeoreferencerMainWindow::showRasterPropertiesDialog()
}
else
{
mMessageBar->pushMessage( tr( "Raster Properties" ), tr( "Please load raster to be georeferenced." ), Qgis::Info, messageTimeout() );
mMessageBar->pushMessage( tr( "Raster Properties" ), tr( "Please load raster to be georeferenced." ), Qgis::Warning );
}
}

Expand Down Expand Up @@ -1292,7 +1292,7 @@ void QgsGeoreferencerMainWindow::saveGCPs()
}
else
{
mMessageBar->pushMessage( tr( "Write Error" ), tr( "Could not write to GCP points file %1." ).arg( mGCPpointsFileName ), Qgis::Warning, messageTimeout() );
mMessageBar->pushMessage( tr( "Write Error" ), tr( "Could not write to GCP points file %1." ).arg( mGCPpointsFileName ), Qgis::Critical );
return;
}

Expand Down Expand Up @@ -1340,7 +1340,7 @@ bool QgsGeoreferencerMainWindow::georeference()
double pixelXSize, pixelYSize, rotation;
if ( !mGeorefTransform.getOriginScaleRotation( origin, pixelXSize, pixelYSize, rotation ) )
{
mMessageBar->pushMessage( tr( "Transform Failed" ), tr( "Failed to calculate linear transform parameters." ), Qgis::Warning, messageTimeout() );
mMessageBar->pushMessage( tr( "Transform Failed" ), tr( "Failed to calculate linear transform parameters." ), Qgis::Critical );
return false;
}

Expand Down Expand Up @@ -1388,7 +1388,7 @@ bool QgsGeoreferencerMainWindow::georeference()
if ( res == 0 ) // fault to compute GCP transform
{
//TODO: be more specific in the error message
mMessageBar->pushMessage( tr( "Transform Failed" ), tr( "Failed to compute GCP transform: Transform is not solvable." ), Qgis::Warning, messageTimeout() );
mMessageBar->pushMessage( tr( "Transform Failed" ), tr( "Failed to compute GCP transform: Transform is not solvable." ), Qgis::Critical );
return false;
}
else if ( res == -1 ) // operation canceled
Expand Down Expand Up @@ -1423,7 +1423,7 @@ bool QgsGeoreferencerMainWindow::writeWorldFile( const QgsPointXY &origin, doubl
QFile file( mWorldFileName );
if ( !file.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
{
mMessageBar->pushMessage( tr( "Save World File" ), tr( "Could not write to %1." ).arg( mWorldFileName ), Qgis::Critical, messageTimeout() );
mMessageBar->pushMessage( tr( "Save World File" ), tr( "Could not write to %1." ).arg( mWorldFileName ), Qgis::Critical );
return false;
}

Expand Down Expand Up @@ -1927,7 +1927,7 @@ bool QgsGeoreferencerMainWindow::checkReadyGeoref()
{
if ( mRasterFileName.isEmpty() )
{
mMessageBar->pushMessage( tr( "No Raster Loaded" ), tr( "Please load raster to be georeferenced." ), Qgis::Warning, messageTimeout() );
mMessageBar->pushMessage( tr( "No Raster Loaded" ), tr( "Please load raster to be georeferenced." ), Qgis::Warning );
return false;
}

Expand All @@ -1950,14 +1950,14 @@ bool QgsGeoreferencerMainWindow::checkReadyGeoref()
{
mMessageBar->pushMessage( tr( "Not Enough GCPs" ), tr( "%1 transformation requires at least %2 GCPs. Please define more." )
.arg( convertTransformEnumToString( mTransformParam ) ).arg( mGeorefTransform.getMinimumGCPCount() )
, Qgis::Warning, messageTimeout() );
, Qgis::Critical );
return false;
}

// Update the transform if necessary
if ( !updateGeorefTransform() )
{
mMessageBar->pushMessage( tr( "Transform Failed" ), tr( "Failed to compute GCP transform: Transform is not solvable." ), Qgis::Warning, messageTimeout() );
mMessageBar->pushMessage( tr( "Transform Failed" ), tr( "Failed to compute GCP transform: Transform is not solvable." ), Qgis::Critical );
// logRequaredGCPs();
return false;
}
Expand Down Expand Up @@ -2173,8 +2173,3 @@ void QgsGeoreferencerMainWindow::clearGCPData()
QgisApp::instance()->mapCanvas()->refresh();
}

int QgsGeoreferencerMainWindow::messageTimeout()
{
QgsSettings settings;
return settings.value( QStringLiteral( "qgis/messageTimeout" ), 5 ).toInt();
}
1 change: 0 additions & 1 deletion src/app/georeferencer/qgsgeorefmainwindow.h
Expand Up @@ -259,7 +259,6 @@ class QgsGeoreferencerMainWindow : public QMainWindow, private Ui::QgsGeorefPlug


QgsDockWidget *mDock = nullptr;
int messageTimeout();
};

#endif
6 changes: 3 additions & 3 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Expand Up @@ -2034,7 +2034,7 @@ void QgsLayoutDesignerDialog::print()
}
mMessageBar->pushMessage( tr( "Print layout" ),
message,
Qgis::Success, 0 );
Qgis::Success );
break;
}

Expand Down Expand Up @@ -2646,7 +2646,7 @@ void QgsLayoutDesignerDialog::printAtlas()
}
mMessageBar->pushMessage( tr( "Print atlas" ),
message,
Qgis::Success, 0 );
Qgis::Success );
break;
}

Expand Down Expand Up @@ -3741,7 +3741,7 @@ void QgsLayoutDesignerDialog::printReport()
}
mMessageBar->pushMessage( tr( "Print report" ),
message,
Qgis::Success, 0 );
Qgis::Success );
break;
}

Expand Down
4 changes: 0 additions & 4 deletions src/app/pluginmanager/qgspluginmanager.cpp
Expand Up @@ -1818,10 +1818,6 @@ void QgsPluginManager::showEvent( QShowEvent *e )

void QgsPluginManager::pushMessage( const QString &text, Qgis::MessageLevel level, int duration )
{
if ( duration == -1 )
{
duration = QgisApp::instance()->messageTimeout();
}
msgBar->pushMessage( text, level, duration );
}

Expand Down

0 comments on commit 13951b2

Please sign in to comment.