当前位置: 首页>>代码示例>>C++>>正文


C++ QgsVectorLayer::updateFields方法代码示例

本文整理汇总了C++中QgsVectorLayer::updateFields方法的典型用法代码示例。如果您正苦于以下问题:C++ QgsVectorLayer::updateFields方法的具体用法?C++ QgsVectorLayer::updateFields怎么用?C++ QgsVectorLayer::updateFields使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QgsVectorLayer的用法示例。


在下文中一共展示了QgsVectorLayer::updateFields方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: mapLayer

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
开发者ID:dakcarto,项目名称:QGIS,代码行数:31,代码来源:exportdlg.cpp

示例2: onEditingStarted

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();
}
开发者ID:yellow-sky,项目名称:QGIS,代码行数:50,代码来源:qgsgrassplugin.cpp


注:本文中的QgsVectorLayer::updateFields方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。