Skip to content

Commit 6e3c363

Browse files
committed
Non editable color schemes should not be editable in QgsColorSchemeList
1 parent c159c57 commit 6e3c363

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

src/gui/qgscolorschemelist.cpp

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,11 @@ Qt::ItemFlags QgsColorSchemeModel::flags( const QModelIndex &index ) const
269269
{
270270
case ColorSwatch:
271271
case ColorLabel:
272-
return flags | Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
272+
if ( mScheme->isEditable() )
273+
{
274+
flags = flags | Qt::ItemIsEditable;
275+
}
276+
return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
273277
default:
274278
return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
275279
}
@@ -279,6 +283,9 @@ bool QgsColorSchemeModel::setData( const QModelIndex &index, const QVariant &val
279283
{
280284
Q_UNUSED( role );
281285

286+
if ( !mScheme->isEditable() )
287+
return false;
288+
282289
if ( !index.isValid() )
283290
return false;
284291

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

338345
Qt::DropActions QgsColorSchemeModel::supportedDropActions() const
339346
{
340-
return Qt::MoveAction | Qt::CopyAction;
347+
if ( mScheme->isEditable() )
348+
{
349+
return Qt::MoveAction | Qt::CopyAction;
350+
}
351+
else
352+
{
353+
return Qt::CopyAction;
354+
}
341355
}
342356

343357
QStringList QgsColorSchemeModel::mimeTypes() const
344358
{
359+
if ( !mScheme->isEditable() )
360+
{
361+
return QStringList();
362+
}
363+
345364
QStringList types;
346365
types << "text/xml";
347366
types << "text/plain";
@@ -371,6 +390,11 @@ bool QgsColorSchemeModel::dropMimeData( const QMimeData *data, Qt::DropAction ac
371390
{
372391
Q_UNUSED( column );
373392

393+
if ( !mScheme->isEditable() )
394+
{
395+
return false;
396+
}
397+
374398
if ( action == Qt::IgnoreAction )
375399
{
376400
return true;
@@ -417,6 +441,11 @@ void QgsColorSchemeModel::setScheme( QgsColorScheme *scheme, const QString conte
417441

418442
bool QgsColorSchemeModel::removeRows( int row, int count, const QModelIndex &parent )
419443
{
444+
if ( !mScheme->isEditable() )
445+
{
446+
return false;
447+
}
448+
420449
if ( parent.isValid() )
421450
{
422451
return false;
@@ -440,6 +469,11 @@ bool QgsColorSchemeModel::insertRows( int row, int count, const QModelIndex& par
440469
{
441470
Q_UNUSED( parent );
442471

472+
if ( !mScheme->isEditable() )
473+
{
474+
return false;
475+
}
476+
443477
beginInsertRows( QModelIndex(), row, row + count - 1 );
444478
for ( int i = row; i < row + count; ++i )
445479
{
@@ -452,6 +486,11 @@ bool QgsColorSchemeModel::insertRows( int row, int count, const QModelIndex& par
452486

453487
void QgsColorSchemeModel::addColor( const QColor color, const QString label )
454488
{
489+
if ( !mScheme->isEditable() )
490+
{
491+
return;
492+
}
493+
455494
int row = rowCount();
456495
insertRow( row );
457496
QModelIndex colorIdx = index( row, 0, QModelIndex() );
@@ -539,6 +578,11 @@ bool QgsColorSwatchDelegate::editorEvent( QEvent *event, QAbstractItemModel *mod
539578
Q_UNUSED( option );
540579
if ( event->type() == QEvent::MouseButtonDblClick )
541580
{
581+
if ( !index.model()->flags( index ).testFlag( Qt::ItemIsEditable ) )
582+
{
583+
//item not editable
584+
return false;
585+
}
542586
QColor color = index.model()->data( index, Qt::DisplayRole ).value<QColor>();
543587
QColor newColor = QColorDialog::getColor( color, mParent, tr( "Select color" ), QColorDialog::ShowAlphaChannel );
544588
if ( !newColor.isValid() )

0 commit comments

Comments
 (0)