Files
qelectrotech-source-mirror/tests/qttest/tst_textlines.cpp
T
Beat Hangartner d464428642 Export wrapped texts to DXF line by line
A symbol text with a width (text_width) is drawn wrapped on the folio,
but the DXF export split texts on '\n' only, so it was written as one
long line, running past its box and over the drawing. The export now
writes the lines of folio texts as they are laid out
(TextLines::layoutLines(), new header-only textlines.h). Texts without
a width give the same lines as before.

Tests: tst_textlines, tst_dxfwrappedtext (fails without this change).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 18:00:26 +02:00

55 lines
1.8 KiB
C++

/*
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 <QTextDocument>
#include <QTextOption>
#include "textlines.h"
class tst_textlines : public QObject
{
Q_OBJECT
private slots:
// A text without a width gives its own lines.
void unwrappedTextGivesItsLines()
{
QTextDocument document(QStringLiteral("Motor protection\nswitch Q12"));
QCOMPARE(TextLines::layoutLines(&document),
QStringList({QStringLiteral("Motor protection"), QStringLiteral("switch Q12")}));
}
// A text wrapped to its width gives one line per drawn line, without
// the space the line was broken at.
void wrappedTextGivesTheDrawnLines()
{
QTextDocument document(QStringLiteral("Motor protection switch Q12"));
QTextOption option = document.defaultTextOption();
option.setWrapMode(QTextOption::WordWrap);
document.setDefaultTextOption(option);
document.setTextWidth(1);
QCOMPARE(TextLines::layoutLines(&document),
QStringList({QStringLiteral("Motor"), QStringLiteral("protection"),
QStringLiteral("switch"), QStringLiteral("Q12")}));
}
};
QTEST_MAIN(tst_textlines)
#include "tst_textlines.moc"