[qet] [4027] Refactor some properties dialog.

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


Revision: 4027
Author:   blacksun
Date:     2015-06-23 22:40:05 +0200 (Tue, 23 Jun 2015)
Log Message:
-----------
Refactor some properties dialog.

Modified Paths:
--------------
    trunk/sources/PropertiesEditor/PropertiesEditor.pri
    trunk/sources/qetgraphicsitem/diagramimageitem.cpp
    trunk/sources/qetgraphicsitem/element.cpp
    trunk/sources/qetgraphicsitem/qetshapeitem.cpp
    trunk/sources/ui/diagrampropertieseditordockwidget.cpp
    trunk/sources/ui/elementpropertieswidget.cpp
    trunk/sources/ui/elementpropertieswidget.h

Added Paths:
-----------
    trunk/sources/PropertiesEditor/propertieseditordialog.h

Removed Paths:
-------------
    trunk/sources/ui/elementpropertiesdialog.cpp
    trunk/sources/ui/elementpropertiesdialog.h
    trunk/sources/ui/imagepropertiesdialog.cpp
    trunk/sources/ui/imagepropertiesdialog.h
    trunk/sources/ui/imagepropertiesdialog.ui

Modified: trunk/sources/PropertiesEditor/PropertiesEditor.pri
===================================================================
--- trunk/sources/PropertiesEditor/PropertiesEditor.pri	2015-06-23 03:00:07 UTC (rev 4026)
+++ trunk/sources/PropertiesEditor/PropertiesEditor.pri	2015-06-23 20:40:05 UTC (rev 4027)
@@ -3,7 +3,8 @@
 
 HEADERS += \
     $$PWD/propertieseditordockwidget.h \
-    $$PWD/propertieseditorwidget.h
+    $$PWD/propertieseditorwidget.h \
+    $$PWD/propertieseditordialog.h
 
 SOURCES += \
     $$PWD/propertieseditordockwidget.cpp \

Added: trunk/sources/PropertiesEditor/propertieseditordialog.h
===================================================================
--- trunk/sources/PropertiesEditor/propertieseditordialog.h	                        (rev 0)
+++ trunk/sources/PropertiesEditor/propertieseditordialog.h	2015-06-23 20:40:05 UTC (rev 4027)
@@ -0,0 +1,80 @@
+/*
+	Copyright 2006-2015 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 PROPERTIESEDITORDIALOG_H
+#define PROPERTIESEDITORDIALOG_H
+
+#include <QDialog>
+#include <QDialogButtonBox>
+#include <QVBoxLayout>
+#include <QAbstractButton>
+
+/**
+ * @brief The PropertiesEditorDialog class
+ * Create a dialog to edit some properties of a thing.
+ * Only create a instance of this class and call exec, all is done for you in this class.
+ * The first argument (a template) must be a subclass of QWidget and provide the 3 methods bellow :
+ * QString::title()
+ * void::apply()
+ * void::reset()
+ * You can subclass the interface PropertiesEditorWidget who provide all this methods.
+ * This dialog take ownership of the editor, so the editor will be deleted by this dialog
+ */
+class PropertiesEditorDialog : public QDialog
+{
+		Q_OBJECT
+	public:
+		template<typename T>
+		PropertiesEditorDialog(T editor, QWidget *parent = 0) :
+		QDialog (parent)
+		{
+				//Set dialog title
+			setWindowTitle(editor->title());
+				//Reparent the editor, to be deleted at the same time of this dialog
+			editor->setParent(this);
+
+				//Build the dialog
+			QVBoxLayout *vlayout = new QVBoxLayout(this);
+			vlayout->addWidget(editor);
+			QDialogButtonBox *button_box = new QDialogButtonBox (QDialogButtonBox::Apply | QDialogButtonBox::Cancel | QDialogButtonBox::Reset, this);
+			vlayout->addWidget(button_box);
+
+				//Setup connection between button box and the editor
+			connect(button_box, &QDialogButtonBox::clicked, [editor, button_box, this](QAbstractButton *button)
+			{
+				switch(button_box->buttonRole(button))
+				{
+					case QDialogButtonBox::RejectRole:
+						editor->reset();
+						this->reject();
+						break;
+					case QDialogButtonBox::ResetRole:
+						editor->reset();
+						break;
+					case QDialogButtonBox::ApplyRole:
+						editor->apply();
+						this->accept();
+						break;
+					default:
+						editor->reset();
+						this->reject();
+				}
+			});
+		}
+};
+
+#endif // PROPERTIESEDITORDIALOG_H

