mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Documentation des methodes non documentees
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@84 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
parent
79e057c186
commit
7d25e6091f
@ -134,6 +134,13 @@ void BorderInset::removeColumn() {
|
||||
updateRectangles();
|
||||
}
|
||||
|
||||
/**
|
||||
Permet de changer le nombre de colonnes.
|
||||
Si ce nombre de colonnes est inferieur au minimum requis, cette fonction ne
|
||||
fait rien
|
||||
@param nb_c nouveau nombre de colonnes
|
||||
@see minNbColumns()
|
||||
*/
|
||||
void BorderInset::setNbColumns(int nb_c) {
|
||||
if (nb_c < min_nb_columns) return;
|
||||
nb_columns = nb_c;
|
||||
|
46
conducer.cpp
46
conducer.cpp
@ -508,6 +508,10 @@ void Conducer::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
||||
calculateTextItemPosition();
|
||||
}
|
||||
|
||||
/**
|
||||
Gere les mouvements de souris au dessus du conducteur
|
||||
@param e Le QGraphicsSceneHoverEvent decrivant l'evenement
|
||||
*/
|
||||
void Conducer::hoverMoveEvent(QGraphicsSceneHoverEvent *e) {
|
||||
if (isSelected()) {
|
||||
QPointF hover_point = mapFromScene(e -> pos());
|
||||
@ -596,6 +600,14 @@ void Conducer::updatePoints() {
|
||||
orig_dist_2_terms_y = b2.y() - b1.y();
|
||||
}
|
||||
|
||||
/**
|
||||
Renvoie une valeur donnee apres l'avoir bornee entre deux autres valeurs,
|
||||
en y ajoutant une marge interne.
|
||||
@param tobound valeur a borner
|
||||
@param bound1 borne 1
|
||||
@param bound2 borne 2
|
||||
@return La valeur bornee
|
||||
*/
|
||||
qreal Conducer::conducer_bound(qreal tobound, qreal bound1, qreal bound2) {
|
||||
qreal space = 5.0;
|
||||
if (bound1 < bound2) {
|
||||
@ -605,11 +617,21 @@ qreal Conducer::conducer_bound(qreal tobound, qreal bound1, qreal bound2) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Renvoie une valeur donnee apres l'avoir bornee avant ou apres une valeur.
|
||||
@param tobound valeur a borner
|
||||
@param bound borne
|
||||
@param positive true pour borner la valeur avant la borne, false sinon
|
||||
@return La valeur bornee
|
||||
*/
|
||||
qreal Conducer::conducer_bound(qreal tobound, qreal bound, bool positive) {
|
||||
qreal space = 5.0;
|
||||
return(positive ? qMax(tobound, bound + space) : qMin(tobound, bound - space));
|
||||
}
|
||||
|
||||
/**
|
||||
@return Le nombre de segments composant le conducteur.
|
||||
*/
|
||||
int Conducer::nbSegments() {
|
||||
if (segments == NULL) return(0);
|
||||
int nb_seg = 1;
|
||||
@ -672,6 +694,13 @@ void Conducer::pointsToSegments(QList<QPointF> points_list) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Permet de savoir si un point est tres proche d'un autre. Cela sert surtout
|
||||
pour determiner si un clic a ete effectue pres d'un point donne.
|
||||
@param press_point Point effectivement clique
|
||||
@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) {
|
||||
return (
|
||||
press_point.x() >= point.x() - 5.0 &&\
|
||||
@ -681,6 +710,11 @@ bool Conducer::hasClickedOn(QPointF press_point, QPointF point) {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
Charge les caracteristiques du conducteur depuis un element XML.
|
||||
@param e Un element XML
|
||||
@return true si le chargement a reussi, false sinon
|
||||
*/
|
||||
bool Conducer::fromXml(QDomElement &e) {
|
||||
text_item -> setPlainText(e.attribute("num"));
|
||||
|
||||
@ -752,6 +786,13 @@ bool Conducer::fromXml(QDomElement &e) {
|
||||
return(true);
|
||||
}
|
||||
|
||||
/**
|
||||
Exporte les caracteristiques du conducteur sous forme d'une element XML.
|
||||
@param d Le document XML a utiliser pour creer l'element XML
|
||||
@param table_adr_id Hash stockant les correspondances entre les ids des
|
||||
bornes dans le document XML et leur adresse en memoire
|
||||
@return Un element XML representant le conducteur
|
||||
*/
|
||||
QDomElement Conducer::toXml(QDomDocument &d, QHash<Terminal *, int> &table_adr_id) const {
|
||||
QDomElement e = d.createElement("conducer");
|
||||
e.setAttribute("terminal1", table_adr_id.value(terminal1));
|
||||
@ -814,6 +855,11 @@ ConducerSegment *Conducer::middleSegment() {
|
||||
return(s);
|
||||
}
|
||||
|
||||
/**
|
||||
Positionne le texte du conducteur au milieu du segment qui contient le
|
||||
point au milieu du conducteur
|
||||
@see middleSegment()
|
||||
*/
|
||||
void Conducer::calculateTextItemPosition() {
|
||||
text_item -> setPos(middleSegment() -> middle());
|
||||
}
|
||||
|
@ -1,6 +1,13 @@
|
||||
#include "conducersegment.h"
|
||||
#include <QDebug>
|
||||
|
||||
/**
|
||||
Constructeur
|
||||
@param p1 Le point
|
||||
@param p2
|
||||
@param cs1 Le segment precedent
|
||||
@param cs2 Le segment suivant
|
||||
*/
|
||||
ConducerSegment::ConducerSegment(QPointF p1, QPointF p2, ConducerSegment *cs1, ConducerSegment *cs2) {
|
||||
setFirstPoint(p1);
|
||||
setSecondPoint(p2);
|
||||
@ -8,6 +15,9 @@ ConducerSegment::ConducerSegment(QPointF p1, QPointF p2, ConducerSegment *cs1, C
|
||||
setNextSegment(cs2);
|
||||
}
|
||||
|
||||
/**
|
||||
Destructeur - Relie le segment precedent au suivant
|
||||
*/
|
||||
ConducerSegment::~ConducerSegment() {
|
||||
if (hasPreviousSegment()) previousSegment() -> setNextSegment(nextSegment());
|
||||
if (hasNextSegment()) nextSegment() -> setPreviousSegment(previousSegment());
|
||||
@ -250,6 +260,10 @@ 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) {
|
||||
if (isHorizontal()) return;
|
||||
Q_ASSERT_X(isVertical(), "ConducerSegment::moveX", "segment non vertical");
|
||||
@ -294,6 +308,10 @@ void ConducerSegment::moveX(qreal dx) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Gere les mouvements sur l'axe vertical
|
||||
@param dx taille du deplacement en pixels
|
||||
*/
|
||||
void ConducerSegment::moveY(qreal dy) {
|
||||
if (isVertical()) return;
|
||||
Q_ASSERT_X(isHorizontal(), "ConducerSegment::moveY", "segment non horizontal");
|
||||
@ -406,6 +424,10 @@ void ConducerSegment::moveY(qreal dy) {
|
||||
}
|
||||
}
|
||||
*/
|
||||
/**
|
||||
Change le segment precedent
|
||||
@param ps Le nouveau segment precedent
|
||||
*/
|
||||
void ConducerSegment::setPreviousSegment(ConducerSegment *ps) {
|
||||
previous_segment = ps;
|
||||
if (hasPreviousSegment()) {
|
||||
@ -413,6 +435,10 @@ void ConducerSegment::setPreviousSegment(ConducerSegment *ps) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Change le segment suivant
|
||||
@param ps Le nouveau segment suivant
|
||||
*/
|
||||
void ConducerSegment::setNextSegment(ConducerSegment *ns) {
|
||||
next_segment = ns;
|
||||
if (hasNextSegment()) {
|
||||
@ -420,46 +446,81 @@ void ConducerSegment::setNextSegment(ConducerSegment *ns) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@return Le segment precedent
|
||||
*/
|
||||
ConducerSegment *ConducerSegment::previousSegment() {
|
||||
return(previous_segment);
|
||||
}
|
||||
|
||||
/**
|
||||
@return Le segment suivant
|
||||
*/
|
||||
ConducerSegment *ConducerSegment::nextSegment() {
|
||||
return(next_segment);
|
||||
}
|
||||
|
||||
/**
|
||||
@return true si le segment est vertical, false sinon
|
||||
*/
|
||||
bool ConducerSegment::isVertical() {
|
||||
return(point1.x() == point2.x());
|
||||
}
|
||||
|
||||
/**
|
||||
@return true si le segment est horizontal, false sinon
|
||||
*/
|
||||
bool ConducerSegment::isHorizontal() {
|
||||
return(point1.y() == point2.y());
|
||||
}
|
||||
|
||||
/**
|
||||
@return le premier point du segment
|
||||
*/
|
||||
QPointF ConducerSegment::firstPoint() {
|
||||
return(point1);
|
||||
}
|
||||
|
||||
/**
|
||||
@return le second point du segment
|
||||
*/
|
||||
QPointF ConducerSegment::secondPoint() {
|
||||
return(point2);
|
||||
}
|
||||
|
||||
/**
|
||||
Permet de changer la position du premier point du segment
|
||||
@param p La nouvelle position du premier point
|
||||
*/
|
||||
void ConducerSegment::setFirstPoint(QPointF p) {
|
||||
point1 = p;
|
||||
}
|
||||
|
||||
/**
|
||||
Permet de changer la position du second point du segment
|
||||
@param p La nouvelle position du second point
|
||||
*/
|
||||
void ConducerSegment::setSecondPoint(QPointF p) {
|
||||
point2 = p;
|
||||
}
|
||||
|
||||
/**
|
||||
@return true si le segment a un segment precedent, false sinon
|
||||
*/
|
||||
bool ConducerSegment::hasPreviousSegment() {
|
||||
return(previous_segment != NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
@return true si le segment a un segment suivant, false sinon
|
||||
*/
|
||||
bool ConducerSegment::hasNextSegment() {
|
||||
return(next_segment != NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
@return Le centre du rectangle delimitant le conducteur
|
||||
*/
|
||||
QPointF ConducerSegment::middle() {
|
||||
return(
|
||||
QPointF(
|
||||
@ -469,6 +530,9 @@ QPointF ConducerSegment::middle() {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@return La longueur du conducteur
|
||||
*/
|
||||
qreal ConducerSegment::length() {
|
||||
if (isHorizontal()) {
|
||||
return(secondPoint().x() - firstPoint().x());
|
||||
|
@ -2,6 +2,12 @@
|
||||
#define ELEMENTPERSO_H
|
||||
#include "fixedelement.h"
|
||||
#include <QtGui>
|
||||
/**
|
||||
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);
|
||||
|
207
diagram.h
207
diagram.h
@ -1,69 +1,142 @@
|
||||
#ifndef SCHEMA_H
|
||||
#define SCHEMA_H
|
||||
#define GRILLE_X 10
|
||||
#define GRILLE_Y 10
|
||||
#define MARGIN 5.0
|
||||
#include <QtGui>
|
||||
#include <QtXml>
|
||||
#include "qetapp.h"
|
||||
#include "borderinset.h"
|
||||
class Element;
|
||||
class Terminal;
|
||||
class Diagram : public QGraphicsScene {
|
||||
Q_OBJECT
|
||||
enum BorderOptions { EmptyBorder, Inset, Columns };
|
||||
public:
|
||||
Diagram(QObject * = 0);
|
||||
void drawBackground(QPainter *, const QRectF &);
|
||||
|
||||
// fonctions relatives a la pose de conducteurs
|
||||
inline void poseConducer(bool pf) {
|
||||
if (pf) {
|
||||
if (!poseur_de_conducer -> scene()) addItem(poseur_de_conducer);
|
||||
} else {
|
||||
if (poseur_de_conducer -> scene()) removeItem(poseur_de_conducer);
|
||||
}
|
||||
}
|
||||
inline void setDepart (QPointF d) { poseur_de_conducer -> setLine(QLineF(d, poseur_de_conducer -> line().p2())); }
|
||||
inline void setArrivee(QPointF a) { poseur_de_conducer -> setLine(QLineF(poseur_de_conducer -> line().p1(), a)); }
|
||||
|
||||
// fonctions relatives a l'import / export XML
|
||||
QDomDocument toXml(bool = true);
|
||||
bool fromXml(QDomDocument &, QPointF = QPointF(), bool = true);
|
||||
|
||||
// fonctions relatives aux options graphiques
|
||||
inline void setAffichageGrille(bool dg) { draw_grid = dg; }
|
||||
inline bool displayGrid() { return(draw_grid); }
|
||||
inline void setUseBorder(bool ub) { use_border = ub; }
|
||||
inline bool useBorder() { return(use_border); }
|
||||
inline void setBorderOptions(BorderOptions bo) {
|
||||
border_and_inset.displayBorder(!(bo & EmptyBorder));
|
||||
border_and_inset.displayColumns(bo & Columns);
|
||||
border_and_inset.displayInset(bo & Inset);
|
||||
}
|
||||
inline BorderOptions borderOptions() {
|
||||
BorderOptions retour = EmptyBorder;
|
||||
if (border_and_inset.insetIsDisplayed()) retour = (BorderOptions)(retour|Inset);
|
||||
if (border_and_inset.columnsAreDisplayed()) retour = (BorderOptions)(retour|Columns);
|
||||
return(retour);
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
signals:
|
||||
void selectionChanged();
|
||||
void selectionEmptinessChanged();
|
||||
};
|
||||
#define SCHEMA_H
|
||||
#define GRILLE_X 10
|
||||
#define GRILLE_Y 10
|
||||
#define MARGIN 5.0
|
||||
#include <QtGui>
|
||||
#include <QtXml>
|
||||
#include "qetapp.h"
|
||||
#include "borderinset.h"
|
||||
class Element;
|
||||
class Terminal;
|
||||
class Diagram : public QGraphicsScene {
|
||||
Q_OBJECT
|
||||
enum BorderOptions { EmptyBorder, Inset, Columns };
|
||||
public:
|
||||
Diagram(QObject * = 0);
|
||||
void drawBackground(QPainter *, const QRectF &);
|
||||
|
||||
// fonctions relatives a la pose de conducteurs
|
||||
void poseConducer(bool);
|
||||
|
||||
void setDepart (QPointF);
|
||||
void setArrivee(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);
|
||||
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();
|
||||
|
||||
signals:
|
||||
void selectionChanged();
|
||||
void selectionEmptinessChanged();
|
||||
};
|
||||
|
||||
/**
|
||||
Permet d'ajouter ou enlever le « poseur de conducteur », c'est-a-dire la
|
||||
droite en pointilles qui apparait lorsqu'on pose un conducteur entre deux
|
||||
bornes.
|
||||
@param true pour ajouter le poseur de conducteur, false pour l'enlever
|
||||
*/
|
||||
inline void Diagram::poseConducer(bool pf) {
|
||||
if (pf) {
|
||||
if (!poseur_de_conducer -> scene()) addItem(poseur_de_conducer);
|
||||
} else {
|
||||
if (poseur_de_conducer -> scene()) removeItem(poseur_de_conducer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
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()));
|
||||
}
|
||||
|
||||
/**
|
||||
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));
|
||||
}
|
||||
|
||||
/**
|
||||
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) {
|
||||
draw_grid = dg;
|
||||
}
|
||||
|
||||
/**
|
||||
Permet de savoir si la grille du schema est dessinee ou non
|
||||
@return true si la grille est affichee , false sinon
|
||||
*/
|
||||
inline bool Diagram::displayGrid() {
|
||||
return(draw_grid);
|
||||
}
|
||||
|
||||
/**
|
||||
Permet de specifier si le cadre du schema doit etre pris en compte pour
|
||||
determiner le contour du schema.
|
||||
@param ub true pour prendre le schema en compte, false sinon
|
||||
*/
|
||||
inline void Diagram::setUseBorder(bool ub) {
|
||||
use_border = ub;
|
||||
}
|
||||
|
||||
/**
|
||||
Permet de savoir si le cadre du schema est pris en compte pour
|
||||
determiner le contour du schema.
|
||||
@param ub true le cadre est pris en compte, false sinon
|
||||
*/
|
||||
inline bool Diagram::useBorder() {
|
||||
return(use_border);
|
||||
}
|
||||
|
||||
/**
|
||||
Permet de definir les options du cadre, des colonnes et du cartouche.
|
||||
@param bo Un OU binaire entre les options possibles
|
||||
@see BorderOptions
|
||||
*/
|
||||
inline void Diagram::setBorderOptions(Diagram::BorderOptions bo) {
|
||||
border_and_inset.displayBorder(!(bo & EmptyBorder));
|
||||
border_and_inset.displayColumns(bo & Columns);
|
||||
border_and_inset.displayInset(bo & Inset);
|
||||
}
|
||||
|
||||
/**
|
||||
Permet de savoir les options du cadre, des colonnes et du cartouche.
|
||||
@return Un OU binaire entre les options possibles
|
||||
@see BorderOptions
|
||||
*/
|
||||
inline Diagram::BorderOptions Diagram::borderOptions() {
|
||||
BorderOptions retour = EmptyBorder;
|
||||
if (border_and_inset.insetIsDisplayed()) retour = (BorderOptions)(retour|Inset);
|
||||
if (border_and_inset.columnsAreDisplayed()) retour = (BorderOptions)(retour|Columns);
|
||||
return(retour);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -329,10 +329,17 @@ bool DiagramView::ouvrir(QString n_fichier, int *erreur) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Slot appele lorsque la selection change.
|
||||
*/
|
||||
void DiagramView::slot_selectionChanged() {
|
||||
emit(selectionChanged());
|
||||
}
|
||||
|
||||
/**
|
||||
Gere la fermeture du schema.
|
||||
@param event Le QCloseEvent decrivant l'evenement
|
||||
*/
|
||||
void DiagramView::closeEvent(QCloseEvent *event) {
|
||||
// demande d'abord a l'utilisateur s'il veut enregistrer le schema en cours
|
||||
QMessageBox::StandardButton reponse = QMessageBox::question(
|
||||
@ -413,11 +420,17 @@ bool DiagramView::private_enregistrer(QString &n_fichier) {
|
||||
return(true);
|
||||
}
|
||||
|
||||
/**
|
||||
Exporte le schema.
|
||||
*/
|
||||
void DiagramView::dialogExport() {
|
||||
ExportDialog ed(scene, this);
|
||||
ed.exec();
|
||||
}
|
||||
|
||||
/**
|
||||
Imprime le schema.
|
||||
*/
|
||||
void DiagramView::dialogPrint() {
|
||||
QPrinter qprin;
|
||||
qprin.setOutputFormat(QPrinter::PdfFormat);
|
||||
@ -436,6 +449,9 @@ void DiagramView::dialogPrint() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Edite les informations du schema.
|
||||
*/
|
||||
void DiagramView::dialogEditInfos() {
|
||||
// recupere le cartouche du schema
|
||||
BorderInset *inset = &(scene -> border_and_inset);
|
||||
@ -484,10 +500,16 @@ void DiagramView::dialogEditInfos() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@return true s'il y a des elements selectionnes sur le schema, false sinon
|
||||
*/
|
||||
bool DiagramView::hasSelectedItems() {
|
||||
return(scene -> selectedItems().size() > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
Ajoute une colonne au schema.
|
||||
*/
|
||||
void DiagramView::addColumn() {
|
||||
// ajoute la colonne
|
||||
scene -> border_and_inset.addColumn();
|
||||
@ -499,6 +521,9 @@ void DiagramView::addColumn() {
|
||||
scene -> update(sceneRect());
|
||||
}
|
||||
|
||||
/**
|
||||
Enleve une colonne au schema.
|
||||
*/
|
||||
void DiagramView::removeColumn() {
|
||||
scene -> border_and_inset.removeColumn();
|
||||
|
||||
@ -510,10 +535,16 @@ void DiagramView::removeColumn() {
|
||||
scene -> update(old_sr);
|
||||
}
|
||||
|
||||
/**
|
||||
Agrandit le schema en hauteur
|
||||
*/
|
||||
void DiagramView::expand() {
|
||||
adjustHeight(20.0);
|
||||
}
|
||||
|
||||
/**
|
||||
Retrecit le schema en hauteur
|
||||
*/
|
||||
void DiagramView::shrink() {
|
||||
adjustHeight(-20.0);
|
||||
}
|
||||
|
@ -118,6 +118,11 @@ QVariant Element::itemChange(GraphicsItemChange change, const QVariant &value) {
|
||||
return(QGraphicsItem::itemChange(change, value));
|
||||
}
|
||||
|
||||
/**
|
||||
Permet de specifier l'orientation de l'element
|
||||
@param o la nouvelle orientation de l'objet
|
||||
@return true si l'orientation a pu etre appliquee, false sinon
|
||||
*/
|
||||
bool Element::setOrientation(Terminal::Orientation o) {
|
||||
// verifie que l'orientation demandee est acceptee
|
||||
if (!acceptOrientation(o)) return(false);
|
||||
@ -418,7 +423,6 @@ QDomElement Element::toXml(QDomDocument &document, QHash<Terminal *, int> &table
|
||||
return(element);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Methode statique sans rapport direct avec la manipulation des elements.
|
||||
Etant donne un element XML e, elle renvoie la liste de tous les elements
|
||||
@ -445,4 +449,3 @@ QList<QDomElement> Element::findInDomElement(QDomElement e, QString parent, QStr
|
||||
}
|
||||
return(return_list);
|
||||
}
|
||||
|
||||
|
267
element.h
267
element.h
@ -1,97 +1,174 @@
|
||||
#ifndef ELEMENT_H
|
||||
#define ELEMENT_H
|
||||
#include <QtGui>
|
||||
#include "terminal.h"
|
||||
class Diagram;
|
||||
class Element : public QGraphicsItem {
|
||||
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);
|
||||
inline bool connexionsInternesAcceptees() { return(peut_relier_ses_propres_terminals); }
|
||||
inline void setConnexionsInternesAcceptees(bool cia) { peut_relier_ses_propres_terminals = cia; }
|
||||
static bool valideXml(QDomElement &);
|
||||
virtual bool fromXml(QDomElement &, QHash<int, Terminal *>&);
|
||||
virtual QDomElement toXml (QDomDocument &, QHash<Terminal *, int>&) const;
|
||||
// methodes d'acces aux possibilites d'orientation
|
||||
inline Terminal::Orientation orientation() const { return(ori); }
|
||||
inline bool acceptOrientation(Terminal::Orientation o) {
|
||||
switch(o) {
|
||||
case Terminal::Nord: return(ori_n);
|
||||
case Terminal::Est: return(ori_e);
|
||||
case Terminal::Sud: return(ori_s);
|
||||
case Terminal::Ouest: return(ori_w);
|
||||
default: return(false);
|
||||
}
|
||||
}
|
||||
inline Terminal::Orientation defaultOrientation() { return(ori_d); }
|
||||
inline Terminal::Orientation nextAcceptableOrientation() {
|
||||
Terminal::Orientation retour = nextOrientation(ori);
|
||||
for (int i = 0 ; i < 4 ; ++ i) {
|
||||
if (acceptOrientation(retour)) return(retour);
|
||||
retour = nextOrientation(retour);
|
||||
}
|
||||
// on ne devrait pas arriver la : renvoi d'une valeur par defaut = nord
|
||||
return(Terminal::Nord);
|
||||
}
|
||||
inline Terminal::Orientation previousAcceptableOrientation() {
|
||||
Terminal::Orientation retour = previousOrientation(ori);
|
||||
for (int i = 0 ; i < 4 ; ++ i) {
|
||||
if (acceptOrientation(retour)) return(retour);
|
||||
retour = previousOrientation(retour);
|
||||
}
|
||||
// on ne devrait pas arriver la : renvoi d'une valeur par defaut = nord
|
||||
return(Terminal::Nord);
|
||||
}
|
||||
bool setOrientation(Terminal::Orientation o);
|
||||
|
||||
protected:
|
||||
void drawAxes(QPainter *, const QStyleOptionGraphicsItem *);
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *);
|
||||
bool ori_n;
|
||||
bool ori_s;
|
||||
bool ori_e;
|
||||
bool ori_w;
|
||||
Terminal::Orientation ori_d;
|
||||
Terminal::Orientation ori;
|
||||
|
||||
private:
|
||||
bool peut_relier_ses_propres_terminals;
|
||||
void drawSelection(QPainter *, const QStyleOptionGraphicsItem *);
|
||||
void updatePixmap();
|
||||
inline Terminal::Orientation nextOrientation(Terminal::Orientation o) {
|
||||
if (o < 0 || o > 2) return(Terminal::Nord);
|
||||
return((Terminal::Orientation)(o + 1));
|
||||
}
|
||||
inline Terminal::Orientation previousOrientation(Terminal::Orientation o) {
|
||||
if (o < 0 || o > 3) return(Terminal::Nord);
|
||||
if (o == Terminal::Nord) return(Terminal::Ouest);
|
||||
return((Terminal::Orientation)(o - 1));
|
||||
}
|
||||
static QList<QDomElement> findInDomElement(QDomElement, QString, QString);
|
||||
|
||||
QSize dimensions;
|
||||
QPoint hotspot_coord;
|
||||
QPixmap apercu;
|
||||
QMenu menu;
|
||||
};
|
||||
#define ELEMENT_H
|
||||
#include <QtGui>
|
||||
#include "terminal.h"
|
||||
/**
|
||||
Cette classe abstraite represente un element electrique.
|
||||
*/
|
||||
class Diagram;
|
||||
class Element : public QGraphicsItem {
|
||||
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<int, Terminal *>&);
|
||||
virtual QDomElement toXml (QDomDocument &, QHash<Terminal *, int>&) 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;
|
||||
bool ori_w;
|
||||
Terminal::Orientation ori_d;
|
||||
Terminal::Orientation ori;
|
||||
|
||||
private:
|
||||
bool peut_relier_ses_propres_terminals;
|
||||
void drawSelection(QPainter *, const QStyleOptionGraphicsItem *);
|
||||
void updatePixmap();
|
||||
Terminal::Orientation nextOrientation(Terminal::Orientation o) const;
|
||||
Terminal::Orientation previousOrientation(Terminal::Orientation o) const;
|
||||
static QList<QDomElement> findInDomElement(QDomElement, QString, QString);
|
||||
|
||||
QSize dimensions;
|
||||
QPoint hotspot_coord;
|
||||
QPixmap apercu;
|
||||
QMenu menu;
|
||||
};
|
||||
|
||||
/**
|
||||
Permet de savoir si l'element accepte les connexions internes,
|
||||
c'est-a-dire que ses bornes peuvent etre reliees entre elles
|
||||
@return true si l'element accepte les connexions internes, false sinon
|
||||
*/
|
||||
inline bool Element::connexionsInternesAcceptees() {
|
||||
return(peut_relier_ses_propres_terminals);
|
||||
}
|
||||
|
||||
/**
|
||||
Permet de specifier si l'element accepte les connexions internes,
|
||||
c'est-a-dire que ses bornes peuvent etre reliees entre elles
|
||||
@param cia true pour que l'element accepte les connexions internes, false pour
|
||||
qu'il les interdise
|
||||
*/
|
||||
inline void Element::setConnexionsInternesAcceptees(bool cia) {
|
||||
peut_relier_ses_propres_terminals = cia;
|
||||
}
|
||||
|
||||
/**
|
||||
Permet de connaitre l'orientation actuelle de l'element
|
||||
@return L'orientation actuelle de l'element
|
||||
*/
|
||||
inline Terminal::Orientation Element::orientation() const {
|
||||
return(ori);
|
||||
}
|
||||
|
||||
/**
|
||||
Permet de savoir si l'element peut etre positionne dans une orientation
|
||||
donnee.
|
||||
@param o L'orientation en question
|
||||
@return true si l'orientation est utilisable, false sinon
|
||||
*/
|
||||
inline bool Element::acceptOrientation(Terminal::Orientation o) const {
|
||||
switch(o) {
|
||||
case Terminal::Nord: return(ori_n);
|
||||
case Terminal::Est: return(ori_e);
|
||||
case Terminal::Sud: return(ori_s);
|
||||
case Terminal::Ouest: return(ori_w);
|
||||
default: return(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Permet de connaitre l'orientation par defaut de l'element
|
||||
@return l'orientation par defaut de l'element
|
||||
*/
|
||||
inline Terminal::Orientation Element::defaultOrientation() const {
|
||||
return(ori_d);
|
||||
}
|
||||
|
||||
/**
|
||||
Permet de connaitre la prochaine orientation autorisee pour cet element
|
||||
@return la prochaine orientation autorisee pour cet element
|
||||
*/
|
||||
inline Terminal::Orientation Element::nextAcceptableOrientation() const {
|
||||
Terminal::Orientation retour = nextOrientation(ori);
|
||||
for (int i = 0 ; i < 4 ; ++ i) {
|
||||
if (acceptOrientation(retour)) return(retour);
|
||||
retour = nextOrientation(retour);
|
||||
}
|
||||
// on ne devrait pas arriver la : renvoi d'une valeur par defaut = nord
|
||||
return(Terminal::Nord);
|
||||
}
|
||||
|
||||
/**
|
||||
Permet de connaitre la precedente orientation autorisee pour cet element
|
||||
@return la precedente orientation autorisee pour cet element
|
||||
*/
|
||||
inline Terminal::Orientation Element::previousAcceptableOrientation() const {
|
||||
Terminal::Orientation retour = previousOrientation(ori);
|
||||
for (int i = 0 ; i < 4 ; ++ i) {
|
||||
if (acceptOrientation(retour)) return(retour);
|
||||
retour = previousOrientation(retour);
|
||||
}
|
||||
// on ne devrait pas arriver la : renvoi d'une valeur par defaut = nord
|
||||
return(Terminal::Nord);
|
||||
}
|
||||
|
||||
/**
|
||||
Permet de connaitre l'orientation suivante apres celle donnee en parametre.
|
||||
Les orientations sont generalement presentees dans l'ordre suivant : Nord,
|
||||
Est, Sud, Ouest.
|
||||
@param o une orientation
|
||||
@return l'orientation suivante
|
||||
*/
|
||||
inline Terminal::Orientation Element::nextOrientation(Terminal::Orientation o) const {
|
||||
if (o < 0 || o > 2) return(Terminal::Nord);
|
||||
return((Terminal::Orientation)(o + 1));
|
||||
}
|
||||
|
||||
/**
|
||||
Permet de connaitre l'orientation precedant celle donnee en parametre.
|
||||
Les orientations sont generalement presentees dans l'ordre suivant : Nord,
|
||||
Est, Sud, Ouest.
|
||||
@param o une orientation
|
||||
@return l'orientation precedente
|
||||
*/
|
||||
inline Terminal::Orientation Element::previousOrientation(Terminal::Orientation o) const {
|
||||
if (o < 0 || o > 3) return(Terminal::Nord);
|
||||
if (o == Terminal::Nord) return(Terminal::Ouest);
|
||||
return((Terminal::Orientation)(o - 1));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -3,7 +3,11 @@
|
||||
#include "elementscategoryeditor.h"
|
||||
#include "elementscategory.h"
|
||||
|
||||
ElementsCategoriesWidget::ElementsCategoriesWidget(QWidget * parent) : QWidget(parent) {
|
||||
/**
|
||||
Constructeur
|
||||
@param parent Le QWidget parent
|
||||
*/
|
||||
ElementsCategoriesWidget::ElementsCategoriesWidget(QWidget *parent) : QWidget(parent) {
|
||||
// initialise la liste des categories
|
||||
elementscategorieslist = new ElementsCategoriesList(this);
|
||||
|
||||
@ -39,10 +43,16 @@ ElementsCategoriesWidget::ElementsCategoriesWidget(QWidget * parent) : QWidget(p
|
||||
setLayout(vlayout);
|
||||
}
|
||||
|
||||
/**
|
||||
Destructeur
|
||||
*/
|
||||
ElementsCategoriesWidget::~ElementsCategoriesWidget() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
Lance un editeur de categorie en mode "creation de categorie"
|
||||
*/
|
||||
void ElementsCategoriesWidget::newCategory() {
|
||||
QString s_c_path = elementscategorieslist -> selectedCategoryPath();
|
||||
if (s_c_path.isNull()) return;
|
||||
@ -50,6 +60,9 @@ void ElementsCategoriesWidget::newCategory() {
|
||||
elementscategorieslist -> reload();
|
||||
}
|
||||
|
||||
/**
|
||||
Lance un editeur de categorie en mode "edition de categorie"
|
||||
*/
|
||||
void ElementsCategoriesWidget::editCategory() {
|
||||
QString s_c_path = elementscategorieslist -> selectedCategoryPath();
|
||||
if (s_c_path.isNull()) return;
|
||||
@ -57,6 +70,9 @@ void ElementsCategoriesWidget::editCategory() {
|
||||
elementscategorieslist -> reload();
|
||||
}
|
||||
|
||||
/**
|
||||
Supprime la categorie selectionnee
|
||||
*/
|
||||
void ElementsCategoriesWidget::removeCategory() {
|
||||
// recupere le nom et le chemin de la categorie
|
||||
QString s_c_name = elementscategorieslist -> selectedCategoryName();
|
||||
@ -103,6 +119,10 @@ void ElementsCategoriesWidget::removeCategory() {
|
||||
elementscategorieslist -> reload();
|
||||
}
|
||||
|
||||
/**
|
||||
Met a jour l'etat (active / desactive) des boutons en fonction de ce qui
|
||||
est selectionne.
|
||||
*/
|
||||
void ElementsCategoriesWidget::updateButtons() {
|
||||
QList<QTreeWidgetItem *> sel_items = elementscategorieslist -> selectedItems();
|
||||
bool sel_items_empty = !sel_items.isEmpty();
|
||||
|
@ -3,7 +3,8 @@
|
||||
#include <QtGui>
|
||||
/**
|
||||
Cette classe represente un widget integrant la liste des categories
|
||||
de l'utilisteur surplombee de boutons permettant d'ajouter
|
||||
de l'utilisteur surplombee de boutons permettant d'ajouter, de modifier
|
||||
ou de supprimer des categories
|
||||
*/
|
||||
class ElementsCategoriesList;
|
||||
class ElementsCategoriesWidget : public QWidget {
|
||||
@ -26,7 +27,7 @@ class ElementsCategoriesWidget : public QWidget {
|
||||
bool rmdir(const QString &);
|
||||
|
||||
public:
|
||||
inline ElementsCategoriesList &elementsCategoriesList() const { return(*elementscategorieslist); }
|
||||
ElementsCategoriesList &elementsCategoriesList() const;
|
||||
|
||||
public slots:
|
||||
void newCategory();
|
||||
@ -34,4 +35,12 @@ class ElementsCategoriesWidget : public QWidget {
|
||||
void removeCategory();
|
||||
void updateButtons();
|
||||
};
|
||||
|
||||
/**
|
||||
@return La liste des categories d'elements du widget
|
||||
*/
|
||||
inline ElementsCategoriesList &ElementsCategoriesWidget::elementsCategoriesList() const {
|
||||
return(*elementscategorieslist);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -103,14 +103,27 @@ QHash<QString, QString> ElementsCategory::categoryNames() const {
|
||||
return(category_names);
|
||||
}
|
||||
|
||||
/**
|
||||
Vide la liste des noms de la categorie
|
||||
*/
|
||||
void ElementsCategory::clearNames() {
|
||||
category_names.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
Ajoute un nom a la categorie.
|
||||
Si la langue existe deja, le nom pour cette langue est remplace.
|
||||
@param lang La langue pour laquelle le nom est utilisable
|
||||
@param value Le nom
|
||||
*/
|
||||
void ElementsCategory::addName(const QString &lang, const QString &value) {
|
||||
category_names.insert(lang, value);
|
||||
}
|
||||
|
||||
/**
|
||||
Cree la categorie
|
||||
@return true si la creation a reussi, false sinon
|
||||
*/
|
||||
bool ElementsCategory::write() const {
|
||||
|
||||
// cree le dossier de la categorie
|
||||
|
@ -1,6 +1,11 @@
|
||||
#ifndef ELEMENTS_CATEGORY_H
|
||||
#define ELEMENTS_CATEGORY_H
|
||||
#include <QtCore>
|
||||
/**
|
||||
Cette classe represente une categorie d'elements.
|
||||
Une categorie d'elements est en fait un dossier avec un fichier
|
||||
qet_directory contenant ses caracteristiques (pour le moment : ses noms).
|
||||
*/
|
||||
class ElementsCategory : public QDir {
|
||||
// Constructeur, destructeur
|
||||
public:
|
||||
|
@ -1,6 +1,10 @@
|
||||
#include "elementspanelwidget.h"
|
||||
#include "newelementwizard.h"
|
||||
|
||||
/**
|
||||
Constructeur
|
||||
@param parent Le QWidget parent de ce widget
|
||||
*/
|
||||
ElementsPanelWidget::ElementsPanelWidget(QWidget *parent) : QWidget(parent) {
|
||||
// initalise le panel d'elements
|
||||
elements_panel = new ElementsPanel(this);
|
||||
@ -21,6 +25,9 @@ ElementsPanelWidget::ElementsPanelWidget(QWidget *parent) : QWidget(parent) {
|
||||
setLayout(vlayout);
|
||||
}
|
||||
|
||||
/**
|
||||
Appelle l'assistant de creation de nouvel element
|
||||
*/
|
||||
void ElementsPanelWidget::newElement() {
|
||||
NewElementWizard *new_element_wizard = new NewElementWizard();
|
||||
new_element_wizard -> exec();
|
||||
|
@ -1,24 +1,29 @@
|
||||
#ifndef ELEMENTS_PANEL_WIDGET_H
|
||||
#define ELEMENTS_PANEL_WIDGET_H
|
||||
#include <QtGui>
|
||||
#include "elementspanel.h"
|
||||
class ElementsPanelWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
// constructeurs
|
||||
public:
|
||||
ElementsPanelWidget(QWidget * = 0);
|
||||
|
||||
// attributs
|
||||
private:
|
||||
ElementsPanel *elements_panel;
|
||||
QToolBar *toolbar;
|
||||
|
||||
// methodes
|
||||
public:
|
||||
inline ElementsPanel &elementsPanel() const { return(*elements_panel); }
|
||||
|
||||
public slots:
|
||||
void newElement();
|
||||
};
|
||||
#define ELEMENTS_PANEL_WIDGET_H
|
||||
#include <QtGui>
|
||||
#include "elementspanel.h"
|
||||
|
||||
/**
|
||||
Cette classe est un widget qui contient le panel d'elements surplombe d'une
|
||||
barre d'outils avec differentes actions pour gerer les elements.
|
||||
*/
|
||||
class ElementsPanelWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
// constructeurs
|
||||
public:
|
||||
ElementsPanelWidget(QWidget * = 0);
|
||||
|
||||
// attributs
|
||||
private:
|
||||
ElementsPanel *elements_panel;
|
||||
QToolBar *toolbar;
|
||||
|
||||
// methodes
|
||||
public:
|
||||
inline ElementsPanel &elementsPanel() const { return(*elements_panel); }
|
||||
|
||||
public slots:
|
||||
void newElement();
|
||||
};
|
||||
#endif
|
||||
|
@ -1,25 +1,48 @@
|
||||
#include "elementtextitem.h"
|
||||
|
||||
/**
|
||||
Constructeur
|
||||
@param parent Le QGraphicsItem parent du champ de texte
|
||||
@param scene La scene a laquelle appartient le champ de texte
|
||||
*/
|
||||
ElementTextItem::ElementTextItem(QGraphicsItem *parent, QGraphicsScene *scene) : QGraphicsTextItem(parent, scene) {
|
||||
follow_parent_rotations = false;
|
||||
setTextInteractionFlags(Qt::TextEditorInteraction);
|
||||
}
|
||||
|
||||
/**
|
||||
Constructeur
|
||||
@param parent Le QGraphicsItem parent du champ de texte
|
||||
@param scene La scene a laquelle appartient le champ de texte
|
||||
@param text Le texte affiche par le champ de texte
|
||||
*/
|
||||
ElementTextItem::ElementTextItem(const QString &text, QGraphicsItem *parent, QGraphicsScene *scene) : QGraphicsTextItem(text, parent, scene) {
|
||||
follow_parent_rotations = false;
|
||||
setTextInteractionFlags(Qt::TextEditorInteraction);
|
||||
}
|
||||
|
||||
/**
|
||||
Modifie la position du champ de texte
|
||||
@param pos La nouvelle position du champ de texte
|
||||
*/
|
||||
void ElementTextItem::setPos(const QPointF &pos) {
|
||||
QPointF actual_pos = pos;
|
||||
actual_pos -= QPointF(0.0, boundingRect().height() / 2.0);
|
||||
QGraphicsItem::setPos(actual_pos);
|
||||
}
|
||||
|
||||
/**
|
||||
Modifie la position du champ de texte
|
||||
@param x La nouvelle abscisse du champ de texte
|
||||
@param y La nouvelle ordonnee du champ de texte
|
||||
*/
|
||||
void ElementTextItem::setPos(qreal x, qreal y) {
|
||||
setPos(QPointF(x, y));
|
||||
}
|
||||
|
||||
/**
|
||||
@return La position (bidouillee) du champ de texte
|
||||
*/
|
||||
QPointF ElementTextItem::pos() const {
|
||||
QPointF actual_pos = QGraphicsTextItem::pos();
|
||||
actual_pos += QPointF(0.0, boundingRect().height() / 2.0);
|
||||
|
@ -1,27 +1,51 @@
|
||||
#ifndef ELEMENT_TEXT_ITEM_H
|
||||
#define ELEMENT_TEXT_ITEM_H
|
||||
#include <QGraphicsTextItem>
|
||||
#include <QtXml>
|
||||
class ElementTextItem : public QGraphicsTextItem {
|
||||
// constructeurs
|
||||
public:
|
||||
ElementTextItem(QGraphicsItem * = 0, QGraphicsScene * = 0);
|
||||
ElementTextItem(const QString &, QGraphicsItem * = 0, QGraphicsScene * = 0);
|
||||
|
||||
// attributs
|
||||
private:
|
||||
bool follow_parent_rotations;
|
||||
|
||||
// methodes
|
||||
public:
|
||||
enum { Type = UserType + 1003 };
|
||||
virtual int type() const { return Type; }
|
||||
inline bool followParentRotations() const { return(follow_parent_rotations); }
|
||||
inline void setFollowParentRotations(bool frp) { follow_parent_rotations = frp; }
|
||||
void fromXml(QDomElement &);
|
||||
QDomElement toXml(QDomDocument &);
|
||||
void setPos(const QPointF &);
|
||||
void setPos(qreal, qreal);
|
||||
QPointF pos() const;
|
||||
};
|
||||
#define ELEMENT_TEXT_ITEM_H
|
||||
#include <QGraphicsTextItem>
|
||||
#include <QtXml>
|
||||
/**
|
||||
Cette classe represente un element de texte editable.
|
||||
Il est possible pour ce champ de texte de rester dans le sens de la lecture
|
||||
malgre les rotations de son element parent.
|
||||
*/
|
||||
class ElementTextItem : public QGraphicsTextItem {
|
||||
// constructeurs
|
||||
public:
|
||||
ElementTextItem(QGraphicsItem * = 0, QGraphicsScene * = 0);
|
||||
ElementTextItem(const QString &, QGraphicsItem * = 0, QGraphicsScene * = 0);
|
||||
|
||||
// attributs
|
||||
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 setPos(const QPointF &);
|
||||
void setPos(qreal, qreal);
|
||||
QPointF pos() const;
|
||||
};
|
||||
|
||||
/**
|
||||
Permet de savoir si le champ de texte suit les rotations de son parent.
|
||||
@return true si le champ de texte suit les rotations de son parent, false
|
||||
sinon
|
||||
*/
|
||||
inline bool ElementTextItem::followParentRotations() const {
|
||||
return(follow_parent_rotations);
|
||||
}
|
||||
|
||||
/**
|
||||
Permet de specifier si le champ de texte suit les rotations de son parent.
|
||||
@param frp true si le champ de texte doit suivre les rotations de son
|
||||
parent, false pour qu'ils ne les suivent pas
|
||||
*/
|
||||
inline void ElementTextItem::setFollowParentRotations(bool frp) {
|
||||
follow_parent_rotations = frp;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -216,6 +216,9 @@ QWidget *ExportDialog::rightPart() {
|
||||
return(retour);
|
||||
}
|
||||
|
||||
/**
|
||||
Slot corrigeant la largeur (typiquement lors d'un changement de la hauteur)
|
||||
*/
|
||||
void ExportDialog::slot_correctWidth() {
|
||||
if (!keep_aspect_ratio -> isChecked() || dontchangewidth) return;
|
||||
dontchangeheight = true;
|
||||
@ -223,6 +226,9 @@ void ExportDialog::slot_correctWidth() {
|
||||
dontchangeheight = false;
|
||||
}
|
||||
|
||||
/**
|
||||
Slot corrigeant la hauteur (typiquement lors d'un changement de la largeur)
|
||||
*/
|
||||
void ExportDialog::slot_correctHeight() {
|
||||
if (!keep_aspect_ratio -> isChecked() || dontchangeheight) return;
|
||||
dontchangewidth = true;
|
||||
@ -230,6 +236,9 @@ void ExportDialog::slot_correctHeight() {
|
||||
dontchangewidth = false;
|
||||
}
|
||||
|
||||
/**
|
||||
Slot demandant a l'utilisateur de choisir un fichier
|
||||
*/
|
||||
void ExportDialog::slot_chooseAFile() {
|
||||
QString user_file = QFileDialog::getSaveFileName(
|
||||
this,
|
||||
@ -243,6 +252,10 @@ void ExportDialog::slot_chooseAFile() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Genere l'image a exporter
|
||||
@return l'image a exporter
|
||||
*/
|
||||
QImage ExportDialog::generateImage() {
|
||||
// memorise les parametres relatifs au schema
|
||||
bool state_drawBorder = diagram -> border_and_inset.borderIsDisplayed();
|
||||
@ -280,6 +293,10 @@ QImage ExportDialog::generateImage() {
|
||||
return(image);
|
||||
}
|
||||
|
||||
/**
|
||||
Slot effectuant les verifications necessaires apres la validation du
|
||||
dialogue.
|
||||
*/
|
||||
void ExportDialog::slot_check() {
|
||||
|
||||
// verifie que le fichier a ete specifie
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "qetapp.h"
|
||||
//#include "diagram.h"
|
||||
#include "diagramview.h"
|
||||
#include "elementspanelwidget.h"
|
||||
#include "aboutqet.h"
|
||||
|
@ -134,6 +134,10 @@ bool Terminal::addConducer(Conducer *f) {
|
||||
return(true);
|
||||
}
|
||||
|
||||
/**
|
||||
Enleve un conducteur donne a la borne
|
||||
@param f Conducteur a enlever
|
||||
*/
|
||||
void Terminal::removeConducer(Conducer *f) {
|
||||
int index = liste_conducers.indexOf(f);
|
||||
if (index == -1) return;
|
||||
@ -419,4 +423,3 @@ bool Terminal::fromXml(QDomElement &terminal) {
|
||||
terminal.attribute("orientation").toInt() == sens
|
||||
);
|
||||
}
|
||||
|
||||
|
175
terminal.h
175
terminal.h
@ -1,82 +1,97 @@
|
||||
#ifndef BORNE_H
|
||||
#define BORNE_H
|
||||
#define TAILLE_BORNE 4
|
||||
#include <QtGui>
|
||||
#include <QtXml>
|
||||
class Conducer;
|
||||
class Element;
|
||||
class Diagram;
|
||||
/**
|
||||
Classe modelisant la « borne » d'un appareil, c'est-a-dire un
|
||||
branchement possible pour un Conducteur.
|
||||
*/
|
||||
class Terminal : public QGraphicsItem {
|
||||
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);
|
||||
|
||||
// destructeur
|
||||
~Terminal();
|
||||
|
||||
// implementation des methodes virtuelles pures de QGraphicsItem
|
||||
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
|
||||
QRectF boundingRect() const;
|
||||
|
||||
// methodes de manipulation des conducteurs lies a cette borne
|
||||
bool addConducer(Conducer *);
|
||||
void removeConducer(Conducer *);
|
||||
inline int nbConducers() const { return(liste_conducers.size()); }
|
||||
|
||||
// methodes de lecture
|
||||
QList<Conducer *> conducers() const;
|
||||
Terminal::Orientation orientation() const;
|
||||
inline QPointF amarrageConducer() const { return(mapToScene(amarrage_conducer)); }
|
||||
void updateConducer(QPointF = QPointF());
|
||||
|
||||
// methodes relatives a l'import/export au format XML
|
||||
static bool valideXml(QDomElement &);
|
||||
bool fromXml (QDomElement &);
|
||||
QDomElement toXml (QDomDocument &) const;
|
||||
|
||||
protected:
|
||||
// methodes de gestion des evenements
|
||||
void hoverEnterEvent (QGraphicsSceneHoverEvent *);
|
||||
void hoverMoveEvent (QGraphicsSceneHoverEvent *);
|
||||
void hoverLeaveEvent (QGraphicsSceneHoverEvent *);
|
||||
void mousePressEvent (QGraphicsSceneMouseEvent *);
|
||||
void mouseMoveEvent (QGraphicsSceneMouseEvent *);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
|
||||
|
||||
private:
|
||||
// pointeur vers la QGraphicsScene de type Diagram (evite quelques casts en interne)
|
||||
Diagram *diagram_scene;
|
||||
// coordonnees des points d'amarrage
|
||||
QPointF amarrage_conducer;
|
||||
QPointF amarrage_elmt;
|
||||
// orientation de la borne
|
||||
Terminal::Orientation sens;
|
||||
// liste des conducers lies a cette borne
|
||||
QList<Conducer *> liste_conducers;
|
||||
// pointeur vers un rectangle correspondant au bounding rect ; permet de ne calculer le bounding rect qu'une seule fois ; le pointeur c'est parce que le compilo exige une methode const
|
||||
QRectF *br;
|
||||
Terminal *terminal_precedente;
|
||||
bool hovered;
|
||||
// methode initialisant les differents membres de la borne
|
||||
void initialise(QPointF, Terminal::Orientation);
|
||||
// differentes couleurs utilisables pour l'effet "hover"
|
||||
QColor couleur_hovered;
|
||||
QColor couleur_neutre;
|
||||
QColor couleur_autorise;
|
||||
QColor couleur_prudence;
|
||||
QColor couleur_interdit;
|
||||
};
|
||||
#define BORNE_H
|
||||
#define TAILLE_BORNE 4
|
||||
#include <QtGui>
|
||||
#include <QtXml>
|
||||
class Conducer;
|
||||
class Element;
|
||||
class Diagram;
|
||||
/**
|
||||
Classe modelisant la « borne » d'un appareil, c'est-a-dire un
|
||||
branchement possible pour un Conducteur.
|
||||
*/
|
||||
class Terminal : public QGraphicsItem {
|
||||
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);
|
||||
|
||||
// destructeur
|
||||
~Terminal();
|
||||
|
||||
// implementation des methodes virtuelles pures de QGraphicsItem
|
||||
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
|
||||
QRectF boundingRect() const;
|
||||
|
||||
// methodes de manipulation des conducteurs lies a cette borne
|
||||
bool addConducer(Conducer *);
|
||||
void removeConducer(Conducer *);
|
||||
int nbConducers() const;
|
||||
|
||||
// methodes de lecture
|
||||
QList<Conducer *> 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;
|
||||
|
||||
protected:
|
||||
// methodes de gestion des evenements
|
||||
void hoverEnterEvent (QGraphicsSceneHoverEvent *);
|
||||
void hoverMoveEvent (QGraphicsSceneHoverEvent *);
|
||||
void hoverLeaveEvent (QGraphicsSceneHoverEvent *);
|
||||
void mousePressEvent (QGraphicsSceneMouseEvent *);
|
||||
void mouseMoveEvent (QGraphicsSceneMouseEvent *);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
|
||||
|
||||
private:
|
||||
// pointeur vers la QGraphicsScene de type Diagram (evite quelques casts en interne)
|
||||
Diagram *diagram_scene;
|
||||
// coordonnees des points d'amarrage
|
||||
QPointF amarrage_conducer;
|
||||
QPointF amarrage_elmt;
|
||||
// orientation de la borne
|
||||
Terminal::Orientation sens;
|
||||
// liste des conducers lies a cette borne
|
||||
QList<Conducer *> liste_conducers;
|
||||
// pointeur vers un rectangle correspondant au bounding rect ; permet de ne calculer le bounding rect qu'une seule fois ; le pointeur c'est parce que le compilo exige une methode const
|
||||
QRectF *br;
|
||||
Terminal *terminal_precedente;
|
||||
bool hovered;
|
||||
// methode initialisant les differents membres de la borne
|
||||
void initialise(QPointF, Terminal::Orientation);
|
||||
// differentes couleurs utilisables pour l'effet "hover"
|
||||
QColor couleur_hovered;
|
||||
QColor couleur_neutre;
|
||||
QColor couleur_autorise;
|
||||
QColor couleur_prudence;
|
||||
QColor couleur_interdit;
|
||||
};
|
||||
|
||||
/**
|
||||
@return Le nombre de conducteurs associes a la borne
|
||||
*/
|
||||
inline int Terminal::nbConducers() const {
|
||||
return(liste_conducers.size());
|
||||
}
|
||||
|
||||
/**
|
||||
@return La position du point d'amarrage de la borne
|
||||
*/
|
||||
inline QPointF Terminal::amarrageConducer() const {
|
||||
return(mapToScene(amarrage_conducer));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user