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