@@ -44,12 +44,17 @@ void QgsLegendRenderer::drawLegend( QPainter *painter )
44
44
paintAndDetermineSize ( painter );
45
45
}
46
46
47
-
48
47
QSizeF QgsLegendRenderer::paintAndDetermineSize ( QPainter *painter )
48
+ {
49
+ return paintAndDetermineSizeInternal ( nullptr , painter );
50
+ }
51
+
52
+ QSizeF QgsLegendRenderer::paintAndDetermineSizeInternal ( QgsRenderContext *context, QPainter *painter )
49
53
{
50
54
QSizeF size ( 0 , 0 );
51
55
QgsLayerTreeGroup *rootGroup = mLegendModel ->rootGroup ();
52
- if ( !rootGroup ) return size;
56
+ if ( !rootGroup )
57
+ return size;
53
58
54
59
QList<Atom> atomList = createAtomList ( rootGroup, mSettings .splitLayer () );
55
60
@@ -98,7 +103,8 @@ QSizeF QgsLegendRenderer::paintAndDetermineSize( QPainter *painter )
98
103
point.ry () += spaceAboveAtom ( atom );
99
104
}
100
105
101
- QSizeF atomSize = drawAtom ( atom, painter, point );
106
+ QSizeF atomSize = context ? drawAtom ( atom, context, point )
107
+ : drawAtom ( atom, painter, point );
102
108
columnWidth = std::max ( atomSize.width (), columnWidth );
103
109
104
110
point.ry () += atom.size .height ();
@@ -139,7 +145,10 @@ QSizeF QgsLegendRenderer::paintAndDetermineSize( QPainter *painter )
139
145
point.rx () = size.width () - mSettings .boxSpace ();
140
146
}
141
147
point.ry () = mSettings .boxSpace ();
142
- drawTitle ( painter, point, mSettings .titleAlignment (), size.width () );
148
+ if ( context )
149
+ drawTitle ( context, point, mSettings .titleAlignment (), size.width () );
150
+ else
151
+ drawTitle ( painter, point, mSettings .titleAlignment (), size.width () );
143
152
}
144
153
145
154
return size;
@@ -355,8 +364,12 @@ void QgsLegendRenderer::setColumns( QList<Atom> &atomList )
355
364
}
356
365
}
357
366
358
-
359
367
QSizeF QgsLegendRenderer::drawTitle ( QPainter *painter, QPointF point, Qt::AlignmentFlag halignment, double legendWidth )
368
+ {
369
+ return drawTitleInternal ( nullptr , painter, point, halignment, legendWidth );
370
+ }
371
+
372
+ QSizeF QgsLegendRenderer::drawTitleInternal ( QgsRenderContext *context, QPainter *painter, QPointF point, Qt::AlignmentFlag halignment, double legendWidth )
360
373
{
361
374
QSizeF size ( 0 , 0 );
362
375
if ( mSettings .title ().isEmpty () )
@@ -367,7 +380,11 @@ QSizeF QgsLegendRenderer::drawTitle( QPainter *painter, QPointF point, Qt::Align
367
380
QStringList lines = mSettings .splitStringForWrapping ( mSettings .title () );
368
381
double y = point.y ();
369
382
370
- if ( painter )
383
+ if ( context )
384
+ {
385
+ context->painter ()->setPen ( mSettings .fontColor () );
386
+ }
387
+ else if ( painter )
371
388
{
372
389
painter->setPen ( mSettings .fontColor () );
373
390
}
@@ -403,7 +420,11 @@ QSizeF QgsLegendRenderer::drawTitle( QPainter *painter, QPointF point, Qt::Align
403
420
404
421
QRectF r ( textBoxLeft, y, textBoxWidth, height );
405
422
406
- if ( painter )
423
+ if ( context->painter () )
424
+ {
425
+ mSettings .drawText ( context->painter (), r, *titlePart, titleFont, halignment, Qt::AlignVCenter, Qt::TextDontClip );
426
+ }
427
+ else if ( painter )
407
428
{
408
429
mSettings .drawText ( painter, r, *titlePart, titleFont, halignment, Qt::AlignVCenter, Qt::TextDontClip );
409
430
}
@@ -449,6 +470,11 @@ double QgsLegendRenderer::spaceAboveAtom( const Atom &atom )
449
470
450
471
// Draw atom and expand its size (using actual nucleons labelXOffset)
451
472
QSizeF QgsLegendRenderer::drawAtom ( const Atom &atom, QPainter *painter, QPointF point )
473
+ {
474
+ return drawAtomInteral ( atom, nullptr , painter, point );
475
+ }
476
+
477
+ QSizeF QgsLegendRenderer::drawAtomInteral ( const Atom &atom, QgsRenderContext *context, QPainter *painter, QPointF point )
452
478
{
453
479
bool first = true ;
454
480
QSizeF size = QSizeF ( atom.size );
@@ -463,7 +489,10 @@ QSizeF QgsLegendRenderer::drawAtom( const Atom &atom, QPainter *painter, QPointF
463
489
{
464
490
point.ry () += mSettings .style ( s ).margin ( QgsLegendStyle::Top );
465
491
}
466
- drawGroupTitle ( groupItem, painter, point );
492
+ if ( context )
493
+ drawGroupTitle ( groupItem, context, point );
494
+ else
495
+ drawGroupTitle ( groupItem, painter, point );
467
496
}
468
497
}
469
498
else if ( QgsLayerTreeLayer *layerItem = qobject_cast<QgsLayerTreeLayer *>( nucleon.item ) )
@@ -475,7 +504,10 @@ QSizeF QgsLegendRenderer::drawAtom( const Atom &atom, QPainter *painter, QPointF
475
504
{
476
505
point.ry () += mSettings .style ( s ).margin ( QgsLegendStyle::Top );
477
506
}
478
- drawLayerTitle ( layerItem, painter, point );
507
+ if ( context )
508
+ drawLayerTitle ( layerItem, context, point );
509
+ else
510
+ drawLayerTitle ( layerItem, painter, point );
479
511
}
480
512
}
481
513
else if ( QgsLayerTreeModelLegendNode *legendNode = qobject_cast<QgsLayerTreeModelLegendNode *>( nucleon.item ) )
@@ -485,7 +517,8 @@ QSizeF QgsLegendRenderer::drawAtom( const Atom &atom, QPainter *painter, QPointF
485
517
point.ry () += mSettings .style ( QgsLegendStyle::Symbol ).margin ( QgsLegendStyle::Top );
486
518
}
487
519
488
- Nucleon symbolNucleon = drawSymbolItem ( legendNode, painter, point, nucleon.labelXOffset );
520
+ Nucleon symbolNucleon = context ? drawSymbolItem ( legendNode, context, point, nucleon.labelXOffset )
521
+ : drawSymbolItem ( legendNode, painter, point, nucleon.labelXOffset );
489
522
// expand width, it may be wider because of labelXOffset
490
523
size.rwidth () = std::max ( symbolNucleon.size .width (), size.width () );
491
524
}
@@ -495,15 +528,20 @@ QSizeF QgsLegendRenderer::drawAtom( const Atom &atom, QPainter *painter, QPointF
495
528
return size;
496
529
}
497
530
498
-
499
531
QgsLegendRenderer::Nucleon QgsLegendRenderer::drawSymbolItem ( QgsLayerTreeModelLegendNode *symbolItem, QPainter *painter, QPointF point, double labelXOffset )
532
+ {
533
+ return drawSymbolItemInternal ( symbolItem, nullptr , painter, point, labelXOffset );
534
+ }
535
+
536
+ QgsLegendRenderer::Nucleon QgsLegendRenderer::drawSymbolItemInternal ( QgsLayerTreeModelLegendNode *symbolItem, QgsRenderContext *context, QPainter *painter, QPointF point, double labelXOffset )
500
537
{
501
538
QgsLayerTreeModelLegendNode::ItemContext ctx;
502
- ctx.painter = painter;
539
+ ctx.painter = context ? context-> painter () : painter;
503
540
ctx.point = point;
504
541
ctx.labelXOffset = labelXOffset;
505
542
506
- QgsLayerTreeModelLegendNode::ItemMetrics im = symbolItem->draw ( mSettings , painter ? &ctx : nullptr );
543
+ QgsLayerTreeModelLegendNode::ItemMetrics im = symbolItem->draw ( mSettings , context ? &ctx
544
+ : ( painter ? &ctx : nullptr ) );
507
545
508
546
Nucleon nucleon;
509
547
nucleon.item = symbolItem;
@@ -516,8 +554,12 @@ QgsLegendRenderer::Nucleon QgsLegendRenderer::drawSymbolItem( QgsLayerTreeModelL
516
554
return nucleon;
517
555
}
518
556
519
-
520
557
QSizeF QgsLegendRenderer::drawLayerTitle ( QgsLayerTreeLayer *nodeLayer, QPainter *painter, QPointF point )
558
+ {
559
+ return drawLayerTitleInternal ( nodeLayer, nullptr , painter, point );
560
+ }
561
+
562
+ QSizeF QgsLegendRenderer::drawLayerTitleInternal ( QgsLayerTreeLayer *nodeLayer, QgsRenderContext *context, QPainter *painter, QPointF point )
521
563
{
522
564
QSizeF size ( 0 , 0 );
523
565
QModelIndex idx = mLegendModel ->node2index ( nodeLayer );
@@ -527,15 +569,21 @@ QSizeF QgsLegendRenderer::drawLayerTitle( QgsLayerTreeLayer *nodeLayer, QPainter
527
569
528
570
double y = point.y ();
529
571
530
- if ( painter ) painter->setPen ( mSettings .fontColor () );
572
+ if ( context && context->painter () )
573
+ context->painter ()->setPen ( mSettings .fontColor () );
574
+ else if ( painter )
575
+ painter->setPen ( mSettings .fontColor () );
531
576
532
577
QFont layerFont = mSettings .style ( nodeLegendStyle ( nodeLayer ) ).font ();
533
578
534
579
QStringList lines = mSettings .splitStringForWrapping ( mLegendModel ->data ( idx, Qt::DisplayRole ).toString () );
535
580
for ( QStringList::Iterator layerItemPart = lines.begin (); layerItemPart != lines.end (); ++layerItemPart )
536
581
{
537
582
y += mSettings .fontAscentMillimeters ( layerFont );
538
- if ( painter ) mSettings .drawText ( painter, point.x (), y, *layerItemPart, layerFont );
583
+ if ( context && context->painter () )
584
+ mSettings .drawText ( context->painter (), point.x (), y, *layerItemPart, layerFont );
585
+ if ( painter )
586
+ mSettings .drawText ( painter, point.x (), y, *layerItemPart, layerFont );
539
587
qreal width = mSettings .textWidthMillimeters ( layerFont, *layerItemPart );
540
588
size.rwidth () = std::max ( width, size.width () );
541
589
if ( layerItemPart != ( lines.end () - 1 ) )
@@ -549,23 +597,33 @@ QSizeF QgsLegendRenderer::drawLayerTitle( QgsLayerTreeLayer *nodeLayer, QPainter
549
597
return size;
550
598
}
551
599
552
-
553
600
QSizeF QgsLegendRenderer::drawGroupTitle ( QgsLayerTreeGroup *nodeGroup, QPainter *painter, QPointF point )
601
+ {
602
+ return drawGroupTitleInternal ( nodeGroup, nullptr , painter, point );
603
+ }
604
+
605
+ QSizeF QgsLegendRenderer::drawGroupTitleInternal ( QgsLayerTreeGroup *nodeGroup, QgsRenderContext *context, QPainter *painter, QPointF point )
554
606
{
555
607
QSizeF size ( 0 , 0 );
556
608
QModelIndex idx = mLegendModel ->node2index ( nodeGroup );
557
609
558
610
double y = point.y ();
559
611
560
- if ( painter ) painter->setPen ( mSettings .fontColor () );
612
+ if ( context && context->painter () )
613
+ context->painter ()->setPen ( mSettings .fontColor () );
614
+ else if ( painter )
615
+ painter->setPen ( mSettings .fontColor () );
561
616
562
617
QFont groupFont = mSettings .style ( nodeLegendStyle ( nodeGroup ) ).font ();
563
618
564
619
QStringList lines = mSettings .splitStringForWrapping ( mLegendModel ->data ( idx, Qt::DisplayRole ).toString () );
565
620
for ( QStringList::Iterator groupPart = lines.begin (); groupPart != lines.end (); ++groupPart )
566
621
{
567
622
y += mSettings .fontAscentMillimeters ( groupFont );
568
- if ( painter ) mSettings .drawText ( painter, point.x (), y, *groupPart, groupFont );
623
+ if ( context && context->painter () )
624
+ mSettings .drawText ( context->painter (), point.x (), y, *groupPart, groupFont );
625
+ else if ( painter )
626
+ mSettings .drawText ( painter, point.x (), y, *groupPart, groupFont );
569
627
qreal width = mSettings .textWidthMillimeters ( groupFont, *groupPart );
570
628
size.rwidth () = std::max ( width, size.width () );
571
629
if ( groupPart != ( lines.end () - 1 ) )
@@ -577,8 +635,6 @@ QSizeF QgsLegendRenderer::drawGroupTitle( QgsLayerTreeGroup *nodeGroup, QPainter
577
635
return size;
578
636
}
579
637
580
-
581
-
582
638
QgsLegendStyle::Style QgsLegendRenderer::nodeLegendStyle ( QgsLayerTreeNode *node, QgsLayerTreeModel *model )
583
639
{
584
640
QString style = node->customProperty ( QStringLiteral ( " legend/title-style" ) ).toString ();
@@ -631,307 +687,37 @@ void QgsLegendRenderer::setNodeLegendStyle( QgsLayerTreeNode *node, QgsLegendSty
631
687
node->removeCustomProperty ( QStringLiteral ( " legend/title-style" ) );
632
688
}
633
689
634
-
635
- // new version of classes using QgsRenderContext
636
690
QSizeF QgsLegendRenderer::drawTitle ( QgsRenderContext *rendercontext, QPointF point, Qt::AlignmentFlag halignment, double legendWidth )
637
691
{
638
- QSizeF size ( 0 , 0 );
639
- if ( mSettings .title ().isEmpty () )
640
- {
641
- return size;
642
- }
643
-
644
- QStringList lines = mSettings .splitStringForWrapping ( mSettings .title () );
645
- double y = point.y ();
646
-
647
- if ( rendercontext->painter () )
648
- {
649
- rendercontext->painter ()->setPen ( mSettings .fontColor () );
650
- }
651
-
652
- // calculate width and left pos of rectangle to draw text into
653
- double textBoxWidth;
654
- double textBoxLeft;
655
- switch ( halignment )
656
- {
657
- case Qt::AlignHCenter:
658
- textBoxWidth = ( std::min ( static_cast < double >( point.x () ), legendWidth - point.x () ) - mSettings .boxSpace () ) * 2.0 ;
659
- textBoxLeft = point.x () - textBoxWidth / 2 .;
660
- break ;
661
- case Qt::AlignRight:
662
- textBoxLeft = mSettings .boxSpace ();
663
- textBoxWidth = point.x () - mSettings .boxSpace ();
664
- break ;
665
- case Qt::AlignLeft:
666
- default :
667
- textBoxLeft = point.x ();
668
- textBoxWidth = legendWidth - point.x () - mSettings .boxSpace ();
669
- break ;
670
- }
671
-
672
- QFont titleFont = mSettings .style ( QgsLegendStyle::Title ).font ();
673
-
674
- for ( QStringList::Iterator titlePart = lines.begin (); titlePart != lines.end (); ++titlePart )
675
- {
676
- // last word is not drawn if rectangle width is exactly text width, so add 1
677
- // TODO - correctly calculate size of italicized text, since QFontMetrics does not
678
- qreal width = mSettings .textWidthMillimeters ( titleFont, *titlePart ) + 1 ;
679
- qreal height = mSettings .fontAscentMillimeters ( titleFont ) + mSettings .fontDescentMillimeters ( titleFont );
680
-
681
- QRectF r ( textBoxLeft, y, textBoxWidth, height );
682
-
683
- if ( rendercontext->painter () )
684
- {
685
- mSettings .drawText ( rendercontext->painter (), r, *titlePart, titleFont, halignment, Qt::AlignVCenter, Qt::TextDontClip );
686
- }
687
-
688
- // update max width of title
689
- size.rwidth () = std::max ( width, size.rwidth () );
690
-
691
- y += height;
692
- if ( titlePart != ( lines.end () - 1 ) )
693
- {
694
- y += mSettings .lineSpacing ();
695
- }
696
- }
697
- size.rheight () = y - point.y ();
698
-
699
- return size;
692
+ return drawTitleInternal ( rendercontext, nullptr , point, halignment, legendWidth );
700
693
}
701
694
702
-
703
-
704
- // Draw atom and expand its size (using actual nucleons labelXOffset)
705
695
QSizeF QgsLegendRenderer::drawAtom ( const Atom &atom, QgsRenderContext *rendercontext, QPointF point )
706
696
{
707
- bool first = true ;
708
- QSizeF size = QSizeF ( atom.size );
709
- Q_FOREACH ( const Nucleon &nucleon, atom.nucleons )
710
- {
711
- if ( QgsLayerTreeGroup *groupItem = qobject_cast<QgsLayerTreeGroup *>( nucleon.item ) )
712
- {
713
- QgsLegendStyle::Style s = nodeLegendStyle ( groupItem );
714
- if ( s != QgsLegendStyle::Hidden )
715
- {
716
- if ( !first )
717
- {
718
- point.ry () += mSettings .style ( s ).margin ( QgsLegendStyle::Top );
719
- }
720
- drawGroupTitle ( groupItem, rendercontext, point );
721
- }
722
- }
723
- else if ( QgsLayerTreeLayer *layerItem = qobject_cast<QgsLayerTreeLayer *>( nucleon.item ) )
724
- {
725
- QgsLegendStyle::Style s = nodeLegendStyle ( layerItem );
726
- if ( s != QgsLegendStyle::Hidden )
727
- {
728
- if ( !first )
729
- {
730
- point.ry () += mSettings .style ( s ).margin ( QgsLegendStyle::Top );
731
- }
732
- drawLayerTitle ( layerItem, rendercontext, point );
733
- }
734
- }
735
- else if ( QgsLayerTreeModelLegendNode *legendNode = qobject_cast<QgsLayerTreeModelLegendNode *>( nucleon.item ) )
736
- {
737
- if ( !first )
738
- {
739
- point.ry () += mSettings .style ( QgsLegendStyle::Symbol ).margin ( QgsLegendStyle::Top );
740
- }
741
-
742
- Nucleon symbolNucleon = drawSymbolItem ( legendNode, rendercontext, point, nucleon.labelXOffset );
743
- // expand width, it may be wider because of labelXOffset
744
- size.rwidth () = std::max ( symbolNucleon.size .width (), size.width () );
745
- }
746
- point.ry () += nucleon.size .height ();
747
- first = false ;
748
- }
749
- return size;
697
+ return drawAtomInteral ( atom, rendercontext, nullptr , point );
750
698
}
751
699
752
-
753
700
QgsLegendRenderer::Nucleon QgsLegendRenderer::drawSymbolItem ( QgsLayerTreeModelLegendNode *symbolItem, QgsRenderContext *rendercontext, QPointF point, double labelXOffset )
754
701
{
755
- QgsLayerTreeModelLegendNode::ItemContext ctx;
756
- ctx.painter = rendercontext->painter ();
757
- ctx.point = point;
758
- ctx.labelXOffset = labelXOffset;
759
-
760
- QgsLayerTreeModelLegendNode::ItemMetrics im = symbolItem->draw ( mSettings , rendercontext ? &ctx : nullptr );
761
-
762
- Nucleon nucleon;
763
- nucleon.item = symbolItem;
764
- nucleon.symbolSize = im.symbolSize ;
765
- nucleon.labelSize = im.labelSize ;
766
- // QgsDebugMsg( QStringLiteral( "symbol height = %1 label height = %2").arg( symbolSize.height()).arg( labelSize.height() ));
767
- double width = std::max ( static_cast < double >( im.symbolSize .width () ), labelXOffset ) + im.labelSize .width ();
768
- double height = std::max ( im.symbolSize .height (), im.labelSize .height () );
769
- nucleon.size = QSizeF ( width, height );
770
- return nucleon;
702
+ return drawSymbolItemInternal ( symbolItem, rendercontext, nullptr , point, labelXOffset );
771
703
}
772
704
773
-
774
705
QSizeF QgsLegendRenderer::drawLayerTitle ( QgsLayerTreeLayer *nodeLayer, QgsRenderContext *rendercontext, QPointF point )
775
706
{
776
- QSizeF size ( 0 , 0 );
777
- QModelIndex idx = mLegendModel ->node2index ( nodeLayer );
778
-
779
- // Let the user omit the layer title item by having an empty layer title string
780
- if ( mLegendModel ->data ( idx, Qt::DisplayRole ).toString ().isEmpty () ) return size;
781
-
782
- double y = point.y ();
783
-
784
- if ( rendercontext->painter () ) rendercontext->painter ()->setPen ( mSettings .fontColor () );
785
-
786
- QFont layerFont = mSettings .style ( nodeLegendStyle ( nodeLayer ) ).font ();
787
-
788
- QStringList lines = mSettings .splitStringForWrapping ( mLegendModel ->data ( idx, Qt::DisplayRole ).toString () );
789
- for ( QStringList::Iterator layerItemPart = lines.begin (); layerItemPart != lines.end (); ++layerItemPart )
790
- {
791
- y += mSettings .fontAscentMillimeters ( layerFont );
792
- if ( rendercontext->painter () ) mSettings .drawText ( rendercontext->painter (), point.x (), y, *layerItemPart, layerFont );
793
- qreal width = mSettings .textWidthMillimeters ( layerFont, *layerItemPart );
794
- size.rwidth () = std::max ( width, size.width () );
795
- if ( layerItemPart != ( lines.end () - 1 ) )
796
- {
797
- y += mSettings .lineSpacing ();
798
- }
799
- }
800
- size.rheight () = y - point.y ();
801
-
802
- return size;
707
+ return drawLayerTitleInternal ( nodeLayer, rendercontext, nullptr , point );
803
708
}
804
709
805
-
806
710
QSizeF QgsLegendRenderer::drawGroupTitle ( QgsLayerTreeGroup *nodeGroup, QgsRenderContext *rendercontext, QPointF point )
807
711
{
808
- QSizeF size ( 0 , 0 );
809
- QModelIndex idx = mLegendModel ->node2index ( nodeGroup );
810
-
811
- double y = point.y ();
812
-
813
- if ( rendercontext->painter () ) rendercontext->painter ()->setPen ( mSettings .fontColor () );
814
-
815
- QFont groupFont = mSettings .style ( nodeLegendStyle ( nodeGroup ) ).font ();
816
-
817
- QStringList lines = mSettings .splitStringForWrapping ( mLegendModel ->data ( idx, Qt::DisplayRole ).toString () );
818
- for ( QStringList::Iterator groupPart = lines.begin (); groupPart != lines.end (); ++groupPart )
819
- {
820
- y += mSettings .fontAscentMillimeters ( groupFont );
821
- if ( rendercontext->painter () ) mSettings .drawText ( rendercontext->painter (), point.x (), y, *groupPart, groupFont );
822
- qreal width = mSettings .textWidthMillimeters ( groupFont, *groupPart );
823
- size.rwidth () = std::max ( width, size.width () );
824
- if ( groupPart != ( lines.end () - 1 ) )
825
- {
826
- y += mSettings .lineSpacing ();
827
- }
828
- }
829
- size.rheight () = y - point.y ();
830
- return size;
712
+ return drawGroupTitleInternal ( nodeGroup, rendercontext, nullptr , point );
831
713
}
832
714
833
-
834
715
void QgsLegendRenderer::drawLegend ( QgsRenderContext &context )
835
716
{
836
717
paintAndDetermineSize ( &context );
837
718
}
838
719
839
720
QSizeF QgsLegendRenderer::paintAndDetermineSize ( QgsRenderContext *context )
840
721
{
841
- QSizeF size ( 0 , 0 );
842
- QgsLayerTreeGroup *rootGroup = mLegendModel ->rootGroup ();
843
- if ( !rootGroup ) return size;
844
-
845
- QList<Atom> atomList = createAtomList ( rootGroup, mSettings .splitLayer () );
846
-
847
- setColumns ( atomList );
848
-
849
- qreal maxColumnWidth = 0 ;
850
- if ( mSettings .equalColumnWidth () )
851
- {
852
- Q_FOREACH ( const Atom &atom, atomList )
853
- {
854
- maxColumnWidth = std::max ( atom.size .width (), maxColumnWidth );
855
- }
856
- }
857
-
858
- // calculate size of title
859
- QSizeF titleSize = drawTitle ();
860
- // add title margin to size of title text
861
- titleSize.rwidth () += mSettings .boxSpace () * 2.0 ;
862
- double columnTop = mSettings .boxSpace () + titleSize.height () + mSettings .style ( QgsLegendStyle::Title ).margin ( QgsLegendStyle::Bottom );
863
-
864
- QPointF point ( mSettings .boxSpace (), columnTop );
865
- bool firstInColumn = true ;
866
- double columnMaxHeight = 0 ;
867
- qreal columnWidth = 0 ;
868
- int column = 0 ;
869
- Q_FOREACH ( const Atom &atom, atomList )
870
- {
871
- if ( atom.column > column )
872
- {
873
- // Switch to next column
874
- if ( mSettings .equalColumnWidth () )
875
- {
876
- point.rx () += mSettings .columnSpace () + maxColumnWidth;
877
- }
878
- else
879
- {
880
- point.rx () += mSettings .columnSpace () + columnWidth;
881
- }
882
- point.ry () = columnTop;
883
- columnWidth = 0 ;
884
- column++;
885
- firstInColumn = true ;
886
- }
887
- if ( !firstInColumn )
888
- {
889
- point.ry () += spaceAboveAtom ( atom );
890
- }
891
-
892
- QSizeF atomSize = drawAtom ( atom, context, point );
893
- columnWidth = std::max ( atomSize.width (), columnWidth );
894
-
895
- point.ry () += atom.size .height ();
896
- columnMaxHeight = std::max ( point.y () - columnTop, columnMaxHeight );
897
-
898
- firstInColumn = false ;
899
- }
900
- point.rx () += columnWidth + mSettings .boxSpace ();
901
-
902
- size.rheight () = columnTop + columnMaxHeight + mSettings .boxSpace ();
903
- size.rwidth () = point.x ();
904
- if ( !mSettings .title ().isEmpty () )
905
- {
906
- size.rwidth () = std::max ( titleSize.width (), size.width () );
907
- }
908
-
909
- // override the size if it was set by the user
910
- if ( mLegendSize .isValid () )
911
- {
912
- qreal w = std::max ( size.width (), mLegendSize .width () );
913
- qreal h = std::max ( size.height (), mLegendSize .height () );
914
- size = QSizeF ( w, h );
915
- }
916
-
917
- // Now we have set the correct total item width and can draw the title centered
918
- if ( !mSettings .title ().isEmpty () )
919
- {
920
- if ( mSettings .titleAlignment () == Qt::AlignLeft )
921
- {
922
- point.rx () = mSettings .boxSpace ();
923
- }
924
- else if ( mSettings .titleAlignment () == Qt::AlignHCenter )
925
- {
926
- point.rx () = size.width () / 2 ;
927
- }
928
- else
929
- {
930
- point.rx () = size.width () - mSettings .boxSpace ();
931
- }
932
- point.ry () = mSettings .boxSpace ();
933
- drawTitle ( context, point, mSettings .titleAlignment (), size.width () );
934
- }
935
-
936
- return size;
722
+ return paintAndDetermineSizeInternal ( context, nullptr );
937
723
}
0 commit comments