|
30 | 30 | QgsContinuousColorDialog::QgsContinuousColorDialog(QgsVectorLayer * layer) |
31 | 31 | : QDialog(), mVectorLayer(layer) |
32 | 32 | { |
33 | | - setupUi(this); |
| 33 | + setupUi(this); |
34 | 34 | #ifdef QGISDEBUG |
35 | | - qWarning("constructor QgsContinuousColorDialog"); |
| 35 | + qWarning("constructor QgsContinuousColorDialog"); |
36 | 36 | #endif |
37 | 37 |
|
38 | | - QObject::connect(btnMinValue, SIGNAL(clicked()), this, SLOT(selectMinimumColor())); |
39 | | - QObject::connect(btnMaxValue, SIGNAL(clicked()), this, SLOT(selectMaximumColor())); |
| 38 | + QObject::connect(btnMinValue, SIGNAL(clicked()), this, SLOT(selectMinimumColor())); |
| 39 | + QObject::connect(btnMaxValue, SIGNAL(clicked()), this, SLOT(selectMaximumColor())); |
40 | 40 |
|
41 | | - //find out the numerical fields of mVectorLayer |
42 | | - QgsVectorDataProvider *provider = mVectorLayer->getDataProvider(); |
43 | | - if (provider) |
44 | | - { |
45 | | - const QgsFieldMap & fields = provider->fields(); |
46 | | - int fieldnumber(0), combonumber(0); |
47 | | - QString str; |
48 | | - |
49 | | - for (QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); ++it) |
50 | | - { |
51 | | - QVariant::Type type = (*it).type(); |
52 | | - if (type == QVariant::Int || type == QVariant::Double) |
53 | | - { |
54 | | - str = (*it).name(); |
55 | | - classificationComboBox->insertItem(str); |
56 | | - mFieldMap.insert(std::make_pair(combonumber, fieldnumber)); |
57 | | - combonumber++; |
58 | | - } |
59 | | - fieldnumber++; |
60 | | - } |
61 | | - } |
62 | | - else |
| 41 | + //find out the numerical fields of mVectorLayer |
| 42 | + QgsVectorDataProvider *provider = mVectorLayer->getDataProvider(); |
| 43 | + if (provider) |
| 44 | + { |
| 45 | + const QgsFieldMap & fields = provider->fields(); |
| 46 | + int fieldnumber(0), combonumber(0); |
| 47 | + QString str; |
| 48 | + |
| 49 | + for (QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); ++it) |
63 | 50 | { |
64 | | - qWarning("Warning, data provider is null in QgsContinuousColorDialog::QgsContinuousColorDialog(...)"); |
65 | | - return; |
| 51 | + QVariant::Type type = (*it).type(); |
| 52 | + if (type == QVariant::Int || type == QVariant::Double) |
| 53 | + { |
| 54 | + str = (*it).name(); |
| 55 | + classificationComboBox->insertItem(str); |
| 56 | + mFieldMap.insert(std::make_pair(combonumber, fieldnumber)); |
| 57 | + combonumber++; |
| 58 | + } |
| 59 | + fieldnumber++; |
66 | 60 | } |
| 61 | + } |
| 62 | + else |
| 63 | + { |
| 64 | + qWarning("Warning, data provider is null in QgsContinuousColorDialog::QgsContinuousColorDialog(...)"); |
| 65 | + return; |
| 66 | + } |
67 | 67 |
|
68 | | - //restore the correct colors for minimum and maximum values |
| 68 | + //restore the correct colors for minimum and maximum values |
69 | 69 |
|
70 | | - const QgsContinuousColorRenderer* renderer = dynamic_cast < const QgsContinuousColorRenderer * >(layer->renderer());; |
| 70 | + const QgsContinuousColorRenderer* renderer = dynamic_cast < const QgsContinuousColorRenderer * >(layer->renderer());; |
71 | 71 |
|
72 | | - if (renderer) |
73 | | - { |
74 | | - // Awkard - here we want to search through mFieldMap for a |
75 | | - // particular value, while elsewhere in this code we need to search |
76 | | - // for a particular key, so one or the other loses out, which is here. |
77 | | - |
78 | | - std::map<int,int>::const_iterator iter = mFieldMap.begin(); |
79 | | - while (iter != mFieldMap.end()) |
80 | | - { |
81 | | - if (iter->second == renderer->classificationField()) |
82 | | - break; |
83 | | - iter++; |
84 | | - } |
85 | | - if (iter != mFieldMap.end()) |
86 | | - classificationComboBox->setCurrentItem(iter->first); |
87 | | - else |
88 | | - classificationComboBox->setCurrentItem(-1); |
89 | | - |
90 | | - const QgsSymbol* minsymbol = renderer->minimumSymbol(); |
91 | | - const QgsSymbol* maxsymbol = renderer->maximumSymbol(); |
92 | | - |
93 | | - if (mVectorLayer->vectorType() == QGis::Line || mVectorLayer->vectorType() == QGis::Point) |
94 | | - { |
95 | | - btnMinValue->setColor( minsymbol->pen().color() ); |
96 | | - btnMaxValue->setColor( maxsymbol->pen().color() ); |
97 | | - } |
98 | | - else |
| 72 | + if (renderer) |
| 73 | + { |
| 74 | + // Awkard - here we want to search through mFieldMap for a |
| 75 | + // particular value, while elsewhere in this code we need to search |
| 76 | + // for a particular key, so one or the other loses out, which is here. |
| 77 | + |
| 78 | + std::map<int,int>::const_iterator iter = mFieldMap.begin(); |
| 79 | + while (iter != mFieldMap.end()) |
99 | 80 | { |
100 | | - btnMinValue->setColor( minsymbol->brush().color() ); |
101 | | - btnMaxValue->setColor( maxsymbol->brush().color() ); |
| 81 | + if (iter->second == renderer->classificationField()) |
| 82 | + break; |
| 83 | + iter++; |
102 | 84 | } |
| 85 | + if (iter != mFieldMap.end()) |
| 86 | + classificationComboBox->setCurrentItem(iter->first); |
| 87 | + else |
| 88 | + classificationComboBox->setCurrentItem(-1); |
103 | 89 |
|
104 | | - outlinewidthspinbox->setMinValue(0); |
105 | | - outlinewidthspinbox->setValue(minsymbol->pen().width()); |
| 90 | + const QgsSymbol* minsymbol = renderer->minimumSymbol(); |
| 91 | + const QgsSymbol* maxsymbol = renderer->maximumSymbol(); |
106 | 92 |
|
107 | | - if (renderer->drawPolygonOutline()) |
108 | | - cb_polygonOutline->setCheckState(Qt::Checked); |
109 | | - else |
110 | | - cb_polygonOutline->setCheckState(Qt::Unchecked); |
111 | | - if (mVectorLayer->vectorType() != QGis::Polygon) |
112 | | - cb_polygonOutline->setVisible(false); |
| 93 | + if (mVectorLayer->vectorType() == QGis::Line || mVectorLayer->vectorType() == QGis::Point) |
| 94 | + { |
| 95 | + btnMinValue->setColor( minsymbol->pen().color() ); |
| 96 | + btnMaxValue->setColor( maxsymbol->pen().color() ); |
113 | 97 | } |
114 | 98 | else |
115 | 99 | { |
116 | | - cb_polygonOutline->setCheckState(Qt::Checked); |
117 | | - outlinewidthspinbox->setValue(1); |
118 | | - if (mVectorLayer->vectorType() != QGis::Polygon) |
119 | | - cb_polygonOutline->setVisible(false); |
| 100 | + btnMinValue->setColor( minsymbol->brush().color() ); |
| 101 | + btnMaxValue->setColor( maxsymbol->brush().color() ); |
| 102 | + } |
120 | 103 |
|
121 | | - btnMinValue->setColor(Qt::black); |
122 | | - btnMaxValue->setColor(Qt::white); |
| 104 | + outlinewidthspinbox->setMinValue(0); |
| 105 | + outlinewidthspinbox->setValue(minsymbol->pen().width()); |
123 | 106 |
|
124 | | - } |
125 | | - // Ensure that the state of other widgets is appropriate for the |
126 | | - // state of the polygonoutline checkbox. |
127 | | - on_cb_polygonOutline_clicked(); |
| 107 | + if (renderer->drawPolygonOutline()) |
| 108 | + cb_polygonOutline->setCheckState(Qt::Checked); |
| 109 | + else |
| 110 | + cb_polygonOutline->setCheckState(Qt::Unchecked); |
| 111 | + if (mVectorLayer->vectorType() != QGis::Polygon) |
| 112 | + cb_polygonOutline->setVisible(false); |
| 113 | + } |
| 114 | + else |
| 115 | + { |
| 116 | + cb_polygonOutline->setCheckState(Qt::Checked); |
| 117 | + outlinewidthspinbox->setValue(1); |
| 118 | + if (mVectorLayer->vectorType() != QGis::Polygon) |
| 119 | + cb_polygonOutline->setVisible(false); |
| 120 | + |
| 121 | + btnMinValue->setColor(Qt::black); |
| 122 | + btnMaxValue->setColor(Qt::white); |
| 123 | + |
| 124 | + } |
| 125 | + // Ensure that the state of other widgets is appropriate for the |
| 126 | + // state of the polygonoutline checkbox. |
| 127 | + on_cb_polygonOutline_clicked(); |
128 | 128 | } |
129 | 129 |
|
130 | 130 | QgsContinuousColorDialog::QgsContinuousColorDialog() |
131 | 131 | { |
132 | | - setupUi(this); |
| 132 | + setupUi(this); |
133 | 133 | #ifdef QGISDEBUG |
134 | | - qWarning("constructor QgsContinuousColorDialog"); |
| 134 | + qWarning("constructor QgsContinuousColorDialog"); |
135 | 135 | #endif |
136 | 136 | } |
137 | 137 |
|
138 | 138 | QgsContinuousColorDialog::~QgsContinuousColorDialog() |
139 | 139 | { |
140 | 140 | #ifdef QGISDEBUG |
141 | | - qWarning("destructor QgsContinuousColorDialog"); |
| 141 | + qWarning("destructor QgsContinuousColorDialog"); |
142 | 142 | #endif |
143 | 143 | } |
144 | 144 |
|
145 | 145 | void QgsContinuousColorDialog::apply() |
146 | 146 | { |
147 | | - int comboIndex = classificationComboBox->currentIndex(); |
148 | | - if (comboIndex == -1) //don't do anything, if there is no classification field |
149 | | - { |
150 | | - return; |
151 | | - } |
152 | | - std::map < int, int >::iterator iter = mFieldMap.find(comboIndex); |
153 | | - // Should never happen... |
154 | | - assert(iter != mFieldMap.end()); |
155 | | - |
156 | | - int classfield = iter->second; |
157 | | - |
158 | | - //find the minimum and maximum for the classification variable |
159 | | - double minimum, maximum; |
160 | | - QgsVectorDataProvider *provider = dynamic_cast<QgsVectorDataProvider*>(mVectorLayer->getDataProvider()); |
161 | | - if (provider) |
162 | | - { |
163 | | - minimum = provider->minValue(classfield).toDouble(); |
164 | | - maximum = provider->maxValue(classfield).toDouble(); |
165 | | - } |
166 | | - else |
167 | | - { |
168 | | - qWarning("Warning, provider is null in QgsGraSyExtensionWidget::QgsGraSyExtensionWidget(...)"); |
169 | | - return; |
170 | | - } |
171 | | - |
172 | | - |
173 | | - //create the render items for minimum and maximum value |
174 | | - QgsSymbol* minsymbol = new QgsSymbol(mVectorLayer->vectorType(), QString::number(minimum, 'f'), "", ""); |
175 | | - if (mVectorLayer->vectorType() == QGis::Line || mVectorLayer->vectorType() == QGis::Point) |
176 | | - { |
177 | | - minsymbol->setPen(QPen(btnMinValue->color(), outlinewidthspinbox->value())); |
178 | | - } |
179 | | - else |
180 | | - { |
181 | | - minsymbol->setBrush(QBrush(btnMinValue->color())); |
182 | | - minsymbol->setPen(QPen(QColor(0, 0, 0), outlinewidthspinbox->value())); |
183 | | - } |
184 | | - |
185 | | - QgsSymbol* maxsymbol = new QgsSymbol(mVectorLayer->vectorType(), QString::number(maximum, 'f'), "", ""); |
186 | | - if (mVectorLayer->vectorType() == QGis::Line || mVectorLayer->vectorType() == QGis::Point) |
187 | | - { |
188 | | - maxsymbol->setPen(QPen(btnMaxValue->color(), outlinewidthspinbox->value())); |
189 | | - } |
190 | | - else |
191 | | - { |
192 | | - maxsymbol->setBrush(QBrush(btnMaxValue->color())); |
193 | | - maxsymbol->setPen(QPen(QColor(0, 0, 0), outlinewidthspinbox->value())); |
194 | | - } |
195 | | - |
196 | | - QgsContinuousColorRenderer* renderer = new QgsContinuousColorRenderer(mVectorLayer->vectorType()); |
197 | | - mVectorLayer->setRenderer(renderer); |
198 | | - |
199 | | - renderer->setMinimumSymbol(minsymbol); |
200 | | - renderer->setMaximumSymbol(maxsymbol); |
201 | | - renderer->setClassificationField(classfield); |
202 | | - bool drawOutline = (cb_polygonOutline->checkState() == Qt::Checked) ? true:false; |
203 | | - renderer->setDrawPolygonOutline(drawOutline); |
| 147 | + int comboIndex = classificationComboBox->currentIndex(); |
| 148 | + if (comboIndex == -1) //don't do anything, if there is no classification field |
| 149 | + { |
| 150 | + return; |
| 151 | + } |
| 152 | + std::map < int, int >::iterator iter = mFieldMap.find(comboIndex); |
| 153 | + // Should never happen... |
| 154 | + assert(iter != mFieldMap.end()); |
| 155 | + |
| 156 | + int classfield = iter->second; |
| 157 | + |
| 158 | + //find the minimum and maximum for the classification variable |
| 159 | + double minimum, maximum; |
| 160 | + QgsVectorDataProvider *provider = dynamic_cast<QgsVectorDataProvider*>(mVectorLayer->getDataProvider()); |
| 161 | + if (provider) |
| 162 | + { |
| 163 | + minimum = provider->minValue(classfield).toDouble(); |
| 164 | + maximum = provider->maxValue(classfield).toDouble(); |
| 165 | + } |
| 166 | + else |
| 167 | + { |
| 168 | + qWarning("Warning, provider is null in QgsGraSyExtensionWidget::QgsGraSyExtensionWidget(...)"); |
| 169 | + return; |
| 170 | + } |
| 171 | + |
| 172 | + |
| 173 | + //create the render items for minimum and maximum value |
| 174 | + QgsSymbol* minsymbol = new QgsSymbol(mVectorLayer->vectorType(), QString::number(minimum, 'f'), "", ""); |
| 175 | + if (mVectorLayer->vectorType() == QGis::Line || mVectorLayer->vectorType() == QGis::Point) |
| 176 | + { |
| 177 | + minsymbol->setPen(QPen(btnMinValue->color(), outlinewidthspinbox->value())); |
| 178 | + } |
| 179 | + else |
| 180 | + { |
| 181 | + minsymbol->setBrush(QBrush(btnMinValue->color())); |
| 182 | + minsymbol->setPen(QPen(QColor(0, 0, 0), outlinewidthspinbox->value())); |
| 183 | + } |
| 184 | + |
| 185 | + QgsSymbol* maxsymbol = new QgsSymbol(mVectorLayer->vectorType(), QString::number(maximum, 'f'), "", ""); |
| 186 | + if (mVectorLayer->vectorType() == QGis::Line || mVectorLayer->vectorType() == QGis::Point) |
| 187 | + { |
| 188 | + maxsymbol->setPen(QPen(btnMaxValue->color(), outlinewidthspinbox->value())); |
| 189 | + } |
| 190 | + else |
| 191 | + { |
| 192 | + maxsymbol->setBrush(QBrush(btnMaxValue->color())); |
| 193 | + maxsymbol->setPen(QPen(QColor(0, 0, 0), outlinewidthspinbox->value())); |
| 194 | + } |
| 195 | + |
| 196 | + QgsContinuousColorRenderer* renderer = new QgsContinuousColorRenderer(mVectorLayer->vectorType()); |
| 197 | + mVectorLayer->setRenderer(renderer); |
| 198 | + |
| 199 | + renderer->setMinimumSymbol(minsymbol); |
| 200 | + renderer->setMaximumSymbol(maxsymbol); |
| 201 | + renderer->setClassificationField(classfield); |
| 202 | + bool drawOutline = (cb_polygonOutline->checkState() == Qt::Checked) ? true:false; |
| 203 | + renderer->setDrawPolygonOutline(drawOutline); |
204 | 204 | } |
205 | 205 |
|
206 | 206 | void QgsContinuousColorDialog::selectMinimumColor() |
207 | 207 | { |
208 | | - QColor mincolor = QColorDialog::getColor(btnMinValue->color(), this); |
209 | | - if(mincolor.isValid()) |
210 | | - { |
211 | | - btnMinValue->setColor(mincolor); |
212 | | - } |
213 | | - setActiveWindow(); |
| 208 | + QColor mincolor = QColorDialog::getColor(btnMinValue->color(), this); |
| 209 | + if(mincolor.isValid()) |
| 210 | + { |
| 211 | + btnMinValue->setColor(mincolor); |
| 212 | + } |
| 213 | + setActiveWindow(); |
214 | 214 | } |
215 | 215 |
|
216 | 216 | void QgsContinuousColorDialog::selectMaximumColor() |
217 | 217 | { |
218 | | - QColor maxcolor = QColorDialog::getColor(btnMaxValue->color(), this); |
219 | | - if(maxcolor.isValid()) |
220 | | - { |
221 | | - btnMaxValue->setColor(maxcolor); |
222 | | - } |
223 | | - setActiveWindow(); |
| 218 | + QColor maxcolor = QColorDialog::getColor(btnMaxValue->color(), this); |
| 219 | + if(maxcolor.isValid()) |
| 220 | + { |
| 221 | + btnMaxValue->setColor(maxcolor); |
| 222 | + } |
| 223 | + setActiveWindow(); |
224 | 224 | } |
225 | 225 |
|
226 | 226 | void QgsContinuousColorDialog::on_cb_polygonOutline_clicked() |
|
0 commit comments