Add a generic device: a box symbol with terminals on any side

Edit > Add > Generic device (also on the Add toolbar, and found by the
command search as diagrameditor.add_generic_device) opens a three-page
wizard for devices used too rarely to draw a symbol for, such as a VSD
or a power supply:

1. Layout: terminals per side (0 for none), a gap every N terminals,
   divider marks on gaps, groups lined up across opposite sides, pitch
   and extra size.
2. Terminals: a table per side and the same list as one line, where
   In{4} is In1..In4, Q{z4} is Q0..Q3, X{3-6} is X3..X6 and an empty
   entry is a gap; number pins 1..n counter-clockwise; paste rows of
   side, name, function from a spreadsheet or a CSV file.
3. Information: name, label, manufacturer, reference, description.

A preview beside every page shows the box as it will be placed. Finish,
available from the first page, writes an ordinary symbol to the folder
"Generic devices" of the project's collection and puts it on the cursor.
The box sizes itself to its terminals and their names; every terminal
lands on the grid and gets a uuid. No new XML: any QElectroTech reads it.

The layout is pure (sources/genericdevice/genericdevice.cpp) and tested
by tst_genericdevice. ElementPictureFactory gains pictureFromDefinition()
to draw the preview with the same code as a placed element.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-10-09 23:27:37 +13:00
parent ff35d0dc69
commit a3594c6633
24 changed files with 2729 additions and 1 deletions
+23
View File
@@ -257,6 +257,29 @@ ElementPictureFactory::~ElementPictureFactory()
}
}
/**
@brief ElementPictureFactory::pictureFromDefinition
@return the drawing of an element @a definition that is in no
collection yet, such as one being made by a dialog, drawn by the same
code as a placed element. Not cached.
*/
QPicture ElementPictureFactory::pictureFromDefinition(const QDomElement &definition) const
{
QPicture picture;
QPainter painter(&picture);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setRenderHint(QPainter::TextAntialiasing, true);
primitives primitives_;
const QDomElement description = definition.firstChildElement(QStringLiteral("description"));
for (QDomElement part = description.firstChildElement() ; !part.isNull() ;
part = part.nextSiblingElement()) {
parseElement(part, painter, primitives_);
}
painter.end();
qDeleteAll(primitives_.m_texts);
return picture;
}
/**
@brief ElementPictureFactory::build
Build the picture from location.