Пример #1
0
void rulesDialog::updateRuleItems( const QString &layerName )
{
  if ( layerName.isEmpty() )
  {
    return;
  }

  mRuleBox->clear();

  if ( layerName == "No layer" )
  {
    return;
  }

  QString layerId = mLayer1Box->itemData( mLayer1Box->currentIndex() ).toString();

  QgsMapLayerRegistry* layerRegistry = QgsMapLayerRegistry::instance();
  QgsVectorLayer* vlayer = ( QgsVectorLayer* )layerRegistry->mapLayers()[layerId];

  if ( !vlayer )
  {
    qDebug() << "not a vector layer";
    return;
  }

  for ( QMap<QString, TopologyRule>::iterator it = mTestConfMap.begin(); it != mTestConfMap.end(); ++it )
  {
    TopologyRule rule = it.value();
    if ( rule.layer1AcceptsType( vlayer->geometryType() ) )
    {
      mRuleBox->addItem( it.key() );
    }

  }
}
Пример #2
0
void rulesDialog::initGui()
{
  QgsMapLayerRegistry* layerRegistry = QgsMapLayerRegistry::instance();

  QList<QString> layerList = layerRegistry->mapLayers().keys();

  mLayer1Box->clear();
  mLayer1Box->addItem( "No layer" );

  mLayer2Box->clear();
  mLayer2Box->addItem( "No layer" );

  mLayer1Box->blockSignals( true );
  for ( int i = 0; i < layerList.size(); ++i )
  {
    QgsVectorLayer* v1 = ( QgsVectorLayer* )layerRegistry->mapLayers()[layerList[i]];
    qDebug() << "layerid = " + layerList[i];

    // add layer name to the layer combo boxes

    mLayer1Box->addItem( v1->name(), v1->id() );
  }
  mLayer1Box->blockSignals( false );

}
Пример #3
0
void rulesDialog::showControls( const QString& testName )
{
  if ( testName.isEmpty() )
  {
    return;
  }

  mLayer2Box->clear();
  mLayer2Box->addItem( "No layer" );
  TopologyRule topologyRule = mTestConfMap[testName];
  QgsMapLayerRegistry* layerRegistry = QgsMapLayerRegistry::instance();
  QList<QString> layerList = layerRegistry->mapLayers().keys();

  if ( topologyRule.useSecondLayer )
  {
    mLayer2Box->setVisible( true );
    for ( int i = 0; i < layerList.count(); ++i )
    {
      QgsVectorLayer* v1 = ( QgsVectorLayer* )layerRegistry->mapLayers()[layerList[i]];

      if ( !v1 )
      {
        continue;
      }


      if ( v1->name() == mLayer1Box->currentText() )
      {
        continue;
      }


      if ( v1->type() == QgsMapLayer::VectorLayer )
      {
        if ( topologyRule.layer2AcceptsType( v1->geometryType() ) )
        {
          mLayer2Box->addItem( v1->name() , v1->id() );
        }
      }
    }
  }
  else
  {
    mLayer2Box->setVisible( false );
  }


  if ( topologyRule.useTolerance )
  {
    mToleranceBox->setVisible( true );
    mToleranceLabel->setVisible( true );
  }
  else
  {
    mToleranceBox->setVisible( false );
    mToleranceLabel->setVisible( false );
  }

}
Пример #4
0
// Slot called when the menu item is activated
void QgsGPSPlugin::run()
{
    // find all GPX layers
    std::vector<QgsVectorLayer*> gpxLayers;
    QMap<QString, QgsMapLayer*>::const_iterator iter;
    QgsMapLayerRegistry* registry = QgsMapLayerRegistry::instance();
    QMap<QString, QgsMapLayer*> layers = registry->mapLayers();
    for ( iter = layers.constBegin();
            iter != layers.constEnd(); ++iter )
    {
        if ( iter.value()->type() == QgsMapLayer::VectorLayer )
        {
            QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer *>( iter.value() );
            if ( vLayer->providerType() == QLatin1String( "gpx" ) )
                gpxLayers.push_back( vLayer );
        }
    }

    QgsGPSPluginGui *myPluginGui =
        new QgsGPSPluginGui( mImporters, mDevices, gpxLayers, mQGisInterface->mainWindow(),
                             QgisGui::ModalDialogFlags );
    myPluginGui->setAttribute( Qt::WA_DeleteOnClose );
    //listen for when the layer has been made so we can draw it
    connect( myPluginGui, SIGNAL( drawVectorLayer( QString, QString, QString ) ),
             this, SLOT( drawVectorLayer( QString, QString, QString ) ) );
    connect( myPluginGui, SIGNAL( loadGPXFile( QString, bool, bool, bool ) ),
             this, SLOT( loadGPXFile( QString, bool, bool, bool ) ) );
    connect( myPluginGui, SIGNAL( importGPSFile( QString, QgsBabelFormat*, bool,
                                  bool, bool, QString, QString ) ),
             this, SLOT( importGPSFile( QString, QgsBabelFormat*, bool, bool,
                                        bool, QString, QString ) ) );
    connect( myPluginGui, SIGNAL( convertGPSFile( QString, int,
                                  QString, QString ) ),
             this, SLOT( convertGPSFile( QString, int,
                                         QString, QString ) ) );
    connect( myPluginGui, SIGNAL( downloadFromGPS( QString, QString, bool, bool,
                                  bool, QString, QString ) ),
             this, SLOT( downloadFromGPS( QString, QString, bool, bool, bool,
                                          QString, QString ) ) );
    connect( myPluginGui, SIGNAL( uploadToGPS( QgsVectorLayer*, QString, QString ) ),
             this, SLOT( uploadToGPS( QgsVectorLayer*, QString, QString ) ) );
    connect( this, SIGNAL( closeGui() ), myPluginGui, SLOT( close() ) );

    myPluginGui->show();
}
Пример #5
0
QgsRectangle QgsMapSettings::fullExtent() const
{
  QgsDebugMsg( "called." );
  QgsMapLayerRegistry* registry = QgsMapLayerRegistry::instance();

  // reset the map canvas extent since the extent may now be smaller
  // We can't use a constructor since QgsRectangle normalizes the rectangle upon construction
  QgsRectangle fullExtent;
  fullExtent.setMinimal();

  // iterate through the map layers and test each layers extent
  // against the current min and max values
  QStringList::const_iterator it = mLayers.begin();
  QgsDebugMsg( QString( "Layer count: %1" ).arg( mLayers.count() ) );
  while ( it != mLayers.end() )
  {
    QgsMapLayer * lyr = registry->mapLayer( *it );
    if ( !lyr )
    {
      QgsDebugMsg( QString( "WARNING: layer '%1' not found in map layer registry!" ).arg( *it ) );
    }
    else
    {
      QgsDebugMsg( "Updating extent using " + lyr->name() );
      QgsDebugMsg( "Input extent: " + lyr->extent().toString() );

      if ( lyr->extent().isNull() )
      {
        ++it;
        continue;
      }

      // Layer extents are stored in the coordinate system (CS) of the
      // layer. The extent must be projected to the canvas CS
      QgsRectangle extent = layerExtentToOutputExtent( lyr, lyr->extent() );

      QgsDebugMsg( "Output extent: " + extent.toString() );
      fullExtent.unionRect( extent );

    }
    ++it;
  }

  if ( fullExtent.width() == 0.0 || fullExtent.height() == 0.0 )
  {
    // If all of the features are at the one point, buffer the
    // rectangle a bit. If they are all at zero, do something a bit
    // more crude.

    if ( fullExtent.xMinimum() == 0.0 && fullExtent.xMaximum() == 0.0 &&
         fullExtent.yMinimum() == 0.0 && fullExtent.yMaximum() == 0.0 )
    {
      fullExtent.set( -1.0, -1.0, 1.0, 1.0 );
    }
    else
    {
      const double padFactor = 1e-8;
      double widthPad = fullExtent.xMinimum() * padFactor;
      double heightPad = fullExtent.yMinimum() * padFactor;
      double xmin = fullExtent.xMinimum() - widthPad;
      double xmax = fullExtent.xMaximum() + widthPad;
      double ymin = fullExtent.yMinimum() - heightPad;
      double ymax = fullExtent.yMaximum() + heightPad;
      fullExtent.set( xmin, ymin, xmax, ymax );
    }
  }

  QgsDebugMsg( "Full extent: " + fullExtent.toString() );
  return fullExtent;
}