[qet] [3157] Element editor -> properties: user can edit subtype for master.

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 3157
Author:   blacksun
Date:     2014-06-20 22:10:09 +0200 (Fri, 20 Jun 2014)
Log Message:
-----------
Element editor -> properties: user can edit subtype for master.
Change the properties is now managed by undo command

Modified Paths:
--------------
    trunk/sources/editor/editorcommands.cpp
    trunk/sources/editor/editorcommands.h
    trunk/sources/editor/elementscene.cpp
    trunk/sources/editor/elementscene.h
    trunk/sources/editor/ui/elementpropertieseditorwidget.cpp
    trunk/sources/editor/ui/elementpropertieseditorwidget.ui

Modified: trunk/sources/editor/editorcommands.cpp
===================================================================
--- trunk/sources/editor/editorcommands.cpp	2014-06-20 20:00:11 UTC (rev 3156)
+++ trunk/sources/editor/editorcommands.cpp	2014-06-20 20:10:09 UTC (rev 3157)
@@ -660,3 +660,33 @@
 		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();
+}
+
+
+

Modified: trunk/sources/editor/editorcommands.h
===================================================================
--- trunk/sources/editor/editorcommands.h	2014-06-20 20:00:11 UTC (rev 3156)
+++ trunk/sources/editor/editorcommands.h	2014-06-20 20:10:09 UTC (rev 3157)
@@ -349,4 +349,17 @@
 	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

Modified: trunk/sources/editor/elementscene.cpp
===================================================================
--- trunk/sources/editor/elementscene.cpp	2014-06-20 20:00:11 UTC (rev 3156)
+++ trunk/sources/editor/elementscene.cpp	2014-06-20 20:10:09 UTC (rev 3157)
@@ -424,7 +424,7 @@
 	// 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 @@
  * 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));
 }
 
 /**

Modified: trunk/sources/editor/elementscene.h
===================================================================
--- trunk/sources/editor/elementscene.h	2014-06-20 20:00:11 UTC (rev 3156)
+++ trunk/sources/editor/elementscene.h	2014-06-20 20:10:09 UTC (rev 3157)
@@ -38,6 +38,7 @@
 	border due to its fixed size and its hotspot.
 */
 class ElementScene : public QGraphicsScene {
+	friend class ChangePropertiesCommand;
 	Q_OBJECT
 	
 	// enum

Modified: trunk/sources/editor/ui/elementpropertieseditorwidget.cpp
===================================================================
--- trunk/sources/editor/ui/elementpropertieseditorwidget.cpp	2014-06-20 20:00:11 UTC (rev 3156)
+++ trunk/sources/editor/ui/elementpropertieseditorwidget.cpp	2014-06-20 20:10:09 UTC (rev 3157)
@@ -45,12 +45,23 @@
 	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 @@
 	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 @@
 		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_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);
 }

Modified: trunk/sources/editor/ui/elementpropertieseditorwidget.ui
===================================================================
--- trunk/sources/editor/ui/elementpropertieseditorwidget.ui	2014-06-20 20:00:11 UTC (rev 3156)
+++ trunk/sources/editor/ui/elementpropertieseditorwidget.ui	2014-06-20 20:10:09 UTC (rev 3157)
@@ -79,6 +79,25 @@
     </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">
       <enum>Qt::Vertical</enum>


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/