Source
511
511
QColor brushColor = coloredBrush.color();
512
512
linePen.setColor(brushColor);
513
513
p->setPen(linePen);
514
514
// compare then save for next point
515
515
sameBin = (thisbin==lastbin);
516
516
sameLine = sameBin && (thisx > lastx); // for colorized data
517
517
lastbin = thisbin;
518
518
}
519
519
520
520
sameMask = (thismask==lastmask); // only connect same-masked points
521
+
bool secondpoint(i==drawIndex+1), morepoints(i<n-1);
522
+
523
+
double nextx, nexty;
524
+
bool nextmask;
525
+
if (morepoints) {
526
+
m_maskedData->xyAndMaskAt(i+1, nextx, nexty, nextmask);
527
+
}
521
528
522
529
if (drawLine && !thismask) { // connect unflagged pts
523
530
if(drawMaskedLine && !samePen && !diffColorLine)
524
531
p->setPen(m_line.asQPen()); // set pen for unflagged symbols
525
532
if(brect.contains(lastix, lastiy) || brect.contains(thisix, thisiy)) {
526
533
if (m_step) { // need midpoint for step
527
534
if (sameMask && sameLine) { // connect to last point
528
-
int ixdiff(((lastix + thisix)/2) - lastix);
535
+
int ixdiff(((lastix + thisix)/2) - lastix); // midpoint for step
536
+
// 3 lines: last pt to mid; vertical line; mid to this point
529
537
p->drawLine(lastix, lastiy, thisix-ixdiff, lastiy);
530
538
p->drawLine(thisix-ixdiff, lastiy, thisix-ixdiff, thisiy);
531
539
p->drawLine(thisix-ixdiff, thisiy, thisix, thisiy);
532
-
if (i==drawIndex+1) { // also draw leading line for first point
540
+
541
+
if (secondpoint) { // draw leading line for first point in plot
533
542
p->drawLine(lastix-ixdiff, lastiy, lastix, lastiy);
534
543
}
535
-
// peek at next point and draw trailing line
536
-
if ((i<n-1 && (m_coloredData->binAt(i+1) != thisbin)) ||
537
-
(i == n-1)) { // last point
538
-
p->drawLine(thisix, thisiy, thisix+ixdiff, thisiy);
544
+
545
+
// normally, next point draws trailing line for last point unless:
546
+
// 1. this is last point in plot or in this line (bin changes)
547
+
// 2. same bin but mask changes for next point
548
+
if (!morepoints || (morepoints && (m_coloredData->binAt(i+1)!=thisbin))) {
549
+
p->drawLine(thisix, thisiy, thisix+ixdiff, thisiy); // last point
550
+
}
551
+
if ((morepoints && (m_coloredData->binAt(i+1) == thisbin)) &&
552
+
(nextmask != thismask)) {
553
+
p->drawLine(thisix, thisiy, thisix+ixdiff, thisiy); // mask changes
539
554
}
540
555
} else if ((i < n-1) && (m_coloredData->binAt(i+1)==thisbin)) {
541
556
// first point in new line, use next point to draw leading line
542
-
double nextx, nexty;
543
-
bool nextmask;
544
-
m_maskedData->xyAndMaskAt(i+1, nextx, nexty, nextmask);
545
557
if (nextmask==thismask) {
546
558
int nextix(xMap.transform(nextx));
547
559
int ixdiff(((thisix + nextix)/2) - thisix);
548
560
// don't want ix<0
549
561
if (ixdiff > thisix) ixdiff=thisix;
550
562
p->drawLine(thisix-ixdiff, thisiy, thisix, thisiy);
551
563
}
552
564
}
553
565
} else if (sameMask && sameLine) { // connect last point to this point
554
566
p->drawLine(lastix, lastiy, thisix, thisiy);
555
567
}
556
568
}
557
569
} else if(drawMaskedLine && thismask) { // connect flagged points
558
570
if(drawLine && !samePen && !diffColorLine)
559
571
p->setPen(m_maskedLine.asQPen()); // set pen for flagged symbols
560
572
if(brect.contains(lastix, lastiy) || brect.contains(thisix, thisiy)) {
561
-
if (m_maskedStep) { // need midpoint for step
562
-
if (sameMask && sameLine) { // connect to last point
563
-
int ixdiff(((lastix + thisix)/2) - lastix);
573
+
if (m_maskedStep) {
574
+
if (sameMask && sameLine) {
575
+
int ixdiff(((lastix + thisix)/2) - lastix); // midpoint for step
564
576
p->drawLine(lastix, lastiy, thisix-ixdiff, lastiy);
565
577
p->drawLine(thisix-ixdiff, lastiy, thisix-ixdiff, thisiy);
566
578
p->drawLine(thisix-ixdiff, thisiy, thisix, thisiy);
567
-
if (i==drawIndex+1) { // draw leading line for first point
579
+
if (secondpoint) {
568
580
p->drawLine(lastix-ixdiff, lastiy, lastix, lastiy);
569
581
}
570
-
// peek at next point and draw trailing line
571
-
if ((i<n-1 && (m_coloredData->binAt(i+1) != thisbin)) ||
572
-
(i == n-1)) { // last point
582
+
if (!morepoints || (morepoints && (m_coloredData->binAt(i+1)!=thisbin))) {
583
+
p->drawLine(thisix, thisiy, thisix+ixdiff, thisiy);
584
+
}
585
+
if ((morepoints && (m_coloredData->binAt(i+1) == thisbin)) &&
586
+
(nextmask != thismask)) {
573
587
p->drawLine(thisix, thisiy, thisix+ixdiff, thisiy);
574
588
}
575
589
} else if ((i < n-1) && (m_coloredData->binAt(i+1)==thisbin)) {
576
-
// first point in new line, use next point to draw leading line
577
590
double nextx, nexty;
578
591
bool nextmask;
579
592
m_maskedData->xyAndMaskAt(i+1, nextx, nexty, nextmask);
580
593
if (nextmask==thismask) {
581
594
int nextix(xMap.transform(nextx));
582
595
int ixdiff(((thisix + nextix)/2) - thisix);
583
-
// don't want ix<0
584
596
if (ixdiff > thisix) ixdiff=thisix;
585
597
p->drawLine(thisix-ixdiff, thisiy, thisix, thisiy);
586
598
}
587
599
}
588
600
} else if (sameMask && sameLine) { // connect last point to this point
589
601
p->drawLine(lastix, lastiy, thisix, thisiy);
590
602
}
591
603
}
592
604
}
593
605
}