Beispiel #1
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();
}
Beispiel #2
0
void QgsGrassPlugin::onEditingStopped()
{
  QgsDebugMsg( "entered" );
  QgsVectorLayer *vectorLayer = qobject_cast<QgsVectorLayer *>( sender() );
  if ( vectorLayer )
  {
    QString style = mOldStyles.value( vectorLayer );
    if ( vectorLayer->styleManager()->currentStyle() == "GRASS Edit" ) // not changed by user
    {
      QgsDebugMsg( "reset style to " + style );
      vectorLayer->styleManager()->setCurrentStyle( style );
    }
  }
  resetEditActions();
}