Skip to content

Commit bf0c30b

Browse files
author
jef
committed
spatial query plugin: port to new QgsGeometry operators, gui cleanup
git-svn-id: http://svn.osgeo.org/qgis/trunk@13367 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent e946ed1 commit bf0c30b

8 files changed

+214
-505
lines changed

src/plugins/spatialquery/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,11 @@ INCLUDE_DIRECTORIES(
4141
../../core/symbology
4242
../../gui
4343
..
44-
${GEOS_INCLUDE_DIR}
4544
)
4645

4746
TARGET_LINK_LIBRARIES(spatialqueryplugin
4847
qgis_core
4948
qgis_gui
50-
${GEOS_LIBRARY}
5149
)
5250

5351

src/plugins/spatialquery/qgsspatialquery.cpp

+18-27
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ void QgsSpatialQuery::runQuery( QSet<int> & qsetIndexResult, int relation, QgsVe
5555
setQuery( lyrTarget, lyrReference );
5656

5757
// Create Spatial index for Reference - Set mIndexReference
58-
mPb->setFormat( "Processing 1/2 - %p%" );
58+
mPb->setFormat( QObject::tr( "Processing 1/2 - %p%" ) );
5959
int totalStep = mUseReferenceSelection
6060
? mLayerReference->selectedFeatureCount()
6161
: ( int )( mLayerReference->featureCount() );
6262
mPb->init( 1, totalStep );
6363
setSpatialIndexReference(); // Need set mLayerReference before
6464

6565
// Make Query
66-
mPb->setFormat( "Processing 2/2 - %p%" );
66+
mPb->setFormat( QObject::tr( "Processing 2/2 - %p%" ) );
6767
totalStep = mUseTargetSelection
6868
? mLayerTarget->selectedFeatureCount()
6969
: ( int )( mLayerTarget->featureCount() );
@@ -181,9 +181,7 @@ bool QgsSpatialQuery::hasValidGeometry( QgsFeature &feature )
181181
return false;
182182
}
183183

184-
GEOSGeometry *geomGeos = geom->asGeos();
185-
186-
if ( GEOSisEmpty( geomGeos ) || 1 != GEOSisValid( geomGeos ) )
184+
if ( geom->isGeosEmpty() || !geom->isGeosValid() )
187185
{
188186
return false;
189187
}
@@ -218,33 +216,32 @@ void QgsSpatialQuery::setSpatialIndexReference()
218216

