mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-08 04:44:13 +02:00
Return qet.imageCrop() as {x, y, width, height}
The crop rectangle came back as the string "x,y,width,height", which a script had to split and parse. elementGeometry() returns a map; the crop now does the same, and an empty map for no such image. Suggested in the review of #1310. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
@@ -88,6 +88,13 @@ class tst_imagecropundo : public QObject
|
||||
if (!m.hasMatch()) return {};
|
||||
return QImage::fromData(QByteArray::fromBase64(m.captured(1).toLatin1())).size();
|
||||
}
|
||||
// qet.imageCrop()'s {x, y, width, height}, as logged by the script.
|
||||
static QRect rect(const QJsonValue &crop)
|
||||
{
|
||||
const QJsonObject o = crop.toObject();
|
||||
return QRect(o.value("x").toInt(-1), o.value("y").toInt(-1),
|
||||
o.value("width").toInt(-1), o.value("height").toInt(-1));
|
||||
}
|
||||
|
||||
private slots:
|
||||
void initTestCase()
|
||||
@@ -122,16 +129,16 @@ qet.log('PROBE ' + JSON.stringify(r));
|
||||
|
||||
const QJsonObject r = run(script, QStringLiteral(QET_EXAMPLES_DIR "/741.qet"));
|
||||
QVERIFY2(!r.isEmpty(), "the script logged nothing");
|
||||
QCOMPARE(r.value("full").toString(), QStringLiteral("0,0,40,30"));
|
||||
QCOMPARE(rect(r.value("full")), QRect(0, 0, 40, 30));
|
||||
QVERIFY(r.value("cropped_ok").toBool());
|
||||
QCOMPARE(r.value("cropped").toString(), QStringLiteral("10,5,20,10"));
|
||||
QCOMPARE(rect(r.value("cropped")), QRect(10, 5, 20, 10));
|
||||
// Crops that change nothing report it, and push no undo step:
|
||||
// the undo below still undoes the real crop.
|
||||
QCOMPARE(r.value("same_ok").toBool(true), false);
|
||||
QCOMPARE(r.value("empty_ok").toBool(true), false);
|
||||
QCOMPARE(r.value("outside_ok").toBool(true), false);
|
||||
QCOMPARE(r.value("undone").toString(), QStringLiteral("0,0,40,30"));
|
||||
QCOMPARE(r.value("redone").toString(), QStringLiteral("10,5,20,10"));
|
||||
QCOMPARE(rect(r.value("undone")), QRect(0, 0, 40, 30));
|
||||
QCOMPARE(rect(r.value("redone")), QRect(10, 5, 20, 10));
|
||||
|
||||
const QByteArray undone_xml = read(undone);
|
||||
QVERIFY(undone_xml.contains("<image "));
|
||||
|
||||
Reference in New Issue
Block a user