[qet] [2869] element master widget property: improve gui.

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


Revision: 2869
Author:   blacksun
Date:     2014-02-22 18:24:20 +0100 (Sat, 22 Feb 2014)
Log Message:
-----------
element master widget property: improve gui.
add slave element class.
element class: replace diagramcontext informations by elementInformations because informations is already used in xml file for element.
minor improvement.

Modified Paths:
--------------
    trunk/sources/factory/elementfactory.cpp
    trunk/sources/qetgraphicsitem/element.cpp
    trunk/sources/qetgraphicsitem/element.h
    trunk/sources/qetgraphicsitem/masterelement.cpp
    trunk/sources/qetgraphicsitem/masterelement.h
    trunk/sources/ui/elementinfowidget.cpp
    trunk/sources/ui/elementpropertieswidget.cpp
    trunk/sources/ui/masterpropertieswidget.cpp
    trunk/sources/ui/masterpropertieswidget.h
    trunk/sources/ui/masterpropertieswidget.ui

Added Paths:
-----------
    trunk/sources/qetgraphicsitem/slaveelement.cpp
    trunk/sources/qetgraphicsitem/slaveelement.h

Modified: trunk/sources/factory/elementfactory.cpp
===================================================================
--- trunk/sources/factory/elementfactory.cpp	2014-02-22 12:04:05 UTC (rev 2868)
+++ trunk/sources/factory/elementfactory.cpp	2014-02-22 17:24:20 UTC (rev 2869)
@@ -23,6 +23,7 @@
 #include "qetgraphicsitem/simpleelement.h"
 #include "qetgraphicsitem/reportelement.h"
 #include "qetgraphicsitem/masterelement.h"
+#include "qetgraphicsitem/slaveelement.h"
 
 ElementFactory* ElementFactory::factory_ = 0;
 /**
@@ -48,6 +49,7 @@
 		QString link_type = element_definition->xml().attribute("link_type");
 		if (link_type == "next_report" || link_type == "previous_report") return (new ReportElement(location, link_type, qgi, s, state));
 		if (link_type == "master") return (new MasterElement(location, qgi, s, state));
+		if (link_type == "slave") return (new SlaveElement (location, qgi, s, state));
 	}
 	
 	//default if nothing match for link_type

Modified: trunk/sources/qetgraphicsitem/element.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/element.cpp	2014-02-22 12:04:05 UTC (rev 2868)
+++ trunk/sources/qetgraphicsitem/element.cpp	2014-02-22 17:24:20 UTC (rev 2869)
@@ -33,7 +33,7 @@
 	internal_connections_(false),
 	must_highlight_(false)
 {
-	link_type_ = 0;
+	link_type_ = Simple;
 	uuid_ = QUuid::createUuid();
 	setZValue(10);
 }
@@ -397,7 +397,9 @@
 	uuid_= QUuid(e.attribute("uuid", QUuid::createUuid().toString()));
 
 	//load informations
-	informations_.fromXml(e.firstChildElement("informations"), "information");
+	element_informations_.fromXml(e.firstChildElement("elementInformations"), "elementInformation");
+	//load kind informations
+	kind_informations_.fromXml(e.firstChildElement("kindInformations"), "kindInformation");
 
 	// position, selection
 	setPos(e.attribute("x").toDouble(), e.attribute("y").toDouble());
@@ -479,9 +481,19 @@
 	}
 
 	//save information of this element
-	QDomElement infos = document.createElement("informations");
-	informations_.toXml(infos, "information");
-	element.appendChild(infos);
+	if (! element_informations_.keys().isEmpty()) {
+		QDomElement infos = document.createElement("elementInformations");
+		element_informations_.toXml(infos, "elementInformation");
+		element.appendChild(infos);
+	}
+
+	//save kind_informations of this element
+	if (! kind_informations_.keys().isEmpty()) {
+		QDomElement kind_infos = document.createElement("kindInformations");
+		kind_informations_.toXml(kind_infos, "kindInformation");
+		element.appendChild(kind_infos);
+	}
+
 	
 	return(element);
 }

Modified: trunk/sources/qetgraphicsitem/element.h
===================================================================
--- trunk/sources/qetgraphicsitem/element.h	2014-02-22 12:04:05 UTC (rev 2868)
+++ trunk/sources/qetgraphicsitem/element.h	2014-02-22 17:24:20 UTC (rev 2869)
@@ -44,15 +44,13 @@
 	enum { Type = UserType + 1000 };
 	// this enum is use to know the kind of element and
 	// to use flag for element provider class
-	enum {Simple = 1,
+	enum kind {Simple = 1,
 		  NextReport = 2,
 		  PreviousReport = 4,
 		  AllReport = 6,
 		  Master = 8,
-		  SlaveNO = 16,
-		  SlaveNC = 32,
-		  AllSlave = 48,
-		  Bornier = 64};
+		  Slave = 16,
+		  Bornier = 32};
 	
 	private:
 	QSize   dimensions;
@@ -115,16 +113,19 @@
 	QList <Element *> connected_elements;
 	QList <QUuid> tmp_uuids_link;
 	QUuid uuid_;
-	int link_type_;
+	kind link_type_;
 
 		//METHODS related to information
 		public:
-	DiagramContext informations()const {return informations_;}
-	void setInformations(DiagramContext dc) {informations_ = dc;}
+	DiagramContext elementInformations()const {return element_informations_;}
+	void setElementInformations(DiagramContext dc) {element_informations_ = dc;}
+	DiagramContext kindInformations() const {return kind_informations_;}	//@kind_information_ is used to store more information
+																			//about the herited class like contactelement for know
+																			// kind of contact (simple tempo) or number of contact show by the element.
 
 		//ATTRIBUTES
 		protected:
-	DiagramContext informations_;
+	DiagramContext element_informations_, kind_informations_;
 
 	/**
 		Draw this element

Modified: trunk/sources/qetgraphicsitem/masterelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/masterelement.cpp	2014-02-22 12:04:05 UTC (rev 2868)
+++ trunk/sources/qetgraphicsitem/masterelement.cpp	2014-02-22 17:24:20 UTC (rev 2869)
@@ -1,3 +1,20 @@
+/*
+	Copyright 2006-2014 The QElectroTech Team
+	This file is part of QElectroTech.
+
+	QElectroTech is free software: you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation, either version 2 of the License, or
+	(at your option) any later version.
+
+	QElectroTech is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	GNU General Public License for more details.
+
+	You should have received a copy of the GNU General Public License
+	along with QElectroTech.  If not, see <http://www.gnu.org/licenses/>.
+*/
 #include "masterelement.h"
 
 /**
@@ -28,12 +45,9 @@
  * For this class element must be a slave
  * @param elmt
  */
