100 QPainter painter(
this);
101 painter.setRenderHint(QPainter::Antialiasing);
103 const int w = width();
104 const int h = height();
109 const int plotW = w - mLeft - mRight;
110 const int plotH = h - mTop - mBottom;
114 if (plotW <= 0 || plotH <= 0)
123 QLinearGradient gradient(mLeft, 0, mLeft + plotW, 0);
124 const int steps = 25;
125 double stepLeftMiddle = (middleNorm - leftNorm) / steps;
126 double stepMiddleRight = (rightNorm - middleNorm) / steps;
129 for (
int i = 1; i < steps; ++i) {
130 double pos1 = leftNorm + stepLeftMiddle * i;
131 double val1 =
static_cast<double>(i) * (0.5 /
static_cast<double>(steps));
134 double pos2 = middleNorm + stepMiddleRight * i;
135 double val2 = 0.5 +
static_cast<double>(i) * (0.5 /
static_cast<double>(steps));
140 painter.fillRect(QRect(mLeft, mTop, plotW, plotH), gradient);
144 painter.setPen(QPen(Qt::black, 1));
145 painter.drawLine(mLeft, mTop, mLeft, mTop + plotH);
146 painter.drawLine(mLeft, mTop + plotH, mLeft + plotW, mTop + plotH);
150 const int nYTicks = 5;
151 for (
int i = 0; i <= nYTicks; ++i) {
152 int yVal = maxFreq * i / nYTicks;
153 int y = mTop + plotH - (plotH * i / nYTicks);
154 painter.drawLine(mLeft - 5, y, mLeft, y);
155 painter.drawText(QRect(0, y - 10, mLeft - 8, 20), Qt::AlignRight | Qt::AlignVCenter, QString::number(yVal));
159 const int nXTicks = 5;
160 for (
int i = 0; i <= nXTicks; ++i) {
162 int x = mLeft + plotW * i / nXTicks;
163 painter.drawLine(x, mTop + plotH, x, mTop + plotH + 5);
164 painter.drawText(QRect(x - 30, mTop + plotH + 6, 60, 20), Qt::AlignCenter, QString::number(dataVal,
'g', 3));
178 painter.setBrush(QColor(70, 130, 180));
179 painter.drawEllipse(QPointF(px, py), 3, 3);
182 auto getPoint = [
this](
int idx) -> QPointF {
184 if (idx < 0) idx = 0;
185 if (idx >= count) idx = count - 1;
190 path.moveTo(getPoint(0));
192 for (
int i = 0; i < n - 1; ++i) {
193 QPointF p0 = getPoint(i - 1);
194 QPointF p1 = getPoint(i);
195 QPointF p2 = getPoint(i + 1);
196 QPointF p3 = getPoint(i + 2);
199 QPointF cp1(p1.x() + (p2.x() - p0.x()) / 6.0,
200 p1.y() + (p2.y() - p0.y()) / 6.0);
201 QPointF cp2(p2.x() - (p3.x() - p1.x()) / 6.0,
202 p2.y() - (p3.y() - p1.y()) / 6.0);
204 path.cubicTo(cp1, cp2, p2);
207 painter.setPen(QPen(QColor(70, 130, 180), 2));
208 painter.setBrush(Qt::NoBrush);
209 painter.drawPath(path);
214 auto drawThresholdLine = [&](
double dataX,
const QColor& color) {
217 painter.setPen(QPen(color, 2));
218 painter.drawLine(QPointF(px, mTop), QPointF(px, mTop + plotH));
274 qDebug() <<
"Data set not found.";
283 qDebug() <<
"One or more of the values given are out of the minimum and maximum range. Changed to default thresholds.";
289 double vals[3] = {
static_cast<double>(correctedVectorThreshold.x()),
290 static_cast<double>(correctedVectorThreshold.y()),
291 static_cast<double>(correctedVectorThreshold.z()) };
292 std::sort(vals, vals + 3);