/*
Copyright 2006-2012 Xavier Guerrin
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 .
*/
#ifndef TITLEBLOCK_TEMPLATE_H
#define TITLEBLOCK_TEMPLATE_H
#include
#include
#include "diagramcontext.h"
#include "titleblockcell.h"
#include "dimension.h"
#include "qet.h"
/**
This class represents an title block template for an electric diagram.
It can read from an XML document the layout of the table that graphically
represents the title block, and can produce a graphical rendering of it from a
diagram context (object embedding the informations of the diagram we want to
represent the title block.
*/
class TitleBlockTemplate : public QObject {
Q_OBJECT
// constructors, destructor
public:
TitleBlockTemplate(QObject * = 0);
virtual ~TitleBlockTemplate();
private:
TitleBlockTemplate(const TitleBlockTemplate &);
// methods
public:
TitleBlockCell *createCell(const TitleBlockCell * = 0);
static QFont fontForCell(const TitleBlockCell &);
bool loadFromXmlFile(const QString &);
bool loadFromXmlElement(const QDomElement &);
bool saveToXmlFile(const QString &);
bool saveToXmlElement(QDomElement &) const;
TitleBlockTemplate *clone() const;
QString name() const;
int rowDimension(int);
void setRowDimension(int, const TitleBlockDimension &);
TitleBlockDimension columnDimension(int);
void setColumnDimension(int, const TitleBlockDimension &);
int columnsCount() const;
int rowsCount() const;
QList columnsWidth(int) const;
QList rowsHeights() const;
int width(int);
int height() const;
bool moveRow(int, int);
void addRow(int = -1);
bool insertRow(int, const QList &, int = -1);
QList takeRow(int);
QList createRow();
bool moveColumn(int, int);
void addColumn(int = -1);
bool insertColumn(const TitleBlockDimension &, const QList &, int = -1);
QList takeColumn(int);
QList createColumn();
TitleBlockCell *cell(int, int) const;
QSet spannedCells(const TitleBlockCell *) const;
bool addLogo(const QString &, QByteArray *, const QString & = "svg", const QString & = "xml");
bool addLogoFromFile(const QString &, const QString & = QString());
bool removeLogo(const QString &);
bool renameLogo(const QString &, const QString &);
void setLogoStorage(const QString &, const QString &);
QList logos() const;
QString logoType(const QString &) const;
QSvgRenderer *vectorLogo(const QString &) const;
QPixmap bitmapLogo(const QString &) const;
void render(QPainter &, const DiagramContext &, int) const;
void renderCell(QPainter &, const TitleBlockCell &, const DiagramContext &, const QRect &) const;
QString toString() const;
protected:
bool loadLogos(const QDomElement &, bool = false);
bool loadLogo(const QDomElement &);
bool loadGrid(const QDomElement &);
bool loadCells(const QDomElement &);
void loadCell(const QDomElement &);
void saveLogos(QDomElement &) const;
void saveLogo(const QString &, QDomElement &) const;
void saveGrid(QDomElement &) const;
void saveCells(QDomElement &) const;
void saveCell(TitleBlockCell *, QDomElement &) const;
QList createCellsList(int);
private:
void parseRows(const QString &);
void parseColumns(const QString &);
bool checkCell(const QDomElement &, TitleBlockCell ** = 0);
void flushCells();
void initCells();
int lengthRange(int, int, const QList &) const;
QString finalTextForCell(const TitleBlockCell &, const DiagramContext &) const;
void renderTextCell(QPainter &, const QString &, const TitleBlockCell &, const QRectF &) const;
void applyCellSpans();
void forgetSpanning();
bool checkCellSpan(TitleBlockCell *);
void applyCellSpan(TitleBlockCell *);
void applyRowColNums();
void rowColsChanged();
// attributes
private:
QString name_; ///< name identifying the Title Block Template within its parent project
QHash data_logos_; ///< Logos raw data
QHash storage_logos_; ///< Logos applied storage type (e.g. "xml" or "base64")
QHash type_logos_; ///< Logos types (e.g. "png", "jpeg", "svg")
QHash vector_logos_; ///< Rendered objects for vector logos
QHash bitmap_logos_; ///< Pixmaps for bitmap logos
QList rows_heights_; ///< rows heights -- simple integers
QList columns_width_; ///< columns widths -- @see TitleBlockColDimension
QList registered_cells_; ///< Cells objects created rattached to this template, but not mandatorily used
QList< QList > cells_; ///< Cells grid
};
#endif