2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2010-01-03 16:25:37 +00:00
|
|
|
Copyright 2006-2010 Xavier Guerrin
|
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"
|
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(),
|
|
|
|
useDate(UseDateValue)
|
|
|
|
{
|
2007-12-01 10:29:03 +00:00
|
|
|
}
|
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
/**
|
|
|
|
Destructeur
|
|
|
|
*/
|
2010-12-20 02:45:36 +00: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 &&\
|
|
|
|
ip.folio == folio
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
|
*/
|
2010-12-20 02:45:36 +00: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);
|
|
|
|
e.setAttribute("folio", folio);
|
|
|
|
e.setAttribute("date", exportDate());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Importe le cartouche a partir des attributs XML de l'element e
|
|
|
|
@param e Element XML dont les attributs seront lus
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
void TitleBlockProperties::fromXml(QDomElement &e) {
|
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");
|
|
|
|
if (e.hasAttribute("folio")) folio = e.attribute("folio");
|
|
|
|
if (e.hasAttribute("date")) setDateFromString(e.attribute("date"));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Exporte le cartouche dans une configuration.
|
|
|
|
@param settings Parametres a ecrire
|
|
|
|
@param prefix prefixe a ajouter devant les noms des parametres
|
|
|
|
*/
|
2010-12-20 02:45:36 +00: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);
|
|
|
|
settings.setValue(prefix + "folio", folio);
|
|
|
|
settings.setValue(prefix + "date", exportDate());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
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();
|
|
|
|
folio = settings.value(prefix + "folio", "%id/%total").toString();
|
|
|
|
setDateFromString(settings.value(prefix + "date").toString());
|
|
|
|
}
|
|
|
|
|
2007-12-01 10:29:03 +00:00
|
|
|
/**
|
|
|
|
@return La date a utiliser
|
|
|
|
*/
|
2010-12-20 02:45:36 +00: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
|
|
|
|
*/
|
2010-12-20 02:45:36 +00: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;
|
|
|
|
}
|
|
|
|
}
|