mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-10 06:04:12 +02:00
Add "Scale element..." to the element editor, keeping terminals on the grid
Edit > Scale element... scales the whole element about its hotspot by a factor picked from x0.5, x1.5, x2, x2.5, x3, x4. Only the factors that leave every terminal on the 10 px folio grid are offered, so wires to a scaled element stay straight. An element whose terminals are off the grid today is offered only the factors that bring them on to it; if none does, the dialog says so and OK is disabled. Drawn parts are scaled with their existing handleUserTransformation(), as the resize handles do. Texts, dynamic text fields and terminals are set directly so that font sizes (whole points, 4 pt minimum), terminal name offsets and line end sizes scale too, which the resize handles do not do. One undo step restores the element. Unlike "Import an element to resize", this needs no external program and works on the element being edited. Grew out of issue #1338. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -149,6 +149,13 @@ add_test(NAME tst_terminalnamecheck COMMAND tst_terminalnamecheck)
|
||||
target_include_directories(tst_terminalnamecheck PRIVATE ${QET_DIR}/sources)
|
||||
target_link_libraries(tst_terminalnamecheck PRIVATE Qt::Test)
|
||||
|
||||
# symbolscale.h is header-only: which factors the element editor offers
|
||||
# for scaling an element without taking its terminals off the grid.
|
||||
add_executable(tst_symbolscale tst_symbolscale.cpp)
|
||||
add_test(NAME tst_symbolscale COMMAND tst_symbolscale)
|
||||
target_include_directories(tst_symbolscale PRIVATE ${QET_DIR}/sources)
|
||||
target_link_libraries(tst_symbolscale PRIVATE Qt::Test)
|
||||
|
||||
# configprofile.h is header-only: which settings a saved configuration
|
||||
# profile carries, and how loading one replaces the live settings.
|
||||
add_executable(tst_configprofile tst_configprofile.cpp)
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
Copyright 2006-2026 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <QtTest>
|
||||
|
||||
#include "editor/symbolscale.h"
|
||||
|
||||
class tst_symbolscale : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
// Terminals 10 px apart: whole factors are safe, halving is not.
|
||||
void tenPitchTakesWholeFactors()
|
||||
{
|
||||
const QList<QPointF> terminals{{0, -20}, {0, 20}, {10, 0}};
|
||||
QCOMPARE(SymbolScale::safeFactors(terminals),
|
||||
(QList<qreal>{2.0, 3.0, 4.0}));
|
||||
}
|
||||
|
||||
// Terminals 20 px apart: every candidate is safe.
|
||||
void twentyPitchTakesEverything()
|
||||
{
|
||||
const QList<QPointF> terminals{{-20, 0}, {20, 40}};
|
||||
QCOMPARE(SymbolScale::safeFactors(terminals), SymbolScale::candidates());
|
||||
}
|
||||
|
||||
// Off the grid by 5 px today: only even factors bring it on.
|
||||
void fivePxOffIsRescuedByEvenFactors()
|
||||
{
|
||||
const QList<QPointF> terminals{{-5, 0}, {5, 30}};
|
||||
QVERIFY(!SymbolScale::allOnGrid(terminals));
|
||||
QCOMPARE(SymbolScale::offGridCount(terminals), 2);
|
||||
QCOMPARE(SymbolScale::safeFactors(terminals),
|
||||
(QList<qreal>{2.0, 4.0}));
|
||||
}
|
||||
|
||||
// Off by an odd amount: nothing helps.
|
||||
void oddOffsetHasNoSafeFactor()
|
||||
{
|
||||
QVERIFY(SymbolScale::safeFactors({{-7, 0}, {0, 20}}).isEmpty());
|
||||
}
|
||||
|
||||
void noTerminalTakesEverything()
|
||||
{
|
||||
QCOMPARE(SymbolScale::safeFactors({}), SymbolScale::candidates());
|
||||
}
|
||||
|
||||
// Saved with two decimals: 19.999 still counts as 20.
|
||||
void savedRoundingIsTolerated()
|
||||
{
|
||||
QVERIFY(SymbolScale::onGrid(19.999));
|
||||
QVERIFY(SymbolScale::onGrid(-30.001));
|
||||
QVERIFY(!SymbolScale::onGrid(19.9));
|
||||
}
|
||||
|
||||
void fontSizeIsWholeAndReadable()
|
||||
{
|
||||
QCOMPARE(SymbolScale::scaledFontSize(9, 2.0), 18);
|
||||
QCOMPARE(SymbolScale::scaledFontSize(9, 1.5), 14);
|
||||
QCOMPARE(SymbolScale::scaledFontSize(6, 0.5), 4);
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_APPLESS_MAIN(tst_symbolscale)
|
||||
#include "tst_symbolscale.moc"
|
||||
Reference in New Issue
Block a user