mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 13:30:34 +01:00
Revert Martin pull request for now, and return to last 7e9fd8df9 commit
This commit is contained in:
@@ -863,53 +863,6 @@ bool Diagram::initFromXml(QDomElement &document, QPointF position, bool consider
|
|||||||
return(from_xml);
|
return(from_xml);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief findTerminal
|
|
||||||
* Find terminal to which the conductor should be connected
|
|
||||||
* \param conductor_index 1 or 2 depending on which terminal is searched
|
|
||||||
* \param f Conductor xml element
|
|
||||||
* \param table_adr_id Hash table to all terminal id assignement (legacy)
|
|
||||||
* \param added_elements Elements found in the xml file
|
|
||||||
* \return
|
|
||||||
*/
|
|
||||||
Terminal* findTerminal(int conductor_index, QDomElement& f, QHash<int, Terminal *>& table_adr_id, QList<Element *>& added_elements) {
|
|
||||||
assert(conductor_index == 1 || conductor_index == 2);
|
|
||||||
|
|
||||||
QString element_index = "element" + QString::number(conductor_index);
|
|
||||||
QString terminal_index = "terminal" + QString::number(conductor_index);
|
|
||||||
|
|
||||||
if (f.hasAttribute(element_index)) {
|
|
||||||
QUuid element_uuid = QUuid(f.attribute(element_index));
|
|
||||||
// element1 did not exist in the conductor part of the xml until prior 0.7
|
|
||||||
// It is used as an indicator that uuid's are used to identify terminals
|
|
||||||
bool element_found = false;
|
|
||||||
for (auto element: added_elements) {
|
|
||||||
if (element->uuid() != element_uuid)
|
|
||||||
continue;
|
|
||||||
element_found = true;
|
|
||||||
QUuid terminal_uuid = QUuid(f.attribute(terminal_index));
|
|
||||||
for (auto terminal: element->terminals()) {
|
|
||||||
if (terminal->uuid() != terminal_uuid)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
return terminal;
|
|
||||||
}
|
|
||||||
qDebug() << "Diagram::fromXml() : "<< terminal_index << ":" << terminal_uuid << "not found in " << element_index << ":" << element_uuid;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (!element_found)
|
|
||||||
qDebug() << "Diagram::fromXml() : " << element_index << ": " << element_uuid << "not found";
|
|
||||||
} else {
|
|
||||||
// Backward compatibility. Until version 0.7 a generated id is used to link the terminal.
|
|
||||||
int id_p1 = f.attribute(terminal_index).toInt();
|
|
||||||
if (!table_adr_id.contains(id_p1)) {
|
|
||||||
qDebug() << "Diagram::fromXml() : terminal id " << id_p1 << " not found";
|
|
||||||
} else
|
|
||||||
return table_adr_id.value(id_p1);
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Importe le schema decrit dans un element XML. Si une position est
|
Importe le schema decrit dans un element XML. Si une position est
|
||||||
precisee, les elements importes sont positionnes de maniere a ce que le
|
precisee, les elements importes sont positionnes de maniere a ce que le
|
||||||
@@ -1078,11 +1031,13 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
|
|||||||
if (!Conductor::valideXml(f)) continue;
|
if (!Conductor::valideXml(f)) continue;
|
||||||
|
|
||||||
//Check if terminal that conductor must be linked is know
|
//Check if terminal that conductor must be linked is know
|
||||||
|
int id_p1 = f.attribute("terminal1").toInt();
|
||||||
Terminal* p1 = findTerminal(1, f, table_adr_id, added_elements);
|
int id_p2 = f.attribute("terminal2").toInt();
|
||||||
Terminal* p2 = findTerminal(2, f, table_adr_id, added_elements);
|
if (table_adr_id.contains(id_p1) && table_adr_id.contains(id_p2))
|
||||||
|
{
|
||||||
if (p1 && p2 && p1 != p2)
|
Terminal *p1 = table_adr_id.value(id_p1);
|
||||||
|
Terminal *p2 = table_adr_id.value(id_p2);
|
||||||
|
if (p1 != p2)
|
||||||
{
|
{
|
||||||
Conductor *c = new Conductor(p1, p2);
|
Conductor *c = new Conductor(p1, p2);
|
||||||
if (c->isValid())
|
if (c->isValid())
|
||||||
@@ -1095,6 +1050,8 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
|
|||||||
delete c;
|
delete c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else qDebug() << "Diagram::fromXml() : Le chargement du conducteur" << id_p1 << id_p2 << "a echoue";
|
||||||
|
}
|
||||||
|
|
||||||
//Load tables
|
//Load tables
|
||||||
QVector<QetGraphicsTableItem *> added_tables;
|
QVector<QetGraphicsTableItem *> added_tables;
|
||||||
|
|||||||
@@ -128,10 +128,6 @@ CustomElementPart *ArcEditor::currentPart() const {
|
|||||||
return(part);
|
return(part);
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<CustomElementPart*> ArcEditor::currentParts() const {
|
|
||||||
return style_->currentParts();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ArcEditor::updateArcS
|
* @brief ArcEditor::updateArcS
|
||||||
* Update the start angle of the arc according to the edited value.
|
* Update the start angle of the arc according to the edited value.
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ class ArcEditor : public ElementItemEditor
|
|||||||
public:
|
public:
|
||||||
bool setPart(CustomElementPart *) override;
|
bool setPart(CustomElementPart *) override;
|
||||||
CustomElementPart *currentPart() const override;
|
CustomElementPart *currentPart() const override;
|
||||||
QList<CustomElementPart*> currentParts() const override;
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateArcS();
|
void updateArcS();
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ class ElementItemEditor : public QWidget
|
|||||||
virtual bool setParts(QList <CustomElementPart *>) {return false;}
|
virtual bool setParts(QList <CustomElementPart *>) {return false;}
|
||||||
|
|
||||||
virtual CustomElementPart *currentPart() const = 0;
|
virtual CustomElementPart *currentPart() const = 0;
|
||||||
virtual QList<CustomElementPart*> currentParts() const = 0;
|
|
||||||
virtual void updateForm() = 0;
|
virtual void updateForm() = 0;
|
||||||
|
|
||||||
// attributes
|
// attributes
|
||||||
|
|||||||
@@ -109,10 +109,6 @@ CustomElementPart *EllipseEditor::currentPart() const {
|
|||||||
return(part);
|
return(part);
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<CustomElementPart*> EllipseEditor::currentParts() const {
|
|
||||||
return style_->currentParts();
|
|
||||||
}
|
|
||||||
|
|
||||||
void EllipseEditor::editingFinished()
|
void EllipseEditor::editingFinished()
|
||||||
{
|
{
|
||||||
if (m_locked) return;
|
if (m_locked) return;
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ class EllipseEditor : public ElementItemEditor
|
|||||||
public:
|
public:
|
||||||
bool setPart(CustomElementPart *) override;
|
bool setPart(CustomElementPart *) override;
|
||||||
CustomElementPart *currentPart() const override;
|
CustomElementPart *currentPart() const override;
|
||||||
QList<CustomElementPart*> currentParts() const override;
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void editingFinished();
|
void editingFinished();
|
||||||
|
|||||||
@@ -25,11 +25,9 @@
|
|||||||
@param scene La scene sur laquelle figure cette borne
|
@param scene La scene sur laquelle figure cette borne
|
||||||
*/
|
*/
|
||||||
PartTerminal::PartTerminal(QETElementEditor *editor, QGraphicsItem *parent) :
|
PartTerminal::PartTerminal(QETElementEditor *editor, QGraphicsItem *parent) :
|
||||||
CustomElementGraphicPart(editor, parent)
|
CustomElementGraphicPart(editor, parent),
|
||||||
|
m_orientation(Qet::North)
|
||||||
{
|
{
|
||||||
d = new TerminalData(this);
|
|
||||||
d->m_orientation = Qet::North;
|
|
||||||
d->m_uuid = QUuid::createUuid(); // if part is loaded this uuid will be overwritten, but being sure that terminal has a uuid
|
|
||||||
updateSecondPoint();
|
updateSecondPoint();
|
||||||
setZValue(100000);
|
setZValue(100000);
|
||||||
}
|
}
|
||||||
@@ -43,8 +41,15 @@ PartTerminal::~PartTerminal() {
|
|||||||
@param xml_elmt Element XML a lire
|
@param xml_elmt Element XML a lire
|
||||||
*/
|
*/
|
||||||
void PartTerminal::fromXml(const QDomElement &xml_elmt) {
|
void PartTerminal::fromXml(const QDomElement &xml_elmt) {
|
||||||
d->fromXml(xml_elmt);
|
// lit la position de la borne
|
||||||
setPos(d->m_pos);
|
qreal term_x = 0.0, term_y = 0.0;
|
||||||
|
QET::attributeIsAReal(xml_elmt, "x", &term_x);
|
||||||
|
QET::attributeIsAReal(xml_elmt, "y", &term_y);
|
||||||
|
setPos(QPointF(term_x, term_y));
|
||||||
|
|
||||||
|
// lit l'orientation de la borne
|
||||||
|
m_orientation = Qet::orientationFromString(xml_elmt.attribute("orientation"));
|
||||||
|
|
||||||
updateSecondPoint();
|
updateSecondPoint();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +59,18 @@ void PartTerminal::fromXml(const QDomElement &xml_elmt) {
|
|||||||
@return un element XML decrivant la borne
|
@return un element XML decrivant la borne
|
||||||
*/
|
*/
|
||||||
const QDomElement PartTerminal::toXml(QDomDocument &xml_document) const {
|
const QDomElement PartTerminal::toXml(QDomDocument &xml_document) const {
|
||||||
return d->toXml(xml_document);
|
QDomElement xml_element = xml_document.createElement("terminal");
|
||||||
|
|
||||||
|
// ecrit la position de la borne
|
||||||
|
xml_element.setAttribute("x", QString("%1").arg(scenePos().x()));
|
||||||
|
xml_element.setAttribute("y", QString("%1").arg(scenePos().y()));
|
||||||
|
|
||||||
|
|
||||||
|
// ecrit l'orientation de la borne
|
||||||
|
xml_element.setAttribute("orientation", Qet::orientationToString(m_orientation));
|
||||||
|
// Write name and number to XML
|
||||||
|
|
||||||
|
return(xml_element);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -79,7 +95,7 @@ void PartTerminal::paint(QPainter *p, const QStyleOptionGraphicsItem *options, Q
|
|||||||
// dessin de la borne en rouge
|
// dessin de la borne en rouge
|
||||||
t.setColor(isSelected() ? Terminal::neutralColor : Qt::red);
|
t.setColor(isSelected() ? Terminal::neutralColor : Qt::red);
|
||||||
p -> setPen(t);
|
p -> setPen(t);
|
||||||
p -> drawLine(QPointF(0.0, 0.0), d->second_point);
|
p -> drawLine(QPointF(0.0, 0.0), second_point);
|
||||||
|
|
||||||
// dessin du point d'amarrage au conducteur en bleu
|
// dessin du point d'amarrage au conducteur en bleu
|
||||||
t.setColor(isSelected() ? Qt::red : Terminal::neutralColor);
|
t.setColor(isSelected() ? Qt::red : Terminal::neutralColor);
|
||||||
@@ -99,7 +115,7 @@ void PartTerminal::paint(QPainter *p, const QStyleOptionGraphicsItem *options, Q
|
|||||||
QPainterPath PartTerminal::shape() const
|
QPainterPath PartTerminal::shape() const
|
||||||
{
|
{
|
||||||
QPainterPath shape;
|
QPainterPath shape;
|
||||||
shape.lineTo(d->second_point);
|
shape.lineTo(second_point);
|
||||||
|
|
||||||
QPainterPathStroker pps;
|
QPainterPathStroker pps;
|
||||||
pps.setWidth(1);
|
pps.setWidth(1);
|
||||||
@@ -113,7 +129,7 @@ QPainterPath PartTerminal::shape() const
|
|||||||
*/
|
*/
|
||||||
QRectF PartTerminal::boundingRect() const
|
QRectF PartTerminal::boundingRect() const
|
||||||
{
|
{
|
||||||
QRectF br(QPointF(0, 0), d->second_point);
|
QRectF br(QPointF(0, 0), second_point);
|
||||||
br = br.normalized();
|
br = br.normalized();
|
||||||
|
|
||||||
qreal adjust = (SHADOWS_HEIGHT + 1) / 2;
|
qreal adjust = (SHADOWS_HEIGHT + 1) / 2;
|
||||||
@@ -127,31 +143,24 @@ QRectF PartTerminal::boundingRect() const
|
|||||||
*/
|
*/
|
||||||
void PartTerminal::setOrientation(Qet::Orientation ori)
|
void PartTerminal::setOrientation(Qet::Orientation ori)
|
||||||
{
|
{
|
||||||
if (d->m_orientation == ori) return;
|
if (m_orientation == ori) return;
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
d->m_orientation = ori;
|
m_orientation = ori;
|
||||||
updateSecondPoint();
|
updateSecondPoint();
|
||||||
emit orientationChanged();
|
emit orientationChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PartTerminal::setName(QString& name)
|
|
||||||
{
|
|
||||||
if (d->m_name == name) return;
|
|
||||||
d->m_name = name;
|
|
||||||
emit nameChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Met a jour la position du second point en fonction de la position et de
|
Met a jour la position du second point en fonction de la position et de
|
||||||
l'orientation de la borne.
|
l'orientation de la borne.
|
||||||
*/
|
*/
|
||||||
void PartTerminal::updateSecondPoint() {
|
void PartTerminal::updateSecondPoint() {
|
||||||
qreal ts = 4.0; // terminal size
|
qreal ts = 4.0; // terminal size
|
||||||
switch(d->m_orientation) {
|
switch(m_orientation) {
|
||||||
case Qet::North: d->second_point = QPointF(0.0, ts); break;
|
case Qet::North: second_point = QPointF(0.0, ts); break;
|
||||||
case Qet::East : d->second_point = QPointF(-ts, 0.0); break;
|
case Qet::East : second_point = QPointF(-ts, 0.0); break;
|
||||||
case Qet::South: d->second_point = QPointF(0.0, -ts); break;
|
case Qet::South: second_point = QPointF(0.0, -ts); break;
|
||||||
case Qet::West : d->second_point = QPointF(ts, 0.0); break;
|
case Qet::West : second_point = QPointF(ts, 0.0); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,8 +19,6 @@
|
|||||||
#define PART_TERMINAL_H
|
#define PART_TERMINAL_H
|
||||||
|
|
||||||
#include "customelementgraphicpart.h"
|
#include "customelementgraphicpart.h"
|
||||||
#include "QUuid"
|
|
||||||
#include "terminaldata.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -33,7 +31,6 @@ class PartTerminal : public CustomElementGraphicPart
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
Q_PROPERTY(Qet::Orientation orientation READ orientation WRITE setOrientation)
|
Q_PROPERTY(Qet::Orientation orientation READ orientation WRITE setOrientation)
|
||||||
Q_PROPERTY(QString name READ name WRITE setName)
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -45,7 +42,12 @@ class PartTerminal : public CustomElementGraphicPart
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void orientationChanged();
|
void orientationChanged();
|
||||||
void nameChanged();
|
|
||||||
|
// attributes
|
||||||
|
private:
|
||||||
|
Qet::Orientation m_orientation;
|
||||||
|
QPointF second_point;
|
||||||
|
|
||||||
|
|
||||||
// methods
|
// methods
|
||||||
public:
|
public:
|
||||||
@@ -55,7 +57,7 @@ class PartTerminal : public CustomElementGraphicPart
|
|||||||
* @return the QGraphicsItem type
|
* @return the QGraphicsItem type
|
||||||
*/
|
*/
|
||||||
int type() const override { return Type; }
|
int type() const override { return Type; }
|
||||||
QString name() const override { return d->m_name; }
|
QString name() const override { return(QObject::tr("borne", "element part name")); }
|
||||||
QString xmlName() const override { return(QString("terminal")); }
|
QString xmlName() const override { return(QString("terminal")); }
|
||||||
void fromXml(const QDomElement &) override;
|
void fromXml(const QDomElement &) override;
|
||||||
const QDomElement toXml(QDomDocument &) const override;
|
const QDomElement toXml(QDomDocument &) const override;
|
||||||
@@ -69,14 +71,11 @@ class PartTerminal : public CustomElementGraphicPart
|
|||||||
void startUserTransformation(const QRectF &) override;
|
void startUserTransformation(const QRectF &) override;
|
||||||
void handleUserTransformation(const QRectF &, const QRectF &) override;
|
void handleUserTransformation(const QRectF &, const QRectF &) override;
|
||||||
|
|
||||||
Qet::Orientation orientation() const {return d->m_orientation;}
|
Qet::Orientation orientation() const {return m_orientation;}
|
||||||
void setOrientation(Qet::Orientation ori);
|
void setOrientation(Qet::Orientation ori);
|
||||||
|
|
||||||
void setName(QString& name);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateSecondPoint();
|
void updateSecondPoint();
|
||||||
TerminalData* d; // pointer to the terminal data
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPointF saved_position_;
|
QPointF saved_position_;
|
||||||
|
|||||||
@@ -146,10 +146,6 @@ CustomElementPart *LineEditor::currentPart() const {
|
|||||||
return(part);
|
return(part);
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<CustomElementPart*> LineEditor::currentParts() const {
|
|
||||||
return style_->currentParts();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief LineEditor::editedP1
|
* @brief LineEditor::editedP1
|
||||||
* @return The edited P1 in item coordinate
|
* @return The edited P1 in item coordinate
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ class LineEditor : public ElementItemEditor
|
|||||||
public:
|
public:
|
||||||
bool setPart(CustomElementPart *) override;
|
bool setPart(CustomElementPart *) override;
|
||||||
CustomElementPart *currentPart() const override;
|
CustomElementPart *currentPart() const override;
|
||||||
QList<CustomElementPart*> currentParts() const override;
|
|
||||||
QPointF editedP1() const;
|
QPointF editedP1() const;
|
||||||
QPointF editedP2() const;
|
QPointF editedP2() const;
|
||||||
|
|
||||||
|
|||||||
@@ -610,72 +610,62 @@ void QETElementEditor::slot_setNoDragToView() {
|
|||||||
void QETElementEditor::slot_updateInformations()
|
void QETElementEditor::slot_updateInformations()
|
||||||
{
|
{
|
||||||
QList<QGraphicsItem *> selected_qgis = m_elmt_scene -> selectedItems();
|
QList<QGraphicsItem *> selected_qgis = m_elmt_scene -> selectedItems();
|
||||||
if (selected_qgis.isEmpty()) {
|
|
||||||
clearToolsDock();
|
|
||||||
m_default_informations -> setText(tr("%n partie(s) sélectionnée(s).",
|
|
||||||
"",
|
|
||||||
selected_qgis.size()));
|
|
||||||
m_default_informations -> setAlignment(Qt::AlignHCenter | Qt::AlignTop);
|
|
||||||
m_tools_dock_stack -> setCurrentIndex(0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<CustomElementPart *> cep_list;
|
QList<CustomElementPart *> cep_list;
|
||||||
|
bool style_editable = false;
|
||||||
|
|
||||||
CustomElementPart* part = dynamic_cast<CustomElementPart *>(selected_qgis.first());
|
//Test if part are editable by style editor
|
||||||
QString selection_xml_name = part->xmlName();
|
if (selected_qgis.size() >= 2)
|
||||||
bool same_xml_name = true;
|
{
|
||||||
bool style_editable = true;
|
style_editable = true;
|
||||||
for (QGraphicsItem *qgi: selected_qgis) {
|
foreach (QGraphicsItem *qgi, selected_qgis)
|
||||||
if (CustomElementPart *cep = dynamic_cast<CustomElementPart *>(qgi)) {
|
{
|
||||||
|
if (CustomElementPart *cep = dynamic_cast<CustomElementPart *>(qgi))
|
||||||
cep_list << cep;
|
cep_list << cep;
|
||||||
if (cep->xmlName() != selection_xml_name)
|
else
|
||||||
same_xml_name = false;
|
|
||||||
} else {
|
|
||||||
style_editable = false;
|
style_editable = false;
|
||||||
same_xml_name = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (style_editable)
|
if (style_editable)
|
||||||
style_editable = StyleEditor::isStyleEditable(cep_list);
|
style_editable = StyleEditor::isStyleEditable(cep_list);
|
||||||
|
|
||||||
if (same_xml_name) {
|
}
|
||||||
if (selection_xml_name == "terminal" ||
|
|
||||||
selection_xml_name == "text" ||
|
if(selected_qgis.size() == 1)
|
||||||
selection_xml_name == "dynamic_text") {
|
{
|
||||||
|
QGraphicsItem *qgi = selected_qgis.first();
|
||||||
|
if (CustomElementPart *selection = dynamic_cast<CustomElementPart *>(qgi))
|
||||||
|
{
|
||||||
|
if (QWidget *widget = m_tools_dock_stack->widget(1))
|
||||||
|
{
|
||||||
|
if (ElementItemEditor *editor = dynamic_cast<ElementItemEditor *>(widget))
|
||||||
|
{
|
||||||
|
if(editor->currentPart() == selection)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//There's one selected item
|
||||||
|
if (selected_qgis.size() == 1)
|
||||||
|
{
|
||||||
|
QGraphicsItem *qgi = selected_qgis.first();
|
||||||
|
if (CustomElementPart *selection = dynamic_cast<CustomElementPart *>(qgi))
|
||||||
|
{
|
||||||
|
//The current editor already edit the selected part
|
||||||
|
if (QWidget *widget = m_tools_dock_stack->widget(1))
|
||||||
|
if (ElementItemEditor *editor = dynamic_cast<ElementItemEditor *>(widget))
|
||||||
|
if(editor->currentPart() == selection)
|
||||||
|
return;
|
||||||
|
|
||||||
clearToolsDock();
|
clearToolsDock();
|
||||||
//We add the editor widget
|
//We add the editor widget
|
||||||
ElementItemEditor *editor = static_cast<ElementItemEditor*>(m_editors[selection_xml_name]);
|
QString selection_xml_name = selection -> xmlName();
|
||||||
|
ElementItemEditor *selection_editor = m_editors[selection_xml_name];
|
||||||
// TODO: Check if it takes longer than setting the parts again to the editor.
|
if (selection_editor)
|
||||||
bool equal = true;
|
|
||||||
QList<CustomElementPart*> parts = editor->currentParts();
|
|
||||||
if (parts.length() == cep_list.length()) {
|
|
||||||
for (auto cep: cep_list) {
|
|
||||||
bool part_found = false;
|
|
||||||
for (auto part: parts) {
|
|
||||||
if (part == cep) {
|
|
||||||
part_found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!part_found) {
|
|
||||||
equal = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
equal = false;
|
|
||||||
|
|
||||||
if (editor)
|
|
||||||
{
|
{
|
||||||
bool success = true;
|
if (selection_editor->setPart(selection))
|
||||||
if (equal == false) {
|
|
||||||
success = editor->setParts(cep_list);
|
|
||||||
}
|
|
||||||
if (success)
|
|
||||||
{
|
{
|
||||||
m_tools_dock_stack->insertWidget(1, editor);
|
m_tools_dock_stack->insertWidget(1, selection_editor);
|
||||||
m_tools_dock_stack -> setCurrentIndex(1);
|
m_tools_dock_stack -> setCurrentIndex(1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -683,13 +673,10 @@ void QETElementEditor::slot_updateInformations()
|
|||||||
qDebug() << "Editor refused part.";
|
qDebug() << "Editor refused part.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//There's several parts selecteds and all can be edited by style editor.
|
//There's several parts selecteds and all can be edited by style editor.
|
||||||
if (style_editable)
|
else if (style_editable)
|
||||||
{
|
{
|
||||||
clearToolsDock();
|
clearToolsDock();
|
||||||
ElementItemEditor *selection_editor = m_editors["style"];
|
ElementItemEditor *selection_editor = m_editors["style"];
|
||||||
|
|||||||
@@ -489,7 +489,6 @@ bool StyleEditor::setPart(CustomElementPart *new_part) {
|
|||||||
if (CustomElementGraphicPart *part_graphic = dynamic_cast<CustomElementGraphicPart *>(new_part))
|
if (CustomElementGraphicPart *part_graphic = dynamic_cast<CustomElementGraphicPart *>(new_part))
|
||||||
{
|
{
|
||||||
part = part_graphic;
|
part = part_graphic;
|
||||||
m_cep_list.append(part_graphic);
|
|
||||||
updateForm();
|
updateForm();
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
@@ -539,10 +538,6 @@ CustomElementPart *StyleEditor::currentPart() const {
|
|||||||
return(part);
|
return(part);
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<CustomElementPart*> StyleEditor::currentParts() const {
|
|
||||||
return m_cep_list;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief StyleEditor::isStyleEditable
|
* @brief StyleEditor::isStyleEditable
|
||||||
* @param cep_list
|
* @param cep_list
|
||||||
@@ -553,7 +548,7 @@ bool StyleEditor::isStyleEditable(QList<CustomElementPart *> cep_list)
|
|||||||
QStringList str;
|
QStringList str;
|
||||||
str << "arc" << "ellipse" << "line" << "polygon" << "rect";
|
str << "arc" << "ellipse" << "line" << "polygon" << "rect";
|
||||||
|
|
||||||
for (CustomElementPart *cep: cep_list)
|
foreach (CustomElementPart *cep, cep_list)
|
||||||
if (!str.contains(cep -> xmlName()))
|
if (!str.contains(cep -> xmlName()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|||||||
@@ -53,9 +53,8 @@ class StyleEditor : public ElementItemEditor
|
|||||||
// methods
|
// methods
|
||||||
public:
|
public:
|
||||||
bool setPart(CustomElementPart *) override;
|
bool setPart(CustomElementPart *) override;
|
||||||
bool setParts(QList<CustomElementPart *>);
|
bool setParts(QList<CustomElementPart *>) override;
|
||||||
CustomElementPart *currentPart() const override;
|
CustomElementPart *currentPart() const override;
|
||||||
QList<CustomElementPart*> currentParts() const override;
|
|
||||||
|
|
||||||
static bool isStyleEditable (QList <CustomElementPart *> cep_list);
|
static bool isStyleEditable (QList <CustomElementPart *> cep_list);
|
||||||
|
|
||||||
|
|||||||
@@ -25,29 +25,17 @@
|
|||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
|
||||||
TerminalEditor::TerminalEditor(QETElementEditor* editor, QWidget* parent):
|
|
||||||
ElementItemEditor(editor, parent)
|
|
||||||
{
|
|
||||||
m_part = nullptr;
|
|
||||||
m_terminals.clear();
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructeur
|
Constructeur
|
||||||
@param editor L'editeur d'element concerne
|
@param editor L'editeur d'element concerne
|
||||||
@param term La borne a editer
|
@param term La borne a editer
|
||||||
@param parent QWidget parent de ce widget
|
@param parent QWidget parent de ce widget
|
||||||
*/
|
*/
|
||||||
TerminalEditor::TerminalEditor(QETElementEditor *editor, QList<PartTerminal *> &terms, QWidget *parent) :
|
TerminalEditor::TerminalEditor(QETElementEditor *editor, PartTerminal *term, QWidget *parent) :
|
||||||
ElementItemEditor(editor, parent),
|
ElementItemEditor(editor, parent),
|
||||||
m_terminals(terms),
|
part(term),
|
||||||
m_part(terms.first())
|
m_locked(false)
|
||||||
{
|
{
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TerminalEditor::init() {
|
|
||||||
qle_x = new QDoubleSpinBox();
|
qle_x = new QDoubleSpinBox();
|
||||||
qle_y = new QDoubleSpinBox();
|
qle_y = new QDoubleSpinBox();
|
||||||
|
|
||||||
@@ -82,8 +70,6 @@ void TerminalEditor::init() {
|
|||||||
updateForm();
|
updateForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Destructeur
|
/// Destructeur
|
||||||
TerminalEditor::~TerminalEditor() {
|
TerminalEditor::~TerminalEditor() {
|
||||||
};
|
};
|
||||||
@@ -98,49 +84,21 @@ TerminalEditor::~TerminalEditor() {
|
|||||||
*/
|
*/
|
||||||
bool TerminalEditor::setPart(CustomElementPart *new_part)
|
bool TerminalEditor::setPart(CustomElementPart *new_part)
|
||||||
{
|
{
|
||||||
m_terminals.clear();
|
|
||||||
if (!new_part)
|
if (!new_part)
|
||||||
{
|
{
|
||||||
if (m_part)
|
if (part)
|
||||||
disconnect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
|
disconnect(part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
|
||||||
m_part = nullptr;
|
part = nullptr;
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
if (PartTerminal *part_terminal = static_cast<PartTerminal *>(new_part))
|
if (PartTerminal *part_terminal = dynamic_cast<PartTerminal *>(new_part))
|
||||||
{
|
{
|
||||||
if(m_part == part_terminal) return true;
|
if(part == part_terminal) return true;
|
||||||
if (m_part)
|
if (part)
|
||||||
disconnect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
|
disconnect(part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
|
||||||
m_part = part_terminal;
|
part = part_terminal;
|
||||||
updateForm();
|
updateForm();
|
||||||
connect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
|
connect(part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TerminalEditor::setParts(QList<CustomElementPart *> parts)
|
|
||||||
{
|
|
||||||
if (parts.isEmpty())
|
|
||||||
{
|
|
||||||
m_terminals.clear();
|
|
||||||
if (m_part)
|
|
||||||
disconnect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
|
|
||||||
m_part = nullptr;
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PartTerminal *part_terminal = static_cast<PartTerminal *>(parts.first()))
|
|
||||||
{
|
|
||||||
if (m_part)
|
|
||||||
disconnect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
|
|
||||||
m_part = part_terminal;
|
|
||||||
m_terminals.clear();
|
|
||||||
m_terminals.append(part_terminal);
|
|
||||||
for (int i=1; i < parts.length(); i++)
|
|
||||||
m_terminals.append(static_cast<PartTerminal*>(parts[i]));
|
|
||||||
updateForm();
|
|
||||||
connect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
return(false);
|
return(false);
|
||||||
@@ -150,15 +108,7 @@ bool TerminalEditor::setParts(QList<CustomElementPart *> parts)
|
|||||||
@return la primitive actuellement editee, ou 0 si ce widget n'en edite pas
|
@return la primitive actuellement editee, ou 0 si ce widget n'en edite pas
|
||||||
*/
|
*/
|
||||||
CustomElementPart *TerminalEditor::currentPart() const {
|
CustomElementPart *TerminalEditor::currentPart() const {
|
||||||
return(m_part);
|
return(part);
|
||||||
}
|
|
||||||
|
|
||||||
QList<CustomElementPart*> TerminalEditor::currentParts() const {
|
|
||||||
QList<CustomElementPart*> parts;
|
|
||||||
for (auto term: m_terminals) {
|
|
||||||
parts.append(static_cast<CustomElementPart*>(term));
|
|
||||||
}
|
|
||||||
return parts;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Met a jour l'orientation de la borne et cree un objet d'annulation
|
/// Met a jour l'orientation de la borne et cree un objet d'annulation
|
||||||
@@ -167,52 +117,27 @@ void TerminalEditor::updateTerminalO()
|
|||||||
if (m_locked) return;
|
if (m_locked) return;
|
||||||
m_locked = true;
|
m_locked = true;
|
||||||
QVariant var(orientation -> itemData(orientation -> currentIndex()));
|
QVariant var(orientation -> itemData(orientation -> currentIndex()));
|
||||||
|
if (var != part->property("orientation"))
|
||||||
for (int i=0; i < m_terminals.length(); i++) {
|
|
||||||
PartTerminal* term = m_terminals[i];
|
|
||||||
if (var != term->property("orientation"))
|
|
||||||
{
|
{
|
||||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(term, "orientation", term->property("orientation"), var);
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(part, "orientation", part->property("orientation"), var);
|
||||||
undo->setText(tr("Modifier l'orientation d'une borne"));
|
undo->setText(tr("Modifier l'orientation d'une borne"));
|
||||||
undoStack().push(undo);
|
undoStack().push(undo);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
m_locked = false;
|
m_locked = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TerminalEditor::updateXPos() {
|
void TerminalEditor::updatePos()
|
||||||
|
{
|
||||||
if (m_locked) return;
|
if (m_locked) return;
|
||||||
m_locked = true;
|
m_locked = true;
|
||||||
QPointF new_pos(qle_x->value(), 0);
|
QPointF new_pos(qle_x->value(), qle_y->value());
|
||||||
|
if (new_pos != part->pos())
|
||||||
for (int i=0; i < m_terminals.length(); i++) {
|
{
|
||||||
PartTerminal* term = m_terminals[i];
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(part, "pos", part->property("pos"), new_pos);
|
||||||
new_pos.setY(term->pos().y()); // change only x value
|
|
||||||
if (term->pos() != new_pos) {
|
|
||||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(term, "pos", term->property("pos"), new_pos);
|
|
||||||
undo->setText(tr("Déplacer une borne"));
|
undo->setText(tr("Déplacer une borne"));
|
||||||
undo->enableAnimation();
|
undo->enableAnimation();
|
||||||
undoStack().push(undo);
|
undoStack().push(undo);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
m_locked=false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TerminalEditor::updateYPos() {
|
|
||||||
if (m_locked) return;
|
|
||||||
m_locked = true;
|
|
||||||
QPointF new_pos(0, qle_y->value()); // change only y value
|
|
||||||
|
|
||||||
for (int i=0; i < m_terminals.length(); i++) {
|
|
||||||
PartTerminal* term = m_terminals[i];
|
|
||||||
new_pos.setX(term->pos().x());
|
|
||||||
if (term->pos() != new_pos) {
|
|
||||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(term, "pos", term->property("pos"), new_pos);
|
|
||||||
undo->setText(tr("Déplacer une borne"));
|
|
||||||
undo->enableAnimation();
|
|
||||||
undoStack().push(undo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_locked=false;
|
m_locked=false;
|
||||||
}
|
}
|
||||||
/// update Number and name, create cancel object
|
/// update Number and name, create cancel object
|
||||||
@@ -221,11 +146,11 @@ void TerminalEditor::updateYPos() {
|
|||||||
Met a jour le formulaire d'edition
|
Met a jour le formulaire d'edition
|
||||||
*/
|
*/
|
||||||
void TerminalEditor::updateForm() {
|
void TerminalEditor::updateForm() {
|
||||||
if (!m_part) return;
|
if (!part) return;
|
||||||
activeConnections(false);
|
activeConnections(false);
|
||||||
qle_x -> setValue(m_part->property("x").toReal());
|
qle_x -> setValue(part->property("x").toReal());
|
||||||
qle_y -> setValue(m_part->property("y").toReal());
|
qle_y -> setValue(part->property("y").toReal());
|
||||||
orientation -> setCurrentIndex(orientation->findData(m_part->property("orientation")));
|
orientation -> setCurrentIndex(orientation->findData(part->property("orientation")));
|
||||||
activeConnections(true);
|
activeConnections(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,14 +162,14 @@ void TerminalEditor::activeConnections(bool active)
|
|||||||
{
|
{
|
||||||
if (active)
|
if (active)
|
||||||
{
|
{
|
||||||
connect(qle_x, &QDoubleSpinBox::editingFinished, this, &TerminalEditor::updateXPos);
|
connect(qle_x, SIGNAL(editingFinished()), this, SLOT(updatePos()));
|
||||||
connect(qle_y, &QDoubleSpinBox::editingFinished, this, &TerminalEditor::updateYPos);
|
connect(qle_y, SIGNAL(editingFinished()), this, SLOT(updatePos()));
|
||||||
connect(orientation, QOverload<int>::of(&QComboBox::activated), this, &TerminalEditor::updateTerminalO);
|
connect(orientation, SIGNAL(activated(int)), this, SLOT(updateTerminalO()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
disconnect(qle_x, &QDoubleSpinBox::editingFinished, this, &TerminalEditor::updateXPos);
|
disconnect(qle_x, SIGNAL(editingFinished()), this, SLOT(updatePos()));
|
||||||
disconnect(qle_y, &QDoubleSpinBox::editingFinished, this, &TerminalEditor::updateYPos);
|
disconnect(qle_y, SIGNAL(editingFinished()), this, SLOT(updatePos()));
|
||||||
disconnect(orientation, QOverload<int>::of(&QComboBox::activated), this, &TerminalEditor::updateTerminalO);
|
disconnect(orientation, SIGNAL(activated(int)), this, SLOT(updateTerminalO()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,41 +26,31 @@ class QComboBox;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
This class provides a widget to edit terminals within the element editor.
|
This class provides a widget to edit terminals within the element editor.
|
||||||
The class is capable to change the values of multiple parts of the same time.
|
|
||||||
The displayed values are from the first selected element
|
|
||||||
*/
|
*/
|
||||||
class TerminalEditor : public ElementItemEditor {
|
class TerminalEditor : public ElementItemEditor {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
// Constructors, destructor
|
// Constructors, destructor
|
||||||
public:
|
public:
|
||||||
TerminalEditor(QETElementEditor *, QList<PartTerminal *>& terms, QWidget * = nullptr);
|
TerminalEditor(QETElementEditor *, PartTerminal * = nullptr, QWidget * = nullptr);
|
||||||
TerminalEditor(QETElementEditor *, QWidget * = nullptr);
|
|
||||||
|
|
||||||
~TerminalEditor() override;
|
~TerminalEditor() override;
|
||||||
private:
|
private:
|
||||||
TerminalEditor(const TerminalEditor &);
|
TerminalEditor(const TerminalEditor &);
|
||||||
|
|
||||||
void init();
|
|
||||||
|
|
||||||
// attributes
|
// attributes
|
||||||
private:
|
private:
|
||||||
QList<PartTerminal *> m_terminals;
|
PartTerminal *part;
|
||||||
PartTerminal *m_part{nullptr};
|
|
||||||
QDoubleSpinBox *qle_x, *qle_y;
|
QDoubleSpinBox *qle_x, *qle_y;
|
||||||
QComboBox *orientation;
|
QComboBox *orientation;
|
||||||
bool m_locked{false};
|
bool m_locked;
|
||||||
|
|
||||||
// methods
|
// methods
|
||||||
public:
|
public:
|
||||||
bool setPart(CustomElementPart *) override;
|
bool setPart(CustomElementPart *) override;
|
||||||
bool setParts(QList<CustomElementPart *> parts) override;
|
|
||||||
CustomElementPart *currentPart() const override;
|
CustomElementPart *currentPart() const override;
|
||||||
QList<CustomElementPart*> currentParts() const override;
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateTerminalO();
|
void updateTerminalO();
|
||||||
void updateXPos();
|
void updatePos();
|
||||||
void updateYPos();
|
|
||||||
void updateForm() override;
|
void updateForm() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -57,7 +57,10 @@ DynamicTextFieldEditor::~DynamicTextFieldEditor()
|
|||||||
*/
|
*/
|
||||||
bool DynamicTextFieldEditor::setPart(CustomElementPart *part)
|
bool DynamicTextFieldEditor::setPart(CustomElementPart *part)
|
||||||
{
|
{
|
||||||
disconnectConnections();
|
//Remove previous connection
|
||||||
|
if(!m_connection_list.isEmpty())
|
||||||
|
for(const QMetaObject::Connection& con : m_connection_list)
|
||||||
|
disconnect(con);
|
||||||
|
|
||||||
QGraphicsItem *qgi = part->toItem();
|
QGraphicsItem *qgi = part->toItem();
|
||||||
if(!qgi)
|
if(!qgi)
|
||||||
@@ -68,42 +71,21 @@ bool DynamicTextFieldEditor::setPart(CustomElementPart *part)
|
|||||||
m_text_field = static_cast<PartDynamicTextField *>(qgi);
|
m_text_field = static_cast<PartDynamicTextField *>(qgi);
|
||||||
updateForm();
|
updateForm();
|
||||||
|
|
||||||
setUpConnections();
|
//Setup the connection
|
||||||
|
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::colorChanged, [this](){this->updateForm();});
|
||||||
|
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::fontChanged, [this](){this->updateForm();});
|
||||||
|
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::taggChanged, [this](){this->updateForm();});
|
||||||
|
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::textFromChanged, [this](){this->updateForm();});
|
||||||
|
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::textChanged, [this](){this->updateForm();});
|
||||||
|
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::infoNameChanged, [this](){this->updateForm();});
|
||||||
|
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::rotationChanged, [this](){this->updateForm();});
|
||||||
|
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::frameChanged, [this](){this->updateForm();});
|
||||||
|
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::textWidthChanged,[this]() {this->updateForm();});
|
||||||
|
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::compositeTextChanged, [this]() {this->updateForm();});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DynamicTextFieldEditor::setParts(QList <CustomElementPart *> parts) {
|
|
||||||
if (parts.isEmpty())
|
|
||||||
{
|
|
||||||
m_parts.clear();
|
|
||||||
if (m_text_field) {
|
|
||||||
disconnectConnections();
|
|
||||||
}
|
|
||||||
m_text_field = nullptr;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PartDynamicTextField *part= static_cast<PartDynamicTextField *>(parts.first()))
|
|
||||||
{
|
|
||||||
if (m_text_field) {
|
|
||||||
disconnectConnections();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_text_field = part;
|
|
||||||
m_parts.clear();
|
|
||||||
m_parts.append(part);
|
|
||||||
for (int i=1; i < parts.length(); i++)
|
|
||||||
m_parts.append(static_cast<PartDynamicTextField*>(parts[i]));
|
|
||||||
|
|
||||||
setUpConnections();
|
|
||||||
|
|
||||||
updateForm();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief DynamicTextFieldEditor::currentPart
|
* @brief DynamicTextFieldEditor::currentPart
|
||||||
* @return The current edited part, note they can return nullptr if
|
* @return The current edited part, note they can return nullptr if
|
||||||
@@ -113,14 +95,6 @@ CustomElementPart *DynamicTextFieldEditor::currentPart() const {
|
|||||||
return m_text_field.data();
|
return m_text_field.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<CustomElementPart*> DynamicTextFieldEditor::currentParts() const {
|
|
||||||
QList<CustomElementPart*> parts;
|
|
||||||
for (auto part: m_parts) {
|
|
||||||
parts.append(static_cast<CustomElementPart*>(part));
|
|
||||||
}
|
|
||||||
return parts;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DynamicTextFieldEditor::updateForm()
|
void DynamicTextFieldEditor::updateForm()
|
||||||
{
|
{
|
||||||
if(m_text_field)
|
if(m_text_field)
|
||||||
@@ -154,29 +128,6 @@ void DynamicTextFieldEditor::updateForm()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DynamicTextFieldEditor::setUpConnections() {
|
|
||||||
assert(m_connection_list.isEmpty());
|
|
||||||
//Setup the connection
|
|
||||||
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::colorChanged, [this](){this->updateForm();});
|
|
||||||
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::fontChanged, [this](){this->updateForm();});
|
|
||||||
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::taggChanged, [this](){this->updateForm();});
|
|
||||||
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::textFromChanged, [this](){this->updateForm();});
|
|
||||||
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::textChanged, [this](){this->updateForm();});
|
|
||||||
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::infoNameChanged, [this](){this->updateForm();});
|
|
||||||
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::rotationChanged, [this](){this->updateForm();});
|
|
||||||
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::frameChanged, [this](){this->updateForm();});
|
|
||||||
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::textWidthChanged,[this]() {this->updateForm();});
|
|
||||||
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::compositeTextChanged, [this]() {this->updateForm();});
|
|
||||||
}
|
|
||||||
|
|
||||||
void DynamicTextFieldEditor::disconnectConnections() {
|
|
||||||
//Remove previous connection
|
|
||||||
if(!m_connection_list.isEmpty())
|
|
||||||
for(const QMetaObject::Connection& con : m_connection_list)
|
|
||||||
disconnect(con);
|
|
||||||
m_connection_list.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief DynamicTextFieldEditor::fillInfoComboBox
|
* @brief DynamicTextFieldEditor::fillInfoComboBox
|
||||||
* Fill the combo box "element information"
|
* Fill the combo box "element information"
|
||||||
@@ -205,100 +156,81 @@ void DynamicTextFieldEditor::fillInfoComboBox()
|
|||||||
|
|
||||||
void DynamicTextFieldEditor::on_m_x_sb_editingFinished()
|
void DynamicTextFieldEditor::on_m_x_sb_editingFinished()
|
||||||
{
|
{
|
||||||
double value = ui->m_x_sb->value();
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "x", m_text_field.data()->x(), ui->m_x_sb->value());
|
||||||
for (int i = 0; i < m_parts.length(); i++) {
|
|
||||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "x", m_parts[i]->x(), value);
|
|
||||||
undo->setText(tr("Déplacer un champ texte"));
|
undo->setText(tr("Déplacer un champ texte"));
|
||||||
undo->enableAnimation(true);
|
undo->enableAnimation(true);
|
||||||
undoStack().push(undo);
|
undoStack().push(undo);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void DynamicTextFieldEditor::on_m_y_sb_editingFinished()
|
void DynamicTextFieldEditor::on_m_y_sb_editingFinished()
|
||||||
{
|
{
|
||||||
double value = ui->m_y_sb->value();
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "y", m_text_field.data()->y(), ui->m_y_sb->value());
|
||||||
for (int i = 0; i < m_parts.length(); i++) {
|
|
||||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "y", m_parts[i]->y(), value);
|
|
||||||
undo->setText(tr("Déplacer un champ texte"));
|
undo->setText(tr("Déplacer un champ texte"));
|
||||||
undo->enableAnimation(true);
|
undo->enableAnimation(true);
|
||||||
undoStack().push(undo);
|
undoStack().push(undo);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void DynamicTextFieldEditor::on_m_rotation_sb_editingFinished()
|
void DynamicTextFieldEditor::on_m_rotation_sb_editingFinished()
|
||||||
{
|
{
|
||||||
int value = ui->m_rotation_sb->value();
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "rotation", m_text_field.data()->rotation(), ui->m_rotation_sb->value());
|
||||||
for (int i = 0; i < m_parts.length(); i++) {
|
|
||||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "rotation", m_parts[i]->rotation(), value);
|
|
||||||
undo->setText(tr("Pivoter un champ texte"));
|
undo->setText(tr("Pivoter un champ texte"));
|
||||||
undo->enableAnimation(true);
|
undo->enableAnimation(true);
|
||||||
undoStack().push(undo);
|
undoStack().push(undo);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void DynamicTextFieldEditor::on_m_user_text_le_editingFinished()
|
void DynamicTextFieldEditor::on_m_user_text_le_editingFinished()
|
||||||
{
|
{
|
||||||
QString text = ui->m_user_text_le->text();
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "text", m_text_field.data()->text(), ui->m_user_text_le->text());
|
||||||
for (int i = 0; i < m_parts.length(); i++) {
|
|
||||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "text", m_parts[i]->text(), text);
|
|
||||||
undo->setText(tr("Modifier le texte d'un champ texte"));
|
undo->setText(tr("Modifier le texte d'un champ texte"));
|
||||||
undoStack().push(undo);
|
undoStack().push(undo);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void DynamicTextFieldEditor::on_m_size_sb_editingFinished()
|
void DynamicTextFieldEditor::on_m_size_sb_editingFinished()
|
||||||
{
|
{
|
||||||
QFont font_ = m_text_field->font();
|
QFont font_ = m_text_field->font();
|
||||||
font_.setPointSize(ui->m_size_sb->value());
|
font_.setPointSize(ui->m_size_sb->value());
|
||||||
for (int i = 0; i < m_parts.length(); i++) {
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "font", m_text_field.data()->font(), font_);
|
||||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "font", m_parts[i]->font(), font_);
|
|
||||||
undo->setText(tr("Modifier la police d'un champ texte"));
|
undo->setText(tr("Modifier la police d'un champ texte"));
|
||||||
undoStack().push(undo);
|
undoStack().push(undo);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void DynamicTextFieldEditor::on_m_frame_cb_clicked()
|
void DynamicTextFieldEditor::on_m_frame_cb_clicked()
|
||||||
{
|
{
|
||||||
bool frame = ui->m_frame_cb->isChecked();
|
bool frame = ui->m_frame_cb->isChecked();
|
||||||
|
|
||||||
for (int i = 0; i < m_parts.length(); i++) {
|
if(frame != m_text_field.data()->frame())
|
||||||
if(frame != m_parts[i]->frame())
|
|
||||||
{
|
{
|
||||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "frame", m_parts[i]->frame(), frame);
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "frame", m_text_field.data()->frame(), frame);
|
||||||
undo->setText(tr("Modifier le cadre d'un champ texte"));
|
undo->setText(tr("Modifier le cadre d'un champ texte"));
|
||||||
undoStack().push(undo);
|
undoStack().push(undo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void DynamicTextFieldEditor::on_m_width_sb_editingFinished()
|
void DynamicTextFieldEditor::on_m_width_sb_editingFinished()
|
||||||
{
|
{
|
||||||
qreal width = (qreal)ui->m_width_sb->value();
|
qreal width = (qreal)ui->m_width_sb->value();
|
||||||
|
|
||||||
for (int i = 0; i < m_parts.length(); i++) {
|
if(width != m_text_field.data()->textWidth())
|
||||||
if(width != m_parts[i]->textWidth())
|
|
||||||
{
|
{
|
||||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "textWidth", m_parts[i]->textWidth(), width);
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "textWidth", m_text_field.data()->textWidth(), width);
|
||||||
undo->setText(tr("Modifier la largeur d'un texte"));
|
undo->setText(tr("Modifier la largeur d'un texte"));
|
||||||
undoStack().push(undo);
|
undoStack().push(undo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void DynamicTextFieldEditor::on_m_elmt_info_cb_activated(const QString &arg1)
|
void DynamicTextFieldEditor::on_m_elmt_info_cb_activated(const QString &arg1)
|
||||||
{
|
{
|
||||||
Q_UNUSED(arg1)
|
Q_UNUSED(arg1)
|
||||||
|
|
||||||
QString info = ui->m_elmt_info_cb->currentData().toString();
|
QString info = ui->m_elmt_info_cb->currentData().toString();
|
||||||
for (int i = 0; i < m_parts.length(); i++) {
|
|
||||||
if(info != m_parts[i]->infoName())
|
if(info != m_text_field.data()->infoName())
|
||||||
{
|
{
|
||||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "infoName", m_parts[i]->infoName(), info);
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "infoName", m_text_field.data()->infoName(), info);
|
||||||
undo->setText(tr("Modifier l'information d'un texte"));
|
undo->setText(tr("Modifier l'information d'un texte"));
|
||||||
undoStack().push(undo);
|
undoStack().push(undo);
|
||||||
|
|
||||||
m_parts[i]->setPlainText(elementEditor()->elementScene()->elementInformation().value(m_parts[i]->infoName()).toString());
|
m_text_field.data()->setPlainText(elementEditor()->elementScene()->elementInformation().value(m_text_field.data()->infoName()).toString());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,15 +252,13 @@ void DynamicTextFieldEditor::on_m_text_from_cb_activated(int index)
|
|||||||
else if(index == 1) tf = DynamicElementTextItem::ElementInfo;
|
else if(index == 1) tf = DynamicElementTextItem::ElementInfo;
|
||||||
else tf = DynamicElementTextItem::CompositeText;
|
else tf = DynamicElementTextItem::CompositeText;
|
||||||
|
|
||||||
for (int i = 0; i < m_parts.length(); i++) {
|
if(tf != m_text_field.data()->textFrom())
|
||||||
if(tf != m_parts[i]->textFrom())
|
|
||||||
{
|
{
|
||||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "textFrom", m_parts[i]->textFrom(), tf);
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "textFrom", m_text_field.data()->textFrom(), tf);
|
||||||
undo->setText(tr("Modifier la source de texte, d'un texte"));
|
undo->setText(tr("Modifier la source de texte, d'un texte"));
|
||||||
undoStack().push(undo);
|
undoStack().push(undo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void DynamicTextFieldEditor::on_m_composite_text_pb_clicked()
|
void DynamicTextFieldEditor::on_m_composite_text_pb_clicked()
|
||||||
{
|
{
|
||||||
@@ -336,30 +266,26 @@ void DynamicTextFieldEditor::on_m_composite_text_pb_clicked()
|
|||||||
if(ctd.exec())
|
if(ctd.exec())
|
||||||
{
|
{
|
||||||
QString ct = ctd.plainText();
|
QString ct = ctd.plainText();
|
||||||
for (int i = 0; i < m_parts.length(); i++) {
|
if(ct != m_text_field.data()->compositeText())
|
||||||
if(ct != m_parts[i]->compositeText())
|
|
||||||
{
|
{
|
||||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "compositeText", m_parts[i]->compositeText(), ctd.plainText());
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field.data(), "compositeText", m_text_field.data()->compositeText(), ctd.plainText());
|
||||||
undoStack().push(undo);
|
undoStack().push(undo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void DynamicTextFieldEditor::on_m_alignment_pb_clicked()
|
void DynamicTextFieldEditor::on_m_alignment_pb_clicked()
|
||||||
{
|
{
|
||||||
AlignmentTextDialog atd(m_text_field.data()->alignment(), this);
|
AlignmentTextDialog atd(m_text_field.data()->alignment(), this);
|
||||||
atd.exec();
|
atd.exec();
|
||||||
|
|
||||||
for (int i = 0; i < m_parts.length(); i++) {
|
if(atd.alignment() != m_text_field.data()->alignment())
|
||||||
if(atd.alignment() != m_parts[i]->alignment())
|
|
||||||
{
|
{
|
||||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "alignment", QVariant(m_parts[i]->alignment()), QVariant(atd.alignment()));
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field.data(), "alignment", QVariant(m_text_field.data()->alignment()), QVariant(atd.alignment()));
|
||||||
undo->setText(tr("Modifier l'alignement d'un champ texte"));
|
undo->setText(tr("Modifier l'alignement d'un champ texte"));
|
||||||
undoStack().push(undo);
|
undoStack().push(undo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void DynamicTextFieldEditor::on_m_font_pb_clicked()
|
void DynamicTextFieldEditor::on_m_font_pb_clicked()
|
||||||
{
|
{
|
||||||
@@ -370,25 +296,18 @@ void DynamicTextFieldEditor::on_m_font_pb_clicked()
|
|||||||
ui->m_font_pb->setText(font_.family());
|
ui->m_font_pb->setText(font_.family());
|
||||||
ui->m_size_sb->setValue(font_.pointSize());
|
ui->m_size_sb->setValue(font_.pointSize());
|
||||||
|
|
||||||
for (int i = 0; i < m_parts.length(); i++) {
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field.data(), "font", m_text_field->font(), font_);
|
||||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "font", m_parts[i]->font(), font_);
|
|
||||||
undo->setText(tr("Modifier la police d'un champ texte"));
|
undo->setText(tr("Modifier la police d'un champ texte"));
|
||||||
undoStack().push(undo);
|
undoStack().push(undo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void DynamicTextFieldEditor::on_m_color_kpb_changed(const QColor &newColor)
|
void DynamicTextFieldEditor::on_m_color_kpb_changed(const QColor &newColor)
|
||||||
{
|
{
|
||||||
if (!newColor.isValid())
|
if(newColor.isValid() && newColor != m_text_field.data()->color())
|
||||||
return;
|
|
||||||
|
|
||||||
for (int i = 0; i < m_parts.length(); i++) {
|
|
||||||
if(newColor != m_parts[i]->color())
|
|
||||||
{
|
{
|
||||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "color", m_parts[i]->color(), newColor);
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "color", m_text_field.data()->color(), newColor);
|
||||||
undo->setText(tr("Modifier la couleur d'un champ texte"));
|
undo->setText(tr("Modifier la couleur d'un champ texte"));
|
||||||
undoStack().push(undo);
|
undoStack().push(undo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -38,15 +38,11 @@ class DynamicTextFieldEditor : public ElementItemEditor
|
|||||||
~DynamicTextFieldEditor() override;
|
~DynamicTextFieldEditor() override;
|
||||||
|
|
||||||
bool setPart(CustomElementPart *part) override;
|
bool setPart(CustomElementPart *part) override;
|
||||||
bool setParts(QList <CustomElementPart *>) override;
|
|
||||||
CustomElementPart *currentPart() const override;
|
CustomElementPart *currentPart() const override;
|
||||||
QList<CustomElementPart*> currentParts() const override;
|
|
||||||
void updateForm() override;
|
void updateForm() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void fillInfoComboBox();
|
void fillInfoComboBox();
|
||||||
void setUpConnections();
|
|
||||||
void disconnectConnections();
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_m_x_sb_editingFinished();
|
void on_m_x_sb_editingFinished();
|
||||||
@@ -67,7 +63,6 @@ class DynamicTextFieldEditor : public ElementItemEditor
|
|||||||
private:
|
private:
|
||||||
Ui::DynamicTextFieldEditor *ui;
|
Ui::DynamicTextFieldEditor *ui;
|
||||||
QPointer<PartDynamicTextField> m_text_field;
|
QPointer<PartDynamicTextField> m_text_field;
|
||||||
QList<PartDynamicTextField*> m_parts;
|
|
||||||
QList<QMetaObject::Connection> m_connection_list;
|
QList<QMetaObject::Connection> m_connection_list;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -98,10 +98,6 @@ CustomElementPart *PolygonEditor::currentPart() const {
|
|||||||
return m_part;
|
return m_part;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<CustomElementPart*> PolygonEditor::currentParts() const {
|
|
||||||
return m_style->currentParts();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief PolygonEditor::updateForm
|
* @brief PolygonEditor::updateForm
|
||||||
* Update the widget
|
* Update the widget
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ class PolygonEditor : public ElementItemEditor
|
|||||||
|
|
||||||
bool setPart(CustomElementPart *part) override;
|
bool setPart(CustomElementPart *part) override;
|
||||||
CustomElementPart *currentPart() const override;
|
CustomElementPart *currentPart() const override;
|
||||||
QList<CustomElementPart*> currentParts() const override;
|
|
||||||
void updateForm() override;
|
void updateForm() override;
|
||||||
QVector<QPointF> pointsFromTree();
|
QVector<QPointF> pointsFromTree();
|
||||||
bool eventFilter(QObject *watched, QEvent *event) override;
|
bool eventFilter(QObject *watched, QEvent *event) override;
|
||||||
|
|||||||
@@ -103,10 +103,6 @@ CustomElementPart *RectangleEditor::currentPart() const {
|
|||||||
return m_part;
|
return m_part;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<CustomElementPart*> RectangleEditor::currentParts() const {
|
|
||||||
return m_style->currentParts();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief RectangleEditor::topLeft
|
* @brief RectangleEditor::topLeft
|
||||||
* @return The edited topLeft already mapped to part coordinate
|
* @return The edited topLeft already mapped to part coordinate
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ class RectangleEditor : public ElementItemEditor
|
|||||||
|
|
||||||
bool setPart(CustomElementPart *part) override;
|
bool setPart(CustomElementPart *part) override;
|
||||||
CustomElementPart *currentPart() const override;
|
CustomElementPart *currentPart() const override;
|
||||||
QList<CustomElementPart*> currentParts() const override;
|
|
||||||
QPointF editedTopLeft () const;
|
QPointF editedTopLeft () const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|||||||
@@ -57,7 +57,10 @@ void TextEditor::updateForm()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
disconnectEditConnection();
|
for (QMetaObject::Connection c : m_edit_connection) {
|
||||||
|
disconnect(c);
|
||||||
|
}
|
||||||
|
m_edit_connection.clear();
|
||||||
|
|
||||||
ui->m_line_edit->setText(m_text->toPlainText());
|
ui->m_line_edit->setText(m_text->toPlainText());
|
||||||
ui->m_x_sb->setValue(m_text->pos().x());
|
ui->m_x_sb->setValue(m_text->pos().x());
|
||||||
@@ -70,30 +73,6 @@ void TextEditor::updateForm()
|
|||||||
setUpEditConnection();
|
setUpEditConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditor::setUpChangeConnection(QPointer<PartText> part) {
|
|
||||||
assert(m_change_connection.isEmpty());
|
|
||||||
m_change_connection << connect(part, &PartText::plainTextChanged, this, &TextEditor::updateForm);
|
|
||||||
m_change_connection << connect(part, &PartText::xChanged, this, &TextEditor::updateForm);
|
|
||||||
m_change_connection << connect(part, &PartText::yChanged, this, &TextEditor::updateForm);
|
|
||||||
m_change_connection << connect(part, &PartText::rotationChanged, this, &TextEditor::updateForm);
|
|
||||||
m_change_connection << connect(part, &PartText::fontChanged, this, &TextEditor::updateForm);
|
|
||||||
m_change_connection << connect(part, &PartText::colorChanged, this, &TextEditor::updateForm);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextEditor::disconnectChangeConnection() {
|
|
||||||
for (QMetaObject::Connection c : m_change_connection) {
|
|
||||||
disconnect(c);
|
|
||||||
}
|
|
||||||
m_change_connection.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextEditor::disconnectEditConnection() {
|
|
||||||
for (QMetaObject::Connection c : m_edit_connection) {
|
|
||||||
disconnect(c);
|
|
||||||
}
|
|
||||||
m_edit_connection.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief TextEditor::setPart
|
* @brief TextEditor::setPart
|
||||||
* Set the current text to edit.
|
* Set the current text to edit.
|
||||||
@@ -106,18 +85,27 @@ bool TextEditor::setPart(CustomElementPart *part)
|
|||||||
if (!part)
|
if (!part)
|
||||||
{
|
{
|
||||||
m_text = nullptr;
|
m_text = nullptr;
|
||||||
disconnectChangeConnection();
|
for (QMetaObject::Connection c : m_change_connection) {
|
||||||
|
disconnect(c);
|
||||||
|
}
|
||||||
|
m_change_connection.clear();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PartText *part_text = static_cast<PartText *>(part))
|
if (PartText *part_text = dynamic_cast<PartText *>(part))
|
||||||
{
|
{
|
||||||
if (part_text == m_text) {
|
if (part_text == m_text) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
m_text = part_text;
|
m_text = part_text;
|
||||||
|
|
||||||
setUpChangeConnection(m_text);
|
m_change_connection.clear();
|
||||||
|
m_change_connection << connect(part_text, &PartText::plainTextChanged, this, &TextEditor::updateForm);
|
||||||
|
m_change_connection << connect(part_text, &PartText::xChanged, this, &TextEditor::updateForm);
|
||||||
|
m_change_connection << connect(part_text, &PartText::yChanged, this, &TextEditor::updateForm);
|
||||||
|
m_change_connection << connect(part_text, &PartText::rotationChanged, this, &TextEditor::updateForm);
|
||||||
|
m_change_connection << connect(part_text, &PartText::fontChanged, this, &TextEditor::updateForm);
|
||||||
|
m_change_connection << connect(part_text, &PartText::colorChanged, this, &TextEditor::updateForm);
|
||||||
|
|
||||||
updateForm();
|
updateForm();
|
||||||
return true;
|
return true;
|
||||||
@@ -125,37 +113,6 @@ bool TextEditor::setPart(CustomElementPart *part)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TextEditor::setParts(QList <CustomElementPart *> parts) {
|
|
||||||
if (parts.isEmpty())
|
|
||||||
{
|
|
||||||
m_parts.clear();
|
|
||||||
if (m_text) {
|
|
||||||
disconnectChangeConnection();
|
|
||||||
}
|
|
||||||
m_text = nullptr;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PartText *part= static_cast<PartText *>(parts.first()))
|
|
||||||
{
|
|
||||||
if (m_text) {
|
|
||||||
disconnectChangeConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_text = part;
|
|
||||||
m_parts.clear();
|
|
||||||
m_parts.append(part);
|
|
||||||
for (int i=1; i < parts.length(); i++)
|
|
||||||
m_parts.append(static_cast<PartText*>(parts[i]));
|
|
||||||
|
|
||||||
setUpChangeConnection(m_text);
|
|
||||||
|
|
||||||
updateForm();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief TextEditor::currentPart
|
* @brief TextEditor::currentPart
|
||||||
* @return The current part
|
* @return The current part
|
||||||
@@ -164,14 +121,6 @@ CustomElementPart *TextEditor::currentPart() const {
|
|||||||
return m_text;
|
return m_text;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<CustomElementPart*> TextEditor::currentParts() const {
|
|
||||||
QList<CustomElementPart*> parts;
|
|
||||||
for (auto part: m_parts) {
|
|
||||||
parts.append(static_cast<CustomElementPart*>(part));
|
|
||||||
}
|
|
||||||
return parts;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief TextEditor::setUpEditConnection
|
* @brief TextEditor::setUpEditConnection
|
||||||
* Setup the connection between the widgets of this editor and the undo command
|
* Setup the connection between the widgets of this editor and the undo command
|
||||||
@@ -179,77 +128,63 @@ QList<CustomElementPart*> TextEditor::currentParts() const {
|
|||||||
*/
|
*/
|
||||||
void TextEditor::setUpEditConnection()
|
void TextEditor::setUpEditConnection()
|
||||||
{
|
{
|
||||||
disconnectEditConnection();
|
for (QMetaObject::Connection c : m_edit_connection) {
|
||||||
|
disconnect(c);
|
||||||
|
}
|
||||||
|
m_edit_connection.clear();
|
||||||
|
|
||||||
m_edit_connection << connect(ui->m_line_edit, &QLineEdit::textEdited, [this]()
|
m_edit_connection << connect(ui->m_line_edit, &QLineEdit::textEdited, [this]()
|
||||||
{
|
{
|
||||||
QString text_ = ui->m_line_edit->text();
|
QString text_ = ui->m_line_edit->text();
|
||||||
for (int i=0; i < m_parts.length(); i++) {
|
if (text_ != m_text->toPlainText())
|
||||||
PartText* partText = m_parts[i];
|
|
||||||
if (text_ != partText->toPlainText())
|
|
||||||
{
|
{
|
||||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "text", partText->toPlainText(), text_);
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "text", m_text->toPlainText(), text_);
|
||||||
undo->setText(tr("Modifier le contenu d'un champ texte"));
|
undo->setText(tr("Modifier le contenu d'un champ texte"));
|
||||||
undoStack().push(undo);
|
undoStack().push(undo);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
m_edit_connection << connect(ui->m_x_sb, QOverload<int>::of(&QSpinBox::valueChanged), [this]()
|
m_edit_connection << connect(ui->m_x_sb, QOverload<int>::of(&QSpinBox::valueChanged), [this]()
|
||||||
{
|
{
|
||||||
QPointF pos(ui->m_x_sb->value(), 0);
|
QPointF pos(ui->m_x_sb->value(), ui->m_y_sb->value());
|
||||||
for (int i=0; i < m_parts.length(); i++) {
|
if (pos != m_text->pos())
|
||||||
PartText* partText = m_parts[i];
|
|
||||||
pos.setY(partText->pos().y());
|
|
||||||
if (pos != partText->pos())
|
|
||||||
{
|
{
|
||||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "pos", partText->pos(), pos);
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "pos", m_text->pos(), pos);
|
||||||
undo->setText(tr("Déplacer un champ texte"));
|
undo->setText(tr("Déplacer un champ texte"));
|
||||||
undo->setAnimated(true, false);
|
undo->setAnimated(true, false);
|
||||||
undoStack().push(undo);
|
undoStack().push(undo);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
m_edit_connection << connect(ui->m_y_sb, QOverload<int>::of(&QSpinBox::valueChanged), [this]()
|
m_edit_connection << connect(ui->m_y_sb, QOverload<int>::of(&QSpinBox::valueChanged), [this]()
|
||||||
{
|
{
|
||||||
QPointF pos(0, ui->m_y_sb->value());
|
QPointF pos(ui->m_x_sb->value(), ui->m_y_sb->value());
|
||||||
for (int i=0; i < m_parts.length(); i++) {
|
if (pos != m_text->pos())
|
||||||
PartText* partText = m_parts[i];
|
|
||||||
pos.setX(partText->pos().x());
|
|
||||||
if (pos != partText->pos())
|
|
||||||
{
|
{
|
||||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "pos", partText->pos(), pos);
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "pos", m_text->pos(), pos);
|
||||||
undo->setText(tr("Déplacer un champ texte"));
|
undo->setText(tr("Déplacer un champ texte"));
|
||||||
undo->setAnimated(true, false);
|
undo->setAnimated(true, false);
|
||||||
undoStack().push(undo);
|
undoStack().push(undo);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
m_edit_connection << connect(ui->m_rotation_sb, QOverload<int>::of(&QSpinBox::valueChanged), [this]()
|
m_edit_connection << connect(ui->m_rotation_sb, QOverload<int>::of(&QSpinBox::valueChanged), [this]()
|
||||||
{
|
{
|
||||||
for (int i=0; i < m_parts.length(); i++) {
|
if (ui->m_rotation_sb->value() != m_text->rotation())
|
||||||
PartText* partText = m_parts[i];
|
|
||||||
if (ui->m_rotation_sb->value() != partText->rotation())
|
|
||||||
{
|
{
|
||||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "rotation", partText->rotation(), ui->m_rotation_sb->value());
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "rotation", m_text->rotation(), ui->m_rotation_sb->value());
|
||||||
undo->setText(tr("Pivoter un champ texte"));
|
undo->setText(tr("Pivoter un champ texte"));
|
||||||
undo->setAnimated(true, false);
|
undo->setAnimated(true, false);
|
||||||
undoStack().push(undo);
|
undoStack().push(undo);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
m_edit_connection << connect(ui->m_size_sb, QOverload<int>::of(&QSpinBox::valueChanged), [this]()
|
m_edit_connection << connect(ui->m_size_sb, QOverload<int>::of(&QSpinBox::valueChanged), [this]()
|
||||||
{
|
{
|
||||||
for (int i=0; i < m_parts.length(); i++) {
|
if (m_text->font().pointSize() != ui->m_size_sb->value())
|
||||||
PartText* partText = m_parts[i];
|
|
||||||
if (partText->font().pointSize() != ui->m_size_sb->value())
|
|
||||||
{
|
{
|
||||||
QFont font_ = partText->font();
|
QFont font_ = m_text->font();
|
||||||
font_.setPointSize(ui->m_size_sb->value());
|
font_.setPointSize(ui->m_size_sb->value());
|
||||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "font", partText->font(), font_);
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "font", m_text->font(), font_);
|
||||||
undo->setText(tr("Modifier la police d'un texte"));
|
undo->setText(tr("Modifier la police d'un texte"));
|
||||||
undoStack().push(undo);
|
undoStack().push(undo);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,24 +196,18 @@ void TextEditor::on_m_font_pb_clicked()
|
|||||||
bool ok;
|
bool ok;
|
||||||
QFont font_ = QFontDialog::getFont(&ok, m_text->font(), this);
|
QFont font_ = QFontDialog::getFont(&ok, m_text->font(), this);
|
||||||
|
|
||||||
if (ok && font_ != m_text->font()) {
|
if (ok && font_ != m_text->font())
|
||||||
|
{
|
||||||
ui->m_size_sb->blockSignals(true);
|
ui->m_size_sb->blockSignals(true);
|
||||||
ui->m_size_sb->setValue(font_.pointSize());
|
ui->m_size_sb->setValue(font_.pointSize());
|
||||||
ui->m_size_sb->blockSignals(false);
|
ui->m_size_sb->blockSignals(false);
|
||||||
|
|
||||||
ui->m_font_pb->setText(font_.family());
|
ui->m_font_pb->setText(font_.family());
|
||||||
}
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "font", m_text->font(), font_);
|
||||||
|
|
||||||
for (int i=0; i < m_parts.length(); i++) {
|
|
||||||
PartText* partText = m_parts[i];
|
|
||||||
if (ok && font_ != partText->font())
|
|
||||||
{
|
|
||||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "font", partText->font(), font_);
|
|
||||||
undo->setText(tr("Modifier la police d'un texte"));
|
undo->setText(tr("Modifier la police d'un texte"));
|
||||||
undoStack().push(undo);
|
undoStack().push(undo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief TextEditor::on_m_color_pb_changed
|
* @brief TextEditor::on_m_color_pb_changed
|
||||||
@@ -286,13 +215,10 @@ void TextEditor::on_m_font_pb_clicked()
|
|||||||
*/
|
*/
|
||||||
void TextEditor::on_m_color_pb_changed(const QColor &newColor)
|
void TextEditor::on_m_color_pb_changed(const QColor &newColor)
|
||||||
{
|
{
|
||||||
for (int i=0; i < m_parts.length(); i++) {
|
if (newColor != m_text->defaultTextColor())
|
||||||
PartText* partText = m_parts[i];
|
|
||||||
if (newColor != partText->defaultTextColor())
|
|
||||||
{
|
{
|
||||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "color", partText->defaultTextColor(), newColor);
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "color", m_text->defaultTextColor(), newColor);
|
||||||
undo->setText(tr("Modifier la couleur d'un texte"));
|
undo->setText(tr("Modifier la couleur d'un texte"));
|
||||||
undoStack().push(undo);
|
undoStack().push(undo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -39,24 +39,18 @@ class TextEditor : public ElementItemEditor
|
|||||||
|
|
||||||
void updateForm() override;
|
void updateForm() override;
|
||||||
bool setPart(CustomElementPart *part) override;
|
bool setPart(CustomElementPart *part) override;
|
||||||
bool setParts(QList <CustomElementPart *>) override;
|
|
||||||
CustomElementPart *currentPart() const override;
|
CustomElementPart *currentPart() const override;
|
||||||
QList<CustomElementPart*> currentParts() const override;
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_m_font_pb_clicked();
|
void on_m_font_pb_clicked();
|
||||||
void on_m_color_pb_changed(const QColor &newColor);
|
void on_m_color_pb_changed(const QColor &newColor);
|
||||||
private:
|
private:
|
||||||
void setUpEditConnection();
|
void setUpEditConnection();
|
||||||
void setUpChangeConnection(QPointer<PartText> part);
|
|
||||||
void disconnectChangeConnection();
|
|
||||||
void disconnectEditConnection();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::TextEditor *ui;
|
Ui::TextEditor *ui;
|
||||||
|
|
||||||
QPointer <PartText> m_text;
|
QPointer <PartText> m_text;
|
||||||
QList<PartText*> m_parts;
|
|
||||||
QList <QMetaObject::Connection> m_edit_connection;
|
QList <QMetaObject::Connection> m_edit_connection;
|
||||||
QList <QMetaObject::Connection> m_change_connection;
|
QList <QMetaObject::Connection> m_change_connection;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -34,8 +34,8 @@ class PropertiesInterface
|
|||||||
virtual void toSettings (QSettings &settings, const QString = QString()) const =0;
|
virtual void toSettings (QSettings &settings, const QString = QString()) const =0;
|
||||||
virtual void fromSettings (const QSettings &settings, const QString = QString()) =0;
|
virtual void fromSettings (const QSettings &settings, const QString = QString()) =0;
|
||||||
// Save/load properties to xml element
|
// Save/load properties to xml element
|
||||||
virtual QDomElement toXml (QDomDocument &xml_document) const =0;
|
virtual void toXml (QDomElement &xml_element) const =0;
|
||||||
virtual bool fromXml (const QDomElement &xml_element) =0;
|
virtual void fromXml (const QDomElement &xml_element) =0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PROPERTIESINTERFACE_H
|
#endif // PROPERTIESINTERFACE_H
|
||||||
|
|||||||
@@ -1,86 +0,0 @@
|
|||||||
#include "terminaldata.h"
|
|
||||||
|
|
||||||
#include <QGraphicsObject>
|
|
||||||
|
|
||||||
TerminalData::TerminalData():
|
|
||||||
PropertiesInterface()
|
|
||||||
{
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
TerminalData::TerminalData(QGraphicsObject *parent):
|
|
||||||
PropertiesInterface(),
|
|
||||||
q(parent)
|
|
||||||
{
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TerminalData::init() {
|
|
||||||
}
|
|
||||||
|
|
||||||
TerminalData::~TerminalData()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void TerminalData::setParent(QGraphicsObject* parent)
|
|
||||||
{
|
|
||||||
q = parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TerminalData::toSettings(QSettings &settings, const QString) const
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void TerminalData::fromSettings(const QSettings &settings, const QString)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
QDomElement TerminalData::toXml(QDomDocument &xml_document) const
|
|
||||||
{
|
|
||||||
QDomElement xml_element = xml_document.createElement("terminal");
|
|
||||||
|
|
||||||
// ecrit la position de la borne
|
|
||||||
xml_element.setAttribute("x", QString("%1").arg(q->scenePos().x()));
|
|
||||||
xml_element.setAttribute("y", QString("%1").arg(q->scenePos().y()));
|
|
||||||
|
|
||||||
|
|
||||||
xml_element.setAttribute("uuid", m_uuid.toString());
|
|
||||||
xml_element.setAttribute("name", m_name);
|
|
||||||
|
|
||||||
// ecrit l'orientation de la borne
|
|
||||||
xml_element.setAttribute("orientation", Qet::orientationToString(m_orientation));
|
|
||||||
// Write name and number to XML
|
|
||||||
|
|
||||||
return(xml_element);
|
|
||||||
}
|
|
||||||
bool TerminalData::fromXml (const QDomElement &xml_element)
|
|
||||||
{
|
|
||||||
// lit la position de la borne
|
|
||||||
qreal term_x = 0.0, term_y = 0.0;
|
|
||||||
if (!QET::attributeIsAReal(xml_element, "x", &term_x))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!QET::attributeIsAReal(xml_element, "y", &term_y))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
m_pos = QPointF(term_x, term_y);
|
|
||||||
|
|
||||||
//emit posFromXML(QPointF(term_x, term_y));
|
|
||||||
|
|
||||||
QString uuid = xml_element.attribute("uuid");
|
|
||||||
// update part and add uuid, which is used in the new version to connect terminals together
|
|
||||||
// if the attribute not exists, means, the element is created with an older version of qet. So use the legacy approach
|
|
||||||
// to identify terminals
|
|
||||||
if (!uuid.isEmpty())
|
|
||||||
m_uuid = QUuid(uuid);
|
|
||||||
|
|
||||||
m_name = xml_element.attribute("name");
|
|
||||||
|
|
||||||
// lit l'orientation de la borne
|
|
||||||
m_orientation = Qet::orientationFromString(xml_element.attribute("orientation"));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
#ifndef TERMINALDATA_H
|
|
||||||
#define TERMINALDATA_H
|
|
||||||
|
|
||||||
#include "propertiesinterface.h"
|
|
||||||
#include "qet.h"
|
|
||||||
|
|
||||||
#include <QUuid>
|
|
||||||
#include <QPointF>
|
|
||||||
|
|
||||||
class QGraphicsObject;
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief The TerminalData class
|
|
||||||
* Data of the terminal. Stored in extra class so it can be used by PartTerminal and Terminal without
|
|
||||||
* defining everything again.
|
|
||||||
*/
|
|
||||||
class TerminalData : public PropertiesInterface
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
TerminalData();
|
|
||||||
TerminalData(QGraphicsObject* parent);
|
|
||||||
~TerminalData();
|
|
||||||
|
|
||||||
void init();
|
|
||||||
|
|
||||||
void setParent(QGraphicsObject* parent);
|
|
||||||
|
|
||||||
// Save/load properties to setting file. QString is use for prefix a word befor the name of each paramètre
|
|
||||||
void toSettings(QSettings &settings, const QString = QString()) const override;
|
|
||||||
void fromSettings(const QSettings &settings, const QString = QString()) override;
|
|
||||||
// Save/load properties to xml element
|
|
||||||
// This method is only called from the PartTerminal and should never called from the Terminal class
|
|
||||||
QDomElement toXml(QDomDocument &xml_element) const override;
|
|
||||||
bool fromXml(const QDomElement &xml_element) override;
|
|
||||||
|
|
||||||
// must be public, because this class is a private member of PartTerminal/Terminal and they must
|
|
||||||
// access this data
|
|
||||||
public:
|
|
||||||
/*!
|
|
||||||
* \brief m_orientation
|
|
||||||
* Orientation of the terminal
|
|
||||||
*/
|
|
||||||
Qet::Orientation m_orientation;
|
|
||||||
/*!
|
|
||||||
* \brief second_point
|
|
||||||
* Position of the second point of the terminal in scene coordinates
|
|
||||||
*/
|
|
||||||
QPointF second_point;
|
|
||||||
/*!
|
|
||||||
* \brief m_uuid
|
|
||||||
* Uuid of the terminal.
|
|
||||||
*
|
|
||||||
* In elementscene.cpp an element gets a new uuid when saving the element. In the current state
|
|
||||||
* each connection is made by using the local position of the terminal and a dynamic id. In the new
|
|
||||||
* case, each terminal should have it's own uuid to identify it uniquely. When changing each time this
|
|
||||||
* uuid, the conductor after updating the part is anymore valid. So if in the loaded document a uuid exists,
|
|
||||||
* use this one and don't create a new one.
|
|
||||||
*/
|
|
||||||
QUuid m_uuid;
|
|
||||||
/*!
|
|
||||||
* \brief m_name
|
|
||||||
* Name of the element. It can be used to create wiring harness tables
|
|
||||||
*/
|
|
||||||
QString m_name;
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief m_pos
|
|
||||||
* Position of the terminal. The second point is calculated from this position and the orientation
|
|
||||||
* Important: this variable is only updated during read from xml and not during mouse move!
|
|
||||||
* It is used to store the initial position so that PartTerminal and Terminal have access to it.
|
|
||||||
*/
|
|
||||||
QPointF m_pos;
|
|
||||||
private:
|
|
||||||
QGraphicsObject* q{nullptr};
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // TERMINALDATA_H
|
|
||||||
@@ -93,11 +93,7 @@ void XRefProperties::fromSettings(const QSettings &settings, const QString prefi
|
|||||||
* Save to xml
|
* Save to xml
|
||||||
* @param xml_element: QDomElement to use for saving
|
* @param xml_element: QDomElement to use for saving
|
||||||
*/
|
*/
|
||||||
QDomElement XRefProperties::toXml(QDomDocument &xml_document) const {
|
void XRefProperties::toXml(QDomElement &xml_element) const {
|
||||||
|
|
||||||
QDomElement xml_element = xml_document.createElement("xref");
|
|
||||||
xml_element.setAttribute("type", m_key);
|
|
||||||
|
|
||||||
xml_element.setAttribute("showpowerctc", m_show_power_ctc? "true" : "false");
|
xml_element.setAttribute("showpowerctc", m_show_power_ctc? "true" : "false");
|
||||||
QString display = m_display == Cross? "cross" : "contacts";
|
QString display = m_display == Cross? "cross" : "contacts";
|
||||||
xml_element.setAttribute("displayhas", display);
|
xml_element.setAttribute("displayhas", display);
|
||||||
@@ -118,8 +114,6 @@ QDomElement XRefProperties::toXml(QDomDocument &xml_document) const {
|
|||||||
foreach (QString key, m_prefix.keys()) {
|
foreach (QString key, m_prefix.keys()) {
|
||||||
xml_element.setAttribute(key + "prefix", m_prefix.value(key));
|
xml_element.setAttribute(key + "prefix", m_prefix.value(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
return xml_element;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -127,7 +121,7 @@ QDomElement XRefProperties::toXml(QDomDocument &xml_document) const {
|
|||||||
* Load from xml
|
* Load from xml
|
||||||
* @param xml_element: QDomElement to use for load
|
* @param xml_element: QDomElement to use for load
|
||||||
*/
|
*/
|
||||||
bool XRefProperties::fromXml(const QDomElement &xml_element) {
|
void XRefProperties::fromXml(const QDomElement &xml_element) {
|
||||||
m_show_power_ctc = xml_element.attribute("showpowerctc") == "true";
|
m_show_power_ctc = xml_element.attribute("showpowerctc") == "true";
|
||||||
QString display = xml_element.attribute("displayhas", "cross");
|
QString display = xml_element.attribute("displayhas", "cross");
|
||||||
display == "cross"? m_display = Cross : m_display = Contacts;
|
display == "cross"? m_display = Cross : m_display = Contacts;
|
||||||
@@ -149,7 +143,6 @@ bool XRefProperties::fromXml(const QDomElement &xml_element) {
|
|||||||
foreach (QString key, m_prefix_keys) {
|
foreach (QString key, m_prefix_keys) {
|
||||||
m_prefix.insert(key, xml_element.attribute(key + "prefix"));
|
m_prefix.insert(key, xml_element.attribute(key + "prefix"));
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ class XRefProperties : public PropertiesInterface
|
|||||||
|
|
||||||
void toSettings (QSettings &settings, const QString = QString()) const override;
|
void toSettings (QSettings &settings, const QString = QString()) const override;
|
||||||
void fromSettings (const QSettings &settings, const QString = QString()) override;
|
void fromSettings (const QSettings &settings, const QString = QString()) override;
|
||||||
QDomElement toXml (QDomDocument &xml_document) const override;
|
void toXml (QDomElement &xml_element) const override;
|
||||||
bool fromXml(const QDomElement &xml_element) override;
|
void fromXml (const QDomElement &xml_element) override;
|
||||||
|
|
||||||
static QHash<QString, XRefProperties> defaultProperties();
|
static QHash<QString, XRefProperties> defaultProperties();
|
||||||
|
|
||||||
@@ -73,8 +73,6 @@ class XRefProperties : public PropertiesInterface
|
|||||||
void setOffset(const int offset) {m_offset = offset;}
|
void setOffset(const int offset) {m_offset = offset;}
|
||||||
int offset() const {return m_offset;}
|
int offset() const {return m_offset;}
|
||||||
|
|
||||||
void setKey(QString& key) {m_key = key;}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_show_power_ctc;
|
bool m_show_power_ctc;
|
||||||
DisplayHas m_display;
|
DisplayHas m_display;
|
||||||
@@ -85,7 +83,6 @@ class XRefProperties : public PropertiesInterface
|
|||||||
QString m_master_label;
|
QString m_master_label;
|
||||||
QString m_slave_label;
|
QString m_slave_label;
|
||||||
int m_offset;
|
int m_offset;
|
||||||
QString m_key;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // XREFPROPERTIES_H
|
#endif // XREFPROPERTIES_H
|
||||||
|
|||||||
@@ -580,26 +580,12 @@ bool Conductor::valideXml(QDomElement &e){
|
|||||||
|
|
||||||
bool conv_ok;
|
bool conv_ok;
|
||||||
// parse l'abscisse
|
// parse l'abscisse
|
||||||
if (e.hasAttribute("element1")) {
|
|
||||||
if (QUuid(e.attribute("element1")).isNull())
|
|
||||||
return false;
|
|
||||||
if (QUuid(e.attribute("terminal1")).isNull())
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
e.attribute("terminal1").toInt(&conv_ok);
|
e.attribute("terminal1").toInt(&conv_ok);
|
||||||
if (!conv_ok) return(false);
|
if (!conv_ok) return(false);
|
||||||
}
|
|
||||||
|
|
||||||
// parse l'ordonnee
|
// parse l'ordonnee
|
||||||
if (e.hasAttribute("element2")) {
|
|
||||||
if (QUuid(e.attribute("element2")).isNull())
|
|
||||||
return false;
|
|
||||||
if (QUuid(e.attribute("terminal2")).isNull())
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
e.attribute("terminal2").toInt(&conv_ok);
|
e.attribute("terminal2").toInt(&conv_ok);
|
||||||
if (!conv_ok) return(false);
|
if (!conv_ok) return(false);
|
||||||
}
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1008,23 +994,8 @@ QDomElement Conductor::toXml(QDomDocument &dom_document, QHash<Terminal *, int>
|
|||||||
|
|
||||||
dom_element.setAttribute("x", QString::number(pos().x()));
|
dom_element.setAttribute("x", QString::number(pos().x()));
|
||||||
dom_element.setAttribute("y", QString::number(pos().y()));
|
dom_element.setAttribute("y", QString::number(pos().y()));
|
||||||
|
dom_element.setAttribute("terminal1", table_adr_id.value(terminal1));
|
||||||
// Terminal is uniquely identified by the uuid of the terminal and the element
|
dom_element.setAttribute("terminal2", table_adr_id.value(terminal2));
|
||||||
if (terminal1->uuid().isNull()) {
|
|
||||||
// legacy method to identify the terminal
|
|
||||||
dom_element.setAttribute("terminal1", table_adr_id.value(terminal1)); // for backward compability
|
|
||||||
} else {
|
|
||||||
dom_element.setAttribute("element1", terminal1->parentElement()->uuid().toString());
|
|
||||||
dom_element.setAttribute("terminal1", terminal1->uuid().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (terminal2->uuid().isNull()) {
|
|
||||||
// legacy method to identify the terminal
|
|
||||||
dom_element.setAttribute("terminal2", table_adr_id.value(terminal2)); // for backward compability
|
|
||||||
} else {
|
|
||||||
dom_element.setAttribute("element2", terminal2->parentElement()->uuid().toString());
|
|
||||||
dom_element.setAttribute("terminal2", terminal2->uuid().toString());
|
|
||||||
}
|
|
||||||
dom_element.setAttribute("freezeLabel", m_freeze_label? "true" : "false");
|
dom_element.setAttribute("freezeLabel", m_freeze_label? "true" : "false");
|
||||||
|
|
||||||
// on n'exporte les segments du conducteur que si ceux-ci ont
|
// on n'exporte les segments du conducteur que si ceux-ci ont
|
||||||
@@ -1060,8 +1031,7 @@ QDomElement Conductor::toXml(QDomDocument &dom_document, QHash<Terminal *, int>
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Conductor::pathFromXml
|
* @brief Conductor::pathFromXml
|
||||||
* Generate the path (of the line) from xml file by checking the segments in the xml
|
* Generate the path from xml file
|
||||||
* file
|
|
||||||
* @param e
|
* @param e
|
||||||
* @return true if generate path success else return false
|
* @return true if generate path success else return false
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
#include "elementprovider.h"
|
#include "elementprovider.h"
|
||||||
#include "diagramposition.h"
|
#include "diagramposition.h"
|
||||||
#include "terminal.h"
|
#include "terminal.h"
|
||||||
#include "terminaldata.h"
|
|
||||||
#include "PropertiesEditor/propertieseditordialog.h"
|
#include "PropertiesEditor/propertieseditordialog.h"
|
||||||
#include "elementpropertieswidget.h"
|
#include "elementpropertieswidget.h"
|
||||||
#include "numerotationcontextcommands.h"
|
#include "numerotationcontextcommands.h"
|
||||||
@@ -561,22 +560,36 @@ DynamicElementTextItem *Element::parseDynamicText(const QDomElement &dom_element
|
|||||||
return deti;
|
return deti;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Element::parseTerminal
|
|
||||||
* Parse partTerminal from xml structure
|
|
||||||
* \param dom_element
|
|
||||||
* \return
|
|
||||||
*/
|
|
||||||
Terminal *Element::parseTerminal(const QDomElement &dom_element)
|
Terminal *Element::parseTerminal(const QDomElement &dom_element)
|
||||||
{
|
{
|
||||||
|
qreal terminalx, terminaly;
|
||||||
TerminalData* data = new TerminalData();
|
Qet::Orientation terminalo;
|
||||||
if (!data->fromXml(dom_element)) {
|
if (!QET::attributeIsAReal(dom_element, QString("x"), &terminalx)) {
|
||||||
delete data;
|
return(nullptr);
|
||||||
return nullptr;
|
}
|
||||||
|
if (!QET::attributeIsAReal(dom_element, QString("y"), &terminaly)) {
|
||||||
|
return(nullptr);
|
||||||
|
}
|
||||||
|
if (!dom_element.hasAttribute("orientation")) {
|
||||||
|
return(nullptr);
|
||||||
|
}
|
||||||
|
if (dom_element.attribute("orientation") == "n") {
|
||||||
|
terminalo = Qet::North;
|
||||||
|
}
|
||||||
|
else if (dom_element.attribute("orientation") == "s") {
|
||||||
|
terminalo = Qet::South;
|
||||||
|
}
|
||||||
|
else if (dom_element.attribute("orientation") == "e") {
|
||||||
|
terminalo = Qet::East;
|
||||||
|
}
|
||||||
|
else if (dom_element.attribute("orientation") == "w") {
|
||||||
|
terminalo = Qet::West;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
Terminal *new_terminal = new Terminal(data, this);
|
Terminal *new_terminal = new Terminal(terminalx, terminaly, terminalo, this);
|
||||||
m_terminals << new_terminal;
|
m_terminals << new_terminal;
|
||||||
|
|
||||||
//Sort from top to bottom and left to rigth
|
//Sort from top to bottom and left to rigth
|
||||||
@@ -1047,7 +1060,7 @@ QDomElement Element::toXml(QDomDocument &document, QHash<Terminal *, int> &table
|
|||||||
foreach(Terminal *t, terminals()) {
|
foreach(Terminal *t, terminals()) {
|
||||||
// alors on enregistre la borne
|
// alors on enregistre la borne
|
||||||
QDomElement terminal = t -> toXml(document);
|
QDomElement terminal = t -> toXml(document);
|
||||||
terminal.setAttribute("id", id_terminal); // for backward compatibility
|
terminal.setAttribute("id", id_terminal);
|
||||||
table_adr_id.insert(t, id_terminal ++);
|
table_adr_id.insert(t, id_terminal ++);
|
||||||
xml_terminals.appendChild(terminal);
|
xml_terminals.appendChild(terminal);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@
|
|||||||
#include "diagramcommands.h"
|
#include "diagramcommands.h"
|
||||||
#include "conductorautonumerotation.h"
|
#include "conductorautonumerotation.h"
|
||||||
#include "conductortextitem.h"
|
#include "conductortextitem.h"
|
||||||
#include "terminaldata.h"
|
|
||||||
|
|
||||||
QColor Terminal::neutralColor = QColor(Qt::blue);
|
QColor Terminal::neutralColor = QColor(Qt::blue);
|
||||||
QColor Terminal::allowedColor = QColor(Qt::darkGreen);
|
QColor Terminal::allowedColor = QColor(Qt::darkGreen);
|
||||||
@@ -40,13 +39,17 @@ const qreal Terminal::Z = 1000;
|
|||||||
@param number of terminal
|
@param number of terminal
|
||||||
@param name of terminal
|
@param name of terminal
|
||||||
*/
|
*/
|
||||||
void Terminal::init(QString number, QString name, bool hiddenName) {
|
void Terminal::init(QPointF pf, Qet::Orientation o, QString number, QString name, bool hiddenName) {
|
||||||
|
// definition du pount d'amarrage pour un conducteur
|
||||||
|
dock_conductor_ = pf;
|
||||||
|
|
||||||
hovered_color_ = Terminal::neutralColor;
|
// definition de l'orientation de la borne (par defaut : sud)
|
||||||
|
if (o < Qet::North || o > Qet::West) ori_ = Qet::South;
|
||||||
|
else ori_ = o;
|
||||||
|
|
||||||
// calcul de la position du point d'amarrage a l'element
|
// calcul de la position du point d'amarrage a l'element
|
||||||
dock_elmt_ = d->m_pos;
|
dock_elmt_ = dock_conductor_;
|
||||||
switch(d->m_orientation) {
|
switch(ori_) {
|
||||||
case Qet::North: dock_elmt_ += QPointF(0, Terminal::terminalSize); break;
|
case Qet::North: dock_elmt_ += QPointF(0, Terminal::terminalSize); break;
|
||||||
case Qet::East : dock_elmt_ += QPointF(-Terminal::terminalSize, 0); break;
|
case Qet::East : dock_elmt_ += QPointF(-Terminal::terminalSize, 0); break;
|
||||||
case Qet::West : dock_elmt_ += QPointF(Terminal::terminalSize, 0); break;
|
case Qet::West : dock_elmt_ += QPointF(Terminal::terminalSize, 0); break;
|
||||||
@@ -71,27 +74,6 @@ void Terminal::init(QString number, QString name, bool hiddenName) {
|
|||||||
setZValue(Z);
|
setZValue(Z);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Terminal::init
|
|
||||||
* Additionaly to the init above, this method stores position and orientation into the data class
|
|
||||||
* \param pf
|
|
||||||
* \param o
|
|
||||||
* \param number
|
|
||||||
* \param name
|
|
||||||
* \param hiddenName
|
|
||||||
*/
|
|
||||||
void Terminal::init(QPointF pf, Qet::Orientation o, QString number, QString name, bool hiddenName)
|
|
||||||
{
|
|
||||||
// definition du pount d'amarrage pour un conducteur
|
|
||||||
d->m_pos = pf;
|
|
||||||
|
|
||||||
// definition de l'orientation de la borne (par defaut : sud)
|
|
||||||
if (o < Qet::North || o > Qet::West) d->m_orientation = Qet::South;
|
|
||||||
else d->m_orientation = o;
|
|
||||||
|
|
||||||
init(number, name, hiddenName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
initialise une borne
|
initialise une borne
|
||||||
@param pf position du point d'amarrage pour un conducteur
|
@param pf position du point d'amarrage pour un conducteur
|
||||||
@@ -101,8 +83,11 @@ void Terminal::init(QPointF pf, Qet::Orientation o, QString number, QString name
|
|||||||
*/
|
*/
|
||||||
Terminal::Terminal(QPointF pf, Qet::Orientation o, Element *e) :
|
Terminal::Terminal(QPointF pf, Qet::Orientation o, Element *e) :
|
||||||
QGraphicsObject(e),
|
QGraphicsObject(e),
|
||||||
d(new TerminalData(this)),
|
m_draw_help_line(false),
|
||||||
parent_element_ (e)
|
m_help_line (nullptr),
|
||||||
|
m_help_line_a (nullptr),
|
||||||
|
parent_element_ (e),
|
||||||
|
hovered_color_ (Terminal::neutralColor)
|
||||||
{
|
{
|
||||||
init(pf, o, "_", "_", false);
|
init(pf, o, "_", "_", false);
|
||||||
}
|
}
|
||||||
@@ -117,8 +102,11 @@ Terminal::Terminal(QPointF pf, Qet::Orientation o, Element *e) :
|
|||||||
*/
|
*/
|
||||||
Terminal::Terminal(qreal pf_x, qreal pf_y, Qet::Orientation o, Element *e) :
|
Terminal::Terminal(qreal pf_x, qreal pf_y, Qet::Orientation o, Element *e) :
|
||||||
QGraphicsObject(e),
|
QGraphicsObject(e),
|
||||||
d(new TerminalData(this)),
|
m_draw_help_line (false),
|
||||||
parent_element_ (e)
|
m_help_line (nullptr),
|
||||||
|
m_help_line_a (nullptr),
|
||||||
|
parent_element_ (e),
|
||||||
|
hovered_color_ (Terminal::neutralColor)
|
||||||
{
|
{
|
||||||
init(QPointF(pf_x, pf_y), o, "_", "_", false);
|
init(QPointF(pf_x, pf_y), o, "_", "_", false);
|
||||||
}
|
}
|
||||||
@@ -135,22 +123,15 @@ Terminal::Terminal(qreal pf_x, qreal pf_y, Qet::Orientation o, Element *e) :
|
|||||||
*/
|
*/
|
||||||
Terminal::Terminal(QPointF pf, Qet::Orientation o, QString num, QString name, bool hiddenName, Element *e) :
|
Terminal::Terminal(QPointF pf, Qet::Orientation o, QString num, QString name, bool hiddenName, Element *e) :
|
||||||
QGraphicsObject (e),
|
QGraphicsObject (e),
|
||||||
d(new TerminalData(this)),
|
m_draw_help_line (false),
|
||||||
parent_element_ (e)
|
m_help_line (nullptr),
|
||||||
|
m_help_line_a (nullptr),
|
||||||
|
parent_element_ (e),
|
||||||
|
hovered_color_ (Terminal::neutralColor)
|
||||||
{
|
{
|
||||||
init(pf, o, std::move(num), std::move(name), hiddenName);
|
init(pf, o, std::move(num), std::move(name), hiddenName);
|
||||||
}
|
}
|
||||||
|
|
||||||
Terminal::Terminal(TerminalData* data, Element* e) :
|
|
||||||
QGraphicsObject(e),
|
|
||||||
d(data),
|
|
||||||
parent_element_(e)
|
|
||||||
{
|
|
||||||
// TODO: what is when multiple parents exist. So the other relation is lost.
|
|
||||||
d->setParent(this);
|
|
||||||
init("_", "_", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Destructeur
|
Destructeur
|
||||||
La destruction de la borne entraine la destruction des conducteurs
|
La destruction de la borne entraine la destruction des conducteurs
|
||||||
@@ -172,15 +153,15 @@ Qet::Orientation Terminal::orientation() const {
|
|||||||
if (Element *elt = qgraphicsitem_cast<Element *>(parentItem())) {
|
if (Element *elt = qgraphicsitem_cast<Element *>(parentItem())) {
|
||||||
// orientations actuelle et par defaut de l'element
|
// orientations actuelle et par defaut de l'element
|
||||||
int ori_cur = elt -> orientation();
|
int ori_cur = elt -> orientation();
|
||||||
if (ori_cur == 0) return(d->m_orientation);
|
if (ori_cur == 0) return(ori_);
|
||||||
else {
|
else {
|
||||||
// calcul l'angle de rotation implique par l'orientation de l'element parent
|
// calcul l'angle de rotation implique par l'orientation de l'element parent
|
||||||
// angle de rotation de la borne sur la scene, divise par 90
|
// angle de rotation de la borne sur la scene, divise par 90
|
||||||
int angle = ori_cur + d->m_orientation;
|
int angle = ori_cur + ori_;
|
||||||
while (angle >= 4) angle -= 4;
|
while (angle >= 4) angle -= 4;
|
||||||
return((Qet::Orientation)angle);
|
return((Qet::Orientation)angle);
|
||||||
}
|
}
|
||||||
} else return(d->m_orientation);
|
} else return(ori_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -257,7 +238,7 @@ void Terminal::paint(QPainter *p, const QStyleOptionGraphicsItem *options, QWidg
|
|||||||
p -> setRenderHint(QPainter::SmoothPixmapTransform, false);
|
p -> setRenderHint(QPainter::SmoothPixmapTransform, false);
|
||||||
|
|
||||||
// on travaille avec les coordonnees de l'element parent
|
// on travaille avec les coordonnees de l'element parent
|
||||||
QPointF c = mapFromParent(d->m_pos);
|
QPointF c = mapFromParent(dock_conductor_);
|
||||||
QPointF e = mapFromParent(dock_elmt_);
|
QPointF e = mapFromParent(dock_elmt_);
|
||||||
|
|
||||||
QPen t;
|
QPen t;
|
||||||
@@ -409,11 +390,11 @@ QLineF Terminal::HelpLine() const
|
|||||||
*/
|
*/
|
||||||
QRectF Terminal::boundingRect() const {
|
QRectF Terminal::boundingRect() const {
|
||||||
if (br_ -> isNull()) {
|
if (br_ -> isNull()) {
|
||||||
qreal dcx = d->m_pos.x();
|
qreal dcx = dock_conductor_.x();
|
||||||
qreal dcy = d->m_pos.y();
|
qreal dcy = dock_conductor_.y();
|
||||||
qreal dex = dock_elmt_.x();
|
qreal dex = dock_elmt_.x();
|
||||||
qreal dey = dock_elmt_.y();
|
qreal dey = dock_elmt_.y();
|
||||||
QPointF origin = (dcx <= dex && dcy <= dey ? d->m_pos : dock_elmt_);
|
QPointF origin = (dcx <= dex && dcy <= dey ? dock_conductor_ : dock_elmt_);
|
||||||
origin += QPointF(-3.0, -3.0);
|
origin += QPointF(-3.0, -3.0);
|
||||||
qreal w = qAbs((int)(dcx - dex)) + 7;
|
qreal w = qAbs((int)(dcx - dex)) + 7;
|
||||||
qreal h = qAbs((int)(dcy - dey)) + 7;
|
qreal h = qAbs((int)(dcy - dey)) + 7;
|
||||||
@@ -511,10 +492,10 @@ void Terminal::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
|
|||||||
@param e L'evenement souris correspondant
|
@param e L'evenement souris correspondant
|
||||||
*/
|
*/
|
||||||
void Terminal::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
void Terminal::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
||||||
if (Diagram *diag = diagram()) {
|
if (Diagram *d = diagram()) {
|
||||||
diag -> setConductorStart(mapToScene(QPointF(d->m_pos)));
|
d -> setConductorStart(mapToScene(QPointF(dock_conductor_)));
|
||||||
diag -> setConductorStop(e -> scenePos());
|
d -> setConductorStop(e -> scenePos());
|
||||||
diag -> setConductor(true);
|
d -> setConductor(true);
|
||||||
//setCursor(Qt::CrossCursor);
|
//setCursor(Qt::CrossCursor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -536,13 +517,13 @@ void Terminal::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Diagram *diag = diagram();
|
Diagram *d = diagram();
|
||||||
if (!diag) return;
|
if (!d) return;
|
||||||
// si la scene est un Diagram, on actualise le poseur de conducteur
|
// si la scene est un Diagram, on actualise le poseur de conducteur
|
||||||
diag -> setConductorStop(e -> scenePos());
|
d -> setConductorStop(e -> scenePos());
|
||||||
|
|
||||||
// on recupere la liste des qgi sous le pointeur
|
// on recupere la liste des qgi sous le pointeur
|
||||||
QList<QGraphicsItem *> qgis = diag -> items(e -> scenePos());
|
QList<QGraphicsItem *> qgis = d -> items(e -> scenePos());
|
||||||
|
|
||||||
/* le qgi le plus haut
|
/* le qgi le plus haut
|
||||||
= le poseur de conductor
|
= le poseur de conductor
|
||||||
@@ -678,10 +659,6 @@ bool Terminal::isLinkedTo(Terminal *other_terminal) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Terminal::canBeLinkedTo
|
* @brief Terminal::canBeLinkedTo
|
||||||
* Checking if the terminal can be linked to \p other_terminal or not
|
|
||||||
* Reasons for not linable:
|
|
||||||
* - \p other_terminal is this terminal
|
|
||||||
* - this terminal is already connected to \p other_terminal
|
|
||||||
* @param other_terminal
|
* @param other_terminal
|
||||||
* @return true if this terminal can be linked to @other_terminal,
|
* @return true if this terminal can be linked to @other_terminal,
|
||||||
* otherwise false
|
* otherwise false
|
||||||
@@ -708,9 +685,9 @@ QList<Conductor *> Terminal::conductors() const {
|
|||||||
*/
|
*/
|
||||||
QDomElement Terminal::toXml(QDomDocument &doc) const {
|
QDomElement Terminal::toXml(QDomDocument &doc) const {
|
||||||
QDomElement qdo = doc.createElement("terminal");
|
QDomElement qdo = doc.createElement("terminal");
|
||||||
qdo.setAttribute("x", QString("%1").arg(dock_elmt_.x())); // for backward compatibility
|
qdo.setAttribute("x", QString("%1").arg(dock_elmt_.x()));
|
||||||
qdo.setAttribute("y", QString("%1").arg(dock_elmt_.y()));// for backward compatibility
|
qdo.setAttribute("y", QString("%1").arg(dock_elmt_.y()));
|
||||||
qdo.setAttribute("orientation", d->m_orientation);
|
qdo.setAttribute("orientation", ori_);
|
||||||
qdo.setAttribute("number", number_terminal_);
|
qdo.setAttribute("number", number_terminal_);
|
||||||
qdo.setAttribute("name", name_terminal_);
|
qdo.setAttribute("name", name_terminal_);
|
||||||
qdo.setAttribute("nameHidden", name_terminal_hidden);
|
qdo.setAttribute("nameHidden", name_terminal_hidden);
|
||||||
@@ -762,22 +739,13 @@ bool Terminal::fromXml(QDomElement &terminal) {
|
|||||||
number_terminal_ = terminal.attribute("number");
|
number_terminal_ = terminal.attribute("number");
|
||||||
name_terminal_ = terminal.attribute("name");
|
name_terminal_ = terminal.attribute("name");
|
||||||
name_terminal_hidden = terminal.attribute("nameHidden").toInt();
|
name_terminal_hidden = terminal.attribute("nameHidden").toInt();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
qFuzzyCompare(terminal.attribute("x").toDouble(), dock_elmt_.x()) &&
|
qFuzzyCompare(terminal.attribute("x").toDouble(), dock_elmt_.x()) &&
|
||||||
qFuzzyCompare(terminal.attribute("y").toDouble(), dock_elmt_.y()) &&
|
qFuzzyCompare(terminal.attribute("y").toDouble(), dock_elmt_.y()) &&
|
||||||
(terminal.attribute("orientation").toInt() == d->m_orientation)
|
(terminal.attribute("orientation").toInt() == ori_)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
@return the position, relative to the scene, of the docking point for
|
|
||||||
conductors.
|
|
||||||
*/
|
|
||||||
inline QPointF Terminal::dockConductor() const {
|
|
||||||
return(mapToScene(d->m_pos));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@return le Diagram auquel cette borne appartient, ou 0 si cette borne est independant
|
@return le Diagram auquel cette borne appartient, ou 0 si cette borne est independant
|
||||||
*/
|
*/
|
||||||
@@ -792,10 +760,6 @@ Element *Terminal::parentElement() const {
|
|||||||
return(parent_element_);
|
return(parent_element_);
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid Terminal::uuid() const {
|
|
||||||
return d->m_uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Conductor::relatedPotentialTerminal
|
* @brief Conductor::relatedPotentialTerminal
|
||||||
* Return terminal at the same potential from the same
|
* Return terminal at the same potential from the same
|
||||||
|
|||||||
@@ -23,12 +23,9 @@
|
|||||||
class Conductor;
|
class Conductor;
|
||||||
class Diagram;
|
class Diagram;
|
||||||
class Element;
|
class Element;
|
||||||
class TerminalData;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This class represents a terminal of an electrical element, i.e. a possible
|
This class represents a terminal of an electrical element, i.e. a possible
|
||||||
plug point for conductors.
|
plug point for conductors.
|
||||||
This class handles all mouse events for connecting conductors
|
|
||||||
*/
|
*/
|
||||||
class Terminal : public QGraphicsObject
|
class Terminal : public QGraphicsObject
|
||||||
{
|
{
|
||||||
@@ -42,7 +39,6 @@ class Terminal : public QGraphicsObject
|
|||||||
public:
|
public:
|
||||||
Terminal(QPointF, Qet::Orientation, Element * = nullptr);
|
Terminal(QPointF, Qet::Orientation, Element * = nullptr);
|
||||||
Terminal(qreal, qreal, Qet::Orientation, Element * = nullptr);
|
Terminal(qreal, qreal, Qet::Orientation, Element * = nullptr);
|
||||||
Terminal(TerminalData* data, Element *e = nullptr);
|
|
||||||
Terminal(QPointF, Qet::Orientation, QString number, QString name, bool hiddenName, Element * = nullptr);
|
Terminal(QPointF, Qet::Orientation, QString number, QString name, bool hiddenName, Element * = nullptr);
|
||||||
~Terminal() override;
|
~Terminal() override;
|
||||||
|
|
||||||
@@ -67,7 +63,6 @@ class Terminal : public QGraphicsObject
|
|||||||
int conductorsCount () const;
|
int conductorsCount () const;
|
||||||
Diagram *diagram () const;
|
Diagram *diagram () const;
|
||||||
Element *parentElement () const;
|
Element *parentElement () const;
|
||||||
QUuid uuid () const;
|
|
||||||
|
|
||||||
QList<Conductor *> conductors() const;
|
QList<Conductor *> conductors() const;
|
||||||
Qet::Orientation orientation() const;
|
Qet::Orientation orientation() const;
|
||||||
@@ -111,23 +106,24 @@ class Terminal : public QGraphicsObject
|
|||||||
static QColor forbiddenColor;
|
static QColor forbiddenColor;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_draw_help_line{false};
|
bool m_draw_help_line;
|
||||||
QGraphicsLineItem *m_help_line{nullptr};
|
QGraphicsLineItem *m_help_line;
|
||||||
QGraphicsLineItem *m_help_line_a{nullptr};
|
QGraphicsLineItem *m_help_line_a;
|
||||||
|
|
||||||
|
|
||||||
TerminalData* d;
|
|
||||||
|
|
||||||
/// Parent electrical element
|
/// Parent electrical element
|
||||||
Element *parent_element_{nullptr};
|
Element *parent_element_;
|
||||||
|
/// docking point for conductors
|
||||||
|
QPointF dock_conductor_;
|
||||||
/// docking point for parent element
|
/// docking point for parent element
|
||||||
QPointF dock_elmt_;
|
QPointF dock_elmt_;
|
||||||
|
/// terminal orientation
|
||||||
|
Qet::Orientation ori_;
|
||||||
/// List of conductors attached to the terminal
|
/// List of conductors attached to the terminal
|
||||||
QList<Conductor *> conductors_;
|
QList<Conductor *> conductors_;
|
||||||
/// Pointer to a rectangle representing the terminal bounding rect;
|
/// Pointer to a rectangle representing the terminal bounding rect;
|
||||||
/// used to calculate the bounding rect once only;
|
/// used to calculate the bounding rect once only;
|
||||||
/// used a pointer because boundingRect() is supposed to be const.
|
/// used a pointer because boundingRect() is supposed to be const.
|
||||||
QRectF *br_{nullptr};
|
QRectF *br_;
|
||||||
/// Last terminal seen through an attached conductor
|
/// Last terminal seen through an attached conductor
|
||||||
Terminal *previous_terminal_;
|
Terminal *previous_terminal_;
|
||||||
/// Whether the mouse pointer is hovering the terminal
|
/// Whether the mouse pointer is hovering the terminal
|
||||||
@@ -141,8 +137,7 @@ class Terminal : public QGraphicsObject
|
|||||||
bool name_terminal_hidden;
|
bool name_terminal_hidden;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void init(QString number, QString name, bool hiddenName);
|
void init(QPointF, Qet::Orientation, QString number, QString name, bool hiddenName);
|
||||||
void init(QPointF pf, Qet::Orientation o, QString number, QString name, bool hiddenName);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -152,6 +147,14 @@ inline int Terminal::conductorsCount() const {
|
|||||||
return(conductors_.size());
|
return(conductors_.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@return the position, relative to the scene, of the docking point for
|
||||||
|
conductors.
|
||||||
|
*/
|
||||||
|
inline QPointF Terminal::dockConductor() const {
|
||||||
|
return(mapToScene(dock_conductor_));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@return the number of terminal.
|
@return the number of terminal.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1583,8 +1583,9 @@ void QETProject::writeDefaultPropertiesXml(QDomElement &xml_element) {
|
|||||||
// export default XRef properties
|
// export default XRef properties
|
||||||
QDomElement xrefs_elmt = xml_document.createElement("xrefs");
|
QDomElement xrefs_elmt = xml_document.createElement("xrefs");
|
||||||
foreach (QString key, defaultXRefProperties().keys()) {
|
foreach (QString key, defaultXRefProperties().keys()) {
|
||||||
defaultXRefProperties()[key].setKey(key);
|
QDomElement xref_elmt = xml_document.createElement("xref");
|
||||||
QDomElement xref_elmt = defaultXRefProperties()[key].toXml(xml_document);
|
xref_elmt.setAttribute("type", key);
|
||||||
|
defaultXRefProperties()[key].toXml(xref_elmt);
|
||||||
xrefs_elmt.appendChild(xref_elmt);
|
xrefs_elmt.appendChild(xref_elmt);
|
||||||
}
|
}
|
||||||
xml_element.appendChild(xrefs_elmt);
|
xml_element.appendChild(xrefs_elmt);
|
||||||
|
|||||||
Reference in New Issue
Block a user