QElectroTech  0.70
titleblockcell.cpp
Go to the documentation of this file.
1 #include "titleblockcell.h"
2 #include "titleblocktemplate.h"
8  num_row = num_col = -1;
9  row_span = col_span = 0;
12  spanner_cell = nullptr;
13  display_label = true;
14  alignment = Qt::AlignCenter | Qt::AlignVCenter;
15  font_size = 9;
16  hadjust = false;
17  logo_reference = QString("");
18 }
19 
24 }
25 
30  return(cell_type);
31 }
32 
37  return(alignment & Qt::AlignHorizontal_Mask);
38 }
39 
44  return(alignment & Qt::AlignVertical_Mask);
45 }
46 
52 void TitleBlockCell::setAttribute(const QString &attribute, const QVariant &attr_value) {
53  if (attribute == "type") {
54  int new_type = attr_value.toInt();
55  if (new_type <= TitleBlockCell::LogoCell) {
56  cell_type = static_cast<TitleBlockCell::TemplateCellType>(new_type);
57  }
58  } else if (attribute == "name") {
59  value_name = attr_value.toString();
60  } else if (attribute == "logo") {
61  logo_reference = attr_value.toString();
62  } else if (attribute == "label") {
63  label = qvariant_cast<NamesList>(attr_value);
64  } else if (attribute == "displaylabel") {
65  display_label = attr_value.toBool();
66  } else if (attribute == "value") {
67  value = qvariant_cast<NamesList>(attr_value);
68  } else if (attribute == "alignment") {
69  alignment = attr_value.toInt();
70  } else if (attribute == "fontsize") {
71  font_size = attr_value.toInt();
72  } else if (attribute == "horizontal_adjust") {
73  hadjust = attr_value.toBool();
74  }
75 }
76 
81 QVariant TitleBlockCell::attribute(const QString &attribute) {
82  if (attribute == "type") {
83  return(type());
84  } else if (attribute == "name") {
85  return(value_name);
86  } else if (attribute == "logo") {
87  return(logo_reference);
88  } else if (attribute == "label") {
89  return(qVariantFromValue(label));
90  } else if (attribute == "displaylabel") {
91  return(display_label);
92  } else if (attribute == "value") {
93  return(qVariantFromValue(value));
94  } else if (attribute == "alignment") {
95  return(alignment);
96  } else if (attribute == "fontsize") {
97  return(TitleBlockTemplate::fontForCell(*this).pointSizeF());
98  } else if (attribute == "horizontal_adjust") {
99  return(hadjust);
100  }
101  return(QVariant());
102 }
103 
108 QString TitleBlockCell::attributeName(const QString &attribute) {
109  if (attribute == "type") {
110  return(QObject::tr("type", "title block cell property human name"));
111  } else if (attribute == "name") {
112  return(QObject::tr("nom", "title block cell property human name"));
113  } else if (attribute == "logo") {
114  return(QObject::tr("logo", "title block cell property human name"));
115  } else if (attribute == "label") {
116  return(QObject::tr("label", "title block cell property human name"));
117  } else if (attribute == "displaylabel") {
118  return(QObject::tr("affichage du label", "title block cell property human name"));
119  } else if (attribute == "value") {
120  return(QObject::tr("valeur affichée", "title block cell property human name"));
121  } else if (attribute == "alignment") {
122  return(QObject::tr("alignement du texte", "title block cell property human name"));
123  } else if (attribute == "fontsize") {
124  return(QObject::tr("taille du texte", "title block cell property human name"));
125  } else if (attribute == "horizontal_adjust") {
126  return(QObject::tr("ajustement horizontal", "title block cell property human name"));
127  }
128  return(QString());
129 }
130 
134 bool TitleBlockCell::spans() const {
135  return(row_span || col_span);
136 }
137 
143  value_name = other_cell.value_name;
144  cell_type = other_cell.cell_type;
145  logo_reference = other_cell.logo_reference;
146  value = other_cell.value;
147  label = other_cell.label;
148  display_label = other_cell.display_label;
149  font_size = other_cell.font_size;
150  alignment = other_cell.alignment;
151  hadjust = other_cell.hadjust;
152 }
153 
157 void TitleBlockCell::loadContentFromXml(const QDomElement &cell_element) {
158  // common properties
159  if (cell_element.hasAttribute("name") && !cell_element.attribute("name").isEmpty()) {
160  value_name = cell_element.attribute("name");
161  }
162 
163  // specific properties
164  if (cell_element.tagName() == "logo") {
165  if (cell_element.hasAttribute("resource") && !cell_element.attribute("resource").isEmpty()) {
167  logo_reference = cell_element.attribute("resource");
168  }
169  } else if (cell_element.tagName() == "field") {
171 
172  QHash<QString, QString> names_options;
173  names_options["TagName"] = "translation";
174 
175  names_options["ParentTagName"] = "value";
176  NamesList value_nameslist;
177  value_nameslist.fromXml(cell_element, names_options);
178  if (!value_nameslist.name().isEmpty()) {
179  value = value_nameslist;
180  }
181 
182  names_options["ParentTagName"] = "label";
183  NamesList label_nameslist;
184  label_nameslist.fromXml(cell_element, names_options);
185  if (!label_nameslist.name().isEmpty()) {
186  label = label_nameslist;
187  }
188 
189  if (cell_element.hasAttribute("displaylabel")) {
190  if (cell_element.attribute("displaylabel").compare("false", Qt::CaseInsensitive) == 0) {
191  display_label = false;
192  }
193  }
194  int fontsize;
195  if (QET::attributeIsAnInteger(cell_element, "fontsize", &fontsize)) {
196  font_size = fontsize;
197  } else {
198  font_size = -1;
199  }
200 
201  // horizontal and vertical alignments
202  alignment = 0;
203 
204  QString halignment = cell_element.attribute("align", "left");
205  if (halignment == "right") alignment |= Qt::AlignRight;
206  else if (halignment == "center") alignment |= Qt::AlignHCenter;
207  else alignment |= Qt::AlignLeft;
208 
209  QString valignment = cell_element.attribute("valign", "center");
210  if (valignment == "bottom") alignment |= Qt::AlignBottom;
211  else if (valignment == "top") alignment |= Qt::AlignTop;
212  else alignment |= Qt::AlignVCenter;
213 
214  // horizontal text adjustment
215  hadjust = cell_element.attribute("hadjust", "true") == "true";
216  }
217 }
218 
222 void TitleBlockCell::saveContentToXml(QDomElement &cell_elmt) {
223  cell_elmt.setAttribute("name", value_name);
224 
225  if (type() == TitleBlockCell::EmptyCell) {
226  cell_elmt.setTagName("empty");
227  } else if (type() == TitleBlockCell::LogoCell) {
228  cell_elmt.setTagName("logo");
229  cell_elmt.setAttribute("resource", logo_reference);
230  } else {
231  cell_elmt.setTagName("field");
232 
233  QDomDocument parent_document = cell_elmt.ownerDocument();
234 
235  QHash<QString, QString> names_options;
236  names_options["TagName"] = "translation";
237  names_options["ParentTagName"] = "value";
238  cell_elmt.appendChild(value.toXml(parent_document, names_options));
239  names_options["ParentTagName"] = "label";
240  cell_elmt.appendChild(label.toXml(parent_document, names_options));
241 
242  cell_elmt.setAttribute("displaylabel", display_label ? "true" : "false");
243  if (font_size != -1) {
244  cell_elmt.setAttribute("fontsize", font_size);
245  }
246 
247  if (alignment & Qt::AlignRight) {
248  cell_elmt.setAttribute("align", "right");
249  } else if (alignment & Qt::AlignHCenter) {
250  cell_elmt.setAttribute("align", "center");
251  } else {
252  cell_elmt.setAttribute("align", "left");
253  }
254 
255  if (alignment & Qt::AlignBottom) {
256  cell_elmt.setAttribute("valign", "bottom");
257  } else if (alignment & Qt::AlignTop) {
258  cell_elmt.setAttribute("valign", "top");
259  } else {
260  cell_elmt.setAttribute("valign", "center");
261  }
262 
263  if (hadjust) cell_elmt.setAttribute("hadjust", "true");
264  }
265 }
bool attributeIsAnInteger(const QDomElement &, const QString &, int *=nullptr)
Definition: qet.cpp:200
NamesList value
Text displayed by the cell.
int applied_row_span
Actually applied row span.
virtual ~TitleBlockCell()
bool spans() const
void setAttribute(const QString &, const QVariant &)
void fromXml(const QDomElement &, const QHash< QString, QString > &=QHash< QString, QString >())
Definition: nameslist.cpp:120
int num_col
x coordinate of the cell within its parent title block template grid
int alignment
Where the label+text should be displayed within the visual cell.
QString name(const QString &=QString()) const
Definition: nameslist.cpp:205
QDomElement toXml(QDomDocument &, const QHash< QString, QString > &=QHash< QString, QString >()) const
Definition: nameslist.cpp:143
void loadContentFromCell(const TitleBlockCell &)
int row_span
number of extra rows spanned by this cell
bool display_label
Whether to display the label or not.
the cell span parameters should be applied without restriction
int font_size
Font size the text should be rendered with.
TemplateCellType cell_type
Cell type: empty, text, logo?
QIcon tr
Definition: qeticons.cpp:204
int verticalAlign() const
static QFont fontForCell(const TitleBlockCell &)
NamesList label
Label displayed by the cell.
bool hadjust
Whether to reduce the font size if the text does not fit in the cell.
static QString attributeName(const QString &)
QVariant attribute(const QString &)
TitleBlockCell * spanner_cell
Cell spanning this cell, if any.
QString logo_reference
Logo displayed by this cell, it it is a logo cell.
int horizontalAlign() const
void loadContentFromXml(const QDomElement &)
int span_state
how should row_span and col_span be applied given other cells in the parent template ...
TemplateCellType type() const
void saveContentToXml(QDomElement &)
int col_span
number of extra columns spanned by this cell
QString value_name
name of the cell; not displayed when the title block template is rendered
int num_row
y coordinate of the cell within its parent title block template grid
int applied_col_span
Actually applied column span.