-void MasterElement::linkToElement(Element *elmt) {
-	// check if this element is already linked
-	if (connected_elements.contains(elmt)) return;
-	
-	//check if elmt is a slave
-	if (elmt->linkType() == SlaveNO || elmt->linkType() == SlaveNC) {
+void MasterElement::linkToElement(Element *elmt) {	
+	// check if element is slave and if isn't already linked
+	if (elmt->linkType() == Slave && !connected_elements.contains(elmt)) {
 		///TODO create the cross ref and connection
 		connected_elements << elmt;
 		elmt->linkToElement(this);
@@ -49,7 +63,7 @@
 	if (!isFree()) {
 		foreach(Element *elmt, connected_elements) {
 			unlinkElement(elmt);
-		}	
+		}
 	}
 }
 

Modified: trunk/sources/qetgraphicsitem/masterelement.h
===================================================================
--- trunk/sources/qetgraphicsitem/masterelement.h	2014-02-22 12:04:05 UTC (rev 2868)
+++ trunk/sources/qetgraphicsitem/masterelement.h	2014-02-22 17:24:20 UTC (rev 2869)
@@ -1,3 +1,20 @@
+/*
+	Copyright 2006-2014 The QElectroTech Team
+	This file is part of QElectroTech.
+
+	QElectroTech is free software: you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation, either version 2 of the License, or
+	(at your option) any later version.
+
+	QElectroTech is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	GNU General Public License for more details.
+
+	You should have received a copy of the GNU General Public License
+	along with QElectroTech.  If not, see <http://www.gnu.org/licenses/>.
+*/
 #ifndef MASTERELEMENT_H
 #define MASTERELEMENT_H
 

Added: trunk/sources/qetgraphicsitem/slaveelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/slaveelement.cpp	                        (rev 0)
+++ trunk/sources/qetgraphicsitem/slaveelement.cpp	2014-02-22 17:24:20 UTC (rev 2869)
@@ -0,0 +1,81 @@
+/*
+	Copyright 2006-2014 The QElectroTech Team
+	This file is part of QElectroTech.
+
+	QElectroTech is free software: you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation, either version 2 of the License, or
+	(at your option) any later version.
+
+	QElectroTech is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	GNU General Public License for more details.
+
+	You should have received a copy of the GNU General Public License
+	along with QElectroTech.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#include "slaveelement.h"
+
+/**
+ * @brief SlaveElement::SlaveElement
+ * Default constructor
+ * @param location location of xml definition
+ * @param qgi parent QGraphicItem
+ * @param s parent diagram
+ * @param state int used to know if the creation of element have error
+ */
+SlaveElement::SlaveElement(const ElementsLocation &location, QGraphicsItem *qgi, Diagram *s, int *state) :
+	CustomElement(location, qgi, s, state)
+{
+	link_type_ = Slave;
+}
+
+/**
+ * @brief SlaveElement::~SlaveElement
+ * default destructor
+ */
+SlaveElement::~SlaveElement() {
+	unlinkAllElements();
+}
+
+/**
+ * @brief SlaveElement::linkToElement
+ * Link this slave to another element
+ * For this class element must be a master
+ * @param elmt
+ */
+void SlaveElement::linkToElement(Element *elmt) {
+	// check if element is master and if isn't already linked
+	if (elmt->linkType() == Master && !connected_elements.contains(elmt)) {
+		if(!isFree()) unlinkAllElements();
+		connected_elements << elmt;
+		elmt->linkToElement(this);
+	}
+}
+
+/**
+ * @brief SlaveElement::unlinkAllElements
+ * Unlink all of the element in the QList connected_elements
+ */
+void SlaveElement::unlinkAllElements() {
+	// if this element is free no need to do something
+	if (!isFree()) {
+		foreach(Element *elmt, connected_elements) {
+			unlinkElement(elmt);
+		}
+	}
+}
+
+/**
+ * @brief SlaveElement::unlinkElement
+ * Unlink the given elmt in parametre
+ * @param elmt
+ */
+void SlaveElement::unlinkElement(Element *elmt) {
+	//Ensure elmt is linked to this element
+	if (connected_elements.contains(elmt)) {
+		connected_elements.removeOne(elmt);
+		elmt->unlinkElement(this);
+	}
+}

Added: trunk/sources/qetgraphicsitem/slaveelement.h
===================================================================
--- trunk/sources/qetgraphicsitem/slaveelement.h	                        (rev 0)
+++ trunk/sources/qetgraphicsitem/slaveelement.h	2014-02-22 17:24:20 UTC (rev 2869)
@@ -0,0 +1,39 @@
+/*
+	Copyright 2006-2014 The QElectroTech Team
+	This file is part of QElectroTech.
+
+	QElectroTech is free software: you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation, either version 2 of the License, or
+	(at your option) any later version.
+
+	QElectroTech is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	GNU General Public License for more details.
+
+	You should have received a copy of the GNU General Public License
+	along with QElectroTech.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifndef SLAVEELEMENT_H
+#define SLAVEELEMENT_H
+
+#include "customelement.h"
+
+class SlaveElement : public CustomElement
+{
+	Q_OBJECT
+	public:
+	explicit SlaveElement (const ElementsLocation &, QGraphicsItem * = 0, Diagram * = 0, int * = 0);
+	~SlaveElement();
+	virtual void linkToElement(Element *elmt);
+	virtual void unlinkAllElements();
+	virtual void unlinkElement(Element *elmt);
+
+	signals:
+
+	public slots:
+
+};
+
+#endif // SLAVEELEMENT_H

Modified: trunk/sources/ui/elementinfowidget.cpp
===================================================================
--- trunk/sources/ui/elementinfowidget.cpp	2014-02-22 12:04:05 UTC (rev 2868)
+++ trunk/sources/ui/elementinfowidget.cpp	2014-02-22 17:24:20 UTC (rev 2869)
@@ -29,7 +29,7 @@
 	QWidget(parent),
 	ui(new Ui::ElementInfoWidget),
 	element_(elmt),
-	elmt_info(elmt->informations())
+	elmt_info(elmt->elementInformations())
 {
 	ui->setupUi(this);
 	buildInterface();
@@ -59,7 +59,7 @@
 						eipw->text(),
 						eipw->mustShow());
 	}
-	element_->setInformations(dc);
+	element_->setElementInformations(dc);
 }
 
 /**

Modified: trunk/sources/ui/elementpropertieswidget.cpp
===================================================================
--- trunk/sources/ui/elementpropertieswidget.cpp	2014-02-22 12:04:05 UTC (rev 2868)
+++ trunk/sources/ui/elementpropertieswidget.cpp	2014-02-22 17:24:20 UTC (rev 2869)
@@ -122,15 +122,13 @@
 			tab_ -> addTab(frp_, tr("Report de folio"));
 			break;
 		case Element::Master:
-			mpw_ = new MasterPropertiesWidget(this);
-			tab_ -> addTab(mpw_, tr("R\351f\351rence crois\351 (maitre)"));
+			mpw_ = new MasterPropertiesWidget(element_, this);
+			tab_ -> addTab(mpw_, tr("R\351f\351rence crois\351e (maitre)"));
 			eiw_ = new ElementInfoWidget(element_, this);
 			tab_ -> addTab(eiw_, tr("Information"));
 			break;
-		case Element::SlaveNC:
+		case Element::Slave:
 			break;
-		case Element::SlaveNO:
-			break;
 		case Element::Bornier:
 			break;
 		default:

Modified: trunk/sources/ui/masterpropertieswidget.cpp
===================================================================
--- trunk/sources/ui/masterpropertieswidget.cpp	2014-02-22 12:04:05 UTC (rev 2868)
+++ trunk/sources/ui/masterpropertieswidget.cpp	2014-02-22 17:24:20 UTC (rev 2869)
@@ -1,14 +1,70 @@
+/*
+	Copyright 2006-2014 The QElectroTech Team
+	This file is part of QElectroTech.
+
+	QElectroTech is free software: you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation, either version 2 of the License, or
+	(at your option) any later version.
+
+	QElectroTech is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	GNU General Public License for more details.
+
+	You should have received a copy of the GNU General Public License
+	along with QElectroTech.  If not, see <http://www.gnu.org/licenses/>.
+*/
 #include "masterpropertieswidget.h"
 #include "ui_masterpropertieswidget.h"
+#include <QListWidgetItem>
+#include <diagramposition.h>
+#include <elementprovider.h>
 
-MasterPropertiesWidget::MasterPropertiesWidget(QWidget *parent) :
+MasterPropertiesWidget::MasterPropertiesWidget(Element *elmt, QWidget *parent) :
 	QWidget(parent),
-	ui(new Ui::MasterPropertiesWidget)
+	ui(new Ui::MasterPropertiesWidget),
+	element_(elmt)
 {
 	ui->setupUi(this);
+	buildInterface();
 }
 
 MasterPropertiesWidget::~MasterPropertiesWidget()
 {
 	delete ui;
 }
+
+void MasterPropertiesWidget::buildInterface() {
+	ElementProvider elmt_prov(element_->diagram()->project());
+
+	foreach(Element *elmt, elmt_prov.freeElement(Element::Slave)) {
+		//label for list widget
+		QString widget_text;
+		QString title = elmt->diagram()->title();
+		if (title.isEmpty()) title = tr("Sans titre");
+		widget_text += QString(tr("Folio\240 %1 (%2), position %3.")).arg(elmt->diagram()->folioIndex() + 1)
+																	  .arg(title)
+																	  .arg(elmt->diagram() -> convertPosition(elmt -> scenePos()).toString());
+		QListWidgetItem *lwi_ = new QListWidgetItem(elmt->pixmap(), widget_text);
+		ui->free_list->addItem(lwi_);
+	}
+}
+
+/**
+ * @brief MasterPropertiesWidget::on_link_button_clicked
+ * move curent item in the free_list to linked_list
+ */
+void MasterPropertiesWidget::on_link_button_clicked() {
+	//take the curent item from free_list and push it to linked_list
+	ui->linked_list->addItem(
+				ui->free_list->takeItem(
+					ui->free_list->currentRow()));
+}
+
+void MasterPropertiesWidget::on_unlink_button_clicked() {
+	//take the curent item from linked_list and push it to free_list
+	ui->free_list->addItem(
+				ui->linked_list->takeItem(
+					ui->linked_list->currentRow()));
+}

Modified: trunk/sources/ui/masterpropertieswidget.h
===================================================================
--- trunk/sources/ui/masterpropertieswidget.h	2014-02-22 12:04:05 UTC (rev 2868)
+++ trunk/sources/ui/masterpropertieswidget.h	2014-02-22 17:24:20 UTC (rev 2869)
@@ -1,3 +1,20 @@
+/*
+	Copyright 2006-2014 The QElectroTech Team
+	This file is part of QElectroTech.
+
+	QElectroTech is free software: you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation, either version 2 of the License, or
+	(at your option) any later version.
+
+	QElectroTech is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	GNU General Public License for more details.
+
+	You should have received a copy of the GNU General Public License
+	along with QElectroTech.  If not, see <http://www.gnu.org/licenses/>.
+*/
 #ifndef MASTERPROPERTIESWIDGET_H
 #define MASTERPROPERTIESWIDGET_H
 
@@ -2,2 +19,3 @@
 #include <QWidget>
+#include <qetgraphicsitem/element.h>
 
@@ -12,11 +30,19 @@
 	Q_OBJECT
 
 	public:
-	explicit MasterPropertiesWidget(QWidget *parent = 0);
+	explicit MasterPropertiesWidget(Element *elmt, QWidget *parent = 0);
 	~MasterPropertiesWidget();
 
 	private:
+	void buildInterface();
+
+	private slots:
+	void on_link_button_clicked();
+	void on_unlink_button_clicked();
+
+	private:
 	Ui::MasterPropertiesWidget *ui;
+	Element *element_;
 };
 
 #endif // MASTERPROPERTIESWIDGET_H

Modified: trunk/sources/ui/masterpropertieswidget.ui
===================================================================
--- trunk/sources/ui/masterpropertieswidget.ui	2014-02-22 12:04:05 UTC (rev 2868)
+++ trunk/sources/ui/masterpropertieswidget.ui	2014-02-22 17:24:20 UTC (rev 2869)
@@ -1,21 +1,103 @@
+<?xml version="1.0" encoding="UTF-8"?>
 <ui version="4.0">
- <author/>
- <comment/>
- <exportmacro/>
  <class>MasterPropertiesWidget</class>
  <widget class="QWidget" name="MasterPropertiesWidget">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>400</width>
-    <height>300</height>
+    <width>564</width>
+    <height>318</height>
    </rect>
   </property>
   <property name="windowTitle">
    <string>Form</string>
   </property>
+  <layout class="QGridLayout" name="gridLayout_2">
+   <item row="1" column="1" rowspan="5">
+    <widget class="QListWidget" name="free_list"/>
+   </item>
+   <item row="5" column="2">
+    <spacer name="verticalSpacer_2">
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>20</width>
+       <height>40</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+   <item row="4" column="2">
+    <widget class="QPushButton" name="unlink_button">
+     <property name="toolTip">
+      <string>Délier l'élément séléctionné</string>
+     </property>
+     <property name="text">
+      <string/>
+     </property>
+     <property name="icon">
+      <iconset resource="../../qelectrotech.qrc">
+       <normaloff>:/ico/16x16/arrow-left.png</normaloff>:/ico/16x16/arrow-left.png</iconset>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="3" rowspan="5">
+    <widget class="QListWidget" name="linked_list"/>
+   </item>
+   <item row="3" column="2">
+    <widget class="QPushButton" name="link_button">
+     <property name="toolTip">
+      <string>Lier l'élément séléctionné</string>
+     </property>
+     <property name="text">
+      <string/>
+     </property>
+     <property name="icon">
+      <iconset resource="../../qelectrotech.qrc">
+       <normaloff>:/ico/16x16/arrow-right.png</normaloff>:/ico/16x16/arrow-right.png</iconset>
+     </property>
+    </widget>
+   </item>
+   <item row="0" column="1">
+    <widget class="QLabel" name="label">
+     <property name="text">
+      <string>Éléments disponibles</string>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignCenter</set>
+     </property>
+    </widget>
+   </item>
+   <item row="0" column="3">
+    <widget class="QLabel" name="label_2">
+     <property name="text">
+      <string>Éléments liés</string>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignCenter</set>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="2">
+    <spacer name="verticalSpacer">
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>20</width>
+       <height>40</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+  </layout>
  </widget>
- <pixmapfunction/>
+ <resources>
+  <include location="../../qelectrotech.qrc"/>
+ </resources>
  <connections/>
 </ui>


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