Skip to content

Commit 008bad8

Browse files
author
mhugent
committedFeb 10, 2007
Added a 'classify' button to the graduated symbology button. Replaced Qt3 compatibility classes with Qt4 ones
git-svn-id: http://svn.osgeo.org/qgis/trunk@6557 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent abda3e8 commit 008bad8

File tree

5 files changed

+164
-196
lines changed

5 files changed

+164
-196
lines changed
 

‎src/app/qgsgraduatedsymboldialog.cpp

Lines changed: 86 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ QgsGraduatedSymbolDialog::QgsGraduatedSymbolDialog(QgsVectorLayer * layer): QDia
6363
return;
6464
}
6565

66-
modeComboBox->insertItem("Empty");
6766
modeComboBox->insertItem("Equal Interval");
67+
modeComboBox->insertItem("Empty");
6868

6969
//restore the correct settings
7070
const QgsGraduatedSymbolRenderer* renderer = dynamic_cast < const QgsGraduatedSymbolRenderer * >(layer->renderer());
@@ -97,23 +97,22 @@ QgsGraduatedSymbolDialog::QgsGraduatedSymbolDialog(QgsVectorLayer * layer): QDia
9797
sym->setNamedPointSymbol((*it)->pointSymbolName());
9898
sym->setPointSize((*it)->pointSize());
9999
mEntries.insert(std::make_pair(classbreak,sym));
100-
mClassBreakBox->insertItem(classbreak);
100+
mClassListWidget->addItem(classbreak);
101101
}
102102

103103
}
104104

105105
//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()));
110108
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()));
112111

113112
mSymbolWidgetStack->addWidget(&sydialog);
114-
mSymbolWidgetStack->raiseWidget(&sydialog);
113+
mSymbolWidgetStack->setCurrentWidget(&sydialog);
115114

116-
mClassBreakBox->setCurrentItem(0);
115+
mClassListWidget->setCurrentRow(0);
117116
}
118117

119118
QgsGraduatedSymbolDialog::QgsGraduatedSymbolDialog(): QDialog(), mVectorLayer(0), sydialog(0)
@@ -154,78 +153,78 @@ void QgsGraduatedSymbolDialog::apply()
154153

155154
QgsGraduatedSymbolRenderer* renderer = new QgsGraduatedSymbolRenderer(mVectorLayer->vectorType());
156155

157-
for (uint item=0;item<mClassBreakBox->count();++item)
156+
for (int item=0;item<mClassListWidget->count();++item)
158157
{
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())
162161
{
163-
continue;
162+
continue;
164163
}
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)
177176
{
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+
181180
}
182-
183-
if (mVectorLayer->vectorType() != QGis::Line)
181+
182+
if (mVectorLayer->vectorType() != QGis::Line)
184183
{
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());
187186
}
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++)
192191
{
193-
if (lower_bound.ref(j).isLetter())
192+
if (lower_bound.ref(j).isLetter())
194193
{
195-
lbcontainsletter = true;
194+
lbcontainsletter = true;
196195
}
197196
}
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++)
202201
{
203-
if (upper_bound.ref(j).isLetter())
202+
if (upper_bound.ref(j).isLetter())
204203
{
205-
ubcontainsletter = true;
204+
ubcontainsletter = true;
206205
}
207206
}
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
209208
{
210-
renderer->addSymbol(sy);
209+
renderer->addSymbol(sy);
211210
}
212-
else
211+
else
213212
{
214-
delete sy;
213+
delete sy;
215214
}
216215
}
217216

218217
std::map<QString,int>::iterator iter=mFieldMap.find(classificationComboBox->currentText());
219218
if(iter!=mFieldMap.end())
220-
{
221-
renderer->setClassificationField(iter->second);
222-
}
219+
{
220+
renderer->setClassificationField(iter->second);
221+
}
223222
mVectorLayer->setRenderer(renderer);
224223
}
225224

226225
void QgsGraduatedSymbolDialog::adjustClassification()
227226
{
228-
mClassBreakBox->clear();
227+
mClassListWidget->clear();
229228
QGis::VectorType m_type = mVectorLayer->vectorType();
230229
QgsVectorDataProvider *provider = dynamic_cast<QgsVectorDataProvider *>(mVectorLayer->getDataProvider());
231230
double minimum, maximum;
@@ -275,7 +274,7 @@ void QgsGraduatedSymbolDialog::adjustClassification()
275274
if (modeComboBox->currentText() == "Empty")
276275
{
277276
listboxtext="Empty"+QString::number(i+1);
278-
mClassBreakBox->insertItem(listboxtext);
277+
mClassListWidget->addItem(listboxtext);
279278
}
280279
else if(modeComboBox->currentText() == "Equal Interval")
281280
{
@@ -292,7 +291,7 @@ void QgsGraduatedSymbolDialog::adjustClassification()
292291
symbol->setLowerValue(QString::number(lower,'f',3));
293292
symbol->setUpperValue(QString::number(upper,'f',3));
294293
listboxtext=QString::number(lower,'f',3)+" - " +QString::number(upper,'f',3);
295-
mClassBreakBox->insertItem(listboxtext);
294+
mClassListWidget->addItem(listboxtext);
296295
}
297296
//set default symbology
298297

@@ -328,13 +327,13 @@ void QgsGraduatedSymbolDialog::adjustClassification()
328327

329328
mEntries.insert(std::make_pair(listboxtext,symbol));
330329
}
331-
mClassBreakBox->setCurrentItem(0);
330+
mClassListWidget->setCurrentRow(0);
332331
}
333332

