20 #include <QFileDialog> 21 #include <QAbstractButton> 22 #include <QDialogButtonBox> 23 #include <QMessageBox> 30 connect( mButtonAddColor, &QToolButton::clicked,
this, &QgsPresetColorRampWidget::mButtonAddColor_clicked );
31 mTreeColors->setScheme( &mRamp );
39 connect( mTreeColors->model(), &QAbstractItemModel::dataChanged,
this, &QgsPresetColorRampWidget::schemeChanged );
40 connect( mTreeColors->model(), &QAbstractItemModel::rowsRemoved,
this, &QgsPresetColorRampWidget::schemeChanged );
53 mTreeColors->setScheme( &mRamp );
58 void QgsPresetColorRampWidget::updatePreview()
60 QSize size( 300, 40 );
64 void QgsPresetColorRampWidget::setColors()
70 void QgsPresetColorRampWidget::mButtonAddColor_clicked()
85 if ( !newColor.isValid() )
95 void QgsPresetColorRampWidget::schemeChanged()
97 mTreeColors->saveColorsToScheme();
102 void QgsPresetColorRampWidget::newColorChanged(
const QColor &color )
104 int row = mTreeColors->model()->rowCount() - 1;
105 QModelIndex colorIndex = mTreeColors->model()->index( row, 0 );
106 mTreeColors->model()->setData( colorIndex, color );
112 QVBoxLayout *vLayout =
new QVBoxLayout();
114 vLayout->addWidget( mWidget );
115 mButtonBox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok, Qt::Horizontal );
116 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
117 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
118 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsPresetColorRampDialog::showHelp );
119 vLayout->addWidget( mButtonBox );
120 setLayout( vLayout );
121 setWindowTitle( tr(
"Color Presets Ramp" ) );
130 void QgsPresetColorRampDialog::showHelp()
132 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/style_library.html#color-ramp" ) );
static QColor getColor(const QColor &initialColor, QWidget *parent, const QString &title=QString(), bool allowOpacity=false)
Returns a color selection from a color dialog.
void removeSelection()
Removes any selected colors from the list.
QDialogButtonBox * buttonBox() const
Returns a reference to the dialog's button box.
void pasteColors()
Pastes colors from clipboard to the list.
void showExportColorsDialog()
Displays a file picker dialog allowing users to export colors from the list into a file...
void changed()
Emitted when the dialog settings change.
void showImportColorsDialog()
Displays a file picker dialog allowing users to import colors into the list from a file...
static QString colorToName(const QColor &color)
Returns a friendly display name for a color.
QgsPresetColorRampDialog(const QgsPresetSchemeColorRamp &ramp, QWidget *parent=nullptr)
Constructor for QgsPresetColorRampDialog.
A scheme based color ramp consisting of a list of predefined colors.
static QPixmap colorRampPreviewPixmap(QgsColorRamp *ramp, QSize size, int padding=0)
Returns a pixmap preview for a color ramp.
void copyColors()
Copies colors from the list to the clipboard.
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
static QColor lastUsedColor()
Returns the most recently used color.