mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
Fix some more conditional formatting panel high dpi issues
This commit is contained in:
parent
72efc1edde
commit
1f033fe83d
@ -110,9 +110,11 @@ Check if the rule matches using the given value and feature
|
||||
:return: ``True`` of the rule matches against the given feature
|
||||
%End
|
||||
|
||||
QPixmap renderPreview() const;
|
||||
QPixmap renderPreview( const QSize &size = QSize() ) const;
|
||||
%Docstring
|
||||
Render a preview icon of the rule.
|
||||
Render a preview icon of the rule, at the specified ``size``.
|
||||
|
||||
If ``size`` is not specified, a default size will be used.
|
||||
|
||||
:return: QPixmap preview of the style
|
||||
%End
|
||||
|
@ -193,9 +193,9 @@ bool QgsConditionalStyle::matches( const QVariant &value, QgsExpressionContext &
|
||||
return exp.evaluate( &context ).toBool();
|
||||
}
|
||||
|
||||
QPixmap QgsConditionalStyle::renderPreview() const
|
||||
QPixmap QgsConditionalStyle::renderPreview( const QSize &size ) const
|
||||
{
|
||||
QPixmap pixmap( 64, 32 );
|
||||
QPixmap pixmap( size.isValid() ? size.width() : 64, size.isValid() ? size.height() : 32 );
|
||||
pixmap.fill( Qt::transparent );
|
||||
|
||||
QPainter painter( &pixmap );
|
||||
@ -203,10 +203,14 @@ QPixmap QgsConditionalStyle::renderPreview() const
|
||||
if ( validBackgroundColor() )
|
||||
painter.setBrush( mBackColor );
|
||||
|
||||
QRect rect = QRect( 0, 0, 64, 32 );
|
||||
QRect rect = QRect( 0, 0, pixmap.width(), pixmap.height() );
|
||||
painter.setPen( Qt::NoPen );
|
||||
painter.drawRect( rect );
|
||||
painter.drawPixmap( 8, 8, icon() );
|
||||
const QPixmap symbolIcon = icon();
|
||||
if ( !symbolIcon.isNull() )
|
||||
{
|
||||
painter.drawPixmap( ( pixmap.width() / 3 - symbolIcon.width() ) / 2, ( pixmap.height() - symbolIcon.height() ) / 2, symbolIcon );
|
||||
}
|
||||
|
||||
if ( validTextColor() )
|
||||
painter.setPen( mTextColor );
|
||||
@ -216,7 +220,7 @@ QPixmap QgsConditionalStyle::renderPreview() const
|
||||
painter.setRenderHint( QPainter::Antialiasing );
|
||||
painter.setRenderHint( QPainter::HighQualityAntialiasing );
|
||||
painter.setFont( font() );
|
||||
rect = QRect( 32, 0, 32, 32 );
|
||||
rect = QRect( pixmap.width() / 3, 0, 2 * pixmap.width() / 3, pixmap.height() );
|
||||
painter.drawText( rect, Qt::AlignCenter, QStringLiteral( "abc\n123" ) );
|
||||
painter.end();
|
||||
return pixmap;
|
||||
|
@ -127,10 +127,13 @@ class CORE_EXPORT QgsConditionalStyle
|
||||
bool matches( const QVariant &value, QgsExpressionContext &context ) const;
|
||||
|
||||
/**
|
||||
* \brief Render a preview icon of the rule.
|
||||
* \brief Render a preview icon of the rule, at the specified \a size.
|
||||
*
|
||||
* If \a size is not specified, a default size will be used.
|
||||
*
|
||||
* \returns QPixmap preview of the style
|
||||
*/
|
||||
QPixmap renderPreview() const;
|
||||
QPixmap renderPreview( const QSize &size = QSize() ) const;
|
||||
|
||||
/**
|
||||
* \brief Set the name of the style. Names are optional but handy for display
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "qgsstyle.h"
|
||||
#include "qgsvectorlayer.h"
|
||||
#include "qgsexpressioncontextutils.h"
|
||||
#include "qgsguiutils.h"
|
||||
|
||||
//
|
||||
// QgsFieldConditionalFormatWidget
|
||||
@ -189,10 +190,14 @@ void QgsFieldConditionalFormatWidget::reloadStyles()
|
||||
mModel->clear();
|
||||
|
||||
const auto constGetStyles = getStyles();
|
||||
|
||||
const QSize size( Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 10, Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 2 );
|
||||
listView->setIconSize( size );
|
||||
|
||||
for ( const QgsConditionalStyle &style : constGetStyles )
|
||||
{
|
||||
QStandardItem *item = new QStandardItem( style.displayText() );
|
||||
item->setIcon( QIcon( style.renderPreview() ) );
|
||||
item->setIcon( QIcon( style.renderPreview( size ) ) );
|
||||
mModel->appendRow( item );
|
||||
}
|
||||
}
|
||||
@ -253,6 +258,16 @@ QgsEditConditionalFormatRuleWidget::QgsEditConditionalFormatRuleWidget( QWidget
|
||||
mFontStrikethroughBtn->setChecked( false );
|
||||
mFontUnderlineBtn->setChecked( false );
|
||||
|
||||
const int buttonSize = QgsGuiUtils::scaleIconSize( 24 );
|
||||
mFontUnderlineBtn->setMinimumSize( buttonSize, buttonSize );
|
||||
mFontUnderlineBtn->setMaximumSize( buttonSize, buttonSize );
|
||||
mFontStrikethroughBtn->setMinimumSize( buttonSize, buttonSize );
|
||||
mFontStrikethroughBtn->setMaximumSize( buttonSize, buttonSize );
|
||||
mFontBoldBtn->setMinimumSize( buttonSize, buttonSize );
|
||||
mFontBoldBtn->setMaximumSize( buttonSize, buttonSize );
|
||||
mFontItalicBtn->setMinimumSize( buttonSize, buttonSize );
|
||||
mFontItalicBtn->setMaximumSize( buttonSize, buttonSize );
|
||||
|
||||
connect( mSaveRule, &QAbstractButton::clicked, this, &QgsEditConditionalFormatRuleWidget::ruleSaved );
|
||||
connect( mCancelButton, &QAbstractButton::clicked, this, &QgsEditConditionalFormatRuleWidget::cancelled );
|
||||
connect( mDeleteButton, &QAbstractButton::clicked, this, &QgsEditConditionalFormatRuleWidget::ruleDeleted );
|
||||
|
Loading…
x
Reference in New Issue
Block a user