Modified: trunk/sources/qetgraphicsitem/diagramimageitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/diagramimageitem.cpp	2015-06-23 03:00:07 UTC (rev 4026)
+++ trunk/sources/qetgraphicsitem/diagramimageitem.cpp	2015-06-23 20:40:05 UTC (rev 4027)
@@ -17,7 +17,8 @@
 */
 #include "diagramimageitem.h"
 #include "diagram.h"
-#include "imagepropertiesdialog.h"
+#include "PropertiesEditor/propertieseditordialog.h"
+#include "imagepropertieswidget.h"
 
 /**
  * @brief DiagramImageItem::DiagramImageItem
@@ -85,7 +86,7 @@
 void DiagramImageItem::editProperty()
 {
 	if (diagram() -> isReadOnly()) return;
-	ImagePropertiesDialog dialog(this, QApplication::activeWindow());
+	PropertiesEditorDialog dialog(new ImagePropertiesWidget(this), QApplication::activeWindow());
 	dialog.exec();
 }
 

Modified: trunk/sources/qetgraphicsitem/element.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/element.cpp	2015-06-23 03:00:07 UTC (rev 4026)
+++ trunk/sources/qetgraphicsitem/element.cpp	2015-06-23 20:40:05 UTC (rev 4027)
@@ -22,10 +22,11 @@
 #include "elementtextitem.h"
 #include "diagramcommands.h"
 #include <QtDebug>
-#include <elementpropertiesdialog.h>
 #include "elementprovider.h"
 #include "diagramposition.h"
 #include "terminal.h"
+#include "PropertiesEditor/propertieseditordialog.h"
+#include "elementpropertieswidget.h"
 
 /**
 	Constructeur pour un element sans scene ni parent
@@ -48,14 +49,15 @@
 Element::~Element() {
 }
 
-void Element::editProperty() {
-	if (diagram())
-		if(!diagram()->isReadOnly()){
-			ElementPropertiesDialog epw (this, diagram()->views().first());
-			connect(&epw, SIGNAL(editElementRequired(ElementsLocation)), diagram(), SIGNAL(editElementRequired(ElementsLocation)));
-			connect(&epw, SIGNAL(findElementRequired(ElementsLocation)), diagram(), SIGNAL(findElementRequired(ElementsLocation)));
-			epw.exec();
-		}
+void Element::editProperty()
+{
+	if (diagram() && !diagram()->isReadOnly())
+	{
+		ElementPropertiesWidget *epw = new ElementPropertiesWidget(this);
+		PropertiesEditorDialog dialog(epw, QApplication::activeWindow());
+		connect(epw, &ElementPropertiesWidget::findEditClicked, &dialog, &QDialog::reject);
+		dialog.exec();
+	}
 }
 
 

Modified: trunk/sources/qetgraphicsitem/qetshapeitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/qetshapeitem.cpp	2015-06-23 03:00:07 UTC (rev 4026)
+++ trunk/sources/qetgraphicsitem/qetshapeitem.cpp	2015-06-23 20:40:05 UTC (rev 4027)
@@ -20,6 +20,7 @@
 #include "diagram.h"
 #include "qet.h"
 #include "shapegraphicsitempropertieswidget.h"
+#include "PropertiesEditor/propertieseditordialog.h"
 
 
 /**
@@ -359,24 +360,8 @@
 {
 	if (diagram() -> isReadOnly()) return;
 
-	//the dialog
-	QDialog property_dialog(diagram()->views().at(0));
-	property_dialog.setWindowTitle(tr("Éditer les propriétés d'une shape, Zone ", "window title"));
-	//the main layout
-	QVBoxLayout dialog_layout(&property_dialog);
-	ShapeGraphicsItemPropertiesWidget *sgipw = new ShapeGraphicsItemPropertiesWidget(this, &property_dialog);
-	dialog_layout.addWidget(sgipw);
-
-	//dialog button, box
-	QDialogButtonBox dbb(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
-	dialog_layout.addWidget(&dbb);
-	connect(&dbb, SIGNAL(accepted()), &property_dialog, SLOT(accept()));
-	connect(&dbb, SIGNAL(rejected()), &property_dialog, SLOT(reject()));
-
-	if (property_dialog.exec() == QDialog::Accepted)
-		sgipw->apply();
-	else
-		sgipw->reset();
+	PropertiesEditorDialog ped(new ShapeGraphicsItemPropertiesWidget(this), diagram()->views().at(0));
+	ped.exec();
 }
 
 /**

Modified: trunk/sources/ui/diagrampropertieseditordockwidget.cpp
===================================================================
--- trunk/sources/ui/diagrampropertieseditordockwidget.cpp	2015-06-23 03:00:07 UTC (rev 4026)
+++ trunk/sources/ui/diagrampropertieseditordockwidget.cpp	2015-06-23 20:40:05 UTC (rev 4027)
@@ -98,10 +98,7 @@
 
 			clear();
 			m_edited_qgi_type = type_;
-			ElementPropertiesWidget *epw = new ElementPropertiesWidget(static_cast<Element*>(item), this);
-			connect (epw, &ElementPropertiesWidget::editElementRequired , m_diagram, &Diagram::editElementRequired);
-			connect (epw, &ElementPropertiesWidget::findElementRequired, m_diagram, &Diagram::findElementRequired);
-			addEditor(epw);
+			addEditor(new ElementPropertiesWidget(static_cast<Element*>(item), this));
 			break; }
 
 		case DiagramImageItem::Type: {

Deleted: trunk/sources/ui/elementpropertiesdialog.cpp
===================================================================
--- trunk/sources/ui/elementpropertiesdialog.cpp	2015-06-23 03:00:07 UTC (rev 4026)
+++ trunk/sources/ui/elementpropertiesdialog.cpp	2015-06-23 20:40:05 UTC (rev 4027)
@@ -1,90 +0,0 @@
-/*
-	Copyright 2006-2015 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 "elementpropertiesdialog.h"
-#include "elementpropertieswidget.h"
-
-#include <QDialogButtonBox>
-#include <QVBoxLayout>
-
-/**
- * @brief ElementPropertiesDialog::ElementPropertiesDialog
- * default constructor
- * @param elmt
- * @param parent
- */
-ElementPropertiesDialog::ElementPropertiesDialog(Element *elmt, QWidget *parent) :
-	QDialog(parent),
-	element_ (elmt)
-{
-	m_editor = new ElementPropertiesWidget(elmt, this);
-
-	connect(m_editor, SIGNAL(editElementRequired(ElementsLocation)), this , SLOT(editElement(ElementsLocation)));
-	connect(m_editor, SIGNAL(findElementRequired(ElementsLocation)), this, SLOT(findInPanel(ElementsLocation)));
-
-	dbb = new QDialogButtonBox(QDialogButtonBox::Apply | QDialogButtonBox::Cancel | QDialogButtonBox::Reset, Qt::Horizontal, this);
-	connect(dbb, SIGNAL(clicked(QAbstractButton*)), this, SLOT(standardButtonClicked(QAbstractButton*)));
-
-	QVBoxLayout *main_layout = new QVBoxLayout(this);
-	main_layout -> addWidget(m_editor);
-	main_layout -> addWidget(dbb);
-	setLayout(main_layout);
-}
-
-/**
- * @brief ElementPropertiesDialog::standardButtonClicked
- * apply action when click in the dialog standard button box
- * @param button
- * the cliked button
- */
-void ElementPropertiesDialog::standardButtonClicked(QAbstractButton *button) {
-	int  answer = dbb -> buttonRole(button);
-
-	switch (answer) {
-		case QDialogButtonBox::ResetRole:
-			m_editor->reset();
-			break;
-		case QDialogButtonBox::ApplyRole:
-			m_editor->apply();
-			accept();
-			break;
-		default:
-			reject();
-			break;
-	}
-}
-
-/**
- * @brief ElementPropertiesDialog::findInPanel
- * Slot
- */
-void ElementPropertiesDialog::findInPanel(const ElementsLocation &location)
-{
-	emit findElementRequired(location);
-	reject();
-}
-
-/**
- * @brief ElementPropertiesDialog::editElement
- * Slot
- */
-void ElementPropertiesDialog::editElement(const ElementsLocation &location)
-{
-	emit findElementRequired(location);
-	emit editElementRequired(location);
-	reject();
-}

