This commit is contained in:
Martin Marmsoler
2020-05-26 23:23:19 +02:00
committed by Laurent Trinques
parent f2c796bdb0
commit 304ea00d7b
4 changed files with 156 additions and 68 deletions

View File

@@ -613,11 +613,48 @@ void QETElementEditor::slot_updateInformations()
QList<CustomElementPart *> cep_list; QList<CustomElementPart *> cep_list;
bool style_editable = false; bool style_editable = false;
bool same_xml_name = true;
CustomElementPart* part = dynamic_cast<CustomElementPart *>(selected_qgis.first());
QString selection_xml_name;
if (part) {
selection_xml_name = part->xmlName();
for (auto itm: selected_qgis) {
CustomElementPart *selection = dynamic_cast<CustomElementPart *>(itm);
if (selection -> xmlName() != selection_xml_name) {
same_xml_name = false;
break;
}
}
} else
same_xml_name = false;
if (same_xml_name) {
if (selection_xml_name == "terminal") {
clearToolsDock();
//We add the editor widget
TerminalEditor *editor = static_cast<TerminalEditor*>(m_editors[selection_xml_name]);
if (editor)
{
if (editor->setTerminals(selection))
{
m_tools_dock_stack->insertWidget(1, selection_editor);
m_tools_dock_stack -> setCurrentIndex(1);
}
else
{
qDebug() << "Editor refused part.";
}
}
}
}
//Test if part are editable by style editor //Test if part are editable by style editor
if (selected_qgis.size() >= 2) if (selected_qgis.size() >= 2)
{ {
style_editable = true; style_editable = true;
foreach (QGraphicsItem *qgi, selected_qgis) for (QGraphicsItem *qgi: selected_qgis)
{ {
if (CustomElementPart *cep = dynamic_cast<CustomElementPart *>(qgi)) if (CustomElementPart *cep = dynamic_cast<CustomElementPart *>(qgi))
cep_list << cep; cep_list << cep;

View File

@@ -548,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";
foreach (CustomElementPart *cep, cep_list) for (CustomElementPart *cep: cep_list)
if (!str.contains(cep -> xmlName())) if (!str.contains(cep -> xmlName()))
return false; return false;

View File

@@ -25,17 +25,29 @@
#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, PartTerminal *term, QWidget *parent) : TerminalEditor::TerminalEditor(QETElementEditor *editor, QList<PartTerminal *> &terms, QWidget *parent) :
ElementItemEditor(editor, parent), ElementItemEditor(editor, parent),
part(term), m_terminals(terms),
m_locked(false) m_part(terms.first())
{ {
init();
}
void TerminalEditor::init() {
qle_x = new QDoubleSpinBox(); qle_x = new QDoubleSpinBox();
qle_y = new QDoubleSpinBox(); qle_y = new QDoubleSpinBox();
@@ -70,6 +82,8 @@ TerminalEditor::TerminalEditor(QETElementEditor *editor, PartTerminal *term, QWi
updateForm(); updateForm();
} }
/// Destructeur /// Destructeur
TerminalEditor::~TerminalEditor() { TerminalEditor::~TerminalEditor() {
}; };
@@ -84,21 +98,47 @@ TerminalEditor::~TerminalEditor() {
*/ */
bool TerminalEditor::setPart(CustomElementPart* new_part) bool TerminalEditor::setPart(CustomElementPart* new_part)
{ {
m_terminals.clear();
if (!new_part) if (!new_part)
{ {
if (part) if (m_part)
disconnect(part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm); disconnect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
part = nullptr; m_part = nullptr;
return(true); return(true);
} }
if (PartTerminal *part_terminal = dynamic_cast<PartTerminal *>(new_part)) if (PartTerminal *part_terminal = dynamic_cast<PartTerminal *>(new_part))
{ {
if(part == part_terminal) return true; if(m_part == part_terminal) return true;
if (part) if (m_part)
disconnect(part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm); disconnect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
part = part_terminal; m_part = part_terminal;
updateForm(); updateForm();
connect(part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm); connect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
return(true);
}
return(false);
}
bool TerminalEditor::setTerminals(QList<PartTerminal *> terminals)
{
if (terminals.isEmpty())
{
m_terminals.clear();
if (m_part)
disconnect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
m_part = nullptr;
return(true);
}
if (PartTerminal *part_terminal = dynamic_cast<PartTerminal *>(terminals.first()))
{
if(m_part == part_terminal) return true;
if (m_part)
disconnect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
m_part = part_terminal;
m_terminals = terminals;
updateForm();
connect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
return(true); return(true);
} }
return(false); return(false);
@@ -108,7 +148,7 @@ bool TerminalEditor::setPart(CustomElementPart *new_part)
@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(part); return(m_part);
} }
/// 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
@@ -117,12 +157,15 @@ 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 (auto term: m_terminals) {
if (var != term->property("orientation"))
{ {
QPropertyUndoCommand *undo = new QPropertyUndoCommand(part, "orientation", part->property("orientation"), var); QPropertyUndoCommand *undo = new QPropertyUndoCommand(term, "orientation", term->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;
} }
@@ -131,13 +174,15 @@ void TerminalEditor::updatePos()
if (m_locked) return; if (m_locked) return;
m_locked = true; m_locked = true;
QPointF new_pos(qle_x->value(), qle_y->value()); QPointF new_pos(qle_x->value(), qle_y->value());
if (new_pos != part->pos())
{ for (auto term: m_terminals) {
QPropertyUndoCommand *undo = new QPropertyUndoCommand(part, "pos", part->property("pos"), new_pos); 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; m_locked=false;
} }
/// update Number and name, create cancel object /// update Number and name, create cancel object
@@ -146,11 +191,11 @@ void TerminalEditor::updatePos()
Met a jour le formulaire d'edition Met a jour le formulaire d'edition
*/ */
void TerminalEditor::updateForm() { void TerminalEditor::updateForm() {
if (!part) return; if (!m_part) return;
activeConnections(false); activeConnections(false);
qle_x -> setValue(part->property("x").toReal()); qle_x -> setValue(m_part->property("x").toReal());
qle_y -> setValue(part->property("y").toReal()); qle_y -> setValue(m_part->property("y").toReal());
orientation -> setCurrentIndex(orientation->findData(part->property("orientation"))); orientation -> setCurrentIndex(orientation->findData(m_part->property("orientation")));
activeConnections(true); activeConnections(true);
} }

View File

@@ -31,21 +31,27 @@ class TerminalEditor : public ElementItemEditor {
Q_OBJECT Q_OBJECT
// Constructors, destructor // Constructors, destructor
public: public:
TerminalEditor(QETElementEditor *, PartTerminal * = nullptr, QWidget * = nullptr); TerminalEditor(QETElementEditor *, QList<PartTerminal *>& terms, QWidget * = nullptr);
TerminalEditor(QETElementEditor *, QWidget * = nullptr);
~TerminalEditor() override; ~TerminalEditor() override;
private: private:
TerminalEditor(const TerminalEditor &); TerminalEditor(const TerminalEditor &);
void init();
// attributes // attributes
private: private:
PartTerminal *part; QList<PartTerminal *> m_terminals;
PartTerminal *m_part{nullptr};
QDoubleSpinBox *qle_x, *qle_y; QDoubleSpinBox *qle_x, *qle_y;
QComboBox *orientation; QComboBox *orientation;
bool m_locked; bool m_locked{false};
// methods // methods
public: public:
bool setPart(CustomElementPart *) override; bool setPart(CustomElementPart *) override;
bool setTerminals(QList<PartTerminal*> terminals);
CustomElementPart *currentPart() const override; CustomElementPart *currentPart() const override;
public slots: public slots: