[qet] [1131] Project files now load and save inset templates.

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


Revision: 1131
Author:   xavier
Date:     2010-12-19 19:14:05 +0100 (Sun, 19 Dec 2010)
Log Message:
-----------
Project files now load and save inset templates.

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

Modified: branches/0.3/sources/diagram.cpp
===================================================================
--- branches/0.3/sources/diagram.cpp	2010-12-19 18:12:56 UTC (rev 1130)
+++ branches/0.3/sources/diagram.cpp	2010-12-19 18:14:05 UTC (rev 1131)
@@ -85,7 +85,7 @@
 		if (qgraphicsitem_cast<Conductor *>(qgi)) continue;
 		deletable_items << qgi;
 	}
-
+	
 	// suppression des items supprimables
 	foreach(QGraphicsItem *qgi_d, deletable_items) {
 		delete qgi_d;
@@ -280,6 +280,9 @@
 		racine.setAttribute("height",  QString("%1").arg(border_and_inset.diagramHeight()));
 		racine.setAttribute("displaycols", border_and_inset.columnsAreDisplayed() ? "true" : "false");
 		racine.setAttribute("displayrows", border_and_inset.rowsAreDisplayed()    ? "true" : "false");
+		if (!inset_template_name_.isEmpty()) {
+			racine.setAttribute("insettemplate", inset_template_name_);
+		}
 		
 		// type de conducteur par defaut
 		QDomElement default_conductor = document.createElement("defaultconductor");
@@ -419,6 +422,14 @@
 		border_and_inset.setDate(QDate::fromString(root.attribute("date"), "yyyyMMdd"));
 		border_and_inset.setFileName(root.attribute("filename"));
 		border_and_inset.setFolio(root.attribute("folio"));
+		if (root.hasAttribute("insettemplate") && project_) {
+			QString inset_template_name = root.attribute("insettemplate");
+			const InsetTemplate *inset_template = project_ -> getTemplateByName(inset_template_name);
+			if (inset_template) {
+				inset_template_name_ = inset_template_name;
+				border_and_inset.setInsetTemplate(inset_template);
+			}
+		}
 		
 		bool ok;
 		// nombre de colonnes

Modified: branches/0.3/sources/diagram.h
===================================================================
--- branches/0.3/sources/diagram.h	2010-12-19 18:12:56 UTC (rev 1130)
+++ branches/0.3/sources/diagram.h	2010-12-19 18:14:05 UTC (rev 1131)
@@ -85,6 +85,7 @@
 	QDomDocument xml_document;
 	QETProject *project_;
 	bool read_only_;
+	QString inset_template_name_;
 	
 	// methodes
 	protected:

Modified: branches/0.3/sources/qetproject.cpp
===================================================================
--- branches/0.3/sources/qetproject.cpp	2010-12-19 18:12:56 UTC (rev 1130)
+++ branches/0.3/sources/qetproject.cpp	2010-12-19 18:14:05 UTC (rev 1131)
@@ -25,6 +25,7 @@
 #include "integrationmoveelementshandler.h"
 #include "basicmoveelementshandler.h"
 #include "qetmessagebox.h"
+#include "insettemplate.h"
 
 QString QETProject::integration_category_name = "import";
 
@@ -267,6 +268,51 @@
 }
 
 /**
+	@return the list of the inset templates embedded within this project 
+*/
+QList<QString> QETProject::embeddedInsetTemplates() const {
+	return(inset_templates_xml_.keys());
+}
+
+/**
+	@param template_name Name of the requested template
+	@return the requested template, or 0 if there is no vltaid template of this
+	name within the project
+*/
+const InsetTemplate *QETProject::getTemplateByName(const QString &template_name) {
+	// Do we have already loaded this template?
+	if (inset_templates_.contains(template_name)) {
+		return(inset_templates_[template_name]);
+	}
+	
+	// No? Do we even know of it?
+	if (!inset_templates_xml_.contains(template_name)) {
+		return(0);
+	}
+	
+	// Ok, we have its XML description, we have to generate an InsetTemplate object
+	InsetTemplate *inset_template = new InsetTemplate(this);
+	if (inset_template -> loadFromXmlElement(inset_templates_xml_[template_name])) {
+		inset_templates_.insert(template_name, inset_template);
+		return(inset_template);
+	} else {
+		return(0);
+	}
+}
+
+/**
+	@param template_name Name of the requested template
+	@return the XML description of the requested template, or a null QDomElement
+	if the project does not have such an inset template
+*/
+QDomElement QETProject::getTemplateXmlDescriptionByName(const QString &template_name) {
+	if (inset_templates_xml_.contains(template_name)) {
+		return(inset_templates_xml_[template_name]);
+	}
+	return(QDomElement());
+}
+
+/**
 	@return les dimensions par defaut utilisees lors de la creation d'un
 	nouveau schema dans ce projet.
 */
