bool SignalDrawer::draw(const double fromX, const double fromY, const double toX, const double toY, const GraphLayers layers)
{
QPixmap* fresh;
+ QPainter painter;
bool ret;
setNewRelativeConstraints(fromX, fromY, toX, toY);
goto error_out;
}
+ painter.begin(fresh);
/* Draw the scale */
if (flags(GraphLayers::SCALE & layers)) {
- ret = drawScale(fresh);
+ ret = drawScale(&painter);
if (!ret) {
Logger::log(Logger::Level::WARNING, ME_SENDER_STR, __QFUNC__ + " cannot draw scales");
goto error_out;
/* Draw the signal itself */
if (flags(GraphLayers::GRAPH & layers)) {
- ret = drawGraph(fresh);
+ ret = drawGraph(&painter);
if (!ret) {
Logger::log(Logger::Level::WARNING, ME_SENDER_STR, __QFUNC__ + " cannot draw graph");
goto error_out;
/* Draw integrated peaks */
if (flags(GraphLayers::INTEGRATION & layers)) {
- ret = drawPeaks(fresh);
+ ret = drawPeaks(&painter);
if (!ret) {
Logger::log(Logger::Level::WARNING, ME_SENDER_STR, __QFUNC__ + " cannot draw integrated peaks");
goto error_out;
}
/* Draw axes labels */
- ret = drawAxisLabel(SignalController::Axis::TIME, fresh);
+ ret = drawAxisLabel(SignalController::Axis::TIME, &painter);
if (!ret) {
Logger::log(Logger::Level::WARNING, ME_SENDER_STR, __QFUNC__ + " cannot draw X axis label");
goto error_out;
}
- ret = drawAxisLabel(SignalController::Axis::VALUE, fresh);
+ ret = drawAxisLabel(SignalController::Axis::VALUE, &painter);
if (!ret) {
Logger::log(Logger::Level::WARNING, ME_SENDER_STR, __QFUNC__ + " cannot draw Y axis label");
goto error_out;
}
+ painter.end();
renderFresh(fresh);
p.drawPixmap(rect, *source, rect);
}
-bool SignalDrawer::drawGraph(QPixmap* const target)
+bool SignalDrawer::drawGraph(QPainter* const painter)
{
std::shared_ptr<GraphDrawData> gdData = m_controller->getGraphDrawData(m_relXMin, m_relXMax);
if (gdData->ddataLen == 0)
m_gdData = gdData;
- return renderGraph(target);
+ return renderGraph(painter);
}
-bool SignalDrawer::drawAxisLabel(const SignalController::Axis axis, QPixmap* const target)
+bool SignalDrawer::drawAxisLabel(const SignalController::Axis axis, QPainter* const painter)
{
- QPainter p;
int xPix, yPix;
QString text;
- if (target == nullptr) {
- Logger::log(Logger::Level::WARNING, ME_SENDER_STR, __QFUNC__ + " null pointer to pixmap");
+ if (painter == nullptr) {
+ Logger::log(Logger::Level::WARNING, ME_SENDER_STR, __QFUNC__ + " null pointer to QPainter");
return false;
}
break;
}
- p.begin(target);
- p.setFont(m_axisLabelFont);
- p.drawText(xPix, yPix, text);
- p.end();
+ painter->setPen(QColor(Qt::black));
+ painter->setFont(m_axisLabelFont);
+ painter->drawText(xPix, yPix, text);
return true;
}
-bool SignalDrawer::drawPeaks(QPixmap* const target)
+bool SignalDrawer::drawPeaks(QPainter* const painter)
{
std::vector<PeakDrawData> pdData = m_controller->getPeaksDrawData(m_relXMin, m_relYMin, m_relXMax, m_relYMax);
if (pdData.size() < 1)
return true;
for (const PeakDrawData& pd : pdData) {
- QRegion reg = renderPeak(pd, target);
+ QRegion reg = renderPeak(pd, painter);
if (reg.isEmpty()) return false;
}
p->drawLine(m_leftGraphOffset, 0, m_leftGraphOffset, m_gHeight);
}
-bool SignalDrawer::drawScale(QPixmap* const target)
+bool SignalDrawer::drawScale(QPainter* const painter)
{
- QPainter p;
-
- if (target == nullptr) {
- Logger::log(Logger::Level::WARNING, ME_SENDER_STR, __QFUNC__ + " null pointer to pixmap");
+ if (painter == nullptr) {
+ Logger::log(Logger::Level::WARNING, ME_SENDER_STR, __QFUNC__ + " null pointer to QPainter");
return false;
}
- p.begin(target);
- p.setFont(m_axisLabelFont);
+ painter->setFont(m_axisLabelFont);
/* VALUE scale must be drawn first - left offset of the graph depends on it */
- drawValueScale(&p);
- drawTimeScale(&p);
- p.end();
+ drawValueScale(painter);
+ drawTimeScale(painter);
return true;
}
return peakReg;
}
-bool SignalDrawer::renderGraph(QPixmap* const target)
+bool SignalDrawer::renderGraph(QPainter* const painter)
{
- QPainter p;
int fromXPix, fromYPix;
if (m_width < m_leftGraphOffset || m_height < SCALE_MARGIN_TIME) {
return false;
}
- p.begin(target);
- p.setPen(QColor(Qt::blue));
+ painter->setPen(QColor(Qt::blue));
fromXPix = relToXPix(m_gdData->ddata[0].first);
fromYPix = relToYPix(m_gdData->ddata[0].second);
if (fromYPix >= m_gHeight && toYPix >= m_gHeight) {
/* Draw nothing */
} else if (toXPix == fromXPix)
- p.drawLine(fromXPix, (fromYPix >= m_gHeight) ? m_gHeight : fromYPix, toXPix, (toYPix >= m_gHeight) ? m_gHeight : toYPix);
+ painter->drawLine(fromXPix, (fromYPix >= m_gHeight) ? m_gHeight : fromYPix, toXPix, (toYPix >= m_gHeight) ? m_gHeight : toYPix);
else if (toYPix >= m_gHeight) {
double k = static_cast<double>(toYPix - fromYPix) / static_cast<double>(toXPix - fromXPix);
double cToYPix = m_gHeight;
cToXPix = fromXPix;
else
cToXPix = floor(cToXPix + 0.5);
- p.drawLine(fromXPix, fromYPix, cToXPix, m_gHeight);
+ painter->drawLine(fromXPix, fromYPix, cToXPix, m_gHeight);
} else if (fromYPix >= m_gHeight) {
double k = static_cast<double>(toYPix - fromYPix) / static_cast<double>(toXPix - fromXPix);
double cFromYPix = m_gHeight;
cFromXPix = fromXPix;
else
cFromXPix = floor(cFromXPix + 0.5);
- p.drawLine(cFromXPix, m_gHeight, toXPix, toYPix);
+ painter->drawLine(cFromXPix, m_gHeight, toXPix, toYPix);
} else
- p.drawLine(fromXPix, fromYPix, toXPix, toYPix);
+ painter->drawLine(fromXPix, fromYPix, toXPix, toYPix);
fromXPix = toXPix;
fromYPix = toYPix;
}
- p.end();
-
return true;
}
m_background = new QPixmap(*m_pixmap);
}
+QRegion SignalDrawer::renderPeak(const PeakDrawData &pd, QPixmap* const pixmap)
+{
+ QPainter painter(pixmap);
+ return renderPeak(pd, &painter);
+}
-QRegion SignalDrawer::renderPeak(const PeakDrawData& pd, QPixmap* const target)
+QRegion SignalDrawer::renderPeak(const PeakDrawData& pd, QPainter* const painter)
{
- QPainter p;
QFont font("arial", 10);
QFontMetrics fm(font);
QString aucText, timeText;
int peakX, peakY;
int beginXPix, endXPix;
- if (target == nullptr) {
+ if (painter == nullptr) {
Logger::log(Logger::Level::WARNING, ME_SENDER_STR, __QFUNC__ + " null pointer to pixmap");
return QRect();
}
aucText = m_locale.toString(pd.auc, 'f', 4);
timeText = QString("A:") + m_locale.toString(pd.time, 'f', 4);
- p.begin(target);
- p.setPen(Qt::red);
- p.drawLine(fromXPix, fromYPix, toXPix, toYPix);
+ painter->setPen(Qt::red);
+ painter->drawLine(fromXPix, fromYPix, toXPix, toYPix);
if (pd.itype == IntegrationType::BASELINE) {
- p.drawLine(fromXPix, fromYPix, fromXPix, relToYPix(pd.blFromY));
- p.drawLine(toXPix, toYPix, toXPix, relToYPix(pd.blToY));
+ painter->drawLine(fromXPix, fromYPix, fromXPix, relToYPix(pd.blFromY));
+ painter->drawLine(toXPix, toYPix, toXPix, relToYPix(pd.blToY));
}
/* Draw AREA and TIME caption */
- p.setFont(font);
- p.setPen(Qt::black);
+ painter->setFont(font);
+ painter->setPen(Qt::black);
tTextWidth = fm.width(timeText);
if (peakY - tTextWidth < 2)
peakY += tTextWidth - peakY + 2;
tTextHeight = fm.height();
- p.save();
- p.translate(peakX, peakY);
- p.rotate(-90);
- p.drawText(0, 0, timeText);
- p.rotate(+90);
- p.restore();
+ painter->save();
+ painter->translate(peakX, peakY);
+ painter->rotate(-90);
+ painter->drawText(0, 0, timeText);
+ painter->rotate(+90);
+ painter->restore();
aTextWidth = fm.width(aucText);
- p.drawText(peakX + 5, peakY, aucText);
+ painter->drawText(peakX + 5, peakY, aucText);
if (peakX - tTextHeight < fromXPix)
beginXPix = (peakX - tTextHeight > 0) ? peakX - tTextHeight : 0;
endXPix = toXPix;
peakReg = QRect(beginXPix, 0, endXPix - beginXPix + 1, m_height);
- p.end();
if (peakReg.intersects(m_xAxisLabelRect)) {
//qDebug() << "x inters";
- drawAxisLabel(SignalController::Axis::TIME, target);
+ drawAxisLabel(SignalController::Axis::TIME, painter);
peakReg += m_xAxisLabelRect;
}
if (peakReg.intersects(m_yAxisLabelRect)) {
//qDebug() << "y inters";
- drawAxisLabel(SignalController::Axis::VALUE, target);
+ drawAxisLabel(SignalController::Axis::VALUE, painter);
peakReg += m_yAxisLabelRect;
}