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


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

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


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

示例1: currentFeature

bool QgsMapToolLabel::currentFeature( QgsFeature& f, bool fetchGeom )
{
    QgsVectorLayer* vlayer = currentLayer();
    if ( !vlayer )
    {
        return false;
    }
    return vlayer->featureAtId( mCurrentLabelPos.featureId, f, fetchGeom, true );
}
开发者ID:rukku,项目名称:Quantum-GIS,代码行数:9,代码来源:qgsmaptoollabel.cpp

示例2: currentLabelText

QString QgsMapToolLabel::currentLabelText()
{
    QgsVectorLayer* vlayer = currentLayer();
    if ( !vlayer )
    {
        return "";
    }

    QString labelField = vlayer->customProperty( "labeling/fieldName" ).toString();
    if ( !labelField.isEmpty() )
    {
        int labelFieldId = vlayer->fieldNameIndex( labelField );
        QgsFeature f;
        if ( vlayer->featureAtId( mCurrentLabelPos.featureId, f, false, true ) )
        {
            return f.attributeMap()[labelFieldId].toString();
        }
    }
    return "";
}
开发者ID:rukku,项目名称:Quantum-GIS,代码行数:20,代码来源:qgsmaptoollabel.cpp

示例3: init

void QgsLabelPropertyDialog::init( const QString& layerId, int featureId )
{
  if ( !mMapRenderer )
  {
    return;
  }

  //get feature attributes
  QgsVectorLayer* vlayer = dynamic_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( layerId ) );
  if ( !vlayer )
  {
    return;
  }

  QgsFeature f;
  if ( !vlayer->featureAtId( featureId, f, false, true ) )
  {
    return;
  }
  const QgsAttributeMap& attributeValues = f.attributeMap();

  //get layerproperties. Problem: only for pallabeling...
  QgsPalLabeling* lbl = dynamic_cast<QgsPalLabeling*>( mMapRenderer->labelingEngine() );
  if ( !lbl )
  {
    return;
  }

  blockElementSignals( true );

  //get label field and fill line edit
  QString labelFieldName = vlayer->customProperty( "labeling/fieldName" ).toString();
  if ( !labelFieldName.isEmpty() )
  {
    mCurrentLabelField = vlayer->fieldNameIndex( labelFieldName );
    mLabelTextLineEdit->setText( attributeValues[mCurrentLabelField].toString() );
    const QgsFieldMap& layerFields = vlayer->pendingFields();
    switch ( layerFields[mCurrentLabelField].type() )
    {
      case QVariant::Double:
        mLabelTextLineEdit->setValidator( new QDoubleValidator( this ) );
        break;
      case QVariant::Int:
      case QVariant::UInt:
      case QVariant::LongLong:
        mLabelTextLineEdit->setValidator( new QIntValidator( this ) );
        break;
      default:
        break;
    }
  }

  //get attributes of the feature and fill data defined values
  QgsPalLayerSettings& layerSettings = lbl->layer( layerId );
  mLabelFont = layerSettings.textFont;

  //set all the gui elements to the default values
  mFontSizeSpinBox->setValue( layerSettings.textFont.pointSizeF() );
  mBufferColorButton->setColor( layerSettings.textColor );
  mLabelDistanceSpinBox->setValue( layerSettings.dist );
  mBufferSizeSpinBox->setValue( layerSettings.bufferSize );
  mMinScaleSpinBox->setValue( layerSettings.scaleMin );
  mMaxScaleSpinBox->setValue( layerSettings.scaleMax );
  mHaliComboBox->setCurrentIndex( mHaliComboBox->findText( "Left" ) );
  mValiComboBox->setCurrentIndex( mValiComboBox->findText( "Bottom" ) );

  disableGuiElements();

  mDataDefinedProperties = layerSettings.dataDefinedProperties;
  QMap< QgsPalLayerSettings::DataDefinedProperties, int >::const_iterator propIt = mDataDefinedProperties.constBegin();

  for ( ; propIt != mDataDefinedProperties.constEnd(); ++propIt )
  {
    switch ( propIt.key() )
    {
      case QgsPalLayerSettings::Show:
        mShowLabelChkbx->setEnabled( true );
        mShowLabelChkbx->setChecked( attributeValues[propIt.value()].toInt() != 0 );
        break;
      case QgsPalLayerSettings::AlwaysShow:
        mAlwaysShowChkbx->setEnabled( true );
        mAlwaysShowChkbx->setChecked( attributeValues[propIt.value()].toBool() );
        break;
      case QgsPalLayerSettings::MinScale:
        mMinScaleSpinBox->setEnabled( true );
        mMinScaleSpinBox->setValue( attributeValues[propIt.value()].toInt() );
        break;
      case QgsPalLayerSettings::MaxScale:
        mMaxScaleSpinBox->setEnabled( true );
        mMaxScaleSpinBox->setValue( attributeValues[propIt.value()].toInt() );
        break;
      case QgsPalLayerSettings::Size:
        mFontSizeSpinBox->setEnabled( true );
        mLabelFont.setPointSizeF( attributeValues[propIt.value()].toDouble() );
        mFontSizeSpinBox->setValue( attributeValues[propIt.value()].toDouble() );
        break;
      case QgsPalLayerSettings::BufferSize:
        mBufferSizeSpinBox->setEnabled( true );
        mBufferSizeSpinBox->setValue( attributeValues[propIt.value()].toDouble() );
        break;
//.........这里部分代码省略.........
开发者ID:hCivil,项目名称:Quantum-GIS,代码行数:101,代码来源:qgslabelpropertydialog.cpp

示例4: labelFontCurrentFeature

QFont QgsMapToolLabel::labelFontCurrentFeature()
{
    QFont font;
    QgsVectorLayer* vlayer = currentLayer();

    bool labelSettingsOk;
    QgsPalLayerSettings& layerSettings = currentLabelSettings( &labelSettingsOk );

    if ( labelSettingsOk && vlayer )
    {
        font = layerSettings.textFont;

        QgsFeature f;
        if ( vlayer->featureAtId( mCurrentLabelPos.featureId, f, false, true ) )
        {
            const QgsAttributeMap& attributes = f.attributeMap();
            QMap< QgsPalLayerSettings::DataDefinedProperties, int > ddProperties = layerSettings.dataDefinedProperties;

            //size
            QMap< QgsPalLayerSettings::DataDefinedProperties, int >::const_iterator sizeIt = ddProperties.find( QgsPalLayerSettings::Size );
            if ( sizeIt != ddProperties.constEnd() )
            {
                if ( layerSettings.fontSizeInMapUnits )
                {
                    font.setPixelSize( layerSettings.sizeToPixel( attributes[*sizeIt].toDouble(), QgsRenderContext() ) );
                }
                else
                {
                    font.setPointSizeF( attributes[*sizeIt].toDouble() );
                }
            }

            //family
            QMap< QgsPalLayerSettings::DataDefinedProperties, int >::const_iterator familyIt = ddProperties.find( QgsPalLayerSettings::Family );
            if ( familyIt != ddProperties.constEnd() )
            {
                font.setFamily( attributes[*sizeIt].toString() );
            }

            //underline
            QMap< QgsPalLayerSettings::DataDefinedProperties, int >::const_iterator underlineIt = ddProperties.find( QgsPalLayerSettings::Underline );
            if ( familyIt != ddProperties.constEnd() )
            {
                font.setUnderline( attributes[*underlineIt].toBool() );
            }

            //strikeout
            QMap< QgsPalLayerSettings::DataDefinedProperties, int >::const_iterator strikeoutIt = ddProperties.find( QgsPalLayerSettings::Strikeout );
            if ( strikeoutIt != ddProperties.constEnd() )
            {
                font.setStrikeOut( attributes[*strikeoutIt].toBool() );
            }

            //bold
            QMap< QgsPalLayerSettings::DataDefinedProperties, int >::const_iterator boldIt = ddProperties.find( QgsPalLayerSettings::Bold );
            if ( boldIt != ddProperties.constEnd() )
            {
                font.setBold( attributes[*boldIt].toBool() );
            }

            //italic
            QMap< QgsPalLayerSettings::DataDefinedProperties, int >::const_iterator italicIt = ddProperties.find( QgsPalLayerSettings::Italic );
            if ( italicIt != ddProperties.constEnd() )
            {
                font.setItalic( attributes[*italicIt].toBool() );
            }
        }
    }

    return font;
}
开发者ID:rukku,项目名称:Quantum-GIS,代码行数:71,代码来源:qgsmaptoollabel.cpp


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