mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-20 16:20:52 +01: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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user