@@ -327,6 +373,16 @@
 	project_root.setAttribute("title", project_title_);
 	xml_doc.appendChild(project_root);
 	
+	// inset templates, if any
+	if (inset_templates_xml_.count()) {
+		qDebug() << qPrintable(QString("QETProject::toXml() : exporting %1 inset templates").arg(inset_templates_xml_.count()));
+		QDomElement insettemplates_elmt = xml_doc.createElement("insettemplates");
+		foreach (QDomElement e, inset_templates_xml_) {
+			insettemplates_elmt.appendChild(e);
+		}
+		project_root.appendChild(insettemplates_elmt);
+	}
+	
 	// proprietes pour les nouveaux schemas
 	QDomElement new_diagrams_properties = xml_doc.createElement("newdiagrams");
 	writeDefaultPropertiesXml(new_diagrams_properties);
@@ -734,6 +790,9 @@
 	// charge les proprietes par defaut pour les nouveaux schemas
 	readDefaultPropertiesXml();
 	
+	// load the embedded inset templates
+	readEmbeddedTemplatesXml();
+	
 	// charge la collection embarquee
 	readElementsCollectionXml();
 	
@@ -777,6 +836,24 @@
 }
 
 /**
+	Loads the embedded template from the XML description of the project
+*/
+void QETProject::readEmbeddedTemplatesXml() {
+	foreach (QDomElement e, QET::findInDomElement(document_root_.documentElement(), "insettemplates", "insettemplate")) {
+		// each inset template must have a name
+		if (!e.hasAttribute("name")) continue;
+		QString inset_template_name = e.attribute("name");
+		
+		// if several templates have the same name, we keep the first one encountered
+		if (inset_templates_xml_.contains(inset_template_name)) continue;
+		
+		// we simply store the XML element describing the inset template,
+		// without any further analysis for the moment
+		inset_templates_xml_.insert(inset_template_name, e);
+	}
+}
+
+/**
 	Charge les schemas depuis la description XML du projet
 */
 void QETProject::readElementsCollectionXml() {

Modified: branches/0.3/sources/qetproject.h
===================================================================
--- branches/0.3/sources/qetproject.h	2010-12-19 18:12:56 UTC (rev 1130)
+++ branches/0.3/sources/qetproject.h	2010-12-19 18:14:05 UTC (rev 1131)
@@ -29,6 +29,7 @@
 class ElementsCategory;
 class ElementDefinition;
 class ElementsLocation;
+class InsetTemplate;
 class XmlElementsCollection;
 class MoveElementsHandler;
 /**
@@ -79,6 +80,9 @@
 	QString title() const;
 	qreal declaredQElectroTechVersion();
 	void setTitle(const QString &);
+	QList<QString> embeddedInsetTemplates() const;
+	const InsetTemplate *getTemplateByName(const QString &template_name);
+	QDomElement getTemplateXmlDescriptionByName(const QString &);
 	BorderProperties defaultBorderProperties() const;
 	void setDefaultBorderProperties(const BorderProperties &);
 	InsetProperties defaultInsetProperties() const;
@@ -124,6 +128,7 @@
 	void readProjectXml();
 	void readDiagramsXml();
 	void readElementsCollectionXml();
+	void readEmbeddedTemplatesXml();
 	void readDefaultPropertiesXml();
 	void writeDefaultPropertiesXml(QDomElement &);
 	void addDiagram(Diagram *);
@@ -158,5 +163,9 @@
 	ConductorProperties default_conductor_properties_;
 	/// Proprietes par defaut du cartouche pour les nouveaux schemas dans ce projet
 	InsetProperties default_inset_properties_;
+	/// XML descriptions of embedded inset templates
+	QHash<QString, QDomElement> inset_templates_xml_;
+	/// Already parsed embedded inset templates
+	QHash<QString, InsetTemplate *> inset_templates_;
 };
 #endif


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