QElectroTech 0.100.0-dev
Loading...
Searching...
No Matches
titleblocktemplate.h
Go to the documentation of this file.
1/*
2 Copyright 2006-2024 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#ifndef TITLEBLOCK_TEMPLATE_H
19#define TITLEBLOCK_TEMPLATE_H
20#include "diagramcontext.h"
21#include "qet.h"
23#include "titleblockcell.h"
24
25#include <QtSvg>
26#include <QtXml>
27
37class TitleBlockTemplate : public QObject {
38 Q_OBJECT
39
40 // constructors, destructor
41 public:
42 TitleBlockTemplate(QObject * = nullptr);
43 ~TitleBlockTemplate() override;
44 private:
46
47 // methods
48 public:
49 TitleBlockCell *createCell(const TitleBlockCell * = nullptr);
50 static QFont fontForCell(const TitleBlockCell &);
51 bool loadFromXmlFile(const QString &);
52 bool loadFromXmlElement(const QDomElement &);
53 bool saveToXmlFile(const QString &);
54 bool saveToXmlElement(QDomElement &) const;
55 void exportCellToXml(TitleBlockCell *,QDomElement &) const;
57 QString name() const;
58 QString information() const;
59 void setInformation(const QString &);
60 int rowDimension(int);
61 void setRowDimension(int, const TitleBlockDimension &);
63 void setColumnDimension(int, const TitleBlockDimension &);
64 int columnsCount() const;
65 int rowsCount() const;
66 QList<int> columnsWidth(int) const;
67 QList<int> rowsHeights() const;
70 int minimumWidth();
71 int maximumWidth();
72 int width(int);
73 int height() const;
74
75 bool moveRow(int, int);
76 void addRow(int = -1);
77 bool insertRow(int, const QList<TitleBlockCell *> &, int = -1);
78 QList<TitleBlockCell *> takeRow(int);
79 QList<TitleBlockCell *> createRow();
80
81 bool moveColumn(int, int);
82 void addColumn(int = -1);
84 const QList<TitleBlockCell *> &, int = -1);
85 QList<TitleBlockCell *> takeColumn(int);
86 QList<TitleBlockCell *> createColumn();
87
88 TitleBlockCell *cell(int, int) const;
89 QSet<TitleBlockCell *> spannedCells(
90 const TitleBlockCell *, bool = false) const;
91 QHash<TitleBlockCell *, QPair<int, int> > getAllSpans() const;
92 void setAllSpans(const QHash<TitleBlockCell *, QPair<int, int> > &);
93 bool addLogo(
94 const QString &,
95 QByteArray *,
96 const QString & = "svg",
97 const QString & = "xml");
98 bool addLogoFromFile(const QString &, const QString & = QString());
99 bool saveLogoToFile(const QString &, const QString &);
100 bool removeLogo(const QString &);
101 bool renameLogo(const QString &, const QString &);
102 void setLogoStorage(const QString &, const QString &);
103 QList<QString> logos() const;
104 QString logoType(const QString &) const;
105 QSvgRenderer *vectorLogo(const QString &) const;
106 QPixmap bitmapLogo(const QString &) const;
107
108 void render(QPainter &, const DiagramContext &, int) const;
109 void renderDxf(
110 QRectF &,
111 const DiagramContext &,
112 int,
113 QString &,
114 int) const;
115 void renderCell(QPainter &,
116 const TitleBlockCell &,
117 const DiagramContext &,
118 const QRect &) const;
119 void applyCellSpans();
120 void forgetSpanning();
121 void forgetSpanning(TitleBlockCell *, bool = true);
124 void applyRowColNums();
125 void rowColsChanged();
126 QStringList listOfVariables();
127
128 protected:
129 void loadInformation(const QDomElement &);
130 bool loadLogos(const QDomElement &, bool = false);
131 bool loadLogo(const QDomElement &);
132 bool loadGrid(const QDomElement &);
133 bool loadCells(const QDomElement &);
134 void loadCell(const QDomElement &);
135 void saveInformation(QDomElement &) const;
136 void saveLogos(QDomElement &) const;
137 void saveLogo(const QString &, QDomElement &) const;
138 void saveGrid(QDomElement &) const;
139 void saveCells(QDomElement &) const;
140 void saveCell(TitleBlockCell *, QDomElement &, bool = false) const;
141 QList<TitleBlockCell *> createCellsList(int);
142
143 private:
144 void parseRows(const QString &);
145 void parseColumns(const QString &);
146 bool checkCell(const QDomElement &, TitleBlockCell ** = nullptr);
148 void initCells();
149 int lengthRange(int, int, const QList<int> &) const;
150 QString finalTextForCell(
151 const TitleBlockCell &,
152 const DiagramContext &) const;
153 QString interpreteVariables(
154 const QString &,
155 const DiagramContext &) const;
156 void renderTextCell(
157 QPainter &,
158 const QString &,
159 const TitleBlockCell &,
160 const QRectF &) const;
162 QString &,
163 const QString &,
164 const TitleBlockCell &,
165 qreal,
166 qreal,
167 qreal,
168 qreal,
169 int) const;
170
171 // attributes
172 private:
177 QString name_;
182 QHash<QString, QByteArray > data_logos_;
187 QHash<QString, QString> storage_logos_;
192 QHash<QString, QString> type_logos_;
196 QHash<QString, QSvgRenderer *> vector_logos_;
200 QHash<QString, QPixmap> bitmap_logos_;
201
202 QList<int> rows_heights_;
207 QList<TitleBlockDimension> columns_width_;
212 QList<TitleBlockCell *> registered_cells_;
213 QList< QList<TitleBlockCell *> > cells_;
214};
215#endif
Definition diagramcontext.h:57
Definition titleblockcell.h:26
The TitleBlockTemplate class This class represents an title block template for an electric diagram....
Definition titleblocktemplate.h:37
QString logoType(const QString &) const
TitleBlockTemplate::logoType.
Definition titleblocktemplate.cpp:1460
void exportCellToXml(TitleBlockCell *, QDomElement &) const
TitleBlockTemplate::exportCellToXml.
Definition titleblocktemplate.cpp:184
void applyRowColNums()
TitleBlockTemplate::applyRowColNums Ensure all cells have the right col+row numbers.
Definition titleblocktemplate.cpp:2088
int maximumWidth()
TitleBlockTemplate::maximumWidth.
Definition titleblocktemplate.cpp:989
QHash< QString, QString > storage_logos_
storage_logos_ : Logos applied storage type (e.g. "xml" or "base64")
Definition titleblocktemplate.h:187
int height() const
TitleBlockTemplate::height.
Definition titleblocktemplate.cpp:1016
QList< TitleBlockCell * > createRow()
TitleBlockTemplate::createRow.
Definition titleblocktemplate.cpp:1098
void applyCellSpan(TitleBlockCell *)
TitleBlockTemplate::applyCellSpan Ensure the spans of the provided cell are applied within the grid s...
Definition titleblocktemplate.cpp:2054
void saveGrid(QDomElement &) const
TitleBlockTemplate::saveGrid Export this template's cells grid as XML.
Definition titleblocktemplate.cpp:588
bool checkCell(const QDomElement &, TitleBlockCell **=nullptr)
TitleBlockTemplate::checkCell Load the essential attributes of a cell: row and column indices and spa...
Definition titleblocktemplate.cpp:672
QList< TitleBlockDimension > columns_width_
columns_width_ : columns widths –
Definition titleblocktemplate.h:207
bool loadFromXmlFile(const QString &)
TitleBlockTemplate::loadFromXmlFile Load a titleblock template from an XML file.
Definition titleblocktemplate.cpp:94
bool saveToXmlElement(QDomElement &) const
TitleBlockTemplate::saveToXmlElement Save the title block template as XML.
Definition titleblocktemplate.cpp:165
void forgetSpanning()
TitleBlockTemplate::forgetSpanning Set the spanner_cell attribute of every cell to 0.
Definition titleblocktemplate.cpp:1937
bool moveRow(int, int)
TitleBlockTemplate::moveRow Move a row within this template.
Definition titleblocktemplate.cpp:1032
void renderTextCell(QPainter &, const QString &, const TitleBlockCell &, const QRectF &) const
TitleBlockTemplate::renderTextCell This method uses a painter to render the text of a cell into the c...
Definition titleblocktemplate.cpp:1792
void applyCellSpans()
TitleBlockTemplate::applyCellSpans Forget any previously applied span, then apply again all spans def...
Definition titleblocktemplate.cpp:1975
bool renameLogo(const QString &, const QString &)
TitleBlockTemplate::renameLogo Rename the logo_name logo to new_name.
Definition titleblocktemplate.cpp:1408
QList< int > rows_heights_
rows heights – simple integers
Definition titleblocktemplate.h:202
bool addLogo(const QString &, QByteArray *, const QString &="svg", const QString &="xml")
TitleBlockTemplate::addLogo.
Definition titleblocktemplate.cpp:1278
TitleBlockCell * cell(int, int) const
TitleBlockTemplate::cell.
Definition titleblocktemplate.cpp:1179
void renderTextCellDxf(QString &, const QString &, const TitleBlockCell &, qreal, qreal, qreal, qreal, int) const
TitleBlockTemplate::renderTextCellDxf.
Definition titleblocktemplate.cpp:1847
QString name_
name_ : name identifying the Title Block Template within its parent collection
Definition titleblocktemplate.h:177
bool moveColumn(int, int)
TitleBlockTemplate::moveColumn Move the column at index "from" to index "to".
Definition titleblocktemplate.cpp:1110
bool loadLogos(const QDomElement &, bool=false)
TitleBlockTemplate::loadLogos Import the logos from a given XML titleblock template.
Definition titleblocktemplate.cpp:280
QList< TitleBlockCell * > registered_cells_
registered_cells_ : Cells objects created rattached to this template, but not mandatorily used
Definition titleblocktemplate.h:212
int minimumWidth()
Definition titleblocktemplate.cpp:963
void initCells()
TitleBlockTemplate::initCells Initialize the internal cells grid with the row and column counts....
Definition titleblocktemplate.cpp:733
QHash< TitleBlockCell *, QPair< int, int > > getAllSpans() const
TitleBlockTemplate::getAllSpans Export the span parameters of all cell in the current grid.
Definition titleblocktemplate.cpp:1237
void setAllSpans(const QHash< TitleBlockCell *, QPair< int, int > > &)
TitleBlockTemplate::setAllSpans Restore a set of span parameters.
Definition titleblocktemplate.cpp:1260
QHash< QString, QByteArray > data_logos_
data_logos_ : Logos raw data
Definition titleblocktemplate.h:182
QString finalTextForCell(const TitleBlockCell &, const DiagramContext &) const
TitleBlockTemplate::finalTextForCell.
Definition titleblocktemplate.cpp:1709
QList< int > rowsHeights() const
TitleBlockTemplate::rowsHeights.
Definition titleblocktemplate.cpp:923
QStringList listOfVariables()
TitleBlockTemplate::listOfVariables Get list of variables.
Definition titleblocktemplate.cpp:1756
bool checkCellSpan(TitleBlockCell *)
TitleBlockTemplate::checkCellSpan Check whether a given cell can be spanned according to its row_span...
Definition titleblocktemplate.cpp:1998
void loadInformation(const QDomElement &)
TitleBlockTemplate::loadInformation Import text informations from a given XML title block template.
Definition titleblocktemplate.cpp:262
void parseColumns(const QString &)
TitleBlockTemplate::parseColumns Parse the columns widths.
Definition titleblocktemplate.cpp:428
void parseRows(const QString &)
TitleBlockTemplate::parseRows Parse the rows heights.
Definition titleblocktemplate.cpp:389
bool loadGrid(const QDomElement &)
Definition titleblocktemplate.cpp:357
void loadCell(const QDomElement &)
TitleBlockTemplate::loadCell Load a cell into this template.
Definition titleblocktemplate.cpp:509
QHash< QString, QSvgRenderer * > vector_logos_
vector_logos_ : Rendered objects for vector logos
Definition titleblocktemplate.h:196
bool insertColumn(const TitleBlockDimension &, const QList< TitleBlockCell * > &, int=-1)
TitleBlockTemplate::insertColumn.
Definition titleblocktemplate.cpp:1137
static QFont fontForCell(const TitleBlockCell &)
TitleBlockTemplate::fontForCell.
Definition titleblocktemplate.cpp:84
TitleBlockTemplate(const TitleBlockTemplate &)
int rowDimension(int)
TitleBlockTemplate::rowDimension.
Definition titleblocktemplate.cpp:779
int width(int)
TitleBlockTemplate::width.
Definition titleblocktemplate.cpp:1004
QString name() const
TitleBlockTemplate::name.
Definition titleblocktemplate.cpp:752
void render(QPainter &, const DiagramContext &, int) const
TitleBlockTemplate::render Render the titleblock.
Definition titleblocktemplate.cpp:1508
void rowColsChanged()
TitleBlockTemplate::rowColsChanged Take care of consistency and span-related problematics when adding...
Definition titleblocktemplate.cpp:2103
void saveCell(TitleBlockCell *, QDomElement &, bool=false) const
TitleBlockTemplate::saveCell Export a specific cell as XML.
Definition titleblocktemplate.cpp:634
~TitleBlockTemplate() override
TitleBlockTemplate::~TitleBlockTemplate Destructor.
Definition titleblocktemplate.cpp:43
QString interpreteVariables(const QString &, const DiagramContext &) const
TitleBlockTemplate::interpreteVariables.
Definition titleblocktemplate.cpp:1736
int columnTypeTotal(QET::TitleBlockColumnLength)
TitleBlockTemplate::columnTypeTotal.
Definition titleblocktemplate.cpp:948
QString information_
Definition titleblocktemplate.h:178
void setColumnDimension(int, const TitleBlockDimension &)
TitleBlockTemplate::setColumnDimension Set the width of a column.
Definition titleblocktemplate.cpp:820
TitleBlockCell * createCell(const TitleBlockCell *=nullptr)
TitleBlockTemplate::createCell Create a new cell and associate it with this template,...
Definition titleblocktemplate.cpp:56
int rowsCount() const
TitleBlockTemplate::rowsCount.
Definition titleblocktemplate.cpp:842
void saveInformation(QDomElement &) const
TitleBlockTemplate::saveInformation Export this template's extra information.
Definition titleblocktemplate.cpp:521
QList< TitleBlockCell * > createCellsList(int)
TitleBlockTemplate::createCellsList.
Definition titleblocktemplate.cpp:72
QSet< TitleBlockCell * > spannedCells(const TitleBlockCell *, bool=false) const
TitleBlockTemplate::spannedCells.
Definition titleblocktemplate.cpp:1198
int columnsCount() const
TitleBlockTemplate::columnsCount.
Definition titleblocktemplate.cpp:833
void setRowDimension(int, const TitleBlockDimension &)
TitleBlockTemplate::setRowDimension Set the height of a row.
Definition titleblocktemplate.cpp:793
TitleBlockTemplate * clone() const
TitleBlockTemplate::clone.
Definition titleblocktemplate.cpp:196
QList< int > columnsWidth(int) const
TitleBlockTemplate::columnsWidth.
Definition titleblocktemplate.cpp:852
QList< QString > logos() const
TitleBlockTemplate::logos.
Definition titleblocktemplate.cpp:1448
bool removeLogo(const QString &)
TitleBlockTemplate::removeLogo.
Definition titleblocktemplate.cpp:1382
void setLogoStorage(const QString &, const QString &)
TitleBlockTemplate::setLogoStorage Set the kind of storage for the logo_name logo.
Definition titleblocktemplate.cpp:1437
QHash< QString, QPixmap > bitmap_logos_
bitmap_logos_ : Pixmaps for bitmap logos
Definition titleblocktemplate.h:200
void saveLogo(const QString &, QDomElement &) const
TitleBlockTemplate::saveLogo Export a specific logo as XML.
Definition titleblocktemplate.cpp:557
int columnTypeCount(QET::TitleBlockColumnLength)
TitleBlockTemplate::columnTypeCount.
Definition titleblocktemplate.cpp:933
TitleBlockDimension columnDimension(int)
TitleBlockTemplate::columnDimension.
Definition titleblocktemplate.cpp:806
QHash< QString, QString > type_logos_
type_logos_ : Logos types (e.g. "png", "jpeg", "svg")
Definition titleblocktemplate.h:192
QSvgRenderer * vectorLogo(const QString &) const
TitleBlockTemplate::vectorLogo.
Definition titleblocktemplate.cpp:1475
QList< QList< TitleBlockCell * > > cells_
Cells grid.
Definition titleblocktemplate.h:213
QString information() const
TitleBlockTemplate::information.
Definition titleblocktemplate.cpp:761
void renderDxf(QRectF &, const DiagramContext &, int, QString &, int) const
TitleBlockTemplate::renderDxf Render the titleblock in DXF.
Definition titleblocktemplate.cpp:1570
bool loadLogo(const QDomElement &)
TitleBlockTemplate::loadLogo Import the logo from a given XML logo description.
Definition titleblocktemplate.cpp:319
bool loadCells(const QDomElement &)
TitleBlockTemplate::loadCells Analyze an XML element, looking for grid cells. The grid cells are chec...
Definition titleblocktemplate.cpp:487
void addRow(int=-1)
TitleBlockTemplate::addRow Add a new 25px-wide row at the provided index.
Definition titleblocktemplate.cpp:1049
void saveLogos(QDomElement &) const
TitleBlockTemplate::saveLogos Export this template's logos as XML.
Definition titleblocktemplate.cpp:538
QPixmap bitmapLogo(const QString &) const
TitleBlockTemplate::bitmapLogo.
Definition titleblocktemplate.cpp:1490
void addColumn(int=-1)
TitleBlockTemplate::addColumn Add a new 50px-wide column at the provided index.
Definition titleblocktemplate.cpp:1125
QList< TitleBlockCell * > takeColumn(int)
TitleBlockTemplate::takeColumn Removes the column at index i.
Definition titleblocktemplate.cpp:1153
bool loadFromXmlElement(const QDomElement &)
TitleBlockTemplate::loadFromXmlElement.
Definition titleblocktemplate.cpp:121
int lengthRange(int, int, const QList< int > &) const
TitleBlockTemplate::lengthRange.
Definition titleblocktemplate.cpp:2118
QList< TitleBlockCell * > createColumn()
TitleBlockTemplate::createColumn.
Definition titleblocktemplate.cpp:1168
bool saveToXmlFile(const QString &)
TitleBlockTemplate::saveToXmlFile Save the title block template into an XML file.
Definition titleblocktemplate.cpp:145
void saveCells(QDomElement &) const
TitleBlockTemplate::saveCells Export this template's cells as XML (without the grid-related informati...
Definition titleblocktemplate.cpp:613
void renderCell(QPainter &, const TitleBlockCell &, const DiagramContext &, const QRect &) const
TitleBlockTemplate::renderCell Render a titleblock cell.
Definition titleblocktemplate.cpp:1657
QList< TitleBlockCell * > takeRow(int)
TitleBlockTemplate::takeRow Removes the row at index i.
Definition titleblocktemplate.cpp:1082
bool saveLogoToFile(const QString &, const QString &)
TitleBlockTemplate::saveLogoToFile.
Definition titleblocktemplate.cpp:1361
bool insertRow(int, const QList< TitleBlockCell * > &, int=-1)
TitleBlockTemplate::insertRow.
Definition titleblocktemplate.cpp:1063
void setInformation(const QString &)
TitleBlockTemplate::setInformation.
Definition titleblocktemplate.cpp:770
bool addLogoFromFile(const QString &, const QString &=QString())
TitleBlockTemplate::addLogoFromFile.
Definition titleblocktemplate.cpp:1332
TitleBlockColumnLength
enum used to specify the type of a length
Definition qet.h:141
Definition dimension.h:26