Element editor -> properties: user can edit subtype for master.

Change the properties is now managed by undo command


git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3157 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2014-06-20 20:10:09 +00:00
parent ba04d35288
commit 60748954b6
6 changed files with 96 additions and 10 deletions

View File

@@ -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();
}

View File

@@ -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 <QString> m_type;
QList <DiagramContext> m_info;
};
#endif

View File

@@ -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));
}
/**

View File

@@ -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

View File

@@ -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)));
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);
}

View File

@@ -78,6 +78,25 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="m_master_gb">
<property name="title">
<string>Élément maître</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Type concret</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="m_master_type_cb"/>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">