QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
Go to the documentation of this file.
23 : QToolButton( parent )
24 , mShape(
QgsStyle::defaultStyle()->defaultPatch(
QgsSymbol::Fill, QSizeF( 10, 5 ) ) )
25 , mDialogTitle( dialogTitle.isEmpty() ? tr(
"Legend Patch Shape" ) : dialogTitle )
29 connect(
this, &QAbstractButton::clicked,
this, &QgsLegendPatchShapeButton::showSettingsDialog );
32 mMenu =
new QMenu(
this );
33 connect( mMenu, &QMenu::aboutToShow,
this, &QgsLegendPatchShapeButton::prepareMenu );
35 setPopupMode( QToolButton::MenuButtonPopup );
38 QSize size = QToolButton::minimumSizeHint();
40 mSizeHint = QSize( size.width(), std::max( size.height(), fontHeight ) );
55 if ( mPreviewSymbol->type() != type )
87 mPreviewSymbol.reset( symbol );
91 void QgsLegendPatchShapeButton::showSettingsDialog()
143 mIsDefault = mShape.
isNull();
171 if ( e->button() == Qt::RightButton )
173 QToolButton::showMenu();
176 QToolButton::mousePressEvent( e );
179 void QgsLegendPatchShapeButton::prepareMenu()
183 QAction *configureAction =
new QAction( tr(
"Configure Patch…" ),
this );
184 mMenu->addAction( configureAction );
185 connect( configureAction, &QAction::triggered,
this, &QgsLegendPatchShapeButton::showSettingsDialog );
187 QAction *defaultAction =
new QAction( tr(
"Reset to Default" ),
this );
188 mMenu->addAction( defaultAction );
189 connect( defaultAction, &QAction::triggered,
this, [ = ] {
setToDefault(); emit
changed(); } );
191 mMenu->addSeparator();
196 for (
const QString &name : qgis::as_const( patchNames ) )
204 QAction *action =
new QAction( name,
this );
205 action->setIcon( icon );
206 connect( action, &QAction::triggered,
this, [ = ] { loadPatchFromStyle( name ); } );
207 mMenu->addAction( action );
213 void QgsLegendPatchShapeButton::loadPatchFromStyle(
const QString &name )
224 if ( e->type() == QEvent::EnabledChange )
228 QToolButton::changeEvent( e );
234 QToolButton::showEvent( e );
239 QToolButton::resizeEvent( event );
245 void QgsLegendPatchShapeButton::updatePreview()
247 QSize currentIconSize;
251 if ( !mIconSize.isValid() )
254 QStyleOptionToolButton opt;
255 initStyleOption( &opt );
256 QRect buttonSize = QApplication::style()->subControlRect( QStyle::CC_ToolButton, &opt, QStyle::SC_ToolButton,
260 mIconSize = QSize( buttonSize.width() - 10, height() - 6 );
262 mIconSize = QSize( buttonSize.width() - 10, height() - 12 );
265 currentIconSize = mIconSize;
271 currentIconSize = QSize( width() - 10, height() - 6 );
273 currentIconSize = QSize( width() - 10, height() - 12 );
277 if ( !currentIconSize.isValid() || currentIconSize.width() <= 0 || currentIconSize.height() <= 0 )
284 setIconSize( currentIconSize );
290 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
293 int width =
static_cast< int >(
Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance(
'X' ) * 23 );
295 int height =
static_cast< int >( width / 1.61803398875 );
299 QBuffer buffer( &data );
300 pm.save( &buffer,
"PNG", 100 );
301 setToolTip( QStringLiteral(
"<img src='data:image/png;base64, %3'>" ).arg( QString( data.toBase64() ) ) );
306 mDialogTitle = title;
QStringList symbolsOfFavorite(StyleEntity type) const
Returns the symbol names which are flagged as favorite.
static QgsMarkerSymbol * createSimple(const QgsStringMap &properties)
Create a marker symbol with one symbol layer: SimpleMarker with specified properties.
@ LegendPatchShapeEntity
Legend patch shape (since QGIS 3.14)
QgsLegendPatchShape defaultPatch(QgsSymbol::SymbolType type, QSizeF size) const
Returns the default legend patch shape for the given symbol type.
QgsSymbol::SymbolType symbolType() const
Returns the symbol type associated with this patch.
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.
static QgsStyle * defaultStyle()
Returns default application-wide style.
static QIcon symbolPreviewIcon(const QgsSymbol *symbol, QSize size, int padding=0, QgsLegendPatchShape *shape=nullptr)
Returns an icon preview for a color ramp.
static QPixmap symbolPreviewPixmap(const QgsSymbol *symbol, QSize size, int padding=0, QgsRenderContext *customContext=nullptr, bool selected=false, const QgsExpressionContext *expressionContext=nullptr, const QgsLegendPatchShape *shape=nullptr)
Returns a pixmap preview for a color ramp.
static const double UI_SCALE_FACTOR
UI scaling factor.
QMap< QString, QString > QgsStringMap
QgsLegendPatchShape legendPatchShape(const QString &name) const
Returns the legend patch shape with the specified name.
static QgsLineSymbol * createSimple(const QgsStringMap &properties)
Create a line symbol with one symbol layer: SimpleLine with specified properties.
static QgsFillSymbol * createSimple(const QgsStringMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties.
SymbolType
Type of the symbol.
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly,...
bool isNull() const
Returns true if the patch shape is a null QgsLegendPatchShape, which indicates that the default legen...