22 #include <QAbstractButton> 23 #include <QDialogButtonBox> 26 static void updateColorButton( QAbstractButton *button, QColor color )
30 button->setIcon( QIcon( p ) );
44 QSize iconSize( 50, 16 );
45 cboSchemeName->setIconSize( iconSize );
48 Q_FOREACH (
const QString &schemeName, schemes )
54 cboSchemeName->addItem( icon, schemeName );
58 connect( cboSchemeName,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsColorBrewerColorRampWidget::setSchemeName );
59 connect( cboColors,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsColorBrewerColorRampWidget::setColors );
69 void QgsColorBrewerColorRampWidget::populateVariants()
71 QString oldVariant = cboColors->currentText();
74 QString schemeName = cboSchemeName->currentText();
76 Q_FOREACH (
int variant, variants )
78 cboColors->addItem( QString::number( variant ) );
82 int idx = cboColors->findText( oldVariant );
86 idx = cboColors->count() - 1;
88 cboColors->setCurrentIndex( idx );
91 void QgsColorBrewerColorRampWidget::updatePreview()
93 QSize size( 300, 40 );
97 void QgsColorBrewerColorRampWidget::updateUi()
101 whileBlocking( cboColors )->setCurrentIndex( cboColors->findText( QString::number( mRamp.
colors() ) ) );
105 void QgsColorBrewerColorRampWidget::setSchemeName()
115 void QgsColorBrewerColorRampWidget::setColors()
117 int num = cboColors->currentText().toInt();
126 QVBoxLayout *vLayout =
new QVBoxLayout();
128 vLayout->addWidget( mWidget );
129 QDialogButtonBox *bbox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok, Qt::Horizontal );
130 connect( bbox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
131 connect( bbox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
132 connect( bbox, &QDialogButtonBox::helpRequested,
this, &QgsColorBrewerColorRampDialog::showHelp );
133 vLayout->addWidget( bbox );
134 setLayout( vLayout );
135 setWindowTitle( tr(
"ColorBrewer Ramp" ) );
139 void QgsColorBrewerColorRampDialog::showHelp()
141 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...
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.
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.