mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -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.
|
//! Set index of the current item. May be used by view. Item marked as current is underlined.
|
||||||
void setCurrentIndex( const QModelIndex& currentIndex );
|
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:
|
signals:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -2338,7 +2338,14 @@ void QgisApp::setupLayerTreeViewFromSettings()
|
|||||||
{
|
{
|
||||||
QSettings s;
|
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( willRemoveChildren( QgsLayerTreeNode*, int, int ) ), this, SLOT( nodeWillRemoveChildren( QgsLayerTreeNode*, int, int ) ) );
|
||||||
connect( mRootNode, SIGNAL( removedChildren( QgsLayerTreeNode*, int, int ) ), this, SLOT( nodeRemovedChildren() ) );
|
connect( mRootNode, SIGNAL( removedChildren( QgsLayerTreeNode*, int, int ) ), this, SLOT( nodeRemovedChildren() ) );
|
||||||
connect( mRootNode, SIGNAL( visibilityChanged( QgsLayerTreeNode*, Qt::CheckState ) ), this, SLOT( nodeVisibilityChanged( QgsLayerTreeNode* ) ) );
|
connect( mRootNode, SIGNAL( visibilityChanged( QgsLayerTreeNode*, Qt::CheckState ) ), this, SLOT( nodeVisibilityChanged( QgsLayerTreeNode* ) ) );
|
||||||
|
|
||||||
|
mFontLayer.setBold( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsLayerTreeModel::~QgsLayerTreeModel()
|
QgsLayerTreeModel::~QgsLayerTreeModel()
|
||||||
@ -244,11 +246,9 @@ QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const
|
|||||||
}
|
}
|
||||||
else if ( role == Qt::FontRole )
|
else if ( role == Qt::FontRole )
|
||||||
{
|
{
|
||||||
QFont f;
|
QFont f( QgsLayerTree::isLayer( node ) ? mFontLayer : ( QgsLayerTree::isGroup( node ) ? mFontGroup : QFont() ) );
|
||||||
if ( node->customProperty( "embedded" ).toInt() )
|
if ( node->customProperty( "embedded" ).toInt() )
|
||||||
f.setItalic( true );
|
f.setItalic( true );
|
||||||
if ( QgsLayerTree::isLayer( node ) )
|
|
||||||
f.setBold( true );
|
|
||||||
if ( index == mCurrentIndex )
|
if ( index == mCurrentIndex )
|
||||||
f.setUnderline( true );
|
f.setUnderline( true );
|
||||||
return f;
|
return f;
|
||||||
@ -452,6 +452,43 @@ void QgsLayerTreeModel::setCurrentIndex( const QModelIndex& currentIndex )
|
|||||||
emit dataChanged( currentIndex, 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 )
|
void QgsLayerTreeModel::nodeWillAddChildren( QgsLayerTreeNode* node, int indexFrom, int indexTo )
|
||||||
{
|
{
|
||||||
Q_ASSERT( node );
|
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
|
Qt::DropActions QgsLayerTreeModel::supportedDropActions() const
|
||||||
{
|
{
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#define QGSLAYERTREEMODEL_H
|
#define QGSLAYERTREEMODEL_H
|
||||||
|
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
|
#include <QFont>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
|
||||||
class QgsLayerTreeNode;
|
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.
|
//! Set index of the current item. May be used by view. Item marked as current is underlined.
|
||||||
void setCurrentIndex( const QModelIndex& currentIndex );
|
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:
|
signals:
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
@ -158,6 +164,9 @@ class GUI_EXPORT QgsLayerTreeModel : public QAbstractItemModel
|
|||||||
void connectToLayer( QgsLayerTreeLayer* nodeLayer );
|
void connectToLayer( QgsLayerTreeLayer* nodeLayer );
|
||||||
void disconnectFromLayer( 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 QgsLayerTreeModelSymbologyNode* index2symnode( const QModelIndex& index );
|
||||||
|
|
||||||
static const QIcon& iconGroup();
|
static const QIcon& iconGroup();
|
||||||
@ -171,6 +180,9 @@ class GUI_EXPORT QgsLayerTreeModel : public QAbstractItemModel
|
|||||||
QMap<QgsLayerTreeLayer*, QList<QgsLayerTreeModelSymbologyNode*> > mSymbologyNodes;
|
QMap<QgsLayerTreeLayer*, QList<QgsLayerTreeModelSymbologyNode*> > mSymbologyNodes;
|
||||||
//! Current index - will be underlined
|
//! Current index - will be underlined
|
||||||
QPersistentModelIndex mCurrentIndex;
|
QPersistentModelIndex mCurrentIndex;
|
||||||
|
|
||||||
|
QFont mFontLayer;
|
||||||
|
QFont mFontGroup;
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsLayerTreeModel::Flags )
|
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsLayerTreeModel::Flags )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user