Deleted: trunk/sources/ui/elementpropertiesdialog.h
===================================================================
--- trunk/sources/ui/elementpropertiesdialog.h	2015-06-23 03:00:07 UTC (rev 4026)
+++ trunk/sources/ui/elementpropertiesdialog.h	2015-06-23 20:40:05 UTC (rev 4027)
@@ -1,57 +0,0 @@
-/*
-	Copyright 2006-2015 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 ELEMENTPROPERTIESDIALOG_H
-#define ELEMENTPROPERTIESDIALOG_H
-
-#include <QDialog>
-
-class Element;
-class ElementsLocation;
-class QAbstractButton;
-class QDialogButtonBox;
-class ElementPropertiesWidget;
-
-/**
- * @brief The ElementPropertiesDialog class
- * Display the element properties widget in a QDialog
- */
-class ElementPropertiesDialog : public QDialog
-{
-	Q_OBJECT
-
-	public:
-		explicit ElementPropertiesDialog(Element *elmt, QWidget *parent = 0);
-
-	signals:
-			/// Signal emitted when users wish to locate an element from the diagram within elements collection
-		void findElementRequired(const ElementsLocation &);
-			/// Signal emitted when users wish to edit an element from the diagram
-		void editElementRequired(const ElementsLocation &);
-
-	public slots:
-		void standardButtonClicked (QAbstractButton *);
-		void findInPanel (const ElementsLocation &);
-		void editElement (const ElementsLocation &);
-
-	private:
-		Element                 *element_;
-		QDialogButtonBox        *dbb;
-		ElementPropertiesWidget *m_editor;
-};
-
-#endif // ELEMENTPROPERTIESDIALOG_H

