[qet] [1132] Changed every occurence in the code of the "inset" term to " title block". |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 1132
Author: xavier
Date: 2010-12-20 03:45:36 +0100 (Mon, 20 Dec 2010)
Log Message:
-----------
Changed every occurence in the code of the "inset" term to "title block".
Modified Paths:
--------------
branches/0.3/qelectrotech.qrc
branches/0.3/sources/borderpropertieswidget.cpp
branches/0.3/sources/borderpropertieswidget.h
branches/0.3/sources/configpages.cpp
branches/0.3/sources/configpages.h
branches/0.3/sources/diagram.cpp
branches/0.3/sources/diagram.h
branches/0.3/sources/diagramcommands.cpp
branches/0.3/sources/diagramcommands.h
branches/0.3/sources/diagramcontext.h
branches/0.3/sources/diagramview.cpp
branches/0.3/sources/exportproperties.cpp
branches/0.3/sources/exportproperties.h
branches/0.3/sources/exportpropertieswidget.cpp
branches/0.3/sources/exportpropertieswidget.h
branches/0.3/sources/hotspoteditor.cpp
branches/0.3/sources/projectview.cpp
branches/0.3/sources/qet.cpp
branches/0.3/sources/qet.h
branches/0.3/sources/qetapp.cpp
branches/0.3/sources/qetapp.h
branches/0.3/sources/qetdiagrameditor.cpp
branches/0.3/sources/qetdiagrameditor.h
branches/0.3/sources/qetproject.cpp
branches/0.3/sources/qetproject.h
Added Paths:
-----------
branches/0.3/sources/bordertitleblock.cpp
branches/0.3/sources/bordertitleblock.h
branches/0.3/sources/titleblockcell.h
branches/0.3/sources/titleblockproperties.cpp
branches/0.3/sources/titleblockproperties.h
branches/0.3/sources/titleblockpropertieswidget.cpp
branches/0.3/sources/titleblockpropertieswidget.h
branches/0.3/sources/titleblocktemplate.cpp
branches/0.3/sources/titleblocktemplate.h
branches/0.3/sources/titleblocktemplaterenderer.cpp
branches/0.3/sources/titleblocktemplaterenderer.h
branches/0.3/titleblocks/
branches/0.3/titleblocks/default.titleblock
Removed Paths:
-------------
branches/0.3/insets/
branches/0.3/sources/borderinset.cpp
branches/0.3/sources/borderinset.h
branches/0.3/sources/insetcell.h
branches/0.3/sources/insetproperties.cpp
branches/0.3/sources/insetproperties.h
branches/0.3/sources/insetpropertieswidget.cpp
branches/0.3/sources/insetpropertieswidget.h
branches/0.3/sources/insettemplate.cpp
branches/0.3/sources/insettemplate.h
branches/0.3/sources/insettemplaterenderer.cpp
branches/0.3/sources/insettemplaterenderer.h
branches/0.3/titleblocks/default.inset
Modified: branches/0.3/qelectrotech.qrc
===================================================================
--- branches/0.3/qelectrotech.qrc 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/qelectrotech.qrc 2010-12-20 02:45:36 UTC (rev 1132)
@@ -180,7 +180,7 @@
<file>ico/oxygen-icons/48x48/apps/qelectrotech.png</file>
<file>ico/oxygen-icons/64x64/apps/qelectrotech.png</file>
<file>ico/splash.png</file>
- <file>insets/default.inset</file>
+ <file>titleblocks/default.titleblock</file>
<file>LICENSE</file>
</qresource>
</RCC>
Deleted: branches/0.3/sources/borderinset.cpp
===================================================================
--- branches/0.3/sources/borderinset.cpp 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/borderinset.cpp 2010-12-20 02:45:36 UTC (rev 1132)
@@ -1,504 +0,0 @@
-/*
- Copyright 2006-2010 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 <http://www.gnu.org/licenses/>.
-*/
-#include <QPainter>
-#include "insettemplate.h"
-#include "insettemplaterenderer.h"
-#include "diagramcontext.h"
-#include "borderinset.h"
-#include "diagramposition.h"
-#include "qetapp.h"
-#include "math.h"
-
-/**
- Constructeur simple : construit une bordure en recuperant les dimensions
- dans la configuration de l'application.
- @param parent QObject parent de ce BorderInset
-*/
-BorderInset::BorderInset(QObject *parent) :
- QObject(parent)
-{
- // at first, the internal inset template renderer uses the default inset template
- inset_template_renderer = new InsetTemplateRenderer(this);
- inset_template_renderer -> setInsetTemplate(QETApp::defaultInsetTemplate());
-
- // dimensions par defaut du schema
- importBorder(BorderProperties());
-
- // contenu par defaut du cartouche
- importInset(InsetProperties());
-
- display_inset = true;
- display_border = true;
- setFolioData(1, 1);
- updateRectangles();
-}
-
-/**
- Destructeur - ne fait rien
-*/
-BorderInset::~BorderInset() {
-}
-
-/**
- @return la hauteur du cartouche
-*/
-qreal BorderInset::insetHeight() const {
- return(inset_template_renderer -> height());
-}
-
-/**
- @return Le nombre minimum de colonnes qu'un schema doit comporter
-*/
-int BorderInset::minNbColumns() {
- return(3);
-}
-
-/**
- @return la largeur minimale d'une colonne de schema
-*/
-qreal BorderInset::minColumnsWidth() {
- return(5.0);
-}
-
-/**
- @return Le nombre minimum de lignes qu'un schema doit comporter
-*/
-int BorderInset::minNbRows() {
- return(2);
-}
-
-/**
- @return la hauteur minimale d'une ligne de schema
-*/
-qreal BorderInset::minRowsHeight() {
- return(5.0);
-}
-
-/**
- @return les proprietes du cartouches
-*/
-InsetProperties BorderInset::exportInset() {
- InsetProperties ip;
- ip.author = bi_author;
- ip.date = bi_date;
- ip.title = bi_title;
- ip.folio = bi_folio;
- ip.filename = bi_filename;
- return(ip);
-}
-
-/**
- @param ip les nouvelles proprietes du cartouche
-*/
-void BorderInset::importInset(const InsetProperties &ip) {
- bi_author = ip.author;
- bi_date = ip.date;
- setTitle(ip.title);
- bi_folio = ip.folio;
- bi_filename = ip.filename;
- updateDiagramContextForInset();
- emit(needFolioData());
-}
-
-/**
- @return les proprietes de la bordure
-*/
-BorderProperties BorderInset::exportBorder() {
- BorderProperties bp;
- bp.columns_count = nbColumns();
- bp.columns_width = columnsWidth();
- bp.columns_header_height = columnsHeaderHeight();
- bp.display_columns = columnsAreDisplayed();
- bp.rows_count = nbRows();
- bp.rows_height = rowsHeight();
- bp.rows_header_width = rowsHeaderWidth();
- bp.display_rows = rowsAreDisplayed();
- return(bp);
-}
-
-/**
- @param bp les nouvelles proprietes de la bordure
-*/
-void BorderInset::importBorder(const BorderProperties &bp) {
- setColumnsHeaderHeight(bp.columns_header_height);
- setNbColumns(bp.columns_count);
- setColumnsWidth(bp.columns_width);
- displayColumns(bp.display_columns);
- setRowsHeaderWidth(bp.rows_header_width);
- setNbRows(bp.rows_count);
- setRowsHeight(bp.rows_height);
- displayRows(bp.display_rows);
-}
-
-/**
- @return the inset template used to render the inset
- @see InsetTemplateRenderer::insetTemplate()
-*/
-const InsetTemplate *BorderInset::insetTemplate() {
- return(inset_template_renderer -> insetTemplate());
-}
-
-/**
- @param inset_template The new inset template to use to render the inset
- @see InsetTemplateRenderer::setInsetTemplate()
-*/
-void BorderInset::setInsetTemplate(const InsetTemplate *inset_template) {
- inset_template_renderer -> setInsetTemplate(inset_template);
-}
-
-/**
- @param di true pour afficher le cartouche, false sinon
-*/
-void BorderInset::displayInset(bool di) {
- bool change = (di != display_inset);
- display_inset = di;
- if (change) emit(displayChanged());
-}
-
-/**
- @param dc true pour afficher les entetes des colonnes, false sinon
-*/
-void BorderInset::displayColumns(bool dc) {
- bool change = (dc != display_columns);
- display_columns = dc;
- if (change) emit(displayChanged());
-}
-
-/**
- @param dr true pour afficher les entetes des lignes, false sinon
-*/
-void BorderInset::displayRows(bool dr) {
- bool change = (dr != display_rows);
- display_rows = dr;
- if (change) emit(displayChanged());
-}
-
-/**
- @param db true pour afficher la bordure du schema, false sinon
- Note : si l'affichage de la bordure est ainsi desactivee, les lignes et
- colonnes ne seront pas dessinees.
-*/
-void BorderInset::displayBorder(bool db) {
- bool change = (db != display_border);
- display_border = db;
- if (change) emit(displayChanged());
-}
-
-/**
- Methode recalculant les rectangles composant le cadre et le cartouche en
- fonction des attributs de taille
-*/
-void BorderInset::updateRectangles() {
- // rectangle delimitant le schema
- QRectF previous_diagram = diagram;
- diagram = QRectF(0, 0, diagramWidth(), diagramHeight());
- if (diagram != previous_diagram) emit(borderChanged(previous_diagram, diagram));
-
- // rectangles relatifs au cartouche
- inset = QRectF(diagram.bottomLeft().x(), diagram.bottomLeft().y(), insetWidth(), insetHeight());
-}
-
-/**
- Dessine le cadre et le cartouche
- @param qp QPainter a utiliser pour dessiner le cadre et le cartouche
- @param x Abscisse du cadre
- @param y Ordonnee du cadre
-*/
-void BorderInset::draw(QPainter *qp, qreal x, qreal y) {
- // translate tous les rectangles
- diagram .translate(x, y);
- inset .translate(x, y);
-
- // prepare le QPainter
- qp -> save();
- qp -> setPen(Qt::black);
- qp -> setBrush(Qt::NoBrush);
-
- // dessine le cadre
- if (display_border) qp -> drawRect(diagram);
-
- qp -> setFont(QETApp::diagramTextsFont());
-
- // dessine la case vide qui apparait des qu'il y a un entete
- if (display_border && (display_columns || display_rows)) {
- qp -> setBrush(Qt::white);
- QRectF first_rectangle(
- diagram.topLeft().x(),
- diagram.topLeft().y(),
- rows_header_width,
- columns_header_height
- );
- qp -> drawRect(first_rectangle);
- }
-
- // dessine la numerotation des colonnes
- if (display_border && display_columns) {
- for (int i = 1 ; i <= nb_columns ; ++ i) {
- QRectF numbered_rectangle = QRectF(
- diagram.topLeft().x() + (rows_header_width + ((i - 1) * columns_width)),
- diagram.topLeft().y(),
- columns_width,
- columns_header_height
- );
- qp -> drawRect(numbered_rectangle);
- qp -> drawText(numbered_rectangle, Qt::AlignVCenter | Qt::AlignCenter, QString("%1").arg(i));
- }
- }
-
- // dessine la numerotation des lignes
- if (display_border && display_rows) {
- QString row_string("A");
- for (int i = 1 ; i <= nb_rows ; ++ i) {
- QRectF lettered_rectangle = QRectF(
- diagram.topLeft().x(),
- diagram.topLeft().y() + (columns_header_height + ((i - 1) * rows_height)),
- rows_header_width,
- rows_height
- );
- qp -> drawRect(lettered_rectangle);
- qp -> drawText(lettered_rectangle, Qt::AlignVCenter | Qt::AlignCenter, row_string);
- row_string = incrementLetters(row_string);
- }
- }
-
- // render the inset, using the InsetTemplate object
- if (display_inset) {
- qp -> translate(inset.topLeft());
- inset_template_renderer -> render(qp, inset.width());
- qp -> translate(-inset.topLeft());
- }
-
- qp -> restore();
-
- // annule la translation des rectangles
- diagram .translate(-x, -y);
- inset .translate(-x, -y);
-}
-
-/**
- Ajoute une colonne.
-*/
-void BorderInset::addColumn() {
- setNbColumns(nbColumns() + 1);
-}
-
-/**
- Enleve une colonne sans passer sous le minimum requis.
- @see minNbColumns()
-*/
-void BorderInset::removeColumn() {
- setNbColumns(nbColumns() - 1);
-}
-
-/**
- Ajoute une ligne.
-*/
-void BorderInset::addRow() {
- setNbRows(nbRows() + 1);
-}
-
-/**
- Enleve une ligne sans passer sous le minimum requis.
- @see minNbRows()
-*/
-void BorderInset::removeRow() {
- setNbRows(nbRows() - 1);
-}
-
-/**
- Permet de changer le nombre de colonnes.
- Si ce nombre de colonnes est inferieur au minimum requis, c'est ce minimum
- qui est utilise.
- @param nb_c nouveau nombre de colonnes
- @see minNbColumns()
-*/
-void BorderInset::setNbColumns(int nb_c) {
- if (nb_c == nbColumns()) return;
- nb_columns = qMax(minNbColumns(), nb_c);
- setInsetWidth(diagramWidth());
-}
-
-/**
- Change la largeur des colonnes.
- Si la largeur indiquee est inferieure au minimum requis, c'est ce minimum
- qui est utilise.
- @param new_cw nouvelle largeur des colonnes
- @see minColumnsWidth()
-*/
-void BorderInset::setColumnsWidth(const qreal &new_cw) {
- if (new_cw == columnsWidth()) return;
- columns_width = qMax(minColumnsWidth(), new_cw);
- setInsetWidth(diagramWidth());
-}
-
-/**
- Change la hauteur des en-tetes contenant les numeros de colonnes. Celle-ci
- doit rester comprise entre 5 et 50 px.
- @param new_chh nouvelle hauteur des en-tetes de colonnes
-*/
-void BorderInset::setColumnsHeaderHeight(const qreal &new_chh) {
- columns_header_height = qBound(qreal(5.0), new_chh, qreal(50.0));
- updateRectangles();
-}
-
-/**
- Permet de changer le nombre de lignes.
- Si ce nombre de lignes est inferieur au minimum requis, cette fonction ne
- fait rien
- @param nb_r nouveau nombre de lignes
- @see minNbRows()
-*/
-void BorderInset::setNbRows(int nb_r) {
- if (nb_r == nbRows()) return;
- nb_rows = qMax(minNbRows(), nb_r);
- setInsetWidth(diagramWidth());
- updateRectangles();
-}
-
-/**
- Change la hauteur des lignes.
- Si la hauteur indiquee est inferieure au minimum requis, c'est ce minimum
- qui est utilise.
- @param new_rh nouvelle hauteur des lignes
- @see minRowsHeight()
-*/
-void BorderInset::setRowsHeight(const qreal &new_rh) {
- if (new_rh == rowsHeight()) return;
- rows_height = qMax(minRowsHeight(), new_rh);
- updateRectangles();
-}
-
-/**
- Change la largeur des en-tetes contenant les numeros de lignes. Celle-ci
- doit rester comprise entre 5 et 50 px.
- @param new_rhw nouvelle largeur des en-tetes des lignes
-*/
-void BorderInset::setRowsHeaderWidth(const qreal &new_rhw) {
- rows_header_width = qBound(qreal(5.0), new_rhw, qreal(50.0));
- updateRectangles();
-}
-
-/**
- Cette methode essaye de se rapprocher le plus possible de la hauteur donnee
- en parametre en modifiant le nombre de lignes en cours.
-*/
-void BorderInset::setDiagramHeight(const qreal &height) {
- // taille des lignes a utiliser = rows_height
- setNbRows(qRound(ceil(height / rows_height)));
-}
-
-/**
- Change la largeur du cartouche. Cette largeur sera restreinte a celle du
- schema.
-*/
-void BorderInset::setInsetWidth(const qreal &new_iw) {
- inset_width = qMin(diagramWidth(), new_iw);
- updateRectangles();
-}
-
-
-/**
- Ajuste la largeur du cartouche de facon a ce que celui-ci soit aussi large
- que le schema
-*/
-void BorderInset::adjustInsetToColumns() {
- setInsetWidth(diagramWidth());
-}
-
-/**
- @param pos Position cartesienne (ex : 10.3, 45.2) a transformer en position
- dans la grille (ex : B2)
- @return la position dans la grille correspondant a pos
-*/
-DiagramPosition BorderInset::convertPosition(const QPointF &pos) {
- // recupere le rectangle quadrille par les en-tetes
- QRectF grid_rect(
- rowsHeaderWidth(),
- columnsHeaderHeight(),
- diagramWidth(),
- diagramHeight()
- );
-
- if (!grid_rect.contains(pos)) {
- return(DiagramPosition("", 0));
- }
-
- QPointF relative_pos = pos - grid_rect.topLeft();
- int row_number = int(ceil(relative_pos.x() / columnsWidth()));
- int column_number = int(ceil(relative_pos.y() / rowsHeight()));
-
- QString letter = "A";
- for (int i = 1 ; i < column_number ; ++ i) {
- letter = incrementLetters(letter);
- }
-
- return(DiagramPosition(letter, row_number));
-}
-
-/**
- Update the informations given to the inset template by regenerating a
- DiagramContext object.
-*/
-void BorderInset::updateDiagramContextForInset() {
- DiagramContext context;
- context.addValue("author", bi_author);
- context.addValue("date", bi_date.toString("dd/MM/yyyy"));
- context.addValue("title", bi_title);
- context.addValue("filename", bi_filename);
- context.addValue("folio", bi_final_folio);
- context.addValue("folio-id", folio_index_);
- context.addValue("folio-total", folio_total_);
-
- inset_template_renderer -> setContext(context);
-}
-
-QString BorderInset::incrementLetters(const QString &string) {
- if (string.isEmpty()) {
- return("A");
- } else {
- // separe les digits precedents du dernier digit
- QString first_digits(string.left(string.count() - 1));
- QChar last_digit(string.at(string.count() - 1));
- if (last_digit != 'Z') {
- // incremente le dernier digit
- last_digit = last_digit.toAscii() + 1;
- return(first_digits + QString(last_digit));
- } else {
- return(incrementLetters(first_digits) + "A");
- }
- }
-}
-
-/**
- @param index numero du schema (de 1 a total)
- @param total nombre total de schemas dans le projet
-*/
-void BorderInset::setFolioData(int index, int total) {
- if (index < 1 || total < 1 || index > total) return;
-
- // memorise les informations
- folio_index_ = index;
- folio_total_ = total;
-
- // regenere le contenu du champ folio
- bi_final_folio = bi_folio;
- bi_final_folio.replace("%id", QString::number(folio_index_));
- bi_final_folio.replace("%total", QString::number(folio_total_));
-
- updateDiagramContextForInset();
-}
Deleted: branches/0.3/sources/borderinset.h
===================================================================
--- branches/0.3/sources/borderinset.h 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/borderinset.h 2010-12-20 02:45:36 UTC (rev 1132)
@@ -1,229 +0,0 @@
-/*
- Copyright 2006-2010 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 <http://www.gnu.org/licenses/>.
-*/
-#ifndef BORDERINSET_H
-#define BORDERINSET_H
-#include "insetproperties.h"
-#include "borderproperties.h"
-#include <QObject>
-#include <QRectF>
-#include <QDate>
-class QPainter;
-class DiagramPosition;
-class InsetTemplate;
-class InsetTemplateRenderer;
-/**
- Cette classe represente l'ensemble bordure + cartouche qui encadre le
- schema electrique.
-*/
-class BorderInset : public QObject {
- Q_OBJECT
-
- // constructeurs, destructeur
- public:
- BorderInset(QObject * = 0);
- virtual ~BorderInset();
-
- private:
- BorderInset(const BorderInset &);
-
- // methodes
- public:
- static int minNbColumns();
- static qreal minColumnsWidth();
- static int minNbRows();
- static qreal minRowsHeight();
-
- void draw(QPainter *, qreal = 0.0, qreal = 0.0);
-
- // methodes d'acces en lecture aux dimensions
- // colonnes
- /// @return le nombre de colonnes du schema
- int nbColumns() const { return(nb_columns); }
- /// @return la largeur des colonnes en pixels
- qreal columnsWidth() const { return(columns_width); }
- /// @return la taille de l'ensemble des colonnes, en-tete des lignes non inclus
- qreal columnsTotalWidth() const { return(nb_columns * columns_width); }
- /// @return la hauteur, en pixels, des en-tetes des colonnes
- qreal columnsHeaderHeight() const { return(columns_header_height); }
-
- // lignes
- /// @return le nombre de lignes du schema
- int nbRows() const { return(nb_rows); }
- /// @return la hauteur des lignes en pixels
- qreal rowsHeight() const { return(rows_height); }
- /// @return la taille de l'ensemble des lignes, en-tete des colonnes non inclus
- qreal rowsTotalHeight() const { return(nb_rows * rows_height); }
- /// @return la largeur, en pixels, des en-tetes des lignes
- qreal rowsHeaderWidth() const { return(rows_header_width); }
-
- // cadre sans le cartouche = schema
- /// @return la largeur du schema, c'est-a-dire du cadre sans le cartouche
- qreal diagramWidth() const { return(columnsTotalWidth() + rowsHeaderWidth()); }
- /// @return la hauteurdu schema, c'est-a-dire du cadre sans le cartouche
- qreal diagramHeight() const { return(rowsTotalHeight() + columnsHeaderHeight()); }
-
- // cartouche
- /// @return la largeur du cartouche
- qreal insetWidth() const { return(inset_width); }
- qreal insetHeight() const;
-
- // cadre avec le cartouche
- /// @return la hauteur de la bordure
- qreal borderWidth() const { return(diagramWidth()); }
- /// @return la hauteur de la bordure
- qreal borderHeight() const { return(diagramHeight() + insetHeight()); }
-
- // methodes d'acces en lecture aux informations du cartouche
- /// @return le champ "Auteur" du cartouche
- QString author() const { return(bi_author); }
- /// @return le champ "Date" du cartouche
- QDate date() const { return(bi_date); }
- /// @return le champ "Titre" du cartouche
- QString title() const { return(bi_title); }
- /// @return le champ "Folio" du cartouche
- QString folio() const { return(bi_folio); }
- /// @return le champ "Fichier" du cartouche
- QString fileName() const { return(bi_filename); }
-
- // methodes d'acces en lecture aux options
- /// @return true si le cartouche est affiche, false sinon
- bool insetIsDisplayed() const { return(display_inset); }
- /// @return true si les entetes des colonnes sont affiches, false sinon
- bool columnsAreDisplayed() const { return(display_columns); }
- /// @return true si les entetes des lignes sont affiches, false sinon
- bool rowsAreDisplayed() const { return(display_rows); }
- /// @return true si la bordure est affichee, false sinon
- bool borderIsDisplayed() const { return(display_border); }
-
- // methodes d'acces en ecriture aux dimensions
- void addColumn ();
- void addRow ();
- void removeColumn ();
- void removeRow ();
- void setNbColumns (int);
- void setNbRows (int);
- void setColumnsWidth (const qreal &);
- void setRowsHeight (const qreal &);
- void setColumnsHeaderHeight(const qreal &);
- void setRowsHeaderWidth (const qreal &);
- void setDiagramHeight (const qreal &);
- void setInsetWidth (const qreal &);
- void adjustInsetToColumns ();
-
- DiagramPosition convertPosition(const QPointF &);
-
- // methodes d'acces en ecriture aux informations du cartouche
- /// @param author le nouveau contenu du champ "Auteur"
- void setAuthor (const QString &author) { bi_author = author; }
- /// @param date le nouveau contenu du champ "Date"
- void setDate (const QDate &date) { bi_date = date; }
- /// @param title le nouveau contenu du champ "Titre"
- void setTitle (const QString &title) {
- if (bi_title != title) {
- bi_title = title;
- emit(diagramTitleChanged(title));
- }
- }
- /// @param folio le nouveau contenu du champ "Folio"
- void setFolio (const QString &folio) { bi_folio = folio; }
- void setFolioData(int, int);
- /// @param filename le nouveau contenu du champ "Fichier"
- void setFileName (const QString &filename) { bi_filename = filename; }
-
- InsetProperties exportInset();
- void importInset(const InsetProperties &);
- BorderProperties exportBorder();
- void importBorder(const BorderProperties &);
-
- const InsetTemplate *insetTemplate();
- void setInsetTemplate(const InsetTemplate *);
-
- // methodes d'acces en ecriture aux options
- void displayInset(bool);
- void displayColumns(bool);
- void displayRows(bool);
- void displayBorder(bool);
-
- private:
- void updateRectangles();
- void updateDiagramContextForInset();
- QString incrementLetters(const QString &);
-
- // signaux
- signals:
- /**
- Signal emis lorsque la bordure change
- @param old_border Ancienne bordure
- @param new_border Nouvelle bordure
- */
- void borderChanged(QRectF old_border, QRectF new_border);
- /**
- Signal emise lorsque des options d'affichage change
- */
- void displayChanged();
-
- /**
- Signal emis lorsque le titre du schema change
- */
- void diagramTitleChanged(const QString &);
-
- /**
- Signal emis lorsque le cartouche requiert une mise a jour des donnees
- utilisees pour generer le folio.
- */
- void needFolioData();
-
- // attributs
- private:
- // informations du cartouche
- QString bi_author;
- QDate bi_date;
- QString bi_title;
- QString bi_folio;
- QString bi_final_folio;
- int folio_index_;
- int folio_total_;
- QString bi_filename;
-
- // dimensions du cadre (lignes et colonnes)
- // colonnes : nombres et dimensions
- int nb_columns;
- qreal columns_width;
- qreal columns_header_height;
-
- // lignes : nombres et dimensions
- int nb_rows;
- qreal rows_height;
- qreal rows_header_width;
-
- // dimensions du cartouche
- qreal inset_width;
- qreal inset_height;
-
- // rectangles utilises pour le dessin
- QRectF diagram;
- QRectF inset;
-
- // booleens pour les options de dessin
- bool display_inset;
- bool display_columns;
- bool display_rows;
- bool display_border;
- InsetTemplateRenderer *inset_template_renderer;
-};
-#endif
Modified: branches/0.3/sources/borderpropertieswidget.cpp
===================================================================
--- branches/0.3/sources/borderpropertieswidget.cpp 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/borderpropertieswidget.cpp 2010-12-20 02:45:36 UTC (rev 1132)
@@ -18,7 +18,7 @@
#include "borderpropertieswidget.h"
#include <QtGui>
#include "qetapp.h"
-#include "borderinset.h"
+#include "bordertitleblock.h"
/**
Constructeur
@@ -99,11 +99,11 @@
QLabel *ds1 = new QLabel(tr("Colonnes :"));
columns_count = new QSpinBox(diagram_size_box);
- columns_count -> setMinimum(BorderInset::minNbColumns());
+ columns_count -> setMinimum(BorderTitleBlock::minNbColumns());
columns_count -> setMaximum(10000); // valeur arbitraire
columns_width = new QSpinBox(diagram_size_box);
- columns_width -> setMinimum(qRound(BorderInset::minColumnsWidth()));
+ columns_width -> setMinimum(qRound(BorderTitleBlock::minColumnsWidth()));
columns_width -> setSingleStep(10);
columns_width -> setPrefix(tr("\327", "multiplication symbol"));
columns_width -> setSuffix(tr("px", "unit for cols width"));
@@ -114,11 +114,11 @@
QLabel *ds2 = new QLabel(tr("Lignes :"));
rows_count = new QSpinBox(diagram_size_box);
- rows_count -> setMinimum(BorderInset::minNbRows());
+ rows_count -> setMinimum(BorderTitleBlock::minNbRows());
rows_count -> setMaximum(10000); // valeur arbitraire
rows_height = new QSpinBox(diagram_size_box);
- rows_height -> setMinimum(qRound(BorderInset::minRowsHeight()));
+ rows_height -> setMinimum(qRound(BorderTitleBlock::minRowsHeight()));
rows_height -> setSingleStep(10);
rows_height -> setPrefix(tr("\327", "multiplication symbol"));
rows_height -> setSuffix(tr("px", "unit for rows height"));
Modified: branches/0.3/sources/borderpropertieswidget.h
===================================================================
--- branches/0.3/sources/borderpropertieswidget.h 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/borderpropertieswidget.h 2010-12-20 02:45:36 UTC (rev 1132)
@@ -24,7 +24,7 @@
/**
Cette classe represente un widget permettant d'editer les dimensions et les
options d'affichage d'un schema, cartouche non inclus.
- @see InsetPropertiesWidget
+ @see TitleBlockPropertiesWidget
*/
class BorderPropertiesWidget : public QWidget {
Q_OBJECT
Copied: branches/0.3/sources/bordertitleblock.cpp (from rev 1131, branches/0.3/sources/borderinset.cpp)
===================================================================
--- branches/0.3/sources/bordertitleblock.cpp (rev 0)
+++ branches/0.3/sources/bordertitleblock.cpp 2010-12-20 02:45:36 UTC (rev 1132)
@@ -0,0 +1,504 @@
+/*
+ Copyright 2006-2010 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 <http://www.gnu.org/licenses/>.
+*/
+#include <QPainter>
+#include "titleblocktemplate.h"
+#include "titleblocktemplaterenderer.h"
+#include "diagramcontext.h"
+#include "bordertitleblock.h"
+#include "diagramposition.h"
+#include "qetapp.h"
+#include "math.h"
+
+/**
+ Constructeur simple : construit une bordure en recuperant les dimensions
+ dans la configuration de l'application.
+ @param parent QObject parent de ce BorderTitleBlock
+*/
+BorderTitleBlock::BorderTitleBlock(QObject *parent) :
+ QObject(parent)
+{
+ // at first, the internal titleblock template renderer uses the default titleblock template
+ titleblock_template_renderer = new TitleBlockTemplateRenderer(this);
+ titleblock_template_renderer -> setTitleBlockTemplate(QETApp::defaultTitleBlockTemplate());
+
+ // dimensions par defaut du schema
+ importBorder(BorderProperties());
+
+ // contenu par defaut du cartouche
+ importTitleBlock(TitleBlockProperties());
+
+ display_titleblock = true;
+ display_border = true;
+ setFolioData(1, 1);
+ updateRectangles();
+}
+
+/**
+ Destructeur - ne fait rien
+*/
+BorderTitleBlock::~BorderTitleBlock() {
+}
+
+/**
+ @return la hauteur du cartouche
+*/
+qreal BorderTitleBlock::titleBlockHeight() const {
+ return(titleblock_template_renderer -> height());
+}
+
+/**
+ @return Le nombre minimum de colonnes qu'un schema doit comporter
+*/
+int BorderTitleBlock::minNbColumns() {
+ return(3);
+}
+
+/**
+ @return la largeur minimale d'une colonne de schema
+*/
+qreal BorderTitleBlock::minColumnsWidth() {
+ return(5.0);
+}
+
+/**
+ @return Le nombre minimum de lignes qu'un schema doit comporter
+*/
+int BorderTitleBlock::minNbRows() {
+ return(2);
+}
+
+/**
+ @return la hauteur minimale d'une ligne de schema
+*/
+qreal BorderTitleBlock::minRowsHeight() {
+ return(5.0);
+}
+
+/**
+ @return les proprietes du cartouches
+*/
+TitleBlockProperties BorderTitleBlock::exportTitleBlock() {
+ TitleBlockProperties ip;
+ ip.author = bi_author;
+ ip.date = bi_date;
+ ip.title = bi_title;
+ ip.folio = bi_folio;
+ ip.filename = bi_filename;
+ return(ip);
+}
+
+/**
+ @param ip les nouvelles proprietes du cartouche
+*/
+void BorderTitleBlock::importTitleBlock(const TitleBlockProperties &ip) {
+ bi_author = ip.author;
+ bi_date = ip.date;
+ setTitle(ip.title);
+ bi_folio = ip.folio;
+ bi_filename = ip.filename;
+ updateDiagramContextForTitleBlock();
+ emit(needFolioData());
+}
+
+/**
+ @return les proprietes de la bordure
+*/
+BorderProperties BorderTitleBlock::exportBorder() {
+ BorderProperties bp;
+ bp.columns_count = nbColumns();
+ bp.columns_width = columnsWidth();
+ bp.columns_header_height = columnsHeaderHeight();
+ bp.display_columns = columnsAreDisplayed();
+ bp.rows_count = nbRows();
+ bp.rows_height = rowsHeight();
+ bp.rows_header_width = rowsHeaderWidth();
+ bp.display_rows = rowsAreDisplayed();
+ return(bp);
+}
+
+/**
+ @param bp les nouvelles proprietes de la bordure
+*/
+void BorderTitleBlock::importBorder(const BorderProperties &bp) {
+ setColumnsHeaderHeight(bp.columns_header_height);
+ setNbColumns(bp.columns_count);
+ setColumnsWidth(bp.columns_width);
+ displayColumns(bp.display_columns);
+ setRowsHeaderWidth(bp.rows_header_width);
+ setNbRows(bp.rows_count);
+ setRowsHeight(bp.rows_height);
+ displayRows(bp.display_rows);
+}
+
+/**
+ @return the titleblock template used to render the titleblock
+ @see TitleBlockTemplateRenderer::titleBlockTemplate()
+*/
+const TitleBlockTemplate *BorderTitleBlock::titleBlockTemplate() {
+ return(titleblock_template_renderer -> titleBlockTemplate());
+}
+
+/**
+ @param titleblock_template The new titleblock template to use to render the titleblock
+ @see TitleBlockTemplateRenderer::setTitleBlockTemplate()
+*/
+void BorderTitleBlock::setTitleBlockTemplate(const TitleBlockTemplate *titleblock_template) {
+ titleblock_template_renderer -> setTitleBlockTemplate(titleblock_template);
+}
+
+/**
+ @param di true pour afficher le cartouche, false sinon
+*/
+void BorderTitleBlock::displayTitleBlock(bool di) {
+ bool change = (di != display_titleblock);
+ display_titleblock = di;
+ if (change) emit(displayChanged());
+}
+
+/**
+ @param dc true pour afficher les entetes des colonnes, false sinon
+*/
+void BorderTitleBlock::displayColumns(bool dc) {
+ bool change = (dc != display_columns);
+ display_columns = dc;
+ if (change) emit(displayChanged());
+}
+
+/**
+ @param dr true pour afficher les entetes des lignes, false sinon
+*/
+void BorderTitleBlock::displayRows(bool dr) {
+ bool change = (dr != display_rows);
+ display_rows = dr;
+ if (change) emit(displayChanged());
+}
+
+/**
+ @param db true pour afficher la bordure du schema, false sinon
+ Note : si l'affichage de la bordure est ainsi desactivee, les lignes et
+ colonnes ne seront pas dessinees.
+*/
+void BorderTitleBlock::displayBorder(bool db) {
+ bool change = (db != display_border);
+ display_border = db;
+ if (change) emit(displayChanged());
+}
+
+/**
+ Methode recalculant les rectangles composant le cadre et le cartouche en
+ fonction des attributs de taille
+*/
+void BorderTitleBlock::updateRectangles() {
+ // rectangle delimitant le schema
+ QRectF previous_diagram = diagram;
+ diagram = QRectF(0, 0, diagramWidth(), diagramHeight());
+ if (diagram != previous_diagram) emit(borderChanged(previous_diagram, diagram));
+
+ // rectangles relatifs au cartouche
+ titleblock = QRectF(diagram.bottomLeft().x(), diagram.bottomLeft().y(), titleBlockWidth(), titleBlockHeight());
+}
+
+/**
+ Dessine le cadre et le cartouche
+ @param qp QPainter a utiliser pour dessiner le cadre et le cartouche
+ @param x Abscisse du cadre
+ @param y Ordonnee du cadre
+*/
+void BorderTitleBlock::draw(QPainter *qp, qreal x, qreal y) {
+ // translate tous les rectangles
+ diagram .translate(x, y);
+ titleblock .translate(x, y);
+
+ // prepare le QPainter
+ qp -> save();
+ qp -> setPen(Qt::black);
+ qp -> setBrush(Qt::NoBrush);
+
+ // dessine le cadre
+ if (display_border) qp -> drawRect(diagram);
+
+ qp -> setFont(QETApp::diagramTextsFont());
+
+ // dessine la case vide qui apparait des qu'il y a un entete
+ if (display_border && (display_columns || display_rows)) {
+ qp -> setBrush(Qt::white);
+ QRectF first_rectangle(
+ diagram.topLeft().x(),
+ diagram.topLeft().y(),
+ rows_header_width,
+ columns_header_height
+ );
+ qp -> drawRect(first_rectangle);
+ }
+
+ // dessine la numerotation des colonnes
+ if (display_border && display_columns) {
+ for (int i = 1 ; i <= nb_columns ; ++ i) {
+ QRectF numbered_rectangle = QRectF(
+ diagram.topLeft().x() + (rows_header_width + ((i - 1) * columns_width)),
+ diagram.topLeft().y(),
+ columns_width,
+ columns_header_height
+ );
+ qp -> drawRect(numbered_rectangle);
+ qp -> drawText(numbered_rectangle, Qt::AlignVCenter | Qt::AlignCenter, QString("%1").arg(i));
+ }
+ }
+
+ // dessine la numerotation des lignes
+ if (display_border && display_rows) {
+ QString row_string("A");
+ for (int i = 1 ; i <= nb_rows ; ++ i) {
+ QRectF lettered_rectangle = QRectF(
+ diagram.topLeft().x(),
+ diagram.topLeft().y() + (columns_header_height + ((i - 1) * rows_height)),
+ rows_header_width,
+ rows_height
+ );
+ qp -> drawRect(lettered_rectangle);
+ qp -> drawText(lettered_rectangle, Qt::AlignVCenter | Qt::AlignCenter, row_string);
+ row_string = incrementLetters(row_string);
+ }
+ }
+
+ // render the titleblock, using the TitleBlockTemplate object
+ if (display_titleblock) {
+ qp -> translate(titleblock.topLeft());
+ titleblock_template_renderer -> render(qp, titleblock.width());
+ qp -> translate(-titleblock.topLeft());
+ }
+
+ qp -> restore();
+
+ // annule la translation des rectangles
+ diagram .translate(-x, -y);
+ titleblock .translate(-x, -y);
+}
+
+/**
+ Ajoute une colonne.
+*/
+void BorderTitleBlock::addColumn() {
+ setNbColumns(nbColumns() + 1);
+}
+
+/**
+ Enleve une colonne sans passer sous le minimum requis.
+ @see minNbColumns()
+*/
+void BorderTitleBlock::removeColumn() {
+ setNbColumns(nbColumns() - 1);
+}
+
+/**
+ Ajoute une ligne.
+*/
+void BorderTitleBlock::addRow() {
+ setNbRows(nbRows() + 1);
+}
+
+/**
+ Enleve une ligne sans passer sous le minimum requis.
+ @see minNbRows()
+*/
+void BorderTitleBlock::removeRow() {
+ setNbRows(nbRows() - 1);
+}
+
+/**
+ Permet de changer le nombre de colonnes.
+ Si ce nombre de colonnes est inferieur au minimum requis, c'est ce minimum
+ qui est utilise.
+ @param nb_c nouveau nombre de colonnes
+ @see minNbColumns()
+*/
+void BorderTitleBlock::setNbColumns(int nb_c) {
+ if (nb_c == nbColumns()) return;
+ nb_columns = qMax(minNbColumns(), nb_c);
+ setTitleBlockWidth(diagramWidth());
+}
+
+/**
+ Change la largeur des colonnes.
+ Si la largeur indiquee est inferieure au minimum requis, c'est ce minimum
+ qui est utilise.
+ @param new_cw nouvelle largeur des colonnes
+ @see minColumnsWidth()
+*/
+void BorderTitleBlock::setColumnsWidth(const qreal &new_cw) {
+ if (new_cw == columnsWidth()) return;
+ columns_width = qMax(minColumnsWidth(), new_cw);
+ setTitleBlockWidth(diagramWidth());
+}
+
+/**
+ Change la hauteur des en-tetes contenant les numeros de colonnes. Celle-ci
+ doit rester comprise entre 5 et 50 px.
+ @param new_chh nouvelle hauteur des en-tetes de colonnes
+*/
+void BorderTitleBlock::setColumnsHeaderHeight(const qreal &new_chh) {
+ columns_header_height = qBound(qreal(5.0), new_chh, qreal(50.0));
+ updateRectangles();
+}
+
+/**
+ Permet de changer le nombre de lignes.
+ Si ce nombre de lignes est inferieur au minimum requis, cette fonction ne
+ fait rien
+ @param nb_r nouveau nombre de lignes
+ @see minNbRows()
+*/
+void BorderTitleBlock::setNbRows(int nb_r) {
+ if (nb_r == nbRows()) return;
+ nb_rows = qMax(minNbRows(), nb_r);
+ setTitleBlockWidth(diagramWidth());
+ updateRectangles();
+}
+
+/**
+ Change la hauteur des lignes.
+ Si la hauteur indiquee est inferieure au minimum requis, c'est ce minimum
+ qui est utilise.
+ @param new_rh nouvelle hauteur des lignes
+ @see minRowsHeight()
+*/
+void BorderTitleBlock::setRowsHeight(const qreal &new_rh) {
+ if (new_rh == rowsHeight()) return;
+ rows_height = qMax(minRowsHeight(), new_rh);
+ updateRectangles();
+}
+
+/**
+ Change la largeur des en-tetes contenant les numeros de lignes. Celle-ci
+ doit rester comprise entre 5 et 50 px.
+ @param new_rhw nouvelle largeur des en-tetes des lignes
+*/
+void BorderTitleBlock::setRowsHeaderWidth(const qreal &new_rhw) {
+ rows_header_width = qBound(qreal(5.0), new_rhw, qreal(50.0));
+ updateRectangles();
+}
+
+/**
+ Cette methode essaye de se rapprocher le plus possible de la hauteur donnee
+ en parametre en modifiant le nombre de lignes en cours.
+*/
+void BorderTitleBlock::setDiagramHeight(const qreal &height) {
+ // taille des lignes a utiliser = rows_height
+ setNbRows(qRound(ceil(height / rows_height)));
+}
+
+/**
+ Change la largeur du cartouche. Cette largeur sera restreinte a celle du
+ schema.
+*/
+void BorderTitleBlock::setTitleBlockWidth(const qreal &new_iw) {
+ titleblock_width = qMin(diagramWidth(), new_iw);
+ updateRectangles();
+}
+
+
+/**
+ Ajuste la largeur du cartouche de facon a ce que celui-ci soit aussi large
+ que le schema
+*/
+void BorderTitleBlock::adjustTitleBlockToColumns() {
+ setTitleBlockWidth(diagramWidth());
+}
+
+/**
+ @param pos Position cartesienne (ex : 10.3, 45.2) a transformer en position
+ dans la grille (ex : B2)
+ @return la position dans la grille correspondant a pos
+*/
+DiagramPosition BorderTitleBlock::convertPosition(const QPointF &pos) {
+ // recupere le rectangle quadrille par les en-tetes
+ QRectF grid_rect(
+ rowsHeaderWidth(),
+ columnsHeaderHeight(),
+ diagramWidth(),
+ diagramHeight()
+ );
+
+ if (!grid_rect.contains(pos)) {
+ return(DiagramPosition("", 0));
+ }
+
+ QPointF relative_pos = pos - grid_rect.topLeft();
+ int row_number = int(ceil(relative_pos.x() / columnsWidth()));
+ int column_number = int(ceil(relative_pos.y() / rowsHeight()));
+
+ QString letter = "A";
+ for (int i = 1 ; i < column_number ; ++ i) {
+ letter = incrementLetters(letter);
+ }
+
+ return(DiagramPosition(letter, row_number));
+}
+
+/**
+ Update the informations given to the titleblock template by regenerating a
+ DiagramContext object.
+*/
+void BorderTitleBlock::updateDiagramContextForTitleBlock() {
+ DiagramContext context;
+ context.addValue("author", bi_author);
+ context.addValue("date", bi_date.toString("dd/MM/yyyy"));
+ context.addValue("title", bi_title);
+ context.addValue("filename", bi_filename);
+ context.addValue("folio", bi_final_folio);
+ context.addValue("folio-id", folio_index_);
+ context.addValue("folio-total", folio_total_);
+
+ titleblock_template_renderer -> setContext(context);
+}
+
+QString BorderTitleBlock::incrementLetters(const QString &string) {
+ if (string.isEmpty()) {
+ return("A");
+ } else {
+ // separe les digits precedents du dernier digit
+ QString first_digits(string.left(string.count() - 1));
+ QChar last_digit(string.at(string.count() - 1));
+ if (last_digit != 'Z') {
+ // incremente le dernier digit
+ last_digit = last_digit.toAscii() + 1;
+ return(first_digits + QString(last_digit));
+ } else {
+ return(incrementLetters(first_digits) + "A");
+ }
+ }
+}
+
+/**
+ @param index numero du schema (de 1 a total)
+ @param total nombre total de schemas dans le projet
+*/
+void BorderTitleBlock::setFolioData(int index, int total) {
+ if (index < 1 || total < 1 || index > total) return;
+
+ // memorise les informations
+ folio_index_ = index;
+ folio_total_ = total;
+
+ // regenere le contenu du champ folio
+ bi_final_folio = bi_folio;
+ bi_final_folio.replace("%id", QString::number(folio_index_));
+ bi_final_folio.replace("%total", QString::number(folio_total_));
+
+ updateDiagramContextForTitleBlock();
+}
Copied: branches/0.3/sources/bordertitleblock.h (from rev 1131, branches/0.3/sources/borderinset.h)
===================================================================
--- branches/0.3/sources/bordertitleblock.h (rev 0)
+++ branches/0.3/sources/bordertitleblock.h 2010-12-20 02:45:36 UTC (rev 1132)
@@ -0,0 +1,229 @@
+/*
+ Copyright 2006-2010 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 <http://www.gnu.org/licenses/>.
+*/
+#ifndef BORDERTITLEBLOCK_H
+#define BORDERTITLEBLOCK_H
+#include "titleblockproperties.h"
+#include "borderproperties.h"
+#include <QObject>
+#include <QRectF>
+#include <QDate>
+class QPainter;
+class DiagramPosition;
+class TitleBlockTemplate;
+class TitleBlockTemplateRenderer;
+/**
+ Cette classe represente l'ensemble bordure + cartouche qui encadre le
+ schema electrique.
+*/
+class BorderTitleBlock : public QObject {
+ Q_OBJECT
+
+ // constructeurs, destructeur
+ public:
+ BorderTitleBlock(QObject * = 0);
+ virtual ~BorderTitleBlock();
+
+ private:
+ BorderTitleBlock(const BorderTitleBlock &);
+
+ // methodes
+ public:
+ static int minNbColumns();
+ static qreal minColumnsWidth();
+ static int minNbRows();
+ static qreal minRowsHeight();
+
+ void draw(QPainter *, qreal = 0.0, qreal = 0.0);
+
+ // methodes d'acces en lecture aux dimensions
+ // colonnes
+ /// @return le nombre de colonnes du schema
+ int nbColumns() const { return(nb_columns); }
+ /// @return la largeur des colonnes en pixels
+ qreal columnsWidth() const { return(columns_width); }
+ /// @return la taille de l'ensemble des colonnes, en-tete des lignes non inclus
+ qreal columnsTotalWidth() const { return(nb_columns * columns_width); }
+ /// @return la hauteur, en pixels, des en-tetes des colonnes
+ qreal columnsHeaderHeight() const { return(columns_header_height); }
+
+ // lignes
+ /// @return le nombre de lignes du schema
+ int nbRows() const { return(nb_rows); }
+ /// @return la hauteur des lignes en pixels
+ qreal rowsHeight() const { return(rows_height); }
+ /// @return la taille de l'ensemble des lignes, en-tete des colonnes non inclus
+ qreal rowsTotalHeight() const { return(nb_rows * rows_height); }
+ /// @return la largeur, en pixels, des en-tetes des lignes
+ qreal rowsHeaderWidth() const { return(rows_header_width); }
+
+ // cadre sans le cartouche = schema
+ /// @return la largeur du schema, c'est-a-dire du cadre sans le cartouche
+ qreal diagramWidth() const { return(columnsTotalWidth() + rowsHeaderWidth()); }
+ /// @return la hauteurdu schema, c'est-a-dire du cadre sans le cartouche
+ qreal diagramHeight() const { return(rowsTotalHeight() + columnsHeaderHeight()); }
+
+ // cartouche
+ /// @return la largeur du cartouche
+ qreal titleBlockWidth() const { return(titleblock_width); }
+ qreal titleBlockHeight() const;
+
+ // cadre avec le cartouche
+ /// @return la hauteur de la bordure
+ qreal borderWidth() const { return(diagramWidth()); }
+ /// @return la hauteur de la bordure
+ qreal borderHeight() const { return(diagramHeight() + titleBlockHeight()); }
+
+ // methodes d'acces en lecture aux informations du cartouche
+ /// @return le champ "Auteur" du cartouche
+ QString author() const { return(bi_author); }
+ /// @return le champ "Date" du cartouche
+ QDate date() const { return(bi_date); }
+ /// @return le champ "Titre" du cartouche
+ QString title() const { return(bi_title); }
+ /// @return le champ "Folio" du cartouche
+ QString folio() const { return(bi_folio); }
+ /// @return le champ "Fichier" du cartouche
+ QString fileName() const { return(bi_filename); }
+
+ // methodes d'acces en lecture aux options
+ /// @return true si le cartouche est affiche, false sinon
+ bool titleBlockIsDisplayed() const { return(display_titleblock); }
+ /// @return true si les entetes des colonnes sont affiches, false sinon
+ bool columnsAreDisplayed() const { return(display_columns); }
+ /// @return true si les entetes des lignes sont affiches, false sinon
+ bool rowsAreDisplayed() const { return(display_rows); }
+ /// @return true si la bordure est affichee, false sinon
+ bool borderIsDisplayed() const { return(display_border); }
+
+ // methodes d'acces en ecriture aux dimensions
+ void addColumn ();
+ void addRow ();
+ void removeColumn ();
+ void removeRow ();
+ void setNbColumns (int);
+ void setNbRows (int);
+ void setColumnsWidth (const qreal &);
+ void setRowsHeight (const qreal &);
+ void setColumnsHeaderHeight(const qreal &);
+ void setRowsHeaderWidth (const qreal &);
+ void setDiagramHeight (const qreal &);
+ void setTitleBlockWidth (const qreal &);
+ void adjustTitleBlockToColumns ();
+
+ DiagramPosition convertPosition(const QPointF &);
+
+ // methodes d'acces en ecriture aux informations du cartouche
+ /// @param author le nouveau contenu du champ "Auteur"
+ void setAuthor (const QString &author) { bi_author = author; }
+ /// @param date le nouveau contenu du champ "Date"
+ void setDate (const QDate &date) { bi_date = date; }
+ /// @param title le nouveau contenu du champ "Titre"
+ void setTitle (const QString &title) {
+ if (bi_title != title) {
+ bi_title = title;
+ emit(diagramTitleChanged(title));
+ }
+ }
+ /// @param folio le nouveau contenu du champ "Folio"
+ void setFolio (const QString &folio) { bi_folio = folio; }
+ void setFolioData(int, int);
+ /// @param filename le nouveau contenu du champ "Fichier"
+ void setFileName (const QString &filename) { bi_filename = filename; }
+
+ TitleBlockProperties exportTitleBlock();
+ void importTitleBlock(const TitleBlockProperties &);
+ BorderProperties exportBorder();
+ void importBorder(const BorderProperties &);
+
+ const TitleBlockTemplate *titleBlockTemplate();
+ void setTitleBlockTemplate(const TitleBlockTemplate *);
+
+ // methodes d'acces en ecriture aux options
+ void displayTitleBlock(bool);
+ void displayColumns(bool);
+ void displayRows(bool);
+ void displayBorder(bool);
+
+ private:
+ void updateRectangles();
+ void updateDiagramContextForTitleBlock();
+ QString incrementLetters(const QString &);
+
+ // signaux
+ signals:
+ /**
+ Signal emis lorsque la bordure change
+ @param old_border Ancienne bordure
+ @param new_border Nouvelle bordure
+ */
+ void borderChanged(QRectF old_border, QRectF new_border);
+ /**
+ Signal emise lorsque des options d'affichage change
+ */
+ void displayChanged();
+
+ /**
+ Signal emis lorsque le titre du schema change
+ */
+ void diagramTitleChanged(const QString &);
+
+ /**
+ Signal emis lorsque le cartouche requiert une mise a jour des donnees
+ utilisees pour generer le folio.
+ */
+ void needFolioData();
+
+ // attributs
+ private:
+ // informations du cartouche
+ QString bi_author;
+ QDate bi_date;
+ QString bi_title;
+ QString bi_folio;
+ QString bi_final_folio;
+ int folio_index_;
+ int folio_total_;
+ QString bi_filename;
+
+ // dimensions du cadre (lignes et colonnes)
+ // colonnes : nombres et dimensions
+ int nb_columns;
+ qreal columns_width;
+ qreal columns_header_height;
+
+ // lignes : nombres et dimensions
+ int nb_rows;
+ qreal rows_height;
+ qreal rows_header_width;
+
+ // dimensions du cartouche
+ qreal titleblock_width;
+ qreal titleblock_height;
+
+ // rectangles utilises pour le dessin
+ QRectF diagram;
+ QRectF titleblock;
+
+ // booleens pour les options de dessin
+ bool display_titleblock;
+ bool display_columns;
+ bool display_rows;
+ bool display_border;
+ TitleBlockTemplateRenderer *titleblock_template_renderer;
+};
+#endif
Modified: branches/0.3/sources/configpages.cpp
===================================================================
--- branches/0.3/sources/configpages.cpp 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/configpages.cpp 2010-12-20 02:45:36 UTC (rev 1132)
@@ -18,10 +18,10 @@
#include "configpages.h"
#include "borderpropertieswidget.h"
#include "conductorpropertieswidget.h"
-#include "insetpropertieswidget.h"
+#include "titleblockpropertieswidget.h"
#include "qetapp.h"
#include "qetdiagrameditor.h"
-#include "borderinset.h"
+#include "bordertitleblock.h"
#include "qeticons.h"
#include "exportpropertieswidget.h"
@@ -34,7 +34,7 @@
bpw = new BorderPropertiesWidget(QETDiagramEditor::defaultBorderProperties());
// proprietes par defaut d'un cartouche
- ipw = new InsetPropertiesWidget(QETDiagramEditor::defaultInsetProperties(), true);
+ ipw = new TitleBlockPropertiesWidget(QETDiagramEditor::defaultTitleBlockProperties(), true);
// proprietes par defaut des conducteurs
cpw = new ConductorPropertiesWidget(QETDiagramEditor::defaultConductorProperties());
@@ -77,7 +77,7 @@
bpw -> borderProperties().toSettings(settings, "diagrameditor/default");
// proprietes du cartouche
- ipw-> insetProperties().toSettings(settings, "diagrameditor/default");
+ ipw-> titleBlockProperties().toSettings(settings, "diagrameditor/default");
// proprietes par defaut des conducteurs
cpw -> conductorProperties().toSettings(settings, "diagrameditor/defaultconductor");
Modified: branches/0.3/sources/configpages.h
===================================================================
--- branches/0.3/sources/configpages.h 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/configpages.h 2010-12-20 02:45:36 UTC (rev 1132)
@@ -20,7 +20,7 @@
#include <QtGui>
class BorderPropertiesWidget;
class ConductorPropertiesWidget;
-class InsetPropertiesWidget;
+class TitleBlockPropertiesWidget;
class ExportPropertiesWidget;
/**
Cette classe abstraite contient les methodes que toutes les pages de
@@ -65,7 +65,7 @@
// attributs
public:
BorderPropertiesWidget *bpw; ///< Widget d'edition des dimensions du schema
- InsetPropertiesWidget *ipw; ///< Widget d'edition des proprietes par defaut du cartouche
+ TitleBlockPropertiesWidget *ipw; ///< Widget d'edition des proprietes par defaut du cartouche
ConductorPropertiesWidget *cpw; ///< Widget d'edition des proprietes par defaut des conducteurs
};
Modified: branches/0.3/sources/diagram.cpp
===================================================================
--- branches/0.3/sources/diagram.cpp 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/diagram.cpp 2010-12-20 02:45:36 UTC (rev 1132)
@@ -131,7 +131,7 @@
p -> drawPoints(points);
}
- if (use_border) border_and_inset.draw(p, margin, margin);
+ if (use_border) border_and_titleblock.draw(p, margin, margin);
p -> restore();
}
@@ -190,8 +190,8 @@
source_area = QRectF(
0.0,
0.0,
- border_and_inset.borderWidth () + 2.0 * margin,
- border_and_inset.borderHeight() + 2.0 * margin
+ border_and_titleblock.borderWidth () + 2.0 * margin,
+ border_and_titleblock.borderHeight() + 2.0 * margin
);
}
@@ -233,8 +233,8 @@
image_width = items_rect.width();
image_height = items_rect.height();
} else {
- image_width = border_and_inset.borderWidth();
- image_height = border_and_inset.borderHeight();
+ image_width = border_and_titleblock.borderWidth();
+ image_height = border_and_titleblock.borderHeight();
}
image_width += 2.0 * margin;
@@ -267,21 +267,21 @@
// proprietes du schema
if (whole_content) {
- if (!border_and_inset.author().isNull()) racine.setAttribute("author", border_and_inset.author());
- if (!border_and_inset.date().isNull()) racine.setAttribute("date", border_and_inset.date().toString("yyyyMMdd"));
- if (!border_and_inset.title().isNull()) racine.setAttribute("title", border_and_inset.title());
- if (!border_and_inset.fileName().isNull()) racine.setAttribute("filename", border_and_inset.fileName());
- if (!border_and_inset.folio().isNull()) racine.setAttribute("folio", border_and_inset.folio());
- racine.setAttribute("cols", border_and_inset.nbColumns());
- racine.setAttribute("colsize", QString("%1").arg(border_and_inset.columnsWidth()));
- racine.setAttribute("rows", border_and_inset.nbRows());
- racine.setAttribute("rowsize", QString("%1").arg(border_and_inset.rowsHeight()));
+ if (!border_and_titleblock.author().isNull()) racine.setAttribute("author", border_and_titleblock.author());
+ if (!border_and_titleblock.date().isNull()) racine.setAttribute("date", border_and_titleblock.date().toString("yyyyMMdd"));
+ if (!border_and_titleblock.title().isNull()) racine.setAttribute("title", border_and_titleblock.title());
+ if (!border_and_titleblock.fileName().isNull()) racine.setAttribute("filename", border_and_titleblock.fileName());
+ if (!border_and_titleblock.folio().isNull()) racine.setAttribute("folio", border_and_titleblock.folio());
+ racine.setAttribute("cols", border_and_titleblock.nbColumns());
+ racine.setAttribute("colsize", QString("%1").arg(border_and_titleblock.columnsWidth()));
+ racine.setAttribute("rows", border_and_titleblock.nbRows());
+ racine.setAttribute("rowsize", QString("%1").arg(border_and_titleblock.rowsHeight()));
// attribut datant de la version 0.1 - laisse pour retrocompatibilite
- racine.setAttribute("height", QString("%1").arg(border_and_inset.diagramHeight()));
- racine.setAttribute("displaycols", border_and_inset.columnsAreDisplayed() ? "true" : "false");
- racine.setAttribute("displayrows", border_and_inset.rowsAreDisplayed() ? "true" : "false");
- if (!inset_template_name_.isEmpty()) {
- racine.setAttribute("insettemplate", inset_template_name_);
+ racine.setAttribute("height", QString("%1").arg(border_and_titleblock.diagramHeight()));
+ racine.setAttribute("displaycols", border_and_titleblock.columnsAreDisplayed() ? "true" : "false");
+ racine.setAttribute("displayrows", border_and_titleblock.rowsAreDisplayed() ? "true" : "false");
+ if (!titleblock_template_name_.isEmpty()) {
+ racine.setAttribute("titleblocktemplate", titleblock_template_name_);
}
// type de conducteur par defaut
@@ -417,49 +417,49 @@
// lecture des attributs de ce schema
if (consider_informations) {
- border_and_inset.setAuthor(root.attribute("author"));
- border_and_inset.setTitle(root.attribute("title"));
- border_and_inset.setDate(QDate::fromString(root.attribute("date"), "yyyyMMdd"));
- border_and_inset.setFileName(root.attribute("filename"));
- border_and_inset.setFolio(root.attribute("folio"));
- if (root.hasAttribute("insettemplate") && project_) {
- QString inset_template_name = root.attribute("insettemplate");
- const InsetTemplate *inset_template = project_ -> getTemplateByName(inset_template_name);
- if (inset_template) {
- inset_template_name_ = inset_template_name;
- border_and_inset.setInsetTemplate(inset_template);
+ border_and_titleblock.setAuthor(root.attribute("author"));
+ border_and_titleblock.setTitle(root.attribute("title"));
+ border_and_titleblock.setDate(QDate::fromString(root.attribute("date"), "yyyyMMdd"));
+ border_and_titleblock.setFileName(root.attribute("filename"));
+ border_and_titleblock.setFolio(root.attribute("folio"));
+ if (root.hasAttribute("titleblocktemplate") && project_) {
+ QString titleblock_template_name = root.attribute("titleblocktemplate");
+ const TitleBlockTemplate *titleblock_template = project_ -> getTemplateByName(titleblock_template_name);
+ if (titleblock_template) {
+ titleblock_template_name_ = titleblock_template_name;
+ border_and_titleblock.setTitleBlockTemplate(titleblock_template);
}
}
bool ok;
// nombre de colonnes
int nb_cols = root.attribute("cols").toInt(&ok);
- if (ok) border_and_inset.setNbColumns(nb_cols);
+ if (ok) border_and_titleblock.setNbColumns(nb_cols);
// taille des colonnes
double col_size = root.attribute("colsize").toDouble(&ok);
- if (ok) border_and_inset.setColumnsWidth(col_size);
+ if (ok) border_and_titleblock.setColumnsWidth(col_size);
// retrocompatibilite : les schemas enregistres avec la 0.1 ont un attribut "height"
if (root.hasAttribute("rows") && root.hasAttribute("rowsize")) {
// nombre de lignes
int nb_rows = root.attribute("rows").toInt(&ok);
- if (ok) border_and_inset.setNbRows(nb_rows);
+ if (ok) border_and_titleblock.setNbRows(nb_rows);
// taille des lignes
double row_size = root.attribute("rowsize").toDouble(&ok);
- if (ok) border_and_inset.setRowsHeight(row_size);
+ if (ok) border_and_titleblock.setRowsHeight(row_size);
} else {
// hauteur du schema
double height = root.attribute("height").toDouble(&ok);
- if (ok) border_and_inset.setDiagramHeight(height);
+ if (ok) border_and_titleblock.setDiagramHeight(height);
}
// affichage des lignes et colonnes
- border_and_inset.displayColumns(root.attribute("displaycols") != "false");
- border_and_inset.displayRows(root.attribute("displayrows") != "false");
+ border_and_titleblock.displayColumns(root.attribute("displaycols") != "false");
+ border_and_titleblock.displayRows(root.attribute("displayrows") != "false");
- border_and_inset.adjustInsetToColumns();
+ border_and_titleblock.adjustTitleBlockToColumns();
// repere le permier element "defaultconductor"
for (QDomNode node = root.firstChild() ; !node.isNull() ; node = node.nextSibling()) {
@@ -806,8 +806,8 @@
QRectF(
margin,
margin,
- border_and_inset.borderWidth(),
- border_and_inset.borderHeight()
+ border_and_titleblock.borderWidth(),
+ border_and_titleblock.borderHeight()
)
);
}
@@ -816,7 +816,7 @@
@return le titre du cartouche
*/
QString Diagram::title() const {
- return(border_and_inset.title());
+ return(border_and_titleblock.title());
}
/**
@@ -912,8 +912,8 @@
// exporte les options de rendu en cours
ExportProperties old_properties;
old_properties.draw_grid = displayGrid();
- old_properties.draw_border = border_and_inset.borderIsDisplayed();
- old_properties.draw_inset = border_and_inset.insetIsDisplayed();
+ old_properties.draw_border = border_and_titleblock.borderIsDisplayed();
+ old_properties.draw_titleblock = border_and_titleblock.titleBlockIsDisplayed();
old_properties.draw_terminals = drawTerminals();
old_properties.draw_colored_conductors = drawColoredConductors();
old_properties.exported_area = useBorder() ? QET::BorderArea : QET::ElementsArea;
@@ -923,8 +923,8 @@
setDrawTerminals (new_properties.draw_terminals);
setDrawColoredConductors (new_properties.draw_colored_conductors);
setDisplayGrid (new_properties.draw_grid);
- border_and_inset.displayBorder(new_properties.draw_border);
- border_and_inset.displayInset (new_properties.draw_inset);
+ border_and_titleblock.displayBorder(new_properties.draw_border);
+ border_and_titleblock.displayTitleBlock (new_properties.draw_titleblock);
// retourne les anciennes options de rendu
return(old_properties);
@@ -939,8 +939,8 @@
// decale la position pour prendre en compte les marges en haut a gauche du schema
QPointF final_pos = pos - QPointF(margin, margin);
- // delegue le calcul au BorderInset
- DiagramPosition diagram_position = border_and_inset.convertPosition(final_pos);
+ // delegue le calcul au BorderTitleBlock
+ DiagramPosition diagram_position = border_and_titleblock.convertPosition(final_pos);
// embarque la position cartesienne
diagram_position.setPosition(pos);
Modified: branches/0.3/sources/diagram.h
===================================================================
--- branches/0.3/sources/diagram.h 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/diagram.h 2010-12-20 02:45:36 UTC (rev 1132)
@@ -19,7 +19,7 @@
#define DIAGRAM_H
#include <QtGui>
#include <QtXml>
-#include "borderinset.h"
+#include "bordertitleblock.h"
#include "conductorproperties.h"
#include "exportproperties.h"
#include "qgimanager.h"
@@ -57,14 +57,14 @@
/**
Represente les options possibles pour l'affichage du schema :
* EmptyBorder : N'afficher que la bordure
- * Inset : Afficher le cartouche
+ * TitleBlock : Afficher le cartouche
* Columns : Afficher les colonnes
*/
- enum BorderOptions { EmptyBorder, Inset, Columns };
+ enum BorderOptions { EmptyBorder, TitleBlock, Columns };
/// Proprietes par defaut des nouveaux conducteurs
ConductorProperties defaultConductorProperties;
/// Dimensions et cartouches du schema
- BorderInset border_and_inset;
+ BorderTitleBlock border_and_titleblock;
/// taille de la grille en abscisse
static const int xGrid;
/// taille de la grille en ordonnee
@@ -85,7 +85,7 @@
QDomDocument xml_document;
QETProject *project_;
bool read_only_;
- QString inset_template_name_;
+ QString titleblock_template_name_;
// methodes
protected:
@@ -249,9 +249,9 @@
@see BorderOptions
*/
inline void Diagram::setBorderOptions(Diagram::BorderOptions bo) {
- border_and_inset.displayBorder(!(bo & EmptyBorder));
- border_and_inset.displayColumns(bo & Columns);
- border_and_inset.displayInset(bo & Inset);
+ border_and_titleblock.displayBorder(!(bo & EmptyBorder));
+ border_and_titleblock.displayColumns(bo & Columns);
+ border_and_titleblock.displayTitleBlock(bo & TitleBlock);
}
/**
@@ -261,8 +261,8 @@
*/
inline Diagram::BorderOptions Diagram::borderOptions() {
BorderOptions retour = EmptyBorder;
- if (border_and_inset.insetIsDisplayed()) retour = (BorderOptions)(retour|Inset);
- if (border_and_inset.columnsAreDisplayed()) retour = (BorderOptions)(retour|Columns);
+ if (border_and_titleblock.titleBlockIsDisplayed()) retour = (BorderOptions)(retour|TitleBlock);
+ if (border_and_titleblock.columnsAreDisplayed()) retour = (BorderOptions)(retour|Columns);
return(retour);
}
Modified: branches/0.3/sources/diagramcommands.cpp
===================================================================
--- branches/0.3/sources/diagramcommands.cpp 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/diagramcommands.cpp 2010-12-20 02:45:36 UTC (rev 1132)
@@ -828,32 +828,32 @@
@param new_ip Nouvelles proprietes du cartouche
@param parent QUndoCommand parent
*/
-ChangeInsetCommand::ChangeInsetCommand(
+ChangeTitleBlockCommand::ChangeTitleBlockCommand(
Diagram *d,
- const InsetProperties &old_ip,
- const InsetProperties &new_ip,
+ const TitleBlockProperties &old_ip,
+ const TitleBlockProperties &new_ip,
QUndoCommand *parent
) :
QUndoCommand(QObject::tr("modifier le cartouche", "undo caption"), parent),
diagram(d),
- old_inset(old_ip),
- new_inset(new_ip)
+ old_titleblock(old_ip),
+ new_titleblock(new_ip)
{
}
/// Destructeur
-ChangeInsetCommand::~ChangeInsetCommand() {
+ChangeTitleBlockCommand::~ChangeTitleBlockCommand() {
}
/// Annule la modification de cartouche
-void ChangeInsetCommand::undo() {
- diagram -> border_and_inset.importInset(old_inset);
+void ChangeTitleBlockCommand::undo() {
+ diagram -> border_and_titleblock.importTitleBlock(old_titleblock);
diagram -> invalidate(diagram -> border());
}
/// Refait la modification de cartouche
-void ChangeInsetCommand::redo() {
- diagram -> border_and_inset.importInset(new_inset);
+void ChangeTitleBlockCommand::redo() {
+ diagram -> border_and_titleblock.importTitleBlock(new_titleblock);
diagram -> invalidate(diagram -> border());
}
@@ -878,12 +878,12 @@
/// Annule les changements apportes au schema
void ChangeBorderCommand::undo() {
- diagram -> border_and_inset.importBorder(old_properties);
+ diagram -> border_and_titleblock.importBorder(old_properties);
}
/// Refait les changements apportes au schema
void ChangeBorderCommand::redo() {
- diagram -> border_and_inset.importBorder(new_properties);
+ diagram -> border_and_titleblock.importBorder(new_properties);
}
/**
Modified: branches/0.3/sources/diagramcommands.h
===================================================================
--- branches/0.3/sources/diagramcommands.h 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/diagramcommands.h 2010-12-20 02:45:36 UTC (rev 1132)
@@ -22,7 +22,7 @@
#include "conductor.h"
#include "conductorproperties.h"
#include "diagramcontent.h"
-#include "insetproperties.h"
+#include "titleblockproperties.h"
#include "qet.h"
class Diagram;
class DiagramTextItem;
@@ -419,13 +419,13 @@
/**
Cette classe represente l'action de modifier les informations du cartouche d'un schema
*/
-class ChangeInsetCommand : public QUndoCommand {
+class ChangeTitleBlockCommand : public QUndoCommand {
// constructeurs, destructeur
public:
- ChangeInsetCommand(Diagram *, const InsetProperties &, const InsetProperties &, QUndoCommand * = 0);
- virtual ~ChangeInsetCommand();
+ ChangeTitleBlockCommand(Diagram *, const TitleBlockProperties &, const TitleBlockProperties &, QUndoCommand * = 0);
+ virtual ~ChangeTitleBlockCommand();
private:
- ChangeInsetCommand(const ChangeInsetCommand &);
+ ChangeTitleBlockCommand(const ChangeTitleBlockCommand &);
// methodes
public:
@@ -437,9 +437,9 @@
/// schema modifie
Diagram *diagram;
/// proprietes avant changement
- InsetProperties old_inset;
+ TitleBlockProperties old_titleblock;
/// proprietes apres changement
- InsetProperties new_inset;
+ TitleBlockProperties new_titleblock;
};
/**
Modified: branches/0.3/sources/diagramcontext.h
===================================================================
--- branches/0.3/sources/diagramcontext.h 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/diagramcontext.h 2010-12-20 02:45:36 UTC (rev 1132)
@@ -22,7 +22,7 @@
#include <QVariant>
/**
This class represents a diagram context, i.e. the data (a list of key/value
- pairs) of a diagram at a given time. It is notably used by inset templates
+ pairs) of a diagram at a given time. It is notably used by titleblock templates
to fetch the informations they need to do their rendering.
*/
class DiagramContext {
Modified: branches/0.3/sources/diagramview.cpp
===================================================================
--- branches/0.3/sources/diagramview.cpp 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/diagramview.cpp 2010-12-20 02:45:36 UTC (rev 1132)
@@ -26,7 +26,7 @@
#include "conductortextitem.h"
#include "elementtextitem.h"
#include "independenttextitem.h"
-#include "insetpropertieswidget.h"
+#include "titleblockpropertieswidget.h"
#include "qetapp.h"
#include "qetproject.h"
#include "borderpropertieswidget.h"
@@ -67,9 +67,9 @@
connect(scene, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
connect(scene, SIGNAL(readOnlyChanged(bool)), this, SLOT(applyReadOnly()));
- connect(&(scene -> border_and_inset), SIGNAL(borderChanged(QRectF, QRectF)), this, SLOT(adjustSceneRect()));
- connect(&(scene -> border_and_inset), SIGNAL(displayChanged()), this, SLOT(adjustSceneRect()));
- connect(&(scene -> border_and_inset), SIGNAL(diagramTitleChanged(const QString &)), this, SLOT(updateWindowTitle()));
+ connect(&(scene -> border_and_titleblock), SIGNAL(borderChanged(QRectF, QRectF)), this, SLOT(adjustSceneRect()));
+ connect(&(scene -> border_and_titleblock), SIGNAL(displayChanged()), this, SLOT(adjustSceneRect()));
+ connect(&(scene -> border_and_titleblock), SIGNAL(diagramTitleChanged(const QString &)), this, SLOT(updateWindowTitle()));
connect(&(scene -> undoStack()), SIGNAL(cleanChanged(bool)), this, SLOT(updateWindowTitle()));
connect(this, SIGNAL(aboutToAddElement()), this, SLOT(addDroppedElement()), Qt::QueuedConnection);
@@ -412,8 +412,8 @@
bool diagram_is_read_only = scene -> isReadOnly();
// recupere le cartouche et les dimensions du schema
- InsetProperties inset = scene -> border_and_inset.exportInset();
- BorderProperties border = scene -> border_and_inset.exportBorder();
+ TitleBlockProperties titleblock = scene -> border_and_titleblock.exportTitleBlock();
+ BorderProperties border = scene -> border_and_titleblock.exportBorder();
// construit le dialogue
QDialog popup(diagramEditor());
@@ -426,8 +426,8 @@
BorderPropertiesWidget *border_infos = new BorderPropertiesWidget(border, &popup);
border_infos -> setReadOnly(diagram_is_read_only);
- InsetPropertiesWidget *inset_infos = new InsetPropertiesWidget(inset, false, &popup);
- inset_infos -> setReadOnly(diagram_is_read_only);
+ TitleBlockPropertiesWidget *titleblock_infos = new TitleBlockPropertiesWidget(titleblock, false, &popup);
+ titleblock_infos -> setReadOnly(diagram_is_read_only);
// boutons
QDialogButtonBox boutons(diagram_is_read_only ? QDialogButtonBox::Ok : QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
@@ -437,16 +437,16 @@
// ajout dans une disposition verticale
QVBoxLayout layout_v(&popup);
layout_v.addWidget(border_infos);
- layout_v.addWidget(inset_infos);
+ layout_v.addWidget(titleblock_infos);
layout_v.addStretch();
layout_v.addWidget(&boutons);
// si le dialogue est accepte
if (popup.exec() == QDialog::Accepted && !diagram_is_read_only) {
- InsetProperties new_inset = inset_infos -> insetProperties();
+ TitleBlockProperties new_titleblock = titleblock_infos -> titleBlockProperties();
BorderProperties new_border = border_infos -> borderProperties();
// s'il y a des modifications au cartouche
- if (new_inset != inset) {
- scene -> undoStack().push(new ChangeInsetCommand(scene, inset, new_inset));
+ if (new_titleblock != titleblock) {
+ scene -> undoStack().push(new ChangeTitleBlockCommand(scene, titleblock, new_titleblock));
}
// s'il y a des modifications aux dimensions du schema
@@ -501,8 +501,8 @@
*/
void DiagramView::addColumn() {
if (scene -> isReadOnly()) return;
- BorderProperties old_bp = scene -> border_and_inset.exportBorder();
- BorderProperties new_bp = scene -> border_and_inset.exportBorder();
+ BorderProperties old_bp = scene -> border_and_titleblock.exportBorder();
+ BorderProperties new_bp = scene -> border_and_titleblock.exportBorder();
new_bp.columns_count += 1;
scene -> undoStack().push(new ChangeBorderCommand(scene, old_bp, new_bp));
}
@@ -512,8 +512,8 @@
*/
void DiagramView::removeColumn() {
if (scene -> isReadOnly()) return;
- BorderProperties old_bp = scene -> border_and_inset.exportBorder();
- BorderProperties new_bp = scene -> border_and_inset.exportBorder();
+ BorderProperties old_bp = scene -> border_and_titleblock.exportBorder();
+ BorderProperties new_bp = scene -> border_and_titleblock.exportBorder();
new_bp.columns_count -= 1;
scene -> undoStack().push(new ChangeBorderCommand(scene, old_bp, new_bp));
}
@@ -523,8 +523,8 @@
*/
void DiagramView::addRow() {
if (scene -> isReadOnly()) return;
- BorderProperties old_bp = scene -> border_and_inset.exportBorder();
- BorderProperties new_bp = scene -> border_and_inset.exportBorder();
+ BorderProperties old_bp = scene -> border_and_titleblock.exportBorder();
+ BorderProperties new_bp = scene -> border_and_titleblock.exportBorder();
new_bp.rows_count += 1;
scene -> undoStack().push(new ChangeBorderCommand(scene, old_bp, new_bp));
}
@@ -534,8 +534,8 @@
*/
void DiagramView::removeRow() {
if (scene -> isReadOnly()) return;
- BorderProperties old_bp = scene -> border_and_inset.exportBorder();
- BorderProperties new_bp = scene -> border_and_inset.exportBorder();
+ BorderProperties old_bp = scene -> border_and_titleblock.exportBorder();
+ BorderProperties new_bp = scene -> border_and_titleblock.exportBorder();
new_bp.rows_count -= 1;
scene -> undoStack().push(new ChangeBorderCommand(scene, old_bp, new_bp));
}
@@ -987,14 +987,14 @@
Gere les double-clics sur le schema
*/
void DiagramView::mouseDoubleClickEvent(QMouseEvent *e) {
- BorderInset &bi = scene -> border_and_inset;
+ BorderTitleBlock &bi = scene -> border_and_titleblock;
// recupere le rectangle corespondant au cartouche
- QRectF inset_rect(
+ QRectF titleblock_rect(
Diagram::margin,
Diagram::margin + bi.diagramHeight(),
- bi.insetWidth(),
- bi.insetHeight()
+ bi.titleBlockWidth(),
+ bi.titleBlockHeight()
);
// recupere le rectangle correspondant aux en-tetes des colonnes
@@ -1025,7 +1025,7 @@
} else {
QGraphicsView::mouseDoubleClickEvent(e);
}
- } else if (inset_rect.contains(click_pos) || columns_rect.contains(click_pos) || rows_rect.contains(click_pos)) {
+ } else if (titleblock_rect.contains(click_pos) || columns_rect.contains(click_pos) || rows_rect.contains(click_pos)) {
// edite les proprietes du schema
editDiagramProperties();
} else {
Modified: branches/0.3/sources/exportproperties.cpp
===================================================================
--- branches/0.3/sources/exportproperties.cpp 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/exportproperties.cpp 2010-12-20 02:45:36 UTC (rev 1132)
@@ -31,7 +31,7 @@
format("PNG"),
draw_grid(false),
draw_border(true),
- draw_inset(true),
+ draw_titleblock(true),
draw_terminals(false),
draw_colored_conductors(true),
exported_area(QET::BorderArea)
@@ -54,7 +54,7 @@
settings.setValue(prefix + "format", format);
settings.setValue(prefix + "drawgrid", draw_grid);
settings.setValue(prefix + "drawborder", draw_border);
- settings.setValue(prefix + "drawinset", draw_inset);
+ settings.setValue(prefix + "drawtitleblock", draw_titleblock);
settings.setValue(prefix + "drawterminals", draw_terminals);
settings.setValue(prefix + "drawcoloredconductors", draw_colored_conductors);
settings.setValue(prefix + "area", QET::diagramAreaToString(exported_area));
@@ -74,7 +74,7 @@
draw_grid = settings.value(prefix + "drawgrid", false).toBool();
draw_border = settings.value(prefix + "drawborder", true ).toBool();
- draw_inset = settings.value(prefix + "drawinset", true ).toBool();
+ draw_titleblock = settings.value(prefix + "drawtitleblock", true ).toBool();
draw_terminals = settings.value(prefix + "drawterminals", false).toBool();
draw_colored_conductors = settings.value(prefix + "drawcoloredconductors", true ).toBool();
Modified: branches/0.3/sources/exportproperties.h
===================================================================
--- branches/0.3/sources/exportproperties.h 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/exportproperties.h 2010-12-20 02:45:36 UTC (rev 1132)
@@ -41,7 +41,7 @@
QString format; ///< Quel format d'image faut-il utiliser ?
bool draw_grid; ///< Faut-il dessiner la grille ?
bool draw_border; ///< Faut-il dessiner le cadre ?
- bool draw_inset; ///< Faut-il dessiner le cartouche ?
+ bool draw_titleblock; ///< Faut-il dessiner le cartouche ?
bool draw_terminals; ///< Faut-il dessiner les bornes ?
bool draw_colored_conductors; ///< Faut-il respecter les couleurs des conducteurs ?
QET::DiagramArea exported_area; ///< Zone du schema a exporter
Modified: branches/0.3/sources/exportpropertieswidget.cpp
===================================================================
--- branches/0.3/sources/exportpropertieswidget.cpp 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/exportpropertieswidget.cpp 2010-12-20 02:45:36 UTC (rev 1132)
@@ -50,7 +50,7 @@
export_properties.format = format -> itemData(format -> currentIndex()).toString();
export_properties.draw_grid = draw_grid -> isChecked();
export_properties.draw_border = draw_border -> isChecked();
- export_properties.draw_inset = draw_inset -> isChecked();
+ export_properties.draw_titleblock = draw_titleblock -> isChecked();
export_properties.draw_terminals = draw_terminals -> isChecked();
export_properties.draw_colored_conductors = draw_colored_conductors -> isChecked();
export_properties.exported_area = export_border -> isChecked() ? QET::BorderArea : QET::ElementsArea;
@@ -70,7 +70,7 @@
draw_grid -> setChecked(export_properties.draw_grid);
draw_border -> setChecked(export_properties.draw_border);
- draw_inset -> setChecked(export_properties.draw_inset);
+ draw_titleblock -> setChecked(export_properties.draw_titleblock);
draw_terminals -> setChecked(export_properties.draw_terminals);
draw_colored_conductors -> setChecked(export_properties.draw_colored_conductors);
@@ -169,8 +169,8 @@
optionshlayout -> addWidget(draw_border, 1, 0);
// dessiner le cartouche
- draw_inset = new QCheckBox(tr("Dessiner le cartouche"), groupbox_options);
- optionshlayout -> addWidget(draw_inset, 2, 0);
+ draw_titleblock = new QCheckBox(tr("Dessiner le cartouche"), groupbox_options);
+ optionshlayout -> addWidget(draw_titleblock, 2, 0);
// dessiner les bornes
draw_terminals = new QCheckBox(tr("Dessiner les bornes"), groupbox_options);
@@ -190,8 +190,8 @@
setTabOrder(format, export_border);
setTabOrder(export_border, draw_border);
setTabOrder(draw_border, draw_grid);
- setTabOrder(draw_grid, draw_inset);
- setTabOrder(draw_inset, draw_terminals);
+ setTabOrder(draw_grid, draw_titleblock);
+ setTabOrder(draw_titleblock, draw_terminals);
setTabOrder(draw_terminals, draw_colored_conductors);
// connexion du bouton permettant le choix du repertoire
@@ -202,7 +202,7 @@
connect(exported_content_choices, SIGNAL(buttonClicked(QAbstractButton *)), this, SIGNAL(exportedAreaChanged()));
connect(draw_grid, SIGNAL(stateChanged(int)), this, SIGNAL(optionChanged()));
connect(draw_border, SIGNAL(stateChanged(int)), this, SIGNAL(optionChanged()));
- connect(draw_inset, SIGNAL(stateChanged(int)), this, SIGNAL(optionChanged()));
+ connect(draw_titleblock, SIGNAL(stateChanged(int)), this, SIGNAL(optionChanged()));
connect(draw_terminals, SIGNAL(stateChanged(int)), this, SIGNAL(optionChanged()));
connect(draw_colored_conductors, SIGNAL(stateChanged(int)), this, SIGNAL(optionChanged()));
}
Modified: branches/0.3/sources/exportpropertieswidget.h
===================================================================
--- branches/0.3/sources/exportpropertieswidget.h 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/exportpropertieswidget.h 2010-12-20 02:45:36 UTC (rev 1132)
@@ -61,7 +61,7 @@
QComboBox *format;
QCheckBox *draw_grid;
QCheckBox *draw_border;
- QCheckBox *draw_inset;
+ QCheckBox *draw_titleblock;
QCheckBox *draw_terminals;
QCheckBox *draw_colored_conductors;
QRadioButton *export_border;
Modified: branches/0.3/sources/hotspoteditor.cpp
===================================================================
--- branches/0.3/sources/hotspoteditor.cpp 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/hotspoteditor.cpp 2010-12-20 02:45:36 UTC (rev 1132)
@@ -53,17 +53,17 @@
sb_hotspot_y -> setSingleStep(10);
diagram_scene = new Diagram();
- diagram_scene -> border_and_inset.setColumnsWidth(50.0);
- diagram_scene -> border_and_inset.setNbColumns(3);
- diagram_scene -> border_and_inset.setRowsHeight(60.0);
- diagram_scene -> border_and_inset.setNbRows(2);
- diagram_scene -> border_and_inset.displayRows(false);
- diagram_scene -> border_and_inset.displayInset(false);
+ diagram_scene -> border_and_titleblock.setColumnsWidth(50.0);
+ diagram_scene -> border_and_titleblock.setNbColumns(3);
+ diagram_scene -> border_and_titleblock.setRowsHeight(60.0);
+ diagram_scene -> border_and_titleblock.setNbRows(2);
+ diagram_scene -> border_and_titleblock.displayRows(false);
+ diagram_scene -> border_and_titleblock.displayTitleBlock(false);
diagram_view = new QGraphicsView(diagram_scene);
diagram_view -> setMinimumSize(
- qRound(diagram_scene -> border_and_inset.diagramWidth() + (3 * Diagram::margin)),
- qRound(diagram_scene -> border_and_inset.diagramHeight() + (3 * Diagram::margin))
+ qRound(diagram_scene -> border_and_titleblock.diagramWidth() + (3 * Diagram::margin)),
+ qRound(diagram_scene -> border_and_titleblock.diagramHeight() + (3 * Diagram::margin))
);
diagram_view -> setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
diagram_view -> setResizeAnchor(QGraphicsView::AnchorUnderMouse);
Deleted: branches/0.3/sources/insetcell.h
===================================================================
--- branches/0.3/sources/insetcell.h 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/insetcell.h 2010-12-20 02:45:36 UTC (rev 1132)
@@ -1,41 +0,0 @@
-/*
- Copyright 2006-2010 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 <http://www.gnu.org/licenses/>.
-*/
-#ifndef INSET_CELL_H
-#define INSET_CELL_H
-/**
- This class is a container for the various parameters of an inset cell
- @see InsetColumnLength
-*/
-class InsetCell {
- public:
- InsetCell();
- QString toString() const;
- bool is_null;
- int num_row;
- int num_col;
- int row_span;
- int col_span;
- InsetCell *spanner_cell;
- QString value_name;
- QString value;
- QString label;
- bool display_label;
- int alignment;
- QString logo_reference;
-};
-#endif
Deleted: branches/0.3/sources/insetproperties.cpp
===================================================================
--- branches/0.3/sources/insetproperties.cpp 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/insetproperties.cpp 2010-12-20 02:45:36 UTC (rev 1132)
@@ -1,154 +0,0 @@
-/*
- Copyright 2006-2010 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 <http://www.gnu.org/licenses/>.
-*/
-#include "insetproperties.h"
-
-/**
- Constructeur. Initialise un objet InsetProperties avec tous les champs
- vides (date vide + useDate a UseDateValue).
-*/
-InsetProperties::InsetProperties() :
- date(),
- useDate(UseDateValue)
-{
-}
-
-/**
- Destructeur
-*/
-InsetProperties::~InsetProperties() {
-}
-
-/**
- @param ip autre conteneur InsetProperties
- @return true si ip et ce conteneur sont identiques, false sinon
-*/
-bool InsetProperties::operator==(const InsetProperties &ip) {
- return(
- ip.title == title &&\
- ip.author == author &&\
- ip.date == date &&\
- ip.filename == filename &&\
- ip.folio == folio
- );
-}
-
-/**
- @param ip autre conteneur InsetProperties
- @return false si ip et ce conteneur sont identiques, true sinon
-*/
-bool InsetProperties::operator!=(const InsetProperties &ip) {
- return(!(*this == ip));
-}
-
-
-/**
- Exporte le cartouche sous formes d'attributs XML ajoutes a l'element e.
- @param e Element XML auquel seront ajoutes des attributs
-*/
-void InsetProperties::toXml(QDomElement &e) const {
- e.setAttribute("author", author);
- e.setAttribute("title", title);
- e.setAttribute("filename", filename);
- e.setAttribute("folio", folio);
- e.setAttribute("date", exportDate());
-}
-
-/**
- Importe le cartouche a partir des attributs XML de l'element e
- @param e Element XML dont les attributs seront lus
-*/
-void InsetProperties::fromXml(QDomElement &e) {
- if (e.hasAttribute("author")) author = e.attribute("author");
- if (e.hasAttribute("title")) title = e.attribute("title");
- if (e.hasAttribute("filename")) filename = e.attribute("filename");
- if (e.hasAttribute("folio")) folio = e.attribute("folio");
- if (e.hasAttribute("date")) setDateFromString(e.attribute("date"));
-}
-
-/**
- Exporte le cartouche dans une configuration.
- @param settings Parametres a ecrire
- @param prefix prefixe a ajouter devant les noms des parametres
-*/
-void InsetProperties::toSettings(QSettings &settings, const QString &prefix) const {
- settings.setValue(prefix + "title", title);
- settings.setValue(prefix + "author", author);
- settings.setValue(prefix + "filename", filename);
- settings.setValue(prefix + "folio", folio);
- settings.setValue(prefix + "date", exportDate());
-}
-
-/**
- Importe le cartouche depuis une configuration.
- @param settings Parametres a lire
- @param prefix prefixe a ajouter devant les noms des parametres
-*/
-void InsetProperties::fromSettings(QSettings &settings, const QString &prefix) {
- title = settings.value(prefix + "title").toString();
- author = settings.value(prefix + "author").toString();
- filename = settings.value(prefix + "filename").toString();
- folio = settings.value(prefix + "folio", "%id/%total").toString();
- setDateFromString(settings.value(prefix + "date").toString());
-}
-
-/**
- @return La date a utiliser
-*/
-QDate InsetProperties::finalDate() const {
- if (useDate == UseDateValue) {
- return(date);
- } else {
- return(QDate::currentDate());
- }
-}
-
-/**
- @return une chaine de caracteres decrivant comment gerer la date dans le
- cartouche : la chaine peut valoir :
- * null pour ne pas afficher de date
- * now pour afficher la date courante (a la creation du schema)
- * une date au format yyyyMMdd pour utiliser une date fixe
-*/
-QString InsetProperties::exportDate() const {
- QString date_setting_value;
- if (useDate == UseDateValue) {
- if (date.isNull()) date_setting_value = "null";
- else date_setting_value = date.toString("yyyyMMdd");
- } else {
- date_setting_value = "now";
- }
- return(date_setting_value);
-}
-
-/**
- Charge les attributs date et useDate a partir d'une chaine de caracteres.
- @param date_string Chaine de caracteres a analyser
- @see exportDate
-*/
-void InsetProperties::setDateFromString(const QString &date_string) {
- if (date_string == "now") {
- date = QDate::currentDate();
- useDate = CurrentDate;
- } else if (date_string.isEmpty() || date_string == "null") {
- date = QDate();
- useDate = UseDateValue;
- } else {
- date = QDate::fromString(date_string, "yyyyMMdd");
- useDate = UseDateValue;
- }
-}
Deleted: branches/0.3/sources/insetproperties.h
===================================================================
--- branches/0.3/sources/insetproperties.h 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/insetproperties.h 2010-12-20 02:45:36 UTC (rev 1132)
@@ -1,58 +0,0 @@
-/*
- Copyright 2006-2010 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 <http://www.gnu.org/licenses/>.
-*/
-#ifndef INSET_PROPERTIES_H
-#define INSET_PROPERTIES_H
-#include <QtCore>
-#include <QtXml>
-/**
- Cette classe est un conteneur pour les proprietes d'un cartouche de schema
- : titre, auteur, date, nom de fichier et folio
-*/
-class InsetProperties {
- public:
- InsetProperties();
- virtual ~InsetProperties();
- /// Specifie comment gerer la date
- enum DateManagement {
- UseDateValue, ///< utilise l'attribut date
- CurrentDate ///< utilise la date courante
- };
-
- bool operator==(const InsetProperties &);
- bool operator!=(const InsetProperties &);
-
- void toXml(QDomElement &) const;
- void fromXml(QDomElement &);
- void toSettings(QSettings &, const QString & = QString()) const;
- void fromSettings(QSettings &, const QString & = QString());
-
- QDate finalDate() const ;
-
- // attributs
- QString title; ///< Titre affiche par le cartouche
- QString author; ///< Auteur affiche par le cartouche
- QDate date; ///< Date affichee par le cartouche ; si la date est nulle, le champ reste vide
- QString filename; ///< Nom de fichier affiche par le cartouche
- QString folio; ///< Folio affiche par le cartouche
- DateManagement useDate; ///< Indique s'il faut utiliser ou non l'attribut date
-
- private:
- QString exportDate() const;
- void setDateFromString(const QString &);
-};
-#endif
Deleted: branches/0.3/sources/insetpropertieswidget.cpp
===================================================================
--- branches/0.3/sources/insetpropertieswidget.cpp 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/insetpropertieswidget.cpp 2010-12-20 02:45:36 UTC (rev 1132)
@@ -1,177 +0,0 @@
-/*
- Copyright 2006-2010 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 <http://www.gnu.org/licenses/>.
-*/
-#include "insetpropertieswidget.h"
-#include "qetapp.h"
-
-/**
- Constructeur
- @param inset InsetProperties a afficher
- @param current true pour afficher l'option "Date courante"
- @param parent QWidget parent
-*/
-InsetPropertiesWidget::InsetPropertiesWidget(const InsetProperties &inset, bool current, QWidget *parent) : QWidget(parent), display_current_date(false) {
-
- QVBoxLayout *this_layout = new QVBoxLayout(this);
- this_layout -> setContentsMargins(0, 0, 0, 0);
- QGroupBox *inset_infos = new QGroupBox(tr("Informations du cartouche"), this);
- inset_infos -> setMinimumSize(300, 330);
- this_layout -> addWidget(inset_infos);
-
- inset_title = new QLineEdit(this);
- inset_author = new QLineEdit(this);
-
- QButtonGroup *date_policy_group = new QButtonGroup(this);
- inset_no_date = new QRadioButton(tr("Pas de date"), this);
- inset_current_date = new QRadioButton(tr("Date courante"), this);
- inset_fixed_date = new QRadioButton(tr("Date fixe : "), this);
- date_policy_group -> addButton(inset_no_date);
- date_policy_group -> addButton(inset_current_date);
- date_policy_group -> addButton(inset_fixed_date);
- inset_date = new QDateEdit(QDate::currentDate(), this);
- inset_date -> setEnabled(inset_fixed_date -> isChecked());
- inset_current_date -> setVisible(display_current_date);
- connect(inset_fixed_date, SIGNAL(toggled(bool)), inset_date, SLOT(setEnabled(bool)));
- inset_date -> setCalendarPopup(true);
-
- QGridLayout *layout_date = new QGridLayout();
- layout_date -> addWidget(inset_no_date, 0, 0);
- layout_date -> addWidget(inset_current_date, 1, 0);
- layout_date -> addWidget(inset_fixed_date, 2, 0);
- layout_date -> addWidget(inset_date, 2, 1);
- layout_date -> setColumnStretch(0, 1);
- layout_date -> setColumnStretch(1, 500);
-
- inset_filename = new QLineEdit(this);
- inset_folio = new QLineEdit(this);
- QLabel *folio_tip = new QLabel(
- tr(
- "Les variables suivantes sont utilisables dans le champ Folio :\n"
- " - %id : num\351ro du sch\351ma courant dans le projet\n"
- " - %total : nombre total de sch\351mas dans le projet"
- )
- );
- folio_tip -> setWordWrap(true);
-
- QGridLayout *layout_champs = new QGridLayout(inset_infos);
-
- layout_champs -> addWidget(new QLabel(tr("Titre : ")), 0, 0);
- layout_champs -> addWidget(inset_title, 0, 1);
- layout_champs -> addWidget(new QLabel(tr("Auteur : ")), 1, 0);
- layout_champs -> addWidget(inset_author, 1, 1);
- layout_champs -> addWidget(new QLabel(tr("Date : ")), 2, 0, Qt::AlignTop);
- layout_champs -> addLayout(layout_date, 2, 1);
- layout_champs -> addWidget(new QLabel(tr("Fichier : ")), 3, 0);
- layout_champs -> addWidget(inset_filename, 3, 1);
- layout_champs -> addWidget(new QLabel(tr("Folio : ")), 4, 0);
- layout_champs -> addWidget(inset_folio, 4, 1);
- layout_champs -> addWidget(folio_tip, 5, 1, Qt::AlignTop);
- layout_champs -> setRowStretch(5, 500);
-
- inset_current_date -> setVisible(display_current_date = current);
- setInsetProperties(inset);
- setLayout(this_layout);
-}
-
-/// Destructeur
-InsetPropertiesWidget::~InsetPropertiesWidget() {
-}
-
-/**
- @return Les proprietes affichees par le widget
-*/
-InsetProperties InsetPropertiesWidget::insetProperties() const {
- InsetProperties prop;
- prop.title = inset_title -> text();
- prop.author = inset_author -> text();
- prop.filename = inset_filename -> text();
- prop.folio = inset_folio -> text();
- if (inset_no_date -> isChecked()) {
- prop.useDate = InsetProperties::UseDateValue;
- prop.date = QDate();
- } else if (inset_fixed_date -> isChecked()) {
- prop.useDate = InsetProperties::UseDateValue;
- prop.date = inset_date -> date();
- } else if (display_current_date && inset_current_date -> isChecked()) {
- prop.useDate = InsetProperties::CurrentDate;
- prop.date = QDate::currentDate();
- }
- return(prop);
-}
-
-/**
- Specifie les proprietes que le widget doit afficher
- @param inset nouvelles proprietes affichees par le widget
-*/
-void InsetPropertiesWidget::setInsetProperties(const InsetProperties &inset) {
- inset_title -> setText(inset.title);
- inset_author -> setText(inset.author);
- inset_filename -> setText(inset.filename);
- inset_folio -> setText(inset.folio);
- if (display_current_date) {
- if (inset.useDate == InsetProperties::CurrentDate) {
- inset_current_date -> setChecked(true);
- } else {
- if (inset.date.isNull()) {
- inset_no_date -> setChecked(true);
- } else {
- inset_fixed_date -> setChecked(true);
- inset_date -> setDate(inset.date);
- }
- }
- } else {
- if (inset.useDate == InsetProperties::CurrentDate) {
- inset_fixed_date -> setChecked(true);
- inset_date -> setDate(QDate::currentDate());
- } else {
- if (inset.date.isNull()) {
- inset_no_date -> setChecked(true);
- } else {
- inset_fixed_date -> setChecked(true);
- inset_date -> setDate(inset.date);
- }
- }
- }
-}
-
-/**
- @return true si le widget affiche la proposition "Date courante", false sinon
-*/
-bool InsetPropertiesWidget::displayCurrentDate() const {
- return(display_current_date);
-}
-
-/**
- @return true si ce widget est en lecture seule, false sinon
-*/
-bool InsetPropertiesWidget::isReadOnly() const {
- return(inset_title -> isReadOnly());
-}
-
-/**
- @param ro true pour passer ce widget en lecture seule, false sinon
-*/
-void InsetPropertiesWidget::setReadOnly(bool ro) {
- inset_title -> setReadOnly(ro);
- inset_author -> setReadOnly(ro);
- inset_date -> setReadOnly(ro);
- inset_filename -> setReadOnly(ro);
- inset_folio -> setReadOnly(ro);
- inset_no_date -> setDisabled(ro);
- inset_current_date -> setDisabled(ro);
- inset_fixed_date -> setDisabled(ro);
-}
Deleted: branches/0.3/sources/insetpropertieswidget.h
===================================================================
--- branches/0.3/sources/insetpropertieswidget.h 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/insetpropertieswidget.h 2010-12-20 02:45:36 UTC (rev 1132)
@@ -1,55 +0,0 @@
-/*
- Copyright 2006-2010 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 <http://www.gnu.org/licenses/>.
-*/
-#ifndef INSET_PROPERTIES_WIDGET_H
-#define INSET_PROPERTIES_WIDGET_H
-#include <QtGui>
-#include "insetproperties.h"
-/**
- Ce widget permet d'editer un objet InsetProperties, c'est-a-dire les
- valeurs affichees par le cartouche d'un schema.
-*/
-class InsetPropertiesWidget : public QWidget {
- Q_OBJECT
- // constructeurs, destructeur
- public:
- InsetPropertiesWidget(const InsetProperties &inset = InsetProperties(), bool = false, QWidget * = 0);
- virtual ~InsetPropertiesWidget();
- private:
- InsetPropertiesWidget(const InsetPropertiesWidget &);
-
- // methodes
- public:
- InsetProperties insetProperties() const;
- void setInsetProperties(const InsetProperties &);
- bool displayCurrentDate() const;
- bool isReadOnly() const;
- void setReadOnly(bool);
-
- // attributs
- private:
- QLineEdit *inset_title;
- QLineEdit *inset_author;
- QDateEdit *inset_date;
- QLineEdit *inset_filename;
- QLineEdit *inset_folio;
- QRadioButton *inset_no_date;
- QRadioButton *inset_current_date;
- QRadioButton *inset_fixed_date;
- bool display_current_date;
-};
-#endif
Deleted: branches/0.3/sources/insettemplate.cpp
===================================================================
--- branches/0.3/sources/insettemplate.cpp 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/insettemplate.cpp 2010-12-20 02:45:36 UTC (rev 1132)
@@ -1,580 +0,0 @@
-/*
- Copyright 2006-2010 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 <http://www.gnu.org/licenses/>.
-*/
-#include "insettemplate.h"
-#include "qet.h"
-#include "qetapp.h"
-
-/**
- Constructor
- @param parent parent QObject
-*/
-InsetTemplate::InsetTemplate(QObject *parent) :
- QObject(parent)
-{
-}
-
-/**
- Destructor
-*/
-InsetTemplate::~InsetTemplate() {
- loadLogos(QDomElement(), true);
-}
-
-/**
- @param filepath A file path to read the template from.
- @return true if the reading succeeds, false otherwise.
-*/
-bool InsetTemplate::loadFromXmlFile(const QString &filepath) {
- // opens the file
- QFile template_file(filepath);
- if (!template_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
- return(false);
- }
-
- // parses its content as XML
- bool xml_parsing = xml_description_.setContent(&template_file);
- if (!xml_parsing) {
- return(false);
- }
-#ifdef INSET_TEMPLATE_DEBUG
- qDebug() << Q_FUNC_INFO << filepath << "opened";
-#endif
- return(loadFromXmlElement(xml_description_.documentElement()));
-}
-
-/**
- @param xml_element An XML document to read the template from.
- @return true if the reading succeeds, false otherwise.
-*/
-bool InsetTemplate::loadFromXmlElement(const QDomElement &xml_element) {
- // we expect the XML element to be an <insettemplate>
- if (xml_element.tagName() != "insettemplate") {
- return(false);
- }
-
- loadLogos(xml_element, true);
- loadGrid(xml_element);
- return(true);
-}
-
-/**
- Imports the logos from a given XML inset template.
- @param xml_element An XML element representing an inset template.
- @param reset true to delete all previously known logos before, false
- otherwise.
- @return true if the reading succeeds, false otherwise.
-*/
-bool InsetTemplate::loadLogos(const QDomElement &xml_element, bool reset) {
- if (reset) {
- qDeleteAll(vector_logos_.begin(), vector_logos_.end());
- vector_logos_.clear();
- qDeleteAll(bitmap_logos_.begin(), bitmap_logos_.end());
- bitmap_logos_.clear();
- }
-
- // we look for //logos/logo elements
- for (QDomNode n = xml_element.firstChild() ; !n.isNull() ; n = n.nextSibling()) {
- if (n.isElement() && n.toElement().tagName() == "logos") {
- for (QDomNode p = n.firstChild() ; !p.isNull() ; p = p.nextSibling()) {
- if (p.isElement() && p.toElement().tagName() == "logo") {
- loadLogo(p.toElement());
- }
- }
- }
- }
-
- return(true);
-}
-
-/**
- Imports the logo from a given XML logo description.
- @param xml_element An XML element representing a logo within an inset
- template.
- @return true if the reading succeeds, false otherwise.
-*/
-bool InsetTemplate::loadLogo(const QDomElement &xml_element) {
- // we require a name
- if (!xml_element.hasAttribute("name")) {
- return(false);
- }
- QString logo_name = xml_element.attribute("name");
- QString logo_type = xml_element.attribute("type", "png");
- QString logo_storage = xml_element.attribute("storage", "base64");
-
- // Both QSvgRenderer and QPixmap read their data from a QByteArray, so
- // we convert the available data to that format.
- QByteArray logo_data;
- if (logo_storage == "xml") {
- // only svg uses xml storage
- QDomNodeList svg_nodes = xml_element.elementsByTagName("svg");
- if (svg_nodes.isEmpty()) {
- return(false);
- }
- QDomElement svg_element = svg_nodes.at(0).toElement();
- QTextStream xml_to_byte_array(&logo_data);
- svg_element.save(xml_to_byte_array, 0);
- } else if (logo_storage == "base64") {
- logo_data = QByteArray::fromBase64(xml_element.text().toAscii());
- } else {
- return(false);
- }
-
- // we can now create our image object from the byte array
- if (logo_type == "svg") {
- // SVG format is handled by the QSvgRenderer class
- QSvgRenderer *svg = new QSvgRenderer(logo_data);
- vector_logos_.insert(logo_name, svg);
-
- /*QSvgWidget *test_svgwidget = new QSvgWidget();
- test_svgwidget -> load(logo_data);
- test_svgwidget -> show();*/
- } else {
- // bitmap formats are handled by the QPixmap class
- QPixmap *logo_pixmap = new QPixmap();
- logo_pixmap -> loadFromData(logo_data);
- if (!logo_pixmap -> width() || !logo_pixmap -> height()) {
- return(false);
- }
- bitmap_logos_.insert(logo_name, logo_pixmap);
-
- /*QLabel *test_label = new QLabel();
- test_label -> setPixmap(*logo_pixmap);
- test_label -> show();*/
- }
-
- return(true);
-}
-
-/**
- Imports the grid from a given XML inset template.
- @param xml_element An XML element representing an inset template.
- @return true if the reading succeeds, false otherwise.
-*/
-bool InsetTemplate::loadGrid(const QDomElement &xml_element) {
- // we parse the first available "grid" XML element
- QDomElement grid_element;
- for (QDomNode n = xml_element.firstChild() ; !n.isNull() ; n = n.nextSibling()) {
- if (n.isElement() && n.toElement().tagName() == "grid") {
- grid_element = n.toElement();
- break;
- }
- }
-
- if (!grid_element.hasAttribute("rows") || !grid_element.hasAttribute("cols")) {
- return(false);
- }
-
- parseRows(grid_element.attribute("rows"));
- parseColumns(grid_element.attribute("cols"));
- loadCells(grid_element);
- return(true);
-}
-
-/**
- Parses the rows heights
- @param rows_string A string describing the rows heights of the inset
-*/
-void InsetTemplate::parseRows(const QString &rows_string) {
- rows_heights_.clear();
- // parse the rows attribute: we expect a serie of absolute heights
- QRegExp row_size_format("^([0-9]+)(?:px)?$", Qt::CaseInsensitive);
- bool conv_ok;
-
- QStringList rows_descriptions = rows_string.split(QChar(';'), QString::SkipEmptyParts);
- foreach (QString rows_description, rows_descriptions) {
- if (row_size_format.exactMatch(rows_description)) {
- int row_size = row_size_format.capturedTexts().at(1).toInt(&conv_ok);
- if (conv_ok) rows_heights_ << row_size;
- }
- }
-#ifdef INSET_TEMPLATE_DEBUG
- qDebug() << Q_FUNC_INFO << "Rows heights:" << rows_heights_;
-#endif
-}
-
-/**
- Parses the columns widths
- @param cols_string A string describing the columns widths of the inset
-*/
-void InsetTemplate::parseColumns(const QString &cols_string) {
- columns_width_.clear();
- // parse the cols attribute: we expect a serie of absolute or relative widths
- QRegExp abs_col_size_format("^([0-9]+)(?:px)?$", Qt::CaseInsensitive);
- QRegExp rel_col_size_format("^([rt])([0-9]+)%$", Qt::CaseInsensitive);
- bool conv_ok;
-
- QStringList cols_descriptions = cols_string.split(QChar(';'), QString::SkipEmptyParts);
- foreach (QString cols_description, cols_descriptions) {
- if (abs_col_size_format.exactMatch(cols_description)) {
- int col_size = abs_col_size_format.capturedTexts().at(1).toInt(&conv_ok);
- if (conv_ok) columns_width_ << InsetColDimension(col_size, QET::Absolute);
- } else if (rel_col_size_format.exactMatch(cols_description)) {
- int col_size = rel_col_size_format.capturedTexts().at(2).toInt(&conv_ok);
- QET::InsetColumnLength col_type = rel_col_size_format.capturedTexts().at(1) == "t" ? QET::RelativeToTotalLength : QET::RelativeToRemainingLength;
- if (conv_ok) columns_width_ << InsetColDimension(col_size, col_type );
- }
- }
-#ifdef INSET_TEMPLATE_DEBUG
- foreach (InsetColDimension icd, columns_width_) {
- qDebug() << Q_FUNC_INFO << QString("%1 [%2]").arg(icd.value).arg(QET::insetColumnLengthToString(icd.type));
- }
-#endif
-}
-
-/**
- Analyze an XML element, looking for grid cells. The grid cells are checked
- and stored in this object.
- @param xml_element XML element to analyze
-*/
-bool InsetTemplate::loadCells(const QDomElement &xml_element) {
- initCells();
- // we are interested by the "logo" and "field" elements
- QDomElement grid_element;
- for (QDomNode n = xml_element.firstChild() ; !n.isNull() ; n = n.nextSibling()) {
- if (!n.isElement()) continue;
- QDomElement cell_element = n.toElement();
- if (cell_element.tagName() == "field" || cell_element.tagName() == "logo") {
- InsetCell *loaded_cell;
- if (!checkCell(cell_element, &loaded_cell)) continue;
-
- if (cell_element.tagName() == "logo") {
- if (cell_element.hasAttribute("resource") && !cell_element.attribute("resource").isEmpty()) {
- loaded_cell -> logo_reference = cell_element.attribute("resource");
- }
- } else if (cell_element.tagName() == "field") {
- if (cell_element.hasAttribute("name") && !cell_element.attribute("name").isEmpty()) {
- loaded_cell -> value_name = cell_element.attribute("name");
- }
- if (cell_element.hasAttribute("value") && !cell_element.attribute("value").isEmpty()) {
- loaded_cell -> value = cell_element.attribute("value");
- }
- if (cell_element.hasAttribute("label") && !cell_element.attribute("label").isEmpty()) {
- loaded_cell -> label = cell_element.attribute("label");
- }
- if (cell_element.hasAttribute("displaylabel") && cell_element.attribute("displaylabel").compare("false", Qt::CaseInsensitive) == 0) {
- loaded_cell -> display_label = false;
- }
-
- // horiwontal and vertical alignments
- loaded_cell -> alignment = 0;
-
- QString halignment = cell_element.attribute("align", "left");
- if (halignment == "right") loaded_cell -> alignment |= Qt::AlignRight;
- else if (halignment == "center") loaded_cell -> alignment |= Qt::AlignHCenter;
- else loaded_cell -> alignment |= Qt::AlignLeft;
-
- QString valignment = cell_element.attribute("valign", "center");
- if (halignment == "bottom") loaded_cell -> alignment |= Qt::AlignBottom;
- else if (halignment == "top") loaded_cell -> alignment |= Qt::AlignTop;
- else loaded_cell -> alignment |= Qt::AlignVCenter;
- }
- }
- }
-
- return(true);
-}
-
-/**
- @param xml_element XML element representing a cell, i.e. either an inset
- logo or an inset field.
- @param inset_cell_ptr Pointer to an InsetCell object pointer - if non-zero and if
- this method returns true, will be filled with the created InsetCell
- @return TRUE if the cell appears to be ok, FALSE otherwise
-*/
-bool InsetTemplate::checkCell(const QDomElement &xml_element, InsetCell **inset_cell_ptr) {
- int col_count = columns_width_.count(), row_count = rows_heights_.count();
-
-#ifdef INSET_TEMPLATE_DEBUG
- qDebug() << Q_FUNC_INFO << "begin" << row_count << col_count;
-#endif
-
- int row_num, col_num, row_span, col_span;
- bool has_row_span = false;
- bool has_col_span = false;
- row_num = col_num = -1;
- row_span = col_span = 0;
-
- // parse the row and col attributes
- if (!QET::attributeIsAnInteger(xml_element, "row", &row_num) || row_num < 0 || row_num >= row_count) {
- return(false);
- }
- if (!QET::attributeIsAnInteger(xml_element, "col", &col_num) || col_num < 0 || col_num >= col_count) {
- return(false);
- }
-
- // check whether the target cell can be used or not
-#ifdef INSET_TEMPLATE_DEBUG
- qDebug() << Q_FUNC_INFO << "cell access" << col_num << row_num;
-#endif
- InsetCell *cell_ptr = &(cells_[col_num][row_num]);
- if (!cell_ptr -> is_null || cell_ptr -> spanner_cell) {
- return(false);
- }
-
- // parse the rowspan and colspan attributes
- if (QET::attributeIsAnInteger(xml_element, "rowspan", &row_span) && row_span > 0) {
- if (row_num + row_span >= row_count) row_span = row_count - 1 - row_num;
- has_row_span = true;
- }
-
- if (QET::attributeIsAnInteger(xml_element, "colspan", &col_span) && col_span > 0) {
- if (col_num + col_span >= col_count) col_span = col_count - 1 - col_num;
- has_col_span = true;
- }
-
- // check if we can span on the required area
- if (has_row_span || has_col_span) {
- for (int i = col_num ; i <= col_num + col_span ; ++ i) {
- for (int j = row_num ; j <= row_num + row_span ; ++ j) {
- if (i == col_num && j == row_num) continue;
-#ifdef INSET_TEMPLATE_DEBUG
- qDebug() << Q_FUNC_INFO << "span check" << i << j;
-#endif
- InsetCell *current_cell = &(cells_[i][j]);
- if (!current_cell -> is_null || current_cell -> spanner_cell) {
- return(false);
- }
- }
- }
- }
-
- // at this point, the cell is ok - we fill the adequate cells in the matrix
-#ifdef INSET_TEMPLATE_DEBUG
- qDebug() << Q_FUNC_INFO << "cell writing";
-#endif
- cell_ptr -> num_row = row_num;
- cell_ptr -> num_col = col_num;
- if (has_row_span) cell_ptr -> row_span = row_span;
- if (has_col_span) cell_ptr -> col_span = col_span;
- cell_ptr -> is_null = false;
- if (inset_cell_ptr) *inset_cell_ptr = cell_ptr;
-
- if (has_row_span || has_col_span) {
- for (int i = col_num ; i <= col_num + col_span ; ++ i) {
- for (int j = row_num ; j <= row_num + row_span ; ++ j) {
- if (i == col_num && j == row_num) continue;
-#ifdef INSET_TEMPLATE_DEBUG
- qDebug() << Q_FUNC_INFO << "span cells writing" << i << j;
-#endif
- InsetCell *current_cell = &(cells_[i][j]);
- current_cell -> num_row = j;
- current_cell -> num_col = i;
- current_cell -> is_null = false;
- current_cell -> spanner_cell = cell_ptr;
- }
- }
- }
-
- return(true);
-}
-
-/**
- Initializes the internal cells grid with the row and column counts.
- Note that this method does nothing if one of the internal lists
- columns_width_ and rows_heights_ is empty.
-*/
-void InsetTemplate::initCells() {
- if (columns_width_.count() < 1 || rows_heights_.count() < 1) return;
-
- cells_.resize(columns_width_.count());
- int row_count = rows_heights_.count();
- for (int i = 0 ; i < columns_width_.count() ; ++ i) {
- cells_[i].resize(row_count);
- // ensure every cell is a null cell
- for (int j = 0 ; j < row_count ; ++ j) {
- cells_[i][j] = InsetCell();
- }
- }
-
-#ifdef INSET_TEMPLATE_DEBUG
- qDebug() << Q_FUNC_INFO << toString();
-#endif
-}
-
-/**
- @return A string representing the inset template
- @see InsetCell::toString()
-*/
-QString InsetTemplate::toString() const {
- QString str = "\n";
- for (int j = 0 ; j < rows_heights_.count() ; ++ j) {
- for (int i = 0 ; i < columns_width_.count() ; ++ i) {
- str += cells_[i][j].toString() + " ";
- }
- str += "\n";
- }
- return(str);
-}
-
-/**
- @param total_width The total width of the inset to render
- @return the list of the columns widths for this rendering
-*/
-QList<int> InsetTemplate::columnsWidth(int total_width) const {
- if (total_width < 0) return(QList<int>());
-
- // we first iter to determine the absolute and total-width-related widths
- QVector<int> final_widths(columns_width_.count());
- int abs_widths_sum = 0;
-
- for (int i = 0 ; i < columns_width_.count() ; ++ i) {
- InsetColDimension icd = columns_width_.at(i);
- if (icd.type == QET::Absolute) {
- abs_widths_sum += icd.value;
- final_widths[i] = icd.value;
- } else if (icd.type == QET::RelativeToTotalLength) {
- int abs_value = int(total_width * icd.value / 100);
- abs_widths_sum += abs_value;
- final_widths[i] = abs_value;
- }
- }
-
- // we can now deduce the remaining width
- int remaining_width = total_width - abs_widths_sum;
-
- // we do a second iteration to build the final widths list
- for (int i = 0 ; i < columns_width_.count() ; ++ i) {
- InsetColDimension icd = columns_width_.at(i);
- if (icd.type == QET::RelativeToRemainingLength) {
- final_widths[i] = int(remaining_width * icd.value / 100);
- }
- }
- return(final_widths.toList());
-}
-
-int InsetTemplate::height() const {
- int height = 0;
- foreach(int row_height, rows_heights_) {
- height += row_height;
- }
- return(height);
-}
-
-/**
- Render the inset.
- @param painter Painter to use to render the inset
- @param diagram_context Diagram context to use to generate the inset strings
- @param inset_width Width of the inset to render
-*/
-void InsetTemplate::render(QPainter &painter, const DiagramContext &diagram_context, int inset_width) const {
- QList<int> widths = columnsWidth(inset_width);
- int inset_height = height();
-
- // prepare the QPainter
- painter.setPen(Qt::black);
- painter.setBrush(Qt::white);
- painter.setFont(QETApp::diagramTextsFont());
-
- // draw the inset border
- painter.drawRect(QRect(0, 0, inset_width, inset_height));
-
- // run through each inidividual cell
- for (int j = 0 ; j < rows_heights_.count() ; ++ j) {
- for (int i = 0 ; i < columns_width_.count() ; ++ i) {
- if (cells_[i][j].spanner_cell) continue;
-
- // calculate the border rect of the current cell
- int x = lengthRange(0, cells_[i][j].num_col, widths);
- int y = lengthRange(0, cells_[i][j].num_row, rows_heights_);
- int w = lengthRange(cells_[i][j].num_col, cells_[i][j].num_col + 1 + cells_[i][j].col_span, widths);
- int h = lengthRange(cells_[i][j].num_row, cells_[i][j].num_row + 1 + cells_[i][j].row_span, rows_heights_);
- QRect cell_rect(x, y, w, h);
-
- // draw the border rect of the current cell
- painter.drawRect(cell_rect);
-
- // render the inner content of the current cell
- if (!cells_[i][j].logo_reference.isEmpty()) {
- // the current cell appear to be a logo - we first look for the
- // logo reference in our vector logos list, since they offer a
- // potentially better (or, at least, not resolution-limited) rendering
- if (vector_logos_.contains(cells_[i][j].logo_reference)) {
- vector_logos_[cells_[i][j].logo_reference] -> render(&painter, cell_rect);
- } else if (bitmap_logos_.contains(cells_[i][j].logo_reference)) {
- painter.drawPixmap(cell_rect, *(bitmap_logos_[cells_[i][j].logo_reference]));
- }
- } else {
- painter.drawText(cell_rect, cells_[i][j].alignment, finalTextForCell(cells_[i][j], diagram_context));
- }
-
- // draw again the border rect of the current cell, without the brush this time
- painter.setBrush(Qt::NoBrush);
- painter.drawRect(cell_rect);
- }
- }
-}
-
-/**
- @param cell A cell from this template
- @param diagram_context Diagram context to use to generate the final text for the given cell
- @return the final text that has to be drawn in the given cell
-*/
-QString InsetTemplate::finalTextForCell(const InsetCell &cell, const DiagramContext &diagram_context) const {
- QString cell_text = cell.value;
-
- foreach (QString key, diagram_context.keys()) {
- cell_text.replace("%{" + key + "}", diagram_context[key].toString());
- cell_text.replace("%" + key, diagram_context[key].toString());
- }
- if (cell.display_label && !cell.label.isEmpty()) {
- cell_text = QString(tr(" %1 : %2", "inset content - please let the blank space at the beginning")).arg(cell.label).arg(cell_text);
- } else {
- cell_text = QString(tr(" %1")).arg(cell_text);
- }
- return(cell_text);
-}
-
-/**
- @return the width between two borders
- @param start start border number
- @param end end border number
-*/
-int InsetTemplate::lengthRange(int start, int end, const QList<int> &lengths_list) const {
- if (start > end || start >= lengths_list.count() || end > lengths_list.count()) {
- qDebug() << Q_FUNC_INFO << "wont use" << start << "and" << end;
- return(0);
- }
-
- int length = 0;
- for (int i = start ; i < end ; ++i) {
- length += lengths_list[i];
- }
- return(length);
-}
-
-
-
-/**
- Constructor
-*/
-InsetCell::InsetCell() {
- num_row = num_col = -1;
- row_span = col_span = 0;
- display_label = is_null = true;
- spanner_cell = 0;
-}
-
-/**
- @return A string representing the inset cell
-*/
-QString InsetCell::toString() const {
- if (is_null) return("InsetCell{null}");
- QString span_desc = (row_span > 0 || col_span > 0) ? QString("+%3,%4").arg(row_span).arg(col_span) : QET::pointerString(spanner_cell);
- QString base_desc = QString("InsetCell{ [%1, %2] %3 }").arg(num_row).arg(num_col).arg(span_desc);
- return(base_desc);
-}
Deleted: branches/0.3/sources/insettemplate.h
===================================================================
--- branches/0.3/sources/insettemplate.h 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/insettemplate.h 2010-12-20 02:45:36 UTC (rev 1132)
@@ -1,92 +0,0 @@
-/*
- Copyright 2006-2010 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 <http://www.gnu.org/licenses/>.
-*/
-#ifndef INSET_TEMPLATE_H
-#define INSET_TEMPLATE_H
-#include <QtXml>
-#include <QtSvg>
-#include "diagramcontext.h"
-#include "insetcell.h"
-#include "qet.h"
-
-/**
- This struct is a simple container associating a length with its type.
- @see InsetColumnLength
-*/
-struct InsetColDimension {
- InsetColDimension(int v, QET::InsetColumnLength t = QET::Absolute) {
- value = v;
- type = t;
- }
- QET::InsetColumnLength type;
- int value;
-};
-
-/**
- This class represents an inset templ)ate for an electric diagram.
- It can read from an XML document the layout of the table that graphically
- represents the inset, and can produce a graphical rendering of it from a
- diagram context (object embedding the informations of the diagram we want to
- represent the inset.
-*/
-class InsetTemplate : public QObject {
- Q_OBJECT
-
- // constructeurs, destructeur
- public:
- InsetTemplate(QObject * = 0);
- virtual ~InsetTemplate();
- private:
- InsetTemplate(const InsetTemplate &);
-
- // methodes
- public:
- bool loadFromXmlFile(const QString &);
- bool loadFromXmlElement(const QDomElement &);
- void setContext(const DiagramContext &);
-
- QList<int> columnsWidth(int) const;
- int height() const;
-
- void render(QPainter &, const DiagramContext &, int) const;
- QString toString() const;
-
- protected:
- bool loadLogos(const QDomElement &, bool = false);
- bool loadLogo(const QDomElement &);
- bool loadGrid(const QDomElement &);
- bool loadCells(const QDomElement &);
-
- private:
- void parseRows(const QString &);
- void parseColumns(const QString &);
- bool checkCell(const QDomElement &, InsetCell ** = 0);
- void flushCells();
- void initCells();
- int lengthRange(int, int, const QList<int> &) const;
- QString finalTextForCell(const InsetCell &, const DiagramContext &) const;
-
- // attributs
- private:
- QDomDocument xml_description_;
- QHash<QString, QSvgRenderer *> vector_logos_;
- QHash<QString, QPixmap *> bitmap_logos_;
- QList<int> rows_heights_;
- QList<InsetColDimension> columns_width_;
- QVector< QVector<InsetCell> > cells_;
-};
-#endif
Deleted: branches/0.3/sources/insettemplaterenderer.cpp
===================================================================
--- branches/0.3/sources/insettemplaterenderer.cpp 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/insettemplaterenderer.cpp 2010-12-20 02:45:36 UTC (rev 1132)
@@ -1,96 +0,0 @@
-#include "insettemplaterenderer.h"
-#include "insettemplate.h"
-
-/**
- Constructor
- @param parnet Parent QObject of this renderer
-*/
-InsetTemplateRenderer::InsetTemplateRenderer(QObject *parent) :
- QObject(parent),
- inset_template_(0),
- last_known_inset_width_(-1)
-{
-}
-
-/**
- Destructor
-*/
-InsetTemplateRenderer::~InsetTemplateRenderer() {
-}
-
-/**
- @return the inset template used for the rendering
-*/
-const InsetTemplate *InsetTemplateRenderer::insetTemplate() const {
- return(inset_template_);
-}
-
-/**
- @param inset_template Inset template to render.
-*/
-void InsetTemplateRenderer::setInsetTemplate(const InsetTemplate *inset_template) {
- if (inset_template != inset_template_) {
- inset_template_ = inset_template;
- invalidateRenderedTemplate();
- }
-}
-
-/**
- @param context Diagram Context to use when rendering the inset
-*/
-void InsetTemplateRenderer::setContext(const DiagramContext &context) {
- context_ = context;
- invalidateRenderedTemplate();
-}
-
-/**
- @return the height of the rendered template, or -1 if no template has been
- set for this renderer.
- @see InsetTemplate::height()
-*/
-int InsetTemplateRenderer::height() const {
- if (!inset_template_) return(-1);
- return(inset_template_ -> height());
-}
-
-/**
- Render the inset.
- @param provided_painter QPainter to use to render the inset.
- @param inset_width The total width of the inset to render
-*/
-void InsetTemplateRenderer::render(QPainter *provided_painter, int inset_width) {
- if (!inset_template_) return;
-
- // Do we really need to calculate all this again?
- if (inset_width != last_known_inset_width_ || rendered_template_.isNull()) {
- renderToQPicture(inset_width);
- }
-
- provided_painter -> save();
- rendered_template_.play(provided_painter);
- provided_painter -> restore();
-}
-
-/**
- Renders the inset to the internal QPicture
- @param inset_width Width of the inset to render
-*/
-void InsetTemplateRenderer::renderToQPicture(int inset_width) {
- if (!inset_template_) return;
-
- // we render the template on our internal QPicture
- QPainter painter(&rendered_template_);
-
- inset_template_ -> render(painter, context_, inset_width);
-
- // memorize the last known width
- last_known_inset_width_ = inset_width;
-}
-
-/**
- Invalidates the previous rendering of the template by resetting the internal
- QPicture.
-*/
-void InsetTemplateRenderer::invalidateRenderedTemplate() {
- rendered_template_ = QPicture();
-}
Deleted: branches/0.3/sources/insettemplaterenderer.h
===================================================================
--- branches/0.3/sources/insettemplaterenderer.h 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/insettemplaterenderer.h 2010-12-20 02:45:36 UTC (rev 1132)
@@ -1,45 +0,0 @@
-/*
- Copyright 2006-2010 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 <http://www.gnu.org/licenses/>.
-*/
-#ifndef INSET_TEMPLATE_RENDERER_H
-#define INSET_TEMPLATE_RENDERER_H
-#include <QPicture>
-#include "diagramcontext.h"
-class InsetTemplate;
-class InsetTemplateRenderer : public QObject {
- Q_OBJECT
-
- public:
- InsetTemplateRenderer(QObject * = 0);
- virtual ~InsetTemplateRenderer();
- const InsetTemplate *insetTemplate() const;
- void setInsetTemplate(const InsetTemplate *);
- void setContext(const DiagramContext &context);
- int height() const;
- void render(QPainter *, int);
-
- private:
- void renderToQPicture(int);
- void invalidateRenderedTemplate();
-
- private:
- const InsetTemplate *inset_template_;
- QPicture rendered_template_;
- DiagramContext context_;
- int last_known_inset_width_;
-};
-#endif
Modified: branches/0.3/sources/projectview.cpp
===================================================================
--- branches/0.3/sources/projectview.cpp 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/projectview.cpp 2010-12-20 02:45:36 UTC (rev 1132)
@@ -26,7 +26,7 @@
#include "qetelementeditor.h"
#include "interactivemoveelementshandler.h"
#include "borderpropertieswidget.h"
-#include "insetpropertieswidget.h"
+#include "titleblockpropertieswidget.h"
#include "conductorpropertieswidget.h"
#include "qeticons.h"
#include "qetmessagebox.h"
@@ -424,7 +424,7 @@
bpw -> setReadOnly(project_is_read_only);
// proprietes par defaut d'un cartouche
- InsetPropertiesWidget *ipw = new InsetPropertiesWidget(project_ -> defaultInsetProperties(), true);
+ TitleBlockPropertiesWidget *ipw = new TitleBlockPropertiesWidget(project_ -> defaultTitleBlockProperties(), true);
ipw -> setReadOnly(project_is_read_only);
// proprietes par defaut des conducteurs
@@ -469,7 +469,7 @@
if (properties_dialog.exec() == QDialog::Accepted && !project_is_read_only) {
project_ -> setTitle(title_field -> text());
project_ -> setDefaultBorderProperties(bpw -> borderProperties());
- project_ -> setDefaultInsetProperties(ipw -> insetProperties());
+ project_ -> setDefaultTitleBlockProperties(ipw -> titleBlockProperties());
project_ -> setDefaultConductorProperties(cpw -> conductorProperties());
}
}
Modified: branches/0.3/sources/qet.cpp
===================================================================
--- branches/0.3/sources/qet.cpp 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/qet.cpp 2010-12-20 02:45:36 UTC (rev 1132)
@@ -517,11 +517,11 @@
}
/**
- @param icl an InsetColumnLength object
- @see InsetColumnLength
- @return a string describing the type of this InsetColumnLength object
+ @param icl an TitleBlockColumnLength object
+ @see TitleBlockColumnLength
+ @return a string describing the type of this TitleBlockColumnLength object
*/
-QString QET::insetColumnLengthToString(const InsetColumnLength &icl) {
+QString QET::titleBlockColumnLengthToString(const TitleBlockColumnLength &icl) {
QString type_str;
if (icl== Absolute) type_str = "absolute";
else if (icl == RelativeToTotalLength) type_str = "relative to total";
Modified: branches/0.3/sources/qet.h
===================================================================
--- branches/0.3/sources/qet.h 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/qet.h 2010-12-20 02:45:36 UTC (rev 1132)
@@ -98,7 +98,7 @@
};
/// enum used to specify the type of a length
- enum InsetColumnLength {
+ enum TitleBlockColumnLength {
Absolute, ///< the length is absolute and should be applied as is
RelativeToTotalLength, ///< the length is just a fraction of the total available length
RelativeToRemainingLength ///< the length is just a fraction of the length that is still available when other types of lengths have been removed
@@ -132,6 +132,6 @@
QString pointerString(void *);
qreal correctAngle(const qreal &);
bool compareCanonicalFilePaths(const QString &, const QString &);
- QString insetColumnLengthToString(const InsetColumnLength &);
+ QString titleBlockColumnLengthToString(const TitleBlockColumnLength &);
}
#endif
Modified: branches/0.3/sources/qetapp.cpp
===================================================================
--- branches/0.3/sources/qetapp.cpp 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/qetapp.cpp 2010-12-20 02:45:36 UTC (rev 1132)
@@ -22,7 +22,7 @@
#include "qetelementeditor.h"
#include "elementscollectionitem.h"
#include "fileelementscollection.h"
-#include "insettemplate.h"
+#include "titleblocktemplate.h"
#include "qetproject.h"
#include "qtextorientationspinboxwidget.h"
#include "recentfiles.h"
@@ -46,7 +46,7 @@
RecentFiles *QETApp::projects_recent_files_ = 0;
RecentFiles *QETApp::elements_recent_files_ = 0;
AboutQET *QETApp::about_dialog_ = 0;
-InsetTemplate *QETApp::default_inset_template_ = 0;
+TitleBlockTemplate *QETApp::default_titleblock_template_ = 0;
/**
Constructeur
@@ -531,16 +531,16 @@
}
/**
- @return the default inset template for diagrams
+ @return the default titleblock template for diagrams
*/
-InsetTemplate *QETApp::defaultInsetTemplate() {
- if (!QETApp::default_inset_template_) {
- InsetTemplate *inset_template = new InsetTemplate(QETApp::instance());
- if (inset_template -> loadFromXmlFile(":/insets/default.inset")) {
- QETApp::default_inset_template_ = inset_template;
+TitleBlockTemplate *QETApp::defaultTitleBlockTemplate() {
+ if (!QETApp::default_titleblock_template_) {
+ TitleBlockTemplate *titleblock_template = new TitleBlockTemplate(QETApp::instance());
+ if (titleblock_template -> loadFromXmlFile(":/titleblocks/default.titleblock")) {
+ QETApp::default_titleblock_template_ = titleblock_template;
}
}
- return(default_inset_template_);
+ return(default_titleblock_template_);
}
Modified: branches/0.3/sources/qetapp.h
===================================================================
--- branches/0.3/sources/qetapp.h 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/qetapp.h 2010-12-20 02:45:36 UTC (rev 1132)
@@ -30,7 +30,7 @@
class FileElementsCollection;
class ElementsCategory;
class ElementDefinition;
-class InsetTemplate;
+class TitleBlockTemplate;
class QETProject;
class QTextOrientationSpinBoxWidget;
class RecentFiles;
@@ -99,7 +99,7 @@
static QList<QETElementEditor *> elementEditors();
static QList<QETElementEditor *> elementEditors(QETProject *);
static QTextOrientationSpinBoxWidget *createTextOrientationSpinBoxWidget();
- static InsetTemplate *defaultInsetTemplate();
+ static TitleBlockTemplate *defaultTitleBlockTemplate();
protected:
#ifdef Q_OS_DARWIN
@@ -142,7 +142,7 @@
static RecentFiles *projects_recent_files_;
static RecentFiles *elements_recent_files_;
static AboutQET *about_dialog_;
- static InsetTemplate *default_inset_template_;
+ static TitleBlockTemplate *default_titleblock_template_;
public slots:
void systray(QSystemTrayIcon::ActivationReason);
Modified: branches/0.3/sources/qetdiagrameditor.cpp
===================================================================
--- branches/0.3/sources/qetdiagrameditor.cpp 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/qetdiagrameditor.cpp 2010-12-20 02:45:36 UTC (rev 1132)
@@ -660,7 +660,7 @@
// transmet les proprietes par defaut des nouveaux schemas
new_project -> setDefaultBorderProperties(defaultBorderProperties());
new_project -> setDefaultConductorProperties(defaultConductorProperties());
- new_project -> setDefaultInsetProperties(defaultInsetProperties());
+ new_project -> setDefaultTitleBlockProperties(defaultTitleBlockProperties());
// ajoute un schema au projet
new_project -> addNewDiagram();
@@ -1780,11 +1780,11 @@
/**
@return Les proprietes par defaut pour le cartouche d'un schema
*/
-InsetProperties QETDiagramEditor::defaultInsetProperties() {
+TitleBlockProperties QETDiagramEditor::defaultTitleBlockProperties() {
// accede a la configuration de l'application
QSettings &settings = QETApp::settings();
- InsetProperties def;
+ TitleBlockProperties def;
// lit le cartouche par defaut dans la configuration
def.fromSettings(settings, "diagrameditor/default");
Modified: branches/0.3/sources/qetdiagrameditor.h
===================================================================
--- branches/0.3/sources/qetdiagrameditor.h 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/qetdiagrameditor.h 2010-12-20 02:45:36 UTC (rev 1132)
@@ -20,7 +20,7 @@
#include <QtGui>
#include "borderproperties.h"
#include "conductorproperties.h"
-#include "insetproperties.h"
+#include "titleblockproperties.h"
#include "exportproperties.h"
class QETProject;
class ProjectView;
@@ -56,7 +56,7 @@
QList<DiagramView *> projectViews() const;
QList<QString> editedFiles() const;
ProjectView *viewForFile(const QString &) const;
- static InsetProperties defaultInsetProperties();
+ static TitleBlockProperties defaultTitleBlockProperties();
static BorderProperties defaultBorderProperties();
static ConductorProperties defaultConductorProperties();
static ExportProperties defaultExportProperties();
Modified: branches/0.3/sources/qetproject.cpp
===================================================================
--- branches/0.3/sources/qetproject.cpp 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/qetproject.cpp 2010-12-20 02:45:36 UTC (rev 1132)
@@ -25,7 +25,7 @@
#include "integrationmoveelementshandler.h"
#include "basicmoveelementshandler.h"
#include "qetmessagebox.h"
-#include "insettemplate.h"
+#include "titleblocktemplate.h"
QString QETProject::integration_category_name = "import";
@@ -268,10 +268,10 @@
}
/**
- @return the list of the inset templates embedded within this project
+ @return the list of the titleblock templates embedded within this project
*/
-QList<QString> QETProject::embeddedInsetTemplates() const {
- return(inset_templates_xml_.keys());
+QList<QString> QETProject::embeddedTitleBlockTemplates() const {
+ return(titleblock_templates_xml_.keys());
}
/**
@@ -279,22 +279,22 @@
@return the requested template, or 0 if there is no vltaid template of this
name within the project
*/
-const InsetTemplate *QETProject::getTemplateByName(const QString &template_name) {
+const TitleBlockTemplate *QETProject::getTemplateByName(const QString &template_name) {
// Do we have already loaded this template?
- if (inset_templates_.contains(template_name)) {
- return(inset_templates_[template_name]);
+ if (titleblock_templates_.contains(template_name)) {
+ return(titleblock_templates_[template_name]);
}
// No? Do we even know of it?
- if (!inset_templates_xml_.contains(template_name)) {
+ if (!titleblock_templates_xml_.contains(template_name)) {
return(0);
}
- // Ok, we have its XML description, we have to generate an InsetTemplate object
- InsetTemplate *inset_template = new InsetTemplate(this);
- if (inset_template -> loadFromXmlElement(inset_templates_xml_[template_name])) {
- inset_templates_.insert(template_name, inset_template);
- return(inset_template);
+ // Ok, we have its XML description, we have to generate an TitleBlockTemplate object
+ TitleBlockTemplate *titleblock_template = new TitleBlockTemplate(this);
+ if (titleblock_template -> loadFromXmlElement(titleblock_templates_xml_[template_name])) {
+ titleblock_templates_.insert(template_name, titleblock_template);
+ return(titleblock_template);
} else {
return(0);
}
@@ -303,11 +303,11 @@
/**
@param template_name Name of the requested template
@return the XML description of the requested template, or a null QDomElement
- if the project does not have such an inset template
+ if the project does not have such an titleblock template
*/
QDomElement QETProject::getTemplateXmlDescriptionByName(const QString &template_name) {
- if (inset_templates_xml_.contains(template_name)) {
- return(inset_templates_xml_[template_name]);
+ if (titleblock_templates_xml_.contains(template_name)) {
+ return(titleblock_templates_xml_[template_name]);
}
return(QDomElement());
}
@@ -333,17 +333,17 @@
@return le cartouche par defaut utilise lors de la creation d'un
nouveau schema dans ce projet.
*/
-InsetProperties QETProject::defaultInsetProperties() const {
- return(default_inset_properties_);
+TitleBlockProperties QETProject::defaultTitleBlockProperties() const {
+ return(default_titleblock_properties_);
}
/**
Permet de specifier le cartouche par defaut utilise lors de la creation
d'un nouveau schema dans ce projet.
- @param inset Cartouche d'un schema
+ @param titleblock Cartouche d'un schema
*/
-void QETProject::setDefaultInsetProperties(const InsetProperties &inset) {
- default_inset_properties_ = inset;
+void QETProject::setDefaultTitleBlockProperties(const TitleBlockProperties &titleblock) {
+ default_titleblock_properties_ = titleblock;
}
/**
@@ -373,14 +373,14 @@
project_root.setAttribute("title", project_title_);
xml_doc.appendChild(project_root);
- // inset templates, if any
- if (inset_templates_xml_.count()) {
- qDebug() << qPrintable(QString("QETProject::toXml() : exporting %1 inset templates").arg(inset_templates_xml_.count()));
- QDomElement insettemplates_elmt = xml_doc.createElement("insettemplates");
- foreach (QDomElement e, inset_templates_xml_) {
- insettemplates_elmt.appendChild(e);
+ // titleblock templates, if any
+ if (titleblock_templates_xml_.count()) {
+ qDebug() << qPrintable(QString("QETProject::toXml() : exporting %1 titleblock templates").arg(titleblock_templates_xml_.count()));
+ QDomElement titleblocktemplates_elmt = xml_doc.createElement("titleblocktemplates");
+ foreach (QDomElement e, titleblock_templates_xml_) {
+ titleblocktemplates_elmt.appendChild(e);
}
- project_root.appendChild(insettemplates_elmt);
+ project_root.appendChild(titleblocktemplates_elmt);
}
// proprietes pour les nouveaux schemas
@@ -696,8 +696,8 @@
Diagram *diagram = new Diagram();
// lui transmet les parametres par defaut
- diagram -> border_and_inset.importBorder(defaultBorderProperties());
- diagram -> border_and_inset.importInset(defaultInsetProperties());
+ diagram -> border_and_titleblock.importBorder(defaultBorderProperties());
+ diagram -> border_and_titleblock.importTitleBlock(defaultTitleBlockProperties());
diagram -> defaultConductorProperties = defaultConductorProperties();
addDiagram(diagram);
@@ -790,7 +790,7 @@
// charge les proprietes par defaut pour les nouveaux schemas
readDefaultPropertiesXml();
- // load the embedded inset templates
+ // load the embedded titleblock templates
readEmbeddedTemplatesXml();
// charge la collection embarquee
@@ -839,17 +839,17 @@
Loads the embedded template from the XML description of the project
*/
void QETProject::readEmbeddedTemplatesXml() {
- foreach (QDomElement e, QET::findInDomElement(document_root_.documentElement(), "insettemplates", "insettemplate")) {
- // each inset template must have a name
+ foreach (QDomElement e, QET::findInDomElement(document_root_.documentElement(), "titleblocktemplates", "titleblocktemplate")) {
+ // each titleblock template must have a name
if (!e.hasAttribute("name")) continue;
- QString inset_template_name = e.attribute("name");
+ QString titleblock_template_name = e.attribute("name");
// if several templates have the same name, we keep the first one encountered
- if (inset_templates_xml_.contains(inset_template_name)) continue;
+ if (titleblock_templates_xml_.contains(titleblock_template_name)) continue;
- // we simply store the XML element describing the inset template,
+ // we simply store the XML element describing the titleblock template,
// without any further analysis for the moment
- inset_templates_xml_.insert(inset_template_name, e);
+ titleblock_templates_xml_.insert(titleblock_template_name, e);
}
}
@@ -893,11 +893,11 @@
// par defaut, les valeurs sont celles de la configuration QElectroTech
default_border_properties_ = QETDiagramEditor::defaultBorderProperties();
- default_inset_properties_ = QETDiagramEditor::defaultInsetProperties();
+ default_titleblock_properties_ = QETDiagramEditor::defaultTitleBlockProperties();
default_conductor_properties_ = QETDiagramEditor::defaultConductorProperties();
// lecture des valeurs indiquees dans le projet
- QDomElement border_elmt, inset_elmt, conductors_elmt;
+ QDomElement border_elmt, titleblock_elmt, conductors_elmt;
// recherche des elements XML concernant les dimensions, le cartouche et les conducteurs
for (QDomNode child = newdiagrams_elmt.firstChild() ; !child.isNull() ; child = child.nextSibling()) {
@@ -906,7 +906,7 @@
if (child_elmt.tagName() == "border") {
border_elmt = child_elmt;
} else if (child_elmt.tagName() == "inset") {
- inset_elmt = child_elmt;
+ titleblock_elmt = child_elmt;
} else if (child_elmt.tagName() == "conductors") {
conductors_elmt = child_elmt;
}
@@ -914,7 +914,7 @@
// dimensions, cartouche, et conducteurs
if (!border_elmt.isNull()) default_border_properties_.fromXml(border_elmt);
- if (!inset_elmt.isNull()) default_inset_properties_.fromXml(inset_elmt);
+ if (!titleblock_elmt.isNull()) default_titleblock_properties_.fromXml(titleblock_elmt);
if (!conductors_elmt.isNull()) default_conductor_properties_.fromXml(conductors_elmt);
}
@@ -935,9 +935,9 @@
xml_element.appendChild(border_elmt);
// exporte le contenu du cartouche
- QDomElement inset_elmt = xml_document.createElement("inset");
- default_inset_properties_.toXml(inset_elmt);
- xml_element.appendChild(inset_elmt);
+ QDomElement titleblock_elmt = xml_document.createElement("inset");
+ default_titleblock_properties_.toXml(titleblock_elmt);
+ xml_element.appendChild(titleblock_elmt);
// exporte le type de conducteur par defaut
QDomElement conductor_elmt = xml_document.createElement("conductors");
@@ -958,7 +958,7 @@
// si le schema est ecrit, alors il faut reecrire le fichier projet
connect(diagram, SIGNAL(written()), this, SLOT(componentWritten()));
connect(
- &(diagram -> border_and_inset),
+ &(diagram -> border_and_titleblock),
SIGNAL(needFolioData()),
this,
SLOT(updateDiagramsFolioData())
@@ -1059,7 +1059,7 @@
void QETProject::updateDiagramsFolioData() {
int total_folio = diagrams_.count();
for (int i = 0 ; i < total_folio ; ++ i) {
- diagrams_[i] -> border_and_inset.setFolioData(i + 1, total_folio);
+ diagrams_[i] -> border_and_titleblock.setFolioData(i + 1, total_folio);
}
}
Modified: branches/0.3/sources/qetproject.h
===================================================================
--- branches/0.3/sources/qetproject.h 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/sources/qetproject.h 2010-12-20 02:45:36 UTC (rev 1132)
@@ -23,13 +23,13 @@
#include "elementslocation.h"
#include "borderproperties.h"
#include "conductorproperties.h"
-#include "insetproperties.h"
+#include "titleblockproperties.h"
class Diagram;
class ElementsCollection;
class ElementsCategory;
class ElementDefinition;
class ElementsLocation;
-class InsetTemplate;
+class TitleBlockTemplate;
class XmlElementsCollection;
class MoveElementsHandler;
/**
@@ -80,13 +80,13 @@
QString title() const;
qreal declaredQElectroTechVersion();
void setTitle(const QString &);
- QList<QString> embeddedInsetTemplates() const;
- const InsetTemplate *getTemplateByName(const QString &template_name);
+ QList<QString> embeddedTitleBlockTemplates() const;
+ const TitleBlockTemplate *getTemplateByName(const QString &template_name);
QDomElement getTemplateXmlDescriptionByName(const QString &);
BorderProperties defaultBorderProperties() const;
void setDefaultBorderProperties(const BorderProperties &);
- InsetProperties defaultInsetProperties() const;
- void setDefaultInsetProperties(const InsetProperties &);
+ TitleBlockProperties defaultTitleBlockProperties() const;
+ void setDefaultTitleBlockProperties(const TitleBlockProperties &);
ConductorProperties defaultConductorProperties() const;
void setDefaultConductorProperties(const ConductorProperties &);
QDomDocument toXml();
@@ -162,10 +162,10 @@
/// Proprietes par defaut des conducteurs pour les nouveaux schemas dans ce projet
ConductorProperties default_conductor_properties_;
/// Proprietes par defaut du cartouche pour les nouveaux schemas dans ce projet
- InsetProperties default_inset_properties_;
- /// XML descriptions of embedded inset templates
- QHash<QString, QDomElement> inset_templates_xml_;
- /// Already parsed embedded inset templates
- QHash<QString, InsetTemplate *> inset_templates_;
+ TitleBlockProperties default_titleblock_properties_;
+ /// XML descriptions of embedded titleblock templates
+ QHash<QString, QDomElement> titleblock_templates_xml_;
+ /// Already parsed embedded titleblock templates
+ QHash<QString, TitleBlockTemplate *> titleblock_templates_;
};
#endif
Copied: branches/0.3/sources/titleblockcell.h (from rev 1131, branches/0.3/sources/insetcell.h)
===================================================================
--- branches/0.3/sources/titleblockcell.h (rev 0)
+++ branches/0.3/sources/titleblockcell.h 2010-12-20 02:45:36 UTC (rev 1132)
@@ -0,0 +1,41 @@
+/*
+ Copyright 2006-2010 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 <http://www.gnu.org/licenses/>.
+*/
+#ifndef TITLEBLOCK_CELL_H
+#define TITLEBLOCK_CELL_H
+/**
+ This class is a container for the various parameters of an titleblock cell
+ @see TitleBlockColumnLength
+*/
+class TitleBlockCell {
+ public:
+ TitleBlockCell();
+ QString toString() const;
+ bool is_null;
+ int num_row;
+ int num_col;
+ int row_span;
+ int col_span;
+ TitleBlockCell *spanner_cell;
+ QString value_name;
+ QString value;
+ QString label;
+ bool display_label;
+ int alignment;
+ QString logo_reference;
+};
+#endif
Copied: branches/0.3/sources/titleblockproperties.cpp (from rev 1131, branches/0.3/sources/insetproperties.cpp)
===================================================================
--- branches/0.3/sources/titleblockproperties.cpp (rev 0)
+++ branches/0.3/sources/titleblockproperties.cpp 2010-12-20 02:45:36 UTC (rev 1132)
@@ -0,0 +1,154 @@
+/*
+ Copyright 2006-2010 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 <http://www.gnu.org/licenses/>.
+*/
+#include "titleblockproperties.h"
+
+/**
+ Constructeur. Initialise un objet TitleBlockProperties avec tous les champs
+ vides (date vide + useDate a UseDateValue).
+*/
+TitleBlockProperties::TitleBlockProperties() :
+ date(),
+ useDate(UseDateValue)
+{
+}
+
+/**
+ Destructeur
+*/
+TitleBlockProperties::~TitleBlockProperties() {
+}
+
+/**
+ @param ip autre conteneur TitleBlockProperties
+ @return true si ip et ce conteneur sont identiques, false sinon
+*/
+bool TitleBlockProperties::operator==(const TitleBlockProperties &ip) {
+ return(
+ ip.title == title &&\
+ ip.author == author &&\
+ ip.date == date &&\
+ ip.filename == filename &&\
+ ip.folio == folio
+ );
+}
+
+/**
+ @param ip autre conteneur TitleBlockProperties
+ @return false si ip et ce conteneur sont identiques, true sinon
+*/
+bool TitleBlockProperties::operator!=(const TitleBlockProperties &ip) {
+ return(!(*this == ip));
+}
+
+
+/**
+ Exporte le cartouche sous formes d'attributs XML ajoutes a l'element e.
+ @param e Element XML auquel seront ajoutes des attributs
+*/
+void TitleBlockProperties::toXml(QDomElement &e) const {
+ e.setAttribute("author", author);
+ e.setAttribute("title", title);
+ e.setAttribute("filename", filename);
+ e.setAttribute("folio", folio);
+ e.setAttribute("date", exportDate());
+}
+
+/**
+ Importe le cartouche a partir des attributs XML de l'element e
+ @param e Element XML dont les attributs seront lus
+*/
+void TitleBlockProperties::fromXml(QDomElement &e) {
+ if (e.hasAttribute("author")) author = e.attribute("author");
+ if (e.hasAttribute("title")) title = e.attribute("title");
+ if (e.hasAttribute("filename")) filename = e.attribute("filename");
+ if (e.hasAttribute("folio")) folio = e.attribute("folio");
+ if (e.hasAttribute("date")) setDateFromString(e.attribute("date"));
+}
+
+/**
+ Exporte le cartouche dans une configuration.
+ @param settings Parametres a ecrire
+ @param prefix prefixe a ajouter devant les noms des parametres
+*/
+void TitleBlockProperties::toSettings(QSettings &settings, const QString &prefix) const {
+ settings.setValue(prefix + "title", title);
+ settings.setValue(prefix + "author", author);
+ settings.setValue(prefix + "filename", filename);
+ settings.setValue(prefix + "folio", folio);
+ settings.setValue(prefix + "date", exportDate());
+}
+
+/**
+ Importe le cartouche depuis une configuration.
+ @param settings Parametres a lire
+ @param prefix prefixe a ajouter devant les noms des parametres
+*/
+void TitleBlockProperties::fromSettings(QSettings &settings, const QString &prefix) {
+ title = settings.value(prefix + "title").toString();
+ author = settings.value(prefix + "author").toString();
+ filename = settings.value(prefix + "filename").toString();
+ folio = settings.value(prefix + "folio", "%id/%total").toString();
+ setDateFromString(settings.value(prefix + "date").toString());
+}
+
+/**
+ @return La date a utiliser
+*/
+QDate TitleBlockProperties::finalDate() const {
+ if (useDate == UseDateValue) {
+ return(date);
+ } else {
+ return(QDate::currentDate());
+ }
+}
+
+/**
+ @return une chaine de caracteres decrivant comment gerer la date dans le
+ cartouche : la chaine peut valoir :
+ * null pour ne pas afficher de date
+ * now pour afficher la date courante (a la creation du schema)
+ * une date au format yyyyMMdd pour utiliser une date fixe
+*/
+QString TitleBlockProperties::exportDate() const {
+ QString date_setting_value;
+ if (useDate == UseDateValue) {
+ if (date.isNull()) date_setting_value = "null";
+ else date_setting_value = date.toString("yyyyMMdd");
+ } else {
+ date_setting_value = "now";
+ }
+ return(date_setting_value);
+}
+
+/**
+ Charge les attributs date et useDate a partir d'une chaine de caracteres.
+ @param date_string Chaine de caracteres a analyser
+ @see exportDate
+*/
+void TitleBlockProperties::setDateFromString(const QString &date_string) {
+ if (date_string == "now") {
+ date = QDate::currentDate();
+ useDate = CurrentDate;
+ } else if (date_string.isEmpty() || date_string == "null") {
+ date = QDate();
+ useDate = UseDateValue;
+ } else {
+ date = QDate::fromString(date_string, "yyyyMMdd");
+ useDate = UseDateValue;
+ }
+}
Copied: branches/0.3/sources/titleblockproperties.h (from rev 1131, branches/0.3/sources/insetproperties.h)
===================================================================
--- branches/0.3/sources/titleblockproperties.h (rev 0)
+++ branches/0.3/sources/titleblockproperties.h 2010-12-20 02:45:36 UTC (rev 1132)
@@ -0,0 +1,58 @@
+/*
+ Copyright 2006-2010 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 <http://www.gnu.org/licenses/>.
+*/
+#ifndef TITLEBLOCK_PROPERTIES_H
+#define TITLEBLOCK_PROPERTIES_H
+#include <QtCore>
+#include <QtXml>
+/**
+ Cette classe est un conteneur pour les proprietes d'un cartouche de schema
+ : titre, auteur, date, nom de fichier et folio
+*/
+class TitleBlockProperties {
+ public:
+ TitleBlockProperties();
+ virtual ~TitleBlockProperties();
+ /// Specifie comment gerer la date
+ enum DateManagement {
+ UseDateValue, ///< utilise l'attribut date
+ CurrentDate ///< utilise la date courante
+ };
+
+ bool operator==(const TitleBlockProperties &);
+ bool operator!=(const TitleBlockProperties &);
+
+ void toXml(QDomElement &) const;
+ void fromXml(QDomElement &);
+ void toSettings(QSettings &, const QString & = QString()) const;
+ void fromSettings(QSettings &, const QString & = QString());
+
+ QDate finalDate() const ;
+
+ // attributs
+ QString title; ///< Titre affiche par le cartouche
+ QString author; ///< Auteur affiche par le cartouche
+ QDate date; ///< Date affichee par le cartouche ; si la date est nulle, le champ reste vide
+ QString filename; ///< Nom de fichier affiche par le cartouche
+ QString folio; ///< Folio affiche par le cartouche
+ DateManagement useDate; ///< Indique s'il faut utiliser ou non l'attribut date
+
+ private:
+ QString exportDate() const;
+ void setDateFromString(const QString &);
+};
+#endif
Copied: branches/0.3/sources/titleblockpropertieswidget.cpp (from rev 1131, branches/0.3/sources/insetpropertieswidget.cpp)
===================================================================
--- branches/0.3/sources/titleblockpropertieswidget.cpp (rev 0)
+++ branches/0.3/sources/titleblockpropertieswidget.cpp 2010-12-20 02:45:36 UTC (rev 1132)
@@ -0,0 +1,177 @@
+/*
+ Copyright 2006-2010 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 <http://www.gnu.org/licenses/>.
+*/
+#include "titleblockpropertieswidget.h"
+#include "qetapp.h"
+
+/**
+ Constructeur
+ @param titleblock TitleBlockProperties a afficher
+ @param current true pour afficher l'option "Date courante"
+ @param parent QWidget parent
+*/
+TitleBlockPropertiesWidget::TitleBlockPropertiesWidget(const TitleBlockProperties &titleblock, bool current, QWidget *parent) : QWidget(parent), display_current_date(false) {
+
+ QVBoxLayout *this_layout = new QVBoxLayout(this);
+ this_layout -> setContentsMargins(0, 0, 0, 0);
+ QGroupBox *titleblock_infos = new QGroupBox(tr("Informations du cartouche"), this);
+ titleblock_infos -> setMinimumSize(300, 330);
+ this_layout -> addWidget(titleblock_infos);
+
+ titleblock_title = new QLineEdit(this);
+ titleblock_author = new QLineEdit(this);
+
+ QButtonGroup *date_policy_group = new QButtonGroup(this);
+ titleblock_no_date = new QRadioButton(tr("Pas de date"), this);
+ titleblock_current_date = new QRadioButton(tr("Date courante"), this);
+ titleblock_fixed_date = new QRadioButton(tr("Date fixe : "), this);
+ date_policy_group -> addButton(titleblock_no_date);
+ date_policy_group -> addButton(titleblock_current_date);
+ date_policy_group -> addButton(titleblock_fixed_date);
+ titleblock_date = new QDateEdit(QDate::currentDate(), this);
+ titleblock_date -> setEnabled(titleblock_fixed_date -> isChecked());
+ titleblock_current_date -> setVisible(display_current_date);
+ connect(titleblock_fixed_date, SIGNAL(toggled(bool)), titleblock_date, SLOT(setEnabled(bool)));
+ titleblock_date -> setCalendarPopup(true);
+
+ QGridLayout *layout_date = new QGridLayout();
+ layout_date -> addWidget(titleblock_no_date, 0, 0);
+ layout_date -> addWidget(titleblock_current_date, 1, 0);
+ layout_date -> addWidget(titleblock_fixed_date, 2, 0);
+ layout_date -> addWidget(titleblock_date, 2, 1);
+ layout_date -> setColumnStretch(0, 1);
+ layout_date -> setColumnStretch(1, 500);
+
+ titleblock_filename = new QLineEdit(this);
+ titleblock_folio = new QLineEdit(this);
+ QLabel *folio_tip = new QLabel(
+ tr(
+ "Les variables suivantes sont utilisables dans le champ Folio :\n"
+ " - %id : num\351ro du sch\351ma courant dans le projet\n"
+ " - %total : nombre total de sch\351mas dans le projet"
+ )
+ );
+ folio_tip -> setWordWrap(true);
+
+ QGridLayout *layout_champs = new QGridLayout(titleblock_infos);
+
+ layout_champs -> addWidget(new QLabel(tr("Titre : ")), 0, 0);
+ layout_champs -> addWidget(titleblock_title, 0, 1);
+ layout_champs -> addWidget(new QLabel(tr("Auteur : ")), 1, 0);
+ layout_champs -> addWidget(titleblock_author, 1, 1);
+ layout_champs -> addWidget(new QLabel(tr("Date : ")), 2, 0, Qt::AlignTop);
+ layout_champs -> addLayout(layout_date, 2, 1);
+ layout_champs -> addWidget(new QLabel(tr("Fichier : ")), 3, 0);
+ layout_champs -> addWidget(titleblock_filename, 3, 1);
+ layout_champs -> addWidget(new QLabel(tr("Folio : ")), 4, 0);
+ layout_champs -> addWidget(titleblock_folio, 4, 1);
+ layout_champs -> addWidget(folio_tip, 5, 1, Qt::AlignTop);
+ layout_champs -> setRowStretch(5, 500);
+
+ titleblock_current_date -> setVisible(display_current_date = current);
+ setTitleBlockProperties(titleblock);
+ setLayout(this_layout);
+}
+
+/// Destructeur
+TitleBlockPropertiesWidget::~TitleBlockPropertiesWidget() {
+}
+
+/**
+ @return Les proprietes affichees par le widget
+*/
+TitleBlockProperties TitleBlockPropertiesWidget::titleBlockProperties() const {
+ TitleBlockProperties prop;
+ prop.title = titleblock_title -> text();
+ prop.author = titleblock_author -> text();
+ prop.filename = titleblock_filename -> text();
+ prop.folio = titleblock_folio -> text();
+ if (titleblock_no_date -> isChecked()) {
+ prop.useDate = TitleBlockProperties::UseDateValue;
+ prop.date = QDate();
+ } else if (titleblock_fixed_date -> isChecked()) {
+ prop.useDate = TitleBlockProperties::UseDateValue;
+ prop.date = titleblock_date -> date();
+ } else if (display_current_date && titleblock_current_date -> isChecked()) {
+ prop.useDate = TitleBlockProperties::CurrentDate;
+ prop.date = QDate::currentDate();
+ }
+ return(prop);
+}
+
+/**
+ Specifie les proprietes que le widget doit afficher
+ @param titleblock nouvelles proprietes affichees par le widget
+*/
+void TitleBlockPropertiesWidget::setTitleBlockProperties(const TitleBlockProperties &titleblock) {
+ titleblock_title -> setText(titleblock.title);
+ titleblock_author -> setText(titleblock.author);
+ titleblock_filename -> setText(titleblock.filename);
+ titleblock_folio -> setText(titleblock.folio);
+ if (display_current_date) {
+ if (titleblock.useDate == TitleBlockProperties::CurrentDate) {
+ titleblock_current_date -> setChecked(true);
+ } else {
+ if (titleblock.date.isNull()) {
+ titleblock_no_date -> setChecked(true);
+ } else {
+ titleblock_fixed_date -> setChecked(true);
+ titleblock_date -> setDate(titleblock.date);
+ }
+ }
+ } else {
+ if (titleblock.useDate == TitleBlockProperties::CurrentDate) {
+ titleblock_fixed_date -> setChecked(true);
+ titleblock_date -> setDate(QDate::currentDate());
+ } else {
+ if (titleblock.date.isNull()) {
+ titleblock_no_date -> setChecked(true);
+ } else {
+ titleblock_fixed_date -> setChecked(true);
+ titleblock_date -> setDate(titleblock.date);
+ }
+ }
+ }
+}
+
+/**
+ @return true si le widget affiche la proposition "Date courante", false sinon
+*/
+bool TitleBlockPropertiesWidget::displayCurrentDate() const {
+ return(display_current_date);
+}
+
+/**
+ @return true si ce widget est en lecture seule, false sinon
+*/
+bool TitleBlockPropertiesWidget::isReadOnly() const {
+ return(titleblock_title -> isReadOnly());
+}
+
+/**
+ @param ro true pour passer ce widget en lecture seule, false sinon
+*/
+void TitleBlockPropertiesWidget::setReadOnly(bool ro) {
+ titleblock_title -> setReadOnly(ro);
+ titleblock_author -> setReadOnly(ro);
+ titleblock_date -> setReadOnly(ro);
+ titleblock_filename -> setReadOnly(ro);
+ titleblock_folio -> setReadOnly(ro);
+ titleblock_no_date -> setDisabled(ro);
+ titleblock_current_date -> setDisabled(ro);
+ titleblock_fixed_date -> setDisabled(ro);
+}
Copied: branches/0.3/sources/titleblockpropertieswidget.h (from rev 1131, branches/0.3/sources/insetpropertieswidget.h)
===================================================================
--- branches/0.3/sources/titleblockpropertieswidget.h (rev 0)
+++ branches/0.3/sources/titleblockpropertieswidget.h 2010-12-20 02:45:36 UTC (rev 1132)
@@ -0,0 +1,55 @@
+/*
+ Copyright 2006-2010 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 <http://www.gnu.org/licenses/>.
+*/
+#ifndef TITLEBLOCK_PROPERTIES_WIDGET_H
+#define TITLEBLOCK_PROPERTIES_WIDGET_H
+#include <QtGui>
+#include "titleblockproperties.h"
+/**
+ Ce widget permet d'editer un objet TitleBlockProperties, c'est-a-dire les
+ valeurs affichees par le cartouche d'un schema.
+*/
+class TitleBlockPropertiesWidget : public QWidget {
+ Q_OBJECT
+ // constructeurs, destructeur
+ public:
+ TitleBlockPropertiesWidget(const TitleBlockProperties &titleblock = TitleBlockProperties(), bool = false, QWidget * = 0);
+ virtual ~TitleBlockPropertiesWidget();
+ private:
+ TitleBlockPropertiesWidget(const TitleBlockPropertiesWidget &);
+
+ // methodes
+ public:
+ TitleBlockProperties titleBlockProperties() const;
+ void setTitleBlockProperties(const TitleBlockProperties &);
+ bool displayCurrentDate() const;
+ bool isReadOnly() const;
+ void setReadOnly(bool);
+
+ // attributs
+ private:
+ QLineEdit *titleblock_title;
+ QLineEdit *titleblock_author;
+ QDateEdit *titleblock_date;
+ QLineEdit *titleblock_filename;
+ QLineEdit *titleblock_folio;
+ QRadioButton *titleblock_no_date;
+ QRadioButton *titleblock_current_date;
+ QRadioButton *titleblock_fixed_date;
+ bool display_current_date;
+};
+#endif
Copied: branches/0.3/sources/titleblocktemplate.cpp (from rev 1131, branches/0.3/sources/insettemplate.cpp)
===================================================================
--- branches/0.3/sources/titleblocktemplate.cpp (rev 0)
+++ branches/0.3/sources/titleblocktemplate.cpp 2010-12-20 02:45:36 UTC (rev 1132)
@@ -0,0 +1,580 @@
+/*
+ Copyright 2006-2010 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 <http://www.gnu.org/licenses/>.
+*/
+#include "titleblocktemplate.h"
+#include "qet.h"
+#include "qetapp.h"
+
+/**
+ Constructor
+ @param parent parent QObject
+*/
+TitleBlockTemplate::TitleBlockTemplate(QObject *parent) :
+ QObject(parent)
+{
+}
+
+/**
+ Destructor
+*/
+TitleBlockTemplate::~TitleBlockTemplate() {
+ loadLogos(QDomElement(), true);
+}
+
+/**
+ @param filepath A file path to read the template from.
+ @return true if the reading succeeds, false otherwise.
+*/
+bool TitleBlockTemplate::loadFromXmlFile(const QString &filepath) {
+ // opens the file
+ QFile template_file(filepath);
+ if (!template_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ return(false);
+ }
+
+ // parses its content as XML
+ bool xml_parsing = xml_description_.setContent(&template_file);
+ if (!xml_parsing) {
+ return(false);
+ }
+#ifdef TITLEBLOCK_TEMPLATE_DEBUG
+ qDebug() << Q_FUNC_INFO << filepath << "opened";
+#endif
+ return(loadFromXmlElement(xml_description_.documentElement()));
+}
+
+/**
+ @param xml_element An XML document to read the template from.
+ @return true if the reading succeeds, false otherwise.
+*/
+bool TitleBlockTemplate::loadFromXmlElement(const QDomElement &xml_element) {
+ // we expect the XML element to be an <titleblocktemplate>
+ if (xml_element.tagName() != "titleblocktemplate") {
+ return(false);
+ }
+
+ loadLogos(xml_element, true);
+ loadGrid(xml_element);
+ return(true);
+}
+
+/**
+ Imports the logos from a given XML titleblock template.
+ @param xml_element An XML element representing an titleblock template.
+ @param reset true to delete all previously known logos before, false
+ otherwise.
+ @return true if the reading succeeds, false otherwise.
+*/
+bool TitleBlockTemplate::loadLogos(const QDomElement &xml_element, bool reset) {
+ if (reset) {
+ qDeleteAll(vector_logos_.begin(), vector_logos_.end());
+ vector_logos_.clear();
+ qDeleteAll(bitmap_logos_.begin(), bitmap_logos_.end());
+ bitmap_logos_.clear();
+ }
+
+ // we look for //logos/logo elements
+ for (QDomNode n = xml_element.firstChild() ; !n.isNull() ; n = n.nextSibling()) {
+ if (n.isElement() && n.toElement().tagName() == "logos") {
+ for (QDomNode p = n.firstChild() ; !p.isNull() ; p = p.nextSibling()) {
+ if (p.isElement() && p.toElement().tagName() == "logo") {
+ loadLogo(p.toElement());
+ }
+ }
+ }
+ }
+
+ return(true);
+}
+
+/**
+ Imports the logo from a given XML logo description.
+ @param xml_element An XML element representing a logo within an titleblock
+ template.
+ @return true if the reading succeeds, false otherwise.
+*/
+bool TitleBlockTemplate::loadLogo(const QDomElement &xml_element) {
+ // we require a name
+ if (!xml_element.hasAttribute("name")) {
+ return(false);
+ }
+ QString logo_name = xml_element.attribute("name");
+ QString logo_type = xml_element.attribute("type", "png");
+ QString logo_storage = xml_element.attribute("storage", "base64");
+
+ // Both QSvgRenderer and QPixmap read their data from a QByteArray, so
+ // we convert the available data to that format.
+ QByteArray logo_data;
+ if (logo_storage == "xml") {
+ // only svg uses xml storage
+ QDomNodeList svg_nodes = xml_element.elementsByTagName("svg");
+ if (svg_nodes.isEmpty()) {
+ return(false);
+ }
+ QDomElement svg_element = svg_nodes.at(0).toElement();
+ QTextStream xml_to_byte_array(&logo_data);
+ svg_element.save(xml_to_byte_array, 0);
+ } else if (logo_storage == "base64") {
+ logo_data = QByteArray::fromBase64(xml_element.text().toAscii());
+ } else {
+ return(false);
+ }
+
+ // we can now create our image object from the byte array
+ if (logo_type == "svg") {
+ // SVG format is handled by the QSvgRenderer class
+ QSvgRenderer *svg = new QSvgRenderer(logo_data);
+ vector_logos_.insert(logo_name, svg);
+
+ /*QSvgWidget *test_svgwidget = new QSvgWidget();
+ test_svgwidget -> load(logo_data);
+ test_svgwidget -> show();*/
+ } else {
+ // bitmap formats are handled by the QPixmap class
+ QPixmap *logo_pixmap = new QPixmap();
+ logo_pixmap -> loadFromData(logo_data);
+ if (!logo_pixmap -> width() || !logo_pixmap -> height()) {
+ return(false);
+ }
+ bitmap_logos_.insert(logo_name, logo_pixmap);
+
+ /*QLabel *test_label = new QLabel();
+ test_label -> setPixmap(*logo_pixmap);
+ test_label -> show();*/
+ }
+
+ return(true);
+}
+
+/**
+ Imports the grid from a given XML titleblock template.
+ @param xml_element An XML element representing an titleblock template.
+ @return true if the reading succeeds, false otherwise.
+*/
+bool TitleBlockTemplate::loadGrid(const QDomElement &xml_element) {
+ // we parse the first available "grid" XML element
+ QDomElement grid_element;
+ for (QDomNode n = xml_element.firstChild() ; !n.isNull() ; n = n.nextSibling()) {
+ if (n.isElement() && n.toElement().tagName() == "grid") {
+ grid_element = n.toElement();
+ break;
+ }
+ }
+
+ if (!grid_element.hasAttribute("rows") || !grid_element.hasAttribute("cols")) {
+ return(false);
+ }
+
+ parseRows(grid_element.attribute("rows"));
+ parseColumns(grid_element.attribute("cols"));
+ loadCells(grid_element);
+ return(true);
+}
+
+/**
+ Parses the rows heights
+ @param rows_string A string describing the rows heights of the titleblock
+*/
+void TitleBlockTemplate::parseRows(const QString &rows_string) {
+ rows_heights_.clear();
+ // parse the rows attribute: we expect a serie of absolute heights
+ QRegExp row_size_format("^([0-9]+)(?:px)?$", Qt::CaseInsensitive);
+ bool conv_ok;
+
+ QStringList rows_descriptions = rows_string.split(QChar(';'), QString::SkipEmptyParts);
+ foreach (QString rows_description, rows_descriptions) {
+ if (row_size_format.exactMatch(rows_description)) {
+ int row_size = row_size_format.capturedTexts().at(1).toInt(&conv_ok);
+ if (conv_ok) rows_heights_ << row_size;
+ }
+ }
+#ifdef TITLEBLOCK_TEMPLATE_DEBUG
+ qDebug() << Q_FUNC_INFO << "Rows heights:" << rows_heights_;
+#endif
+}
+
+/**
+ Parses the columns widths
+ @param cols_string A string describing the columns widths of the titleblock
+*/
+void TitleBlockTemplate::parseColumns(const QString &cols_string) {
+ columns_width_.clear();
+ // parse the cols attribute: we expect a serie of absolute or relative widths
+ QRegExp abs_col_size_format("^([0-9]+)(?:px)?$", Qt::CaseInsensitive);
+ QRegExp rel_col_size_format("^([rt])([0-9]+)%$", Qt::CaseInsensitive);
+ bool conv_ok;
+
+ QStringList cols_descriptions = cols_string.split(QChar(';'), QString::SkipEmptyParts);
+ foreach (QString cols_description, cols_descriptions) {
+ if (abs_col_size_format.exactMatch(cols_description)) {
+ int col_size = abs_col_size_format.capturedTexts().at(1).toInt(&conv_ok);
+ if (conv_ok) columns_width_ << TitleBlockColDimension(col_size, QET::Absolute);
+ } else if (rel_col_size_format.exactMatch(cols_description)) {
+ int col_size = rel_col_size_format.capturedTexts().at(2).toInt(&conv_ok);
+ QET::TitleBlockColumnLength col_type = rel_col_size_format.capturedTexts().at(1) == "t" ? QET::RelativeToTotalLength : QET::RelativeToRemainingLength;
+ if (conv_ok) columns_width_ << TitleBlockColDimension(col_size, col_type );
+ }
+ }
+#ifdef TITLEBLOCK_TEMPLATE_DEBUG
+ foreach (TitleBlockColDimension icd, columns_width_) {
+ qDebug() << Q_FUNC_INFO << QString("%1 [%2]").arg(icd.value).arg(QET::titleBlockColumnLengthToString(icd.type));
+ }
+#endif
+}
+
+/**
+ Analyze an XML element, looking for grid cells. The grid cells are checked
+ and stored in this object.
+ @param xml_element XML element to analyze
+*/
+bool TitleBlockTemplate::loadCells(const QDomElement &xml_element) {
+ initCells();
+ // we are interested by the "logo" and "field" elements
+ QDomElement grid_element;
+ for (QDomNode n = xml_element.firstChild() ; !n.isNull() ; n = n.nextSibling()) {
+ if (!n.isElement()) continue;
+ QDomElement cell_element = n.toElement();
+ if (cell_element.tagName() == "field" || cell_element.tagName() == "logo") {
+ TitleBlockCell *loaded_cell;
+ if (!checkCell(cell_element, &loaded_cell)) continue;
+
+ if (cell_element.tagName() == "logo") {
+ if (cell_element.hasAttribute("resource") && !cell_element.attribute("resource").isEmpty()) {
+ loaded_cell -> logo_reference = cell_element.attribute("resource");
+ }
+ } else if (cell_element.tagName() == "field") {
+ if (cell_element.hasAttribute("name") && !cell_element.attribute("name").isEmpty()) {
+ loaded_cell -> value_name = cell_element.attribute("name");
+ }
+ if (cell_element.hasAttribute("value") && !cell_element.attribute("value").isEmpty()) {
+ loaded_cell -> value = cell_element.attribute("value");
+ }
+ if (cell_element.hasAttribute("label") && !cell_element.attribute("label").isEmpty()) {
+ loaded_cell -> label = cell_element.attribute("label");
+ }
+ if (cell_element.hasAttribute("displaylabel") && cell_element.attribute("displaylabel").compare("false", Qt::CaseInsensitive) == 0) {
+ loaded_cell -> display_label = false;
+ }
+
+ // horiwontal and vertical alignments
+ loaded_cell -> alignment = 0;
+
+ QString halignment = cell_element.attribute("align", "left");
+ if (halignment == "right") loaded_cell -> alignment |= Qt::AlignRight;
+ else if (halignment == "center") loaded_cell -> alignment |= Qt::AlignHCenter;
+ else loaded_cell -> alignment |= Qt::AlignLeft;
+
+ QString valignment = cell_element.attribute("valign", "center");
+ if (halignment == "bottom") loaded_cell -> alignment |= Qt::AlignBottom;
+ else if (halignment == "top") loaded_cell -> alignment |= Qt::AlignTop;
+ else loaded_cell -> alignment |= Qt::AlignVCenter;
+ }
+ }
+ }
+
+ return(true);
+}
+
+/**
+ @param xml_element XML element representing a cell, i.e. either an titleblock
+ logo or an titleblock field.
+ @param titleblock_cell_ptr Pointer to an TitleBlockCell object pointer - if non-zero and if
+ this method returns true, will be filled with the created TitleBlockCell
+ @return TRUE if the cell appears to be ok, FALSE otherwise
+*/
+bool TitleBlockTemplate::checkCell(const QDomElement &xml_element, TitleBlockCell **titleblock_cell_ptr) {
+ int col_count = columns_width_.count(), row_count = rows_heights_.count();
+
+#ifdef TITLEBLOCK_TEMPLATE_DEBUG
+ qDebug() << Q_FUNC_INFO << "begin" << row_count << col_count;
+#endif
+
+ int row_num, col_num, row_span, col_span;
+ bool has_row_span = false;
+ bool has_col_span = false;
+ row_num = col_num = -1;
+ row_span = col_span = 0;
+
+ // parse the row and col attributes
+ if (!QET::attributeIsAnInteger(xml_element, "row", &row_num) || row_num < 0 || row_num >= row_count) {
+ return(false);
+ }
+ if (!QET::attributeIsAnInteger(xml_element, "col", &col_num) || col_num < 0 || col_num >= col_count) {
+ return(false);
+ }
+
+ // check whether the target cell can be used or not
+#ifdef TITLEBLOCK_TEMPLATE_DEBUG
+ qDebug() << Q_FUNC_INFO << "cell access" << col_num << row_num;
+#endif
+ TitleBlockCell *cell_ptr = &(cells_[col_num][row_num]);
+ if (!cell_ptr -> is_null || cell_ptr -> spanner_cell) {
+ return(false);
+ }
+
+ // parse the rowspan and colspan attributes
+ if (QET::attributeIsAnInteger(xml_element, "rowspan", &row_span) && row_span > 0) {
+ if (row_num + row_span >= row_count) row_span = row_count - 1 - row_num;
+ has_row_span = true;
+ }
+
+ if (QET::attributeIsAnInteger(xml_element, "colspan", &col_span) && col_span > 0) {
+ if (col_num + col_span >= col_count) col_span = col_count - 1 - col_num;
+ has_col_span = true;
+ }
+
+ // check if we can span on the required area
+ if (has_row_span || has_col_span) {
+ for (int i = col_num ; i <= col_num + col_span ; ++ i) {
+ for (int j = row_num ; j <= row_num + row_span ; ++ j) {
+ if (i == col_num && j == row_num) continue;
+#ifdef TITLEBLOCK_TEMPLATE_DEBUG
+ qDebug() << Q_FUNC_INFO << "span check" << i << j;
+#endif
+ TitleBlockCell *current_cell = &(cells_[i][j]);
+ if (!current_cell -> is_null || current_cell -> spanner_cell) {
+ return(false);
+ }
+ }
+ }
+ }
+
+ // at this point, the cell is ok - we fill the adequate cells in the matrix
+#ifdef TITLEBLOCK_TEMPLATE_DEBUG
+ qDebug() << Q_FUNC_INFO << "cell writing";
+#endif
+ cell_ptr -> num_row = row_num;
+ cell_ptr -> num_col = col_num;
+ if (has_row_span) cell_ptr -> row_span = row_span;
+ if (has_col_span) cell_ptr -> col_span = col_span;
+ cell_ptr -> is_null = false;
+ if (titleblock_cell_ptr) *titleblock_cell_ptr = cell_ptr;
+
+ if (has_row_span || has_col_span) {
+ for (int i = col_num ; i <= col_num + col_span ; ++ i) {
+ for (int j = row_num ; j <= row_num + row_span ; ++ j) {
+ if (i == col_num && j == row_num) continue;
+#ifdef TITLEBLOCK_TEMPLATE_DEBUG
+ qDebug() << Q_FUNC_INFO << "span cells writing" << i << j;
+#endif
+ TitleBlockCell *current_cell = &(cells_[i][j]);
+ current_cell -> num_row = j;
+ current_cell -> num_col = i;
+ current_cell -> is_null = false;
+ current_cell -> spanner_cell = cell_ptr;
+ }
+ }
+ }
+
+ return(true);
+}
+
+/**
+ Initializes the internal cells grid with the row and column counts.
+ Note that this method does nothing if one of the internal lists
+ columns_width_ and rows_heights_ is empty.
+*/
+void TitleBlockTemplate::initCells() {
+ if (columns_width_.count() < 1 || rows_heights_.count() < 1) return;
+
+ cells_.resize(columns_width_.count());
+ int row_count = rows_heights_.count();
+ for (int i = 0 ; i < columns_width_.count() ; ++ i) {
+ cells_[i].resize(row_count);
+ // ensure every cell is a null cell
+ for (int j = 0 ; j < row_count ; ++ j) {
+ cells_[i][j] = TitleBlockCell();
+ }
+ }
+
+#ifdef TITLEBLOCK_TEMPLATE_DEBUG
+ qDebug() << Q_FUNC_INFO << toString();
+#endif
+}
+
+/**
+ @return A string representing the titleblock template
+ @see TitleBlockCell::toString()
+*/
+QString TitleBlockTemplate::toString() const {
+ QString str = "\n";
+ for (int j = 0 ; j < rows_heights_.count() ; ++ j) {
+ for (int i = 0 ; i < columns_width_.count() ; ++ i) {
+ str += cells_[i][j].toString() + " ";
+ }
+ str += "\n";
+ }
+ return(str);
+}
+
+/**
+ @param total_width The total width of the titleblock to render
+ @return the list of the columns widths for this rendering
+*/
+QList<int> TitleBlockTemplate::columnsWidth(int total_width) const {
+ if (total_width < 0) return(QList<int>());
+
+ // we first iter to determine the absolute and total-width-related widths
+ QVector<int> final_widths(columns_width_.count());
+ int abs_widths_sum = 0;
+
+ for (int i = 0 ; i < columns_width_.count() ; ++ i) {
+ TitleBlockColDimension icd = columns_width_.at(i);
+ if (icd.type == QET::Absolute) {
+ abs_widths_sum += icd.value;
+ final_widths[i] = icd.value;
+ } else if (icd.type == QET::RelativeToTotalLength) {
+ int abs_value = int(total_width * icd.value / 100);
+ abs_widths_sum += abs_value;
+ final_widths[i] = abs_value;
+ }
+ }
+
+ // we can now deduce the remaining width
+ int remaining_width = total_width - abs_widths_sum;
+
+ // we do a second iteration to build the final widths list
+ for (int i = 0 ; i < columns_width_.count() ; ++ i) {
+ TitleBlockColDimension icd = columns_width_.at(i);
+ if (icd.type == QET::RelativeToRemainingLength) {
+ final_widths[i] = int(remaining_width * icd.value / 100);
+ }
+ }
+ return(final_widths.toList());
+}
+
+int TitleBlockTemplate::height() const {
+ int height = 0;
+ foreach(int row_height, rows_heights_) {
+ height += row_height;
+ }
+ return(height);
+}
+
+/**
+ Render the titleblock.
+ @param painter Painter to use to render the titleblock
+ @param diagram_context Diagram context to use to generate the titleblock strings
+ @param titleblock_width Width of the titleblock to render
+*/
+void TitleBlockTemplate::render(QPainter &painter, const DiagramContext &diagram_context, int titleblock_width) const {
+ QList<int> widths = columnsWidth(titleblock_width);
+ int titleblock_height = height();
+
+ // prepare the QPainter
+ painter.setPen(Qt::black);
+ painter.setBrush(Qt::white);
+ painter.setFont(QETApp::diagramTextsFont());
+
+ // draw the titleblock border
+ painter.drawRect(QRect(0, 0, titleblock_width, titleblock_height));
+
+ // run through each inidividual cell
+ for (int j = 0 ; j < rows_heights_.count() ; ++ j) {
+ for (int i = 0 ; i < columns_width_.count() ; ++ i) {
+ if (cells_[i][j].spanner_cell) continue;
+
+ // calculate the border rect of the current cell
+ int x = lengthRange(0, cells_[i][j].num_col, widths);
+ int y = lengthRange(0, cells_[i][j].num_row, rows_heights_);
+ int w = lengthRange(cells_[i][j].num_col, cells_[i][j].num_col + 1 + cells_[i][j].col_span, widths);
+ int h = lengthRange(cells_[i][j].num_row, cells_[i][j].num_row + 1 + cells_[i][j].row_span, rows_heights_);
+ QRect cell_rect(x, y, w, h);
+
+ // draw the border rect of the current cell
+ painter.drawRect(cell_rect);
+
+ // render the inner content of the current cell
+ if (!cells_[i][j].logo_reference.isEmpty()) {
+ // the current cell appear to be a logo - we first look for the
+ // logo reference in our vector logos list, since they offer a
+ // potentially better (or, at least, not resolution-limited) rendering
+ if (vector_logos_.contains(cells_[i][j].logo_reference)) {
+ vector_logos_[cells_[i][j].logo_reference] -> render(&painter, cell_rect);
+ } else if (bitmap_logos_.contains(cells_[i][j].logo_reference)) {
+ painter.drawPixmap(cell_rect, *(bitmap_logos_[cells_[i][j].logo_reference]));
+ }
+ } else {
+ painter.drawText(cell_rect, cells_[i][j].alignment, finalTextForCell(cells_[i][j], diagram_context));
+ }
+
+ // draw again the border rect of the current cell, without the brush this time
+ painter.setBrush(Qt::NoBrush);
+ painter.drawRect(cell_rect);
+ }
+ }
+}
+
+/**
+ @param cell A cell from this template
+ @param diagram_context Diagram context to use to generate the final text for the given cell
+ @return the final text that has to be drawn in the given cell
+*/
+QString TitleBlockTemplate::finalTextForCell(const TitleBlockCell &cell, const DiagramContext &diagram_context) const {
+ QString cell_text = cell.value;
+
+ foreach (QString key, diagram_context.keys()) {
+ cell_text.replace("%{" + key + "}", diagram_context[key].toString());
+ cell_text.replace("%" + key, diagram_context[key].toString());
+ }
+ if (cell.display_label && !cell.label.isEmpty()) {
+ cell_text = QString(tr(" %1 : %2", "titleblock content - please let the blank space at the beginning")).arg(cell.label).arg(cell_text);
+ } else {
+ cell_text = QString(tr(" %1")).arg(cell_text);
+ }
+ return(cell_text);
+}
+
+/**
+ @return the width between two borders
+ @param start start border number
+ @param end end border number
+*/
+int TitleBlockTemplate::lengthRange(int start, int end, const QList<int> &lengths_list) const {
+ if (start > end || start >= lengths_list.count() || end > lengths_list.count()) {
+ qDebug() << Q_FUNC_INFO << "wont use" << start << "and" << end;
+ return(0);
+ }
+
+ int length = 0;
+ for (int i = start ; i < end ; ++i) {
+ length += lengths_list[i];
+ }
+ return(length);
+}
+
+
+
+/**
+ Constructor
+*/
+TitleBlockCell::TitleBlockCell() {
+ num_row = num_col = -1;
+ row_span = col_span = 0;
+ display_label = is_null = true;
+ spanner_cell = 0;
+}
+
+/**
+ @return A string representing the titleblock cell
+*/
+QString TitleBlockCell::toString() const {
+ if (is_null) return("TitleBlockCell{null}");
+ QString span_desc = (row_span > 0 || col_span > 0) ? QString("+%3,%4").arg(row_span).arg(col_span) : QET::pointerString(spanner_cell);
+ QString base_desc = QString("TitleBlockCell{ [%1, %2] %3 }").arg(num_row).arg(num_col).arg(span_desc);
+ return(base_desc);
+}
Copied: branches/0.3/sources/titleblocktemplate.h (from rev 1131, branches/0.3/sources/insettemplate.h)
===================================================================
--- branches/0.3/sources/titleblocktemplate.h (rev 0)
+++ branches/0.3/sources/titleblocktemplate.h 2010-12-20 02:45:36 UTC (rev 1132)
@@ -0,0 +1,92 @@
+/*
+ Copyright 2006-2010 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 <http://www.gnu.org/licenses/>.
+*/
+#ifndef TITLEBLOCK_TEMPLATE_H
+#define TITLEBLOCK_TEMPLATE_H
+#include <QtXml>
+#include <QtSvg>
+#include "diagramcontext.h"
+#include "titleblockcell.h"
+#include "qet.h"
+
+/**
+ This struct is a simple container associating a length with its type.
+ @see TitleBlockColumnLength
+*/
+struct TitleBlockColDimension {
+ TitleBlockColDimension(int v, QET::TitleBlockColumnLength t = QET::Absolute) {
+ value = v;
+ type = t;
+ }
+ QET::TitleBlockColumnLength type;
+ int value;
+};
+
+/**
+ This class represents an titleblock templ)ate for an electric diagram.
+ It can read from an XML document the layout of the table that graphically
+ represents the titleblock, and can produce a graphical rendering of it from a
+ diagram context (object embedding the informations of the diagram we want to
+ represent the titleblock.
+*/
+class TitleBlockTemplate : public QObject {
+ Q_OBJECT
+
+ // constructeurs, destructeur
+ public:
+ TitleBlockTemplate(QObject * = 0);
+ virtual ~TitleBlockTemplate();
+ private:
+ TitleBlockTemplate(const TitleBlockTemplate &);
+
+ // methodes
+ public:
+ bool loadFromXmlFile(const QString &);
+ bool loadFromXmlElement(const QDomElement &);
+ void setContext(const DiagramContext &);
+
+ QList<int> columnsWidth(int) const;
+ int height() const;
+
+ void render(QPainter &, const DiagramContext &, int) const;
+ QString toString() const;
+
+ protected:
+ bool loadLogos(const QDomElement &, bool = false);
+ bool loadLogo(const QDomElement &);
+ bool loadGrid(const QDomElement &);
+ bool loadCells(const QDomElement &);
+
+ 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<int> &) const;
+ QString finalTextForCell(const TitleBlockCell &, const DiagramContext &) const;
+
+ // attributs
+ private:
+ QDomDocument xml_description_;
+ QHash<QString, QSvgRenderer *> vector_logos_;
+ QHash<QString, QPixmap *> bitmap_logos_;
+ QList<int> rows_heights_;
+ QList<TitleBlockColDimension> columns_width_;
+ QVector< QVector<TitleBlockCell> > cells_;
+};
+#endif
Copied: branches/0.3/sources/titleblocktemplaterenderer.cpp (from rev 1131, branches/0.3/sources/insettemplaterenderer.cpp)
===================================================================
--- branches/0.3/sources/titleblocktemplaterenderer.cpp (rev 0)
+++ branches/0.3/sources/titleblocktemplaterenderer.cpp 2010-12-20 02:45:36 UTC (rev 1132)
@@ -0,0 +1,96 @@
+#include "titleblocktemplaterenderer.h"
+#include "titleblocktemplate.h"
+
+/**
+ Constructor
+ @param parnet Parent QObject of this renderer
+*/
+TitleBlockTemplateRenderer::TitleBlockTemplateRenderer(QObject *parent) :
+ QObject(parent),
+ titleblock_template_(0),
+ last_known_titleblock_width_(-1)
+{
+}
+
+/**
+ Destructor
+*/
+TitleBlockTemplateRenderer::~TitleBlockTemplateRenderer() {
+}
+
+/**
+ @return the titleblock template used for the rendering
+*/
+const TitleBlockTemplate *TitleBlockTemplateRenderer::titleBlockTemplate() const {
+ return(titleblock_template_);
+}
+
+/**
+ @param titleblock_template TitleBlock template to render.
+*/
+void TitleBlockTemplateRenderer::setTitleBlockTemplate(const TitleBlockTemplate *titleblock_template) {
+ if (titleblock_template != titleblock_template_) {
+ titleblock_template_ = titleblock_template;
+ invalidateRenderedTemplate();
+ }
+}
+
+/**
+ @param context Diagram Context to use when rendering the titleblock
+*/
+void TitleBlockTemplateRenderer::setContext(const DiagramContext &context) {
+ context_ = context;
+ invalidateRenderedTemplate();
+}
+
+/**
+ @return the height of the rendered template, or -1 if no template has been
+ set for this renderer.
+ @see TitleBlockTemplate::height()
+*/
+int TitleBlockTemplateRenderer::height() const {
+ if (!titleblock_template_) return(-1);
+ return(titleblock_template_ -> height());
+}
+
+/**
+ Render the titleblock.
+ @param provided_painter QPainter to use to render the titleblock.
+ @param titleblock_width The total width of the titleblock to render
+*/
+void TitleBlockTemplateRenderer::render(QPainter *provided_painter, int titleblock_width) {
+ if (!titleblock_template_) return;
+
+ // Do we really need to calculate all this again?
+ if (titleblock_width != last_known_titleblock_width_ || rendered_template_.isNull()) {
+ renderToQPicture(titleblock_width);
+ }
+
+ provided_painter -> save();
+ rendered_template_.play(provided_painter);
+ provided_painter -> restore();
+}
+
+/**
+ Renders the titleblock to the internal QPicture
+ @param titleblock_width Width of the titleblock to render
+*/
+void TitleBlockTemplateRenderer::renderToQPicture(int titleblock_width) {
+ if (!titleblock_template_) return;
+
+ // we render the template on our internal QPicture
+ QPainter painter(&rendered_template_);
+
+ titleblock_template_ -> render(painter, context_, titleblock_width);
+
+ // memorize the last known width
+ last_known_titleblock_width_ = titleblock_width;
+}
+
+/**
+ Invalidates the previous rendering of the template by resetting the internal
+ QPicture.
+*/
+void TitleBlockTemplateRenderer::invalidateRenderedTemplate() {
+ rendered_template_ = QPicture();
+}
Copied: branches/0.3/sources/titleblocktemplaterenderer.h (from rev 1131, branches/0.3/sources/insettemplaterenderer.h)
===================================================================
--- branches/0.3/sources/titleblocktemplaterenderer.h (rev 0)
+++ branches/0.3/sources/titleblocktemplaterenderer.h 2010-12-20 02:45:36 UTC (rev 1132)
@@ -0,0 +1,45 @@
+/*
+ Copyright 2006-2010 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 <http://www.gnu.org/licenses/>.
+*/
+#ifndef TITLEBLOCK_TEMPLATE_RENDERER_H
+#define TITLEBLOCK_TEMPLATE_RENDERER_H
+#include <QPicture>
+#include "diagramcontext.h"
+class TitleBlockTemplate;
+class TitleBlockTemplateRenderer : public QObject {
+ Q_OBJECT
+
+ public:
+ TitleBlockTemplateRenderer(QObject * = 0);
+ virtual ~TitleBlockTemplateRenderer();
+ const TitleBlockTemplate *titleBlockTemplate() const;
+ void setTitleBlockTemplate(const TitleBlockTemplate *);
+ void setContext(const DiagramContext &context);
+ int height() const;
+ void render(QPainter *, int);
+
+ private:
+ void renderToQPicture(int);
+ void invalidateRenderedTemplate();
+
+ private:
+ const TitleBlockTemplate *titleblock_template_;
+ QPicture rendered_template_;
+ DiagramContext context_;
+ int last_known_titleblock_width_;
+};
+#endif
Deleted: branches/0.3/titleblocks/default.inset
===================================================================
--- branches/0.3/insets/default.inset 2010-12-19 18:14:05 UTC (rev 1131)
+++ branches/0.3/titleblocks/default.inset 2010-12-20 02:45:36 UTC (rev 1132)
@@ -1,11 +0,0 @@
-<insettemplate name="default">
- <informations>Author: The QElectroTech team
-License: see http://qelectrotech.org/wiki/doc/elements_license</informations>
- <grid rows="25px;25px" cols="t22%;r100%;t22%">
- <field row="0" col="0" name="author" label="Auteur" displaylabel="true" align="left" rowspan="0" value="%author" />
- <field row="1" col="0" name="date" label="Date" displaylabel="true" align="left" rowspan="0" value="%date" />
- <field row="0" col="1" name="title" label="Titre" displaylabel="false" align="center" rowspan="1" value="%title" />
- <field row="0" col="2" name="file" label="Fichier" displaylabel="true" align="left" rowspan="0" value="%filename" />
- <field row="1" col="2" name="folio" label="Folio" displaylabel="true" align="left" rowspan="0" value="%{folio-id}/%{folio-total}" />
- </grid>
-</insettemplate>
Copied: branches/0.3/titleblocks/default.titleblock (from rev 1131, branches/0.3/insets/default.inset)
===================================================================
--- branches/0.3/titleblocks/default.titleblock (rev 0)
+++ branches/0.3/titleblocks/default.titleblock 2010-12-20 02:45:36 UTC (rev 1132)
@@ -0,0 +1,11 @@
+<titleblocktemplate name="default">
+ <informations>Author: The QElectroTech team
+License: see http://qelectrotech.org/wiki/doc/elements_license</informations>
+ <grid rows="25px;25px" cols="t22%;r100%;t22%">
+ <field row="0" col="0" name="author" label="Auteur" displaylabel="true" align="left" rowspan="0" value="%author" />
+ <field row="1" col="0" name="date" label="Date" displaylabel="true" align="left" rowspan="0" value="%date" />
+ <field row="0" col="1" name="title" label="Titre" displaylabel="false" align="center" rowspan="1" value="%title" />
+ <field row="0" col="2" name="file" label="Fichier" displaylabel="true" align="left" rowspan="0" value="%filename" />
+ <field row="1" col="2" name="folio" label="Folio" displaylabel="true" align="left" rowspan="0" value="%{folio-id}/%{folio-total}" />
+ </grid>
+</titleblocktemplate>