[qet] [2675] element class: replace enum linkertype by #define ( better way for use flags)

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


Revision: 2675
Author:   blacksun
Date:     2013-12-29 14:27:46 +0100 (Sun, 29 Dec 2013)
Log Message:
-----------
element class: replace enum linkertype by #define (better way for use flags)

Modified Paths:
--------------
    trunk/sources/elementprovider.cpp
    trunk/sources/elementprovider.h
    trunk/sources/qetgraphicsitem/element.h
    trunk/sources/qetgraphicsitem/ghostelement.h
    trunk/sources/qetgraphicsitem/reportelement.cpp
    trunk/sources/qetgraphicsitem/simpleelement.cpp
    trunk/sources/ui/elementpropertieswidget.cpp
    trunk/sources/ui/folioreportproperties.cpp

Modified: trunk/sources/elementprovider.cpp
===================================================================
--- trunk/sources/elementprovider.cpp	2013-12-29 13:25:09 UTC (rev 2674)
+++ trunk/sources/elementprovider.cpp	2013-12-29 13:27:46 UTC (rev 2675)
@@ -34,10 +34,10 @@
  * 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)
+ * (You can find all filter with the #define in Element.h)
  * @return
  */
-QList <Element *> ElementProvider::FreeElement(int filter) {
+QList <Element *> ElementProvider::FreeElement(const int filter) const{
 	QList <Element *> free_elmt;
 
 	//serch in all diagram

Modified: trunk/sources/elementprovider.h
===================================================================
--- trunk/sources/elementprovider.h	2013-12-29 13:25:09 UTC (rev 2674)
+++ trunk/sources/elementprovider.h	2013-12-29 13:27:46 UTC (rev 2675)
@@ -32,7 +32,7 @@
 {
 	public:
 	ElementProvider(QETProject *prj, Diagram *diagram=0);
-	QList <Element *> FreeElement(int filter);
+	QList <Element *> FreeElement(const int filter) const;
 
 	private:
 	QList <Diagram *> diag_list;

Modified: trunk/sources/qetgraphicsitem/element.h
===================================================================
--- trunk/sources/qetgraphicsitem/element.h	2013-12-29 13:25:09 UTC (rev 2674)
+++ trunk/sources/qetgraphicsitem/element.h	2013-12-29 13:27:46 UTC (rev 2675)
@@ -22,21 +22,21 @@
 #include "qetgraphicsitem.h"
 class Diagram;
 class ElementTextItem;
+
+// this define is use to know the kind of element and
+// to use flag for element provider class
+#define SIMPLE 1
+#define REPORT 2
+#define MASTER 4
+#define SLAVE 8
+#define BORNIER 16
+
 /**
 	This is the base class for electrical elements.
 */
 class Element : public QetGraphicsItem {
 	
 	Q_OBJECT
-
-	public:
-	enum linkerType{
-		simple = 1,
-		report = 2,
-		master = 4,
-		slave = 8,
-		bornier = 16
-	};
 	
 	// constructors, destructor
 	public:

Modified: trunk/sources/qetgraphicsitem/ghostelement.h
===================================================================
--- trunk/sources/qetgraphicsitem/ghostelement.h	2013-12-29 13:25:09 UTC (rev 2674)
+++ trunk/sources/qetgraphicsitem/ghostelement.h	2013-12-29 13:27:46 UTC (rev 2675)
@@ -43,7 +43,7 @@
 	// methods
 	public:
 	virtual bool fromXml(QDomElement &, QHash<int, Terminal *> &, bool = false);
-	virtual int linkType() const {return Element::simple;}
+	virtual int linkType() const {return SIMPLE;}
 	
 	protected:
 	QRectF minimalBoundingRect() const;

Modified: trunk/sources/qetgraphicsitem/reportelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/reportelement.cpp	2013-12-29 13:25:09 UTC (rev 2674)
+++ trunk/sources/qetgraphicsitem/reportelement.cpp	2013-12-29 13:27:46 UTC (rev 2675)
@@ -22,5 +22,5 @@
 {}
 
 int ReportElement::linkType() const {
-	return ReportElement::report;
+	return REPORT;
 }

Modified: trunk/sources/qetgraphicsitem/simpleelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/simpleelement.cpp	2013-12-29 13:25:09 UTC (rev 2674)
+++ trunk/sources/qetgraphicsitem/simpleelement.cpp	2013-12-29 13:27:46 UTC (rev 2675)
@@ -22,5 +22,5 @@
 {}
 
 int SimpleElement::linkType() const {
-	return SimpleElement::simple;
+	return SIMPLE;
 }

Modified: trunk/sources/ui/elementpropertieswidget.cpp
===================================================================
--- trunk/sources/ui/elementpropertieswidget.cpp	2013-12-29 13:25:09 UTC (rev 2674)
+++ trunk/sources/ui/elementpropertieswidget.cpp	2013-12-29 13:27:46 UTC (rev 2675)
@@ -90,17 +90,17 @@
 
 	//Add tab according to the element
 	switch (element_ -> linkType()) {
-		case Element::simple:
+		case SIMPLE:
 			break;
-		case Element::report:
+		case REPORT:
 			frp_ = new FolioReportProperties(element_, this);
 			tab_ -> addTab(frp_, tr("Report de folio"));
 			break;
-		case Element::master:
+		case MASTER:
 			break;
-		case Element::slave:
+		case SLAVE:
 			break;
-		case Element::bornier:
+		case BORNIER:
 			break;
 		default:
 			break;

Modified: trunk/sources/ui/folioreportproperties.cpp
===================================================================
--- trunk/sources/ui/folioreportproperties.cpp	2013-12-29 13:25:09 UTC (rev 2674)
+++ trunk/sources/ui/folioreportproperties.cpp	2013-12-29 13:27:46 UTC (rev 2675)
@@ -12,14 +12,16 @@
 	ui->setupUi(this);
 
 	ElementProvider ep(element_->diagram()->project(), element_->diagram());
-	QList <Element *> elmt_list = ep.FreeElement(Element::report);
+	QList <Element *> elmt_list = ep.FreeElement(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());
+			QString title = elmt->diagram()->title();
+			if (title.isEmpty()) title = tr("Sans titre");
+			button_text += QString(tr("Folio\240 %1 (%2), position %3.")).arg(elmt->diagram()->folioIndex() + 1)
+																		  .arg(title)
+																		  .arg(elmt->diagram() -> convertPosition(elmt -> scenePos()).toString());
 
 			QRadioButton *rb = new QRadioButton(button_text , this);
 			ui->available_report_layout->addWidget(rb);


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