Skip to content
Permalink
Browse files

Make it easier to use the correct timeout for messages in message bars,

and ensure that correct timeouts are used for all created messages
  • Loading branch information
nyalldawson committed Nov 21, 2020
1 parent b010d88 commit 13951b2be49944eddaec591b4a349073386621d2
Showing with 287 additions and 307 deletions.
  1. +16 −6 python/gui/auto_generated/qgsmessagebar.sip.in
  2. +8 −4 python/gui/auto_generated/qgsmessagebaritem.sip.in
  3. +3 −3 src/app/3d/qgs3dmapconfigwidget.cpp
  4. +3 −3 src/app/dwg/qgsdwgimportdialog.cpp
  5. +13 −18 src/app/georeferencer/qgsgeorefmainwindow.cpp
  6. +0 −1 src/app/georeferencer/qgsgeorefmainwindow.h
  7. +3 −3 src/app/layout/qgslayoutdesignerdialog.cpp
  8. +0 −4 src/app/pluginmanager/qgspluginmanager.cpp
  9. +74 −86 src/app/qgisapp.cpp
  10. +0 −3 src/app/qgisapp.h
  11. +2 −1 src/app/qgisappinterface.cpp
  12. +2 −2 src/app/qgsattributetabledialog.cpp
  13. +1 −1 src/app/qgsguivectorlayertools.cpp
  14. +1 −1 src/app/qgshandlebadlayers.cpp
  15. +1 −1 src/app/qgsmaptoolcircle2tangentspoint.cpp
  16. +1 −1 src/app/qgsmaptoolcircle3tangents.cpp
  17. +2 −4 src/app/qgsmaptoolselectutils.cpp
  18. +5 −10 src/app/qgsmaptoolsplitfeatures.cpp
  19. +5 −10 src/app/qgsmaptoolsplitparts.cpp
  20. +3 −10 src/app/qgsselectbyformdialog.cpp
  21. +1 −2 src/app/vertextool/qgsvertextool.cpp
  22. +3 −4 src/gui/attributetable/qgsfeaturefilterwidget.cpp
  23. +0 −1 src/gui/attributetable/qgsfeaturefilterwidget_p.h
  24. +7 −13 src/gui/auth/qgsauthconfigeditor.cpp
  25. +0 −1 src/gui/auth/qgsauthconfigeditor.h
  26. +11 −16 src/gui/auth/qgsautheditorwidgets.cpp
  27. +0 −1 src/gui/auth/qgsautheditorwidgets.h
  28. +27 −29 src/gui/auth/qgsauthguiutils.cpp
  29. +10 −10 src/gui/auth/qgsauthguiutils.h
  30. +1 −1 src/gui/labeling/qgslabelengineconfigdialog.cpp
  31. +8 −2 src/gui/layertree/qgslayertreeview.cpp
  32. +4 −4 src/gui/processing/models/qgsmodeldesignerdialog.cpp
  33. +1 −1 src/gui/processing/qgsprocessingalgorithmdialogbase.cpp
  34. +2 −2 src/gui/processing/qgsprocessingwidgetwrapperimpl.cpp
  35. +1 −2 src/gui/qgsattributedialog.cpp
  36. +6 −16 src/gui/qgsattributeform.cpp
  37. +0 −1 src/gui/qgsattributeform.h
  38. +4 −9 src/gui/qgsexpressionselectiondialog.cpp
  39. +1 −2 src/gui/qgsmapcanvastracer.cpp
  40. +26 −0 src/gui/qgsmessagebar.cpp
  41. +15 −6 src/gui/qgsmessagebar.h
  42. +3 −0 src/gui/qgsmessagebaritem.cpp
  43. +8 −4 src/gui/qgsmessagebaritem.h
  44. +5 −8 src/gui/vector/qgsvectorlayerproperties.cpp
@@ -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.
@@ -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();
@@ -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:
@@ -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 );
@@ -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 );
@@ -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 );
@@ -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 );
@@ -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;

@@ -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 );
@@ -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 );
}
}

@@ -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();
@@ -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() )
@@ -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 );
}
}

@@ -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;
}

@@ -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 );
}
}

@@ -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;
}

@@ -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;
}

@@ -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
@@ -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;
}

@@ -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;
}

@@ -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;
}
@@ -2173,8 +2173,3 @@ void QgsGeoreferencerMainWindow::clearGCPData()
QgisApp::instance()->mapCanvas()->refresh();
}

int QgsGeoreferencerMainWindow::messageTimeout()
{
QgsSettings settings;
return settings.value( QStringLiteral( "qgis/messageTimeout" ), 5 ).toInt();
}
@@ -259,7 +259,6 @@ class QgsGeoreferencerMainWindow : public QMainWindow, private Ui::QgsGeorefPlug


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

#endif
@@ -2034,7 +2034,7 @@ void QgsLayoutDesignerDialog::print()
}
mMessageBar->pushMessage( tr( "Print layout" ),
message,
Qgis::Success, 0 );
Qgis::Success );
break;
}

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

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

@@ -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 );
}

0 comments on commit 13951b2

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