Skip to content

Commit

Permalink
Merge pull request #1127 from 3nids/fix8873
Browse files Browse the repository at this point in the history
better message display in map edit tools (fix #8873)
  • Loading branch information
3nids committed Mar 17, 2014
2 parents 1c0d5e2 + b7b1931 commit 1a669dc
Show file tree
Hide file tree
Showing 18 changed files with 123 additions and 47 deletions.
4 changes: 4 additions & 0 deletions python/gui/qgsmapcanvas.sip
Expand Up @@ -354,6 +354,10 @@ class QgsMapCanvas : QGraphicsView

//! Emit map tool changed event
void mapToolSet( QgsMapTool *tool );

//! Emit map tool changed with the old tool
//! @note added in 2.3
void mapToolSet( QgsMapTool *newTool, QgsMapTool* oldTool );

// ### QGIS 3: remove the signal
//! Emitted when selection in any layer gets changed
Expand Down
5 changes: 5 additions & 0 deletions python/gui/qgsmaptool.sip
Expand Up @@ -105,6 +105,11 @@ class QgsMapTool : QObject

//! returns pointer to the tool's map canvas
QgsMapCanvas* canvas();

/** return the tool name
* @note added in 2.3
*/
QString toolName();

protected:

Expand Down
8 changes: 7 additions & 1 deletion src/app/nodetool/qgsmaptoolnodetool.cpp
Expand Up @@ -362,10 +362,13 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )

if ( snapResults.size() < 1 )
{
displaySnapToleranceWarning();
emit displayMessage( tr( "could not snap to a segment on the current layer." ) );
return;
}

// remove previous warning
emit removeMessage();

mSelectedFeature = new QgsSelectedFeature( snapResults[0].snappedAtGeometry, vlayer, mCanvas );
connect( QgisApp::instance()->legend(), SIGNAL( currentLayerChanged( QgsMapLayer* ) ), this, SLOT( currentLayerChanged( QgsMapLayer* ) ) );
connect( mSelectedFeature, SIGNAL( destroyed() ), this, SLOT( selectedFeatureDestroyed() ) );
Expand All @@ -374,6 +377,9 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
}
else
{
// remove previous warning
emit removeMessage();

QgsVectorLayer *vlayer = mSelectedFeature->vlayer();
Q_ASSERT( vlayer );

Expand Down
53 changes: 45 additions & 8 deletions src/app/qgisapp.cpp
Expand Up @@ -579,6 +579,8 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
mpGpsDock->setWidget( mpGpsWidget );
mpGpsDock->hide();

mLastMapToolMessage = 0;

mLogViewer = new QgsMessageLogViewer( statusBar(), this );

mLogDock = new QDockWidget( tr( "Log Messages" ), this );
Expand Down Expand Up @@ -1890,8 +1892,8 @@ void QgisApp::setupConnections()
this, SLOT( showScale( double ) ) );
connect( mMapCanvas, SIGNAL( scaleChanged( double ) ),
this, SLOT( updateMouseCoordinatePrecision() ) );
connect( mMapCanvas, SIGNAL( mapToolSet( QgsMapTool * ) ),
this, SLOT( mapToolChanged( QgsMapTool * ) ) );
connect( mMapCanvas, SIGNAL( mapToolSet( QgsMapTool *, QgsMapTool * ) ),
this, SLOT( mapToolChanged( QgsMapTool *, QgsMapTool * ) ) );
connect( mMapCanvas, SIGNAL( selectionChanged( QgsMapLayer * ) ),
this, SLOT( selectionChanged( QgsMapLayer * ) ) );
connect( mMapCanvas, SIGNAL( extentsChanged() ),
Expand Down Expand Up @@ -2006,9 +2008,9 @@ void QgisApp::createCanvasTools()
mMapTools.mMoveFeature->setAction( mActionMoveFeature );
mMapTools.mRotateFeature = new QgsMapToolRotateFeature( mMapCanvas );
mMapTools.mRotateFeature->setAction( mActionRotateFeature );
//need at least geos 3.3 for OffsetCurve tool
//need at least geos 3.3 for OffsetCurve tool
#if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \
((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=3)))
((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=3)))
mMapTools.mOffsetCurve = new QgsMapToolOffsetCurve( mMapCanvas );
mMapTools.mOffsetCurve->setAction( mActionOffsetCurve );
#else
Expand Down Expand Up @@ -2059,7 +2061,7 @@ void QgisApp::createCanvasTools()
mMapTools.mRotateLabel->setAction( mActionRotateLabel );
mMapTools.mChangeLabelProperties = new QgsMapToolChangeLabelProperties( mMapCanvas );
mMapTools.mChangeLabelProperties->setAction( mActionChangeLabelProperties );
//ensure that non edit tool is initialised or we will get crashes in some situations
//ensure that non edit tool is initialised or we will get crashes in some situations
mNonEditMapTool = mMapTools.mPan;
}

