mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 22:00:35 +01:00
Factorisation de code : reunion des 3 proprietes (type, singleLineProperties et texte) au sein d'une meme classe ConductorProperties
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@177 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
226
conductor.cpp
226
conductor.cpp
@@ -23,7 +23,6 @@ Conductor::Conductor(Terminal *p1, Terminal* p2, Element *parent, QGraphicsScene
|
|||||||
terminal1(p1),
|
terminal1(p1),
|
||||||
terminal2(p2),
|
terminal2(p2),
|
||||||
destroyed(false),
|
destroyed(false),
|
||||||
type_(Multi),
|
|
||||||
segments(NULL),
|
segments(NULL),
|
||||||
previous_z_value(zValue()),
|
previous_z_value(zValue()),
|
||||||
modified_path(false),
|
modified_path(false),
|
||||||
@@ -55,8 +54,8 @@ Conductor::Conductor(Terminal *p1, Terminal* p2, Element *parent, QGraphicsScene
|
|||||||
|
|
||||||
// ajout du champ de texte editable
|
// ajout du champ de texte editable
|
||||||
text_item = new DiagramTextItem();
|
text_item = new DiagramTextItem();
|
||||||
text_item -> setPlainText("_");
|
text_item -> setPlainText(properties_.text);
|
||||||
text_item -> previous_text = "_";
|
text_item -> previous_text = properties_.text;
|
||||||
calculateTextItemPosition();
|
calculateTextItemPosition();
|
||||||
text_item -> setParentItem(this);
|
text_item -> setParentItem(this);
|
||||||
}
|
}
|
||||||
@@ -417,9 +416,9 @@ void Conductor::paint(QPainter *qp, const QStyleOptionGraphicsItem *options, QWi
|
|||||||
|
|
||||||
// dessin du conducteur
|
// dessin du conducteur
|
||||||
qp -> drawPath(path());
|
qp -> drawPath(path());
|
||||||
if (type_ == Single) {
|
if (properties_.type == ConductorProperties::Single) {
|
||||||
if (isSelected()) qp -> setBrush(Qt::red);
|
if (isSelected()) qp -> setBrush(Qt::red);
|
||||||
singleLineProperties.draw(
|
properties_.singleLineProperties.draw(
|
||||||
qp,
|
qp,
|
||||||
middleSegment() -> isHorizontal() ? QET::Horizontal : QET::Vertical,
|
middleSegment() -> isHorizontal() ? QET::Horizontal : QET::Vertical,
|
||||||
QRectF(middleSegment() -> middle() - QPointF(10.0, 7.5), QSizeF(20.0, 15.0))
|
QRectF(middleSegment() -> middle() - QPointF(10.0, 7.5), QSizeF(20.0, 15.0))
|
||||||
@@ -792,18 +791,8 @@ bool Conductor::hasClickedOn(QPointF press_point, QPointF point) const {
|
|||||||
*/
|
*/
|
||||||
bool Conductor::fromXml(QDomElement &e) {
|
bool Conductor::fromXml(QDomElement &e) {
|
||||||
// recupere la "configuration" du conducteur
|
// recupere la "configuration" du conducteur
|
||||||
if (e.attribute("type") == typeToString(Single)) {
|
properties_.fromXml(e);
|
||||||
// recupere les parametres specifiques a un conducteur unifilaire
|
readProperties();
|
||||||
singleLineProperties.fromXml(e);
|
|
||||||
setConductorType(Conductor::Single);
|
|
||||||
} else if (e.attribute("type") == typeToString(Simple)) {
|
|
||||||
setConductorType(Conductor::Simple);
|
|
||||||
} else {
|
|
||||||
// recupere le champ de texte
|
|
||||||
text_item -> setPlainText(e.attribute("num"));
|
|
||||||
text_item -> previous_text = e.attribute("num");
|
|
||||||
setConductorType(Conductor::Multi);
|
|
||||||
}
|
|
||||||
|
|
||||||
// parcourt les elements XML "segment" et en extrait deux listes de longueurs
|
// parcourt les elements XML "segment" et en extrait deux listes de longueurs
|
||||||
// les segments non valides sont ignores
|
// les segments non valides sont ignores
|
||||||
@@ -895,12 +884,7 @@ QDomElement Conductor::toXml(QDomDocument &d, QHash<Terminal *, int> &table_adr_
|
|||||||
}
|
}
|
||||||
|
|
||||||
// exporte la "configuration" du conducteur
|
// exporte la "configuration" du conducteur
|
||||||
e.setAttribute("type", typeToString(type_));
|
properties_.toXml(d, e);
|
||||||
if (type_ == Single) {
|
|
||||||
singleLineProperties.toXml(d, e);
|
|
||||||
} else if (type_ == Multi) {
|
|
||||||
e.setAttribute("num", text_item -> toPlainText());
|
|
||||||
}
|
|
||||||
return(e);
|
return(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1014,23 +998,6 @@ ConductorProfile Conductor::profile() const {
|
|||||||
return(conductor_profile);
|
return(conductor_profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @return le type du conducteur
|
|
||||||
Conductor::ConductorType Conductor::conductorType() const {
|
|
||||||
return(type_);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Definit le conducteur comme etant unifilaire ou multifilaire
|
|
||||||
Un conducteur unifilaire peut arborer des symboles mais pas de texte
|
|
||||||
et vice-versa.
|
|
||||||
@param sl true pour un conducteur unifilaire, false pour un conducteur multifilaire
|
|
||||||
*/
|
|
||||||
void Conductor::setConductorType(ConductorType t) {
|
|
||||||
if (typeToString(t).isNull()) return;
|
|
||||||
type_ = t;
|
|
||||||
text_item -> setVisible(type_ == Conductor::Multi);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @return le texte du conducteur
|
/// @return le texte du conducteur
|
||||||
QString Conductor::text() const {
|
QString Conductor::text() const {
|
||||||
return(text_item -> toPlainText());
|
return(text_item -> toPlainText());
|
||||||
@@ -1044,178 +1011,21 @@ void Conductor::setText(const QString &t) {
|
|||||||
text_item -> previous_text = t;
|
text_item -> previous_text = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/// @param p les proprietes de ce conducteur
|
||||||
Constructeur par defaut
|
void Conductor::setProperties(const ConductorProperties &p) {
|
||||||
*/
|
properties_ = p;
|
||||||
SingleLineProperties::SingleLineProperties() :
|
readProperties();
|
||||||
hasGround(true),
|
|
||||||
hasNeutral(true),
|
|
||||||
phases(1)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Destructeur
|
/// @return les proprietes de ce conducteur
|
||||||
SingleLineProperties::~SingleLineProperties() {
|
ConductorProperties Conductor::properties() const {
|
||||||
|
return(properties_);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Definit le nombre de phases (0, 1, 2, ou 3)
|
Relit les proprietes et les applique
|
||||||
@param n Nombre de phases
|
|
||||||
*/
|
*/
|
||||||
void SingleLineProperties::setPhasesCount(int n) {
|
void Conductor::readProperties() {
|
||||||
phases = qBound(0, n, 3);
|
setText(properties_.text);
|
||||||
}
|
text_item -> setVisible(properties_.type == ConductorProperties::Multi);
|
||||||
|
|
||||||
/// @return le nombre de phases (0, 1, 2, ou 3)
|
|
||||||
unsigned short int SingleLineProperties::phasesCount() {
|
|
||||||
return(phases);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Dessine les symboles propres a un conducteur unifilaire
|
|
||||||
@param painter QPainter a utiliser pour dessiner les symboles
|
|
||||||
@param direction direction du segment sur lequel les symboles apparaitront
|
|
||||||
@param rect rectangle englobant le dessin ; utilise pour specifier a la fois la position et la taille du dessin
|
|
||||||
*/
|
|
||||||
void SingleLineProperties::draw(QPainter *painter, QET::ConductorSegmentType direction, const QRectF &rect) {
|
|
||||||
// s'il n'y a rien a dessiner, on retourne immediatement
|
|
||||||
if (!hasNeutral && !hasGround && !phases) return;
|
|
||||||
|
|
||||||
// prepare le QPainter
|
|
||||||
painter -> save();
|
|
||||||
QPen pen(painter -> pen());
|
|
||||||
pen.setCapStyle(Qt::FlatCap);
|
|
||||||
pen.setJoinStyle(Qt::MiterJoin);
|
|
||||||
painter -> setPen(pen);
|
|
||||||
painter -> setRenderHint(QPainter::Antialiasing, true);
|
|
||||||
|
|
||||||
uint symbols_count = (hasNeutral ? 1 : 0) + (hasGround ? 1 : 0) + phases;
|
|
||||||
qreal interleave;
|
|
||||||
qreal symbol_width;
|
|
||||||
if (direction == QET::Horizontal) {
|
|
||||||
interleave = rect.width() / (symbols_count + 1);
|
|
||||||
symbol_width = rect.width() / 12;
|
|
||||||
for (uint i = 1 ; i <= symbols_count ; ++ i) {
|
|
||||||
// dessine le tronc du symbole
|
|
||||||
QPointF symbol_p1(rect.x() + (i * interleave) + symbol_width, rect.y() + rect.height() * 0.75);
|
|
||||||
QPointF symbol_p2(rect.x() + (i * interleave) - symbol_width, rect.y() + rect.height() * 0.25);
|
|
||||||
painter -> drawLine(QLineF(symbol_p1, symbol_p2));
|
|
||||||
|
|
||||||
// dessine le reste des symboles terre et neutre
|
|
||||||
if (hasGround && i == 1) {
|
|
||||||
drawGround(painter, direction, symbol_p2, symbol_width * 2.0);
|
|
||||||
} else if (hasNeutral && ((i == 1 && !hasGround) || (i == 2 && hasGround))) {
|
|
||||||
drawNeutral(painter, direction, symbol_p2, symbol_width * 1.35);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
interleave = rect.height() / (symbols_count + 1);
|
|
||||||
symbol_width = rect.height() / 12;
|
|
||||||
for (uint i = 1 ; i <= symbols_count ; ++ i) {
|
|
||||||
// dessine le tronc du symbole
|
|
||||||
QPointF symbol_p2(rect.x() + rect.width() * 0.75, rect.y() + (i * interleave) - symbol_width);
|
|
||||||
QPointF symbol_p1(rect.x() + rect.width() * 0.25, rect.y() + (i * interleave) + symbol_width);
|
|
||||||
painter -> drawLine(QLineF(symbol_p1, symbol_p2));
|
|
||||||
|
|
||||||
// dessine le reste des symboles terre et neutre
|
|
||||||
if (hasGround && i == 1) {
|
|
||||||
drawGround(painter, direction, symbol_p2, symbol_width * 2.0);
|
|
||||||
} else if (hasNeutral && ((i == 1 && !hasGround) || (i == 2 && hasGround))) {
|
|
||||||
drawNeutral(painter, direction, symbol_p2, symbol_width * 1.5);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
painter -> restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Dessine le segment correspondant au symbole de la terre sur un conducteur unifilaire
|
|
||||||
@param painter QPainter a utiliser pour dessiner le segment
|
|
||||||
@param direction direction du segment sur lequel le symbole apparaitra
|
|
||||||
@param center centre du segment
|
|
||||||
@param size taille du segment
|
|
||||||
*/
|
|
||||||
void SingleLineProperties::drawGround(QPainter *painter, QET::ConductorSegmentType direction, QPointF center, qreal size) {
|
|
||||||
painter -> save();
|
|
||||||
|
|
||||||
// prepare le QPainter
|
|
||||||
painter -> setRenderHint(QPainter::Antialiasing, false);
|
|
||||||
QPen pen2(painter -> pen());
|
|
||||||
pen2.setCapStyle(Qt::SquareCap);
|
|
||||||
painter -> setPen(pen2);
|
|
||||||
|
|
||||||
// dessine le segment representant la terre
|
|
||||||
qreal half_size = size / 2.0;
|
|
||||||
QPointF offset_point(
|
|
||||||
(direction == QET::Horizontal) ? half_size : 0.0,
|
|
||||||
(direction == QET::Horizontal) ? 0.0 : half_size
|
|
||||||
);
|
|
||||||
painter -> drawLine(
|
|
||||||
QLineF(
|
|
||||||
center + offset_point,
|
|
||||||
center - offset_point
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
painter -> restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Dessine le cercle correspondant au symbole du neutre sur un conducteur unifilaire
|
|
||||||
@param painter QPainter a utiliser pour dessiner le segment
|
|
||||||
@param direction direction du segment sur lequel le symbole apparaitra
|
|
||||||
@param center centre du cercle
|
|
||||||
@param size diametre du cercle
|
|
||||||
*/
|
|
||||||
void SingleLineProperties::drawNeutral(QPainter *painter, QET::ConductorSegmentType, QPointF center, qreal size) {
|
|
||||||
painter -> save();
|
|
||||||
|
|
||||||
// prepare le QPainter
|
|
||||||
if (painter -> brush() == Qt::NoBrush) painter -> setBrush(Qt::black);
|
|
||||||
painter -> setPen(Qt::NoPen);
|
|
||||||
|
|
||||||
// desine le cercle representant le neutre
|
|
||||||
painter -> drawEllipse(
|
|
||||||
QRectF(
|
|
||||||
center - QPointF(size / 2.0, size / 2.0),
|
|
||||||
QSizeF(size, size)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
painter -> restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
exporte les parametres du conducteur unifilaire sous formes d'attributs XML
|
|
||||||
ajoutes a l'element e.
|
|
||||||
@param d Document XML ; utilise pour ajouter (potentiellement) des elements XML
|
|
||||||
@param e Element XML auquel seront ajoutes des attributs
|
|
||||||
*/
|
|
||||||
void SingleLineProperties::toXml(QDomDocument &, QDomElement &e) const {
|
|
||||||
e.setAttribute("ground", hasGround ? "true" : "false");
|
|
||||||
e.setAttribute("neutral", hasNeutral ? "true" : "false");
|
|
||||||
e.setAttribute("phase", phases);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
importe les parametres du conducteur unifilaire a partir des attributs XML
|
|
||||||
de l'element e
|
|
||||||
@param e Element XML dont les attributs seront lus
|
|
||||||
*/
|
|
||||||
void SingleLineProperties::fromXml(QDomElement &e) {
|
|
||||||
hasGround = e.attribute("ground") == "true";
|
|
||||||
hasNeutral = e.attribute("neutral") == "true";
|
|
||||||
setPhasesCount(e.attribute("phase").toInt());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
|
|
||||||
*/
|
|
||||||
QString Conductor::typeToString(ConductorType t) {
|
|
||||||
switch(t) {
|
|
||||||
case Simple: return("simple");
|
|
||||||
case Single: return("single");
|
|
||||||
case Multi: return("mutli");
|
|
||||||
default: return(QString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
33
conductor.h
33
conductor.h
@@ -3,28 +3,10 @@
|
|||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
#include "terminal.h"
|
#include "terminal.h"
|
||||||
#include "conductorprofile.h"
|
#include "conductorprofile.h"
|
||||||
|
#include "conductorproperties.h"
|
||||||
#include "diagramtextitem.h"
|
#include "diagramtextitem.h"
|
||||||
class ConductorSegment;
|
class ConductorSegment;
|
||||||
class Element;
|
class Element;
|
||||||
/**
|
|
||||||
Cette classe represente les proprietes specifiques a un conducteur unifilaire
|
|
||||||
*/
|
|
||||||
class SingleLineProperties {
|
|
||||||
public:
|
|
||||||
SingleLineProperties();
|
|
||||||
virtual ~SingleLineProperties();
|
|
||||||
void setPhasesCount(int);
|
|
||||||
unsigned short int phasesCount();
|
|
||||||
void draw(QPainter *, QET::ConductorSegmentType, const QRectF &);
|
|
||||||
void toXml(QDomDocument &, QDomElement &) const;
|
|
||||||
void fromXml(QDomElement &);
|
|
||||||
bool hasGround;
|
|
||||||
bool hasNeutral;
|
|
||||||
private:
|
|
||||||
unsigned short int phases;
|
|
||||||
void drawGround (QPainter *, QET::ConductorSegmentType, QPointF, qreal);
|
|
||||||
void drawNeutral(QPainter *, QET::ConductorSegmentType, QPointF, qreal);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Cette classe represente un conducteur. Un conducteur relie deux bornes d'element.
|
Cette classe represente un conducteur. Un conducteur relie deux bornes d'element.
|
||||||
@@ -42,14 +24,11 @@ class Conductor : public QGraphicsPathItem {
|
|||||||
// attributs
|
// attributs
|
||||||
public:
|
public:
|
||||||
enum { Type = UserType + 1001 };
|
enum { Type = UserType + 1001 };
|
||||||
enum ConductorType { Simple, Single, Multi };
|
|
||||||
|
|
||||||
/// premiere borne a laquelle le fil est rattache
|
/// premiere borne a laquelle le fil est rattache
|
||||||
Terminal *terminal1;
|
Terminal *terminal1;
|
||||||
/// deuxieme borne a laquelle le fil est rattache
|
/// deuxieme borne a laquelle le fil est rattache
|
||||||
Terminal *terminal2;
|
Terminal *terminal2;
|
||||||
/// caracteristiques des conducteurs unifilaires
|
|
||||||
SingleLineProperties singleLineProperties;
|
|
||||||
|
|
||||||
// methodes
|
// methodes
|
||||||
public:
|
public:
|
||||||
@@ -70,10 +49,11 @@ class Conductor : public QGraphicsPathItem {
|
|||||||
bool fromXml(QDomElement &);
|
bool fromXml(QDomElement &);
|
||||||
QDomElement toXml(QDomDocument &, QHash<Terminal *, int> &) const;
|
QDomElement toXml(QDomDocument &, QHash<Terminal *, int> &) const;
|
||||||
const QList<ConductorSegment *> segmentsList() const;
|
const QList<ConductorSegment *> segmentsList() const;
|
||||||
|
void setProperties(const ConductorProperties &);
|
||||||
|
ConductorProperties properties() const;
|
||||||
void setProfile(const ConductorProfile &);
|
void setProfile(const ConductorProfile &);
|
||||||
ConductorProfile profile() const;
|
ConductorProfile profile() const;
|
||||||
ConductorType conductorType() const;
|
void readProperties();
|
||||||
void setConductorType(ConductorType);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *);
|
virtual void mousePressEvent(QGraphicsSceneMouseEvent *);
|
||||||
@@ -82,10 +62,10 @@ class Conductor : public QGraphicsPathItem {
|
|||||||
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *);
|
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/// caracteristiques du conducteur
|
||||||
|
ConductorProperties properties_;
|
||||||
/// booleen indiquant si le fil est encore valide
|
/// booleen indiquant si le fil est encore valide
|
||||||
bool destroyed;
|
bool destroyed;
|
||||||
/// enum indiquant le mode du conducteur : simple, unifilaire ou non
|
|
||||||
ConductorType type_;
|
|
||||||
/// champ de texte editable pour les conducteurs non unifilaires
|
/// champ de texte editable pour les conducteurs non unifilaires
|
||||||
DiagramTextItem *text_item;
|
DiagramTextItem *text_item;
|
||||||
/// segments composant le conducteur
|
/// segments composant le conducteur
|
||||||
@@ -124,6 +104,5 @@ class Conductor : public QGraphicsPathItem {
|
|||||||
static QPointF extendTerminal(const QPointF &, QET::Orientation, qreal = 12.0);
|
static QPointF extendTerminal(const QPointF &, QET::Orientation, qreal = 12.0);
|
||||||
static qreal conductor_bound(qreal, qreal, qreal, qreal = 0.0);
|
static qreal conductor_bound(qreal, qreal, qreal, qreal = 0.0);
|
||||||
static qreal conductor_bound(qreal, qreal, bool);
|
static qreal conductor_bound(qreal, qreal, bool);
|
||||||
static QString typeToString(ConductorType);
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -6,12 +6,23 @@
|
|||||||
@param parent QWidget parent
|
@param parent QWidget parent
|
||||||
*/
|
*/
|
||||||
ConductorPropertiesWidget::ConductorPropertiesWidget(QWidget *parent) :
|
ConductorPropertiesWidget::ConductorPropertiesWidget(QWidget *parent) :
|
||||||
QWidget(parent),
|
QWidget(parent)
|
||||||
type_(Conductor::Multi)
|
|
||||||
{
|
{
|
||||||
buildInterface();
|
buildInterface();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Constructeur
|
||||||
|
@param parent QWidget parent
|
||||||
|
@param cp Proprietes a editer
|
||||||
|
*/
|
||||||
|
ConductorPropertiesWidget::ConductorPropertiesWidget(const ConductorProperties &cp, QWidget *parent) :
|
||||||
|
QWidget(parent)
|
||||||
|
{
|
||||||
|
buildInterface();
|
||||||
|
setConductorProperties(cp);
|
||||||
|
}
|
||||||
|
|
||||||
/// construit l'interface du widget
|
/// construit l'interface du widget
|
||||||
void ConductorPropertiesWidget::buildInterface() {
|
void ConductorPropertiesWidget::buildInterface() {
|
||||||
|
|
||||||
@@ -69,56 +80,65 @@ void ConductorPropertiesWidget::buildInterface() {
|
|||||||
groupbox_layout -> addLayout(singleline_layout1);
|
groupbox_layout -> addLayout(singleline_layout1);
|
||||||
|
|
||||||
radio_buttons = new QButtonGroup(this);
|
radio_buttons = new QButtonGroup(this);
|
||||||
radio_buttons -> addButton(simple, Conductor::Simple);
|
radio_buttons -> addButton(simple, ConductorProperties::Simple);
|
||||||
radio_buttons -> addButton(multiline, Conductor::Multi);
|
radio_buttons -> addButton(multiline, ConductorProperties::Multi);
|
||||||
radio_buttons -> addButton(singleline, Conductor::Single);
|
radio_buttons -> addButton(singleline, ConductorProperties::Single);
|
||||||
|
|
||||||
buildConnections();
|
buildConnections();
|
||||||
setConductorType(Conductor::Multi);
|
setConductorType(ConductorProperties::Multi);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Met en place les connexions signaux/slots
|
/// Met en place les connexions signaux/slots
|
||||||
void ConductorPropertiesWidget::buildConnections() {
|
void ConductorPropertiesWidget::buildConnections() {
|
||||||
connect(phase_slider, SIGNAL(valueChanged(int)), phase_spinbox, SLOT(setValue(int)));
|
connect(phase_slider, SIGNAL(valueChanged(int)), phase_spinbox, SLOT(setValue(int)));
|
||||||
connect(phase_spinbox, SIGNAL(valueChanged(int)), phase_slider, SLOT(setValue(int)));
|
connect(phase_spinbox, SIGNAL(valueChanged(int)), phase_slider, SLOT(setValue(int)));
|
||||||
connect(ground_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateSingleLineConfig()));
|
connect(ground_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateConfig()));
|
||||||
connect(neutral_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateSingleLineConfig()));
|
connect(neutral_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateConfig()));
|
||||||
connect(phase_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateSingleLineConfig()));
|
connect(phase_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateConfig()));
|
||||||
connect(phase_slider, SIGNAL(valueChanged(int)), this, SLOT(updateSingleLineConfig()));
|
connect(phase_slider, SIGNAL(valueChanged(int)), this, SLOT(updateConfig()));
|
||||||
connect(radio_buttons, SIGNAL(buttonClicked(int)), this, SLOT(setConductorType(int)));
|
connect(radio_buttons, SIGNAL(buttonClicked(int)), this, SLOT(updateConfig()));
|
||||||
|
connect(text_field, SIGNAL(textChanged(const QString &)), this, SLOT(updateConfig()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Enleve les connexions signaux/slots
|
/// Enleve les connexions signaux/slots
|
||||||
void ConductorPropertiesWidget::destroyConnections() {
|
void ConductorPropertiesWidget::destroyConnections() {
|
||||||
disconnect(phase_slider, SIGNAL(valueChanged(int)), phase_spinbox, SLOT(setValue(int)));
|
disconnect(phase_slider, SIGNAL(valueChanged(int)), phase_spinbox, SLOT(setValue(int)));
|
||||||
disconnect(phase_spinbox, SIGNAL(valueChanged(int)), phase_slider, SLOT(setValue(int)));
|
disconnect(phase_spinbox, SIGNAL(valueChanged(int)), phase_slider, SLOT(setValue(int)));
|
||||||
disconnect(ground_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateSingleLineConfig()));
|
disconnect(ground_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateConfig()));
|
||||||
disconnect(neutral_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateSingleLineConfig()));
|
disconnect(neutral_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateConfig()));
|
||||||
disconnect(phase_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateSingleLineConfig()));
|
disconnect(phase_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateConfig()));
|
||||||
disconnect(phase_slider, SIGNAL(valueChanged(int)), this, SLOT(updateSingleLineConfig()));
|
disconnect(phase_slider, SIGNAL(valueChanged(int)), this, SLOT(updateConfig()));
|
||||||
disconnect(radio_buttons, SIGNAL(buttonClicked(int)), this, SLOT(setConductorType(int)));
|
disconnect(radio_buttons, SIGNAL(buttonClicked(int)), this, SLOT(updateConfig()));
|
||||||
|
disconnect(text_field, SIGNAL(textChanged(const QString &)), this, SLOT(updateConfig()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Destructeur
|
/// Destructeur
|
||||||
ConductorPropertiesWidget::~ConductorPropertiesWidget() {
|
ConductorPropertiesWidget::~ConductorPropertiesWidget() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Met a jour les proprietes unifilaires
|
/// Met a jour les proprietes
|
||||||
void ConductorPropertiesWidget::updateSingleLineConfig() {
|
void ConductorPropertiesWidget::updateConfig() {
|
||||||
slp.hasGround = ground_checkbox -> isChecked();
|
properties_.type = static_cast<ConductorProperties::ConductorType>(radio_buttons -> checkedId());
|
||||||
slp.hasNeutral = neutral_checkbox -> isChecked();
|
properties_.text = text_field -> text();
|
||||||
slp.setPhasesCount(phase_checkbox -> isChecked() ? phase_spinbox -> value() : 0);
|
properties_.singleLineProperties.hasGround = ground_checkbox -> isChecked();
|
||||||
updatePreview();
|
properties_.singleLineProperties.hasNeutral = neutral_checkbox -> isChecked();
|
||||||
|
properties_.singleLineProperties.setPhasesCount(phase_checkbox -> isChecked() ? phase_spinbox -> value() : 0);
|
||||||
|
|
||||||
|
updateDisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Met a jour l'affichage des proprietes unifilaires
|
/// Met a jour l'affichage des proprietes
|
||||||
void ConductorPropertiesWidget::updateSingleLineDisplay() {
|
void ConductorPropertiesWidget::updateDisplay() {
|
||||||
destroyConnections();
|
destroyConnections();
|
||||||
ground_checkbox -> setChecked(slp.hasGround);
|
|
||||||
neutral_checkbox -> setChecked(slp.hasNeutral);
|
setConductorType(properties_.type);
|
||||||
phase_spinbox -> setValue(slp.phasesCount());
|
text_field -> setText(properties_.text);
|
||||||
phase_slider -> setValue(slp.phasesCount());
|
ground_checkbox -> setChecked(properties_.singleLineProperties.hasGround);
|
||||||
phase_checkbox -> setChecked(slp.phasesCount());
|
neutral_checkbox -> setChecked(properties_.singleLineProperties.hasNeutral);
|
||||||
|
phase_spinbox -> setValue(properties_.singleLineProperties.phasesCount());
|
||||||
|
phase_slider -> setValue(properties_.singleLineProperties.phasesCount());
|
||||||
|
phase_checkbox -> setChecked(properties_.singleLineProperties.phasesCount());
|
||||||
|
|
||||||
buildConnections();
|
buildConnections();
|
||||||
updatePreview();
|
updatePreview();
|
||||||
}
|
}
|
||||||
@@ -132,31 +152,26 @@ void ConductorPropertiesWidget::updatePreview() {
|
|||||||
painter.eraseRect(pixmap_rect);
|
painter.eraseRect(pixmap_rect);
|
||||||
painter.drawRect(pixmap_rect.adjusted(0,0,-1,-1));
|
painter.drawRect(pixmap_rect.adjusted(0,0,-1,-1));
|
||||||
painter.drawLine(QLineF(0, pixmap_rect.height() / 2, pixmap_rect.width(), pixmap_rect.height() / 2));
|
painter.drawLine(QLineF(0, pixmap_rect.height() / 2, pixmap_rect.width(), pixmap_rect.height() / 2));
|
||||||
slp.draw(&painter, QET::Horizontal, pixmap_rect);
|
properties_.singleLineProperties.draw(&painter, QET::Horizontal, pixmap_rect);
|
||||||
painter.end();
|
painter.end();
|
||||||
preview -> setPixmap(pixmap);
|
preview -> setPixmap(pixmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @return true si le widget est en mode unifilaire, false sinon
|
|
||||||
Conductor::ConductorType ConductorPropertiesWidget::conductorType() const {
|
|
||||||
return(type_);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Passe le widget en mode simple, unifilaire ou multifilaire
|
Passe le widget en mode simple, unifilaire ou multifilaire
|
||||||
@param t le type de conducteur
|
@param t le type de conducteur
|
||||||
*/
|
*/
|
||||||
void ConductorPropertiesWidget::setConductorType(Conductor::ConductorType t) {
|
void ConductorPropertiesWidget::setConductorType(ConductorProperties::ConductorType t) {
|
||||||
type_ = t;
|
|
||||||
// widgets lies au simple
|
// widgets lies au simple
|
||||||
simple -> setChecked(t == Conductor::Simple);
|
simple -> setChecked(t == ConductorProperties::Simple);
|
||||||
|
|
||||||
// widgets lies au mode multifilaire
|
// widgets lies au mode multifilaire
|
||||||
multiline -> setChecked(t == Conductor::Multi);
|
multiline -> setChecked(t == ConductorProperties::Multi);
|
||||||
text_field -> setEnabled(t == Conductor::Multi);
|
text_field -> setEnabled(t == ConductorProperties::Multi);
|
||||||
|
|
||||||
// widgets lies au mode unifilaire
|
// widgets lies au mode unifilaire
|
||||||
bool sl = (t == Conductor::Single);
|
bool sl = (t == ConductorProperties::Single);
|
||||||
singleline -> setChecked(sl);
|
singleline -> setChecked(sl);
|
||||||
preview -> setEnabled(sl);
|
preview -> setEnabled(sl);
|
||||||
phase_checkbox -> setEnabled(sl);
|
phase_checkbox -> setEnabled(sl);
|
||||||
@@ -164,30 +179,15 @@ void ConductorPropertiesWidget::setConductorType(Conductor::ConductorType t) {
|
|||||||
phase_spinbox -> setEnabled(sl);
|
phase_spinbox -> setEnabled(sl);
|
||||||
ground_checkbox -> setEnabled(sl);
|
ground_checkbox -> setEnabled(sl);
|
||||||
neutral_checkbox -> setEnabled(sl);
|
neutral_checkbox -> setEnabled(sl);
|
||||||
updateSingleLineDisplay();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConductorPropertiesWidget::setConductorType(int t) {
|
/// @param p les nouvelles proprietes
|
||||||
setConductorType(static_cast<Conductor::ConductorType>(t));
|
void ConductorPropertiesWidget::setConductorProperties(const ConductorProperties &p) {
|
||||||
|
properties_ = p;
|
||||||
|
updateDisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @param prop Les nouvelles proprietes unifilaires de ce conducteur
|
/// @return les proprietes editees
|
||||||
void ConductorPropertiesWidget::setSingleLineProperties(const SingleLineProperties &prop) {
|
ConductorProperties ConductorPropertiesWidget::conductorProperties() const {
|
||||||
slp = prop;
|
return(properties_);
|
||||||
updateSingleLineDisplay();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @return les proprietes unifilaires de ce conducteur
|
|
||||||
SingleLineProperties ConductorPropertiesWidget::singleLineProperties() const {
|
|
||||||
return(slp);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @param text Le texte de ce conducteur
|
|
||||||
void ConductorPropertiesWidget::setConductorText(const QString &text) {
|
|
||||||
text_field -> setText(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @return Le texte de ce conducteur
|
|
||||||
QString ConductorPropertiesWidget::conductorText() const {
|
|
||||||
return(text_field -> text());
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ class ConductorPropertiesWidget : public QWidget {
|
|||||||
// constructeurs, destructeur
|
// constructeurs, destructeur
|
||||||
public:
|
public:
|
||||||
ConductorPropertiesWidget(QWidget * = 0);
|
ConductorPropertiesWidget(QWidget * = 0);
|
||||||
|
ConductorPropertiesWidget(const ConductorProperties &, QWidget * = 0);
|
||||||
virtual ~ConductorPropertiesWidget();
|
virtual ~ConductorPropertiesWidget();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -14,18 +15,16 @@ class ConductorPropertiesWidget : public QWidget {
|
|||||||
|
|
||||||
// methodes
|
// methodes
|
||||||
public:
|
public:
|
||||||
Conductor::ConductorType conductorType() const;
|
void setConductorProperties(const ConductorProperties &);
|
||||||
void setSingleLineProperties(const SingleLineProperties &);
|
ConductorProperties conductorProperties() const;
|
||||||
SingleLineProperties singleLineProperties() const;
|
|
||||||
QString conductorText() const;
|
private:
|
||||||
void setConductorText(const QString &);
|
void setConductorType(ConductorProperties::ConductorType);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updatePreview();
|
void updatePreview();
|
||||||
void updateSingleLineConfig();
|
void updateConfig();
|
||||||
void updateSingleLineDisplay();
|
void updateDisplay();
|
||||||
void setConductorType(Conductor::ConductorType);
|
|
||||||
void setConductorType(int);
|
|
||||||
|
|
||||||
// attributs prives
|
// attributs prives
|
||||||
private:
|
private:
|
||||||
@@ -41,9 +40,7 @@ class ConductorPropertiesWidget : public QWidget {
|
|||||||
QCheckBox *neutral_checkbox;
|
QCheckBox *neutral_checkbox;
|
||||||
QLabel *preview;
|
QLabel *preview;
|
||||||
|
|
||||||
Conductor::ConductorType type_;
|
ConductorProperties properties_;
|
||||||
SingleLineProperties slp;
|
|
||||||
QString conductor_text;
|
|
||||||
|
|
||||||
// methodes privees
|
// methodes privees
|
||||||
void buildInterface();
|
void buildInterface();
|
||||||
|
|||||||
@@ -526,18 +526,14 @@ ChangeConductorPropertiesCommand::~ChangeConductorPropertiesCommand() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// definit l'ancienne configuration
|
/// definit l'ancienne configuration
|
||||||
void ChangeConductorPropertiesCommand::setOldSettings(Conductor::ConductorType single, const QString &text, const SingleLineProperties &slp) {
|
void ChangeConductorPropertiesCommand::setOldSettings(const ConductorProperties &properties) {
|
||||||
old_type = single;
|
old_properties = properties;
|
||||||
old_conductor_text = text;
|
|
||||||
old_slp = slp;
|
|
||||||
old_settings_set = true;
|
old_settings_set = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// definit la nouvelle configuration
|
/// definit la nouvelle configuration
|
||||||
void ChangeConductorPropertiesCommand::setNewSettings(Conductor::ConductorType single, const QString &text, const SingleLineProperties &slp) {
|
void ChangeConductorPropertiesCommand::setNewSettings(const ConductorProperties &properties) {
|
||||||
new_type = single;
|
new_properties = properties;
|
||||||
new_conductor_text = text;
|
|
||||||
new_slp = slp;
|
|
||||||
new_settings_set = true;
|
new_settings_set = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -547,9 +543,7 @@ void ChangeConductorPropertiesCommand::setNewSettings(Conductor::ConductorType s
|
|||||||
*/
|
*/
|
||||||
void ChangeConductorPropertiesCommand::undo() {
|
void ChangeConductorPropertiesCommand::undo() {
|
||||||
if (old_settings_set && new_settings_set) {
|
if (old_settings_set && new_settings_set) {
|
||||||
conductor -> setConductorType(old_type);
|
conductor -> setProperties(old_properties);
|
||||||
conductor -> setText(old_conductor_text);
|
|
||||||
conductor -> singleLineProperties = old_slp;
|
|
||||||
conductor -> update();
|
conductor -> update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -560,9 +554,7 @@ void ChangeConductorPropertiesCommand::undo() {
|
|||||||
*/
|
*/
|
||||||
void ChangeConductorPropertiesCommand::redo() {
|
void ChangeConductorPropertiesCommand::redo() {
|
||||||
if (old_settings_set && new_settings_set) {
|
if (old_settings_set && new_settings_set) {
|
||||||
conductor -> setConductorType(new_type);
|
conductor -> setProperties(new_properties);
|
||||||
conductor -> setText(new_conductor_text);
|
|
||||||
conductor -> singleLineProperties = new_slp;
|
|
||||||
conductor -> update();
|
conductor -> update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "diagram.h"
|
#include "diagram.h"
|
||||||
#include "diagramtextitem.h"
|
#include "diagramtextitem.h"
|
||||||
#include "conductor.h"
|
#include "conductor.h"
|
||||||
|
#include "conductorproperties.h"
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
/**
|
/**
|
||||||
Cette classe represente l'action d'ajouter un element au schema
|
Cette classe represente l'action d'ajouter un element au schema
|
||||||
@@ -335,21 +336,17 @@ class ChangeConductorPropertiesCommand : public QUndoCommand {
|
|||||||
public:
|
public:
|
||||||
virtual void undo();
|
virtual void undo();
|
||||||
virtual void redo();
|
virtual void redo();
|
||||||
virtual void setOldSettings(Conductor::ConductorType, const QString &, const SingleLineProperties &);
|
virtual void setOldSettings(const ConductorProperties &);
|
||||||
virtual void setNewSettings(Conductor::ConductorType, const QString &, const SingleLineProperties &);
|
virtual void setNewSettings(const ConductorProperties &);
|
||||||
|
|
||||||
// attributs
|
// attributs
|
||||||
private:
|
private:
|
||||||
/// conducteur modifie
|
/// conducteur modifie
|
||||||
Conductor *conductor;
|
Conductor *conductor;
|
||||||
/// anciennes proprietes
|
/// anciennes proprietes
|
||||||
Conductor::ConductorType old_type;
|
ConductorProperties old_properties;
|
||||||
QString old_conductor_text;
|
|
||||||
SingleLineProperties old_slp;
|
|
||||||
/// nouvelles proprietes
|
/// nouvelles proprietes
|
||||||
Conductor::ConductorType new_type;
|
ConductorProperties new_properties;
|
||||||
QString new_conductor_text;
|
|
||||||
SingleLineProperties new_slp;
|
|
||||||
/// booleens indiquant si les proprietes ont ete definies ou non
|
/// booleens indiquant si les proprietes ont ete definies ou non
|
||||||
bool old_settings_set;
|
bool old_settings_set;
|
||||||
bool new_settings_set;
|
bool new_settings_set;
|
||||||
|
|||||||
@@ -44,6 +44,19 @@ void DiagramTextItem::focusOutEvent(QFocusEvent *e) {
|
|||||||
if (Diagram *dia = diagram()) {
|
if (Diagram *dia = diagram()) {
|
||||||
dia -> undoStack().push(new ChangeDiagramTextCommand(this, previous_text, toPlainText()));
|
dia -> undoStack().push(new ChangeDiagramTextCommand(this, previous_text, toPlainText()));
|
||||||
previous_text = toPlainText();
|
previous_text = toPlainText();
|
||||||
|
|
||||||
|
// si l'object parent est un conducteur, previent celui-ci du changement de texte
|
||||||
|
Conductor *c;
|
||||||
|
if (parentItem() && (c = qgraphicsitem_cast<Conductor *>(parentItem()))) {
|
||||||
|
ConductorProperties cp = c -> properties();
|
||||||
|
cp.text = toPlainText();
|
||||||
|
c -> setProperties(cp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// deselectionne le texte
|
||||||
|
QTextCursor cursor = textCursor();
|
||||||
|
cursor.clearSelection();
|
||||||
|
setTextCursor(cursor);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -707,14 +707,8 @@ void DiagramView::editConductor() {
|
|||||||
Conductor *edited_conductor = selected_conductors.first();
|
Conductor *edited_conductor = selected_conductors.first();
|
||||||
|
|
||||||
// initialise l'editeur de proprietes pour le conducteur
|
// initialise l'editeur de proprietes pour le conducteur
|
||||||
ConductorPropertiesWidget *cpw = new ConductorPropertiesWidget();
|
ConductorProperties old_properties = edited_conductor -> properties();
|
||||||
cpw -> setConductorType(edited_conductor -> conductorType());
|
ConductorPropertiesWidget *cpw = new ConductorPropertiesWidget(old_properties);
|
||||||
cpw -> setConductorText(edited_conductor -> text());
|
|
||||||
cpw -> setSingleLineProperties(edited_conductor -> singleLineProperties);
|
|
||||||
|
|
||||||
// initialise egalement l'objet UndoCommand correspondant
|
|
||||||
ChangeConductorPropertiesCommand *ccpc = new ChangeConductorPropertiesCommand(edited_conductor);
|
|
||||||
ccpc -> setOldSettings(edited_conductor -> conductorType(), edited_conductor -> text(), edited_conductor -> singleLineProperties);
|
|
||||||
|
|
||||||
// l'insere dans un dialogue
|
// l'insere dans un dialogue
|
||||||
QDialog conductor_dialog;
|
QDialog conductor_dialog;
|
||||||
@@ -728,10 +722,16 @@ void DiagramView::editConductor() {
|
|||||||
|
|
||||||
// execute le dialogue et met a jour le conducteur
|
// execute le dialogue et met a jour le conducteur
|
||||||
if (conductor_dialog.exec() == QDialog::Accepted) {
|
if (conductor_dialog.exec() == QDialog::Accepted) {
|
||||||
ccpc -> setNewSettings(cpw -> conductorType(), cpw -> conductorText(), cpw -> singleLineProperties());
|
// recupere les nouvelles propietes
|
||||||
diagram() -> undoStack().push(ccpc);
|
ConductorProperties new_properties = cpw -> conductorProperties();
|
||||||
} else {
|
|
||||||
delete ccpc;
|
if (new_properties != old_properties) {
|
||||||
|
// initialise l'objet UndoCommand correspondant
|
||||||
|
ChangeConductorPropertiesCommand *ccpc = new ChangeConductorPropertiesCommand(edited_conductor);
|
||||||
|
ccpc -> setOldSettings(old_properties);
|
||||||
|
ccpc -> setNewSettings(new_properties);
|
||||||
|
diagram() -> undoStack().push(ccpc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -66,7 +66,8 @@ HEADERS += aboutqet.h \
|
|||||||
diagramcommands.h \
|
diagramcommands.h \
|
||||||
diagramtextitem.h \
|
diagramtextitem.h \
|
||||||
insetproperties.h \
|
insetproperties.h \
|
||||||
conductorpropertieswidget.h
|
conductorpropertieswidget.h \
|
||||||
|
conductorproperties.h
|
||||||
SOURCES += aboutqet.cpp \
|
SOURCES += aboutqet.cpp \
|
||||||
borderinset.cpp \
|
borderinset.cpp \
|
||||||
conductor.cpp \
|
conductor.cpp \
|
||||||
@@ -125,7 +126,8 @@ SOURCES += aboutqet.cpp \
|
|||||||
editor/textfieldeditor.cpp \
|
editor/textfieldeditor.cpp \
|
||||||
diagramcommands.cpp \
|
diagramcommands.cpp \
|
||||||
diagramtextitem.cpp \
|
diagramtextitem.cpp \
|
||||||
conductorpropertieswidget.cpp
|
conductorpropertieswidget.cpp \
|
||||||
|
conductorproperties.cpp
|
||||||
RESOURCES += qelectrotech.qrc
|
RESOURCES += qelectrotech.qrc
|
||||||
TRANSLATIONS += lang/qet_en.ts lang/qt_fr.ts
|
TRANSLATIONS += lang/qet_en.ts lang/qt_fr.ts
|
||||||
RC_FILE = ico/windows_icon/application_icon/qelectrotech.rc
|
RC_FILE = ico/windows_icon/application_icon/qelectrotech.rc
|
||||||
|
|||||||
Reference in New Issue
Block a user