Skip to content

Commit 1a669dc

Browse files
committed
Merge pull request #1127 from 3nids/fix8873
better message display in map edit tools (fix #8873)
2 parents 1c0d5e2 + b7b1931 commit 1a669dc

18 files changed

+123
-47
lines changed

python/gui/qgsmapcanvas.sip

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,10 @@ class QgsMapCanvas : QGraphicsView
354354

355355
//! Emit map tool changed event
356356
void mapToolSet( QgsMapTool *tool );
357+
358+
//! Emit map tool changed with the old tool
359+
//! @note added in 2.3
360+
void mapToolSet( QgsMapTool *newTool, QgsMapTool* oldTool );
357361

358362
// ### QGIS 3: remove the signal
359363
//! Emitted when selection in any layer gets changed

python/gui/qgsmaptool.sip

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ class QgsMapTool : QObject
105105

106106
//! returns pointer to the tool's map canvas
107107
QgsMapCanvas* canvas();
108+
109+
/** return the tool name
110+
* @note added in 2.3
111+
*/
112+
QString toolName();
108113

109114
protected:
110115

src/app/nodetool/qgsmaptoolnodetool.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,13 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
362362

363363
if ( snapResults.size() < 1 )
364364
{
365-
displaySnapToleranceWarning();
365+
emit displayMessage( tr( "could not snap to a segment on the current layer." ) );
366366
return;
367367
}
368368

369+
// remove previous warning
370+
emit removeMessage();
371+
369372
mSelectedFeature = new QgsSelectedFeature( snapResults[0].snappedAtGeometry, vlayer, mCanvas );
370373
connect( QgisApp::instance()->legend(), SIGNAL( currentLayerChanged( QgsMapLayer* ) ), this, SLOT( currentLayerChanged( QgsMapLayer* ) ) );
371374
connect( mSelectedFeature, SIGNAL( destroyed() ), this, SLOT( selectedFeatureDestroyed() ) );
@@ -374,6 +377,9 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
374377
}
375378
else
376379
{
380+
// remove previous warning
381+
emit removeMessage();
382+
377383
QgsVectorLayer *vlayer = mSelectedFeature->vlayer();
378384
Q_ASSERT( vlayer );
379385

src/app/qgisapp.cpp

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,8 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
579579
mpGpsDock->setWidget( mpGpsWidget );
580580
mpGpsDock->hide();
581581

582+
mLastMapToolMessage = 0;
583+
582584
mLogViewer = new QgsMessageLogViewer( statusBar(), this );
583585

584586
mLogDock = new QDockWidget( tr( "Log Messages" ), this );
@@ -1890,8 +1892,8 @@ void QgisApp::setupConnections()
18901892
this, SLOT( showScale( double ) ) );
18911893
connect( mMapCanvas, SIGNAL( scaleChanged( double ) ),
18921894
this, SLOT( updateMouseCoordinatePrecision() ) );
1893-
connect( mMapCanvas, SIGNAL( mapToolSet( QgsMapTool * ) ),
1894-
this, SLOT( mapToolChanged( QgsMapTool * ) ) );
1895+
connect( mMapCanvas, SIGNAL( mapToolSet( QgsMapTool *, QgsMapTool * ) ),
1896+
this, SLOT( mapToolChanged( QgsMapTool *, QgsMapTool * ) ) );
18951897
connect( mMapCanvas, SIGNAL( selectionChanged( QgsMapLayer * ) ),
18961898
this, SLOT( selectionChanged( QgsMapLayer * ) ) );
18971899
connect( mMapCanvas, SIGNAL( extentsChanged() ),
@@ -2006,9 +2008,9 @@ void QgisApp::createCanvasTools()
20062008
mMapTools.mMoveFeature->setAction( mActionMoveFeature );
20072009
mMapTools.mRotateFeature = new QgsMapToolRotateFeature( mMapCanvas );
20082010
mMapTools.mRotateFeature->setAction( mActionRotateFeature );
2009-
//need at least geos 3.3 for OffsetCurve tool
2011+
//need at least geos 3.3 for OffsetCurve tool
20102012
#if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \
2011-
((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=3)))
2013+
((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=3)))
20122014
mMapTools.mOffsetCurve = new QgsMapToolOffsetCurve( mMapCanvas );
20132015
mMapTools.mOffsetCurve->setAction( mActionOffsetCurve );
20142016
#else
@@ -2059,7 +2061,7 @@ void QgisApp::createCanvasTools()
20592061
mMapTools.mRotateLabel->setAction( mActionRotateLabel );
20602062
mMapTools.mChangeLabelProperties = new QgsMapToolChangeLabelProperties( mMapCanvas );
20612063
mMapTools.mChangeLabelProperties->setAction( mActionChangeLabelProperties );
2062-
//ensure that non edit tool is initialised or we will get crashes in some situations
2064+
//ensure that non edit tool is initialised or we will get crashes in some situations
20632065
mNonEditMapTool = mMapTools.mPan;
20642066
}
20652067

@@ -8020,11 +8022,25 @@ void QgisApp::showProgress( int theProgress, int theTotalSteps )
80208022
}
80218023
}
80228024