Expand Down Expand Up @@ -8020,11 +8022,25 @@ void QgisApp::showProgress( int theProgress, int theTotalSteps )
}
}

void QgisApp::mapToolChanged( QgsMapTool *tool )
void QgisApp::mapToolChanged( QgsMapTool *newTool, QgsMapTool *oldTool )
{
if ( tool && !tool->isEditTool() )
if ( oldTool )
{
mNonEditMapTool = tool;
disconnect( oldTool, SIGNAL( displayMessage( QString ) ), this, SLOT( displayMapToolMessage( QString ) ) );
disconnect( oldTool, SIGNAL( displayMessage( QString, QgsMessageBar::MessageLevel ) ), this, SLOT( displayMapToolMessage( QString, QgsMessageBar::MessageLevel ) ) );
disconnect( oldTool, SIGNAL( removeMessage() ), this, SLOT( removeMapToolMessage() ) );
}

if ( newTool )
{
if ( !newTool->isEditTool() )
{
mNonEditMapTool = newTool;
}

connect( newTool, SIGNAL( displayMessage( QString ) ), this, SLOT( displayMapToolMessage( QString ) ) );
connect( newTool, SIGNAL( displayMessage( QString, QgsMessageBar::MessageLevel ) ), this, SLOT( displayMapToolMessage( QString, QgsMessageBar::MessageLevel ) ) );
connect( newTool, SIGNAL( removeMessage() ), this, SLOT( removeMapToolMessage() ) );
}
}

Expand Down Expand Up @@ -8151,6 +8167,27 @@ void QgisApp::showStatusMessage( QString theMessage )
statusBar()->showMessage( theMessage );
}

void QgisApp::displayMapToolMessage( QString message, QgsMessageBar::MessageLevel level )
{
// remove previous message
messageBar()->popWidget( mLastMapToolMessage );

QgsMapTool* tool = mapCanvas()->mapTool();

if ( tool )
{
mLastMapToolMessage = new QgsMessageBarItem( tool->toolName(), message, level, messageTimeout() );
messageBar()->pushItem( mLastMapToolMessage );
}
}

void QgisApp::removeMapToolMessage()
{
// remove previous message
messageBar()->popWidget( mLastMapToolMessage );
}


// Show the maptip using tooltip
void QgisApp::showMapTip()
{
Expand Down
8 changes: 6 additions & 2 deletions src/app/qgisapp.h
Expand Up @@ -92,6 +92,7 @@ class QgsTileScaleWidget;
#include "qgsrasterlayer.h"
#include "qgssnappingdialog.h"
#include "qgspluginmanager.h"
#include "qgsmessagebar.h"

#include "ui_qgisapp.h"

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

//! map tool changed
void mapToolChanged( QgsMapTool *tool );
void mapToolChanged( QgsMapTool *newTool , QgsMapTool* oldTool );

/** Called when some layer's editing mode was toggled on/off
* @note added in 1.9 */
Expand All @@ -1015,6 +1016,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
void extentsViewToggled( bool theFlag );
void showExtents();
void showStatusMessage( QString theMessage );
void displayMapToolMessage( QString message, QgsMessageBar::MessageLevel level = QgsMessageBar::INFO );
void removeMapToolMessage();
void updateMouseCoordinatePrecision();
void hasCrsTransformEnabled( bool theFlag );
void destinationCrsChanged();
Expand Down Expand Up @@ -1522,6 +1525,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! Persistent GPS toolbox
QgsGPSInformationWidget * mpGpsWidget;

QgsMessageBarItem* mLastMapToolMessage;

QgsMessageLogViewer *mLogViewer;

//! project changed
Expand All @@ -1541,7 +1546,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
bool gestureEvent( QGestureEvent *event );
void tapAndHoldTriggered( QTapAndHoldGesture *gesture );
#endif

};

