Merge pull request #371 from qelectrotech/master

Merge last commits on mastert to branch qt6-cmake
This commit is contained in:
Laurent Trinques
2025-02-28 13:46:46 +01:00
committed by GitHub
19 changed files with 127 additions and 73 deletions

View File

@@ -26,6 +26,7 @@ Comment[nl]=Bewerken bedradingsdiagrammen.
Comment[be]=Bewerken elektrisch schema.
Comment[da]=Rediger elektriske diagrammer.
Comment[ja]=電気回路図の編集。
Comment[sk]=Úprava elektrických schém.
GenericName=Electrical diagram editor
GenericName[de]=Schaltplaneditor
GenericName[fr]=Éditeur de schémas électriques
@@ -42,3 +43,4 @@ GenericName[nl]=Elektrische schema editor
GenericName[be]=Elektrische schema editor
GenericName[da]=Elektrisk diagram redigering
GenericName[ja]=電気回路図エディタ
GenericName[sk]=Editor elektrických schém

View File

@@ -20,6 +20,7 @@
#include "../diagram.h"
#include "../diagramposition.h"
#include "../qetapp.h"
#include "../qetgraphicsitem/conductor.h"
#include "../qetgraphicsitem/element.h"
#include "../qetxml.h"
@@ -189,12 +190,14 @@ namespace autonum
QString AssignVariables::formulaToLabel(QString formula,
sequentialNumbers &seqStruct,
Diagram *diagram,
const Element *elmt)
const Element *elmt,
const Conductor *cndr)
{
AssignVariables av(std::move(formula),
seqStruct,
diagram,
elmt);
elmt,
cndr);
seqStruct = av.m_seq_struct;
return av.m_assigned_label;
}
@@ -301,13 +304,14 @@ namespace autonum
AssignVariables::AssignVariables(const QString& formula,
const sequentialNumbers& seqStruct,
Diagram *diagram,
const Element *elmt):
const Element *elmt,
const Conductor *cndr):
m_diagram(diagram),
m_arg_formula(formula),
m_assigned_label(formula),
m_seq_struct(seqStruct),
m_element(elmt)
m_element(elmt),
m_conductor(cndr)
{
if (m_diagram)
{
@@ -349,6 +353,14 @@ namespace autonum
m_assigned_label.replace("%prefix", m_element->getPrefix());
}
if (m_conductor)
{
m_assigned_label.replace("%wf", cndr->properties().m_function);
m_assigned_label.replace("%wv", cndr->properties().m_tension_protocol);
m_assigned_label.replace("%wc", cndr->properties().m_wire_color);
m_assigned_label.replace("%ws", cndr->properties().m_wire_section);
}
assignTitleBlockVar();
assignProjectVar();
assignSequence();

View File

@@ -24,6 +24,7 @@
#include <QString>
#include <QStringList>
class Conductor;
class Diagram;
class Element;
class ElementsLocation;
@@ -61,12 +62,12 @@ namespace autonum
class AssignVariables
{
public:
static QString formulaToLabel (QString formula, sequentialNumbers &seqStruct, Diagram *diagram, const Element *elmt = nullptr);
static QString formulaToLabel (QString formula, sequentialNumbers &seqStruct, Diagram *diagram, const Element *elmt = nullptr, const Conductor *cndr = nullptr);
static QString replaceVariable (const QString &formula, const DiagramContext &dc);
static QString genericXref (const Element *element);
private:
AssignVariables(const QString& formula, const sequentialNumbers& seqStruct , Diagram *diagram, const Element *elmt = nullptr);
AssignVariables(const QString& formula, const sequentialNumbers& seqStruct , Diagram *diagram, const Element *elmt = nullptr, const Conductor *cndr = nullptr);
void assignTitleBlockVar();
void assignProjectVar();
void assignSequence();
@@ -76,6 +77,7 @@ namespace autonum
QString m_assigned_label;
sequentialNumbers m_seq_struct;
const Element *m_element = nullptr;
const Conductor *m_conductor = nullptr;
};
void setSequentialToList(QStringList &list, NumerotationContext &nc, const QString& type);

View File

@@ -248,9 +248,9 @@ void DiagramEventAddElement::addElement()
QUndoCommand *undo_object = new QUndoCommand(tr("Ajouter %1").arg(element->name()));
new AddGraphicsObjectCommand(element, m_diagram, m_element -> pos(), undo_object);
//When we search for free aligned terminal we
//temporally remove m_element to avoid any interaction with the function Element::AlignedFreeTerminals
//this is useful when an element who have two (or more) terminals opposite,
//When we search for free aligned terminal we temporally remove m_element to
//avoid any interaction with the function Element::AlignedFreeTerminals
//This is useful when an element has two (or more) terminals on opposite sides,
//because m_element is exactly at the same pos of the new element
//added to the scene so new conductor are created between terminal of the new element
//and the opposite terminal of m_element.

View File

@@ -541,19 +541,19 @@ void RotateElementsCommand::undo()
}
else if (item->type() == PartLine::Type) {
PartLine* line = qgraphicsitem_cast<PartLine*>(item);
line->setRotation(-90);
line->setRotation(line->rotation()-90);
}
else if (item->type() == PartPolygon::Type) {
PartPolygon* poly = qgraphicsitem_cast<PartPolygon*>(item);
poly->setRotation(-90);
poly->setRotation(poly->rotation()-90);
}
else if (item->type() == PartText::Type) {
PartText* text = qgraphicsitem_cast<PartText*>(item);
text->setRotation(-90);
text->setRotation(text->rotation()-90);
}
else if (item->type() == PartDynamicTextField::Type) {
PartDynamicTextField* dyntext = qgraphicsitem_cast<PartDynamicTextField*>(item);
dyntext->setRotation(-90);
dyntext->setRotation(dyntext->rotation()-90);
}
else {
item->setRotation(item->rotation()-90);
@@ -586,19 +586,19 @@ void RotateElementsCommand::redo()
}
else if (item->type() == PartLine::Type) {
PartLine* line = qgraphicsitem_cast<PartLine*>(item);
line->setRotation(+90);
line->setRotation(line->rotation()+90);
}
else if (item->type() == PartPolygon::Type) {
PartPolygon* poly = qgraphicsitem_cast<PartPolygon*>(item);
poly->setRotation(+90);
poly->setRotation(poly->rotation()+90);
}
else if (item->type() == PartText::Type) {
PartText* text = qgraphicsitem_cast<PartText*>(item);
text->setRotation(+90);
text->setRotation(text->rotation()+90);
}
else if (item->type() == PartDynamicTextField::Type) {
PartDynamicTextField* dyntext = qgraphicsitem_cast<PartDynamicTextField*>(item);
dyntext->setRotation(+90);
dyntext->setRotation(dyntext->rotation()+90);
}
else {
item->setRotation(item->rotation()+90);
@@ -622,22 +622,22 @@ void RotateFineElementsCommand::undo()
{
if (item->type() == PartLine::Type) {
PartLine* line = qgraphicsitem_cast<PartLine*>(item);
line->setRotation(-5);
line->setRotation(line->rotation()-5);
}
else if (item->type() == PartPolygon::Type) {
PartPolygon* poly = qgraphicsitem_cast<PartPolygon*>(item);
poly->setRotation(-5);
poly->setRotation(poly->rotation()-5);
}
else if (item->type() == PartText::Type) {
PartText* text = qgraphicsitem_cast<PartText*>(item);
text->setRotation(-5);
text->setRotation(text->rotation()-5);
}
else if (item->type() == PartDynamicTextField::Type) {
PartDynamicTextField* dyntext = qgraphicsitem_cast<PartDynamicTextField*>(item);
dyntext->setRotation(-5);
dyntext->setRotation(dyntext->rotation()-5);
}
else {
//item->setRotation(-5);
//item->setRotation(item->rotation()-5);
}
}
}
@@ -651,22 +651,22 @@ void RotateFineElementsCommand::redo()
{
if (item->type() == PartLine::Type) {
PartLine* line = qgraphicsitem_cast<PartLine*>(item);
line->setRotation(+5);
line->setRotation(line->rotation()+5);
}
else if (item->type() == PartPolygon::Type) {
PartPolygon* poly = qgraphicsitem_cast<PartPolygon*>(item);
poly->setRotation(+5);
poly->setRotation(poly->rotation()+5);
}
else if (item->type() == PartText::Type) {
PartText* text = qgraphicsitem_cast<PartText*>(item);
text->setRotation(+5);
text->setRotation(text->rotation()+5);
}
else if (item->type() == PartDynamicTextField::Type) {
PartDynamicTextField* dyntext = qgraphicsitem_cast<PartDynamicTextField*>(item);
dyntext->setRotation(+5);
dyntext->setRotation(dyntext->rotation()+5);
}
else {
//item->setRotation(+5);
//item->setRotation(item->rotation()+5);
}
}
}

