diff --git a/editor/customelementpart.h b/editor/customelementpart.h index dce859f43..30b34e7d8 100644 --- a/editor/customelementpart.h +++ b/editor/customelementpart.h @@ -51,6 +51,7 @@ class CustomElementPart { virtual QWidget *elementInformations() = 0; virtual void setProperty(const QString &, const QVariant &) = 0; virtual QVariant property(const QString &) = 0; + virtual bool isUseless() const = 0; virtual QETElementEditor *elementEditor() const; virtual ElementScene *elementScene() const; virtual QUndoStack &undoStack() const; diff --git a/editor/elementscene.cpp b/editor/elementscene.cpp index 000a3160e..944bb3727 100644 --- a/editor/elementscene.cpp +++ b/editor/elementscene.cpp @@ -232,20 +232,24 @@ void ElementScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) { if (e -> button() & Qt::LeftButton) { switch(behavior) { case Line: + if (qgiManager().manages(current_line)) break; undo_stack.push(new AddPartCommand(tr("ligne"), this, current_line)); emit(partsAdded()); break; case Ellipse: + if (qgiManager().manages(current_ellipse)) break; current_ellipse -> setRect(current_ellipse -> rect().normalized()); undo_stack.push(new AddPartCommand(tr("ellipse"), this, current_ellipse)); emit(partsAdded()); break; case Arc: + if (qgiManager().manages(current_arc)) break; current_arc-> setRect(current_arc -> rect().normalized()); undo_stack.push(new AddPartCommand(tr("arc"), this, current_arc)); emit(partsAdded()); break; case Circle: + if (qgiManager().manages(current_circle)) break; current_circle -> setRect(current_circle -> rect().normalized()); undo_stack.push(new AddPartCommand(tr("cercle"), this, current_circle)); emit(partsAdded()); @@ -381,6 +385,7 @@ const QDomDocument ElementScene::toXml() const { // description de l'element foreach(QGraphicsItem *qgi, zItems(true)) { if (CustomElementPart *ce = dynamic_cast(qgi)) { + if (ce -> isUseless()) continue; description.appendChild(ce -> toXml(xml_document)); } } diff --git a/editor/partarc.cpp b/editor/partarc.cpp index 9018b9468..a49b682e8 100644 --- a/editor/partarc.cpp +++ b/editor/partarc.cpp @@ -241,3 +241,13 @@ int PartArc::angle() const { int PartArc::startAngle() const { return(start_angle); } + +/** + @return true si cette partie n'est pas pertinente et ne merite pas d'etre + conservee / enregistree. + Un arc est pertinent des lors que ses dimensions et son etendue ne sont + pas nulles. +*/ +bool PartArc::isUseless() const { + return(rect().isNull() || !angle()); +} diff --git a/editor/partarc.h b/editor/partarc.h index 678172af5..aea7a1aa5 100644 --- a/editor/partarc.h +++ b/editor/partarc.h @@ -54,6 +54,7 @@ class PartArc : public QGraphicsEllipseItem, public CustomElementGraphicPart { virtual int startAngle() const; virtual void setProperty(const QString &, const QVariant &); virtual QVariant property(const QString &); + virtual bool isUseless() const; protected: QVariant itemChange(GraphicsItemChange, const QVariant &); diff --git a/editor/partcircle.cpp b/editor/partcircle.cpp index 7340ccff5..b861efca9 100644 --- a/editor/partcircle.cpp +++ b/editor/partcircle.cpp @@ -188,3 +188,12 @@ QRectF PartCircle::boundingRect() const { r.adjust(-adjust, -adjust, adjust, adjust); return(r); } + +/** + @return true si cette partie n'est pas pertinente et ne merite pas d'etre + conservee / enregistree. + Un cercle est pertinent des lors que son rayon n'est pas nul +*/ +bool PartCircle::isUseless() const { + return(rect().isNull()); +} diff --git a/editor/partcircle.h b/editor/partcircle.h index 3520dcf4f..fdc779456 100644 --- a/editor/partcircle.h +++ b/editor/partcircle.h @@ -50,6 +50,7 @@ class PartCircle : public QGraphicsEllipseItem, public CustomElementGraphicPart QPointF sceneCenter() const; virtual void setProperty(const QString &, const QVariant &); virtual QVariant property(const QString &); + virtual bool isUseless() const; protected: QVariant itemChange(GraphicsItemChange, const QVariant &); diff --git a/editor/partellipse.cpp b/editor/partellipse.cpp index ec7a603c8..1130db886 100644 --- a/editor/partellipse.cpp +++ b/editor/partellipse.cpp @@ -178,3 +178,12 @@ QVariant PartEllipse::itemChange(GraphicsItemChange change, const QVariant &valu QPointF PartEllipse::sceneTopLeft() const { return(mapToScene(rect().topLeft())); } + +/** + @return true si cette partie n'est pas pertinente et ne merite pas d'etre + conservee / enregistree. + Une ellipse est pertinente des lors que ses dimensions ne sont pas nulles +*/ +bool PartEllipse::isUseless() const { + return(rect().isNull()); +} diff --git a/editor/partellipse.h b/editor/partellipse.h index 9f7f01b69..94a17bfe0 100644 --- a/editor/partellipse.h +++ b/editor/partellipse.h @@ -48,6 +48,7 @@ class PartEllipse : public QGraphicsEllipseItem, public CustomElementGraphicPart virtual QPointF sceneTopLeft() const; virtual void setProperty(const QString &, const QVariant &); virtual QVariant property(const QString &); + virtual bool isUseless() const; protected: QVariant itemChange(GraphicsItemChange, const QVariant &); diff --git a/editor/partline.cpp b/editor/partline.cpp index 96a5d7646..9dfc94755 100644 --- a/editor/partline.cpp +++ b/editor/partline.cpp @@ -65,12 +65,6 @@ const QDomElement PartLine::toXml(QDomDocument &xml_document) const { QPointF p1(sceneP1()); QPointF p2(sceneP2()); - // cas particulier : on n'enregistre pas les lignes equivalentes a un point - if (p1 == p2) { - QDomElement *null_qdom_elmt = new QDomElement(); - return(*null_qdom_elmt); - } - QDomElement xml_element = xml_document.createElement("line"); xml_element.setAttribute("x1", p1.x()); xml_element.setAttribute("y1", p1.y()); @@ -248,3 +242,13 @@ QRectF PartLine::boundingRect() const { r.adjust(-adjust, -adjust, adjust, adjust); return(r); } + +/** + @return true si cette partie n'est pas pertinente et ne merite pas d'etre + conservee / enregistree. + Une ligne est pertinente des lors que ses deux points sont differents +*/ +bool PartLine::isUseless() const { + return(sceneP1() == sceneP2()); +} + diff --git a/editor/partline.h b/editor/partline.h index 92625c229..8b315ed58 100644 --- a/editor/partline.h +++ b/editor/partline.h @@ -51,6 +51,7 @@ class PartLine : public QGraphicsLineItem, public CustomElementGraphicPart { virtual QRectF boundingRect() const; virtual void setProperty(const QString &, const QVariant &); virtual QVariant property(const QString &); + virtual bool isUseless() const; protected: QVariant itemChange(GraphicsItemChange, const QVariant &); diff --git a/editor/partpolygon.cpp b/editor/partpolygon.cpp index 72dff8095..b797f2756 100644 --- a/editor/partpolygon.cpp +++ b/editor/partpolygon.cpp @@ -144,3 +144,22 @@ QVariant PartPolygon::itemChange(GraphicsItemChange change, const QVariant &valu } return(QGraphicsPolygonItem::itemChange(change, value)); } + + +/** + @return true si cette partie n'est pas pertinente et ne merite pas d'etre + conservee / enregistree. + Un polygone est pertinent des lors qu'il possede deux points differents. +*/ +bool PartPolygon::isUseless() const { + QPolygonF poly(polygon()); + + if (polygon().count() < 2) return(true); + + QPointF previous_point; + for (int i = 1 ; i < poly.count() ; ++ i) { + if (poly[i] != poly[i-1]) return(false); + } + + return(true); +} diff --git a/editor/partpolygon.h b/editor/partpolygon.h index ed87c8e4f..fed60d192 100644 --- a/editor/partpolygon.h +++ b/editor/partpolygon.h @@ -62,6 +62,7 @@ class PartPolygon : public QGraphicsPolygonItem, public CustomElementGraphicPart bool isClosed() const; void setProperty(const QString &, const QVariant &); virtual QVariant property(const QString &); + virtual bool isUseless() const; protected: QVariant itemChange(GraphicsItemChange, const QVariant &); diff --git a/editor/partterminal.cpp b/editor/partterminal.cpp index c92bd7e14..b059f0493 100644 --- a/editor/partterminal.cpp +++ b/editor/partterminal.cpp @@ -216,3 +216,13 @@ void PartTerminal::updateSecondPoint() { case QET::West : second_point = QPointF(ts, 0.0); break; } } + +/** + @return true si cette partie n'est pas pertinente et ne merite pas d'etre + conservee / enregistree. + Une borne est toujours pertinente ; cette fonction renvoie donc + toujours false +*/ +bool PartTerminal::isUseless() const { + return(false); +} diff --git a/editor/partterminal.h b/editor/partterminal.h index 834adb347..96c0ed00d 100644 --- a/editor/partterminal.h +++ b/editor/partterminal.h @@ -54,6 +54,7 @@ class PartTerminal : public CustomElementPart, public QGraphicsItem { void setOrientation(QET::Orientation); virtual void setProperty(const QString &, const QVariant &); virtual QVariant property(const QString &); + virtual bool isUseless() const; protected: QVariant itemChange(GraphicsItemChange, const QVariant &); diff --git a/editor/parttext.cpp b/editor/parttext.cpp index 0e2c4f1ad..89dd7f79b 100644 --- a/editor/parttext.cpp +++ b/editor/parttext.cpp @@ -207,3 +207,12 @@ QRectF PartText::boundingRect() const { r.adjust(0.0, -2.0, 0.0, 0.0); return(r); } + +/** + @return true si cette partie n'est pas pertinente et ne merite pas d'etre + conservee / enregistree. + Un texte statique n'est pas pertinent lorsque son texte est vide. +*/ +bool PartText::isUseless() const { + return(toPlainText().isEmpty()); +} diff --git a/editor/parttext.h b/editor/parttext.h index 90a3c9231..4dbd9aa78 100644 --- a/editor/parttext.h +++ b/editor/parttext.h @@ -49,6 +49,7 @@ class PartText : public QGraphicsTextItem, public CustomElementPart { void setPos(qreal, qreal); virtual void setProperty(const QString &, const QVariant &); virtual QVariant property(const QString &); + virtual bool isUseless() const; protected: virtual void focusOutEvent(QFocusEvent *); diff --git a/editor/parttextfield.cpp b/editor/parttextfield.cpp index 575ab6ca4..b15fa2f18 100644 --- a/editor/parttextfield.cpp +++ b/editor/parttextfield.cpp @@ -231,3 +231,13 @@ QRectF PartTextField::boundingRect() const { r.adjust(0.0, -2.0, 0.0, 0.0); return(r); } + +/** + @return true si cette partie n'est pas pertinente et ne merite pas d'etre + conservee / enregistree. + Un champ de texte est toujours pertinent ; cette fonction renvoie donc + toujours false +*/ +bool PartTextField::isUseless() const { + return(false); +} diff --git a/editor/parttextfield.h b/editor/parttextfield.h index 571dbd236..3ad145626 100644 --- a/editor/parttextfield.h +++ b/editor/parttextfield.h @@ -55,6 +55,7 @@ class PartTextField : public QGraphicsTextItem, public CustomElementPart { void setFollowParentRotations(bool); virtual void setProperty(const QString &, const QVariant &); virtual QVariant property(const QString &); + virtual bool isUseless() const; protected: virtual void focusOutEvent(QFocusEvent *); diff --git a/qgimanager.cpp b/qgimanager.cpp index abdd9bb9d..21c951a76 100644 --- a/qgimanager.cpp +++ b/qgimanager.cpp @@ -91,3 +91,12 @@ void QGIManager::release(const QList &qgis) { void QGIManager::setDestroyQGIOnDelete(bool b) { destroy_qgi_on_delete = b; } + +/** + Permet de savoir si ce QGIManager gere ou non un item donne + @param qgi QGraphicsItem dont il faut verifier la presence + @return true si l'item est gere, false sinon +*/ +bool QGIManager::manages(QGraphicsItem *qgi) const { + return(qgi_manager.contains(qgi)); +} diff --git a/qgimanager.h b/qgimanager.h index 686a4015e..75e7eb511 100644 --- a/qgimanager.h +++ b/qgimanager.h @@ -46,5 +46,6 @@ class QGIManager { void manage(const QList &); void release(const QList &); void setDestroyQGIOnDelete(bool); + bool manages(QGraphicsItem *) const; }; #endif