void TrafficGraphWidget::paintPath(QPainterPath &path, const TrafficGraphData::SampleQueue &queue, SampleChooser chooser) { int h = height() - YMARGIN * 2, w = width() - XMARGIN * 2; int sampleCount = queue.size(), x = XMARGIN + w, y; if(sampleCount > 0) { path.moveTo(x, YMARGIN + h); for(int i = 0; i < sampleCount; ++i) { x = XMARGIN + w - w * i / TrafficGraphData::DESIRED_DATA_SAMPLES; y = YMARGIN + h - (int)(h * chooser(queue.at(i)) / fMax); path.lineTo(x, y); } path.lineTo(x, YMARGIN + h); } }
void TrafficGraphDataTests::simpleCurrentSampleQueueTests() { TrafficGraphData trafficGraphData(TrafficGraphData::Range_5m); for (int i = 0; i < TrafficGraphData::DESIRED_DATA_SAMPLES; i++) QVERIFY(trafficGraphData.update(TrafficSample(i, i))); TrafficGraphData::SampleQueue queue = trafficGraphData.getCurrentRangeQueue(); QCOMPARE(queue.size(), TrafficGraphData::DESIRED_DATA_SAMPLES); for (int i = 0; i < TrafficGraphData::DESIRED_DATA_SAMPLES; i++){ QCOMPARE((int)queue.at(i).in, TrafficGraphData::DESIRED_DATA_SAMPLES - i - 1); QCOMPARE((int)queue.at(i).out, TrafficGraphData::DESIRED_DATA_SAMPLES - i - 1); } QVERIFY(trafficGraphData.update(TrafficSample(0, 0))); queue = trafficGraphData.getCurrentRangeQueue(); QCOMPARE(queue.size(), TrafficGraphData::DESIRED_DATA_SAMPLES); QCOMPARE((int)queue.at(0).in, 0); QCOMPARE((int)queue.at(0).out, 0); }