From: Michal MalĂ˝ Date: Tue, 18 Feb 2014 23:59:45 +0000 (+0100) Subject: - Declare absVal in scale drawers as double (regression) X-Git-Tag: 0.2a~4 X-Git-Url: https://gitweb.devoid-pointer.net/?a=commitdiff_plain;h=53a74af4e907c65a14416d5336f2573a5a91b962;p=anyanka.git - Declare absVal in scale drawers as double (regression) - Add 5 % extra margin to Y axis by default --- diff --git a/gui/graphview.cpp b/gui/graphview.cpp index 91d5cd3..42c337d 100644 --- a/gui/graphview.cpp +++ b/gui/graphview.cpp @@ -30,7 +30,8 @@ const double GraphView::DEFAULT_Y_MARGIN = 0.05; const QString GraphView::ME_SENDER_STR("GraphView"); GraphView::GraphView(std::shared_ptr 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) @@ -450,8 +451,8 @@ void GraphView::setDefaultZoom() 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) @@ -468,6 +469,8 @@ void GraphView::onCtxMenuDeletePeak(const QPoint pixPos) { const PeakDrawData pdData = m_controller->deletePeak(xPixToRel(pixPos.x())); QRect rect = erasePeak(pdData); + if (rect.isEmpty()) + return; refresh(rect); } diff --git a/gui/graphview.h b/gui/graphview.h index 179e481..a2a1eec 100644 --- a/gui/graphview.h +++ b/gui/graphview.h @@ -62,6 +62,17 @@ private: 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; diff --git a/gui/signalview.cpp b/gui/signalview.cpp index 35682e7..c1da218 100644 --- a/gui/signalview.cpp +++ b/gui/signalview.cpp @@ -37,6 +37,7 @@ SignalView::SignalView(std::shared_ptr controller, QWidget* pa { 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); diff --git a/signalcontroller.cpp b/signalcontroller.cpp index d073d11..14a7764 100644 --- a/signalcontroller.cpp +++ b/signalcontroller.cpp @@ -149,21 +149,16 @@ RulerDrawData SignalController::getRulerDrawData(const double from, const double 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); } diff --git a/signaldrawer.cpp b/signaldrawer.cpp index 09559b5..345ad2a 100644 --- a/signaldrawer.cpp +++ b/signaldrawer.cpp @@ -7,10 +7,14 @@ const QString SignalDrawer::ME_SENDER_STR("SignalDrawer"); const int SignalDrawer::SCALE_MARGIN_TIME(16); const int SignalDrawer::SCALE_MARGIN_VALUE(48); -SignalDrawer::SignalDrawer(std::shared_ptr controller) : +SignalDrawer::SignalDrawer(std::shared_ptr 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) { } @@ -66,7 +70,7 @@ bool SignalDrawer::setDimensions(const int width, const int height) qDebug() << __QFUNC__ << width << height << m_width << m_height; - return draw(); + return draw(m_relXMin, m_relYMin, m_relXMax, m_relYMax); } /** Protected methods **/ @@ -106,7 +110,7 @@ bool SignalDrawer::drawPeaks(QPixmap* const target) bool SignalDrawer::renderScale(const SignalController::Axis axis, QPixmap* const target) { QPainter p; - int absVal; + double absVal; double relMin, relMax; std::function tickDrawFunc; std::function textDrawFunc; @@ -133,9 +137,7 @@ bool SignalDrawer::renderScale(const SignalController::Axis axis, QPixmap* const } 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 */ { @@ -163,21 +165,21 @@ bool SignalDrawer::renderScale(const SignalController::Axis axis, QPixmap* const 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); @@ -191,12 +193,10 @@ void SignalDrawer::renderTimeScaleTick(QPainter*const p, const double rel, const } } -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); @@ -227,9 +227,9 @@ QRect SignalDrawer::erasePeak(const PeakDrawData& pd) 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); @@ -242,7 +242,6 @@ QRect SignalDrawer::erasePeak(const PeakDrawData& pd) 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 @@ -351,7 +350,6 @@ QRect SignalDrawer::renderPeak(const PeakDrawData& pd, QPixmap* const target) 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 diff --git a/signaldrawer.h b/signaldrawer.h index dd5ba6a..0c89ff3 100644 --- a/signaldrawer.h +++ b/signaldrawer.h @@ -9,6 +9,8 @@ #include 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) {} @@ -18,12 +20,11 @@ struct Constraints { class SignalDrawer { public: - SignalDrawer(std::shared_ptr controller); + SignalDrawer(std::shared_ptr 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);