mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 22:00:35 +01:00
Project files now load and save inset templates.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1131 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -280,6 +280,9 @@ QDomDocument Diagram::toXml(bool whole_content) {
|
|||||||
racine.setAttribute("height", QString("%1").arg(border_and_inset.diagramHeight()));
|
racine.setAttribute("height", QString("%1").arg(border_and_inset.diagramHeight()));
|
||||||
racine.setAttribute("displaycols", border_and_inset.columnsAreDisplayed() ? "true" : "false");
|
racine.setAttribute("displaycols", border_and_inset.columnsAreDisplayed() ? "true" : "false");
|
||||||
racine.setAttribute("displayrows", border_and_inset.rowsAreDisplayed() ? "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
|
// type de conducteur par defaut
|
||||||
QDomElement default_conductor = document.createElement("defaultconductor");
|
QDomElement default_conductor = document.createElement("defaultconductor");
|
||||||
@@ -419,6 +422,14 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
|
|||||||
border_and_inset.setDate(QDate::fromString(root.attribute("date"), "yyyyMMdd"));
|
border_and_inset.setDate(QDate::fromString(root.attribute("date"), "yyyyMMdd"));
|
||||||
border_and_inset.setFileName(root.attribute("filename"));
|
border_and_inset.setFileName(root.attribute("filename"));
|
||||||
border_and_inset.setFolio(root.attribute("folio"));
|
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;
|
bool ok;
|
||||||
// nombre de colonnes
|
// nombre de colonnes
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ class Diagram : public QGraphicsScene {
|
|||||||
QDomDocument xml_document;
|
QDomDocument xml_document;
|
||||||
QETProject *project_;
|
QETProject *project_;
|
||||||
bool read_only_;
|
bool read_only_;
|
||||||
|
QString inset_template_name_;
|
||||||
|
|
||||||
// methodes
|
// methodes
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include "integrationmoveelementshandler.h"
|
#include "integrationmoveelementshandler.h"
|
||||||
#include "basicmoveelementshandler.h"
|
#include "basicmoveelementshandler.h"
|
||||||
#include "qetmessagebox.h"
|
#include "qetmessagebox.h"
|
||||||
|
#include "insettemplate.h"
|
||||||
|
|
||||||
QString QETProject::integration_category_name = "import";
|
QString QETProject::integration_category_name = "import";
|
||||||
|
|
||||||
@@ -266,6 +267,51 @@ void QETProject::setTitle(const QString &title) {
|
|||||||
emit(projectInformationsChanged(this));
|
emit(projectInformationsChanged(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@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
|
@return les dimensions par defaut utilisees lors de la creation d'un
|
||||||
nouveau schema dans ce projet.
|
nouveau schema dans ce projet.
|
||||||
@@ -327,6 +373,16 @@ QDomDocument QETProject::toXml() {
|
|||||||
project_root.setAttribute("title", project_title_);
|
project_root.setAttribute("title", project_title_);
|
||||||
xml_doc.appendChild(project_root);
|
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
|
// proprietes pour les nouveaux schemas
|
||||||
QDomElement new_diagrams_properties = xml_doc.createElement("newdiagrams");
|
QDomElement new_diagrams_properties = xml_doc.createElement("newdiagrams");
|
||||||
writeDefaultPropertiesXml(new_diagrams_properties);
|
writeDefaultPropertiesXml(new_diagrams_properties);
|
||||||
@@ -734,6 +790,9 @@ void QETProject::readProjectXml() {
|
|||||||
// charge les proprietes par defaut pour les nouveaux schemas
|
// charge les proprietes par defaut pour les nouveaux schemas
|
||||||
readDefaultPropertiesXml();
|
readDefaultPropertiesXml();
|
||||||
|
|
||||||
|
// load the embedded inset templates
|
||||||
|
readEmbeddedTemplatesXml();
|
||||||
|
|
||||||
// charge la collection embarquee
|
// charge la collection embarquee
|
||||||
readElementsCollectionXml();
|
readElementsCollectionXml();
|
||||||
|
|
||||||
@@ -776,6 +835,24 @@ void QETProject::readDiagramsXml() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
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
|
Charge les schemas depuis la description XML du projet
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ class ElementsCollection;
|
|||||||
class ElementsCategory;
|
class ElementsCategory;
|
||||||
class ElementDefinition;
|
class ElementDefinition;
|
||||||
class ElementsLocation;
|
class ElementsLocation;
|
||||||
|
class InsetTemplate;
|
||||||
class XmlElementsCollection;
|
class XmlElementsCollection;
|
||||||
class MoveElementsHandler;
|
class MoveElementsHandler;
|
||||||
/**
|
/**
|
||||||
@@ -79,6 +80,9 @@ class QETProject : public QObject {
|
|||||||
QString title() const;
|
QString title() const;
|
||||||
qreal declaredQElectroTechVersion();
|
qreal declaredQElectroTechVersion();
|
||||||
void setTitle(const QString &);
|
void setTitle(const QString &);
|
||||||
|
QList<QString> embeddedInsetTemplates() const;
|
||||||
|
const InsetTemplate *getTemplateByName(const QString &template_name);
|
||||||
|
QDomElement getTemplateXmlDescriptionByName(const QString &);
|
||||||
BorderProperties defaultBorderProperties() const;
|
BorderProperties defaultBorderProperties() const;
|
||||||
void setDefaultBorderProperties(const BorderProperties &);
|
void setDefaultBorderProperties(const BorderProperties &);
|
||||||
InsetProperties defaultInsetProperties() const;
|
InsetProperties defaultInsetProperties() const;
|
||||||
@@ -124,6 +128,7 @@ class QETProject : public QObject {
|
|||||||
void readProjectXml();
|
void readProjectXml();
|
||||||
void readDiagramsXml();
|
void readDiagramsXml();
|
||||||
void readElementsCollectionXml();
|
void readElementsCollectionXml();
|
||||||
|
void readEmbeddedTemplatesXml();
|
||||||
void readDefaultPropertiesXml();
|
void readDefaultPropertiesXml();
|
||||||
void writeDefaultPropertiesXml(QDomElement &);
|
void writeDefaultPropertiesXml(QDomElement &);
|
||||||
void addDiagram(Diagram *);
|
void addDiagram(Diagram *);
|
||||||
@@ -158,5 +163,9 @@ class QETProject : public QObject {
|
|||||||
ConductorProperties default_conductor_properties_;
|
ConductorProperties default_conductor_properties_;
|
||||||
/// Proprietes par defaut du cartouche pour les nouveaux schemas dans ce projet
|
/// Proprietes par defaut du cartouche pour les nouveaux schemas dans ce projet
|
||||||
InsetProperties default_inset_properties_;
|
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
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user