QGIS API Documentation  3.6.0-Noosa (5873452)
qgssymbolbutton.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgssymbolbutton.h
3  -----------------
4  Date : July 2017
5  Copyright : (C) 2017 by Nyall Dawson
6  Email : nyall dot dawson at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgssymbolbutton.h"
17 #include "qgspanelwidget.h"
18 #include "qgsexpressioncontext.h"
20 #include "qgsvectorlayer.h"
22 #include "qgsstyle.h"
23 #include "qgscolorwidgets.h"
24 #include "qgscolorschemeregistry.h"
25 #include "qgscolorswatchgrid.h"
26 #include "qgssymbollayerutils.h"
27 #include "qgsapplication.h"
28 #include "qgsguiutils.h"
30 
31 #include <QMenu>
32 #include <QClipboard>
33 #include <QDrag>
34 
35 QgsSymbolButton::QgsSymbolButton( QWidget *parent, const QString &dialogTitle )
36  : QToolButton( parent )
37  , mDialogTitle( dialogTitle.isEmpty() ? tr( "Symbol Settings" ) : dialogTitle )
38 {
39  mSymbol.reset( QgsFillSymbol::createSimple( QgsStringMap() ) );
40 
41  setAcceptDrops( true );
42  connect( this, &QAbstractButton::clicked, this, &QgsSymbolButton::showSettingsDialog );
43 
44  //setup dropdown menu
45  mMenu = new QMenu( this );
46  connect( mMenu, &QMenu::aboutToShow, this, &QgsSymbolButton::prepareMenu );
47  setMenu( mMenu );
48  setPopupMode( QToolButton::MenuButtonPopup );
49 
50  //make sure height of button looks good under different platforms
51  QSize size = QToolButton::minimumSizeHint();
52  int fontHeight = static_cast< int >( Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 1.4 );
53  mSizeHint = QSize( size.width(), std::max( size.height(), fontHeight ) );
54 }
55 
57 {
58 
59  return mSizeHint;
60 }
61 
63 {
64  return mSizeHint;
65 }
66 
68 {
69  if ( type != mType )
70  {
71  switch ( type )
72  {
73  case QgsSymbol::Marker:
74  mSymbol.reset( QgsMarkerSymbol::createSimple( QgsStringMap() ) );
75  break;
76 
77  case QgsSymbol::Line:
78  mSymbol.reset( QgsLineSymbol::createSimple( QgsStringMap() ) );
79  break;
80 
81  case QgsSymbol::Fill:
82  mSymbol.reset( QgsFillSymbol::createSimple( QgsStringMap() ) );
83  break;
84 
85  case QgsSymbol::Hybrid:
86  break;
87  }
88  }
89  updatePreview();
90  mType = type;
91 }
92 
93 void QgsSymbolButton::showSettingsDialog()
94 {
95  QgsExpressionContext context;
96  if ( mExpressionContextGenerator )
97  context = mExpressionContextGenerator->createExpressionContext();
98  else
99  {
101  }
102  QgsSymbol *newSymbol = mSymbol->clone();
103 
104  QgsSymbolWidgetContext symbolContext;
105  symbolContext.setExpressionContext( &context );
106  symbolContext.setMapCanvas( mMapCanvas );
107  symbolContext.setMessageBar( mMessageBar );
108 
110  if ( panel && panel->dockMode() )
111  {
112  QgsSymbolSelectorWidget *d = new QgsSymbolSelectorWidget( newSymbol, QgsStyle::defaultStyle(), mLayer, nullptr );
113  d->setContext( symbolContext );
114  connect( d, &QgsPanelWidget::widgetChanged, this, &QgsSymbolButton::updateSymbolFromWidget );
115  connect( d, &QgsPanelWidget::panelAccepted, this, &QgsSymbolButton::cleanUpSymbolSelector );
116  panel->openPanel( d );
117  }
118  else
119  {
120  QgsSymbolSelectorDialog dialog( newSymbol, QgsStyle::defaultStyle(), mLayer, nullptr );
121  dialog.setWindowTitle( mDialogTitle );
122  dialog.setContext( symbolContext );
123  if ( dialog.exec() )
124  {
125  setSymbol( newSymbol );
126  }
127  else
128  {
129  delete newSymbol;
130  }
131 
132  // reactivate button's window
133  activateWindow();
134  }
135 }
136 
137 void QgsSymbolButton::updateSymbolFromWidget()
138 {
139  if ( QgsSymbolSelectorWidget *w = qobject_cast<QgsSymbolSelectorWidget *>( sender() ) )
140  setSymbol( w->symbol()->clone() );
141 }
142 
143 void QgsSymbolButton::cleanUpSymbolSelector( QgsPanelWidget *container )
144 {
145  QgsSymbolSelectorWidget *w = qobject_cast<QgsSymbolSelectorWidget *>( container );
146  if ( !w )
147  return;
148 
149  delete w->symbol();
150 }
151 
153 {
154  return mMapCanvas;
155 }
156 
158 {
159  mMapCanvas = mapCanvas;
160 }
161 
163 {
164  mMessageBar = bar;
165 }
166 
168 {
169  return mMessageBar;
170 }
171 
173 {
174  return mLayer;
175 }
176 
178 {
179  mLayer = layer;
180 }
181 
183 {
184  mExpressionContextGenerator = generator;
185 }
186 
188 {
189  mSymbol.reset( symbol );
190  updatePreview();
191  emit changed();
192 }
193 
194 void QgsSymbolButton::setColor( const QColor &color )
195 {
196  QColor opaque = color;
197  opaque.setAlphaF( 1.0 );
198 
199  if ( opaque == mSymbol->color() )
200  return;
201 
202  mSymbol->setColor( opaque );
203  updatePreview();
204  emit changed();
205 }
206 
208 {
209  QApplication::clipboard()->setMimeData( QgsSymbolLayerUtils::symbolToMimeData( mSymbol.get() ) );
210 }
211 
213 {
214  std::unique_ptr< QgsSymbol > symbol( QgsSymbolLayerUtils::symbolFromMimeData( QApplication::clipboard()->mimeData() ) );
215  if ( symbol && symbol->type() == mType )
216  setSymbol( symbol.release() );
217 }
218 
220 {
221  QApplication::clipboard()->setMimeData( QgsSymbolLayerUtils::colorToMimeData( mSymbol->color() ) );
222 }
223 
225 {
226  QColor clipColor;
227  bool hasAlpha = false;
228  if ( colorFromMimeData( QApplication::clipboard()->mimeData(), clipColor, hasAlpha ) )
229  {
230  //paste color
231  setColor( clipColor );
233  }
234 }
235 
236 void QgsSymbolButton::mousePressEvent( QMouseEvent *e )
237 {
238  if ( e->button() == Qt::RightButton )
239  {
240  QToolButton::showMenu();
241  return;
242  }
243  else if ( e->button() == Qt::LeftButton )
244  {
245  mDragStartPosition = e->pos();
246  }
247  QToolButton::mousePressEvent( e );
248 }
249 
250 void QgsSymbolButton::mouseMoveEvent( QMouseEvent *e )
251 {
252  //handle dragging colors/symbols from button
253 
254  if ( !( e->buttons() & Qt::LeftButton ) )
255  {
256  //left button not depressed, so not a drag
257  QToolButton::mouseMoveEvent( e );
258  return;
259  }
260 
261  if ( ( e->pos() - mDragStartPosition ).manhattanLength() < QApplication::startDragDistance() )
262  {
263  //mouse not moved, so not a drag
264  QToolButton::mouseMoveEvent( e );
265  return;
266  }
267 
268  //user is dragging
269  QDrag *drag = new QDrag( this );
270  drag->setMimeData( QgsSymbolLayerUtils::colorToMimeData( mSymbol->color() ) );
271  drag->setPixmap( QgsColorWidget::createDragIcon( mSymbol->color() ) );
272  drag->exec( Qt::CopyAction );
273  setDown( false );
274 }
275 
276 void QgsSymbolButton::dragEnterEvent( QDragEnterEvent *e )
277 {
278  //is dragged data valid color data?
279  QColor mimeColor;
280  bool hasAlpha = false;
281 
282  if ( colorFromMimeData( e->mimeData(), mimeColor, hasAlpha ) )
283  {
284  //if so, we accept the drag, and temporarily change the button's color
285  //to match the dragged color. This gives immediate feedback to the user
286  //that colors can be dropped here
287  e->acceptProposedAction();
288  updatePreview( mimeColor );
289  }
290 }
291 
292 void QgsSymbolButton::dragLeaveEvent( QDragLeaveEvent *e )
293 {
294  Q_UNUSED( e );
295  //reset button color
296  updatePreview();
297 }
298 
299 void QgsSymbolButton::dropEvent( QDropEvent *e )
300 {
301  //is dropped data valid format data?
302  QColor mimeColor;
303  bool hasAlpha = false;
304  if ( colorFromMimeData( e->mimeData(), mimeColor, hasAlpha ) )
305  {
306  //accept drop and set new color
307  e->acceptProposedAction();
308  mimeColor.setAlphaF( 1.0 );
309  mSymbol->setColor( mimeColor );
311  updatePreview();
312  emit changed();
313  }
314  updatePreview();
315 }
316 
317 void QgsSymbolButton::prepareMenu()
318 {
319  //we need to tear down and rebuild this menu every time it is shown. Otherwise the space allocated to any
320  //QgsColorSwatchGridAction is not recalculated by Qt and the swatch grid may not be the correct size
321  //for the number of colors shown in the grid. Note that we MUST refresh color swatch grids every time this
322  //menu is opened, otherwise color schemes like the recent color scheme grid are meaningless
323  mMenu->clear();
324 
325  QAction *configureAction = new QAction( tr( "Configure Symbol…" ), this );
326  mMenu->addAction( configureAction );
327  connect( configureAction, &QAction::triggered, this, &QgsSymbolButton::showSettingsDialog );
328 
329  QAction *copySymbolAction = new QAction( tr( "Copy Symbol" ), this );
330  mMenu->addAction( copySymbolAction );
331  connect( copySymbolAction, &QAction::triggered, this, &QgsSymbolButton::copySymbol );
332  QAction *pasteSymbolAction = new QAction( tr( "Paste Symbol" ), this );
333  //enable or disable paste action based on current clipboard contents. We always show the paste
334  //action, even if it's disabled, to give hint to the user that pasting symbols is possible
335  std::unique_ptr< QgsSymbol > tempSymbol( QgsSymbolLayerUtils::symbolFromMimeData( QApplication::clipboard()->mimeData() ) );
336  if ( tempSymbol && tempSymbol->type() == mType )
337  {
338  const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
339  pasteSymbolAction->setIcon( QgsSymbolLayerUtils::symbolPreviewIcon( tempSymbol.get(), QSize( iconSize, iconSize ), 1 ) );
340  }
341  else
342  {
343  pasteSymbolAction->setEnabled( false );
344  }
345  mMenu->addAction( pasteSymbolAction );
346  connect( pasteSymbolAction, &QAction::triggered, this, &QgsSymbolButton::pasteSymbol );
347 
348  mMenu->addSeparator();
349 
350  QgsColorWheel *colorWheel = new QgsColorWheel( mMenu );
351  colorWheel->setColor( mSymbol->color() );
352  QgsColorWidgetAction *colorAction = new QgsColorWidgetAction( colorWheel, mMenu, mMenu );
353  colorAction->setDismissOnColorSelection( false );
354  connect( colorAction, &QgsColorWidgetAction::colorChanged, this, &QgsSymbolButton::setColor );
355  mMenu->addAction( colorAction );
356 
358  QColor alphaColor = mSymbol->color();
359  alphaColor.setAlphaF( mSymbol->opacity() );
360  alphaRamp->setColor( alphaColor );
361  QgsColorWidgetAction *alphaAction = new QgsColorWidgetAction( alphaRamp, mMenu, mMenu );
362  alphaAction->setDismissOnColorSelection( false );
363  connect( alphaAction, &QgsColorWidgetAction::colorChanged, this, [ = ]( const QColor & color )
364  {
365  double opacity = color.alphaF();
366  mSymbol->setOpacity( opacity );
367  updatePreview();
368  emit changed();
369  } );
370  connect( colorAction, &QgsColorWidgetAction::colorChanged, alphaRamp, [alphaRamp]( const QColor & color ) { alphaRamp->setColor( color, false ); }
371  );
372  mMenu->addAction( alphaAction );
373 
374  //get schemes with ShowInColorButtonMenu flag set
375  QList< QgsColorScheme * > schemeList = QgsApplication::colorSchemeRegistry()->schemes( QgsColorScheme::ShowInColorButtonMenu );
376  QList< QgsColorScheme * >::iterator it = schemeList.begin();
377  for ( ; it != schemeList.end(); ++it )
378  {
379  QgsColorSwatchGridAction *colorAction = new QgsColorSwatchGridAction( *it, mMenu, QStringLiteral( "symbology" ), this );
380  colorAction->setBaseColor( mSymbol->color() );
381  mMenu->addAction( colorAction );
382  connect( colorAction, &QgsColorSwatchGridAction::colorChanged, this, &QgsSymbolButton::setColor );
383  connect( colorAction, &QgsColorSwatchGridAction::colorChanged, this, &QgsSymbolButton::addRecentColor );
384  }
385 
386  mMenu->addSeparator();
387 
388  QAction *copyColorAction = new QAction( tr( "Copy Color" ), this );
389  mMenu->addAction( copyColorAction );
390  connect( copyColorAction, &QAction::triggered, this, &QgsSymbolButton::copyColor );
391 
392  QAction *pasteColorAction = new QAction( tr( "Paste Color" ), this );
393  //enable or disable paste action based on current clipboard contents. We always show the paste
394  //action, even if it's disabled, to give hint to the user that pasting colors is possible
395  QColor clipColor;
396  bool hasAlpha = false;
397  if ( colorFromMimeData( QApplication::clipboard()->mimeData(), clipColor, hasAlpha ) )
398  {
399  pasteColorAction->setIcon( createColorIcon( clipColor ) );
400  }
401  else
402  {
403  pasteColorAction->setEnabled( false );
404  }
405  mMenu->addAction( pasteColorAction );
406  connect( pasteColorAction, &QAction::triggered, this, &QgsSymbolButton::pasteColor );
407 }
408 
409 void QgsSymbolButton::addRecentColor( const QColor &color )
410 {
412 }
413 
414 
416 {
417  if ( e->type() == QEvent::EnabledChange )
418  {
419  updatePreview();
420  }
421  QToolButton::changeEvent( e );
422 }
423 
424 void QgsSymbolButton::showEvent( QShowEvent *e )
425 {
426  updatePreview();
427  QToolButton::showEvent( e );
428 }
429 
430 void QgsSymbolButton::resizeEvent( QResizeEvent *event )
431 {
432  QToolButton::resizeEvent( event );
433  //recalculate icon size and redraw icon
434  mIconSize = QSize();
435  updatePreview();
436 }
437 
438 void QgsSymbolButton::updatePreview( const QColor &color, QgsSymbol *tempSymbol )
439 {
440  std::unique_ptr< QgsSymbol > previewSymbol;
441 
442  if ( tempSymbol )
443  previewSymbol.reset( tempSymbol->clone() );
444  else
445  previewSymbol.reset( mSymbol->clone() );
446 
447  if ( color.isValid() )
448  previewSymbol->setColor( color );
449 
450  QSize currentIconSize;
451  //icon size is button size with a small margin
452  if ( menu() )
453  {
454  if ( !mIconSize.isValid() )
455  {
456  //calculate size of push button part of widget (ie, without the menu dropdown button part)
457  QStyleOptionToolButton opt;
458  initStyleOption( &opt );
459  QRect buttonSize = QApplication::style()->subControlRect( QStyle::CC_ToolButton, &opt, QStyle::SC_ToolButton,
460  this );
461  //make sure height of icon looks good under different platforms
462 #ifdef Q_OS_WIN
463  mIconSize = QSize( buttonSize.width() - 10, height() - 6 );
464 #else
465  mIconSize = QSize( buttonSize.width() - 10, height() - 12 );
466 #endif
467  }
468  currentIconSize = mIconSize;
469  }
470  else
471  {
472  //no menu
473 #ifdef Q_OS_WIN
474  currentIconSize = QSize( width() - 10, height() - 6 );
475 #else
476  currentIconSize = QSize( width() - 10, height() - 12 );
477 #endif
478  }
479 
480  if ( !currentIconSize.isValid() || currentIconSize.width() <= 0 || currentIconSize.height() <= 0 )
481  {
482  return;
483  }
484 
485  //create an icon pixmap
486  QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( previewSymbol.get(), currentIconSize );
487  setIconSize( currentIconSize );
488  setIcon( icon );
489 
490  // set tooltip
491  // create very large preview image
492  int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 23 );
493  int height = static_cast< int >( width / 1.61803398875 ); // golden ratio
494 
495  QPixmap pm = QgsSymbolLayerUtils::symbolPreviewPixmap( previewSymbol.get(), QSize( width, height ), height / 20 );
496  QByteArray data;
497  QBuffer buffer( &data );
498  pm.save( &buffer, "PNG", 100 );
499  setToolTip( QStringLiteral( "<img src='data:image/png;base64, %3'>" ).arg( QString( data.toBase64() ) ) );
500 }
501 
502 bool QgsSymbolButton::colorFromMimeData( const QMimeData *mimeData, QColor &resultColor, bool &hasAlpha )
503 {
504  hasAlpha = false;
505  QColor mimeColor = QgsSymbolLayerUtils::colorFromMimeData( mimeData, hasAlpha );
506 
507  if ( mimeColor.isValid() )
508  {
509  resultColor = mimeColor;
510  return true;
511  }
512 
513  //could not get color from mime data
514  return false;
515 }
516 
517 QPixmap QgsSymbolButton::createColorIcon( const QColor &color ) const
518 {
519  //create an icon pixmap
520  const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
521  QPixmap pixmap( iconSize, iconSize );
522  pixmap.fill( Qt::transparent );
523 
524  QPainter p;
525  p.begin( &pixmap );
526 
527  //draw color over pattern
528  p.setBrush( QBrush( color ) );
529 
530  //draw border
531  p.setPen( QColor( 197, 197, 197 ) );
532  p.drawRect( 0, 0, iconSize - 1, iconSize - 1 );
533  p.end();
534  return pixmap;
535 }
536 
537 void QgsSymbolButton::setDialogTitle( const QString &title )
538 {
539  mDialogTitle = title;
540 }
541 
542 QString QgsSymbolButton::dialogTitle() const
543 {
544  return mDialogTitle;
545 }
546 
548 {
549  return mSymbol.get();
550 }
void openPanel(QgsPanelWidget *panel)
Open a panel or dialog depending on dock mode setting If dock mode is true this method will emit the ...
A color swatch grid which can be embedded into a menu.
static QgsSymbol * symbolFromMimeData(const QMimeData *data)
Attempts to parse mime data as a symbol.
void setMessageBar(QgsMessageBar *bar)
Sets the message bar associated with the widget.
void registerExpressionContextGenerator(QgsExpressionContextGenerator *generator)
Register an expression context generator class that will be used to retrieve an expression context fo...
QSize minimumSizeHint() const override
bool dockMode()
Returns the dock mode state.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:61
void copyColor()
Copies the current symbol color to the clipboard.
static const double UI_SCALE_FACTOR
UI scaling factor.
Definition: qgis.h:139
QgsSymbol * symbol()
Returns the symbol that is currently active in the widget.
void mousePressEvent(QMouseEvent *e) override
virtual void setColor(const QColor &color, bool emitSignals=false)
Sets the color for the widget.
static QgsLineSymbol * createSimple(const QgsStringMap &properties)
Create a line symbol with one symbol layer: SimpleLine with specified properties. ...
Definition: qgssymbol.cpp:1137
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly...
void setDialogTitle(const QString &title)
Sets the title for the symbol settings dialog window.
static QgsFillSymbol * createSimple(const QgsStringMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties. ...
Definition: qgssymbol.cpp:1148
void showEvent(QShowEvent *e) override
static QIcon symbolPreviewIcon(const QgsSymbol *symbol, QSize size, int padding=0)
Returns an icon preview for a color ramp.
void changed()
Emitted when the symbol&#39;s settings are changed.
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:45
void colorChanged(const QColor &color)
Emitted when a color has been selected from the widget.
Base class for any widget that can be shown as a inline panel.
Line symbol.
Definition: qgssymbol.h:86
Show scheme in color button drop-down menu.
void panelAccepted(QgsPanelWidget *panel)
Emitted when the panel is accepted by the user.
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the widget.
QMap< QString, QString > QgsStringMap
Definition: qgis.h:587
void pasteSymbol()
Pastes a symbol from the clipboard.
void pasteColor()
Pastes a color from the clipboard to the symbol.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:73
static QgsStyle * defaultStyle()
Returns default application-wide style.
Definition: qgsstyle.cpp:46
void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the symbol widget is shown, e.g., the associated map canvas and expression ...
void setMessageBar(QgsMessageBar *bar)
Sets the message bar associated with the widget.
SymbolType
Type of the symbol.
Definition: qgssymbol.h:83
QList< QgsColorScheme * > schemes() const
Returns all color schemes in the registry.
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
void resizeEvent(QResizeEvent *event) override
A color wheel widget.
QgsSymbolButton(QWidget *parent=nullptr, const QString &dialogTitle=QString())
Construct a new symbol button.
static QgsPanelWidget * findParentPanel(QWidget *widget)
Traces through the parents of a widget to find if it is contained within a QgsPanelWidget widget...
Contains settings which reflect the context in which a symbol (or renderer) widget is shown...
Alpha component (opacity) of color.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
A color ramp widget.
void mouseMoveEvent(QMouseEvent *e) override
void setColor(const QColor &color, bool emitSignals=false) override
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer&#39;s project and layer.
Symbol selector widget that can be used to select and build a symbol.
void setColor(const QColor &color)
Sets the current color for the symbol.
QString dialogTitle() const
Returns the title for the symbol settings dialog window.
static void addRecentColor(const QColor &color)
Adds a color to the list of recent colors.
void widgetChanged()
Emitted when the widget state changes.
void changeEvent(QEvent *e) override
void setExpressionContext(QgsExpressionContext *context)
Sets the optional expression context used for the widget.
Abstract interface for generating an expression context.
QgsVectorLayer * layer() const
Returns the layer associated with the widget.
Marker symbol.
Definition: qgssymbol.h:85
static QgsColorSchemeRegistry * colorSchemeRegistry()
Returns the application&#39;s color scheme registry, used for managing color schemes. ...
Fill symbol.
Definition: qgssymbol.h:87
void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the symbol widget is shown, e.g., the associated map canvas and expression ...
void setLayer(QgsVectorLayer *layer)
Sets a layer to associate with the widget.
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
An action containing a color widget, which can be embedded into a menu.
void dropEvent(QDropEvent *e) override
static QMimeData * colorToMimeData(const QColor &color)
Creates mime data from a color.
void dragLeaveEvent(QDragLeaveEvent *e) override
QSize sizeHint() const override
void setMapCanvas(QgsMapCanvas *canvas)
Sets a map canvas to associate with the widget.
static QMimeData * symbolToMimeData(QgsSymbol *symbol)
Creates new mime data from a symbol.
void setSymbol(QgsSymbol *symbol)
Sets the symbol for the button.
void appendScopes(const QList< QgsExpressionContextScope *> &scopes)
Appends a list of scopes to the end of the context.
static QgsMarkerSymbol * createSimple(const QgsStringMap &properties)
Create a marker symbol with one symbol layer: SimpleMarker with specified properties.
Definition: qgssymbol.cpp:1126
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
void copySymbol()
Copies the current symbol to the clipboard.
void setDismissOnColorSelection(bool dismiss)
Sets whether the parent menu should be dismissed and closed when a color is selected from the action&#39;...
Represents a vector layer which manages a vector based data sets.
void setSymbolType(QgsSymbol::SymbolType type)
Sets the symbol type which the button requires.
static QPixmap createDragIcon(const QColor &color)
Create an icon for dragging colors.
void dragEnterEvent(QDragEnterEvent *e) override
QgsSymbol * symbol()
Returns the current symbol defined by the button.
Hybrid symbol.
Definition: qgssymbol.h:88
static QColor colorFromMimeData(const QMimeData *data, bool &hasAlpha)
Attempts to parse mime data as a color.
QgsMessageBar * messageBar() const
Returns the message bar associated with the widget.
void colorChanged(const QColor &color)
Emitted when a color has been selected from the widget.
void setBaseColor(const QColor &baseColor)
Sets the base color for the color grid.
static QPixmap symbolPreviewPixmap(const QgsSymbol *symbol, QSize size, int padding=0, QgsRenderContext *customContext=nullptr)
Returns a pixmap preview for a color ramp.