mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 13:30:34 +01:00
WIP
This commit is contained in:
committed by
Laurent Trinques
parent
451d5c8f58
commit
b85b341941
@@ -613,11 +613,48 @@ void QETElementEditor::slot_updateInformations()
|
||||
QList<CustomElementPart *> cep_list;
|
||||
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
|
||||
if (selected_qgis.size() >= 2)
|
||||
{
|
||||
style_editable = true;
|
||||
foreach (QGraphicsItem *qgi, selected_qgis)
|
||||
for (QGraphicsItem *qgi: selected_qgis)
|
||||
{
|
||||
if (CustomElementPart *cep = dynamic_cast<CustomElementPart *>(qgi))
|
||||
cep_list << cep;
|
||||
|
||||
@@ -548,7 +548,7 @@ bool StyleEditor::isStyleEditable(QList<CustomElementPart *> cep_list)
|
||||
QStringList str;
|
||||
str << "arc" << "ellipse" << "line" << "polygon" << "rect";
|
||||
|
||||
foreach (CustomElementPart *cep, cep_list)
|
||||
for (CustomElementPart *cep: cep_list)
|
||||
if (!str.contains(cep -> xmlName()))
|
||||
return false;
|
||||
|
||||
|
||||
@@ -25,17 +25,29 @@
|
||||
#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, PartTerminal *term, QWidget *parent) :
|
||||
TerminalEditor::TerminalEditor(QETElementEditor *editor, QList<PartTerminal *> &terms, QWidget *parent) :
|
||||
ElementItemEditor(editor, parent),
|
||||
part(term),
|
||||
m_locked(false)
|
||||
m_terminals(terms),
|
||||
m_part(terms.first())
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
void TerminalEditor::init() {
|
||||
qle_x = new QDoubleSpinBox();
|
||||
qle_y = new QDoubleSpinBox();
|
||||
|
||||
@@ -70,6 +82,8 @@ TerminalEditor::TerminalEditor(QETElementEditor *editor, PartTerminal *term, QWi
|
||||
updateForm();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// Destructeur
|
||||
TerminalEditor::~TerminalEditor() {
|
||||
};
|
||||
@@ -84,21 +98,47 @@ TerminalEditor::~TerminalEditor() {
|
||||
*/
|
||||
bool TerminalEditor::setPart(CustomElementPart* new_part)
|
||||
{
|
||||
m_terminals.clear();
|
||||
if (!new_part)
|
||||
{
|
||||
if (part)
|
||||
disconnect(part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
|
||||
part = nullptr;
|
||||
if (m_part)
|
||||
disconnect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
|
||||
m_part = nullptr;
|
||||
return(true);
|
||||
}
|
||||
if (PartTerminal *part_terminal = dynamic_cast<PartTerminal *>(new_part))
|
||||
{
|
||||
if(part == part_terminal) return true;
|
||||
if (part)
|
||||
disconnect(part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
|
||||
part = part_terminal;
|
||||
if(m_part == part_terminal) return true;
|
||||
if (m_part)
|
||||
disconnect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
|
||||
m_part = part_terminal;
|
||||
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(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
|
||||
*/
|
||||
CustomElementPart *TerminalEditor::currentPart() const {
|
||||
return(part);
|
||||
return(m_part);
|
||||
}
|
||||
|
||||
/// 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;
|
||||
m_locked = true;
|
||||
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"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
m_locked = false;
|
||||
}
|
||||
|
||||
@@ -131,13 +174,15 @@ 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);
|
||||
|
||||
for (auto term: m_terminals) {
|
||||
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;
|
||||
}
|
||||
/// update Number and name, create cancel object
|
||||
@@ -146,11 +191,11 @@ void TerminalEditor::updatePos()
|
||||
Met a jour le formulaire d'edition
|
||||
*/
|
||||
void TerminalEditor::updateForm() {
|
||||
if (!part) return;
|
||||
if (!m_part) return;
|
||||
activeConnections(false);
|
||||
qle_x -> setValue(part->property("x").toReal());
|
||||
qle_y -> setValue(part->property("y").toReal());
|
||||
orientation -> setCurrentIndex(orientation->findData(part->property("orientation")));
|
||||
qle_x -> setValue(m_part->property("x").toReal());
|
||||
qle_y -> setValue(m_part->property("y").toReal());
|
||||
orientation -> setCurrentIndex(orientation->findData(m_part->property("orientation")));
|
||||
activeConnections(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,21 +31,27 @@ class TerminalEditor : public ElementItemEditor {
|
||||
Q_OBJECT
|
||||
// Constructors, destructor
|
||||
public:
|
||||
TerminalEditor(QETElementEditor *, PartTerminal * = nullptr, QWidget * = nullptr);
|
||||
TerminalEditor(QETElementEditor *, QList<PartTerminal *>& terms, QWidget * = nullptr);
|
||||
TerminalEditor(QETElementEditor *, QWidget * = nullptr);
|
||||
|
||||
~TerminalEditor() override;
|
||||
private:
|
||||
TerminalEditor(const TerminalEditor &);
|
||||
|
||||
void init();
|
||||
|
||||
// attributes
|
||||
private:
|
||||
PartTerminal *part;
|
||||
QList<PartTerminal *> m_terminals;
|
||||
PartTerminal *m_part{nullptr};
|
||||
QDoubleSpinBox *qle_x, *qle_y;
|
||||
QComboBox *orientation;
|
||||
bool m_locked;
|
||||
bool m_locked{false};
|
||||
|
||||
// methods
|
||||
public:
|
||||
bool setPart(CustomElementPart *) override;
|
||||
bool setTerminals(QList<PartTerminal*> terminals);
|
||||
CustomElementPart *currentPart() const override;
|
||||
|
||||
public slots:
|
||||
|
||||
Reference in New Issue
Block a user