Skip to content

Commit

Permalink
combine layer type and edit icon when editing (fixes #11411)
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Oct 16, 2014
1 parent 086b262 commit 4bf04e1
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 deletions src/core/layertree/qgslayertreemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const

if ( QgsLayerTree::isLayer( node ) )
{
QgsLayerTreeLayer* nodeLayer = QgsLayerTree::toLayer( node );
QgsLayerTreeLayer *nodeLayer = QgsLayerTree::toLayer( node );

QgsMapLayer* layer = nodeLayer->layer();
QgsMapLayer *layer = nodeLayer->layer();
if ( !layer )
return QVariant();

Expand All @@ -218,39 +218,47 @@ QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const
return QIcon( rlayer->previewAsPixmap( QSize( 32, 32 ) ) );
}
}
else if ( layer->type() == QgsMapLayer::VectorLayer )

QgsVectorLayer *vlayer = dynamic_cast<QgsVectorLayer*>( layer );

if ( layer->type() == QgsMapLayer::RasterLayer )
{
QgsVectorLayer* vlayer = static_cast<QgsVectorLayer*>( layer );
if ( vlayer->isEditable() )
{
if ( vlayer->isModified() )
return QIcon( QgsApplication::getThemePixmap( "/mIconEditableEdits.png" ) );
else
return QIcon( QgsApplication::getThemePixmap( "/mIconEditable.png" ) );
}
return QgsLayerItem::iconRaster();
}

QIcon icon;

// if there's just on legend entry that should be embedded in layer - do that!
if ( testFlag( ShowLegend ) && mLegendNodes[nodeLayer].count() == 1 && mLegendNodes[nodeLayer][0]->isEmbeddedInParent() )
return mLegendNodes[nodeLayer][0]->data( Qt::DecorationRole );

if ( layer->type() == QgsMapLayer::RasterLayer )
{
return QgsLayerItem::iconRaster();
icon = QIcon( qvariant_cast<QPixmap>( mLegendNodes[nodeLayer][0]->data( Qt::DecorationRole ) ) );
}
else if ( layer->type() == QgsMapLayer::VectorLayer )
{
QgsVectorLayer* vlayer = static_cast<QgsVectorLayer*>( layer );
if ( vlayer->geometryType() == QGis::Point )
return QgsLayerItem::iconPoint();
icon = QgsLayerItem::iconPoint();
else if ( vlayer->geometryType() == QGis::Line )
return QgsLayerItem::iconLine();
icon = QgsLayerItem::iconLine();
else if ( vlayer->geometryType() == QGis::Polygon )
return QgsLayerItem::iconPolygon();
icon = QgsLayerItem::iconPolygon();
else if ( vlayer->geometryType() == QGis::NoGeometry )
return QgsLayerItem::iconTable();
icon = QgsLayerItem::iconTable();
else
icon = QgsLayerItem::iconDefault();
}
return QgsLayerItem::iconDefault();

if ( vlayer && vlayer->isEditable() )
{
QPixmap pixmap( icon.pixmap( 16, 16 ) );

QPainter painter( &pixmap );
painter.drawPixmap( 0, 0, 16, 16, QgsApplication::getThemePixmap( vlayer->isModified() ? "/mIconEditableEdits.png" : "/mIconEditable.png" ) );
painter.end();

icon = QIcon( pixmap );
}

return icon;
}
}
else if ( role == Qt::CheckStateRole )
Expand Down

0 comments on commit 4bf04e1

Please sign in to comment.