Skip to content
Permalink
Browse files

Avoid new colors in ramp overwriting old colors

  • Loading branch information
nyalldawson committed Sep 14, 2016
1 parent 392a986 commit 03907605e3a1c9c1c8acfcc4e935016ad8bc8f27
@@ -85,8 +85,9 @@ class QgsColorSchemeModel: QAbstractItemModel
/** Add a color to the list
* @param color color to add
* @param label label for color
* @param allowDuplicate set to true to allow duplicate colors to be added (colors which are already present in the list)
*/
void addColor( const QColor color, const QString &label = QString() );
void addColor( const QColor &color, const QString &label = QString(), bool allowDuplicate = false );

/** Returns whether the color scheme model has been modified
* @returns true if colors have been modified
@@ -162,11 +163,12 @@ class QgsColorSchemeList: QTreeView
*/
void removeSelection();

/** Adds a color to the list
/** Add a color to the list
* @param color color to add
* @param label optional label for color
* @param label label for color
* @param allowDuplicate set to true to allow duplicate colors to be added (colors which are already present in the list)
*/
void addColor( const QColor &color, const QString &label = QString() );
void addColor( const QColor &color, const QString &label = QString(), bool allowDuplicate = false );

/** Pastes colors from clipboard to the list
* @see copyColors
@@ -93,9 +93,9 @@ void QgsColorSchemeList::removeSelection()
}
}

void QgsColorSchemeList::addColor( const QColor &color, const QString &label )
void QgsColorSchemeList::addColor( const QColor &color, const QString &label, bool allowDuplicate )
{
mModel->addColor( color, label );
mModel->addColor( color, label, allowDuplicate );
}

void QgsColorSchemeList::pasteColors()
@@ -647,22 +647,25 @@ bool QgsColorSchemeModel::insertRows( int row, int count, const QModelIndex& par
return true;
}

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

//matches existing color? if so, remove it first
QPair< QColor, QString > newColor = qMakePair( color, !label.isEmpty() ? label : QgsSymbolLayerUtils::colorToName( color ) );
//if color already exists, remove it
int existingIndex = mColors.indexOf( newColor );
if ( existingIndex >= 0 )
if ( !allowDuplicate )
{
beginRemoveRows( QModelIndex(), existingIndex, existingIndex );
mColors.removeAt( existingIndex );
endRemoveRows();
//matches existing color? if so, remove it first
QPair< QColor, QString > newColor = qMakePair( color, !label.isEmpty() ? label : QgsSymbolLayerUtils::colorToName( color ) );
//if color already exists, remove it
int existingIndex = mColors.indexOf( newColor );
if ( existingIndex >= 0 )
{
beginRemoveRows( QModelIndex(), existingIndex, existingIndex );
mColors.removeAt( existingIndex );
endRemoveRows();
}
}

int row = rowCount();
@@ -119,8 +119,9 @@ class GUI_EXPORT QgsColorSchemeModel: public QAbstractItemModel
/** Add a color to the list
* @param color color to add
* @param label label for color
* @param allowDuplicate set to true to allow duplicate colors to be added (colors which are already present in the list)
*/
void addColor( const QColor &color, const QString &label = QString() );
void addColor( const QColor &color, const QString &label = QString(), bool allowDuplicate = false );

/** Returns whether the color scheme model has been modified
* @returns true if colors have been modified
@@ -210,8 +211,9 @@ class GUI_EXPORT QgsColorSchemeList: public QTreeView
/** Adds a color to the list
* @param color color to add
* @param label optional label for color
* @param allowDuplicate set to true to allow duplicate colors to be added, ie colors which already exist in the list
*/
void addColor( const QColor &color, const QString &label = QString() );
void addColor( const QColor &color, const QString &label = QString(), bool allowDuplicate = false );

/** Pastes colors from clipboard to the list
* @see copyColors
@@ -74,7 +74,7 @@ void QgsPresetColorRampWidget::on_mButtonAddColor_clicked()
{
if ( dockMode() )
{
mTreeColors->addColor( QgsRecentColorScheme::lastUsedColor(), QgsSymbolLayerUtils::colorToName( QgsRecentColorScheme::lastUsedColor() ) );
mTreeColors->addColor( QgsRecentColorScheme::lastUsedColor(), QgsSymbolLayerUtils::colorToName( QgsRecentColorScheme::lastUsedColor() ), true );

QgsCompoundColorWidget* colorWidget = new QgsCompoundColorWidget( this, QgsRecentColorScheme::lastUsedColor(), QgsCompoundColorWidget::LayoutVertical );
colorWidget->setPanelTitle( tr( "Select Color" ) );

0 comments on commit 0390760

Please sign in to comment.
You can’t perform that action at this time.