spatial query plugin: fix warnings, reindent, include in debian package

git-svn-id: http://svn.osgeo.org/qgis/trunk@13360 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
jef 2010-04-24 09:00:25 +00:00
parent e0ec67b2fe
commit 3d2b177143
18 changed files with 1016 additions and 1014 deletions

3
debian/changelog vendored
View File

@ -5,8 +5,9 @@ qgis (1.5.0) UNRELEASED; urgency=low
* require CMake >2.6 and Qt 4.4 for sid
* remove circular dependencies
* integrate new GRASS raster provider
* add spatialquery plugin
-- Jürgen E. Fischer <jef@norbit.de> Thu, 04 Feb 2010 23:20:29 +0100
-- Jürgen E. Fischer <jef@norbit.de> Sat, 24 Apr 2010 10:57:21 +0200
qgis (1.4.0) UNRELEASED; urgency=low

1
debian/qgis.install vendored
View File

@ -26,6 +26,7 @@ usr/lib/qgis/libevis.so
usr/lib/qgis/libosmprovider.so
usr/lib/qgis/librasterterrainplugin.so
usr/lib/qgis/liblabelingplugin.so
usr/lib/qgis/libspatialqueryplugin.so
usr/share/pixmaps/qgis-icon.xpm
usr/share/pixmaps/qgis-mime-icon.png
usr/share/pixmaps/qgis-mime-icon.png usr/share/icons/crystalsvg/128x128/mimetypes

2
debian/rules vendored
View File

@ -10,7 +10,7 @@ DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
DISTRIBUTION := $(shell dpkg-parsechangelog --format rfc822 | sed -ne "s/^Distribution: //p")
ifneq ($(DISTRIBUTION),$(findstring $(DISTRIBUTION),"lenny hardy intrepid jaunty karmic"))
ifneq ($(DISTRIBUTION),$(findstring $(DISTRIBUTION),"lenny hardy intrepid jaunty karmic lucid"))
DISTRIBUTION := sid
endif

View File

