Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
improved identify menu with a dedicated class
  • Loading branch information
3nids committed Sep 16, 2014
1 parent aa95ae4 commit 1fb524f
Show file tree
Hide file tree
Showing 10 changed files with 839 additions and 194 deletions.
3 changes: 0 additions & 3 deletions python/gui/qgsmaptoolidentify.sip
Expand Up @@ -80,16 +80,13 @@ class QgsMapToolIdentify : QgsMapTool

public slots:
void formatChanged( QgsRasterLayer *layer );
void layerDestroyed();

signals:
void identifyProgress( int, int );
void identifyMessage( QString );
void changedRasterResults( QList<QgsMapToolIdentify::IdentifyResult>& );

protected:
//! rubber bands for layer select mode
void deleteRubberBands();

/** Performs the identification.
To avoid beeing forced to specify IdentifyMode with a list of layers
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsidentifyresultsdialog.h
Expand Up @@ -51,7 +51,7 @@ class QwtPlotCurve;

class APP_EXPORT QgsIdentifyResultsWebView : public QWebView
{
Q_OBJECT;
Q_OBJECT
public:
QgsIdentifyResultsWebView( QWidget *parent = 0 );
QSize sizeHint() const;
Expand Down
51 changes: 42 additions & 9 deletions src/app/qgsmaptoolidentifyaction.cpp
Expand Up @@ -14,13 +14,15 @@
***************************************************************************/

#include "qgsapplication.h"
#include "qgsattributetabledialog.h"
#include "qgscursors.h"
#include "qgsdistancearea.h"
#include "qgsfeature.h"
#include "qgsfield.h"
#include "qgsgeometry.h"
#include "qgslogger.h"
#include "qgsidentifyresultsdialog.h"
#include "qgsidentifymenu.h"
#include "qgsmapcanvas.h"
#include "qgsmaptopixel.h"
#include "qgsmessageviewer.h"
Expand Down Expand Up @@ -50,6 +52,12 @@ QgsMapToolIdentifyAction::QgsMapToolIdentifyAction( QgsMapCanvas * canvas )
mCursor = QCursor( myIdentifyQPixmap, 1, 1 );

connect( this, SIGNAL( changedRasterResults( QList<IdentifyResult>& ) ), this, SLOT( handleChangedRasterResults( QList<IdentifyResult>& ) ) );

mIdentifyMenu->setAllowMultipleReturn( true );

QgsMapLayerAction* attrTableAction = new QgsMapLayerAction( tr( "Show attribute table" ), mIdentifyMenu, QgsMapLayer::VectorLayer, QgsMapLayerAction::MultipleFeatures );
connect( attrTableAction, SIGNAL( triggeredForFeatures( QgsMapLayer*, QList<const QgsFeature*> ) ), this, SLOT( showAttributeTable( QgsMapLayer*, QList<const QgsFeature*> ) ) );
identifyMenu()->addCustomAction( attrTableAction );
}

QgsMapToolIdentifyAction::~QgsMapToolIdentifyAction()
Expand All @@ -58,7 +66,6 @@ QgsMapToolIdentifyAction::~QgsMapToolIdentifyAction()
{
mResultsDialog->done( 0 );
}
deleteRubberBands();
}

QgsIdentifyResultsDialog *QgsMapToolIdentifyAction::resultsDialog()
Expand All @@ -74,6 +81,26 @@ QgsIdentifyResultsDialog *QgsMapToolIdentifyAction::resultsDialog()
return mResultsDialog;
}

void QgsMapToolIdentifyAction::showAttributeTable( QgsMapLayer* layer, QList<const QgsFeature*> featureList )
{
resultsDialog()->clear();

QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( layer );
if ( !vl )
return;

QString filter = "$id IN (";
Q_FOREACH ( const QgsFeature* feature, featureList )
{
filter.append( QString( "%1," ).arg( feature->id() ) );
}
filter = filter.replace( QRegExp( ",$" ), ")" );

QgsAttributeTableDialog* tableDialog = new QgsAttributeTableDialog( vl );
tableDialog->setFilterExpression( filter );
tableDialog->show();
}

