diff --git a/src/gui/qgscolorschemelist.cpp b/src/gui/qgscolorschemelist.cpp index 3bc4af5ff17..abfc6005d71 100644 --- a/src/gui/qgscolorschemelist.cpp +++ b/src/gui/qgscolorschemelist.cpp @@ -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; } @@ -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; @@ -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"; @@ -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; @@ -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; @@ -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 ) { @@ -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() ); @@ -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 newColor = QColorDialog::getColor( color, mParent, tr( "Select color" ), QColorDialog::ShowAlphaChannel ); if ( !newColor.isValid() )