@ -14,11 +14,6 @@ SET (SPATIALQUERY_SRCS
SET (SPATIALQUERY_MOC_HDRS
qgsspatialqueryplugin.h
qgsspatialquerydialog.h
qgsspatialquery.h
qgsreaderfeatures.h
qgsrubberselectid.h
qgsgeometrycoordinatetransform.h
qgsmngprogressbar.h
)
SET( SPATIALQUERY_UIS qgsspatialquerydialogbase.ui)

View File

@ -23,33 +23,33 @@
QgsGeometryCoordinateTransform::~QgsGeometryCoordinateTransform()
{
delete mCoordTransform;
delete mCoordTransform;
} // QgsGeometryCoordinateTransform::~QgsGeometryCoordinateTransform()
void QgsGeometryCoordinateTransform::setCoordinateTransform(QgsVectorLayer* lyrTarget, QgsVectorLayer* lyrReference)
void QgsGeometryCoordinateTransform::setCoordinateTransform( QgsVectorLayer* lyrTarget, QgsVectorLayer* lyrReference )
{
// Transform Forward: Target to Reference
// * Use srs() to use old versions QGis - will be deprecited in 2.0 (after use crs())
QgsCoordinateReferenceSystem srsTarget = lyrTarget->srs();
QgsCoordinateReferenceSystem srsReference = lyrReference->srs();
// Transform Forward: Target to Reference
// * Use srs() to use old versions QGis - will be deprecited in 2.0 (after use crs())
QgsCoordinateReferenceSystem srsTarget = lyrTarget->srs();
QgsCoordinateReferenceSystem srsReference = lyrReference->srs();
mCoordTransform = new QgsCoordinateTransform(srsTarget, srsReference);
mCoordTransform = new QgsCoordinateTransform( srsTarget, srsReference );
mFuncTransform = ( srsTarget != srsReference)
mFuncTransform = ( srsTarget != srsReference )
? &QgsGeometryCoordinateTransform::setGeomTransform
: &QgsGeometryCoordinateTransform::setNoneGeomTransform;
} // void QgsGeometryCoordinateTransform::setCoordinateTransform(QgsVectorLayer* lyrTarget, QgsVectorLayer* lyrReference)
void QgsGeometryCoordinateTransform::transform(QgsGeometry *geom)
void QgsGeometryCoordinateTransform::transform( QgsGeometry *geom )
{
(this->*mFuncTransform)(geom);
( this->*mFuncTransform )( geom );
} // void QgsGeometryCoordinateTransform::transformCoordenate()
void QgsGeometryCoordinateTransform::setGeomTransform(QgsGeometry *geom)
void QgsGeometryCoordinateTransform::setGeomTransform( QgsGeometry *geom )
{
geom->transform(*mCoordTransform);
geom->transform( *mCoordTransform );
} // void QgsGeometryCoordinateTransform::setGeomTransform(QgsGeometry *geom)

View File

@ -29,44 +29,44 @@
*/
class QgsGeometryCoordinateTransform
{
public:
public:
/**
* \brief Constructor for a Geometry Coordinate Transform.
*
*/
QgsGeometryCoordinateTransform () {};
QgsGeometryCoordinateTransform() {};
/**
* \brief Destructor
*/
~QgsGeometryCoordinateTransform ();
~QgsGeometryCoordinateTransform();
/**
* \brief Sets the coordinate reference system the target and reference layer
* \param lyrTarget target layer.
* \param lyrReference reference layer.
*/
void setCoordinateTransform(QgsVectorLayer* lyrTarget, QgsVectorLayer* lyrReference);
void setCoordinateTransform( QgsVectorLayer* lyrTarget, QgsVectorLayer* lyrReference );
/**
* \brief Transform the coordinates reference system of the geometry, if target have the different system of reference
* \param geom Geometry
*/
void transform(QgsGeometry *geom);
private:
void transform( QgsGeometry *geom );
private:
/**
* \brief Transform the coordinates reference system of the geometry (use by transform)
* \param geom Geometry
*/
void setGeomTransform(QgsGeometry *geom);
void setGeomTransform( QgsGeometry *geom );
/**
* \brief None transform the coordinates reference system of the geometry (use by transform)
* \param geom Geometry
*/
void setNoneGeomTransform(QgsGeometry *geom) {};
void setNoneGeomTransform( QgsGeometry *geom ) {};
QgsCoordinateTransform * mCoordTransform;
void (QgsGeometryCoordinateTransform::* mFuncTransform)(QgsGeometry *);
void ( QgsGeometryCoordinateTransform::* mFuncTransform )( QgsGeometry * );
};
#endif // GEOMETRYCOORDINATETRANSFORM_H

View File

@ -19,32 +19,32 @@
#include "qgsmngprogressbar.h"
MngProgressBar::MngProgressBar(QProgressBar *pb)
MngProgressBar::MngProgressBar( QProgressBar *pb )
{
mPb = pb;
mPb->reset();
mPb = pb;
mPb->reset();
} // MngProgressBar::MngProgressBar(QProgressBar *pb)
void MngProgressBar::init(int minimum, int maximum)
void MngProgressBar::init( int minimum, int maximum )
{
mPb->reset();
mPb->setRange(minimum, maximum);
mPb->reset();
mPb->setRange( minimum, maximum );
} // void MngProgressBar::init(int minimum, int maximum)
void MngProgressBar::setFormat(QString format)
void MngProgressBar::setFormat( QString format )
{
// special caracters:
// %p - is replaced by the percentage completed.
// %v - is replaced by the current value.
// %m - is replaced by the total number of steps.
mPb->setFormat(format);
mPb->setFormat( format );
} // void MngProgressBar::setFormat(QString format)
void MngProgressBar::step(int step)
void MngProgressBar::step( int step )
{
mPb->setValue(step);
mPb->repaint();
mPb->setValue( step );
mPb->repaint();
} // void MngProgressBar::step()

View File

@ -27,39 +27,39 @@
*/
class MngProgressBar
{
public:
public:
/**
* \brief Constructor for a MngProgressBar.
* \param pb Pointer to the MngProgressBar object.
*/
MngProgressBar(QProgressBar *pb);
MngProgressBar( QProgressBar *pb );
/**
* \brief Destructor
*/
~MngProgressBar() { mPb->reset(); };
/**
* \brief Sets the progress bar's minimum and maximum values to minimum and maximum respectively
* \param minimum minimun value.
* \param maximum maximum value.
*/
void init(int minimum, int maximum);
void init( int minimum, int maximum );
/**
* \brief Sets the format the current text.
* \param format This property holds the string used to generate the current text.
*/
void setFormat(QString format);
void setFormat( QString format );
/**
* \brief Sets current value progress bar's
* \param step current value
*/
void step(int step );
void step( int step );
private:
private:
QProgressBar * mPb;
};
#endif // QGSMNGPROGRESSBAR_H

View File

@ -1,88 +1,88 @@
/***************************************************************************
qgsreaderfeatures.cpp
-------------------
begin : Dec 29, 2009
copyright : (C) 2009 by Diego Moreira And Luiz Motta
email : moreira.geo at gmail.com And motta.luiz at gmail.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. *
* *
***************************************************************************/
/* $Id: $ */
#include <qgsvectordataprovider.h>
#include "qgsreaderfeatures.h"
QgsReaderFeatures::QgsReaderFeatures(QgsVectorLayer *layer, bool useSelection)
{
mLayer = layer;
initReader(useSelection);
} // QgsReaderFeatures::QgsReaderFeatures(QgsVectorLayer *layer, bool useSelection)
QgsReaderFeatures::~QgsReaderFeatures()
{
if ( mListSelectedFeature.count() > 0 )
{
mListSelectedFeature.clear();
}
} // QgsReaderFeatures::~QgsReaderFeatures()
bool QgsReaderFeatures::nextFeature(QgsFeature & feature)
{
return (this->*mFuncNextFeature)(feature);
} // bool QgsReaderFeatures::nextFeature(QgsFeature & feature)
void QgsReaderFeatures::initReader(bool useSelection)
{
if ( useSelection )
{
mListSelectedFeature = mLayer->selectedFeatures();
mIterSelectedFeature = mListSelectedFeature.begin();
mFuncNextFeature = &QgsReaderFeatures::nextFeatureSelected;
}
else
{
QgsAttributeList attListGeom;
int idGeom = 0;
attListGeom.append(idGeom);
mLayer->select(attListGeom, mLayer->extent(), true, false);
mFuncNextFeature = &QgsReaderFeatures::nextFeatureTotal;
}
} // void QgsReaderFeatures::initReader()
bool QgsReaderFeatures::nextFeatureTotal ( QgsFeature & feature )
{
return mLayer->dataProvider()->nextFeature(feature);
} // bool QgsReaderFeatures::nextFeatureTotal ( QgsFeature & feature )
bool QgsReaderFeatures::nextFeatureSelected ( QgsFeature & feature )
{
bool bReturn = true;
if ( mIterSelectedFeature == mListSelectedFeature.end() )
{
bReturn = false;
}
else
{
feature = *mIterSelectedFeature;
mIterSelectedFeature++;
}
return bReturn;
} // bool QgsReaderFeatures::nextFeatureSelected( QgsFeature &feature )
/***************************************************************************
qgsreaderfeatures.cpp
-------------------
begin : Dec 29, 2009
copyright : (C) 2009 by Diego Moreira And Luiz Motta
email : moreira.geo at gmail.com And motta.luiz at gmail.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. *
* *
***************************************************************************/
/* $Id: $ */
#include <qgsvectordataprovider.h>
#include "qgsreaderfeatures.h"
QgsReaderFeatures::QgsReaderFeatures( QgsVectorLayer *layer, bool useSelection )
{
mLayer = layer;
initReader( useSelection );
} // QgsReaderFeatures::QgsReaderFeatures(QgsVectorLayer *layer, bool useSelection)
QgsReaderFeatures::~QgsReaderFeatures()
{
if ( mListSelectedFeature.count() > 0 )
{
mListSelectedFeature.clear();
}
} // QgsReaderFeatures::~QgsReaderFeatures()
bool QgsReaderFeatures::nextFeature( QgsFeature & feature )
{
return ( this->*mFuncNextFeature )( feature );
} // bool QgsReaderFeatures::nextFeature(QgsFeature & feature)
void QgsReaderFeatures::initReader( bool useSelection )
{
if ( useSelection )
{
mListSelectedFeature = mLayer->selectedFeatures();
mIterSelectedFeature = mListSelectedFeature.begin();
mFuncNextFeature = &QgsReaderFeatures::nextFeatureSelected;
}
else
{
QgsAttributeList attListGeom;
int idGeom = 0;
attListGeom.append( idGeom );
mLayer->select( attListGeom, mLayer->extent(), true, false );
mFuncNextFeature = &QgsReaderFeatures::nextFeatureTotal;
}
} // void QgsReaderFeatures::initReader()
bool QgsReaderFeatures::nextFeatureTotal( QgsFeature & feature )
{
return mLayer->dataProvider()->nextFeature( feature );
} // bool QgsReaderFeatures::nextFeatureTotal ( QgsFeature & feature )
bool QgsReaderFeatures::nextFeatureSelected( QgsFeature & feature )
{
bool bReturn = true;
if ( mIterSelectedFeature == mListSelectedFeature.end() )
{
bReturn = false;
}
else
{
feature = *mIterSelectedFeature;
mIterSelectedFeature++;
}
return bReturn;
} // bool QgsReaderFeatures::nextFeatureSelected( QgsFeature &feature )

View File

@ -1,78 +1,78 @@
/***************************************************************************
qgsreaderfeatures.h
-------------------
begin : Dec 29, 2009
copyright : (C) 2009 by Diego Moreira And Luiz Motta
email : moreira.geo at gmail.com And motta.luiz at gmail.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. *
* *
***************************************************************************/
/* $Id: $ */
#ifndef READERFEATURES_H
#define READERFEATURES_H
#include <qgsvectorlayer.h>
#include <qgsfeature.h>
/**
* \class QgsReaderFeatures
* \brief Reader Features
*/
class QgsReaderFeatures
{
public:
/**
* \brief Constructor for a Reader Features.
* \param layer Pointer to the layer.
* \param useSelection Use or not use the features selected
*/
QgsReaderFeatures(QgsVectorLayer *layer, bool useSelection);
/**
* \brief Destructor
*/
~QgsReaderFeatures();
/**
* \brief Next feature
* \param feature reference to next Feature.
* \returns True if has next feature.
*/
bool nextFeature(QgsFeature & feature);
private:
/**
* \brief init Reader
* \param useSelection Use or not use the features selected
*/
void initReader(bool useSelection);
/**
* \brief Next feature, not using the features selected
* \param feature reference to next Feature.
* \returns True if has next feature.
*/
bool nextFeatureTotal(QgsFeature & feature);
/**
* \brief Next feature, using the features selected
* \param feature reference to next Feature.
* \returns True if has next feature.
*/
bool nextFeatureSelected(QgsFeature & feature);
QgsVectorLayer * mLayer;
QgsFeatureList mListSelectedFeature;
QList<QgsFeature>::iterator mIterSelectedFeature;
bool (QgsReaderFeatures::* mFuncNextFeature) ( QgsFeature &);
};
#endif // READERFEATURES_H
/***************************************************************************
qgsreaderfeatures.h
-------------------
begin : Dec 29, 2009
copyright : (C) 2009 by Diego Moreira And Luiz Motta
email : moreira.geo at gmail.com And motta.luiz at gmail.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. *
* *
***************************************************************************/
/* $Id: $ */
#ifndef READERFEATURES_H
#define READERFEATURES_H
#include <qgsvectorlayer.h>
#include <qgsfeature.h>
/**
* \class QgsReaderFeatures
* \brief Reader Features
*/
class QgsReaderFeatures
{
public:
/**
* \brief Constructor for a Reader Features.
* \param layer Pointer to the layer.
* \param useSelection Use or not use the features selected
*/
QgsReaderFeatures( QgsVectorLayer *layer, bool useSelection );
/**
* \brief Destructor
*/
~QgsReaderFeatures();
/**
* \brief Next feature
* \param feature reference to next Feature.
* \returns True if has next feature.
*/
bool nextFeature( QgsFeature & feature );
private:
/**
* \brief init Reader
* \param useSelection Use or not use the features selected
*/
void initReader( bool useSelection );
/**
* \brief Next feature, not using the features selected
* \param feature reference to next Feature.
* \returns True if has next feature.
*/
bool nextFeatureTotal( QgsFeature & feature );
/**
* \brief Next feature, using the features selected
* \param feature reference to next Feature.
* \returns True if has next feature.
*/
bool nextFeatureSelected( QgsFeature & feature );
QgsVectorLayer * mLayer;
QgsFeatureList mListSelectedFeature;
QList<QgsFeature>::iterator mIterSelectedFeature;
bool ( QgsReaderFeatures::* mFuncNextFeature )( QgsFeature & );
};
#endif // READERFEATURES_H

View File

@ -22,62 +22,62 @@
#include "qgsfeature.h"
QgsRubberSelectId::QgsRubberSelectId( QgsMapCanvas* mapCanvas)
QgsRubberSelectId::QgsRubberSelectId( QgsMapCanvas* mapCanvas )
{
mIsPolygon = true;
mMapCanvas = mapCanvas;
mRubberBand = new QgsRubberBand( mMapCanvas, mIsPolygon );
mIsPolygon = true;
mMapCanvas = mapCanvas;
mRubberBand = new QgsRubberBand( mMapCanvas, mIsPolygon );
} // QgsRubberSelectId::QgsRubberSelectId( QgsMapCanvas* mapCanvas, bool isPolygon = true )
QgsRubberSelectId::~QgsRubberSelectId()
{
reset();
delete mRubberBand;
reset();
delete mRubberBand;
} // QgsRubberSelectId::~QgsRubberSelectId()
void QgsRubberSelectId::isGeometryNotPolygon(bool isPolygon = false)
void QgsRubberSelectId::isGeometryNotPolygon( bool isPolygon = false )
{
reset();
delete mRubberBand;
mIsPolygon = isPolygon;
mRubberBand = new QgsRubberBand( mMapCanvas, mIsPolygon );
reset();
delete mRubberBand;
mIsPolygon = isPolygon;
mRubberBand = new QgsRubberBand( mMapCanvas, mIsPolygon );
} // void QgsRubberSelectId::isGeometryNotPolygon(bool isPolygon)
void QgsRubberSelectId::reset()
{
mRubberBand->reset( mIsPolygon );
mRubberBand->reset( mIsPolygon );
} // void QgsRubberSelectId::reset()
void QgsRubberSelectId::setColor(int colorRed, int colorGreen, int colorBlue, int width, float alfa = 0)
void QgsRubberSelectId::setColor( int colorRed, int colorGreen, int colorBlue, int width, float alfa = 0 )
{
QColor color = QColor( colorRed, colorGreen, colorBlue );
color.setAlpha( alfa );
mRubberBand->setColor( color );
mRubberBand->setWidth( width );
QColor color = QColor( colorRed, colorGreen, colorBlue );
color.setAlpha( alfa );
mRubberBand->setColor( color );
mRubberBand->setWidth( width );
} // void QgsRubberSelectId::setColor(int colorRed, int colorGreen, int colorBlue, float alfa, width)
void QgsRubberSelectId::addFeature( QgsVectorLayer* mLayer, int fid )
{
QgsFeature feat;
if ( !mLayer->featureAtId( fid, feat, true, false ) )
{
return;
}
if ( !feat.geometry() )
{
return;
}
QgsFeature feat;
if ( !mLayer->featureAtId( fid, feat, true, false ) )
{
return;
}
if ( !feat.geometry() )
{
return;
}
mRubberBand->setToGeometry( feat.geometry(), mLayer );
mRubberBand->setToGeometry( feat.geometry(), mLayer );
} // void QgsRubberSelectId::addFeature( QgsVectorLayer* mLayer, int Id )
void QgsRubberSelectId::show()
{
mRubberBand->show();
mRubberBand->show();
} // QgsRubberSelectId::show()

View File

@ -30,12 +30,12 @@
*/
class QgsRubberSelectId
{
public:
public:
/**
* Constructor for a class RubberSelectedId.
* @param mapCanvas Pointer to the iface.mapCanvas().
*/
QgsRubberSelectId( QgsMapCanvas* mapCanvas);
QgsRubberSelectId( QgsMapCanvas* mapCanvas );
/**
* \brief Destructor
*/
@ -45,7 +45,7 @@ public:
* \brief Set if is geometry polygon for rubber band
* \param isPolygon boolean for type geometry is polygon
*/
void isGeometryNotPolygon(bool isPolygon);
void isGeometryNotPolygon( bool isPolygon );
/**
* \brief Reset rubber band
@ -72,7 +72,7 @@ public:
* \brief Show rubber band
*/
void show();
private:
private:
//! RubberBand
QgsRubberBand* mRubberBand;
bool mIsPolygon;

View File

@ -25,163 +25,166 @@
#include "qgsgeometrycoordinatetransform.h"
#include "qgsspatialquery.h"
QgsSpatialQuery::QgsSpatialQuery(MngProgressBar *pb)
QgsSpatialQuery::QgsSpatialQuery( MngProgressBar *pb )
{
mPb = pb;
mUseTargetSelection = mUseReferenceSelection = false;
mPb = pb;
mUseTargetSelection = mUseReferenceSelection = false;
} // QgsSpatialQuery::QgsSpatialQuery(MngProgressBar *pb)
QgsSpatialQuery::~QgsSpatialQuery()
{
delete mReaderFeaturesTarget;
delete mReaderFeaturesTarget;
} // QgsSpatialQuery::~QgsSpatialQuery()
void QgsSpatialQuery::setSelectedFeaturesTarget(bool useSelected)
void QgsSpatialQuery::setSelectedFeaturesTarget( bool useSelected )
{
mUseTargetSelection = useSelected;
mUseTargetSelection = useSelected;
} // void QgsSpatialQuery::setSelectedFeaturesTarget(bool useSelected)
void QgsSpatialQuery::setSelectedFeaturesReference(bool useSelected)
void QgsSpatialQuery::setSelectedFeaturesReference( bool useSelected )
{
mUseReferenceSelection = useSelected;
mUseReferenceSelection = useSelected;
} // void QgsSpatialQuery::setSelectedFeaturesReference(bool useSelected)
void QgsSpatialQuery::runQuery( QSet<int> & qsetIndexResult, int relation, QgsVectorLayer* lyrTarget, QgsVectorLayer* lyrReference )
{
setQuery(lyrTarget, lyrReference);
setQuery( lyrTarget, lyrReference );
// Create Spatial index for Reference - Set mIndexReference
mPb->setFormat("Processing 1/2 - %p%");
int totalStep = mUseReferenceSelection
? mLayerReference->selectedFeatureCount()
: (int) (mLayerReference->featureCount());
mPb->init(1, totalStep);
setSpatialIndexReference(); // Need set mLayerReference before
// Create Spatial index for Reference - Set mIndexReference
mPb->setFormat( "Processing 1/2 - %p%" );
int totalStep = mUseReferenceSelection
? mLayerReference->selectedFeatureCount()
: ( int )( mLayerReference->featureCount() );
mPb->init( 1, totalStep );
setSpatialIndexReference(); // Need set mLayerReference before
// Make Query
mPb->setFormat("Processing 2/2 - %p%");
totalStep = mUseTargetSelection
? mLayerTarget->selectedFeatureCount()
: (int) (mLayerTarget->featureCount());
mPb->init(1, totalStep);
// Make Query
mPb->setFormat( "Processing 2/2 - %p%" );
totalStep = mUseTargetSelection
? mLayerTarget->selectedFeatureCount()
: ( int )( mLayerTarget->featureCount() );
mPb->init( 1, totalStep );
execQuery(qsetIndexResult, relation);
execQuery( qsetIndexResult, relation );
} // QSet<int> QgsSpatialQuery::runQuery( int relation)
QMap<QString, int>* QgsSpatialQuery::getTypesOperations(QgsVectorLayer* lyrTarget, QgsVectorLayer* lyrReference)
QMap<QString, int>* QgsSpatialQuery::getTypesOperations( QgsVectorLayer* lyrTarget, QgsVectorLayer* lyrReference )
{
/* Relations from OGC document (obtain in February 2010)
06-103r3_Candidate_Implementation_Specification_for_Geographic_Information_-_Simple_feature_access_-_Part_1_Common_Architecture_v1.2.0.pdf
/* Relations from OGC document (obtain in February 2010)
06-103r3_Candidate_Implementation_Specification_for_Geographic_Information_-_Simple_feature_access_-_Part_1_Common_Architecture_v1.2.0.pdf
(P)oint, (L)ine and (A)rea
Target Geometry(P,L,A) / Reference Geometry (P,L,A)
dim -> Dimension of geometry
Relations:
1) Intersects and Disjoint: All
2) Touches: P/L P/A L/L L/A A/A
dimReference > dimTarget OR dimReference = dimTarget if dimReference > 0
3) Crosses: P/L P/A L/L L/A
dimReference > dimTarget OR dimReference = dimTarget if dimReference = 1
4) Within: P/L P/A L/A A/A
dimReference > dimTarget OR dimReference = dimTarget if dimReference = 2
5) Equals: P/P L/L A/A
dimReference = dimTarget
6) Overlaps: P/P L/L A/A
dimReference = dimTarget
7) Contains: L/P A/P A/L A/A
dimReference < dimTarget OR dimReference = dimTarget if dimReference = 2
*/
(P)oint, (L)ine and (A)rea
Target Geometry(P,L,A) / Reference Geometry (P,L,A)
dim -> Dimension of geometry
Relations:
1) Intersects and Disjoint: All
2) Touches: P/L P/A L/L L/A A/A
dimReference > dimTarget OR dimReference = dimTarget if dimReference > 0
3) Crosses: P/L P/A L/L L/A
dimReference > dimTarget OR dimReference = dimTarget if dimReference = 1
4) Within: P/L P/A L/A A/A
dimReference > dimTarget OR dimReference = dimTarget if dimReference = 2
5) Equals: P/P L/L A/A
dimReference = dimTarget
6) Overlaps: P/P L/L A/A
dimReference = dimTarget
7) Contains: L/P A/P A/L A/A
dimReference < dimTarget OR dimReference = dimTarget if dimReference = 2
*/
QMap<QString, int> * operations = new QMap<QString, int>;
operations->insert(QObject::tr("Intersects"), Intersects);
operations->insert(QObject::tr("Disjoint"), Disjoint);
QMap<QString, int> * operations = new QMap<QString, int>;
operations->insert( QObject::tr( "Intersects" ), Intersects );
operations->insert( QObject::tr( "Disjoint" ), Disjoint );
short int dimTarget=0, dimReference=0;
dimTarget = dimensionGeometry(lyrTarget->geometryType());
dimReference = dimensionGeometry(lyrReference->geometryType());
short int dimTarget = 0, dimReference = 0;
dimTarget = dimensionGeometry( lyrTarget->geometryType() );
dimReference = dimensionGeometry( lyrReference->geometryType() );
if (dimReference > dimTarget)
if ( dimReference > dimTarget )
{
operations->insert( QObject::tr( "Touches" ), Touches );
operations->insert( QObject::tr( "Crosses" ), Crosses );
operations->insert( QObject::tr( "Within" ), Within );
}
else if ( dimReference < dimTarget )
{
operations->insert( QObject::tr( "Contains" ), Contains );
}
else // dimReference == dimTarget
{
operations->insert( QObject::tr( "Equals" ), Equals );
operations->insert( QObject::tr( "Overlaps" ), Overlaps );
switch ( dimReference )
{
operations->insert(QObject::tr("Touches"), Touches);
operations->insert(QObject::tr("Crosses"), Crosses);
operations->insert(QObject::tr("Within"), Within);
case 0:
break;
case 1:
operations->insert( QObject::tr( "Touches" ), Touches );
operations->insert( QObject::tr( "Crosses" ), Crosses );
break;
case 2:
operations->insert( QObject::tr( "Touches" ), Touches );
operations->insert( QObject::tr( "Within" ), Within );
operations->insert( QObject::tr( "Contains" ), Contains );
}
else if (dimReference < dimTarget)
{
operations->insert(QObject::tr("Contains"), Contains);
}
else // dimReference == dimTarget
{
operations->insert(QObject::tr("Equals"), Equals);
operations->insert(QObject::tr("Overlaps"), Overlaps);
switch (dimReference)
{
case 0:
break;
case 1:
operations->insert(QObject::tr("Touches"), Touches);
operations->insert(QObject::tr("Crosses"), Crosses);
break;
case 2:
operations->insert(QObject::tr("Touches"), Touches);
operations->insert(QObject::tr("Within"), Within);
operations->insert(QObject::tr("Contains"), Contains);
}
}
return operations;
}
return operations;
} // QMap<QString, int>* QgsSpatialQuery::getTypesOperators(QgsVectorLayer* lyrTarget, QgsVectorLayer* lyrReference)
short int QgsSpatialQuery::dimensionGeometry(QGis::GeometryType geomType)
short int QgsSpatialQuery::dimensionGeometry( QGis::GeometryType geomType )
{
int dimGeom = 0;
switch (geomType)
{
int dimGeom = 0;
switch ( geomType )
{
case QGis::Point:
dimGeom = 0;
break;
dimGeom = 0;
break;
case QGis::Line:
dimGeom = 1;
break;
dimGeom = 1;
break;
case QGis::Polygon:
dimGeom = 2;
}
return dimGeom;
dimGeom = 2;
default:
Q_ASSERT( 0 );
dimGeom = 0;
}
return dimGeom;
} // int QgsSpatialQuery::dimensionGeometry(QGis::GeometryType geomType)
void QgsSpatialQuery::setQuery (QgsVectorLayer *layerTarget, QgsVectorLayer *layerReference)
void QgsSpatialQuery::setQuery( QgsVectorLayer *layerTarget, QgsVectorLayer *layerReference )
{
mLayerTarget = layerTarget;
mReaderFeaturesTarget = new QgsReaderFeatures(mLayerTarget, mUseTargetSelection);
mLayerReference = layerReference;
mLayerTarget = layerTarget;
mReaderFeaturesTarget = new QgsReaderFeatures( mLayerTarget, mUseTargetSelection );
mLayerReference = layerReference;
} // void QgsSpatialQuery::setQuery (QgsVectorLayer *layerTarget, QgsVectorLayer *layerReference)
bool QgsSpatialQuery::hasValidGeometry(QgsFeature &feature)
bool QgsSpatialQuery::hasValidGeometry( QgsFeature &feature )
{
if ( ! feature.isValid() )
{
return false;
return false;
}
QgsGeometry *geom = feature.geometry();
if ( NULL == geom )
{
return false;
return false;
}
GEOSGeometry *geomGeos = geom->asGeos();
if ( GEOSisEmpty(geomGeos) || 1 != GEOSisValid(geomGeos))
if ( GEOSisEmpty( geomGeos ) || 1 != GEOSisValid( geomGeos ) )
{
return false;
return false;
}
return true;
@ -190,153 +193,153 @@ bool QgsSpatialQuery::hasValidGeometry(QgsFeature &feature)
void QgsSpatialQuery::setSpatialIndexReference()
{
QgsReaderFeatures * readerFeaturesReference = new QgsReaderFeatures(mLayerReference, mUseReferenceSelection);
QgsFeature feature;
int step = 1;
while ( true )
QgsReaderFeatures * readerFeaturesReference = new QgsReaderFeatures( mLayerReference, mUseReferenceSelection );
QgsFeature feature;
int step = 1;
while ( true )
{
if ( ! readerFeaturesReference->nextFeature( feature ) )
{
if ( ! readerFeaturesReference->nextFeature(feature) )
{
break;
}
mPb->step(step++);
if ( ! hasValidGeometry(feature) )
{
continue;
}
mIndexReference.insertFeature(feature);
break;
}
delete readerFeaturesReference;
mPb->step( step++ );
if ( ! hasValidGeometry( feature ) )
{
continue;
}
mIndexReference.insertFeature( feature );
}
delete readerFeaturesReference;
} // void QgsSpatialQuery::setSpatialIndexReference()
void QgsSpatialQuery::execQuery( QSet<int> & qsetIndexResult, int relation)
void QgsSpatialQuery::execQuery( QSet<int> & qsetIndexResult, int relation )
{
// Set function GEOS
char(*operation)(const GEOSGeometry *, const GEOSGeometry*);
switch (relation)
{
// Set function GEOS
char( *operation )( const GEOSGeometry *, const GEOSGeometry* );
switch ( relation )
{
case Disjoint:
operation = &GEOSDisjoint;
break;
operation = &GEOSDisjoint;
break;
case Equals:
operation = &GEOSEquals;
break;
operation = &GEOSEquals;
break;
case Touches:
operation = &GEOSTouches;
break;
operation = &GEOSTouches;
break;
case Overlaps:
operation = &GEOSOverlaps;
break;
operation = &GEOSOverlaps;
break;
case Within:
operation = &GEOSWithin;
break;
operation = &GEOSWithin;
break;
case Contains:
operation = &GEOSContains;
break;
operation = &GEOSContains;
break;
case Crosses:
operation = &GEOSCrosses;
break;
operation = &GEOSCrosses;
break;
case Intersects:
operation = &GEOSIntersects;
break;
}
operation = &GEOSIntersects;
break;
}
// Transform referencer Target = Reference
QgsGeometryCoordinateTransform *coordinateTransform = new QgsGeometryCoordinateTransform();
coordinateTransform->setCoordinateTransform(mLayerTarget, mLayerReference);
// Transform referencer Target = Reference
QgsGeometryCoordinateTransform *coordinateTransform = new QgsGeometryCoordinateTransform();
coordinateTransform->setCoordinateTransform( mLayerTarget, mLayerReference );
// Set function for populate result
void (QgsSpatialQuery::* funcPopulateIndexResult)
(QSet<int> &, int, QgsGeometry *,
char(*)(const GEOSGeometry *, const GEOSGeometry *) );
funcPopulateIndexResult = ( relation == Disjoint )
? &QgsSpatialQuery::populateIndexResultDisjoint
: &QgsSpatialQuery::populateIndexResult;
// Set function for populate result
void ( QgsSpatialQuery::* funcPopulateIndexResult )
( QSet<int> &, int, QgsGeometry *,
char( * )( const GEOSGeometry *, const GEOSGeometry * ) );
funcPopulateIndexResult = ( relation == Disjoint )
? &QgsSpatialQuery::populateIndexResultDisjoint
: &QgsSpatialQuery::populateIndexResult;
QgsFeature featureTarget;
QgsGeometry * geomTarget;
int step = 1;
while( true )
QgsFeature featureTarget;
QgsGeometry * geomTarget;
int step = 1;
while ( true )
{
if ( ! mReaderFeaturesTarget->nextFeature( featureTarget ) ) break;
mPb->step( step++ );
if ( ! hasValidGeometry( featureTarget ) )
{
if ( ! mReaderFeaturesTarget->nextFeature(featureTarget) ) break;
mPb->step(step++);
if ( ! hasValidGeometry(featureTarget) )
{
continue;
}
geomTarget = featureTarget.geometry();
coordinateTransform->transform(geomTarget);
(this->*funcPopulateIndexResult)
(qsetIndexResult, featureTarget.id(), geomTarget, operation);
continue;
}
delete coordinateTransform;
geomTarget = featureTarget.geometry();
coordinateTransform->transform( geomTarget );
( this->*funcPopulateIndexResult )
( qsetIndexResult, featureTarget.id(), geomTarget, operation );
}
delete coordinateTransform;
} // QSet<int> QgsSpatialQuery::execQuery( QSet<int> & qsetIndexResult, int relation)
void QgsSpatialQuery::populateIndexResult(
QSet<int> &qsetIndexResult, int idTarget, QgsGeometry * geomTarget,
char(*operation)(const GEOSGeometry *, const GEOSGeometry *) )
QSet<int> &qsetIndexResult, int idTarget, QgsGeometry * geomTarget,
char( *operation )( const GEOSGeometry *, const GEOSGeometry * ) )
{
QList<int> listIdReference;
listIdReference = mIndexReference.intersects(geomTarget->boundingBox());
if ( listIdReference.count() == 0 )
QList<int> listIdReference;
listIdReference = mIndexReference.intersects( geomTarget->boundingBox() );
if ( listIdReference.count() == 0 )
{
return;
}
GEOSGeometry * geosTarget = geomTarget->asGeos();
QgsFeature featureReference;
QgsGeometry * geomReference;
QList<int>::iterator iterIdReference = listIdReference.begin();
for ( ; iterIdReference != listIdReference.end(); iterIdReference++ )
{
mLayerReference->featureAtId( *iterIdReference, featureReference );
geomReference = featureReference.geometry();
if (( *operation )( geosTarget, geomReference->asGeos() ) == 1 )
{
return;
}
GEOSGeometry * geosTarget = geomTarget->asGeos();
QgsFeature featureReference;
QgsGeometry * geomReference;
QList<int>::iterator iterIdReference = listIdReference.begin();
for( ; iterIdReference != listIdReference.end(); iterIdReference++ )
{
mLayerReference->featureAtId(*iterIdReference, featureReference);
geomReference = featureReference.geometry();
if( (*operation)(geosTarget, geomReference->asGeos()) == 1 )
{
qsetIndexResult.insert(idTarget);
break;
}
qsetIndexResult.insert( idTarget );
break;
}
}
} // void QgsSpatialQuery::populateIndexResult(...
void QgsSpatialQuery::populateIndexResultDisjoint(
QSet<int> &qsetIndexResult, int idTarget, QgsGeometry * geomTarget,
char(*operation)(const GEOSGeometry *, const GEOSGeometry *) )
QSet<int> &qsetIndexResult, int idTarget, QgsGeometry * geomTarget,
char( *operation )( const GEOSGeometry *, const GEOSGeometry * ) )
{
QList<int> listIdReference;
listIdReference = mIndexReference.intersects(geomTarget->boundingBox());
if ( listIdReference.count() == 0 )
QList<int> listIdReference;
listIdReference = mIndexReference.intersects( geomTarget->boundingBox() );
if ( listIdReference.count() == 0 )
{
qsetIndexResult.insert( idTarget );
return;
}
GEOSGeometry * geosTarget = geomTarget->asGeos();
QgsFeature featureReference;
QgsGeometry * geomReference;
QList<int>::iterator iterIdReference = listIdReference.begin();
bool addIndex = true;
for ( ; iterIdReference != listIdReference.end(); iterIdReference++ )
{
mLayerReference->featureAtId( *iterIdReference, featureReference );
geomReference = featureReference.geometry();
if (( *operation )( geosTarget, geomReference->asGeos() ) == 0 )
{
qsetIndexResult.insert(idTarget);
return;
}
GEOSGeometry * geosTarget = geomTarget->asGeos();
QgsFeature featureReference;
QgsGeometry * geomReference;
QList<int>::iterator iterIdReference = listIdReference.begin();
bool addIndex = true;
for( ; iterIdReference != listIdReference.end(); iterIdReference++ )
{
mLayerReference->featureAtId(*iterIdReference, featureReference);
geomReference = featureReference.geometry();
if( (*operation)(geosTarget, geomReference->asGeos()) == 0 )
{
addIndex = false;
break;
}
}
if ( addIndex )
{
qsetIndexResult.insert(idTarget);
addIndex = false;
break;
}
}
if ( addIndex )
{
qsetIndexResult.insert( idTarget );
}
} // void QgsSpatialQuery::populateIndexResultDisjoint( ...