#ifdef ANDROID
Expand Down
11 changes: 6 additions & 5 deletions src/app/qgsmaptooladdpart.cpp
Expand Up @@ -62,7 +62,7 @@ void QgsMapToolAddPart::canvasReleaseEvent( QMouseEvent * e )

if ( !selectionErrorMsg.isEmpty() )
{
QMessageBox::critical( 0, tr( "Error. Could not add part." ), selectionErrorMsg );
emit displayMessage( tr( "Could not add part. %1" ).arg( selectionErrorMsg ) , QgsMessageBar::WARNING );
stopCapturing();
return;
}
Expand Down Expand Up @@ -101,9 +101,7 @@ void QgsMapToolAddPart::canvasReleaseEvent( QMouseEvent * e )
else if ( error == 2 )
{
//problem with coordinate transformation
QMessageBox::information( 0,
tr( "Coordinate transform error" ),
tr( "Cannot transform the point to the layers coordinate system" ) );
emit displayMessage( tr( "Coordinate transform error. Cannot transform the point to the layers coordinate system" ) , QgsMessageBar::WARNING );
return;
}

Expand Down Expand Up @@ -156,6 +154,9 @@ void QgsMapToolAddPart::canvasReleaseEvent( QMouseEvent * e )
{
case 0:
{
// remove previous message
emit removeMessage();

//add points to other features to keep topology up-to-date
int topologicalEditing = QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 );
if ( topologicalEditing )
Expand Down Expand Up @@ -194,6 +195,6 @@ void QgsMapToolAddPart::canvasReleaseEvent( QMouseEvent * e )
break;
}

QMessageBox::critical( 0, tr( "Error, could not add part" ), errorMessage );
emit displayMessage( errorMessage , QgsMessageBar::WARNING );
vlayer->destroyEditCommand();
}
5 changes: 4 additions & 1 deletion src/app/qgsmaptooldeletepart.cpp
Expand Up @@ -52,6 +52,9 @@ void QgsMapToolDeletePart::canvasPressEvent( QMouseEvent *e )

if ( mRecentSnappingResults.size() > 0 )
{
// remove previous warning
emit removeMessage();

QgsPoint markerPoint = mRecentSnappingResults.begin()->snappedVertex;

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

Expand Down
9 changes: 7 additions & 2 deletions src/app/qgsmaptooldeletering.cpp
Expand Up @@ -23,8 +23,10 @@
#include <QMessageBox>

QgsMapToolDeleteRing::QgsMapToolDeleteRing( QgsMapCanvas* canvas )
: QgsMapToolVertexEdit( canvas ), mCross( 0 )
: QgsMapToolVertexEdit( canvas )
, mCross( 0 )
{
mToolName = tr( "Delete ring" );
}

QgsMapToolDeleteRing::~QgsMapToolDeleteRing()
Expand Down Expand Up @@ -52,6 +54,9 @@ void QgsMapToolDeleteRing::canvasPressEvent( QMouseEvent *e )

if ( mRecentSnappingResults.size() > 0 )
{
// remove previous warning
emit removeMessage();

QgsPoint markerPoint = mRecentSnappingResults.begin()->snappedVertex;

//show vertex marker
Expand All @@ -61,7 +66,7 @@ void QgsMapToolDeleteRing::canvasPressEvent( QMouseEvent *e )
}
else
{
displaySnapToleranceWarning();
emit displayMessage( tr( "could not snap to a ring on the current layer." ) );
}
}

Expand Down
15 changes: 3 additions & 12 deletions src/app/qgsmaptooledit.cpp
Expand Up @@ -14,12 +14,11 @@
***************************************************************************/

#include "qgsmaptooledit.h"
#include "qgisapp.h"
#include "qgsmessagebar.h"
#include "qgsproject.h"
#include "qgsmapcanvas.h"
#include "qgsrubberband.h"
#include "qgsvectorlayer.h"

