[QGIS Commit] r15484 - trunk/qgis/src/plugins/spatialquery

svn_qgis at osgeo.org svn_qgis at osgeo.org
Mon Mar 14 17:42:40 EDT 2011


Author: timlinux
Date: 2011-03-14 14:42:40 -0700 (Mon, 14 Mar 2011)
New Revision: 15484

Modified:
   trunk/qgis/src/plugins/spatialquery/qgsspatialquery.cpp
   trunk/qgis/src/plugins/spatialquery/qgsspatialquerydialog.cpp
   trunk/qgis/src/plugins/spatialquery/qgsspatialquerydialog.h
   trunk/qgis/src/plugins/spatialquery/qgsspatialqueryplugin.cpp
Log:
Updates for spatial query plugin from Luiz.

Modified: trunk/qgis/src/plugins/spatialquery/qgsspatialquery.cpp
===================================================================
--- trunk/qgis/src/plugins/spatialquery/qgsspatialquery.cpp	2011-03-14 21:36:02 UTC (rev 15483)
+++ trunk/qgis/src/plugins/spatialquery/qgsspatialquery.cpp	2011-03-14 21:42:40 UTC (rev 15484)
@@ -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>
 
@@ -99,7 +99,7 @@
 
   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() );

Modified: trunk/qgis/src/plugins/spatialquery/qgsspatialquerydialog.cpp
===================================================================
--- trunk/qgis/src/plugins/spatialquery/qgsspatialquerydialog.cpp	2011-03-14 21:36:02 UTC (rev 15483)
+++ trunk/qgis/src/plugins/spatialquery/qgsspatialquerydialog.cpp	2011-03-14 21:42:40 UTC (rev 15484)
@@ -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>
@@ -44,8 +44,6 @@
   initGui();
   connectAll();
 
-  mMsgLayersLessTwo = tr( "The spatial query requires at least two layers" );
-
 } // QgsSpatialQueryDialog::QgsSpatialQueryDialog( QWidget* parent, QgisInterface* iface )
 
 QgsSpatialQueryDialog::~QgsSpatialQueryDialog()
@@ -59,12 +57,40 @@
 
 } // 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()
 {
   mRubberSelectId->setStyle( 250, 0, 0, 2 ); // Same identify
@@ -515,8 +541,8 @@
 {
   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;

Modified: trunk/qgis/src/plugins/spatialquery/qgsspatialquerydialog.h
===================================================================
--- trunk/qgis/src/plugins/spatialquery/qgsspatialquerydialog.h	2011-03-14 21:36:02 UTC (rev 15483)
+++ trunk/qgis/src/plugins/spatialquery/qgsspatialquerydialog.h	2011-03-14 21:42:40 UTC (rev 15484)
@@ -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
@@ -44,8 +44,8 @@
     //! 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
@@ -157,9 +157,6 @@
     QString mSourceSelected;
     bool mIsSelectedOperator;
 
-    // Message
-    QString mMsgLayersLessTwo;
-
     void MsgDEBUG( QString sMSg );
 };
 

Modified: trunk/qgis/src/plugins/spatialquery/qgsspatialqueryplugin.cpp
===================================================================
--- trunk/qgis/src/plugins/spatialquery/qgsspatialqueryplugin.cpp	2011-03-14 21:36:02 UTC (rev 15483)
+++ trunk/qgis/src/plugins/spatialquery/qgsspatialqueryplugin.cpp	2011-03-14 21:42:40 UTC (rev 15484)
@@ -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 $ */
 
 
 //
@@ -107,9 +107,10 @@
 {
   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 );



More information about the QGIS-commit mailing list