View File

@ -35,14 +35,14 @@
*/
enum Topologic_Relation
{
Intersects,
Disjoint,
Touches,
Crosses,
Within,
Equals,
Overlaps,
Contains
Intersects,
Disjoint,
Touches,
Crosses,
Within,
Equals,
Overlaps,
Contains
};
@ -53,12 +53,12 @@ enum Topologic_Relation
*/
class QgsSpatialQuery
{
public:
public:
/**
* \brief Constructor for a Spatial query.
* \param pb Pointer to the MngProgressBar object.
*/
QgsSpatialQuery(MngProgressBar *pb);
QgsSpatialQuery( MngProgressBar *pb );
/**
* \brief Destructor
@ -69,13 +69,13 @@ public:
* \brief Sets if using selected features in Target layer
* \param useSelected TRUE if use selected.
*/
void setSelectedFeaturesTarget(bool useSelected);
void setSelectedFeaturesTarget( bool useSelected );
/**
* \brief Sets if using selected features in Reference layer
* \param useSelected TRUE if use selected.
*/
void setSelectedFeaturesReference(bool useSelected);
void setSelectedFeaturesReference( bool useSelected );
/**
* \brief Execute the query
@ -99,9 +99,9 @@ public:
* \param geomType Geometry Type
* \returns short int Topologic Dimension
*/
static short int dimensionGeometry(QGis::GeometryType geomType);
static short int dimensionGeometry( QGis::GeometryType geomType );
private:
private:
/**
* \brief Sets the target layer and reference layer
@ -114,7 +114,7 @@ private:
* \brief Verify has valid Geometry in feature
* \param QgsFeature Feature
*/
bool hasValidGeometry(QgsFeature &feature);
bool hasValidGeometry( QgsFeature &feature );
/**
* \brief Build the Spatial Index
@ -126,7 +126,7 @@ private:
* \param qsetIndexResult Reference to QSet contains the result query
* \param relation Enum Topologic Relation
*/
void execQuery(QSet<int> & qsetIndexResult, int relation);
void execQuery( QSet<int> & qsetIndexResult, int relation );
/**
* \brief Populate index Result
@ -136,8 +136,8 @@ private:
* \param operation Pointer to function of GEOS operation
*/
void populateIndexResult(
QSet<int> & qsetIndexResult, int idTarget, QgsGeometry * geomTarget,
char(*operation)(const GEOSGeometry *, const GEOSGeometry *) );
QSet<int> & qsetIndexResult, int idTarget, QgsGeometry * geomTarget,
char( *operation )( const GEOSGeometry *, const GEOSGeometry * ) );
/**
* \brief Populate index Result Disjoint
* \param qsetIndexResult Reference to QSet contains the result query
@ -146,8 +146,8 @@ private:
* \param operation Pointer to function of GEOS operation
*/
void populateIndexResultDisjoint(
QSet<int> & qsetIndexResult, int idTarget, QgsGeometry * geomTarget,
char(*operation)(const GEOSGeometry *, const GEOSGeometry *) );
QSet<int> & qsetIndexResult, int idTarget, QgsGeometry * geomTarget,
char( *operation )( const GEOSGeometry *, const GEOSGeometry * ) );
MngProgressBar *mPb;
bool mUseReferenceSelection;

