Skip to content
Permalink
Browse files
Merge remote branch '3nids/maptoolidentify_returnresults'
  • Loading branch information
blazek committed Feb 7, 2013
2 parents 863da7d + d97f05e commit 4e64d72cbf4eb6735d9fe35b5d6e76633c2a0034
@@ -20,36 +20,26 @@ class QgsMapToolIdentify : QgsMapTool
VectorLayer,
RasterLayer,
};

struct VectorResult
{
VectorResult();
VectorResult(QgsVectorLayer* layer, QgsFeature feature, QMap< QString, QString > derivedAttributes);
QgsVectorLayer* mLayer;
QgsFeature mFeature;
QMap< QString, QString > mDerivedAttributes;
};

struct RasterResult

struct IdentifyResult
{
RasterResult();
RasterResult( QgsRasterLayer * layer, QString label, QgsFields fields, QgsFeature feature, QMap< QString, QString > derivedAttributes );
QgsRasterLayer* mLayer;
IdentifyResult();

IdentifyResult( QgsMapLayer * layer, QgsFeature feature, QMap< QString, QString > derivedAttributes );

IdentifyResult( QgsMapLayer * layer, QString label, QMap< QString, QString > attributes, QMap< QString, QString > derivedAttributes );

IdentifyResult( QgsMapLayer * layer, QString label, QgsFields fields, QgsFeature feature, QMap< QString, QString > derivedAttributes );

QgsMapLayer* mLayer;
QString mLabel;
QgsFields mFields;
QgsFeature mFeature;
QMap< QString, QString > mAttributes;
QMap< QString, QString > mDerivedAttributes;
};

struct IdentifyResults
{
IdentifyResults();
IdentifyResults ( QList<QgsMapToolIdentify::VectorResult> vectorResults , QList<QgsMapToolIdentify::RasterResult> rasterResults);
QList<QgsMapToolIdentify::VectorResult> mVectorResults;
QList<QgsMapToolIdentify::RasterResult> mRasterResults;
};

//! constructor
QgsMapToolIdentify( QgsMapCanvas* canvas );

@@ -73,8 +63,8 @@ class QgsMapToolIdentify : QgsMapTool
@param y y coordinates of mouseEvent
@param layerList Performs the identification within the given list of layers. Default value is an empty list, i.e. uses all the layers.
@param mode Identification mode. Can use Qgis default settings or a defined mode. Default mode is DefaultQgsSetting.
@return true if identification succeeded and a feature has been found, false otherwise.*/
bool identify(int x, int y, QList<QgsMapLayer*> layerList = QList<QgsMapLayer*>(), IdentifyMode mode = DefaultQgsSetting);
@return a list of IdentifyResult*/
QList<QgsMapToolIdentify::IdentifyResult> identify(int x, int y, QList<QgsMapLayer*> layerList = QList<QgsMapLayer*>(), IdentifyMode mode = DefaultQgsSetting);

/** Performs the identification.
To avoid beeing forced to specify IdentifyMode with a list of layers
@@ -83,11 +73,8 @@ class QgsMapToolIdentify : QgsMapTool
@param y y coordinates of mouseEvent
@param mode Identification mode. Can use Qgis default settings or a defined mode.
@param layerType Only performs identification in a certain type of layers (raster, vector). Default value is AllLayers.
@return true if identification succeeded and a feature has been found, false otherwise.*/
bool identify(int x, int y, IdentifyMode mode, LayerType layerType = AllLayers);

/** Access to results */
IdentifyResults &results();
@return a list of IdentifyResult*/
QList<QgsMapToolIdentify::IdentifyResult> identify(int x, int y, IdentifyMode mode, LayerType layerType = AllLayers);

signals:
void identifyProgress( int, int );
@@ -23,7 +23,7 @@
#include <QPair>
#include <QAction>

class QgsIdentifyResults;
class QgsIdentifyResultsDialog;
class QgsVectorLayer;
class QgsHighlight;
class QgsAttributeDialog;
@@ -292,9 +292,19 @@ QTreeWidgetItem *QgsIdentifyResultsDialog::layerItem( QObject *layer )
return 0;
}

void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer,
const QgsFeature &f,
const QMap<QString, QString> &derivedAttributes )
void QgsIdentifyResultsDialog::addFeature( QgsMapToolIdentify::IdentifyResult result )
{
if ( result.mLayer->type() == QgsMapLayer::VectorLayer )
{
addFeature( qobject_cast<QgsVectorLayer *>( result.mLayer ), result.mFeature, result.mDerivedAttributes );
}
else if ( result.mLayer->type() == QgsMapLayer::RasterLayer )
{
addFeature( qobject_cast<QgsRasterLayer *>( result.mLayer ), result.mLabel, result.mAttributes, result.mDerivedAttributes, result.mFields, result.mFeature );
}
}

