Skip to content
Permalink
Browse files

Allow editing colors in a color list inline in the style panel

  • Loading branch information
nyalldawson committed Sep 14, 2016
1 parent ec50cac commit 5b6bf82aec20b7082c68f600db9c4c3c7768b5c6
Showing with 29 additions and 0 deletions.
  1. +24 −0 src/gui/qgscolorschemelist.cpp
  2. +5 −0 src/gui/qgscolorschemelist.h
@@ -758,7 +758,22 @@ bool QgsColorSwatchDelegate::editorEvent( QEvent *event, QAbstractItemModel *mod
//item not editable
return false;
}

QColor color = index.model()->data( index, Qt::DisplayRole ).value<QColor>();

QgsPanelWidget* panel = QgsPanelWidget::findParentPanel( qobject_cast< QWidget* >( parent() ) );
if ( panel && panel->dockMode() )
{
QgsCompoundColorWidget* colorWidget = new QgsCompoundColorWidget( panel, color, QgsCompoundColorWidget::LayoutVertical );
colorWidget->setPanelTitle( tr( "Select color" ) );
colorWidget->setAllowAlpha( true );
colorWidget->setProperty( "index", index );
connect( colorWidget, SIGNAL( currentColorChanged( QColor ) ), this, SLOT( colorChanged() ) );
panel->openPanel( colorWidget );
return true;
}


QColor newColor = QgsColorDialog::getColor( color, mParent, tr( "Select color" ), true );
if ( !newColor.isValid() )
{
@@ -770,3 +785,12 @@ bool QgsColorSwatchDelegate::editorEvent( QEvent *event, QAbstractItemModel *mod

return false;
}

void QgsColorSwatchDelegate::colorChanged()
{
if ( QgsCompoundColorWidget* colorWidget = qobject_cast< QgsCompoundColorWidget* >( sender() ) )
{
QModelIndex index = colorWidget->property( "index" ).toModelIndex();
const_cast< QAbstractItemModel* >( index.model() )->setData( index, colorWidget->color(), Qt::EditRole );
}
}
@@ -22,6 +22,7 @@
#include <QFile>

class QMimeData;
class QgsPanelWidget;

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

private slots:

void colorChanged();

private:
QWidget* mParent;

0 comments on commit 5b6bf82

Please sign in to comment.
You can’t perform that action at this time.