diff --git a/sources/editor/editorcommands.cpp b/sources/editor/editorcommands.cpp index 22ddb2156..7e26d9b60 100644 --- a/sources/editor/editorcommands.cpp +++ b/sources/editor/editorcommands.cpp @@ -660,3 +660,33 @@ void ScalePartsCommand::adjustText() { setText(QObject::tr("redimensionnement de %1 primitives", "undo caption -- %1 always > 1").arg(scaled_primitives_.count())); } } +/** + * @brief ChangePropertiesCommand::ChangePropertiesCommand + * Change the properties of the drawed element + * @param scene: scene to belong the property + * @param type: new type of element. + * @param context: new info about type. + * @param parent: parent undo + */ +ChangePropertiesCommand::ChangePropertiesCommand(ElementScene *scene, QString type, DiagramContext info, QUndoCommand *parent) : + ElementEditionCommand(scene, 0, parent) +{ + m_type << scene->m_elmt_type << type; + m_info << scene->m_elmt_kindInfo << info; + setText(QObject::tr("Modifier les propri\351t\351s")); +} + +ChangePropertiesCommand::~ChangePropertiesCommand() {} + +void ChangePropertiesCommand::undo() { + editor_scene_-> m_elmt_type = m_type.first(); + editor_scene_-> m_elmt_kindInfo = m_info.first(); +} + +void ChangePropertiesCommand::redo() { + editor_scene_-> m_elmt_type = m_type.last(); + editor_scene_-> m_elmt_kindInfo = m_info.last(); +} + + + diff --git a/sources/editor/editorcommands.h b/sources/editor/editorcommands.h index fb6e56ec3..41a9ac5d2 100644 --- a/sources/editor/editorcommands.h +++ b/sources/editor/editorcommands.h @@ -349,4 +349,17 @@ class ScalePartsCommand : public ElementEditionCommand { bool first_redo; }; +class ChangePropertiesCommand : public ElementEditionCommand { + public: + ChangePropertiesCommand (ElementScene *scene, QString type, DiagramContext info, QUndoCommand *parent=0); + virtual ~ChangePropertiesCommand (); + + virtual void undo(); + virtual void redo(); + + private: + QList m_type; + QList m_info; +}; + #endif diff --git a/sources/editor/elementscene.cpp b/sources/editor/elementscene.cpp index 9d1d392fb..c8462595e 100644 --- a/sources/editor/elementscene.cpp +++ b/sources/editor/elementscene.cpp @@ -424,7 +424,7 @@ const QDomDocument ElementScene::toXml(bool all_parts) { // noms de l'element root.appendChild(_names.toXml(xml_document)); - if (m_elmt_type == "slave") { + if (m_elmt_type == "slave" || m_elmt_type == "master") { QDomElement kindInfo = xml_document.createElement("kindInformations"); m_elmt_kindInfo.toXml(kindInfo, "kindInformation"); root.appendChild(kindInfo); @@ -722,8 +722,12 @@ void ElementScene::slot_editAuthorInformations() { * Open dialog to edit the element properties */ void ElementScene::slot_editProperties() { - ElementPropertiesEditorWidget epew(m_elmt_type, m_elmt_kindInfo); + QString type = m_elmt_type; + DiagramContext info = m_elmt_kindInfo; + ElementPropertiesEditorWidget epew(type, info); epew.exec(); + if (type != m_elmt_type || info != m_elmt_kindInfo) + undoStack().push(new ChangePropertiesCommand(this, type, info)); } /** diff --git a/sources/editor/elementscene.h b/sources/editor/elementscene.h index 7cbc253f7..0af1bf1ce 100644 --- a/sources/editor/elementscene.h +++ b/sources/editor/elementscene.h @@ -38,6 +38,7 @@ class PartArc; border due to its fixed size and its hotspot. */ class ElementScene : public QGraphicsScene { + friend class ChangePropertiesCommand; Q_OBJECT // enum diff --git a/sources/editor/ui/elementpropertieseditorwidget.cpp b/sources/editor/ui/elementpropertieseditorwidget.cpp index 7cbec8c0d..063c9d081 100644 --- a/sources/editor/ui/elementpropertieseditorwidget.cpp +++ b/sources/editor/ui/elementpropertieseditorwidget.cpp @@ -45,11 +45,22 @@ ElementPropertiesEditorWidget::~ElementPropertiesEditorWidget() delete ui; } +/** + * @brief ElementPropertiesEditorWidget::upDateInterface + * Update the interface with the curent value + */ void ElementPropertiesEditorWidget::upDateInterface() { ui -> m_base_type_cb -> setCurrentIndex (ui -> m_base_type_cb -> findData (QVariant(m_basic_type))); - ui -> m_state_cb -> setCurrentIndex (ui -> m_state_cb -> findData (m_dc["state"].toString())); - ui -> m_type_cb -> setCurrentIndex (ui -> m_type_cb -> findData (m_dc["type"].toString())); - ui -> m_number_ctc -> setValue (m_dc["number"].toInt()); + + if (m_basic_type == "slave") { + ui -> m_state_cb -> setCurrentIndex (ui -> m_state_cb -> findData (m_dc["state"].toString())); + ui -> m_type_cb -> setCurrentIndex (ui -> m_type_cb -> findData (m_dc["type"].toString())); + ui -> m_number_ctc -> setValue (m_dc["number"].toInt()); + } + + else if (m_basic_type == "master") { + ui -> m_master_type_cb -> setCurrentIndex (ui -> m_master_type_cb -> findData (m_dc["type"])); + } on_m_base_type_cb_currentIndexChanged(ui->m_base_type_cb->currentIndex()); } @@ -72,6 +83,10 @@ void ElementPropertiesEditorWidget::setUpInterface() { ui -> m_type_cb -> addItem(tr("Puissance"), QVariant("power")); ui -> m_type_cb -> addItem(tr("Temporis\351 travail"), QVariant("delayOn")); ui -> m_type_cb -> addItem(tr("Temporis\351 repos"), QVariant("delayOff")); + + //Master option + ui -> m_master_type_cb -> addItem(tr("Bobine"), QVariant("coil")); + ui -> m_master_type_cb -> addItem(tr("Organe de protection"), QVariant("protection")); } /** @@ -86,6 +101,9 @@ void ElementPropertiesEditorWidget::on_m_buttonBox_accepted() m_dc.addValue("type", ui -> m_type_cb -> itemData(ui -> m_type_cb -> currentIndex())); m_dc.addValue("number", QVariant(ui -> m_number_ctc -> value())); } + else if(m_basic_type == "master") { + m_dc.addValue("type", ui -> m_master_type_cb -> itemData(ui -> m_master_type_cb -> currentIndex())); + } this->close(); } @@ -95,10 +113,11 @@ void ElementPropertiesEditorWidget::on_m_buttonBox_accepted() */ void ElementPropertiesEditorWidget::on_m_base_type_cb_currentIndexChanged(int index) { - if (ui->m_base_type_cb->itemData(index).toString() == "slave") { - ui->m_slave_gb->setEnabled(true); - } else { - ui->m_slave_gb->setEnabled(false); - } + bool slave = false , master = false; + if (ui -> m_base_type_cb -> itemData(index).toString() == "slave") slave = true; + else if (ui -> m_base_type_cb -> itemData(index).toString() == "master") master = true; + + ui -> m_slave_gb -> setVisible(slave); + ui -> m_master_gb -> setVisible(master); } diff --git a/sources/editor/ui/elementpropertieseditorwidget.ui b/sources/editor/ui/elementpropertieseditorwidget.ui index 522985e0e..e0738c37d 100644 --- a/sources/editor/ui/elementpropertieseditorwidget.ui +++ b/sources/editor/ui/elementpropertieseditorwidget.ui @@ -78,6 +78,25 @@ + + + + Élément maître + + + + + + Type concret + + + + + + + + +