const QString GraphView::ME_SENDER_STR("GraphView");
GraphView::GraphView(std::shared_ptr<SignalController> controller, QWidget* parent) :
- QWidget(parent), SignalDrawer(controller),
+ QWidget(parent), SignalDrawer(controller, Constraints(SignalController::RELATIVE_MIN, RELATIVE_Y_MIN_WITH_MARGIN(), SignalController::RELATIVE_MAX,
+ RELATIVE_Y_MAX_WITH_MARGIN())),
m_mouseMode(GraphView::MouseMode::CROSSHAIR),
m_graphCrosshairXPix(-1),
m_graphCrosshairYPix(-1)
m_relXMax = SignalController::RELATIVE_MAX;
m_relXMin = SignalController::RELATIVE_MIN;
- m_relYMax = SignalController::RELATIVE_MAX + (range * DEFAULT_Y_MARGIN);
- m_relYMin = SignalController::RELATIVE_MIN - (range * DEFAULT_Y_MARGIN);
+ m_relYMax = RELATIVE_Y_MAX_WITH_MARGIN();
+ m_relYMin = RELATIVE_Y_MIN_WITH_MARGIN();
}
void GraphView::zoom(const int fromXPix, const int fromYPix, const int toXPix, const int toYPix)
{
const PeakDrawData pdData = m_controller->deletePeak(xPixToRel(pixPos.x()));
QRect rect = erasePeak(pdData);
+ if (rect.isEmpty())
+ return;
refresh(rect);
}
void showContextMenu(const QPoint& pos, const QPoint& globalPos);
void zoom(const int fromXPix, const int fromYPix, const int toXPix, const int toYPix);
+ static inline double RELATIVE_Y_MAX_WITH_MARGIN()
+ {
+ const double range = SignalController::RELATIVE_MAX - SignalController::RELATIVE_MIN;
+ return SignalController::RELATIVE_MAX + (range * DEFAULT_Y_MARGIN);
+ }
+ static inline double RELATIVE_Y_MIN_WITH_MARGIN()
+ {
+ const double range = SignalController::RELATIVE_MAX - SignalController::RELATIVE_MIN;
+ return SignalController::RELATIVE_MIN - (range * DEFAULT_Y_MARGIN);
+ }
+
GraphViewContextMenu m_ctxMenu;
MouseMode m_mouseMode;
{
ui->setupUi(this);
m_graphView = new GraphView(controller, this);
+ setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding));
ui->qw_container->setLayout(new QVBoxLayout());
ui->qw_container->layout()->addWidget(m_graphView);
break;
}
- if (axis == Axis::VALUE)
- qDebug() << " ---- VALUE SCALE ----";
-
/* Calculate step */
diffAbs = toAbs - fromAbs;
step = 1 / pow(10, floor(log10(1 / (diffAbs))) + 1); // Magic - you want to love it but you better not touch!
relStep = (diffRel * step) / (diffAbs);
- if (axis == Axis::VALUE)
- qDebug() << __QFUNC__ << "Step" << step << "RelStep" << relStep << "relDiff" << diffRel;
+ //qDebug() << __QFUNC__ << "Step" << step << "RelStep" << relStep << "relDiff" << diffRel;
/* Calculate position of the first major tick */
firstTickAbs = ceil(fromAbs / step) * step;
firstTickRel = (diffRel / diffAbs) * (firstTickAbs - fromAbs) + from;
- if (axis == Axis::VALUE)
- qDebug() << __QFUNC__ << "First tick Abs:" << firstTickAbs << "Rel:" << firstTickRel;
+ //qDebug() << __QFUNC__ << "First tick Abs:" << firstTickAbs << "Rel:" << firstTickRel;
return RulerDrawData(firstTickAbs, firstTickRel, step, relStep);
}
const int SignalDrawer::SCALE_MARGIN_TIME(16);
const int SignalDrawer::SCALE_MARGIN_VALUE(48);
-SignalDrawer::SignalDrawer(std::shared_ptr<SignalController> controller) :
+SignalDrawer::SignalDrawer(std::shared_ptr<SignalController> controller, const Constraints& constraints) :
m_controller(controller),
m_background(nullptr),
- m_pixmap(nullptr)
+ m_pixmap(nullptr),
+ m_relXMax(constraints.toX),
+ m_relXMin(constraints.fromX),
+ m_relYMax(constraints.toY),
+ m_relYMin(constraints.fromY)
{
}
qDebug() << __QFUNC__ << width << height << m_width << m_height;
- return draw();
+ return draw(m_relXMin, m_relYMin, m_relXMax, m_relYMax);
}
/** Protected methods **/
bool SignalDrawer::renderScale(const SignalController::Axis axis, QPixmap* const target)
{
QPainter p;
- int absVal;
+ double absVal;
double relMin, relMax;
std::function<void (const double, const TickType)> tickDrawFunc;
std::function<void (const double, const double)> textDrawFunc;
}
RulerDrawData rd = m_controller->getRulerDrawData(relMin, relMax, axis);
-
- if (axis == SignalController::Axis::VALUE)
- qDebug() << __QFUNC__ << "step" << rd.step << "relStep" << rd.relStep;
+ //qDebug() << __QFUNC__ << "step" << rd.step << "relStep" << rd.relStep;
/* Draw subticks before the first tick */
{
return true;
}
-void SignalDrawer::renderTimeScaleText(QPainter*const p, const double rel, const double value)
+void SignalDrawer::renderTimeScaleText(QPainter* const p, const double rel, const double value)
{
const int xPix = relToXPix(rel);
p->drawText(xPix + 2, m_gHeight + 15, m_locale.toString(value, 'f', 3));
}
-void SignalDrawer::renderValueScaleText(QPainter*const p, const double rel, const double value)
+void SignalDrawer::renderValueScaleText(QPainter* const p, const double rel, const double value)
{
const int yPix = relToYPix(rel);
p->drawText(1, yPix + 5, m_locale.toString(value, 'f', 2));
}
-void SignalDrawer::renderTimeScaleTick(QPainter*const p, const double rel, const TickType tt)
+void SignalDrawer::renderTimeScaleTick(QPainter* const p, const double rel, const TickType tt)
{
const int xPix = relToXPix(rel);
}
}
-void SignalDrawer::renderValueScaleTick(QPainter*const p, const double rel, const TickType tt)
+void SignalDrawer::renderValueScaleTick(QPainter* const p, const double rel, const TickType tt)
{
const int yPix = relToYPix(rel);
- qDebug() << __QFUNC__ << "yPix" << yPix << "rel" << rel;
-
switch (tt) {
case TickType::TICK:
p->drawLine(SCALE_MARGIN_VALUE - 6, yPix, SCALE_MARGIN_VALUE - 1, yPix);
if (pd.auc == 0)
return QRect();
- fromXPix = relToXPix(pd.fromX) + SCALE_MARGIN_VALUE; fromYPix = relToYPix(pd.fromY);
- toXPix = relToXPix(pd.toX) + SCALE_MARGIN_VALUE; toYPix = relToYPix(pd.toY);
- peakX = relToXPix(pd.peakX) + SCALE_MARGIN_VALUE; peakY = relToYPix(pd.peakY);
+ fromXPix = relToXPix(pd.fromX); fromYPix = relToYPix(pd.fromY);
+ toXPix = relToXPix(pd.toX); toYPix = relToYPix(pd.toY);
+ peakX = relToXPix(pd.peakX); peakY = relToYPix(pd.peakY);
aucText = m_locale.toString(pd.auc, 'f', 4);
timeText = m_locale.toString(pd.time, 'f', 4);
tTextWidth = fm.width(timeText);
beginXPix = (peakX - tTextHeight > 0) ? peakX - tTextHeight : 0;
else
beginXPix = fromXPix;
- qDebug() << __QFUNC__ << beginXPix << fromXPix << tTextHeight;
if (peakX + 5 + aTextWidth > toXPix)
endXPix = peakX + 5 + aTextWidth;
else
beginXPix = (peakX - tTextHeight > 0) ? peakX - tTextHeight : 0;
else
beginXPix = fromXPix;
- qDebug() << __QFUNC__ << beginXPix << fromXPix << tTextHeight;
if (peakX + 5 + aTextWidth > toXPix)
endXPix = peakX + 5 + aTextWidth;
else
#include <memory>
struct Constraints {
+ Constraints() : fromX(SignalController::RELATIVE_MIN), fromY(SignalController::RELATIVE_MAX),
+ toX(SignalController::RELATIVE_MAX), toY(SignalController::RELATIVE_MAX) {}
Constraints(const double fromX, const double fromY, const double toX, const double toY) :
fromX(fromX), fromY(fromY), toX(toX), toY(toY) {}
class SignalDrawer
{
public:
- SignalDrawer(std::shared_ptr<SignalController> controller);
+ SignalDrawer(std::shared_ptr<SignalController> controller, const Constraints& constraints = Constraints());
~SignalDrawer();
Constraints currentConstraints();
int dheight() const { return m_height; }
- bool draw(const double fromX = SignalController::RELATIVE_MIN, const double fromY = SignalController::RELATIVE_MIN,
- const double toX = SignalController::RELATIVE_MAX, const double toY = SignalController::RELATIVE_MAX);
+ bool draw(const double fromX, const double fromY, const double toX, const double toY);
bool drawGraph(QPixmap* const target);
bool drawPeaks(QPixmap* const target);
QRect erasePeak(const PeakDrawData& pd);