Skip to content
Permalink
Browse files

Default names for colors when adding to schemes

  • Loading branch information
nyalldawson committed Sep 12, 2014
1 parent 5b3e014 commit b44ef92b02796094c37f10e14c98acf5eabec902
@@ -191,6 +191,14 @@ class QgsSymbolLayerV2Utils
static QgsVectorColorRampV2* loadColorRamp( QDomElement& element ) /Factory/;
static QDomElement saveColorRamp( QString name, QgsVectorColorRampV2* ramp, QDomDocument& doc );

/**
* Returns a friendly display name for a color
* @param color source color
* @returns display name for color
* @note added in 2.5
*/
static QString colorToName( const QColor& color );

/**
* Attempts to parse a string as a list of colors using a variety of common formats, including hex
* codes, rgb and rgba strings.
@@ -37,6 +37,7 @@
#include "qgsdialog.h"
#include "qgscomposer.h"
#include "qgscolorschemeregistry.h"
#include "qgssymbollayerv2utils.h"

#include <QInputDialog>
#include <QFileDialog>
@@ -2087,7 +2088,7 @@ void QgsOptions::on_mButtonAddColor_clicked()
}
activateWindow();

mTreeCustomColors->addColor( newColor );
mTreeCustomColors->addColor( newColor, QgsSymbolLayerV2Utils::colorToName( newColor ) );
}

void QgsOptions::on_mButtonImportColors_clicked()
@@ -47,6 +47,7 @@
#include "qgsrelationmanager.h"
#include "qgisapp.h"
#include "qgscolorschemeregistry.h"
#include "qgssymbollayerv2utils.h"

//qt includes
#include <QColorDialog>
@@ -1700,7 +1701,7 @@ void QgsProjectProperties::on_mButtonAddColor_clicked()
}
activateWindow();

mTreeProjectColors->addColor( newColor );
mTreeProjectColors->addColor( newColor, QgsSymbolLayerV2Utils::colorToName( newColor ) );
}

void QgsProjectProperties::on_mButtonImportColors_clicked()
@@ -69,7 +69,7 @@ QgsNamedColorList QgsRecentColorScheme::fetchColors( const QString context,
QgsNamedColorList colorList;
foreach ( QVariant color, recentColorVariants )
{
colorList.append( qMakePair( color.value<QColor>(), QString() ) );
colorList.append( qMakePair( color.value<QColor>(), QgsSymbolLayerV2Utils::colorToName( color.value<QColor>() ) ) );
}
return colorList;
}
@@ -2732,6 +2732,18 @@ QDomElement QgsSymbolLayerV2Utils::saveColorRamp( QString name, QgsVectorColorRa
return rampEl;
}

QString QgsSymbolLayerV2Utils::colorToName( const QColor &color )
{
if ( !color.isValid() )
{
return QString();
}

//TODO - utilise a color names database (such as X11) to return nicer names
//for now, just return hex codes
return color.name();
}

QList<QColor> QgsSymbolLayerV2Utils::parseColorList( const QString colorStr )
{
QList<QColor> colors;
@@ -229,6 +229,14 @@ class CORE_EXPORT QgsSymbolLayerV2Utils
static QgsVectorColorRampV2* loadColorRamp( QDomElement& element );
static QDomElement saveColorRamp( QString name, QgsVectorColorRampV2* ramp, QDomDocument& doc );

/**
* Returns a friendly display name for a color
* @param color source color
* @returns display name for color
* @note added in 2.5
*/
static QString colorToName( const QColor& color );

/**
* Attempts to parse a string as a list of colors using a variety of common formats, including hex
* codes, rgb and rgba strings.
@@ -106,7 +106,7 @@ void QgsColorSchemeList::pasteColors()
QgsNamedColorList::const_iterator colorIt = pastedColors.constBegin();
for ( ; colorIt != pastedColors.constEnd(); ++colorIt )
{
mModel->addColor(( *colorIt ).first, ( *colorIt ).second );
mModel->addColor(( *colorIt ).first, !( *colorIt ).second.isEmpty() ? ( *colorIt ).second : QgsSymbolLayerV2Utils::colorToName(( *colorIt ).first ) );
}
}

@@ -151,7 +151,7 @@ bool QgsColorSchemeList::importColorsFromGpl( QFile &file )
QgsNamedColorList::const_iterator colorIt = importedColors.constBegin();
for ( ; colorIt != importedColors.constEnd(); ++colorIt )
{
mModel->addColor(( *colorIt ).first, ( *colorIt ).second );
mModel->addColor(( *colorIt ).first, !( *colorIt ).second.isEmpty() ? ( *colorIt ).second : QgsSymbolLayerV2Utils::colorToName(( *colorIt ).first ) );
}

return true;
@@ -422,7 +422,7 @@ bool QgsColorSchemeModel::dropMimeData( const QMimeData *data, Qt::DropAction ac
QModelIndex colorIdx = index( beginRow, 0, QModelIndex() );
setData( colorIdx, QVariant(( *colorIt ).first ) );
QModelIndex labelIdx = index( beginRow, 1, QModelIndex() );
setData( labelIdx, QVariant(( *colorIt ).second ) );
setData( labelIdx, !( *colorIt ).second.isEmpty() ? ( *colorIt ).second : QgsSymbolLayerV2Utils::colorToName(( *colorIt ).first ) );
beginRow++;
}

0 comments on commit b44ef92

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