本文整理汇总了C++中QgsVectorLayer::customProperty方法的典型用法代码示例。如果您正苦于以下问题:C++ QgsVectorLayer::customProperty方法的具体用法?C++ QgsVectorLayer::customProperty怎么用?C++ QgsVectorLayer::customProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QgsVectorLayer
的用法示例。
在下文中一共展示了QgsVectorLayer::customProperty方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: currentLabelText
QString QgsMapToolLabel::currentLabelText( int trunc )
{
bool settingsOk;
QgsPalLayerSettings& labelSettings = currentLabelSettings( &settingsOk );
if ( !settingsOk )
{
return "";
}
if ( labelSettings.isExpression )
{
QString labelText = mCurrentLabelPos.labelText;
if ( trunc > 0 && labelText.length() > trunc )
{
labelText.truncate( trunc );
labelText += "...";
}
return labelText;
}
else
{
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->getFeatures( QgsFeatureRequest().setFilterFid( mCurrentLabelPos.featureId ).setFlags( QgsFeatureRequest::NoGeometry ) ).nextFeature( f ) )
{
QString labelText = f.attribute( labelFieldId ).toString();
if ( trunc > 0 && labelText.length() > trunc )
{
labelText.truncate( trunc );
labelText += "...";
}
return labelText;
}
}
}
return "";
}
示例2: currentLabelText
QString QgsMapToolLabel::currentLabelText( int trunc )
{
if ( !mCurrentLabel.valid )
{
return QLatin1String( "" );
}
QgsPalLayerSettings& labelSettings = mCurrentLabel.settings;
if ( labelSettings.isExpression )
{
QString labelText = mCurrentLabel.pos.labelText;
if ( trunc > 0 && labelText.length() > trunc )
{
labelText.truncate( trunc );
labelText += QLatin1String( "..." );
}
return labelText;
}
else
{
QgsVectorLayer* vlayer = mCurrentLabel.layer;
if ( !vlayer )
{
return QLatin1String( "" );
}
QString labelField = vlayer->customProperty( QStringLiteral( "labeling/fieldName" ) ).toString();
if ( !labelField.isEmpty() )
{
int labelFieldId = vlayer->fields().lookupField( labelField );
QgsFeature f;
if ( vlayer->getFeatures( QgsFeatureRequest().setFilterFid( mCurrentLabel.pos.featureId ).setFlags( QgsFeatureRequest::NoGeometry ) ).nextFeature( f ) )
{
QString labelText = f.attribute( labelFieldId ).toString();
if ( trunc > 0 && labelText.length() > trunc )
{
labelText.truncate( trunc );
labelText += QLatin1String( "..." );
}
return labelText;
}
}
}
return QLatin1String( "" );
}
示例3: 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 "";
}
示例4: 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;
//.........这里部分代码省略.........
示例5: init
void QgsLabelPropertyDialog::init( const QString& layerId, const QString& providerId, int featureId, const QString& labelText )
{
//get feature attributes
QgsVectorLayer* vlayer = dynamic_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( layerId ) );
if ( !vlayer )
{
return;
}
if ( !vlayer->labeling() )
{
return;
}
if ( !vlayer->getFeatures( QgsFeatureRequest().setFilterFid( featureId ).setFlags( QgsFeatureRequest::NoGeometry ) ).nextFeature( mCurLabelFeat ) )
{
return;
}
QgsAttributes attributeValues = mCurLabelFeat.attributes();
//get layerproperties. Problem: only for pallabeling...
blockElementSignals( true );
QgsPalLayerSettings layerSettings = vlayer->labeling()->settings( vlayer, providerId );
//get label field and fill line edit
if ( layerSettings.isExpression && !labelText.isNull() )
{
mLabelTextLineEdit->setText( labelText );
mLabelTextLineEdit->setEnabled( false );
mLabelTextLabel->setText( tr( "Expression result" ) );
}
else
{
QString labelFieldName = vlayer->customProperty( "labeling/fieldName" ).toString();
if ( !labelFieldName.isEmpty() )
{
mCurLabelField = vlayer->fieldNameIndex( labelFieldName );
if ( mCurLabelField >= 0 )
{
mLabelTextLineEdit->setText( attributeValues.at( mCurLabelField ).toString() );
const QgsFields& layerFields = vlayer->fields();
switch ( layerFields.at( mCurLabelField ).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;
}
}
else
{
mLabelTextLineEdit->setEnabled( false );
}
}
}
//get attributes of the feature and fill data defined values
// font is set directly from QgsLabelPosition
updateFont( mLabelFont, false );
//set all the gui elements to the default layer-level values
mLabelDistanceSpinBox->clear();
mLabelDistanceSpinBox->setSpecialValueText( tr( "Layer default (%1)" ).arg( QString::number( layerSettings.dist, 'f', mLabelDistanceSpinBox->decimals() ) ) );
mBufferSizeSpinBox->clear();
mBufferSizeSpinBox->setSpecialValueText( tr( "Layer default (%1)" ).arg( QString::number( layerSettings.bufferSize, 'f', mBufferSizeSpinBox->decimals() ) ) );
mRotationSpinBox->clear();
mXCoordSpinBox->clear();
mYCoordSpinBox->clear();
mShowLabelChkbx->setChecked( true );
mFontColorButton->setColor( layerSettings.textColor );
mBufferColorButton->setColor( layerSettings.bufferColor );
mMinScaleSpinBox->setValue( layerSettings.scaleMin );
mMaxScaleSpinBox->setValue( layerSettings.scaleMax );
mHaliComboBox->setCurrentIndex( mHaliComboBox->findData( "Left" ) );
mValiComboBox->setCurrentIndex( mValiComboBox->findData( "Bottom" ) );
mFontColorButton->setColorDialogTitle( tr( "Font color" ) );
mBufferColorButton->setColorDialogTitle( tr( "Buffer color" ) );
disableGuiElements();
QMap< QgsPalLayerSettings::DataDefinedProperties, QgsDataDefined* >::const_iterator it = layerSettings.dataDefinedProperties.constBegin();
for ( ; it != layerSettings.dataDefinedProperties.constEnd(); ++it )
{
mDataDefinedProperties.insert( it.key(), it.value() ? new QgsDataDefined( *it.value() ) : nullptr );
}
//set widget values from data defined results
setDataDefinedValues( layerSettings, vlayer );
//enable widgets connected to data defined fields
enableDataDefinedWidgets( vlayer );
//.........这里部分代码省略.........