mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Refactoring: move code from Diagram to BorderTitleBlock.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1141 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
parent
2b0e478f08
commit
3b07252a9a
@ -89,6 +89,89 @@ qreal BorderTitleBlock::minRowsHeight() {
|
||||
return(5.0);
|
||||
}
|
||||
|
||||
/**
|
||||
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
|
||||
*/
|
||||
|
@ -145,6 +145,11 @@ class BorderTitleBlock : public QObject {
|
||||
/// @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();
|
||||
|
@ -272,24 +272,8 @@ QDomDocument Diagram::toXml(bool whole_content) {
|
||||
|
||||
// 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());
|
||||
|
||||
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);
|
||||
}
|
||||
border_and_titleblock.titleBlockToXml(racine);
|
||||
border_and_titleblock.borderToXml(racine);
|
||||
|
||||
// type de conducteur par defaut
|
||||
QDomElement default_conductor = document.createElement("defaultconductor");
|
||||
@ -424,51 +408,14 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
|
||||
|
||||
// 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", ""));
|
||||
|
||||
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();
|
||||
border_and_titleblock.titleBlockFromXml(root);
|
||||
border_and_titleblock.borderFromXml(root);
|
||||
|
||||
// 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 Diagram::applyProperties(const ExportProperties &new_properties
|
||||
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user