219217
void QgsSpatialQuery::execQuery( QSet<int> & qsetIndexResult, int relation )
220218
{
221-
// Set GEOS function
222-
char( *operation )( const GEOSGeometry *, const GEOSGeometry* );
219+
bool ( QgsGeometry::* operation )( QgsGeometry * );
223220
switch ( relation )
224221
{
225222
case Disjoint:
226-
operation = &GEOSDisjoint;
223+
operation = &QgsGeometry::disjoint;
227224
break;
228225
case Equals:
229-
operation = &GEOSEquals;
226+
operation = &QgsGeometry::equals;
230227
break;
231228
case Touches:
232-
operation = &GEOSTouches;
229+
operation = &QgsGeometry::touches;
233230
break;
234231
case Overlaps:
235-
operation = &GEOSOverlaps;
232+
operation = &QgsGeometry::overlaps;
236233
break;
237234
case Within:
238-
operation = &GEOSWithin;
235+
operation = &QgsGeometry::within;
239236
break;
240237
case Contains:
241-
operation = &GEOSContains;
238+
operation = &QgsGeometry::contains;
242239
break;
243240
case Crosses:
244-
operation = &GEOSCrosses;
241+
operation = &QgsGeometry::crosses;
245242
break;
246243
case Intersects:
247-
operation = &GEOSIntersects;
244+
operation = &QgsGeometry::intersects;
248245
break;
249246
}
250247

@@ -253,20 +250,16 @@ void QgsSpatialQuery::execQuery( QSet<int> & qsetIndexResult, int relation )
253250
coordinateTransform->setCoordinateTransform( mLayerTarget, mLayerReference );
254251

255252
// Set function for populate result
256-
void ( QgsSpatialQuery::* funcPopulateIndexResult )
257-
( QSet<int> &, int, QgsGeometry *,
258-
char( * )( const GEOSGeometry *, const GEOSGeometry * ) );
253+
void ( QgsSpatialQuery::* funcPopulateIndexResult )( QSet<int> &, int, QgsGeometry *, bool ( QgsGeometry::* )( QgsGeometry * ) );
259254
funcPopulateIndexResult = ( relation == Disjoint )
260255
? &QgsSpatialQuery::populateIndexResultDisjoint
261256
: &QgsSpatialQuery::populateIndexResult;
262257

263258
QgsFeature featureTarget;
264259
QgsGeometry * geomTarget;
265260
int step = 1;
266-
while ( true )
261+
while ( mReaderFeaturesTarget->nextFeature( featureTarget ) )
267262
{
268-
if ( ! mReaderFeaturesTarget->nextFeature( featureTarget ) ) break;
269-
270263
mPb->step( step++ );
271264

272265
if ( ! hasValidGeometry( featureTarget ) )
@@ -285,23 +278,22 @@ void QgsSpatialQuery::execQuery( QSet<int> & qsetIndexResult, int relation )
285278

286279
void QgsSpatialQuery::populateIndexResult(
287280
QSet<int> &qsetIndexResult, int idTarget, QgsGeometry * geomTarget,
288-
char( *operation )( const GEOSGeometry *, const GEOSGeometry * ) )
281+
bool ( QgsGeometry::* op )( QgsGeometry * ) )
289282
{
290283
QList<int> listIdReference;
291284
listIdReference = mIndexReference.intersects( geomTarget->boundingBox() );
292285
if ( listIdReference.count() == 0 )
293286
{
294287
return;
295288
}
296-
GEOSGeometry * geosTarget = geomTarget->asGeos();
297289
QgsFeature featureReference;
298290
QgsGeometry * geomReference;
299291
QList<int>::iterator iterIdReference = listIdReference.begin();
300292
for ( ; iterIdReference != listIdReference.end(); iterIdReference++ )
301293
{
302294
mLayerReference->featureAtId( *iterIdReference, featureReference );
303295
geomReference = featureReference.geometry();
304-
if (( *operation )( geosTarget, geomReference->asGeos() ) == 1 )
296+
if (( geomTarget->*op )( geomReference ) == 1 )
305297
{
306298
qsetIndexResult.insert( idTarget );
307299
break;
@@ -312,7 +304,7 @@ void QgsSpatialQuery::populateIndexResult(
312304

313305
void QgsSpatialQuery::populateIndexResultDisjoint(
314306
QSet<int> &qsetIndexResult, int idTarget, QgsGeometry * geomTarget,
315-
char( *operation )( const GEOSGeometry *, const GEOSGeometry * ) )
307+
bool ( QgsGeometry::* op )( QgsGeometry * ) )
316308
{
317309
QList<int> listIdReference;
318310
listIdReference = mIndexReference.intersects( geomTarget->boundingBox() );
@@ -321,7 +313,6 @@ void QgsSpatialQuery::populateIndexResultDisjoint(
321313
qsetIndexResult.insert( idTarget );
322314
return;
323315
}
324-
GEOSGeometry * geosTarget = geomTarget->asGeos();
325316
QgsFeature featureReference;
326317
QgsGeometry * geomReference;
327318
QList<int>::iterator iterIdReference = listIdReference.begin();
@@ -330,7 +321,7 @@ void QgsSpatialQuery::populateIndexResultDisjoint(
330321
{
331322
mLayerReference->featureAtId( *iterIdReference, featureReference );
332323
geomReference = featureReference.geometry();
333-
if (( *operation )( geosTarget, geomReference->asGeos() ) == 0 )
324+
if (( geomTarget->*op )( geomTarget ) == 0 )
334325
{
335326
addIndex = false;
336327
break;

src/plugins/spatialquery/qgsspatialquery.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
#ifndef SPATIALQUERY_H
2020
#define SPATIALQUERY_H
2121

22-
#include <geos_c.h>
23-
2422
#include <qgsvectorlayer.h>
2523
#include <qgsspatialindex.h>
2624

@@ -137,7 +135,7 @@ class QgsSpatialQuery
137135
*/
138136
void populateIndexResult(
139137
QSet<int> & qsetIndexResult, int idTarget, QgsGeometry * geomTarget,
140-
char( *operation )( const GEOSGeometry *, const GEOSGeometry * ) );
138+
bool ( QgsGeometry::* operation )( QgsGeometry * ) );
141139
/**
142140
* \brief Populate index Result Disjoint
143141
* \param qsetIndexResult Reference to QSet contains the result query
@@ -147,7 +145,7 @@ class QgsSpatialQuery
147145
*/
148146
void populateIndexResultDisjoint(
149147
QSet<int> & qsetIndexResult, int idTarget, QgsGeometry * geomTarget,
150-
char( *operation )( const GEOSGeometry *, const GEOSGeometry * ) );
148+
bool ( QgsGeometry::* operation )( QgsGeometry * ) );
151149

152150
MngProgressBar *mPb;
153151
bool mUseReferenceSelection;

src/plugins/spatialquery/qgsspatialquerydialog.cpp

+19-12
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ void QgsSpatialQueryDialog::evaluateCheckBox( bool isTarget )
152152
checkbox->setChecked( isCheckBoxValid );
153153
checkbox->setEnabled( isCheckBoxValid );
154154
QString textCheckBox = isCheckBoxValid
155-
? QString::number( selectedCount ) + " " + tr( "Selected geometries" )
155+
? tr( "%n selected geometries", "selected geometries", selectedCount )
156156
: tr( "Selected geometries" );
157157
checkbox->setText( textCheckBox );
158158

@@ -185,30 +185,37 @@ void QgsSpatialQueryDialog::runQuery()
185185
buttonBox->setEnabled( true );
186186

187187
grpResults->show();
188-
grpInputs->hide();
188+
setInputsVisible( false );
189189
progressBarStatus->hide();
190190
buttonBox->button( QDialogButtonBox::Close )->show();
191191
buttonBox->button( QDialogButtonBox::Cancel )->hide();
192192
buttonBox->button( QDialogButtonBox::Ok )->hide();
193193
} // void QgsSpatialQueryDialog::runQuery()
194194

195+
void QgsSpatialQueryDialog::setInputsVisible( bool show )
196+
{
197+
grpTargetGroupBox->setVisible( show );
198+
grpReferenceGroupBox->setVisible( show );
199+
grpOperationGroupBox->setVisible( show );
200+
}
201+
195202
void QgsSpatialQueryDialog::showLogProcessing( bool hasShow )
196203
{
197204
static int heightDialogNoStatus = 0;
198205

199206
hasShow ? textEditStatus->show() : textEditStatus->hide();
200-
this->adjustSize();
207+
adjustSize();
201208

202209
if ( ! hasShow )
203210
{
204211
if ( heightDialogNoStatus == 0 )
205212
{
206-
heightDialogNoStatus = this->geometry().height();
213+
heightDialogNoStatus = geometry().height();
207214
}
208215
else
209216
{
210-
this->setGeometry( this->geometry().x(), this->geometry().y(),
211-
this->geometry().width(), heightDialogNoStatus );
217+
setGeometry( geometry().x(), geometry().y(),
218+
geometry().width(), heightDialogNoStatus );
212219
}
213220
}
214221

@@ -613,18 +620,18 @@ void QgsSpatialQueryDialog::on_selectedFeatureListWidget_currentTextChanged( con
613620
mRubberSelectId->reset();
614621
selectedFeatureListWidget->setEnabled( false );
615622

616-
QCursor cursor;
617-
cursor.setShape( Qt::WaitCursor );
618-
Qt::CursorShape shapeCurrent = this->cursor().shape();
619-
this->setCursor( cursor );
620-
cursor.setShape( shapeCurrent );
623+
QCursor c;
624+
c.setShape( Qt::WaitCursor );
625+
Qt::CursorShape shapeCurrent = cursor().shape();
626+
setCursor( c );
627+
c.setShape( shapeCurrent );
621628

622629
bool ok;
623630
int Id = currentText.toInt( &ok );
624631
mRubberSelectId->addFeature( mLayerTarget, Id );
625632

626633
selectedFeatureListWidget->setEnabled( true );
627-
this->setCursor( cursor );
634+
setCursor( c );
628635
selectedFeatureListWidget->setFocus();
629636
mRubberSelectId->show();
630637

src/plugins/spatialquery/qgsspatialquerydialog.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,13 @@ class QgsSpatialQueryDialog : public QDialog, private Ui::QgsSpatialQueryDialogB
122122
//! Rubber band for features result
123123
QgsRubberSelectId* mRubberSelectId;
124124

125-
// Menssage
125+
// Message
126126
QString mMsgLayersLessTwo;
127127

128128
void MsgDEBUG( QString sMSg );
129+
130+
//! show/hide target, reference and operation group box
131+
void setInputsVisible( bool show );
129132
};
130133

131134
#endif // SPATIALQUERYDIALOG_H

0 commit comments

Comments
 (0)