Skip to content

Commit 64ab61d

Browse files
author
mhugent
committed
Changes to the unique value renderer and -dialog: 'classify' and 'delete class' button. Features which do not have a matching symbol are rendered with NoPen and NoBrush
git-svn-id: http://svn.osgeo.org/qgis/trunk@6472 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 7bd9622 commit 64ab61d

4 files changed

+103
-65
lines changed

src/app/qgsuniquevaluedialog.cpp

+37-16
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,9 @@ QgsUniqueValueDialog::QgsUniqueValueDialog(QgsVectorLayer* vl): QDialog(), mVect
7777
mClassBreakBox->insertItem(symbolvalue);
7878
}
7979
}
80-
else
81-
{
82-
changeClassificationAttribute(0);
83-
}
8480

85-
QObject::connect(mClassificationComboBox, SIGNAL(activated(int)), this, SLOT(changeClassificationAttribute(int)));
81+
QObject::connect(mClassifyButton, SIGNAL(clicked()), this, SLOT(changeClassificationAttribute()));
82+
QObject::connect(mDeletePushButton, SIGNAL(clicked()), this, SLOT(deleteCurrentClass()));
8683
QObject::connect(mClassBreakBox, SIGNAL(selectionChanged()), this, SLOT(changeCurrentValue()));
8784
QObject::connect(&sydialog, SIGNAL(settingsChanged()), this, SLOT(applySymbologyChanges()));
8885
mSymbolWidgetStack->addWidget(&sydialog);
@@ -126,8 +123,9 @@ void QgsUniqueValueDialog::apply()
126123
mVectorLayer->setRenderer(renderer);
127124
}
128125

