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),
|
||||
terminal2(p2),
|
||||
destroyed(false),
|
||||
type_(Multi),
|
||||
segments(NULL),
|
||||
previous_z_value(zValue()),
|
||||
modified_path(false),
|
||||
@@ -55,8 +54,8 @@ Conductor::Conductor(Terminal *p1, Terminal* p2, Element *parent, QGraphicsScene
|
||||
|
||||
// ajout du champ de texte editable
|
||||
text_item = new DiagramTextItem();
|
||||
text_item -> setPlainText("_");
|
||||
text_item -> previous_text = "_";
|
||||
text_item -> setPlainText(properties_.text);
|
||||
text_item -> previous_text = properties_.text;
|
||||
calculateTextItemPosition();
|
||||
text_item -> setParentItem(this);
|
||||
}
|
||||
@@ -417,9 +416,9 @@ void Conductor::paint(QPainter *qp, const QStyleOptionGraphicsItem *options, QWi
|
||||
|
||||
// dessin du conducteur
|
||||
qp -> drawPath(path());
|
||||
if (type_ == Single) {
|
||||
if (properties_.type == ConductorProperties::Single) {
|
||||
if (isSelected()) qp -> setBrush(Qt::red);
|
||||
singleLineProperties.draw(
|
||||
properties_.singleLineProperties.draw(
|
||||
qp,
|
||||
middleSegment() -> isHorizontal() ? QET::Horizontal : QET::Vertical,
|
||||
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) {
|
||||
// recupere la "configuration" du conducteur
|
||||
if (e.attribute("type") == typeToString(Single)) {
|
||||
// recupere les parametres specifiques a un conducteur unifilaire
|
||||
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);
|
||||
}
|
||||
properties_.fromXml(e);
|
||||
readProperties();
|
||||
|
||||
// parcourt les elements XML "segment" et en extrait deux listes de longueurs
|
||||
// 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
|
||||
e.setAttribute("type", typeToString(type_));
|
||||
if (type_ == Single) {
|
||||
singleLineProperties.toXml(d, e);
|
||||
} else if (type_ == Multi) {
|
||||
e.setAttribute("num", text_item -> toPlainText());
|
||||
}
|
||||
properties_.toXml(d, e);
|
||||
return(e);
|
||||
}
|
||||
|
||||
@@ -1014,23 +998,6 @@ ConductorProfile Conductor::profile() const {
|
||||
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
|
||||
QString Conductor::text() const {
|
||||
return(text_item -> toPlainText());
|
||||
@@ -1044,178 +1011,21 @@ void Conductor::setText(const QString &t) {
|
||||
text_item -> previous_text = t;
|
||||
}
|
||||
|
||||
/**
|
||||
Constructeur par defaut
|
||||
*/
|
||||
SingleLineProperties::SingleLineProperties() :
|
||||
hasGround(true),
|
||||
hasNeutral(true),
|
||||
phases(1)
|
||||
{
|
||||
/// @param p les proprietes de ce conducteur
|
||||
void Conductor::setProperties(const ConductorProperties &p) {
|
||||
properties_ = p;
|
||||
readProperties();
|
||||
}
|
||||
|
||||
/// Destructeur
|
||||
SingleLineProperties::~SingleLineProperties() {
|
||||
/// @return les proprietes de ce conducteur
|
||||
ConductorProperties Conductor::properties() const {
|
||||
return(properties_);
|
||||
}
|
||||
|
||||
/**
|
||||
Definit le nombre de phases (0, 1, 2, ou 3)
|
||||
@param n Nombre de phases
|
||||
Relit les proprietes et les applique
|
||||
*/
|
||||
void SingleLineProperties::setPhasesCount(int n) {
|
||||
phases = qBound(0, n, 3);
|
||||
}
|
||||
|
||||
/// @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());
|
||||
}
|
||||
void Conductor::readProperties() {
|
||||
setText(properties_.text);
|
||||
text_item -> setVisible(properties_.type == ConductorProperties::Multi);
|
||||
}
|
||||
|
||||
33
conductor.h
33
conductor.h
@@ -3,28 +3,10 @@
|
||||
#include <QtGui>
|
||||
#include "terminal.h"
|
||||
#include "conductorprofile.h"
|
||||
#include "conductorproperties.h"
|
||||
#include "diagramtextitem.h"
|
||||
class ConductorSegment;
|
||||
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.
|
||||
@@ -42,14 +24,11 @@ class Conductor : public QGraphicsPathItem {
|
||||
// attributs
|
||||
public:
|
||||
enum { Type = UserType + 1001 };
|
||||
enum ConductorType { Simple, Single, Multi };
|
||||
|
||||
/// premiere borne a laquelle le fil est rattache
|
||||
Terminal *terminal1;
|
||||
/// deuxieme borne a laquelle le fil est rattache
|
||||
Terminal *terminal2;
|
||||
/// caracteristiques des conducteurs unifilaires
|
||||
SingleLineProperties singleLineProperties;
|
||||
|
||||
// methodes
|
||||
public:
|
||||
@@ -70,10 +49,11 @@ class Conductor : public QGraphicsPathItem {
|
||||
bool fromXml(QDomElement &);
|
||||
QDomElement toXml(QDomDocument &, QHash<Terminal *, int> &) const;
|
||||
const QList<ConductorSegment *> segmentsList() const;
|
||||
void setProperties(const ConductorProperties &);
|
||||
ConductorProperties properties() const;
|
||||
void setProfile(const ConductorProfile &);
|
||||
ConductorProfile profile() const;
|
||||
ConductorType conductorType() const;
|
||||
void setConductorType(ConductorType);
|
||||
void readProperties();
|
||||
|
||||
protected:
|
||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *);
|
||||
@@ -82,10 +62,10 @@ class Conductor : public QGraphicsPathItem {
|
||||
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *);
|
||||
|
||||
private:
|
||||
/// caracteristiques du conducteur
|
||||
ConductorProperties properties_;
|
||||
/// booleen indiquant si le fil est encore valide
|
||||
bool destroyed;
|
||||
/// enum indiquant le mode du conducteur : simple, unifilaire ou non
|
||||
ConductorType type_;
|
||||
/// champ de texte editable pour les conducteurs non unifilaires
|
||||
DiagramTextItem *text_item;
|
||||
/// segments composant le conducteur
|
||||
@@ -124,6 +104,5 @@ class Conductor : public QGraphicsPathItem {
|
||||
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, bool);
|
||||
static QString typeToString(ConductorType);
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -6,12 +6,23 @@
|
||||
@param parent QWidget parent
|
||||
*/
|
||||
ConductorPropertiesWidget::ConductorPropertiesWidget(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
type_(Conductor::Multi)
|
||||
QWidget(parent)
|
||||
{
|
||||
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
|
||||
void ConductorPropertiesWidget::buildInterface() {
|
||||
|
||||
@@ -69,56 +80,65 @@ void ConductorPropertiesWidget::buildInterface() {
|
||||
groupbox_layout -> addLayout(singleline_layout1);
|
||||
|
||||
radio_buttons = new QButtonGroup(this);
|
||||
radio_buttons -> addButton(simple, Conductor::Simple);
|
||||
radio_buttons -> addButton(multiline, Conductor::Multi);
|
||||
radio_buttons -> addButton(singleline, Conductor::Single);
|
||||
radio_buttons -> addButton(simple, ConductorProperties::Simple);
|
||||
radio_buttons -> addButton(multiline, ConductorProperties::Multi);
|
||||
radio_buttons -> addButton(singleline, ConductorProperties::Single);
|
||||
|
||||
buildConnections();
|
||||
setConductorType(Conductor::Multi);
|
||||
setConductorType(ConductorProperties::Multi);
|
||||
}
|
||||
|
||||
/// Met en place les connexions signaux/slots
|
||||
void ConductorPropertiesWidget::buildConnections() {
|
||||
connect(phase_slider, SIGNAL(valueChanged(int)), phase_spinbox, SLOT(setValue(int)));
|
||||
connect(phase_spinbox, SIGNAL(valueChanged(int)), phase_slider, SLOT(setValue(int)));
|
||||
connect(ground_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateSingleLineConfig()));
|
||||
connect(neutral_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateSingleLineConfig()));
|
||||
connect(phase_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateSingleLineConfig()));
|
||||
connect(phase_slider, SIGNAL(valueChanged(int)), this, SLOT(updateSingleLineConfig()));
|
||||
connect(radio_buttons, SIGNAL(buttonClicked(int)), this, SLOT(setConductorType(int)));
|
||||
connect(phase_slider, SIGNAL(valueChanged(int)), phase_spinbox, SLOT(setValue(int)));
|
||||
connect(phase_spinbox, SIGNAL(valueChanged(int)), phase_slider, SLOT(setValue(int)));
|
||||
connect(ground_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateConfig()));
|
||||
connect(neutral_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateConfig()));
|
||||
connect(phase_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateConfig()));
|
||||
connect(phase_slider, SIGNAL(valueChanged(int)), this, SLOT(updateConfig()));
|
||||
connect(radio_buttons, SIGNAL(buttonClicked(int)), this, SLOT(updateConfig()));
|
||||
connect(text_field, SIGNAL(textChanged(const QString &)), this, SLOT(updateConfig()));
|
||||
}
|
||||
|
||||
/// Enleve les connexions signaux/slots
|
||||
void ConductorPropertiesWidget::destroyConnections() {
|
||||
disconnect(phase_slider, SIGNAL(valueChanged(int)), phase_spinbox, SLOT(setValue(int)));
|
||||
disconnect(phase_spinbox, SIGNAL(valueChanged(int)), phase_slider, SLOT(setValue(int)));
|
||||
disconnect(ground_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateSingleLineConfig()));
|
||||
disconnect(neutral_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateSingleLineConfig()));
|
||||
disconnect(phase_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateSingleLineConfig()));
|
||||
disconnect(phase_slider, SIGNAL(valueChanged(int)), this, SLOT(updateSingleLineConfig()));
|
||||
disconnect(radio_buttons, SIGNAL(buttonClicked(int)), this, SLOT(setConductorType(int)));
|
||||
disconnect(phase_slider, SIGNAL(valueChanged(int)), phase_spinbox, SLOT(setValue(int)));
|
||||
disconnect(phase_spinbox, SIGNAL(valueChanged(int)), phase_slider, SLOT(setValue(int)));
|
||||
disconnect(ground_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateConfig()));
|
||||
disconnect(neutral_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateConfig()));
|
||||
disconnect(phase_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateConfig()));
|
||||
disconnect(phase_slider, SIGNAL(valueChanged(int)), this, SLOT(updateConfig()));
|
||||
disconnect(radio_buttons, SIGNAL(buttonClicked(int)), this, SLOT(updateConfig()));
|
||||
disconnect(text_field, SIGNAL(textChanged(const QString &)), this, SLOT(updateConfig()));
|
||||
}
|
||||
|
||||
/// Destructeur
|
||||
ConductorPropertiesWidget::~ConductorPropertiesWidget() {
|
||||
}
|
||||
|
||||
/// Met a jour les proprietes unifilaires
|
||||
void ConductorPropertiesWidget::updateSingleLineConfig() {
|
||||
slp.hasGround = ground_checkbox -> isChecked();
|
||||
slp.hasNeutral = neutral_checkbox -> isChecked();
|
||||
slp.setPhasesCount(phase_checkbox -> isChecked() ? phase_spinbox -> value() : 0);
|
||||
updatePreview();
|
||||
/// Met a jour les proprietes
|
||||
void ConductorPropertiesWidget::updateConfig() {
|
||||
properties_.type = static_cast<ConductorProperties::ConductorType>(radio_buttons -> checkedId());
|
||||
properties_.text = text_field -> text();
|
||||
properties_.singleLineProperties.hasGround = ground_checkbox -> isChecked();
|
||||
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
|
||||
void ConductorPropertiesWidget::updateSingleLineDisplay() {
|
||||
/// Met a jour l'affichage des proprietes
|
||||
void ConductorPropertiesWidget::updateDisplay() {
|
||||
destroyConnections();
|
||||
ground_checkbox -> setChecked(slp.hasGround);
|
||||
neutral_checkbox -> setChecked(slp.hasNeutral);
|
||||
phase_spinbox -> setValue(slp.phasesCount());
|
||||
phase_slider -> setValue(slp.phasesCount());
|
||||
phase_checkbox -> setChecked(slp.phasesCount());
|
||||
|
||||
setConductorType(properties_.type);
|
||||
text_field -> setText(properties_.text);
|
||||
ground_checkbox -> setChecked(properties_.singleLineProperties.hasGround);
|
||||
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();
|
||||
updatePreview();
|
||||
}
|
||||
@@ -132,31 +152,26 @@ void ConductorPropertiesWidget::updatePreview() {
|
||||
painter.eraseRect(pixmap_rect);
|
||||
painter.drawRect(pixmap_rect.adjusted(0,0,-1,-1));
|
||||
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();
|
||||
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
|
||||
@param t le type de conducteur
|
||||
*/
|
||||
void ConductorPropertiesWidget::setConductorType(Conductor::ConductorType t) {
|
||||
type_ = t;
|
||||
void ConductorPropertiesWidget::setConductorType(ConductorProperties::ConductorType t) {
|
||||
|
||||
// widgets lies au simple
|
||||
simple -> setChecked(t == Conductor::Simple);
|
||||
simple -> setChecked(t == ConductorProperties::Simple);
|
||||
|
||||
// widgets lies au mode multifilaire
|
||||
multiline -> setChecked(t == Conductor::Multi);
|
||||
text_field -> setEnabled(t == Conductor::Multi);
|
||||
multiline -> setChecked(t == ConductorProperties::Multi);
|
||||
text_field -> setEnabled(t == ConductorProperties::Multi);
|
||||
|
||||
// widgets lies au mode unifilaire
|
||||
bool sl = (t == Conductor::Single);
|
||||
bool sl = (t == ConductorProperties::Single);
|
||||
singleline -> setChecked(sl);
|
||||
preview -> setEnabled(sl);
|
||||
phase_checkbox -> setEnabled(sl);
|
||||
@@ -164,30 +179,15 @@ void ConductorPropertiesWidget::setConductorType(Conductor::ConductorType t) {
|
||||
phase_spinbox -> setEnabled(sl);
|
||||
ground_checkbox -> setEnabled(sl);
|
||||
neutral_checkbox -> setEnabled(sl);
|
||||
updateSingleLineDisplay();
|
||||
}
|
||||
|
||||
void ConductorPropertiesWidget::setConductorType(int t) {
|
||||
setConductorType(static_cast<Conductor::ConductorType>(t));
|
||||
/// @param p les nouvelles proprietes
|
||||
void ConductorPropertiesWidget::setConductorProperties(const ConductorProperties &p) {
|
||||
properties_ = p;
|
||||
updateDisplay();
|
||||
}
|
||||
|
||||
/// @param prop Les nouvelles proprietes unifilaires de ce conducteur
|
||||
void ConductorPropertiesWidget::setSingleLineProperties(const SingleLineProperties &prop) {
|
||||
slp = prop;
|
||||
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());
|
||||
/// @return les proprietes editees
|
||||
ConductorProperties ConductorPropertiesWidget::conductorProperties() const {
|
||||
return(properties_);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ class ConductorPropertiesWidget : public QWidget {
|
||||
// constructeurs, destructeur
|
||||
public:
|
||||
ConductorPropertiesWidget(QWidget * = 0);
|
||||
ConductorPropertiesWidget(const ConductorProperties &, QWidget * = 0);
|
||||
virtual ~ConductorPropertiesWidget();
|
||||
|
||||
private:
|
||||
@@ -14,18 +15,16 @@ class ConductorPropertiesWidget : public QWidget {
|
||||
|
||||
// methodes
|
||||
public:
|
||||
Conductor::ConductorType conductorType() const;
|
||||
void setSingleLineProperties(const SingleLineProperties &);
|
||||
SingleLineProperties singleLineProperties() const;
|
||||
QString conductorText() const;
|
||||
void setConductorText(const QString &);
|
||||
void setConductorProperties(const ConductorProperties &);
|
||||
ConductorProperties conductorProperties() const;
|
||||
|
||||
private:
|
||||
void setConductorType(ConductorProperties::ConductorType);
|
||||
|
||||
public slots:
|
||||
void updatePreview();
|
||||
void updateSingleLineConfig();
|
||||
void updateSingleLineDisplay();
|
||||
void setConductorType(Conductor::ConductorType);
|
||||
void setConductorType(int);
|
||||
void updateConfig();
|
||||
void updateDisplay();
|
||||
|
||||
// attributs prives
|
||||
private:
|
||||
@@ -41,9 +40,7 @@ class ConductorPropertiesWidget : public QWidget {
|
||||
QCheckBox *neutral_checkbox;
|
||||
QLabel *preview;
|
||||
|
||||
Conductor::ConductorType type_;
|
||||
SingleLineProperties slp;
|
||||
QString conductor_text;
|
||||
ConductorProperties properties_;
|
||||
|
||||
// methodes privees
|
||||
void buildInterface();
|
||||
|
||||
@@ -526,18 +526,14 @@ ChangeConductorPropertiesCommand::~ChangeConductorPropertiesCommand() {
|
||||
}
|
||||
|
||||
/// definit l'ancienne configuration
|
||||
void ChangeConductorPropertiesCommand::setOldSettings(Conductor::ConductorType single, const QString &text, const SingleLineProperties &slp) {
|
||||
old_type = single;
|
||||
old_conductor_text = text;
|
||||
old_slp = slp;
|
||||
void ChangeConductorPropertiesCommand::setOldSettings(const ConductorProperties &properties) {
|
||||
old_properties = properties;
|
||||
old_settings_set = true;
|
||||
}
|
||||
|
||||
/// definit la nouvelle configuration
|
||||
void ChangeConductorPropertiesCommand::setNewSettings(Conductor::ConductorType single, const QString &text, const SingleLineProperties &slp) {
|
||||
new_type = single;
|
||||
new_conductor_text = text;
|
||||
new_slp = slp;
|
||||
void ChangeConductorPropertiesCommand::setNewSettings(const ConductorProperties &properties) {
|
||||
new_properties = properties;
|
||||
new_settings_set = true;
|
||||
}
|
||||
|
||||
@@ -547,9 +543,7 @@ void ChangeConductorPropertiesCommand::setNewSettings(Conductor::ConductorType s
|
||||
*/
|
||||
void ChangeConductorPropertiesCommand::undo() {
|
||||
if (old_settings_set && new_settings_set) {
|
||||
conductor -> setConductorType(old_type);
|
||||
conductor -> setText(old_conductor_text);
|
||||
conductor -> singleLineProperties = old_slp;
|
||||
conductor -> setProperties(old_properties);
|
||||
conductor -> update();
|
||||
}
|
||||
}
|
||||
@@ -560,9 +554,7 @@ void ChangeConductorPropertiesCommand::undo() {
|
||||
*/
|
||||
void ChangeConductorPropertiesCommand::redo() {
|
||||
if (old_settings_set && new_settings_set) {
|
||||
conductor -> setConductorType(new_type);
|
||||
conductor -> setText(new_conductor_text);
|
||||
conductor -> singleLineProperties = new_slp;
|
||||
conductor -> setProperties(new_properties);
|
||||
conductor -> update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "diagram.h"
|
||||
#include "diagramtextitem.h"
|
||||
#include "conductor.h"
|
||||
#include "conductorproperties.h"
|
||||
#include <QtGui>
|
||||
/**
|
||||
Cette classe represente l'action d'ajouter un element au schema
|
||||
@@ -335,21 +336,17 @@ class ChangeConductorPropertiesCommand : public QUndoCommand {
|
||||
public:
|
||||
virtual void undo();
|
||||
virtual void redo();
|
||||
virtual void setOldSettings(Conductor::ConductorType, const QString &, const SingleLineProperties &);
|
||||
virtual void setNewSettings(Conductor::ConductorType, const QString &, const SingleLineProperties &);
|
||||
virtual void setOldSettings(const ConductorProperties &);
|
||||
virtual void setNewSettings(const ConductorProperties &);
|
||||
|
||||
// attributs
|
||||
private:
|
||||
/// conducteur modifie
|
||||
Conductor *conductor;
|
||||
/// anciennes proprietes
|
||||
Conductor::ConductorType old_type;
|
||||
QString old_conductor_text;
|
||||
SingleLineProperties old_slp;
|
||||
ConductorProperties old_properties;
|
||||
/// nouvelles proprietes
|
||||
Conductor::ConductorType new_type;
|
||||
QString new_conductor_text;
|
||||
SingleLineProperties new_slp;
|
||||
ConductorProperties new_properties;
|
||||
/// booleens indiquant si les proprietes ont ete definies ou non
|
||||
bool old_settings_set;
|
||||
bool new_settings_set;
|
||||
|
||||
@@ -44,6 +44,19 @@ void DiagramTextItem::focusOutEvent(QFocusEvent *e) {
|
||||
if (Diagram *dia = diagram()) {
|
||||
dia -> undoStack().push(new ChangeDiagramTextCommand(this, 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();
|
||||
|
||||
// initialise l'editeur de proprietes pour le conducteur
|
||||
ConductorPropertiesWidget *cpw = new ConductorPropertiesWidget();
|
||||
cpw -> setConductorType(edited_conductor -> conductorType());
|
||||
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);
|
||||
ConductorProperties old_properties = edited_conductor -> properties();
|
||||
ConductorPropertiesWidget *cpw = new ConductorPropertiesWidget(old_properties);
|
||||
|
||||
// l'insere dans un dialogue
|
||||
QDialog conductor_dialog;
|
||||
@@ -728,10 +722,16 @@ void DiagramView::editConductor() {
|
||||
|
||||
// execute le dialogue et met a jour le conducteur
|
||||
if (conductor_dialog.exec() == QDialog::Accepted) {
|
||||
ccpc -> setNewSettings(cpw -> conductorType(), cpw -> conductorText(), cpw -> singleLineProperties());
|
||||
diagram() -> undoStack().push(ccpc);
|
||||
} else {
|
||||
delete ccpc;
|
||||
// recupere les nouvelles propietes
|
||||
ConductorProperties new_properties = cpw -> conductorProperties();
|
||||
|
||||
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 \
|
||||
diagramtextitem.h \
|
||||
insetproperties.h \
|
||||
conductorpropertieswidget.h
|
||||
conductorpropertieswidget.h \
|
||||
conductorproperties.h
|
||||
SOURCES += aboutqet.cpp \
|
||||
borderinset.cpp \
|
||||
conductor.cpp \
|
||||
@@ -125,7 +126,8 @@ SOURCES += aboutqet.cpp \
|
||||
editor/textfieldeditor.cpp \
|
||||
diagramcommands.cpp \
|
||||
diagramtextitem.cpp \
|
||||
conductorpropertieswidget.cpp
|
||||
conductorpropertieswidget.cpp \
|
||||
conductorproperties.cpp
|
||||
RESOURCES += qelectrotech.qrc
|
||||
TRANSLATIONS += lang/qet_en.ts lang/qt_fr.ts
|
||||
RC_FILE = ico/windows_icon/application_icon/qelectrotech.rc
|
||||
|
||||
Reference in New Issue
Block a user