mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
[layertree] respect bold font settings for layer/group
This commit is contained in:
parent
9af0b376b3
commit
2e39e602a2
@ -88,6 +88,11 @@ class QgsLayerTreeModel : QAbstractItemModel
|
||||
//! Set index of the current item. May be used by view. Item marked as current is underlined.
|
||||
void setCurrentIndex( const QModelIndex& currentIndex );
|
||||
|
||||
//! Set font for a particular type of layer tree node. nodeType should come from QgsLayerTreeNode::NodeType enumeration
|
||||
void setLayerTreeNodeFont( int nodeType, const QFont& font );
|
||||
//! Get font for a particular type of layer tree node. nodeType should come from QgsLayerTreeNode::NodeType enumeration
|
||||
QFont layerTreeNodeFont( int nodeType ) const;
|
||||
|
||||
signals:
|
||||
|
||||
};
|
||||
|
@ -2338,7 +2338,14 @@ void QgisApp::setupLayerTreeViewFromSettings()
|
||||
{
|
||||
QSettings s;
|
||||
|
||||
mLayerTreeView->layerTreeModel()->setFlag( QgsLayerTreeModel::ShowRasterPreviewIcon, s.value( "/qgis/createRasterLegendIcons", false ).toBool() );
|
||||
QgsLayerTreeModel* model = mLayerTreeView->layerTreeModel();
|
||||
model->setFlag( QgsLayerTreeModel::ShowRasterPreviewIcon, s.value( "/qgis/createRasterLegendIcons", false ).toBool() );
|
||||
|
||||
QFont fontLayer, fontGroup;
|
||||
fontLayer.setBold( s.value( "/qgis/legendLayersBold", true ).toBool() );
|
||||
fontGroup.setBold( s.value( "/qgis/legendGroupsBold", false ).toBool() );
|
||||
model->setLayerTreeNodeFont( QgsLayerTreeNode::NodeLayer, fontLayer );
|
||||
model->setLayerTreeNodeFont( QgsLayerTreeNode::NodeGroup, fontGroup );
|
||||
}
|
||||
|
||||
|
||||
|
@ -40,6 +40,8 @@ QgsLayerTreeModel::QgsLayerTreeModel( QgsLayerTreeGroup* rootNode, QObject *pare
|
||||
connect( mRootNode, SIGNAL( willRemoveChildren( QgsLayerTreeNode*, int, int ) ), this, SLOT( nodeWillRemoveChildren( QgsLayerTreeNode*, int, int ) ) );
|
||||
connect( mRootNode, SIGNAL( removedChildren( QgsLayerTreeNode*, int, int ) ), this, SLOT( nodeRemovedChildren() ) );
|
||||
connect( mRootNode, SIGNAL( visibilityChanged( QgsLayerTreeNode*, Qt::CheckState ) ), this, SLOT( nodeVisibilityChanged( QgsLayerTreeNode* ) ) );
|
||||
|
||||
mFontLayer.setBold( true );
|
||||
}
|
||||
|
||||
QgsLayerTreeModel::~QgsLayerTreeModel()
|
||||
@ -244,11 +246,9 @@ QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const
|
||||
}
|
||||
else if ( role == Qt::FontRole )
|
||||
{
|
||||
QFont f;
|
||||
QFont f( QgsLayerTree::isLayer( node ) ? mFontLayer : ( QgsLayerTree::isGroup( node ) ? mFontGroup : QFont() ) );
|
||||
if ( node->customProperty( "embedded" ).toInt() )
|
||||
f.setItalic( true );
|
||||
if ( QgsLayerTree::isLayer( node ) )
|
||||
f.setBold( true );
|
||||
if ( index == mCurrentIndex )
|
||||
f.setUnderline( true );
|
||||
return f;
|
||||
@ -452,6 +452,43 @@ void QgsLayerTreeModel::setCurrentIndex( const QModelIndex& currentIndex )
|
||||
emit dataChanged( currentIndex, currentIndex );
|
||||
}
|
||||
|
||||
|
||||
void QgsLayerTreeModel::setLayerTreeNodeFont( int nodeType, const QFont& font )
|
||||
{
|
||||
if ( nodeType == QgsLayerTreeNode::NodeGroup )
|
||||
{
|
||||
if ( mFontGroup != font )
|
||||
{
|
||||
mFontGroup = font;
|
||||
recursivelyEmitDataChanged();
|
||||
}
|
||||
}
|
||||
else if ( nodeType == QgsLayerTreeNode::NodeLayer )
|
||||
{
|
||||
if ( mFontLayer != font )
|
||||
{
|
||||
mFontLayer = font;
|
||||
recursivelyEmitDataChanged();
|
||||
}
|
||||
}
|
||||
else
|
||||
QgsDebugMsg( "invalid node type" );
|
||||
}
|
||||
|
||||
|
||||
QFont QgsLayerTreeModel::layerTreeNodeFont( int nodeType ) const
|
||||
{
|
||||
if ( nodeType == QgsLayerTreeNode::NodeGroup )
|
||||
return mFontGroup;
|
||||
else if ( nodeType == QgsLayerTreeNode::NodeLayer )
|
||||
return mFontLayer;
|
||||
else
|
||||
{
|
||||
QgsDebugMsg( "invalid node type" );
|
||||
return QFont();
|
||||
}
|
||||
}
|
||||
|
||||
void QgsLayerTreeModel::nodeWillAddChildren( QgsLayerTreeNode* node, int indexFrom, int indexTo )
|
||||
{
|
||||
Q_ASSERT( node );
|
||||
@ -747,6 +784,20 @@ void QgsLayerTreeModel::disconnectFromLayer( QgsLayerTreeLayer* nodeLayer )
|
||||
}
|
||||
}
|
||||
|
||||
void QgsLayerTreeModel::recursivelyEmitDataChanged( const QModelIndex& idx )
|
||||
{
|
||||
QgsLayerTreeNode* node = index2node( idx );
|
||||
if ( !node )
|
||||
return;
|
||||
|
||||
int count = node->children().count();
|
||||
if ( count == 0 )
|
||||
return;
|
||||
emit dataChanged( index( 0, 0, idx ), index( count - 1, 0, idx ) );
|
||||
for ( int i = 0; i < count; ++i )
|
||||
recursivelyEmitDataChanged( index( i, 0, idx ) );
|
||||
}
|
||||
|
||||
|
||||
Qt::DropActions QgsLayerTreeModel::supportedDropActions() const
|
||||
{
|
||||
|
@ -17,6 +17,7 @@
|
||||
#define QGSLAYERTREEMODEL_H
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QFont>
|
||||
#include <QIcon>
|
||||
|
||||
class QgsLayerTreeNode;
|
||||
@ -133,6 +134,11 @@ class GUI_EXPORT QgsLayerTreeModel : public QAbstractItemModel
|
||||
//! Set index of the current item. May be used by view. Item marked as current is underlined.
|
||||
void setCurrentIndex( const QModelIndex& currentIndex );
|
||||
|
||||
//! Set font for a particular type of layer tree node. nodeType should come from QgsLayerTreeNode::NodeType enumeration
|
||||
void setLayerTreeNodeFont( int nodeType, const QFont& font );
|
||||
//! Get font for a particular type of layer tree node. nodeType should come from QgsLayerTreeNode::NodeType enumeration
|
||||
QFont layerTreeNodeFont( int nodeType ) const;
|
||||
|
||||
signals:
|
||||
|
||||
protected slots:
|
||||
@ -158,6 +164,9 @@ class GUI_EXPORT QgsLayerTreeModel : public QAbstractItemModel
|
||||
void connectToLayer( QgsLayerTreeLayer* nodeLayer );
|
||||
void disconnectFromLayer( QgsLayerTreeLayer* nodeLayer );
|
||||
|
||||
//! emit dataChanged() for layer tree node items
|
||||
void recursivelyEmitDataChanged( const QModelIndex& index = QModelIndex() );
|
||||
|
||||
static QgsLayerTreeModelSymbologyNode* index2symnode( const QModelIndex& index );
|
||||
|
||||
static const QIcon& iconGroup();
|
||||
@ -171,6 +180,9 @@ class GUI_EXPORT QgsLayerTreeModel : public QAbstractItemModel
|
||||
QMap<QgsLayerTreeLayer*, QList<QgsLayerTreeModelSymbologyNode*> > mSymbologyNodes;
|
||||
//! Current index - will be underlined
|
||||
QPersistentModelIndex mCurrentIndex;
|
||||
|
||||
QFont mFontLayer;
|
||||
QFont mFontGroup;
|
||||
};
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsLayerTreeModel::Flags )
|
||||
|
Loading…
x
Reference in New Issue
Block a user