File diff suppressed because it is too large Load Diff

View File

@ -34,13 +34,13 @@
class QgsSpatialQueryDialog : public QDialog, private Ui::QgsSpatialQueryDialogBase
{
Q_OBJECT
public:
public:
/**
* Constructor for a dialog. The QgisInterface pointer is passed by
* QGIS when it attempts to instantiate the plugin.
* @param iface Pointer to the QgisInterface object.
*/
QgsSpatialQueryDialog(QWidget *parent = 0, QgisInterface* iface = 0);
QgsSpatialQueryDialog( QWidget *parent = 0, QgisInterface* iface = 0 );
//! Destructor
~QgsSpatialQueryDialog();
@ -50,24 +50,24 @@ public:
//! Unload plugins by QGIS - Disconnect signal from QGIS
void disconnectQGis();
private slots:
private slots:
//! Slots for signs of Dialog
void on_buttonBox_accepted();
void on_buttonBox_rejected();
void on_targetLayerComboBox_currentIndexChanged( int index );
void on_referenceLayerComboBox_currentIndexChanged( int index );
void on_selectedFeatureListWidget_currentTextChanged ( const QString& currentText );
void on_showLogProcessingCheckBox_clicked(bool checked);
void on_selectedFeatureListWidget_currentTextChanged( const QString& currentText );
void on_showLogProcessingCheckBox_clicked( bool checked );
//! Slots for signs of QGIS
void signal_qgis_layerWasAdded ( QgsMapLayer* mapLayer );
void signal_qgis_layerWillBeRemoved ( QString idLayer );
void signal_qgis_layerWasAdded( QgsMapLayer* mapLayer );
void signal_qgis_layerWillBeRemoved( QString idLayer );
//! Slots for signs of Layers (Target or Reference)
void signal_layerTarget_selectionFeaturesChanged();
void signal_layerReference_selectionFeaturesChanged();
private:
private:
//! Initialize the Gui
void initGui();
//! Set Color mRubberSelectId
@ -79,11 +79,11 @@ private slots:
//! Run Query
void runQuery();
//! Show Log Processing
void showLogProcessing(bool hasShow);
void showLogProcessing( bool hasShow );
//! Show result of query
void showResultQuery(QDateTime *datetimeStart, QDateTime *datetimeEnd);
void showResultQuery( QDateTime *datetimeStart, QDateTime *datetimeEnd );
//! Get Description Layer to show result
QString getDescriptionLayerShow(bool isTarget);
QString getDescriptionLayerShow( bool isTarget );
//! Connect all slots
void connectAll();
//! Disconnect all slots
@ -91,15 +91,15 @@ private slots:
//! reject - override
void reject();
//! Get Vector layer from combobox
QgsVectorLayer * getLayerFromCombobox(bool isTarget, int index);
QgsVectorLayer * getLayerFromCombobox( bool isTarget, int index );
//! Get Icon for vector layer
QIcon getIconTypeGeometry(QGis::GeometryType geomType);
QIcon getIconTypeGeometry( QGis::GeometryType geomType );
//! Add layer in combobox (text, data and tooltips)
void addLayerCombobox(bool isTarget, QgsVectorLayer* vectorLayer);
void addLayerCombobox( bool isTarget, QgsVectorLayer* vectorLayer );
//! Find Layer in combobox
int getIndexLayerCombobox(bool isTarget, QgsVectorLayer* vectorLayer);
int getIndexLayerCombobox( bool isTarget, QgsVectorLayer* vectorLayer );
//! Remove layer in combobox and setting GUI
void removeLayer(bool isTarget, QgsVectorLayer* lyrRemove);
void removeLayer( bool isTarget, QgsVectorLayer* lyrRemove );
//! Populates targetLayerComboBox with all layers
void populateTargetLayerComboBox();
//! Populates referenceLayerComboBox with all layers except the current target layer
@ -125,7 +125,7 @@ private slots:
// Menssage
QString mMsgLayersLessTwo;
void MsgDEBUG(QString sMSg);
void MsgDEBUG( QString sMSg );
};
#endif // SPATIALQUERYDIALOG_H

