Skip to content

Commit 5b6bf82

Browse files
committed
Allow editing colors in a color list inline in the style panel
1 parent ec50cac commit 5b6bf82

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/gui/qgscolorschemelist.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,22 @@ bool QgsColorSwatchDelegate::editorEvent( QEvent *event, QAbstractItemModel *mod
758758
//item not editable
759759
return false;
760760
}
761+
761762
QColor color = index.model()->data( index, Qt::DisplayRole ).value<QColor>();
763+
764+
QgsPanelWidget* panel = QgsPanelWidget::findParentPanel( qobject_cast< QWidget* >( parent() ) );
765+
if ( panel && panel->dockMode() )
766+
{
767+
QgsCompoundColorWidget* colorWidget = new QgsCompoundColorWidget( panel, color, QgsCompoundColorWidget::LayoutVertical );
768+
colorWidget->setPanelTitle( tr( "Select color" ) );
769+
colorWidget->setAllowAlpha( true );
770+
colorWidget->setProperty( "index", index );
771+
connect( colorWidget, SIGNAL( currentColorChanged( QColor ) ), this, SLOT( colorChanged() ) );
772+
panel->openPanel( colorWidget );
773+
return true;
774+
}
775+
776+
762777
QColor newColor = QgsColorDialog::getColor( color, mParent, tr( "Select color" ), true );
763778
if ( !newColor.isValid() )
764779
{
@@ -770,3 +785,12 @@ bool QgsColorSwatchDelegate::editorEvent( QEvent *event, QAbstractItemModel *mod
770785

771786
return false;
772787
}
788+
789+
void QgsColorSwatchDelegate::colorChanged()
790+
{
791+
if ( QgsCompoundColorWidget* colorWidget = qobject_cast< QgsCompoundColorWidget* >( sender() ) )
792+
{
793+
QModelIndex index = colorWidget->property( "index" ).toModelIndex();
794+
const_cast< QAbstractItemModel* >( index.model() )->setData( index, colorWidget->color(), Qt::EditRole );
795+
}
796+
}

src/gui/qgscolorschemelist.h

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <QFile>
2323

2424
class QMimeData;
25+
class QgsPanelWidget;
2526

2627
/** \ingroup gui
2728
* \class QgsColorSwatchDelegate
@@ -39,6 +40,10 @@ class GUI_EXPORT QgsColorSwatchDelegate : public QAbstractItemDelegate
3940
QSize sizeHint( const QStyleOptionViewItem & option, const QModelIndex & index ) const override;
4041
bool editorEvent( QEvent * event, QAbstractItemModel * model, const QStyleOptionViewItem & option, const QModelIndex & index ) override;
4142

43+
private slots:
44+
45+
void colorChanged();
46+
4247
private:
4348
QWidget* mParent;
4449

0 commit comments

Comments
 (0)