mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Titleblock templates values and labels can now be translated.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1286 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
parent
6de787a0cc
commit
caa0df63dc
@ -30,6 +30,7 @@
|
||||
#include "hotspoteditor.h"
|
||||
#include "editorcommands.h"
|
||||
#include "elementcontent.h"
|
||||
#include "nameslist.h"
|
||||
|
||||
/**
|
||||
Constructeur
|
||||
|
@ -102,23 +102,28 @@ const QString NamesList::operator[](const QString &lang) const {
|
||||
return(hash_names.value(lang));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Charge la liste de noms depuis un element XML. Cet element est sense etre
|
||||
le parent d'un element "names", qui contient lui meme les "name".
|
||||
Les noms precedemment contenus dans la liste ne sont pas effaces mais
|
||||
peuvent etre ecrases.
|
||||
@param xml_element L'element XML a analyser
|
||||
@param xml_options A set of options related to XML parsing.
|
||||
@see getXmlOptions()
|
||||
*/
|
||||
void NamesList::fromXml(const QDomElement &xml_element) {
|
||||
void NamesList::fromXml(const QDomElement &xml_element, const QHash<QString, QString> &xml_options) {
|
||||
QHash<QString, QString> xml_opt = getXmlOptions(xml_options);
|
||||
// parcourt les enfants "names" de l'element XML
|
||||
for (QDomNode node = xml_element.firstChild() ; !node.isNull() ; node = node.nextSibling()) {
|
||||
QDomElement names = node.toElement();
|
||||
if (names.isNull() || names.tagName() != "names") continue;
|
||||
if (names.isNull() || names.tagName() != xml_opt["ParentTagName"]) continue;
|
||||
// parcourt les petits-enfants "name"
|
||||
for (QDomNode n = names.firstChild() ; !n.isNull() ; n = n.nextSibling()) {
|
||||
QDomElement name = n.toElement();
|
||||
if (name.isNull() || name.tagName() != "name") continue;
|
||||
addName(name.attribute("lang"), name.text());
|
||||
if (name.isNull() || name.tagName() != xml_opt["TagName"]) continue;
|
||||
addName(name.attribute(xml_opt["LanguageAttribute"]), name.text());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -127,22 +132,45 @@ void NamesList::fromXml(const QDomElement &xml_element) {
|
||||
Exporte la liste des noms vers un element XML. Veillez a verifier que la
|
||||
liste de noms n'est pas vide avant de l'exporter.
|
||||
@param xml_document Le document XML dans lequel l'element XML sera insere
|
||||
@param xml_options A set of options related to XML parsing.
|
||||
@return L'element XML correspondant a la section "names"
|
||||
@see count()
|
||||
*/
|
||||
QDomElement NamesList::toXml(QDomDocument &xml_document) const {
|
||||
QDomElement names_elmt = xml_document.createElement("names");
|
||||
QDomElement NamesList::toXml(QDomDocument &xml_document, const QHash<QString, QString> &xml_options) const {
|
||||
QHash<QString, QString> xml_opt = getXmlOptions(xml_options);
|
||||
QDomElement names_elmt = xml_document.createElement(xml_opt["ParentTagName"]);
|
||||
QHashIterator<QString, QString> names_iterator(hash_names);
|
||||
while (names_iterator.hasNext()) {
|
||||
names_iterator.next();
|
||||
QDomElement name_elmt = xml_document.createElement("name");
|
||||
name_elmt.setAttribute("lang", names_iterator.key());
|
||||
QDomElement name_elmt = xml_document.createElement(xml_opt["TagName"]);
|
||||
name_elmt.setAttribute(xml_opt["LanguageAttribute"], names_iterator.key());
|
||||
name_elmt.appendChild(xml_document.createTextNode(names_iterator.value()));
|
||||
names_elmt.appendChild(name_elmt);
|
||||
}
|
||||
return(names_elmt);
|
||||
}
|
||||
|
||||
/**
|
||||
@param xml_options A set of options related to XML parsing. Available keys:
|
||||
* ParentTagName (falls back to "names")
|
||||
* TagName (falls back to "name")
|
||||
* LanguageAttribute (falls back to "lang")
|
||||
@return the same set, with at least all the known options
|
||||
*/
|
||||
QHash<QString, QString> NamesList::getXmlOptions(const QHash<QString, QString> &xml_options) const {
|
||||
QHash<QString, QString> new_xml_options = xml_options;
|
||||
if (!xml_options.contains("ParentTagName")) {
|
||||
new_xml_options.insert("ParentTagName", "names");
|
||||
}
|
||||
if (!xml_options.contains("TagName")) {
|
||||
new_xml_options.insert("TagName", "name");
|
||||
}
|
||||
if (!xml_options.contains("LanguageAttribute")) {
|
||||
new_xml_options.insert("LanguageAttribute", "lang");
|
||||
}
|
||||
return new_xml_options;
|
||||
}
|
||||
|
||||
/**
|
||||
@param nl une autre liste de noms
|
||||
@return true si les listes de noms sont differentes, false sinon
|
||||
|
@ -53,7 +53,10 @@ class NamesList {
|
||||
QString name(const QString & = QString()) const;
|
||||
|
||||
// methodes relatives a XML
|
||||
void fromXml(const QDomElement &);
|
||||
QDomElement toXml(QDomDocument &) const;
|
||||
void fromXml(const QDomElement &, const QHash<QString, QString> & = QHash<QString, QString>());
|
||||
QDomElement toXml(QDomDocument &, const QHash<QString, QString> & = QHash<QString, QString>()) const;
|
||||
|
||||
protected:
|
||||
QHash<QString, QString> getXmlOptions(const QHash<QString, QString> & = QHash<QString, QString>()) const;
|
||||
};
|
||||
#endif
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "titleblocktemplate.h"
|
||||
#include "qet.h"
|
||||
#include "qetapp.h"
|
||||
#include "nameslist.h"
|
||||
|
||||
/**
|
||||
Constructor
|
||||
@ -45,6 +46,9 @@ bool TitleBlockTemplate::loadFromXmlFile(const QString &filepath) {
|
||||
if (!template_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
return(false);
|
||||
}
|
||||
#ifdef TITLEBLOCK_TEMPLATE_DEBUG
|
||||
qDebug() << Q_FUNC_INFO << filepath << "opened";
|
||||
#endif
|
||||
|
||||
// parses its content as XML
|
||||
bool xml_parsing = xml_description_.setContent(&template_file);
|
||||
@ -52,7 +56,7 @@ bool TitleBlockTemplate::loadFromXmlFile(const QString &filepath) {
|
||||
return(false);
|
||||
}
|
||||
#ifdef TITLEBLOCK_TEMPLATE_DEBUG
|
||||
qDebug() << Q_FUNC_INFO << filepath << "opened";
|
||||
qDebug() << Q_FUNC_INFO << filepath << "opened and parsed";
|
||||
#endif
|
||||
return(loadFromXmlElement(xml_description_.documentElement()));
|
||||
}
|
||||
@ -264,12 +268,24 @@ bool TitleBlockTemplate::loadCells(const QDomElement &xml_element) {
|
||||
if (cell_element.hasAttribute("name") && !cell_element.attribute("name").isEmpty()) {
|
||||
loaded_cell -> value_name = cell_element.attribute("name");
|
||||
}
|
||||
if (cell_element.hasAttribute("value") && !cell_element.attribute("value").isEmpty()) {
|
||||
loaded_cell -> value = cell_element.attribute("value");
|
||||
|
||||
QHash<QString, QString> names_options;
|
||||
names_options["TagName"] = "translation";
|
||||
|
||||
names_options["ParentTagName"] = "value";
|
||||
NamesList value_nameslist;
|
||||
value_nameslist.fromXml(cell_element, names_options);
|
||||
if (!value_nameslist.name().isEmpty()) {
|
||||
loaded_cell -> value = value_nameslist.name();
|
||||
}
|
||||
if (cell_element.hasAttribute("label") && !cell_element.attribute("label").isEmpty()) {
|
||||
loaded_cell -> label = cell_element.attribute("label");
|
||||
|
||||
names_options["ParentTagName"] = "label";
|
||||
NamesList label_nameslist;
|
||||
label_nameslist.fromXml(cell_element, names_options);
|
||||
if (!label_nameslist.name().isEmpty()) {
|
||||
loaded_cell -> label = label_nameslist.name();
|
||||
}
|
||||
|
||||
if (cell_element.hasAttribute("displaylabel") && cell_element.attribute("displaylabel").compare("false", Qt::CaseInsensitive) == 0) {
|
||||
loaded_cell -> display_label = false;
|
||||
}
|
||||
|
@ -2,10 +2,50 @@
|
||||
<informations>Author: The QElectroTech team
|
||||
License: see http://qelectrotech.org/wiki/doc/elements_license</informations>
|
||||
<grid rows="25px;25px" cols="t22%;r100%;t22%">
|
||||
<field row="0" col="0" name="author" label="Auteur" displaylabel="true" align="left" rowspan="0" value="%author" />
|
||||
<field row="1" col="0" name="date" label="Date" displaylabel="true" align="left" rowspan="0" value="%date" />
|
||||
<field row="0" col="1" name="title" label="Titre" displaylabel="false" align="center" rowspan="1" value="%title" />
|
||||
<field row="0" col="2" name="file" label="Fichier" displaylabel="true" align="left" rowspan="0" value="%filename" />
|
||||
<field row="1" col="2" name="folio" label="Folio" displaylabel="true" align="left" rowspan="0" value="%{folio-id}/%{folio-total}" />
|
||||
<field row="0" col="0" name="author" displaylabel="true" align="left" rowspan="0">
|
||||
<label>
|
||||
<translation lang="en">Author</translation>
|
||||
<translation lang="fr">Auteur</translation>
|
||||
</label>
|
||||
<value>
|
||||
<translation lang="en">%author</translation>
|
||||
</value>
|
||||
</field>
|
||||
<field row="1" col="0" name="date" displaylabel="true" align="left" rowspan="0">
|
||||
<label>
|
||||
<translation lang="en">Date</translation>
|
||||
<translation lang="fr">Date</translation>
|
||||
</label>
|
||||
<value>
|
||||
<translation lang="en">%date</translation>
|
||||
</value>
|
||||
</field>
|
||||
<field row="0" col="1" name="title" displaylabel="false" align="center" rowspan="1">
|
||||
<label>
|
||||
<translation lang="en">Title</translation>
|
||||
<translation lang="fr">Titre</translation>
|
||||
</label>
|
||||
<value>
|
||||
<translation lang="en">%title</translation>
|
||||
</value>
|
||||
</field>
|
||||
<field row="0" col="2" name="file" displaylabel="true" align="left" rowspan="0">
|
||||
<label>
|
||||
<translation lang="en">File</translation>
|
||||
<translation lang="fr">Fichier</translation>
|
||||
</label>
|
||||
<value>
|
||||
<translation lang="en">%filename</translation>
|
||||
</value>
|
||||
</field>
|
||||
<field row="1" col="2" name="folio" displaylabel="true" align="left" rowspan="0">
|
||||
<label>
|
||||
<translation lang="en">Folio</translation>
|
||||
<translation lang="fr">Folio</translation>
|
||||
</label>
|
||||
<value>
|
||||
<translation lang="en">%{folio-id}/%{folio-total}</translation>
|
||||
</value>
|
||||
</field>
|
||||
</grid>
|
||||
</titleblocktemplate>
|
||||
|
Loading…
x
Reference in New Issue
Block a user