From: Michal MalĂ˝ Date: Fri, 13 Mar 2015 19:34:20 +0000 (+0100) Subject: - Version bump X-Git-Tag: 0.4c X-Git-Url: https://gitweb.devoid-pointer.net/?a=commitdiff_plain;h=1b756c701051269766fdc961c07a4cc4515deea8;p=anyanka.git - Version bump - Use saner rounding rules in ruler ticks calculations --- diff --git a/globalinfo.cpp b/globalinfo.cpp index 0ba63ae..557eda4 100644 --- a/globalinfo.cpp +++ b/globalinfo.cpp @@ -25,6 +25,6 @@ const int GlobalInfo::APP_VERSION_MAJ(0); const int GlobalInfo::APP_VERSION_MIN(4); -const QString GlobalInfo::APP_VERSION_REV("b"); +const QString GlobalInfo::APP_VERSION_REV("c"); const QString GlobalInfo::APP_NAME("Anyanka"); const QString GlobalInfo::ORG_NAME("devoid-pointer.net"); diff --git a/signalcontroller.cpp b/signalcontroller.cpp index 54a303e..84fe7ab 100644 --- a/signalcontroller.cpp +++ b/signalcontroller.cpp @@ -200,12 +200,13 @@ RulerDrawData SignalController::getRulerDrawData(const double from, const double pixelStep = pixelLength / numSteps + 1; //Logger::log(Logger::Level::DEBUG, ME_SENDER_STR, __QFUNC__ + QString("pixelStep %1, step %2, pixelLength %3, numSteps %4").arg(pixelStep).arg(step).arg(pixelLength).arg(numSteps)); if (pixelStep < minPixelStep) { - const double upscaleFactor = ceil(minPixelStep / pixelStep); - step *= upscaleFactor; + const double upscaleFactor = minPixelStep / pixelStep; + step *= ceil(upscaleFactor / 2.0) * 2.0; //Logger::log(Logger::Level::DEBUG, ME_SENDER_STR, __QFUNC__ + QString("Corrected step %1, upscaleFactor %2").arg(step).arg(upscaleFactor)); - } else if (pixelStep > maxPixelStep) { - const double downscaleFactor = ceil(pixelStep / maxPixelStep); - step /= downscaleFactor; + } + else if (pixelStep > maxPixelStep) { + const double downscaleFactor = pixelStep / maxPixelStep; + step /= ceil(downscaleFactor / 2.0) * 2.0; //Logger::log(Logger::Level::DEBUG, ME_SENDER_STR, __QFUNC__ + QString("Corrected step %1, downscaleFactor %2").arg(step).arg(downscaleFactor)); } relStep = (diffRel * step) / (diffAbs); diff --git a/signaldrawer.cpp b/signaldrawer.cpp index edc61aa..10cc7d0 100644 --- a/signaldrawer.cpp +++ b/signaldrawer.cpp @@ -27,7 +27,7 @@ const int SignalDrawer::AXIS_LABEL_BORDER_OFFSET(2); const int SignalDrawer::AXIS_LABEL_SCALE_OFFSET(3); -const int SignalDrawer::MAXIMAL_AXIS_BIGTICK_STEP(75); +const int SignalDrawer::MAXIMAL_AXIS_BIGTICK_STEP(150); const int SignalDrawer::MINIMAL_AXIS_BIGTICK_STEP(25); const int SignalDrawer::SCALE_MARGIN_TIME(16); const int SignalDrawer::SCALE_MARGIN_VALUE(12); @@ -277,13 +277,16 @@ void SignalDrawer::drawScaleByTicks(const RulerDrawData& rd, std::function textDrawFunc; std::function tickDrawFunc; textDrawFunc = std::bind(&SignalDrawer::renderTimeScaleText, this, p, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); - tickDrawFunc = std::bind(&SignalDrawer::renderTimeScaleTick, this, p, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); + tickDrawFunc = std::bind(&SignalDrawer::renderTimeScaleTick, this, p, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); - RulerDrawData rd = m_controller->getRulerDrawData(m_relXMin, m_relXMax, SignalController::Axis::TIME, m_gWidth, MINIMAL_AXIS_BIGTICK_STEP, MAXIMAL_AXIS_BIGTICK_STEP); + RulerDrawData rd = m_controller->getRulerDrawData(m_relXMin, m_relXMax, SignalController::Axis::TIME, m_gWidth, + MINIMAL_AXIS_BIGTICK_STEP, maxBigTickStep); if (!rd.valid) return; @@ -301,11 +304,13 @@ void SignalDrawer::drawValueScale(QPainter* const p) std::function textDrawFunc; std::function tickDrawFunc; int maxCueWidth = 0; + int maxBigTickStep = calculateMaximalTickStep(m_gHeight); textDrawFunc = std::bind(&SignalDrawer::renderValueScaleText, this, p, std::ref(maxCueWidth), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); tickDrawFunc = std::bind(&SignalDrawer::renderValueScaleTick, this, p, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); - RulerDrawData rd = m_controller->getRulerDrawData(m_relYMin, m_relYMax, SignalController::Axis::VALUE, m_gHeight, MINIMAL_AXIS_BIGTICK_STEP, MAXIMAL_AXIS_BIGTICK_STEP); + RulerDrawData rd = m_controller->getRulerDrawData(m_relYMin, m_relYMax, SignalController::Axis::VALUE, m_gHeight, + MINIMAL_AXIS_BIGTICK_STEP, maxBigTickStep); if (!rd.valid) return; @@ -609,6 +614,19 @@ QRegion SignalDrawer::renderPeak(const PeakDrawData& pd, QPainter* const painter /** Private functions **/ +int SignalDrawer::calculateMaximalTickStep(const int dimension) +{ + if (dimension < MAXIMAL_AXIS_BIGTICK_STEP) { + /* The viewport is just too small for the ticks to fit in */ + if (dimension < MINIMAL_AXIS_BIGTICK_STEP) { + return MINIMAL_AXIS_BIGTICK_STEP + 1; + } else { + return ((dimension - MINIMAL_AXIS_BIGTICK_STEP) / 2) + MINIMAL_AXIS_BIGTICK_STEP + 1; + } + } + return MAXIMAL_AXIS_BIGTICK_STEP; +} + double SignalDrawer::linesIntersection(const double k1, const double q1, const double k2, const double q2) { double ret = (q1 - q2) / (k2 - k1); diff --git a/signaldrawer.h b/signaldrawer.h index 39b98e6..a64dce7 100644 --- a/signaldrawer.h +++ b/signaldrawer.h @@ -114,6 +114,7 @@ protected: private: QRect axisLabelBoundingRect(const SignalController::Axis axis); + int calculateMaximalTickStep(const int dimension); double linesIntersection(const double k1, const double q1, const double k2, const double q2); void restoreRelativeConstraints(); void setNewRelativeConstraints(const double fromX, const double fromY, const double toX, const double toY);