[qet] [3295] Conductor properties dialog: dialog is now build in is own class.

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


Revision: 3295
Author:   blacksun
Date:     2014-09-02 20:41:25 +0200 (Tue, 02 Sep 2014)
Log Message:
-----------
Conductor properties dialog: dialog is now build in is own class.
The conductor himself call the dialog when he have mouse double click.
The dialog isn't managed by the diagram view anymore. 

Modified Paths:
--------------
    trunk/sources/diagramview.cpp
    trunk/sources/diagramview.h
    trunk/sources/qetdiagrameditor.cpp
    trunk/sources/qetdiagrameditor.h
    trunk/sources/qetgraphicsitem/conductor.cpp
    trunk/sources/qetgraphicsitem/conductor.h

Added Paths:
-----------
    trunk/sources/ui/conductorpropertiesdialog.cpp
    trunk/sources/ui/conductorpropertiesdialog.h
    trunk/sources/ui/conductorpropertiesdialog.ui

Modified: trunk/sources/diagramview.cpp
===================================================================
--- trunk/sources/diagramview.cpp	2014-09-01 14:56:11 UTC (rev 3294)
+++ trunk/sources/diagramview.cpp	2014-09-02 18:41:25 UTC (rev 3295)
@@ -37,7 +37,6 @@
 #include "qetmessagebox.h"
 #include "qtextorientationspinboxwidget.h"
 #include <QGraphicsObject>
-#include <ui/elementpropertieswidget.h>
 #include <QGraphicsPixmapItem>
 #include <QGraphicsSceneMouseEvent>
 #include "factory/elementfactory.h"
@@ -914,7 +913,7 @@
 													 DiagramContent::SelectedOnly).size()) {
 		// edit conductor
 		if (selection.conductors(DiagramContent::AnyConductor | DiagramContent::SelectedOnly).size())
-			editConductor(selection.conductors().first());
+			selection.conductors().first()->editProperty();
 		// edit element
 		else if (selection.elements.size())
 			selection.elements.toList().first() -> editProperty();
@@ -949,88 +948,6 @@
 }
 
 /**
-	Affiche un dialogue permettant d'editer le conducteur selectionne.
-	Ne fait rien s'il y a 0 ou plusieurs conducteurs selectionnes.
-*/
-void DiagramView::editConductor() {
-	QList<Conductor *> selected_conductors(scene -> selectedConductors().toList());
-	
-	// on ne peut editer qu'un conducteur a la fois
-	if (selected_conductors.count() != 1) return;
-	Conductor *edited_conductor = selected_conductors.first();
-	
-	editConductor(edited_conductor);
-}
-
-/**
-	Edite le conducteur passe en parametre
-	@param edited_conductor Conducteur a editer
-*/
-void DiagramView::editConductor(Conductor *edited_conductor) {
-	if (scene -> isReadOnly() || !edited_conductor) return;
-	
-	// initialise l'editeur de proprietes pour le conducteur
-	ConductorProperties old_properties = edited_conductor -> properties();
-	ConductorPropertiesWidget *cpw = new ConductorPropertiesWidget(old_properties);
-	
-	// l'insere dans un dialogue
-	QDialog conductor_dialog(diagramEditor());
-#ifdef Q_WS_MAC
-	conductor_dialog.setWindowFlags(Qt::Sheet);
-#endif
-	conductor_dialog.setWindowTitle(tr("\311diter les propri\351t\351s d'un conducteur", "window title"));
-	QVBoxLayout *dialog_layout = new QVBoxLayout(&conductor_dialog);
-	dialog_layout -> addWidget(cpw);
-	QCheckBox *cb_apply_all = new QCheckBox(tr("Appliquer les propri\351t\351s \340 l'ensemble des conducteurs de ce potentiel"), &conductor_dialog);
-	cb_apply_all->setChecked(true);
-	dialog_layout -> addStretch();
-	dialog_layout -> addWidget(cb_apply_all);
-	QDialogButtonBox *dbb = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
-	dbb -> setParent(&conductor_dialog);
-	dialog_layout -> addWidget(dbb);
-	connect(dbb, SIGNAL(accepted()), &conductor_dialog, SLOT(accept()));
-	connect(dbb, SIGNAL(rejected()), &conductor_dialog, SLOT(reject()));
-	cpw -> setFocus(Qt::ActiveWindowFocusReason);
-	
-	// execute le dialogue et met a jour le conducteur
-	if (conductor_dialog.exec() == QDialog::Accepted) {
-		// recupere les nouvelles proprietes
-		ConductorProperties new_properties = cpw -> properties();
-
-		if (new_properties != old_properties) {
-				if (cb_apply_all -> isChecked()) {
-					QList <Conductor *> conductorslist = edited_conductor -> relatedPotentialConductors().toList();
-					conductorslist << edited_conductor;
-					QList <ConductorProperties> old_properties_list;
-
-					foreach (Conductor *c, conductorslist) {
-						if (c == edited_conductor) {
-							old_properties_list << old_properties;
-						}
-						else {
-							old_properties_list << c -> properties();
-							c -> setProperties(new_properties);
-						}
-					}
-					//initialize the corresponding UndoCommand object
-					ChangeSeveralConductorsPropertiesCommand *cscpc = new ChangeSeveralConductorsPropertiesCommand(conductorslist);
-					cscpc -> setOldSettings(old_properties_list);
-					cscpc -> setNewSettings(new_properties);
-					diagram() -> undoStack().push(cscpc);
-				}
-
-			else {
-				// initialise l'objet UndoCommand correspondant
-				ChangeConductorPropertiesCommand *ccpc = new ChangeConductorPropertiesCommand(edited_conductor);
-				ccpc -> setOldSettings(old_properties);
-				ccpc -> setNewSettings(new_properties);
-				diagram() -> undoStack().push(ccpc);
-			}
-		}
-	}
-}
-
-/**
 	Edit the color of the given conductor
 	@param edited_conductor Conductor we want to change the color
 */