334333
void QgsGraduatedSymbolDialog::changeCurrentValue()
335334
{
336335
sydialog.blockSignals(true);//block signals to prevent sydialog from changing the current QgsRenderItem
337-
Q3ListBoxItem* item=mClassBreakBox->selectedItem();
336+
QListWidgetItem* item=mClassListWidget->currentItem();
338337
if(item)
339338
{
340339
QString value=item->text();
@@ -350,7 +349,7 @@ void QgsGraduatedSymbolDialog::changeCurrentValue()
350349

351350
void QgsGraduatedSymbolDialog::applySymbologyChanges()
352351
{
353-
Q3ListBoxItem* item=mClassBreakBox->selectedItem();
352+
QListWidgetItem* item=mClassListWidget->currentItem();
354353
if(item)
355354
{
356355
QString value=item->text();
@@ -363,7 +362,7 @@ void QgsGraduatedSymbolDialog::applySymbologyChanges()
363362
}
364363
}
365364

366-
void QgsGraduatedSymbolDialog::changeClass(Q3ListBoxItem* item)
365+
void QgsGraduatedSymbolDialog::modifyClass(QListWidgetItem* item)
367366
{
368367
QString currenttext=item->text();
369368
QgsSymbol* symbol=0;
@@ -389,12 +388,34 @@ void QgsGraduatedSymbolDialog::changeClass(Q3ListBoxItem* item)
389388
symbol->setUpperValue(dialog.upperValue());
390389
QString newclass=dialog.lowerValue()+"-"+dialog.upperValue();
391390
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);
398392
}
399393
}
400394
}
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+
}

‎src/app/qgsgraduatedsymboldialog.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class QgsGraduatedSymbolDialog: public QDialog, private Ui::QgsGraduatedSymbolDi
4646
/**Writes changes in the single symbol dialog to the corresponding QgsRangeRenderItem*/
4747
void applySymbologyChanges();
4848
/**Shows a dialog to modify lower and upper values*/
49-
void changeClass(Q3ListBoxItem* item);
49+
void modifyClass(QListWidgetItem* item);
5050
protected:
5151
/**Pointer to the associated vector layer*/
5252
QgsVectorLayer* mVectorLayer;
@@ -57,6 +57,11 @@ class QgsGraduatedSymbolDialog: public QDialog, private Ui::QgsGraduatedSymbolDi
5757
/**Dialog which shows the settings of the activated class*/
5858
QgsSingleSymbolDialog sydialog;
5959
int mClassificationField;
60+
61+
protected slots:
62+
/**Removes a class from the classification*/
63+
void deleteCurrentClass();
64+
6065
private:
6166
/**Default constructor is privat to not use is*/
6267
QgsGraduatedSymbolDialog();

‎src/app/qgsuniquevaluedialog.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ QgsUniqueValueDialog::QgsUniqueValueDialog(QgsVectorLayer* vl): QDialog(), mVect
5454

5555
if (renderer)
5656
{
57-
mClassBreakBox->clear();
57+
mClassListWidget->clear();
5858

5959
// XXX - mloskot - fix for Ticket #31 (bug)
6060
QgsAttributeList attributes = renderer->classificationAttributes();
@@ -74,18 +74,18 @@ QgsUniqueValueDialog::QgsUniqueValueDialog(QgsVectorLayer* vl): QDialog(), mVect
7474
sym->setNamedPointSymbol(symbol->pointSymbolName());
7575
sym->setPointSize(symbol->pointSize());
7676
mValues.insert(std::make_pair(symbolvalue,sym));
77-
mClassBreakBox->addItem(symbolvalue);
77+
mClassListWidget->addItem(symbolvalue);
7878
}
7979
}
8080