View File

@ -57,83 +57,84 @@ static const QgisPlugin::PLUGINTYPE type_ = QgisPlugin::UI;
* @param qgis Pointer to the QGIS main window
* @parma mIface Pointer to the QGIS interface object
*/
QgsSpatialQueryPlugin::QgsSpatialQueryPlugin(QgisInterface* iface)
:QgisPlugin( name_, description_, version_, type_ ),
mIface(iface)
QgsSpatialQueryPlugin::QgsSpatialQueryPlugin( QgisInterface* iface )
: QgisPlugin( name_, description_, version_, type_ ),
mIface( iface )
{
mDialog = NULL;
mDialog = NULL;
}
QgsSpatialQueryPlugin::~QgsSpatialQueryPlugin()
{
mIface = NULL;
delete mSpatialQueryAction;
delete mDialog;
mIface = NULL;
delete mSpatialQueryAction;
delete mDialog;
}
/*
* Initialize the GUI interface for the plugin
*/
void QgsSpatialQueryPlugin::initGui()
{
// Create the action for tool
mSpatialQueryAction = new QAction( QIcon(), tr("&Spatial Query"), this);
// Create the action for tool
mSpatialQueryAction = new QAction( QIcon(), tr( "&Spatial Query" ), this );
// Connect the action to the spatialQuery slot
connect(mSpatialQueryAction, SIGNAL(activated()), this, SLOT(run()));
// Connect the action to the spatialQuery slot
connect( mSpatialQueryAction, SIGNAL( activated() ), this, SLOT( run() ) );
setCurrentTheme( "" );
// this is called when the icon theme is changed
connect( mIface, SIGNAL( currentThemeChanged( QString ) ), this, SLOT( setCurrentTheme( QString ) ) );
setCurrentTheme( "" );
// this is called when the icon theme is changed
connect( mIface, SIGNAL( currentThemeChanged( QString ) ), this, SLOT( setCurrentTheme( QString ) ) );
// Add the icon to the toolbar and to the plugin menu
mIface->addToolBarIcon(mSpatialQueryAction);
mIface->addPluginToMenu(tr("&Spatial Query"), mSpatialQueryAction);
// Add the icon to the toolbar and to the plugin menu
mIface->addToolBarIcon( mSpatialQueryAction );
mIface->addPluginToMenu( tr( "&Spatial Query" ), mSpatialQueryAction );
}
//Unload the plugin by cleaning up the GUI
void QgsSpatialQueryPlugin::unload()
{
// remove the GUI
mIface->removeToolBarIcon(mSpatialQueryAction);
mIface->removePluginMenu(tr("&Spatial Query"), mSpatialQueryAction);
// remove the GUI
mIface->removeToolBarIcon( mSpatialQueryAction );
mIface->removePluginMenu( tr( "&Spatial Query" ), mSpatialQueryAction );
delete mSpatialQueryAction;
delete mSpatialQueryAction;
}
void QgsSpatialQueryPlugin::run()
{
if (!mDialog){
if(QgsMapLayerRegistry::instance()->mapLayers().size() < 2)
{
QgsSpatialQueryDialog::messageLayersLessTwo();
return;
}
mDialog = new QgsSpatialQueryDialog(mIface->mainWindow(), mIface);
mDialog->setModal(false);
mDialog->show();
if ( !mDialog )
{
if ( QgsMapLayerRegistry::instance()->mapLayers().size() < 2 )
{
QgsSpatialQueryDialog::messageLayersLessTwo();
return;
}
mDialog = new QgsSpatialQueryDialog( mIface->mainWindow(), mIface );
mDialog->setModal( false );
mDialog->show();
}
else
{
if ( !mDialog->isVisible() )
{
delete mDialog;
mDialog = NULL;
run();
}
else
{
if ( !mDialog->isVisible() )
{
delete mDialog;
mDialog = NULL;
run();
}
else
{
mDialog->activateWindow();
}
mDialog->activateWindow();
}
}
}
//! Set icons to the current theme
void QgsSpatialQueryPlugin::setCurrentTheme( QString )
{
mSpatialQueryAction->setIcon(getThemeIcon("/spatialquery.png"));
mSpatialQueryAction->setIcon( getThemeIcon( "/spatialquery.png" ) );
}
QIcon QgsSpatialQueryPlugin::getThemeIcon( const QString &theName )
@ -142,19 +143,19 @@ QIcon QgsSpatialQueryPlugin::getThemeIcon( const QString &theName )
{
return QIcon( QgsApplication::activeThemePath() + "/plugins" + theName );
}
else if (QFile::exists(QgsApplication::defaultThemePath() + "/plugins" + theName ))
else if ( QFile::exists( QgsApplication::defaultThemePath() + "/plugins" + theName ) )
{
return QIcon( QgsApplication::defaultThemePath() + "/plugins" + theName );
}
else
{
return QIcon(":/icons" + theName);
return QIcon( ":/icons" + theName );
}
}
void QgsSpatialQueryPlugin::MsgDEBUG(QString sMSg)
void QgsSpatialQueryPlugin::MsgDEBUG( QString sMSg )
{
QMessageBox::warning(0, tr("DEBUG"), sMSg, QMessageBox::Ok);
QMessageBox::warning( 0, tr( "DEBUG" ), sMSg, QMessageBox::Ok );
}
@ -164,9 +165,9 @@ void QgsSpatialQueryPlugin::MsgDEBUG(QString sMSg)
* of the plugin class
*/
// Class factory to return a new instance of the plugin class
QGISEXTERN QgisPlugin* classFactory(QgisInterface* iface)
QGISEXTERN QgisPlugin* classFactory( QgisInterface* iface )
{
return new QgsSpatialQueryPlugin(iface);
return new QgsSpatialQueryPlugin( iface );
}
// Return the name of the plugin
@ -194,7 +195,7 @@ QGISEXTERN QString version()
}
// Delete ourself
QGISEXTERN void unload(QgisPlugin* theSpatialQueryPluginPointer)
QGISEXTERN void unload( QgisPlugin* theSpatialQueryPluginPointer )
{
delete theSpatialQueryPluginPointer;
}

View File

@ -45,17 +45,17 @@ class QAction;
class QgsSpatialQueryPlugin: public QObject, public QgisPlugin
{
Q_OBJECT
public:
public:
/**
* \brief Constructor for a plugin. The QgisInterface pointer is passed by
* QGIS when it attempts to instantiate the plugin.
* \param iface Pointer to the QgisInterface object.
*/
QgsSpatialQueryPlugin(QgisInterface* iface);
QgsSpatialQueryPlugin( QgisInterface* iface );
//! Destructor
~QgsSpatialQueryPlugin();
public slots:
public slots:
//! init the gui
void initGui();
//! unload the plugin
@ -66,7 +66,7 @@ class QgsSpatialQueryPlugin: public QObject, public QgisPlugin
void setCurrentTheme( QString theThemeName );
QIcon getThemeIcon( const QString &theThemeName );
private:
private:
QgsSpatialQueryDialog *mDialog;
//! Pointer to the QgisInterface object
@ -75,7 +75,7 @@ class QgsSpatialQueryPlugin: public QObject, public QgisPlugin
QAction* mSpatialQueryAction;
void MsgDEBUG(QString sMSg);
void MsgDEBUG( QString sMSg );
};
#endif