2010-12-19 18:08:08 +00:00
|
|
|
/*
|
2012-01-01 22:51:51 +00:00
|
|
|
Copyright 2006-2012 Xavier Guerrin
|
2010-12-19 18:08:08 +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
|
|
|
#ifndef TITLEBLOCK_TEMPLATE_H
|
|
|
|
#define TITLEBLOCK_TEMPLATE_H
|
2010-12-19 18:08:08 +00:00
|
|
|
#include <QtXml>
|
|
|
|
#include <QtSvg>
|
|
|
|
#include "diagramcontext.h"
|
2010-12-20 02:45:36 +00:00
|
|
|
#include "titleblockcell.h"
|
2011-12-25 17:45:39 +00:00
|
|
|
#include "dimension.h"
|
2010-12-19 18:08:08 +00:00
|
|
|
#include "qet.h"
|
|
|
|
|
|
|
|
/**
|
2011-12-25 17:45:39 +00:00
|
|
|
This class represents an title block template for an electric diagram.
|
2010-12-19 18:08:08 +00:00
|
|
|
It can read from an XML document the layout of the table that graphically
|
2011-12-25 17:45:39 +00:00
|
|
|
represents the title block, and can produce a graphical rendering of it from a
|
2010-12-19 18:08:08 +00:00
|
|
|
diagram context (object embedding the informations of the diagram we want to
|
2011-12-25 17:45:39 +00:00
|
|
|
represent the title block.
|
2010-12-19 18:08:08 +00:00
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
class TitleBlockTemplate : public QObject {
|
2010-12-19 18:08:08 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
2011-12-25 17:45:39 +00:00
|
|
|
// constructors, destructor
|
2010-12-19 18:08:08 +00:00
|
|
|
public:
|
2010-12-20 02:45:36 +00:00
|
|
|
TitleBlockTemplate(QObject * = 0);
|
|
|
|
virtual ~TitleBlockTemplate();
|
2010-12-19 18:08:08 +00:00
|
|
|
private:
|
2010-12-20 02:45:36 +00:00
|
|
|
TitleBlockTemplate(const TitleBlockTemplate &);
|
2010-12-19 18:08:08 +00:00
|
|
|
|
2011-12-25 17:45:39 +00:00
|
|
|
// methods
|
2010-12-19 18:08:08 +00:00
|
|
|
public:
|
2011-12-25 17:45:39 +00:00
|
|
|
TitleBlockCell *createCell(const TitleBlockCell * = 0);
|
|
|
|
static QFont fontForCell(const TitleBlockCell &);
|
2010-12-19 18:08:08 +00:00
|
|
|
bool loadFromXmlFile(const QString &);
|
|
|
|
bool loadFromXmlElement(const QDomElement &);
|
2012-01-12 06:47:02 +00:00
|
|
|
bool saveToXmlFile(const QString &);
|
2011-12-25 17:45:39 +00:00
|
|
|
bool saveToXmlElement(QDomElement &) const;
|
2012-03-11 16:06:22 +00:00
|
|
|
void exportCellToXml(TitleBlockCell *,QDomElement &) const;
|
2011-12-25 17:45:39 +00:00
|
|
|
TitleBlockTemplate *clone() const;
|
2010-12-24 23:35:40 +00:00
|
|
|
QString name() const;
|
2012-03-02 17:55:27 +00:00
|
|
|
QString information() const;
|
|
|
|
void setInformation(const QString &);
|
2011-12-25 17:45:39 +00:00
|
|
|
int rowDimension(int);
|
|
|
|
void setRowDimension(int, const TitleBlockDimension &);
|
|
|
|
TitleBlockDimension columnDimension(int);
|
|
|
|
void setColumnDimension(int, const TitleBlockDimension &);
|
|
|
|
int columnsCount() const;
|
|
|
|
int rowsCount() const;
|
2010-12-19 18:08:08 +00:00
|
|
|
QList<int> columnsWidth(int) const;
|
2011-12-25 17:45:39 +00:00
|
|
|
QList<int> rowsHeights() const;
|
2012-02-28 18:54:34 +00:00
|
|
|
int columnTypeCount(QET::TitleBlockColumnLength);
|
|
|
|
int columnTypeTotal(QET::TitleBlockColumnLength);
|
|
|
|
int minimumWidth();
|
|
|
|
int maximumWidth();
|
2011-12-30 02:05:46 +00:00
|
|
|
int width(int);
|
2010-12-19 18:08:08 +00:00
|
|
|
int height() const;
|
|
|
|
|
2011-12-25 17:45:39 +00:00
|
|
|
bool moveRow(int, int);
|
|
|
|
void addRow(int = -1);
|
|
|
|
bool insertRow(int, const QList<TitleBlockCell *> &, int = -1);
|
|
|
|
QList<TitleBlockCell *> takeRow(int);
|
|
|
|
QList<TitleBlockCell *> createRow();
|
|
|
|
|
|
|
|
bool moveColumn(int, int);
|
|
|
|
void addColumn(int = -1);
|
|
|
|
bool insertColumn(const TitleBlockDimension &, const QList<TitleBlockCell *> &, int = -1);
|
|
|
|
QList<TitleBlockCell *> takeColumn(int);
|
|
|
|
QList<TitleBlockCell *> createColumn();
|
|
|
|
|
|
|
|
TitleBlockCell *cell(int, int) const;
|
2012-04-08 20:51:40 +00:00
|
|
|
QSet<TitleBlockCell *> spannedCells(const TitleBlockCell *, bool = false) const;
|
2012-03-25 16:34:53 +00:00
|
|
|
QHash<TitleBlockCell *, QPair<int, int> > getAllSpans() const;
|
|
|
|
void setAllSpans(const QHash<TitleBlockCell *, QPair<int, int> > &);
|
2011-12-25 17:45:39 +00:00
|
|
|
bool addLogo(const QString &, QByteArray *, const QString & = "svg", const QString & = "xml");
|
|
|
|
bool addLogoFromFile(const QString &, const QString & = QString());
|
2012-05-11 17:47:38 +00:00
|
|
|
bool saveLogoToFile(const QString &, const QString &);
|
2011-12-25 17:45:39 +00:00
|
|
|
bool removeLogo(const QString &);
|
|
|
|
bool renameLogo(const QString &, const QString &);
|
|
|
|
void setLogoStorage(const QString &, const QString &);
|
|
|
|
QList<QString> logos() const;
|
|
|
|
QString logoType(const QString &) const;
|
|
|
|
QSvgRenderer *vectorLogo(const QString &) const;
|
|
|
|
QPixmap bitmapLogo(const QString &) const;
|
|
|
|
|
2010-12-19 18:08:08 +00:00
|
|
|
void render(QPainter &, const DiagramContext &, int) const;
|
2011-12-25 17:45:39 +00:00
|
|
|
void renderCell(QPainter &, const TitleBlockCell &, const DiagramContext &, const QRect &) const;
|
2010-12-19 18:08:08 +00:00
|
|
|
QString toString() const;
|
2012-03-25 16:34:53 +00:00
|
|
|
void applyCellSpans();
|
|
|
|
void forgetSpanning();
|
|
|
|
void forgetSpanning(TitleBlockCell *, bool = true);
|
|
|
|
bool checkCellSpan(TitleBlockCell *);
|
|
|
|
void applyCellSpan(TitleBlockCell *);
|
|
|
|
void applyRowColNums();
|
|
|
|
void rowColsChanged();
|
2013-04-15 20:44:19 +00:00
|
|
|
QStringList listOfVariables();
|
2010-12-19 18:08:08 +00:00
|
|
|
|
|
|
|
protected:
|
2012-03-02 17:55:27 +00:00
|
|
|
void loadInformation(const QDomElement &);
|
2010-12-19 18:08:08 +00:00
|
|
|
bool loadLogos(const QDomElement &, bool = false);
|
|
|
|
bool loadLogo(const QDomElement &);
|
|
|
|
bool loadGrid(const QDomElement &);
|
|
|
|
bool loadCells(const QDomElement &);
|
2011-12-25 17:45:39 +00:00
|
|
|
void loadCell(const QDomElement &);
|
2012-03-02 17:55:27 +00:00
|
|
|
void saveInformation(QDomElement &) const;
|
2011-12-25 17:45:39 +00:00
|
|
|
void saveLogos(QDomElement &) const;
|
|
|
|
void saveLogo(const QString &, QDomElement &) const;
|
|
|
|
void saveGrid(QDomElement &) const;
|
|
|
|
void saveCells(QDomElement &) const;
|
2012-03-11 16:06:22 +00:00
|
|
|
void saveCell(TitleBlockCell *, QDomElement &, bool = false) const;
|
2011-12-25 17:45:39 +00:00
|
|
|
QList<TitleBlockCell *> createCellsList(int);
|
2010-12-19 18:08:08 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void parseRows(const QString &);
|
|
|
|
void parseColumns(const QString &);
|
2010-12-20 02:45:36 +00:00
|
|
|
bool checkCell(const QDomElement &, TitleBlockCell ** = 0);
|
2010-12-19 18:08:08 +00:00
|
|
|
void flushCells();
|
|
|
|
void initCells();
|
|
|
|
int lengthRange(int, int, const QList<int> &) const;
|
2010-12-20 02:45:36 +00:00
|
|
|
QString finalTextForCell(const TitleBlockCell &, const DiagramContext &) const;
|
2012-05-09 21:17:09 +00:00
|
|
|
QString interpreteVariables(const QString &, const DiagramContext &) const;
|
2011-02-08 06:53:47 +00:00
|
|
|
void renderTextCell(QPainter &, const QString &, const TitleBlockCell &, const QRectF &) const;
|
2010-12-19 18:08:08 +00:00
|
|
|
|
2011-12-25 17:45:39 +00:00
|
|
|
// attributes
|
2010-12-19 18:08:08 +00:00
|
|
|
private:
|
2012-03-02 17:55:27 +00:00
|
|
|
QString name_; ///< name identifying the Title Block Template within its parent collection
|
|
|
|
QString information_;
|
2011-12-25 17:45:39 +00:00
|
|
|
|
|
|
|
QHash<QString, QByteArray > data_logos_; ///< Logos raw data
|
|
|
|
QHash<QString, QString> storage_logos_; ///< Logos applied storage type (e.g. "xml" or "base64")
|
|
|
|
QHash<QString, QString> type_logos_; ///< Logos types (e.g. "png", "jpeg", "svg")
|
|
|
|
QHash<QString, QSvgRenderer *> vector_logos_; ///< Rendered objects for vector logos
|
|
|
|
QHash<QString, QPixmap> bitmap_logos_; ///< Pixmaps for bitmap logos
|
|
|
|
|
|
|
|
QList<int> rows_heights_; ///< rows heights -- simple integers
|
2012-03-02 17:55:27 +00:00
|
|
|
QList<TitleBlockDimension> columns_width_; ///< columns widths -- @see TitleBlockColDimension
|
2011-12-25 17:45:39 +00:00
|
|
|
QList<TitleBlockCell *> registered_cells_; ///< Cells objects created rattached to this template, but not mandatorily used
|
|
|
|
QList< QList<TitleBlockCell *> > cells_; ///< Cells grid
|
2010-12-19 18:08:08 +00:00
|
|
|
};
|
|
|
|
#endif
|