comparison layer/RegionLayer.cpp @ 1410:d057dcc827e7 fix-static-analysis

Merge from default branch
author Chris Cannam
date Tue, 04 Dec 2018 13:49:09 +0000
parents c8a6fd3f9dff 24234307c9b2
children 2487521e857b
comparison
equal deleted inserted replaced
1408:c8a6fd3f9dff 1410:d057dcc827e7
879 879
880 int x0 = rect.left() - 40, x1 = rect.right(); 880 int x0 = rect.left() - 40, x1 = rect.right();
881 sv_frame_t frame0 = v->getFrameForX(x0); 881 sv_frame_t frame0 = v->getFrameForX(x0);
882 sv_frame_t frame1 = v->getFrameForX(x1); 882 sv_frame_t frame1 = v->getFrameForX(x1);
883 883
884 RegionModel::PointList points(m_model->getPoints(frame0, frame1)); 884 sv_frame_t wholeFrame0 = v->getFrameForX(0);
885 sv_frame_t wholeFrame1 = v->getFrameForX(v->getPaintWidth());
886
887 RegionModel::PointList points(m_model->getPoints(wholeFrame0, wholeFrame1));
885 if (points.empty()) return; 888 if (points.empty()) return;
886 889
887 paint.setPen(getBaseQColor()); 890 paint.setPen(getBaseQColor());
888 891
889 QColor brushColour(getBaseQColor()); 892 QColor brushColour(getBaseQColor());
920 i != points.end(); ++i) { 923 i != points.end(); ++i) {
921 924
922 const RegionModel::Point &p(*i); 925 const RegionModel::Point &p(*i);
923 926
924 int x = v->getXForFrame(p.frame); 927 int x = v->getXForFrame(p.frame);
928 int w = v->getXForFrame(p.frame + p.duration) - x;
925 int y = getYForValue(v, p.value); 929 int y = getYForValue(v, p.value);
926 int w = v->getXForFrame(p.frame + p.duration) - x;
927 int h = 9; 930 int h = 9;
928 int ex = x + w; 931 int ex = x + w;
929 932
933 int gap = v->scalePixelSize(2);
934
930 RegionModel::PointList::const_iterator j = i; 935 RegionModel::PointList::const_iterator j = i;
931 ++j; 936 ++j;
932 937
933 if (j != points.end()) { 938 if (j != points.end()) {
934 const RegionModel::Point &q(*j); 939 const RegionModel::Point &q(*j);
966 971
967 } else { 972 } else {
968 paint.setPen(QPen(getForegroundQColor(v->getView()), 2)); 973 paint.setPen(QPen(getForegroundQColor(v->getView()), 2));
969 } 974 }
970 975
971 paint.drawRect(x, -1, ex - x, v->getPaintHeight() + 2); 976 paint.drawRect(x, -1, ex - x, v->getPaintHeight() + gap);
972 977
973 } else { 978 } else {
974 979
975 if (shouldIlluminate && 980 if (shouldIlluminate &&
976 // "illuminatePoint == p" 981 // "illuminatePoint == p"
980 paint.setPen(v->getForeground()); 985 paint.setPen(v->getForeground());
981 paint.setBrush(v->getForeground()); 986 paint.setBrush(v->getForeground());
982 987
983 QString vlabel = QString("%1%2").arg(p.value).arg(getScaleUnits()); 988 QString vlabel = QString("%1%2").arg(p.value).arg(getScaleUnits());
984 PaintAssistant::drawVisibleText(v, paint, 989 PaintAssistant::drawVisibleText(v, paint,
985 x - paint.fontMetrics().width(vlabel) - 2, 990 x - paint.fontMetrics().width(vlabel) - gap,
986 y + paint.fontMetrics().height()/2 991 y + paint.fontMetrics().height()/2
987 - paint.fontMetrics().descent(), 992 - paint.fontMetrics().descent(),
988 vlabel, PaintAssistant::OutlinedText); 993 vlabel, PaintAssistant::OutlinedText);
989 994
990 QString hlabel = RealTime::frame2RealTime 995 QString hlabel = RealTime::frame2RealTime
991 (p.frame, m_model->getSampleRate()).toText(true).c_str(); 996 (p.frame, m_model->getSampleRate()).toText(true).c_str();
992 PaintAssistant::drawVisibleText(v, paint, 997 PaintAssistant::drawVisibleText(v, paint,
993 x, 998 x,
994 y - h/2 - paint.fontMetrics().descent() - 2, 999 y - h/2 - paint.fontMetrics().descent() - gap,
995 hlabel, PaintAssistant::OutlinedText); 1000 hlabel, PaintAssistant::OutlinedText);
996 } 1001 }
997 1002
998 paint.drawLine(x, y-1, x + w, y-1); 1003 paint.drawLine(x, y-1, x + w, y-1);
999 paint.drawLine(x, y+1, x + w, y+1); 1004 paint.drawLine(x, y+1, x + w, y+1);
1009 i != points.end(); ++i) { 1014 i != points.end(); ++i) {
1010 1015
1011 const RegionModel::Point &p(*i); 1016 const RegionModel::Point &p(*i);
1012 1017
1013 int x = v->getXForFrame(p.frame); 1018 int x = v->getXForFrame(p.frame);
1019 int w = v->getXForFrame(p.frame + p.duration) - x;
1014 int y = getYForValue(v, p.value); 1020 int y = getYForValue(v, p.value);
1015 1021
1022 QString label = p.label;
1023 if (label == "") {
1024 label = QString("%1%2").arg(p.value).arg(getScaleUnits());
1025 }
1026 int labelWidth = paint.fontMetrics().width(label);
1027
1028 int gap = v->scalePixelSize(2);
1029
1030 if (m_plotStyle == PlotSegmentation) {
1031 if ((x + w < x0 && x + labelWidth + gap < x0) || x > x1) {
1032 continue;
1033 }
1034 } else {
1035 if (x + w < x0 || x - labelWidth - gap > x1) {
1036 continue;
1037 }
1038 }
1039
1016 bool illuminated = false; 1040 bool illuminated = false;
1017 1041
1018 if (m_plotStyle != PlotSegmentation) { 1042 if (m_plotStyle != PlotSegmentation) {
1019 1043
1020 if (shouldIlluminate && 1044 if (shouldIlluminate &&
1025 illuminated = true; 1049 illuminated = true;
1026 } 1050 }
1027 } 1051 }
1028 1052
1029 if (!illuminated) { 1053 if (!illuminated) {
1030 QString label = p.label;
1031 if (label == "") {
1032 label = QString("%1%2").arg(p.value).arg(getScaleUnits());
1033 }
1034 1054
1035 int labelX, labelY; 1055 int labelX, labelY;
1036 1056
1037 if (m_plotStyle != PlotSegmentation) { 1057 if (m_plotStyle != PlotSegmentation) {
1038 labelX = x - paint.fontMetrics().width(label) - 2; 1058 labelX = x - labelWidth - gap;
1039 labelY = y + paint.fontMetrics().height()/2 1059 labelY = y + paint.fontMetrics().height()/2
1040 - paint.fontMetrics().descent(); 1060 - paint.fontMetrics().descent();
1041 } else { 1061 } else {
1042 labelX = x + 5; 1062 labelX = x + 5;
1043 labelY = v->getTextLabelHeight(this, paint); 1063 labelY = v->getTextLabelHeight(this, paint);
1045 if (lastLabelY < v->getPaintHeight()/2) { 1065 if (lastLabelY < v->getPaintHeight()/2) {
1046 labelY = lastLabelY + fontHeight; 1066 labelY = lastLabelY + fontHeight;
1047 } 1067 }
1048 } 1068 }
1049 lastLabelY = labelY; 1069 lastLabelY = labelY;
1050 nextLabelMinX = labelX + paint.fontMetrics().width(label); 1070 nextLabelMinX = labelX + labelWidth;
1051 } 1071 }
1052 1072
1053 PaintAssistant::drawVisibleText(v, paint, labelX, labelY, label, PaintAssistant::OutlinedText); 1073 PaintAssistant::drawVisibleText(v, paint, labelX, labelY, label,
1074 PaintAssistant::OutlinedText);
1054 } 1075 }
1055 } 1076 }
1056 1077
1057 paint.restore(); 1078 paint.restore();
1058 } 1079 }