void QgsMapToolIdentifyAction::canvasMoveEvent( QMouseEvent *e )
{
Q_UNUSED( e );
Expand All @@ -90,12 +117,24 @@ void QgsMapToolIdentifyAction::canvasReleaseEvent( QMouseEvent *e )
connect( this, SIGNAL( identifyProgress( int, int ) ), QgisApp::instance(), SLOT( showProgress( int, int ) ) );
connect( this, SIGNAL( identifyMessage( QString ) ), QgisApp::instance(), SLOT( showStatusMessage( QString ) ) );

QList<IdentifyResult> results = QgsMapToolIdentify::identify( e->x(), e->y() );
identifyMenu()->setResultsIfExternalAction( false );

bool extendedMenu = e->modifiers() == Qt::ShiftModifier;
identifyMenu()->setExecWithSingleResult( extendedMenu );
identifyMenu()->setShowFeatureActions( extendedMenu );
IdentifyMode mode = extendedMenu ? LayerSelection : DefaultQgsSetting;

QList<IdentifyResult> results = QgsMapToolIdentify::identify( e->x(), e->y(), mode );

disconnect( this, SIGNAL( identifyProgress( int, int ) ), QgisApp::instance(), SLOT( showProgress( int, int ) ) );
disconnect( this, SIGNAL( identifyMessage( QString ) ), QgisApp::instance(), SLOT( showStatusMessage( QString ) ) );

if ( !results.isEmpty() )
if ( results.isEmpty() )
{
resultsDialog()->clear();
QgisApp::instance()->statusBar()->showMessage( tr( "No features at this position found." ) );
}
else
{
// Show the dialog before items are inserted so that items can resize themselves
// according to dialog size also the first time, see also #9377
Expand All @@ -111,11 +150,6 @@ void QgsMapToolIdentifyAction::canvasReleaseEvent( QMouseEvent *e )
// Call QgsIdentifyResultsDialog::show() to adjust with items
resultsDialog()->show();
}
else
{
resultsDialog()->clear();
QgisApp::instance()->statusBar()->showMessage( tr( "No features at this position found." ) );
}

// update possible view modes
resultsDialog()->updateViewModes();
Expand Down Expand Up @@ -145,7 +179,6 @@ void QgsMapToolIdentifyAction::deactivate()
{
resultsDialog()->deactivate();
QgsMapTool::deactivate();
deleteRubberBands();
}

QGis::UnitType QgsMapToolIdentifyAction::displayUnits()
Expand Down
5 changes: 5 additions & 0 deletions src/app/qgsmaptoolidentifyaction.h
Expand Up @@ -71,13 +71,18 @@ class APP_EXPORT QgsMapToolIdentifyAction : public QgsMapToolIdentify
void identifyMessage( QString );
void copyToClipboard( QgsFeatureStore & );

private slots:
void showAttributeTable( QgsMapLayer* layer, QList<const QgsFeature*> featureList );
private:
//! Pointer to the identify results dialog for name/value pairs
QPointer<QgsIdentifyResultsDialog> mResultsDialog;

QgsIdentifyResultsDialog *resultsDialog();

virtual QGis::UnitType displayUnits();

// pointers to the custom actions for identify menu
QAction* mAttributeTableAction;
};

#endif
3 changes: 3 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -166,6 +166,7 @@ qgsfilterlineedit.cpp
qgsformannotationitem.cpp
qgsgenericprojectionselector.cpp
qgshighlight.cpp
qgsidentifymenu.cpp
qgshtmlannotationitem.cpp
qgslegendinterface.cpp
qgsludialog.cpp
Expand Down Expand Up @@ -365,6 +366,7 @@ qgsfilterlineedit.h
qgsformannotationitem.h
qgsgenericprojectionselector.h
qgshtmlannotationitem.h
qgsidentifymenu.h
qgslegendinterface.h
qgslonglongvalidator.h
qgsludialog.h
Expand Down Expand Up @@ -451,6 +453,7 @@ qgsfiledropedit.h
qgsfilterlineedit.h
qgsgenericprojectionselector.h
qgshighlight.h
qgsidentifymenu.h
qgsmapcanvas.h
qgsmapcanvasitem.h
qgsmapcanvasmap.h
Expand Down

0 comments on commit 1fb524f

Please sign in to comment.