[qet] [3370] Diagram command: additem, minor improvement

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


Revision: 3370
Author:   blacksun
Date:     2014-10-11 19:45:11 +0200 (Sat, 11 Oct 2014)
Log Message:
-----------
Diagram command: additem, minor improvement

Modified Paths:
--------------
    trunk/sources/diagramcommands.cpp
    trunk/sources/diagramcommands.h
    trunk/sources/qetgraphicsitem/diagramimageitem.cpp
    trunk/sources/qetgraphicsitem/diagramimageitem.h
    trunk/sources/qetgraphicsitem/qetgraphicsitem.h
    trunk/sources/qetgraphicsitem/qetshapeitem.cpp
    trunk/sources/qetgraphicsitem/qetshapeitem.h

Modified: trunk/sources/diagramcommands.cpp
===================================================================
--- trunk/sources/diagramcommands.cpp	2014-10-10 18:16:02 UTC (rev 3369)
+++ trunk/sources/diagramcommands.cpp	2014-10-11 17:45:11 UTC (rev 3370)
@@ -29,31 +29,17 @@
 #include "conductorautonumerotation.h"
 #include <QPropertyAnimation>
 
-/**
- * Specialized template function
- */
-template<>
-QString itemText <DiagramImageItem *> (DiagramImageItem *item) {
-	Q_UNUSED(item);
-	return QObject::tr("une image");
+QString itemText(const QetGraphicsItem *item) {
+	return item->name();
 }
-template<>
-QString itemText <IndependentTextItem *> (IndependentTextItem *item) {
+
+QString itemText(const IndependentTextItem *item) {
 	Q_UNUSED(item);
 	return QObject::tr("un champ texte");
 }
-template<>
-QString itemText <Element *> (Element *item) {
-	return QObject::tr("un \351l\351ment : %1").arg(item->name());
-}
-template<>
-QString itemText <QetShapeItem *> (QetShapeItem *item) {
+
+QString itemText(const Conductor *item) {
 	Q_UNUSED(item);
-	return QObject::tr("une shape");
-}
-template<>
-QString itemText <Conductor *> (Conductor *item) {
-	Q_UNUSED(item);
 	return QObject::tr("un conducteur");
 }
 

Modified: trunk/sources/diagramcommands.h
===================================================================
--- trunk/sources/diagramcommands.h	2014-10-10 18:16:02 UTC (rev 3369)
+++ trunk/sources/diagramcommands.h	2014-10-11 17:45:11 UTC (rev 3370)
@@ -33,6 +33,7 @@
 class ElementTextItem;
 class IndependentTextItem;
 class DiagramImageItem;
+class QetGraphicsItem;
 
 /**
  * @brief The AddItemCommand class
@@ -73,14 +74,10 @@
 		QPointF m_pos;
 };
 
-/**
- *Template function: return generique name of a QGraphicsItem.
- */
-template <typename T>
-QString itemText(T item) {
-	Q_UNUSED (item);
-	return QObject::tr("un item");
-}
+//Return a string to describe a QGraphicsItem
+QString itemText(const QetGraphicsItem     *item);
+QString itemText(const IndependentTextItem *item);
+QString itemText(const Conductor           *item);
 
 /**
 	This command removes content from a particular diagram.

Modified: trunk/sources/qetgraphicsitem/diagramimageitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/diagramimageitem.cpp	2014-10-10 18:16:02 UTC (rev 3369)
+++ trunk/sources/qetgraphicsitem/diagramimageitem.cpp	2014-10-11 17:45:11 UTC (rev 3370)
@@ -181,6 +181,14 @@
 }
 
 /**
+ * @brief DiagramImageItem::name
+ * @return the generic name of this item (picture)
+ */
+QString DiagramImageItem::name() const {
+	return tr("une image");
+}
+
+/**
 	Load the image from this xml element
 	@param e xml element that define an image
 */

Modified: trunk/sources/qetgraphicsitem/diagramimageitem.h
===================================================================
--- trunk/sources/qetgraphicsitem/diagramimageitem.h	2014-10-10 18:16:02 UTC (rev 3369)
+++ trunk/sources/qetgraphicsitem/diagramimageitem.h	2014-10-11 17:45:11 UTC (rev 3370)
@@ -55,6 +55,7 @@
 	virtual void editProperty();
 	void setPixmap(const QPixmap &pixmap);
 	virtual QRectF boundingRect() const;
+	virtual QString name() const;
 	
 	protected:
 	virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);

Modified: trunk/sources/qetgraphicsitem/qetgraphicsitem.h
===================================================================
--- trunk/sources/qetgraphicsitem/qetgraphicsitem.h	2014-10-10 18:16:02 UTC (rev 3369)
+++ trunk/sources/qetgraphicsitem/qetgraphicsitem.h	2014-10-11 17:45:11 UTC (rev 3370)
@@ -37,6 +37,7 @@
 	virtual void rotateBy(const qreal &);
 	virtual void applyRotation(const qreal &);
 	virtual void editProperty (){}
+	virtual QString name()const {return QString("");}
 
 	signals:
 	void positionChange(QPointF);

Modified: trunk/sources/qetgraphicsitem/qetshapeitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/qetshapeitem.cpp	2014-10-10 18:16:02 UTC (rev 3369)
+++ trunk/sources/qetgraphicsitem/qetshapeitem.cpp	2014-10-11 17:45:11 UTC (rev 3370)
@@ -371,3 +371,27 @@
 	//...or not
 	setScale(scale_);
 }
+
+/**
+ * @brief QetShapeItem::name
+ * @return the name of the curent shape.
+ */
+QString QetShapeItem::name() const {
+	switch (m_shapeType) {
+		case Line:
+			return tr("une ligne");
+			break;
+		case Rectangle:
+			return tr("un rectangle");
+			break;
+		case Ellipse:
+			return tr("une \351llipse");
+			break;
+		case Polyline:
+			return tr("une polyligne");
+			break;
+		default:
+			return tr("une shape");
+			break;
+	}
+}

Modified: trunk/sources/qetgraphicsitem/qetshapeitem.h
===================================================================
--- trunk/sources/qetgraphicsitem/qetshapeitem.h	2014-10-10 18:16:02 UTC (rev 3369)
+++ trunk/sources/qetgraphicsitem/qetshapeitem.h	2014-10-11 17:45:11 UTC (rev 3370)
@@ -58,6 +58,7 @@
 	virtual bool		toDXF	(const QString &filepath);
 
 	virtual void editProperty();
+	virtual QString name() const;
 
 	void setP2		  (QPointF P2);
 	void setNextPoint (QPointF P);


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