Skip to content

Commit 6b6896b

Browse files
authoredNov 17, 2016
Merge pull request #3777 from nirvn/symbols_preview_padding
[symbology] add padding value for symbol/coloramp preview
2 parents 24ffa15 + a8a05ba commit 6b6896b

File tree

8 files changed

+84
-40
lines changed

8 files changed

+84
-40
lines changed
 

‎doc/api_break.dox

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,6 +1423,7 @@ QgsSymbolLayerUtils (renamed from QgsSymbolLayerUtilsV2) {#qgis_api_break
14231423

14241424
- encodeOutputUnit() and decodeOutputUnit() were removed. QgsUnitTypes::encodeUnit() and QgsUnitTypes::decodeRenderUnit() should be used instead.
14251425
- The signatures for wellKnownMarkerToSld() and wellKnownMarkerFromSld() were changed.
1426+
- The symbolPreviewPixmap() customContext is now the fourth parameter
14261427

14271428

14281429
QgsSymbolSelectorWidget {#qgis_api_break_3_0_QgsSymbolSelectorWidget}

‎python/core/symbology-ng/qgssymbollayerutils.sip

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,23 @@ class QgsSymbolLayerUtils
9595

9696
static QPainter::CompositionMode decodeBlendMode( const QString& s );
9797

98-
static QIcon symbolPreviewIcon( QgsSymbol* symbol, QSize size );
98+
/** Returns an icon preview for a color ramp.
99+
* @param symbol symbol
100+
* @param size target pixmap size
101+
* @param padding space between icon edge and symbol
102+
* @see symbolPreviewPixmap()
103+
*/
104+
static QIcon symbolPreviewIcon( QgsSymbol* symbol, QSize size, int padding = 0 );
105+
106+
/** Returns a pixmap preview for a color ramp.
107+
* @param symbol symbol
108+
* @param size target pixmap size
109+
* @param padding space between icon edge and symbol
110+
* @param customContext render context to use when rendering symbol
111+
* @note customContext parameter added in 2.6
112+
* @see symbolPreviewIcon()
113+
*/
114+
static QPixmap symbolPreviewPixmap( QgsSymbol* symbol, QSize size, int padding = 0, QgsRenderContext* customContext = 0 );
99115

100116
/** Draws a symbol layer preview to a QPicture
101117
* @param layer symbol layer to draw
@@ -118,14 +134,23 @@ class QgsSymbolLayerUtils
118134
*/
119135
static QIcon symbolLayerPreviewIcon( QgsSymbolLayer* layer, QgsUnitTypes::RenderUnit u, QSize size, const QgsMapUnitScale& scale = QgsMapUnitScale() );
120136

121-
static QIcon colorRampPreviewIcon( QgsColorRamp* ramp, QSize size );
137+
/** Returns a icon preview for a color ramp.
138+
* @param ramp color ramp
139+
* @param size target icon size
140+
* @param padding space between icon edge and symbol
141+
* @see colorRampPreviewPixmap()
142+
*/
143+
static QIcon colorRampPreviewIcon( QgsColorRamp* ramp, QSize size, int padding = 0 );
144+
/** Returns a pixmap preview for a color ramp.
145+
* @param ramp color ramp
146+
* @param size target pixmap size
147+
* @param padding space between icon edge and symbol
148+
* @see colorRampPreviewIcon()
149+
*/
150+
static QPixmap colorRampPreviewPixmap( QgsColorRamp* ramp, QSize size, int padding = 0 );
122151

123152
static void drawStippledBackground( QPainter* painter, QRect rect );
124153

125-
//! @note customContext parameter added in 2.6
126-
static QPixmap symbolPreviewPixmap( QgsSymbol* symbol, QSize size, QgsRenderContext* customContext = 0 );
127-
static QPixmap colorRampPreviewPixmap( QgsColorRamp* ramp, QSize size );
128-
129154
/** Returns the maximum estimated bleed for the symbol */
130155
static double estimateMaxSymbolBleed( QgsSymbol* symbol );
131156

‎src/core/layertree/qgslayertreemodellegendnode.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,15 @@ QSize QgsSymbolLegendNode::minimumIconSize( QgsRenderContext* context ) const
168168
if ( mItem.symbol() && mItem.symbol()->type() == QgsSymbol::Marker )
169169
{
170170
minSz = QgsImageOperation::nonTransparentImageRect(
171-
QgsSymbolLayerUtils::symbolPreviewPixmap( mItem.symbol(), QSize( 512, 512 ),
171+
QgsSymbolLayerUtils::symbolPreviewPixmap( mItem.symbol(), QSize( 512, 512 ), 0,
172172
context ).toImage(),
173173
minSz,
174174
true ).size();
175175
}
176176
else if ( mItem.symbol() && mItem.symbol()->type() == QgsSymbol::Line )
177177
{
178178
minSz = QgsImageOperation::nonTransparentImageRect(
179-
QgsSymbolLayerUtils::symbolPreviewPixmap( mItem.symbol(), QSize( minSz.width(), 512 ),
179+
QgsSymbolLayerUtils::symbolPreviewPixmap( mItem.symbol(), QSize( minSz.width(), 512 ), 0,
180180
context ).toImage(),
181181
minSz,
182182
true ).size();
@@ -273,7 +273,7 @@ QVariant QgsSymbolLegendNode::data( int role ) const
273273
if ( mItem.symbol() )
274274
{
275275
QScopedPointer<QgsRenderContext> context( createTemporaryRenderContext() );
276-
pix = QgsSymbolLayerUtils::symbolPreviewPixmap( mItem.symbol(), mIconSize, context.data() );
276+
pix = QgsSymbolLayerUtils::symbolPreviewPixmap( mItem.symbol(), mIconSize, 0, context.data() );
277277
}
278278
else
279279
{

‎src/core/symbology-ng/qgssymbollayerutils.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -574,12 +574,12 @@ QPainter::CompositionMode QgsSymbolLayerUtils::decodeBlendMode( const QString &s
574574
return QPainter::CompositionMode_SourceOver; // "Normal"
575575
}
576576

577-
QIcon QgsSymbolLayerUtils::symbolPreviewIcon( QgsSymbol* symbol, QSize size )
577+
QIcon QgsSymbolLayerUtils::symbolPreviewIcon( QgsSymbol* symbol, QSize size, int padding )
578578
{
579-
return QIcon( symbolPreviewPixmap( symbol, size ) );
579+
return QIcon( symbolPreviewPixmap( symbol, size, padding ) );
580580
}
581581

582-
QPixmap QgsSymbolLayerUtils::symbolPreviewPixmap( QgsSymbol* symbol, QSize size, QgsRenderContext* customContext )
582+
QPixmap QgsSymbolLayerUtils::symbolPreviewPixmap( QgsSymbol* symbol, QSize size, int padding, QgsRenderContext* customContext )
583583
{
584584
Q_ASSERT( symbol );
585585

@@ -588,9 +588,21 @@ QPixmap QgsSymbolLayerUtils::symbolPreviewPixmap( QgsSymbol* symbol, QSize size,
588588
QPainter painter;
589589
painter.begin( &pixmap );
590590
painter.setRenderHint( QPainter::Antialiasing );
591+
591592
if ( customContext )
593+
{
592594
customContext->setPainter( &painter );
595+
}
596+
597+
if ( padding > 0 )
598+
{
599+
size.setWidth( size.rwidth() - ( padding * 2 ) );
600+
size.setHeight( size.rheight() - ( padding * 2 ) );
601+
painter.translate( padding, padding );
602+
}
603+
593604
symbol->drawPreviewIcon( &painter, size, customContext );
605+
594606
painter.end();
595607
return pixmap;
596608
}
@@ -636,12 +648,12 @@ QIcon QgsSymbolLayerUtils::symbolLayerPreviewIcon( QgsSymbolLayer* layer, QgsUni
636648
return QIcon( pixmap );
637649
}
638650

639-
QIcon QgsSymbolLayerUtils::colorRampPreviewIcon( QgsColorRamp* ramp, QSize size )
651+
QIcon QgsSymbolLayerUtils::colorRampPreviewIcon( QgsColorRamp* ramp, QSize size, int padding )
640652
{
641-
return QIcon( colorRampPreviewPixmap( ramp, size ) );
653+
return QIcon( colorRampPreviewPixmap( ramp, size, padding ) );
642654
}
643655

644-
QPixmap QgsSymbolLayerUtils::colorRampPreviewPixmap( QgsColorRamp* ramp, QSize size )
656+
QPixmap QgsSymbolLayerUtils::colorRampPreviewPixmap( QgsColorRamp* ramp, QSize size, int padding )
645657
{
646658
QPixmap pixmap( size );
647659
pixmap.fill( Qt::transparent );
@@ -650,15 +662,15 @@ QPixmap QgsSymbolLayerUtils::colorRampPreviewPixmap( QgsColorRamp* ramp, QSize s
650662
painter.begin( &pixmap );
651663

652664
//draw stippled background, for transparent images
653-
drawStippledBackground( &painter, QRect( 0, 0, size.width(), size.height() ) );
665+
drawStippledBackground( &painter, QRect( padding, padding, size.width() - padding * 2, size.height() - padding * 2 ) );
654666

655667
// antialising makes the colors duller, and no point in antialiasing a color ramp
656668
// painter.setRenderHint( QPainter::Antialiasing );
657669
for ( int i = 0; i < size.width(); i++ )
658670
{
659671
QPen pen( ramp->color( static_cast< double >( i ) / size.width() ) );
660672
painter.setPen( pen );
661-
painter.drawLine( i, 0, i, size.height() - 1 );
673+
painter.drawLine( i, 0 + padding, i, size.height() - 1 - padding );
662674
}
663675
painter.end();
664676
return pixmap;

‎src/core/symbology-ng/qgssymbollayerutils.h

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,23 @@ class CORE_EXPORT QgsSymbolLayerUtils
138138

139139
static QPainter::CompositionMode decodeBlendMode( const QString& s );
140140

141-
static QIcon symbolPreviewIcon( QgsSymbol* symbol, QSize size );
141+
/** Returns an icon preview for a color ramp.
142+
* @param symbol symbol
143+
* @param size target pixmap size
144+
* @param padding space between icon edge and symbol
145+
* @see symbolPreviewPixmap()
146+
*/
147+
static QIcon symbolPreviewIcon( QgsSymbol* symbol, QSize size, int padding = 0 );
148+
149+
/** Returns a pixmap preview for a color ramp.
150+
* @param symbol symbol
151+
* @param size target pixmap size
152+
* @param padding space between icon edge and symbol
153+
* @param customContext render context to use when rendering symbol
154+
* @note customContext parameter added in 2.6
155+
* @see symbolPreviewIcon()
156+
*/
157+
static QPixmap symbolPreviewPixmap( QgsSymbol* symbol, QSize size, int padding = 0, QgsRenderContext* customContext = nullptr );
142158

143159
/** Draws a symbol layer preview to a QPicture
144160
* @param layer symbol layer to draw
@@ -161,25 +177,24 @@ class CORE_EXPORT QgsSymbolLayerUtils
161177
*/
162178
static QIcon symbolLayerPreviewIcon( QgsSymbolLayer* layer, QgsUnitTypes::RenderUnit u, QSize size, const QgsMapUnitScale& scale = QgsMapUnitScale() );
163179

164-
/** Returns a icon preview for a color ramp.
180+
/** Returns an icon preview for a color ramp.
165181
* @param ramp color ramp
166182
* @param size target icon size
183+
* @param padding space between icon edge and color ramp
167184
* @see colorRampPreviewPixmap()
168185
*/
169-
static QIcon colorRampPreviewIcon( QgsColorRamp* ramp, QSize size );
186+
static QIcon colorRampPreviewIcon( QgsColorRamp* ramp, QSize size, int padding = 0 );
170187

171188
/** Returns a pixmap preview for a color ramp.
172189
* @param ramp color ramp
173190
* @param size target pixmap size
191+
* @param padding space between icon edge and color ramp
174192
* @see colorRampPreviewIcon()
175193
*/
176-
static QPixmap colorRampPreviewPixmap( QgsColorRamp* ramp, QSize size );
194+
static QPixmap colorRampPreviewPixmap( QgsColorRamp* ramp, QSize size, int padding = 0 );
177195

178196
static void drawStippledBackground( QPainter* painter, QRect rect );
179197

180-
//! @note customContext parameter added in 2.6
181-
static QPixmap symbolPreviewPixmap( QgsSymbol* symbol, QSize size, QgsRenderContext* customContext = nullptr );
182-
183198
//! Returns the maximum estimated bleed for the symbol
184199
static double estimateMaxSymbolBleed( QgsSymbol* symbol );
185200

‎src/gui/symbology-ng/qgsstylemanagerdialog.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -236,17 +236,8 @@ void QgsStyleManagerDialog::on_tabItemType_currentChanged( int )
236236
actnExportAsPNG->setVisible( flag );
237237
actnExportAsSVG->setVisible( flag );
238238

239-
// set icon and grid size, depending on type
240-
if ( currentItemType() == 1 || currentItemType() == 3 )
241-
{
242-
listItems->setIconSize( QSize( 75, 50 ) );
243-
listItems->setGridSize( QSize( 100, 80 ) );
244-
}
245-
else
246-
{
247-
listItems->setIconSize( QSize( 50, 50 ) );
248-
listItems->setGridSize( QSize( 75, 80 ) );
249-
}
239+
listItems->setIconSize( QSize( 100, 90 ) );
240+
listItems->setGridSize( QSize( 120, 110 ) );
250241

251242
populateList();
252243
}
@@ -275,7 +266,7 @@ void QgsStyleManagerDialog::populateSymbols( const QStringList& symbolNames, boo
275266
if ( symbol && symbol->type() == type )
276267
{
277268
QStandardItem* item = new QStandardItem( name );
278-
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( symbol, listItems->iconSize() );
269+
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( symbol, listItems->iconSize(), 18 );
279270
item->setIcon( icon );
280271
item->setData( name ); // used to find out original name when user edited the name
281272
item->setCheckable( check );
@@ -301,7 +292,7 @@ void QgsStyleManagerDialog::populateColorRamps( const QStringList& colorRamps, b
301292
QScopedPointer< QgsColorRamp > ramp( mStyle->colorRamp( name ) );
302293

303294
QStandardItem* item = new QStandardItem( name );
304-
QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.data(), listItems->iconSize() );
295+
QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.data(), listItems->iconSize(), 18 );
305296
item->setIcon( icon );
306297
item->setData( name ); // used to find out original name when user edited the name
307298
item->setCheckable( check );

‎src/gui/symbology-ng/qgssymbolslistwidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ void QgsSymbolsListWidget::populateSymbols( const QStringList& names )
243243
itemFont.setPointSize( 10 );
244244
item->setFont( itemFont );
245245
// create preview icon
246-
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( s, previewSize );
246+
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( s, previewSize, 15 );
247247
item->setIcon( icon );
248248
// add to model
249249
model->appendRow( item );

‎src/ui/symbollayer/widget_symbolslist.ui

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
</property>
3838
<property name="iconSize">
3939
<size>
40-
<width>48</width>
41-
<height>48</height>
40+
<width>77</width>
41+
<height>70</height>
4242
</size>
4343
</property>
4444
<property name="textElideMode">

0 commit comments

Comments
 (0)
Please sign in to comment.