comparison layer/TimeValueLayer.cpp @ 632:9d8f6552014d

Some refinements to drawing values in place of absent labels
author Chris Cannam
date Tue, 16 Apr 2013 15:17:33 +0100
parents f69e08be3379
children c6d705bf1672
comparison
equal deleted inserted replaced
631:f69e08be3379 632:9d8f6552014d
40 #include <QInputDialog> 40 #include <QInputDialog>
41 41
42 #include <iostream> 42 #include <iostream>
43 #include <cmath> 43 #include <cmath>
44 44
45 #define DEBUG_TIME_VALUE_LAYER 1 45 //#define DEBUG_TIME_VALUE_LAYER 1
46 46
47 TimeValueLayer::TimeValueLayer() : 47 TimeValueLayer::TimeValueLayer() :
48 SingleColourLayer(), 48 SingleColourLayer(),
49 m_model(0), 49 m_model(0),
50 m_editing(false), 50 m_editing(false),
761 max = 1.0; 761 max = 1.0;
762 762
763 } else { 763 } else {
764 764
765 getDisplayExtents(min, max); 765 getDisplayExtents(min, max);
766 766
767 if (m_verticalScale == LogScale) { 767 if (m_verticalScale == LogScale) {
768 LogRange::mapRange(min, max); 768 LogRange::mapRange(min, max);
769 log = true; 769 log = true;
770 } 770 }
771 } 771 }
1080 } else if (m_plotStyle == PlotLines) { 1080 } else if (m_plotStyle == PlotLines) {
1081 1081
1082 if (pointCount == 0) { 1082 if (pointCount == 0) {
1083 path.moveTo(x + w/2, y); 1083 path.moveTo(x + w/2, y);
1084 } 1084 }
1085 ++pointCount;
1086 1085
1087 // paint.drawLine(x + w/2, y, nx + w/2, ny); 1086 // paint.drawLine(x + w/2, y, nx + w/2, ny);
1088 path.lineTo(nx + w/2, ny); 1087 path.lineTo(nx + w/2, ny);
1089 1088
1090 } else { 1089 } else {
1104 } 1103 }
1105 1104
1106 if (pointCount == 0 || gap) { 1105 if (pointCount == 0 || gap) {
1107 path.moveTo((x0 + x1) / 2, (y0 + y1) / 2); 1106 path.moveTo((x0 + x1) / 2, (y0 + y1) / 2);
1108 } 1107 }
1109 ++pointCount;
1110 1108
1111 if (nx - x > 5) { 1109 if (nx - x > 5) {
1112 path.cubicTo(x0, y0, 1110 path.cubicTo(x0, y0,
1113 x0, y0, 1111 x0, y0,
1114 (x0 + x1) / 2, (y0 + y1) / 2); 1112 (x0 + x1) / 2, (y0 + y1) / 2);
1149 1147
1150 if (label == "" && 1148 if (label == "" &&
1151 (m_plotStyle == PlotPoints || 1149 (m_plotStyle == PlotPoints ||
1152 m_plotStyle == PlotSegmentation || 1150 m_plotStyle == PlotSegmentation ||
1153 m_plotStyle == PlotConnectedPoints)) { 1151 m_plotStyle == PlotConnectedPoints)) {
1154 label = QString("%1").arg(p.value); 1152 char lc[20];
1153 snprintf(lc, 20, "%.3g", p.value);
1154 label = lc;
1155 italic = true; 1155 italic = true;
1156 } 1156 }
1157 1157
1158 if (label != "") { 1158 if (label != "") {
1159 if (!haveNext || nx > x + 6 + paint.fontMetrics().width(label)) { 1159 bool haveRoom = nx > x + 6 + paint.fontMetrics().width(label);
1160 if (haveRoom ||
1161 (!haveNext &&
1162 (pointCount == 0 || !italic))) {
1160 v->drawVisibleText(paint, x + 5, textY, label, 1163 v->drawVisibleText(paint, x + 5, textY, label,
1161 italic ? 1164 italic ?
1162 View::OutlinedItalicText : 1165 View::OutlinedItalicText :
1163 View::OutlinedText); 1166 View::OutlinedText);
1164 } 1167 }
1165 } 1168 }
1166 1169
1167 prevFrame = p.frame; 1170 prevFrame = p.frame;
1171 ++pointCount;
1168 } 1172 }
1169 1173
1170 if ((m_plotStyle == PlotCurve || m_plotStyle == PlotDiscreteCurves || 1174 if ((m_plotStyle == PlotCurve || m_plotStyle == PlotDiscreteCurves ||
1171 m_plotStyle == PlotLines) 1175 m_plotStyle == PlotLines)
1172 && !path.isEmpty()) { 1176 && !path.isEmpty()) {