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 "borderproperties.h"
19 
20 /**
21 	Constructeur. Initialise un objet BorderProperties avec les proprietes par
22 	defaut suivantes :
23 	  * 17 colonnes affichees de 60.0 px de large pour 20.0px de haut
24 	  * 8 lignes affichees de 80.0 px de haut pour 20.0px de large
25 */
BorderProperties()26 BorderProperties::BorderProperties() :
27 	columns_count(17),
28 	columns_width(60.0),
29 	columns_header_height(20.0),
30 	display_columns(true),
31 	rows_count(8),
32 	rows_height(80.0),
33 	rows_header_width(20.0),
34 	display_rows(true)
35 {
36 }
37 
38 /**
39 	Destructeur
40 */
~BorderProperties()41 BorderProperties::~BorderProperties() {
42 }
43 
44 /**
45 	@param bp autre conteneur BorderProperties
46 	@return true si ip et ce conteneur sont identiques, false sinon
47 */
operator ==(const BorderProperties & bp)48 bool BorderProperties::operator==(const BorderProperties &bp) {
49 	return(
50 		bp.columns_count == columns_count &&\
51 		bp.columns_width == columns_width &&\
52 		bp.columns_header_height == columns_header_height &&\
53 		bp.display_columns == display_columns &&\
54 		bp.rows_count == rows_count &&\
55 		bp.rows_height == rows_height &&\
56 		bp.rows_header_width == rows_header_width &&\
57 		bp.display_rows == display_rows
58 	);
59 }
60 
61 /**
62 	@param bp autre conteneur BorderProperties
63 	@return false si bp et ce conteneur sont identiques, true sinon
64 */
operator !=(const BorderProperties & bp)65 bool BorderProperties::operator!=(const BorderProperties &bp) {
66 	return(!(*this == bp));
67 }
68 
69 /**
70 	Exporte les dimensions sous formes d'attributs XML ajoutes a l'element e.
71 	@param e Element XML auquel seront ajoutes des attributs
72 */
toXml(QDomElement & e) const73 void BorderProperties::toXml(QDomElement &e) const {
74 	e.setAttribute("cols",        columns_count);
75 	e.setAttribute("colsize",     QString("%1").arg(columns_width));
76 	e.setAttribute("rows",        rows_count);
77 	e.setAttribute("rowsize",     QString("%1").arg(rows_height));
78 	e.setAttribute("displaycols", display_columns ? "true" : "false");
79 	e.setAttribute("displayrows", display_rows    ? "true" : "false");
80 }
81 
82 /**
83 	Importe les dimensions a partir des attributs XML de l'element e
84 	@param e Element XML dont les attributs seront lus
85 */
fromXml(QDomElement & e)86 void BorderProperties::fromXml(QDomElement &e) {
87 	if (e.hasAttribute("cols"))        columns_count   = e.attribute("cols").toInt();
88 	if (e.hasAttribute("colsize"))     columns_width   = e.attribute("colsize").toInt();
89 	if (e.hasAttribute("rows"))        rows_count      = e.attribute("rows").toInt();
90 	if (e.hasAttribute("rowsize"))     rows_height     = e.attribute("rowsize").toInt();
91 	if (e.hasAttribute("displaycols")) display_columns = e.attribute("displaycols") == "true";
92 	if (e.hasAttribute("displayrows")) display_rows    = e.attribute("displayrows") == "true";
93 }
94 
95 /**
96 	Exporte les dimensions dans une configuration.
97 	@param settings Parametres a ecrire
98 	@param prefix prefixe a ajouter devant les noms des parametres
99 */
toSettings(QSettings & settings,const QString & prefix) const100 void BorderProperties::toSettings(QSettings &settings, const QString &prefix) const {
101 	settings.setValue(prefix + "cols",        columns_count);
102 	settings.setValue(prefix + "colsize",     columns_width);
103 	settings.setValue(prefix + "displaycols", display_columns);
104 	settings.setValue(prefix + "rows",        rows_count);
105 	settings.setValue(prefix + "rowsize",     rows_height);
106 	settings.setValue(prefix + "displayrows", display_rows);
107 }
108 
109 /**
110 	Importe les dimensions depuis une configuration.
111 	@param settings Parametres a lire
112 	@param prefix prefixe a ajouter devant les noms des parametres
113 */
fromSettings(QSettings & settings,const QString & prefix)114 void BorderProperties::fromSettings(QSettings &settings, const QString &prefix) {
115 	columns_count   = settings.value(prefix + "cols",            columns_count).toInt();
116 	columns_width   = qRound(settings.value(prefix + "colsize",  columns_width).toDouble());
117 	display_columns = settings.value(prefix + "displaycols",     display_columns).toBool();
118 
119 	rows_count      = settings.value(prefix + "rows",            rows_count).toInt();
120 	rows_height     = qRound(settings.value(prefix + "rowsize",  rows_height).toDouble());
121 	display_rows    = settings.value(prefix + "displayrows",     display_rows).toBool();
122 }
123 
124 /**
125  * @brief BorderProperties::defaultProperties
126  * @return the default properties stored in the setting file
127  */
defaultProperties()128 BorderProperties BorderProperties::defaultProperties()
129 {
130 	QSettings settings;
131 
132 	BorderProperties def;
133 	def.fromSettings(settings, "diagrameditor/default");
134 
135 	return(def);
136 }
137