Skip to content

Commit

Permalink
Updates for spatial query plugin from Luiz.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@15484 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Mar 14, 2011
1 parent 7054a22 commit a894e32
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/plugins/spatialquery/qgsspatialquery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id: qgsspatialquery.cpp 15141 2011-02-08 13:34:43Z jef $ */
/* $Id: qgsspatialquery.cpp 15302 2011-03-01 08:00:54Z timlinux $ */

#include <QMessageBox>

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

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

short int dimTarget = 0, dimReference = 0;
dimTarget = dimensionGeometry( lyrTarget->geometryType() );
Expand Down
44 changes: 35 additions & 9 deletions src/plugins/spatialquery/qgsspatialquerydialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id$ */
/* $Id: qgsspatialquerydialog.cpp 15448 2011-03-12 10:17:05Z jef $ */

#include <QMessageBox>
#include <QDateTime>
Expand Down Expand Up @@ -44,8 +44,6 @@ QgsSpatialQueryDialog::QgsSpatialQueryDialog( QWidget* parent, QgisInterface* if
initGui();
connectAll();

mMsgLayersLessTwo = tr( "The spatial query requires at least two layers" );

} // QgsSpatialQueryDialog::QgsSpatialQueryDialog( QWidget* parent, QgisInterface* iface )

QgsSpatialQueryDialog::~QgsSpatialQueryDialog()
Expand All @@ -59,11 +57,39 @@ QgsSpatialQueryDialog::~QgsSpatialQueryDialog()

} // QgsSpatialQueryDialog::~QgsSpatialQueryDialog()

void QgsSpatialQueryDialog::messageLayersLessTwo()
bool QgsSpatialQueryDialog::hasPossibleQuery( QString &msg )
{
QString msgLayersLessTwo = tr( "The spatial query requires at least two layers" );
QMessageBox::warning( 0, tr( "Insufficient number of layers" ), msgLayersLessTwo, QMessageBox::Ok );
} // void QgsSpatialQueryDialog::messageLayersLessTwo()
// Count the number of vector layer
QMap <QString, QgsMapLayer*> layers = QgsMapLayerRegistry::instance()->mapLayers();
QMapIterator <QString, QgsMapLayer*> item( layers );
QgsMapLayer * mapLayer = NULL;
QgsVectorLayer * lyr = NULL;
unsigned int totalVector = 0;
while ( item.hasNext() )
{
item.next();
mapLayer = item.value();
if ( mapLayer->type() != QgsMapLayer::VectorLayer )
{
continue;
}
lyr = qobject_cast<QgsVectorLayer *>( mapLayer );
if ( !lyr )
{
continue;
}
totalVector++;
}
// check is possible query
if( totalVector < 2 ) {
msg = tr( "The spatial query requires at least two vector layers" );
return false;
}
else {
return true;
}

} // bool QgsSpatialQueryDialog::hasPossibleQuery( QString &msg )

void QgsSpatialQueryDialog::initGui()
{
Expand Down Expand Up @@ -515,8 +541,8 @@ void QgsSpatialQueryDialog::populateCbTargetLayer()
{
cbTargetLayer->blockSignals( true );

QMap <QString, QgsMapLayer*> map = QgsMapLayerRegistry::instance()->mapLayers();
QMapIterator <QString, QgsMapLayer*> item( map );
QMap <QString, QgsMapLayer*> layers = QgsMapLayerRegistry::instance()->mapLayers();
QMapIterator <QString, QgsMapLayer*> item( layers );
QgsMapLayer * mapLayer = NULL;
QgsVectorLayer * lyr = NULL;
QString layerId;
Expand Down
9 changes: 3 additions & 6 deletions src/plugins/spatialquery/qgsspatialquerydialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id$ */
/* $Id: qgsspatialquerydialog.h 15303 2011-03-01 08:10:18Z jef $ */

#ifndef SPATIALQUERYDIALOG_H
#define SPATIALQUERYDIALOG_H
Expand Down Expand Up @@ -44,8 +44,8 @@ class QgsSpatialQueryDialog : public QDialog, private Ui::QgsSpatialQueryDialogB
//! Destructor
~QgsSpatialQueryDialog();

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

private slots:
//! Slots for signs of Dialog
Expand Down Expand Up @@ -157,9 +157,6 @@ class QgsSpatialQueryDialog : public QDialog, private Ui::QgsSpatialQueryDialogB
QString mSourceSelected;
bool mIsSelectedOperator;

// Message
QString mMsgLayersLessTwo;

void MsgDEBUG( QString sMSg );
};

Expand Down
7 changes: 4 additions & 3 deletions src/plugins/spatialquery/qgsspatialqueryplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id: qgsspatialqueryplugin.cpp 14897 2010-12-12 19:19:54Z wonder $ */
/* $Id: qgsspatialqueryplugin.cpp 15302 2011-03-01 08:00:54Z timlinux $ */


//
Expand Down Expand Up @@ -107,9 +107,10 @@ void QgsSpatialQueryPlugin::run()
{
if ( !mDialog )
{
if ( QgsMapLayerRegistry::instance()->mapLayers().size() < 2 )
QString msg;
if ( ! QgsSpatialQueryDialog::hasPossibleQuery( msg ) )
{
QgsSpatialQueryDialog::messageLayersLessTwo();
QMessageBox::warning( mIface->mainWindow(), tr( "Not possible execute the query" ), msg, QMessageBox::Ok );
return;
}
mDialog = new QgsSpatialQueryDialog( mIface->mainWindow(), mIface );
Expand Down

0 comments on commit a894e32

Please sign in to comment.