[qet] [1141] Refactoring: move code from Diagram to BorderTitleBlock.

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


Revision: 1141
Author:   xavier
Date:     2011-01-09 01:01:38 +0100 (Sun, 09 Jan 2011)
Log Message:
-----------
Refactoring: move code from Diagram to BorderTitleBlock.

Modified Paths:
--------------
    branches/0.3/sources/bordertitleblock.cpp
    branches/0.3/sources/bordertitleblock.h
    branches/0.3/sources/diagram.cpp

Modified: branches/0.3/sources/bordertitleblock.cpp
===================================================================
--- branches/0.3/sources/bordertitleblock.cpp	2010-12-28 18:57:24 UTC (rev 1140)
+++ branches/0.3/sources/bordertitleblock.cpp	2011-01-09 00:01:38 UTC (rev 1141)
@@ -90,6 +90,89 @@
 }
 
 /**
+	Exports the title block current values to XML.
+	@param xml_elmt the XML element attributes will be added to
+*/
+void BorderTitleBlock::titleBlockToXml(QDomElement &xml_elmt) {
+	if (!author().isNull())    xml_elmt.setAttribute("author",   author());
+	if (!date().isNull())      xml_elmt.setAttribute("date",     date().toString("yyyyMMdd"));
+	if (!title().isNull())     xml_elmt.setAttribute("title",    title());
+	if (!fileName().isNull())  xml_elmt.setAttribute("filename", fileName());
+	if (!folio().isNull())     xml_elmt.setAttribute("folio",    folio());
+	
+	QString current_template_name = titleBlockTemplateName();
+	if (!current_template_name.isEmpty()) {
+		xml_elmt.setAttribute("titleblocktemplate", current_template_name);
+	}
+}
+
+/**
+	Reads the title block values from XML.
+	@param xml_elmt the XML element values will be read from
+*/
+void BorderTitleBlock::titleBlockFromXml(const QDomElement &xml_elmt) {
+	setAuthor(xml_elmt.attribute("author"));
+	setTitle(xml_elmt.attribute("title"));
+	setDate(QDate::fromString(xml_elmt.attribute("date"), "yyyyMMdd"));
+	setFileName(xml_elmt.attribute("filename"));
+	setFolio(xml_elmt.attribute("folio"));
+	needTitleBlockTemplate(xml_elmt.attribute("titleblocktemplate", ""));
+}
+
+/**
+	Exports the border current settings to XML.
+	@param xml_elmt the XML element attributes will be added to
+*/
+void BorderTitleBlock::borderToXml(QDomElement &xml_elmt) {
+	xml_elmt.setAttribute("cols",        nbColumns());
+	xml_elmt.setAttribute("colsize",     QString("%1").arg(columnsWidth()));
+	xml_elmt.setAttribute("displaycols", columnsAreDisplayed() ? "true" : "false");
+	
+	xml_elmt.setAttribute("rows",        nbRows());
+	xml_elmt.setAttribute("rowsize",     QString("%1").arg(rowsHeight()));
+	xml_elmt.setAttribute("displayrows", rowsAreDisplayed() ? "true" : "false");
+	
+	// attribut datant de la version 0.1 - laisse pour retrocompatibilite
+	xml_elmt.setAttribute("height", QString("%1").arg(diagramHeight()));
+}
+
+/**
+	Reads the border settings from XML.
+	@param xml_elmt the XML element values will be read from
+*/
+void BorderTitleBlock::borderFromXml(const QDomElement &xml_elmt) {
+	bool ok;
+	// columns count
+	int cols_count = xml_elmt.attribute("cols").toInt(&ok);
+	if (ok) setNbColumns(cols_count);
+	
+	// columns width
+	double cols_width = xml_elmt.attribute("colsize").toDouble(&ok);
+	if (ok) setColumnsWidth(cols_width);
+	
+	// backward compatibility: diagrams saved with 0.1 version have a "height" attribute
+	if (xml_elmt.hasAttribute("rows") && xml_elmt.hasAttribute("rowsize")) {
+		// rows counts
+		int rows_count = xml_elmt.attribute("rows").toInt(&ok);
+		if (ok) setNbRows(rows_count);
+		
+		// taille des lignes
+		double rows_size = xml_elmt.attribute("rowsize").toDouble(&ok);
+		if (ok) setRowsHeight(rows_size);
+	} else {
+		// hauteur du schema
+		double height = xml_elmt.attribute("height").toDouble(&ok);
+		if (ok) setDiagramHeight(height);
+	}
+	
+	// rows and columns display
+	displayColumns(xml_elmt.attribute("displaycols") != "false");
+	displayRows(xml_elmt.attribute("displayrows") != "false");
+	
+	adjustTitleBlockToColumns();
+}
+
+/**
 	@return les proprietes du cartouches
 */
 TitleBlockProperties BorderTitleBlock::exportTitleBlock() {

Modified: branches/0.3/sources/bordertitleblock.h
===================================================================
--- branches/0.3/sources/bordertitleblock.h	2010-12-28 18:57:24 UTC (rev 1140)
+++ branches/0.3/sources/bordertitleblock.h	2011-01-09 00:01:38 UTC (rev 1141)
@@ -145,6 +145,11 @@
 	/// @param filename le nouveau contenu du champ "Fichier"
 	void setFileName           (const QString &filename) { bi_filename     = filename; }
 	
+	void titleBlockToXml(QDomElement &);
+	void titleBlockFromXml(const QDomElement &);
+	void borderToXml(QDomElement &);
+	void borderFromXml(const QDomElement &);
+	
 	TitleBlockProperties exportTitleBlock();
 	void importTitleBlock(const TitleBlockProperties &);
 	BorderProperties exportBorder();

Modified: branches/0.3/sources/diagram.cpp
===================================================================
--- branches/0.3/sources/diagram.cpp	2010-12-28 18:57:24 UTC (rev 1140)
+++ branches/0.3/sources/diagram.cpp	2011-01-09 00:01:38 UTC (rev 1141)
@@ -272,25 +272,9 @@
 	
 	// proprietes du schema
 	if (whole_content) {
-		if (!border_and_titleblock.author().isNull())    racine.setAttribute("author",   border_and_titleblock.author());
-		if (!border_and_titleblock.date().isNull())      racine.setAttribute("date",     border_and_titleblock.date().toString("yyyyMMdd"));
-		if (!border_and_titleblock.title().isNull())     racine.setAttribute("title",    border_and_titleblock.title());
-		if (!border_and_titleblock.fileName().isNull())  racine.setAttribute("filename", border_and_titleblock.fileName());
-		if (!border_and_titleblock.folio().isNull())     racine.setAttribute("folio",    border_and_titleblock.folio());
+		border_and_titleblock.titleBlockToXml(racine);
+		border_and_titleblock.borderToXml(racine);
 		
-		racine.setAttribute("cols",    border_and_titleblock.nbColumns());
-		racine.setAttribute("colsize", QString("%1").arg(border_and_titleblock.columnsWidth()));
-		racine.setAttribute("rows",    border_and_titleblock.nbRows());
-		racine.setAttribute("rowsize", QString("%1").arg(border_and_titleblock.rowsHeight()));
-		// attribut datant de la version 0.1 - laisse pour retrocompatibilite
-		racine.setAttribute("height",  QString("%1").arg(border_and_titleblock.diagramHeight()));
-		racine.setAttribute("displaycols", border_and_titleblock.columnsAreDisplayed() ? "true" : "false");
-		racine.setAttribute("displayrows", border_and_titleblock.rowsAreDisplayed()    ? "true" : "false");
-		QString current_template_name = border_and_titleblock.titleBlockTemplateName();
-		if (!current_template_name.isEmpty()) {
-			racine.setAttribute("titleblocktemplate", current_template_name);
-		}
-		
 		// type de conducteur par defaut
 		QDomElement default_conductor = document.createElement("defaultconductor");
 		defaultConductorProperties.toXml(default_conductor);
@@ -424,51 +408,14 @@
 	
 	// lecture des attributs de ce schema
 	if (consider_informations) {
-		border_and_titleblock.setAuthor(root.attribute("author"));
-		border_and_titleblock.setTitle(root.attribute("title"));
-		border_and_titleblock.setDate(QDate::fromString(root.attribute("date"), "yyyyMMdd"));
-		border_and_titleblock.setFileName(root.attribute("filename"));
-		border_and_titleblock.setFolio(root.attribute("folio"));
-		setTitleBlockTemplate(root.attribute("titleblocktemplate", ""));
+		border_and_titleblock.titleBlockFromXml(root);
+		border_and_titleblock.borderFromXml(root);
 		
-		bool ok;
-		// nombre de colonnes
-		int nb_cols = root.attribute("cols").toInt(&ok);
-		if (ok) border_and_titleblock.setNbColumns(nb_cols);
-		
-		// taille des colonnes
-		double col_size = root.attribute("colsize").toDouble(&ok);
-		if (ok) border_and_titleblock.setColumnsWidth(col_size);
-		
-		// retrocompatibilite : les schemas enregistres avec la 0.1 ont un attribut "height"
-		if (root.hasAttribute("rows") && root.hasAttribute("rowsize")) {
-			// nombre de lignes
-			int nb_rows = root.attribute("rows").toInt(&ok);
-			if (ok) border_and_titleblock.setNbRows(nb_rows);
-			
-			// taille des lignes
-			double row_size = root.attribute("rowsize").toDouble(&ok);
-			if (ok) border_and_titleblock.setRowsHeight(row_size);
-		} else {
-			// hauteur du schema
-			double height = root.attribute("height").toDouble(&ok);
-			if (ok) border_and_titleblock.setDiagramHeight(height);
-		}
-		
-		// affichage des lignes et colonnes
-		border_and_titleblock.displayColumns(root.attribute("displaycols") != "false");
-		border_and_titleblock.displayRows(root.attribute("displayrows") != "false");
-		
-		border_and_titleblock.adjustTitleBlockToColumns();
-		
 		// repere le permier element "defaultconductor"
-		for (QDomNode node = root.firstChild() ; !node.isNull() ; node = node.nextSibling()) {
-			QDomElement elmts = node.toElement();
-			if(elmts.isNull() || elmts.tagName() != "defaultconductor") continue;
-			defaultConductorProperties.fromXml(elmts);
-			break;
+		QDomElement default_conductor_elmt = root.firstChildElement("defaultconductor");
+		if (!default_conductor_elmt.isNull()) {
+			defaultConductorProperties.fromXml(default_conductor_elmt);
 		}
-		
 	}
 	
 	// si la racine n'a pas d'enfant : le chargement est fini (schema vide)
@@ -954,7 +901,7 @@
 	ExportProperties old_properties;
 	old_properties.draw_grid               = displayGrid();
 	old_properties.draw_border             = border_and_titleblock.borderIsDisplayed();
-	old_properties.draw_titleblock              = border_and_titleblock.titleBlockIsDisplayed();
+	old_properties.draw_titleblock         = border_and_titleblock.titleBlockIsDisplayed();
 	old_properties.draw_terminals          = drawTerminals();
 	old_properties.draw_colored_conductors = drawColoredConductors();
 	old_properties.exported_area           = useBorder() ? QET::BorderArea : QET::ElementsArea;


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