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