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(); }
void QgsSymbolSelectorWidget::duplicateLayer() { QModelIndex idx = layersTree->currentIndex(); if ( !idx.isValid() ) return; SymbolLayerItem *item = static_cast<SymbolLayerItem *>( model->itemFromIndex( idx ) ); if ( !item->isLayer() ) return; QgsSymbolLayer *source = item->layer(); int insertIdx = item->row(); item = static_cast<SymbolLayerItem *>( item->parent() ); QgsSymbol *parentSymbol = item->symbol(); QgsSymbolLayer *newLayer = source->clone(); if ( insertIdx == -1 ) parentSymbol->appendSymbolLayer( newLayer ); else parentSymbol->insertSymbolLayer( item->rowCount() - insertIdx, newLayer ); SymbolLayerItem *newLayerItem = new SymbolLayerItem( newLayer ); item->insertRow( insertIdx == -1 ? 0 : insertIdx, newLayerItem ); if ( newLayer->subSymbol() ) { loadSymbol( newLayer->subSymbol(), newLayerItem ); layersTree->setExpanded( newLayerItem->index(), true ); } item->updatePreview(); layersTree->setCurrentIndex( model->indexFromItem( newLayerItem ) ); updateUi(); updatePreview(); }
void QgsDwgImportDialog::createGroup( QgsLayerTreeGroup *group, const QString &name, const QStringList &layers, bool visible ) { QgsLayerTreeGroup *layerGroup = group->addGroup( name ); QgsDebugMsg( QStringLiteral( " %1" ).arg( name ) ) ; Q_ASSERT( layerGroup ); QString layerFilter; if ( !layers.isEmpty() ) { QStringList exprlist; const auto constLayers = layers; for ( QString layer : constLayers ) { exprlist.append( QStringLiteral( "'%1'" ).arg( layer.replace( QLatin1String( "'" ), QLatin1String( "''" ) ) ) ); } layerFilter = QStringLiteral( "layer IN (%1) AND " ).arg( exprlist.join( QStringLiteral( "," ) ) ); } QgsVectorLayer *l = nullptr; QgsSymbol *sym = nullptr; l = layer( layerGroup, layerFilter, QStringLiteral( "hatches" ) ); if ( l ) { QgsSimpleFillSymbolLayer *sfl = new QgsSimpleFillSymbolLayer(); sfl->setDataDefinedProperty( QgsSymbolLayer::PropertyFillColor, QgsProperty::fromField( QStringLiteral( "color" ) ) ); sfl->setStrokeStyle( Qt::NoPen ); sym = new QgsFillSymbol(); sym->changeSymbolLayer( 0, sfl ); l->setRenderer( new QgsSingleSymbolRenderer( sym ) ); } l = layer( layerGroup, layerFilter, QStringLiteral( "lines" ) ); if ( l ) { QgsSimpleLineSymbolLayer *sll = new QgsSimpleLineSymbolLayer(); sll->setDataDefinedProperty( QgsSymbolLayer::PropertyStrokeColor, QgsProperty::fromField( QStringLiteral( "color" ) ) ); sll->setPenJoinStyle( Qt::MiterJoin ); sll->setDataDefinedProperty( QgsSymbolLayer::PropertyStrokeWidth, QgsProperty::fromField( QStringLiteral( "linewidth" ) ) ); // sll->setUseCustomDashPattern( true ); // sll->setCustomDashPatternUnit( QgsSymbolV2::MapUnit ); // sll->setDataDefinedProperty( QgsSymbolLayer::PropertyCustomDash, QgsProperty::fromField( "linetype" ) ); sym = new QgsLineSymbol(); sym->changeSymbolLayer( 0, sll ); sym->setOutputUnit( QgsUnitTypes::RenderMillimeters ); l->setRenderer( new QgsSingleSymbolRenderer( sym ) ); } l = layer( layerGroup, layerFilter, QStringLiteral( "polylines" ) ); if ( l ) { sym = new QgsLineSymbol(); QgsSimpleLineSymbolLayer *sll = new QgsSimpleLineSymbolLayer(); sll->setDataDefinedProperty( QgsSymbolLayer::PropertyStrokeColor, QgsProperty::fromField( QStringLiteral( "color" ) ) ); sll->setPenJoinStyle( Qt::MiterJoin ); sll->setDataDefinedProperty( QgsSymbolLayer::PropertyStrokeWidth, QgsProperty::fromField( QStringLiteral( "width" ) ) ); sll->setDataDefinedProperty( QgsSymbolLayer::PropertyLayerEnabled, QgsProperty::fromExpression( QStringLiteral( "width>0" ) ) ); sll->setOutputUnit( QgsUnitTypes::RenderMapUnits ); // sll->setUseCustomDashPattern( true ); // sll->setCustomDashPatternUnit( QgsSymbolV2::MapUnit ); // sll->setDataDefinedProperty( QgsSymbolLayer::PropertyCustomDash, QgsProperty::fromField( "linetype" ) ); sym->changeSymbolLayer( 0, sll ); sll = new QgsSimpleLineSymbolLayer(); sll->setDataDefinedProperty( QgsSymbolLayer::PropertyStrokeColor, QgsProperty::fromField( QStringLiteral( "color" ) ) ); sll->setPenJoinStyle( Qt::MiterJoin ); sll->setDataDefinedProperty( QgsSymbolLayer::PropertyStrokeWidth, QgsProperty::fromField( QStringLiteral( "linewidth" ) ) ); sll->setDataDefinedProperty( QgsSymbolLayer::PropertyLayerEnabled, QgsProperty::fromExpression( QStringLiteral( "width=0" ) ) ); sll->setOutputUnit( QgsUnitTypes::RenderMillimeters ); sym->appendSymbolLayer( sll ); l->setRenderer( new QgsSingleSymbolRenderer( sym ) ); } l = layer( layerGroup, layerFilter, QStringLiteral( "texts" ) ); if ( l ) { l->setRenderer( new QgsNullSymbolRenderer() ); QgsTextFormat tf; tf.setSizeUnit( QgsUnitTypes::RenderMapUnits ); QgsPalLayerSettings pls; pls.setFormat( tf ); pls.drawLabels = true; pls.fieldName = QStringLiteral( "text" ); pls.wrapChar = QStringLiteral( "\\P" ); pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::Size, QgsProperty::fromField( QStringLiteral( "height" ) ) ); pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::Color, QgsProperty::fromField( QStringLiteral( "color" ) ) ); pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::MultiLineHeight, QgsProperty::fromExpression( QStringLiteral( "CASE WHEN interlin<0 THEN 1 ELSE interlin*1.5 END" ) ) ); pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::PositionX, QgsProperty::fromExpression( QStringLiteral( "$x" ) ) ); pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::PositionY, QgsProperty::fromExpression( QStringLiteral( "$y" ) ) ); // DXF TEXT // vertical: 0 = Base, 1 = Bottom, 2 = Middle, 3 = Top, default Base // horizontal: 0 = Left, 1 = Center, 2 = Right, 3 = Aligned (if Base), 4 = Middle (if Base), default Left // DXF MTEXT // 1 = Top left; 2 = Top center; 3 = Top right // 4 = Middle left; 5 = Middle center; 6 = Middle right // 7 = Bottom left; 8 = Bottom center; 9 = Bottom right // QGIS Quadrant // 0 QuadrantAboveLeft, 1 QuadrantAbove, 2 QuadrantAboveRight, // 3 QuadrantLeft, 4 QuadrantOver, 5 QuadrantRight, // 6 QuadrantBelowLeft, 7 QuadrantBelow, 8 QuadrantBelowRight, pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::Hali, QgsProperty::fromExpression( QStringLiteral( "CASE" " WHEN etype=%1 THEN" " CASE" " WHEN textgen % 3=2 THEN 'Center'" " WHEN textgen % 3=0 THEN 'Right'" " ELSE 'Left'" " END" " ELSE" " CASE" " WHEN alignh=1 THEN 'Center'" " WHEN alignh=2 THEN 'Right'" " ELSE 'Left'" " END" " END" ).arg( DRW::MTEXT ) ) ); pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::Vali, QgsProperty::fromExpression( QStringLiteral( "CASE" " WHEN etype=%1 THEN" " CASE" " WHEN textgen<4 THEN 'Top'" " WHEN textgen<7 THEN 'Half'" " ELSE 'Bottom'" " END" " ELSE" " CASE" " WHEN alignv=1 THEN 'Bottom'" " WHEN alignv=2 THEN 'Half'" " WHEN alignv=3 THEN 'Top'" " ELSE 'Base'" " END" " END" ).arg( DRW::MTEXT ) ) ); pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::LabelRotation, QgsProperty::fromExpression( QStringLiteral( "360-angle" ) ) ); pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::AlwaysShow, QgsProperty::fromExpression( QStringLiteral( "1" ) ) ); l->setLabeling( new QgsVectorLayerSimpleLabeling( pls ) ); l->setLabelsEnabled( true ); } l = layer( layerGroup, layerFilter, QStringLiteral( "points" ) ); if ( l ) { // FIXME: use PDMODE? l->setRenderer( new QgsNullSymbolRenderer() ); } if ( !cbExpandInserts->isChecked() ) layer( layerGroup, layerFilter, QStringLiteral( "inserts" ) ); if ( !layerGroup->children().isEmpty() ) { layerGroup->setExpanded( false ); layerGroup->setItemVisibilityChecked( visible ); } else { layerGroup->parent()->takeChild( layerGroup ); delete layerGroup; } }
QgsGrassEditRenderer::QgsGrassEditRenderer() : QgsFeatureRenderer( QStringLiteral( "grassEdit" ) ) { QHash<int, QColor> colors; //colors.insert( QgsGrassVectorMap::TopoUndefined, QColor( 125, 125, 125 ) ); colors.insert( QgsGrassVectorMap::TopoLine, QColor( Qt::black ) ); colors.insert( QgsGrassVectorMap::TopoBoundaryError, QColor( Qt::red ) ); colors.insert( QgsGrassVectorMap::TopoBoundaryErrorLeft, QColor( 255, 125, 0 ) ); colors.insert( QgsGrassVectorMap::TopoBoundaryErrorRight, QColor( 255, 125, 0 ) ); colors.insert( QgsGrassVectorMap::TopoBoundaryOk, QColor( Qt::green ) ); QHash<int, QString> labels; //labels.insert( QgsGrassVectorMap::TopoUndefined, "Unknown type" ); labels.insert( QgsGrassVectorMap::TopoLine, QStringLiteral( "Line" ) ); labels.insert( QgsGrassVectorMap::TopoBoundaryError, QStringLiteral( "Boundary (topological error on both sides)" ) ); labels.insert( QgsGrassVectorMap::TopoBoundaryErrorLeft, QStringLiteral( "Boundary (topological error on the left side)" ) ); labels.insert( QgsGrassVectorMap::TopoBoundaryErrorRight, QStringLiteral( "Boundary (topological error on the right side)" ) ); labels.insert( QgsGrassVectorMap::TopoBoundaryOk, QStringLiteral( "Boundary (correct)" ) ); QgsCategoryList categoryList; // first/last vertex marker to distinguish vertices from nodes QgsMarkerLineSymbolLayer *firstVertexMarkerLine = new QgsMarkerLineSymbolLayer( false ); QgsSimpleMarkerSymbolLayer *markerSymbolLayer = new QgsSimpleMarkerSymbolLayer( QgsSimpleMarkerSymbolLayerBase::Cross2, 2 ); markerSymbolLayer->setColor( QColor( 255, 0, 0 ) ); markerSymbolLayer->setStrokeColor( QColor( 255, 0, 0 ) ); markerSymbolLayer->setStrokeWidth( 0.5 ); QgsSymbolLayerList markerLayers; markerLayers << markerSymbolLayer; QgsMarkerSymbol *markerSymbol = new QgsMarkerSymbol( markerLayers ); firstVertexMarkerLine->setSubSymbol( markerSymbol ); firstVertexMarkerLine->setPlacement( QgsTemplatedLineSymbolLayerBase::FirstVertex ); QgsMarkerLineSymbolLayer *lastVertexMarkerLine = static_cast<QgsMarkerLineSymbolLayer *>( firstVertexMarkerLine->clone() ); lastVertexMarkerLine->setPlacement( QgsTemplatedLineSymbolLayerBase::LastVertex ); Q_FOREACH ( int value, colors.keys() ) { QgsSymbol *symbol = QgsSymbol::defaultSymbol( QgsWkbTypes::LineGeometry ); symbol->setColor( colors.value( value ) ); symbol->appendSymbolLayer( firstVertexMarkerLine->clone() ); symbol->appendSymbolLayer( lastVertexMarkerLine->clone() ); categoryList << QgsRendererCategory( QVariant( value ), symbol, labels.value( value ) ); } delete firstVertexMarkerLine; delete lastVertexMarkerLine; mLineRenderer = new QgsCategorizedSymbolRenderer( QStringLiteral( "topo_symbol" ), categoryList ); colors.clear(); labels.clear(); colors.insert( QgsGrassVectorMap::TopoPoint, QColor( 0, 255, 255 ) ); colors.insert( QgsGrassVectorMap::TopoCentroidIn, QColor( 0, 255, 0 ) ); colors.insert( QgsGrassVectorMap::TopoCentroidOut, QColor( 255, 0, 0 ) ); colors.insert( QgsGrassVectorMap::TopoCentroidDupl, QColor( 255, 0, 255 ) ); labels.insert( QgsGrassVectorMap::TopoPoint, QStringLiteral( "Point" ) ); labels.insert( QgsGrassVectorMap::TopoCentroidIn, QStringLiteral( "Centroid in area" ) ); labels.insert( QgsGrassVectorMap::TopoCentroidOut, QStringLiteral( "Centroid outside area" ) ); labels.insert( QgsGrassVectorMap::TopoCentroidDupl, QStringLiteral( "Duplicate centroid" ) ); categoryList.clear(); Q_FOREACH ( int value, colors.keys() ) { QgsSymbol *symbol = QgsSymbol::defaultSymbol( QgsWkbTypes::PointGeometry ); symbol->setColor( colors.value( value ) ); categoryList << QgsRendererCategory( QVariant( value ), symbol, labels.value( value ) ); } mMarkerRenderer = new QgsCategorizedSymbolRenderer( QStringLiteral( "topo_symbol" ), categoryList ); }