129-
void QgsUniqueValueDialog::changeClassificationAttribute(int nr)
126+
void QgsUniqueValueDialog::changeClassificationAttribute()
130127
{
128+
int nr = mClassificationComboBox->currentIndex();
131129
//delete old entries
132130
for(std::map<QString,QgsSymbol*>::iterator it=mValues.begin();it!=mValues.end();++it)
133131
{
@@ -151,7 +149,7 @@ void QgsUniqueValueDialog::changeClassificationAttribute(int nr)
151149
while(provider->getNextFeature(feat, false, attlist))
152150
{
153151
const QgsAttributeMap& vec = feat.attributeMap();
154-
value=vec[0].fieldValue();
152+
value=vec[nr].fieldValue();
155153

156154
if(mValues.find(value)==mValues.end())
157155
{
@@ -162,7 +160,6 @@ void QgsUniqueValueDialog::changeClassificationAttribute(int nr)
162160

163161
//set symbology for all QgsSiSyDialogs
164162
QColor thecolor;
165-
double frac;
166163

167164
for(std::map<QString,QgsSymbol*>::iterator it=mValues.begin();it!=mValues.end();++it)
168165
{
@@ -200,18 +197,42 @@ void QgsUniqueValueDialog::changeCurrentValue()
200197
{
201198
sydialog.blockSignals(true);//block signal to prevent sydialog from changing the current QgsRenderItem
202199
Q3ListBoxItem* item=mClassBreakBox->selectedItem();
203-
QString value=item->text();
204-
std::map<QString,QgsSymbol*>::iterator it=mValues.find(value);
205-
if(it!=mValues.end())
200+
if(item)
201+
{
202+
QString value=item->text();
203+
std::map<QString,QgsSymbol*>::iterator it=mValues.find(value);
204+
if(it!=mValues.end())
205+
{
206+
sydialog.set( it->second);
207+
sydialog.setLabel(it->second->label());
208+
}
209+
else
210+
{
211+
//no entry found
212+
}
213+
}
214+
sydialog.blockSignals(false);
215+
}
216+
217+
void QgsUniqueValueDialog::deleteCurrentClass()
218+
{
219+
QString classValue = mClassBreakBox->currentText();
220+
int currentIndex = mClassBreakBox->currentItem();
221+
mValues.erase(classValue);
222+
mClassBreakBox->removeItem(currentIndex);
223+
qWarning("numRows: ");
224+
qWarning(QString::number(mClassBreakBox->numRows()));
225+
//
226+
if(mClassBreakBox->numRows() < (currentIndex + 1))
206227
{
207-
sydialog.set( it->second);
208-
sydialog.setLabel(it->second->label());
228+
qWarning("selecting numRows - 1");
229+
mClassBreakBox->setSelected(mClassBreakBox->numRows() - 1, true);
209230
}
210-
else
231+
else
211232
{
212-
//no entry found
233+
qWarning("selecting currentIndex");
234+
mClassBreakBox->setSelected(currentIndex, true);
213235
}
214-
sydialog.blockSignals(false);
215236
}
216237

217238
void QgsUniqueValueDialog::applySymbologyChanges()

src/app/qgsuniquevaluedialog.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ class QgsUniqueValueDialog: public QDialog, private Ui::QgsUniqueValueDialogBase
4747

4848
protected slots:
4949
/**Set new attribut for classification*/
50-
void changeClassificationAttribute(int nr);
50+
void changeClassificationAttribute();
5151
/**Changes the display of the single symbol dialog*/
5252
void changeCurrentValue();
53+
/**Removes a class from the classification*/
54+
void deleteCurrentClass();
5355
/**Writes changes in the single symbol dialog to the corresponding QgsSymbol*/
5456
void applySymbologyChanges();
5557
};

src/core/renderer/qgsuniquevaluerenderer.cpp

+11-4
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ void QgsUniqueValueRenderer::renderFeature(QPainter* p, QgsFeature& f,QImage* im
114114
}
115115

116116
// Line, polygon
117-
if ( mVectorType != QGis::Point )
117+
else if ( mVectorType != QGis::Point )
118118
{
119119
if( !selected )
120120
{
@@ -137,9 +137,16 @@ void QgsUniqueValueRenderer::renderFeature(QPainter* p, QgsFeature& f,QImage* im
137137
}
138138
else
139139
{
140-
#ifdef QGISDEBUG
141-
qWarning("Warning, no render item found in QgsUniqueValueRenderer::renderFeature");
142-
#endif
140+
//no matching symbol found. In this case, set Qt::NoPen, Qt::NoBrush or transparent image
141+
if ( img && mVectorType == QGis::Point )
142+
{
143+
//todo: fill image transparent
144+
}
145+
else if ( mVectorType != QGis::Point )
146+
{
147+
p->setPen(Qt::NoPen);
148+
p->setBrush(Qt::NoBrush);
149+
}
143150
}
144151

145152
}

src/ui/qgsuniquevaluedialogbase.ui

+52-44
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,48 @@
11
<ui version="4.0" >
2-
<author></author>
3-
<comment></comment>
4-
<exportmacro></exportmacro>
52
<class>QgsUniqueValueDialogBase</class>
63
<widget class="QDialog" name="QgsUniqueValueDialogBase" >
74
<property name="geometry" >
85
<rect>
96
<x>0</x>
107
<y>0</y>
11-
<width>500</width>
12-
<height>279</height>
8+
<width>505</width>
9+
<height>300</height>
1310
</rect>
1411
</property>
1512
<property name="windowTitle" >
1613
<string>Form1</string>
1714
</property>
1815
<layout class="QGridLayout" >
1916
<property name="margin" >
20-
<number>8</number>
17+
<number>9</number>
2118
</property>
2219
<property name="spacing" >
2320
<number>6</number>
2421
</property>
25-
<item row="1" column="2" colspan="2" >
26-
<widget class="Q3ListBox" name="mClassBreakBox" />
22+
<item row="0" column="0" >
23+
<widget class="QLabel" name="mClassVarLabel" >
24+
<property name="minimumSize" >
25+
<size>
26+
<width>0</width>
27+
<height>20</height>
28+
</size>
29+
</property>
30+
<property name="text" >
31+
<string>Classification Field:</string>
32+
</property>
33+
<property name="buddy" >
34+
<cstring>mClassificationComboBox</cstring>
35+
</property>
36+
</widget>
2737
</item>
28-
<item row="1" column="0" colspan="2" >
29-
<widget class="Q3WidgetStack" name="mSymbolWidgetStack" >
30-
<widget class="QWidget" name="WStackPage" >
31-
<property name="geometry" >
32-
<rect>
33-
<x>0</x>
34-
<y>0</y>
35-
<width>156</width>
36-
<height>234</height>
37-
</rect>
38-
</property>
39-
</widget>
38+
<item row="0" column="4" >
39+
<widget class="QPushButton" name="mDeletePushButton" >
40+
<property name="text" >
41+
<string>Delete class</string>
42+
</property>
4043
</widget>
4144
</item>
42-
<item row="0" column="3" >
45+
<item row="0" column="5" >
4346
<spacer>
4447
<property name="orientation" >
4548
<enum>Qt::Horizontal</enum>
@@ -49,12 +52,15 @@
4952
</property>
5053
<property name="sizeHint" >
5154
<size>
52-
<width>210</width>
53-
<height>21</height>
55+
<width>51</width>
56+
<height>25</height>
5457
</size>
5558
</property>
5659
</spacer>
5760
</item>
61+
<item row="1" column="2" colspan="4" >
62+
<widget class="Q3ListBox" name="mClassBreakBox" />
63+
</item>
5864
<item row="0" column="1" colspan="2" >
5965
<widget class="QComboBox" name="mClassificationComboBox" >
6066
<property name="minimumSize" >
@@ -65,40 +71,42 @@
6571
</property>
6672
</widget>
6773
</item>
68-
<item row="0" column="0" >
69-
<widget class="QLabel" name="mClassVarLabel" >
70-
<property name="minimumSize" >
71-
<size>
72-
<width>0</width>
73-
<height>20</height>
74-
</size>
75-
</property>
74+
<item row="0" column="3" >
75+
<widget class="QPushButton" name="mClassifyButton" >
7676
<property name="text" >
77-
<string>Classification Field:</string>
78-
</property>
79-
<property name="buddy" >
80-
<cstring>mClassificationComboBox</cstring>
77+
<string>Classify</string>
8178
</property>
8279
</widget>
8380
</item>
81+
<item row="1" column="0" colspan="2" >
82+
<widget class="Q3WidgetStack" name="mSymbolWidgetStack" >
83+
<widget class="QWidget" name="WStackPage" >
84+
<property name="geometry" >
85+
<rect>
86+
<x>0</x>
87+
<y>0</y>
88+
<width>190</width>
89+
<height>246</height>
90+
</rect>
91+
</property>
92+
</widget>
93+
</widget>
94+
</item>
8495
</layout>
8596
</widget>
8697
<layoutdefault spacing="6" margin="11" />
8798
<pixmapfunction>qPixmapFromMimeSource</pixmapfunction>
8899
<customwidgets>
100+
<customwidget>
101+
<class>Q3ListBox</class>
102+
<extends>Q3Frame</extends>
103+
<header>q3listbox.h</header>
104+
</customwidget>
89105
<customwidget>
90106
<class>Q3WidgetStack</class>
91-
<extends></extends>
107+
<extends>Q3WidgetStack</extends>
92108
<header>q3widgetstack.h</header>
93109
<container>1</container>
94-
<pixmap></pixmap>
95-
</customwidget>
96-
<customwidget>
97-
<class>Q3ListBox</class>
98-
<extends></extends>
99-
<header>q3listbox.h</header>
100-
<container>0</container>
101-
<pixmap></pixmap>
102110
</customwidget>
103111
</customwidgets>
104112
<resources/>

0 commit comments

Comments
 (0)