Skip to content

Commit 7f32157

Browse files
author
wonder
committedOct 20, 2010
[FEATURE] Allow creation of color ramps in color ramp combo box.
git-svn-id: http://svn.osgeo.org/qgis/trunk@14421 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 8ee79eb commit 7f32157

9 files changed

+279
-167
lines changed
 

‎src/gui/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
SET(QGIS_GUI_SRCS
33

44
symbology-ng/qgsbrushstylecombobox.cpp
5+
symbology-ng/qgscolorrampcombobox.cpp
56
symbology-ng/qgsdashspacedialog.cpp
67
symbology-ng/qgspenstylecombobox.cpp
78
symbology-ng/qgssymbollayerv2widget.cpp
@@ -73,6 +74,7 @@ symbology-ng/qgssymbolv2selectordialog.h
7374
symbology-ng/qgsvectorgradientcolorrampv2dialog.h
7475
symbology-ng/qgsvectorrandomcolorrampv2dialog.h
7576
symbology-ng/qgsvectorcolorbrewercolorrampv2dialog.h
77+
symbology-ng/qgscolorrampcombobox.h
7678
symbology-ng/characterwidget.h
7779
symbology-ng/qgspenstylecombobox.h
7880
symbology-ng/qgsbrushstylecombobox.h

‎src/gui/symbology-ng/qgscategorizedsymbolrendererv2widget.cpp

Lines changed: 35 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ QgsRendererV2Widget* QgsCategorizedSymbolRendererV2Widget::create( QgsVectorLaye
2424
}
2525

2626
QgsCategorizedSymbolRendererV2Widget::QgsCategorizedSymbolRendererV2Widget( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer )
27-
: QgsRendererV2Widget( layer, style )
27+
: QgsRendererV2Widget( layer, style )
2828
{
2929

3030
// try to recognize the previous renderer
3131
// (null renderer means "no previous renderer")
32-
if ( !renderer || renderer->type() != "categorizedSymbol" )
32+
if( !renderer || renderer->type() != "categorizedSymbol" )
3333
{
3434
// we're not going to use it - so let's delete the renderer
3535
delete renderer;
@@ -48,7 +48,9 @@ QgsCategorizedSymbolRendererV2Widget::QgsCategorizedSymbolRendererV2Widget( QgsV
4848
setupUi( this );
4949

5050
populateColumns();
51-
populateColorRamps();
51+
52+
cboCategorizedColorRamp->populate( mStyle );
53+
5254
QStandardItemModel* m = new QStandardItemModel( this );
5355
QStringList labels;
5456
labels << tr( "Symbol" ) << tr( "Value" ) << tr( "Label" );
@@ -100,23 +102,17 @@ void QgsCategorizedSymbolRendererV2Widget::updateUiFromRenderer()
100102
connect( cboCategorizedColumn, SIGNAL( currentIndexChanged( int ) ), this, SLOT( categoryColumnChanged() ) );
101103

102104
// set source symbol
103-
if ( mRenderer->sourceSymbol() )
105+
if( mRenderer->sourceSymbol() )
104106
{
105107
delete mCategorizedSymbol;
106108
mCategorizedSymbol = mRenderer->sourceSymbol()->clone();
107109
updateCategorizedSymbolIcon();
108110
}
109111

110112
// set source color ramp
111-
if ( mRenderer->sourceColorRamp() )
113+
if( mRenderer->sourceColorRamp() )
112114
{
113-
QSize rampIconSize( 50, 16 );
114-
QIcon icon = QgsSymbolLayerV2Utils::colorRampPreviewIcon( mRenderer->sourceColorRamp(), rampIconSize );
115-
if ( cboCategorizedColorRamp->itemText( 0 ) == "[source]" )
116-
cboCategorizedColorRamp->setItemIcon( 0, icon );
117-
else
118-
cboCategorizedColorRamp->insertItem( 0, icon, "[source]" );
119-
cboCategorizedColorRamp->setCurrentIndex( 0 );
115+
cboCategorizedColorRamp->setSourceColorRamp( mRenderer->sourceColorRamp() );
120116
}
121117

122118
}
@@ -129,7 +125,7 @@ QgsFeatureRendererV2* QgsCategorizedSymbolRendererV2Widget::renderer()
129125
void QgsCategorizedSymbolRendererV2Widget::changeCategorizedSymbol()
130126
{
131127
QgsSymbolV2SelectorDialog dlg( mCategorizedSymbol, mStyle, this );
132-
if ( !dlg.exec() )
128+
if( !dlg.exec() )
133129
return;
134130

135131
updateCategorizedSymbolIcon();
@@ -154,7 +150,7 @@ void QgsCategorizedSymbolRendererV2Widget::populateCategories()
154150

155151
// TODO: sort?? utils.sortVariantList(keys);
156152

157-
for ( i = 0; i < count; i++ )
153+
for( i = 0; i < count; i++ )
158154
{
159155
const QgsRendererCategoryV2 &cat = mRenderer->categories()[i];
160156
addCategory( cat );
@@ -170,26 +166,12 @@ void QgsCategorizedSymbolRendererV2Widget::populateColumns()
170166
cboCategorizedColumn->clear();
171167
const QgsFieldMap& flds = mLayer->pendingFields();
172168
QgsFieldMap::ConstIterator it = flds.begin();
173-
for ( ; it != flds.end(); ++it )
169+
for( ; it != flds.end(); ++it )
174170
{
175171
cboCategorizedColumn->addItem( it->name() );
176172
}
177173
}
178174

179-
void QgsCategorizedSymbolRendererV2Widget::populateColorRamps()
180-
{
181-
QSize rampIconSize( 50, 16 );
182-
cboCategorizedColorRamp->setIconSize( rampIconSize );
183-
184-
QStringList rampNames = mStyle->colorRampNames();
185-
for ( QStringList::iterator it = rampNames.begin(); it != rampNames.end(); ++it )
186-
{
187-
QgsVectorColorRampV2* ramp = mStyle->colorRamp( *it );
188-
QIcon icon = QgsSymbolLayerV2Utils::colorRampPreviewIcon( ramp, rampIconSize );
189-
cboCategorizedColorRamp->addItem( icon, *it );
190-
delete ramp;
191-
}
192-
}
193175

194176
void QgsCategorizedSymbolRendererV2Widget::addCategory( const QgsRendererCategoryV2 &cat )
195177
{
@@ -214,21 +196,21 @@ void QgsCategorizedSymbolRendererV2Widget::categoryColumnChanged()
214196

215197
void QgsCategorizedSymbolRendererV2Widget::categoriesDoubleClicked( const QModelIndex & idx )
216198
{
217-
if ( idx.isValid() && idx.column() == 0 )
199+
if( idx.isValid() && idx.column() == 0 )
218200
changeCategorySymbol();
219201
}
220202

221203
void QgsCategorizedSymbolRendererV2Widget::changeCategorySymbol()
222204
{
223205
QVariant k = currentCategory();
224-
if ( !k.isValid() )
206+
if( !k.isValid() )
225207
return;
226208

227209
int catIdx = mRenderer->categoryIndexForValue( k );
228210
QgsSymbolV2* newSymbol = mRenderer->categories()[catIdx].symbol()->clone();
229211

230212
QgsSymbolV2SelectorDialog dlg( newSymbol, mStyle, this );
231-
if ( !dlg.exec() )
213+
if( !dlg.exec() )
232214
{
233215
delete newSymbol;
234216
return;
@@ -246,7 +228,7 @@ static void _createCategories( QgsCategoryList& cats, QList<QVariant>& values, Q
246228

247229
int num = values.count();
248230

249-
for ( int i = 0; i < num; i++ )
231+
for( int i = 0; i < num; i++ )
250232
{
251233
QVariant value = values[i];
252234
double x = i / ( double ) num;
@@ -269,16 +251,11 @@ void QgsCategorizedSymbolRendererV2Widget::addCategories()
269251
//if (!dlg.exec())
270252
// return;
271253

272-
QgsVectorColorRampV2* ramp = NULL;
273-
QString rampName = cboCategorizedColorRamp->currentText();
274-
if ( rampName == "[source]" )
275-
ramp = mRenderer->sourceColorRamp()->clone();
276-
else
277-
ramp = mStyle->colorRamp( rampName );
254+
QgsVectorColorRampV2* ramp = cboCategorizedColorRamp->currentColorRamp();
278255

279-
if ( ramp == NULL )
256+
if( ramp == NULL )
280257
{
281-
if ( cboCategorizedColorRamp->count() == 0 )
258+
if( cboCategorizedColorRamp->count() == 0 )
282259
QMessageBox::critical( this, tr( "Error" ), tr( "There are no available color ramps. You can add them in Style Manager." ) );
283260
else
284261
QMessageBox::critical( this, tr( "Error" ), tr( "The selected color ramp is not available." ) );
@@ -288,34 +265,34 @@ void QgsCategorizedSymbolRendererV2Widget::addCategories()
288265
QgsCategoryList cats;
289266
_createCategories( cats, unique_vals, mCategorizedSymbol, ramp );
290267

291-
if ( !mOldClassificationAttribute.isEmpty() &&
292-
attrName != mOldClassificationAttribute &&
293-
mRenderer->categories().count() > 0 )
268+
if( !mOldClassificationAttribute.isEmpty() &&
269+
attrName != mOldClassificationAttribute &&
270+
mRenderer->categories().count() > 0 )
294271
{
295272
int res = QMessageBox::question( this,
296273
tr( "Confirm Delete" ),
297274
tr( "The classification field was changed from '%1' to '%2'.\n"
298275
"Should the existing classes be deleted before classification?" )
299276
.arg( mOldClassificationAttribute ).arg( attrName ),
300277
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel );
301-
if ( res == QMessageBox::Cancel )
278+
if( res == QMessageBox::Cancel )
302279
return;
303280

304281
bool deleteExisting = ( res == QMessageBox::Yes );
305-
if ( !deleteExisting )
282+
if( !deleteExisting )
306283
{
307284
QgsCategoryList prevCats = mRenderer->categories();
308-
for ( int i = 0; i < cats.size(); ++i )
285+
for( int i = 0; i < cats.size(); ++i )
309286
{
310287
bool contains = false;
311288
QVariant value = cats.at( i ).value();
312-
for ( int j = 0; j < prevCats.size() && !contains; ++j )
289+
for( int j = 0; j < prevCats.size() && !contains; ++j )
313290
{
314-
if ( prevCats.at( j ).value() == value )
291+
if( prevCats.at( j ).value() == value )
315292
contains = true;
316293
}
317294

318-
if ( !contains )
295+
if( !contains )
319296
prevCats.append( cats.at( i ) );
320297
}
321298
cats = prevCats;
@@ -351,15 +328,15 @@ void QgsCategorizedSymbolRendererV2Widget::addCategories()
351328
int QgsCategorizedSymbolRendererV2Widget::currentCategoryRow()
352329
{
353330
QModelIndex idx = viewCategories->selectionModel()->currentIndex();
354-
if ( !idx.isValid() )
331+
if( !idx.isValid() )
355332
return -1;
356333
return idx.row();
357334
}
358335

359336
QVariant QgsCategorizedSymbolRendererV2Widget::currentCategory()
360337
{
361338
int row = currentCategoryRow();
362-
if ( row == -1 )
339+
if( row == -1 )
363340
return QVariant();
364341
QStandardItemModel* m = qobject_cast<QStandardItemModel*>( viewCategories->model() );
365342
return m->item( row, 1 )->data();
@@ -368,11 +345,11 @@ QVariant QgsCategorizedSymbolRendererV2Widget::currentCategory()
368345
void QgsCategorizedSymbolRendererV2Widget::deleteCategory()
369346
{
370347
QVariant k = currentCategory();
371-
if ( !k.isValid() )
348+
if( !k.isValid() )
372349
return;
373350

374351
int idx = mRenderer->categoryIndexForValue( k );
375-
if ( idx < 0 )
352+
if( idx < 0 )
376353
return;
377354

378355
mRenderer->deleteCategory( idx );
@@ -390,19 +367,19 @@ void QgsCategorizedSymbolRendererV2Widget::changeCurrentValue( QStandardItem * i
390367
{
391368
int idx = item->row();
392369
QString newtext = item->text();
393-
if ( item->column() == 1 )
370+
if( item->column() == 1 )
394371
{
395372
QVariant value = newtext;
396373
// try to preserve variant type for this value
397374
QVariant::Type t = item->data().type();
398-
if ( t == QVariant::Int )
375+
if( t == QVariant::Int )
399376
value = newtext.toInt();
400-
else if ( t == QVariant::Double )
377+
else if( t == QVariant::Double )
401378
value = newtext.toDouble();
402379
mRenderer->updateCategoryValue( idx, value );
403380
item->setData( value );
404381
}
405-
else if ( item->column() == 2 )
382+
else if( item->column() == 2 )
406383
{
407384
mRenderer->updateCategoryLabel( idx, newtext );
408385
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#include "qgscolorrampcombobox.h"
2+
3+
#include "qgssymbollayerv2utils.h"
4+
#include "qgsvectorcolorrampv2.h"
5+
#include "qgsstylev2.h"
6+
#include "qgsstylev2managerdialog.h"
7+
8+
QSize QgsColorRampComboBox::rampIconSize( 50, 16 );
9+
10+
QgsColorRampComboBox::QgsColorRampComboBox( QWidget *parent ) :
11+
QComboBox( parent ), mStyle( NULL ), mSourceColorRamp( NULL )
12+
{
13+
}
14+
15+
QgsColorRampComboBox::~QgsColorRampComboBox()
16+
{
17+
delete mSourceColorRamp;
18+
}
19+
20+
void QgsColorRampComboBox::populate( QgsStyleV2* style )
21+
{
22+
if( count() != 0 )
23+
return; // already populated!
24+
25+
mStyle = style;
26+
27+
setIconSize( rampIconSize );
28+
29+
QStringList rampNames = mStyle->colorRampNames();
30+
for( QStringList::iterator it = rampNames.begin(); it != rampNames.end(); ++it )
31+
{
32+
QgsVectorColorRampV2* ramp = style->colorRamp( *it );
33+
QIcon icon = QgsSymbolLayerV2Utils::colorRampPreviewIcon( ramp, rampIconSize );
34+
35+
addItem( icon, *it );
36+
37+
delete ramp;
38+
}
39+
40+
addItem( tr( "New color ramp..." ) );
41+
connect( this, SIGNAL( currentIndexChanged( int ) ), SLOT( colorRampChanged( int ) ) );
42+
}
43+
44+
QgsVectorColorRampV2* QgsColorRampComboBox::currentColorRamp()
45+
{
46+
QString rampName = currentText();
47+
if( rampName == "[source]" && mSourceColorRamp )
48+
return mSourceColorRamp->clone();
49+
else
50+
return mStyle->colorRamp( rampName );
51+
}
52+
53+
void QgsColorRampComboBox::setSourceColorRamp( QgsVectorColorRampV2* sourceRamp )
54+
{
55+
mSourceColorRamp = sourceRamp->clone();
56+
57+
QIcon icon = QgsSymbolLayerV2Utils::colorRampPreviewIcon( mSourceColorRamp, rampIconSize );
58+
if( itemText( 0 ) == "[source]" )
59+
setItemIcon( 0, icon );
60+
else
61+
insertItem( 0, icon, "[source]" );
62+
setCurrentIndex( 0 );
63+
}
64+
65+
void QgsColorRampComboBox::colorRampChanged( int index )
66+
{
67+
if( index != count() - 1 )
68+
return;
69+
70+
// last item: "new color ramp..."
71+
QString rampName = QgsStyleV2ManagerDialog::addColorRampStatic( this, mStyle );
72+
if( rampName.isEmpty() )
73+
return;
74+
75+
// put newly added ramp into the combo
76+
QgsVectorColorRampV2* ramp = mStyle->colorRamp( rampName );
77+
QIcon icon = QgsSymbolLayerV2Utils::colorRampPreviewIcon( ramp, rampIconSize );
78+
79+
blockSignals( true ); // avoid calling this method again!
80+
insertItem( index, icon, rampName );
81+
blockSignals( false );
82+
83+
delete ramp;
84+
85+
// ... and set it as active
86+
setCurrentIndex( index );
87+
88+
// make sure the color ramp is stored
89+
mStyle->save();
90+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#ifndef QGSCOLORRAMPCOMBOBOX_H
2+
#define QGSCOLORRAMPCOMBOBOX_H
3+
4+
#include <QComboBox>
5+
6+
class QgsStyleV2;
7+
class QgsVectorColorRampV2;
8+
9+
class QgsColorRampComboBox : public QComboBox
10+
{
11+
Q_OBJECT
12+
public:
13+
explicit QgsColorRampComboBox( QWidget *parent = 0 );
14+
15+
~QgsColorRampComboBox();
16+
17+
//! initialize the combo box with color ramps from the style
18+
void populate( QgsStyleV2* style );
19+
20+
//! add/select color ramp which was used previously by the renderer
21+
void setSourceColorRamp( QgsVectorColorRampV2* sourceRamp );
22+
23+
//! return new instance of the current color ramp or NULL if there is no active color ramp
24+
QgsVectorColorRampV2* currentColorRamp();
25+
26+
static QSize rampIconSize;
27+
28+
signals:
29+
30+
public slots:
31+
32+
void colorRampChanged( int index );
33+
34+
protected:
35+
QgsStyleV2* mStyle;
36+
QgsVectorColorRampV2* mSourceColorRamp; // owns the copy
37+
};
38+
39+
#endif // QGSCOLORRAMPCOMBOBOX_H

‎src/gui/symbology-ng/qgsgraduatedsymbolrendererv2widget.cpp

Lines changed: 28 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ QgsRendererV2Widget* QgsGraduatedSymbolRendererV2Widget::create( QgsVectorLayer*
2525
}
2626

2727
QgsGraduatedSymbolRendererV2Widget::QgsGraduatedSymbolRendererV2Widget( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer )
28-
: QgsRendererV2Widget( layer, style )
28+
: QgsRendererV2Widget( layer, style )
2929
{
3030

3131
// try to recognize the previous renderer
3232
// (null renderer means "no previous renderer")
33-
if ( !renderer || renderer->type() != "graduatedSymbol" )
33+
if( !renderer || renderer->type() != "graduatedSymbol" )
3434
{
3535
// we're not going to use it - so let's delete the renderer
3636
delete renderer;
@@ -46,7 +46,9 @@ QgsGraduatedSymbolRendererV2Widget::QgsGraduatedSymbolRendererV2Widget( QgsVecto
4646
setupUi( this );
4747

4848
populateColumns();
49-
populateColorRamps();
49+
50+
cboGraduatedColorRamp->populate( mStyle );
51+
5052
QStandardItemModel* mg = new QStandardItemModel( this );
5153
QStringList labels;
5254
labels << tr( "Range" ) << tr( "Label" );
@@ -96,9 +98,9 @@ void QgsGraduatedSymbolRendererV2Widget::updateUiFromRenderer()
9698
populateRanges();
9799

98100
// update UI from the graduated renderer (update combo boxes, view)
99-
if ( mRenderer->mode() < cboGraduatedMode->count() )
101+
if( mRenderer->mode() < cboGraduatedMode->count() )
100102
cboGraduatedMode->setCurrentIndex( mRenderer->mode() );
101-
if ( mRenderer->ranges().count() )
103+
if( mRenderer->ranges().count() )
102104
spinGraduatedClasses->setValue( mRenderer->ranges().count() );
103105

104106
// set column
@@ -109,23 +111,17 @@ void QgsGraduatedSymbolRendererV2Widget::updateUiFromRenderer()
109111
connect( cboGraduatedColumn, SIGNAL( currentIndexChanged( int ) ), this, SLOT( graduatedColumnChanged() ) );
110112

111113
// set source symbol
112-
if ( mRenderer->sourceSymbol() )
114+
if( mRenderer->sourceSymbol() )
113115
{
114116
delete mGraduatedSymbol;
115117
mGraduatedSymbol = mRenderer->sourceSymbol()->clone();
116118
updateGraduatedSymbolIcon();
117119
}
118120

119121
// set source color ramp
120-
if ( mRenderer->sourceColorRamp() )
122+
if( mRenderer->sourceColorRamp() )
121123
{
122-
QSize rampIconSize( 50, 16 );
123-
QIcon icon = QgsSymbolLayerV2Utils::colorRampPreviewIcon( mRenderer->sourceColorRamp(), rampIconSize );
124-
if ( cboGraduatedColorRamp->itemText( 0 ) == "[source]" )
125-
cboGraduatedColorRamp->setItemIcon( 0, icon );
126-
else
127-
cboGraduatedColorRamp->insertItem( 0, icon, "[source]" );
128-
cboGraduatedColorRamp->setCurrentIndex( 0 );
124+
cboGraduatedColorRamp->setSourceColorRamp( mRenderer->sourceColorRamp() );
129125
}
130126

131127
}
@@ -137,9 +133,9 @@ void QgsGraduatedSymbolRendererV2Widget::populateColumns()
137133
cboGraduatedColumn->clear();
138134
const QgsFieldMap& flds = mLayer->pendingFields();
139135
QgsFieldMap::ConstIterator it = flds.begin();
140-
for ( ; it != flds.end(); ++it )
136+
for( ; it != flds.end(); ++it )
141137
{
142-
if ( it->type() == QVariant::Double || it->type() == QVariant::Int )
138+
if( it->type() == QVariant::Double || it->type() == QVariant::Int )
143139
cboGraduatedColumn->addItem( it->name() );
144140
}
145141
}
@@ -150,53 +146,31 @@ void QgsGraduatedSymbolRendererV2Widget::graduatedColumnChanged()
150146
}
151147

152148

153-
void QgsGraduatedSymbolRendererV2Widget::populateColorRamps()
154-
{
155-
QSize rampIconSize( 50, 16 );
156-
cboGraduatedColorRamp->setIconSize( rampIconSize );
157-
158-
QStringList rampNames = mStyle->colorRampNames();
159-
for ( QStringList::iterator it = rampNames.begin(); it != rampNames.end(); ++it )
160-
{
161-
QgsVectorColorRampV2* ramp = mStyle->colorRamp( *it );
162-
QIcon icon = QgsSymbolLayerV2Utils::colorRampPreviewIcon( ramp, rampIconSize );
163-
cboGraduatedColorRamp->addItem( icon, *it );
164-
delete ramp;
165-
}
166-
}
167-
168-
169-
170149
void QgsGraduatedSymbolRendererV2Widget::classifyGraduated()
171150
{
172151
QString attrName = cboGraduatedColumn->currentText();
173152

174153
int classes = spinGraduatedClasses->value();
175154

176-
QgsVectorColorRampV2* ramp = NULL;
177-
QString rampName = cboGraduatedColorRamp->currentText();
178-
if ( rampName == "[source]" )
179-
ramp = mRenderer->sourceColorRamp()->clone();
180-
else
181-
ramp = mStyle->colorRamp( rampName );
155+
QgsVectorColorRampV2* ramp = cboGraduatedColorRamp->currentColorRamp();
182156

183-
if ( ramp == NULL )
157+
if( ramp == NULL )
184158
{
185-
if ( cboGraduatedColorRamp->count() == 0 )
159+
if( cboGraduatedColorRamp->count() == 0 )
186160
QMessageBox::critical( this, tr( "Error" ), tr( "There are no available color ramps. You can add them in Style Manager." ) );
187161
else
188162
QMessageBox::critical( this, tr( "Error" ), tr( "The selected color ramp is not available." ) );
189163
return;
190164
}
191165

192166
QgsGraduatedSymbolRendererV2::Mode mode;
193-
if ( cboGraduatedMode->currentIndex() == 0 )
167+
if( cboGraduatedMode->currentIndex() == 0 )
194168
mode = QgsGraduatedSymbolRendererV2::EqualInterval;
195-
else if ( cboGraduatedMode->currentIndex() == 2 )
169+
else if( cboGraduatedMode->currentIndex() == 2 )
196170
mode = QgsGraduatedSymbolRendererV2::Jenks;
197-
else if ( cboGraduatedMode->currentIndex() == 3 )
171+
else if( cboGraduatedMode->currentIndex() == 3 )
198172
mode = QgsGraduatedSymbolRendererV2::StdDev;
199-
else if ( cboGraduatedMode->currentIndex() == 4 )
173+
else if( cboGraduatedMode->currentIndex() == 4 )
200174
mode = QgsGraduatedSymbolRendererV2::Pretty;
201175
else // default should be quantile for now
202176
mode = QgsGraduatedSymbolRendererV2::Quantile;
@@ -212,7 +186,7 @@ void QgsGraduatedSymbolRendererV2Widget::classifyGraduated()
212186
void QgsGraduatedSymbolRendererV2Widget::changeGraduatedSymbol()
213187
{
214188
QgsSymbolV2SelectorDialog dlg( mGraduatedSymbol, mStyle, this );
215-
if ( !dlg.exec() )
189+
if( !dlg.exec() )
216190
return;
217191

218192
updateGraduatedSymbolIcon();
@@ -240,7 +214,7 @@ void QgsGraduatedSymbolRendererV2Widget::populateRanges()
240214

241215
int i, count = mRenderer->ranges().count();
242216

243-
for ( i = 0; i < count; i++ )
217+
for( i = 0; i < count; i++ )
244218
{
245219
const QgsRendererRangeV2& range = mRenderer->ranges()[i];
246220
QString rangeStr = QString::number( range.lowerValue(), 'f', 4 ) + " - " + QString::number( range.upperValue(), 'f', 4 );
@@ -268,23 +242,23 @@ void QgsGraduatedSymbolRendererV2Widget::populateRanges()
268242
int QgsRendererV2PropertiesDialog::currentRangeRow()
269243
{
270244
QModelIndex idx = viewGraduated->selectionModel()->currentIndex();
271-
if ( !idx.isValid() )
245+
if( !idx.isValid() )
272246
return -1;
273247
return idx.row();
274248
}
275249
#endif
276250

277251
void QgsGraduatedSymbolRendererV2Widget::rangesDoubleClicked( const QModelIndex & idx )
278252
{
279-
if ( idx.isValid() && idx.column() == 0 )
253+
if( idx.isValid() && idx.column() == 0 )
280254
changeRangeSymbol( idx.row() );
281-
if ( idx.isValid() && idx.column() == 1 )
255+
if( idx.isValid() && idx.column() == 1 )
282256
changeRange( idx.row() );
283257
}
284258

285259
void QgsGraduatedSymbolRendererV2Widget::rangesClicked( const QModelIndex & idx )
286260
{
287-
if ( !idx.isValid() )
261+
if( !idx.isValid() )
288262
mRowSelected = -1;
289263
else
290264
mRowSelected = idx.row();
@@ -295,7 +269,7 @@ void QgsGraduatedSymbolRendererV2Widget::changeRangeSymbol( int rangeIdx )
295269
QgsSymbolV2* newSymbol = mRenderer->ranges()[rangeIdx].symbol()->clone();
296270

297271
QgsSymbolV2SelectorDialog dlg( newSymbol, mStyle, this );
298-
if ( !dlg.exec() )
272+
if( !dlg.exec() )
299273
{
300274
delete newSymbol;
301275
return;
@@ -314,7 +288,7 @@ void QgsGraduatedSymbolRendererV2Widget::changeRange( int rangeIdx )
314288
dialog.setLowerValue( QString( "%1" ).arg( range.lowerValue() ) );
315289
dialog.setUpperValue( QString( "%1" ).arg( range.upperValue() ) );
316290

317-
if ( dialog.exec() == QDialog::Accepted )
291+
if( dialog.exec() == QDialog::Accepted )
318292
{
319293
double lowerValue = dialog.lowerValue().toDouble();
320294
double upperValue = dialog.upperValue().toDouble();
@@ -341,7 +315,7 @@ void QgsGraduatedSymbolRendererV2Widget::deleteCurrentClass()
341315

342316
void QgsGraduatedSymbolRendererV2Widget::changeCurrentValue( QStandardItem * item )
343317
{
344-
if ( item->column() == 2 )
318+
if( item->column() == 2 )
345319
{
346320
QString label = item->text();
347321
int idx = item->row();

‎src/gui/symbology-ng/qgsstylev2managerdialog.cpp

Lines changed: 66 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222

2323
QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* parent )
24-
: QDialog( parent ), mStyle( style ), mModified( false )
24+
: QDialog( parent ), mStyle( style ), mModified( false )
2525
{
2626

2727
setupUi( this );
@@ -52,7 +52,7 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
5252

5353
void QgsStyleV2ManagerDialog::onFinished()
5454
{
55-
if ( mModified )
55+
if( mModified )
5656
{
5757
mStyle->save();
5858
}
@@ -66,9 +66,9 @@ void QgsStyleV2ManagerDialog::populateTypes()
6666
int markerCount = 0, lineCount = 0, fillCount = 0;
6767

6868
QStringList symbolNames = mStyle->symbolNames();
69-
for ( int i = 0; i < symbolNames.count(); ++i )
69+
for( int i = 0; i < symbolNames.count(); ++i )
7070
{
71-
switch ( mStyle->symbolRef( symbolNames[i] )->type() )
71+
switch( mStyle->symbolRef( symbolNames[i] )->type() )
7272
{
7373
case QgsSymbolV2::Marker: markerCount++; break;
7474
case QgsSymbolV2::Line: lineCount++; break;
@@ -94,11 +94,11 @@ void QgsStyleV2ManagerDialog::populateList()
9494
// get current symbol type
9595
int itemType = currentItemType();
9696

97-
if ( itemType < 3 )
97+
if( itemType < 3 )
9898
{
9999
populateSymbols( itemType );
100100
}
101-
else if ( itemType == 3 )
101+
else if( itemType == 3 )
102102
{
103103
populateColorRamps();
104104
}
@@ -115,11 +115,11 @@ void QgsStyleV2ManagerDialog::populateSymbols( int type )
115115

116116
QStringList symbolNames = mStyle->symbolNames();
117117

118-
for ( int i = 0; i < symbolNames.count(); ++i )
118+
for( int i = 0; i < symbolNames.count(); ++i )
119119
{
120120
QString name = symbolNames[i];
121121
QgsSymbolV2* symbol = mStyle->symbol( name );
122-
if ( symbol->type() == type )
122+
if( symbol->type() == type )
123123
{
124124
QStandardItem* item = new QStandardItem( name );
125125
QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon( symbol, listItems->iconSize() );
@@ -139,7 +139,7 @@ void QgsStyleV2ManagerDialog::populateColorRamps()
139139

140140
QStringList colorRamps = mStyle->colorRampNames();
141141

142-
for ( int i = 0; i < colorRamps.count(); ++i )
142+
for( int i = 0; i < colorRamps.count(); ++i )
143143
{
144144
QString name = colorRamps[i];
145145
QgsVectorColorRampV2* ramp = mStyle->colorRamp( name );
@@ -161,18 +161,18 @@ int QgsStyleV2ManagerDialog::currentItemType()
161161
QString QgsStyleV2ManagerDialog::currentItemName()
162162
{
163163
QModelIndex index = listItems->selectionModel()->currentIndex();
164-
if ( !index.isValid() )
164+
if( !index.isValid() )
165165
return QString();
166166
return index.model()->data( index, 0 ).toString();
167167
}
168168

169169
void QgsStyleV2ManagerDialog::addItem()
170170
{
171-
if ( currentItemType() < 3 )
171+
if( currentItemType() < 3 )
172172
{
173173
addSymbol();
174174
}
175-
else if ( currentItemType() == 3 )
175+
else if( currentItemType() == 3 )
176176
{
177177
addColorRamp();
178178
}
@@ -189,7 +189,7 @@ bool QgsStyleV2ManagerDialog::addSymbol()
189189
{
190190
// create new symbol with current type
191191
QgsSymbolV2* symbol;
192-
switch ( currentItemType() )
192+
switch( currentItemType() )
193193
{
194194
case QgsSymbolV2::Marker: symbol = new QgsMarkerSymbolV2(); break;
195195
case QgsSymbolV2::Line: symbol = new QgsLineSymbolV2(); break;
@@ -199,7 +199,7 @@ bool QgsStyleV2ManagerDialog::addSymbol()
199199

200200
// get symbol design
201201
QgsSymbolV2PropertiesDialog dlg( symbol, this );
202-
if ( dlg.exec() == 0 )
202+
if( dlg.exec() == 0 )
203203
{
204204
delete symbol;
205205
return false;
@@ -209,7 +209,7 @@ bool QgsStyleV2ManagerDialog::addSymbol()
209209
bool ok;
210210
QString name = QInputDialog::getText( this, tr( "Symbol name" ),
211211
tr( "Please enter name for new symbol:" ), QLineEdit::Normal, tr( "new symbol" ), &ok );
212-
if ( !ok || name.isEmpty() )
212+
if( !ok || name.isEmpty() )
213213
{
214214
delete symbol;
215215
return false;
@@ -221,48 +221,49 @@ bool QgsStyleV2ManagerDialog::addSymbol()
221221
return true;
222222
}
223223

224-
bool QgsStyleV2ManagerDialog::addColorRamp()
224+
225+
QString QgsStyleV2ManagerDialog::addColorRampStatic( QWidget* parent, QgsStyleV2* style )
225226
{
226227
// let the user choose the color ramp type
227228
QStringList rampTypes;
228229
rampTypes << tr( "Gradient" ) << tr( "Random" ) << tr( "ColorBrewer" );
229230
bool ok;
230-
QString rampType = QInputDialog::getItem( this, tr( "Color ramp type" ),
231+
QString rampType = QInputDialog::getItem( parent, tr( "Color ramp type" ),
231232
tr( "Please select color ramp type:" ), rampTypes, 0, false, &ok );
232-
if ( !ok || rampType.isEmpty() )
233-
return false;
233+
if( !ok || rampType.isEmpty() )
234+
return QString();
234235

235236
QgsVectorColorRampV2 *ramp = NULL;
236-
if ( rampType == tr( "Gradient" ) )
237+
if( rampType == tr( "Gradient" ) )
237238
{
238239
QgsVectorGradientColorRampV2* gradRamp = new QgsVectorGradientColorRampV2();
239-
QgsVectorGradientColorRampV2Dialog dlg( gradRamp, this );
240-
if ( !dlg.exec() )
240+
QgsVectorGradientColorRampV2Dialog dlg( gradRamp, parent );
241+
if( !dlg.exec() )
241242
{
242243
delete gradRamp;
243-
return false;
244+
return QString();
244245
}
245246
ramp = gradRamp;
246247
}
247-
else if ( rampType == tr( "Random" ) )
248+
else if( rampType == tr( "Random" ) )
248249
{
249250
QgsVectorRandomColorRampV2* randRamp = new QgsVectorRandomColorRampV2();
250-
QgsVectorRandomColorRampV2Dialog dlg( randRamp, this );
251-
if ( !dlg.exec() )
251+
QgsVectorRandomColorRampV2Dialog dlg( randRamp, parent );
252+
if( !dlg.exec() )
252253
{
253254
delete randRamp;
254-
return false;
255+
return QString();
255256
}
256257
ramp = randRamp;
257258
}
258-
else if ( rampType == tr( "ColorBrewer" ) )
259+
else if( rampType == tr( "ColorBrewer" ) )
259260
{
260261
QgsVectorColorBrewerColorRampV2* brewerRamp = new QgsVectorColorBrewerColorRampV2();
261-
QgsVectorColorBrewerColorRampV2Dialog dlg( brewerRamp, this );
262-
if ( !dlg.exec() )
262+
QgsVectorColorBrewerColorRampV2Dialog dlg( brewerRamp, parent );
263+
if( !dlg.exec() )
263264
{
264265
delete brewerRamp;
265-
return false;
266+
return QString();
266267
}
267268
ramp = brewerRamp;
268269
}
@@ -272,29 +273,41 @@ bool QgsStyleV2ManagerDialog::addColorRamp()
272273
}
273274

274275
// get name
275-
QString name = QInputDialog::getText( this, tr( "Color ramp name" ),
276+
QString name = QInputDialog::getText( parent, tr( "Color ramp name" ),
276277
tr( "Please enter name for new color ramp:" ), QLineEdit::Normal, tr( "new color ramp" ), &ok );
277-
if ( !ok || name.isEmpty() )
278+
if( !ok || name.isEmpty() )
278279
{
279-
if ( ramp )
280+
if( ramp )
280281
delete ramp;
281-
return false;
282+
return QString();
282283
}
283284

284285
// add new symbol to style and re-populate the list
285-
mStyle->addColorRamp( name, ramp );
286-
mModified = true;
287-
return true;
286+
style->addColorRamp( name, ramp );
287+
return name;
288+
}
289+
290+
291+
bool QgsStyleV2ManagerDialog::addColorRamp()
292+
{
293+
QString rampName = addColorRampStatic( this , mStyle );
294+
if( !rampName.isEmpty() )
295+
{
296+
mModified = true;
297+
return true;
298+
}
299+
300+
return false;
288301
}
289302

290303

291304
void QgsStyleV2ManagerDialog::editItem()
292305
{
293-
if ( currentItemType() < 3 )
306+
if( currentItemType() < 3 )
294307
{
295308
editSymbol();
296309
}
297-
else if ( currentItemType() == 3 )
310+
else if( currentItemType() == 3 )
298311
{
299312
editColorRamp();
300313
}
@@ -309,14 +322,14 @@ void QgsStyleV2ManagerDialog::editItem()
309322
bool QgsStyleV2ManagerDialog::editSymbol()
310323
{
311324
QString symbolName = currentItemName();
312-
if ( symbolName.isEmpty() )
325+
if( symbolName.isEmpty() )
313326
return false;
314327

315328
QgsSymbolV2* symbol = mStyle->symbol( symbolName );
316329

317330
// let the user edit the symbol and update list when done
318331
QgsSymbolV2PropertiesDialog dlg( symbol, this );
319-
if ( dlg.exec() == 0 )
332+
if( dlg.exec() == 0 )
320333
{
321334
delete symbol;
322335
return false;
@@ -331,36 +344,36 @@ bool QgsStyleV2ManagerDialog::editSymbol()
331344
bool QgsStyleV2ManagerDialog::editColorRamp()
332345
{
333346
QString name = currentItemName();
334-
if ( name.isEmpty() )
347+
if( name.isEmpty() )
335348
return false;
336349

337350
QgsVectorColorRampV2* ramp = mStyle->colorRamp( name );
338351

339-
if ( ramp->type() == "gradient" )
352+
if( ramp->type() == "gradient" )
340353
{
341354
QgsVectorGradientColorRampV2* gradRamp = static_cast<QgsVectorGradientColorRampV2*>( ramp );
342355
QgsVectorGradientColorRampV2Dialog dlg( gradRamp, this );
343-
if ( !dlg.exec() )
356+
if( !dlg.exec() )
344357
{
345358
delete ramp;
346359
return false;
347360
}
348361
}
349-
else if ( ramp->type() == "random" )
362+
else if( ramp->type() == "random" )
350363
{
351364
QgsVectorRandomColorRampV2* randRamp = static_cast<QgsVectorRandomColorRampV2*>( ramp );
352365
QgsVectorRandomColorRampV2Dialog dlg( randRamp, this );
353-
if ( !dlg.exec() )
366+
if( !dlg.exec() )
354367
{
355368
delete ramp;
356369
return false;
357370
}
358371
}
359-
else if ( ramp->type() == "colorbrewer" )
372+
else if( ramp->type() == "colorbrewer" )
360373
{
361374
QgsVectorColorBrewerColorRampV2* brewerRamp = static_cast<QgsVectorColorBrewerColorRampV2*>( ramp );
362375
QgsVectorColorBrewerColorRampV2Dialog dlg( brewerRamp, this );
363-
if ( !dlg.exec() )
376+
if( !dlg.exec() )
364377
{
365378
delete ramp;
366379
return false;
@@ -379,11 +392,11 @@ bool QgsStyleV2ManagerDialog::editColorRamp()
379392

380393
void QgsStyleV2ManagerDialog::removeItem()
381394
{
382-
if ( currentItemType() < 3 )
395+
if( currentItemType() < 3 )
383396
{
384397
removeSymbol();
385398
}
386-
else if ( currentItemType() == 3 )
399+
else if( currentItemType() == 3 )
387400
{
388401
removeColorRamp();
389402
}
@@ -399,7 +412,7 @@ void QgsStyleV2ManagerDialog::removeItem()
399412
bool QgsStyleV2ManagerDialog::removeSymbol()
400413
{
401414
QString symbolName = currentItemName();
402-
if ( symbolName.isEmpty() )
415+
if( symbolName.isEmpty() )
403416
return false;
404417

405418
// delete from style and update list
@@ -411,7 +424,7 @@ bool QgsStyleV2ManagerDialog::removeSymbol()
411424
bool QgsStyleV2ManagerDialog::removeColorRamp()
412425
{
413426
QString rampName = currentItemName();
414-
if ( rampName.isEmpty() )
427+
if( rampName.isEmpty() )
415428
return false;
416429

417430
mStyle->removeColorRamp( rampName );

‎src/gui/symbology-ng/qgsstylev2managerdialog.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ class GUI_EXPORT QgsStyleV2ManagerDialog : public QDialog, private Ui::QgsStyleV
1616
public:
1717
QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* parent = NULL );
1818

19+
//! open add color ramp dialog, return color ramp's name if the ramp has been added
20+
static QString addColorRampStatic( QWidget* parent, QgsStyleV2* style );
21+
1922
public slots:
2023
void addItem();
2124
void editItem();

‎src/ui/qgscategorizedsymbolrendererv2widget.ui

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
</widget>
7979
</item>
8080
<item>
81-
<widget class="QComboBox" name="cboCategorizedColorRamp">
81+
<widget class="QgsColorRampComboBox" name="cboCategorizedColorRamp">
8282
<property name="sizePolicy">
8383
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
8484
<horstretch>1</horstretch>
@@ -169,6 +169,13 @@
169169
</item>
170170
</layout>
171171
</widget>
172+
<customwidgets>
173+
<customwidget>
174+
<class>QgsColorRampComboBox</class>
175+
<extends>QComboBox</extends>
176+
<header>qgscolorrampcombobox.h</header>
177+
</customwidget>
178+
</customwidgets>
172179
<tabstops>
173180
<tabstop>cboCategorizedColumn</tabstop>
174181
<tabstop>btnChangeCategorizedSymbol</tabstop>

‎src/ui/qgsgraduatedsymbolrendererv2widget.ui

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
</widget>
8787
</item>
8888
<item row="2" column="1">
89-
<widget class="QComboBox" name="cboGraduatedColorRamp"/>
89+
<widget class="QgsColorRampComboBox" name="cboGraduatedColorRamp"/>
9090
</item>
9191
<item row="2" column="3">
9292
<widget class="QLabel" name="label_8">
@@ -199,6 +199,13 @@
199199
</item>
200200
</layout>
201201
</widget>
202+
<customwidgets>
203+
<customwidget>
204+
<class>QgsColorRampComboBox</class>
205+
<extends>QComboBox</extends>
206+
<header>qgscolorrampcombobox.h</header>
207+
</customwidget>
208+
</customwidgets>
202209
<tabstops>
203210
<tabstop>cboGraduatedColumn</tabstop>
204211
<tabstop>btnChangeGraduatedSymbol</tabstop>

0 commit comments

Comments
 (0)
Please sign in to comment.