QElectroTech  0.70
titleblockproperties.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 "titleblockproperties.h"
19 #include "qet.h"
20 #include "qetapp.h"
21 
27  date(),
28  useDate(UseDateValue),
29  display_at(Qt::BottomEdge),
30  collection (QET::QetCollection::Common)
31 {
32 }
33 
38 }
39 
45  return(
46  ip.title == title &&\
47  ip.author == author &&\
48  ip.date == date &&\
49  ip.filename == filename &&\
50  ip.plant == plant &&\
51  ip.locmach == locmach &&\
52  ip.indexrev == indexrev &&\
53  ip.version == version &&\
54  ip.folio == folio &&\
57  ip.context == context &&\
58  ip.display_at == display_at &&\
60  );
61 }
62 
68  return(!(*this == ip));
69 }
70 
71 
76 void TitleBlockProperties::toXml(QDomElement &e) const {
77  e.setAttribute("author", author);
78  e.setAttribute("title", title);
79  e.setAttribute("filename", filename);
80  e.setAttribute("plant", plant);
81  e.setAttribute("locmach", locmach);
82  e.setAttribute("indexrev",indexrev);
83  e.setAttribute("version", version);
84  e.setAttribute("folio", folio);
85  e.setAttribute("auto_page_num", auto_page_num);
86  e.setAttribute("date", exportDate());
87  e.setAttribute("displayAt", (display_at == Qt::BottomEdge? "bottom" : "right"));
88  if (!template_name.isEmpty())
89  {
90  e.setAttribute("titleblocktemplate", template_name);
91  e.setAttribute("titleblocktemplateCollection", QET::qetCollectionToString(collection));
92  }
93 
94  if (context.keys().count()) {
95  QDomElement properties = e.ownerDocument().createElement("properties");
96  context.toXml(properties);
97  e.appendChild(properties);
98  }
99 }
100 
105 void TitleBlockProperties::fromXml(const QDomElement &e) {
106  // reads the historical fields
107  if (e.hasAttribute("author")) author = e.attribute("author");
108  if (e.hasAttribute("title")) title = e.attribute("title");
109  if (e.hasAttribute("filename")) filename = e.attribute("filename");
110  if (e.hasAttribute("plant")) plant = e.attribute("plant");
111  if (e.hasAttribute("locmach")) locmach = e.attribute("locmach");
112  if (e.hasAttribute("indexrev")) indexrev = e.attribute("indexrev");
113  if (e.hasAttribute("version")) version = e.attribute("version");
114  if (e.hasAttribute("folio")) folio = e.attribute("folio");
115  if (e.hasAttribute("auto_page_num")) auto_page_num = e.attribute("auto_page_num");
116  if (e.hasAttribute("date")) setDateFromString(e.attribute("date"));
117  if (e.hasAttribute("displayAt")) display_at = (e.attribute("displayAt") == "bottom" ? Qt::BottomEdge : Qt::RightEdge);
118 
119  // reads the template used to render the title block
120  if (e.hasAttribute("titleblocktemplate"))
121  {
122  template_name = e.attribute("titleblocktemplate");
123  collection = QET::qetCollectionFromString(e.attribute("titleblocktemplateCollection"));
124  }
125 
126  // reads the additional fields used to fill the title block
127  context.clear();
128  foreach (QDomElement e, QET::findInDomElement(e, "properties")) {
129  context.fromXml(e);
130  }
131 }
132 
139 void TitleBlockProperties::toSettings(QSettings &settings, const QString &prefix) const {
140  settings.setValue(prefix + "title", title);
141  settings.setValue(prefix + "author", author);
142  settings.setValue(prefix + "filename", filename);
143  settings.setValue(prefix + "plant", plant);
144  settings.setValue(prefix + "locmach", locmach);
145  settings.setValue(prefix + "indexrev", indexrev);
146  settings.setValue(prefix + "version", version);
147  settings.setValue(prefix + "folio", folio);
148  settings.setValue(prefix + "auto_page_num", auto_page_num);
149  settings.setValue(prefix + "date", exportDate());
150  settings.setValue(prefix + "displayAt", (display_at == Qt::BottomEdge? "bottom" : "right"));
151  settings.setValue(prefix + "titleblocktemplate", template_name.isEmpty()? QString() : template_name);
152  settings.setValue(prefix + "titleblocktemplateCollection", QET::qetCollectionToString(collection));
153  context.toSettings(settings, prefix + "properties");
154 }
155 
161 void TitleBlockProperties::fromSettings(QSettings &settings, const QString &prefix) {
162  title = settings.value(prefix + "title").toString();
163  author = settings.value(prefix + "author").toString();
164  filename = settings.value(prefix + "filename").toString();
165  plant = settings.value(prefix + "plant").toString();
166  locmach = settings.value(prefix + "locmach").toString();
167  indexrev = settings.value(prefix + "indexrev").toString();
168  version = settings.value(prefix + "version").toString();
169  folio = settings.value(prefix + "folio", "%id/%total").toString();
170  auto_page_num = settings.value(prefix + "auto_page_num").toString();
171  setDateFromString(settings.value(prefix + "date").toString());
172  display_at = (settings.value(prefix + "displayAt", QVariant("bottom")).toString() == "bottom" ? Qt::BottomEdge : Qt::RightEdge);
173  template_name = settings.value(prefix + "titleblocktemplate").toString();
174  collection = QET::qetCollectionFromString(settings.value(prefix + "titleblocktemplateCollection").toString());
175  context.fromSettings(settings, prefix + "properties");
176 }
177 
183 {
184  QSettings settings;
185 
187  def.fromSettings(settings, "diagrameditor/default");
188 
189  return(def);
190 }
191 
196  if (useDate == UseDateValue) {
197  return(date);
198  } else {
199  return(QDate::currentDate());
200  }
201 }
202 
211  QString date_setting_value;
212  if (useDate == UseDateValue) {
213  if (date.isNull()) date_setting_value = "null";
214  else date_setting_value = date.toString("yyyyMMdd");
215  } else {
216  date_setting_value = "now";
217  }
218  return(date_setting_value);
219 }
220 
226 void TitleBlockProperties::setDateFromString(const QString &date_string) {
227  if (date_string == "now") {
228  date = QDate::currentDate();
230  } else if (date_string.isEmpty() || date_string == "null") {
231  date = QDate();
233  } else {
234  date = QDate::fromString(date_string, "yyyyMMdd");
236  }
237 }
void fromSettings(QSettings &, const QString &)
QString locmach
Location(displayed by the default template)
QString plant
Plant (displayed by the default template)
Qt::Edge display_at
Edge to display the titleblock.
void setDateFromString(const QString &)
Definition: qet.h:28
void toSettings(QSettings &, const QString &=QString()) const
TitleBlockProperties::toSettings Export the TitleBlockProperties into a QSettings.
void toSettings(QSettings &, const QString &) const
void toXml(QDomElement &) const
void fromSettings(QSettings &, const QString &=QString())
QDate date
Date (displayed by the default template)
QetCollection
Enum used to specify the origin of a collection of thing (title block, element etc...)
Definition: qet.h:150
QString filename
Filename (displayed by the default template)
QString qetCollectionToString(const QetCollection &c)
QET::qetCollectionToString.
Definition: qet.cpp:597
QetCollection qetCollectionFromString(const QString &str)
QET::qetCollectionFromString.
Definition: qet.cpp:618
QList< QString > keys(KeyOrder=None) const
DiagramContext context
Container for the additional, user-defined fields.
void fromXml(const QDomElement &)
bool operator==(const TitleBlockProperties &)
void fromXml(const QDomElement &, const QString &="property")
QString version
Version (displayed by the default template)
QList< QDomElement > findInDomElement(const QDomElement &, const QString &)
Definition: qet.cpp:300
DateManagement useDate
Wheter to use the date attribute.
bool operator!=(const TitleBlockProperties &)
void toXml(QDomElement &, const QString &="property") const
QString author
Author of the diagram/folio (displayed by the default template)
QString indexrev
Revision Index (displayed by the default template)
QET::QetCollection collection
Specify the location of the title block.
QString folio
Folio information (displayed by the default template)
From common collection.
Definition: qet.h:151
QString title
Folio title (displayed by the default template)
static TitleBlockProperties defaultProperties()
TitleBlockProperties::defaultProperties Return the default properties stored in the setting file...
QString template_name
Name of the template used to render the title block - an empty string means "the default template pro...