17#include "moc_qgscolorbrewercolorrampdialog.cpp"
23#include <QAbstractButton>
24#include <QDialogButtonBox>
27static void updateColorButton( QAbstractButton *button, QColor color )
31 button->setIcon( QIcon( p ) );
44 const QSize iconSize( 50, 16 );
45 cboSchemeName->setIconSize( iconSize );
48 const auto constSchemes = schemes;
49 for (
const QString &schemeName : constSchemes )
55 cboSchemeName->addItem( icon, schemeName );
59 connect( cboSchemeName,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsColorBrewerColorRampWidget::setSchemeName );
60 connect( cboColors,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsColorBrewerColorRampWidget::setColors );
70void QgsColorBrewerColorRampWidget::populateVariants()
72 const QString oldVariant = cboColors->currentText();
75 const QString schemeName = cboSchemeName->currentText();
77 const auto constVariants = variants;
78 for (
const int variant : constVariants )
80 cboColors->addItem( QString::number( variant ) );
84 int idx = cboColors->findText( oldVariant );
88 idx = cboColors->count() - 1;
90 cboColors->setCurrentIndex( idx );
93void QgsColorBrewerColorRampWidget::updatePreview()
95 const QSize size( 300, 40 );
99void QgsColorBrewerColorRampWidget::updateUi()
103 whileBlocking( cboColors )->setCurrentIndex( cboColors->findText( QString::number( mRamp.
colors() ) ) );
107void QgsColorBrewerColorRampWidget::setSchemeName()
117void QgsColorBrewerColorRampWidget::setColors()
119 const int num = cboColors->currentText().toInt();
128 QVBoxLayout *vLayout =
new QVBoxLayout();
131 vLayout->addWidget( mWidget );
132 mButtonBox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok, Qt::Horizontal );
133 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
134 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
135 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsColorBrewerColorRampDialog::showHelp );
136 vLayout->addWidget( mButtonBox );
137 setLayout( vLayout );
138 setWindowTitle( tr(
"ColorBrewer Ramp" ) );
147void QgsColorBrewerColorRampDialog::showHelp()
149 QgsHelp::openHelp( QStringLiteral(
"style_library/style_manager.html#setting-a-color-ramp" ) );
QgsColorBrewerColorRamp ramp
QgsColorBrewerColorRampDialog(const QgsColorBrewerColorRamp &ramp, QWidget *parent=nullptr)
Constructor for QgsColorBrewerColorRampDialog.
void changed()
Emitted when the dialog settings change.
QDialogButtonBox * buttonBox() const
Returns a reference to the dialog's button box.
Color ramp utilising "Color Brewer" preset color schemes.
static QList< int > listSchemeVariants(const QString &schemeName)
Returns a list of the valid variants (numbers of colors) for a specified color brewer scheme name.
static QStringList listSchemeNames()
Returns a list of all valid color brewer scheme names.
QString schemeName() const
Returns the name of the color brewer color scheme.
int colors() const
Returns the number of colors in the ramp.
void setSchemeName(const QString &schemeName)
Sets the name of the color brewer color scheme.
void setColors(int colors)
Sets the number of colors in the ramp.
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
static QIcon colorRampPreviewIcon(QgsColorRamp *ramp, QSize size, int padding=0)
Returns an icon preview for a color ramp.
static QPixmap colorRampPreviewPixmap(QgsColorRamp *ramp, QSize size, int padding=0, Qt::Orientation direction=Qt::Horizontal, bool flipDirection=false, bool drawTransparentBackground=true)
Returns a pixmap preview for a color ramp.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.