[qet] [773] Il est desormais possible de poser des conducteurs en pointilles.

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 773
Author:   xavier
Date:     2009-10-11 01:10:38 +0200 (Sun, 11 Oct 2009)
Log Message:
-----------
Il est desormais possible de poser des conducteurs en pointilles.

Modified Paths:
--------------
    trunk/sources/conductor.cpp
    trunk/sources/conductorproperties.cpp
    trunk/sources/conductorproperties.h
    trunk/sources/conductorpropertieswidget.cpp
    trunk/sources/conductorpropertieswidget.h

Modified: trunk/sources/conductor.cpp
===================================================================
--- trunk/sources/conductor.cpp	2009-10-10 04:06:01 UTC (rev 772)
+++ trunk/sources/conductor.cpp	2009-10-10 23:10:38 UTC (rev 773)
@@ -467,8 +467,10 @@
 	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 @@
 	// dessine les eventuelles jonctions
 	QList<QPointF> 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) {

Modified: trunk/sources/conductorproperties.cpp
===================================================================
--- trunk/sources/conductorproperties.cpp	2009-10-10 04:06:01 UTC (rev 772)
+++ trunk/sources/conductorproperties.cpp	2009-10-10 23:10:38 UTC (rev 773)
@@ -187,7 +187,8 @@
 ConductorProperties::ConductorProperties() :
 	type(Multi),
 	color(Qt::black),
-	text("_")
+	text("_"),
+	style(Qt::SolidLine)
 {
 }
 
@@ -214,6 +215,11 @@
 	} 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 @@
 		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::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 @@
 	}
 	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 @@
 	return(
 		other.type == type &&\
 		other.color == color &&\
+		other.color == style &&\
 		other.text == text &&\
 		other.singleLineProperties == singleLineProperties
 	);
@@ -312,12 +326,50 @@
 	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
 */

Modified: trunk/sources/conductorproperties.h
===================================================================
--- trunk/sources/conductorproperties.h	2009-10-10 04:06:01 UTC (rev 772)
+++ trunk/sources/conductorproperties.h	2009-10-10 23:10:38 UTC (rev 773)
@@ -75,6 +75,8 @@
 	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 @@
 	// operateurs
 	int operator==(const ConductorProperties &);
 	int operator!=(const ConductorProperties &);
+	
+	private:
+	void readStyle(const QString &);
+	QString writeStyle() const;
 };
 #endif

Modified: trunk/sources/conductorpropertieswidget.cpp
===================================================================
--- trunk/sources/conductorpropertieswidget.cpp	2009-10-10 04:06:01 UTC (rev 772)
+++ trunk/sources/conductorpropertieswidget.cpp	2009-10-10 23:10:38 UTC (rev 773)
@@ -102,10 +102,13 @@
 	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 @@
 	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 @@
 	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 @@
 	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 @@
 void ConductorPropertiesWidget::updateConfig() {
 	properties_.type = static_cast<ConductorProperties::ConductorType>(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 @@
 	
 	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);

Modified: trunk/sources/conductorpropertieswidget.h
===================================================================
--- trunk/sources/conductorpropertieswidget.h	2009-10-10 04:06:01 UTC (rev 772)
+++ trunk/sources/conductorpropertieswidget.h	2009-10-10 23:10:38 UTC (rev 773)
@@ -66,6 +66,7 @@
 	QCheckBox *neutral_checkbox;
 	QLabel *preview;
 	QPushButton *color_button;
+	QCheckBox *dashed_checkbox;
 	
 	ConductorProperties properties_;
 	


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/