2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2021-02-20 12:13:46 +01:00
|
|
|
Copyright 2006-2021 The QElectroTech Team
|
2007-12-01 10:47:15 +00:00
|
|
|
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 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/>.
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
#include "titleblockproperties.h"
|
2011-01-09 15:16:51 +00:00
|
|
|
#include "qet.h"
|
2014-10-26 11:57:38 +00:00
|
|
|
#include "qetapp.h"
|
2007-12-01 10:29:03 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
/**
|
2010-12-20 02:45:36 +00:00
|
|
|
Constructeur. Initialise un objet TitleBlockProperties avec tous les champs
|
2009-04-03 19:30:25 +00:00
|
|
|
vides (date vide + useDate a UseDateValue).
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
TitleBlockProperties::TitleBlockProperties() :
|
2009-04-03 19:30:25 +00:00
|
|
|
date(),
|
2015-03-16 13:29:27 +00:00
|
|
|
useDate(UseDateValue),
|
2015-04-17 11:36:28 +00:00
|
|
|
display_at(Qt::BottomEdge),
|
|
|
|
collection (QET::QetCollection::Common)
|
2009-04-03 19:30:25 +00:00
|
|
|
{
|
2007-12-01 10:29:03 +00:00
|
|
|
}
|
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
/**
|
|
|
|
Destructeur
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
TitleBlockProperties::~TitleBlockProperties()
|
|
|
|
{
|
2007-12-01 10:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-12-20 02:45:36 +00:00
|
|
|
@param ip autre conteneur TitleBlockProperties
|
2007-12-01 10:29:03 +00:00
|
|
|
@return true si ip et ce conteneur sont identiques, false sinon
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
bool TitleBlockProperties::operator==(const TitleBlockProperties &ip) {
|
2007-12-01 10:29:03 +00:00
|
|
|
return(
|
|
|
|
ip.title == title &&\
|
|
|
|
ip.author == author &&\
|
|
|
|
ip.date == date &&\
|
|
|
|
ip.filename == filename &&\
|
2018-12-04 22:33:11 +00:00
|
|
|
ip.plant == plant &&\
|
2016-08-12 11:32:56 +00:00
|
|
|
ip.locmach == locmach &&\
|
2016-08-11 18:32:08 +00:00
|
|
|
ip.indexrev == indexrev &&\
|
2016-08-10 12:25:47 +00:00
|
|
|
ip.version == version &&\
|
2010-12-24 23:35:40 +00:00
|
|
|
ip.folio == folio &&\
|
2016-05-13 15:00:22 +00:00
|
|
|
ip.auto_page_num == auto_page_num &&\
|
2011-01-09 15:16:51 +00:00
|
|
|
ip.template_name == template_name &&\
|
2015-03-16 13:29:27 +00:00
|
|
|
ip.context == context &&\
|
2015-04-17 11:36:28 +00:00
|
|
|
ip.display_at == display_at &&\
|
|
|
|
ip.collection == collection
|
2007-12-01 10:29:03 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-12-20 02:45:36 +00:00
|
|
|
@param ip autre conteneur TitleBlockProperties
|
2007-12-01 10:29:03 +00:00
|
|
|
@return false si ip et ce conteneur sont identiques, true sinon
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
bool TitleBlockProperties::operator!=(const TitleBlockProperties &ip) {
|
2007-12-01 10:29:03 +00:00
|
|
|
return(!(*this == ip));
|
|
|
|
}
|
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Exporte le cartouche sous formes d'attributs XML ajoutes a l'element e.
|
|
|
|
@param e Element XML auquel seront ajoutes des attributs
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
void TitleBlockProperties::toXml(QDomElement &e) const
|
|
|
|
{
|
2009-04-03 19:30:25 +00:00
|
|
|
e.setAttribute("author", author);
|
|
|
|
e.setAttribute("title", title);
|
|
|
|
e.setAttribute("filename", filename);
|
2018-12-04 22:33:11 +00:00
|
|
|
e.setAttribute("plant", plant);
|
2016-08-12 11:32:56 +00:00
|
|
|
e.setAttribute("locmach", locmach);
|
2016-08-11 18:32:08 +00:00
|
|
|
e.setAttribute("indexrev",indexrev);
|
2016-08-10 12:25:47 +00:00
|
|
|
e.setAttribute("version", version);
|
2009-04-03 19:30:25 +00:00
|
|
|
e.setAttribute("folio", folio);
|
2016-05-13 15:00:22 +00:00
|
|
|
e.setAttribute("auto_page_num", auto_page_num);
|
2009-04-03 19:30:25 +00:00
|
|
|
e.setAttribute("date", exportDate());
|
2015-03-16 13:29:27 +00:00
|
|
|
e.setAttribute("displayAt", (display_at == Qt::BottomEdge? "bottom" : "right"));
|
2015-04-17 11:36:28 +00:00
|
|
|
if (!template_name.isEmpty())
|
|
|
|
{
|
2010-12-24 23:35:40 +00:00
|
|
|
e.setAttribute("titleblocktemplate", template_name);
|
2015-04-17 11:36:28 +00:00
|
|
|
e.setAttribute("titleblocktemplateCollection", QET::qetCollectionToString(collection));
|
2010-12-24 23:35:40 +00:00
|
|
|
}
|
2011-01-09 15:16:51 +00:00
|
|
|
|
|
|
|
if (context.keys().count()) {
|
|
|
|
QDomElement properties = e.ownerDocument().createElement("properties");
|
2012-07-01 21:54:06 +00:00
|
|
|
context.toXml(properties);
|
2011-01-09 15:16:51 +00:00
|
|
|
e.appendChild(properties);
|
|
|
|
}
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Importe le cartouche a partir des attributs XML de l'element e
|
|
|
|
@param e Element XML dont les attributs seront lus
|
|
|
|
*/
|
2011-01-09 15:16:51 +00:00
|
|
|
void TitleBlockProperties::fromXml(const QDomElement &e) {
|
|
|
|
// reads the historical fields
|
2009-04-03 19:30:25 +00:00
|
|
|
if (e.hasAttribute("author")) author = e.attribute("author");
|
|
|
|
if (e.hasAttribute("title")) title = e.attribute("title");
|
|
|
|
if (e.hasAttribute("filename")) filename = e.attribute("filename");
|
2018-12-04 22:33:11 +00:00
|
|
|
if (e.hasAttribute("plant")) plant = e.attribute("plant");
|
2016-08-12 11:32:56 +00:00
|
|
|
if (e.hasAttribute("locmach")) locmach = e.attribute("locmach");
|
2018-12-04 22:33:11 +00:00
|
|
|
if (e.hasAttribute("indexrev")) indexrev = e.attribute("indexrev");
|
|
|
|
if (e.hasAttribute("version")) version = e.attribute("version");
|
2009-04-03 19:30:25 +00:00
|
|
|
if (e.hasAttribute("folio")) folio = e.attribute("folio");
|
2016-05-13 15:00:22 +00:00
|
|
|
if (e.hasAttribute("auto_page_num")) auto_page_num = e.attribute("auto_page_num");
|
2009-04-03 19:30:25 +00:00
|
|
|
if (e.hasAttribute("date")) setDateFromString(e.attribute("date"));
|
2015-03-16 13:29:27 +00:00
|
|
|
if (e.hasAttribute("displayAt")) display_at = (e.attribute("displayAt") == "bottom" ? Qt::BottomEdge : Qt::RightEdge);
|
2011-01-09 15:16:51 +00:00
|
|
|
|
2015-04-17 11:36:28 +00:00
|
|
|
// reads the template used to render the title block
|
|
|
|
if (e.hasAttribute("titleblocktemplate"))
|
|
|
|
{
|
|
|
|
template_name = e.attribute("titleblocktemplate");
|
|
|
|
collection = QET::qetCollectionFromString(e.attribute("titleblocktemplateCollection"));
|
|
|
|
}
|
2011-01-09 15:16:51 +00:00
|
|
|
|
|
|
|
// reads the additional fields used to fill the title block
|
2012-07-01 21:54:03 +00:00
|
|
|
context.clear();
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach (QDomElement e, QET::findInDomElement(e, "properties")) {
|
2012-07-01 21:54:06 +00:00
|
|
|
context.fromXml(e);
|
2011-01-09 15:16:51 +00:00
|
|
|
}
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief TitleBlockProperties::toSettings
|
|
|
|
Export the TitleBlockProperties into a QSettings
|
|
|
|
@param settings : setting to use
|
|
|
|
@param prefix : name to use as prefix for this property
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
void TitleBlockProperties::toSettings(QSettings &settings, const QString &prefix) const
|
|
|
|
{
|
2009-04-03 19:30:25 +00:00
|
|
|
settings.setValue(prefix + "title", title);
|
|
|
|
settings.setValue(prefix + "author", author);
|
|
|
|
settings.setValue(prefix + "filename", filename);
|
2018-12-04 22:33:11 +00:00
|
|
|
settings.setValue(prefix + "plant", plant);
|
2016-08-12 11:32:56 +00:00
|
|
|
settings.setValue(prefix + "locmach", locmach);
|
2016-08-11 18:32:08 +00:00
|
|
|
settings.setValue(prefix + "indexrev", indexrev);
|
2016-08-10 12:25:47 +00:00
|
|
|
settings.setValue(prefix + "version", version);
|
2009-04-03 19:30:25 +00:00
|
|
|
settings.setValue(prefix + "folio", folio);
|
2016-05-13 15:00:22 +00:00
|
|
|
settings.setValue(prefix + "auto_page_num", auto_page_num);
|
2009-04-03 19:30:25 +00:00
|
|
|
settings.setValue(prefix + "date", exportDate());
|
2015-03-16 13:29:27 +00:00
|
|
|
settings.setValue(prefix + "displayAt", (display_at == Qt::BottomEdge? "bottom" : "right"));
|
2015-04-09 09:39:34 +00:00
|
|
|
settings.setValue(prefix + "titleblocktemplate", template_name.isEmpty()? QString() : template_name);
|
2015-04-17 11:36:28 +00:00
|
|
|
settings.setValue(prefix + "titleblocktemplateCollection", QET::qetCollectionToString(collection));
|
2012-07-01 21:54:06 +00:00
|
|
|
context.toSettings(settings, prefix + "properties");
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Importe le cartouche depuis une configuration.
|
|
|
|
@param settings Parametres a lire
|
|
|
|
@param prefix prefixe a ajouter devant les noms des parametres
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
void TitleBlockProperties::fromSettings(QSettings &settings, const QString &prefix) {
|
2009-04-03 19:30:25 +00:00
|
|
|
title = settings.value(prefix + "title").toString();
|
|
|
|
author = settings.value(prefix + "author").toString();
|
|
|
|
filename = settings.value(prefix + "filename").toString();
|
2018-12-04 22:33:11 +00:00
|
|
|
plant = settings.value(prefix + "plant").toString();
|
2016-08-12 11:32:56 +00:00
|
|
|
locmach = settings.value(prefix + "locmach").toString();
|
2016-08-11 18:32:08 +00:00
|
|
|
indexrev = settings.value(prefix + "indexrev").toString();
|
|
|
|
version = settings.value(prefix + "version").toString();
|
2009-04-03 19:30:25 +00:00
|
|
|
folio = settings.value(prefix + "folio", "%id/%total").toString();
|
2016-05-13 15:00:22 +00:00
|
|
|
auto_page_num = settings.value(prefix + "auto_page_num").toString();
|
2009-04-03 19:30:25 +00:00
|
|
|
setDateFromString(settings.value(prefix + "date").toString());
|
2015-03-16 13:29:27 +00:00
|
|
|
display_at = (settings.value(prefix + "displayAt", QVariant("bottom")).toString() == "bottom" ? Qt::BottomEdge : Qt::RightEdge);
|
2015-04-09 09:39:34 +00:00
|
|
|
template_name = settings.value(prefix + "titleblocktemplate").toString();
|
2015-04-17 11:36:28 +00:00
|
|
|
collection = QET::qetCollectionFromString(settings.value(prefix + "titleblocktemplateCollection").toString());
|
2012-07-01 21:54:06 +00:00
|
|
|
context.fromSettings(settings, prefix + "properties");
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
|
|
|
|
2014-10-26 11:57:38 +00:00
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief TitleBlockProperties::defaultProperties
|
|
|
|
Return the default properties stored in the setting file
|
|
|
|
*/
|
2015-09-16 15:11:13 +00:00
|
|
|
TitleBlockProperties TitleBlockProperties::defaultProperties()
|
|
|
|
{
|
|
|
|
QSettings settings;
|
2014-10-26 11:57:38 +00:00
|
|
|
|
|
|
|
TitleBlockProperties def;
|
|
|
|
def.fromSettings(settings, "diagrameditor/default");
|
|
|
|
|
|
|
|
return(def);
|
|
|
|
}
|
|
|
|
|
2007-12-01 10:29:03 +00:00
|
|
|
/**
|
|
|
|
@return La date a utiliser
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
QDate TitleBlockProperties::finalDate() const
|
|
|
|
{
|
2007-12-01 10:29:03 +00:00
|
|
|
if (useDate == UseDateValue) {
|
|
|
|
return(date);
|
|
|
|
} else {
|
|
|
|
return(QDate::currentDate());
|
|
|
|
}
|
|
|
|
}
|
2009-04-03 19:30:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
@return une chaine de caracteres decrivant comment gerer la date dans le
|
|
|
|
cartouche : la chaine peut valoir :
|
|
|
|
* null pour ne pas afficher de date
|
|
|
|
* now pour afficher la date courante (a la creation du schema)
|
|
|
|
* une date au format yyyyMMdd pour utiliser une date fixe
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
QString TitleBlockProperties::exportDate() const
|
|
|
|
{
|
2009-04-03 19:30:25 +00:00
|
|
|
QString date_setting_value;
|
|
|
|
if (useDate == UseDateValue) {
|
|
|
|
if (date.isNull()) date_setting_value = "null";
|
|
|
|
else date_setting_value = date.toString("yyyyMMdd");
|
|
|
|
} else {
|
|
|
|
date_setting_value = "now";
|
|
|
|
}
|
|
|
|
return(date_setting_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Charge les attributs date et useDate a partir d'une chaine de caracteres.
|
|
|
|
@param date_string Chaine de caracteres a analyser
|
|
|
|
@see exportDate
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
void TitleBlockProperties::setDateFromString(const QString &date_string) {
|
2009-04-03 19:30:25 +00:00
|
|
|
if (date_string == "now") {
|
|
|
|
date = QDate::currentDate();
|
|
|
|
useDate = CurrentDate;
|
|
|
|
} else if (date_string.isEmpty() || date_string == "null") {
|
|
|
|
date = QDate();
|
|
|
|
useDate = UseDateValue;
|
|
|
|
} else {
|
|
|
|
date = QDate::fromString(date_string, "yyyyMMdd");
|
|
|
|
useDate = UseDateValue;
|
|
|
|
}
|
|
|
|
}
|