Modified: trunk/sources/ui/elementpropertieswidget.cpp
===================================================================
--- trunk/sources/ui/elementpropertieswidget.cpp	2015-06-23 03:00:07 UTC (rev 4026)
+++ trunk/sources/ui/elementpropertieswidget.cpp	2015-06-23 20:40:05 UTC (rev 4027)
@@ -124,8 +124,12 @@
  */
 void ElementPropertiesWidget::findInPanel()
 {
-	if (CustomElement *custom_element = qobject_cast<CustomElement *>(m_element))
-		emit findElementRequired(custom_element->location());
+	CustomElement *custom_element = qobject_cast<CustomElement *>(m_element);
+	if (custom_element && m_diagram)
+	{
+		m_diagram->findElementRequired(custom_element->location());
+		emit findEditClicked();
+	}
 }
 
 /**
@@ -134,10 +138,12 @@
  */
 void ElementPropertiesWidget::editElement()
 {
-	if (CustomElement *custom_element = qobject_cast<CustomElement *>(m_element))
+	CustomElement *custom_element = qobject_cast<CustomElement *>(m_element);
+	if (custom_element && m_diagram)
 	{
-		emit findElementRequired(custom_element->location());
-		emit editElementRequired(custom_element->location());
+		m_diagram->findElementRequired(custom_element->location());
+		m_diagram->editElementRequired(custom_element->location());
+		emit findEditClicked();
 	}
 }
 

Modified: trunk/sources/ui/elementpropertieswidget.h
===================================================================
--- trunk/sources/ui/elementpropertieswidget.h	2015-06-23 03:00:07 UTC (rev 4026)
+++ trunk/sources/ui/elementpropertieswidget.h	2015-06-23 20:40:05 UTC (rev 4027)
@@ -48,10 +48,7 @@
 		QWidget *generalWidget();
 
 	signals:
