[qet] [2672] add class ElementProvider and build small ui for the properties of folio report element

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


Revision: 2672
Author:   blacksun
Date:     2013-12-28 14:28:27 +0100 (Sat, 28 Dec 2013)
Log Message:
-----------
add class ElementProvider and build small ui for the properties of folio report element

Modified Paths:
--------------
    trunk/sources/diagram.cpp
    trunk/sources/diagram.h
    trunk/sources/qetgraphicsitem/element.h
    trunk/sources/ui/elementpropertieswidget.cpp
    trunk/sources/ui/elementpropertieswidget.h

Added Paths:
-----------
    trunk/sources/elementprovider.cpp
    trunk/sources/elementprovider.h
    trunk/sources/ui/folioreportproperties.cpp
    trunk/sources/ui/folioreportproperties.h
    trunk/sources/ui/folioreportproperties.ui

Modified: trunk/sources/diagram.cpp
===================================================================
--- trunk/sources/diagram.cpp	2013-12-27 04:27:12 UTC (rev 2671)
+++ trunk/sources/diagram.cpp	2013-12-28 13:28:27 UTC (rev 2672)
@@ -936,6 +936,15 @@
 	return(elements_list);
 }
 
+QList <Element *> Diagram::elements() const {
+	QList<Element *> element_list;
+	foreach (QGraphicsItem *qgi, items()) {
+		if (Element *elmt = qgraphicsitem_cast<Element *>(qgi))
+			element_list <<elmt;
+	}
+	return (element_list);
+}
+
 /**
 	Initialise un deplacement d'elements, conducteurs et champs de texte sur le
 	schema.

Modified: trunk/sources/diagram.h
===================================================================
--- trunk/sources/diagram.h	2013-12-27 04:27:12 UTC (rev 2671)
+++ trunk/sources/diagram.h	2013-12-28 13:28:27 UTC (rev 2672)
@@ -165,6 +165,7 @@
 	bool isEmpty() const;
 	
 	QList<CustomElement *> customElements() const;
+	QList<Element *> elements() const;
 	QSet<DiagramTextItem *> selectedTexts() const;
 	QSet<ConductorTextItem *> selectedConductorTexts() const;
 	QSet<Conductor *> selectedConductors() const;

Added: trunk/sources/elementprovider.cpp
===================================================================
--- trunk/sources/elementprovider.cpp	                        (rev 0)
+++ trunk/sources/elementprovider.cpp	2013-12-28 13:28:27 UTC (rev 2672)
@@ -0,0 +1,54 @@
+/*
+	Copyright 2006-2013 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 "elementprovider.h"
+
+/**
+ * @brief ElementProvider::ElementProvider Constructor
+ * @param prj the project where we must find element
+ * @param diagram the digram to exclude from the search
+ */
+ElementProvider::ElementProvider(QETProject *prj, Diagram *diagram)
+{
+	diag_list = prj->diagrams();
+	diag_list.removeOne(diagram);
+}
+
+/**
+ * @brief ElementProvider::FreeElement
+ * Search and return the asked element corresponding  with the given filter
+ * All returned element are free, ie element aren't connected with another element
+ * @param filter
+ * the filter for search element
+ * (the filter must be the enum linkerType in Element.h)
+ * @return
+ */
+QList <Element *> ElementProvider::FreeElement(int filter) {
+	QList <Element *> free_elmt;
+
+	//serch in all diagram
+	foreach (Diagram *d, diag_list) {
+		//get all element in diagram d
+		QList <Element *> elmt_list;
+		elmt_list = d->elements();
+		foreach (Element *elmt, elmt_list) {
+			if (filter & elmt->linkType())
+				if (elmt->isFree()) free_elmt << elmt;
+		}
+	}
+	return (free_elmt);
+}

