QElectroTech  0.70
titleblocktemplate.h
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 #ifndef TITLEBLOCK_TEMPLATE_H
19 #define TITLEBLOCK_TEMPLATE_H
20 #include <QtXml>
21 #include <QtSvg>
22 #include "diagramcontext.h"
23 #include "titleblockcell.h"
24 #include "dimension.h"
25 #include "qet.h"
26 
34 class TitleBlockTemplate : public QObject {
35  Q_OBJECT
36 
37  // constructors, destructor
38  public:
39  TitleBlockTemplate(QObject * = nullptr);
40  ~TitleBlockTemplate() override;
41  private:
43 
44  // methods
45  public:
46  TitleBlockCell *createCell(const TitleBlockCell * = nullptr);
47  static QFont fontForCell(const TitleBlockCell &);
48  bool loadFromXmlFile(const QString &);
49  bool loadFromXmlElement(const QDomElement &);
50  bool saveToXmlFile(const QString &);
51  bool saveToXmlElement(QDomElement &) const;
52  void exportCellToXml(TitleBlockCell *,QDomElement &) const;
53  TitleBlockTemplate *clone() const;
54  QString name() const;
55  QString information() const;
56  void setInformation(const QString &);
57  int rowDimension(int);
58  void setRowDimension(int, const TitleBlockDimension &);
60  void setColumnDimension(int, const TitleBlockDimension &);
61  int columnsCount() const;
62  int rowsCount() const;
63  QList<int> columnsWidth(int) const;
64  QList<int> rowsHeights() const;
67  int minimumWidth();
68  int maximumWidth();
69  int width(int);
70  int height() const;
71 
72  bool moveRow(int, int);
73  void addRow(int = -1);
74  bool insertRow(int, const QList<TitleBlockCell *> &, int = -1);
75  QList<TitleBlockCell *> takeRow(int);
76  QList<TitleBlockCell *> createRow();
77 
78  bool moveColumn(int, int);
79  void addColumn(int = -1);
80  bool insertColumn(const TitleBlockDimension &, const QList<TitleBlockCell *> &, int = -1);
81  QList<TitleBlockCell *> takeColumn(int);
82  QList<TitleBlockCell *> createColumn();
83 
84  TitleBlockCell *cell(int, int) const;
85  QSet<TitleBlockCell *> spannedCells(const TitleBlockCell *, bool = false) const;
86  QHash<TitleBlockCell *, QPair<int, int> > getAllSpans() const;
87  void setAllSpans(const QHash<TitleBlockCell *, QPair<int, int> > &);
88  bool addLogo(const QString &, QByteArray *, const QString & = "svg", const QString & = "xml");
89  bool addLogoFromFile(const QString &, const QString & = QString());
90  bool saveLogoToFile(const QString &, const QString &);
91  bool removeLogo(const QString &);
92  bool renameLogo(const QString &, const QString &);
93  void setLogoStorage(const QString &, const QString &);
94  QList<QString> logos() const;
95  QString logoType(const QString &) const;
96  QSvgRenderer *vectorLogo(const QString &) const;
97  QPixmap bitmapLogo(const QString &) const;
98 
99  void render(QPainter &, const DiagramContext &, int) const;
100  void renderDxf(QRectF &, const DiagramContext &, int, QString &, int) const;
101  void renderCell(QPainter &, const TitleBlockCell &, const DiagramContext &, const QRect &) const;
102  void applyCellSpans();
103  void forgetSpanning();
104  void forgetSpanning(TitleBlockCell *, bool = true);
107  void applyRowColNums();
108  void rowColsChanged();
109  QStringList listOfVariables();
110 
111  protected:
112  void loadInformation(const QDomElement &);
113  bool loadLogos(const QDomElement &, bool = false);
114  bool loadLogo(const QDomElement &);
115  bool loadGrid(const QDomElement &);
116  bool loadCells(const QDomElement &);
117  void loadCell(const QDomElement &);
118  void saveInformation(QDomElement &) const;
119  void saveLogos(QDomElement &) const;
120  void saveLogo(const QString &, QDomElement &) const;
121  void saveGrid(QDomElement &) const;
122  void saveCells(QDomElement &) const;
123  void saveCell(TitleBlockCell *, QDomElement &, bool = false) const;
124  QList<TitleBlockCell *> createCellsList(int);
125 
126  private:
127  void parseRows(const QString &);
128  void parseColumns(const QString &);
129  bool checkCell(const QDomElement &, TitleBlockCell ** = nullptr);
130  void flushCells();
131  void initCells();
132  int lengthRange(int, int, const QList<int> &) const;
133  QString finalTextForCell(const TitleBlockCell &, const DiagramContext &) const;
134  QString interpreteVariables(const QString &, const DiagramContext &) const;
135  void renderTextCell(QPainter &, const QString &, const TitleBlockCell &, const QRectF &) const;
136  void renderTextCellDxf(QString &, const QString &, const TitleBlockCell &, qreal, qreal, qreal, qreal, int) const;
137 
138  // attributes
139  private:
140  QString name_;
141  QString information_;
142 
143  QHash<QString, QByteArray > data_logos_;
144  QHash<QString, QString> storage_logos_;
145  QHash<QString, QString> type_logos_;
146  QHash<QString, QSvgRenderer *> vector_logos_;
147  QHash<QString, QPixmap> bitmap_logos_;
148 
149  QList<int> rows_heights_;
150  QList<TitleBlockDimension> columns_width_;
151  QList<TitleBlockCell *> registered_cells_;
152  QList< QList<TitleBlockCell *> > cells_;
153 };
154 #endif
bool loadFromXmlFile(const QString &)
QHash< QString, QByteArray > data_logos_
Logos raw data.
bool loadGrid(const QDomElement &)
QList< TitleBlockCell * > createColumn()
bool addLogoFromFile(const QString &, const QString &=QString())
void parseColumns(const QString &)
QHash< QString, QPixmap > bitmap_logos_
Pixmaps for bitmap logos.
bool saveLogoToFile(const QString &, const QString &)
QList< int > rows_heights_
rows heights – simple integers
QList< TitleBlockCell * > registered_cells_
Cells objects created rattached to this template, but not mandatorily used.
int lengthRange(int, int, const QList< int > &) const
QString name_
name identifying the Title Block Template within its parent collection
int columnTypeCount(QET::TitleBlockColumnLength)
void saveGrid(QDomElement &) const
void saveCells(QDomElement &) const
QList< TitleBlockCell * > createRow()
void applyCellSpan(TitleBlockCell *)
TitleBlockTemplate * clone() const
void setColumnDimension(int, const TitleBlockDimension &)
void renderCell(QPainter &, const TitleBlockCell &, const DiagramContext &, const QRect &) const
QHash< QString, QSvgRenderer * > vector_logos_
Rendered objects for vector logos.
bool loadFromXmlElement(const QDomElement &)
QList< int > columnsWidth(int) const
void setAllSpans(const QHash< TitleBlockCell *, QPair< int, int > > &)
QStringList listOfVariables()
Get list of variables.
QList< TitleBlockDimension > columns_width_
columns widths –
TitleBlockColumnLength
enum used to specify the type of a length
Definition: qet.h:143
void saveLogos(QDomElement &) const
QString interpreteVariables(const QString &, const DiagramContext &) const
QPixmap bitmapLogo(const QString &) const
bool addLogo(const QString &, QByteArray *, const QString &="svg", const QString &="xml")
void setLogoStorage(const QString &, const QString &)
void exportCellToXml(TitleBlockCell *, QDomElement &) const
void parseRows(const QString &)
void saveLogo(const QString &, QDomElement &) const
TitleBlockDimension columnDimension(int)
void render(QPainter &, const DiagramContext &, int) const
bool loadLogos(const QDomElement &, bool=false)
QList< TitleBlockCell * > createCellsList(int)
QList< int > rowsHeights() const
bool checkCell(const QDomElement &, TitleBlockCell **=nullptr)
bool checkCellSpan(TitleBlockCell *)
bool removeLogo(const QString &)
void saveCell(TitleBlockCell *, QDomElement &, bool=false) const
void renderTextCell(QPainter &, const QString &, const TitleBlockCell &, const QRectF &) const
QHash< TitleBlockCell *, QPair< int, int > > getAllSpans() const
void setRowDimension(int, const TitleBlockDimension &)
TitleBlockTemplate(QObject *=nullptr)
QList< TitleBlockCell * > takeRow(int)
QString logoType(const QString &) const
void renderTextCellDxf(QString &, const QString &, const TitleBlockCell &, qreal, qreal, qreal, qreal, int) const
bool loadLogo(const QDomElement &)
static QFont fontForCell(const TitleBlockCell &)
int columnTypeTotal(QET::TitleBlockColumnLength)
void loadInformation(const QDomElement &)
TitleBlockCell * cell(int, int) const
QList< QString > logos() const
QHash< QString, QString > storage_logos_
Logos applied storage type (e.g. "xml" or "base64")
bool saveToXmlFile(const QString &)
bool renameLogo(const QString &, const QString &)
void loadCell(const QDomElement &)
void renderDxf(QRectF &, const DiagramContext &, int, QString &, int) const
TitleBlockCell * createCell(const TitleBlockCell *=nullptr)
void setInformation(const QString &)
bool insertRow(int, const QList< TitleBlockCell *> &, int=-1)
bool saveToXmlElement(QDomElement &) const
void saveInformation(QDomElement &) const
QSet< TitleBlockCell * > spannedCells(const TitleBlockCell *, bool=false) const
QString finalTextForCell(const TitleBlockCell &, const DiagramContext &) const
bool loadCells(const QDomElement &)
QSvgRenderer * vectorLogo(const QString &) const
QHash< QString, QString > type_logos_
Logos types (e.g. "png", "jpeg", "svg")
QList< QList< TitleBlockCell * > > cells_
Cells grid.
bool insertColumn(const TitleBlockDimension &, const QList< TitleBlockCell *> &, int=-1)
QList< TitleBlockCell * > takeColumn(int)
QString information() const