@@ -63,8 +63,8 @@ QgsGraduatedSymbolDialog::QgsGraduatedSymbolDialog(QgsVectorLayer * layer): QDia
63
63
return ;
64
64
}
65
65
66
- modeComboBox->insertItem (" Empty" );
67
66
modeComboBox->insertItem (" Equal Interval" );
67
+ modeComboBox->insertItem (" Empty" );
68
68
69
69
// restore the correct settings
70
70
const QgsGraduatedSymbolRenderer* renderer = dynamic_cast < const QgsGraduatedSymbolRenderer * >(layer->renderer ());
@@ -97,23 +97,22 @@ QgsGraduatedSymbolDialog::QgsGraduatedSymbolDialog(QgsVectorLayer * layer): QDia
97
97
sym->setNamedPointSymbol ((*it)->pointSymbolName ());
98
98
sym->setPointSize ((*it)->pointSize ());
99
99
mEntries .insert (std::make_pair (classbreak,sym));
100
- mClassBreakBox -> insertItem (classbreak);
100
+ mClassListWidget -> addItem (classbreak);
101
101
}
102
102
103
103
}
104
104
105
105
// do the necessary signal/slot connections
106
- QObject::connect (numberofclassesspinbox, SIGNAL (valueChanged (int )), this , SLOT (adjustClassification ()));
107
- QObject::connect (classificationComboBox, SIGNAL (activated (int )), this , SLOT (adjustClassification ()));
108
- QObject::connect (modeComboBox, SIGNAL (activated (int )), this , SLOT (adjustClassification ()));
109
- QObject::connect (mClassBreakBox , SIGNAL (selectionChanged ()), this , SLOT (changeCurrentValue ()));
106
+ QObject::connect (mClassifyButton , SIGNAL (clicked ()), this , SLOT (adjustClassification ()));
107
+ QObject::connect (mClassListWidget , SIGNAL (currentItemChanged (QListWidgetItem*, QListWidgetItem*)), this , SLOT (changeCurrentValue ()));
110
108
QObject::connect (&sydialog, SIGNAL (settingsChanged ()), this , SLOT (applySymbologyChanges ()));
111
- QObject::connect (mClassBreakBox , SIGNAL (doubleClicked (Q3ListBoxItem*)), this , SLOT (changeClass (Q3ListBoxItem*)));
109
+ QObject::connect (mClassListWidget , SIGNAL (itemDoubleClicked (QListWidgetItem*)), this , SLOT (modifyClass (QListWidgetItem*)));
110
+ QObject::connect (mDeleteClassButton , SIGNAL (clicked ()), this , SLOT (deleteCurrentClass ()));
112
111
113
112
mSymbolWidgetStack ->addWidget (&sydialog);
114
- mSymbolWidgetStack ->raiseWidget (&sydialog);
113
+ mSymbolWidgetStack ->setCurrentWidget (&sydialog);
115
114
116
- mClassBreakBox -> setCurrentItem (0 );
115
+ mClassListWidget -> setCurrentRow (0 );
117
116
}
118
117
119
118
QgsGraduatedSymbolDialog::QgsGraduatedSymbolDialog (): QDialog(), mVectorLayer(0 ), sydialog(0 )
@@ -154,78 +153,78 @@ void QgsGraduatedSymbolDialog::apply()
154
153
155
154
QgsGraduatedSymbolRenderer* renderer = new QgsGraduatedSymbolRenderer (mVectorLayer ->vectorType ());
156
155
157
- for (uint item=0 ;item<mClassBreakBox ->count ();++item)
156
+ for (int item=0 ;item<mClassListWidget ->count ();++item)
158
157
{
159
- QString classbreak=mClassBreakBox -> text (item);
160
- std::map<QString,QgsSymbol*>::iterator it=mEntries .find (classbreak);
161
- if (it==mEntries .end ())
158
+ QString classbreak=mClassListWidget -> item (item)-> text ( );
159
+ std::map<QString,QgsSymbol*>::iterator it=mEntries .find (classbreak);
160
+ if (it==mEntries .end ())
162
161
{
163
- continue ;
162
+ continue ;
164
163
}
165
-
166
- QString lower_bound=it->second ->lowerValue ();
167
- QString upper_bound=it->second ->upperValue ();
168
- QString label=it->second ->label ();
169
-
170
- QgsSymbol* sy = new QgsSymbol (mVectorLayer ->vectorType (), lower_bound, upper_bound, label);
171
-
172
- sy->setColor (it->second ->pen ().color ());
173
- sy->setLineStyle (it->second ->pen ().style ());
174
- sy->setLineWidth (it->second ->pen ().width ());
175
-
176
- if (mVectorLayer ->vectorType () == QGis::Point)
164
+
165
+ QString lower_bound=it->second ->lowerValue ();
166
+ QString upper_bound=it->second ->upperValue ();
167
+ QString label=it->second ->label ();
168
+
169
+ QgsSymbol* sy = new QgsSymbol (mVectorLayer ->vectorType (), lower_bound, upper_bound, label);
170
+
171
+ sy->setColor (it->second ->pen ().color ());
172
+ sy->setLineStyle (it->second ->pen ().style ());
173
+ sy->setLineWidth (it->second ->pen ().width ());
174
+
175
+ if (mVectorLayer ->vectorType () == QGis::Point)
177
176
{
178
- sy->setNamedPointSymbol (it->second ->pointSymbolName ());
179
- sy->setPointSize (it->second ->pointSize ());
180
-
177
+ sy->setNamedPointSymbol (it->second ->pointSymbolName ());
178
+ sy->setPointSize (it->second ->pointSize ());
179
+
181
180
}
182
-
183
- if (mVectorLayer ->vectorType () != QGis::Line)
181
+
182
+ if (mVectorLayer ->vectorType () != QGis::Line)
184
183
{
185
- sy->setFillColor (it->second ->brush ().color ());
186
- sy->setFillStyle (it->second ->brush ().style ());
184
+ sy->setFillColor (it->second ->brush ().color ());
185
+ sy->setFillStyle (it->second ->brush ().style ());
187
186
}
188
-
189
- // test, if lower_bound is numeric or not (making a subclass of QString would be the proper solution)
190
- bool lbcontainsletter = false ;
191
- for (int j = 0 ; j < lower_bound.length (); j++)
187
+
188
+ // test, if lower_bound is numeric or not (making a subclass of QString would be the proper solution)
189
+ bool lbcontainsletter = false ;
190
+ for (int j = 0 ; j < lower_bound.length (); j++)
192
191
{
193
- if (lower_bound.ref (j).isLetter ())
192
+ if (lower_bound.ref (j).isLetter ())
194
193
{
195
- lbcontainsletter = true ;
194
+ lbcontainsletter = true ;
196
195
}
197
196
}
198
-
199
- // test, if upper_bound is numeric or not (making a subclass of QString would be the proper solution)
200
- bool ubcontainsletter = false ;
201
- for (int j = 0 ; j < upper_bound.length (); j++)
197
+
198
+ // test, if upper_bound is numeric or not (making a subclass of QString would be the proper solution)
199
+ bool ubcontainsletter = false ;
200
+ for (int j = 0 ; j < upper_bound.length (); j++)
202
201
{
203
- if (upper_bound.ref (j).isLetter ())
202
+ if (upper_bound.ref (j).isLetter ())
204
203
{
205
- ubcontainsletter = true ;
204
+ ubcontainsletter = true ;
206
205
}
207
206
}
208
- if (lbcontainsletter == false && ubcontainsletter == false && lower_bound.length () > 0 && upper_bound.length () > 0 ) // only add the item if the value bounds do not contain letters and are not null strings
207
+ if (lbcontainsletter == false && ubcontainsletter == false && lower_bound.length () > 0 && upper_bound.length () > 0 ) // only add the item if the value bounds do not contain letters and are not null strings
209
208
{
210
- renderer->addSymbol (sy);
209
+ renderer->addSymbol (sy);
211
210
}
212
- else
211
+ else
213
212
{
214
- delete sy;
213
+ delete sy;
215
214
}
216
215
}
217
216
218
217
std::map<QString,int >::iterator iter=mFieldMap .find (classificationComboBox->currentText ());
219
218
if (iter!=mFieldMap .end ())
220
- {
221
- renderer->setClassificationField (iter->second );
222
- }
219
+ {
220
+ renderer->setClassificationField (iter->second );
221
+ }
223
222
mVectorLayer ->setRenderer (renderer);
224
223
}
225
224
226
225
void QgsGraduatedSymbolDialog::adjustClassification ()
227
226
{
228
- mClassBreakBox ->clear ();
227
+ mClassListWidget ->clear ();
229
228
QGis::VectorType m_type = mVectorLayer ->vectorType ();
230
229
QgsVectorDataProvider *provider = dynamic_cast <QgsVectorDataProvider *>(mVectorLayer ->getDataProvider ());
231
230
double minimum, maximum;
@@ -275,7 +274,7 @@ void QgsGraduatedSymbolDialog::adjustClassification()
275
274
if (modeComboBox->currentText () == " Empty" )
276
275
{
277
276
listboxtext=" Empty" +QString::number (i+1 );
278
- mClassBreakBox -> insertItem (listboxtext);
277
+ mClassListWidget -> addItem (listboxtext);
279
278
}
280
279
else if (modeComboBox->currentText () == " Equal Interval" )
281
280
{
@@ -292,7 +291,7 @@ void QgsGraduatedSymbolDialog::adjustClassification()
292
291
symbol->setLowerValue (QString::number (lower,' f' ,3 ));
293
292
symbol->setUpperValue (QString::number (upper,' f' ,3 ));
294
293
listboxtext=QString::number (lower,' f' ,3 )+" - " +QString::number (upper,' f' ,3 );
295
- mClassBreakBox -> insertItem (listboxtext);
294
+ mClassListWidget -> addItem (listboxtext);
296
295
}
297
296
// set default symbology
298
297
@@ -328,13 +327,13 @@ void QgsGraduatedSymbolDialog::adjustClassification()
328
327
329
328
mEntries .insert (std::make_pair (listboxtext,symbol));
330
329
}
331
- mClassBreakBox -> setCurrentItem (0 );
330
+ mClassListWidget -> setCurrentRow (0 );
332
331
}
333
332
334
333
void QgsGraduatedSymbolDialog::changeCurrentValue ()
335
334
{
336
335
sydialog.blockSignals (true );// block signals to prevent sydialog from changing the current QgsRenderItem
337
- Q3ListBoxItem * item=mClassBreakBox -> selectedItem ();
336
+ QListWidgetItem * item=mClassListWidget -> currentItem ();
338
337
if (item)
339
338
{
340
339
QString value=item->text ();
@@ -350,7 +349,7 @@ void QgsGraduatedSymbolDialog::changeCurrentValue()
350
349
351
350
void QgsGraduatedSymbolDialog::applySymbologyChanges ()
352
351
{
353
- Q3ListBoxItem * item=mClassBreakBox -> selectedItem ();
352
+ QListWidgetItem * item=mClassListWidget -> currentItem ();
354
353
if (item)
355
354
{
356
355
QString value=item->text ();
@@ -363,7 +362,7 @@ void QgsGraduatedSymbolDialog::applySymbologyChanges()
363
362
}
364
363
}
365
364
366
- void QgsGraduatedSymbolDialog::changeClass (Q3ListBoxItem * item)
365
+ void QgsGraduatedSymbolDialog::modifyClass (QListWidgetItem * item)
367
366
{
368
367
QString currenttext=item->text ();
369
368
QgsSymbol* symbol=0 ;
@@ -389,12 +388,34 @@ void QgsGraduatedSymbolDialog::changeClass(Q3ListBoxItem* item)
389
388
symbol->setUpperValue (dialog.upperValue ());
390
389
QString newclass=dialog.lowerValue ()+" -" +dialog.upperValue ();
391
390
mEntries .insert (std::make_pair (newclass,symbol));
392
- int index=mClassBreakBox ->index (item);
393
- QObject::disconnect (mClassBreakBox , SIGNAL (selectionChanged ()), this , SLOT (changeCurrentValue ()));
394
- mClassBreakBox ->removeItem (index);
395
- mClassBreakBox ->insertItem (newclass,index);
396
- mClassBreakBox ->setSelected (index,true );
397
- QObject::connect (mClassBreakBox , SIGNAL (selectionChanged ()), this , SLOT (changeCurrentValue ()));
391
+ item->setText (newclass);
398
392
}
399
393
}
400
394
}
395
+
396
+ void QgsGraduatedSymbolDialog::deleteCurrentClass ()
397
+ {
398
+ QListWidgetItem* currentItem = mClassListWidget ->currentItem ();
399
+ if (!currentItem)
400
+ {
401
+ return ;
402
+ }
403
+
404
+ QString classValue = currentItem->text ();
405
+ int currentIndex = mClassListWidget ->currentRow ();
406
+ mEntries .erase (classValue);
407
+ delete (mClassListWidget ->takeItem (currentIndex));
408
+ qWarning (" numRows: " );
409
+ qWarning (QString::number (mClassListWidget ->count ()));
410
+ //
411
+ if (mClassListWidget ->count () < (currentIndex + 1 ))
412
+ {
413
+ qWarning (" selecting numRows - 1" );
414
+ mClassListWidget ->setCurrentRow (mClassListWidget ->count () - 1 );
415
+ }
416
+ else
417
+ {
418
+ qWarning (" selecting currentIndex" );
419
+ mClassListWidget ->setCurrentRow (currentIndex);
420
+ }
421
+ }
0 commit comments