17#include "moc_qgscolorbrewercolorrampdialog.cpp"
23#include <QAbstractButton>
24#include <QDialogButtonBox>
27static void updateColorButton( QAbstractButton *button, QColor color )
31 button->setIcon( QIcon( p ) );
45 const QSize iconSize( 50, 16 );
46 cboSchemeName->setIconSize( iconSize );
49 const auto constSchemes = schemes;
50 for (
const QString &schemeName : constSchemes )
56 cboSchemeName->addItem( icon, schemeName );
60 connect( cboSchemeName,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsColorBrewerColorRampWidget::setSchemeName );
61 connect( cboColors,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsColorBrewerColorRampWidget::setColors );
71void QgsColorBrewerColorRampWidget::populateVariants()
73 const QString oldVariant = cboColors->currentText();
76 const QString schemeName = cboSchemeName->currentText();
78 const auto constVariants = variants;
79 for (
const int variant : constVariants )
81 cboColors->addItem( QString::number( variant ) );
85 int idx = cboColors->findText( oldVariant );
89 idx = cboColors->count() - 1;
91 cboColors->setCurrentIndex( idx );
94void QgsColorBrewerColorRampWidget::updatePreview()
96 const QSize size( 300, 40 );
100void QgsColorBrewerColorRampWidget::updateUi()
104 whileBlocking( cboColors )->setCurrentIndex( cboColors->findText( QString::number( mRamp.
colors() ) ) );
108void QgsColorBrewerColorRampWidget::setSchemeName()
118void QgsColorBrewerColorRampWidget::setColors()
120 const int num = cboColors->currentText().toInt();
129 QVBoxLayout *vLayout =
new QVBoxLayout();
132 vLayout->addWidget( mWidget );
133 mButtonBox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok, Qt::Horizontal );
134 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
135 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
136 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsColorBrewerColorRampDialog::showHelp );
137 vLayout->addWidget( mButtonBox );
138 setLayout( vLayout );
139 setWindowTitle( tr(
"ColorBrewer Ramp" ) );
148void QgsColorBrewerColorRampDialog::showHelp()
150 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.