From 285f56ea468a662ac8ee97594c638b82aacd88de Mon Sep 17 00:00:00 2001 From: xavier Date: Sat, 10 Oct 2009 23:10:38 +0000 Subject: [PATCH] Il est desormais possible de poser des conducteurs en pointilles. git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@773 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/conductor.cpp | 9 +++-- sources/conductorproperties.cpp | 54 ++++++++++++++++++++++++++- sources/conductorproperties.h | 6 +++ sources/conductorpropertieswidget.cpp | 10 ++++- sources/conductorpropertieswidget.h | 1 + 5 files changed, 75 insertions(+), 5 deletions(-) diff --git a/sources/conductor.cpp b/sources/conductor.cpp index 0388b1a80..1171918ef 100644 --- a/sources/conductor.cpp +++ b/sources/conductor.cpp @@ -467,8 +467,10 @@ void Conductor::paint(QPainter *qp, const QStyleOptionGraphicsItem *options, QWi qp -> setBrush(conductor_brush); QPen final_conductor_pen = conductor_pen; - // modification du QPen generique pour lui affecter la couleur adequate + // modification du QPen generique pour lui affecter la couleur et le style adequats final_conductor_pen.setColor(final_conductor_color); + final_conductor_pen.setStyle(properties_.style); + final_conductor_pen.setJoinStyle(Qt::SvgMiterJoin); // meilleur rendu des pointilles // utilisation d'un trait "cosmetique" en-dessous d'un certain zoom if (options && options -> levelOfDetail < 1.0) { @@ -518,8 +520,9 @@ void Conductor::paint(QPainter *qp, const QStyleOptionGraphicsItem *options, QWi // dessine les eventuelles jonctions QList junctions_list = junctions(); if (!junctions_list.isEmpty()) { - QBrush junction_brush(Qt::SolidPattern); - junction_brush.setColor(final_conductor_color); + final_conductor_pen.setStyle(Qt::SolidLine); + QBrush junction_brush(final_conductor_color, Qt::SolidPattern); + qp -> setPen(final_conductor_pen); qp -> setBrush(junction_brush); qp -> setRenderHint(QPainter::Antialiasing, true); foreach(QPointF point, junctions_list) { diff --git a/sources/conductorproperties.cpp b/sources/conductorproperties.cpp index 114758dd5..fc5aa2f8c 100644 --- a/sources/conductorproperties.cpp +++ b/sources/conductorproperties.cpp @@ -187,7 +187,8 @@ void SingleLineProperties::fromXml(QDomElement &e) { ConductorProperties::ConductorProperties() : type(Multi), color(Qt::black), - text("_") + text("_"), + style(Qt::SolidLine) { } @@ -214,6 +215,11 @@ void ConductorProperties::toXml(QDomElement &e) const { } else if (type == Multi) { e.setAttribute("num", text); } + + QString conductor_style = writeStyle(); + if (!conductor_style.isEmpty()) { + e.setAttribute("style", conductor_style); + } } /** @@ -230,6 +236,9 @@ void ConductorProperties::fromXml(QDomElement &e) { color = QColor(Qt::black); } + // lit le style du conducteur + readStyle(e.attribute("style")); + if (e.attribute("type") == typeToString(Single)) { // recupere les parametres specifiques a un conducteur unifilaire singleLineProperties.fromXml(e); @@ -249,6 +258,7 @@ void ConductorProperties::fromXml(QDomElement &e) { */ void ConductorProperties::toSettings(QSettings &settings, const QString &prefix) const { settings.setValue(prefix + "color", color.name()); + settings.setValue(prefix + "style", writeStyle()); settings.setValue(prefix + "type", typeToString(type)); settings.setValue(prefix + "text", text); singleLineProperties.toSettings(settings, prefix); @@ -277,6 +287,9 @@ void ConductorProperties::fromSettings(QSettings &settings, const QString &prefi } singleLineProperties.fromSettings(settings, prefix); text = settings.value(prefix + "text", "_").toString(); + + // lit le style du conducteur + readStyle(settings.value(prefix + "style").toString()); } /** @@ -299,6 +312,7 @@ int ConductorProperties::operator==(const ConductorProperties &other) { return( other.type == type &&\ other.color == color &&\ + other.color == style &&\ other.text == text &&\ other.singleLineProperties == singleLineProperties ); @@ -312,11 +326,49 @@ int ConductorProperties::operator!=(const ConductorProperties &other) { return( other.type != type ||\ other.color != color ||\ + other.color != style ||\ other.text != text ||\ other.singleLineProperties != singleLineProperties ); } +/** + Applique les styles passes en parametre dans cet objet + @param style_string Chaine decrivant le style du conducteur +*/ +void ConductorProperties::readStyle(const QString &style_string) { + style = Qt::SolidLine; // style par defaut + + if (style_string.isEmpty()) return; + + // recupere la liste des couples style / valeur + QStringList styles = style_string.split(";", QString::SkipEmptyParts); + + QRegExp rx("^\\s*([a-z-]+)\\s*:\\s*([a-z-]+)\\s*$"); + foreach (QString style_str, styles) { + if (rx.exactMatch(style_str)) { + QString style_name = rx.cap(1); + QString style_value = rx.cap(2); + if (style_name == "line-style") { + if (style_value == "dashed") style = Qt::DashLine; + else if (style_value == "normal") style = Qt::SolidLine; + } + } + } +} + +/** + Exporte le style du conducteur sous forme d'une chaine de caracteres + @return une chaine de caracteres decrivant le style du conducteur +*/ +QString ConductorProperties::writeStyle() const { + if (style == Qt::DashLine) { + return("line-style: dashed;"); + } else { + return(QString()); + } +} + /** @param other l'autre ensemble de proprietes avec lequel il faut effectuer la comparaison @return true si les deux ensembles de proprietes sont identiques, false sinon diff --git a/sources/conductorproperties.h b/sources/conductorproperties.h index 23ea3742e..c02996cc2 100644 --- a/sources/conductorproperties.h +++ b/sources/conductorproperties.h @@ -75,6 +75,8 @@ class ConductorProperties { QColor color; /// texte affiche si le conducteur est multifilaire QString text; + /// style du conducteur (Qt::SolidLine ou Qt::DashLine) + Qt::PenStyle style; /// proprietes si le conducteur est unifilaire SingleLineProperties singleLineProperties; @@ -89,5 +91,9 @@ class ConductorProperties { // operateurs int operator==(const ConductorProperties &); int operator!=(const ConductorProperties &); + + private: + void readStyle(const QString &); + QString writeStyle() const; }; #endif diff --git a/sources/conductorpropertieswidget.cpp b/sources/conductorpropertieswidget.cpp index 9722c89a9..4e683f896 100644 --- a/sources/conductorpropertieswidget.cpp +++ b/sources/conductorpropertieswidget.cpp @@ -102,10 +102,13 @@ void ConductorPropertiesWidget::buildInterface() { QHBoxLayout *color_layout = new QHBoxLayout(); QLabel *text1 = new QLabel(tr("Couleur :")); color_button = new QPushButton(""); + dashed_checkbox = new QCheckBox(tr("Trait en pointill\351s")); color_layout -> addWidget(text1); color_layout -> addWidget(color_button); + setColorButton(properties_.color); + dashed_checkbox -> setChecked(properties_.style == Qt::DashLine); groupbox_layout -> addWidget(simple); groupbox_layout -> addWidget(multiline); @@ -114,6 +117,7 @@ void ConductorPropertiesWidget::buildInterface() { groupbox_layout -> addLayout(singleline_layout1); groupbox2_layout -> addLayout(color_layout); + groupbox2_layout -> addWidget(dashed_checkbox); radio_buttons = new QButtonGroup(this); radio_buttons -> addButton(simple, ConductorProperties::Simple); @@ -134,6 +138,7 @@ void ConductorPropertiesWidget::buildConnections() { 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())); + connect(dashed_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateConfig())); connect(color_button, SIGNAL(clicked()), this, SLOT(chooseColor())); } @@ -176,7 +181,8 @@ void ConductorPropertiesWidget::destroyConnections() { 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())); - disconnect(color_button, SIGNAL(clicked()), this, SLOT(chooseColor())); + disconnect(color_button, SIGNAL(clicked()), this, SLOT(chooseColor())); + disconnect(dashed_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateConfig())); } /// Destructeur @@ -187,6 +193,7 @@ ConductorPropertiesWidget::~ConductorPropertiesWidget() { void ConductorPropertiesWidget::updateConfig() { properties_.type = static_cast(radio_buttons -> checkedId()); properties_.color = colorButton(); + properties_.style = dashed_checkbox -> isChecked() ? Qt::DashLine : Qt::SolidLine; properties_.text = text_field -> text(); properties_.singleLineProperties.hasGround = ground_checkbox -> isChecked(); properties_.singleLineProperties.hasNeutral = neutral_checkbox -> isChecked(); @@ -201,6 +208,7 @@ void ConductorPropertiesWidget::updateDisplay() { setConductorType(properties_.type); setColorButton(properties_.color); + dashed_checkbox -> setChecked(properties_.style == Qt::DashLine); text_field -> setText(properties_.text); ground_checkbox -> setChecked(properties_.singleLineProperties.hasGround); neutral_checkbox -> setChecked(properties_.singleLineProperties.hasNeutral); diff --git a/sources/conductorpropertieswidget.h b/sources/conductorpropertieswidget.h index fa44bc958..f98a92f70 100644 --- a/sources/conductorpropertieswidget.h +++ b/sources/conductorpropertieswidget.h @@ -66,6 +66,7 @@ class ConductorPropertiesWidget : public QWidget { QCheckBox *neutral_checkbox; QLabel *preview; QPushButton *color_button; + QCheckBox *dashed_checkbox; ConductorProperties properties_;