@@ -269,7 +269,11 @@ Qt::ItemFlags QgsColorSchemeModel::flags( const QModelIndex &index ) const
269
269
{
270
270
case ColorSwatch:
271
271
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;
273
277
default :
274
278
return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
275
279
}
@@ -279,6 +283,9 @@ bool QgsColorSchemeModel::setData( const QModelIndex &index, const QVariant &val
279
283
{
280
284
Q_UNUSED ( role );
281
285
286
+ if ( !mScheme ->isEditable () )
287
+ return false ;
288
+
282
289
if ( !index.isValid () )
283
290
return false ;
284
291
@@ -337,11 +344,23 @@ QVariant QgsColorSchemeModel::headerData( int section, Qt::Orientation orientati
337
344
338
345
Qt::DropActions QgsColorSchemeModel::supportedDropActions () const
339
346
{
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
+ }
341
355
}
342
356
343
357
QStringList QgsColorSchemeModel::mimeTypes () const
344
358
{
359
+ if ( !mScheme ->isEditable () )
360
+ {
361
+ return QStringList ();
362
+ }
363
+
345
364
QStringList types;
346
365
types << " text/xml" ;
347
366
types << " text/plain" ;
@@ -371,6 +390,11 @@ bool QgsColorSchemeModel::dropMimeData( const QMimeData *data, Qt::DropAction ac
371
390
{
372
391
Q_UNUSED ( column );
373
392
393
+ if ( !mScheme ->isEditable () )
394
+ {
395
+ return false ;
396
+ }
397
+
374
398
if ( action == Qt::IgnoreAction )
375
399
{
376
400
return true ;
@@ -417,6 +441,11 @@ void QgsColorSchemeModel::setScheme( QgsColorScheme *scheme, const QString conte
417
441
418
442
bool QgsColorSchemeModel::removeRows ( int row, int count, const QModelIndex &parent )
419
443
{
444
+ if ( !mScheme ->isEditable () )
445
+ {
446
+ return false ;
447
+ }
448
+
420
449
if ( parent.isValid () )
421
450
{
422
451
return false ;
@@ -440,6 +469,11 @@ bool QgsColorSchemeModel::insertRows( int row, int count, const QModelIndex& par
440
469
{
441
470
Q_UNUSED ( parent );
442
471
472
+ if ( !mScheme ->isEditable () )
473
+ {
474
+ return false ;
475
+ }
476
+
443
477
beginInsertRows ( QModelIndex (), row, row + count - 1 );
444
478
for ( int i = row; i < row + count; ++i )
445
479
{
@@ -452,6 +486,11 @@ bool QgsColorSchemeModel::insertRows( int row, int count, const QModelIndex& par
452
486
453
487
void QgsColorSchemeModel::addColor ( const QColor color, const QString label )
454
488
{
489
+ if ( !mScheme ->isEditable () )
490
+ {
491
+ return ;
492
+ }
493
+
455
494
int row = rowCount ();
456
495
insertRow ( row );
457
496
QModelIndex colorIdx = index ( row, 0 , QModelIndex () );
@@ -539,6 +578,11 @@ bool QgsColorSwatchDelegate::editorEvent( QEvent *event, QAbstractItemModel *mod
539
578
Q_UNUSED ( option );
540
579
if ( event->type () == QEvent::MouseButtonDblClick )
541
580
{
581
+ if ( !index.model ()->flags ( index ).testFlag ( Qt::ItemIsEditable ) )
582
+ {
583
+ // item not editable
584
+ return false ;
585
+ }
542
586
QColor color = index.model ()->data ( index, Qt::DisplayRole ).value <QColor>();
543
587
QColor newColor = QColorDialog::getColor ( color, mParent , tr ( " Select color" ), QColorDialog::ShowAlphaChannel );
544
588
if ( !newColor.isValid () )
0 commit comments