Skip to content

Commit

Permalink
[layertree] Underline current layer
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed May 22, 2014
1 parent af5f1aa commit 2837778
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/gui/layertree/qgslayertreemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ QgsLayerTreeModel::QgsLayerTreeModel( QgsLayerTreeGroup* rootNode, QObject *pare
: QAbstractItemModel( parent )
, mRootNode( rootNode )
, mFlags( ShowSymbology )
, mCurrentNode( 0 )
{
Q_ASSERT( mRootNode );

Expand Down Expand Up @@ -236,6 +237,8 @@ QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const
f.setItalic( true );
if ( QgsLayerTree::isLayer( node ) )
f.setBold( true );
if ( node == mCurrentNode )
f.setUnderline( true );
return f;
}
else if ( role == Qt::ToolTipRole )
Expand Down Expand Up @@ -382,6 +385,23 @@ void QgsLayerTreeModel::refreshLayerSymbology( QgsLayerTreeLayer* nodeLayer )
addSymbologyToLayer( nodeLayer );
}

void QgsLayerTreeModel::setCurrentNode( QgsLayerTreeNode* currentNode )
{
if ( mCurrentNode )
{
QModelIndex idx = node2index( mCurrentNode );
emit dataChanged( idx, idx );
}

mCurrentNode = currentNode;

if ( mCurrentNode )
{
QModelIndex idx = node2index( mCurrentNode );
emit dataChanged( idx, idx );
}
}

void QgsLayerTreeModel::nodeWillAddChildren( QgsLayerTreeNode* node, int indexFrom, int indexTo )
{
Q_ASSERT( node );
Expand Down
5 changes: 5 additions & 0 deletions src/gui/layertree/qgslayertreemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ class GUI_EXPORT QgsLayerTreeModel : public QAbstractItemModel

void refreshLayerSymbology( QgsLayerTreeLayer* nodeLayer );

QgsLayerTreeNode* currentNode() const { return mCurrentNode; }
void setCurrentNode( QgsLayerTreeNode* currentNode );

signals:

protected slots:
Expand Down Expand Up @@ -122,6 +125,8 @@ class GUI_EXPORT QgsLayerTreeModel : public QAbstractItemModel
Flags mFlags;

QMap<QgsLayerTreeLayer*, QList<QgsLayerTreeModelSymbologyNode*> > mSymbologyNodes;

QgsLayerTreeNode* mCurrentNode;
};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsLayerTreeModel::Flags )
Expand Down
5 changes: 5 additions & 0 deletions src/gui/layertree/qgslayertreeview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ void QgsLayerTreeView::onCurrentChanged( QModelIndex current, QModelIndex previo
if ( layerPrevious == layerCurrent )
return;

if ( layerCurrent )
layerTreeModel()->setCurrentNode( layerTreeModel()->rootGroup()->findLayer( layerCurrent->id() ) );
else
layerTreeModel()->setCurrentNode( 0 );

emit currentLayerChanged( layerCurrent );
}

Expand Down

0 comments on commit 2837778

Please sign in to comment.