Skip to content

Commit

Permalink
Change layer's icon in legend to reflext that the layer is editable.
Browse files Browse the repository at this point in the history
Removed duplicate function.


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@10895 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Jun 9, 2009
1 parent b4549c7 commit e592fd5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
8 changes: 6 additions & 2 deletions src/app/legend/qgslegend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ void QgsLegend::addLayer( QgsMapLayer * layer )
QgsLegendLayer * llayer = new QgsLegendLayer( layer->name() );//generate entry for mStateOfCheckBoxes below
QgsLegendLayerFileGroup * llfgroup = new QgsLegendLayerFileGroup( llayer, QString( "Files" ) );
QgsLegendLayerFile * llfile = new QgsLegendLayerFile( llfgroup, QgsLegendLayerFile::nameFromLayer( layer ), layer );
llayer->setLayerTypeIcon();
llayer->updateIcon();
llayer->setToolTip( 0, layer->publicSource() );

//set the correct check states
Expand Down Expand Up @@ -547,6 +547,10 @@ void QgsLegend::addLayer( QgsMapLayer * layer )
setCurrentItem( llayer );
//make the QTreeWidget item up-to-date
doItemsLayout();

// setup connections that will update the layer icons
connect(layer, SIGNAL(editingStarted()), llayer, SLOT(updateIcon()));
connect(layer, SIGNAL(editingStopped()), llayer, SLOT(updateIcon()));
}

QgsLegendLayerFile* QgsLegend::currentLayerFile()
Expand Down Expand Up @@ -1086,7 +1090,7 @@ bool QgsLegend::readXML( QDomNode& legendnode )
//set the layer type icon if this legendlayerfile is the last in the file group
if ( child.nextSibling().isNull() )
{
static_cast<QgsLegendLayer*>( theLegendLayerFile->parent()->parent() )->setLayerTypeIcon();
static_cast<QgsLegendLayer*>( theLegendLayerFile->parent()->parent() )->updateIcon();
}

theLegendLayerFile->updateLegendItem();
Expand Down
20 changes: 10 additions & 10 deletions src/app/legend/qgslegendlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ void QgsLegendLayer::setupFont() //private method
myFont.setBold( true ); //visually differentiate layer labels from the rest
setFont( 0, myFont );
}
void QgsLegendLayer::setLayerTypeIcon()
{
QIcon myIcon( getOriginalPixmap() );
setIcon( 0, myIcon );
}

bool QgsLegendLayer::isLeafNode()
{
Expand Down Expand Up @@ -407,23 +402,28 @@ void QgsLegendLayer::updateIcon()
if ( mapLayers().size() == 1 )
{
//overview
// FIXME: overview icon is missing
/*
if ( theFile->isInOverview() )
{
// Overlay the overview icon on the default icon
QPixmap myPixmap = QgisApp::getThemePixmap( + "mIconOverview.png" );
QPixmap myPixmap = QgisApp::getThemePixmap( "/mIconOverview.png" );
QPainter p( &newIcon );
p.drawPixmap( 0, 0, myPixmap );
p.end();
}
}*/

//editable
if ( theLayer->isEditable() )
{
QPixmap myPixmap = QgisApp::getThemePixmap( "/mIconEditable.png" );
// use editable icon instead of the layer's type icon
newIcon = myPixmap;

// Overlay the editable icon on the default icon
QPixmap myPixmap = QgisApp::getThemePixmap( + "mIconEditable.png" );
QPainter p( &newIcon );
/*QPainter p( &newIcon );
p.drawPixmap( 0, 0, myPixmap );
p.end();
p.end();*/
}
}

Expand Down
12 changes: 5 additions & 7 deletions src/app/legend/qgslegendlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ class QgsLegendLayer : public QgsLegendItem
QgsLegendLayer( QTreeWidget*, QString );
QgsLegendLayer( QString name );
~QgsLegendLayer();
/**Sets an icon characterising the type of layer(s) it contains.
Note: cannot be in the constructor because layers are added after creation*/
void setLayerTypeIcon();

bool isLeafNode();
QgsLegendItem::DRAG_ACTION accept( LEGEND_ITEM_TYPE type );
QgsLegendItem::DRAG_ACTION accept( const QgsLegendItem* li ) const;
Expand All @@ -70,10 +68,6 @@ class QgsLegendLayer : public QgsLegendItem
/**Updates symbology of the layer and copies symbology to other layer files in the group*/
void refreshSymbology( const QString& key, double widthScale = 1.0 );

/**Goes through all the legendlayerfiles and adds editing/overview pixmaps to the icon. If not all layer files
have the same editing/overview state, a tristate is applied*/
void updateIcon();

/** called to add appropriate menu items to legend's popup menu */
void addToPopupMenu( QMenu& theMenu, QAction* toggleEditingAction );

Expand All @@ -91,6 +85,10 @@ class QgsLegendLayer : public QgsLegendItem
void saveAsShapefile();
void saveSelectionAsShapefile();

/**Goes through all the legendlayerfiles and adds editing/overview pixmaps to the icon. If not all layer files
have the same editing/overview state, a tristate is applied*/
void updateIcon();

protected:

/** Prepare and change symbology for vector layer */
Expand Down

0 comments on commit e592fd5

Please sign in to comment.