@@ -1383,7 +1300,7 @@
 void DiagramView::mouseDoubleClickEvent(QMouseEvent *e) {
 	BorderTitleBlock &bi = scene -> border_and_titleblock;
 	
-	// recupere le rectangle corespondant au cartouche
+	//Get the rectangle of the titleblock
 	QRectF titleblock_rect(
 		Diagram::margin,
 		Diagram::margin + bi.diagramHeight(),
@@ -1391,7 +1308,7 @@
 		bi.titleBlockHeight()
 	);
 	
-	// recupere le rectangle correspondant aux en-tetes des colonnes
+	// Get the rectangle of the header column
 	QRectF columns_rect(
 		Diagram::margin,
 		Diagram::margin,
@@ -1399,7 +1316,7 @@
 		bi.columnsHeaderHeight()
 	);
 	
-	// recupere le rectangle correspondant aux en-tetes des lignes
+	// Get the rectangle of the header row
 	QRectF rows_rect(
 		Diagram::margin,
 		Diagram::margin,
@@ -1407,22 +1324,15 @@
 		bi.diagramHeight()
 	);
 	
-	// coordonnees du clic par rapport au schema
+	//Get the click pos on the diagram
 	QPointF click_pos = viewportTransform().inverted().map(e -> pos());
 	
-	// detecte le double-clic sur le cartouche ou les colonnes
-	if (QGraphicsItem *qgi = itemAt(e -> pos())) {
-		if (Conductor *c = qgraphicsitem_cast<Conductor *>(qgi)) {
-			editConductor(c);
-		} else {
-			QGraphicsView::mouseDoubleClickEvent(e);
-		}
-	} else if (titleblock_rect.contains(click_pos) || columns_rect.contains(click_pos) || rows_rect.contains(click_pos)) {
-		// edite les proprietes du schema
+	if (titleblock_rect.contains(click_pos) || columns_rect.contains(click_pos) || rows_rect.contains(click_pos)) {
+		e->accept();
 		editDiagramProperties();
-	} else {
-		QGraphicsView::mouseDoubleClickEvent(e);
+		return;
 	}
+	QGraphicsView::mouseDoubleClickEvent(e);
 }
 
 /**

Modified: trunk/sources/diagramview.h
===================================================================
--- trunk/sources/diagramview.h	2014-09-01 14:56:11 UTC (rev 3294)
+++ trunk/sources/diagramview.h	2014-09-02 18:41:25 UTC (rev 3295)
@@ -176,8 +176,6 @@
 	void updateWindowTitle();
 	void editSelectionProperties();
 	void editSelectedConductorColor();
-	void editConductor();
-	void editConductor(Conductor *);
 	void editConductorColor(Conductor *);
 	void resetConductors();
 	

Modified: trunk/sources/qetdiagrameditor.cpp
===================================================================
--- trunk/sources/qetdiagrameditor.cpp	2014-09-01 14:56:11 UTC (rev 3294)
+++ trunk/sources/qetdiagrameditor.cpp	2014-09-02 18:41:25 UTC (rev 3295)
@@ -1497,15 +1497,6 @@
 }
 
 /**
-	Edite les proprietes du conducteur selectionne
-*/
-void QETDiagramEditor::slot_editConductor() {
-	if (DiagramView *dv = currentDiagram()) {
-		dv -> editConductor();
-	}
-}
-
-/**
 	Reinitialise les conducteurs selectionnes
 */
 void QETDiagramEditor::slot_resetConductors() {

Modified: trunk/sources/qetdiagrameditor.h
===================================================================
--- trunk/sources/qetdiagrameditor.h	2014-09-01 14:56:11 UTC (rev 3294)
+++ trunk/sources/qetdiagrameditor.h	2014-09-02 18:41:25 UTC (rev 3295)
@@ -125,7 +125,6 @@
 	void slot_addRow();
 	void slot_removeRow();
 	void editSelectionProperties();
-	void slot_editConductor();
 	void slot_resetConductors();
 	void slot_addText();
 	void slot_addImage();

Modified: trunk/sources/qetgraphicsitem/conductor.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/conductor.cpp	2014-09-01 14:56:11 UTC (rev 3294)
+++ trunk/sources/qetgraphicsitem/conductor.cpp	2014-09-02 18:41:25 UTC (rev 3295)
@@ -26,6 +26,7 @@
 #include "qetdiagrameditor.h"
 #include "terminal.h"
 #include "conductorautonumerotation.h"
+#include "conductorpropertiesdialog.h"
 #define PR(x) qDebug() << #x " = " << x;
 
 bool Conductor::pen_and_brush_initialized = false;
@@ -557,6 +558,16 @@
 }
 
 /**
+ * @brief Conductor::mouseDoubleClickEvent
+ * Action at double click on this item
+ * @param e
+ */
+void Conductor::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e) {
+	e->accept();
+	editProperty();
+}
+
+/**
 	Gere les clics sur le conducteur.
 	@param e L'evenement decrivant le clic.
 */
