QElectroTech  0.70
xrefproperties.cpp
Go to the documentation of this file.
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 "xrefproperties.h"
19 #include "qetapp.h"
20 
26 {
27  m_show_power_ctc = true;
28  m_display = Cross;
29  m_snap_to = Bottom;
30  m_prefix_keys << "power" << "delay" << "switch";
31  m_master_label = "%f-%l%c";
32  m_slave_label = "(%f-%l%c)";
33  m_offset = 0;
34 }
35 
42 void XRefProperties::toSettings(QSettings &settings, const QString prefix) const {
43  settings.setValue(prefix + "showpowerctc", m_show_power_ctc);
44  QString display = m_display == Cross? "cross" : "contacts";
45  settings.setValue(prefix + "displayhas", display);
46  QString snap = m_snap_to == Bottom? "bottom" : "label";
47  settings.setValue(prefix + "snapto", snap);
48  int offset = m_offset;
49  settings.setValue(prefix + "offset", offset);
50  QString master_label = m_master_label;
51  settings.setValue(prefix + "master_label", master_label);
52  QString slave_label = m_slave_label;
53  settings.setValue(prefix + "slave_label", slave_label);
54  foreach (QString key, m_prefix.keys()) {
55  settings.setValue(prefix + key + "prefix", m_prefix.value(key));
56  }
57 }
58 
65 void XRefProperties::fromSettings(const QSettings &settings, const QString prefix) {
66  m_show_power_ctc = settings.value(prefix + "showpowerctc", false).toBool();
67  QString display = settings.value(prefix + "displayhas", "cross").toString();
68  display == "cross"? m_display = Cross : m_display = Contacts;
69  QString snap = settings.value(prefix + "snapto", "label").toString();
70  snap == "bottom"? m_snap_to = Bottom : m_snap_to = Label;
71  m_offset = settings.value(prefix + "offset", "0").toInt();
72  m_master_label = settings.value(prefix + "master_label", "%f-%l%c").toString();
73  m_slave_label = settings.value(prefix + "slave_label", "(%f-%l%c)").toString();
74  foreach (QString key, m_prefix_keys) {
75  m_prefix.insert(key, settings.value(prefix + key + "prefix").toString());
76  }
77 }
78 
84 void XRefProperties::toXml(QDomElement &xml_element) const {
85  xml_element.setAttribute("showpowerctc", m_show_power_ctc? "true" : "false");
86  QString display = m_display == Cross? "cross" : "contacts";
87  xml_element.setAttribute("displayhas", display);
88  QString snap = m_snap_to == Bottom? "bottom" : "label";
89  xml_element.setAttribute("snapto", snap);
90  int offset = m_offset;
91  xml_element.setAttribute("offset", QString::number(offset));
92  QString master_label = m_master_label;
93  xml_element.setAttribute("master_label", master_label);
94  QString slave_label = m_slave_label;
95  xml_element.setAttribute("slave_label", slave_label);
96  foreach (QString key, m_prefix.keys()) {
97  xml_element.setAttribute(key + "prefix", m_prefix.value(key));
98  }
99 }
100 
106 void XRefProperties::fromXml(const QDomElement &xml_element) {
107  m_show_power_ctc = xml_element.attribute("showpowerctc") == "true";
108  QString display = xml_element.attribute("displayhas", "cross");
109  display == "cross"? m_display = Cross : m_display = Contacts;
110  QString snap = xml_element.attribute("snapto", "label");
111  snap == "bottom"? m_snap_to = Bottom : m_snap_to = Label;
112  m_offset = xml_element.attribute("offset", "0").toInt();
113  m_master_label = xml_element.attribute("master_label", "%f-%l%c");
114  m_slave_label = xml_element.attribute("slave_label","(%f-%l%c)");
115  foreach (QString key, m_prefix_keys) {
116  m_prefix.insert(key, xml_element.attribute(key + "prefix"));
117  }
118 }
119 
127 QHash<QString, XRefProperties> XRefProperties::defaultProperties()
128 {
129  QHash <QString, XRefProperties> hash;
130  QStringList keys;
131  keys << "coil" << "protection" << "commutator";
132 
133  QSettings settings;
134 
135  foreach (QString key, keys)
136  {
137  XRefProperties properties;
138  QString str("diagrameditor/defaultxref");
139  properties.fromSettings(settings, str += key);
140  hash.insert(key, properties);
141  }
142 
143  return hash;
144 }
145 
147  return (m_show_power_ctc == xrp.m_show_power_ctc &&
148  m_display == xrp.m_display &&
149  m_snap_to == xrp.m_snap_to &&
150  m_prefix == xrp.m_prefix &&
152  m_slave_label == xrp.m_slave_label &&
153  m_offset == xrp.m_offset);
154 }
155 
157  return (! (*this == xrp));
158 }
159 
160 
QString prefix(const QString &key) const
DisplayHas m_display
The XRefProperties class this class store properties used by XrefItem.
void fromSettings(const QSettings &settings, const QString=QString()) override
XRefProperties::fromSettings load from settings.
QHash< QString, QString > m_prefix
static QHash< QString, XRefProperties > defaultProperties()
XRefProperties::defaultProperties.
QString m_master_label
void toSettings(QSettings &settings, const QString=QString()) const override
XRefProperties::toSettings Save to settings.
int offset() const
bool operator==(const XRefProperties &xrp) const
void toXml(QDomElement &xml_element) const override
XRefProperties::toXml Save to xml.
void fromXml(const QDomElement &xml_element) override
XRefProperties::fromXml Load from xml.
XRefProperties()
XRefProperties::XRefProperties Default Constructor.
bool operator!=(const XRefProperties &xrp) const
QStringList m_prefix_keys
QString m_slave_label