17#include "moc_qgsgradientcolorrampdialog.cpp" 
   24#include <QColorDialog> 
   26#include <QInputDialog> 
   28#include <QTableWidget> 
   32#include <qwt_global.h> 
   33#include <qwt_plot_canvas.h> 
   35#include <qwt_plot_curve.h> 
   36#include <qwt_plot_grid.h> 
   37#include <qwt_plot_marker.h> 
   38#include <qwt_plot_picker.h> 
   39#include <qwt_picker_machine.h> 
   40#include <qwt_plot_layout.h> 
   41#include <qwt_symbol.h> 
   42#include <qwt_legend.h> 
   43#include <qwt_scale_div.h> 
   44#include <qwt_scale_map.h> 
   49  , mCurrentPlotColorComponent( -1 )
 
   50  , mCurrentPlotMarkerIndex( 0 )
 
   55  mColorWidget->setColorModelEditable( 
false );
 
   57  mStopColorSpec->addItem( tr( 
"RGB" ), 
static_cast<int>( QColor::Spec::Rgb ) );
 
   58  mStopColorSpec->addItem( tr( 
"HSV" ), 
static_cast<int>( QColor::Spec::Hsv ) );
 
   59  mStopColorSpec->addItem( tr( 
"HSL" ), 
static_cast<int>( QColor::Spec::Hsl ) );
 
   60  mStopColorSpec->addItem( tr( 
"CMYK" ), 
static_cast<int>( QColor::Spec::Cmyk ) );
 
   61  mStopColorSpec->setCurrentIndex( mStopColorSpec->findData( 
static_cast<int>( 
ramp.
colorSpec() ) ) );
 
   65  mStopDirection->setCurrentIndex( mStopColorSpec->findData( 
static_cast<int>( 
ramp.
direction() ) ) );
 
   67  mStopDirection->setEnabled( hasDirection( 
static_cast<QColor::Spec
>( mStopColorSpec->currentData().toInt() ) ) );
 
   69  connect( mStopColorSpec, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, [
this] {
 
   70    const QColor::Spec colorSpec = 
static_cast<QColor::Spec
>( mStopColorSpec->currentData().toInt() );
 
   71    mStopDirection->setEnabled( hasDirection( colorSpec ) );
 
   73    if ( colorSpec != mColorWidget->color().spec() )
 
   75      mColorWidget->setColor( mColorWidget->color().convertTo( colorSpec ) );
 
   81    mStopEditor->setSelectedStopColorSpec( colorSpec );
 
   84  connect( mStopDirection, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, [
this] {
 
   88    mStopEditor->setSelectedStopDirection( 
static_cast<Qgis::AngularDirection>( mStopDirection->currentData().toInt() ) );
 
   91  connect( cboType, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsGradientColorRampDialog::cboType_currentIndexChanged );
 
   92  connect( btnInformation, &QPushButton::pressed, 
this, &QgsGradientColorRampDialog::btnInformation_pressed );
 
   93  connect( mPositionSpinBox, 
static_cast<void ( QDoubleSpinBox::* )( 
double )
>( &QDoubleSpinBox::valueChanged ), 
this, &QgsGradientColorRampDialog::mPositionSpinBox_valueChanged );
 
   94  connect( mPlotHueCheckbox, &QCheckBox::toggled, 
this, &QgsGradientColorRampDialog::mPlotHueCheckbox_toggled );
 
   95  connect( mPlotLightnessCheckbox, &QCheckBox::toggled, 
this, &QgsGradientColorRampDialog::mPlotLightnessCheckbox_toggled );
 
   96  connect( mPlotSaturationCheckbox, &QCheckBox::toggled, 
this, &QgsGradientColorRampDialog::mPlotSaturationCheckbox_toggled );
 
   97  connect( mPlotAlphaCheckbox, &QCheckBox::toggled, 
this, &QgsGradientColorRampDialog::mPlotAlphaCheckbox_toggled );
 
   99  setWindowModality( Qt::WindowModal );
 
  102  mPositionSpinBox->setShowClearButton( 
false );
 
  103  btnColor1->setAllowOpacity( 
true );
 
  104  btnColor1->setColorDialogTitle( tr( 
"Select Ramp Color" ) );
 
  105  btnColor1->setContext( QStringLiteral( 
"symbology" ) );
 
  106  btnColor1->setShowNoColor( 
true );
 
  107  btnColor1->setNoColorString( tr( 
"Transparent" ) );
 
  108  btnColor2->setAllowOpacity( 
true );
 
  109  btnColor2->setColorDialogTitle( tr( 
"Select Ramp Color" ) );
 
  110  btnColor2->setContext( QStringLiteral( 
"symbology" ) );
 
  111  btnColor2->setShowNoColor( 
true );
 
  112  btnColor2->setNoColorString( tr( 
"Transparent" ) );
 
  113  updateColorButtons();
 
  118  cboType->blockSignals( 
true );
 
  119  cboType->addItem( tr( 
"Discrete" ) );
 
  120  cboType->addItem( tr( 
"Continuous" ) );
 
  122    cboType->setCurrentIndex( 0 );
 
  124    cboType->setCurrentIndex( 1 );
 
  125  cboType->blockSignals( 
false );
 
  127  if ( mRamp.
info().isEmpty() )
 
  128    btnInformation->setEnabled( 
false );
 
  130  mStopEditor->setGradientRamp( mRamp );
 
  137  mPlot->setFrameStyle( QFrame::NoFrame );
 
  138  QFrame *plotCanvasFrame = 
dynamic_cast<QFrame *
>( mPlot->canvas() );
 
  139  if ( plotCanvasFrame )
 
  140    plotCanvasFrame->setFrameStyle( QFrame::NoFrame );
 
  142  mPlot->setAxisScale( QwtPlot::yLeft, 0.0, 1.0 );
 
  143  mPlot->enableAxis( QwtPlot::yLeft, 
false );
 
  146  QwtPlotGrid *grid = 
new QwtPlotGrid();
 
  147  QwtScaleDiv gridDiv( 0.0, 1.0, QList<double>(), QList<double>(), QList<double>() << 0.2 << 0.4 << 0.6 << 0.8 );
 
  148  grid->setXDiv( gridDiv );
 
  149  grid->setYDiv( gridDiv );
 
  150  grid->setPen( QPen( QColor( 0, 0, 0, 50 ) ) );
 
  151  grid->attach( mPlot );
 
  153  mLightnessCurve = 
new QwtPlotCurve();
 
  154  mLightnessCurve->setTitle( tr( 
"Lightness" ) );
 
  155  mLightnessCurve->setPen( QPen( QColor( 70, 150, 255 ), 0.0 ) ),
 
  156    mLightnessCurve->setRenderHint( QwtPlotItem::RenderAntialiased, 
true );
 
  157  mLightnessCurve->attach( mPlot );
 
  159  mHueCurve = 
new QwtPlotCurve();
 
  160  mHueCurve->setTitle( tr( 
"Hue" ) );
 
  161  mHueCurve->setPen( QPen( QColor( 255, 215, 70 ), 0.0 ) ),
 
  162    mHueCurve->setRenderHint( QwtPlotItem::RenderAntialiased, 
true );
 
  163  mHueCurve->attach( mPlot );
 
  165  mSaturationCurve = 
new QwtPlotCurve();
 
  166  mSaturationCurve->setTitle( tr( 
"Saturation" ) );
 
  167  mSaturationCurve->setPen( QPen( QColor( 255, 70, 150 ), 0.0 ) ),
 
  168    mSaturationCurve->setRenderHint( QwtPlotItem::RenderAntialiased, 
true );
 
  169  mSaturationCurve->attach( mPlot );
 
  171  mAlphaCurve = 
new QwtPlotCurve();
 
  172  mAlphaCurve->setTitle( tr( 
"Opacity" ) );
 
  173  mAlphaCurve->setPen( QPen( QColor( 50, 50, 50 ), 0.0 ) ),
 
  174    mAlphaCurve->setRenderHint( QwtPlotItem::RenderAntialiased, 
true );
 
  175  mAlphaCurve->attach( mPlot );
 
  177  mPlotFilter = 
new QgsGradientPlotEventFilter( mPlot );
 
  178  connect( mPlotFilter, &QgsGradientPlotEventFilter::mousePress, 
this, &QgsGradientColorRampDialog::plotMousePress );
 
  179  connect( mPlotFilter, &QgsGradientPlotEventFilter::mouseRelease, 
this, &QgsGradientColorRampDialog::plotMouseRelease );
 
  180  connect( mPlotFilter, &QgsGradientPlotEventFilter::mouseMove, 
this, &QgsGradientColorRampDialog::plotMouseMove );
 
  183  mPlotHueCheckbox->setChecked( settings.
value( QStringLiteral( 
"GradientEditor/plotHue" ), 
false ).toBool() );
 
  184  mPlotLightnessCheckbox->setChecked( settings.
value( QStringLiteral( 
"GradientEditor/plotLightness" ), 
true ).toBool() );
 
  185  mPlotSaturationCheckbox->setChecked( settings.
value( QStringLiteral( 
"GradientEditor/plotSaturation" ), 
false ).toBool() );
 
  186  mPlotAlphaCheckbox->setChecked( settings.
value( QStringLiteral( 
"GradientEditor/plotAlpha" ), 
false ).toBool() );
 
  188  mHueCurve->setVisible( mPlotHueCheckbox->isChecked() );
 
  189  mLightnessCurve->setVisible( mPlotLightnessCheckbox->isChecked() );
 
  190  mSaturationCurve->setVisible( mPlotSaturationCheckbox->isChecked() );
 
  191  mAlphaCurve->setVisible( mPlotAlphaCheckbox->isChecked() );
 
  194  mStopEditor->selectStop( 0 );
 
  196  connect( mButtonBox, &QDialogButtonBox::helpRequested, 
this, &QgsGradientColorRampDialog::showHelp );
 
 
  202  settings.
setValue( QStringLiteral( 
"GradientEditor/plotHue" ), mPlotHueCheckbox->isChecked() );
 
  203  settings.
setValue( QStringLiteral( 
"GradientEditor/plotLightness" ), mPlotLightnessCheckbox->isChecked() );
 
  204  settings.
setValue( QStringLiteral( 
"GradientEditor/plotSaturation" ), mPlotSaturationCheckbox->isChecked() );
 
  205  settings.
setValue( QStringLiteral( 
"GradientEditor/plotAlpha" ), mPlotAlphaCheckbox->isChecked() );
 
 
  212  updateColorButtons();
 
 
  224void QgsGradientColorRampDialog::cboType_currentIndexChanged( 
int index )
 
  229  updateColorButtons();
 
  236void QgsGradientColorRampDialog::btnInformation_pressed()
 
  238  if ( mRamp.
info().isEmpty() )
 
  242  QLabel *label = 
nullptr;
 
  245  QTableWidget *tableInfo = 
new QTableWidget( dlg );
 
  246  tableInfo->verticalHeader()->hide();
 
  247  tableInfo->horizontalHeader()->hide();
 
  248  tableInfo->setRowCount( mRamp.
info().count() );
 
  249  tableInfo->setColumnCount( 2 );
 
  252  for ( QgsStringMap::const_iterator it = rampInfo.constBegin();
 
  253        it != rampInfo.constEnd(); ++it )
 
  255    if ( it.key().startsWith( QLatin1String( 
"cpt-city" ) ) )
 
  257    tableInfo->setItem( i, 0, 
new QTableWidgetItem( it.key() ) );
 
  258    tableInfo->setItem( i, 1, 
new QTableWidgetItem( it.value() ) );
 
  259    tableInfo->resizeRowToContents( i );
 
  262  tableInfo->resizeColumnToContents( 0 );
 
  263  tableInfo->horizontalHeader()->setStretchLastSection( 
true );
 
  264  tableInfo->setRowCount( i );
 
  265  tableInfo->setFixedHeight( tableInfo->rowHeight( 0 ) * i + 5 );
 
  266  dlg->
layout()->addWidget( tableInfo );
 
  267  dlg->resize( 600, 250 );
 
  269  dlg->
layout()->addSpacing( 5 );
 
  272  QString gradientFile = mRamp.
info().value( QStringLiteral( 
"cpt-city-gradient" ) );
 
  273  if ( !gradientFile.isNull() )
 
  275    QString fileName = gradientFile;
 
  277    if ( !QFile::exists( fileName ) )
 
  279      fileName = gradientFile;
 
  280      fileName.replace( QLatin1String( 
"<cpt-city>" ), QLatin1String( 
"http://soliton.vm.bytemark.co.uk/pub/cpt-city" ) );
 
  282    label = 
new QLabel( tr( 
"Gradient file : %1" ).arg( fileName ), dlg );
 
  283    label->setTextInteractionFlags( Qt::TextBrowserInteraction );
 
  284    dlg->
layout()->addSpacing( 5 );
 
  285    dlg->
layout()->addWidget( label );
 
  289  QString licenseFile = mRamp.
info().value( QStringLiteral( 
"cpt-city-license" ) );
 
  290  if ( !licenseFile.isNull() )
 
  292    QString fileName = licenseFile;
 
  294    if ( !QFile::exists( fileName ) )
 
  296      fileName = licenseFile;
 
  297      fileName.replace( QLatin1String( 
"<cpt-city>" ), QLatin1String( 
"http://soliton.vm.bytemark.co.uk/pub/cpt-city" ) );
 
  299    label = 
new QLabel( tr( 
"License file : %1" ).arg( fileName ), dlg );
 
  300    label->setTextInteractionFlags( Qt::TextBrowserInteraction );
 
  301    dlg->
layout()->addSpacing( 5 );
 
  302    dlg->
layout()->addWidget( label );
 
  303    if ( QFile::exists( fileName ) )
 
  305      QTextEdit *textEdit = 
new QTextEdit( dlg );
 
  306      textEdit->setReadOnly( 
true );
 
  307      QFile file( fileName );
 
  308      if ( file.open( QIODevice::ReadOnly | QIODevice::Text ) )
 
  310        textEdit->setText( file.readAll() );
 
  312        dlg->
layout()->addSpacing( 5 );
 
  313        dlg->
layout()->addWidget( textEdit );
 
  314        dlg->resize( 600, 500 );
 
  322void QgsGradientColorRampDialog::updateColorButtons()
 
  324  btnColor1->blockSignals( 
true );
 
  325  btnColor1->setColor( mRamp.
color1() );
 
  326  btnColor1->blockSignals( 
false );
 
  327  btnColor2->blockSignals( 
true );
 
  328  btnColor2->setColor( mRamp.
color2() );
 
  329  btnColor2->blockSignals( 
false );
 
  332void QgsGradientColorRampDialog::updateStopEditor()
 
  334  mStopEditor->blockSignals( 
true );
 
  335  mStopEditor->setGradientRamp( mRamp );
 
  336  mStopEditor->blockSignals( 
false );
 
  339void QgsGradientColorRampDialog::selectedStopChanged( 
const QgsGradientStop &stop )
 
  342  mColorWidget->blockSignals( 
true );
 
  343  mColorWidget->setColor( stop.
color );
 
  344  mColorWidget->blockSignals( 
false );
 
  345  mPositionSpinBox->blockSignals( 
true );
 
  346  mPositionSpinBox->setValue( stop.
offset * 100 );
 
  347  mPositionSpinBox->blockSignals( 
false );
 
  349  mStopColorSpec->setCurrentIndex( mStopColorSpec->findData( 
static_cast<int>( mStopEditor->selectedStop().colorSpec() ) ) );
 
  350  mStopDirection->setCurrentIndex( mStopDirection->findData( 
static_cast<int>( mStopEditor->selectedStop().direction() ) ) );
 
  356    mPositionSpinBox->setDisabled( 
true );
 
  357    mDeleteStopButton->setDisabled( 
true );
 
  361    mPositionSpinBox->setDisabled( 
false );
 
  362    mDeleteStopButton->setDisabled( 
false );
 
  366  mStopColorSpec->setEnabled( !( stop.
offset == 0 && stop.
color == mRamp.
color1() ) );
 
  367  mStopDirection->setEnabled( !( stop.
offset == 0 && stop.
color == mRamp.
color1() ) && hasDirection( mStopEditor->selectedStop().colorSpec() ) );
 
  372void QgsGradientColorRampDialog::colorWidgetChanged( 
const QColor &color )
 
  374  mStopEditor->setSelectedStopColor( color );
 
  377void QgsGradientColorRampDialog::mPositionSpinBox_valueChanged( 
double val )
 
  379  mStopEditor->setSelectedStopOffset( val / 100.0 );
 
  382void QgsGradientColorRampDialog::mPlotHueCheckbox_toggled( 
bool checked )
 
  384  mHueCurve->setVisible( checked );
 
  388void QgsGradientColorRampDialog::mPlotLightnessCheckbox_toggled( 
bool checked )
 
  390  mLightnessCurve->setVisible( checked );
 
  394void QgsGradientColorRampDialog::mPlotSaturationCheckbox_toggled( 
bool checked )
 
  396  mSaturationCurve->setVisible( checked );
 
  400void QgsGradientColorRampDialog::mPlotAlphaCheckbox_toggled( 
bool checked )
 
  402  mAlphaCurve->setVisible( checked );
 
  406void QgsGradientColorRampDialog::plotMousePress( QPointF point )
 
  411  mCurrentPlotColorComponent = -1;
 
  412  mCurrentPlotMarkerIndex = -1;
 
  415  for ( 
int i = 0; i < mRamp.
count(); ++i )
 
  418    double currentOff = 0.0;
 
  422      currentCol = mRamp.
color1();
 
  424    else if ( i == mRamp.
count() - 1 )
 
  427      currentCol = mRamp.
color2();
 
  431      currentOff = mRamp.
stops().at( i - 1 ).offset;
 
  432      currentCol = mRamp.
stops().at( i - 1 ).color;
 
  436    if ( mPlotHueCheckbox->isChecked() )
 
  438      currentDist = std::pow( point.x() - currentOff, 2.0 ) + std::pow( point.y() - currentCol.hslHueF(), 2.0 );
 
  439      if ( currentDist < minDist )
 
  441        minDist = currentDist;
 
  442        mCurrentPlotColorComponent = 0;
 
  443        mCurrentPlotMarkerIndex = i;
 
  446    if ( mPlotLightnessCheckbox->isChecked() )
 
  448      currentDist = std::pow( point.x() - currentOff, 2.0 ) + std::pow( point.y() - currentCol.lightnessF(), 2.0 );
 
  449      if ( currentDist < minDist )
 
  451        minDist = currentDist;
 
  452        mCurrentPlotColorComponent = 1;
 
  453        mCurrentPlotMarkerIndex = i;
 
  456    if ( mPlotSaturationCheckbox->isChecked() )
 
  458      currentDist = std::pow( point.x() - currentOff, 2.0 ) + std::pow( point.y() - currentCol.hslSaturationF(), 2.0 );
 
  459      if ( currentDist < minDist )
 
  461        minDist = currentDist;
 
  462        mCurrentPlotColorComponent = 2;
 
  463        mCurrentPlotMarkerIndex = i;
 
  466    if ( mPlotAlphaCheckbox->isChecked() )
 
  468      currentDist = std::pow( point.x() - currentOff, 2.0 ) + std::pow( point.y() - currentCol.alphaF(), 2.0 );
 
  469      if ( currentDist < minDist )
 
  471        minDist = currentDist;
 
  472        mCurrentPlotColorComponent = 3;
 
  473        mCurrentPlotMarkerIndex = i;
 
  479  if ( mCurrentPlotMarkerIndex >= 0 )
 
  480    mStopEditor->selectStop( mCurrentPlotMarkerIndex );
 
  483void QgsGradientColorRampDialog::plotMouseRelease( QPointF )
 
  485  mCurrentPlotColorComponent = -1;
 
  488void QgsGradientColorRampDialog::plotMouseMove( QPointF point )
 
  490  QColor newColor = mStopEditor->selectedStop().color;
 
  492  if ( mCurrentPlotColorComponent == 0 )
 
  493    newColor = QColor::fromHslF( std::clamp( point.y(), qreal( 0.0 ), qreal( 1.0 ) ), newColor.hslSaturationF(), newColor.lightnessF(), newColor.alphaF() );
 
  494  else if ( mCurrentPlotColorComponent == 1 )
 
  495    newColor = QColor::fromHslF( newColor.hslHueF(), newColor.hslSaturationF(), std::clamp( point.y(), qreal( 0.0 ), qreal( 1.0 ) ), newColor.alphaF() );
 
  496  else if ( mCurrentPlotColorComponent == 2 )
 
  497    newColor = QColor::fromHslF( newColor.hslHueF(), std::clamp( point.y(), qreal( 0.0 ), qreal( 1.0 ) ), newColor.lightnessF(), newColor.alphaF() );
 
  498  else if ( mCurrentPlotColorComponent == 3 )
 
  499    newColor = QColor::fromHslF( newColor.hslHueF(), newColor.hslSaturationF(), newColor.lightnessF(), std::clamp( point.y(), qreal( 0.0 ), qreal( 1.0 ) ) );
 
  501  mStopEditor->setSelectedStopDetails( newColor, std::clamp( point.x(), qreal( 0.0 ), qreal( 1.0 ) ) );
 
  504bool byX( QPointF p1, QPointF p2 )
 
  506  return p1.x() < p2.x();
 
 
  509void QgsGradientColorRampDialog::addPlotMarker( 
double x, 
double y, 
const QColor &color, 
bool isSelected )
 
  511  QColor borderColor = color.darker( 200 );
 
  512  borderColor.setAlpha( 255 );
 
  514  QColor brushColor = color;
 
  515  brushColor.setAlpha( 255 );
 
  517  QwtPlotMarker *marker = 
new QwtPlotMarker();
 
  518  marker->setSymbol( 
new QwtSymbol( QwtSymbol::Ellipse, QBrush( brushColor ), QPen( borderColor, isSelected ? 2 : 1 ), QSize( 8, 8 ) ) );
 
  519  marker->setValue( x, y );
 
  520  marker->attach( mPlot );
 
  521  marker->setRenderHint( QwtPlotItem::RenderAntialiased, 
true );
 
  525void QgsGradientColorRampDialog::addMarkersForColor( 
double x, 
const QColor &color, 
bool isSelected )
 
  527  if ( mPlotHueCheckbox->isChecked() )
 
  528    addPlotMarker( x, color.hslHueF(), color, isSelected && mCurrentPlotColorComponent == 0 );
 
  529  if ( mPlotLightnessCheckbox->isChecked() )
 
  530    addPlotMarker( x, color.lightnessF(), color, isSelected && mCurrentPlotColorComponent == 1 );
 
  531  if ( mPlotSaturationCheckbox->isChecked() )
 
  532    addPlotMarker( x, color.hslSaturationF(), color, isSelected && mCurrentPlotColorComponent == 2 );
 
  533  if ( mPlotAlphaCheckbox->isChecked() )
 
  534    addPlotMarker( x, color.alphaF(), color, isSelected && mCurrentPlotColorComponent == 3 );
 
  537bool QgsGradientColorRampDialog::hasDirection( QColor::Spec colorSpec )
 
  541    case QColor::Spec::Rgb:
 
  542    case QColor::Spec::ExtendedRgb:
 
  543    case QColor::Spec::Cmyk:
 
  544    case QColor::Spec::Invalid:
 
  547    case QColor::Spec::Hsv:
 
  548    case QColor::Spec::Hsl:
 
  555void QgsGradientColorRampDialog::updatePlot()
 
  558  const auto constMMarkers = mMarkers;
 
  559  for ( QwtPlotMarker *marker : constMMarkers )
 
  566  QPolygonF lightnessPoints;
 
  568  QPolygonF saturationPoints;
 
  569  QPolygonF alphaPoints;
 
  570  lightnessPoints << QPointF( 0.0, mRamp.
color1().lightnessF() );
 
  571  huePoints << QPointF( 0.0, mRamp.
color1().hslHueF() );
 
  572  saturationPoints << QPointF( 0.0, mRamp.
color1().hslSaturationF() );
 
  573  alphaPoints << QPointF( 0.0, mRamp.
color1().alphaF() );
 
  574  addMarkersForColor( 0, mRamp.
color1(), mCurrentPlotMarkerIndex == 0 );
 
  577  const auto constStops = mRamp.
stops();
 
  580    lightnessPoints << QPointF( stop.
offset, stop.
color.lightnessF() );
 
  581    huePoints << QPointF( stop.
offset, stop.
color.hslHueF() );
 
  582    saturationPoints << QPointF( stop.
offset, stop.
color.hslSaturationF() );
 
  583    alphaPoints << QPointF( stop.
offset, stop.
color.alphaF() );
 
  585    addMarkersForColor( stop.
offset, stop.
color, mCurrentPlotMarkerIndex == i );
 
  590  for ( 
double p = 0.001; p < 1.0; p += 0.001 )
 
  592    QColor 
c = mRamp.
color( p );
 
  593    lightnessPoints << QPointF( p, 
c.lightnessF() );
 
  594    huePoints << QPointF( p, 
c.hslHueF() );
 
  595    saturationPoints << QPointF( p, 
c.hslSaturationF() );
 
  596    alphaPoints << QPointF( p, 
c.alphaF() );
 
  599  lightnessPoints << QPointF( 1.0, mRamp.
color2().lightnessF() );
 
  600  huePoints << QPointF( 1.0, mRamp.
color2().hslHueF() );
 
  601  saturationPoints << QPointF( 1.0, mRamp.
color2().hslSaturationF() );
 
  602  alphaPoints << QPointF( 1.0, mRamp.
color2().alphaF() );
 
  603  addMarkersForColor( 1.0, mRamp.
color2(), mCurrentPlotMarkerIndex == i );
 
  605  std::sort( lightnessPoints.begin(), lightnessPoints.end(), 
byX );
 
  606  std::sort( huePoints.begin(), huePoints.end(), 
byX );
 
  607  std::sort( saturationPoints.begin(), saturationPoints.end(), 
byX );
 
  608  std::sort( alphaPoints.begin(), alphaPoints.end(), 
byX );
 
  610  mLightnessCurve->setSamples( lightnessPoints );
 
  611  mHueCurve->setSamples( huePoints );
 
  612  mSaturationCurve->setSamples( saturationPoints );
 
  613  mAlphaCurve->setSamples( alphaPoints );
 
  617void QgsGradientColorRampDialog::updateRampFromStopEditor()
 
  619  mRamp = mStopEditor->gradientRamp();
 
  622  mPositionSpinBox->blockSignals( 
true );
 
  623  mPositionSpinBox->setValue( mStopEditor->selectedStop().offset * 100 );
 
  624  mPositionSpinBox->blockSignals( 
false );
 
  625  mColorWidget->blockSignals( 
true );
 
  626  mColorWidget->setColor( mStopEditor->selectedStop().color );
 
  627  mColorWidget->blockSignals( 
false );
 
  629  mStopColorSpec->setCurrentIndex( mStopColorSpec->findData( 
static_cast<int>( mStopEditor->selectedStop().colorSpec() ) ) );
 
  630  mStopDirection->setCurrentIndex( mStopDirection->findData( 
static_cast<int>( mStopEditor->selectedStop().direction() ) ) );
 
  634  mStopColorSpec->setEnabled( !( mStopEditor->selectedStop().offset == 0 && mStopEditor->selectedStop().color == mRamp.
color1() ) );
 
  635  mStopDirection->setEnabled( !( mStopEditor->selectedStop().offset == 0 && mStopEditor->selectedStop().color == mRamp.
color1() ) && hasDirection( mStopEditor->selectedStop().colorSpec() ) );
 
  637  updateColorButtons();
 
  645  mStopEditor->setColor1( color );
 
  646  updateColorButtons();
 
 
  651  mStopEditor->setColor2( color );
 
  652  updateColorButtons();
 
 
  655void QgsGradientColorRampDialog::showHelp()
 
  657  QgsHelp::openHelp( QStringLiteral( 
"style_library/style_manager.html#setting-a-color-ramp" ) );
 
  663QgsGradientPlotEventFilter::QgsGradientPlotEventFilter( QwtPlot *plot )
 
  667  mPlot->canvas()->installEventFilter( 
this );
 
  670bool QgsGradientPlotEventFilter::eventFilter( QObject *
object, QEvent *event )
 
  672  if ( !mPlot->isEnabled() )
 
  673    return QObject::eventFilter( 
object, event );
 
  675  switch ( event->type() )
 
  677    case QEvent::MouseButtonPress:
 
  679      const QMouseEvent *mouseEvent = 
static_cast<QMouseEvent *
>( event );
 
  680      if ( mouseEvent->button() == Qt::LeftButton )
 
  682        emit mousePress( mapPoint( mouseEvent->pos() ) );
 
  686    case QEvent::MouseMove:
 
  688      const QMouseEvent *mouseEvent = 
static_cast<QMouseEvent *
>( event );
 
  689      if ( mouseEvent->buttons() & Qt::LeftButton )
 
  692        emit mouseMove( mapPoint( mouseEvent->pos() ) );
 
  696    case QEvent::MouseButtonRelease:
 
  698      const QMouseEvent *mouseEvent = 
static_cast<QMouseEvent *
>( event );
 
  699      if ( mouseEvent->button() == Qt::LeftButton )
 
  701        emit mouseRelease( mapPoint( mouseEvent->pos() ) );
 
  709  return QObject::eventFilter( 
object, event );
 
  712QPointF QgsGradientPlotEventFilter::mapPoint( QPointF point )
 const 
  717  return QPointF( mPlot->canvasMap( QwtPlot::xBottom ).invTransform( point.x() ), mPlot->canvasMap( QwtPlot::yLeft ).invTransform( point.y() ) );
 
AngularDirection
Angular directions.
 
@ CounterClockwise
Counter-clockwise direction.
 
@ Clockwise
Clockwise direction.
 
static QString defaultBaseDir()
 
A generic dialog with layout and button box.
 
QVBoxLayout * layout()
Returns the central layout. Widgets added to it must have this dialog as parent.
 
~QgsGradientColorRampDialog() override
 
QDialogButtonBox * buttonBox() const
Returns a reference to the dialog's button box.
 
void setColor2(const QColor &color)
Sets the end color for the gradient ramp.
 
QgsGradientColorRamp ramp
 
void setRamp(const QgsGradientColorRamp &ramp)
Sets the color ramp to show in the dialog.
 
QgsGradientColorRampDialog(const QgsGradientColorRamp &ramp, QWidget *parent=nullptr)
Constructor for QgsGradientColorRampDialog.
 
void setColor1(const QColor &color)
Sets the start color for the gradient ramp.
 
void changed()
Emitted when the dialog settings change.
 
Gradient color ramp, which smoothly interpolates between two colors and also supports optional extra ...
 
bool isDiscrete() const
Returns true if the gradient is using discrete interpolation, rather than smoothly interpolating betw...
 
int count() const override
Returns number of defined colors, or -1 if undefined.
 
QgsStringMap info() const
Returns any additional info attached to the gradient ramp (e.g., authorship notes)
 
void convertToDiscrete(bool discrete)
Converts a gradient with existing color stops to or from discrete interpolation.
 
QColor::Spec colorSpec() const
Returns the color specification in which the color component interpolation will occur.
 
QColor color(double value) const override
Returns the color corresponding to a specified value.
 
QColor color1() const
Returns the gradient start color.
 
Qgis::AngularDirection direction() const
Returns the direction to traverse the color wheel using when interpolating hue-based color specificat...
 
QgsGradientStopsList stops() const
Returns the list of intermediate gradient stops for the ramp.
 
QColor color2() const
Returns the gradient end color.
 
void changed()
Emitted when the gradient ramp is changed by a user.
 
void deleteSelectedStop()
Deletes the current selected stop.
 
void selectedStopChanged(const QgsGradientStop &stop)
Emitted when the current selected stop changes.
 
Represents a color stop within a QgsGradientColorRamp color ramp.
 
double offset
Relative positional offset, between 0 and 1.
 
QColor color
Gradient color at stop.
 
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
 
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
 
Stores settings for use within QGIS.
 
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
 
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
 
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
 
#define BUILTIN_UNREACHABLE
 
QMap< QString, QString > QgsStringMap
 
bool byX(QPointF p1, QPointF p2)