@@ -1407,6 +1418,13 @@
 }
 
 /**
+ * @brief Conductor::editProperty
+ */
+void Conductor::editProperty() {
+	ConductorPropertiesDialog::PropertiesDialog(this, diagramEditor());
+}
+
+/**
 	@param a reel
 	@param b reel
 	@param c reel

Modified: trunk/sources/qetgraphicsitem/conductor.h
===================================================================
--- trunk/sources/qetgraphicsitem/conductor.h	2014-09-01 14:56:11 UTC (rev 3294)
+++ trunk/sources/qetgraphicsitem/conductor.h	2014-09-02 18:41:25 UTC (rev 3295)
@@ -108,11 +108,13 @@
 	void autoText();
 	QSet<Conductor *> relatedPotentialConductors(QList <Terminal *> *t_list=0);
 	QETDiagramEditor* diagramEditor() const;
+	void editProperty ();
 	
 	public slots:
 	void displayedTextChanged();
 	
 	protected:
+	virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *);
 	virtual void mousePressEvent(QGraphicsSceneMouseEvent *);
 	virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
 	virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *);

Added: trunk/sources/ui/conductorpropertiesdialog.cpp
===================================================================
--- trunk/sources/ui/conductorpropertiesdialog.cpp	                        (rev 0)
+++ trunk/sources/ui/conductorpropertiesdialog.cpp	2014-09-02 18:41:25 UTC (rev 3295)
@@ -0,0 +1,105 @@
+/*
+	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 "conductorpropertiesdialog.h"
+#include "ui_conductorpropertiesdialog.h"
+
+#include "conductor.h"
+#include "conductorpropertieswidget.h"
+#include "diagramcommands.h"
+#include "diagram.h"
+
+/**
+ * @brief ConductorPropertiesDialog::ConductorPropertiesDialog
+ * Constructor
+ * @param conductor, conductor to edit propertie
+ * @param parent, parent widget
+ */
+ConductorPropertiesDialog::ConductorPropertiesDialog(Conductor *conductor, QWidget *parent) :
+	QDialog(parent),
+	ui(new Ui::ConductorPropertiesDialog)
+{
+	ui->setupUi(this);
+	m_cpw = new ConductorPropertiesWidget(conductor->properties());
+	ui -> main_layout -> insertWidget(1, m_cpw);
+}
+
+/**
+ * @brief ConductorPropertiesDialog::~ConductorPropertiesDialog
+ */
+ConductorPropertiesDialog::~ConductorPropertiesDialog()
+{
+	delete ui;
+}
+
+/**
+ * @brief ConductorPropertiesDialog::PropertiesDialog
+ * Static method for open and apply properties.
+ * @param conductor, conductor to edit propertie
+ * @param parent, parent widget
+ */
+void ConductorPropertiesDialog::PropertiesDialog(Conductor *conductor, QWidget *parent) {
+	ConductorPropertiesDialog cpd (conductor, parent);
+
+	if (cpd.exec() == QDialog::Accepted && cpd.properties() != conductor->properties()) {
+
+		if (cpd.applyAll()) {
+			QList <Conductor *> conductorslist = conductor -> relatedPotentialConductors().toList();
+			conductorslist << conductor;
+			QList <ConductorProperties> old_properties_list;
+
+			foreach (Conductor *c, conductorslist) {
+				if (c == conductor) {
+					old_properties_list << conductor -> properties();
+				} else {
+					old_properties_list << c -> properties();
+					c -> setProperties( cpd.properties() );
+				}
+			}
+			//initialize the corresponding UndoCommand object
+			ChangeSeveralConductorsPropertiesCommand *cscpc = new ChangeSeveralConductorsPropertiesCommand(conductorslist);
+			cscpc -> setOldSettings(old_properties_list);
+			cscpc -> setNewSettings(cpd.properties());
+			conductor -> diagram() -> undoStack().push(cscpc);
+		} else {
+			// initialize the corresponding UndoCommand object
+			ChangeConductorPropertiesCommand *ccpc = new ChangeConductorPropertiesCommand(conductor);
+			ccpc -> setOldSettings(conductor -> properties());
+			ccpc -> setNewSettings(cpd.properties());
+			conductor -> diagram() -> undoStack().push(ccpc);
+		}
+	}
+}
+
+/**
+ * @brief ConductorPropertiesDialog::properties
+ * @return the edited properties
+ */
+ConductorProperties ConductorPropertiesDialog::properties() const {
+	return m_cpw -> properties();
+}
+
+/**
+ * @brief ConductorPropertiesDialog::applyAll
+ * @return
+ * true -> must apply the propertie to all conductor at the same potential
+ * false -> must apply properties only for the edited conductor
+ */
+bool ConductorPropertiesDialog::applyAll() const {
+	return ui -> m_apply_all_cb -> isChecked();
+}

