QGIS API Documentation  3.20.0-Odense (decaadbb31)
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 #include "qgsgui.h"
31 #include "qgscolordialog.h"
32 #include "qgsfillsymbol.h"
33 #include "qgslinesymbol.h"
34 #include "qgsmarkersymbol.h"
35 
36 #include <QMenu>
37 #include <QClipboard>
38 #include <QDrag>
39 #include <QBuffer>
40 
41 QgsSymbolButton::QgsSymbolButton( QWidget *parent, const QString &dialogTitle )
42  : QToolButton( parent )
43  , mDialogTitle( dialogTitle.isEmpty() ? tr( "Symbol Settings" ) : dialogTitle )
44 {
45  mSymbol.reset( QgsFillSymbol::createSimple( QVariantMap() ) );
46 
47  setAcceptDrops( true );
48  connect( this, &QAbstractButton::clicked, this, &QgsSymbolButton::showSettingsDialog );
49 
50  //setup dropdown menu
51  mMenu = new QMenu( this );
52  connect( mMenu, &QMenu::aboutToShow, this, &QgsSymbolButton::prepareMenu );
53  setMenu( mMenu );
54  setPopupMode( QToolButton::MenuButtonPopup );
55 
56  //make sure height of button looks good under different platforms
57  QSize size = QToolButton::minimumSizeHint();
58  int fontHeight = static_cast< int >( Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 1.4 );
59  mSizeHint = QSize( size.width(), std::max( size.height(), fontHeight ) );
60 }
61 
63 
65 {
66 
67  return mSizeHint;
68 }
69 
71 {
72  return mSizeHint;
73 }
74 
76 {
77  if ( type != mType )
78  {
79  switch ( type )
80  {
82  mSymbol.reset( QgsMarkerSymbol::createSimple( QVariantMap() ) );
83  break;
84 
86  mSymbol.reset( QgsLineSymbol::createSimple( QVariantMap() ) );
87  break;
88 
90  mSymbol.reset( QgsFillSymbol::createSimple( QVariantMap() ) );
91  break;
92 
94  break;
95  }
96  }
97  updatePreview();
98  mType = type;
99 }
100 
101 void QgsSymbolButton::showSettingsDialog()
102 {
103  QgsExpressionContext context;
104  if ( mExpressionContextGenerator )
105  context = mExpressionContextGenerator->createExpressionContext();
106  else
107  {
109  }
110  QgsSymbol *newSymbol = mSymbol->clone();
111 
112  QgsSymbolWidgetContext symbolContext;
113  symbolContext.setExpressionContext( &context );
114  symbolContext.setMapCanvas( mMapCanvas );
115  symbolContext.setMessageBar( mMessageBar );
116 
118  if ( panel && panel->dockMode() )
119  {
120  QgsSymbolSelectorWidget *d = new QgsSymbolSelectorWidget( newSymbol, QgsStyle::defaultStyle(), mLayer, panel );
121  d->setPanelTitle( mDialogTitle );
122  d->setContext( symbolContext );
123  connect( d, &QgsPanelWidget::widgetChanged, this, &QgsSymbolButton::updateSymbolFromWidget );
124  connect( d, &QgsPanelWidget::panelAccepted, this, &QgsSymbolButton::cleanUpSymbolSelector );
125  panel->openPanel( d );
126  }
127  else
128  {
129  QgsSymbolSelectorDialog dialog( newSymbol, QgsStyle::defaultStyle(), mLayer, this );
130  dialog.setWindowTitle( mDialogTitle );
131  dialog.setContext( symbolContext );
132  if ( dialog.exec() )
133  {
134  setSymbol( newSymbol );
135  }
136  else
137  {
138  delete newSymbol;
139  }
140 
141  // reactivate button's window
142  activateWindow();
143  }
144 }
145 
146 void QgsSymbolButton::updateSymbolFromWidget()
147 {
148  if ( QgsSymbolSelectorWidget *w = qobject_cast<QgsSymbolSelectorWidget *>( sender() ) )
149  setSymbol( w->symbol()->clone() );
150 }
151 
152 void QgsSymbolButton::cleanUpSymbolSelector( QgsPanelWidget *container )
153 {
154  QgsSymbolSelectorWidget *w = qobject_cast<QgsSymbolSelectorWidget *>( container );
155  if ( !w )
156  return;
157 
158  delete w->symbol();
159 }
160 
162 {
163  return mMapCanvas;
164 }
165 
167 {
168  mMapCanvas = mapCanvas;
169 }
170 
172 {
173  mMessageBar = bar;
174 }
175 
177 {
178  return mMessageBar;
179 }
180 
182 {
183  return mLayer;
184 }
185 
187 {
188  mLayer = layer;
189 }
190 
192 {
193  mExpressionContextGenerator = generator;
194 }
195 
197 {
198  mSymbol.reset( symbol );
199  updatePreview();
200  emit changed();
201 }
202 
203 void QgsSymbolButton::setColor( const QColor &color )
204 {
205  QColor opaque = color;
206  opaque.setAlphaF( 1.0 );
207 
208  if ( opaque == mSymbol->color() )
209  return;
210 
211  mSymbol->setColor( opaque );
212  updatePreview();
213  emit changed();
214 }
215 
217 {
218  QApplication::clipboard()->setMimeData( QgsSymbolLayerUtils::symbolToMimeData( mSymbol.get() ) );
219 }
220 
222 {
223  std::unique_ptr< QgsSymbol > symbol( QgsSymbolLayerUtils::symbolFromMimeData( QApplication::clipboard()->mimeData() ) );
224  if ( symbol && symbol->type() == mType )
225  setSymbol( symbol.release() );
226 }
227 
229 {
230  QApplication::clipboard()->setMimeData( QgsSymbolLayerUtils::colorToMimeData( mSymbol->color() ) );
231 }
232 
234 {
235  QColor clipColor;
236  bool hasAlpha = false;
237  if ( colorFromMimeData( QApplication::clipboard()->mimeData(), clipColor, hasAlpha ) )
238  {
239  //paste color
240  setColor( clipColor );
242  }
243 }
244 
245 void QgsSymbolButton::mousePressEvent( QMouseEvent *e )
246 {
247  if ( mPickingColor )
248  {
249  //don't show dialog if in color picker mode
250  e->accept();
251  return;
252  }
253 
254  if ( e->button() == Qt::RightButton )
255  {
256  QToolButton::showMenu();
257  return;
258  }
259  else if ( e->button() == Qt::LeftButton )
260  {
261  mDragStartPosition = e->pos();
262  }
263  QToolButton::mousePressEvent( e );
264 }
265 
266 void QgsSymbolButton::mouseMoveEvent( QMouseEvent *e )
267 {
268  if ( mPickingColor )
269  {
270  updatePreview( QgsGui::sampleColor( e->globalPos() ) );
271  e->accept();
272  return;
273  }
274 
275  //handle dragging colors/symbols from button
276 
277  if ( !( e->buttons() & Qt::LeftButton ) )
278  {
279  //left button not depressed, so not a drag
280  QToolButton::mouseMoveEvent( e );
281  return;
282  }
283 
284  if ( ( e->pos() - mDragStartPosition ).manhattanLength() < QApplication::startDragDistance() )
285  {
286  //mouse not moved, so not a drag
287  QToolButton::mouseMoveEvent( e );
288  return;
289  }
290 
291  //user is dragging
292  QDrag *drag = new QDrag( this );
293  drag->setMimeData( QgsSymbolLayerUtils::colorToMimeData( mSymbol->color() ) );
294  drag->setPixmap( QgsColorWidget::createDragIcon( mSymbol->color() ) );
295  drag->exec( Qt::CopyAction );
296  setDown( false );
297 }
298 
300 {
301  if ( mPickingColor )
302  {
303  //end color picking operation by sampling the color under cursor
304  stopPicking( e->globalPos() );
305  e->accept();
306  return;
307  }
308 
309  QToolButton::mouseReleaseEvent( e );
310 }
311 
312 void QgsSymbolButton::keyPressEvent( QKeyEvent *e )
313 {
314  if ( !mPickingColor )
315  {
316  //if not picking a color, use default tool button behavior
317  QToolButton::keyPressEvent( e );
318  return;
319  }
320 
321  //cancel picking, sampling the color if space was pressed
322  stopPicking( QCursor::pos(), e->key() == Qt::Key_Space );
323 }
324 
325 void QgsSymbolButton::dragEnterEvent( QDragEnterEvent *e )
326 {
327  //is dragged data valid color data?
328  QColor mimeColor;
329  bool hasAlpha = false;
330 
331  if ( colorFromMimeData( e->mimeData(), mimeColor, hasAlpha ) )
332  {
333  //if so, we accept the drag, and temporarily change the button's color
334  //to match the dragged color. This gives immediate feedback to the user
335  //that colors can be dropped here
336  e->acceptProposedAction();
337  updatePreview( mimeColor );
338  }
339 }
340 
341 void QgsSymbolButton::dragLeaveEvent( QDragLeaveEvent *e )
342 {
343  Q_UNUSED( e )
344  //reset button color
345  updatePreview();
346 }
347 
348 void QgsSymbolButton::dropEvent( QDropEvent *e )
349 {
350  //is dropped data valid format data?
351  QColor mimeColor;
352  bool hasAlpha = false;
353  if ( colorFromMimeData( e->mimeData(), mimeColor, hasAlpha ) )
354  {
355  //accept drop and set new color
356  e->acceptProposedAction();
357  mimeColor.setAlphaF( 1.0 );
358  mSymbol->setColor( mimeColor );
360  updatePreview();
361  emit changed();
362  }
363  updatePreview();
364 }
365 
366 void QgsSymbolButton::prepareMenu()
367 {
368  //we need to tear down and rebuild this menu every time it is shown. Otherwise the space allocated to any
369  //QgsColorSwatchGridAction is not recalculated by Qt and the swatch grid may not be the correct size
370  //for the number of colors shown in the grid. Note that we MUST refresh color swatch grids every time this
371  //menu is opened, otherwise color schemes like the recent color scheme grid are meaningless
372  mMenu->clear();
373 
374  QAction *configureAction = new QAction( tr( "Configure Symbol…" ), this );
375  mMenu->addAction( configureAction );
376  connect( configureAction, &QAction::triggered, this, &QgsSymbolButton::showSettingsDialog );
377 
378  QAction *copySymbolAction = new QAction( tr( "Copy Symbol" ), this );
379  mMenu->addAction( copySymbolAction );
380  connect( copySymbolAction, &QAction::triggered, this, &QgsSymbolButton::copySymbol );
381  QAction *pasteSymbolAction = new QAction( tr( "Paste Symbol" ), this );
382  //enable or disable paste action based on current clipboard contents. We always show the paste
383  //action, even if it's disabled, to give hint to the user that pasting symbols is possible
384  std::unique_ptr< QgsSymbol > tempSymbol( QgsSymbolLayerUtils::symbolFromMimeData( QApplication::clipboard()->mimeData() ) );
385  if ( tempSymbol && tempSymbol->type() == mType )
386  {
387  const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
388  pasteSymbolAction->setIcon( QgsSymbolLayerUtils::symbolPreviewIcon( tempSymbol.get(), QSize( iconSize, iconSize ), 1 ) );
389  }
390  else
391  {
392  pasteSymbolAction->setEnabled( false );
393  }
394  mMenu->addAction( pasteSymbolAction );
395  connect( pasteSymbolAction, &QAction::triggered, this, &QgsSymbolButton::pasteSymbol );
396 
397  mMenu->addSeparator();
398 
399  QgsColorWheel *colorWheel = new QgsColorWheel( mMenu );
400  colorWheel->setColor( mSymbol->color() );
401  QgsColorWidgetAction *colorAction = new QgsColorWidgetAction( colorWheel, mMenu, mMenu );
402  colorAction->setDismissOnColorSelection( false );
403  connect( colorAction, &QgsColorWidgetAction::colorChanged, this, &QgsSymbolButton::setColor );
404  mMenu->addAction( colorAction );
405 
407  QColor alphaColor = mSymbol->color();
408  alphaColor.setAlphaF( mSymbol->opacity() );
409  alphaRamp->setColor( alphaColor );
410  QgsColorWidgetAction *alphaAction = new QgsColorWidgetAction( alphaRamp, mMenu, mMenu );
411  alphaAction->setDismissOnColorSelection( false );
412  connect( alphaAction, &QgsColorWidgetAction::colorChanged, this, [ = ]( const QColor & color )
413  {
414  double opacity = color.alphaF();
415  mSymbol->setOpacity( opacity );
416  updatePreview();
417  emit changed();
418  } );
419  connect( colorAction, &QgsColorWidgetAction::colorChanged, alphaRamp, [alphaRamp]( const QColor & color ) { alphaRamp->setColor( color, false ); }
420  );
421  mMenu->addAction( alphaAction );
422 
423  //get schemes with ShowInColorButtonMenu flag set
424  QList< QgsColorScheme * > schemeList = QgsApplication::colorSchemeRegistry()->schemes( QgsColorScheme::ShowInColorButtonMenu );
425  QList< QgsColorScheme * >::iterator it = schemeList.begin();
426  for ( ; it != schemeList.end(); ++it )
427  {
428  QgsColorSwatchGridAction *colorAction = new QgsColorSwatchGridAction( *it, mMenu, QStringLiteral( "symbology" ), this );
429  colorAction->setBaseColor( mSymbol->color() );
430  mMenu->addAction( colorAction );
431  connect( colorAction, &QgsColorSwatchGridAction::colorChanged, this, &QgsSymbolButton::setColor );
432  connect( colorAction, &QgsColorSwatchGridAction::colorChanged, this, &QgsSymbolButton::addRecentColor );
433  }
434 
435  mMenu->addSeparator();
436 
437  QAction *copyColorAction = new QAction( tr( "Copy Color" ), this );
438  mMenu->addAction( copyColorAction );
439  connect( copyColorAction, &QAction::triggered, this, &QgsSymbolButton::copyColor );
440 
441  QAction *pasteColorAction = new QAction( tr( "Paste Color" ), this );
442  //enable or disable paste action based on current clipboard contents. We always show the paste
443  //action, even if it's disabled, to give hint to the user that pasting colors is possible
444  QColor clipColor;
445  bool hasAlpha = false;
446  if ( colorFromMimeData( QApplication::clipboard()->mimeData(), clipColor, hasAlpha ) )
447  {
448  pasteColorAction->setIcon( createColorIcon( clipColor ) );
449  }
450  else
451  {
452  pasteColorAction->setEnabled( false );
453  }
454  mMenu->addAction( pasteColorAction );
455  connect( pasteColorAction, &QAction::triggered, this, &QgsSymbolButton::pasteColor );
456 
457  QAction *pickColorAction = new QAction( tr( "Pick Color" ), this );
458  mMenu->addAction( pickColorAction );
459  connect( pickColorAction, &QAction::triggered, this, &QgsSymbolButton::activatePicker );
460 
461  QAction *chooseColorAction = new QAction( tr( "Choose Color…" ), this );
462  mMenu->addAction( chooseColorAction );
463  connect( chooseColorAction, &QAction::triggered, this, &QgsSymbolButton::showColorDialog );
464 }
465 
466 void QgsSymbolButton::addRecentColor( const QColor &color )
467 {
469 }
470 
471 void QgsSymbolButton::activatePicker()
472 {
473  //activate picker color
474  QApplication::setOverrideCursor( QgsApplication::getThemeCursor( QgsApplication::Cursor::Sampler ) );
475  grabMouse();
476  grabKeyboard();
477  mPickingColor = true;
478  setMouseTracking( true );
479 }
480 
481 
483 {
484  if ( e->type() == QEvent::EnabledChange )
485  {
486  updatePreview();
487  }
488  QToolButton::changeEvent( e );
489 }
490 
491 void QgsSymbolButton::showEvent( QShowEvent *e )
492 {
493  updatePreview();
494  QToolButton::showEvent( e );
495 }
496 
497 void QgsSymbolButton::resizeEvent( QResizeEvent *event )
498 {
499  QToolButton::resizeEvent( event );
500  //recalculate icon size and redraw icon
501  mIconSize = QSize();
502  updatePreview();
503 }
504 
505 void QgsSymbolButton::updatePreview( const QColor &color, QgsSymbol *tempSymbol )
506 {
507  std::unique_ptr< QgsSymbol > previewSymbol;
508 
509  if ( tempSymbol )
510  previewSymbol.reset( tempSymbol->clone() );
511  else
512  previewSymbol.reset( mSymbol->clone() );
513 
514  if ( color.isValid() )
515  previewSymbol->setColor( color );
516 
517  QSize currentIconSize;
518  //icon size is button size with a small margin
519  if ( menu() )
520  {
521  if ( !mIconSize.isValid() )
522  {
523  //calculate size of push button part of widget (ie, without the menu dropdown button part)
524  QStyleOptionToolButton opt;
525  initStyleOption( &opt );
526  QRect buttonSize = QApplication::style()->subControlRect( QStyle::CC_ToolButton, &opt, QStyle::SC_ToolButton,
527  this );
528  //make sure height of icon looks good under different platforms
529 #ifdef Q_OS_WIN
530  mIconSize = QSize( buttonSize.width() - 10, height() - 6 );
531 #else
532  mIconSize = QSize( buttonSize.width() - 10, height() - 12 );
533 #endif
534  }
535  currentIconSize = mIconSize;
536  }
537  else
538  {
539  //no menu
540 #ifdef Q_OS_WIN
541  currentIconSize = QSize( width() - 10, height() - 6 );
542 #else
543  currentIconSize = QSize( width() - 10, height() - 12 );
544 #endif
545  }
546 
547  if ( !currentIconSize.isValid() || currentIconSize.width() <= 0 || currentIconSize.height() <= 0 )
548  {
549  return;
550  }
551 
552  //create an icon pixmap
553  QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( previewSymbol.get(), currentIconSize );
554  setIconSize( currentIconSize );
555  setIcon( icon );
556 
557  // set tooltip
558  // create very large preview image
559 
560  int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 23 );
561  int height = static_cast< int >( width / 1.61803398875 ); // golden ratio
562 
563  QPixmap pm = QgsSymbolLayerUtils::symbolPreviewPixmap( previewSymbol.get(), QSize( width, height ), height / 20 );
564  QByteArray data;
565  QBuffer buffer( &data );
566  pm.save( &buffer, "PNG", 100 );
567  setToolTip( QStringLiteral( "<img src='data:image/png;base64, %3'>" ).arg( QString( data.toBase64() ) ) );
568 }
569 
570 bool QgsSymbolButton::colorFromMimeData( const QMimeData *mimeData, QColor &resultColor, bool &hasAlpha )
571 {
572  hasAlpha = false;
573  QColor mimeColor = QgsSymbolLayerUtils::colorFromMimeData( mimeData, hasAlpha );
574 
575  if ( mimeColor.isValid() )
576  {
577  resultColor = mimeColor;
578  return true;
579  }
580 
581  //could not get color from mime data
582  return false;
583 }
584 
585 QPixmap QgsSymbolButton::createColorIcon( const QColor &color ) const
586 {
587  //create an icon pixmap
588  const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
589  QPixmap pixmap( iconSize, iconSize );
590  pixmap.fill( Qt::transparent );
591 
592  QPainter p;
593  p.begin( &pixmap );
594 
595  //draw color over pattern
596  p.setBrush( QBrush( color ) );
597 
598  //draw border
599  p.setPen( QColor( 197, 197, 197 ) );
600  p.drawRect( 0, 0, iconSize - 1, iconSize - 1 );
601  p.end();
602  return pixmap;
603 }
604 
605 void QgsSymbolButton::stopPicking( QPoint eventPos, bool samplingColor )
606 {
607  //release mouse and keyboard, and reset cursor
608  releaseMouse();
609  releaseKeyboard();
610  QgsApplication::restoreOverrideCursor();
611  setMouseTracking( false );
612  mPickingColor = false;
613 
614  if ( !samplingColor )
615  {
616  //not sampling color, restore old icon
617  updatePreview();
618  return;
619  }
620 
621  const QColor newColor = QgsGui::sampleColor( eventPos );
622  setColor( newColor );
623  addRecentColor( newColor );
624 }
625 
626 void QgsSymbolButton::showColorDialog()
627 {
629  if ( panel && panel->dockMode() )
630  {
631  QColor currentColor = mSymbol->color();
633  colorWidget->setPanelTitle( tr( "Symbol Color" ) );
634  colorWidget->setAllowOpacity( true );
635 
636  if ( currentColor.isValid() )
637  {
638  colorWidget->setPreviousColor( currentColor );
639  }
640 
641  connect( colorWidget, &QgsCompoundColorWidget::currentColorChanged, this, [ = ]( const QColor & newColor )
642  {
643  if ( newColor.isValid() )
644  {
645  setColor( newColor );
646  }
647  } );
648  panel->openPanel( colorWidget );
649  return;
650  }
651 
652  QgsColorDialog dialog( this, Qt::WindowFlags(), mSymbol->color() );
653  dialog.setTitle( tr( "Symbol Color" ) );
654  dialog.setAllowOpacity( true );
655 
656  if ( dialog.exec() && dialog.color().isValid() )
657  {
658  setColor( dialog.color() );
659  }
660 
661  // reactivate button's window
662  activateWindow();
663 }
664 
665 void QgsSymbolButton::setDialogTitle( const QString &title )
666 {
667  mDialogTitle = title;
668 }
669 
671 {
672  return mDialogTitle;
673 }
674 
676 {
677  return mSymbol.get();
678 }
SymbolType
Symbol types.
Definition: qgis.h:168
@ Marker
Marker symbol.
@ Line
Line symbol.
@ Fill
Fill symbol.
@ Hybrid
Hybrid symbol.
static const double UI_SCALE_FACTOR
UI scaling factor.
Definition: qgis.h:416
static QCursor getThemeCursor(Cursor cursor)
Helper to get a theme cursor.
static QgsColorSchemeRegistry * colorSchemeRegistry()
Returns the application's color scheme registry, used for managing color schemes.
A custom QGIS dialog for selecting a color.
A color ramp widget.
@ Horizontal
Horizontal ramp.
QList< QgsColorScheme * > schemes() const
Returns all color schemes in the registry.
@ ShowInColorButtonMenu
Show scheme in color button drop-down menu.
A color swatch grid which can be embedded into a menu.
void setBaseColor(const QColor &baseColor)
Sets the base color for the color grid.
void colorChanged(const QColor &color)
Emitted when a color has been selected from the widget.
A color wheel widget.
void setColor(const QColor &color, bool emitSignals=false) override
An action containing a color widget, which can be embedded into a menu.
void setDismissOnColorSelection(bool dismiss)
Sets whether the parent menu should be dismissed and closed when a color is selected from the action'...
void colorChanged(const QColor &color)
Emitted when a color has been selected from the widget.
static QPixmap createDragIcon(const QColor &color)
Create an icon for dragging colors.
virtual void setColor(const QColor &color, bool emitSignals=false)
Sets the color for the widget.
@ Alpha
Alpha component (opacity) of color.
A custom QGIS widget for selecting a color, including options for selecting colors via hue wheel,...
@ LayoutVertical
Use a narrower, vertically stacked layout.
void currentColorChanged(const QColor &color)
Emitted when the dialog's color changes.
void setPreviousColor(const QColor &color)
Sets the color to show in an optional "previous color" section.
void setAllowOpacity(bool allowOpacity)
Sets whether opacity modification (transparency) is permitted for the color dialog.
Abstract interface for generating an expression context.
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
static QgsFillSymbol * createSimple(const QVariantMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties.
static QColor sampleColor(QPoint point)
Samples the color on screen at the specified global point (pixel).
Definition: qgsgui.cpp:209
static QgsLineSymbol * createSimple(const QVariantMap &properties)
Create a line symbol with one symbol layer: SimpleLine with specified properties.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:86
static QgsMarkerSymbol * createSimple(const QVariantMap &properties)
Create a marker symbol with one symbol layer: SimpleMarker with specified properties.
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:61
Base class for any widget that can be shown as a inline panel.
void openPanel(QgsPanelWidget *panel)
Open a panel or dialog depending on dock mode setting If dock mode is true this method will emit the ...
void panelAccepted(QgsPanelWidget *panel)
Emitted when the panel is accepted by the user.
void widgetChanged()
Emitted when the widget state changes.
static QgsPanelWidget * findParentPanel(QWidget *widget)
Traces through the parents of a widget to find if it is contained within a QgsPanelWidget widget.
void setPanelTitle(const QString &panelTitle)
Set the title of the panel when shown in the interface.
bool dockMode()
Returns the dock mode state.
static void addRecentColor(const QColor &color)
Adds a color to the list of recent colors.
static QgsStyle * defaultStyle()
Returns default application-wide style.
Definition: qgsstyle.cpp:131
void mouseReleaseEvent(QMouseEvent *e) override
QSize sizeHint() const override
void changeEvent(QEvent *e) override
void setColor(const QColor &color)
Sets the current color for the symbol.
void copySymbol()
Copies the current symbol to the clipboard.
QgsSymbolButton(QWidget *parent=nullptr, const QString &dialogTitle=QString())
Construct a new symbol button.
void copyColor()
Copies the current symbol color to the clipboard.
void setMessageBar(QgsMessageBar *bar)
Sets the message bar associated with the widget.
void pasteSymbol()
Pastes a symbol from the clipboard.
void setSymbol(QgsSymbol *symbol)
Sets the symbol for the button.
void mousePressEvent(QMouseEvent *e) override
void dragEnterEvent(QDragEnterEvent *e) override
void showEvent(QShowEvent *e) override
void setSymbolType(Qgis::SymbolType type)
Sets the symbol type which the button requires.
void setDialogTitle(const QString &title)
Sets the title for the symbol settings dialog window.
void keyPressEvent(QKeyEvent *e) override
void setLayer(QgsVectorLayer *layer)
Sets a layer to associate with the widget.
void resizeEvent(QResizeEvent *event) override
void registerExpressionContextGenerator(QgsExpressionContextGenerator *generator)
Register an expression context generator class that will be used to retrieve an expression context fo...
QSize minimumSizeHint() const override
QgsMessageBar * messageBar() const
Returns the message bar associated with the widget.
void setMapCanvas(QgsMapCanvas *canvas)
Sets a map canvas to associate with the widget.
void dropEvent(QDropEvent *e) override
void pasteColor()
Pastes a color from the clipboard to the symbol.
void changed()
Emitted when the symbol's settings are changed.
void dragLeaveEvent(QDragLeaveEvent *e) override
QgsVectorLayer * layer() const
Returns the layer associated with the widget.
QgsSymbol * symbol()
Returns the current symbol defined by the button.
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
void mouseMoveEvent(QMouseEvent *e) override
static QgsSymbol * symbolFromMimeData(const QMimeData *data)
Attempts to parse mime data as a symbol.
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 QMimeData * symbolToMimeData(const QgsSymbol *symbol)
Creates new mime data from a symbol.
static QColor colorFromMimeData(const QMimeData *data, bool &hasAlpha)
Attempts to parse mime data as a color.
static QIcon symbolPreviewIcon(const QgsSymbol *symbol, QSize size, int padding=0, QgsLegendPatchShape *shape=nullptr)
Returns an icon preview for a color ramp.
static QMimeData * colorToMimeData(const QColor &color)
Creates mime data from a color.
Symbol selector widget that can be used to select and build a symbol.
QgsSymbol * symbol()
Returns the symbol that is currently active in the widget.
void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the symbol widget is shown, e.g., the associated map canvas and expression ...
Contains settings which reflect the context in which a symbol (or renderer) widget is shown,...
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the widget.
void setMessageBar(QgsMessageBar *bar)
Sets the message bar associated with the widget.
void setExpressionContext(QgsExpressionContext *context)
Sets the optional expression context used for the widget.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:38
Qgis::SymbolType type() const
Returns the symbol's type.
Definition: qgssymbol.h:97
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
Represents a vector layer which manages a vector based data sets.
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly,...