void QgsSymbolSelectorWidget::addLayer() { QModelIndex idx = layersTree->currentIndex(); if ( !idx.isValid() ) return; int insertIdx = -1; SymbolLayerItem *item = static_cast<SymbolLayerItem *>( model->itemFromIndex( idx ) ); if ( item->isLayer() ) { insertIdx = item->row(); item = static_cast<SymbolLayerItem *>( item->parent() ); } QgsSymbol *parentSymbol = item->symbol(); // save data-defined values at marker level QgsProperty ddSize( parentSymbol->type() == QgsSymbol::Marker ? static_cast<QgsMarkerSymbol *>( parentSymbol )->dataDefinedSize() : QgsProperty() ); QgsProperty ddAngle( parentSymbol->type() == QgsSymbol::Marker ? static_cast<QgsMarkerSymbol *>( parentSymbol )->dataDefinedAngle() : QgsProperty() ); QgsProperty ddWidth( parentSymbol->type() == QgsSymbol::Line ? static_cast<QgsLineSymbol *>( parentSymbol )->dataDefinedWidth() : QgsProperty() ); QgsSymbolLayer *newLayer = QgsApplication::symbolLayerRegistry()->defaultSymbolLayer( parentSymbol->type() ); if ( insertIdx == -1 ) parentSymbol->appendSymbolLayer( newLayer ); else parentSymbol->insertSymbolLayer( item->rowCount() - insertIdx, newLayer ); // restore data-defined values at marker level if ( ddSize ) static_cast<QgsMarkerSymbol *>( parentSymbol )->setDataDefinedSize( ddSize ); if ( ddAngle ) static_cast<QgsMarkerSymbol *>( parentSymbol )->setDataDefinedAngle( ddAngle ); if ( ddWidth ) static_cast<QgsLineSymbol *>( parentSymbol )->setDataDefinedWidth( ddWidth ); SymbolLayerItem *newLayerItem = new SymbolLayerItem( newLayer ); item->insertRow( insertIdx == -1 ? 0 : insertIdx, newLayerItem ); item->updatePreview(); layersTree->setCurrentIndex( model->indexFromItem( newLayerItem ) ); updateUi(); updatePreview(); }
QgsProperty QgsComposerUtils::readOldDataDefinedProperty( const QgsComposerObject::DataDefinedProperty property, const QDomElement &ddElem ) { if ( property == QgsComposerObject::AllProperties || property == QgsComposerObject::NoProperty ) { //invalid property return QgsProperty(); } QString active = ddElem.attribute( QStringLiteral( "active" ) ); bool isActive = false; if ( active.compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0 ) { isActive = true; } QString field = ddElem.attribute( QStringLiteral( "field" ) ); QString expr = ddElem.attribute( QStringLiteral( "expr" ) ); QString useExpr = ddElem.attribute( QStringLiteral( "useExpr" ) ); bool isExpression = false; if ( useExpr.compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0 ) { isExpression = true; } if ( isExpression ) return QgsProperty::fromExpression( expr, isActive ); else return QgsProperty::fromField( field, isActive ); }
void QgsDataDefinedSizeLegend::updateFromSymbolAndProperty( const QgsMarkerSymbol *symbol, const QgsProperty &ddSize ) { mSymbol.reset( symbol->clone() ); mSymbol->setDataDefinedSize( QgsProperty() ); // original symbol may have had data-defined size associated const QgsSizeScaleTransformer *sizeTransformer = dynamic_cast< const QgsSizeScaleTransformer * >( ddSize.transformer() ); mSizeScaleTransformer.reset( sizeTransformer ? sizeTransformer->clone() : nullptr ); if ( mTitleLabel.isEmpty() ) mTitleLabel = ddSize.propertyType() == QgsProperty::ExpressionBasedProperty ? ddSize.expressionString() : ddSize.field(); // automatically generate classes if no classes are defined if ( sizeTransformer && mSizeClasses.isEmpty() ) { mSizeClasses.clear(); Q_FOREACH ( double v, QgsSymbolLayerUtils::prettyBreaks( sizeTransformer->minValue(), sizeTransformer->maxValue(), 4 ) ) { mSizeClasses << SizeClass( v, QString::number( v ) ); } }
void QgsMapToolRotatePointSymbols::createPixmapItem( QgsMarkerSymbol *markerSymbol ) { if ( !mCanvas ) { return; } //get the image that is used for that symbol, but without point rotation QImage pointImage; if ( markerSymbol ) { QgsSymbol *clone = markerSymbol->clone(); QgsMarkerSymbol *markerClone = static_cast<QgsMarkerSymbol *>( clone ); markerClone->setDataDefinedAngle( QgsProperty() ); pointImage = markerClone->bigSymbolPreviewImage(); delete clone; } mRotationItem = new QgsPointRotationItem( mCanvas ); mRotationItem->setSymbol( pointImage ); }
QgsProperty propertyFromMap( const QgsStringMap &map, const QString &baseName ) { QString prefix; if ( !baseName.isEmpty() ) { prefix.append( QStringLiteral( "%1_dd_" ).arg( baseName ) ); } if ( !map.contains( QStringLiteral( "%1expression" ).arg( prefix ) ) ) { //requires at least the expression value return QgsProperty(); } bool active = ( map.value( QStringLiteral( "%1active" ).arg( prefix ), QStringLiteral( "1" ) ) != QLatin1String( "0" ) ); QString expression = map.value( QStringLiteral( "%1expression" ).arg( prefix ) ); bool useExpression = ( map.value( QStringLiteral( "%1useexpr" ).arg( prefix ), QStringLiteral( "1" ) ) != QLatin1String( "0" ) ); QString field = map.value( QStringLiteral( "%1field" ).arg( prefix ), QString() ); if ( useExpression ) return QgsProperty::fromExpression( expression, active ); else return QgsProperty::fromField( field, active ); }