Added: trunk/sources/elementprovider.h
===================================================================
--- trunk/sources/elementprovider.h	                        (rev 0)
+++ trunk/sources/elementprovider.h	2013-12-28 13:28:27 UTC (rev 2672)
@@ -0,0 +1,41 @@
+/*
+	Copyright 2006-2013 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 ELEMENTPROVIDER_H
+#define ELEMENTPROVIDER_H
+
+#include "qetproject.h"
+#include "diagram.h"
+#include "qetgraphicsitem/element.h"
+
+/**
+  this class can search in the given diagram or project some kind of element
+  like 'folio report' or 'master' and return it.
+  We can get element element with specific status like 'free'.
+*/
+
+class ElementProvider
+{
+	public:
+	ElementProvider(QETProject *prj, Diagram *diagram=0);
+	QList <Element *> FreeElement(int filter);
+
+	private:
+	QList <Diagram *> diag_list;
+};
+
+#endif // ELEMENTPROVIDER_H

Modified: trunk/sources/qetgraphicsitem/element.h
===================================================================
--- trunk/sources/qetgraphicsitem/element.h	2013-12-27 04:27:12 UTC (rev 2671)
+++ trunk/sources/qetgraphicsitem/element.h	2013-12-28 13:28:27 UTC (rev 2672)
@@ -56,6 +56,7 @@
 	QSize   dimensions;
 	QPoint  hotspot_coord;
 	QPixmap preview;
+	QList <Element *> connected_elements;
 	
 	// methods
 	public:
@@ -79,6 +80,7 @@
 	virtual int minTerminalsCount() const = 0;
 	/// @return the maximum number of terminals for this element
 	virtual int maxTerminalsCount() const = 0;
+	bool isFree () const;
 	/**
 		Draw this element
 	*/
@@ -131,6 +133,10 @@
 	void updatePixmap();
 };
 
