mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-01-09 23:39:58 +01:00
Revert Martin pull request for now, and return to last 7e9fd8df9 commit
This commit is contained in:
@@ -128,10 +128,6 @@ CustomElementPart *ArcEditor::currentPart() const {
|
||||
return(part);
|
||||
}
|
||||
|
||||
QList<CustomElementPart*> ArcEditor::currentParts() const {
|
||||
return style_->currentParts();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ArcEditor::updateArcS
|
||||
* Update the start angle of the arc according to the edited value.
|
||||
|
||||
@@ -51,7 +51,6 @@ class ArcEditor : public ElementItemEditor
|
||||
public:
|
||||
bool setPart(CustomElementPart *) override;
|
||||
CustomElementPart *currentPart() const override;
|
||||
QList<CustomElementPart*> currentParts() const override;
|
||||
|
||||
public slots:
|
||||
void updateArcS();
|
||||
|
||||
@@ -54,7 +54,6 @@ class ElementItemEditor : public QWidget
|
||||
virtual bool setParts(QList <CustomElementPart *>) {return false;}
|
||||
|
||||
virtual CustomElementPart *currentPart() const = 0;
|
||||
virtual QList<CustomElementPart*> currentParts() const = 0;
|
||||
virtual void updateForm() = 0;
|
||||
|
||||
// attributes
|
||||
|
||||
@@ -109,10 +109,6 @@ CustomElementPart *EllipseEditor::currentPart() const {
|
||||
return(part);
|
||||
}
|
||||
|
||||
QList<CustomElementPart*> EllipseEditor::currentParts() const {
|
||||
return style_->currentParts();
|
||||
}
|
||||
|
||||
void EllipseEditor::editingFinished()
|
||||
{
|
||||
if (m_locked) return;
|
||||
|
||||
@@ -49,7 +49,6 @@ class EllipseEditor : public ElementItemEditor
|
||||
public:
|
||||
bool setPart(CustomElementPart *) override;
|
||||
CustomElementPart *currentPart() const override;
|
||||
QList<CustomElementPart*> currentParts() const override;
|
||||
|
||||
public slots:
|
||||
void editingFinished();
|
||||
|
||||
@@ -25,11 +25,9 @@
|
||||
@param scene La scene sur laquelle figure cette borne
|
||||
*/
|
||||
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();
|
||||
setZValue(100000);
|
||||
}
|
||||
@@ -43,8 +41,15 @@ PartTerminal::~PartTerminal() {
|
||||
@param xml_elmt Element XML a lire
|
||||
*/
|
||||
void PartTerminal::fromXml(const QDomElement &xml_elmt) {
|
||||
d->fromXml(xml_elmt);
|
||||
setPos(d->m_pos);
|
||||
// lit la position de la borne
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -54,7 +59,18 @@ void PartTerminal::fromXml(const QDomElement &xml_elmt) {
|
||||
@return un element XML decrivant la borne
|
||||
*/
|
||||
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
|
||||
t.setColor(isSelected() ? Terminal::neutralColor : Qt::red);
|
||||
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
|
||||
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 shape;
|
||||
shape.lineTo(d->second_point);
|
||||
shape.lineTo(second_point);
|
||||
|
||||
QPainterPathStroker pps;
|
||||
pps.setWidth(1);
|
||||
@@ -113,7 +129,7 @@ QPainterPath PartTerminal::shape() const
|
||||
*/
|
||||
QRectF PartTerminal::boundingRect() const
|
||||
{
|
||||
QRectF br(QPointF(0, 0), d->second_point);
|
||||
QRectF br(QPointF(0, 0), second_point);
|
||||
br = br.normalized();
|
||||
|
||||
qreal adjust = (SHADOWS_HEIGHT + 1) / 2;
|
||||
@@ -127,31 +143,24 @@ QRectF PartTerminal::boundingRect() const
|
||||
*/
|
||||
void PartTerminal::setOrientation(Qet::Orientation ori)
|
||||
{
|
||||
if (d->m_orientation == ori) return;
|
||||
if (m_orientation == ori) return;
|
||||
prepareGeometryChange();
|
||||
d->m_orientation = ori;
|
||||
m_orientation = ori;
|
||||
updateSecondPoint();
|
||||
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
|
||||
l'orientation de la borne.
|
||||
*/
|
||||
void PartTerminal::updateSecondPoint() {
|
||||
qreal ts = 4.0; // terminal size
|
||||
switch(d->m_orientation) {
|
||||
case Qet::North: d->second_point = QPointF(0.0, ts); break;
|
||||
case Qet::East : d->second_point = QPointF(-ts, 0.0); break;
|
||||
case Qet::South: d->second_point = QPointF(0.0, -ts); break;
|
||||
case Qet::West : d->second_point = QPointF(ts, 0.0); break;
|
||||
switch(m_orientation) {
|
||||
case Qet::North: second_point = QPointF(0.0, ts); break;
|
||||
case Qet::East : second_point = QPointF(-ts, 0.0); break;
|
||||
case Qet::South: second_point = QPointF(0.0, -ts); break;
|
||||
case Qet::West : second_point = QPointF(ts, 0.0); break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
#define PART_TERMINAL_H
|
||||
|
||||
#include "customelementgraphicpart.h"
|
||||
#include "QUuid"
|
||||
#include "terminaldata.h"
|
||||
|
||||
|
||||
|
||||
@@ -33,7 +31,6 @@ class PartTerminal : public CustomElementGraphicPart
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(Qet::Orientation orientation READ orientation WRITE setOrientation)
|
||||
Q_PROPERTY(QString name READ name WRITE setName)
|
||||
|
||||
|
||||
public:
|
||||
@@ -45,7 +42,12 @@ class PartTerminal : public CustomElementGraphicPart
|
||||
|
||||
signals:
|
||||
void orientationChanged();
|
||||
void nameChanged();
|
||||
|
||||
// attributes
|
||||
private:
|
||||
Qet::Orientation m_orientation;
|
||||
QPointF second_point;
|
||||
|
||||
|
||||
// methods
|
||||
public:
|
||||
@@ -55,7 +57,7 @@ class PartTerminal : public CustomElementGraphicPart
|
||||
* @return the QGraphicsItem 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")); }
|
||||
void fromXml(const QDomElement &) override;
|
||||
const QDomElement toXml(QDomDocument &) const override;
|
||||
@@ -69,14 +71,11 @@ class PartTerminal : public CustomElementGraphicPart
|
||||
void startUserTransformation(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 setName(QString& name);
|
||||
|
||||
private:
|
||||
void updateSecondPoint();
|
||||
TerminalData* d; // pointer to the terminal data
|
||||
|
||||
private:
|
||||
QPointF saved_position_;
|
||||
|
||||
@@ -146,10 +146,6 @@ CustomElementPart *LineEditor::currentPart() const {
|
||||
return(part);
|
||||
}
|
||||
|
||||
QList<CustomElementPart*> LineEditor::currentParts() const {
|
||||
return style_->currentParts();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LineEditor::editedP1
|
||||
* @return The edited P1 in item coordinate
|
||||
|
||||
@@ -51,7 +51,6 @@ class LineEditor : public ElementItemEditor
|
||||
public:
|
||||
bool setPart(CustomElementPart *) override;
|
||||
CustomElementPart *currentPart() const override;
|
||||
QList<CustomElementPart*> currentParts() const override;
|
||||
QPointF editedP1() const;
|
||||
QPointF editedP2() const;
|
||||
|
||||
|
||||
@@ -610,86 +610,73 @@ void QETElementEditor::slot_setNoDragToView() {
|
||||
void QETElementEditor::slot_updateInformations()
|
||||
{
|
||||
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;
|
||||
bool style_editable = false;
|
||||
|
||||
CustomElementPart* part = dynamic_cast<CustomElementPart *>(selected_qgis.first());
|
||||
QString selection_xml_name = part->xmlName();
|
||||
bool same_xml_name = true;
|
||||
bool style_editable = true;
|
||||
for (QGraphicsItem *qgi: selected_qgis) {
|
||||
if (CustomElementPart *cep = dynamic_cast<CustomElementPart *>(qgi)) {
|
||||
cep_list << cep;
|
||||
if (cep->xmlName() != selection_xml_name)
|
||||
same_xml_name = false;
|
||||
} else {
|
||||
style_editable = false;
|
||||
same_xml_name = false;
|
||||
}
|
||||
}
|
||||
if (style_editable)
|
||||
style_editable = StyleEditor::isStyleEditable(cep_list);
|
||||
//Test if part are editable by style editor
|
||||
if (selected_qgis.size() >= 2)
|
||||
{
|
||||
style_editable = true;
|
||||
foreach (QGraphicsItem *qgi, selected_qgis)
|
||||
{
|
||||
if (CustomElementPart *cep = dynamic_cast<CustomElementPart *>(qgi))
|
||||
cep_list << cep;
|
||||
else
|
||||
style_editable = false;
|
||||
}
|
||||
if (style_editable)
|
||||
style_editable = StyleEditor::isStyleEditable(cep_list);
|
||||
|
||||
if (same_xml_name) {
|
||||
if (selection_xml_name == "terminal" ||
|
||||
selection_xml_name == "text" ||
|
||||
selection_xml_name == "dynamic_text") {
|
||||
clearToolsDock();
|
||||
//We add the editor widget
|
||||
ElementItemEditor *editor = static_cast<ElementItemEditor*>(m_editors[selection_xml_name]);
|
||||
|
||||
// TODO: Check if it takes longer than setting the parts again to the 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 (equal == false) {
|
||||
success = editor->setParts(cep_list);
|
||||
}
|
||||
if (success)
|
||||
{
|
||||
m_tools_dock_stack->insertWidget(1, editor);
|
||||
m_tools_dock_stack -> setCurrentIndex(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Editor refused part.";
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//There's several parts selecteds and all can be edited by style editor.
|
||||
if (style_editable)
|
||||
}
|
||||
|
||||
if(selected_qgis.size() == 1)
|
||||
{
|
||||
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();
|
||||
//We add the editor widget
|
||||
QString selection_xml_name = selection -> xmlName();
|
||||
ElementItemEditor *selection_editor = m_editors[selection_xml_name];
|
||||
if (selection_editor)
|
||||
{
|
||||
if (selection_editor->setPart(selection))
|
||||
{
|
||||
m_tools_dock_stack->insertWidget(1, selection_editor);
|
||||
m_tools_dock_stack -> setCurrentIndex(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Editor refused part.";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//There's several parts selecteds and all can be edited by style editor.
|
||||
else if (style_editable)
|
||||
{
|
||||
clearToolsDock();
|
||||
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))
|
||||
{
|
||||
part = part_graphic;
|
||||
m_cep_list.append(part_graphic);
|
||||
updateForm();
|
||||
return(true);
|
||||
}
|
||||
@@ -539,10 +538,6 @@ CustomElementPart *StyleEditor::currentPart() const {
|
||||
return(part);
|
||||
}
|
||||
|
||||
QList<CustomElementPart*> StyleEditor::currentParts() const {
|
||||
return m_cep_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief StyleEditor::isStyleEditable
|
||||
* @param cep_list
|
||||
@@ -553,7 +548,7 @@ bool StyleEditor::isStyleEditable(QList<CustomElementPart *> cep_list)
|
||||
QStringList str;
|
||||
str << "arc" << "ellipse" << "line" << "polygon" << "rect";
|
||||
|
||||
for (CustomElementPart *cep: cep_list)
|
||||
foreach (CustomElementPart *cep, cep_list)
|
||||
if (!str.contains(cep -> xmlName()))
|
||||
return false;
|
||||
|
||||
|
||||
@@ -53,9 +53,8 @@ class StyleEditor : public ElementItemEditor
|
||||
// methods
|
||||
public:
|
||||
bool setPart(CustomElementPart *) override;
|
||||
bool setParts(QList<CustomElementPart *>);
|
||||
bool setParts(QList<CustomElementPart *>) override;
|
||||
CustomElementPart *currentPart() const override;
|
||||
QList<CustomElementPart*> currentParts() const override;
|
||||
|
||||
static bool isStyleEditable (QList <CustomElementPart *> cep_list);
|
||||
|
||||
|
||||
@@ -25,65 +25,51 @@
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
|
||||
TerminalEditor::TerminalEditor(QETElementEditor* editor, QWidget* parent):
|
||||
ElementItemEditor(editor, parent)
|
||||
{
|
||||
m_part = nullptr;
|
||||
m_terminals.clear();
|
||||
init();
|
||||
}
|
||||
|
||||
/**
|
||||
Constructeur
|
||||
@param editor L'editeur d'element concerne
|
||||
@param term La borne a editer
|
||||
@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),
|
||||
m_terminals(terms),
|
||||
m_part(terms.first())
|
||||
part(term),
|
||||
m_locked(false)
|
||||
{
|
||||
init();
|
||||
qle_x = new QDoubleSpinBox();
|
||||
qle_y = new QDoubleSpinBox();
|
||||
|
||||
qle_x -> setRange(-5000, 5000);
|
||||
qle_y -> setRange(-5000, 5000);
|
||||
|
||||
orientation = new QComboBox();
|
||||
orientation -> addItem(QET::Icons::North, tr("Nord"), Qet::North);
|
||||
orientation -> addItem(QET::Icons::East, tr("Est"), Qet::East);
|
||||
orientation -> addItem(QET::Icons::South, tr("Sud"), Qet::South);
|
||||
orientation -> addItem(QET::Icons::West, tr("Ouest"), Qet::West);
|
||||
|
||||
QVBoxLayout *main_layout = new QVBoxLayout();
|
||||
main_layout -> addWidget(new QLabel(tr("Position : ")));
|
||||
|
||||
QHBoxLayout *position = new QHBoxLayout();
|
||||
position -> addWidget(new QLabel(tr("x : ")));
|
||||
position -> addWidget(qle_x );
|
||||
position -> addWidget(new QLabel(tr("y : ")));
|
||||
position -> addWidget(qle_y );
|
||||
main_layout -> addLayout(position);
|
||||
|
||||
QHBoxLayout *ori = new QHBoxLayout();
|
||||
ori -> addWidget(new QLabel(tr("Orientation : ")));
|
||||
ori -> addWidget(orientation );
|
||||
main_layout -> addLayout(ori);
|
||||
|
||||
main_layout -> addStretch();
|
||||
setLayout(main_layout);
|
||||
|
||||
activeConnections(true);
|
||||
updateForm();
|
||||
}
|
||||
|
||||
void TerminalEditor::init() {
|
||||
qle_x = new QDoubleSpinBox();
|
||||
qle_y = new QDoubleSpinBox();
|
||||
|
||||
qle_x -> setRange(-5000, 5000);
|
||||
qle_y -> setRange(-5000, 5000);
|
||||
|
||||
orientation = new QComboBox();
|
||||
orientation -> addItem(QET::Icons::North, tr("Nord"), Qet::North);
|
||||
orientation -> addItem(QET::Icons::East, tr("Est"), Qet::East);
|
||||
orientation -> addItem(QET::Icons::South, tr("Sud"), Qet::South);
|
||||
orientation -> addItem(QET::Icons::West, tr("Ouest"), Qet::West);
|
||||
|
||||
QVBoxLayout *main_layout = new QVBoxLayout();
|
||||
main_layout -> addWidget(new QLabel(tr("Position : ")));
|
||||
|
||||
QHBoxLayout *position = new QHBoxLayout();
|
||||
position -> addWidget(new QLabel(tr("x : ")));
|
||||
position -> addWidget(qle_x );
|
||||
position -> addWidget(new QLabel(tr("y : ")));
|
||||
position -> addWidget(qle_y );
|
||||
main_layout -> addLayout(position);
|
||||
|
||||
QHBoxLayout *ori = new QHBoxLayout();
|
||||
ori -> addWidget(new QLabel(tr("Orientation : ")));
|
||||
ori -> addWidget(orientation );
|
||||
main_layout -> addLayout(ori);
|
||||
|
||||
main_layout -> addStretch();
|
||||
setLayout(main_layout);
|
||||
|
||||
activeConnections(true);
|
||||
updateForm();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// Destructeur
|
||||
TerminalEditor::~TerminalEditor() {
|
||||
};
|
||||
@@ -96,69 +82,33 @@ TerminalEditor::~TerminalEditor() {
|
||||
@param new_part Nouvelle primitive a editer
|
||||
@return true si l'editeur a accepter d'editer la primitive, false sinon
|
||||
*/
|
||||
bool TerminalEditor::setPart(CustomElementPart* new_part)
|
||||
bool TerminalEditor::setPart(CustomElementPart *new_part)
|
||||
{
|
||||
m_terminals.clear();
|
||||
if (!new_part)
|
||||
{
|
||||
if (m_part)
|
||||
disconnect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
|
||||
m_part = nullptr;
|
||||
if (part)
|
||||
disconnect(part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
|
||||
part = nullptr;
|
||||
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 (m_part)
|
||||
disconnect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
|
||||
m_part = part_terminal;
|
||||
if(part == part_terminal) return true;
|
||||
if (part)
|
||||
disconnect(part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
|
||||
part = part_terminal;
|
||||
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(false);
|
||||
}
|
||||
|
||||
/**
|
||||
@return la primitive actuellement editee, ou 0 si ce widget n'en edite pas
|
||||
*/
|
||||
CustomElementPart *TerminalEditor::currentPart() const {
|
||||
return(m_part);
|
||||
}
|
||||
|
||||
QList<CustomElementPart*> TerminalEditor::currentParts() const {
|
||||
QList<CustomElementPart*> parts;
|
||||
for (auto term: m_terminals) {
|
||||
parts.append(static_cast<CustomElementPart*>(term));
|
||||
}
|
||||
return parts;
|
||||
return(part);
|
||||
}
|
||||
|
||||
/// Met a jour l'orientation de la borne et cree un objet d'annulation
|
||||
@@ -167,53 +117,28 @@ void TerminalEditor::updateTerminalO()
|
||||
if (m_locked) return;
|
||||
m_locked = true;
|
||||
QVariant var(orientation -> itemData(orientation -> currentIndex()));
|
||||
|
||||
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);
|
||||
undo->setText(tr("Modifier l'orientation d'une borne"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
if (var != part->property("orientation"))
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(part, "orientation", part->property("orientation"), var);
|
||||
undo->setText(tr("Modifier l'orientation d'une borne"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
m_locked = false;
|
||||
}
|
||||
|
||||
void TerminalEditor::updateXPos() {
|
||||
if (m_locked) return;
|
||||
m_locked = true;
|
||||
QPointF new_pos(qle_x->value(), 0);
|
||||
|
||||
for (int i=0; i < m_terminals.length(); i++) {
|
||||
PartTerminal* term = m_terminals[i];
|
||||
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->enableAnimation();
|
||||
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;
|
||||
void TerminalEditor::updatePos()
|
||||
{
|
||||
if (m_locked) return;
|
||||
m_locked = true;
|
||||
QPointF new_pos(qle_x->value(), qle_y->value());
|
||||
if (new_pos != part->pos())
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(part, "pos", part->property("pos"), new_pos);
|
||||
undo->setText(tr("Déplacer une borne"));
|
||||
undo->enableAnimation();
|
||||
undoStack().push(undo);
|
||||
}
|
||||
m_locked=false;
|
||||
}
|
||||
/// update Number and name, create cancel object
|
||||
|
||||
@@ -221,11 +146,11 @@ void TerminalEditor::updateYPos() {
|
||||
Met a jour le formulaire d'edition
|
||||
*/
|
||||
void TerminalEditor::updateForm() {
|
||||
if (!m_part) return;
|
||||
if (!part) return;
|
||||
activeConnections(false);
|
||||
qle_x -> setValue(m_part->property("x").toReal());
|
||||
qle_y -> setValue(m_part->property("y").toReal());
|
||||
orientation -> setCurrentIndex(orientation->findData(m_part->property("orientation")));
|
||||
qle_x -> setValue(part->property("x").toReal());
|
||||
qle_y -> setValue(part->property("y").toReal());
|
||||
orientation -> setCurrentIndex(orientation->findData(part->property("orientation")));
|
||||
activeConnections(true);
|
||||
}
|
||||
|
||||
@@ -237,14 +162,14 @@ void TerminalEditor::activeConnections(bool active)
|
||||
{
|
||||
if (active)
|
||||
{
|
||||
connect(qle_x, &QDoubleSpinBox::editingFinished, this, &TerminalEditor::updateXPos);
|
||||
connect(qle_y, &QDoubleSpinBox::editingFinished, this, &TerminalEditor::updateYPos);
|
||||
connect(orientation, QOverload<int>::of(&QComboBox::activated), this, &TerminalEditor::updateTerminalO);
|
||||
connect(qle_x, SIGNAL(editingFinished()), this, SLOT(updatePos()));
|
||||
connect(qle_y, SIGNAL(editingFinished()), this, SLOT(updatePos()));
|
||||
connect(orientation, SIGNAL(activated(int)), this, SLOT(updateTerminalO()));
|
||||
}
|
||||
else
|
||||
{
|
||||
disconnect(qle_x, &QDoubleSpinBox::editingFinished, this, &TerminalEditor::updateXPos);
|
||||
disconnect(qle_y, &QDoubleSpinBox::editingFinished, this, &TerminalEditor::updateYPos);
|
||||
disconnect(orientation, QOverload<int>::of(&QComboBox::activated), this, &TerminalEditor::updateTerminalO);
|
||||
disconnect(qle_x, SIGNAL(editingFinished()), this, SLOT(updatePos()));
|
||||
disconnect(qle_y, SIGNAL(editingFinished()), this, SLOT(updatePos()));
|
||||
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.
|
||||
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 {
|
||||
Q_OBJECT
|
||||
// Constructors, destructor
|
||||
public:
|
||||
TerminalEditor(QETElementEditor *, QList<PartTerminal *>& terms, QWidget * = nullptr);
|
||||
TerminalEditor(QETElementEditor *, QWidget * = nullptr);
|
||||
|
||||
TerminalEditor(QETElementEditor *, PartTerminal * = nullptr, QWidget * = nullptr);
|
||||
~TerminalEditor() override;
|
||||
private:
|
||||
TerminalEditor(const TerminalEditor &);
|
||||
|
||||
void init();
|
||||
|
||||
// attributes
|
||||
private:
|
||||
QList<PartTerminal *> m_terminals;
|
||||
PartTerminal *m_part{nullptr};
|
||||
PartTerminal *part;
|
||||
QDoubleSpinBox *qle_x, *qle_y;
|
||||
QComboBox *orientation;
|
||||
bool m_locked{false};
|
||||
bool m_locked;
|
||||
|
||||
// methods
|
||||
public:
|
||||
bool setPart(CustomElementPart *) override;
|
||||
bool setParts(QList<CustomElementPart *> parts) override;
|
||||
bool setPart(CustomElementPart *) override;
|
||||
CustomElementPart *currentPart() const override;
|
||||
QList<CustomElementPart*> currentParts() const override;
|
||||
|
||||
public slots:
|
||||
void updateTerminalO();
|
||||
void updateXPos();
|
||||
void updateYPos();
|
||||
void updatePos();
|
||||
void updateForm() override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#include <QColorDialog>
|
||||
|
||||
DynamicTextFieldEditor::DynamicTextFieldEditor(QETElementEditor *editor, PartDynamicTextField *text_field, QWidget *parent) :
|
||||
ElementItemEditor(editor, parent),
|
||||
ElementItemEditor(editor, parent),
|
||||
ui(new Ui::DynamicTextFieldEditor)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
@@ -57,7 +57,10 @@ DynamicTextFieldEditor::~DynamicTextFieldEditor()
|
||||
*/
|
||||
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();
|
||||
if(!qgi)
|
||||
@@ -68,42 +71,21 @@ bool DynamicTextFieldEditor::setPart(CustomElementPart *part)
|
||||
m_text_field = static_cast<PartDynamicTextField *>(qgi);
|
||||
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;
|
||||
}
|
||||
|
||||
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
|
||||
* @return The current edited part, note they can return nullptr if
|
||||
@@ -113,14 +95,6 @@ CustomElementPart *DynamicTextFieldEditor::currentPart() const {
|
||||
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()
|
||||
{
|
||||
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
|
||||
* Fill the combo box "element information"
|
||||
@@ -205,84 +156,66 @@ void DynamicTextFieldEditor::fillInfoComboBox()
|
||||
|
||||
void DynamicTextFieldEditor::on_m_x_sb_editingFinished()
|
||||
{
|
||||
double value = 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->enableAnimation(true);
|
||||
undoStack().push(undo);
|
||||
}
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "x", m_text_field.data()->x(), ui->m_x_sb->value());
|
||||
undo->setText(tr("Déplacer un champ texte"));
|
||||
undo->enableAnimation(true);
|
||||
undoStack().push(undo);
|
||||
}
|
||||
|
||||
void DynamicTextFieldEditor::on_m_y_sb_editingFinished()
|
||||
{
|
||||
double value = 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->enableAnimation(true);
|
||||
undoStack().push(undo);
|
||||
}
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "y", m_text_field.data()->y(), ui->m_y_sb->value());
|
||||
undo->setText(tr("Déplacer un champ texte"));
|
||||
undo->enableAnimation(true);
|
||||
undoStack().push(undo);
|
||||
}
|
||||
|
||||
void DynamicTextFieldEditor::on_m_rotation_sb_editingFinished()
|
||||
{
|
||||
int value = 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->enableAnimation(true);
|
||||
undoStack().push(undo);
|
||||
}
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "rotation", m_text_field.data()->rotation(), ui->m_rotation_sb->value());
|
||||
undo->setText(tr("Pivoter un champ texte"));
|
||||
undo->enableAnimation(true);
|
||||
undoStack().push(undo);
|
||||
}
|
||||
|
||||
void DynamicTextFieldEditor::on_m_user_text_le_editingFinished()
|
||||
{
|
||||
QString 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"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "text", m_text_field.data()->text(), ui->m_user_text_le->text());
|
||||
undo->setText(tr("Modifier le texte d'un champ texte"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
|
||||
void DynamicTextFieldEditor::on_m_size_sb_editingFinished()
|
||||
{
|
||||
QFont font_ = m_text_field->font();
|
||||
font_.setPointSize(ui->m_size_sb->value());
|
||||
for (int i = 0; i < m_parts.length(); i++) {
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "font", m_parts[i]->font(), font_);
|
||||
undo->setText(tr("Modifier la police d'un champ texte"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "font", m_text_field.data()->font(), font_);
|
||||
undo->setText(tr("Modifier la police d'un champ texte"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
|
||||
void DynamicTextFieldEditor::on_m_frame_cb_clicked()
|
||||
{
|
||||
bool frame = ui->m_frame_cb->isChecked();
|
||||
|
||||
for (int i = 0; i < m_parts.length(); i++) {
|
||||
if(frame != m_parts[i]->frame())
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "frame", m_parts[i]->frame(), frame);
|
||||
undo->setText(tr("Modifier le cadre d'un champ texte"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
if(frame != m_text_field.data()->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"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
|
||||
void DynamicTextFieldEditor::on_m_width_sb_editingFinished()
|
||||
{
|
||||
qreal width = (qreal)ui->m_width_sb->value();
|
||||
|
||||
for (int i = 0; i < m_parts.length(); i++) {
|
||||
if(width != m_parts[i]->textWidth())
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "textWidth", m_parts[i]->textWidth(), width);
|
||||
undo->setText(tr("Modifier la largeur d'un texte"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
if(width != m_text_field.data()->textWidth())
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "textWidth", m_text_field.data()->textWidth(), width);
|
||||
undo->setText(tr("Modifier la largeur d'un texte"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
|
||||
void DynamicTextFieldEditor::on_m_elmt_info_cb_activated(const QString &arg1)
|
||||
@@ -290,16 +223,15 @@ void DynamicTextFieldEditor::on_m_elmt_info_cb_activated(const QString &arg1)
|
||||
Q_UNUSED(arg1)
|
||||
|
||||
QString info = ui->m_elmt_info_cb->currentData().toString();
|
||||
for (int i = 0; i < m_parts.length(); i++) {
|
||||
if(info != m_parts[i]->infoName())
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "infoName", m_parts[i]->infoName(), info);
|
||||
undo->setText(tr("Modifier l'information d'un texte"));
|
||||
undoStack().push(undo);
|
||||
|
||||
m_parts[i]->setPlainText(elementEditor()->elementScene()->elementInformation().value(m_parts[i]->infoName()).toString());
|
||||
}
|
||||
}
|
||||
|
||||
if(info != m_text_field.data()->infoName())
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "infoName", m_text_field.data()->infoName(), info);
|
||||
undo->setText(tr("Modifier l'information d'un texte"));
|
||||
undoStack().push(undo);
|
||||
|
||||
m_text_field.data()->setPlainText(elementEditor()->elementScene()->elementInformation().value(m_text_field.data()->infoName()).toString());
|
||||
}
|
||||
}
|
||||
|
||||
void DynamicTextFieldEditor::on_m_text_from_cb_activated(int index)
|
||||
@@ -320,14 +252,12 @@ void DynamicTextFieldEditor::on_m_text_from_cb_activated(int index)
|
||||
else if(index == 1) tf = DynamicElementTextItem::ElementInfo;
|
||||
else tf = DynamicElementTextItem::CompositeText;
|
||||
|
||||
for (int i = 0; i < m_parts.length(); i++) {
|
||||
if(tf != m_parts[i]->textFrom())
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "textFrom", m_parts[i]->textFrom(), tf);
|
||||
undo->setText(tr("Modifier la source de texte, d'un texte"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
if(tf != m_text_field.data()->textFrom())
|
||||
{
|
||||
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"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
|
||||
void DynamicTextFieldEditor::on_m_composite_text_pb_clicked()
|
||||
@@ -336,13 +266,11 @@ void DynamicTextFieldEditor::on_m_composite_text_pb_clicked()
|
||||
if(ctd.exec())
|
||||
{
|
||||
QString ct = ctd.plainText();
|
||||
for (int i = 0; i < m_parts.length(); i++) {
|
||||
if(ct != m_parts[i]->compositeText())
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "compositeText", m_parts[i]->compositeText(), ctd.plainText());
|
||||
undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
if(ct != m_text_field.data()->compositeText())
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field.data(), "compositeText", m_text_field.data()->compositeText(), ctd.plainText());
|
||||
undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,14 +279,12 @@ void DynamicTextFieldEditor::on_m_alignment_pb_clicked()
|
||||
AlignmentTextDialog atd(m_text_field.data()->alignment(), this);
|
||||
atd.exec();
|
||||
|
||||
for (int i = 0; i < m_parts.length(); i++) {
|
||||
if(atd.alignment() != m_parts[i]->alignment())
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "alignment", QVariant(m_parts[i]->alignment()), QVariant(atd.alignment()));
|
||||
undo->setText(tr("Modifier l'alignement d'un champ texte"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
if(atd.alignment() != m_text_field.data()->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"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
|
||||
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_size_sb->setValue(font_.pointSize());
|
||||
|
||||
for (int i = 0; i < m_parts.length(); i++) {
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "font", m_parts[i]->font(), font_);
|
||||
undo->setText(tr("Modifier la police d'un champ texte"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field.data(), "font", m_text_field->font(), font_);
|
||||
undo->setText(tr("Modifier la police d'un champ texte"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
|
||||
void DynamicTextFieldEditor::on_m_color_kpb_changed(const QColor &newColor)
|
||||
{
|
||||
if (!newColor.isValid())
|
||||
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);
|
||||
undo->setText(tr("Modifier la couleur d'un champ texte"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
if(newColor.isValid() && newColor != m_text_field.data()->color())
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "color", m_text_field.data()->color(), newColor);
|
||||
undo->setText(tr("Modifier la couleur d'un champ texte"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,15 +38,11 @@ class DynamicTextFieldEditor : public ElementItemEditor
|
||||
~DynamicTextFieldEditor() override;
|
||||
|
||||
bool setPart(CustomElementPart *part) override;
|
||||
bool setParts(QList <CustomElementPart *>) override;
|
||||
CustomElementPart *currentPart() const override;
|
||||
QList<CustomElementPart*> currentParts() const override;
|
||||
void updateForm() override;
|
||||
|
||||
private:
|
||||
void fillInfoComboBox();
|
||||
void setUpConnections();
|
||||
void disconnectConnections();
|
||||
|
||||
private slots:
|
||||
void on_m_x_sb_editingFinished();
|
||||
@@ -67,7 +63,6 @@ class DynamicTextFieldEditor : public ElementItemEditor
|
||||
private:
|
||||
Ui::DynamicTextFieldEditor *ui;
|
||||
QPointer<PartDynamicTextField> m_text_field;
|
||||
QList<PartDynamicTextField*> m_parts;
|
||||
QList<QMetaObject::Connection> m_connection_list;
|
||||
};
|
||||
|
||||
|
||||
@@ -98,10 +98,6 @@ CustomElementPart *PolygonEditor::currentPart() const {
|
||||
return m_part;
|
||||
}
|
||||
|
||||
QList<CustomElementPart*> PolygonEditor::currentParts() const {
|
||||
return m_style->currentParts();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief PolygonEditor::updateForm
|
||||
* Update the widget
|
||||
|
||||
@@ -38,7 +38,6 @@ class PolygonEditor : public ElementItemEditor
|
||||
|
||||
bool setPart(CustomElementPart *part) override;
|
||||
CustomElementPart *currentPart() const override;
|
||||
QList<CustomElementPart*> currentParts() const override;
|
||||
void updateForm() override;
|
||||
QVector<QPointF> pointsFromTree();
|
||||
bool eventFilter(QObject *watched, QEvent *event) override;
|
||||
|
||||
@@ -103,10 +103,6 @@ CustomElementPart *RectangleEditor::currentPart() const {
|
||||
return m_part;
|
||||
}
|
||||
|
||||
QList<CustomElementPart*> RectangleEditor::currentParts() const {
|
||||
return m_style->currentParts();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief RectangleEditor::topLeft
|
||||
* @return The edited topLeft already mapped to part coordinate
|
||||
|
||||
@@ -42,7 +42,6 @@ class RectangleEditor : public ElementItemEditor
|
||||
|
||||
bool setPart(CustomElementPart *part) override;
|
||||
CustomElementPart *currentPart() const override;
|
||||
QList<CustomElementPart*> currentParts() const override;
|
||||
QPointF editedTopLeft () const;
|
||||
|
||||
public slots:
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
* @param parent : the parent widget
|
||||
*/
|
||||
TextEditor::TextEditor(QETElementEditor *editor, PartText *text, QWidget *parent) :
|
||||
ElementItemEditor(editor, parent),
|
||||
ElementItemEditor(editor, parent),
|
||||
ui(new Ui::TextEditor)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
@@ -57,7 +57,10 @@ void TextEditor::updateForm()
|
||||
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_x_sb->setValue(m_text->pos().x());
|
||||
@@ -70,30 +73,6 @@ void TextEditor::updateForm()
|
||||
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
|
||||
* Set the current text to edit.
|
||||
@@ -106,18 +85,27 @@ bool TextEditor::setPart(CustomElementPart *part)
|
||||
if (!part)
|
||||
{
|
||||
m_text = nullptr;
|
||||
disconnectChangeConnection();
|
||||
for (QMetaObject::Connection c : m_change_connection) {
|
||||
disconnect(c);
|
||||
}
|
||||
m_change_connection.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (PartText *part_text = static_cast<PartText *>(part))
|
||||
if (PartText *part_text = dynamic_cast<PartText *>(part))
|
||||
{
|
||||
if (part_text == m_text) {
|
||||
return true;
|
||||
}
|
||||
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();
|
||||
return true;
|
||||
@@ -125,37 +113,6 @@ bool TextEditor::setPart(CustomElementPart *part)
|
||||
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
|
||||
* @return The current part
|
||||
@@ -164,14 +121,6 @@ CustomElementPart *TextEditor::currentPart() const {
|
||||
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
|
||||
* 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()
|
||||
{
|
||||
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]()
|
||||
{
|
||||
QString text_ = ui->m_line_edit->text();
|
||||
for (int i=0; i < m_parts.length(); i++) {
|
||||
PartText* partText = m_parts[i];
|
||||
if (text_ != partText->toPlainText())
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "text", partText->toPlainText(), text_);
|
||||
undo->setText(tr("Modifier le contenu d'un champ texte"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
if (text_ != m_text->toPlainText())
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "text", m_text->toPlainText(), text_);
|
||||
undo->setText(tr("Modifier le contenu d'un champ texte"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
});
|
||||
m_edit_connection << connect(ui->m_x_sb, QOverload<int>::of(&QSpinBox::valueChanged), [this]()
|
||||
{
|
||||
QPointF pos(ui->m_x_sb->value(), 0);
|
||||
for (int i=0; i < m_parts.length(); i++) {
|
||||
PartText* partText = m_parts[i];
|
||||
pos.setY(partText->pos().y());
|
||||
if (pos != partText->pos())
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "pos", partText->pos(), pos);
|
||||
undo->setText(tr("Déplacer un champ texte"));
|
||||
undo->setAnimated(true, false);
|
||||
undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
QPointF pos(ui->m_x_sb->value(), ui->m_y_sb->value());
|
||||
if (pos != m_text->pos())
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "pos", m_text->pos(), pos);
|
||||
undo->setText(tr("Déplacer un champ texte"));
|
||||
undo->setAnimated(true, false);
|
||||
undoStack().push(undo);
|
||||
}
|
||||
});
|
||||
m_edit_connection << connect(ui->m_y_sb, QOverload<int>::of(&QSpinBox::valueChanged), [this]()
|
||||
{
|
||||
QPointF pos(0, ui->m_y_sb->value());
|
||||
for (int i=0; i < m_parts.length(); i++) {
|
||||
PartText* partText = m_parts[i];
|
||||
pos.setX(partText->pos().x());
|
||||
if (pos != partText->pos())
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "pos", partText->pos(), pos);
|
||||
undo->setText(tr("Déplacer un champ texte"));
|
||||
undo->setAnimated(true, false);
|
||||
undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
QPointF pos(ui->m_x_sb->value(), ui->m_y_sb->value());
|
||||
if (pos != m_text->pos())
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "pos", m_text->pos(), pos);
|
||||
undo->setText(tr("Déplacer un champ texte"));
|
||||
undo->setAnimated(true, false);
|
||||
undoStack().push(undo);
|
||||
}
|
||||
});
|
||||
m_edit_connection << connect(ui->m_rotation_sb, QOverload<int>::of(&QSpinBox::valueChanged), [this]()
|
||||
{
|
||||
for (int i=0; i < m_parts.length(); i++) {
|
||||
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());
|
||||
undo->setText(tr("Pivoter un champ texte"));
|
||||
undo->setAnimated(true, false);
|
||||
undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
if (ui->m_rotation_sb->value() != m_text->rotation())
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "rotation", m_text->rotation(), ui->m_rotation_sb->value());
|
||||
undo->setText(tr("Pivoter un champ texte"));
|
||||
undo->setAnimated(true, false);
|
||||
undoStack().push(undo);
|
||||
}
|
||||
});
|
||||
m_edit_connection << connect(ui->m_size_sb, QOverload<int>::of(&QSpinBox::valueChanged), [this]()
|
||||
{
|
||||
for (int i=0; i < m_parts.length(); i++) {
|
||||
PartText* partText = m_parts[i];
|
||||
if (partText->font().pointSize() != ui->m_size_sb->value())
|
||||
{
|
||||
QFont font_ = partText->font();
|
||||
font_.setPointSize(ui->m_size_sb->value());
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "font", partText->font(), font_);
|
||||
undo->setText(tr("Modifier la police d'un texte"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
if (m_text->font().pointSize() != ui->m_size_sb->value())
|
||||
{
|
||||
QFont font_ = m_text->font();
|
||||
font_.setPointSize(ui->m_size_sb->value());
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "font", m_text->font(), font_);
|
||||
undo->setText(tr("Modifier la police d'un texte"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -261,23 +196,17 @@ void TextEditor::on_m_font_pb_clicked()
|
||||
bool ok;
|
||||
QFont font_ = QFontDialog::getFont(&ok, m_text->font(), this);
|
||||
|
||||
if (ok && font_ != m_text->font()) {
|
||||
ui->m_size_sb->blockSignals(true);
|
||||
ui->m_size_sb->setValue(font_.pointSize());
|
||||
ui->m_size_sb->blockSignals(false);
|
||||
if (ok && font_ != m_text->font())
|
||||
{
|
||||
ui->m_size_sb->blockSignals(true);
|
||||
ui->m_size_sb->setValue(font_.pointSize());
|
||||
ui->m_size_sb->blockSignals(false);
|
||||
|
||||
ui->m_font_pb->setText(font_.family());
|
||||
}
|
||||
|
||||
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"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
ui->m_font_pb->setText(font_.family());
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "font", m_text->font(), font_);
|
||||
undo->setText(tr("Modifier la police d'un texte"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -286,13 +215,10 @@ void TextEditor::on_m_font_pb_clicked()
|
||||
*/
|
||||
void TextEditor::on_m_color_pb_changed(const QColor &newColor)
|
||||
{
|
||||
for (int i=0; i < m_parts.length(); i++) {
|
||||
PartText* partText = m_parts[i];
|
||||
if (newColor != partText->defaultTextColor())
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "color", partText->defaultTextColor(), newColor);
|
||||
undo->setText(tr("Modifier la couleur d'un texte"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
if (newColor != m_text->defaultTextColor())
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "color", m_text->defaultTextColor(), newColor);
|
||||
undo->setText(tr("Modifier la couleur d'un texte"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,26 +39,20 @@ class TextEditor : public ElementItemEditor
|
||||
|
||||
void updateForm() override;
|
||||
bool setPart(CustomElementPart *part) override;
|
||||
bool setParts(QList <CustomElementPart *>) override;
|
||||
CustomElementPart *currentPart() const override;
|
||||
QList<CustomElementPart*> currentParts() const override;
|
||||
|
||||
private slots:
|
||||
void on_m_font_pb_clicked();
|
||||
void on_m_color_pb_changed(const QColor &newColor);
|
||||
private:
|
||||
void setUpEditConnection();
|
||||
void setUpChangeConnection(QPointer<PartText> part);
|
||||
void disconnectChangeConnection();
|
||||
void disconnectEditConnection();
|
||||
|
||||
private:
|
||||
Ui::TextEditor *ui;
|
||||
|
||||
QPointer <PartText> m_text;
|
||||
QList<PartText*> m_parts;
|
||||
QList <QMetaObject::Connection> m_edit_connection;
|
||||
QList <QMetaObject::Connection> m_change_connection;
|
||||
QList <QMetaObject::Connection> m_change_connection;
|
||||
};
|
||||
|
||||
#endif // TEXTEDITOR_H
|
||||
|
||||
Reference in New Issue
Block a user