Skip to content

Commit

Permalink
Stop expanding grid lines when number is reduced for less confusion, …
Browse files Browse the repository at this point in the history
…for #244
  • Loading branch information
markummitchell-tu committed Oct 7, 2017
1 parent 8091211 commit 2f36fcd
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 47 deletions.
3 changes: 0 additions & 3 deletions src/Dlg/DlgSettingsGridRemoval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/Grid/GridLineFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
88 changes: 48 additions & 40 deletions src/Grid/GridLineLimiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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));
}
}
}
Expand All @@ -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 {
Expand All @@ -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));
}
}
}
6 changes: 4 additions & 2 deletions src/Grid/GridLineLimiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -42,7 +43,8 @@ class GridLineLimiter
const MainWindowModel &modelMainWindow,
const DocumentModelGridDisplay &modelGrid,
double &startY,
double &stepY) const;
double &stepY,
double &stopY) const;

private:

Expand Down

0 comments on commit 2f36fcd

Please sign in to comment.