[qet] [3102] element editor: add dialog for edit element properties (master, slave etc...)

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


Revision: 3102
Author:   blacksun
Date:     2014-06-03 22:21:19 +0200 (Tue, 03 Jun 2014)
Log Message:
-----------
element editor: add dialog for edit element properties (master, slave etc...)

Modified Paths:
--------------
    trunk/qelectrotech.pro
    trunk/sources/editor/elementscene.cpp
    trunk/sources/editor/elementscene.h
    trunk/sources/editor/qetelementeditor.cpp
    trunk/sources/editor/qetelementeditor.h
    trunk/sources/qetgraphicsitem/reportelement.cpp

Added Paths:
-----------
    trunk/sources/editor/ui/
    trunk/sources/editor/ui/elementpropertieseditorwidget.cpp
    trunk/sources/editor/ui/elementpropertieseditorwidget.h
    trunk/sources/editor/ui/elementpropertieseditorwidget.ui

Modified: trunk/qelectrotech.pro
===================================================================
--- trunk/qelectrotech.pro	2014-06-02 23:40:14 UTC (rev 3101)
+++ trunk/qelectrotech.pro	2014-06-03 20:21:19 UTC (rev 3102)
@@ -65,12 +65,12 @@
 
 # Fichiers sources
 HEADERS += sources/*.h   sources/ui/*.h   sources/editor/*.h   sources/titleblock/*.h  sources/richtext/*.h sources/qetgraphicsitem/*.h sources/factory/*.cpp \
-    sources/properties/propertiesinterface.h \
-    sources/properties/xrefproperties.h
+           sources/properties/*.h \
+           sources/editor/ui/*.h
 
 SOURCES += sources/*.cpp sources/editor/*.cpp sources/titleblock/*.cpp sources/richtext/*.cpp sources/ui/*.cpp sources/qetgraphicsitem/*.cpp sources/factory/*.cpp \
-    sources/properties/propertiesinterface.cpp \
-    sources/properties/xrefproperties.cpp
+           sources/properties/*.cpp \
+           sources/editor/ui/*.cpp
 
 # Liste des fichiers qui seront incorpores au binaire en tant que ressources Qt
 RESOURCES += qelectrotech.qrc
@@ -85,9 +85,10 @@
 QT += xml svg network sql
 
 # UI DESIGNER FILES AND GENERATION SOURCES FILES
-FORMS += sources/richtext/addlinkdialog.ui  sources/ui/*.ui \
-    sources/ui/linksingleelementwidget.ui \
-    sources/ui/xrefpropertieswidget.ui
+FORMS += sources/richtext/*.ui \
+         sources/ui/*.ui \
+         sources/editor/ui/*.ui
+
 UI_SOURCES_DIR = sources/ui/
 UI_HEADERS_DIR = sources/ui/
 

Modified: trunk/sources/editor/elementscene.cpp
===================================================================
--- trunk/sources/editor/elementscene.cpp	2014-06-02 23:40:14 UTC (rev 3101)
+++ trunk/sources/editor/elementscene.cpp	2014-06-03 20:21:19 UTC (rev 3102)
@@ -30,6 +30,7 @@
 #include "editorcommands.h"
 #include "elementcontent.h"
 #include "nameslist.h"
+#include "ui/elementpropertieseditorwidget.h"
 
 /**
 	Constructeur
@@ -40,7 +41,8 @@
 	QGraphicsScene(parent),
 	qgi_manager(this),
 	element_editor(editor),
-	decorator_(0)
+	decorator_(0),
+	m_elmt_type("simple")
 {
 	setItemIndexMethod(NoIndex);
 	current_polygon = NULL;
@@ -417,9 +419,16 @@
 	root.setAttribute("orientation", "dyyy"); //we keep the orientation for compatibility with previous version of qet
 	root.setAttribute("version", QET::version);
 	root.setAttribute("ic", "true"); //we keep the internal connection for compatibility with previous version of qet
+	root.setAttribute("link_type", m_elmt_type);
 	
 	// noms de l'element
 	root.appendChild(_names.toXml(xml_document));
+
+	if (m_elmt_type == "slave") {
+		QDomElement kindInfo = xml_document.createElement("kindInformations");
+		m_elmt_kindInfo.toXml(kindInfo, "kindInformation");
+		root.appendChild(kindInfo);
+	}
 	
 	// informations complementaires de l'element
 	QDomElement informations_element = xml_document.createElement("informations");
@@ -709,6 +718,15 @@
 }
 
 /**
+ * @brief ElementScene::slot_editProperties
+ * Open dialog to edit the element properties
+ */
+void  ElementScene::slot_editProperties() {
+	ElementPropertiesEditorWidget epew(m_elmt_type, m_elmt_kindInfo);
+	epew.exec();
+}
+
+/**
 	Lance un dialogue pour editer les noms de cet element
 */
 void ElementScene::slot_editNames() {
@@ -918,7 +936,7 @@
 	passee, false sinon.
 */
 bool ElementScene::applyInformations(const QDomDocument &xml_document, QString *error_message) {
-	// la racine est supposee etre une definition d'element
+	// Root must be an element definition
 	QDomElement root = xml_document.documentElement();
 	if (root.tagName() != "definition" || root.attribute("type") != "element") {
 		if (error_message) {
@@ -927,10 +945,14 @@
 		return(false);
 	}
 
-	// extrait les noms de la definition XML
+	//Extract info about element type
+	m_elmt_type = root.attribute("link_type", "simple");
+	m_elmt_kindInfo.fromXml(root.firstChildElement("kindInformations"), "kindInformation");
+
+	//Extract names of xml definition
 	_names.fromXml(root);
 	
-	// extrait les informations complementaires
+	//extract additional informations
 	setInformations(QString());
 	for (QDomNode node = root.firstChild() ; !node.isNull() ; node = node.nextSibling()) {
 		QDomElement elmt = node.toElement();

Modified: trunk/sources/editor/elementscene.h
===================================================================
--- trunk/sources/editor/elementscene.h	2014-06-02 23:40:14 UTC (rev 3101)
+++ trunk/sources/editor/elementscene.h	2014-06-03 20:21:19 UTC (rev 3102)
@@ -22,6 +22,7 @@
 #include "nameslistwidget.h"
 #include "qgimanager.h"
 #include "elementcontent.h"
+#include "diagramcontext.h"
 class CustomElementPart;
 class ElementEditionCommand;
 class ElementPrimitiveDecorator;
@@ -66,6 +67,10 @@
 	NamesList _names;
 	/// Extra informations
 	QString informations_;
+	/// element type
+	QString m_elmt_type;
+	/// element kind info
+	DiagramContext m_elmt_kindInfo;
 	/// QGraphicsItem manager
 	QGIManager qgi_manager;
 	/// Undo stack
@@ -111,6 +116,8 @@
 	void setInternalConnections(bool);
 	QString informations() const;
 	void setInformations(const QString &);
+	QString elementType () const {return m_elmt_type;}
+	DiagramContext elementKindInfo () const {return m_elmt_kindInfo;}
 	virtual int xGrid() const;
 	virtual int yGrid() const;
 	virtual void setGrid(int, int);
@@ -172,6 +179,7 @@
 	void slot_delete();
 	void slot_editNames();
 	void slot_editAuthorInformations();
+	void slot_editProperties();
 	void slot_bringForward();
 	void slot_raise();
 	void slot_lower();

Modified: trunk/sources/editor/qetelementeditor.cpp
===================================================================
--- trunk/sources/editor/qetelementeditor.cpp	2014-06-02 23:40:14 UTC (rev 3101)
+++ trunk/sources/editor/qetelementeditor.cpp	2014-06-03 20:21:19 UTC (rev 3102)
@@ -122,43 +122,44 @@
 	Met en place les actions
 */
 void QETElementEditor::setupActions() {
-	new_element     = new QAction(QET::Icons::DocumentNew,          tr("&Nouveau"),                                  this);
-	open            = new QAction(QET::Icons::DocumentOpen,         tr("&Ouvrir"),                                   this);
-	open_file       = new QAction(QET::Icons::DocumentOpen,         tr("&Ouvrir depuis un fichier"),                 this);
-	save            = new QAction(QET::Icons::DocumentSave,         tr("&Enregistrer"),                              this);
-	save_as         = new QAction(QET::Icons::DocumentSaveAs,       tr("Enregistrer sous"),                          this);
-	save_as_file    = new QAction(QET::Icons::DocumentSaveAs,       tr("Enregistrer dans un fichier"),               this);
-	reload          = new QAction(QET::Icons::ViewRefresh,          tr("Recharger"),                                 this);
-	quit            = new QAction(QET::Icons::ApplicationExit,      tr("&Quitter"),                                  this);
-	selectall       = new QAction(QET::Icons::EditSelectAll,        tr("Tout s\351lectionner"),                      this);
-	deselectall     = new QAction(                                  tr("D\351s\351lectionner tout"),                 this);
-	cut             = new QAction(QET::Icons::EditCut,              tr("Co&uper"),                                   this);
-	copy            = new QAction(QET::Icons::EditCopy,             tr("Cop&ier"),                                   this);
-	paste           = new QAction(QET::Icons::EditPaste,            tr("C&oller"),                                   this);
-	paste_in_area   = new QAction(QET::Icons::EditPaste,            tr("C&oller dans la zone..."),                   this);
-	paste_from_file = new QAction(QET::Icons::XmlTextFile,          tr("un fichier"),                                this);
-	paste_from_elmt = new QAction(QET::Icons::Element,              tr("un \351l\351ment"),                          this);
-	inv_select      = new QAction(                                  tr("Inverser la s\351lection"),                  this);
-	edit_delete     = new QAction(QET::Icons::EditDelete,           tr("&Supprimer"),                                this);
-	zoom_in         = new QAction(QET::Icons::ZoomIn,               tr("Zoom avant"),                                this);
-	zoom_out        = new QAction(QET::Icons::ZoomOut,              tr("Zoom arri\350re"),                           this);
-	zoom_fit        = new QAction(QET::Icons::ZoomFitBest,          tr("Zoom adapt\351"),                            this);
-	zoom_reset      = new QAction(QET::Icons::ZoomOriginal,         tr("Pas de zoom"),                               this);
-	edit_names      = new QAction(QET::Icons::Names,                tr("\311diter les noms"),                        this);
-	edit_author     = new QAction(QET::Icons::UserInformations,     tr("\311diter les informations sur l'auteur"),   this);
-	edit_raise      = new QAction(QET::Icons::Raise,                tr("Rapprocher"),                                this);
-	edit_lower      = new QAction(QET::Icons::Lower,                tr("\311loigner"),                               this);
-	edit_backward   = new QAction(QET::Icons::SendBackward,         tr("Envoyer au fond"),                           this);
-	edit_forward    = new QAction(QET::Icons::BringForward,         tr("Amener au premier plan"),                    this);
-	move            = new QAction(QET::Icons::PartSelect,           tr("D\351placer un objet"),                      this);
-	add_line        = new QAction(QET::Icons::PartLine,             tr("Ajouter une ligne"),                         this);
-	add_rectangle   = new QAction(QET::Icons::PartRectangle,        tr("Ajouter un rectangle"),                      this);
-	add_ellipse     = new QAction(QET::Icons::PartEllipse,          tr("Ajouter une ellipse"),                       this);
-	add_polygon     = new QAction(QET::Icons::PartPolygon,          tr("Ajouter un polygone"),                       this);
-	add_text        = new QAction(QET::Icons::PartText,             tr("Ajouter du texte"),                          this);
-	add_arc         = new QAction(QET::Icons::PartArc,              tr("Ajouter un arc de cercle"),                  this);
-	add_terminal    = new QAction(QET::Icons::Terminal,             tr("Ajouter une borne"),                         this);
-	add_textfield   = new QAction(QET::Icons::PartTextField,        tr("Ajouter un champ de texte"),                 this);
+	new_element       = new QAction(QET::Icons::DocumentNew,          tr("&Nouveau"),                                  this);
+	open              = new QAction(QET::Icons::DocumentOpen,         tr("&Ouvrir"),                                   this);
+	open_file         = new QAction(QET::Icons::DocumentOpen,         tr("&Ouvrir depuis un fichier"),                 this);
+	save              = new QAction(QET::Icons::DocumentSave,         tr("&Enregistrer"),                              this);
+	save_as           = new QAction(QET::Icons::DocumentSaveAs,       tr("Enregistrer sous"),                          this);
+	save_as_file      = new QAction(QET::Icons::DocumentSaveAs,       tr("Enregistrer dans un fichier"),               this);
+	reload            = new QAction(QET::Icons::ViewRefresh,          tr("Recharger"),                                 this);
+	quit              = new QAction(QET::Icons::ApplicationExit,      tr("&Quitter"),                                  this);
+	selectall         = new QAction(QET::Icons::EditSelectAll,        tr("Tout s\351lectionner"),                      this);
+	deselectall       = new QAction(                                  tr("D\351s\351lectionner tout"),                 this);
+	cut               = new QAction(QET::Icons::EditCut,              tr("Co&uper"),                                   this);
+	copy              = new QAction(QET::Icons::EditCopy,             tr("Cop&ier"),                                   this);
+	paste             = new QAction(QET::Icons::EditPaste,            tr("C&oller"),                                   this);
+	paste_in_area     = new QAction(QET::Icons::EditPaste,            tr("C&oller dans la zone..."),                   this);
+	paste_from_file   = new QAction(QET::Icons::XmlTextFile,          tr("un fichier"),                                this);
+	paste_from_elmt   = new QAction(QET::Icons::Element,              tr("un \351l\351ment"),                          this);
+	inv_select        = new QAction(                                  tr("Inverser la s\351lection"),                  this);
+	edit_delete       = new QAction(QET::Icons::EditDelete,           tr("&Supprimer"),                                this);
+	zoom_in           = new QAction(QET::Icons::ZoomIn,               tr("Zoom avant"),                                this);
+	zoom_out          = new QAction(QET::Icons::ZoomOut,              tr("Zoom arri\350re"),                           this);
+	zoom_fit          = new QAction(QET::Icons::ZoomFitBest,          tr("Zoom adapt\351"),                            this);
+	zoom_reset        = new QAction(QET::Icons::ZoomOriginal,         tr("Pas de zoom"),                               this);
+	edit_names        = new QAction(QET::Icons::Names,                tr("\311diter les noms"),                        this);
+	edit_author		  = new QAction(QET::Icons::UserInformations,     tr("\311diter les informations sur l'auteur"),   this);
+	m_edit_properties = new QAction(QET::Icons::ElementEdit,		  tr("\311diter les propri\351t\351es de l'\351l\351ment)"), this);
+	edit_raise        = new QAction(QET::Icons::Raise,                tr("Rapprocher"),                                this);
+	edit_lower        = new QAction(QET::Icons::Lower,                tr("\311loigner"),                               this);
+	edit_backward     = new QAction(QET::Icons::SendBackward,         tr("Envoyer au fond"),                           this);
+	edit_forward      = new QAction(QET::Icons::BringForward,         tr("Amener au premier plan"),                    this);
+	move              = new QAction(QET::Icons::PartSelect,           tr("D\351placer un objet"),                      this);
+	add_line          = new QAction(QET::Icons::PartLine,             tr("Ajouter une ligne"),                         this);
+	add_rectangle     = new QAction(QET::Icons::PartRectangle,        tr("Ajouter un rectangle"),                      this);
+	add_ellipse       = new QAction(QET::Icons::PartEllipse,          tr("Ajouter une ellipse"),                       this);
+	add_polygon       = new QAction(QET::Icons::PartPolygon,          tr("Ajouter un polygone"),                       this);
+	add_text          = new QAction(QET::Icons::PartText,             tr("Ajouter du texte"),                          this);
+	add_arc           = new QAction(QET::Icons::PartArc,              tr("Ajouter un arc de cercle"),                  this);
+	add_terminal      = new QAction(QET::Icons::Terminal,             tr("Ajouter une borne"),                         this);
+	add_textfield     = new QAction(QET::Icons::PartTextField,        tr("Ajouter un champ de texte"),                 this);
 	
 	QString add_status_tip = tr("Maintenez la touche Shift enfonc\351e pour effectuer plusieurs ajouts d'affil\351e");
 	add_line      -> setStatusTip(add_status_tip);
@@ -234,6 +235,7 @@
 	connect(edit_delete,     SIGNAL(triggered()), ce_scene, SLOT(slot_delete()));
 	connect(edit_names,      SIGNAL(triggered()), ce_scene, SLOT(slot_editNames()));
 	connect(edit_author,     SIGNAL(triggered()), ce_scene, SLOT(slot_editAuthorInformations()));
+	connect(m_edit_properties, SIGNAL(triggered()), ce_scene, SLOT(slot_editProperties()));
 	connect(edit_forward,    SIGNAL(triggered()), ce_scene, SLOT(slot_bringForward()));
 	connect(edit_raise,      SIGNAL(triggered()), ce_scene, SLOT(slot_raise()));
 	connect(edit_lower,      SIGNAL(triggered()), ce_scene, SLOT(slot_lower()));
@@ -312,9 +314,13 @@
 	main_toolbar -> addAction(redo);
 	main_toolbar -> addSeparator();
 	main_toolbar -> addAction(edit_delete);
+
 	view_toolbar -> addAction(zoom_fit);
 	view_toolbar -> addAction(zoom_reset);
+
 	element_toolbar -> addAction(edit_names);
+	element_toolbar -> addAction(m_edit_properties);
+
 	depth_toolbar -> addAction(edit_forward);
 	depth_toolbar -> addAction(edit_raise);
 	depth_toolbar -> addAction(edit_lower);
@@ -390,6 +396,7 @@
 	edit_menu -> addSeparator();
 	edit_menu -> addAction(edit_names);
 	edit_menu -> addAction(edit_author);
+	edit_menu -> addAction(m_edit_properties);
 	edit_menu -> addSeparator();
 	edit_menu -> addAction(edit_forward);
 	edit_menu -> addAction(edit_raise);
@@ -637,15 +644,17 @@
 }
 
 /**
-	Effectue diverses verifications sur l'element et en informe l'utilisateur.
-	@return true si la situation est ok, false sinon
-*/
+ * @brief QETElementEditor::checkElement
+ * Do several check about element.
+ * If error is occured return false
+ */
 bool QETElementEditor::checkElement() {
 	// liste les avertissements applicables
 	typedef QPair<QString, QString> QETWarning;
 	QList<QETWarning> warnings;
+	QList<QETWarning> errors;
 		
-	/// Avertissement #2 : si l'element ne comporte aucune borne
+	/// Warning #1: Element haven't got terminal
 	if (!ce_scene -> containsTerminals()) {
 		warnings << qMakePair(
 			tr("Absence de borne", "warning title"),
@@ -658,18 +667,33 @@
 			)
 		);
 	}
+
+	///Error #1: element is slave or master but havent got input tagged 'label'
+	if(ce_scene -> elementType() == "master" || ce_scene -> elementType() == "slave") {
+		bool wrng = true;
+		foreach (CustomElementPart *cep, ce_scene->primitives()) {
+			if (cep->property("tagg").toString() == "label") wrng = false;
+		}
+		if (wrng) {
+			errors << qMakePair(
+							tr("Absence de champ texte 'label'", "warning title"),
+							tr("Les \351l\351ments ma\356tres ou esclaves doivent poss\351der "
+							   "un champ texte comportant le tagg 'label'", "warning description"));
+		}
+	}
 	
-	if (!warnings.count()) return(true);
+	if (!errors.count() && !warnings.count()) return(true);
+	QList<QETWarning> total = warnings << errors;
 	
-	// affiche les avertissements
+	// Display warnings
 	QString warning_message = tr(
 		"La v\351rification de cet \351l\351ment a g\351n\351r\351 %n avertissement(s)\240:",
 		"message box content",
-		warnings.count()
+		total.count()
 	);
 	
 	warning_message += "<ol>";
-	foreach(QETWarning warning, warnings) {
+	foreach(QETWarning warning, total) {
 		warning_message += "<li>";
 		warning_message += QString(
 			tr("<b>%1</b>\240: %2", "warning title: warning description")
@@ -677,15 +701,12 @@
 		warning_message += "</li>";
 	}
 	warning_message += "</ol>";
-	
-	QMessageBox warnings_message_box(this);
-	warnings_message_box.setWindowModality(Qt::WindowModal);
-	warnings_message_box.setWindowFlags(warnings_message_box.windowFlags() | Qt::Sheet);
-	warnings_message_box.setTextFormat(Qt::RichText);
-	warnings_message_box.setWindowTitle(tr("Avertissements", "messagebox title"));
-	warnings_message_box.setText(warning_message);
-	warnings_message_box.exec();
-	return(false);
+
+	QMessageBox::warning(this, tr("Avertissements"), warning_message);
+
+	//if error == 0 that means they are only warning, we return true.
+	if (errors.count() == 0) return(true);
+	return false;
 }
 
 /**
@@ -976,71 +997,84 @@
 	@see slot_saveAs()
 */
 bool QETElementEditor::slot_save() {
-	// verification avant d'enregistrer le fichier
-	checkElement();
-	// si on ne connait pas le nom du fichier en cours, enregistrer revient a enregistrer sous
-	if (opened_from_file) {
-		if (filename_.isEmpty()) return(slot_saveAsFile());
-		// sinon on enregistre dans le nom de fichier connu
-		bool result_save = toFile(filename_);
-		if (result_save) ce_scene -> undoStack().setClean();
-		return(result_save);
-	} else {
-		if (location_.isNull()) return(slot_saveAs());
-		// sinon on enregistre a l'emplacement connu
-		bool result_save = toLocation(location_);
-		if (result_save) ce_scene -> undoStack().setClean();
-		return(result_save);
+	// Check element befor writing
+	if (checkElement()) {
+		// si on ne connait pas le nom du fichier en cours, enregistrer revient a enregistrer sous
+		if (opened_from_file) {
+			if (filename_.isEmpty()) return(slot_saveAsFile());
+			// sinon on enregistre dans le nom de fichier connu
+			bool result_save = toFile(filename_);
+			if (result_save) ce_scene -> undoStack().setClean();
+			return(result_save);
+		} else {
+			if (location_.isNull()) return(slot_saveAs());
+			// sinon on enregistre a l'emplacement connu
+			bool result_save = toLocation(location_);
+			if (result_save) ce_scene -> undoStack().setClean();
+			return(result_save);
+		}
 	}
+	QMessageBox::critical(this, tr("Echec de l'enregistrement"), tr("L'enregistrement \340 \351chou\351,\nles conditions requises ne sont pas valides"));
+	return false;
 }
 
 /**
 	Demande une localisation a l'utilisateur et enregistre l'element
 */
 bool QETElementEditor::slot_saveAs() {
-	// demande une localisation a l'utilisateur
-	ElementsLocation location = ElementDialog::getSaveElementLocation(this);
-	if (location.isNull()) return(false);
+	// Check element befor writing
+	if (checkElement()) {
+		// demande une localisation a l'utilisateur
+		ElementsLocation location = ElementDialog::getSaveElementLocation(this);
+		if (location.isNull()) return(false);
 	
-	// tente l'enregistrement
-	bool result_save = toLocation(location);
-	if (result_save) {
-		setLocation(location);
-		ce_scene -> undoStack().setClean();
+		// tente l'enregistrement
+		bool result_save = toLocation(location);
+		if (result_save) {
+			setLocation(location);
+			ce_scene -> undoStack().setClean();
+		}
+	
+		// retourne un booleen representatif de la reussite de l'enregistrement
+		return(result_save);
 	}
-	
-	// retourne un booleen representatif de la reussite de l'enregistrement
-	return(result_save);
+	QMessageBox::critical(this, tr("Echec de l'enregistrement"), tr("L'enregistrement \340 \351chou\351,\nles conditions requises ne sont pas valides"));
+	return (false);
 }
 
 /**
 	Demande un nom de fichier a l'utilisateur et enregistre l'element
 */
 bool QETElementEditor::slot_saveAsFile() {
-	// demande un nom de fichier a l'utilisateur pour enregistrer l'element
-	QString fn = QFileDialog::getSaveFileName(
-		this,
-		tr("Enregistrer sous", "dialog title"),
-		filename_.isEmpty() ? QETApp::customElementsDir() : QDir(filename_).absolutePath(),
-		tr(
-			"\311l\351ments QElectroTech (*.elmt)",
-			"filetypes allowed when saving an element file"
-		)
-	);
-	// si aucun nom n'est entre, renvoie faux.
-	if (fn.isEmpty()) return(false);
-	// si le nom ne se termine pas par l'extension .elmt, celle-ci est ajoutee
-	if (!fn.endsWith(".elmt", Qt::CaseInsensitive)) fn += ".elmt";
-	// tente d'enregistrer le fichier
-	bool result_save = toFile(fn);
-	// si l'enregistrement reussit, le nom du fichier est conserve
-	if (result_save) {
-		setFileName(fn);
-		QETApp::elementsRecentFiles() -> fileWasOpened(fn);
-		ce_scene -> undoStack().setClean();
+	// Check element befor writing
+	if (checkElement()) {
+		// demande un nom de fichier a l'utilisateur pour enregistrer l'element
+		QString fn = QFileDialog::getSaveFileName(
+			this,
+			tr("Enregistrer sous", "dialog title"),
+			filename_.isEmpty() ? QETApp::customElementsDir() : QDir(filename_).absolutePath(),
+			tr(
+				"\311l\351ments QElectroTech (*.elmt)",
+				"filetypes allowed when saving an element file"
+			)
+		);
+		// si aucun nom n'est entre, renvoie faux.
+		if (fn.isEmpty()) return(false);
+		// si le nom ne se termine pas par l'extension .elmt, celle-ci est ajoutee
+		if (!fn.endsWith(".elmt", Qt::CaseInsensitive)) fn += ".elmt";
+		// tente d'enregistrer le fichier
+		bool result_save = toFile(fn);
+		// si l'enregistrement reussit, le nom du fichier est conserve
+		if (result_save) {
+			setFileName(fn);
+			QETApp::elementsRecentFiles() -> fileWasOpened(fn);
+			ce_scene -> undoStack().setClean();
+		}
+		// retourne un booleen representatif de la reussite de l'enregistrement
+		return(result_save);
 	}
-	// retourne un booleen representatif de la reussite de l'enregistrement
-	return(result_save);
+	QMessageBox::critical(this, tr("Echec de l'enregistrement"), tr("L'enregistrement \340 \351chou\351,\nles conditions requises ne sont pas valides"));
+	return false;
 }
 
 /**

Modified: trunk/sources/editor/qetelementeditor.h
===================================================================
--- trunk/sources/editor/qetelementeditor.h	2014-06-02 23:40:14 UTC (rev 3101)
+++ trunk/sources/editor/qetelementeditor.h	2014-06-03 20:21:19 UTC (rev 3102)
@@ -71,7 +71,7 @@
 	QAction *selectall, *deselectall, *inv_select;
 	QAction *cut, *copy, *paste, *paste_in_area, *paste_from_file, *paste_from_elmt;
 	QAction *undo, *redo;
-	QAction *edit_delete, *edit_size_hs, *edit_names, *edit_author;
+	QAction *edit_delete, *edit_size_hs, *edit_names, *edit_author, *m_edit_properties;
 	QAction *edit_raise, *edit_lower, *edit_backward, *edit_forward;
 	/// actions for the "display" menu
 	QAction *zoom_in, *zoom_out, *zoom_fit, *zoom_reset;

Added: trunk/sources/editor/ui/elementpropertieseditorwidget.cpp
===================================================================
--- trunk/sources/editor/ui/elementpropertieseditorwidget.cpp	                        (rev 0)
+++ trunk/sources/editor/ui/elementpropertieseditorwidget.cpp	2014-06-03 20:21:19 UTC (rev 3102)
@@ -0,0 +1,104 @@
+/*
+	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 "elementpropertieseditorwidget.h"
+#include "ui_elementpropertieseditorwidget.h"
+
+/**
+ * @brief ElementPropertiesEditorWidget::ElementPropertiesEditorWidget
+ * Default constructor
+ * @param basic_type : QString of the drawed element
+ * @param dc : DiagramContext to store kindInfo of drawed element
+ * @param parent : parent widget
+ */
+ElementPropertiesEditorWidget::ElementPropertiesEditorWidget(QString &basic_type, DiagramContext &dc, QWidget *parent) :
+	QDialog(parent),
+	ui(new Ui::ElementPropertiesEditorWidget),
+	m_basic_type(basic_type),
+	m_dc (dc)
+{
+	ui->setupUi(this);
+	setUpInterface();
+	upDateInterface();
+}
+
+/**
+ * @brief ElementPropertiesEditorWidget::~ElementPropertiesEditorWidget
+ * Default destructor
+ */
+ElementPropertiesEditorWidget::~ElementPropertiesEditorWidget()
+{
+	delete ui;
+}
+
+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());
+
+	on_m_base_type_cb_currentIndexChanged(ui->m_base_type_cb->currentIndex());
+}
+
+/**
+ * @brief ElementPropertiesEditorWidget::setUpInterface
+ */
+void ElementPropertiesEditorWidget::setUpInterface() {
+	// Type combo box
+	ui -> m_base_type_cb -> addItem (tr("Simple"),							QVariant("simple"));
+	ui -> m_base_type_cb -> addItem (tr("Ma\356tre"),						QVariant("master"));
+	ui -> m_base_type_cb -> addItem (tr("Esclave"),							QVariant("slave"));
+	ui -> m_base_type_cb -> addItem (tr("Renvoi de folio suivant"),			QVariant("next_report"));
+	ui -> m_base_type_cb -> addItem (tr("Renvoi de folio pr\351c\351dent"), QVariant("previous_report"));
+
+	// Slave option
+	ui -> m_state_cb -> addItem(tr("Normalement ouvert"),   QVariant("NO"));
+	ui -> m_state_cb -> addItem(tr("Normalement ferm\351"), QVariant("NC"));
+	ui -> m_type_cb  -> addItem(tr("Simple"),				QVariant("simple"));
+	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"));
+}
+
+/**
+ * @brief ElementPropertiesEditorWidget::on_m_buttonBox_accepted
+ * Action on button accepted : the new information is set
+ */
+void ElementPropertiesEditorWidget::on_m_buttonBox_accepted()
+{
+	m_basic_type = ui -> m_base_type_cb -> itemData(ui -> m_base_type_cb -> currentIndex()).toString();
+	if (m_basic_type == "slave") {
+		m_dc.addValue("state",  ui -> m_state_cb -> itemData(ui -> m_state_cb -> currentIndex()));
+		m_dc.addValue("type",	ui -> m_type_cb  -> itemData(ui -> m_type_cb  -> currentIndex()));
+		m_dc.addValue("number", QVariant(ui -> m_number_ctc -> value()));
+	}
+	this->close();
+}
+
+/**
+ * @brief ElementPropertiesEditorWidget::on_m_base_type_cb_currentIndexChanged
+ * @param index : Action when combo-box base type index change
+ */
+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);
+	}
+
+}

Added: trunk/sources/editor/ui/elementpropertieseditorwidget.h
===================================================================
--- trunk/sources/editor/ui/elementpropertieseditorwidget.h	                        (rev 0)
+++ trunk/sources/editor/ui/elementpropertieseditorwidget.h	2014-06-03 20:21:19 UTC (rev 3102)
@@ -0,0 +1,60 @@
+/*
+	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 ELEMENTPROPERTIESEDITORWIDGET_H
+#define ELEMENTPROPERTIESEDITORWIDGET_H
+
+#include <QDialog>
+#include <QAbstractButton>
+#include "diagramcontext.h"
+
+namespace Ui {
+	class ElementPropertiesEditorWidget;
+}
+
+/**
+ * @brief The ElementPropertiesEditorWidget class
+ * This class provide a dialog for edit various property of element, like
+ * the type (master, slave, report etc....) and kind info.
+ */
+class ElementPropertiesEditorWidget : public QDialog
+{
+	Q_OBJECT
+
+	//METHODS
+	public:
+	explicit ElementPropertiesEditorWidget(QString &basic_type, DiagramContext &dc, QWidget *parent = 0);
+	~ElementPropertiesEditorWidget();
+
+	void upDateInterface();
+
+	private:
+	void setUpInterface();
+
+	//SLOTS
+	private slots:
+	void on_m_buttonBox_accepted();
+	void on_m_base_type_cb_currentIndexChanged(int index);
+
+	//ATTRIBUTES
+	private:
+	Ui::ElementPropertiesEditorWidget *ui;
+	QString &m_basic_type;
+	DiagramContext &m_dc;
+};
+
+#endif // ELEMENTPROPERTIESEDITORWIDGET_H

Added: trunk/sources/editor/ui/elementpropertieseditorwidget.ui
===================================================================
--- trunk/sources/editor/ui/elementpropertieseditorwidget.ui	                        (rev 0)
+++ trunk/sources/editor/ui/elementpropertieseditorwidget.ui	2014-06-03 20:21:19 UTC (rev 3102)
@@ -0,0 +1,141 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ElementPropertiesEditorWidget</class>
+ <widget class="QDialog" name="ElementPropertiesEditorWidget">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Propriété de l'élément</string>
+  </property>
+  <property name="sizeGripEnabled">
+   <bool>false</bool>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <item>
+      <widget class="QLabel" name="label">
+       <property name="text">
+        <string>Type de base :</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QComboBox" name="m_base_type_cb"/>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <widget class="QGroupBox" name="m_slave_gb">
+     <property name="title">
+      <string>Élément esclave</string>
+     </property>
+     <layout class="QVBoxLayout" name="verticalLayout_2">
+      <item>
+       <layout class="QGridLayout" name="gridLayout">
+        <item row="3" column="1">
+         <widget class="QSpinBox" name="m_number_ctc">
+          <property name="minimum">
+           <number>1</number>
+          </property>
+         </widget>
+        </item>
+        <item row="3" column="0">
+         <widget class="QLabel" name="label_4">
+          <property name="text">
+           <string>Nombre de contact représenté</string>
+          </property>
+         </widget>
+        </item>
+        <item row="2" column="0">
+         <widget class="QLabel" name="label_3">
+          <property name="text">
+           <string>Type de contact</string>
+          </property>
+         </widget>
+        </item>
+        <item row="1" column="0">
+         <widget class="QLabel" name="label_2">
+          <property name="text">
+           <string>État du contact</string>
+          </property>
+         </widget>
+        </item>
+        <item row="1" column="1">
+         <widget class="QComboBox" name="m_state_cb"/>
+        </item>
+        <item row="2" column="1">
+         <widget class="QComboBox" name="m_type_cb"/>
+        </item>
+       </layout>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
+    <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>
+   <item>
+    <widget class="QDialogButtonBox" name="m_buttonBox">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>m_buttonBox</sender>
+   <signal>accepted()</signal>
+   <receiver>ElementPropertiesEditorWidget</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>248</x>
+     <y>254</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>157</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>m_buttonBox</sender>
+   <signal>rejected()</signal>
+   <receiver>ElementPropertiesEditorWidget</receiver>
+   <slot>reject()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>316</x>
+     <y>260</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>286</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>

Modified: trunk/sources/qetgraphicsitem/reportelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/reportelement.cpp	2014-06-02 23:40:14 UTC (rev 3101)
+++ trunk/sources/qetgraphicsitem/reportelement.cpp	2014-06-03 20:21:19 UTC (rev 3102)
@@ -23,7 +23,8 @@
 ReportElement::ReportElement(const ElementsLocation &location, QString link_type,QGraphicsItem *qgi, Diagram *s, int *state) :
 	CustomElement(location, qgi, s, state)
 {
-	texts().at(0)->setNoEditable();
+	if (!texts().isEmpty())
+		texts().first()->setNoEditable();
 	link_type == "next_report"? link_type_=NextReport : link_type_=PreviousReport;
 	link_type == "next_report"? inverse_report=PreviousReport : inverse_report=NextReport;
 	if (s) {
@@ -108,6 +109,7 @@
  * ie the folio and position of the linked folio report
  */
 void ReportElement::updateLabel() {
+	if (texts().isEmpty()) return;
 	ElementTextItem *text = texts().first();
 
 	if (!connected_elements.isEmpty()){


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