mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
MapToolIdentify moved to gui to make it accessible in python
put back convertMeasurement in gui as it is not app specific use display settings for specific app units
This commit is contained in:
parent
0ebc0586ba
commit
682524ff54
@ -39,6 +39,7 @@
|
|||||||
%Include qgsmaptip.sip
|
%Include qgsmaptip.sip
|
||||||
%Include qgsmaptool.sip
|
%Include qgsmaptool.sip
|
||||||
%Include qgsmaptoolemitpoint.sip
|
%Include qgsmaptoolemitpoint.sip
|
||||||
|
%Include qgsmaptoolidentify.sip
|
||||||
%Include qgsmaptoolpan.sip
|
%Include qgsmaptoolpan.sip
|
||||||
%Include qgsmaptooltouch.sip
|
%Include qgsmaptooltouch.sip
|
||||||
%Include qgsmaptoolzoom.sip
|
%Include qgsmaptoolzoom.sip
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <qgsmaptoolzoom.h>
|
#include <qgsmaptoolzoom.h>
|
||||||
#include <qgsmaptoolpan.h>
|
#include <qgsmaptoolpan.h>
|
||||||
#include <qgsmaptoolemitpoint.h>
|
#include <qgsmaptoolemitpoint.h>
|
||||||
|
#include <qgsmaptoolidentify.h>
|
||||||
%End
|
%End
|
||||||
|
|
||||||
%Feature HAVE_TOUCH
|
%Feature HAVE_TOUCH
|
||||||
@ -23,6 +24,8 @@ class QgsMapTool : QObject
|
|||||||
sipClass = sipClass_QgsMapToolPan;
|
sipClass = sipClass_QgsMapToolPan;
|
||||||
else if (dynamic_cast<QgsMapToolEmitPoint*>(sipCpp) != NULL)
|
else if (dynamic_cast<QgsMapToolEmitPoint*>(sipCpp) != NULL)
|
||||||
sipClass = sipClass_QgsMapToolEmitPoint;
|
sipClass = sipClass_QgsMapToolEmitPoint;
|
||||||
|
else if (dynamic_cast<QgsMapToolIdentify*>(sipCpp) != NULL)
|
||||||
|
sipClass = sipClass_QgsMapToolIdentify;
|
||||||
else
|
else
|
||||||
sipClass = NULL;
|
sipClass = NULL;
|
||||||
%End
|
%End
|
||||||
|
115
python/gui/qgsmaptoolidentify.sip
Normal file
115
python/gui/qgsmaptoolidentify.sip
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
|
||||||
|
class QgsMapToolIdentify : QgsMapTool
|
||||||
|
{
|
||||||
|
%TypeHeaderCode
|
||||||
|
#include <qgsmaptoolidentify.h>
|
||||||
|
%End
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum IdentifyMode
|
||||||
|
{
|
||||||
|
DefaultQgsSetting=-1,
|
||||||
|
ActiveLayer,
|
||||||
|
TopDownStopAtFirst,
|
||||||
|
TopDownAll,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum LayerType
|
||||||
|
{
|
||||||
|
AllLayers=-1,
|
||||||
|
VectorLayer,
|
||||||
|
RasterLayer,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VectorResult
|
||||||
|
{
|
||||||
|
VectorResult();
|
||||||
|
VectorResult(QgsVectorLayer* layer, QgsFeature feature, QMap< QString, QString > derivedAttributes);
|
||||||
|
QgsVectorLayer* mLayer;
|
||||||
|
QgsFeature mFeature;
|
||||||
|
QMap< QString, QString > mDerivedAttributes;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct RasterResult
|
||||||
|
{
|
||||||
|
RasterResult();
|
||||||
|
RasterResult( QgsRasterLayer* layer, QString label, QMap< QString, QString > attributes, QMap< QString, QString > derivedAttributes);
|
||||||
|
QgsRasterLayer* mLayer;
|
||||||
|
QString mLabel;
|
||||||
|
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 );
|
||||||
|
|
||||||
|
//! Overridden mouse move event
|
||||||
|
virtual void canvasMoveEvent( QMouseEvent * e );
|
||||||
|
|
||||||
|
//! Overridden mouse press event
|
||||||
|
virtual void canvasPressEvent( QMouseEvent * e );
|
||||||
|
|
||||||
|
//! Overridden mouse release event
|
||||||
|
virtual void canvasReleaseEvent( QMouseEvent * e );
|
||||||
|
|
||||||
|
virtual void activate();
|
||||||
|
|
||||||
|
virtual void deactivate();
|
||||||
|
|
||||||
|
//QgsMapLayer::LayerType LayerType;
|
||||||
|
|
||||||
|
/** Performs the identification.
|
||||||
|
@param x x coordinates of mouseEvent
|
||||||
|
@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);
|
||||||
|
|
||||||
|
/** Performs the identification.
|
||||||
|
To avoid beeing forced to specify IdentifyMode with a list of layers
|
||||||
|
this has been made private and two publics methods are offered
|
||||||
|
@param x x coordinates of mouseEvent
|
||||||
|
@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();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void identifyProgress( int, int );
|
||||||
|
void identifyMessage( QString );
|
||||||
|
|
||||||
|
private:
|
||||||
|
/** Performs the identification.
|
||||||
|
To avoid beeing forced to specify IdentifyMode with a list of layers
|
||||||
|
this has been made private and two publics methods are offered
|
||||||
|
@param x x coordinates of mouseEvent
|
||||||
|
@param y y coordinates of mouseEvent
|
||||||
|
@param mode Identification mode. Can use Qgis default settings or a defined mode.
|
||||||
|
@param layerList Performs the identification within the given list of layers.
|
||||||
|
@param layerType Only performs identification in a certain type of layers (raster, vector).
|
||||||
|
@return true if identification succeeded and a feature has been found, false otherwise.*/
|
||||||
|
bool identify(int x, int y, IdentifyMode mode, QList<QgsMapLayer*> layerList, LayerType layerType = AllLayers);
|
||||||
|
|
||||||
|
bool identifyLayer( QgsMapLayer *layer, int x, int y, LayerType layerType = AllLayers );
|
||||||
|
bool identifyRasterLayer( QgsRasterLayer *layer, int x, int y );
|
||||||
|
bool identifyVectorLayer( QgsVectorLayer *layer, int x, int y );
|
||||||
|
|
||||||
|
//! Private helper
|
||||||
|
virtual void convertMeasurement( QgsDistanceArea &calc, double &measure, QGis::UnitType &u, bool isArea );
|
||||||
|
|
||||||
|
/** Transforms the measurements of derived attributes in the desired units*/
|
||||||
|
virtual QGis::UnitType displayUnits();
|
||||||
|
};
|
@ -38,7 +38,7 @@ SET(QGIS_APP_SRCS
|
|||||||
qgsfieldcalculator.cpp
|
qgsfieldcalculator.cpp
|
||||||
qgsfieldsproperties.cpp
|
qgsfieldsproperties.cpp
|
||||||
qgsgraduatedsymboldialog.cpp
|
qgsgraduatedsymboldialog.cpp
|
||||||
qgsidentifyresults.cpp
|
qgsidentifyresultsdialog.cpp
|
||||||
qgsfeatureaction.cpp
|
qgsfeatureaction.cpp
|
||||||
qgslabeldialog.cpp
|
qgslabeldialog.cpp
|
||||||
qgslabelpropertydialog.cpp
|
qgslabelpropertydialog.cpp
|
||||||
@ -62,7 +62,7 @@ SET(QGIS_APP_SRCS
|
|||||||
qgsmaptoolhtmlannotation.cpp
|
qgsmaptoolhtmlannotation.cpp
|
||||||
qgsmaptoolpinlabels.cpp
|
qgsmaptoolpinlabels.cpp
|
||||||
qgsmaptoolshowhidelabels.cpp
|
qgsmaptoolshowhidelabels.cpp
|
||||||
qgsmaptoolidentify.cpp
|
qgsmaptoolidentifyaction.cpp
|
||||||
qgsmaptoollabel.cpp
|
qgsmaptoollabel.cpp
|
||||||
qgsmaptoolmeasureangle.cpp
|
qgsmaptoolmeasureangle.cpp
|
||||||
qgsmaptoolmovefeature.cpp
|
qgsmaptoolmovefeature.cpp
|
||||||
@ -203,7 +203,7 @@ SET (QGIS_APP_MOC_HDRS
|
|||||||
qgsformannotationdialog.h
|
qgsformannotationdialog.h
|
||||||
qgshtmlannotationdialog.h
|
qgshtmlannotationdialog.h
|
||||||
qgsgraduatedsymboldialog.h
|
qgsgraduatedsymboldialog.h
|
||||||
qgsidentifyresults.h
|
qgsidentifyresultsdialog.h
|
||||||
qgslabeldialog.h
|
qgslabeldialog.h
|
||||||
qgslabelengineconfigdialog.h
|
qgslabelengineconfigdialog.h
|
||||||
qgslabelinggui.h
|
qgslabelinggui.h
|
||||||
@ -222,7 +222,7 @@ SET (QGIS_APP_MOC_HDRS
|
|||||||
qgsmaptoolfeatureaction.h
|
qgsmaptoolfeatureaction.h
|
||||||
qgsmaptoolpinlabels.h
|
qgsmaptoolpinlabels.h
|
||||||
qgsmaptoolshowhidelabels.h
|
qgsmaptoolshowhidelabels.h
|
||||||
qgsmaptoolidentify.h
|
qgsmaptoolidentifyaction.h
|
||||||
qgsmaptoolmeasureangle.h
|
qgsmaptoolmeasureangle.h
|
||||||
qgsmaptoolmovefeature.h
|
qgsmaptoolmovefeature.h
|
||||||
qgsmaptoolmovelabel.h
|
qgsmaptoolmovelabel.h
|
||||||
|
@ -224,7 +224,7 @@
|
|||||||
#include "qgsmaptoolfeatureaction.h"
|
#include "qgsmaptoolfeatureaction.h"
|
||||||
#include "qgsmaptoolformannotation.h"
|
#include "qgsmaptoolformannotation.h"
|
||||||
#include "qgsmaptoolhtmlannotation.h"
|
#include "qgsmaptoolhtmlannotation.h"
|
||||||
#include "qgsmaptoolidentify.h"
|
#include "qgsmaptoolidentifyaction.h"
|
||||||
#include "qgsmaptoolmeasureangle.h"
|
#include "qgsmaptoolmeasureangle.h"
|
||||||
#include "qgsmaptoolmovefeature.h"
|
#include "qgsmaptoolmovefeature.h"
|
||||||
#include "qgsmaptoolrotatefeature.h"
|
#include "qgsmaptoolrotatefeature.h"
|
||||||
@ -1861,7 +1861,7 @@ void QgisApp::createCanvasTools()
|
|||||||
mMapTools.mTouch = new QgsMapToolTouch( mMapCanvas );
|
mMapTools.mTouch = new QgsMapToolTouch( mMapCanvas );
|
||||||
mMapTools.mTouch->setAction( mActionTouch );
|
mMapTools.mTouch->setAction( mActionTouch );
|
||||||
#endif
|
#endif
|
||||||
mMapTools.mIdentify = new QgsMapToolIdentify( mMapCanvas );
|
mMapTools.mIdentify = new QgsMapToolIdentifyAction( mMapCanvas );
|
||||||
mMapTools.mIdentify->setAction( mActionIdentify );
|
mMapTools.mIdentify->setAction( mActionIdentify );
|
||||||
mMapTools.mFeatureAction = new QgsMapToolFeatureAction( mMapCanvas );
|
mMapTools.mFeatureAction = new QgsMapToolFeatureAction( mMapCanvas );
|
||||||
mMapTools.mFeatureAction->setAction( mActionFeatureAction );
|
mMapTools.mFeatureAction->setAction( mActionFeatureAction );
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
#include "qgsfeatureaction.h"
|
#include "qgsfeatureaction.h"
|
||||||
#include "qgsvectorlayer.h"
|
#include "qgsvectorlayer.h"
|
||||||
#include "qgsvectordataprovider.h"
|
#include "qgsvectordataprovider.h"
|
||||||
#include "qgsidentifyresults.h"
|
#include "qgsidentifyresultsdialog.h"
|
||||||
#include "qgsattributedialog.h"
|
#include "qgsattributedialog.h"
|
||||||
#include "qgslogger.h"
|
#include "qgslogger.h"
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
* *
|
* *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
#include "qgsidentifyresults.h"
|
#include "qgsidentifyresultsdialog.h"
|
||||||
#include "qgsapplication.h"
|
#include "qgsapplication.h"
|
||||||
#include "qgisapp.h"
|
#include "qgisapp.h"
|
||||||
#include "qgsmaplayer.h"
|
#include "qgsmaplayer.h"
|
||||||
@ -114,7 +114,7 @@ class QgsIdentifyResultsDock : public QDockWidget
|
|||||||
// action
|
// action
|
||||||
// name value
|
// name value
|
||||||
|
|
||||||
QgsIdentifyResults::QgsIdentifyResults( QgsMapCanvas *canvas, QWidget *parent, Qt::WFlags f )
|
QgsIdentifyResultsDialog::QgsIdentifyResultsDialog( QgsMapCanvas *canvas, QWidget *parent, Qt::WFlags f )
|
||||||
: QDialog( parent, f )
|
: QDialog( parent, f )
|
||||||
, mActionPopup( 0 )
|
, mActionPopup( 0 )
|
||||||
, mCanvas( canvas )
|
, mCanvas( canvas )
|
||||||
@ -157,14 +157,14 @@ QgsIdentifyResults::QgsIdentifyResults( QgsMapCanvas *canvas, QWidget *parent, Q
|
|||||||
this, SLOT( printCurrentItem() ) );
|
this, SLOT( printCurrentItem() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsIdentifyResults::~QgsIdentifyResults()
|
QgsIdentifyResultsDialog::~QgsIdentifyResultsDialog()
|
||||||
{
|
{
|
||||||
clearHighlights();
|
clearHighlights();
|
||||||
if ( mActionPopup )
|
if ( mActionPopup )
|
||||||
delete mActionPopup;
|
delete mActionPopup;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTreeWidgetItem *QgsIdentifyResults::layerItem( QObject *layer )
|
QTreeWidgetItem *QgsIdentifyResultsDialog::layerItem( QObject *layer )
|
||||||
{
|
{
|
||||||
for ( int i = 0; i < lstResults->topLevelItemCount(); i++ )
|
for ( int i = 0; i < lstResults->topLevelItemCount(); i++ )
|
||||||
{
|
{
|
||||||
@ -177,7 +177,7 @@ QTreeWidgetItem *QgsIdentifyResults::layerItem( QObject *layer )
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsIdentifyResults::addFeature( QgsVectorLayer *vlayer,
|
void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer,
|
||||||
const QgsFeature &f,
|
const QgsFeature &f,
|
||||||
const QMap<QString, QString> &derivedAttributes )
|
const QMap<QString, QString> &derivedAttributes )
|
||||||
{
|
{
|
||||||
@ -290,7 +290,7 @@ void QgsIdentifyResults::addFeature( QgsVectorLayer *vlayer,
|
|||||||
highlightFeature( featItem );
|
highlightFeature( featItem );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsIdentifyResults::addFeature( QgsRasterLayer *layer,
|
void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer,
|
||||||
QString label,
|
QString label,
|
||||||
const QMap<QString, QString> &attributes,
|
const QMap<QString, QString> &attributes,
|
||||||
const QMap<QString, QString> &derivedAttributes )
|
const QMap<QString, QString> &derivedAttributes )
|
||||||
@ -345,7 +345,7 @@ void QgsIdentifyResults::addFeature( QgsRasterLayer *layer,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsIdentifyResults::editingToggled()
|
void QgsIdentifyResultsDialog::editingToggled()
|
||||||
{
|
{
|
||||||
QTreeWidgetItem *layItem = layerItem( sender() );
|
QTreeWidgetItem *layItem = layerItem( sender() );
|
||||||
QgsVectorLayer *vlayer = vectorLayer( layItem );
|
QgsVectorLayer *vlayer = vectorLayer( layItem );
|
||||||
@ -380,7 +380,7 @@ void QgsIdentifyResults::editingToggled()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Call to show the dialog box.
|
// Call to show the dialog box.
|
||||||
void QgsIdentifyResults::show()
|
void QgsIdentifyResultsDialog::show()
|
||||||
{
|
{
|
||||||
// Enforce a few things before showing the dialog box
|
// Enforce a few things before showing the dialog box
|
||||||
lstResults->sortItems( 0, Qt::AscendingOrder );
|
lstResults->sortItems( 0, Qt::AscendingOrder );
|
||||||
@ -424,7 +424,7 @@ void QgsIdentifyResults::show()
|
|||||||
|
|
||||||
// Slot called when user clicks the Close button
|
// Slot called when user clicks the Close button
|
||||||
// (saves the current window size/position)
|
// (saves the current window size/position)
|
||||||
void QgsIdentifyResults::close()
|
void QgsIdentifyResultsDialog::close()
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
@ -439,14 +439,14 @@ void QgsIdentifyResults::close()
|
|||||||
|
|
||||||
// Save the current window size/position before closing
|
// Save the current window size/position before closing
|
||||||
// from window menu or X in titlebar
|
// from window menu or X in titlebar
|
||||||
void QgsIdentifyResults::closeEvent( QCloseEvent *e )
|
void QgsIdentifyResultsDialog::closeEvent( QCloseEvent *e )
|
||||||
{
|
{
|
||||||
// We'll close in our own good time thanks...
|
// We'll close in our own good time thanks...
|
||||||
e->ignore();
|
e->ignore();
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsIdentifyResults::itemClicked( QTreeWidgetItem *item, int column )
|
void QgsIdentifyResultsDialog::itemClicked( QTreeWidgetItem *item, int column )
|
||||||
{
|
{
|
||||||
Q_UNUSED( column );
|
Q_UNUSED( column );
|
||||||
if ( item->data( 0, Qt::UserRole ).toString() == "edit" )
|
if ( item->data( 0, Qt::UserRole ).toString() == "edit" )
|
||||||
@ -464,7 +464,7 @@ void QgsIdentifyResults::itemClicked( QTreeWidgetItem *item, int column )
|
|||||||
// actions that can be applied to the data in the identify results
|
// actions that can be applied to the data in the identify results
|
||||||
// dialog box.
|
// dialog box.
|
||||||
|
|
||||||
void QgsIdentifyResults::contextMenuEvent( QContextMenuEvent* event )
|
void QgsIdentifyResultsDialog::contextMenuEvent( QContextMenuEvent* event )
|
||||||
{
|
{
|
||||||
QTreeWidgetItem *item = lstResults->itemAt( lstResults->viewport()->mapFrom( this, event->pos() ) );
|
QTreeWidgetItem *item = lstResults->itemAt( lstResults->viewport()->mapFrom( this, event->pos() ) );
|
||||||
// if the user clicked below the end of the attribute list, just return
|
// if the user clicked below the end of the attribute list, just return
|
||||||
@ -535,25 +535,25 @@ void QgsIdentifyResults::contextMenuEvent( QContextMenuEvent* event )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Save the current window location (store in ~/.qt/qgisrc)
|
// Save the current window location (store in ~/.qt/qgisrc)
|
||||||
void QgsIdentifyResults::saveWindowLocation()
|
void QgsIdentifyResultsDialog::saveWindowLocation()
|
||||||
{
|
{
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
settings.setValue( "/Windows/Identify/geometry", saveGeometry() );
|
settings.setValue( "/Windows/Identify/geometry", saveGeometry() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsIdentifyResults::setColumnText( int column, const QString & label )
|
void QgsIdentifyResultsDialog::setColumnText( int column, const QString & label )
|
||||||
{
|
{
|
||||||
QTreeWidgetItem* header = lstResults->headerItem();
|
QTreeWidgetItem* header = lstResults->headerItem();
|
||||||
header->setText( column, label );
|
header->setText( column, label );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsIdentifyResults::expandColumnsToFit()
|
void QgsIdentifyResultsDialog::expandColumnsToFit()
|
||||||
{
|
{
|
||||||
lstResults->resizeColumnToContents( 0 );
|
lstResults->resizeColumnToContents( 0 );
|
||||||
lstResults->resizeColumnToContents( 1 );
|
lstResults->resizeColumnToContents( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsIdentifyResults::clearHighlights()
|
void QgsIdentifyResultsDialog::clearHighlights()
|
||||||
{
|
{
|
||||||
foreach ( QgsHighlight *h, mHighlights )
|
foreach ( QgsHighlight *h, mHighlights )
|
||||||
{
|
{
|
||||||
@ -563,7 +563,7 @@ void QgsIdentifyResults::clearHighlights()
|
|||||||
mHighlights.clear();
|
mHighlights.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsIdentifyResults::clear()
|
void QgsIdentifyResultsDialog::clear()
|
||||||
{
|
{
|
||||||
for ( int i = 0; i < lstResults->topLevelItemCount(); i++ )
|
for ( int i = 0; i < lstResults->topLevelItemCount(); i++ )
|
||||||
{
|
{
|
||||||
@ -577,7 +577,7 @@ void QgsIdentifyResults::clear()
|
|||||||
mPrintToolButton->setHidden( true );
|
mPrintToolButton->setHidden( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsIdentifyResults::activate()
|
void QgsIdentifyResultsDialog::activate()
|
||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
foreach ( QgsRubberBand *rb, mRubberBands )
|
foreach ( QgsRubberBand *rb, mRubberBands )
|
||||||
@ -593,7 +593,7 @@ void QgsIdentifyResults::activate()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsIdentifyResults::deactivate()
|
void QgsIdentifyResultsDialog::deactivate()
|
||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
foreach ( QgsRubberBand *rb, mRubberBands )
|
foreach ( QgsRubberBand *rb, mRubberBands )
|
||||||
@ -603,7 +603,7 @@ void QgsIdentifyResults::deactivate()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsIdentifyResults::doAction( QTreeWidgetItem *item, int action )
|
void QgsIdentifyResultsDialog::doAction( QTreeWidgetItem *item, int action )
|
||||||
{
|
{
|
||||||
QTreeWidgetItem *featItem = featureItem( item );
|
QTreeWidgetItem *featItem = featureItem( item );
|
||||||
if ( !featItem )
|
if ( !featItem )
|
||||||
@ -633,7 +633,7 @@ void QgsIdentifyResults::doAction( QTreeWidgetItem *item, int action )
|
|||||||
layer->actions()->doAction( action, mFeatures[ featIdx ], idx );
|
layer->actions()->doAction( action, mFeatures[ featIdx ], idx );
|
||||||
}
|
}
|
||||||
|
|
||||||
QTreeWidgetItem *QgsIdentifyResults::featureItem( QTreeWidgetItem *item )
|
QTreeWidgetItem *QgsIdentifyResultsDialog::featureItem( QTreeWidgetItem *item )
|
||||||
{
|
{
|
||||||
if ( !item )
|
if ( !item )
|
||||||
return 0;
|
return 0;
|
||||||
@ -672,7 +672,7 @@ QTreeWidgetItem *QgsIdentifyResults::featureItem( QTreeWidgetItem *item )
|
|||||||
return featItem;
|
return featItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTreeWidgetItem *QgsIdentifyResults::layerItem( QTreeWidgetItem *item )
|
QTreeWidgetItem *QgsIdentifyResultsDialog::layerItem( QTreeWidgetItem *item )
|
||||||
{
|
{
|
||||||
if ( item && item->parent() )
|
if ( item && item->parent() )
|
||||||
{
|
{
|
||||||
@ -683,7 +683,7 @@ QTreeWidgetItem *QgsIdentifyResults::layerItem( QTreeWidgetItem *item )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QgsVectorLayer *QgsIdentifyResults::vectorLayer( QTreeWidgetItem *item )
|
QgsVectorLayer *QgsIdentifyResultsDialog::vectorLayer( QTreeWidgetItem *item )
|
||||||
{
|
{
|
||||||
item = layerItem( item );
|
item = layerItem( item );
|
||||||
if ( !item )
|
if ( !item )
|
||||||
@ -692,7 +692,7 @@ QgsVectorLayer *QgsIdentifyResults::vectorLayer( QTreeWidgetItem *item )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QTreeWidgetItem *QgsIdentifyResults::retrieveAttributes( QTreeWidgetItem *item, QgsAttributeMap &attributes, int &idx )
|
QTreeWidgetItem *QgsIdentifyResultsDialog::retrieveAttributes( QTreeWidgetItem *item, QgsAttributeMap &attributes, int &idx )
|
||||||
{
|
{
|
||||||
QTreeWidgetItem *featItem = featureItem( item );
|
QTreeWidgetItem *featItem = featureItem( item );
|
||||||
if ( !featItem )
|
if ( !featItem )
|
||||||
@ -714,13 +714,13 @@ QTreeWidgetItem *QgsIdentifyResults::retrieveAttributes( QTreeWidgetItem *item,
|
|||||||
return featItem;
|
return featItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsIdentifyResults::itemExpanded( QTreeWidgetItem *item )
|
void QgsIdentifyResultsDialog::itemExpanded( QTreeWidgetItem *item )
|
||||||
{
|
{
|
||||||
Q_UNUSED( item );
|
Q_UNUSED( item );
|
||||||
expandColumnsToFit();
|
expandColumnsToFit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsIdentifyResults::handleCurrentItemChanged( QTreeWidgetItem *current, QTreeWidgetItem *previous )
|
void QgsIdentifyResultsDialog::handleCurrentItemChanged( QTreeWidgetItem *current, QTreeWidgetItem *previous )
|
||||||
{
|
{
|
||||||
Q_UNUSED( previous );
|
Q_UNUSED( previous );
|
||||||
if ( !current )
|
if ( !current )
|
||||||
@ -745,7 +745,7 @@ void QgsIdentifyResults::handleCurrentItemChanged( QTreeWidgetItem *current, QTr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsIdentifyResults::layerDestroyed()
|
void QgsIdentifyResultsDialog::layerDestroyed()
|
||||||
{
|
{
|
||||||
QObject *theSender = sender();
|
QObject *theSender = sender();
|
||||||
|
|
||||||
@ -771,7 +771,7 @@ void QgsIdentifyResults::layerDestroyed()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsIdentifyResults::disconnectLayer( QObject *layer )
|
void QgsIdentifyResultsDialog::disconnectLayer( QObject *layer )
|
||||||
{
|
{
|
||||||
if ( !layer )
|
if ( !layer )
|
||||||
return;
|
return;
|
||||||
@ -792,7 +792,7 @@ void QgsIdentifyResults::disconnectLayer( QObject *layer )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsIdentifyResults::featureDeleted( QgsFeatureId fid )
|
void QgsIdentifyResultsDialog::featureDeleted( QgsFeatureId fid )
|
||||||
{
|
{
|
||||||
QTreeWidgetItem *layItem = layerItem( sender() );
|
QTreeWidgetItem *layItem = layerItem( sender() );
|
||||||
|
|
||||||
@ -822,7 +822,7 @@ void QgsIdentifyResults::featureDeleted( QgsFeatureId fid )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsIdentifyResults::attributeValueChanged( QgsFeatureId fid, int idx, const QVariant &val )
|
void QgsIdentifyResultsDialog::attributeValueChanged( QgsFeatureId fid, int idx, const QVariant &val )
|
||||||
{
|
{
|
||||||
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( sender() );
|
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( sender() );
|
||||||
QTreeWidgetItem *layItem = layerItem( sender() );
|
QTreeWidgetItem *layItem = layerItem( sender() );
|
||||||
@ -855,7 +855,7 @@ void QgsIdentifyResults::attributeValueChanged( QgsFeatureId fid, int idx, const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsIdentifyResults::highlightFeature( QTreeWidgetItem *item )
|
void QgsIdentifyResultsDialog::highlightFeature( QTreeWidgetItem *item )
|
||||||
{
|
{
|
||||||
QgsVectorLayer *layer = vectorLayer( item );
|
QgsVectorLayer *layer = vectorLayer( item );
|
||||||
if ( !layer )
|
if ( !layer )
|
||||||
@ -891,7 +891,7 @@ void QgsIdentifyResults::highlightFeature( QTreeWidgetItem *item )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsIdentifyResults::zoomToFeature()
|
void QgsIdentifyResultsDialog::zoomToFeature()
|
||||||
{
|
{
|
||||||
QTreeWidgetItem *item = lstResults->currentItem();
|
QTreeWidgetItem *item = lstResults->currentItem();
|
||||||
|
|
||||||
@ -929,7 +929,7 @@ void QgsIdentifyResults::zoomToFeature()
|
|||||||
mCanvas->refresh();
|
mCanvas->refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsIdentifyResults::featureForm()
|
void QgsIdentifyResultsDialog::featureForm()
|
||||||
{
|
{
|
||||||
QTreeWidgetItem *item = lstResults->currentItem();
|
QTreeWidgetItem *item = lstResults->currentItem();
|
||||||
|
|
||||||
@ -962,7 +962,7 @@ void QgsIdentifyResults::featureForm()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsIdentifyResults::highlightAll()
|
void QgsIdentifyResultsDialog::highlightAll()
|
||||||
{
|
{
|
||||||
for ( int i = 0; i < lstResults->topLevelItemCount(); i++ )
|
for ( int i = 0; i < lstResults->topLevelItemCount(); i++ )
|
||||||
{
|
{
|
||||||
@ -975,12 +975,12 @@ void QgsIdentifyResults::highlightAll()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsIdentifyResults::highlightLayer()
|
void QgsIdentifyResultsDialog::highlightLayer()
|
||||||
{
|
{
|
||||||
highlightLayer( lstResults->currentItem() );
|
highlightLayer( lstResults->currentItem() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsIdentifyResults::highlightLayer( QTreeWidgetItem *item )
|
void QgsIdentifyResultsDialog::highlightLayer( QTreeWidgetItem *item )
|
||||||
{
|
{
|
||||||
QTreeWidgetItem *layItem = layerItem( item );
|
QTreeWidgetItem *layItem = layerItem( item );
|
||||||
if ( !layItem )
|
if ( !layItem )
|
||||||
@ -994,12 +994,12 @@ void QgsIdentifyResults::highlightLayer( QTreeWidgetItem *item )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsIdentifyResults::layerProperties()
|
void QgsIdentifyResultsDialog::layerProperties()
|
||||||
{
|
{
|
||||||
layerProperties( lstResults->currentItem() );
|
layerProperties( lstResults->currentItem() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsIdentifyResults::layerProperties( QTreeWidgetItem *item )
|
void QgsIdentifyResultsDialog::layerProperties( QTreeWidgetItem *item )
|
||||||
{
|
{
|
||||||
QgsVectorLayer *vlayer = vectorLayer( item );
|
QgsVectorLayer *vlayer = vectorLayer( item );
|
||||||
if ( !vlayer )
|
if ( !vlayer )
|
||||||
@ -1008,17 +1008,17 @@ void QgsIdentifyResults::layerProperties( QTreeWidgetItem *item )
|
|||||||
QgisApp::instance()->showLayerProperties( vlayer );
|
QgisApp::instance()->showLayerProperties( vlayer );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsIdentifyResults::expandAll()
|
void QgsIdentifyResultsDialog::expandAll()
|
||||||
{
|
{
|
||||||
lstResults->expandAll();
|
lstResults->expandAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsIdentifyResults::collapseAll()
|
void QgsIdentifyResultsDialog::collapseAll()
|
||||||
{
|
{
|
||||||
lstResults->collapseAll();
|
lstResults->collapseAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsIdentifyResults::copyAttributeValue()
|
void QgsIdentifyResultsDialog::copyAttributeValue()
|
||||||
{
|
{
|
||||||
QClipboard *clipboard = QApplication::clipboard();
|
QClipboard *clipboard = QApplication::clipboard();
|
||||||
QString text = lstResults->currentItem()->data( 1, Qt::DisplayRole ).toString();
|
QString text = lstResults->currentItem()->data( 1, Qt::DisplayRole ).toString();
|
||||||
@ -1026,7 +1026,7 @@ void QgsIdentifyResults::copyAttributeValue()
|
|||||||
clipboard->setText( text );
|
clipboard->setText( text );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsIdentifyResults::copyFeatureAttributes()
|
void QgsIdentifyResultsDialog::copyFeatureAttributes()
|
||||||
{
|
{
|
||||||
QClipboard *clipboard = QApplication::clipboard();
|
QClipboard *clipboard = QApplication::clipboard();
|
||||||
QString text;
|
QString text;
|
||||||
@ -1054,7 +1054,7 @@ void QgsIdentifyResults::copyFeatureAttributes()
|
|||||||
clipboard->setText( text );
|
clipboard->setText( text );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsIdentifyResults::openUrl( const QUrl &url )
|
void QgsIdentifyResultsDialog::openUrl( const QUrl &url )
|
||||||
{
|
{
|
||||||
if ( !QDesktopServices::openUrl( url ) )
|
if ( !QDesktopServices::openUrl( url ) )
|
||||||
{
|
{
|
||||||
@ -1062,7 +1062,7 @@ void QgsIdentifyResults::openUrl( const QUrl &url )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsIdentifyResults::printCurrentItem()
|
void QgsIdentifyResultsDialog::printCurrentItem()
|
||||||
{
|
{
|
||||||
QTreeWidgetItem *item = lstResults->currentItem();
|
QTreeWidgetItem *item = lstResults->currentItem();
|
||||||
if ( !item )
|
if ( !item )
|
||||||
@ -1078,7 +1078,7 @@ void QgsIdentifyResults::printCurrentItem()
|
|||||||
wv->print( &printer );
|
wv->print( &printer );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsIdentifyResults:: on_mExpandNewToolButton_toggled( bool checked )
|
void QgsIdentifyResultsDialog:: on_mExpandNewToolButton_toggled( bool checked )
|
||||||
{
|
{
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
settings.setValue( "/Map/identifyExpand", checked );
|
settings.setValue( "/Map/identifyExpand", checked );
|
@ -15,8 +15,8 @@
|
|||||||
* (at your option) any later version. *
|
* (at your option) any later version. *
|
||||||
* *
|
* *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
#ifndef QGSIDENTIFYRESULTS_H
|
#ifndef QGSIDENTIFYRESULTSDIALOG_H
|
||||||
#define QGSIDENTIFYRESULTS_H
|
#define QGSIDENTIFYRESULTSDIALOG_H
|
||||||
|
|
||||||
#include "ui_qgsidentifyresultsbase.h"
|
#include "ui_qgsidentifyresultsbase.h"
|
||||||
#include "qgsattributeaction.h"
|
#include "qgsattributeaction.h"
|
||||||
@ -42,7 +42,7 @@ class QDockWidget;
|
|||||||
*@author Gary E.Sherman
|
*@author Gary E.Sherman
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class QgsIdentifyResults: public QDialog, private Ui::QgsIdentifyResultsBase
|
class QgsIdentifyResultsDialog: public QDialog, private Ui::QgsIdentifyResultsBase
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@ -50,9 +50,9 @@ class QgsIdentifyResults: public QDialog, private Ui::QgsIdentifyResultsBase
|
|||||||
|
|
||||||
//! Constructor - takes it own copy of the QgsAttributeAction so
|
//! Constructor - takes it own copy of the QgsAttributeAction so
|
||||||
// that it is independent of whoever created it.
|
// that it is independent of whoever created it.
|
||||||
QgsIdentifyResults( QgsMapCanvas *canvas, QWidget *parent = 0, Qt::WFlags f = 0 );
|
QgsIdentifyResultsDialog( QgsMapCanvas *canvas, QWidget *parent = 0, Qt::WFlags f = 0 );
|
||||||
|
|
||||||
~QgsIdentifyResults();
|
~QgsIdentifyResultsDialog();
|
||||||
|
|
||||||
/** Add add feature from vector layer */
|
/** Add add feature from vector layer */
|
||||||
void addFeature( QgsVectorLayer *layer,
|
void addFeature( QgsVectorLayer *layer,
|
139
src/app/qgsmaptoolidentifyaction.cpp
Normal file
139
src/app/qgsmaptoolidentifyaction.cpp
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
qgsmaptoolidentify.cpp - map tool for identifying features
|
||||||
|
---------------------
|
||||||
|
begin : January 2006
|
||||||
|
copyright : (C) 2006 by Martin Dobias
|
||||||
|
email : wonder.sk at gmail dot com
|
||||||
|
***************************************************************************
|
||||||
|
* *
|
||||||
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include "qgscursors.h"
|
||||||
|
#include "qgsdistancearea.h"
|
||||||
|
#include "qgsfeature.h"
|
||||||
|
#include "qgsfield.h"
|
||||||
|
#include "qgsgeometry.h"
|
||||||
|
#include "qgslogger.h"
|
||||||
|
#include "qgsidentifyresultsdialog.h"
|
||||||
|
#include "qgsmapcanvas.h"
|
||||||
|
#include "qgsmaptopixel.h"
|
||||||
|
#include "qgsmessageviewer.h"
|
||||||
|
#include "qgsmaptoolidentifyaction.h"
|
||||||
|
#include "qgsrasterlayer.h"
|
||||||
|
#include "qgscoordinatereferencesystem.h"
|
||||||
|
#include "qgsvectordataprovider.h"
|
||||||
|
#include "qgsvectorlayer.h"
|
||||||
|
#include "qgsproject.h"
|
||||||
|
#include "qgsmaplayerregistry.h"
|
||||||
|
#include "qgisapp.h"
|
||||||
|
#include "qgsrendererv2.h"
|
||||||
|
|
||||||
|
#include <QSettings>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QMouseEvent>
|
||||||
|
#include <QCursor>
|
||||||
|
#include <QPixmap>
|
||||||
|
#include <QStatusBar>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
|
QgsMapToolIdentifyAction::QgsMapToolIdentifyAction( QgsMapCanvas* canvas )
|
||||||
|
: QgsMapToolIdentify( canvas )
|
||||||
|
{
|
||||||
|
// set cursor
|
||||||
|
QPixmap myIdentifyQPixmap = QPixmap(( const char ** ) identify_cursor );
|
||||||
|
mCursor = QCursor( myIdentifyQPixmap, 1, 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
QgsMapToolIdentifyAction::~QgsMapToolIdentifyAction()
|
||||||
|
{
|
||||||
|
if ( mResultsDialog )
|
||||||
|
{
|
||||||
|
mResultsDialog->done( 0 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QgsIdentifyResultsDialog *QgsMapToolIdentifyAction::resultsDialog()
|
||||||
|
{
|
||||||
|
if ( !mResultsDialog )
|
||||||
|
mResultsDialog = new QgsIdentifyResultsDialog( mCanvas, mCanvas->window() );
|
||||||
|
|
||||||
|
return mResultsDialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgsMapToolIdentifyAction::canvasMoveEvent( QMouseEvent *e )
|
||||||
|
{
|
||||||
|
Q_UNUSED( e );
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgsMapToolIdentifyAction::canvasPressEvent( QMouseEvent *e )
|
||||||
|
{
|
||||||
|
Q_UNUSED( e );
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgsMapToolIdentifyAction::canvasReleaseEvent( QMouseEvent *e )
|
||||||
|
{
|
||||||
|
if ( !mCanvas || mCanvas->isDrawing() )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
resultsDialog()->clear();
|
||||||
|
|
||||||
|
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() );
|
||||||
|
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)
|
||||||
|
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);
|
||||||
|
|
||||||
|
if ( res )
|
||||||
|
{
|
||||||
|
resultsDialog()->show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QSettings mySettings;
|
||||||
|
bool myDockFlag = mySettings.value( "/qgis/dockIdentifyResults", false ).toBool();
|
||||||
|
if ( !myDockFlag )
|
||||||
|
{
|
||||||
|
resultsDialog()->hide();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
resultsDialog()->clear();
|
||||||
|
}
|
||||||
|
QgisApp::instance()->statusBar()->showMessage( tr( "No features at this position found." ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgsMapToolIdentifyAction::activate()
|
||||||
|
{
|
||||||
|
resultsDialog()->activate();
|
||||||
|
QgsMapTool::activate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgsMapToolIdentifyAction::deactivate()
|
||||||
|
{
|
||||||
|
resultsDialog()->deactivate();
|
||||||
|
QgsMapTool::deactivate();
|
||||||
|
}
|
||||||
|
|
||||||
|
QGis::UnitType QgsMapToolIdentifyAction::displayUnits()
|
||||||
|
{
|
||||||
|
// Get the units for display
|
||||||
|
QSettings settings;
|
||||||
|
return QGis::fromLiteral( settings.value( "/qgis/measure/displayunits", QGis::toLiteral( QGis::Meters ) ).toString() );
|
||||||
|
}
|
||||||
|
|
@ -13,11 +13,11 @@
|
|||||||
* *
|
* *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
#ifndef QGSMAPTOOLIDENTIFY_H
|
#ifndef QGSMAPTOOLIDENTIFYACTION_H
|
||||||
#define QGSMAPTOOLIDENTIFY_H
|
#define QGSMAPTOOLIDENTIFYACTION_H
|
||||||
|
|
||||||
#include "qgis.h"
|
#include "qgis.h"
|
||||||
#include "qgsmaptool.h"
|
#include "qgsmaptoolidentify.h"
|
||||||
#include "qgspoint.h"
|
#include "qgspoint.h"
|
||||||
#include "qgsfeature.h"
|
#include "qgsfeature.h"
|
||||||
#include "qgsdistancearea.h"
|
#include "qgsdistancearea.h"
|
||||||
@ -25,28 +25,28 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
|
||||||
class QgsIdentifyResults;
|
class QgsIdentifyResultsDialog;
|
||||||
class QgsMapLayer;
|
class QgsMapLayer;
|
||||||
class QgsRasterLayer;
|
class QgsRasterLayer;
|
||||||
class QgsRubberBand;
|
class QgsRubberBand;
|
||||||
class QgsVectorLayer;
|
class QgsVectorLayer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Map tool for identifying features in current layer
|
\brief Map tool for identifying features layers and showing results
|
||||||
|
|
||||||
after selecting a point shows dialog with identification results
|
after selecting a point shows dialog with identification results
|
||||||
- for raster layers shows value of underlying pixel
|
- for raster layers shows value of underlying pixel
|
||||||
- for vector layers shows feature attributes within search radius
|
- for vector layers shows feature attributes within search radius
|
||||||
(allows to edit values when vector layer is in editing mode)
|
(allows to edit values when vector layer is in editing mode)
|
||||||
*/
|
*/
|
||||||
class QgsMapToolIdentify : public QgsMapTool
|
class QgsMapToolIdentifyAction : public QgsMapToolIdentify
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QgsMapToolIdentify( QgsMapCanvas* canvas );
|
QgsMapToolIdentifyAction( QgsMapCanvas* canvas );
|
||||||
|
|
||||||
~QgsMapToolIdentify();
|
~QgsMapToolIdentifyAction();
|
||||||
|
|
||||||
//! Overridden mouse move event
|
//! Overridden mouse move event
|
||||||
virtual void canvasMoveEvent( QMouseEvent * e );
|
virtual void canvasMoveEvent( QMouseEvent * e );
|
||||||
@ -71,17 +71,16 @@ class QgsMapToolIdentify : public QgsMapTool
|
|||||||
bool identifyVectorLayer( QgsVectorLayer *layer, int x, int y );
|
bool identifyVectorLayer( QgsVectorLayer *layer, int x, int y );
|
||||||
|
|
||||||
//! Pointer to the identify results dialog for name/value pairs
|
//! Pointer to the identify results dialog for name/value pairs
|
||||||
QPointer<QgsIdentifyResults> mResults;
|
QPointer<QgsIdentifyResultsDialog> mResultsDialog;
|
||||||
|
|
||||||
//! Private helper
|
|
||||||
void convertMeasurement( QgsDistanceArea &calc, double &measure, QGis::UnitType &u, bool isArea );
|
|
||||||
|
|
||||||
void addFeature( QgsMapLayer *layer, int fid,
|
void addFeature( QgsMapLayer *layer, int fid,
|
||||||
QString displayField, QString displayValue,
|
QString displayField, QString displayValue,
|
||||||
const QMap< QString, QString > &attributes,
|
const QMap< QString, QString > &attributes,
|
||||||
const QMap< QString, QString > &derivedAttributes );
|
const QMap< QString, QString > &derivedAttributes );
|
||||||
|
|
||||||
QgsIdentifyResults *results();
|
QgsIdentifyResultsDialog *resultsDialog();
|
||||||
|
|
||||||
|
virtual QGis::UnitType displayUnits();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -72,6 +72,7 @@ qgsmapoverviewcanvas.cpp
|
|||||||
qgsmaptip.cpp
|
qgsmaptip.cpp
|
||||||
qgsmaptool.cpp
|
qgsmaptool.cpp
|
||||||
qgsmaptoolemitpoint.cpp
|
qgsmaptoolemitpoint.cpp
|
||||||
|
qgsmaptoolidentify.cpp
|
||||||
qgsmaptoolpan.cpp
|
qgsmaptoolpan.cpp
|
||||||
qgsmaptoolzoom.cpp
|
qgsmaptoolzoom.cpp
|
||||||
qgsmessagebar.cpp
|
qgsmessagebar.cpp
|
||||||
@ -169,6 +170,7 @@ qgsmanageconnectionsdialog.h
|
|||||||
qgsmapcanvas.h
|
qgsmapcanvas.h
|
||||||
qgsmapoverviewcanvas.h
|
qgsmapoverviewcanvas.h
|
||||||
qgsmaptoolemitpoint.h
|
qgsmaptoolemitpoint.h
|
||||||
|
qgsmaptoolidentify.h
|
||||||
qgsmessagebar.h
|
qgsmessagebar.h
|
||||||
qgsmessageviewer.h
|
qgsmessageviewer.h
|
||||||
qgsmessagelogviewer.h
|
qgsmessagelogviewer.h
|
||||||
@ -213,6 +215,7 @@ qgsmapcanvassnapper.h
|
|||||||
qgsmapoverviewcanvas.h
|
qgsmapoverviewcanvas.h
|
||||||
qgsmaptool.h
|
qgsmaptool.h
|
||||||
qgsmaptoolemitpoint.h
|
qgsmaptoolemitpoint.h
|
||||||
|
qgsmaptoolidentify.h
|
||||||
qgsmaptoolpan.h
|
qgsmaptoolpan.h
|
||||||
qgsmaptoolzoom.h
|
qgsmaptoolzoom.h
|
||||||
qgsmessagebar.h
|
qgsmessagebar.h
|
||||||
|
@ -19,18 +19,17 @@
|
|||||||
#include "qgsfield.h"
|
#include "qgsfield.h"
|
||||||
#include "qgsgeometry.h"
|
#include "qgsgeometry.h"
|
||||||
#include "qgslogger.h"
|
#include "qgslogger.h"
|
||||||
#include "qgsidentifyresults.h"
|
|
||||||
#include "qgsmapcanvas.h"
|
#include "qgsmapcanvas.h"
|
||||||
|
#include "qgsmaptoolidentify.h"
|
||||||
#include "qgsmaptopixel.h"
|
#include "qgsmaptopixel.h"
|
||||||
#include "qgsmessageviewer.h"
|
#include "qgsmessageviewer.h"
|
||||||
#include "qgsmaptoolidentify.h"
|
#include "qgsmaplayer.h"
|
||||||
#include "qgsrasterlayer.h"
|
#include "qgsrasterlayer.h"
|
||||||
#include "qgscoordinatereferencesystem.h"
|
#include "qgscoordinatereferencesystem.h"
|
||||||
#include "qgsvectordataprovider.h"
|
#include "qgsvectordataprovider.h"
|
||||||
#include "qgsvectorlayer.h"
|
#include "qgsvectorlayer.h"
|
||||||
#include "qgsproject.h"
|
#include "qgsproject.h"
|
||||||
#include "qgsmaplayerregistry.h"
|
#include "qgsmaplayerregistry.h"
|
||||||
#include "qgisapp.h"
|
|
||||||
#include "qgsrendererv2.h"
|
#include "qgsrendererv2.h"
|
||||||
|
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
@ -51,18 +50,6 @@ QgsMapToolIdentify::QgsMapToolIdentify( QgsMapCanvas* canvas )
|
|||||||
|
|
||||||
QgsMapToolIdentify::~QgsMapToolIdentify()
|
QgsMapToolIdentify::~QgsMapToolIdentify()
|
||||||
{
|
{
|
||||||
if ( mResults )
|
|
||||||
{
|
|
||||||
mResults->done( 0 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QgsIdentifyResults *QgsMapToolIdentify::results()
|
|
||||||
{
|
|
||||||
if ( !mResults )
|
|
||||||
mResults = new QgsIdentifyResults( mCanvas, mCanvas->window() );
|
|
||||||
|
|
||||||
return mResults;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsMapToolIdentify::canvasMoveEvent( QMouseEvent *e )
|
void QgsMapToolIdentify::canvasMoveEvent( QMouseEvent *e )
|
||||||
@ -77,48 +64,72 @@ void QgsMapToolIdentify::canvasPressEvent( QMouseEvent *e )
|
|||||||
|
|
||||||
void QgsMapToolIdentify::canvasReleaseEvent( QMouseEvent *e )
|
void QgsMapToolIdentify::canvasReleaseEvent( QMouseEvent *e )
|
||||||
{
|
{
|
||||||
if ( !mCanvas || mCanvas->isDrawing() )
|
Q_UNUSED( e );
|
||||||
{
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
results()->clear();
|
bool QgsMapToolIdentify::identify(int x, int y, QList<QgsMapLayer *> layerList, IdentifyMode mode)
|
||||||
|
{
|
||||||
|
return identify(x, y, mode, layerList, AllLayers);
|
||||||
|
}
|
||||||
|
|
||||||
QSettings settings;
|
bool QgsMapToolIdentify::identify(int x, int y, IdentifyMode mode, LayerType layerType)
|
||||||
int identifyMode = settings.value( "/Map/identifyMode", 0 ).toInt();
|
{
|
||||||
|
return identify(x, y, mode, QList<QgsMapLayer*>(), layerType);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool QgsMapToolIdentify::identify(int x, int y, IdentifyMode mode, QList<QgsMapLayer*> layerList, LayerType layerType )
|
||||||
|
{
|
||||||
bool res = false;
|
bool res = false;
|
||||||
|
|
||||||
if ( identifyMode == 0 )
|
if ( !mCanvas || mCanvas->isDrawing() )
|
||||||
|
{
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
mResultData.mVectorResults.clear();
|
||||||
|
mResultData.mRasterResults.clear();
|
||||||
|
|
||||||
|
if (mode == DefaultQgsSetting)
|
||||||
|
{
|
||||||
|
QSettings settings;
|
||||||
|
mode = static_cast<IdentifyMode>( settings.value( "/Map/identifyMode", 0 ).toInt() );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( mode == ActiveLayer && ~layerList.isEmpty())
|
||||||
{
|
{
|
||||||
QgsMapLayer *layer = mCanvas->currentLayer();
|
QgsMapLayer *layer = mCanvas->currentLayer();
|
||||||
|
|
||||||
if ( !layer )
|
if ( !layer )
|
||||||
{
|
{
|
||||||
QMessageBox::warning( mCanvas,
|
emit identifyMessage( tr( "No active layer. To identify features, you must choose an active layer." ) );
|
||||||
tr( "No active layer" ),
|
return res;
|
||||||
tr( "To identify features, you must choose an active layer by clicking on its name in the legend" ) );
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QApplication::setOverrideCursor( Qt::WaitCursor );
|
QApplication::setOverrideCursor( Qt::WaitCursor );
|
||||||
|
|
||||||
res = identifyLayer( layer, e->x(), e->y() );
|
res = identifyLayer( layer, x, y, layerType );
|
||||||
|
|
||||||
QApplication::restoreOverrideCursor();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
connect( this, SIGNAL( identifyProgress( int, int ) ), QgisApp::instance(), SLOT( showProgress( int, int ) ) );
|
|
||||||
connect( this, SIGNAL( identifyMessage( QString ) ), QgisApp::instance(), SLOT( showStatusMessage( QString ) ) );
|
|
||||||
|
|
||||||
QApplication::setOverrideCursor( Qt::WaitCursor );
|
QApplication::setOverrideCursor( Qt::WaitCursor );
|
||||||
|
|
||||||
QStringList noIdentifyLayerIdList = QgsProject::instance()->readListEntry( "Identify", "/disabledLayers" );
|
QStringList noIdentifyLayerIdList = QgsProject::instance()->readListEntry( "Identify", "/disabledLayers" );
|
||||||
|
|
||||||
for ( int i = 0; i < mCanvas->layerCount(); i++ )
|
int layerCount;
|
||||||
|
if (layerList.isEmpty())
|
||||||
|
layerCount = mCanvas->layerCount();
|
||||||
|
else
|
||||||
|
layerCount = layerList.count();
|
||||||
|
|
||||||
|
|
||||||
|
for ( int i = 0; i < layerCount; i++ )
|
||||||
{
|
{
|
||||||
QgsMapLayer *layer = mCanvas->layer( i );
|
|
||||||
|
QgsMapLayer *layer ;
|
||||||
|
if (layerList.isEmpty())
|
||||||
|
layer = mCanvas->layer( i );
|
||||||
|
else
|
||||||
|
layer = layerList.value( i );
|
||||||
|
|
||||||
emit identifyProgress( i, mCanvas->layerCount() );
|
emit identifyProgress( i, mCanvas->layerCount() );
|
||||||
emit identifyMessage( tr( "Identifying on %1..." ).arg( layer->name() ) );
|
emit identifyMessage( tr( "Identifying on %1..." ).arg( layer->name() ) );
|
||||||
@ -126,69 +137,47 @@ void QgsMapToolIdentify::canvasReleaseEvent( QMouseEvent *e )
|
|||||||
if ( noIdentifyLayerIdList.contains( layer->id() ) )
|
if ( noIdentifyLayerIdList.contains( layer->id() ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ( identifyLayer( layer, e->x(), e->y() ) )
|
if ( identifyLayer( layer, x, y, layerType ) )
|
||||||
{
|
{
|
||||||
res = true;
|
res = true;
|
||||||
if ( identifyMode == 1 )
|
if ( mode == TopDownStopAtFirst )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emit identifyProgress( mCanvas->layerCount(), mCanvas->layerCount() );
|
emit identifyProgress( mCanvas->layerCount(), mCanvas->layerCount() );
|
||||||
emit identifyMessage( tr( "Identifying done." ) );
|
emit identifyMessage( tr( "Identifying done." ) );
|
||||||
|
|
||||||
disconnect( this, SIGNAL( identifyProgress( int, int ) ), QgisApp::instance(), SLOT( showProgress( int, int ) ) );
|
|
||||||
disconnect( this, SIGNAL( identifyMessage( QString ) ), QgisApp::instance(), SLOT( showStatusMessage( QString ) ) );
|
|
||||||
|
|
||||||
QApplication::restoreOverrideCursor();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( res )
|
QApplication::restoreOverrideCursor();
|
||||||
{
|
|
||||||
results()->show();
|
return res;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
QSettings mySettings;
|
|
||||||
bool myDockFlag = mySettings.value( "/qgis/dockIdentifyResults", false ).toBool();
|
|
||||||
if ( !myDockFlag )
|
|
||||||
{
|
|
||||||
results()->hide();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
results()->clear();
|
|
||||||
}
|
|
||||||
QgisApp::instance()->statusBar()->showMessage( tr( "No features at this position found." ) );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsMapToolIdentify::activate()
|
void QgsMapToolIdentify::activate()
|
||||||
{
|
{
|
||||||
results()->activate();
|
|
||||||
QgsMapTool::activate();
|
QgsMapTool::activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsMapToolIdentify::deactivate()
|
void QgsMapToolIdentify::deactivate()
|
||||||
{
|
{
|
||||||
results()->deactivate();
|
|
||||||
QgsMapTool::deactivate();
|
QgsMapTool::deactivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QgsMapToolIdentify::identifyLayer( QgsMapLayer *layer, int x, int y )
|
bool QgsMapToolIdentify::identifyLayer( QgsMapLayer *layer, int x, int y, LayerType layerType )
|
||||||
{
|
{
|
||||||
bool res = false;
|
if ( layer->type() == QgsMapLayer::RasterLayer && (layerType==AllLayers || layerType==RasterLayer))
|
||||||
|
|
||||||
if ( layer->type() == QgsMapLayer::RasterLayer )
|
|
||||||
{
|
{
|
||||||
res = identifyRasterLayer( qobject_cast<QgsRasterLayer *>( layer ), x, y );
|
return identifyRasterLayer( qobject_cast<QgsRasterLayer *>( layer ), x, y );
|
||||||
|
}
|
||||||
|
else if ( layer->type() == QgsMapLayer::VectorLayer && (layerType==AllLayers || layerType==VectorLayer))
|
||||||
|
{
|
||||||
|
return identifyVectorLayer( qobject_cast<QgsVectorLayer *>( layer ), x, y );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
res = identifyVectorLayer( qobject_cast<QgsVectorLayer *>( layer ), x, y );
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -333,7 +322,7 @@ bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, int x, int
|
|||||||
|
|
||||||
derivedAttributes.insert( tr( "feature id" ), fid < 0 ? tr( "new feature" ) : FID_TO_STRING( fid ) );
|
derivedAttributes.insert( tr( "feature id" ), fid < 0 ? tr( "new feature" ) : FID_TO_STRING( fid ) );
|
||||||
|
|
||||||
results()->addFeature( layer, *f_it, derivedAttributes );
|
mResultData.mVectorResults.append( VectorResult(layer, *f_it, derivedAttributes));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( renderer && renderer->capabilities() & QgsFeatureRendererV2::ScaleDependent )
|
if ( renderer && renderer->capabilities() & QgsFeatureRendererV2::ScaleDependent )
|
||||||
@ -415,13 +404,12 @@ bool QgsMapToolIdentify::identifyRasterLayer( QgsRasterLayer *layer, int x, int
|
|||||||
if ( attributes.size() > 0 )
|
if ( attributes.size() > 0 )
|
||||||
{
|
{
|
||||||
derivedAttributes.insert( tr( "(clicked coordinate)" ), idPoint.toString() );
|
derivedAttributes.insert( tr( "(clicked coordinate)" ), idPoint.toString() );
|
||||||
results()->addFeature( layer, type, attributes, derivedAttributes );
|
mResultData.mRasterResults.append( RasterResult(layer, type, attributes, derivedAttributes));
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void QgsMapToolIdentify::convertMeasurement( QgsDistanceArea &calc, double &measure, QGis::UnitType &u, bool isArea )
|
void QgsMapToolIdentify::convertMeasurement( QgsDistanceArea &calc, double &measure, QGis::UnitType &u, bool isArea )
|
||||||
{
|
{
|
||||||
// Helper for converting between meters and feet
|
// Helper for converting between meters and feet
|
||||||
@ -430,10 +418,16 @@ void QgsMapToolIdentify::convertMeasurement( QgsDistanceArea &calc, double &meas
|
|||||||
// Get the canvas units
|
// Get the canvas units
|
||||||
QGis::UnitType myUnits = mCanvas->mapUnits();
|
QGis::UnitType myUnits = mCanvas->mapUnits();
|
||||||
|
|
||||||
// Get the units for display
|
calc.convertMeasurement( measure, myUnits, displayUnits(), isArea );
|
||||||
QSettings settings;
|
|
||||||
QGis::UnitType displayUnits = QGis::fromLiteral( settings.value( "/qgis/measure/displayunits", QGis::toLiteral( QGis::Meters ) ).toString() );
|
|
||||||
|
|
||||||
calc.convertMeasurement( measure, myUnits, displayUnits, isArea );
|
|
||||||
u = myUnits;
|
u = myUnits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QGis::UnitType QgsMapToolIdentify::displayUnits()
|
||||||
|
{
|
||||||
|
return mCanvas->mapUnits();
|
||||||
|
}
|
||||||
|
|
||||||
|
QgsMapToolIdentify::IdentifyResults &QgsMapToolIdentify::results()
|
||||||
|
{
|
||||||
|
return mResultData;
|
||||||
|
}
|
161
src/gui/qgsmaptoolidentify.h
Normal file
161
src/gui/qgsmaptoolidentify.h
Normal file
@ -0,0 +1,161 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
qgsmaptoolidentify.h - map tool for identifying features
|
||||||
|
---------------------
|
||||||
|
begin : January 2006
|
||||||
|
copyright : (C) 2006 by Martin Dobias
|
||||||
|
email : wonder.sk at gmail dot com
|
||||||
|
***************************************************************************
|
||||||
|
* *
|
||||||
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#ifndef QGSMAPTOOLIDENTIFY_H
|
||||||
|
#define QGSMAPTOOLIDENTIFY_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "qgsmaptool.h"
|
||||||
|
#include "qgspoint.h"
|
||||||
|
#include "qgsfeature.h"
|
||||||
|
#include "qgsdistancearea.h"
|
||||||
|
#include "qgsmaplayer.h"
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QPointer>
|
||||||
|
|
||||||
|
class QgsRasterLayer;
|
||||||
|
class QgsVectorLayer;
|
||||||
|
class QgsMapCanvas;
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Map tool for identifying features in layers
|
||||||
|
|
||||||
|
after selecting a point, performs the identification:
|
||||||
|
- for raster layers shows value of underlying pixel
|
||||||
|
- for vector layers shows feature attributes within search radius
|
||||||
|
(allows to edit values when vector layer is in editing mode)
|
||||||
|
*/
|
||||||
|
class QgsMapToolIdentify : public QgsMapTool
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
enum IdentifyMode
|
||||||
|
{
|
||||||
|
DefaultQgsSetting=-1,
|
||||||
|
ActiveLayer,
|
||||||
|
TopDownStopAtFirst,
|
||||||
|
TopDownAll
|
||||||
|
};
|
||||||
|
|
||||||
|
enum LayerType
|
||||||
|
{
|
||||||
|
AllLayers=-1,
|
||||||
|
VectorLayer,
|
||||||
|
RasterLayer
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VectorResult
|
||||||
|
{
|
||||||
|
VectorResult(){}
|
||||||
|
VectorResult(QgsVectorLayer * layer, QgsFeature feature, QMap< QString, QString > derivedAttributes):
|
||||||
|
mLayer( layer ), mFeature( feature ), mDerivedAttributes( derivedAttributes ) {}
|
||||||
|
QgsVectorLayer* mLayer;
|
||||||
|
QgsFeature mFeature;
|
||||||
|
QMap< QString, QString > mDerivedAttributes;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct RasterResult
|
||||||
|
{
|
||||||
|
RasterResult(){}
|
||||||
|
RasterResult( QgsRasterLayer * layer, QString label, QMap< QString, QString > attributes, QMap< QString, QString > derivedAttributes):
|
||||||
|
mLayer( layer ), mLabel( label ), mAttributes( attributes ), mDerivedAttributes( derivedAttributes ) {}
|
||||||
|
QgsRasterLayer* mLayer;
|
||||||
|
QString mLabel;
|
||||||
|
QMap< QString, QString > mAttributes;
|
||||||
|
QMap< QString, QString > mDerivedAttributes;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct IdentifyResults
|
||||||
|
{
|
||||||
|
IdentifyResults(){}
|
||||||
|
IdentifyResults ( QList<VectorResult> vectorResults , QList<RasterResult> rasterResults) :
|
||||||
|
mVectorResults( vectorResults),
|
||||||
|
mRasterResults( rasterResults )
|
||||||
|
{}
|
||||||
|
QList<VectorResult> mVectorResults;
|
||||||
|
QList<RasterResult> mRasterResults;
|
||||||
|
};
|
||||||
|
|
||||||
|
//! constructor
|
||||||
|
QgsMapToolIdentify( QgsMapCanvas* canvas );
|
||||||
|
|
||||||
|
virtual ~QgsMapToolIdentify();
|
||||||
|
|
||||||
|
//! Overridden mouse move event
|
||||||
|
virtual void canvasMoveEvent( QMouseEvent * e );
|
||||||
|
|
||||||
|
//! Overridden mouse press event
|
||||||
|
virtual void canvasPressEvent( QMouseEvent * e );
|
||||||
|
|
||||||
|
//! Overridden mouse release event
|
||||||
|
virtual void canvasReleaseEvent( QMouseEvent * e );
|
||||||
|
|
||||||
|
virtual void activate();
|
||||||
|
|
||||||
|
virtual void deactivate();
|
||||||
|
|
||||||
|
/** Performs the identification.
|
||||||
|
@param x x coordinates of mouseEvent
|
||||||
|
@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);
|
||||||
|
|
||||||
|
/** Performs the identification.
|
||||||
|
To avoid beeing forced to specify IdentifyMode with a list of layers
|
||||||
|
this has been made private and two publics methods are offered
|
||||||
|
@param x x coordinates of mouseEvent
|
||||||
|
@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();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void identifyProgress( int, int );
|
||||||
|
void identifyMessage( QString );
|
||||||
|
|
||||||
|
private:
|
||||||
|
/** Performs the identification.
|
||||||
|
To avoid beeing forced to specify IdentifyMode with a list of layers
|
||||||
|
this has been made private and two publics methods are offered
|
||||||
|
@param x x coordinates of mouseEvent
|
||||||
|
@param y y coordinates of mouseEvent
|
||||||
|
@param mode Identification mode. Can use Qgis default settings or a defined mode.
|
||||||
|
@param layerList Performs the identification within the given list of layers.
|
||||||
|
@param layerType Only performs identification in a certain type of layers (raster, vector).
|
||||||
|
@return true if identification succeeded and a feature has been found, false otherwise.*/
|
||||||
|
bool identify(int x, int y, IdentifyMode mode, QList<QgsMapLayer*> layerList, LayerType layerType = AllLayers);
|
||||||
|
bool identifyLayer( QgsMapLayer *layer, int x, int y, LayerType layerType = AllLayers );
|
||||||
|
bool identifyRasterLayer( QgsRasterLayer *layer, int x, int y );
|
||||||
|
bool identifyVectorLayer( QgsVectorLayer *layer, int x, int y );
|
||||||
|
|
||||||
|
//! Private helper
|
||||||
|
virtual void convertMeasurement( QgsDistanceArea &calc, double &measure, QGis::UnitType &u, bool isArea );
|
||||||
|
|
||||||
|
/** Transforms the measurements of derived attributes in the desired units*/
|
||||||
|
virtual QGis::UnitType displayUnits();
|
||||||
|
|
||||||
|
IdentifyResults mResultData;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
x
Reference in New Issue
Block a user