comparison layer/TimeValueLayer.cpp @ 771:a964151832a7

Merge from branch tony_integration
author Chris Cannam
date Wed, 14 May 2014 09:54:34 +0100
parents b6dc57688c72
children 1d526ba11a24
comparison
equal deleted inserted replaced
768:8b614632568c 771:a964151832a7
970 970
971 for (SparseTimeValueModel::PointList::const_iterator i = points.begin(); 971 for (SparseTimeValueModel::PointList::const_iterator i = points.begin();
972 i != points.end(); ++i) { 972 i != points.end(); ++i) {
973 973
974 if (m_derivative && i == points.begin()) continue; 974 if (m_derivative && i == points.begin()) continue;
975 975
976 const SparseTimeValueModel::Point &p(*i); 976 const SparseTimeValueModel::Point &p(*i);
977 977
978 float value = p.value; 978 float value = p.value;
979 if (m_derivative) { 979 if (m_derivative) {
980 SparseTimeValueModel::PointList::const_iterator j = i; 980 SparseTimeValueModel::PointList::const_iterator j = i;
985 int x = v->getXForFrame(p.frame); 985 int x = v->getXForFrame(p.frame);
986 int y = getYForValue(v, value); 986 int y = getYForValue(v, value);
987 987
988 bool gap = false; 988 bool gap = false;
989 if (m_plotStyle == PlotDiscreteCurves) { 989 if (m_plotStyle == PlotDiscreteCurves) {
990 if (value == 0.0) {
991 // Treat zeros as gaps
992 continue;
993 }
990 gap = (p.frame > prevFrame && 994 gap = (p.frame > prevFrame &&
991 (p.frame - prevFrame >= m_model->getResolution() * 2)); 995 (p.frame - prevFrame >= m_model->getResolution() * 2));
992 } 996 }
993 997
994 if (m_plotStyle != PlotSegmentation) { 998 if (m_plotStyle != PlotSegmentation) {
998 textY = paint.fontMetrics().ascent() + 1; 1002 textY = paint.fontMetrics().ascent() + 1;
999 } 1003 }
1000 } 1004 }
1001 1005
1002 bool haveNext = false; 1006 bool haveNext = false;
1007 float nvalue = 0.f;
1003 int nf = v->getModelsEndFrame(); 1008 int nf = v->getModelsEndFrame();
1004 int nx = v->getXForFrame(nf); 1009 int nx = v->getXForFrame(nf);
1005 int ny = y; 1010 int ny = y;
1006 1011
1007 SparseTimeValueModel::PointList::const_iterator j = i; 1012 SparseTimeValueModel::PointList::const_iterator j = i;
1008 ++j; 1013 ++j;
1009 1014
1010 if (j != points.end()) { 1015 if (j != points.end()) {
1011 const SparseTimeValueModel::Point &q(*j); 1016 const SparseTimeValueModel::Point &q(*j);
1012 float nvalue = q.value; 1017 nvalue = q.value;
1013 if (m_derivative) nvalue -= p.value; 1018 if (m_derivative) nvalue -= p.value;
1014 nf = q.frame; 1019 nf = q.frame;
1015 nx = v->getXForFrame(nf); 1020 nx = v->getXForFrame(nf);
1016 ny = getYForValue(v, nvalue); 1021 ny = getYForValue(v, nvalue);
1017 haveNext = true; 1022 haveNext = true;
1114 1119
1115 float y0 = y; 1120 float y0 = y;
1116 float y1 = ny; 1121 float y1 = ny;
1117 1122
1118 if (m_plotStyle == PlotDiscreteCurves) { 1123 if (m_plotStyle == PlotDiscreteCurves) {
1119 bool nextGap = nf - p.frame >= m_model->getResolution() * 2; 1124 bool nextGap =
1125 (nvalue == 0.0) ||
1126 (nf - p.frame >= m_model->getResolution() * 2);
1120 if (nextGap) { 1127 if (nextGap) {
1121 x1 = x0; 1128 x1 = x0;
1122 y1 = y0; 1129 y1 = y0;
1123 } 1130 }
1124 } 1131 }
1161 } 1168 }
1162 1169
1163 paint.drawRect(x, -1, nx - x, v->height() + 1); 1170 paint.drawRect(x, -1, nx - x, v->height() + 1);
1164 } 1171 }
1165 1172
1166 QString label = p.label; 1173 if (v->shouldShowFeatureLabels()) {
1167 bool italic = false; 1174
1168 1175 QString label = p.label;
1169 if (label == "" && 1176 bool italic = false;
1170 (m_plotStyle == PlotPoints || 1177
1171 m_plotStyle == PlotSegmentation || 1178 if (label == "" &&
1172 m_plotStyle == PlotConnectedPoints)) { 1179 (m_plotStyle == PlotPoints ||
1173 char lc[20]; 1180 m_plotStyle == PlotSegmentation ||
1174 snprintf(lc, 20, "%.3g", p.value); 1181 m_plotStyle == PlotConnectedPoints)) {
1175 label = lc; 1182 char lc[20];
1176 italic = true; 1183 snprintf(lc, 20, "%.3g", p.value);
1177 } 1184 label = lc;
1178 1185 italic = true;
1179 if (label != "") { 1186 }
1180 // Quick test for 20px before we do the slower test using metrics 1187
1181 bool haveRoom = (nx > x + 20); 1188 if (label != "") {
1182 haveRoom = (haveRoom && 1189 // Quick test for 20px before we do the slower test using metrics
1183 (nx > x + 6 + paint.fontMetrics().width(label))); 1190 bool haveRoom = (nx > x + 20);
1184 if (haveRoom || 1191 haveRoom = (haveRoom &&
1185 (!haveNext && 1192 (nx > x + 6 + paint.fontMetrics().width(label)));
1186 (pointCount == 0 || !italic))) { 1193 if (haveRoom ||
1187 v->drawVisibleText(paint, x + 5, textY, label, 1194 (!haveNext &&
1188 italic ? 1195 (pointCount == 0 || !italic))) {
1189 View::OutlinedItalicText : 1196 v->drawVisibleText(paint, x + 5, textY, label,
1190 View::OutlinedText); 1197 italic ?
1191 } 1198 View::OutlinedItalicText :
1192 } 1199 View::OutlinedText);
1200 }
1201 }
1202 }
1193 1203
1194 prevFrame = p.frame; 1204 prevFrame = p.frame;
1195 ++pointCount; 1205 ++pointCount;
1196 } 1206 }
1197 1207
1231 } 1241 }
1232 1242
1233 void 1243 void
1234 TimeValueLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect) const 1244 TimeValueLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect) const
1235 { 1245 {
1236 if (!m_model) return; 1246 if (!m_model || m_model->getPoints().empty()) return;
1237 1247
1238 QString unit; 1248 QString unit;
1239 float min, max; 1249 float min, max;
1240 bool logarithmic; 1250 bool logarithmic;
1241 1251