@@ -144,193 +144,193 @@ QgsComposerVectorLegend::~QgsComposerVectorLegend()
144
144
145
145
QRect QgsComposerVectorLegend::render ( QPainter *p )
146
146
{
147
- std::cout << " QgsComposerVectorLegend::render p = " << p << std::endl;
148
-
149
- // Painter can be 0, create dummy to avoid many if below
150
- QPainter *painter;
151
- QPixmap *pixmap;
152
- if ( p ) {
153
- painter = p;
154
- } else {
155
- pixmap = new QPixmap (1 ,1 );
156
- painter = new QPainter ( pixmap );
157
- }
147
+ std::cout << " QgsComposerVectorLegend::render p = " << p << std::endl;
158
148
159
- std::cout << " mComposition->scale() = " << mComposition ->scale () << std::endl;
160
- // Font size in canvas units
161
- float titleSize = 25.4 * mComposition ->scale () * mTitleFont .pointSizeFloat () / 72 ;
162
- float sectionSize = 25.4 * mComposition ->scale () * mSectionFont .pointSizeFloat () / 72 ;
163
- float size = 25.4 * mComposition ->scale () * mFont .pointSizeFloat () / 72 ;
149
+ // Painter can be 0, create dummy to avoid many if below
150
+ QPainter *painter;
151
+ QPixmap *pixmap;
152
+ if ( p ) {
153
+ painter = p;
154
+ } else {
155
+ pixmap = new QPixmap (1 ,1 );
156
+ painter = new QPainter ( pixmap );
157
+ }
164
158
165
- std::cout << " font sizes = " << titleSize << " " << sectionSize << " " << size << std::endl;
159
+ std::cout << " mComposition->scale() = " << mComposition ->scale () << std::endl;
160
+ // Font size in canvas units
161
+ float titleSize = 25.4 * mComposition ->scale () * mTitleFont .pointSizeFloat () / 72 ;
162
+ float sectionSize = 25.4 * mComposition ->scale () * mSectionFont .pointSizeFloat () / 72 ;
163
+ float size = 25.4 * mComposition ->scale () * mFont .pointSizeFloat () / 72 ;
166
164
167
- // Metrics
168
- QFont titleFont ( mTitleFont );
169
- QFont sectionFont ( mSectionFont );
170
- QFont font ( mFont );
165
+ std::cout << " font sizes = " << titleSize << " " << sectionSize << " " << size << std::endl;
171
166
172
- titleFont.setPointSizeFloat ( titleSize );
173
- sectionFont.setPointSizeFloat ( sectionSize );
174
- font.setPointSizeFloat ( size );
167
+ // Metrics
168
+ QFont titleFont ( mTitleFont );
169
+ QFont sectionFont ( mSectionFont );
170
+ QFont font ( mFont );
175
171
176
- QFontMetrics titleMetrics ( titleFont );
177
- QFontMetrics sectionMetrics ( sectionFont );
178
- QFontMetrics metrics ( font );
172
+ titleFont.setPointSizeFloat ( titleSize );
173
+ sectionFont.setPointSizeFloat ( sectionSize );
174
+ font.setPointSizeFloat ( size );
175
+
176
+ QFontMetrics titleMetrics ( titleFont );
177
+ QFontMetrics sectionMetrics ( sectionFont );
178
+ QFontMetrics metrics ( font );
179
179
180
- // Fonts for rendering
181
- double psTitleSize = titleMetrics.ascent () * 72.0 / mComposition ->resolution ();
182
- double psSectionSize = sectionMetrics.ascent () * 72.0 / mComposition ->resolution ();
183
- double psSize = metrics.ascent () * 72.0 / mComposition ->resolution ();
180
+ // Fonts for rendering
181
+ double psTitleSize = titleMetrics.ascent () * 72.0 / mComposition ->resolution ();
182
+ double psSectionSize = sectionMetrics.ascent () * 72.0 / mComposition ->resolution ();
183
+ double psSize = metrics.ascent () * 72.0 / mComposition ->resolution ();
184
184
185
- if ( plotStyle () == QgsComposition::Postscript)
186
- {
187
- titleFont.setPointSizeFloat ( psTitleSize );
188
- sectionFont.setPointSizeFloat ( psSectionSize );
189
- font.setPointSizeFloat ( psSize );
190
- }
191
- else
192
- {
193
- titleFont.setPointSizeFloat ( titleSize );
194
- sectionFont.setPointSizeFloat ( sectionSize );
195
- font.setPointSizeFloat ( size );
196
- }
185
+ if ( plotStyle () == QgsComposition::Postscript)
186
+ {
187
+ titleFont.setPointSizeFloat ( psTitleSize );
188
+ sectionFont.setPointSizeFloat ( psSectionSize );
189
+ font.setPointSizeFloat ( psSize );
190
+ }
191
+ else
192
+ {
193
+ titleFont.setPointSizeFloat ( titleSize );
194
+ sectionFont.setPointSizeFloat ( sectionSize );
195
+ font.setPointSizeFloat ( size );
196
+ }
197
197
198
- // Not sure about Style Strategy, QFont::PreferMatch?
199
- titleFont.setStyleStrategy ( (QFont::StyleStrategy) (QFont::PreferOutline | QFont::PreferAntialias) );
200
- sectionFont.setStyleStrategy ( (QFont::StyleStrategy) (QFont::PreferOutline | QFont::PreferAntialias) );
201
- font.setStyleStrategy ( (QFont::StyleStrategy) (QFont::PreferOutline | QFont::PreferAntialias) );
198
+ // Not sure about Style Strategy, QFont::PreferMatch?
199
+ titleFont.setStyleStrategy ( (QFont::StyleStrategy) (QFont::PreferOutline | QFont::PreferAntialias) );
200
+ sectionFont.setStyleStrategy ( (QFont::StyleStrategy) (QFont::PreferOutline | QFont::PreferAntialias) );
201
+ font.setStyleStrategy ( (QFont::StyleStrategy) (QFont::PreferOutline | QFont::PreferAntialias) );
202
202
203
- int x, y;
203
+ int x, y;
204
204
205
- // Title
206
- y = mMargin + titleMetrics.height ();
207
- painter->setPen ( mPen );
208
- painter->setFont ( titleFont );
205
+ // Title
206
+ y = mMargin + titleMetrics.height ();
207
+ painter->setPen ( mPen );
208
+ painter->setFont ( titleFont );
209
209
210
- painter->drawText ( (int ) (2 *mMargin ), y, mTitle );
210
+ painter->drawText ( (int ) (2 *mMargin ), y, mTitle );
211
211
212
- int width = 4 * mMargin + titleMetrics.width ( mTitle );
213
- int height = mMargin + mSymbolSpace + titleMetrics.height (); // mSymbolSpace?
212
+ int width = 4 * mMargin + titleMetrics.width ( mTitle );
213
+ int height = mMargin + mSymbolSpace + titleMetrics.height (); // mSymbolSpace?
214
214
215
- // Layers
216
- QgsComposerMap *map = mComposition ->map ( mMap );
217
- if ( map ) {
218
- std::map<int ,int > doneGroups;
215
+ // Layers
216
+ QgsComposerMap *map = mComposition ->map ( mMap );
217
+ if ( map ) {
218
+ std::map<int ,int > doneGroups;
219
219
220
- int nlayers = mMapCanvas ->layerCount ();
221
- for ( int i = nlayers - 1 ; i >= 0 ; i-- ) {
222
- QgsMapLayer *layer = mMapCanvas ->getZpos (i);
223
- if ( !layer->visible () ) continue ;
224
- if ( layer->type () != QgsMapLayer::VECTOR ) continue ;
225
-
226
- QString layerId = layer->getLayerID ();
227
- if ( ! layerOn (layerId) ) continue ;
220
+ int nlayers = mMapCanvas ->layerCount ();
221
+ for ( int i = nlayers - 1 ; i >= 0 ; i-- ) {
222
+ QgsMapLayer *layer = mMapCanvas ->getZpos (i);
223
+ if ( !layer->visible () ) continue ;
224
+ if ( layer->type () != QgsMapLayer::VECTOR ) continue ;
225
+
226
+ QString layerId = layer->getLayerID ();
227
+ if ( ! layerOn (layerId) ) continue ;
228
228
229
- int group = layerGroup ( layerId );
230
- if ( group > 0 ) {
231
- if ( doneGroups.find (group) != doneGroups.end () ) {
232
- continue ;
233
- } else {
234
- doneGroups.insert (std::make_pair (group,1 ));
235
- }
236
- }
237
-
238
- /* Make list of all layers in the group and count section items */
239
- std::vector<int > groupLayers; // vector of layers
240
- std::vector<int > itemHeights; // maximum item sizes
241
- std::vector<QString> itemLabels; // item labels
242
- int sectionItemsCount = 0 ;
243
- QString sectionTitle;
244
-
245
- for ( int j = nlayers - 1 ; j >= 0 ; j-- ) {
246
- QgsMapLayer *layer2 = mMapCanvas ->getZpos (j);
247
- if ( !layer2->visible () ) continue ;
248
- if ( layer2->type () != QgsMapLayer::VECTOR ) continue ;
229
+ int group = layerGroup ( layerId );
230
+ if ( group > 0 ) {
231
+ if ( doneGroups.find (group) != doneGroups.end () ) {
232
+ continue ;
233
+ } else {
234
+ doneGroups.insert (std::make_pair (group,1 ));
235
+ }
236
+ }
237
+
238
+ /* Make list of all layers in the group and count section items */
239
+ std::vector<int > groupLayers; // vector of layers
240
+ std::vector<int > itemHeights; // maximum item sizes
241
+ std::vector<QString> itemLabels; // item labels
242
+ int sectionItemsCount = 0 ;
243
+ QString sectionTitle;
244
+
245
+ for ( int j = nlayers - 1 ; j >= 0 ; j-- ) {
246
+ QgsMapLayer *layer2 = mMapCanvas ->getZpos (j);
247
+ if ( !layer2->visible () ) continue ;
248
+ if ( layer2->type () != QgsMapLayer::VECTOR ) continue ;
249
249
250
- QString layerId2 = layer2->getLayerID ();;
251
- if ( ! layerOn (layerId2) ) continue ;
250
+ QString layerId2 = layer2->getLayerID ();;
251
+ if ( ! layerOn (layerId2) ) continue ;
252
252
253
- int group2 = layerGroup ( layerId2 );
253
+ int group2 = layerGroup ( layerId2 );
254
254
255
- QgsVectorLayer *vector = dynamic_cast <QgsVectorLayer*> (layer2);
256
- const QgsRenderer *renderer = vector->renderer ();
255
+ QgsVectorLayer *vector = dynamic_cast <QgsVectorLayer*> (layer2);
256
+ const QgsRenderer *renderer = vector->renderer ();
257
257
258
- if ( (group > 0 && group2 == group) || ( group == 0 && j == i ) ) {
259
- groupLayers.push_back (j);
258
+ if ( (group > 0 && group2 == group) || ( group == 0 && j == i ) ) {
259
+ groupLayers.push_back (j);
260
260
261
- std::list<QgsSymbol*> symbols = renderer->symbols ();
261
+ std::list<QgsSymbol*> symbols = renderer->symbols ();
262
262
263
- if ( sectionTitle.length () == 0 ) {
264
- sectionTitle = layer2->name ();
265
- }
263
+ if ( sectionTitle.length () == 0 ) {
264
+ sectionTitle = layer2->name ();
265
+ }
266
266
267
- if ( symbols.size () > sectionItemsCount ) {
268
- sectionItemsCount = symbols.size ();
269
- itemHeights.resize (sectionItemsCount);
270
- itemLabels.resize (sectionItemsCount);
271
- }
272
-
273
- double widthScale = map->widthScale () * mComposition ->scale ();
274
- if ( plotStyle () == QgsComposition::Preview && mPreviewMode == Render ) {
275
- widthScale *= mComposition ->viewScale ();
276
- }
267
+ if ( symbols.size () > sectionItemsCount ) {
268
+ sectionItemsCount = symbols.size ();
269
+ itemHeights.resize (sectionItemsCount);
270
+ itemLabels.resize (sectionItemsCount);
271
+ }
272
+
273
+ double widthScale = map->widthScale () * mComposition ->scale ();
274
+ if ( plotStyle () == QgsComposition::Preview && mPreviewMode == Render ) {
275
+ widthScale *= mComposition ->viewScale ();
276
+ }
277
277
278
- double scale = map->symbolScale () * mComposition ->scale ();
278
+ double scale = map->symbolScale () * mComposition ->scale ();
279
279
280
- int icnt = 0 ;
281
- for ( std::list<QgsSymbol*>::iterator it = symbols.begin (); it != symbols.end (); ++it ) {
280
+ int icnt = 0 ;
281
+ for ( std::list<QgsSymbol*>::iterator it = symbols.begin (); it != symbols.end (); ++it ) {
282
282
283
- QgsSymbol* sym = (*it);
283
+ QgsSymbol* sym = (*it);
284
284
285
- // height
286
- if ( itemHeights[icnt] < mSymbolHeight ) { // init first
287
- itemHeights[icnt] = mSymbolHeight ;
288
- }
285
+ // height
286
+ if ( itemHeights[icnt] < mSymbolHeight ) { // init first
287
+ itemHeights[icnt] = mSymbolHeight ;
288
+ }
289
289
290
- QPixmap pic = sym->getPointSymbolAsPixmap (widthScale, false );
290
+ QPixmap pic = sym->getPointSymbolAsPixmap (widthScale, false );
291
291
292
- int h = (int ) ( scale * pic.height () );
293
- if ( h > itemHeights[icnt] ) {
294
- itemHeights[icnt] = h;
295
- }
292
+ int h = (int ) ( scale * pic.height () );
293
+ if ( h > itemHeights[icnt] ) {
294
+ itemHeights[icnt] = h;
295
+ }
296
296
297
- if ( itemLabels[icnt].length () == 0 ) {
298
- if ( sym->label ().length () > 0 ) {
297
+ if ( itemLabels[icnt].length () == 0 ) {
298
+ if ( sym->label ().length () > 0 ) {
299
299
itemLabels[icnt] = sym->label ();
300
- } else {
300
+ } else {
301
301
itemLabels[icnt] = sym->lowerValue ();
302
302
if (sym->upperValue ().length () > 0 )
303
303
itemLabels[icnt] += " - " + sym->upperValue ();
304
- }
305
- }
304
+ }
305
+ }
306
306
307
- icnt++;
308
- }
309
- }
310
- }
311
- // std::cout << "group size = " << groupLayers.size() << std::endl;
312
- // std::cout << "sectionItemsCount = " << sectionItemsCount << std::endl;
313
-
314
- // Section title
315
- if ( sectionItemsCount > 1 ) {
316
- height += mSymbolSpace ;
317
-
318
- x = (int ) ( 2 *mMargin );
319
- y = (int ) ( height + sectionMetrics.height () );
320
- painter->setPen ( mPen );
321
- painter->setFont ( sectionFont );
322
-
323
- painter->drawText ( x, y,sectionTitle );
324
-
325
- int w = 3 *mMargin + sectionMetrics.width ( sectionTitle );
326
- if ( w > width ) width = w;
327
- height += sectionMetrics.height ();
328
- height += (int ) (0.7 *mSymbolSpace );
329
- }
330
-
331
- // Draw all layers in group
332
- int groupStartHeight = height;
333
- for ( int j = groupLayers.size ()-1 ; j >= 0 ; j-- ) {
307
+ icnt++;
308
+ }
309
+ }
310
+ }
311
+ // std::cout << "group size = " << groupLayers.size() << std::endl;
312
+ // std::cout << "sectionItemsCount = " << sectionItemsCount << std::endl;
313
+
314
+ // Section title
315
+ if ( sectionItemsCount > 1 ) {
316
+ height += mSymbolSpace ;
317
+
318
+ x = (int ) ( 2 *mMargin );
319
+ y = (int ) ( height + sectionMetrics.height () );
320
+ painter->setPen ( mPen );
321
+ painter->setFont ( sectionFont );
322
+
323
+ painter->drawText ( x, y,sectionTitle );
324
+
325
+ int w = 3 *mMargin + sectionMetrics.width ( sectionTitle );
326
+ if ( w > width ) width = w;
327
+ height += sectionMetrics.height ();
328
+ height += (int ) (0.7 *mSymbolSpace );
329
+ }
330
+
331
+ // Draw all layers in group
332
+ int groupStartHeight = height;
333
+ for ( int j = groupLayers.size ()-1 ; j >= 0 ; j-- ) {
334
334
std::cout << " layer = " << groupLayers[j] << std::endl;
335
335
336
336
int localHeight = groupStartHeight;
@@ -344,85 +344,85 @@ QRect QgsComposerVectorLegend::render ( QPainter *p )
344
344
345
345
int icnt = 0 ;
346
346
for ( std::list<QgsSymbol*>::iterator it = symbols.begin (); it != symbols.end (); ++it ) {
347
- localHeight += mSymbolSpace ;
347
+ localHeight += mSymbolSpace ;
348
348
349
- int symbolHeight = itemHeights[icnt];
350
- QgsSymbol* sym = (*it);
349
+ int symbolHeight = itemHeights[icnt];
350
+ QgsSymbol* sym = (*it);
351
351
352
- QPen pen = sym->pen ();
353
- double widthScale = map->widthScale () * mComposition ->scale ();
354
- if ( plotStyle () == QgsComposition::Preview && mPreviewMode == Render ) {
355
- widthScale *= mComposition ->viewScale ();
356
- }
357
- pen.setWidth ( (int ) ( widthScale * pen.width () ) );
358
- painter->setPen ( pen );
359
- painter->setBrush ( sym->brush () );
352
+ QPen pen = sym->pen ();
353
+ double widthScale = map->widthScale () * mComposition ->scale ();
354
+ if ( plotStyle () == QgsComposition::Preview && mPreviewMode == Render ) {
355
+ widthScale *= mComposition ->viewScale ();
356
+ }
357
+ pen.setWidth ( (int ) ( widthScale * pen.width () ) );
358
+ painter->setPen ( pen );
359
+ painter->setBrush ( sym->brush () );
360
360
361
- if ( vector->vectorType () == QGis::Point ) {
362
- double scale = map->symbolScale () * mComposition ->scale ();
363
-
364
- // Get the picture of appropriate size directly from catalogue
365
- QPixmap pic = sym->getPointSymbolAsPixmap (widthScale,false ,sym->color ());
366
-
367
- painter->save ();
368
- painter->scale (scale,scale);
369
- painter->drawPixmap ( static_cast <int >( (1 .*mMargin +mSymbolWidth /2 )/scale-pic.width ()/2 ),
370
- static_cast <int >( (1 .*localHeight+symbolHeight/2 )/scale-1 .*pic.height ()/2 ),
371
- pic );
372
- painter->restore ();
373
-
374
- } else if ( vector->vectorType () == QGis::Line ) {
375
- painter->drawLine ( mMargin , localHeight+mSymbolHeight /2 ,
376
- mMargin +mSymbolWidth , localHeight+mSymbolHeight /2 );
377
- } else if ( vector->vectorType () == QGis::Polygon ) {
378
- painter->drawRect ( mMargin , localHeight, mSymbolWidth , mSymbolHeight );
379
- }
380
-
381
- // Label
382
- painter->setPen ( mPen );
383
- painter->setFont ( font );
384
- QString lab;
385
- if ( sectionItemsCount == 1 ) {
386
- lab = sectionTitle;
387
- } else {
388
- lab = itemLabels[icnt];
389
- }
361
+ if ( vector->vectorType () == QGis::Point ) {
362
+ double scale = map->symbolScale () * mComposition ->scale ();
363
+
364
+ // Get the picture of appropriate size directly from catalogue
365
+ QPixmap pic = sym->getPointSymbolAsPixmap (widthScale,false ,sym->color ());
366
+
367
+ painter->save ();
368
+ painter->scale (scale,scale);
369
+ painter->drawPixmap ( static_cast <int >( (1 .*mMargin +mSymbolWidth /2 )/scale-pic.width ()/2 ),
370
+ static_cast <int >( (1 .*localHeight+symbolHeight/2 )/scale-1 .*pic.height ()/2 ),
371
+ pic );
372
+ painter->restore ();
373
+
374
+ } else if ( vector->vectorType () == QGis::Line ) {
375
+ painter->drawLine ( mMargin , localHeight+mSymbolHeight /2 ,
376
+ mMargin +mSymbolWidth , localHeight+mSymbolHeight /2 );
377
+ } else if ( vector->vectorType () == QGis::Polygon ) {
378
+ painter->drawRect ( mMargin , localHeight, mSymbolWidth , mSymbolHeight );
379
+ }
380
+
381
+ // Label
382
+ painter->setPen ( mPen );
383
+ painter->setFont ( font );
384
+ QString lab;
385
+ if ( sectionItemsCount == 1 ) {
386
+ lab = sectionTitle;
387
+ } else {
388
+ lab = itemLabels[icnt];
389
+ }
390
390
391
- // drawText (x, y w, h, ...) was cutting last letter (the box was tto small)
392
- QRect br = metrics.boundingRect ( lab );
393
- x = (int ) ( 2 *mMargin + mSymbolWidth );
394
- y = (int ) ( localHeight + symbolHeight/2 + ( metrics.height ()/2 - metrics.descent ()) );
391
+ // drawText (x, y w, h, ...) was cutting last letter (the box was tto small)
392
+ QRect br = metrics.boundingRect ( lab );
393
+ x = (int ) ( 2 *mMargin + mSymbolWidth );
394
+ y = (int ) ( localHeight + symbolHeight/2 + ( metrics.height ()/2 - metrics.descent ()) );
395
395
396
- painter->drawText ( x, y, lab );
396
+ painter->drawText ( x, y, lab );
397
397
398
- int w = 3 *mMargin + mSymbolWidth + metrics.width (lab);
399
- if ( w > width ) width = w;
398
+ int w = 3 *mMargin + mSymbolWidth + metrics.width (lab);
399
+ if ( w > width ) width = w;
400
400
401
- localHeight += symbolHeight;
402
- icnt++;
401
+ localHeight += symbolHeight;
402
+ icnt++;
403
403
}
404
- }
405
- /* add height of section items */
406
- height = groupStartHeight;
407
- for ( int j = 0 ; j < itemHeights.size (); j++ ) {
404
+ }
405
+ /* add height of section items */
406
+ height = groupStartHeight;
407
+ for ( int j = 0 ; j < itemHeights.size (); j++ ) {
408
408
height += mSymbolSpace + itemHeights[j];
409
- }
410
- if ( sectionItemsCount > 1 ) { // add more space to separate section from next item
411
- height += mSymbolSpace ;
412
- }
413
409
}
410
+ if ( sectionItemsCount > 1 ) { // add more space to separate section from next item
411
+ height += mSymbolSpace ;
412
+ }
414
413
}
414
+ }
415
415
416
- height += mMargin ;
416
+ height += mMargin ;
417
417
418
- Q3CanvasRectangle::setSize ( width, height );
418
+ Q3CanvasRectangle::setSize ( width, height );
419
419
420
- if ( !p ) {
421
- delete painter;
422
- delete pixmap;
423
- }
420
+ if ( !p ) {
421
+ delete painter;
422
+ delete pixmap;
423
+ }
424
424
425
- return QRect ( 0 , 0 , width, height);
425
+ return QRect ( 0 , 0 , width, height);
426
426
}
427
427
428
428
void QgsComposerVectorLegend::cache ( void )
0 commit comments