mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-02 08:24:14 +02:00
Share the text grid choices; add a preference, a status hint and a unit test
Drop 1:2.5: on a grid of 10 it steps by 4, which misses 10, so texts on two elements 10 apart could never line up. Every remaining divisor is a whole number, which tst_textgrid checks. The divisor list and the snapping arithmetic move to the header-only textgrid.h so the toolbar menu, the preferences page and the test share them. The preferences page gets the same choice under Grille + Clavier; QETApp::textGridChanged keeps every editor's toolbar button in step. While element texts are dragged, the status bar names the text grid and says to release Shift and hold Ctrl for free placement -- Ctrl+Shift together is the pan shortcut. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01G2d2Zi8BfrYRPX88zhaoFG
This commit is contained in:
@@ -91,6 +91,13 @@ add_test(NAME tst_contactusage COMMAND tst_contactusage)
|
||||
target_include_directories(tst_contactusage PRIVATE ${QET_DIR}/sources)
|
||||
target_link_libraries(tst_contactusage PRIVATE Qt::Test)
|
||||
|
||||
# textgrid.h is a header-only helper holding the text snap rules, so this
|
||||
# test builds independently of the rest of the QET sources.
|
||||
add_executable(tst_textgrid tst_textgrid.cpp)
|
||||
add_test(NAME tst_textgrid COMMAND tst_textgrid)
|
||||
target_include_directories(tst_textgrid PRIVATE ${QET_DIR}/sources)
|
||||
target_link_libraries(tst_textgrid PRIVATE Qt::Test)
|
||||
|
||||
add_executable(
|
||||
tst_qetpalette
|
||||
tst_qetpalette.cpp
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
#include <QtTest>
|
||||
|
||||
#include "textgrid.h"
|
||||
|
||||
class tst_textgrid : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
// A label starting off the grid at (-13.3, 13.7), the case from
|
||||
// discussion #1020: the sideways jump shrinks with a finer text grid.
|
||||
void snapsToStep_data()
|
||||
{
|
||||
QTest::addColumn<int>("grid");
|
||||
QTest::addColumn<qreal>("divisor");
|
||||
QTest::addColumn<QPointF>("expected");
|
||||
|
||||
QTest::newRow("off rounds to pixel") << 10 << 0.0 << QPointF(-13, 14);
|
||||
QTest::newRow("1:1 is the folio grid") << 10 << 1.0 << QPointF(-10, 10);
|
||||
QTest::newRow("1:2") << 10 << 2.0 << QPointF(-15, 15);
|
||||
QTest::newRow("1:5") << 10 << 5.0 << QPointF(-14, 14);
|
||||
QTest::newRow("1:10") << 10 << 10.0 << QPointF(-13, 14);
|
||||
QTest::newRow("grid 7, 1:2 steps 3.5") << 7 << 2.0 << QPointF(-14, 14);
|
||||
}
|
||||
|
||||
void snapsToStep()
|
||||
{
|
||||
QFETCH(int, grid);
|
||||
QFETCH(qreal, divisor);
|
||||
QFETCH(QPointF, expected);
|
||||
|
||||
const QPointF snapped = TextGrid::snap(QPointF(-13.3, 13.7), grid, grid, divisor);
|
||||
QCOMPARE(snapped.x(), expected.x());
|
||||
QCOMPARE(snapped.y(), expected.y());
|
||||
}
|
||||
|
||||
// Every folio grid point is also a text grid point, so a text can
|
||||
// always sit exactly where an element or a wire does, and texts of
|
||||
// different elements can line up. This is why every divisor offered
|
||||
// is a whole number: 1:2.5 on a grid of 10 steps by 4, which misses 10.
|
||||
void folioGridPointsAreKept_data()
|
||||
{
|
||||
QTest::addColumn<int>("grid");
|
||||
QTest::addColumn<qreal>("divisor");
|
||||
|
||||
for (int grid : {10, 7, 5})
|
||||
for (qreal divisor : TextGrid::divisors)
|
||||
if (divisor > 0)
|
||||
QTest::newRow(qPrintable(QStringLiteral("grid %1, %2")
|
||||
.arg(grid).arg(TextGrid::ratioLabel(divisor))))
|
||||
<< grid << divisor;
|
||||
}
|
||||
|
||||
void folioGridPointsAreKept()
|
||||
{
|
||||
QFETCH(int, grid);
|
||||
QFETCH(qreal, divisor);
|
||||
|
||||
for (int k = -20; k <= 20; ++k) {
|
||||
const QPointF on_grid(k * grid, -k * grid);
|
||||
QCOMPARE(TextGrid::snap(on_grid, grid, grid, divisor), on_grid);
|
||||
}
|
||||
}
|
||||
|
||||
// Separate X and Y grid sizes are honoured independently.
|
||||
void usesEachAxisGrid()
|
||||
{
|
||||
QCOMPARE(TextGrid::snap(QPointF(13, 13), 10, 20, 2), QPointF(15, 10));
|
||||
}
|
||||
|
||||
void ratioLabel()
|
||||
{
|
||||
QCOMPARE(TextGrid::ratioLabel(2), QStringLiteral("1:2"));
|
||||
QCOMPARE(TextGrid::ratioLabel(10), QStringLiteral("1:10"));
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_GUILESS_MAIN(tst_textgrid)
|
||||
|
||||
#include "tst_textgrid.moc"
|
||||
Reference in New Issue
Block a user