Skip to content
Permalink
Browse files

improved identify menu with a dedicated class

  • Loading branch information
3nids committed Sep 16, 2014
1 parent aa95ae4 commit 1fb524f1195251833edef4637a619cb76ec37ead
@@ -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
@@ -51,7 +51,7 @@ class QwtPlotCurve;

class APP_EXPORT QgsIdentifyResultsWebView : public QWebView
{
Q_OBJECT;
Q_OBJECT
public:
QgsIdentifyResultsWebView( QWidget *parent = 0 );
QSize sizeHint() const;
@@ -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"
@@ -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()
@@ -58,7 +66,6 @@ QgsMapToolIdentifyAction::~QgsMapToolIdentifyAction()
{
mResultsDialog->done( 0 );
}
deleteRubberBands();
}

QgsIdentifyResultsDialog *QgsMapToolIdentifyAction::resultsDialog()
@@ -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 );
@@ -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
@@ -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();
@@ -145,7 +179,6 @@ void QgsMapToolIdentifyAction::deactivate()
{
resultsDialog()->deactivate();
QgsMapTool::deactivate();
deleteRubberBands();
}

QGis::UnitType QgsMapToolIdentifyAction::displayUnits()
@@ -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
@@ -166,6 +166,7 @@ qgsfilterlineedit.cpp
qgsformannotationitem.cpp
qgsgenericprojectionselector.cpp
qgshighlight.cpp
qgsidentifymenu.cpp
qgshtmlannotationitem.cpp
qgslegendinterface.cpp
qgsludialog.cpp
@@ -365,6 +366,7 @@ qgsfilterlineedit.h
qgsformannotationitem.h
qgsgenericprojectionselector.h
qgshtmlannotationitem.h
qgsidentifymenu.h
qgslegendinterface.h
qgslonglongvalidator.h
qgsludialog.h
@@ -451,6 +453,7 @@ qgsfiledropedit.h
qgsfilterlineedit.h
qgsgenericprojectionselector.h
qgshighlight.h
qgsidentifymenu.h
qgsmapcanvas.h
qgsmapcanvasitem.h
qgsmapcanvasmap.h

0 comments on commit 1fb524f

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