Skip to content

Commit

Permalink
Allow editing colors in a color list inline in the style panel
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 14, 2016
1 parent ec50cac commit 5b6bf82
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/gui/qgscolorschemelist.cpp
Expand Up @@ -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() )
{
Expand All @@ -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 );
}
}
5 changes: 5 additions & 0 deletions src/gui/qgscolorschemelist.h
Expand Up @@ -22,6 +22,7 @@
#include <QFile>

class QMimeData;
class QgsPanelWidget;

/** \ingroup gui
* \class QgsColorSwatchDelegate
Expand All @@ -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;

Expand Down

0 comments on commit 5b6bf82

Please sign in to comment.