-			/// Signal emitted when users wish to locate an element from the diagram within elements collection
-		void findElementRequired(const ElementsLocation &);
-			/// Signal emitted when users wish to edit an element from the diagram
-		void editElementRequired(const ElementsLocation &);
+		void findEditClicked();
 
 	private:
 		Diagram *m_diagram;

Deleted: trunk/sources/ui/imagepropertiesdialog.cpp
===================================================================
--- trunk/sources/ui/imagepropertiesdialog.cpp	2015-06-23 03:00:07 UTC (rev 4026)
+++ trunk/sources/ui/imagepropertiesdialog.cpp	2015-06-23 20:40:05 UTC (rev 4027)
@@ -1,29 +0,0 @@
-#include "imagepropertiesdialog.h"
-#include "ui_imagepropertiesdialog.h"
-#include "imagepropertieswidget.h"
-#include "diagramimageitem.h"
-
-ImagePropertiesDialog::ImagePropertiesDialog(DiagramImageItem *image, QWidget *parent) :
-	QDialog(parent),
-	ui(new Ui::ImagePropertiesDialog)
-{
-	ui->setupUi(this);
-	m_editor = new ImagePropertiesWidget(image, this);
-	ui->verticalLayout->insertWidget(0, m_editor);
-}
-
-ImagePropertiesDialog::~ImagePropertiesDialog() {
-	delete ui;
-}
-
-void ImagePropertiesDialog::setImageItem(DiagramImageItem *image) {
-	m_editor->setImageItem(image);
-}
-
-void ImagePropertiesDialog::on_buttonBox_accepted() {
-	m_editor->apply();
-}
-
-void ImagePropertiesDialog::on_buttonBox_rejected() {
-	m_editor->reset();
-}

Deleted: trunk/sources/ui/imagepropertiesdialog.h
===================================================================
--- trunk/sources/ui/imagepropertiesdialog.h	2015-06-23 03:00:07 UTC (rev 4026)
+++ trunk/sources/ui/imagepropertiesdialog.h	2015-06-23 20:40:05 UTC (rev 4027)
@@ -1,31 +0,0 @@
-#ifndef IMAGEPROPERTIESDIALOG_H
-#define IMAGEPROPERTIESDIALOG_H
-
-#include <QDialog>
-
-class ImagePropertiesWidget;
-class DiagramImageItem;
-
-namespace Ui {
-	class ImagePropertiesDialog;
-}
-
-class ImagePropertiesDialog : public QDialog
-{
-		Q_OBJECT
-
-	public:
-		explicit ImagePropertiesDialog(DiagramImageItem *image = nullptr, QWidget *parent = 0);
-		~ImagePropertiesDialog();
-		void setImageItem (DiagramImageItem *image);
-
-	private slots:
-		void on_buttonBox_accepted();
-		void on_buttonBox_rejected();
-
-	private:
-		Ui::ImagePropertiesDialog *ui;
-		ImagePropertiesWidget *m_editor;
-};
-
-#endif // IMAGEPROPERTIESDIALOG_H

Deleted: trunk/sources/ui/imagepropertiesdialog.ui
===================================================================
--- trunk/sources/ui/imagepropertiesdialog.ui	2015-06-23 03:00:07 UTC (rev 4026)
+++ trunk/sources/ui/imagepropertiesdialog.ui	2015-06-23 20:40:05 UTC (rev 4027)
@@ -1,67 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>ImagePropertiesDialog</class>
- <widget class="QDialog" name="ImagePropertiesDialog">
-  <property name="geometry">
-   <rect>
-    <x>0</x>
-    <y>0</y>
-    <width>194</width>
-    <height>52</height>
-   </rect>
-  </property>
-  <property name="windowTitle">
-   <string>Éditer les propriétés de image</string>
-  </property>
-  <layout class="QVBoxLayout" name="verticalLayout">
-   <property name="sizeConstraint">
-    <enum>QLayout::SetMinimumSize</enum>
-   </property>
-   <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>ImagePropertiesDialog</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>ImagePropertiesDialog</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/