diff --git a/aboutqet.cpp b/aboutqet.cpp index 0ce4eb130..a48ce3ce0 100644 --- a/aboutqet.cpp +++ b/aboutqet.cpp @@ -30,6 +30,12 @@ AboutQET::AboutQET(QWidget *parent) : QDialog(parent) { setLayout(disposition); } +/** + Destructeur +*/ +AboutQET::~AboutQET() { +} + /** @return Le titre QElectroTech avec son icone */ @@ -58,7 +64,7 @@ QWidget *AboutQET::ongletAPropos() const { QLabel *apropos = new QLabel( tr("QElectroTech, une application de r\351alisation de sch\351mas \351lectriques.") + "

" + - tr("\251 2006 Les d\351veloppeurs de QElectroTech") + + tr("\251 2006-2007 Les d\351veloppeurs de QElectroTech") + "

" "" "http://qelectrotech.tuxfamily.org/" diff --git a/aboutqet.h b/aboutqet.h index 307c38895..db9cc132d 100644 --- a/aboutqet.h +++ b/aboutqet.h @@ -1,18 +1,26 @@ #ifndef ABOUTQET_H - #define ABOUTQET_H - #include - /** - Cette classe represente la boite de dialogue - « A propos de QElectroTech » - */ - class AboutQET : public QDialog { - Q_OBJECT - public: - AboutQET(QWidget * = 0); - private: - QWidget *titre() const; - QWidget *ongletAPropos() const; - QWidget *ongletAuteurs() const; - QWidget *ongletLicence() const; - }; +#define ABOUTQET_H +#include +/** + Cette classe represente la boite de dialogue + « A propos de QElectroTech » +*/ +class AboutQET : public QDialog { + Q_OBJECT + + // constructeurs, destructeur + public: + AboutQET(QWidget * = 0); + virtual ~AboutQET(); + + private: + AboutQET(AboutQET &); + + // methodes + private: + QWidget *titre() const; + QWidget *ongletAPropos() const; + QWidget *ongletAuteurs() const; + QWidget *ongletLicence() const; +}; #endif diff --git a/borderinset.h b/borderinset.h index 21426f47d..1c9c32178 100644 --- a/borderinset.h +++ b/borderinset.h @@ -1,98 +1,108 @@ #ifndef BORDERINSET_H - #define BORDERINSET_H - #include - #include - #include - #include - /** - Cette classe represente l'ensemble bordure + cartouche qui encadre le - schema electrique. - */ - class BorderInset : public QObject { - Q_OBJECT - public: - BorderInset(QObject * = 0); - ~BorderInset(); - void draw(QPainter *, qreal = 0.0, qreal = 0.0); - - // methodes d'acces en lecture aux dimensions - int nbColumn() const { return(nb_columns); } - qreal columnsWidth() const { return(columns_width); } - qreal columnsHeaderHeight() const { return(columns_header_height); } - qreal columnsHeight() const { return(columns_height); } - qreal borderWidth() const { return(nb_columns * columns_width); } - qreal borderHeight() const { return(columns_height + inset_height); } - qreal insetWidth() const { return(inset_width); } - qreal insetHeight() const { return(inset_height); } - qreal minColumnsHeight() const { return(min_columns_height); } - int minNbColumns() const { return(min_nb_columns); } - - // methodes d'acces en lecture aux informations du cartouche - QString author() const { return(bi_author); } - QDate date() const { return(bi_date); } - QString title() const { return(bi_title); } - QString folio() const { return(bi_folio); } - QString fileName() const { return(bi_filename); } - - // methodes d'acces en lecture aux options - bool insetIsDisplayed() const { return(display_inset); } - bool columnsAreDisplayed() const { return(display_columns); } - bool borderIsDisplayed() const { return(display_border); } - - // methodes d'acces en ecriture aux dimensions - void addColumn (); - void removeColumn (); - void setNbColumns (int); - void setColumnsWidth (const qreal &); - void setColumnsHeaderHeight(const qreal &); - void setColumnsHeight (const qreal &); - void setInsetWidth (const qreal &); - void setInsetHeight (const qreal &); - - // methodes d'acces en ecriture aux informations du cartouche - void setAuthor (const QString &author) { bi_author = author; } - void setDate (const QDate &date) { bi_date = date; } - void setTitle (const QString &title) { bi_title = title; } - void setFolio (const QString &folio) { bi_folio = folio; } - void setFileName (const QString &filename) { bi_filename = filename; } - - // methodes d'acces en ecriture aux options - void displayInset (bool di) { display_inset = di; } - void displayColumns (bool dc) { display_columns = dc; } - void displayBorder (bool db) { display_border = db; } - - private: - // informations du cartouche - QString bi_author; - QDate bi_date; - QString bi_title; - QString bi_folio; // vraiment necessaire ce truc ? - QString bi_filename; // meme remarque - - // dimensions du cadre et du cartouche - int nb_columns; - int min_nb_columns; - qreal columns_width; - qreal columns_header_height; - qreal columns_height; - qreal min_columns_height; - qreal inset_width; - qreal inset_height; - - // rectangles utilises pour le dessin - QRectF border; - QRectF inset; - QRectF inset_author; - QRectF inset_date; - QRectF inset_title; - QRectF inset_file; - QRectF inset_folio; - - // booleens pour les options de dessin - bool display_inset; - bool display_columns; - bool display_border; - - void updateRectangles(); - }; +#define BORDERINSET_H +#include +#include +#include +#include +/** + Cette classe represente l'ensemble bordure + cartouche qui encadre le + schema electrique. +*/ +class BorderInset : public QObject { + Q_OBJECT + + // constructeurs, destructeur + public: + BorderInset(QObject * = 0); + virtual ~BorderInset(); + + private: + BorderInset(const BorderInset &); + + // methodes + public: + void draw(QPainter *, qreal = 0.0, qreal = 0.0); + + // methodes d'acces en lecture aux dimensions + int nbColumn() const { return(nb_columns); } + qreal columnsWidth() const { return(columns_width); } + qreal columnsHeaderHeight() const { return(columns_header_height); } + qreal columnsHeight() const { return(columns_height); } + qreal borderWidth() const { return(nb_columns * columns_width); } + qreal borderHeight() const { return(columns_height + inset_height); } + qreal insetWidth() const { return(inset_width); } + qreal insetHeight() const { return(inset_height); } + qreal minColumnsHeight() const { return(min_columns_height); } + int minNbColumns() const { return(min_nb_columns); } + + // methodes d'acces en lecture aux informations du cartouche + QString author() const { return(bi_author); } + QDate date() const { return(bi_date); } + QString title() const { return(bi_title); } + QString folio() const { return(bi_folio); } + QString fileName() const { return(bi_filename); } + + // methodes d'acces en lecture aux options + bool insetIsDisplayed() const { return(display_inset); } + bool columnsAreDisplayed() const { return(display_columns); } + bool borderIsDisplayed() const { return(display_border); } + + // methodes d'acces en ecriture aux dimensions + void addColumn (); + void removeColumn (); + void setNbColumns (int); + void setColumnsWidth (const qreal &); + void setColumnsHeaderHeight(const qreal &); + void setColumnsHeight (const qreal &); + void setInsetWidth (const qreal &); + void setInsetHeight (const qreal &); + + // methodes d'acces en ecriture aux informations du cartouche + void setAuthor (const QString &author) { bi_author = author; } + void setDate (const QDate &date) { bi_date = date; } + void setTitle (const QString &title) { bi_title = title; } + void setFolio (const QString &folio) { bi_folio = folio; } + void setFileName (const QString &filename) { bi_filename = filename; } + + // methodes d'acces en ecriture aux options + void displayInset (bool di) { display_inset = di; } + void displayColumns (bool dc) { display_columns = dc; } + void displayBorder (bool db) { display_border = db; } + + private: + void updateRectangles(); + + // attributs + private: + // informations du cartouche + QString bi_author; + QDate bi_date; + QString bi_title; + QString bi_folio; // vraiment necessaire ce truc ? + QString bi_filename; // meme remarque + + // dimensions du cadre et du cartouche + int nb_columns; + int min_nb_columns; + qreal columns_width; + qreal columns_header_height; + qreal columns_height; + qreal min_columns_height; + qreal inset_width; + qreal inset_height; + + // rectangles utilises pour le dessin + QRectF border; + QRectF inset; + QRectF inset_author; + QRectF inset_date; + QRectF inset_title; + QRectF inset_file; + QRectF inset_folio; + + // booleens pour les options de dessin + bool display_inset; + bool display_columns; + bool display_border; +}; #endif diff --git a/conducer.cpp b/conducer.cpp index cc8dc1c14..85f4d0953 100644 --- a/conducer.cpp +++ b/conducer.cpp @@ -51,6 +51,21 @@ Conducer::Conducer(Terminal *p1, Terminal* p2, Element *parent, QGraphicsScene * calculateTextItemPosition(); } +/** + Destructeur + Detruit le conducteur ainsi que ses segments. Il ne detruit pas les bornes + mais s'en detache +*/ +Conducer::~Conducer() { +// qDebug() << "~Conducer()" << (void *)this; + // se detache des bornes + if (!isDestroyed()) destroy(); + + // supprime les segments + while (segments -> hasNextSegment()) delete segments -> nextSegment(); + delete segments; +} + /** Met a jour la representation graphique du conducteur. @param rect Rectangle a mettre a jour @@ -632,7 +647,7 @@ qreal Conducer::conducer_bound(qreal tobound, qreal bound, bool positive) { /** @return Le nombre de segments composant le conducteur. */ -int Conducer::nbSegments() { +int Conducer::nbSegments() const { if (segments == NULL) return(0); int nb_seg = 1; ConducerSegment *segment = segments; @@ -701,7 +716,7 @@ void Conducer::pointsToSegments(QList points_list) { @param point point cliquable @return true si l'on peut considerer que le point a ete clique, false sinon */ -bool Conducer::hasClickedOn(QPointF press_point, QPointF point) { +bool Conducer::hasClickedOn(QPointF press_point, QPointF point) const { return ( press_point.x() >= point.x() - 5.0 &&\ press_point.x() < point.x() + 5.0 &&\ diff --git a/conducer.h b/conducer.h index 1c113e935..85981228a 100644 --- a/conducer.h +++ b/conducer.h @@ -1,79 +1,88 @@ #ifndef CONDUCTEUR_H - #define CONDUCTEUR_H - #include - #include "terminal.h" - class ConducerSegment; - class Element; - /** - Cette classe represente un conducteur. Un conducteur relie deux bornes d'element. - */ - class Conducer : public QGraphicsPathItem { - public: - enum { Type = UserType + 1001 }; - virtual int type() const { return Type; } - Conducer(Terminal *, Terminal *, Element * = 0, QGraphicsScene * = 0); - //virtual ~Conducer(); - - void destroy(); - bool isDestroyed() const { return(destroyed); } - void updateWithNewPos(const QRectF &, const Terminal *, const QPointF &); - void update(const QRectF & = QRectF()); - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); - QRectF boundingRect() const; - virtual QPainterPath shape() const; - qreal length(); - ConducerSegment *middleSegment(); - static bool valideXml(QDomElement &); - bool fromXml(QDomElement &); - QDomElement toXml(QDomDocument &, QHash &) const; - - ///Premiere borne a laquelle le fil est rattache - Terminal *terminal1; - ///Deuxieme borne a laquelle le fil est rattache - Terminal *terminal2; - - protected: - void mousePressEvent(QGraphicsSceneMouseEvent *); - void mouseMoveEvent(QGraphicsSceneMouseEvent *); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *); - void hoverMoveEvent(QGraphicsSceneHoverEvent *); - - private: - /// booleen indiquant si le fil est encore valide - bool destroyed; - QGraphicsTextItem *text_item; - ConducerSegment *segments; - QList moves_x; - QList moves_y; - qreal orig_dist_2_terms_x; - qreal orig_dist_2_terms_y; - bool type_trajet_x; - QPointF press_point; - bool moving_point; - bool moving_segment; - int moved_point; - qreal previous_z_value; - ConducerSegment *moved_segment; - bool modified_path; - static QPen conducer_pen; - static QBrush conducer_brush; - static bool pen_and_brush_initialized; - - void segmentsToPath(); - void updatePoints(); - void priv_calculeConducer(const QPointF &, Terminal::Orientation, const QPointF &, Terminal::Orientation); - void priv_modifieConducer(const QPointF &, Terminal::Orientation, const QPointF &, Terminal::Orientation); - int nbSegments(); - - QList segmentsToPoints() const; - void pointsToSegments(QList); - bool hasClickedOn(QPointF, QPointF); - void calculateTextItemPosition(); - static QPointF extendTerminal(const QPointF &, Terminal::Orientation, qreal = 12.0); - static bool surLeMemeAxe(Terminal::Orientation, Terminal::Orientation); - static bool estHorizontale(Terminal::Orientation a); - static bool estVerticale(Terminal::Orientation a); - static qreal conducer_bound(qreal tobound, qreal bound1, qreal bound2); - static qreal conducer_bound(qreal tobound, qreal bound, bool positive); - }; +#define CONDUCTEUR_H +#include +#include "terminal.h" +class ConducerSegment; +class Element; +/** + Cette classe represente un conducteur. Un conducteur relie deux bornes d'element. +*/ +class Conducer : public QGraphicsPathItem { + + // constructeurs, destructeur + public: + Conducer(Terminal *, Terminal *, Element * = 0, QGraphicsScene * = 0); + virtual ~Conducer(); + + private: + Conducer(const Conducer &); + + // attributs + public: + enum { Type = UserType + 1001 }; + ///Premiere borne a laquelle le fil est rattache + Terminal *terminal1; + ///Deuxieme borne a laquelle le fil est rattache + Terminal *terminal2; + + private: + /// booleen indiquant si le fil est encore valide + bool destroyed; + QGraphicsTextItem *text_item; + ConducerSegment *segments; + QList moves_x; + QList moves_y; + qreal orig_dist_2_terms_x; + qreal orig_dist_2_terms_y; + bool type_trajet_x; + QPointF press_point; + bool moving_point; + bool moving_segment; + int moved_point; + qreal previous_z_value; + ConducerSegment *moved_segment; + bool modified_path; + static QPen conducer_pen; + static QBrush conducer_brush; + static bool pen_and_brush_initialized; + + // methodes + public: + virtual int type() const { return Type; } + void destroy(); + bool isDestroyed() const { return(destroyed); } + void updateWithNewPos(const QRectF &, const Terminal *, const QPointF &); + void update(const QRectF & = QRectF()); + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); + QRectF boundingRect() const; + virtual QPainterPath shape() const; + qreal length(); + ConducerSegment *middleSegment(); + static bool valideXml(QDomElement &); + bool fromXml(QDomElement &); + QDomElement toXml(QDomDocument &, QHash &) const; + + protected: + void mousePressEvent(QGraphicsSceneMouseEvent *); + void mouseMoveEvent(QGraphicsSceneMouseEvent *); + void mouseReleaseEvent(QGraphicsSceneMouseEvent *); + void hoverMoveEvent(QGraphicsSceneHoverEvent *); + + private: + void segmentsToPath(); + void updatePoints(); + void priv_calculeConducer(const QPointF &, Terminal::Orientation, const QPointF &, Terminal::Orientation); + void priv_modifieConducer(const QPointF &, Terminal::Orientation, const QPointF &, Terminal::Orientation); + int nbSegments() const; + QList segmentsToPoints() const; + void pointsToSegments(QList); + bool hasClickedOn(QPointF, QPointF) const; + void calculateTextItemPosition(); + static QPointF extendTerminal(const QPointF &, Terminal::Orientation, qreal = 12.0); + static bool surLeMemeAxe(Terminal::Orientation, Terminal::Orientation); + static bool estHorizontale(Terminal::Orientation a); + static bool estVerticale(Terminal::Orientation a); + static qreal conducer_bound(qreal tobound, qreal bound1, qreal bound2); + static qreal conducer_bound(qreal tobound, qreal bound, bool positive); +}; #endif diff --git a/conducersegment.cpp b/conducersegment.cpp index ba4229ceb..b99d6b8c1 100644 --- a/conducersegment.cpp +++ b/conducersegment.cpp @@ -8,9 +8,15 @@ @param cs1 Le segment precedent @param cs2 Le segment suivant */ -ConducerSegment::ConducerSegment(QPointF p1, QPointF p2, ConducerSegment *cs1, ConducerSegment *cs2) { - setFirstPoint(p1); - setSecondPoint(p2); +ConducerSegment::ConducerSegment( + const QPointF &p1, + const QPointF &p2, + ConducerSegment *cs1, + ConducerSegment *cs2 +) : +point1(p1), +point2(p2) +{ setPreviousSegment(cs1); setNextSegment(cs2); } @@ -19,6 +25,7 @@ ConducerSegment::ConducerSegment(QPointF p1, QPointF p2, ConducerSegment *cs1, C Destructeur - Relie le segment precedent au suivant */ ConducerSegment::~ConducerSegment() { + //qDebug() << "~ConducerSegment()" << (void *)this; if (hasPreviousSegment()) previousSegment() -> setNextSegment(nextSegment()); if (hasNextSegment()) nextSegment() -> setPreviousSegment(previousSegment()); } @@ -32,7 +39,7 @@ ConducerSegment::~ConducerSegment() { @param possible_dx La valeur du mouvement possible (au maximum) @return true si le mouvement est possible ; false s'il doit etre limite */ -bool ConducerSegment::canMove1stPointX(qreal asked_dx, qreal &possible_dx) { +bool ConducerSegment::canMove1stPointX(const qreal &asked_dx, qreal &possible_dx) const { Q_ASSERT_X(isVertical(), "ConducerSegment::canMove1stPointX", "segment non vertical"); @@ -91,7 +98,7 @@ bool ConducerSegment::canMove1stPointX(qreal asked_dx, qreal &possible_dx) { @param possible_dx La valeur du mouvement possible (au maximum) @return true si le mouvement est possible ; false s'il doit etre limite */ -bool ConducerSegment::canMove2ndPointX(qreal asked_dx, qreal &possible_dx) { +bool ConducerSegment::canMove2ndPointX(const qreal &asked_dx, qreal &possible_dx) const { Q_ASSERT_X(isVertical(), "ConducerSegment::canMove2ndPointX", "segment non vertical"); @@ -150,7 +157,7 @@ bool ConducerSegment::canMove2ndPointX(qreal asked_dx, qreal &possible_dx) { @param possible_dy La valeur du mouvement possible (au maximum) @return true si le mouvement est possible ; false s'il doit etre limite */ -bool ConducerSegment::canMove1stPointY(qreal asked_dy, qreal &possible_dy) { +bool ConducerSegment::canMove1stPointY(const qreal &asked_dy, qreal &possible_dy) const { Q_ASSERT_X(isHorizontal(), "ConducerSegment::canMove1stPointY", "segment non horizontal"); @@ -209,7 +216,7 @@ bool ConducerSegment::canMove1stPointY(qreal asked_dy, qreal &possible_dy) { @param possible_dy La valeur du mouvement possible (au maximum) @return true si le mouvement est possible ; false s'il doit etre limite */ -bool ConducerSegment::canMove2ndPointY(qreal asked_dy, qreal &possible_dy) { +bool ConducerSegment::canMove2ndPointY(const qreal &asked_dy, qreal &possible_dy) const { Q_ASSERT_X(isHorizontal(), "ConducerSegment::canMove2ndPointY", "segment non horizontal"); @@ -264,7 +271,7 @@ bool ConducerSegment::canMove2ndPointY(qreal asked_dy, qreal &possible_dy) { Gere les mouvements sur l'axe horizontal @param dx taille du deplacement en pixels */ -void ConducerSegment::moveX(qreal dx) { +void ConducerSegment::moveX(const qreal &dx) { if (isHorizontal()) return; Q_ASSERT_X(isVertical(), "ConducerSegment::moveX", "segment non vertical"); @@ -312,7 +319,7 @@ void ConducerSegment::moveX(qreal dx) { Gere les mouvements sur l'axe vertical @param dx taille du deplacement en pixels */ -void ConducerSegment::moveY(qreal dy) { +void ConducerSegment::moveY(const qreal &dy) { if (isVertical()) return; Q_ASSERT_X(isHorizontal(), "ConducerSegment::moveY", "segment non horizontal"); @@ -449,42 +456,42 @@ void ConducerSegment::setNextSegment(ConducerSegment *ns) { /** @return Le segment precedent */ -ConducerSegment *ConducerSegment::previousSegment() { +ConducerSegment *ConducerSegment::previousSegment() const { return(previous_segment); } /** @return Le segment suivant */ -ConducerSegment *ConducerSegment::nextSegment() { +ConducerSegment *ConducerSegment::nextSegment() const { return(next_segment); } /** @return true si le segment est vertical, false sinon */ -bool ConducerSegment::isVertical() { +bool ConducerSegment::isVertical() const { return(point1.x() == point2.x()); } /** @return true si le segment est horizontal, false sinon */ -bool ConducerSegment::isHorizontal() { +bool ConducerSegment::isHorizontal() const { return(point1.y() == point2.y()); } /** @return le premier point du segment */ -QPointF ConducerSegment::firstPoint() { +QPointF ConducerSegment::firstPoint() const { return(point1); } /** @return le second point du segment */ -QPointF ConducerSegment::secondPoint() { +QPointF ConducerSegment::secondPoint() const { return(point2); } @@ -492,7 +499,7 @@ QPointF ConducerSegment::secondPoint() { Permet de changer la position du premier point du segment @param p La nouvelle position du premier point */ -void ConducerSegment::setFirstPoint(QPointF p) { +void ConducerSegment::setFirstPoint(const QPointF &p) { point1 = p; } @@ -500,28 +507,28 @@ void ConducerSegment::setFirstPoint(QPointF p) { Permet de changer la position du second point du segment @param p La nouvelle position du second point */ -void ConducerSegment::setSecondPoint(QPointF p) { +void ConducerSegment::setSecondPoint(const QPointF &p) { point2 = p; } /** @return true si le segment a un segment precedent, false sinon */ -bool ConducerSegment::hasPreviousSegment() { +bool ConducerSegment::hasPreviousSegment() const { return(previous_segment != NULL); } /** @return true si le segment a un segment suivant, false sinon */ -bool ConducerSegment::hasNextSegment() { +bool ConducerSegment::hasNextSegment() const { return(next_segment != NULL); } /** @return Le centre du rectangle delimitant le conducteur */ -QPointF ConducerSegment::middle() { +QPointF ConducerSegment::middle() const { return( QPointF( (point1.x() + point2.x()) / 2.0, @@ -533,7 +540,7 @@ QPointF ConducerSegment::middle() { /** @return La longueur du conducteur */ -qreal ConducerSegment::length() { +qreal ConducerSegment::length() const { if (isHorizontal()) { return(secondPoint().x() - firstPoint().x()); } else { diff --git a/conducersegment.h b/conducersegment.h index 2d8aaa5c7..3e4937132 100644 --- a/conducersegment.h +++ b/conducersegment.h @@ -1,43 +1,47 @@ #ifndef CONDUCER_SEGMENT_H - #define CONDUCER_SEGMENT_H - #include - /** - Cette classe represente un segment de conducteur. - */ - class ConducerSegment { - // constructeurs et destructeur - public: - ConducerSegment(QPointF, QPointF, ConducerSegment * = NULL, ConducerSegment * = NULL); - ~ConducerSegment(); - - // attributs - private: - ConducerSegment *previous_segment; - ConducerSegment *next_segment; - QPointF point1; - QPointF point2; - - // methodes - public: - void moveX(qreal); - void moveY(qreal); - ConducerSegment *previousSegment(); - ConducerSegment *nextSegment(); - bool hasPreviousSegment(); - bool hasNextSegment(); - void setPreviousSegment(ConducerSegment *); - void setNextSegment(ConducerSegment *); - QPointF firstPoint(); - QPointF secondPoint(); - void setFirstPoint(QPointF); - void setSecondPoint(QPointF); - QPointF middle(); - bool isHorizontal(); - bool isVertical(); - qreal length(); - bool canMove1stPointX(qreal, qreal &); - bool canMove2ndPointX(qreal, qreal &); - bool canMove1stPointY(qreal, qreal &); - bool canMove2ndPointY(qreal, qreal &); - }; +#define CONDUCER_SEGMENT_H +#include +/** + Cette classe represente un segment de conducteur. +*/ +class ConducerSegment { + + // constructeurs, destructeur + public: + ConducerSegment(const QPointF &, const QPointF &, ConducerSegment * = NULL, ConducerSegment * = NULL); + virtual ~ConducerSegment(); + + private: + ConducerSegment(const ConducerSegment &); + + // attributs + private: + ConducerSegment *previous_segment; + ConducerSegment *next_segment; + QPointF point1; + QPointF point2; + + // methodes + public: + void moveX(const qreal &); + void moveY(const qreal &); + ConducerSegment *previousSegment() const; + ConducerSegment *nextSegment() const; + bool hasPreviousSegment() const; + bool hasNextSegment() const; + void setPreviousSegment(ConducerSegment *); + void setNextSegment(ConducerSegment *); + QPointF firstPoint() const; + QPointF secondPoint() const; + void setFirstPoint(const QPointF &); + void setSecondPoint(const QPointF &); + QPointF middle() const; + bool isHorizontal() const; + bool isVertical() const; + qreal length() const; + bool canMove1stPointX(const qreal &, qreal &) const; + bool canMove2ndPointX(const qreal &, qreal &) const; + bool canMove1stPointY(const qreal &, qreal &) const; + bool canMove2ndPointY(const qreal &, qreal &) const; +}; #endif diff --git a/customelement.cpp b/customelement.cpp index 12371bfb9..69ed6a62a 100644 --- a/customelement.cpp +++ b/customelement.cpp @@ -156,6 +156,12 @@ CustomElement::CustomElement(QString &nom_fichier, QGraphicsItem *qgi, Diagram * elmt_etat = 0; } +/** + Destructeur +*/ +CustomElement::~CustomElement() { +} + /** @return Le nombre de bornes que l'element possede */ diff --git a/customelement.h b/customelement.h index c40558606..a06c5bd11 100644 --- a/customelement.h +++ b/customelement.h @@ -1,43 +1,102 @@ #ifndef ELEMENTPERSO_H - #define ELEMENTPERSO_H - #include "fixedelement.h" - #include - /** - Cette classe represente un element electrique. Elle est utilisable - comme un element fixe. La difference est que l'element perso lit - sa description (noms, dessin, comportement) dans un fichier XML a fournir - en parametre. - */ - class CustomElement : public FixedElement { - public: - CustomElement(QString &, QGraphicsItem * = 0, Diagram * = 0, int * = NULL); - virtual int nbTerminals() const; - virtual void paint(QPainter *, const QStyleOptionGraphicsItem *); - inline QString typeId() const { return(nomfichier); } - inline QString fichier() const { return(nomfichier); } - inline bool isNull() const { return(elmt_etat != 0); } - inline int etat() const { return(elmt_etat); } - inline QString nom() const { return(priv_nom); } - - private: - int elmt_etat; // contient le code d'erreur si l'instanciation a echoue ou 0 si l'instanciation s'est bien passe - QString priv_nom; - QString nomfichier; - QPicture dessin; - bool parseElement(QDomElement &, QPainter &, Diagram *); - bool parseLine(QDomElement &, QPainter &); - bool parseEllipse(QDomElement &, QPainter &); - bool parseCircle(QDomElement &, QPainter &); - bool parseArc(QDomElement &, QPainter &); - bool parsePolygon(QDomElement &, QPainter &); - bool parseText(QDomElement &, QPainter &); - bool parseInput(QDomElement &, Diagram *); - bool parseTerminal(QDomElement &, Diagram *); - void setQPainterAntiAliasing(QPainter &, bool); - bool attributeIsAnInteger(QDomElement &, QString, int * = NULL); - bool attributeIsAReal(QDomElement &, QString, double * = NULL); - bool validOrientationAttribute(QDomElement &); - void setPainterStyle(QDomElement &, QPainter &); - int nb_terminals; - }; +#define ELEMENTPERSO_H +#include "fixedelement.h" +#include +/** + Cette classe represente un element electrique. Elle est utilisable + comme un element fixe. La difference est que l'element perso lit + sa description (noms, dessin, comportement) dans un fichier XML a fournir + en parametre. +*/ +class CustomElement : public FixedElement { + // constructeurs, destructeur + public: + CustomElement(QString &, QGraphicsItem * = 0, Diagram * = 0, int * = NULL); + virtual ~CustomElement(); + + private: + CustomElement(const CustomElement &); + + // attributs + private: + int elmt_etat; // contient le code d'erreur si l'instanciation a echoue ou 0 si l'instanciation s'est bien passe + QString priv_nom; + QString nomfichier; + QPicture dessin; + int nb_terminals; + + // methodes + public: + virtual int nbTerminals() const; + virtual void paint(QPainter *, const QStyleOptionGraphicsItem *); + QString typeId() const; + QString fichier() const; + bool isNull() const; + int etat() const; + QString nom() const; + + private: + bool parseElement(QDomElement &, QPainter &, Diagram *); + bool parseLine(QDomElement &, QPainter &); + bool parseEllipse(QDomElement &, QPainter &); + bool parseCircle(QDomElement &, QPainter &); + bool parseArc(QDomElement &, QPainter &); + bool parsePolygon(QDomElement &, QPainter &); + bool parseText(QDomElement &, QPainter &); + bool parseInput(QDomElement &, Diagram *); + bool parseTerminal(QDomElement &, Diagram *); + void setQPainterAntiAliasing(QPainter &, bool); + bool attributeIsAnInteger(QDomElement &, QString, int * = NULL); + bool attributeIsAReal(QDomElement &, QString, double * = NULL); + bool validOrientationAttribute(QDomElement &); + void setPainterStyle(QDomElement &, QPainter &); +}; + +/** + @return L'ID du type de l'element ; pour un CustomElement, cela revient au + nom du fichier + @see fichier() +*/ +inline QString CustomElement::typeId() const { + return(nomfichier); +} + +/** + @return L'adresse du fichier contenant la description XML de cet element +*/ +inline QString CustomElement::fichier() const { + return(nomfichier); +} + +/** + @return true si cet element est nul, c'est-a-dire si le chargement de sa + description XML a echoue +*/ +inline bool CustomElement::isNull() const { + return(elmt_etat != 0); +} + +/** + @return Un entier representant l'etat de l'element : + - 0 : L'instanciation a reussi + - 1 : Le fichier n'existe pas + - 2 : Le fichier n'a pu etre ouvert + - 3 : Le fichier n'est pas un document XML + - 4 : Le document XML n'a pas une "definition" comme racine + - 5 : Les attributs de la definition ne sont pas presents et / ou valides + - 6 : La definition est vide + - 7 : L'analyse d'un element XML decrivant une partie du dessin de l'element a echoue + - 8 : Aucune partie du dessin n'a pu etre chargee +*/ +inline int CustomElement::etat() const { + return(elmt_etat); +} + +/** + @return Le nom de l'element +*/ +inline QString CustomElement::nom() const { + return(priv_nom); +} + #endif diff --git a/diagram.cpp b/diagram.cpp index b8cf22975..495ef5eef 100644 --- a/diagram.cpp +++ b/diagram.cpp @@ -10,19 +10,25 @@ */ Diagram::Diagram(QObject *parent) : QGraphicsScene(parent) { setBackgroundBrush(Qt::white); - poseur_de_conducer = new QGraphicsLineItem(0, 0); - poseur_de_conducer -> setZValue(1000000); + conducer_setter = new QGraphicsLineItem(0, 0); + conducer_setter -> setZValue(1000000); QPen t; t.setColor(Qt::black); t.setWidthF(1.5); t.setStyle(Qt::DashLine); - poseur_de_conducer -> setPen(t); - poseur_de_conducer -> setLine(QLineF(QPointF(0.0, 0.0), QPointF(0.0, 0.0))); + conducer_setter -> setPen(t); + conducer_setter -> setLine(QLineF(QPointF(0.0, 0.0), QPointF(0.0, 0.0))); draw_grid = true; use_border = true; connect(this, SIGNAL(changed(const QList &)), this, SLOT(slot_checkSelectionEmptinessChange())); } +/** + Destructeur +*/ +Diagram::~Diagram() { +}; + /** Dessine l'arriere-plan du schema, cad la grille. @param p Le QPainter a utiliser pour dessiner @@ -41,7 +47,7 @@ void Diagram::drawBackground(QPainter *p, const QRectF &r) { p -> setBrush(Qt::white); p -> drawRect(r); - if (draw_grid) { + if (draw_grid && r.width() < 2500 && r.height() < 2500) { // dessine les points de la grille p -> setPen(Qt::black); p -> setBrush(Qt::NoBrush); diff --git a/diagram.h b/diagram.h index ae9cd6133..2dac8eb1f 100644 --- a/diagram.h +++ b/diagram.h @@ -11,38 +11,50 @@ class Element; class Terminal; class Diagram : public QGraphicsScene { Q_OBJECT - enum BorderOptions { EmptyBorder, Inset, Columns }; + + // constructeurs, destructeur public: Diagram(QObject * = 0); + virtual ~Diagram(); + + private: + Diagram(const Diagram &diagram); + + // attributs + public: + enum BorderOptions { EmptyBorder, Inset, Columns }; + BorderInset border_and_inset; + + private: + QGraphicsLineItem *conducer_setter; + bool draw_grid; + bool use_border; + + // methodes + public: void drawBackground(QPainter *, const QRectF &); // fonctions relatives a la pose de conducteurs - void poseConducer(bool); - - void setDepart (QPointF); - void setArrivee(QPointF); + void setConducer(bool); + void setConducerStart (QPointF); + void setConducerStop(QPointF); // fonctions relatives a l'import / export XML QDomDocument toXml(bool = true); bool fromXml(QDomDocument &, QPointF = QPointF(), bool = true); // fonctions relatives aux options graphiques - void setAffichageGrille(bool); + void setDisplayGrid(bool); bool displayGrid(); void setUseBorder(bool); bool useBorder(); void setBorderOptions(BorderOptions); BorderOptions borderOptions(); - BorderInset border_and_inset; + QRectF border() const; QImage toImage(int = -1, int = -1, Qt::AspectRatioMode = Qt::KeepAspectRatio); QSize imageSize() const; - private: - QGraphicsLineItem *poseur_de_conducer; - bool draw_grid; - bool use_border; - private slots: void slot_checkSelectionChange(); void slot_checkSelectionEmptinessChange(); @@ -58,11 +70,11 @@ class Diagram : public QGraphicsScene { bornes. @param true pour ajouter le poseur de conducteur, false pour l'enlever */ -inline void Diagram::poseConducer(bool pf) { +inline void Diagram::setConducer(bool pf) { if (pf) { - if (!poseur_de_conducer -> scene()) addItem(poseur_de_conducer); + if (!conducer_setter -> scene()) addItem(conducer_setter); } else { - if (poseur_de_conducer -> scene()) removeItem(poseur_de_conducer); + if (conducer_setter -> scene()) removeItem(conducer_setter); } } @@ -70,23 +82,23 @@ inline void Diagram::poseConducer(bool pf) { Specifie les coordonnees du point de depart du poseur de conducteur @param d Le nouveau point de depart du poseur de conducteur */ -inline void Diagram::setDepart(QPointF d) { - poseur_de_conducer -> setLine(QLineF(d, poseur_de_conducer -> line().p2())); +inline void Diagram::setConducerStart(QPointF d) { + conducer_setter -> setLine(QLineF(d, conducer_setter -> line().p2())); } /** Specifie les coordonnees du point d'arrivee du poseur de conducteur @param d Le nouveau point d'arrivee du poseur de conducteur */ -inline void Diagram::setArrivee(QPointF a) { - poseur_de_conducer -> setLine(QLineF(poseur_de_conducer -> line().p1(), a)); +inline void Diagram::setConducerStop(QPointF a) { + conducer_setter -> setLine(QLineF(conducer_setter -> line().p1(), a)); } /** Permet de specifier si la grille du schema doit etre dessinee ou non @param dg true pour afficher la grille, false pour ne pas l'afficher */ -inline void Diagram::setAffichageGrille(bool dg) { +inline void Diagram::setDisplayGrid(bool dg) { draw_grid = dg; } diff --git a/diagramview.cpp b/diagramview.cpp index 2726762a0..695a621d8 100644 --- a/diagramview.cpp +++ b/diagramview.cpp @@ -2,6 +2,7 @@ #include "diagram.h" #include "customelement.h" #include "exportdialog.h" +#include "conducer.h" /** Initialise le DiagramView @@ -40,6 +41,12 @@ DiagramView::DiagramView(QWidget *parent) : QGraphicsView(parent) { initialise(); } +/** + Destructeur +*/ +DiagramView::~DiagramView() { +} + /** appelle la methode select sur tous les elements de la liste d'elements */ @@ -443,9 +450,9 @@ void DiagramView::dialogPrint() { if (qpd.exec() == QDialog::Accepted) { QPainter qp(&qprin); - scene -> setAffichageGrille(false); + scene -> setDisplayGrid(false); scene -> render(&qp); - scene -> setAffichageGrille(true); + scene -> setDisplayGrid(true); } } diff --git a/diagramview.h b/diagramview.h index 262703f34..c732831f4 100644 --- a/diagramview.h +++ b/diagramview.h @@ -1,75 +1,79 @@ #ifndef DIAGRAMVIEW_H - #define DIAGRAMVIEW_H - #include - class Diagram; - #include "element.h" - #include "conducer.h" - /** - Classe representant graphiquement un schema electrique - */ - class DiagramView : public QGraphicsView { - Q_OBJECT - public: - // constructeurs - DiagramView(); - DiagramView(QWidget * = 0); - - // nouveaux attributs - Diagram *scene; - - // methodes publiques - bool ouvrir(QString, int * = NULL); - void closeEvent(QCloseEvent *); - QString nom_fichier; - bool enregistrer(); - bool enregistrer_sous(); - void dialogExport(); - void dialogEditInfos(); - void dialogPrint(); - void addColumn(); - void removeColumn(); - void adjustHeight(qreal); - void adjustSceneRect(); - void expand(); - void shrink(); - Diagram *diagram() { return(scene); } - bool hasSelectedItems(); - - private: - bool private_enregistrer(QString &); - void initialise(); - QList garbage; - - void throwToGarbage(QGraphicsItem *); - void mousePressEvent(QMouseEvent *); - void dragEnterEvent(QDragEnterEvent *); - void dragLeaveEvent(QDragLeaveEvent *); - void dragMoveEvent(QDragMoveEvent *); - void dropEvent(QDropEvent *); - - signals: - void selectionChanged(); - void antialiasingChanged(); - void modeChanged(); - - public slots: - void selectNothing(); - void selectAll(); - void selectInvert(); - void supprimer(); - void pivoter(); - void setVisualisationMode(); - void setSelectionMode(); - void zoomPlus(); - void zoomMoins(); - void zoomFit(); - void zoomReset(); - void couper(); - void copier(); - void coller(); - - private slots: - void flushGarbage(); - void slot_selectionChanged(); - }; +#define DIAGRAMVIEW_H +#include +class Diagram; +/** + Classe representant graphiquement un schema electrique +*/ +class DiagramView : public QGraphicsView { + Q_OBJECT + + // constructeurs, destructeur + public: + DiagramView(); + DiagramView(QWidget * = 0); + virtual ~DiagramView(); + + private: + DiagramView(const DiagramView &); + + // attributs + private: + Diagram *scene; + QList garbage; + + // methodes + public: + bool ouvrir(QString, int * = NULL); + void closeEvent(QCloseEvent *); + QString nom_fichier; + bool enregistrer(); + bool enregistrer_sous(); + void dialogExport(); + void dialogEditInfos(); + void dialogPrint(); + void addColumn(); + void removeColumn(); + void adjustHeight(qreal); + void adjustSceneRect(); + void expand(); + void shrink(); + Diagram *diagram() { return(scene); } + bool hasSelectedItems(); + + private: + bool private_enregistrer(QString &); + void initialise(); + void throwToGarbage(QGraphicsItem *); + void mousePressEvent(QMouseEvent *); + void dragEnterEvent(QDragEnterEvent *); + void dragLeaveEvent(QDragLeaveEvent *); + void dragMoveEvent(QDragMoveEvent *); + void dropEvent(QDropEvent *); + + signals: + void selectionChanged(); + void antialiasingChanged(); + void modeChanged(); + + public slots: + void selectNothing(); + void selectAll(); + void selectInvert(); + void supprimer(); + void pivoter(); + void setVisualisationMode(); + void setSelectionMode(); + void zoomPlus(); + void zoomMoins(); + void zoomFit(); + void zoomReset(); + void couper(); + void copier(); + void coller(); + + private slots: + void flushGarbage(); + void slot_selectionChanged(); +}; #endif diff --git a/element.cpp b/element.cpp index 6c08a427c..380652a39 100644 --- a/element.cpp +++ b/element.cpp @@ -3,8 +3,6 @@ #include "elementtextitem.h" #include -/*** Methodes publiques ***/ - /** Constructeur pour un element sans scene ni parent */ @@ -13,6 +11,12 @@ Element::Element(QGraphicsItem *parent, Diagram *scene) : QGraphicsItem(parent, setZValue(10); } +/** + Destructeur +*/ +Element::~Element() { +} + /** Methode principale de dessin de l'element @param painter Le QPainter utilise pour dessiner l'elment @@ -110,10 +114,6 @@ QVariant Element::itemChange(GraphicsItemChange change, const QVariant &value) { foreach(QGraphicsItem *qgi, children()) { if (Terminal *p = qgraphicsitem_cast(qgi)) p -> updateConducer(value.toPointF()); } - } else if (change == QGraphicsItem::ItemSelectedChange) { - foreach(QGraphicsItem *qgi, children()) { - if (Terminal *p = qgraphicsitem_cast(qgi)) p -> updateConducer(); - } } return(QGraphicsItem::itemChange(change, value)); } diff --git a/element.h b/element.h index 681a9480a..1a1efd389 100644 --- a/element.h +++ b/element.h @@ -7,45 +7,20 @@ */ class Diagram; class Element : public QGraphicsItem { + + // constructeurs, destructeur + public: + Element(QGraphicsItem * = 0, Diagram * = 0); + virtual ~Element(); + + private: + Element(const Element &); + + // attributs public: enum { Type = UserType + 1000 }; - virtual int type() const { return Type; } - Element(QGraphicsItem * = 0, Diagram * = 0); - - virtual int nbTerminals() const = 0; - virtual int nbTerminalsMin() const = 0; - virtual int nbTerminalsMax() const = 0; - virtual void paint(QPainter *, const QStyleOptionGraphicsItem *) = 0; - virtual QString typeId() const = 0; - - virtual QString nom() const = 0; - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); - QRectF boundingRect() const; - QSize setSize(int, int); - QPoint setHotspot(QPoint); - QPoint hotspot() const; - void select(); - void deselect(); - QPixmap pixmap(); - QVariant itemChange(GraphicsItemChange, const QVariant &); - void setPos(const QPointF &); - void setPos(qreal, qreal); - bool connexionsInternesAcceptees(); - void setConnexionsInternesAcceptees(bool cia); - static bool valideXml(QDomElement &); - virtual bool fromXml(QDomElement &, QHash&); - virtual QDomElement toXml (QDomDocument &, QHash&) const; - // methodes d'acces aux possibilites d'orientation - Terminal::Orientation orientation() const; - bool acceptOrientation(Terminal::Orientation o) const; - Terminal::Orientation defaultOrientation() const; - Terminal::Orientation nextAcceptableOrientation() const; - Terminal::Orientation previousAcceptableOrientation() const; - bool setOrientation(Terminal::Orientation o); protected: - void drawAxes(QPainter *, const QStyleOptionGraphicsItem *); - void mouseMoveEvent(QGraphicsSceneMouseEvent *); bool ori_n; bool ori_s; bool ori_e; @@ -53,6 +28,63 @@ class Element : public QGraphicsItem { Terminal::Orientation ori_d; Terminal::Orientation ori; + private: + QSize dimensions; + QPoint hotspot_coord; + QPixmap apercu; + QMenu menu; + + // methodes + public: + virtual int type() const { return Type; } + + // methodes virtuelles pures a definir dans les classes enfants + virtual int nbTerminals() const = 0; + virtual int nbTerminalsMin() const = 0; + virtual int nbTerminalsMax() const = 0; + virtual void paint(QPainter *, const QStyleOptionGraphicsItem *) = 0; + virtual QString typeId() const = 0; + virtual QString nom() const = 0; + + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); + QVariant itemChange(GraphicsItemChange, const QVariant &); + QRectF boundingRect() const; + QSize setSize(int, int); + QPixmap pixmap(); + + // methodes relatives au point de saisie + QPoint setHotspot(QPoint); + QPoint hotspot() const; + + // methodes relatives a la selection + void select(); + void deselect(); + + // methodes relatives a la position + void setPos(const QPointF &); + void setPos(qreal, qreal); + + // methodes relatives aux connexions internes + bool connexionsInternesAcceptees(); + void setConnexionsInternesAcceptees(bool cia); + + // methodes relatives aux fichiers XML + static bool valideXml(QDomElement &); + virtual bool fromXml(QDomElement &, QHash&); + virtual QDomElement toXml(QDomDocument &, QHash&) const; + + // methodes d'acces aux possibilites d'orientation + Terminal::Orientation orientation() const; + Terminal::Orientation defaultOrientation() const; + bool acceptOrientation(Terminal::Orientation o) const; + Terminal::Orientation nextAcceptableOrientation() const; + Terminal::Orientation previousAcceptableOrientation() const; + bool setOrientation(Terminal::Orientation o); + + protected: + void drawAxes(QPainter *, const QStyleOptionGraphicsItem *); + void mouseMoveEvent(QGraphicsSceneMouseEvent *); + private: bool peut_relier_ses_propres_terminals; void drawSelection(QPainter *, const QStyleOptionGraphicsItem *); @@ -60,11 +92,6 @@ class Element : public QGraphicsItem { Terminal::Orientation nextOrientation(Terminal::Orientation o) const; Terminal::Orientation previousOrientation(Terminal::Orientation o) const; static QList findInDomElement(QDomElement, QString, QString); - - QSize dimensions; - QPoint hotspot_coord; - QPixmap apercu; - QMenu menu; }; /** diff --git a/elementscategorieslist.cpp b/elementscategorieslist.cpp index efe13fe75..29a7603b2 100644 --- a/elementscategorieslist.cpp +++ b/elementscategorieslist.cpp @@ -21,7 +21,6 @@ ElementsCategoriesList::ElementsCategoriesList(QWidget *parent) : QTreeWidget(pa Destructeur */ ElementsCategoriesList::~ElementsCategoriesList() { - } /** diff --git a/elementscategorieslist.h b/elementscategorieslist.h index 1f27c0045..f72ee8d98 100644 --- a/elementscategorieslist.h +++ b/elementscategorieslist.h @@ -7,23 +7,24 @@ */ class ElementsCategoriesList : public QTreeWidget { Q_OBJECT - // Constructeur, destructeur + + // Constructeurs, destructeur public: ElementsCategoriesList(QWidget * = 0); - ~ElementsCategoriesList(); - - // attributs + virtual ~ElementsCategoriesList(); + private: + ElementsCategoriesList(const ElementsCategoriesList &); // methodes - private: - void addDir(QTreeWidgetItem *, QString, QString = QString()); - QString categoryName(QDir &); - public: QString selectedCategoryPath(); QString selectedCategoryName(); + private: + void addDir(QTreeWidgetItem *, QString, QString = QString()); + QString categoryName(QDir &); + public slots: void reload(); }; diff --git a/elementscategorieswidget.h b/elementscategorieswidget.h index 476bca7f3..85ecebe21 100644 --- a/elementscategorieswidget.h +++ b/elementscategorieswidget.h @@ -9,10 +9,14 @@ class ElementsCategoriesList; class ElementsCategoriesWidget : public QWidget { Q_OBJECT - // Constructeur, destructeur + + // Constructeurs, destructeur public: ElementsCategoriesWidget(QWidget * = 0); - ~ElementsCategoriesWidget(); + virtual ~ElementsCategoriesWidget(); + + private: + ElementsCategoriesWidget(const ElementsCategoriesWidget &); // attributs private: @@ -24,8 +28,6 @@ class ElementsCategoriesWidget : public QWidget { QAction *action_delete; // methodes - bool rmdir(const QString &); - public: ElementsCategoriesList &elementsCategoriesList() const; diff --git a/elementscategory.cpp b/elementscategory.cpp index 733a0aca7..9ce43ba90 100644 --- a/elementscategory.cpp +++ b/elementscategory.cpp @@ -13,7 +13,6 @@ ElementsCategory::ElementsCategory(const QString &path) : QDir(path) { Destructeur */ ElementsCategory::~ElementsCategory() { - } /** diff --git a/elementscategory.h b/elementscategory.h index 293a5193b..033a68f8a 100644 --- a/elementscategory.h +++ b/elementscategory.h @@ -7,20 +7,19 @@ qet_directory contenant ses caracteristiques (pour le moment : ses noms). */ class ElementsCategory : public QDir { - // Constructeur, destructeur + // constructeurs, destructeur public: ElementsCategory(const QString & = QString()); - ~ElementsCategory(); + virtual ~ElementsCategory(); + + private: + ElementsCategory(const ElementsCategory &); // attributs private: QHash category_names; // methodes - private: - bool rmdir(const QString &) const; - void loadNames(); - public: QString name() const; QHash categoryNames() const; @@ -29,5 +28,9 @@ class ElementsCategory : public QDir { bool write() const; bool remove() const; //bool move(const QString &new_parent); + + private: + bool rmdir(const QString &) const; + void loadNames(); }; #endif diff --git a/elementscategoryeditor.h b/elementscategoryeditor.h index 9d56a1f7a..af13edec0 100644 --- a/elementscategoryeditor.h +++ b/elementscategoryeditor.h @@ -9,11 +9,15 @@ class ElementsCategory; class NamesList; class ElementsCategoryEditor : public QDialog { Q_OBJECT - //Constructeurs, destructeur + + // constructeurs, destructeur public: ElementsCategoryEditor(QWidget * = 0); ElementsCategoryEditor(const QString &, bool = true, QWidget * = 0); - ~ElementsCategoryEditor(); + virtual ~ElementsCategoryEditor(); + + private: + ElementsCategoryEditor(const ElementsCategoryEditor &); // attributs private: @@ -29,6 +33,5 @@ class ElementsCategoryEditor : public QDialog { public slots: void acceptCreation(); void acceptUpdate(); - }; #endif diff --git a/elementspanel.cpp b/elementspanel.cpp index d742557ba..737256adf 100644 --- a/elementspanel.cpp +++ b/elementspanel.cpp @@ -35,6 +35,12 @@ ElementsPanel::ElementsPanel(QWidget *parent) : QTreeWidget(parent) { setPalette(qp); } +/** + Destructeur +*/ +ElementsPanel::~ElementsPanel() { +} + /** Gere le mouvement lors d'un drag'n drop */ diff --git a/elementspanel.h b/elementspanel.h index 80cf6047a..31e9f039a 100644 --- a/elementspanel.h +++ b/elementspanel.h @@ -1,24 +1,32 @@ #ifndef PANELAPPAREILS_H - #define PANELAPPAREILS_H - #include - #include "qetapp.h" - /** - Cette classe represente le panel d'appareils (en tant qu'element - graphique) dans lequel l'utilisateur choisit les composants de - son choix et les depose sur le schema par drag'n drop. - */ - class ElementsPanel : public QTreeWidget { - Q_OBJECT - public: - ElementsPanel(QWidget * = 0); - static QString categoryName(QDir &); - public slots: - void dragMoveEvent(QDragMoveEvent *); - void dropEvent(QDropEvent *); - void startDrag(Qt::DropActions); - void reload(); - private: - void addFile(QTreeWidgetItem *, QString); - void addDir(QTreeWidgetItem *, QString, QString = QString()); - }; +#define PANELAPPAREILS_H +#include +#include "qetapp.h" +/** + Cette classe represente le panel d'appareils (en tant qu'element + graphique) dans lequel l'utilisateur choisit les composants de + son choix et les depose sur le schema par drag'n drop. +*/ +class ElementsPanel : public QTreeWidget { + Q_OBJECT + + // constructeurs, destructeur + public: + ElementsPanel(QWidget * = 0); + virtual ~ElementsPanel(); + + private: + ElementsPanel(const ElementsPanel &); + + // methodes + private: + void addFile(QTreeWidgetItem *, QString); + void addDir(QTreeWidgetItem *, QString, QString = QString()); + + public slots: + void dragMoveEvent(QDragMoveEvent *); + void dropEvent(QDropEvent *); + void startDrag(Qt::DropActions); + void reload(); +}; #endif diff --git a/elementspanelwidget.cpp b/elementspanelwidget.cpp index b004cf101..83a3a989d 100644 --- a/elementspanelwidget.cpp +++ b/elementspanelwidget.cpp @@ -25,6 +25,12 @@ ElementsPanelWidget::ElementsPanelWidget(QWidget *parent) : QWidget(parent) { setLayout(vlayout); } +/** + Destructeur +*/ +ElementsPanelWidget::~ElementsPanelWidget() { +} + /** Appelle l'assistant de creation de nouvel element */ diff --git a/elementspanelwidget.h b/elementspanelwidget.h index ea3f6f867..384caaef7 100644 --- a/elementspanelwidget.h +++ b/elementspanelwidget.h @@ -10,9 +10,13 @@ class ElementsPanelWidget : public QWidget { Q_OBJECT - // constructeurs + // constructeurs, destructeur public: ElementsPanelWidget(QWidget * = 0); + virtual ~ElementsPanelWidget(); + + private: + ElementsPanelWidget(const ElementsPanelWidget &); // attributs private: @@ -21,9 +25,17 @@ class ElementsPanelWidget : public QWidget { // methodes public: - inline ElementsPanel &elementsPanel() const { return(*elements_panel); } + inline ElementsPanel &elementsPanel() const; public slots: void newElement(); }; + +/** + @return Le panel d'elements imbrique dans ce widget +*/ +inline ElementsPanel &ElementsPanelWidget::elementsPanel() const { + return(*elements_panel); +} + #endif diff --git a/elementtextitem.cpp b/elementtextitem.cpp index 55d443391..4b0b27d9d 100644 --- a/elementtextitem.cpp +++ b/elementtextitem.cpp @@ -21,6 +21,9 @@ ElementTextItem::ElementTextItem(const QString &text, QGraphicsItem *parent, QGr setTextInteractionFlags(Qt::TextEditorInteraction); } +ElementTextItem::~ElementTextItem() { +} + /** Modifie la position du champ de texte @param pos La nouvelle position du champ de texte @@ -55,7 +58,7 @@ QPointF ElementTextItem::pos() const { valeur a ce champ. @param e L'element XML representant le champ de texte */ -void ElementTextItem::fromXml(QDomElement &e) { +void ElementTextItem::fromXml(const QDomElement &e) { QPointF _pos = pos(); if (e.attribute("x").toDouble() == _pos.x() && e.attribute("y").toDouble() == _pos.y()) { setPlainText(e.attribute("text")); @@ -66,7 +69,7 @@ void ElementTextItem::fromXml(QDomElement &e) { @param document Le document XML a utiliser @return L'element XML representant ce champ de texte */ -QDomElement ElementTextItem::toXml(QDomDocument &document) { +QDomElement ElementTextItem::toXml(QDomDocument &document) const { QDomElement result = document.createElement("input"); result.setAttribute("x", pos().x()); result.setAttribute("y", pos().y()); diff --git a/elementtextitem.h b/elementtextitem.h index 93c0690f5..dca974501 100644 --- a/elementtextitem.h +++ b/elementtextitem.h @@ -8,23 +8,26 @@ malgre les rotations de son element parent. */ class ElementTextItem : public QGraphicsTextItem { - // constructeurs + // constructeurs, destructeur public: ElementTextItem(QGraphicsItem * = 0, QGraphicsScene * = 0); ElementTextItem(const QString &, QGraphicsItem * = 0, QGraphicsScene * = 0); + virtual ~ElementTextItem(); // attributs + public: + enum { Type = UserType + 1003 }; + private: bool follow_parent_rotations; // methodes public: - enum { Type = UserType + 1003 }; virtual int type() const { return Type; } bool followParentRotations() const; void setFollowParentRotations(bool); - void fromXml(QDomElement &); - QDomElement toXml(QDomDocument &); + void fromXml(const QDomElement &); + QDomElement toXml(QDomDocument &) const; void setPos(const QPointF &); void setPos(qreal, qreal); QPointF pos() const; diff --git a/exportdialog.cpp b/exportdialog.cpp index 8212f4521..e64adcfb7 100644 --- a/exportdialog.cpp +++ b/exportdialog.cpp @@ -58,7 +58,6 @@ ExportDialog::ExportDialog(Diagram *dia, QWidget *parent) : QDialog(parent) { Destructeur - ne fait rien */ ExportDialog::~ExportDialog() { - } /** @@ -266,7 +265,7 @@ QImage ExportDialog::generateImage() { // genere l'image diagram -> setUseBorder(export_border -> isChecked()); - diagram -> setAffichageGrille(draw_grid -> isChecked()); + diagram -> setDisplayGrid(draw_grid -> isChecked()); diagram -> border_and_inset.displayBorder(draw_border -> isChecked()); diagram -> border_and_inset.displayColumns(draw_columns -> isChecked()); diagram -> border_and_inset.displayInset(draw_inset -> isChecked()); @@ -287,7 +286,7 @@ QImage ExportDialog::generateImage() { diagram -> border_and_inset.displayBorder(state_drawBorder); diagram -> border_and_inset.displayColumns(state_drawColumns); diagram -> border_and_inset.displayInset(state_drawInset); - diagram -> setAffichageGrille(state_drawGrid); + diagram -> setDisplayGrid(state_drawGrid); diagram -> setUseBorder(state_useBorder); return(image); diff --git a/exportdialog.h b/exportdialog.h index e23958dab..f5015d8f5 100644 --- a/exportdialog.h +++ b/exportdialog.h @@ -1,58 +1,66 @@ #ifndef EXPORTDIALOG_H - #define EXPORTDIALOG_H - #include - #include "diagram.h" - /** - Cette classe represente le dialogue permettant d'exporter un schema - sous forme d'image selon les desirs de l'utilisateur - */ - class ExportDialog : public QDialog { - Q_OBJECT - public: - ExportDialog(Diagram *, QWidget * = 0); - ~ExportDialog(); - - private: - // elements graphiques - QLineEdit *filename; - QPushButton *button_browse; - QComboBox *format; - QSpinBox *width; - QSpinBox *height; - QCheckBox *keep_aspect_ratio; - QCheckBox *draw_grid; - QCheckBox *draw_border; - QCheckBox *draw_inset; - QCheckBox *draw_columns; - QCheckBox *keep_colors; - QRadioButton *export_elements; - QRadioButton *export_border; - QDialogButtonBox *buttons; - QGraphicsScene *preview_scene; - QGraphicsView *preview_view; - - // booleens pour ne pas avoir de boucle lors de l'edition des dimensions de l'image - bool dontchangewidth; - bool dontchangeheight; - - // elements relatifs au traitement effectue par le dialogue - Diagram *diagram; - QSize diagram_size; - QString diagram_path; - qreal diagram_ratio; - - QWidget *leftPart(); - QWidget *rightPart(); - QGroupBox *setupDimensionsGroupBox(); - QGroupBox *setupOptionsGroupBox(); - QImage generateImage(); - - public slots: - void slot_correctWidth(); - void slot_correctHeight(); - void slot_chooseAFile(); - void slot_check(); - void slot_changeUseBorder(); - void slot_refreshPreview(); - }; +#define EXPORTDIALOG_H +#include +#include "diagram.h" +/** + Cette classe represente le dialogue permettant d'exporter un schema + sous forme d'image selon les desirs de l'utilisateur +*/ +class ExportDialog : public QDialog { + Q_OBJECT + + // constructeurs, destructeur + public: + ExportDialog(Diagram *, QWidget * = 0); + virtual ~ExportDialog(); + + private: + ExportDialog(const ExportDialog &); + + // attributs + private: + // elements graphiques + QLineEdit *filename; + QPushButton *button_browse; + QComboBox *format; + QSpinBox *width; + QSpinBox *height; + QCheckBox *keep_aspect_ratio; + QCheckBox *draw_grid; + QCheckBox *draw_border; + QCheckBox *draw_inset; + QCheckBox *draw_columns; + QCheckBox *keep_colors; + QRadioButton *export_elements; + QRadioButton *export_border; + QDialogButtonBox *buttons; + QGraphicsScene *preview_scene; + QGraphicsView *preview_view; + + // booleens pour ne pas avoir de boucle lors de l'edition des dimensions de l'image + bool dontchangewidth; + bool dontchangeheight; + + // elements relatifs au traitement effectue par le dialogue + Diagram *diagram; + QSize diagram_size; + QString diagram_path; + qreal diagram_ratio; + + // methodes + private: + QWidget *leftPart(); + QWidget *rightPart(); + QGroupBox *setupDimensionsGroupBox(); + QGroupBox *setupOptionsGroupBox(); + QImage generateImage(); + + public slots: + void slot_correctWidth(); + void slot_correctHeight(); + void slot_chooseAFile(); + void slot_check(); + void slot_changeUseBorder(); + void slot_refreshPreview(); +}; #endif diff --git a/fixedelement.cpp b/fixedelement.cpp index fc125a33e..774eb4a95 100644 --- a/fixedelement.cpp +++ b/fixedelement.cpp @@ -5,6 +5,12 @@ FixedElement::FixedElement(QGraphicsItem *parent, Diagram *scene) : Element(parent, scene) { } +/** + Destructeur +*/ +FixedElement::~FixedElement() { +} + /** @return Le nombre minimal de bornes que l'element peut avoir */ diff --git a/fixedelement.h b/fixedelement.h index 374c9921e..d7309d743 100644 --- a/fixedelement.h +++ b/fixedelement.h @@ -1,14 +1,23 @@ #ifndef ELEMENTFIXE_H - #define ELEMENTFIXE_H - #include "element.h" - class FixedElement : public Element { - public: - FixedElement(QGraphicsItem * = 0, Diagram * = 0); - int nbTerminalsMin() const; - int nbTerminalsMax() const; - virtual int nbTerminals() const = 0; - virtual void paint(QPainter *, const QStyleOptionGraphicsItem *) = 0; - virtual QString typeId() const = 0; - virtual QString nom() const = 0; - }; +#define ELEMENTFIXE_H +#include "element.h" +/** + Cette classe represente un element avec un nombre fixe de bornes. +*/ +class FixedElement : public Element { + + // constructeurs, destructeur + public: + FixedElement(QGraphicsItem * = 0, Diagram * = 0); + virtual ~FixedElement(); + + // methodes + public: + int nbTerminalsMin() const; + int nbTerminalsMax() const; + virtual int nbTerminals() const = 0; + virtual void paint(QPainter *, const QStyleOptionGraphicsItem *) = 0; + virtual QString typeId() const = 0; + virtual QString nom() const = 0; +}; #endif diff --git a/nameslist.cpp b/nameslist.cpp index bd932c881..227e17c49 100644 --- a/nameslist.cpp +++ b/nameslist.cpp @@ -25,7 +25,6 @@ NamesList::NamesList(QWidget *parent) : QWidget(parent) { Destructeur */ NamesList::~NamesList() { - } /** diff --git a/nameslist.h b/nameslist.h index 8387a5203..26cc96398 100644 --- a/nameslist.h +++ b/nameslist.h @@ -7,10 +7,14 @@ */ class NamesList : public QWidget { Q_OBJECT - //Constructeur, destructeur + + // constructeurs, destructeur public: NamesList(QWidget * = 0); - ~NamesList(); + virtual ~NamesList(); + + private: + NamesList(const NamesList &); // attributs private: @@ -23,6 +27,7 @@ class NamesList : public QWidget { bool checkOneName(); QHash names(); void setNames(QHash &); + private: void clean(); void updateHash(); diff --git a/newelementwizard.h b/newelementwizard.h index 2c9d7a76b..1129f16ee 100644 --- a/newelementwizard.h +++ b/newelementwizard.h @@ -17,10 +17,14 @@ class NamesList; class Diagram; class NewElementWizard : public QDialog { Q_OBJECT - // Constructeur, destructeur + + // constructeurs, destructeur public: NewElementWizard(QWidget * = 0, Qt::WindowFlags = 0); - ~NewElementWizard(); + virtual ~NewElementWizard(); + + private: + NewElementWizard(const NewElementWizard &); // attributs private: diff --git a/qetapp.cpp b/qetapp.cpp index d74c0adb4..dabfaa087 100644 --- a/qetapp.cpp +++ b/qetapp.cpp @@ -88,6 +88,12 @@ QETApp::QETApp(QWidget *parent) : QMainWindow(parent) { connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(slot_updateActions())); } +/** + Destructeur +*/ +QETApp::~QETApp() { +} + /** Gere les evenements relatifs au QSystemTrayIcon @param raison un entier representant l'evenement survenu sur le systray @@ -604,7 +610,7 @@ bool QETApp::fermer() { /** @return Le DiagramView qui a le focus dans l'interface MDI */ -DiagramView *QETApp::diagramEnCours() { +DiagramView *QETApp::diagramEnCours() const { return(qobject_cast(workspace.activeWindow())); } diff --git a/qetapp.h b/qetapp.h index 8f6df7b6b..d485007dc 100644 --- a/qetapp.h +++ b/qetapp.h @@ -1,134 +1,146 @@ #ifndef QETAPP_H - #define QETAPP_H - #include - class DiagramView; - class ElementsPanelWidget; - /** - Cette classe represente la fenetre principale de QElectroTech et, - ipso facto, la plus grande partie de l'interface graphique de QElectroTech. - Il s'agit d'un objet QMainWindow avec un QWorkSpace contenant des objets - « Diagram » en guise de widget central et un « Panel d'Appareils » en guise - de widget « Dock ». - */ - class QETApp : public QMainWindow { - Q_OBJECT - public: - QETApp(QWidget * = 0); - void closeEvent(QCloseEvent *); - void addDiagramView(DiagramView *); - static QString commonElementsDir(); - static QString customElementsDir(); - static QString configDir(); - static QString languagesPath(); - static QString realPath(QString &); - static QString symbolicPath(QString &); - - public slots: - void systray(QSystemTrayIcon::ActivationReason); - void systrayReduce(); - void systrayRestore(); - void quit(QCloseEvent * = NULL); - void toggleFullScreen(); - void aPropos(); - void dialog_print(); - void dialog_export(); - bool dialogue_enregistrer_sous(); - bool enregistrer(); - bool nouveau(); - bool ouvrir(); - bool fermer(); - void slot_editInfos(); - void slot_couper(); - void slot_copier(); - void slot_coller(); - void slot_zoomPlus(); - void slot_zoomMoins(); - void slot_zoomFit(); - void slot_zoomReset(); - void slot_selectAll(); - void slot_selectNothing(); - void slot_selectInvert(); - void slot_supprimer(); - void slot_pivoter(); - void slot_setSelectionMode(); - void slot_setVisualisationMode(); - void slot_updateActions(); - void slot_updateMenuFenetres(); - void slot_addColumn(); - void slot_removeColumn(); - void slot_expand(); - void slot_shrink(); - - protected: - // Actions faisables au travers de menus dans l'application QElectroTech - QAction *mode_selection; - QAction *mode_visualise; - QAction *nouveau_fichier; - QAction *ouvrir_fichier; - QAction *fermer_fichier; - QAction *enr_fichier; - QAction *enr_fichier_sous; - QAction *importer; - QAction *exporter; - QAction *imprimer; - QAction *quitter_qet; - QAction *annuler; - QAction *refaire; - QAction *couper; - QAction *copier; - QAction *coller; - QAction *sel_tout; - QAction *sel_rien; - QAction *sel_inverse; - QAction *supprimer; - QAction *selectionner; - QAction *pivoter; - QAction *infos_diagram; - QAction *add_column; - QAction *remove_column; - QAction *expand_diagram; - QAction *shrink_diagram; - QAction *poser_fil; - QAction *reduce_appli; - QAction *restore_appli; - QAction *zoom_avant; - QAction *zoom_arriere; - QAction *zoom_adapte; - QAction *zoom_reset; - QAction *a_propos_de_qet; - QAction *a_propos_de_qt; - QAction *configurer; - QAction *entrer_pe; - QAction *sortir_pe; - QAction *f_mosaique; - QAction *f_cascade; - QAction *f_reorganise; - QAction *f_prec; - QAction *f_suiv; - - void actions(); - // menus variables - QAction *menu_systray_masquer_restaurer; - - private: - QWorkspace workspace; - DiagramView *diagramEnCours(); - QSignalMapper windowMapper; - /// Dock pour le Panel d'Appareils - QDockWidget *qdw_pa; - /// Panel d'Appareils - ElementsPanelWidget *pa; - /// Elements de menus pour l'icone du systray - QMenu *menu_systray; - QAction *systray_masquer; - QAction * config_fullscreen; - QMenu *menu_fenetres; - /// Icone dans le systray - QSystemTrayIcon *qsti; - /// Geometrie de la fenetre principale - QByteArray wg; - void menus(); - void toolbar(); - QToolBar *barre_outils; - }; +#define QETAPP_H +#include +class DiagramView; +class ElementsPanelWidget; +/** + Cette classe represente la fenetre principale de QElectroTech et, + ipso facto, la plus grande partie de l'interface graphique de QElectroTech. + Il s'agit d'un objet QMainWindow avec un QWorkSpace contenant des objets + « Diagram » en guise de widget central et un « Panel d'Appareils » en guise + de widget « Dock ». +*/ +class QETApp : public QMainWindow { + Q_OBJECT + + // constructeurs, destructeur + public: + QETApp(QWidget * = 0); + virtual ~QETApp(); + + private: + QETApp(const QETApp &); + + // methodes + public: + void closeEvent(QCloseEvent *); + void addDiagramView(DiagramView *); + static QString commonElementsDir(); + static QString customElementsDir(); + static QString configDir(); + static QString languagesPath(); + static QString realPath(QString &); + static QString symbolicPath(QString &); + + protected: + void actions(); + + private: + DiagramView *diagramEnCours() const; + void menus(); + void toolbar(); + + public slots: + void systray(QSystemTrayIcon::ActivationReason); + void systrayReduce(); + void systrayRestore(); + void quit(QCloseEvent * = NULL); + void toggleFullScreen(); + void aPropos(); + void dialog_print(); + void dialog_export(); + bool dialogue_enregistrer_sous(); + bool enregistrer(); + bool nouveau(); + bool ouvrir(); + bool fermer(); + void slot_editInfos(); + void slot_couper(); + void slot_copier(); + void slot_coller(); + void slot_zoomPlus(); + void slot_zoomMoins(); + void slot_zoomFit(); + void slot_zoomReset(); + void slot_selectAll(); + void slot_selectNothing(); + void slot_selectInvert(); + void slot_supprimer(); + void slot_pivoter(); + void slot_setSelectionMode(); + void slot_setVisualisationMode(); + void slot_updateActions(); + void slot_updateMenuFenetres(); + void slot_addColumn(); + void slot_removeColumn(); + void slot_expand(); + void slot_shrink(); + + // attributs + protected: + // Actions faisables au travers de menus dans l'application QElectroTech + QAction *mode_selection; + QAction *mode_visualise; + QAction *nouveau_fichier; + QAction *ouvrir_fichier; + QAction *fermer_fichier; + QAction *enr_fichier; + QAction *enr_fichier_sous; + QAction *importer; + QAction *exporter; + QAction *imprimer; + QAction *quitter_qet; + QAction *annuler; + QAction *refaire; + QAction *couper; + QAction *copier; + QAction *coller; + QAction *sel_tout; + QAction *sel_rien; + QAction *sel_inverse; + QAction *supprimer; + QAction *selectionner; + QAction *pivoter; + QAction *infos_diagram; + QAction *add_column; + QAction *remove_column; + QAction *expand_diagram; + QAction *shrink_diagram; + QAction *poser_fil; + QAction *reduce_appli; + QAction *restore_appli; + QAction *zoom_avant; + QAction *zoom_arriere; + QAction *zoom_adapte; + QAction *zoom_reset; + QAction *a_propos_de_qet; + QAction *a_propos_de_qt; + QAction *configurer; + QAction *entrer_pe; + QAction *sortir_pe; + QAction *f_mosaique; + QAction *f_cascade; + QAction *f_reorganise; + QAction *f_prec; + QAction *f_suiv; + QAction *menu_systray_masquer_restaurer; + + private: + QWorkspace workspace; + QSignalMapper windowMapper; + /// Dock pour le Panel d'Appareils + QDockWidget *qdw_pa; + /// Panel d'Appareils + ElementsPanelWidget *pa; + /// Elements de menus pour l'icone du systray + QMenu *menu_systray; + QAction *systray_masquer; + QAction * config_fullscreen; + QMenu *menu_fenetres; + /// Icone dans le systray + QSystemTrayIcon *qsti; + /// Geometrie de la fenetre principale + QByteArray wg; + QToolBar *barre_outils; +}; #endif diff --git a/terminal.cpp b/terminal.cpp index b58f133b9..500eda721 100644 --- a/terminal.cpp +++ b/terminal.cpp @@ -77,8 +77,12 @@ Terminal::Terminal(qreal pf_x, qreal pf_y, Terminal::Orientation o, Element *e, /** Destructeur + La destruction de la borne entraine la destruction des conducteurs + associes. */ Terminal::~Terminal() { + //qDebug() << "Terminal::~Terminal" << (void *)this; + foreach(Conducer *c, liste_conducers) delete c; delete br; } @@ -139,6 +143,7 @@ bool Terminal::addConducer(Conducer *f) { @param f Conducteur a enlever */ void Terminal::removeConducer(Conducer *f) { + //qDebug() << "Terminal::removeConducer" << (void *)this; int index = liste_conducers.indexOf(f); if (index == -1) return; liste_conducers.removeAt(index); @@ -229,9 +234,9 @@ void Terminal::hoverLeaveEvent(QGraphicsSceneHoverEvent *) { */ void Terminal::mousePressEvent(QGraphicsSceneMouseEvent *e) { if (Diagram *s = qobject_cast(scene())) { - s -> setDepart(mapToScene(QPointF(amarrage_conducer))); - s -> setArrivee(e -> scenePos()); - s -> poseConducer(true); + s -> setConducerStart(mapToScene(QPointF(amarrage_conducer))); + s -> setConducerStop(e -> scenePos()); + s -> setConducer(true); setCursor(Qt::CrossCursor); } } @@ -253,7 +258,7 @@ void Terminal::mouseMoveEvent(QGraphicsSceneMouseEvent *e) { } // si la scene est un Diagram, on actualise le poseur de conducteur - if (Diagram *s = qobject_cast(scene())) s -> setArrivee(e -> scenePos()); + if (Diagram *s = qobject_cast(scene())) s -> setConducerStop(e -> scenePos()); // on recupere la liste des qgi sous le pointeur QList qgis = scene() -> items(e -> scenePos()); @@ -315,7 +320,7 @@ void Terminal::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) { // verifie que la scene est bien un Diagram if (Diagram *s = qobject_cast(scene())) { // on arrete de dessiner l'apercu du conducteur - s -> poseConducer(false); + s -> setConducer(false); // on recupere l'element sous le pointeur lors du MouseReleaseEvent QGraphicsItem *qgi = s -> itemAt(e -> scenePos()); // s'il n'y a rien, on arrete la diff --git a/terminal.h b/terminal.h index d7e3f5634..9dddec00f 100644 --- a/terminal.h +++ b/terminal.h @@ -4,28 +4,29 @@ #include #include class Conducer; -class Element; class Diagram; +class Element; /** Classe modelisant la « borne » d'un appareil, c'est-a-dire un branchement possible pour un Conducteur. */ class Terminal : public QGraphicsItem { + + // constructeurs, destructeur public: - // enum definissant l'orientation de la borne enum Orientation {Nord, Est, Sud, Ouest}; - - // permet de caster un QGraphicsItem en Borne avec qgraphicsitem_cast - enum { Type = UserType + 1002 }; - virtual int type() const { return Type; } - - // constructeurs Terminal(); Terminal(QPointF, Terminal::Orientation, Element * = 0, Diagram * = 0); Terminal(qreal, qreal, Terminal::Orientation, Element * = 0, Diagram * = 0); + virtual ~Terminal(); - // destructeur - ~Terminal(); + private: + Terminal(const Terminal &); + + // methodes + public: + // permet de caster un QGraphicsItem en Borne avec qgraphicsitem_cast + virtual int type() const { return Type; } // implementation des methodes virtuelles pures de QGraphicsItem void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); @@ -37,15 +38,15 @@ class Terminal : public QGraphicsItem { int nbConducers() const; // methodes de lecture - QList conducers() const; + QList conducers() const; Terminal::Orientation orientation() const; QPointF amarrageConducer() const; void updateConducer(QPointF = QPointF()); // methodes relatives a l'import/export au format XML static bool valideXml(QDomElement &); - bool fromXml (QDomElement &); - QDomElement toXml (QDomDocument &) const; + bool fromXml (QDomElement &); + QDomElement toXml (QDomDocument &) const; protected: // methodes de gestion des evenements @@ -56,6 +57,10 @@ class Terminal : public QGraphicsItem { void mouseMoveEvent (QGraphicsSceneMouseEvent *); void mouseReleaseEvent(QGraphicsSceneMouseEvent *); + // attributs + public: + enum { Type = UserType + 1002 }; + private: // pointeur vers la QGraphicsScene de type Diagram (evite quelques casts en interne) Diagram *diagram_scene;