+inline bool Element::isFree() const {
+	return (connected_elements.isEmpty());
+}
+
 /**
 	Indicate whether this element allows internal connections, i.e. whether its
 	terminals can be linked together using a conductor.

Modified: trunk/sources/ui/elementpropertieswidget.cpp
===================================================================
--- trunk/sources/ui/elementpropertieswidget.cpp	2013-12-27 04:27:12 UTC (rev 2671)
+++ trunk/sources/ui/elementpropertieswidget.cpp	2013-12-28 13:28:27 UTC (rev 2672)
@@ -93,8 +93,8 @@
 		case Element::simple:
 			break;
 		case Element::report:
-			w = new QComboBox(this);
-			tab_ -> addTab(w, tr("Report de folio"));
+			frp_ = new FolioReportProperties(element_, this);
+			tab_ -> addTab(frp_, tr("Report de folio"));
 			break;
 		case Element::master:
 			break;

Modified: trunk/sources/ui/elementpropertieswidget.h
===================================================================
--- trunk/sources/ui/elementpropertieswidget.h	2013-12-27 04:27:12 UTC (rev 2671)
+++ trunk/sources/ui/elementpropertieswidget.h	2013-12-28 13:28:27 UTC (rev 2672)
@@ -4,6 +4,7 @@
 #include <QtGui>
 #include <qetgraphicsitem/element.h>
 #include <diagram.h>
+#include <folioreportproperties.h>
 
 class elementpropertieswidget : public QDialog
 {
@@ -27,7 +28,7 @@
 	void editElement ();
 
 	private:
-	QWidget *w; ///this widget is only for test
+	FolioReportProperties *frp_;
 	QDialogButtonBox *dbb;
 	Element *element_;
 	Diagram *diagram_;

Added: trunk/sources/ui/folioreportproperties.cpp
===================================================================
--- trunk/sources/ui/folioreportproperties.cpp	                        (rev 0)
+++ trunk/sources/ui/folioreportproperties.cpp	2013-12-28 13:28:27 UTC (rev 2672)
@@ -0,0 +1,34 @@
+#include "folioreportproperties.h"
+#include "ui_folioreportproperties.h"
+
+#include <diagramposition.h>
+#include <elementprovider.h>
+
+FolioReportProperties::FolioReportProperties(Element *elmt, QWidget *parent) :
+	QWidget(parent),
+	element_(elmt),
+	ui(new Ui::FolioReportProperties)
+{
+	ui->setupUi(this);
+
+	ElementProvider ep(element_->diagram()->project(), element_->diagram());
+	QList <Element *> elmt_list = ep.FreeElement(Element::report);
+
+	foreach (Element *elmt, elmt_list) {
+		if (elmt != element_) {
+			QString button_text;
+			button_text += elmt->name();
+			button_text += QString(tr(" Folio\240: %1, ")).arg(elmt->diagram()->folioIndex() + 1);
+			button_text += QString(tr("Position\240: %1")).arg(elmt->diagram() -> convertPosition(elmt -> scenePos()).toString());
+
+			QRadioButton *rb = new QRadioButton(button_text , this);
+			ui->available_report_layout->addWidget(rb);
+		}
+	}
+	ui->available_report_layout->addStretch();
+}
+
+FolioReportProperties::~FolioReportProperties()
+{
+	delete ui;
+}

Added: trunk/sources/ui/folioreportproperties.h
===================================================================
--- trunk/sources/ui/folioreportproperties.h	                        (rev 0)
+++ trunk/sources/ui/folioreportproperties.h	2013-12-28 13:28:27 UTC (rev 2672)
@@ -0,0 +1,24 @@
+#ifndef FOLIOREPORTPROPERTIES_H
+#define FOLIOREPORTPROPERTIES_H
+
+#include <QWidget>
+#include <qetgraphicsitem/element.h>
+
+namespace Ui {
+	class FolioReportProperties;
+}
+
+class FolioReportProperties : public QWidget
+{
+	Q_OBJECT
+
+	public:
+	explicit FolioReportProperties(Element *elmt, QWidget *parent = 0);
+	~FolioReportProperties();
+
+	private:
+	Element *element_;
+	Ui::FolioReportProperties *ui;
+};
+
+#endif // FOLIOREPORTPROPERTIES_H

Added: trunk/sources/ui/folioreportproperties.ui
===================================================================
--- trunk/sources/ui/folioreportproperties.ui	                        (rev 0)
+++ trunk/sources/ui/folioreportproperties.ui	2013-12-28 13:28:27 UTC (rev 2672)
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>FolioReportProperties</class>
+ <widget class="QWidget" name="FolioReportProperties">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QHBoxLayout" name="horizontalLayout">
+   <item>
+    <layout class="QVBoxLayout" name="verticalLayout">
+     <item>
+      <widget class="QGroupBox" name="Report_gb">
+       <property name="toolTip">
+        <string extracomment="Report de folio pouvant être liée"/>
+       </property>
+       <property name="whatsThis">
+        <string extracomment="C'est ici que vous pouvez spécifier à quel autre report de folio doit être liée celui ci "/>
+       </property>
+       <property name="title">
+        <string>Report de folio disponible :</string>
+       </property>
+       <layout class="QVBoxLayout" name="_2">
+        <property name="sizeConstraint">
+         <enum>QLayout::SetMinimumSize</enum>
+        </property>
+        <property name="leftMargin">
+         <number>0</number>
+        </property>
+        <property name="topMargin">
+         <number>2</number>
+        </property>
+        <property name="rightMargin">
+         <number>0</number>
+        </property>
+        <property name="bottomMargin">
+         <number>0</number>
+        </property>
+        <item>
+         <widget class="QScrollArea" name="scrollArea">
+          <property name="widgetResizable">
+           <bool>true</bool>
+          </property>
+          <widget class="QWidget" name="scroll_area">
+           <property name="geometry">
+            <rect>
+             <x>0</x>
+             <y>0</y>
+             <width>370</width>
+             <height>258</height>
+            </rect>
+           </property>
+           <layout class="QVBoxLayout" name="available_report_layout">
+            <property name="sizeConstraint">
+             <enum>QLayout::SetMinimumSize</enum>
+            </property>
+           </layout>
+          </widget>
+         </widget>
+        </item>
+       </layout>
+      </widget>
+     </item>
+    </layout>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>


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