From 2f36fcd516688c6c74cf425c80a4520efd0a4317 Mon Sep 17 00:00:00 2001 From: markummitchell Date: Sat, 7 Oct 2017 01:01:43 -0700 Subject: [PATCH] Stop expanding grid lines when number is reduced for less confusion, for #244 --- src/Dlg/DlgSettingsGridRemoval.cpp | 3 - src/Grid/GridLineFactory.cpp | 6 +- src/Grid/GridLineLimiter.cpp | 88 ++++++++++++++++-------------- src/Grid/GridLineLimiter.h | 6 +- 4 files changed, 56 insertions(+), 47 deletions(-) diff --git a/src/Dlg/DlgSettingsGridRemoval.cpp b/src/Dlg/DlgSettingsGridRemoval.cpp index 12ba283c..9f7b75c5 100644 --- a/src/Dlg/DlgSettingsGridRemoval.cpp +++ b/src/Dlg/DlgSettingsGridRemoval.cpp @@ -258,15 +258,12 @@ QWidget *DlgSettingsGridRemoval::createSubPanel () { LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGridRemoval::createSubPanel"; - const int COLUMN_CHECKBOX_WIDTH = 60; - QWidget *subPanel = new QWidget (); QGridLayout *layout = new QGridLayout (subPanel); subPanel->setLayout (layout); layout->setColumnStretch(0, 1); // Empty first column layout->setColumnStretch(1, 0); // Checkbox part of "section" checkboxes. In other rows this has empty space as indentation - layout->setColumnMinimumWidth(1, COLUMN_CHECKBOX_WIDTH); layout->setColumnStretch(2, 0); // X layout->setColumnStretch(3, 0); // Y layout->setColumnStretch(4, 1); // Empty last column diff --git a/src/Grid/GridLineFactory.cpp b/src/Grid/GridLineFactory.cpp index cb51ef6c..77a954f0 100644 --- a/src/Grid/GridLineFactory.cpp +++ b/src/Grid/GridLineFactory.cpp @@ -179,14 +179,16 @@ void GridLineFactory::createGridLinesForEvenlySpacedGrid (const DocumentModelGri modelMainWindow, modelGridDisplay, startX, - stepX); + stepX, + stopX); gridLineLimiter.limitForYRadius (document, transformation, m_modelCoords, modelMainWindow, modelGridDisplay, startY, - stepY); + stepY, + stopY); // Apply if possible bool isLinearX = (m_modelCoords.coordScaleXTheta() == COORD_SCALE_LINEAR); diff --git a/src/Grid/GridLineLimiter.cpp b/src/Grid/GridLineLimiter.cpp index f6657707..40fbe999 100644 --- a/src/Grid/GridLineLimiter.cpp +++ b/src/Grid/GridLineLimiter.cpp @@ -43,26 +43,30 @@ void GridLineLimiter::limitForXTheta (const Document &document, const MainWindowModel &modelMainWindow, const DocumentModelGridDisplay &modelGrid, double &startX, - double &stepX) const + double &stepX, + double &stopX) const { startX = modelGrid.startX(); - double stopX = modelGrid.stopX(); + stopX = modelGrid.stopX(); stepX = modelGrid.stepX(); + int countX = modelGrid.countX(); + + bool needReduction = (countX > modelMainWindow.maximumGridLines()); if (modelCoords.coordScaleXTheta() == COORD_SCALE_LINEAR) { // Linear - bool needNewStep = (stepX <= 0); // Prevent divide-by-zero in next computation - if (!needNewStep) { - double count = 1.0 + (stopX - startX) / stepX; - needNewStep = ((int) count > modelMainWindow.maximumGridLines()); + if (!needReduction) { + if (stepX <= 0) { + stepX = 0; + } else { + countX = 1.0 + (stopX - startX) / stepX; + needReduction = (countX > modelMainWindow.maximumGridLines()); + } } - if (needNewStep) { - - // Adjust step so maximum grid lines limit is met - stepX = (stopX - startX) / (modelMainWindow.maximumGridLines() - 1); - + if (needReduction) { + stopX = startX + stepX * (modelMainWindow.maximumGridLines() - 1); } } else { @@ -78,17 +82,17 @@ void GridLineLimiter::limitForXTheta (const Document &document, startX = boundingRectGraph.left (); } - bool needNewStep = (stepX <= 1); // Prevent divide-by-zero in next computation - if (!needNewStep) { - double count = 1.0 + (qLn (stopX) - qLn (startX)) / qLn (stepX); - needNewStep = ((int) count > modelMainWindow.maximumGridLines()); + if (!needReduction) { + if (stepX <= 1) { + stepX = 1; + } else { + countX = 1.0 + (qLn (stopX) - qLn (startX)) / qLn (stepX); + needReduction = (countX > modelMainWindow.maximumGridLines()); + } } - if (needNewStep) { - - // Adjust step so maximum grid lines limit is met - stepX = qExp ((qLn (stopX) - qLn (startX)) / (modelMainWindow.maximumGridLines() - 1)); - + if (needReduction) { + stopX = qExp (qLn (startX) + qLn (stepX) * (modelMainWindow.maximumGridLines() - 1)); } } } @@ -99,26 +103,30 @@ void GridLineLimiter::limitForYRadius (const Document &document, const MainWindowModel &modelMainWindow, const DocumentModelGridDisplay &modelGrid, double &startY, - double &stepY) const + double &stepY, + double &stopY) const { startY = modelGrid.startY(); - double stopY = modelGrid.stopY(); + stopY = modelGrid.stopY(); stepY = modelGrid.stepY(); + int countY = modelGrid.countY(); + + bool needReduction = (countY > modelMainWindow.maximumGridLines()); if (modelCoords.coordScaleYRadius() == COORD_SCALE_LINEAR) { // Linear - bool needNewStep = (stepY <= 0); // Prevent divide-by-zero in next computation - if (!needNewStep) { - double count = 1.0 + (stopY - startY) / stepY; - needNewStep = ((int) count > modelMainWindow.maximumGridLines()); + if (!needReduction) { + if (stepY <= 0) { + stepY = 0; + } else { + countY = 1.0 + (stopY - startY) / stepY; + needReduction = (countY > modelMainWindow.maximumGridLines()); + } } - if (needNewStep) { - - // Adjust step so maximum grid lines limit is met - stepY = (stopY - startY) / (modelMainWindow.maximumGridLines() - 1); - + if (needReduction) { + stopY = startY + stepY * (modelMainWindow.maximumGridLines() - 1); } } else { @@ -134,17 +142,17 @@ void GridLineLimiter::limitForYRadius (const Document &document, startY = boundingRectGraph.top (); } - bool needNewStep = (stepY <= 1); // Prevent divide-by-zero in next computation - if (!needNewStep) { - double count = 1.0 + (qLn (stopY) - qLn (startY)) / qLn (stepY); - needNewStep = ((int) count > modelMainWindow.maximumGridLines()); + if (!needReduction) { + if (stepY <= 1) { + stepY = 1; + } else { + countY = 1.0 + (qLn (stopY) - qLn (startY)) / qLn (stepY); + needReduction = (countY > modelMainWindow.maximumGridLines()); + } } - if (needNewStep) { - - // Adjust step so maximum grid lines limit is met - stepY = qExp ((qLn (stopY) - qLn (startY)) / (modelMainWindow.maximumGridLines() - 1)); - + if (needReduction) { + stopY = qExp (qLn (startY) + qLn (stepY) * (modelMainWindow.maximumGridLines() - 1)); } } } diff --git a/src/Grid/GridLineLimiter.h b/src/Grid/GridLineLimiter.h index 6d526072..7745ccea 100644 --- a/src/Grid/GridLineLimiter.h +++ b/src/Grid/GridLineLimiter.h @@ -33,7 +33,8 @@ class GridLineLimiter const MainWindowModel &modelMainWindow, const DocumentModelGridDisplay &modelGrid, double &startX, - double &stepX) const; + double &stepX, + double &stopX) const; /// Limit step value for y/range coordinate. This is a noop if the maximum grid line limit in MainWindowModel is not exceeded void limitForYRadius (const Document &document, @@ -42,7 +43,8 @@ class GridLineLimiter const MainWindowModel &modelMainWindow, const DocumentModelGridDisplay &modelGrid, double &startY, - double &stepY) const; + double &stepY, + double &stopY) const; private: