QGIS API Documentation  2.17.0-Master (00653d2)
qgsvectorgradientcolorrampv2dialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectorgradientcolorrampv2dialog.cpp
3  ---------------------
4  begin : November 2009
5  copyright : (C) 2009 by Martin Dobias
6  email : wonder dot sk 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 
17 
18 #include "qgsvectorcolorrampv2.h"
19 #include "qgsdialog.h"
20 #include "qgscolordialog.h"
21 #include "qgscptcityarchive.h"
22 
23 #include <QColorDialog>
24 #include <QInputDialog>
25 #include <QPainter>
26 #include <QSettings>
27 #include <QTableWidget>
28 #include <QTextEdit>
29 
30 // QWT Charting widget
31 #include <qwt_global.h>
32 #include <qwt_plot_canvas.h>
33 #include <qwt_plot.h>
34 #include <qwt_plot_curve.h>
35 #include <qwt_plot_grid.h>
36 #include <qwt_plot_marker.h>
37 #include <qwt_plot_picker.h>
38 #include <qwt_picker_machine.h>
39 #include <qwt_plot_layout.h>
40 #include <qwt_symbol.h>
41 #include <qwt_legend.h>
42 
44  : QDialog( parent )
45  , mRamp( ramp )
46  , mCurrentPlotColorComponent( -1 )
47  , mCurrentPlotMarkerIndex( 0 )
48 {
49  setupUi( this );
50 #ifdef Q_OS_MAC
51  setWindowModality( Qt::WindowModal );
52 #endif
53 
54  mPositionSpinBox->setShowClearButton( false );
55  btnColor1->setAllowAlpha( true );
56  btnColor1->setColorDialogTitle( tr( "Select ramp color" ) );
57  btnColor1->setContext( "symbology" );
58  btnColor1->setShowNoColor( true );
59  btnColor1->setNoColorString( tr( "Transparent" ) );
60  btnColor2->setAllowAlpha( true );
61  btnColor2->setColorDialogTitle( tr( "Select ramp color" ) );
62  btnColor2->setContext( "symbology" );
63  btnColor2->setShowNoColor( true );
64  btnColor2->setNoColorString( tr( "Transparent" ) );
65  updateColorButtons();
66  connect( btnColor1, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor1( const QColor& ) ) );
67  connect( btnColor2, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor2( const QColor& ) ) );
68 
69  // fill type combobox
70  cboType->blockSignals( true );
71  cboType->addItem( tr( "Discrete" ) );
72  cboType->addItem( tr( "Continuous" ) );
73  if ( mRamp->isDiscrete() )
74  cboType->setCurrentIndex( 0 );
75  else
76  cboType->setCurrentIndex( 1 );
77  cboType->blockSignals( false );
78 
79  if ( mRamp->info().isEmpty() )
80  btnInformation->setEnabled( false );
81 
82  mStopEditor->setGradientRamp( *mRamp );
83  connect( mStopEditor, SIGNAL( changed() ), this, SLOT( updateRampFromStopEditor() ) );
84 
85  connect( mColorWidget, SIGNAL( currentColorChanged( QColor ) ), this, SLOT( colorWidgetChanged( QColor ) ) );
86  connect( mDeleteStopButton, SIGNAL( clicked() ), mStopEditor, SLOT( deleteSelectedStop() ) );
87 
88  QSettings settings;
89  restoreGeometry( settings.value( "/Windows/GradientEditor/geometry" ).toByteArray() );
90 
91  // hide the ugly canvas frame
92  mPlot->setFrameStyle( QFrame::NoFrame );
93 #if defined(QWT_VERSION) && QWT_VERSION>=0x060000
94  QFrame* plotCanvasFrame = dynamic_cast<QFrame*>( mPlot->canvas() );
95  if ( plotCanvasFrame )
96  plotCanvasFrame->setFrameStyle( QFrame::NoFrame );
97 #else
98  mPlot->canvas()->setFrameStyle( QFrame::NoFrame );
99 #endif
100 
101  mPlot->setAxisScale( QwtPlot::yLeft, 0.0, 1.0 );
102  mPlot->enableAxis( QwtPlot::yLeft, false );
103 
104  mLightnessCurve = new QwtPlotCurve();
105  mLightnessCurve->setTitle( "Lightness" );
106  mLightnessCurve->setPen( QPen( QColor( 70, 150, 255 ), 0.0 ) ),
107  mLightnessCurve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
108  mLightnessCurve->attach( mPlot );
109 
110  mHueCurve = new QwtPlotCurve();
111  mHueCurve->setTitle( "Hue" );
112  mHueCurve->setPen( QPen( QColor( 255, 215, 70 ), 0.0 ) ),
113  mHueCurve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
114  mHueCurve->attach( mPlot );
115 
116  mSaturationCurve = new QwtPlotCurve();
117  mSaturationCurve->setTitle( "Saturation" );
118  mSaturationCurve->setPen( QPen( QColor( 255, 70, 150 ), 0.0 ) ),
119  mSaturationCurve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
120  mSaturationCurve->attach( mPlot );
121 
122  mAlphaCurve = new QwtPlotCurve();
123  mAlphaCurve->setTitle( "Alpha" );
124  mAlphaCurve->setPen( QPen( QColor( 50, 50, 50 ), 0.0 ) ),
125  mAlphaCurve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
126  mAlphaCurve->attach( mPlot );
127 
128  mPlotFilter = new QgsGradientPlotEventFilter( mPlot );
129  connect( mPlotFilter, SIGNAL( mousePress( QPointF ) ), this, SLOT( plotMousePress( QPointF ) ) );
130  connect( mPlotFilter, SIGNAL( mouseRelease( QPointF ) ), this, SLOT( plotMouseRelease( QPointF ) ) );
131  connect( mPlotFilter, SIGNAL( mouseMove( QPointF ) ), this, SLOT( plotMouseMove( QPointF ) ) );
132 
133  mPlotHueCheckbox->setChecked( settings.value( "/GradientEditor/plotHue", false ).toBool() );
134  mPlotLightnessCheckbox->setChecked( settings.value( "/GradientEditor/plotLightness", true ).toBool() );
135  mPlotSaturationCheckbox->setChecked( settings.value( "/GradientEditor/plotSaturation", false ).toBool() );
136  mPlotAlphaCheckbox->setChecked( settings.value( "/GradientEditor/plotAlpha", false ).toBool() );
137 
138  mHueCurve->setVisible( mPlotHueCheckbox->isChecked() );
139  mLightnessCurve->setVisible( mPlotLightnessCheckbox->isChecked() );
140  mSaturationCurve->setVisible( mPlotSaturationCheckbox->isChecked() );
141  mAlphaCurve->setVisible( mPlotAlphaCheckbox->isChecked() );
142 
143  connect( mStopEditor, SIGNAL( selectedStopChanged( QgsGradientStop ) ), this, SLOT( selectedStopChanged( QgsGradientStop ) ) );
144  mStopEditor->selectStop( 0 );
145 }
146 
148 {
149  QSettings settings;
150  settings.setValue( "/Windows/GradientEditor/geometry", saveGeometry() );
151  settings.setValue( "/GradientEditor/plotHue", mPlotHueCheckbox->isChecked() );
152  settings.setValue( "/GradientEditor/plotLightness", mPlotLightnessCheckbox->isChecked() );
153  settings.setValue( "/GradientEditor/plotSaturation", mPlotSaturationCheckbox->isChecked() );
154  settings.setValue( "/GradientEditor/plotAlpha", mPlotAlphaCheckbox->isChecked() );
155 
156 }
157 
159 {
160  if (( index == 0 && mRamp->isDiscrete() ) ||
161  ( index == 1 && !mRamp->isDiscrete() ) )
162  return;
163  mRamp->convertToDiscrete( index == 0 );
164  updateColorButtons();
165  updateStopEditor();
166  updatePlot();
167 }
168 
170 {
171  if ( mRamp->info().isEmpty() )
172  return;
173 
174  QgsDialog *dlg = new QgsDialog( this );
175  QLabel *label = nullptr;
176 
177  // information table
178  QTableWidget *tableInfo = new QTableWidget( dlg );
179  tableInfo->verticalHeader()->hide();
180  tableInfo->horizontalHeader()->hide();
181  tableInfo->setRowCount( mRamp->info().count() );
182  tableInfo->setColumnCount( 2 );
183  int i = 0;
184  QgsStringMap rampInfo = mRamp->info();
185  for ( QgsStringMap::const_iterator it = rampInfo.constBegin();
186  it != rampInfo.constEnd(); ++it )
187  {
188  if ( it.key().startsWith( "cpt-city" ) )
189  continue;
190  tableInfo->setItem( i, 0, new QTableWidgetItem( it.key() ) );
191  tableInfo->setItem( i, 1, new QTableWidgetItem( it.value() ) );
192  tableInfo->resizeRowToContents( i );
193  i++;
194  }
195  tableInfo->resizeColumnToContents( 0 );
196  tableInfo->horizontalHeader()->setStretchLastSection( true );
197  tableInfo->setRowCount( i );
198  tableInfo->setFixedHeight( tableInfo->rowHeight( 0 ) * i + 5 );
199  dlg->layout()->addWidget( tableInfo );
200  dlg->resize( 600, 250 );
201 
202  dlg->layout()->addSpacing( 5 );
203 
204  // gradient file
205  QString gradientFile = mRamp->info().value( "cpt-city-gradient" );
206  if ( ! gradientFile.isNull() )
207  {
208  QString fileName = gradientFile;
209  fileName.replace( "<cpt-city>", QgsCptCityArchive::defaultBaseDir() );
210  if ( ! QFile::exists( fileName ) )
211  {
212  fileName = gradientFile;
213  fileName.replace( "<cpt-city>", "http://soliton.vm.bytemark.co.uk/pub/cpt-city" );
214  }
215  label = new QLabel( tr( "Gradient file : %1" ).arg( fileName ), dlg );
216  label->setTextInteractionFlags( Qt::TextBrowserInteraction );
217  dlg->layout()->addSpacing( 5 );
218  dlg->layout()->addWidget( label );
219  }
220 
221  // license file
222  QString licenseFile = mRamp->info().value( "cpt-city-license" );
223  if ( !licenseFile.isNull() )
224  {
225  QString fileName = licenseFile;
226  fileName.replace( "<cpt-city>", QgsCptCityArchive::defaultBaseDir() );
227  if ( ! QFile::exists( fileName ) )
228  {
229  fileName = licenseFile;
230  fileName.replace( "<cpt-city>", "http://soliton.vm.bytemark.co.uk/pub/cpt-city" );
231  }
232  label = new QLabel( tr( "License file : %1" ).arg( fileName ), dlg );
233  label->setTextInteractionFlags( Qt::TextBrowserInteraction );
234  dlg->layout()->addSpacing( 5 );
235  dlg->layout()->addWidget( label );
236  if ( QFile::exists( fileName ) )
237  {
238  QTextEdit *textEdit = new QTextEdit( dlg );
239  textEdit->setReadOnly( true );
240  QFile file( fileName );
241  if ( file.open( QIODevice::ReadOnly | QIODevice::Text ) )
242  {
243  textEdit->setText( file.readAll() );
244  file.close();
245  dlg->layout()->addSpacing( 5 );
246  dlg->layout()->addWidget( textEdit );
247  dlg->resize( 600, 500 );
248  }
249  }
250  }
251 
252  dlg->show(); //non modal
253 }
254 
255 void QgsVectorGradientColorRampV2Dialog::updateColorButtons()
256 {
257  btnColor1->blockSignals( true );
258  btnColor1->setColor( mRamp->color1() );
259  btnColor1->blockSignals( false );
260  btnColor2->blockSignals( true );
261  btnColor2->setColor( mRamp->color2() );
262  btnColor2->blockSignals( false );
263 }
264 
265 void QgsVectorGradientColorRampV2Dialog::updateStopEditor()
266 {
267  mStopEditor->blockSignals( true );
268  mStopEditor->setGradientRamp( *mRamp );
269  mStopEditor->blockSignals( false );
270 }
271 
272 void QgsVectorGradientColorRampV2Dialog::selectedStopChanged( const QgsGradientStop& stop )
273 {
274  mColorWidget->blockSignals( true );
275  mColorWidget->setColor( stop.color );
276  mColorWidget->blockSignals( false );
277  mPositionSpinBox->blockSignals( true );
278  mPositionSpinBox->setValue( stop.offset * 100 );
279  mPositionSpinBox->blockSignals( false );
280 
281  if (( stop.offset == 0 && stop.color == mRamp->color1() ) || ( stop.offset == 1.0 && stop.color == mRamp->color2() ) )
282  {
283  //first/last stop can't be repositioned
284  mPositionSpinBox->setDisabled( true );
285  mDeleteStopButton->setDisabled( true );
286  }
287  else
288  {
289  mPositionSpinBox->setDisabled( false );
290  mDeleteStopButton->setDisabled( false );
291  }
292 
293  updatePlot();
294 }
295 
296 void QgsVectorGradientColorRampV2Dialog::colorWidgetChanged( const QColor &color )
297 {
298  mStopEditor->setSelectedStopColor( color );
299 }
300 
301 void QgsVectorGradientColorRampV2Dialog::on_mPositionSpinBox_valueChanged( double val )
302 {
303  mStopEditor->setSelectedStopOffset( val / 100.0 );
304 }
305 
306 void QgsVectorGradientColorRampV2Dialog::on_mPlotHueCheckbox_toggled( bool checked )
307 {
308  mHueCurve->setVisible( checked );
309  updatePlot();
310 }
311 
312 void QgsVectorGradientColorRampV2Dialog::on_mPlotLightnessCheckbox_toggled( bool checked )
313 {
314  mLightnessCurve->setVisible( checked );
315  updatePlot();
316 }
317 
318 void QgsVectorGradientColorRampV2Dialog::on_mPlotSaturationCheckbox_toggled( bool checked )
319 {
320  mSaturationCurve->setVisible( checked );
321  updatePlot();
322 }
323 
324 void QgsVectorGradientColorRampV2Dialog::on_mPlotAlphaCheckbox_toggled( bool checked )
325 {
326  mAlphaCurve->setVisible( checked );
327  updatePlot();
328 }
329 
330 void QgsVectorGradientColorRampV2Dialog::plotMousePress( QPointF point )
331 {
332  //find closest part
333 
334  double minDist = 1;
335  mCurrentPlotColorComponent = -1;
336  mCurrentPlotMarkerIndex = -1;
337  // first color
338 
339  for ( int i = 0; i < mRamp->count(); ++i )
340  {
341  QColor currentCol;
342  double currentOff = 0.0;
343  if ( i == 0 )
344  {
345  currentOff = 0.0;
346  currentCol = mRamp->color1();
347  }
348  else if ( i == mRamp->count() - 1 )
349  {
350  currentOff = 1.0;
351  currentCol = mRamp->color2();
352  }
353  else
354  {
355  currentOff = mRamp->stops().at( i - 1 ).offset;
356  currentCol = mRamp->stops().at( i - 1 ).color;
357  }
358 
359  double currentDist;
360  if ( mPlotHueCheckbox->isChecked() )
361  {
362  currentDist = qPow( point.x() - currentOff, 2.0 ) + qPow( point.y() - currentCol.hslHueF(), 2.0 );
363  if ( currentDist < minDist )
364  {
365  minDist = currentDist;
366  mCurrentPlotColorComponent = 0;
367  mCurrentPlotMarkerIndex = i;
368  }
369  }
370  if ( mPlotLightnessCheckbox->isChecked() )
371  {
372  currentDist = qPow( point.x() - currentOff, 2.0 ) + qPow( point.y() - currentCol.lightnessF(), 2.0 );
373  if ( currentDist < minDist )
374  {
375  minDist = currentDist;
376  mCurrentPlotColorComponent = 1;
377  mCurrentPlotMarkerIndex = i;
378  }
379  }
380  if ( mPlotSaturationCheckbox->isChecked() )
381  {
382  currentDist = qPow( point.x() - currentOff, 2.0 ) + qPow( point.y() - currentCol.hslSaturationF(), 2.0 );
383  if ( currentDist < minDist )
384  {
385  minDist = currentDist;
386  mCurrentPlotColorComponent = 2;
387  mCurrentPlotMarkerIndex = i;
388  }
389  }
390  if ( mPlotAlphaCheckbox->isChecked() )
391  {
392  currentDist = qPow( point.x() - currentOff, 2.0 ) + qPow( point.y() - currentCol.alphaF(), 2.0 );
393  if ( currentDist < minDist )
394  {
395  minDist = currentDist;;
396  mCurrentPlotColorComponent = 3;
397  mCurrentPlotMarkerIndex = i;
398  }
399  }
400  }
401 
402  // watch out - selected stop index may differ if stops in editor are out of order!!!
403  if ( mCurrentPlotMarkerIndex >= 0 )
404  mStopEditor->selectStop( mCurrentPlotMarkerIndex );
405 }
406 
407 void QgsVectorGradientColorRampV2Dialog::plotMouseRelease( QPointF )
408 {
409  mCurrentPlotColorComponent = -1;
410 }
411 
412 void QgsVectorGradientColorRampV2Dialog::plotMouseMove( QPointF point )
413 {
414  QColor newColor = mStopEditor->selectedStop().color;
415 
416  if ( mCurrentPlotColorComponent == 0 )
417  newColor = QColor::fromHslF( qBound( qreal( 0.0 ), point.y(), qreal( 1.0 ) ), newColor.hslSaturationF(), newColor.lightnessF(), newColor.alphaF() );
418  else if ( mCurrentPlotColorComponent == 1 )
419  newColor = QColor::fromHslF( newColor.hslHueF(), newColor.hslSaturationF(), qBound( qreal( 0.0 ), point.y(), qreal( 1.0 ) ), newColor.alphaF() );
420  else if ( mCurrentPlotColorComponent == 2 )
421  newColor = QColor::fromHslF( newColor.hslHueF(), qBound( qreal( 0.0 ), point.y(), qreal( 1.0 ) ), newColor.lightnessF(), newColor.alphaF() );
422  else if ( mCurrentPlotColorComponent == 3 )
423  newColor = QColor::fromHslF( newColor.hslHueF(), newColor.hslSaturationF(), newColor.lightnessF(), qBound( qreal( 0.0 ), point.y(), qreal( 1.0 ) ) );
424 
425  mStopEditor->setSelectedStopDetails( newColor, qBound( qreal( 0.0 ), point.x(), qreal( 1.0 ) ) );
426 }
427 
428 bool byX( QPointF p1, QPointF p2 )
429 {
430  return p1.x() < p2.x();
431 }
432 
433 void QgsVectorGradientColorRampV2Dialog::addPlotMarker( double x, double y, const QColor& color, bool isSelected )
434 {
435  QColor borderColor = color.darker( 200 );
436  borderColor.setAlpha( 255 );
437 
438  QColor brushColor = color;
439  brushColor.setAlpha( 255 );
440 
441  QwtPlotMarker *marker = new QwtPlotMarker();
442 #if defined(QWT_VERSION) && QWT_VERSION>=0x060000
443  marker->setSymbol( new QwtSymbol( QwtSymbol::Ellipse, QBrush( brushColor ), QPen( borderColor, isSelected ? 2 : 1 ), QSize( 10, 10 ) ) );
444 #else
445  marker->setSymbol( QwtSymbol( QwtSymbol::Ellipse, QBrush( brushColor ), QPen( borderColor, isSelected ? 2 : 1 ), QSize( 10, 10 ) ) );
446 #endif
447  marker->setValue( x, y );
448  marker->attach( mPlot );
449  marker->setRenderHint( QwtPlotItem::RenderAntialiased, true );
450  mMarkers << marker;
451 }
452 
453 void QgsVectorGradientColorRampV2Dialog::addMarkersForColor( double x, const QColor& color, bool isSelected )
454 {
455  if ( mPlotHueCheckbox->isChecked() )
456  addPlotMarker( x, color.hslHueF(), color, isSelected && mCurrentPlotColorComponent == 0 );
457  if ( mPlotLightnessCheckbox->isChecked() )
458  addPlotMarker( x, color.lightnessF(), color, isSelected && mCurrentPlotColorComponent == 1 );
459  if ( mPlotSaturationCheckbox->isChecked() )
460  addPlotMarker( x, color.hslSaturationF(), color, isSelected && mCurrentPlotColorComponent == 2 );
461  if ( mPlotAlphaCheckbox->isChecked() )
462  addPlotMarker( x, color.alphaF(), color, isSelected && mCurrentPlotColorComponent == 3 );
463 }
464 
465 void QgsVectorGradientColorRampV2Dialog::updatePlot()
466 {
467  // remove existing markers
468  Q_FOREACH ( QwtPlotMarker* marker, mMarkers )
469  {
470  marker->detach();
471  delete marker;
472  }
473  mMarkers.clear();
474 
475  QPolygonF lightnessPoints;
476  QPolygonF huePoints;
477  QPolygonF saturationPoints;
478  QPolygonF alphaPoints;
479  lightnessPoints << QPointF( 0.0, mRamp->color1().lightnessF() );
480  huePoints << QPointF( 0.0, mRamp->color1().hslHueF() );
481  saturationPoints << QPointF( 0.0, mRamp->color1().hslSaturationF() );
482  alphaPoints << QPointF( 0.0, mRamp->color1().alphaF() );
483  addMarkersForColor( 0, mRamp->color1(), mCurrentPlotMarkerIndex == 0 );
484 
485  int i = 1;
486  Q_FOREACH ( const QgsGradientStop& stop, mRamp->stops() )
487  {
488  lightnessPoints << QPointF( stop.offset, stop.color.lightnessF() );
489  huePoints << QPointF( stop.offset, stop.color.hslHueF() );
490  saturationPoints << QPointF( stop.offset, stop.color.hslSaturationF() );
491  alphaPoints << QPointF( stop.offset, stop.color.alphaF() );
492 
493  addMarkersForColor( stop.offset, stop.color, mCurrentPlotMarkerIndex == i );
494  i++;
495  }
496 
497  //add extra intermediate points
498  for ( double p = 0.001; p < 1.0; p += 0.001 )
499  {
500  QColor c = mRamp->color( p );
501  lightnessPoints << QPointF( p, c.lightnessF() );
502  huePoints << QPointF( p, c.hslHueF() );
503  saturationPoints << QPointF( p, c.hslSaturationF() );
504  alphaPoints << QPointF( p, c.alphaF() );
505  }
506 
507  lightnessPoints << QPointF( 1.0, mRamp->color2().lightnessF() );
508  huePoints << QPointF( 1.0, mRamp->color2().hslHueF() );
509  saturationPoints << QPointF( 1.0, mRamp->color2().hslSaturationF() );
510  alphaPoints << QPointF( 1.0, mRamp->color2().alphaF() );
511  addMarkersForColor( 1.0, mRamp->color2(), mCurrentPlotMarkerIndex == i );
512 
513  qSort( lightnessPoints.begin(), lightnessPoints.end(), byX );
514  qSort( huePoints.begin(), huePoints.end(), byX );
515  qSort( saturationPoints.begin(), saturationPoints.end(), byX );
516  qSort( alphaPoints.begin(), alphaPoints.end(), byX );
517 
518 #if defined(QWT_VERSION) && QWT_VERSION>=0x060000
519  mLightnessCurve->setSamples( lightnessPoints );
520  mHueCurve->setSamples( huePoints );
521  mSaturationCurve->setSamples( saturationPoints );
522  mAlphaCurve->setSamples( alphaPoints );
523 #else
524  mLightnessCurve->setData( lightnessPoints );
525  mHueCurve->setData( huePoints );
526  mSaturationCurve->setData( saturationPoints );
527  mAlphaCurve->setData( alphaPoints );
528 #endif
529  mPlot->replot();
530 }
531 
532 void QgsVectorGradientColorRampV2Dialog::updateRampFromStopEditor()
533 {
534  *mRamp = mStopEditor->gradientRamp();
535  mPositionSpinBox->blockSignals( true );
536  mPositionSpinBox->setValue( mStopEditor->selectedStop().offset * 100 );
537  mPositionSpinBox->blockSignals( false );
538  mColorWidget->blockSignals( true );
539  mColorWidget->setColor( mStopEditor->selectedStop().color );
540  mColorWidget->blockSignals( false );
541 
542  updateColorButtons();
543  updatePlot();
544 }
545 
547 {
548  mStopEditor->setColor1( color );
549  updateColorButtons();
550 }
551 
553 {
554  mStopEditor->setColor2( color );
555  updateColorButtons();
556 }
557 
558 
560 
561 QgsGradientPlotEventFilter::QgsGradientPlotEventFilter( QwtPlot *plot )
562  : QObject( plot )
563  , mPlot( plot )
564 {
565  mPlot->canvas()->installEventFilter( this );
566 }
567 
568 bool QgsGradientPlotEventFilter::eventFilter( QObject *object, QEvent *event )
569 {
570  if ( !mPlot->isEnabled() )
571  return QObject::eventFilter( object, event );
572 
573  switch ( event->type() )
574  {
575  case QEvent::MouseButtonPress:
576  {
577  const QMouseEvent* mouseEvent = static_cast<QMouseEvent* >( event );
578  if ( mouseEvent->button() == Qt::LeftButton )
579  {
580  emit mousePress( mapPoint( mouseEvent->pos() ) );
581  }
582  break;
583  }
584  case QEvent::MouseMove:
585  {
586  const QMouseEvent* mouseEvent = static_cast<QMouseEvent* >( event );
587  if ( mouseEvent->buttons() & Qt::LeftButton )
588  {
589  // only emit when button pressed
590  emit mouseMove( mapPoint( mouseEvent->pos() ) );
591  }
592  break;
593  }
594  case QEvent::MouseButtonRelease:
595  {
596  const QMouseEvent* mouseEvent = static_cast<QMouseEvent* >( event );
597  if ( mouseEvent->button() == Qt::LeftButton )
598  {
599  emit mouseRelease( mapPoint( mouseEvent->pos() ) );
600  }
601  break;
602  }
603  default:
604  break;
605  }
606 
607  return QObject::eventFilter( object, event );
608 }
609 
610 QPointF QgsGradientPlotEventFilter::mapPoint( QPointF point ) const
611 {
612  if ( !mPlot )
613  return QPointF();
614 
615  return QPointF( mPlot->canvasMap( QwtPlot::xBottom ).invTransform( point.x() ),
616  mPlot->canvasMap( QwtPlot::yLeft ).invTransform( point.y() ) );
617 }
618 
void clear()
QByteArray toByteArray() const
static unsigned index
virtual bool event(QEvent *e)
Type type() const
void setupUi(QWidget *widget)
QColor darker(int factor) const
Represents a color stop within a gradient color ramp.
qreal alphaF() const
iterator begin()
void setWindowModality(Qt::WindowModality windowModality)
void setItem(int row, int column, QTableWidgetItem *item)
static QString defaultBaseDir()
QColor color2() const
Returns the gradient end color.
void resizeColumnToContents(int column)
const_iterator constBegin() const
const T & at(int i) const
int y() const
A generic dialog with layout and button box.
Definition: qgsdialog.h:30
QColor color1() const
Returns the gradient start color.
void setAlpha(int alpha)
bool isDiscrete() const
Returns true if the gradient is using discrete interpolation, rather than smoothly interpolating betw...
QHeaderView * verticalHeader() const
Qt::MouseButtons buttons() const
bool exists() const
void setFrameStyle(int style)
void addSpacing(int size)
QgsGradientStopsList stops() const
Returns the list of intermediate gradient stops for the ramp.
qreal hslHueF() const
QString tr(const char *sourceText, const char *disambiguation, int n)
bool isNull() const
int rowHeight(int row) const
void setValue(const QString &key, const QVariant &value)
void resize(int w, int h)
virtual int count() const override
Returns number of defined colors, or -1 if undefined.
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
qreal x() const
qreal y() const
QgsStringMap info() const
Returns any additional info attached to the gradient ramp (eg authorship notes)
int x() const
bool restoreGeometry(const QByteArray &geometry)
double offset
Relative positional offset, between 0 and 1.
Qt::MouseButton button() const
const_iterator constEnd() const
QgsVectorGradientColorRampV2Dialog(QgsVectorGradientColorRampV2 *ramp, QWidget *parent=nullptr)
QByteArray readAll()
qreal lightnessF() const
virtual bool eventFilter(QObject *watched, QEvent *event)
void hide()
void convertToDiscrete(bool discrete)
Converts a gradient with existing color stops to or from discrete interpolation.
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
virtual void close()
virtual QColor color(double value) const override
Returns the color corresponding to a specified value.
void setColumnCount(int columns)
void setTextInteractionFlags(QFlags< Qt::TextInteractionFlag > flags)
QString & replace(int position, int n, QChar after)
QVariant value(const QString &key, const QVariant &defaultValue) const
bool byX(QPointF p1, QPointF p2)
QObject(QObject *parent)
QByteArray saveGeometry() const
void setFixedHeight(int h)
QVBoxLayout * layout()
Returns the central layout. Widgets added to it must have this dialog as parent.
Definition: qgsdialog.h:40
bool toBool() const
qreal hslSaturationF() const
void show()
bool isEmpty() const
void setReadOnly(bool ro)
const QPoint & pos() const
void resizeRowToContents(int row)
void setStretchLastSection(bool stretch)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setRowCount(int rows)
QHeaderView * horizontalHeader() const
void setText(const QString &text)
iterator end()
Gradient color ramp, which smoothly interpolates between two colors and also supports optional extra ...
int count(const Key &key) const
QColor fromHslF(qreal h, qreal s, qreal l, qreal a)
const T value(const Key &key) const
QColor color
Gradient color at stop.