View File

@@ -172,8 +172,10 @@ QPainterPath PartArc::shadowShape() const
void PartArc::setRotation(qreal angle) {
qreal diffAngle = qRound((angle - rotation()) * 100.0) / 100.0;
m_rot = QET::correctAngle(angle, true);
// idea taken from QET_ElementScaler:
if (angle > 0) {
if (diffAngle > 0) {
m_start_angle += 270.0 * 16;
while (m_start_angle < 0) { m_start_angle += (360*16); }
while (m_start_angle >= (360*16)) { m_start_angle -= (360*16); }

View File

@@ -67,8 +67,9 @@ QString PartDynamicTextField::xmlName() const
@param angle
*/
void PartDynamicTextField::setRotation(qreal angle) {
QGraphicsObject::setRotation(QET::correctAngle(rotation()+angle, true));
setPos(QTransform().rotate(angle).map(pos()));
qreal diffAngle = qRound((angle - rotation()) * 100.0) / 100.0;
QGraphicsObject::setRotation(QET::correctAngle(angle, true));
setPos(QTransform().rotate(diffAngle).map(pos()));
}
void PartDynamicTextField::mirror() {

View File

@@ -238,8 +238,10 @@ bool PartEllipse::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
void PartEllipse::setRotation(qreal angle) {
qreal diffAngle = qRound((angle - rotation()) * 100.0) / 100.0;
m_rot = QET::correctAngle(angle, true);
// idea taken from QET_ElementScaler:
if (angle > 0) {
if (diffAngle > 0) {
qreal width = m_rect.height();
qreal height = m_rect.width();
qreal x = (m_rect.y() + m_rect.height()) * (-1);

View File

@@ -579,9 +579,10 @@ void PartLine::setSecondEndLength(const qreal &l)
}
void PartLine::setRotation(qreal angle) {
m_rot += angle;
m_line.setP1(QTransform().rotate(angle).map(m_line.p1()));
m_line.setP2(QTransform().rotate(angle).map(m_line.p2()));
qreal diffAngle = qRound((angle - rotation()) * 100.0) / 100.0;
m_rot = QET::correctAngle(angle, true);
m_line.setP1(QTransform().rotate(diffAngle).map(m_line.p1()));
m_line.setP2(QTransform().rotate(diffAngle).map(m_line.p2()));
prepareGeometryChange();
setLine(m_line);
adjustHandlerPos();

View File

@@ -297,8 +297,9 @@ void PartPolygon::resetAllHandlerColor()
void PartPolygon::setRotation(qreal angle) {
QTransform rotation = QTransform().rotate(angle);
m_rot += angle;
qreal diffAngle = qRound((angle - rotation()) * 100.0) / 100.0;
m_rot = QET::correctAngle(angle, true);
QTransform rotation = QTransform().rotate(diffAngle);
setPolygon(rotation.map(m_polygon));
prepareGeometryChange();
adjustHandlerPos();

View File

@@ -168,12 +168,14 @@ void PartRectangle::setYRadius(qreal Y)
}
void PartRectangle::setRotation(qreal angle) {
qreal diffAngle = qRound((angle - rotation()) * 100.0) / 100.0;
m_rot = QET::correctAngle(angle, true);
// for whatever reason: with "rect" we need to use scene-positions...
auto pos = mapToScene(m_rect.x(),m_rect.y());
qreal width = m_rect.height();
qreal height = m_rect.width();
qreal x; qreal y;
if (angle > 0) {
if (diffAngle > 0) {
x = (pos.y() + m_rect.height()) * (-1);
y = pos.x();
} else {

View File

@@ -42,8 +42,9 @@ PartTerminal::~PartTerminal()
}
/**
Import terminal properties from an XML element
Importe les proprietes d'une borne depuis un element XML
@param xml_elmt Element XML a lire
@param xml_elmt Element XML a lire / XML element to read
*/
void PartTerminal::fromXml(const QDomElement &xml_elmt) {
d -> fromXml(xml_elmt);
@@ -166,8 +167,9 @@ void PartTerminal::setRotation(qreal angle) {
else if (180 <= angle_mod && angle_mod < 270) new_ori = Qet::South;
else new_ori = Qet::West;
qreal diffAngle = qRound((angle - rotation()) * 100.0) / 100.0;
double tmp, y, x;
if (angle > 0) {
if (diffAngle > 0) {
tmp = d->m_pos.y();
y = d->m_pos.x();
x = (-1) * tmp;

View File

@@ -68,8 +68,9 @@ PartText::~PartText()
@param angle
*/
void PartText::setRotation(qreal angle) {
QGraphicsObject::setRotation(QET::correctAngle(rotation()+angle, true));
setPos(QTransform().rotate(angle).map(pos()));
qreal diffAngle = qRound((angle - rotation()) * 100.0) / 100.0;
QGraphicsObject::setRotation(QET::correctAngle(angle, true));
setPos(QTransform().rotate(diffAngle).map(pos()));
}
void PartText::mirror() {

View File

@@ -1505,7 +1505,7 @@ void Conductor::refreshText()
{
if (diagram())
{
QString text = autonum::AssignVariables::formulaToLabel(m_properties.m_formula, m_autoNum_seq, diagram());
QString text = autonum::AssignVariables::formulaToLabel(m_properties.m_formula, m_autoNum_seq, diagram(), nullptr, this);
m_properties.text = text;
m_text_item->setPlainText(text);
}
@@ -1590,7 +1590,7 @@ void Conductor::setProperties(const ConductorProperties &property)
{
if (diagram())
{
QString text = autonum::AssignVariables::formulaToLabel(m_properties.m_formula, m_autoNum_seq, diagram());
QString text = autonum::AssignVariables::formulaToLabel(m_properties.m_formula, m_autoNum_seq, diagram(), nullptr, this);
m_properties.text = text;
}
else if (m_properties.text.isEmpty())

View File

@@ -545,8 +545,16 @@ void DynamicElementTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
if(m_slave_Xref_item)
m_slave_Xref_item->setDefaultTextColor(Qt::black);
}
DiagramTextItem::mousePressEvent(event);
// Shift or no parent initiates movement of dynamic text, otherwise movement of parent element
if((event->modifiers() & Qt::ShiftModifier) || !m_parent_element)
{
m_move_parent = false;
DiagramTextItem::mousePressEvent(event);
} else {
m_move_parent = true;
parentElement()->mousePressEvent(event);
}
}
/**
@@ -557,26 +565,33 @@ void DynamicElementTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if((event->buttons() & Qt::LeftButton) && (flags() & ItemIsMovable))
{
if(diagram() && m_first_move)
diagram()->elementTextsMover().beginMovement(diagram(), this);
if(m_first_move)
if(m_move_parent)
{
m_initial_position = pos();
if(parentElement())
parentElement()->setHighlighted(true);
parentElement()->mouseMoveEvent(event);
} else {
if(diagram() && m_first_move)
diagram()->elementTextsMover().beginMovement(diagram(), this);
if(m_first_move)
{
m_initial_position = pos();
if(parentElement())
parentElement()->setHighlighted(true);
}
QPointF current_parent_pos;
QPointF button_down_parent_pos;
current_parent_pos = mapToParent(mapFromScene(event->scenePos()));
button_down_parent_pos = mapToParent(mapFromScene(event->buttonDownScenePos(Qt::LeftButton)));
int diffx = qRound(current_parent_pos.x() - button_down_parent_pos.x());
int diffy = qRound(current_parent_pos.y() - button_down_parent_pos.y());
QPointF new_pos = m_initial_position + QPointF(diffx, diffy);
setPos(new_pos);
if(diagram())
diagram()->elementTextsMover().continueMovement(event);
}
QPointF current_parent_pos;
QPointF button_down_parent_pos;
current_parent_pos = mapToParent(mapFromScene(event->scenePos()));
button_down_parent_pos = mapToParent(mapFromScene(event->buttonDownScenePos(Qt::LeftButton)));
QPointF new_pos = m_initial_position + current_parent_pos - button_down_parent_pos;
event->modifiers() == Qt::ControlModifier ? setPos(new_pos) : setPos(Diagram::snapToGrid(new_pos));
if(diagram())
diagram()->elementTextsMover().continueMovement(event);
} else {
event->ignore();
}
@@ -591,14 +606,19 @@ void DynamicElementTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
*/
void DynamicElementTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (m_parent_element)
m_parent_element->setHighlighted(false);
if(m_move_parent)
{
parentElement()->mouseReleaseEvent(event);
} else {
if (m_parent_element)
m_parent_element->setHighlighted(false);
if(m_parent_element && m_parent_element->diagram())
m_parent_element.data()->diagram()->elementTextsMover().endMovement();
if(!(event->modifiers() & Qt::ControlModifier))
QGraphicsTextItem::mouseReleaseEvent(event);
if(m_parent_element && m_parent_element->diagram())
m_parent_element.data()->diagram()->elementTextsMover().endMovement();
if(!(event->modifiers() & Qt::ControlModifier))
QGraphicsTextItem::mouseReleaseEvent(event);
}
}
/**

View File

@@ -170,6 +170,7 @@ class DynamicElementTextItem : public DiagramTextItem
QPointF m_initial_position;
bool m_keep_visual_rotation = true;
qreal m_visual_rotation_ref = 0;
bool m_move_parent = true;
};
#endif // DYNAMICELEMENTTEXTITEM_H

View File

@@ -42,6 +42,7 @@ class ElementTextItemGroup;
class Element : public QetGraphicsItem
{
friend class DiagramEventAddElement;
friend class DynamicElementTextItem;
Q_OBJECT
public:

View File

@@ -695,11 +695,15 @@ bool Terminal::valideXml(QDomElement &terminal)
/**
@brief Terminal::fromXml
Enables you to find out whether an XML element represents this terminal.
Warning, the XML element is not checked
Permet de savoir si un element XML represente cette borne. Attention,
l'element XML n'est pas verifie
@param terminal Le QDomElement a analyser
@param terminal Le QDomElement a analyser / QDomElement to check
@return true si la borne "se reconnait"
(memes coordonnes, meme orientation), false sinon
true, if the terminal recognises itself (same coordinates,
same orientation), false otherwise
*/
bool Terminal::fromXml(QDomElement &terminal)
{