|
@@
-507,132
+507,159
void QLegend::updateLayout()
|
|
507
|
return;
|
|
507
|
return;
|
|
508
|
}
|
|
508
|
}
|
|
509
|
|
|
509
|
|
|
510
|
// Find out widest item.
|
|
|
|
|
511
|
QSizeF markerMaxSize = maximumMarkerSize();
|
|
|
|
|
512
|
checkFirstMarkerBounds();
|
|
510
|
checkFirstMarkerBounds();
|
|
513
|
|
|
511
|
|
|
514
|
// Use max height as scroll button size
|
|
|
|
|
515
|
rescaleScrollButtons(QSize(markerMaxSize.height() ,markerMaxSize.height()));
|
|
|
|
|
516
|
|
|
|
|
|
517
|
qreal totalWidth = 0;
|
|
|
|
|
518
|
qreal totalHeight = 0;
|
|
|
|
|
519
|
switch (m_alignment)
|
|
512
|
switch (m_alignment)
|
|
520
|
{
|
|
513
|
{
|
|
521
|
// Both cases organise items horizontally
|
|
514
|
// Both cases organise items horizontally
|
|
522
|
case QLegend::AlignmentBottom:
|
|
515
|
case QLegend::AlignmentBottom:
|
|
523
|
case QLegend::AlignmentTop: {
|
|
516
|
case QLegend::AlignmentTop: {
|
|
|
|
|
517
|
layoutHorizontal();
|
|
|
|
|
518
|
break;
|
|
|
|
|
519
|
}
|
|
|
|
|
520
|
// Both cases organize items vertically
|
|
|
|
|
521
|
case QLegend::AlignmentLeft:
|
|
|
|
|
522
|
case QLegend::AlignmentRight: {
|
|
|
|
|
523
|
layoutVertical();
|
|
|
|
|
524
|
break;
|
|
|
|
|
525
|
}
|
|
|
|
|
526
|
default: {
|
|
|
|
|
527
|
break;
|
|
|
|
|
528
|
}
|
|
|
|
|
529
|
}
|
|
524
|
|
|
530
|
|
|
525
|
qreal xStep = markerMaxSize.width();
|
|
531
|
}
|
|
526
|
qreal x = m_pos.x() + m_margin;
|
|
|
|
|
527
|
qreal y = m_pos.y() + m_margin;
|
|
|
|
|
528
|
int column = 0;
|
|
|
|
|
529
|
int maxColumns = 1;
|
|
|
|
|
530
|
qreal scrollButtonWidth = 0;
|
|
|
|
|
531
|
|
|
532
|
|
|
532
|
// Set correct visibility for scroll scrollbuttons
|
|
533
|
/*!
|
|
533
|
if (scrollButtonsVisible()) {
|
|
534
|
\internal Organizes markers horizontally.
|
|
534
|
m_scrollButtonLeft->setVisible(true);
|
|
535
|
Causes legend to be resized.
|
|
535
|
m_scrollButtonRight->setVisible(true);
|
|
536
|
*/
|
|
536
|
// scrollbuttons visible, so add their width to total width
|
|
537
|
void QLegend::layoutHorizontal()
|
|
537
|
totalWidth += (m_scrollButtonLeft->boundingRect().width() + m_margin) * 2;
|
|
538
|
{
|
|
538
|
scrollButtonWidth = m_scrollButtonLeft->boundingRect().width() + m_margin;
|
|
539
|
// Find out widest item.
|
|
539
|
// start position changes by scrollbutton width
|
|
540
|
QSizeF markerMaxSize = maximumMarkerSize();
|
|
540
|
x += scrollButtonWidth;
|
|
541
|
// Use max height as scroll button size
|
|
541
|
} else {
|
|
542
|
rescaleScrollButtons(QSize(markerMaxSize.height() ,markerMaxSize.height()));
|
|
542
|
m_scrollButtonLeft->setVisible(false);
|
|
543
|
|
|
543
|
m_scrollButtonRight->setVisible(false);
|
|
544
|
qreal totalWidth = 0;
|
|
544
|
}
|
|
545
|
qreal totalHeight = 0;
|
|
545
|
m_scrollButtonUp->setVisible(false);
|
|
546
|
|
|
546
|
m_scrollButtonDown->setVisible(false);
|
|
547
|
qreal xStep = markerMaxSize.width();
|
|
|
|
|
548
|
qreal x = m_pos.x() + m_margin;
|
|
|
|
|
549
|
qreal y = m_pos.y() + m_margin;
|
|
|
|
|
550
|
int column = 0;
|
|
|
|
|
551
|
int maxColumns = 1;
|
|
|
|
|
552
|
qreal scrollButtonWidth = 0;
|
|
|
|
|
553
|
|
|
|
|
|
554
|
// Set correct visibility for scroll scrollbuttons
|
|
|
|
|
555
|
if (scrollButtonsVisible()) {
|
|
|
|
|
556
|
m_scrollButtonLeft->setVisible(true);
|
|
|
|
|
557
|
m_scrollButtonRight->setVisible(true);
|
|
|
|
|
558
|
// scrollbuttons visible, so add their width to total width
|
|
|
|
|
559
|
totalWidth += (m_scrollButtonLeft->boundingRect().width() + m_margin) * 2;
|
|
|
|
|
560
|
scrollButtonWidth = m_scrollButtonLeft->boundingRect().width() + m_margin;
|
|
|
|
|
561
|
// start position changes by scrollbutton width
|
|
|
|
|
562
|
x += scrollButtonWidth;
|
|
|
|
|
563
|
} else {
|
|
|
|
|
564
|
m_scrollButtonLeft->setVisible(false);
|
|
|
|
|
565
|
m_scrollButtonRight->setVisible(false);
|
|
|
|
|
566
|
}
|
|
|
|
|
567
|
m_scrollButtonUp->setVisible(false);
|
|
|
|
|
568
|
m_scrollButtonDown->setVisible(false);
|
|
547
|
|
|
569
|
|
|
548
|
for (int i=0; i < m_markers.count(); i++) {
|
|
570
|
for (int i=0; i < m_markers.count(); i++) {
|
|
549
|
LegendMarker *m = m_markers.at(i);
|
|
571
|
LegendMarker *m = m_markers.at(i);
|
|
550
|
if (i < mFirstMarker) {
|
|
572
|
if (i < mFirstMarker) {
|
|
551
|
// Markers before first are not visible.
|
|
573
|
// Markers before first are not visible.
|
|
|
|
|
574
|
m->setVisible(false);
|
|
|
|
|
575
|
} else {
|
|
|
|
|
576
|
if ((x + xStep + scrollButtonWidth + m_margin) > (m_pos.x() + m_maximumSize.width())) {
|
|
|
|
|
577
|
// This marker would go outside legend rect.
|
|
552
|
m->setVisible(false);
|
|
578
|
m->setVisible(false);
|
|
553
|
} else {
|
|
579
|
} else {
|
|
554
|
if ((x + xStep + scrollButtonWidth + m_margin) > (m_pos.x() + m_maximumSize.width())) {
|
|
580
|
// This marker is ok
|
|
555
|
// This marker would go outside legend rect.
|
|
581
|
m->setVisible(true);
|
|
556
|
m->setVisible(false);
|
|
582
|
m->setPos(x, y);
|
|
557
|
} else {
|
|
583
|
x += xStep;
|
|
558
|
// This marker is ok
|
|
584
|
column++;
|
|
559
|
m->setVisible(true);
|
|
|
|
|
560
|
m->setPos(x, y);
|
|
|
|
|
561
|
x += xStep;
|
|
|
|
|
562
|
column++;
|
|
|
|
|
563
|
}
|
|
|
|
|
564
|
}
|
|
585
|
}
|
|
565
|
maxColumns = column;
|
|
|
|
|
566
|
}
|
|
586
|
}
|
|
|
|
|
587
|
maxColumns = column;
|
|
|
|
|
588
|
}
|
|
567
|
|
|
589
|
|
|
568
|
m_scrollButtonLeft->setPos(m_pos.x() + m_margin, y);
|
|
590
|
m_scrollButtonLeft->setPos(m_pos.x() + m_margin, y);
|
|
569
|
m_scrollButtonRight->setPos(x + m_margin, y);
|
|
591
|
m_scrollButtonRight->setPos(x + m_margin, y);
|
|
570
|
|
|
592
|
|
|
571
|
totalWidth += maxColumns * markerMaxSize.width() + m_margin * 2;
|
|
593
|
totalWidth += maxColumns * markerMaxSize.width() + m_margin * 2;
|
|
572
|
totalHeight = markerMaxSize.height() + m_margin * 2;
|
|
594
|
totalHeight = markerMaxSize.height() + m_margin * 2;
|
|
573
|
|
|
595
|
|
|
574
|
break;
|
|
596
|
m_size.setWidth(totalWidth);
|
|
|
|
|
597
|
m_size.setHeight(totalHeight);
|
|
|
|
|
598
|
}
|
|
|
|
|
599
|
|
|
|
|
|
600
|
/*!
|
|
|
|
|
601
|
\internal Organizes markers vertically.
|
|
|
|
|
602
|
Causes legend to be resized.
|
|
|
|
|
603
|
*/
|
|
|
|
|
604
|
void QLegend::layoutVertical()
|
|
|
|
|
605
|
{
|
|
|
|
|
606
|
// Find out widest item.
|
|
|
|
|
607
|
QSizeF markerMaxSize = maximumMarkerSize();
|
|
|
|
|
608
|
// Use max height as scroll button size
|
|
|
|
|
609
|
rescaleScrollButtons(QSize(markerMaxSize.height() ,markerMaxSize.height()));
|
|
|
|
|
610
|
|
|
|
|
|
611
|
qreal totalWidth = 0;
|
|
|
|
|
612
|
qreal totalHeight = 0;
|
|
|
|
|
613
|
|
|
|
|
|
614
|
qreal yStep = markerMaxSize.height();
|
|
|
|
|
615
|
qreal x = m_pos.x() + m_margin;
|
|
|
|
|
616
|
qreal y = m_pos.y() + m_margin;
|
|
|
|
|
617
|
int row = 1;
|
|
|
|
|
618
|
int maxRows = 1;
|
|
|
|
|
619
|
qreal scrollButtonHeight = 0;
|
|
|
|
|
620
|
|
|
|
|
|
621
|
// Set correct visibility for scroll scrollbuttons
|
|
|
|
|
622
|
if (scrollButtonsVisible()) {
|
|
|
|
|
623
|
m_scrollButtonUp->setVisible(true);
|
|
|
|
|
624
|
m_scrollButtonDown->setVisible(true);
|
|
|
|
|
625
|
totalHeight += (m_scrollButtonUp->boundingRect().height() + m_margin) * 2; // scrollbuttons visible, so add their height to total height
|
|
|
|
|
626
|
scrollButtonHeight = m_scrollButtonUp->boundingRect().height();
|
|
|
|
|
627
|
y += scrollButtonHeight + m_margin; // start position changes by scrollbutton height
|
|
|
|
|
628
|
} else {
|
|
|
|
|
629
|
m_scrollButtonUp->setVisible(false);
|
|
|
|
|
630
|
m_scrollButtonDown->setVisible(false);
|
|
575
|
}
|
|
631
|
}
|
|
576
|
// Both cases organize items vertically
|
|
632
|
m_scrollButtonLeft->setVisible(false);
|
|
577
|
case QLegend::AlignmentLeft:
|
|
633
|
m_scrollButtonRight->setVisible(false);
|
|
578
|
case QLegend::AlignmentRight: {
|
|
|
|
|
579
|
qreal yStep = markerMaxSize.height();
|
|
|
|
|
580
|
qreal x = m_pos.x() + m_margin;
|
|
|
|
|
581
|
qreal y = m_pos.y() + m_margin;
|
|
|
|
|
582
|
int row = 1;
|
|
|
|
|
583
|
int maxRows = 1;
|
|
|
|
|
584
|
qreal scrollButtonHeight = 0;
|
|
|
|
|
585
|
|
|
|
|
|
586
|
// Set correct visibility for scroll scrollbuttons
|
|
|
|
|
587
|
if (scrollButtonsVisible()) {
|
|
|
|
|
588
|
m_scrollButtonUp->setVisible(true);
|
|
|
|
|
589
|
m_scrollButtonDown->setVisible(true);
|
|
|
|
|
590
|
totalHeight += (m_scrollButtonUp->boundingRect().height() + m_margin) * 2; // scrollbuttons visible, so add their height to total height
|
|
|
|
|
591
|
scrollButtonHeight = m_scrollButtonUp->boundingRect().height();
|
|
|
|
|
592
|
y += scrollButtonHeight + m_margin; // start position changes by scrollbutton height
|
|
|
|
|
593
|
} else {
|
|
|
|
|
594
|
m_scrollButtonUp->setVisible(false);
|
|
|
|
|
595
|
m_scrollButtonDown->setVisible(false);
|
|
|
|
|
596
|
}
|
|
|
|
|
597
|
m_scrollButtonLeft->setVisible(false);
|
|
|
|
|
598
|
m_scrollButtonRight->setVisible(false);
|
|
|
|
|
599
|
|
|
634
|
|
|
600
|
for (int i=0; i < m_markers.count(); i++) {
|
|
635
|
for (int i=0; i < m_markers.count(); i++) {
|
|
601
|
LegendMarker* m = m_markers.at(i);
|
|
636
|
LegendMarker* m = m_markers.at(i);
|
|
602
|
if (i < mFirstMarker) {
|
|
637
|
if (i < mFirstMarker) {
|
|
603
|
// Markers before first are not visible.
|
|
638
|
// Markers before first are not visible.
|
|
|
|
|
639
|
m->setVisible(false);
|
|
|
|
|
640
|
} else {
|
|
|
|
|
641
|
if ((y + yStep + scrollButtonHeight) > (m_pos.y() + m_maximumSize.height())) {
|
|
|
|
|
642
|
// This marker would go outside legend rect.
|
|
604
|
m->setVisible(false);
|
|
643
|
m->setVisible(false);
|
|
605
|
} else {
|
|
644
|
} else {
|
|
606
|
if ((y + yStep + scrollButtonHeight) > (m_pos.y() + m_maximumSize.height())) {
|
|
645
|
// This marker is ok
|
|
607
|
// This marker would go outside legend rect.
|
|
646
|
m->setVisible(true);
|
|
608
|
m->setVisible(false);
|
|
647
|
m->setPos(x, y);
|
|
609
|
} else {
|
|
648
|
y += yStep;
|
|
610
|
// This marker is ok
|
|
649
|
row++;
|
|
611
|
m->setVisible(true);
|
|
|
|
|
612
|
m->setPos(x, y);
|
|
|
|
|
613
|
y += yStep;
|
|
|
|
|
614
|
row++;
|
|
|
|
|
615
|
}
|
|
|
|
|
616
|
}
|
|
650
|
}
|
|
617
|
maxRows = row;
|
|
|
|
|
618
|
}
|
|
651
|
}
|
|
|
|
|
652
|
maxRows = row;
|
|
|
|
|
653
|
}
|
|
619
|
|
|
654
|
|
|
620
|
m_scrollButtonUp->setPos(m_pos.x() + m_margin, m_pos.y() + m_margin);
|
|
655
|
m_scrollButtonUp->setPos(m_pos.x() + m_margin, m_pos.y() + m_margin);
|
|
621
|
m_scrollButtonDown->setPos(m_pos.x() + m_margin, y + m_margin);
|
|
656
|
m_scrollButtonDown->setPos(m_pos.x() + m_margin, y + m_margin);
|
|
622
|
|
|
657
|
|
|
623
|
totalWidth += markerMaxSize.width() + m_margin * 2;
|
|
658
|
totalWidth += markerMaxSize.width() + m_margin * 2;
|
|
624
|
totalHeight = maxRows * markerMaxSize.height() + m_margin * 4 + scrollButtonHeight; // TODO: check this
|
|
659
|
totalHeight = maxRows * markerMaxSize.height() + m_margin * 4 + scrollButtonHeight; // TODO: check this
|
|
625
|
break;
|
|
|
|
|
626
|
}
|
|
|
|
|
627
|
default: {
|
|
|
|
|
628
|
break;
|
|
|
|
|
629
|
}
|
|
|
|
|
630
|
}
|
|
|
|
|
631
|
|
|
660
|
|
|
632
|
m_size.setWidth(totalWidth);
|
|
661
|
m_size.setWidth(totalWidth);
|
|
633
|
m_size.setHeight(totalHeight);
|
|
662
|
m_size.setHeight(totalHeight);
|
|
634
|
|
|
|
|
|
635
|
update();
|
|
|
|
|
636
|
}
|
|
663
|
}
|
|
637
|
|
|
664
|
|
|
638
|
/*!
|
|
665
|
/*!
|