Пример #1
0
QgsVectorLayer* RgExportDlg::mapLayer() const
{
  QgsVectorLayer* myLayer = NULL;
  QString layerId = mcbLayers->itemData( mcbLayers->currentIndex() ).toString();

  if ( layerId == "-1" )
  {
    // create a temporary layer
    myLayer = new QgsVectorLayer( QString( "LineString?crs=epsg:4326&memoryid=%1" ).arg( QUuid::createUuid().toString() ), "shortest path", "memory" );

    QgsVectorDataProvider *prov = myLayer->dataProvider();
    if ( prov == NULL )
      return NULL;

    QList<QgsField> attrList;
    attrList.append( QgsField( "length", QVariant::Double, "", 20, 8 ) );
    attrList.append( QgsField( "time", QVariant::Double, "", 20, 8 ) );
    prov->addAttributes( attrList );
    myLayer->updateFields();
    QList<QgsMapLayer *> myList;
    myList << myLayer;
    QgsMapLayerRegistry::instance()->addMapLayers( myList );
  }
  else
  {
    // return selected layer
    myLayer = dynamic_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( layerId ) );
  }

  return myLayer;
} // QgsVectorLayer* RgExportDlg::vectorLayer() const
Пример #2
0
void QgsGrassPlugin::onEditingStarted()
{
  QgsDebugMsg( "Entered" );
  QgsVectorLayer *vectorLayer = qobject_cast<QgsVectorLayer *>( sender() );
  if ( !vectorLayer )
    return;
  QgsDebugMsg( "started editing of layer " + vectorLayer->name() );

  // Set editing renderer
  QgsGrassProvider* grassProvider = dynamic_cast<QgsGrassProvider*>( vectorLayer->dataProvider() );
  if ( !grassProvider )
    return;

  QgsRendererV2Registry::instance()->addRenderer( new QgsRendererV2Metadata( "grassEdit",
      QObject::tr( "GRASS Edit" ),
      QgsGrassEditRenderer::create,
      QIcon(),
      QgsGrassEditRendererWidget::create ) );

  QgsGrassEditRenderer *renderer = new QgsGrassEditRenderer();

  mOldStyles[vectorLayer] = vectorLayer->styleManager()->currentStyle();

  // Because the edit style may be stored to project:
  // - do not translate because it may be loaded in QGIS running with different language
  // - do not change the name until really necessary because it could not be found in project
  QString editStyleName = "GRASS Edit"; // should not be translated

  if ( vectorLayer->styleManager()->styles().contains( editStyleName ) )
  {
    QgsDebugMsg( editStyleName + " style exists -> set as current" );
    vectorLayer->styleManager()->setCurrentStyle( editStyleName );
  }
  else
  {
    QgsDebugMsg( "create and set style " + editStyleName );
    vectorLayer->styleManager()->addStyleFromLayer( editStyleName );

    //vectorLayer->styleManager()->addStyle( editStyleName, QgsMapLayerStyle() );
    vectorLayer->styleManager()->setCurrentStyle( editStyleName );
    vectorLayer->setRendererV2( renderer );
  }

  grassProvider->startEditing( vectorLayer );
  vectorLayer->updateFields();

  connect( vectorLayer, SIGNAL( editingStopped() ), SLOT( onEditingStopped() ) );

  resetEditActions();
}