1 /*
2 	Copyright 2006-2019 The QElectroTech Team
3 	This file is part of QElectroTech.
4 
5 	QElectroTech is free software: you can redistribute it and/or modify
6 	it under the terms of the GNU General Public License as published by
7 	the Free Software Foundation, either version 2 of the License, or
8 	(at your option) any later version.
9 
10 	QElectroTech is distributed in the hope that it will be useful,
11 	but WITHOUT ANY WARRANTY; without even the implied warranty of
12 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 	GNU General Public License for more details.
14 
15 	You should have received a copy of the GNU General Public License
16 	along with QElectroTech.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "qetinformation.h"
19 
20 #include <QObject>
21 #include <QHash>
22 
23 /**
24  * @brief QETInformation::titleblockInfoKeys
25  * @return all available key for use with a titleblock
26  */
titleblockInfoKeys()27 QStringList QETInformation::titleblockInfoKeys()
28 {
29 	QStringList info_list;
30 	info_list << "author";
31 	info_list << "date";
32 	info_list << "title";
33 	info_list << "filename";
34 	info_list << "plant";
35 	info_list << "locmach";
36 	info_list << "indexrev";
37 	info_list << "version";
38 	info_list << "folio";
39 	info_list << "folio-id";
40 	info_list << "folio-total";
41 	info_list << "previous-folio-num";
42 	info_list << "next-folio-num";
43 	info_list << "projecttitle";
44 	info_list << "projectpath";
45 	info_list << "projectfilename";
46 	info_list << "saveddate";
47 	info_list << "savedtime";
48 	info_list << "savedfilename";
49 	info_list << "savedfilepath";
50 
51 	return info_list;
52 }
53 
54 /**
55  * @brief QETInformation::titleblockTranslatedInfoKey
56  * @param info : info key to be translated
57  * @return the translated information given by @info
58  * If  @info don't match, return an empty string
59  */
titleblockTranslatedInfoKey(const QString & info)60 QString QETInformation::titleblockTranslatedInfoKey(const QString &info)
61 {
62 	if      (info == "author")             return QObject::tr("Auteur");
63 	else if (info == "date")               return QObject::tr("Date");
64 	else if (info == "title")              return QObject::tr("Titre");
65 	else if (info == "filename")           return QObject::tr("Fichier");
66 	else if (info == "plant")              return QObject::tr("Installation (=)");
67 	else if (info == "locmach")            return QObject::tr("Localisation (+)");
68 	else if (info == "indexrev")           return QObject::tr("Indice de révision");
69 	else if (info == "version")            return QObject::tr("Version de QElectroTech");
70 	else if (info == "folio")              return QObject::tr("Numéro de folio");
71 	else if (info == "folio-id")           return QObject::tr("Position du folio");
72 	else if (info == "folio-total")        return QObject::tr("Nombre de folio");
73 	else if (info == "previous-folio-num") return QObject::tr("Numéro du folio précédent");
74 	else if (info == "next-folio-num")     return QObject::tr("Numéro du folio suivant");
75 	else if (info == "projecttitle")       return QObject::tr("Titre du projet");
76 	else if (info == "projectpath")        return QObject::tr("Chemin du fichier du projet");
77 	else if (info == "projectfilename")    return QObject::tr("Nom du fichier");
78 	else if (info == "saveddate")          return QObject::tr("Date d'enregistrement du fichier");
79 	else if (info == "savedtime")          return QObject::tr("Heure d'enregistrement du fichier");
80 	else if (info == "savedfilename")      return QObject::tr("Nom du fichier enregistré");
81 	else if (info == "savedfilepath")      return QObject::tr("Chemin du fichier enregistré");
82 	else return QString();
83 }
84 
85 /**
86  * @brief QETInformation::titleblockInfoKeysToVar
87  * @param info
88  * @return var in form %{my-var} corresponding to the info.
89  * if there is not available var for the given info, the returned var is %{void}
90  */
titleblockInfoKeysToVar(const QString & info)91 QString QETInformation::titleblockInfoKeysToVar(const QString &info)
92 {
93 	if      (info == "author")             return QString("%{author}");
94 	else if (info == "date")               return QString("%{date}");
95 	else if (info == "title")              return QString("%{title}");
96 	else if (info == "filename")           return QString("%{filename}");
97 	else if (info == "plant")              return QString("%{plant}");
98 	else if (info == "locmach")            return QString("%{locmach}");
99 	else if (info == "indexrev")           return QString("%{indexrev}");
100 	else if (info == "version")            return QString("%{version}");
101 	else if (info == "folio")              return QString("%{folio}");
102 	else if (info == "folio-id")           return QString("%{folio-id}");
103 	else if (info == "folio-total")        return QString("%{folio-total}");
104 	else if (info == "previous-folio-num") return QString("%{previous-folio-num}");
105 	else if (info == "next-folio-num")     return QString("%{next-folio-num}");
106 	else if (info == "projecttitle")       return QString("%{projecttitle}");
107 	else if (info == "projectpath")        return QString("%{projectpath}");
108 	else if (info == "projectfilename")    return QString("%{projectfilename}");
109 	else if (info == "saveddate")          return QString("%{saveddate}");
110 	else if (info == "savedtime")          return QString("%{savedtime}");
111 	else if (info == "savedfilename")      return QString("%{savedfilename}");
112 	else if (info == "savedfilepath")      return QString("%{savedfilepath}");
113 	else return QString("%{void");
114 }
115 
116 /**
117  * @brief QETInformation::titleblockTranslatedKeyHashVar
118  * @return a QHash with for key, the translated information key of title block,
119  * and for value the corresponding var.
120  */
titleblockTranslatedKeyHashVar()121 QHash<QString, QString> QETInformation::titleblockTranslatedKeyHashVar()
122 {
123 	QHash <QString, QString> hash_;
124 	for (QString str : titleblockInfoKeys()) {
125 		hash_.insert(titleblockTranslatedInfoKey(str), titleblockInfoKeysToVar(str));
126 	}
127 	return hash_;
128 }
129