8181
QObject::connect(mClassifyButton, SIGNAL(clicked()), this, SLOT(changeClassificationAttribute()));
8282
QObject::connect(mDeletePushButton, SIGNAL(clicked()), this, SLOT(deleteCurrentClass()));
83-
QObject::connect(mClassBreakBox, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(changeCurrentValue()));
83+
QObject::connect(mClassListWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(changeCurrentValue()));
8484
QObject::connect(&sydialog, SIGNAL(settingsChanged()), this, SLOT(applySymbologyChanges()));
8585
mSymbolWidgetStack->addWidget(&sydialog);
86-
mSymbolWidgetStack->raiseWidget(&sydialog);
86+
mSymbolWidgetStack->setCurrentWidget(&sydialog);
8787

88-
mClassBreakBox->setCurrentItem(0);
88+
mClassListWidget->setCurrentItem(0);
8989
}
9090

9191
QgsUniqueValueDialog::~QgsUniqueValueDialog()
@@ -100,7 +100,7 @@ QgsUniqueValueDialog::~QgsUniqueValueDialog()
100100
myValueIterator = mValues.begin(); // since iterator invalidated due to
101101
// erase(), reset to new first element
102102
}
103-
mClassBreakBox->setCurrentItem(0);
103+
mClassListWidget->setCurrentItem(0);
104104
}
105105

106106
void QgsUniqueValueDialog::apply()
@@ -144,8 +144,8 @@ void QgsUniqueValueDialog::changeClassificationAttribute()
144144
provider->reset();
145145
QgsFeature feat;
146146

147-
//go through all the features and insert their value into the map and into mClassBreakBox
148-
mClassBreakBox->clear();
147+
//go through all the features and insert their value into the map and into mClassListWidget
148+
mClassListWidget->clear();
149149
while(provider->getNextFeature(feat, false, attlist))
150150
{
151151
const QgsAttributeMap& vec = feat.attributeMap();
@@ -168,7 +168,7 @@ void QgsUniqueValueDialog::changeClassificationAttribute()
168168
int green = 1 + (int) (255.0 * rand() / (RAND_MAX + 1.0));
169169
int blue = 1 + (int) (255.0 * rand() / (RAND_MAX + 1.0));
170170
thecolor.setRgb(red, green, blue);
171-
mClassBreakBox->addItem(it->first);
171+
mClassListWidget->addItem(it->first);
172172
QgsSymbol* sym=it->second;
173173
QPen pen;
174174
QBrush brush;
@@ -190,13 +190,13 @@ void QgsUniqueValueDialog::changeClassificationAttribute()
190190
sym->setBrush(brush);
191191
}
192192
}
193-
mClassBreakBox->setCurrentItem(0);
193+
mClassListWidget->setCurrentRow(0);
194194
}
195195

196196
void QgsUniqueValueDialog::changeCurrentValue()
197197
{
198198
sydialog.blockSignals(true);//block signal to prevent sydialog from changing the current QgsRenderItem
199-
QListWidgetItem* item=mClassBreakBox->currentItem();
199+
QListWidgetItem* item=mClassListWidget->currentItem();
200200
if(item)
201201
{
202202
QString value=item->text();
@@ -216,34 +216,34 @@ void QgsUniqueValueDialog::changeCurrentValue()
216216

217217
void QgsUniqueValueDialog::deleteCurrentClass()
218218
{
219-
QListWidgetItem* currentItem = mClassBreakBox->currentItem();
219+
QListWidgetItem* currentItem = mClassListWidget->currentItem();
220220
if(!currentItem)
221221
{
222222
return;
223223
}
224224

225225
QString classValue = currentItem->text();
226-
int currentIndex = mClassBreakBox->currentRow();
226+
int currentIndex = mClassListWidget->currentRow();
227227
mValues.erase(classValue);
228-
delete (mClassBreakBox->takeItem(currentIndex));
228+
delete (mClassListWidget->takeItem(currentIndex));
229229
qWarning("numRows: ");
230-
qWarning(QString::number(mClassBreakBox->count()));
230+
qWarning(QString::number(mClassListWidget->count()));
231231
//
232-
if(mClassBreakBox->count() < (currentIndex + 1))
232+
if(mClassListWidget->count() < (currentIndex + 1))
233233
{
234234
qWarning("selecting numRows - 1");
235-
mClassBreakBox->setCurrentRow(mClassBreakBox->count() - 1);
235+
mClassListWidget->setCurrentRow(mClassListWidget->count() - 1);
236236
}
237237
else
238238
{
239239
qWarning("selecting currentIndex");
240-
mClassBreakBox->setCurrentRow(currentIndex);
240+
mClassListWidget->setCurrentRow(currentIndex);
241241
}
242242
}
243243

244244
void QgsUniqueValueDialog::applySymbologyChanges()
245245
{
246-
QListWidgetItem* item=mClassBreakBox->currentItem();
246+
QListWidgetItem* item=mClassListWidget->currentItem();
247247
if(!item)
248248
{
249249
return;

0 commit comments

Comments
 (0)
Please sign in to comment.