void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer, const QgsFeature &f, const QMap<QString, QString> &derivedAttributes )
{
QTreeWidgetItem *layItem = layerItem( vlayer );

@@ -24,6 +24,7 @@
#include "qgsfeature.h"
#include "qgsfeaturestore.h"
#include "qgsfield.h"
#include "qgsmaptoolidentify.h"
#include "qgscoordinatereferencesystem.h"

#include <QWidget>
@@ -101,18 +102,21 @@ class QgsIdentifyResultsDialog: public QDialog, private Ui::QgsIdentifyResultsBa
~QgsIdentifyResultsDialog();

/** Add add feature from vector layer */
void addFeature( QgsVectorLayer *layer,
void addFeature( QgsVectorLayer * layer,
const QgsFeature &f,
const QMap< QString, QString > &derivedAttributes );

/** Add add feature from other layer */
void addFeature( QgsRasterLayer *layer,
void addFeature( QgsRasterLayer * layer,
QString label,
const QMap< QString, QString > &attributes,
const QMap< QString, QString > &derivedAttributes,
const QgsFields &fields = QgsFields(),
const QgsFeature &feature = QgsFeature() );

/** Add feature from identify results */
void addFeature( QgsMapToolIdentify::IdentifyResult result );

/** map tool was deactivated */
void deactivate();

@@ -41,14 +41,14 @@
#include <QStatusBar>
#include <QVariant>

QgsMapToolIdentifyAction::QgsMapToolIdentifyAction( QgsMapCanvas* canvas )
QgsMapToolIdentifyAction::QgsMapToolIdentifyAction( QgsMapCanvas * canvas )
: QgsMapToolIdentify( canvas )
{
// set cursor
QPixmap myIdentifyQPixmap = QPixmap(( const char ** ) identify_cursor );
mCursor = QCursor( myIdentifyQPixmap, 1, 1 );

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

QgsMapToolIdentifyAction::~QgsMapToolIdentifyAction()
@@ -93,23 +93,18 @@ 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 ) ) );
bool res = QgsMapToolIdentify::identify( e->x(), e->y() );
QList<IdentifyResult> results = QgsMapToolIdentify::identify( e->x(), e->y() );
disconnect( this, SIGNAL( identifyProgress( int, int ) ), QgisApp::instance(), SLOT( showProgress( int, int ) ) );
disconnect( this, SIGNAL( identifyMessage( QString ) ), QgisApp::instance(), SLOT( showStatusMessage( QString ) ) );


QList<VectorResult>::const_iterator vresult;
for ( vresult = results().mVectorResults.begin(); vresult != results().mVectorResults.end(); ++vresult )
QList<IdentifyResult>::const_iterator result;
for ( result = results.begin(); result != results.end(); ++result )
{
resultsDialog()->addFeature( vresult->mLayer, vresult->mFeature, vresult->mDerivedAttributes );
}
QList<RasterResult>::const_iterator rresult;
for ( rresult = results().mRasterResults.begin(); rresult != results().mRasterResults.end(); ++rresult )
{
resultsDialog()->addFeature( rresult->mLayer, rresult->mLabel, rresult->mAttributes, rresult->mDerivedAttributes, rresult->mFields, rresult->mFeature );
resultsDialog()->addFeature( *result );
}

if ( res )
if ( !results.isEmpty() )
{
resultsDialog()->show();
}
@@ -129,14 +124,17 @@ void QgsMapToolIdentifyAction::canvasReleaseEvent( QMouseEvent *e )
}
}

void QgsMapToolIdentifyAction::handleChangedRasterResults( QList<RasterResult>& rasterResults )
void QgsMapToolIdentifyAction::handleChangedRasterResults( QList<IdentifyResult> &results )
{
// Add new result after raster format change
QgsDebugMsg( QString( "%1 raster results" ).arg( rasterResults.size() ) );
QList<RasterResult>::const_iterator rresult;
for ( rresult = rasterResults.begin(); rresult != rasterResults.end(); ++rresult )
QgsDebugMsg( QString( "%1 raster results" ).arg( results.size() ) );
QList<IdentifyResult>::const_iterator rresult;
for ( rresult = results.begin(); rresult != results.end(); ++rresult )
{
resultsDialog()->addFeature( rresult->mLayer, rresult->mLabel, rresult->mAttributes, rresult->mDerivedAttributes, rresult->mFields, rresult->mFeature );
if ( rresult->mLayer->type() == QgsMapLayer::RasterLayer )
{
resultsDialog()->addFeature( qobject_cast<QgsRasterLayer *>( rresult->mLayer ), rresult->mLabel, rresult->mAttributes, rresult->mDerivedAttributes, rresult->mFields, rresult->mFeature );
}
}
}

@@ -46,7 +46,7 @@ class QgsMapToolIdentifyAction : public QgsMapToolIdentify
Q_OBJECT

public:
QgsMapToolIdentifyAction( QgsMapCanvas* canvas );
QgsMapToolIdentifyAction( QgsMapCanvas * canvas );

~QgsMapToolIdentifyAction();

@@ -65,7 +65,7 @@ class QgsMapToolIdentifyAction : public QgsMapToolIdentify

public slots:
void handleCopyToClipboard( QgsFeatureStore & );
void handleChangedRasterResults( QList<RasterResult>& rasterResults );
void handleChangedRasterResults( QList<IdentifyResult>& results );

signals:
void identifyProgress( int, int );
Loading

0 comments on commit 4e64d72

Please sign in to comment.