Added: trunk/sources/ui/conductorpropertiesdialog.h
===================================================================
--- trunk/sources/ui/conductorpropertiesdialog.h	                        (rev 0)
+++ trunk/sources/ui/conductorpropertiesdialog.h	2014-09-02 18:41:25 UTC (rev 3295)
@@ -0,0 +1,49 @@
+/*
+	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 CONDUCTORPROPERTIESDIALOG_H
+#define CONDUCTORPROPERTIESDIALOG_H
+
+#include <QDialog>
+#include "conductorproperties.h"
+
+class Conductor;
+class ConductorPropertiesWidget;
+
+namespace Ui {
+	class ConductorPropertiesDialog;
+}
+
+class ConductorPropertiesDialog : public QDialog
+{
+		Q_OBJECT
+
+	public:
+		explicit ConductorPropertiesDialog (Conductor *conductor, QWidget *parent = 0);
+		static void PropertiesDialog (Conductor *conductor, QWidget *parent = 0);
+		~ConductorPropertiesDialog();
+
+		ConductorProperties properties() const;
+		bool applyAll() const;
+
+	private:
+		Ui::ConductorPropertiesDialog *ui;
+		ConductorPropertiesWidget *m_cpw;
+};
+
+#endif // CONDUCTORPROPERTIESDIALOG_H

Added: trunk/sources/ui/conductorpropertiesdialog.ui
===================================================================
--- trunk/sources/ui/conductorpropertiesdialog.ui	                        (rev 0)
+++ trunk/sources/ui/conductorpropertiesdialog.ui	2014-09-02 18:41:25 UTC (rev 3295)
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ConductorPropertiesDialog</class>
+ <widget class="QDialog" name="ConductorPropertiesDialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>430</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Éditer les propriétés d'un conducteur</string>
+  </property>
+  <layout class="QVBoxLayout" name="main_layout">
+   <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="QCheckBox" name="m_apply_all_cb">
+     <property name="text">
+      <string>Appliquer les propriétés à l'ensemble des conducteurs de ce potentiel</string>
+     </property>
+     <property name="checked">
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QDialogButtonBox" name="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>buttonBox</sender>
+   <signal>accepted()</signal>
+   <receiver>ConductorPropertiesDialog</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>buttonBox</sender>
+   <signal>rejected()</signal>
+   <receiver>ConductorPropertiesDialog</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>


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