Skip to content

Commit

Permalink
Non editable color schemes should not be editable in QgsColorSchemeList
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 11, 2014
1 parent c159c57 commit 6e3c363
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions src/gui/qgscolorschemelist.cpp
Expand Up @@ -269,7 +269,11 @@ Qt::ItemFlags QgsColorSchemeModel::flags( const QModelIndex &index ) const
{
case ColorSwatch:
case ColorLabel:
return flags | Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
if ( mScheme->isEditable() )
{
flags = flags | Qt::ItemIsEditable;
}
return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
default:
return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
Expand All @@ -279,6 +283,9 @@ bool QgsColorSchemeModel::setData( const QModelIndex &index, const QVariant &val
{
Q_UNUSED( role );

if ( !mScheme->isEditable() )
return false;

if ( !index.isValid() )
return false;

Expand Down Expand Up @@ -337,11 +344,23 @@ QVariant QgsColorSchemeModel::headerData( int section, Qt::Orientation orientati

Qt::DropActions QgsColorSchemeModel::supportedDropActions() const
{
return Qt::MoveAction | Qt::CopyAction;
if ( mScheme->isEditable() )
{
return Qt::MoveAction | Qt::CopyAction;
}
else
{
return Qt::CopyAction;
}
}

QStringList QgsColorSchemeModel::mimeTypes() const
{
if ( !mScheme->isEditable() )
{
return QStringList();
}

QStringList types;
types << "text/xml";
types << "text/plain";
Expand Down Expand Up @@ -371,6 +390,11 @@ bool QgsColorSchemeModel::dropMimeData( const QMimeData *data, Qt::DropAction ac
{
Q_UNUSED( column );

if ( !mScheme->isEditable() )
{
return false;
}

if ( action == Qt::IgnoreAction )
{
return true;
Expand Down Expand Up @@ -417,6 +441,11 @@ void QgsColorSchemeModel::setScheme( QgsColorScheme *scheme, const QString conte

bool QgsColorSchemeModel::removeRows( int row, int count, const QModelIndex &parent )
{
if ( !mScheme->isEditable() )
{
return false;
}

if ( parent.isValid() )
{
return false;
Expand All @@ -440,6 +469,11 @@ bool QgsColorSchemeModel::insertRows( int row, int count, const QModelIndex& par
{
Q_UNUSED( parent );

if ( !mScheme->isEditable() )
{
return false;
}

beginInsertRows( QModelIndex(), row, row + count - 1 );
for ( int i = row; i < row + count; ++i )
{
Expand All @@ -452,6 +486,11 @@ bool QgsColorSchemeModel::insertRows( int row, int count, const QModelIndex& par

void QgsColorSchemeModel::addColor( const QColor color, const QString label )
{
if ( !mScheme->isEditable() )
{
return;
}

int row = rowCount();
insertRow( row );
QModelIndex colorIdx = index( row, 0, QModelIndex() );
Expand Down Expand Up @@ -539,6 +578,11 @@ bool QgsColorSwatchDelegate::editorEvent( QEvent *event, QAbstractItemModel *mod
Q_UNUSED( option );
if ( event->type() == QEvent::MouseButtonDblClick )
{
if ( !index.model()->flags( index ).testFlag( Qt::ItemIsEditable ) )
{
//item not editable
return false;
}
QColor color = index.model()->data( index, Qt::DisplayRole ).value<QColor>();
QColor newColor = QColorDialog::getColor( color, mParent, tr( "Select color" ), QColorDialog::ShowAlphaChannel );
if ( !newColor.isValid() )
Expand Down

0 comments on commit 6e3c363

Please sign in to comment.