Skip to content

Commit 717f8ab

Browse files
author
timlinux
committed
Updates for spatial query plugin from Luiz.
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15484 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 434df03 commit 717f8ab

File tree

4 files changed

+44
-20
lines changed

4 files changed

+44
-20
lines changed

src/plugins/spatialquery/qgsspatialquery.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* (at your option) any later version. *
1616
* *
1717
***************************************************************************/
18-
/* $Id: qgsspatialquery.cpp 15141 2011-02-08 13:34:43Z jef $ */
18+
/* $Id: qgsspatialquery.cpp 15302 2011-03-01 08:00:54Z timlinux $ */
1919

2020
#include <QMessageBox>
2121

@@ -99,7 +99,7 @@ QMap<QString, int>* QgsSpatialQuery::getTypesOperations( QgsVectorLayer* lyrTarg
9999

100100
QMap<QString, int> * operations = new QMap<QString, int>;
101101
operations->insert( QObject::tr( "Intersects" ), Intersects );
102-
operations->insert( QObject::tr( "Disjoint" ), Disjoint );
102+
operations->insert( QObject::tr( "Is disjoint" ), Disjoint );
103103

104104
short int dimTarget = 0, dimReference = 0;
105105
dimTarget = dimensionGeometry( lyrTarget->geometryType() );

src/plugins/spatialquery/qgsspatialquerydialog.cpp

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* (at your option) any later version. *
1616
* *
1717
***************************************************************************/
18-
/* $Id$ */
18+
/* $Id: qgsspatialquerydialog.cpp 15448 2011-03-12 10:17:05Z jef $ */
1919

2020
#include <QMessageBox>
2121
#include <QDateTime>
@@ -44,8 +44,6 @@ QgsSpatialQueryDialog::QgsSpatialQueryDialog( QWidget* parent, QgisInterface* if
4444
initGui();
4545
connectAll();
4646

47-
mMsgLayersLessTwo = tr( "The spatial query requires at least two layers" );
48-
4947
} // QgsSpatialQueryDialog::QgsSpatialQueryDialog( QWidget* parent, QgisInterface* iface )
5048

5149
QgsSpatialQueryDialog::~QgsSpatialQueryDialog()
@@ -59,11 +57,39 @@ QgsSpatialQueryDialog::~QgsSpatialQueryDialog()
5957

6058
} // QgsSpatialQueryDialog::~QgsSpatialQueryDialog()
6159

62-
void QgsSpatialQueryDialog::messageLayersLessTwo()
60+
bool QgsSpatialQueryDialog::hasPossibleQuery( QString &msg )
6361
{
64-
QString msgLayersLessTwo = tr( "The spatial query requires at least two layers" );
65-
QMessageBox::warning( 0, tr( "Insufficient number of layers" ), msgLayersLessTwo, QMessageBox::Ok );
66-
} // void QgsSpatialQueryDialog::messageLayersLessTwo()
62+
// Count the number of vector layer
63+
QMap <QString, QgsMapLayer*> layers = QgsMapLayerRegistry::instance()->mapLayers();
64+
QMapIterator <QString, QgsMapLayer*> item( layers );
65+
QgsMapLayer * mapLayer = NULL;
66+
QgsVectorLayer * lyr = NULL;
67+
unsigned int totalVector = 0;
68+
while ( item.hasNext() )
69+
{
70+
item.next();
71+
mapLayer = item.value();
72+
if ( mapLayer->type() != QgsMapLayer::VectorLayer )
73+
{
74+
continue;
75+
}
76+
lyr = qobject_cast<QgsVectorLayer *>( mapLayer );
77+
if ( !lyr )
78+
{
79+
continue;
80+
}
81+
totalVector++;
82+
}
83+
// check is possible query
84+
if( totalVector < 2 ) {
85+
msg = tr( "The spatial query requires at least two vector layers" );
86+
return false;
87+
}
88+
else {
89+
return true;
90+
}
91+
92+
} // bool QgsSpatialQueryDialog::hasPossibleQuery( QString &msg )
6793

6894
void QgsSpatialQueryDialog::initGui()
6995
{
@@ -515,8 +541,8 @@ void QgsSpatialQueryDialog::populateCbTargetLayer()
515541
{
516542
cbTargetLayer->blockSignals( true );
517543

518-
QMap <QString, QgsMapLayer*> map = QgsMapLayerRegistry::instance()->mapLayers();
519-
QMapIterator <QString, QgsMapLayer*> item( map );
544+
QMap <QString, QgsMapLayer*> layers = QgsMapLayerRegistry::instance()->mapLayers();
545+
QMapIterator <QString, QgsMapLayer*> item( layers );
520546
QgsMapLayer * mapLayer = NULL;
521547
QgsVectorLayer * lyr = NULL;
522548
QString layerId;

src/plugins/spatialquery/qgsspatialquerydialog.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* (at your option) any later version. *
1616
* *
1717
***************************************************************************/
18-
/* $Id$ */
18+
/* $Id: qgsspatialquerydialog.h 15303 2011-03-01 08:10:18Z jef $ */
1919

2020
#ifndef SPATIALQUERYDIALOG_H
2121
#define SPATIALQUERYDIALOG_H
@@ -44,8 +44,8 @@ class QgsSpatialQueryDialog : public QDialog, private Ui::QgsSpatialQueryDialogB
4444
//! Destructor
4545
~QgsSpatialQueryDialog();
4646

47-
//! Message about number layers less Two
48-
static void messageLayersLessTwo();
47+
//! Verify is possible execute the query
48+
static bool hasPossibleQuery( QString &msg );
4949

5050
private slots:
5151
//! Slots for signs of Dialog
@@ -157,9 +157,6 @@ class QgsSpatialQueryDialog : public QDialog, private Ui::QgsSpatialQueryDialogB
157157
QString mSourceSelected;
158158
bool mIsSelectedOperator;
159159

160-
// Message
161-
QString mMsgLayersLessTwo;
162-
163160
void MsgDEBUG( QString sMSg );
164161
};
165162

src/plugins/spatialquery/qgsspatialqueryplugin.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* (at your option) any later version. *
1717
* *
1818
***************************************************************************/
19-
/* $Id: qgsspatialqueryplugin.cpp 14897 2010-12-12 19:19:54Z wonder $ */
19+
/* $Id: qgsspatialqueryplugin.cpp 15302 2011-03-01 08:00:54Z timlinux $ */
2020

2121

2222
//
@@ -107,9 +107,10 @@ void QgsSpatialQueryPlugin::run()
107107
{
108108
if ( !mDialog )
109109
{
110-
if ( QgsMapLayerRegistry::instance()->mapLayers().size() < 2 )
110+
QString msg;
111+
if ( ! QgsSpatialQueryDialog::hasPossibleQuery( msg ) )
111112
{
112-
QgsSpatialQueryDialog::messageLayersLessTwo();
113+
QMessageBox::warning( mIface->mainWindow(), tr( "Not possible execute the query" ), msg, QMessageBox::Ok );
113114
return;
114115
}
115116
mDialog = new QgsSpatialQueryDialog( mIface->mainWindow(), mIface );

0 commit comments

Comments
 (0)