Added option to choose between different depth grid quantization schema.

This allows having 3m depth grid for metric users.

* All original properties ( named diferently ) were renamed to three_m_based_grid everywhere to be consistent.
* Plus other small changes requested during review.

Signed-off-by: Vlad A. <elf128@gmail.com>
Signed-off-by: Vlad A <elf128@gmail.com>
This commit is contained in:
Vlad A 2022-05-20 03:28:49 -04:00 committed by Dirk Hohndel
parent 15f3918171
commit 30a964c508
10 changed files with 85 additions and 8 deletions

View file

@ -30,6 +30,7 @@ DiveCartesianAxis::DiveCartesianAxis(Position position, bool inverted, int integ
max(0),
textVisibility(textVisible),
lineVisibility(linesVisible),
gridIsMultipleOfThree(false),
labelScale(labelScale),
dpr(dpr),
transform({1.0, 0.0})
@ -101,7 +102,7 @@ int DiveCartesianAxis::getMinLabelDistance(const DiveCartesianAxis &timeAxis) co
return int(ceil(interval));
}
static double sensibleInterval(double inc, int decimals, bool is_time_axis)
static double sensibleInterval(double inc, int decimals, bool is_time_axis, bool is_multiple_of_three)
{
if (is_time_axis && inc < 60.0) {
// for time axes and less than one hour increments, round to
@ -130,11 +131,22 @@ static double sensibleInterval(double inc, int decimals, bool is_time_axis)
double digits_factor = pow(10.0, digits);
int inc_int = std::max((int)ceil(inc / digits_factor), 1);
// Do "nice" increments of the leading digit. In general: 1, 2, 4, 5.
if (inc_int > 5)
inc_int = 10;
if (inc_int == 3)
inc_int = 4;
if (is_multiple_of_three)
{
// Do increments quantized to 3. In general: 1, 3, 6, 15
if (inc_int > 6)
inc_int = 15;
else if (inc_int > 3)
inc_int = 6;
else if (inc_int == 2)
inc_int = 3;
} else {
// Do "nice" increments of the leading digit. In general: 1, 2, 4, 5.
if (inc_int > 5)
inc_int = 10;
if (inc_int == 3)
inc_int = 4;
}
inc = inc_int * digits_factor;
return inc;
@ -165,7 +177,7 @@ void DiveCartesianAxis::updateTicks(int animSpeed)
// Round the interval to a sensible size in display units
double intervalDisplay = stepValue * transform.a;
intervalDisplay = sensibleInterval(intervalDisplay, fractionalDigits, position == Position::Bottom);
intervalDisplay = sensibleInterval(intervalDisplay, fractionalDigits, position == Position::Bottom, gridIsMultipleOfThree);
// Choose full multiples of the interval as minumum and maximum values
double minDisplay = transform.to(dataMin);
@ -478,6 +490,11 @@ double DiveCartesianAxis::minimum() const
return min;
}
void DiveCartesianAxis::setGridIsMultipleOfThree(bool arg1)
{
gridIsMultipleOfThree = arg1;
}
std::pair<double, double> DiveCartesianAxis::screenMinMax() const
{
return position == Position::Bottom ? std::make_pair(rect.left(), rect.right())

View file

@ -36,6 +36,7 @@ public:
double pointInRange(double pos) const; // Point on screen is in range of axis
void setTextVisible(bool arg1);
void setLinesVisible(bool arg1);
void setGridIsMultipleOfThree(bool arg1);
void updateTicks(int animSpeed);
double width() const; // only for vertical axes
double height() const; // only for horizontal axes
@ -75,6 +76,7 @@ private:
double min, max;
bool textVisibility;
bool lineVisibility;
bool gridIsMultipleOfThree;
double labelScale;
double dpr;
double labelWidth, labelHeight; // maximum expected sizes of label width and height

View file

@ -164,6 +164,7 @@ ProfileScene::ProfileScene(double dpr, bool printMode, bool isGrayscale) :
addTissueItems<0,16>(dpr);
percentageItem->setZValue(1.0);
profileYAxis->setGridIsMultipleOfThree( qPrefDisplay::three_m_based_grid() );
// Add items to scene
addItem(diveComputerText);
@ -304,6 +305,8 @@ void ProfileScene::updateAxes(bool diveHasHeartBeat, bool simplified)
if (width <= 10.0 * dpr)
return clear();
profileYAxis->setGridIsMultipleOfThree( qPrefDisplay::three_m_based_grid() );
// Place the fixed dive computer text at the bottom
double bottomBorder = sceneRect().height() - diveComputerText->height() - 2.0 * dpr * diveComputerTextBorder;
diveComputerText->setPos(0.0, bottomBorder + dpr * diveComputerTextBorder);