Skip to content

Commit

Permalink
Show preview icons in rule based labeling list of rules and vector tile
Browse files Browse the repository at this point in the history
labeling list of rules

Makes it MUCH easier to identify specific rules in the list, and matches
appearance with the rule based renderer/vector tile renderer list appearances.
  • Loading branch information
nyalldawson committed Sep 14, 2020
1 parent 7cd51dc commit d214e63
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/gui/labeling/qgsrulebasedlabelingwidget.cpp
Expand Up @@ -31,6 +31,7 @@
#include <QClipboard>
#include <QMessageBox>

const double ICON_PADDING_FACTOR = 0.16;

static QList<QgsExpressionContextScope *> _globalProjectAtlasMapLayerScopes( QgsMapCanvas *mapCanvas, const QgsMapLayer *layer )
{
Expand Down Expand Up @@ -291,8 +292,8 @@ QVariant QgsRuleBasedLabelingModel::data( const QModelIndex &index, int role ) c
}
else if ( role == Qt::DecorationRole && index.column() == 0 && rule->settings() )
{
// TODO return QgsSymbolLayerUtils::symbolPreviewIcon( rule->symbol(), QSize( 16, 16 ) );
return QVariant();
const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
return QgsPalLayerSettings::labelSettingsPreviewPixmap( *rule->settings(), QSize( iconSize, iconSize ), QString(), static_cast< int >( iconSize * ICON_PADDING_FACTOR ) );
}
else if ( role == Qt::TextAlignmentRole )
{
Expand Down
11 changes: 11 additions & 0 deletions src/gui/vectortile/qgsvectortilebasiclabelingwidget.cpp
Expand Up @@ -26,6 +26,7 @@

///@cond PRIVATE

const double ICON_PADDING_FACTOR = 0.16;

QgsVectorTileBasicLabelingListModel::QgsVectorTileBasicLabelingListModel( QgsVectorTileBasicLabeling *l, QObject *parent )
: QAbstractListModel( parent )
Expand Down Expand Up @@ -96,6 +97,16 @@ QVariant QgsVectorTileBasicLabelingListModel::data( const QModelIndex &index, in
return style.isEnabled() ? Qt::Checked : Qt::Unchecked;
}

case Qt::DecorationRole:
{
if ( index.column() == 0 )
{
const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
return QgsPalLayerSettings::labelSettingsPreviewPixmap( style.labelSettings(), QSize( iconSize, iconSize ), QString(), static_cast< int >( iconSize * ICON_PADDING_FACTOR ) );
}
break;
}

case MinZoom:
return style.minZoomLevel();

Expand Down

0 comments on commit d214e63

Please sign in to comment.