Don't show canvas specific formatting settings in layer tree model

used outside of main canvas

E.g. we shouldn't show scale based visibility text format changes
or the editable toggle in models used for snapping dialog, project
properties, etc.

These properties are only associated with the main map canvas.
This commit is contained in:
Nyall Dawson 2019-08-21 07:46:30 +10:00
parent 885029be5c
commit d014d63ede
4 changed files with 6 additions and 3 deletions

View File

@ -81,6 +81,7 @@ The root node is not transferred by the model.
ShowLegendAsTree,
DeferredLegendInvalidation,
UseEmbeddedWidgets,
UseTextFormatting,
// behavioral flags
AllowNodeReorder,

View File

@ -3999,6 +3999,7 @@ void QgisApp::initLayerTreeView()
model->setFlag( QgsLayerTreeModel::AllowNodeChangeVisibility );
model->setFlag( QgsLayerTreeModel::ShowLegendAsTree );
model->setFlag( QgsLayerTreeModel::UseEmbeddedWidgets );
model->setFlag( QgsLayerTreeModel::UseTextFormatting );
model->setAutoCollapseLegendNodes( 10 );
mLayerTreeView->setModel( model );

View File

@ -230,7 +230,7 @@ QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const
icon = QgsLayerItem::iconDefault();
}
if ( vlayer && vlayer->isEditable() )
if ( vlayer && vlayer->isEditable() && testFlag( UseTextFormatting ) )
{
const int iconSize = scaleIconSize( 16 );
QPixmap pixmap( icon.pixmap( iconSize, iconSize ) );
@ -265,7 +265,7 @@ QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const
return nodeGroup->itemVisibilityChecked() ? Qt::Checked : Qt::Unchecked;
}
}
else if ( role == Qt::FontRole )
else if ( role == Qt::FontRole && testFlag( UseTextFormatting ) )
{
QFont f( QgsLayerTree::isLayer( node ) ? mFontLayer : ( QgsLayerTree::isGroup( node ) ? mFontGroup : QFont() ) );
if ( index == mCurrentIndex )
@ -280,7 +280,7 @@ QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const
}
return f;
}
else if ( role == Qt::ForegroundRole )
else if ( role == Qt::ForegroundRole && testFlag( UseTextFormatting ) )
{
QBrush brush( qApp->palette().color( QPalette::Text ), Qt::SolidPattern );
if ( QgsLayerTree::isLayer( node ) )

View File

@ -97,6 +97,7 @@ class CORE_EXPORT QgsLayerTreeModel : public QAbstractItemModel
ShowLegendAsTree = 0x0004, //!< For legends that support it, will show them in a tree instead of a list (needs also ShowLegend). Added in 2.8
DeferredLegendInvalidation = 0x0008, //!< Defer legend model invalidation
UseEmbeddedWidgets = 0x0010, //!< Layer nodes may optionally include extra embedded widgets (if used in QgsLayerTreeView). Added in 2.16
UseTextFormatting = 0x0020, //!< Layer nodes will alter text appearance based on layer properties, such as scale based visibility
// behavioral flags
AllowNodeReorder = 0x1000, //!< Allow reordering with drag'n'drop