mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-28 04:54:13 +02:00
Let a script control the text fields drawn on a symbol
elementTexts() addElementText() setElementTextProperty() elementTextProperty() deleteElementText() A symbol arrives with the fields its definition gives it -- coil bobine_ka_a_remanence has A2, A1 and a label -- and until now a script could fill the value the label shows (setElementLabel) but not control the fields themselves: where each sits, its size, whether it is framed, what it is bound to, or add and delete one. A field's source is "text" (a fixed string), "info" (follows one of the element's information keys, so it follows setElementInfo and setElementLabel) or "composite" (a formula). Changes go through QPropertyUndoCommand on the item's own properties, as the element-texts editor does, and adding through AddElementTextCommand. An unknown source, a key that is not an element information key, a non-positive size and a bad index are refused with a reason. Two things called text differ for an information-bound field. The "text" property is the stored string, an unused placeholder (empty, or "Texte" for a newly added field); "shows" is what is drawn. I first believed the displayed text was stale in-session and wrote a helper to read it from the element's information instead. That was wrong: comparing toPlainText() against elementInfo() at seven points across relabel, rebinding, setting and undo found no difference. It was the stored string that looked stale, and the helper and the comment claiming the item "refreshes lazily" are removed. The header now says which is which. Fields are addressed by index in the element's own list, which follows the definition and shifts on delete; undoing a deletion puts the field back at the end. Consecutive info/label changes on one element merge into one undo step (ChangeElementInformationCommand::mergeWith), so one undo can revert several -- noted, not a bug. Verified on a coil: the label field moved, enlarged to 14 pt and framed, a new field bound to "comment" showing "24VDC coil", all through the project, exported to PNG and looked at. The saved file carries the moved position, size, frame and bound value, and a reload reads them back. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -31,6 +31,7 @@ class Conductor;
|
||||
class IndependentTextItem;
|
||||
class QetShapeItem;
|
||||
class DiagramImageItem;
|
||||
class DynamicElementTextItem;
|
||||
|
||||
/**
|
||||
@brief The QetScriptApi class
|
||||
@@ -184,6 +185,32 @@ class DiagramImageItem;
|
||||
position-sorted listing, like texts and shapes -- by the on-screen
|
||||
bounding box, so scaling or rotating an image, which turns about its
|
||||
centre, can change where it sorts. Re-list after either.
|
||||
- @b Element @b texts: the text fields drawn on a symbol -- its label,
|
||||
the names beside its terminals, any value the definition placed there.
|
||||
A symbol arrives with the fields its definition gives it; setElementLabel()
|
||||
fills the value one of them shows, and these methods control the fields
|
||||
themselves: where each sits, its size, whether it draws a frame, what it
|
||||
shows, and adding or deleting one. Addressed by index in the element's
|
||||
own list, which follows the definition's order and shifts when one is
|
||||
deleted -- and undoing a deletion puts the field back at the end, so
|
||||
list again after either.
|
||||
|
||||
Two things called text, which differ for a field bound to an
|
||||
information key: the @b "text" property is the field's stored string,
|
||||
which for an information-bound field is an unused placeholder (empty,
|
||||
or "Texte" once one has been added), and @b "shows" is what is drawn,
|
||||
which follows the element's information straight away -- compared
|
||||
against elementInfo() at seven points across relabel, rebinding,
|
||||
setting and undo, with no difference. Read "shows".
|
||||
|
||||
Consecutive setElementInfo()/setElementLabel() calls on one element
|
||||
merge into a single undo step, as ChangeElementInformationCommand
|
||||
does, so one undo can revert several.
|
||||
|
||||
A field's @b source is "text" (a fixed string), "info" (the value of one
|
||||
of the element's information keys, so it follows setElementInfo() and
|
||||
setElementLabel()) or "composite" (a formula over several). Position is in
|
||||
the element's own coordinates, not the folio's.
|
||||
- @b Navigating and @b messaging: select an element, zoom the active
|
||||
view, and show the user a message. Deliberately narrow: selection and
|
||||
messaging work with no view at all (headless `--run`); zoom is a no-op
|
||||
@@ -327,6 +354,18 @@ class QetScriptApi : public QObject
|
||||
Q_INVOKABLE bool setImageRotation(int folioIndex, int imageIndex, double angle);
|
||||
Q_INVOKABLE bool deleteImage(int folioIndex, int imageIndex);
|
||||
|
||||
// -- the text fields shown on a symbol (label, terminal names, ...) --
|
||||
Q_INVOKABLE QStringList elementTexts(int folioIndex, const QString &elementUuid) const;
|
||||
Q_INVOKABLE int addElementText(int folioIndex, const QString &elementUuid,
|
||||
const QString &source, const QString &value,
|
||||
double x, double y);
|
||||
Q_INVOKABLE bool setElementTextProperty(int folioIndex, const QString &elementUuid,
|
||||
int textIndex, const QString &property,
|
||||
const QString &value);
|
||||
Q_INVOKABLE QString elementTextProperty(int folioIndex, const QString &elementUuid,
|
||||
int textIndex, const QString &property) const;
|
||||
Q_INVOKABLE bool deleteElementText(int folioIndex, const QString &elementUuid, int textIndex);
|
||||
|
||||
// -- folios --
|
||||
Q_INVOKABLE int addFolio();
|
||||
Q_INVOKABLE bool setFolioTitle(int folioIndex, const QString &title);
|
||||
@@ -357,6 +396,8 @@ class QetScriptApi : public QObject
|
||||
QList<IndependentTextItem *> sortedTexts(int folioIndex) const;
|
||||
QList<QetShapeItem *> sortedShapes(int folioIndex) const;
|
||||
QList<DiagramImageItem *> sortedImages(int folioIndex) const;
|
||||
DynamicElementTextItem *findElementText(int folioIndex, const QString &elementUuid,
|
||||
int textIndex, const QString &caller) const;
|
||||
IndependentTextItem *findText(int folioIndex, int textIndex, const QString &caller);
|
||||
bool setInfoKey(int folioIndex, const QString &elementUuid,
|
||||
const QString &key, const QString &value, const QString &caller);
|
||||
|
||||
Reference in New Issue
Block a user