mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-26 08:04:13 +01:00
Grid: 7.5 px by default, and only 1 to 50 px from the settings
With 10 px and the default step, the grid went below 100 %, including the zoom of a freshly fitted folio. 7.5 px keeps it down to 75 %: on a 24" 1920x1200 screen 5 px (the old cutoff at 50 %) reads as a gray haze, 7.5 px still as dots. minDotSpacing() now takes only what the preferences page offers, 1 to 50 px, both kept as constants the page uses for its range: "inf", NaN, 1e9 or 0.5 from a hand-edited settings file fall back to the default instead of hiding the grid for good while the page shows another value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+16
-6
@@ -20,6 +20,7 @@
|
||||
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
|
||||
/**
|
||||
@@ -54,26 +55,35 @@ namespace FolioGrid
|
||||
/// at which grid dots are still drawn (General > Appearance)
|
||||
inline const QString min_dot_spacing_key{QStringLiteral("diagrameditor/grid_min_dot_spacing")};
|
||||
/// Grid dots closer than this on screen, in pixels, read as a
|
||||
/// gray haze rather than as a grid
|
||||
constexpr double default_min_dot_spacing = 10.0;
|
||||
/// gray haze rather than as a grid. With the default step of 10,
|
||||
/// the dots go below a zoom of 75 %.
|
||||
constexpr double default_min_dot_spacing = 7.5;
|
||||
/// The smallest and largest distance the preferences page offers
|
||||
constexpr double min_dot_spacing_lowest = 1.0;
|
||||
constexpr double min_dot_spacing_highest = 50.0;
|
||||
|
||||
/**
|
||||
@return the smallest dot distance held in @p value, a settings
|
||||
entry, or the default when it is missing or not a positive number.
|
||||
entry, or the default when it is missing, not a number, not
|
||||
finite, or outside what the preferences page offers: a hand-edited
|
||||
"inf" or 1e9 would hide the grid for good while the page showed
|
||||
another value.
|
||||
*/
|
||||
inline double minDotSpacing(const QVariant &value)
|
||||
{
|
||||
bool ok = false;
|
||||
const double spacing = value.toDouble(&ok);
|
||||
return ok && spacing > 0 ? spacing : default_min_dot_spacing;
|
||||
return ok && std::isfinite(spacing)
|
||||
&& spacing >= min_dot_spacing_lowest && spacing <= min_dot_spacing_highest
|
||||
? spacing : default_min_dot_spacing;
|
||||
}
|
||||
|
||||
/**
|
||||
@return true when the grid dots are drawn: when two of them, @p x_step
|
||||
and @p y_step apart on the folio, stand at least @p min_spacing
|
||||
pixels apart on screen at @p zoom (1 is 100 %). Whatever the step,
|
||||
they go when they would crowd; with the default step and spacing of
|
||||
10, below a zoom of 100 %.
|
||||
they go when they would crowd; with the default step of 10 and
|
||||
spacing of 7.5, below a zoom of 75 %.
|
||||
*/
|
||||
inline bool dotsShown(int x_step, int y_step, double zoom,
|
||||
double min_spacing = default_min_dot_spacing)
|
||||
|
||||
@@ -111,6 +111,8 @@ GeneralConfigurationPage::GeneralConfigurationPage(QWidget *parent) :
|
||||
}
|
||||
|
||||
ui->grid_startup_cb->setChecked(settings.value("diagrameditor/grid_display_startup", true).toBool());
|
||||
ui->m_grid_min_spacing_sb->setRange(FolioGrid::min_dot_spacing_lowest,
|
||||
FolioGrid::min_dot_spacing_highest);
|
||||
ui->m_grid_min_spacing_sb->setValue(
|
||||
FolioGrid::minDotSpacing(settings.value(FolioGrid::min_dot_spacing_key)));
|
||||
ui->guides_startup_cb->setChecked(settings.value("diagrameditor/guides_display_startup", false).toBool());
|
||||
|
||||
@@ -187,7 +187,7 @@
|
||||
<double>0.500000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>10.000000000000000</double>
|
||||
<double>7.500000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@@ -34,13 +34,13 @@ class tst_foliogrid : public QObject
|
||||
private slots:
|
||||
void dotsGoWhenTheyCrowd()
|
||||
{
|
||||
//The default step and spacing: the dots go below 100 %
|
||||
QVERIFY(FolioGrid::dotsShown(10, 10, 1.0));
|
||||
QVERIFY(!FolioGrid::dotsShown(10, 10, 0.99));
|
||||
//The default step and spacing: the dots go below 75 %
|
||||
QVERIFY(FolioGrid::dotsShown(10, 10, 0.75));
|
||||
QVERIFY(!FolioGrid::dotsShown(10, 10, 0.74));
|
||||
//A finer step goes sooner, a coarser one later; the finer of
|
||||
//the two directions decides
|
||||
QVERIFY(!FolioGrid::dotsShown(5, 5, 1.5));
|
||||
QVERIFY(FolioGrid::dotsShown(20, 20, 0.5));
|
||||
QVERIFY(!FolioGrid::dotsShown(5, 5, 1.4));
|
||||
QVERIFY(FolioGrid::dotsShown(20, 20, 0.4));
|
||||
QVERIFY(!FolioGrid::dotsShown(20, 5, 1.0));
|
||||
//A spacing set in the settings: 7.8 px keeps them down to 78 %
|
||||
QVERIFY(FolioGrid::dotsShown(10, 10, 0.78, 7.8));
|
||||
@@ -49,12 +49,22 @@ private slots:
|
||||
|
||||
void dotSpacingFromSettings()
|
||||
{
|
||||
QCOMPARE(FolioGrid::minDotSpacing(QVariant()), 10.0);
|
||||
QCOMPARE(FolioGrid::minDotSpacing(QVariant()), 7.5);
|
||||
QCOMPARE(FolioGrid::minDotSpacing(QVariant(7.8)), 7.8);
|
||||
QCOMPARE(FolioGrid::minDotSpacing(QVariant(QStringLiteral("12"))), 12.0);
|
||||
QCOMPARE(FolioGrid::minDotSpacing(QVariant(0)), 10.0);
|
||||
QCOMPARE(FolioGrid::minDotSpacing(QVariant(-3)), 10.0);
|
||||
QCOMPARE(FolioGrid::minDotSpacing(QVariant(QStringLiteral("ten"))), 10.0);
|
||||
QCOMPARE(FolioGrid::minDotSpacing(QVariant(0)), 7.5);
|
||||
QCOMPARE(FolioGrid::minDotSpacing(QVariant(-3)), 7.5);
|
||||
QCOMPARE(FolioGrid::minDotSpacing(QVariant(QStringLiteral("ten"))), 7.5);
|
||||
//Only what the preferences page offers, 1 to 50 px: no
|
||||
//endless or huge value hides the grid for good
|
||||
QCOMPARE(FolioGrid::minDotSpacing(QVariant(1.0)), 1.0);
|
||||
QCOMPARE(FolioGrid::minDotSpacing(QVariant(50.0)), 50.0);
|
||||
QCOMPARE(FolioGrid::minDotSpacing(QVariant(0.5)), 7.5);
|
||||
QCOMPARE(FolioGrid::minDotSpacing(QVariant(50.5)), 7.5);
|
||||
QCOMPARE(FolioGrid::minDotSpacing(QVariant(1e9)), 7.5);
|
||||
QCOMPARE(FolioGrid::minDotSpacing(QVariant(QStringLiteral("inf"))), 7.5);
|
||||
QCOMPARE(FolioGrid::minDotSpacing(QVariant(std::numeric_limits<double>::infinity())), 7.5);
|
||||
QCOMPARE(FolioGrid::minDotSpacing(QVariant(std::numeric_limits<double>::quiet_NaN())), 7.5);
|
||||
}
|
||||
|
||||
void usableValuesAreKept_data()
|
||||
|
||||
Reference in New Issue
Block a user