mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 05:00:33 +01:00
replace 4 spaces by a tab
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
QElectroTech is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
QElectroTech is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <QMetaEnum>
|
||||
#include <QHash>
|
||||
@@ -22,176 +22,176 @@
|
||||
#include "qetapp.h"
|
||||
|
||||
/**
|
||||
@brief XRefProperties::XRefProperties
|
||||
Default Constructor
|
||||
@brief XRefProperties::XRefProperties
|
||||
Default Constructor
|
||||
*/
|
||||
XRefProperties::XRefProperties()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
@brief XRefProperties::toSettings
|
||||
Save to settings
|
||||
@param settings: QSettings to use
|
||||
@param prefix: prefix before properties name
|
||||
@brief XRefProperties::toSettings
|
||||
Save to settings
|
||||
@param settings: QSettings to use
|
||||
@param prefix: prefix before properties name
|
||||
*/
|
||||
void XRefProperties::toSettings(QSettings &settings,
|
||||
const QString prefix) const
|
||||
const QString prefix) const
|
||||
{
|
||||
settings.setValue(prefix + "showpowerctc", m_show_power_ctc);
|
||||
QString display = m_display == Cross? "cross" : "contacts";
|
||||
settings.setValue(prefix + "displayhas", display);
|
||||
QString snap = m_snap_to == Bottom? "bottom" : "label";
|
||||
settings.setValue(prefix + "snapto", snap);
|
||||
int offset = m_offset;
|
||||
settings.setValue(prefix + "offset", offset);
|
||||
QString master_label = m_master_label;
|
||||
settings.setValue(prefix + "master_label", master_label);
|
||||
QString slave_label = m_slave_label;
|
||||
settings.setValue(prefix + "slave_label", slave_label);
|
||||
settings.setValue(prefix + "showpowerctc", m_show_power_ctc);
|
||||
QString display = m_display == Cross? "cross" : "contacts";
|
||||
settings.setValue(prefix + "displayhas", display);
|
||||
QString snap = m_snap_to == Bottom? "bottom" : "label";
|
||||
settings.setValue(prefix + "snapto", snap);
|
||||
int offset = m_offset;
|
||||
settings.setValue(prefix + "offset", offset);
|
||||
QString master_label = m_master_label;
|
||||
settings.setValue(prefix + "master_label", master_label);
|
||||
QString slave_label = m_slave_label;
|
||||
settings.setValue(prefix + "slave_label", slave_label);
|
||||
|
||||
|
||||
QMetaEnum var = QMetaEnum::fromType<Qt::Alignment>();
|
||||
settings.setValue(prefix + "xrefpos", var.valueToKey(m_xref_pos));
|
||||
QMetaEnum var = QMetaEnum::fromType<Qt::Alignment>();
|
||||
settings.setValue(prefix + "xrefpos", var.valueToKey(m_xref_pos));
|
||||
|
||||
foreach (QString key, m_prefix.keys()) {
|
||||
settings.setValue(prefix + key + "prefix", m_prefix.value(key));
|
||||
}
|
||||
foreach (QString key, m_prefix.keys()) {
|
||||
settings.setValue(prefix + key + "prefix", m_prefix.value(key));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief XRefProperties::fromSettings
|
||||
load from settings
|
||||
@param settings: QSettings to use
|
||||
@param prefix: prefix before properties name
|
||||
@brief XRefProperties::fromSettings
|
||||
load from settings
|
||||
@param settings: QSettings to use
|
||||
@param prefix: prefix before properties name
|
||||
*/
|
||||
void XRefProperties::fromSettings(const QSettings &settings,
|
||||
const QString prefix)
|
||||
const QString prefix)
|
||||
{
|
||||
m_show_power_ctc = settings.value(prefix + "showpowerctc", true).toBool();
|
||||
QString display = settings.value(prefix + "displayhas", "cross").toString();
|
||||
display == "cross"? m_display = Cross : m_display = Contacts;
|
||||
QString snap = settings.value(prefix + "snapto", "label").toString();
|
||||
snap == "bottom"? m_snap_to = Bottom : m_snap_to = Label;
|
||||
m_offset = settings.value(prefix + "offset", "0").toInt();
|
||||
m_master_label = settings.value(prefix + "master_label", "%f-%l%c").toString();
|
||||
m_slave_label = settings.value(prefix + "slave_label", "(%f-%l%c)").toString();
|
||||
m_show_power_ctc = settings.value(prefix + "showpowerctc", true).toBool();
|
||||
QString display = settings.value(prefix + "displayhas", "cross").toString();
|
||||
display == "cross"? m_display = Cross : m_display = Contacts;
|
||||
QString snap = settings.value(prefix + "snapto", "label").toString();
|
||||
snap == "bottom"? m_snap_to = Bottom : m_snap_to = Label;
|
||||
m_offset = settings.value(prefix + "offset", "0").toInt();
|
||||
m_master_label = settings.value(prefix + "master_label", "%f-%l%c").toString();
|
||||
m_slave_label = settings.value(prefix + "slave_label", "(%f-%l%c)").toString();
|
||||
|
||||
QMetaEnum var = QMetaEnum::fromType<Qt::Alignment>();
|
||||
m_xref_pos = Qt::AlignmentFlag(var.keyToValue((settings.value(prefix + "xrefpos").toString()).toStdString().data()));
|
||||
QMetaEnum var = QMetaEnum::fromType<Qt::Alignment>();
|
||||
m_xref_pos = Qt::AlignmentFlag(var.keyToValue((settings.value(prefix + "xrefpos").toString()).toStdString().data()));
|
||||
|
||||
for (QString key : m_prefix_keys) {
|
||||
m_prefix.insert(key, settings.value(prefix + key + "prefix").toString());
|
||||
}
|
||||
for (QString key : m_prefix_keys) {
|
||||
m_prefix.insert(key, settings.value(prefix + key + "prefix").toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief XRefProperties::toXml
|
||||
Save to xml
|
||||
@param xml_document : QDomElement to use for saving
|
||||
@return QDomElement
|
||||
@brief XRefProperties::toXml
|
||||
Save to xml
|
||||
@param xml_document : QDomElement to use for saving
|
||||
@return QDomElement
|
||||
*/
|
||||
QDomElement XRefProperties::toXml(QDomDocument &xml_document) const
|
||||
{
|
||||
|
||||
QDomElement xml_element = xml_document.createElement("xref");
|
||||
QDomElement xml_element = xml_document.createElement("xref");
|
||||
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "type", m_key));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "showpowerctc", m_show_power_ctc));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "displayhas", m_display == Cross? "cross" : "contacts"));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "snapto", m_snap_to == Bottom? "bottom" : "label"));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "type", m_key));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "showpowerctc", m_show_power_ctc));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "displayhas", m_display == Cross? "cross" : "contacts"));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "snapto", m_snap_to == Bottom? "bottom" : "label"));
|
||||
|
||||
|
||||
QMetaEnum var = QMetaEnum::fromType<Qt::Alignment>();
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "xrefpos", var.valueToKey(m_xref_pos)));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "offset", m_offset));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "master_label", m_master_label));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "slave_label", m_slave_label));
|
||||
QMetaEnum var = QMetaEnum::fromType<Qt::Alignment>();
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "xrefpos", var.valueToKey(m_xref_pos)));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "offset", m_offset));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "master_label", m_master_label));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "slave_label", m_slave_label));
|
||||
|
||||
foreach (QString key, m_prefix.keys()) {
|
||||
xml_element.appendChild(createXmlProperty(xml_document, key + "prefix", m_prefix.value(key)));
|
||||
}
|
||||
foreach (QString key, m_prefix.keys()) {
|
||||
xml_element.appendChild(createXmlProperty(xml_document, key + "prefix", m_prefix.value(key)));
|
||||
}
|
||||
|
||||
return xml_element;
|
||||
return xml_element;
|
||||
}
|
||||
|
||||
/** RETURNS True
|
||||
@brief XRefProperties::fromXml
|
||||
Load from xml
|
||||
@param xml_element: QDomElement to use for load
|
||||
@brief XRefProperties::fromXml
|
||||
Load from xml
|
||||
@param xml_element: QDomElement to use for load
|
||||
*/
|
||||
bool XRefProperties::fromXml(const QDomElement &xml_element) {
|
||||
|
||||
if (propertyBool(xml_element, "showpowerctc", &m_show_power_ctc))
|
||||
return false;
|
||||
if (propertyBool(xml_element, "showpowerctc", &m_show_power_ctc))
|
||||
return false;
|
||||
|
||||
QString display;
|
||||
if (propertyString(xml_element, "displayhas", &display) != PropertyFlags::NotFound) {
|
||||
display == "cross"? m_display = Cross : m_display = Contacts;
|
||||
}
|
||||
QString display;
|
||||
if (propertyString(xml_element, "displayhas", &display) != PropertyFlags::NotFound) {
|
||||
display == "cross"? m_display = Cross : m_display = Contacts;
|
||||
}
|
||||
|
||||
|
||||
QString snap;
|
||||
if (propertyString(xml_element, "snapto", &snap) != PropertyFlags::NotFound) {
|
||||
snap == "bottom"? m_snap_to = Bottom : m_snap_to = Label;
|
||||
}
|
||||
QString snap;
|
||||
if (propertyString(xml_element, "snapto", &snap) != PropertyFlags::NotFound) {
|
||||
snap == "bottom"? m_snap_to = Bottom : m_snap_to = Label;
|
||||
}
|
||||
|
||||
QString xrefpos;
|
||||
if (propertyString(xml_element, "xrefpos", &xrefpos) != PropertyFlags::NotFound) {
|
||||
QMetaEnum var = QMetaEnum::fromType<Qt::Alignment>();
|
||||
m_xref_pos = Qt::AlignmentFlag(var.keyToValue(xrefpos.toStdString().data()));
|
||||
}
|
||||
// TODO: why it compiles without this true??
|
||||
propertyInteger(xml_element, "offset", &m_offset);
|
||||
propertyString(xml_element, "master_label", &m_master_label);
|
||||
propertyString(xml_element, "slave_label", &m_slave_label);
|
||||
QString value;
|
||||
foreach (QString key, m_prefix_keys) {
|
||||
if (!propertyString(xml_element, key + "prefix", &value));
|
||||
m_prefix.insert(key, value);
|
||||
}
|
||||
return true;
|
||||
QString xrefpos;
|
||||
if (propertyString(xml_element, "xrefpos", &xrefpos) != PropertyFlags::NotFound) {
|
||||
QMetaEnum var = QMetaEnum::fromType<Qt::Alignment>();
|
||||
m_xref_pos = Qt::AlignmentFlag(var.keyToValue(xrefpos.toStdString().data()));
|
||||
}
|
||||
// TODO: why it compiles without this true??
|
||||
propertyInteger(xml_element, "offset", &m_offset);
|
||||
propertyString(xml_element, "master_label", &m_master_label);
|
||||
propertyString(xml_element, "slave_label", &m_slave_label);
|
||||
QString value;
|
||||
foreach (QString key, m_prefix_keys) {
|
||||
if (!propertyString(xml_element, key + "prefix", &value));
|
||||
m_prefix.insert(key, value);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief XRefProperties::defaultProperties
|
||||
@return the default properties stored in the setting file
|
||||
For the xref, there is 2 propreties.
|
||||
For coil, stored with the string "coil" in the returned QHash.
|
||||
For protection, stored with the string "protection" in the returned QHash.
|
||||
@brief XRefProperties::defaultProperties
|
||||
@return the default properties stored in the setting file
|
||||
For the xref, there is 2 propreties.
|
||||
For coil, stored with the string "coil" in the returned QHash.
|
||||
For protection, stored with the string "protection" in the returned QHash.
|
||||
*/
|
||||
QHash<QString, XRefProperties> XRefProperties::defaultProperties()
|
||||
{
|
||||
QHash <QString, XRefProperties> hash;
|
||||
QStringList keys;
|
||||
keys << "coil" << "protection" << "commutator";
|
||||
QHash <QString, XRefProperties> hash;
|
||||
QStringList keys;
|
||||
keys << "coil" << "protection" << "commutator";
|
||||
|
||||
QSettings settings;
|
||||
QSettings settings;
|
||||
|
||||
foreach (QString key, keys)
|
||||
{
|
||||
XRefProperties properties;
|
||||
QString str("diagrameditor/defaultxref");
|
||||
properties.fromSettings(settings, str += key);
|
||||
hash.insert(key, properties);
|
||||
}
|
||||
foreach (QString key, keys)
|
||||
{
|
||||
XRefProperties properties;
|
||||
QString str("diagrameditor/defaultxref");
|
||||
properties.fromSettings(settings, str += key);
|
||||
hash.insert(key, properties);
|
||||
}
|
||||
|
||||
return hash;
|
||||
return hash;
|
||||
}
|
||||
|
||||
bool XRefProperties::operator ==(const XRefProperties &xrp) const{
|
||||
return (m_show_power_ctc == xrp.m_show_power_ctc &&
|
||||
m_display == xrp.m_display &&
|
||||
m_snap_to == xrp.m_snap_to &&
|
||||
m_prefix == xrp.m_prefix &&
|
||||
m_master_label == xrp.m_master_label &&
|
||||
m_offset == xrp.m_offset &&
|
||||
m_xref_pos == xrp.m_xref_pos );
|
||||
return (m_show_power_ctc == xrp.m_show_power_ctc &&
|
||||
m_display == xrp.m_display &&
|
||||
m_snap_to == xrp.m_snap_to &&
|
||||
m_prefix == xrp.m_prefix &&
|
||||
m_master_label == xrp.m_master_label &&
|
||||
m_offset == xrp.m_offset &&
|
||||
m_xref_pos == xrp.m_xref_pos );
|
||||
}
|
||||
|
||||
bool XRefProperties::operator !=(const XRefProperties &xrp) const
|
||||
{
|
||||
return (! (*this == xrp));
|
||||
return (! (*this == xrp));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user