mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
NamesList: Use ‘Qmap’ instead of ‘Qhash’
to automatically sort the names of an element by language code before saving the element-file. Added English comment in header-file.
This commit is contained in:
@@ -46,7 +46,7 @@ NamesList::~NamesList()
|
|||||||
void NamesList::addName(const QString &lang, const QString &name) {
|
void NamesList::addName(const QString &lang, const QString &name) {
|
||||||
if ((lang.length() != 2) && (lang.length() != 5)) return;
|
if ((lang.length() != 2) && (lang.length() != 5)) return;
|
||||||
if ((lang.length() == 5) && (lang[2] != '_')) return;
|
if ((lang.length() == 5) && (lang[2] != '_')) return;
|
||||||
hash_names.insert(lang, name);
|
map_names.insert(lang, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,7 +54,7 @@ void NamesList::addName(const QString &lang, const QString &name) {
|
|||||||
@param lang la langue pour laquelle il faut supprimer le nom
|
@param lang la langue pour laquelle il faut supprimer le nom
|
||||||
*/
|
*/
|
||||||
void NamesList::removeName(const QString &lang) {
|
void NamesList::removeName(const QString &lang) {
|
||||||
hash_names.remove(lang);
|
map_names.remove(lang);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,7 +62,7 @@ void NamesList::removeName(const QString &lang) {
|
|||||||
*/
|
*/
|
||||||
void NamesList::clearNames()
|
void NamesList::clearNames()
|
||||||
{
|
{
|
||||||
hash_names.clear();
|
map_names.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -70,7 +70,7 @@ void NamesList::clearNames()
|
|||||||
*/
|
*/
|
||||||
QList<QString> NamesList::langs() const
|
QList<QString> NamesList::langs() const
|
||||||
{
|
{
|
||||||
return(hash_names.keys());
|
return(map_names.keys());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -78,7 +78,7 @@ QList<QString> NamesList::langs() const
|
|||||||
*/
|
*/
|
||||||
bool NamesList::isEmpty() const
|
bool NamesList::isEmpty() const
|
||||||
{
|
{
|
||||||
return(hash_names.isEmpty());
|
return(map_names.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -86,7 +86,7 @@ bool NamesList::isEmpty() const
|
|||||||
*/
|
*/
|
||||||
int NamesList::count() const
|
int NamesList::count() const
|
||||||
{
|
{
|
||||||
return(hash_names.count());
|
return(map_names.count());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -95,7 +95,7 @@ int NamesList::count() const
|
|||||||
defini
|
defini
|
||||||
*/
|
*/
|
||||||
QString &NamesList::operator[](const QString &lang) {
|
QString &NamesList::operator[](const QString &lang) {
|
||||||
return(hash_names[lang]);
|
return(map_names[lang]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -105,7 +105,7 @@ QString &NamesList::operator[](const QString &lang) {
|
|||||||
*/
|
*/
|
||||||
const QString NamesList::operator[](const QString &lang) const
|
const QString NamesList::operator[](const QString &lang) const
|
||||||
{
|
{
|
||||||
return(hash_names.value(lang));
|
return(map_names.value(lang));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -184,18 +184,19 @@ QDomElement NamesList::toXml(QDomDocument &xml_document, const QHash<QString, QS
|
|||||||
{
|
{
|
||||||
QHash<QString, QString> xml_opt = getXmlOptions(xml_options);
|
QHash<QString, QString> xml_opt = getXmlOptions(xml_options);
|
||||||
QDomElement names_elmt = xml_document.createElement(xml_opt["ParentTagName"]);
|
QDomElement names_elmt = xml_document.createElement(xml_opt["ParentTagName"]);
|
||||||
if (hash_names.isEmpty()) {
|
if (map_names.isEmpty()) {
|
||||||
|
qInfo() << " NamesList of element is empty - add default: [" << "en" << "] = " << "NoName" << "";
|
||||||
QDomElement name_elmt = xml_document.createElement(xml_opt["TagName"]);
|
QDomElement name_elmt = xml_document.createElement(xml_opt["TagName"]);
|
||||||
name_elmt.setAttribute(xml_opt["LanguageAttribute"], "en");
|
name_elmt.setAttribute(xml_opt["LanguageAttribute"], "en");
|
||||||
name_elmt.appendChild(xml_document.createTextNode("NoName"));
|
name_elmt.appendChild(xml_document.createTextNode("NoName"));
|
||||||
names_elmt.appendChild(name_elmt);
|
names_elmt.appendChild(name_elmt);
|
||||||
}
|
}
|
||||||
QHashIterator<QString, QString> names_iterator(hash_names);
|
QMapIterator<QString, QString> names_iterator(map_names);
|
||||||
while (names_iterator.hasNext()) {
|
while (names_iterator.hasNext()) {
|
||||||
names_iterator.next();
|
names_iterator.next();
|
||||||
QDomElement name_elmt = xml_document.createElement(xml_opt["TagName"]);
|
QDomElement name_elmt = xml_document.createElement(xml_opt["TagName"]);
|
||||||
name_elmt.setAttribute(xml_opt["LanguageAttribute"], names_iterator.key());
|
name_elmt.setAttribute(xml_opt["LanguageAttribute"], names_iterator.key());
|
||||||
name_elmt.appendChild(xml_document.createTextNode(names_iterator.value()));
|
name_elmt.appendChild(xml_document.createTextNode(names_iterator.value().trimmed()));
|
||||||
names_elmt.appendChild(name_elmt);
|
names_elmt.appendChild(name_elmt);
|
||||||
}
|
}
|
||||||
return(names_elmt);
|
return(names_elmt);
|
||||||
@@ -229,7 +230,7 @@ QHash<QString, QString> NamesList::getXmlOptions(const QHash<QString, QString> &
|
|||||||
*/
|
*/
|
||||||
bool NamesList::operator!=(const NamesList &nl) const
|
bool NamesList::operator!=(const NamesList &nl) const
|
||||||
{
|
{
|
||||||
return(hash_names != nl.hash_names);
|
return(map_names != nl.map_names);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -238,7 +239,7 @@ bool NamesList::operator!=(const NamesList &nl) const
|
|||||||
*/
|
*/
|
||||||
bool NamesList::operator==(const NamesList &nl) const
|
bool NamesList::operator==(const NamesList &nl) const
|
||||||
{
|
{
|
||||||
return(hash_names == nl.hash_names);
|
return(map_names == nl.map_names);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -257,10 +258,10 @@ bool NamesList::operator==(const NamesList &nl) const
|
|||||||
QString NamesList::name(const QString &fallback_name) const
|
QString NamesList::name(const QString &fallback_name) const
|
||||||
{
|
{
|
||||||
QString system_language = QETApp::langFromSetting();
|
QString system_language = QETApp::langFromSetting();
|
||||||
if (! hash_names[system_language].isEmpty())
|
if (! map_names[system_language].isEmpty())
|
||||||
return (hash_names[system_language]);
|
return (map_names[system_language]);
|
||||||
if (! hash_names["en"].isEmpty()) return (hash_names["en"]);
|
if (! map_names["en"].isEmpty()) return (map_names["en"]);
|
||||||
if (! fallback_name.isEmpty()) return (fallback_name);
|
if (! fallback_name.isEmpty()) return (fallback_name);
|
||||||
if (hash_names.count()) return (hash_names.begin().value());
|
if (map_names.count()) return (map_names.begin().value());
|
||||||
return (QString(""));
|
return (QString(""));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,12 @@
|
|||||||
|
|
||||||
#include <QtXml>
|
#include <QtXml>
|
||||||
/**
|
/**
|
||||||
|
This class represents a list of names, used by elements and categories
|
||||||
|
to embed the same name in several languages.
|
||||||
|
Languages are represented by two or five letters (typically the first
|
||||||
|
two of the system locale); examples: en for English, fr for French,
|
||||||
|
pt_BR for Brazilian Portuguese.
|
||||||
|
French:
|
||||||
Cette classe represente une liste de noms, utilisee
|
Cette classe represente une liste de noms, utilisee
|
||||||
par les elements et categories pour embarquer un meme nom en plusieurs
|
par les elements et categories pour embarquer un meme nom en plusieurs
|
||||||
langues.
|
langues.
|
||||||
@@ -36,7 +42,7 @@ class NamesList {
|
|||||||
|
|
||||||
// attributes
|
// attributes
|
||||||
private:
|
private:
|
||||||
QHash<QString, QString> hash_names;
|
QMap<QString, QString> map_names;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static int MetaTypeId;
|
static int MetaTypeId;
|
||||||
|
|||||||
Reference in New Issue
Block a user