8023-
void QgisApp::mapToolChanged( QgsMapTool *tool )
8025+
void QgisApp::mapToolChanged( QgsMapTool *newTool, QgsMapTool *oldTool )
80248026
{
8025-
if ( tool && !tool->isEditTool() )
8027+
if ( oldTool )
80268028
{
8027-
mNonEditMapTool = tool;
8029+
disconnect( oldTool, SIGNAL( displayMessage( QString ) ), this, SLOT( displayMapToolMessage( QString ) ) );
8030+
disconnect( oldTool, SIGNAL( displayMessage( QString, QgsMessageBar::MessageLevel ) ), this, SLOT( displayMapToolMessage( QString, QgsMessageBar::MessageLevel ) ) );
8031+
disconnect( oldTool, SIGNAL( removeMessage() ), this, SLOT( removeMapToolMessage() ) );
8032+
}
8033+
8034+
if ( newTool )
8035+
{
8036+
if ( !newTool->isEditTool() )
8037+
{
8038+
mNonEditMapTool = newTool;
8039+
}
8040+
8041+
connect( newTool, SIGNAL( displayMessage( QString ) ), this, SLOT( displayMapToolMessage( QString ) ) );
8042+
connect( newTool, SIGNAL( displayMessage( QString, QgsMessageBar::MessageLevel ) ), this, SLOT( displayMapToolMessage( QString, QgsMessageBar::MessageLevel ) ) );
8043+
connect( newTool, SIGNAL( removeMessage() ), this, SLOT( removeMapToolMessage() ) );
80288044
}
80298045
}
80308046

@@ -8151,6 +8167,27 @@ void QgisApp::showStatusMessage( QString theMessage )
81518167
statusBar()->showMessage( theMessage );
81528168
}
81538169

8170+
void QgisApp::displayMapToolMessage( QString message, QgsMessageBar::MessageLevel level )
8171+
{
8172+
// remove previous message
8173+
messageBar()->popWidget( mLastMapToolMessage );
8174+
8175+
QgsMapTool* tool = mapCanvas()->mapTool();
8176+
8177+
if ( tool )
8178+
{
8179+
mLastMapToolMessage = new QgsMessageBarItem( tool->toolName(), message, level, messageTimeout() );
8180+
messageBar()->pushItem( mLastMapToolMessage );
8181+
}
8182+
}
8183+
8184+
void QgisApp::removeMapToolMessage()
8185+
{
8186+
// remove previous message
8187+
messageBar()->popWidget( mLastMapToolMessage );
8188+
}
8189+
8190+
81548191
// Show the maptip using tooltip
81558192
void QgisApp::showMapTip()
81568193
{

src/app/qgisapp.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class QgsTileScaleWidget;
9292
#include "qgsrasterlayer.h"
9393
#include "qgssnappingdialog.h"
9494
#include "qgspluginmanager.h"
95+
#include "qgsmessagebar.h"
9596

9697
#include "ui_qgisapp.h"
9798

@@ -999,7 +1000,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
9991000
void layerSubsetString();
10001001

10011002
//! map tool changed
1002-
void mapToolChanged( QgsMapTool *tool );
1003+
void mapToolChanged( QgsMapTool *newTool , QgsMapTool* oldTool );
10031004

10041005
/** Called when some layer's editing mode was toggled on/off
10051006
* @note added in 1.9 */
@@ -1015,6 +1016,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
10151016
void extentsViewToggled( bool theFlag );
10161017
void showExtents();
10171018
void showStatusMessage( QString theMessage );
1019+
void displayMapToolMessage( QString message, QgsMessageBar::MessageLevel level = QgsMessageBar::INFO );
1020+
void removeMapToolMessage();
10181021
void updateMouseCoordinatePrecision();
10191022
void hasCrsTransformEnabled( bool theFlag );
10201023
void destinationCrsChanged();
@@ -1522,6 +1525,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
15221525
//! Persistent GPS toolbox
15231526
QgsGPSInformationWidget * mpGpsWidget;
15241527

1528+
QgsMessageBarItem* mLastMapToolMessage;
1529+
15251530
QgsMessageLogViewer *mLogViewer;
15261531

15271532
//! project changed
@@ -1541,7 +1546,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
15411546
bool gestureEvent( QGestureEvent *event );
15421547
void tapAndHoldTriggered( QTapAndHoldGesture *gesture );
15431548
#endif
1544-
15451549
};
15461550

15471551
#ifdef ANDROID

src/app/qgsmaptooladdpart.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void QgsMapToolAddPart::canvasReleaseEvent( QMouseEvent * e )
6262