#include <QKeyEvent>
#include <QSettings>

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

void QgsMapToolEdit::notifyNotVectorLayer()
{
QgisApp::instance()->messageBar()->pushMessage(
tr( "No active vector layer" ),
tr( "Choose a vector layer in the legend" ),
QgsMessageBar::INFO,
QgisApp::instance()->messageTimeout() );
emit displayMessage( tr( "No active vector layer" ) );
}

void QgsMapToolEdit::notifyNotEditableLayer()
{
QgisApp::instance()->messageBar()->pushMessage(
tr( "Layer not editable" ),
tr( "Use 'Toggle Editing' to make it editable" ),
QgsMessageBar::INFO,
QgisApp::instance()->messageTimeout() );
emit displayMessage( tr( "Layer not editable" ) );
}
1 change: 0 additions & 1 deletion src/app/qgsmaptooledit.h
Expand Up @@ -72,7 +72,6 @@ class APP_EXPORT QgsMapToolEdit: public QgsMapTool
/**Display a timed message bar noting the active vector layer is not editable.
@note added in QGIS 1.9*/
void notifyNotEditableLayer();

};

#endif
9 changes: 0 additions & 9 deletions src/app/qgsmaptoolvertexedit.cpp
Expand Up @@ -39,12 +39,3 @@ QgsMapToolVertexEdit::~QgsMapToolVertexEdit()
{

}

void QgsMapToolVertexEdit::displaySnapToleranceWarning()
{
QgisApp::instance()->messageBar()->pushMessage(
tr( "Snap tolerance" ),
tr( "Could not snap segment. Have you set the tolerance in Settings > Snapping Options?" ),
QgsMessageBar::INFO,
QgisApp::instance()->messageTimeout() );
}
3 changes: 0 additions & 3 deletions src/app/qgsmaptoolvertexedit.h
Expand Up @@ -38,9 +38,6 @@ class APP_EXPORT QgsMapToolVertexEdit: public QgsMapToolEdit
/**Snapping results that are collected during the mouse press event
(search for vertices/segments to manipulate)*/
QList<QgsSnappingResult> mRecentSnappingResults;

//! Displays a warning about the snap tolerance settings
void displaySnapToleranceWarning();
};

#endif
1 change: 1 addition & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -239,6 +239,7 @@ qgsmanageconnectionsdialog.h
qgsmapcanvas.h
qgsmaplayeractionregistry.h
qgsmapoverviewcanvas.h
qgsmaptool.h
qgsmaptoolemitpoint.h
qgsmaptoolidentify.h
qgsmessagebaritem.h
Expand Down
4 changes: 4 additions & 0 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -1429,6 +1429,8 @@ void QgsMapCanvas::setMapTool( QgsMapTool* tool )
mLastNonZoomMapTool = NULL;
}

QgsMapTool* oldTool = mMapTool;

// set new map tool and activate it
mMapTool = tool;
if ( mMapTool )
Expand All @@ -1438,6 +1440,7 @@ void QgsMapCanvas::setMapTool( QgsMapTool* tool )
}

emit mapToolSet( mMapTool );
emit mapToolSet( mMapTool, oldTool );
} // setMapTool

void QgsMapCanvas::unsetMapTool( QgsMapTool* tool )
Expand All @@ -1447,6 +1450,7 @@ void QgsMapCanvas::unsetMapTool( QgsMapTool* tool )
mMapTool->deactivate();
mMapTool = NULL;
emit mapToolSet( NULL );
emit mapToolSet( NULL, mMapTool );
setCursor( Qt::ArrowCursor );
}

Expand Down
5 changes: 5 additions & 0 deletions src/gui/qgsmapcanvas.h
Expand Up @@ -435,6 +435,11 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
//! Emit map tool changed event
void mapToolSet( QgsMapTool *tool );

/** Emit map tool changed with the old tool
* @note added in 2.3
*/
void mapToolSet( QgsMapTool *newTool, QgsMapTool* oldTool );

// ### QGIS 3: remove the signal
//! Emitted when selection in any layer gets changed
void selectionChanged( QgsMapLayer * layer );
Expand Down

0 comments on commit 1a669dc

Please sign in to comment.