6363
if ( !selectionErrorMsg.isEmpty() )
6464
{
65-
QMessageBox::critical( 0, tr( "Error. Could not add part." ), selectionErrorMsg );
65+
emit displayMessage( tr( "Could not add part. %1" ).arg( selectionErrorMsg ) , QgsMessageBar::WARNING );
6666
stopCapturing();
6767
return;
6868
}
@@ -101,9 +101,7 @@ void QgsMapToolAddPart::canvasReleaseEvent( QMouseEvent * e )
101101
else if ( error == 2 )
102102
{
103103
//problem with coordinate transformation
104-
QMessageBox::information( 0,
105-
tr( "Coordinate transform error" ),
106-
tr( "Cannot transform the point to the layers coordinate system" ) );
104+
emit displayMessage( tr( "Coordinate transform error. Cannot transform the point to the layers coordinate system" ) , QgsMessageBar::WARNING );
107105
return;
108106
}
109107

@@ -156,6 +154,9 @@ void QgsMapToolAddPart::canvasReleaseEvent( QMouseEvent * e )
156154
{
157155
case 0:
158156
{
157+
// remove previous message
158+
emit removeMessage();
159+
159160
//add points to other features to keep topology up-to-date
160161
int topologicalEditing = QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 );
161162
if ( topologicalEditing )
@@ -194,6 +195,6 @@ void QgsMapToolAddPart::canvasReleaseEvent( QMouseEvent * e )
194195
break;
195196
}
196197

197-
QMessageBox::critical( 0, tr( "Error, could not add part" ), errorMessage );
198+
emit displayMessage( errorMessage , QgsMessageBar::WARNING );
198199
vlayer->destroyEditCommand();
199200
}

src/app/qgsmaptooldeletepart.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ void QgsMapToolDeletePart::canvasPressEvent( QMouseEvent *e )
5252

5353
if ( mRecentSnappingResults.size() > 0 )
5454
{
55+
// remove previous warning
56+
emit removeMessage();
57+
5558
QgsPoint markerPoint = mRecentSnappingResults.begin()->snappedVertex;
5659

5760
//show vertex marker
@@ -61,7 +64,7 @@ void QgsMapToolDeletePart::canvasPressEvent( QMouseEvent *e )
6164
}
6265
else
6366
{
64-
displaySnapToleranceWarning();
67+
emit displayMessage( tr( "could not snap to a part on the current layer." ) );
6568
}
6669
}
6770

src/app/qgsmaptooldeletering.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
#include <QMessageBox>
2424

2525
QgsMapToolDeleteRing::QgsMapToolDeleteRing( QgsMapCanvas* canvas )
26-
: QgsMapToolVertexEdit( canvas ), mCross( 0 )
26+
: QgsMapToolVertexEdit( canvas )
27+
, mCross( 0 )
2728
{
29+
mToolName = tr( "Delete ring" );
2830
}
2931

3032
QgsMapToolDeleteRing::~QgsMapToolDeleteRing()
@@ -52,6 +54,9 @@ void QgsMapToolDeleteRing::canvasPressEvent( QMouseEvent *e )
5254

5355
if ( mRecentSnappingResults.size() > 0 )
5456
{
57+
// remove previous warning
58+
emit removeMessage();
59+
5560
QgsPoint markerPoint = mRecentSnappingResults.begin()->snappedVertex;
5661

5762
//show vertex marker
@@ -61,7 +66,7 @@ void QgsMapToolDeleteRing::canvasPressEvent( QMouseEvent *e )
6166
}
6267
else
6368
{
64-
displaySnapToleranceWarning();
69+
emit displayMessage( tr( "could not snap to a ring on the current layer." ) );
6570
}
6671
}
6772

src/app/qgsmaptooledit.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414
***************************************************************************/
1515

1616
#include "qgsmaptooledit.h"
17-
#include "qgisapp.h"
18-
#include "qgsmessagebar.h"
1917
#include "qgsproject.h"
2018
#include "qgsmapcanvas.h"
2119
#include "qgsrubberband.h"
2220
#include "qgsvectorlayer.h"
21+
2322
#include <QKeyEvent>
2423
#include <QSettings>
2524

@@ -134,18 +133,10 @@ int QgsMapToolEdit::addTopologicalPoints( const QList<QgsPoint>& geom )
134133

135134
void QgsMapToolEdit::notifyNotVectorLayer()
136135
{
137-
QgisApp::instance()->messageBar()->pushMessage(
138-
tr( "No active vector layer" ),
139-
tr( "Choose a vector layer in the legend" ),
140-
QgsMessageBar::INFO,
141-
QgisApp::instance()->messageTimeout() );
136+
emit displayMessage( tr( "No active vector layer" ) );
142137
}
143138

144139
void QgsMapToolEdit::notifyNotEditableLayer()
145140
{
146-
QgisApp::instance()->messageBar()->pushMessage(
147-
tr( "Layer not editable" ),
148-
tr( "Use 'Toggle Editing' to make it editable" ),
149-
QgsMessageBar::INFO,
150-
QgisApp::instance()->messageTimeout() );
141+
emit displayMessage( tr( "Layer not editable" ) );
151142
}

src/app/qgsmaptooledit.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ class APP_EXPORT QgsMapToolEdit: public QgsMapTool
7272
/**Display a timed message bar noting the active vector layer is not editable.
7373
@note added in QGIS 1.9*/
7474
void notifyNotEditableLayer();
75-
7675
};
7776

7877
#endif

0 commit comments

Comments
 (0)