Added a combo box in the title block properties to choose the template that will render the title block.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1134 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
xavier 2010-12-24 23:35:40 +00:00
parent 649e3de3e6
commit aeae9a9f89
11 changed files with 140 additions and 37 deletions

View File

@ -99,6 +99,7 @@ TitleBlockProperties BorderTitleBlock::exportTitleBlock() {
ip.title = bi_title;
ip.folio = bi_folio;
ip.filename = bi_filename;
ip.template_name = titleBlockTemplateName();
return(ip);
}
@ -113,6 +114,7 @@ void BorderTitleBlock::importTitleBlock(const TitleBlockProperties &ip) {
bi_filename = ip.filename;
updateDiagramContextForTitleBlock();
emit(needFolioData());
emit(needTitleBlockTemplate(ip.template_name));
}
/**
@ -161,6 +163,14 @@ void BorderTitleBlock::setTitleBlockTemplate(const TitleBlockTemplate *titlebloc
titleblock_template_renderer -> setTitleBlockTemplate(titleblock_template);
}
/**
@return The name of the template used to render the titleblock.
*/
QString BorderTitleBlock::titleBlockTemplateName() const {
QString tbt_name = titleblock_template_renderer -> titleBlockTemplate() -> name();
return((tbt_name == "default") ? "" : tbt_name);
}
/**
This slot may be used to inform this class that the given title block
template has changed. The title block-dedicated rendering cache will thus be
@ -168,7 +178,7 @@ void BorderTitleBlock::setTitleBlockTemplate(const TitleBlockTemplate *titlebloc
@param template_name Name of the title block template that has changed
*/
void BorderTitleBlock::titleBlockTemplateChanged(const QString &template_name) {
Q_UNUSED(template_name); // this class does not store the name of its template
if (titleBlockTemplateName() != template_name) return;
titleblock_template_renderer -> invalidateRenderedTemplate();
}
@ -181,7 +191,7 @@ void BorderTitleBlock::titleBlockTemplateChanged(const QString &template_name) {
@param new_template (Optional) title block template to use instead
*/
void BorderTitleBlock::titleBlockTemplateRemoved(const QString &removed_template_name, const TitleBlockTemplate *new_template) {
Q_UNUSED(removed_template_name); // this class does not store the name of its template
if (titleBlockTemplateName() != removed_template_name) return;
if (new_template) {
setTitleBlockTemplate(new_template);

View File

@ -152,6 +152,7 @@ class BorderTitleBlock : public QObject {
const TitleBlockTemplate *titleBlockTemplate();
void setTitleBlockTemplate(const TitleBlockTemplate *);
QString titleBlockTemplateName() const;
public slots:
void titleBlockTemplateChanged(const QString &);
@ -192,6 +193,13 @@ class BorderTitleBlock : public QObject {
*/
void needFolioData();
/**
Signal emitted when this object needs to set a specific title block
template. This object cannot handle the job since it does not know of
its parent project.
*/
void needTitleBlockTemplate(const QString &);
// attributs
private:
// informations du cartouche

View File

@ -63,6 +63,11 @@ Diagram::Diagram(QObject *parent) :
// initialise les objets gerant les deplacements
elements_mover_ = new ElementsMover(); // deplacements d'elements/conducteurs/textes
element_texts_mover_ = new ElementTextsMover(); // deplacements d'ElementTextItem
connect(
&border_and_titleblock, SIGNAL(needTitleBlockTemplate(const QString &)),
this, SLOT(setTitleBlockTemplate(const QString &))
);
}
/**
@ -272,6 +277,7 @@ QDomDocument Diagram::toXml(bool whole_content) {
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());
@ -280,8 +286,9 @@ QDomDocument Diagram::toXml(bool whole_content) {
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_);
QString current_template_name = border_and_titleblock.titleBlockTemplateName();
if (!current_template_name.isEmpty()) {
racine.setAttribute("titleblocktemplate", current_template_name);
}
// type de conducteur par defaut
@ -422,14 +429,7 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
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);
}
}
setTitleBlockTemplate(root.attribute("titleblocktemplate", ""));
bool ok;
// nombre de colonnes
@ -772,9 +772,9 @@ void Diagram::diagramTextChanged(DiagramTextItem *text_item, const QString &old_
@param template_name Name of the title block template that has changed
*/
void Diagram::titleBlockTemplateChanged(const QString &template_name) {
if (titleblock_template_name_ == template_name) {
if (border_and_titleblock.titleBlockTemplateName() != template_name) return;
border_and_titleblock.titleBlockTemplateChanged(template_name);
}
update();
}
@ -787,12 +787,23 @@ void Diagram::titleBlockTemplateChanged(const QString &template_name) {
@param new_template (Optional) Name of the title block template to use instead
*/
void Diagram::titleBlockTemplateRemoved(const QString &template_name, const QString &new_template) {
if (titleblock_template_name_ == template_name) {
if (border_and_titleblock.titleBlockTemplateName() != template_name) return;
const TitleBlockTemplate *final_template = project_ -> getTemplateByName(new_template);
titleblock_template_name_ = final_template ? new_template : QString();
border_and_titleblock.titleBlockTemplateRemoved(template_name, final_template);
update();
}
}
/**
Set the template to use to render the title block of this diagram.
@param template_name Name of the title block template.
*/
void Diagram::setTitleBlockTemplate(const QString &template_name) {
if (!project_) return;
QString current_name = border_and_titleblock.titleBlockTemplateName();
const TitleBlockTemplate *titleblock_template = project_ -> getTemplateByName(template_name);
border_and_titleblock.titleBlockTemplateRemoved(current_name, titleblock_template);
}
/**

View File

@ -85,7 +85,6 @@ class Diagram : public QGraphicsScene {
QDomDocument xml_document;
QETProject *project_;
bool read_only_;
QString titleblock_template_name_;
// methodes
protected:
@ -171,6 +170,7 @@ class Diagram : public QGraphicsScene {
void diagramTextChanged(DiagramTextItem *, const QString &, const QString &);
void titleBlockTemplateChanged(const QString &);
void titleBlockTemplateRemoved(const QString &, const QString & = QString());
void setTitleBlockTemplate(const QString &);
// fonctions relative a la selection sur le schema
void selectAll();

View File

@ -426,7 +426,15 @@ void DiagramView::editDiagramProperties() {
BorderPropertiesWidget *border_infos = new BorderPropertiesWidget(border, &popup);
border_infos -> setReadOnly(diagram_is_read_only);
TitleBlockPropertiesWidget *titleblock_infos = new TitleBlockPropertiesWidget(titleblock, false, &popup);
if (QETProject *parent_project = scene -> project()) {
titleblock_infos -> setTitleBlockTemplatesList(parent_project -> embeddedTitleBlockTemplates());
titleblock_infos -> setTitleBlockTemplatesVisible(true);
// we have to parse again the TitleBlockProperties object, since the
// first parsing did not know of our templates
titleblock_infos -> setTitleBlockProperties(titleblock);
}
titleblock_infos -> setReadOnly(diagram_is_read_only);
// boutons

View File

@ -43,7 +43,8 @@ bool TitleBlockProperties::operator==(const TitleBlockProperties &ip) {
ip.author == author &&\
ip.date == date &&\
ip.filename == filename &&\
ip.folio == folio
ip.folio == folio &&\
ip.template_name == template_name
);
}
@ -66,6 +67,9 @@ void TitleBlockProperties::toXml(QDomElement &e) const {
e.setAttribute("filename", filename);
e.setAttribute("folio", folio);
e.setAttribute("date", exportDate());
if (!template_name.isEmpty()) {
e.setAttribute("titleblocktemplate", template_name);
}
}
/**
@ -78,6 +82,7 @@ void TitleBlockProperties::fromXml(QDomElement &e) {
if (e.hasAttribute("filename")) filename = e.attribute("filename");
if (e.hasAttribute("folio")) folio = e.attribute("folio");
if (e.hasAttribute("date")) setDateFromString(e.attribute("date"));
if (e.hasAttribute("titleblocktemplate")) template_name = e.attribute("titleblocktemplate");
}
/**

View File

@ -50,6 +50,7 @@ class TitleBlockProperties {
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
QString template_name; ///< Name of the template used to render the title block - an empty string means "the default template provided by the application"
private:
QString exportDate() const;

View File

@ -16,6 +16,7 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "titleblockpropertieswidget.h"
#include "qeticons.h"
#include "qetapp.h"
/**
@ -32,6 +33,9 @@ TitleBlockPropertiesWidget::TitleBlockPropertiesWidget(const TitleBlockPropertie
titleblock_infos -> setMinimumSize(300, 330);
this_layout -> addWidget(titleblock_infos);
titleblock_template_label = new QLabel(tr("Mod\350le :"));
titleblock_template_name = new QComboBox();
titleblock_title = new QLineEdit(this);
titleblock_author = new QLineEdit(this);
@ -68,23 +72,28 @@ TitleBlockPropertiesWidget::TitleBlockPropertiesWidget(const TitleBlockPropertie
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 -> addWidget(titleblock_template_label, 0, 0);
layout_champs -> addWidget(titleblock_template_name, 0, 1);
layout_champs -> addWidget(new QLabel(tr("Titre : ")), 1, 0);
layout_champs -> addWidget(titleblock_title, 1, 1);
layout_champs -> addWidget(new QLabel(tr("Auteur : ")), 2, 0);
layout_champs -> addWidget(titleblock_author, 2, 1);
layout_champs -> addWidget(new QLabel(tr("Date : ")), 3, 0, Qt::AlignTop);
layout_champs -> addLayout(layout_date, 3, 1);
layout_champs -> addWidget(new QLabel(tr("Fichier : ")), 4, 0);
layout_champs -> addWidget(titleblock_filename, 4, 1);
layout_champs -> addWidget(new QLabel(tr("Folio : ")), 5, 0);
layout_champs -> addWidget(titleblock_folio, 5, 1);
layout_champs -> addWidget(folio_tip, 6, 1, Qt::AlignTop);
layout_champs -> setRowStretch(5, 500);
titleblock_current_date -> setVisible(display_current_date = current);
setTitleBlockProperties(titleblock);
setLayout(this_layout);
// by default, we do not display the template combo box
titleblock_template_label -> setVisible(false);
titleblock_template_name -> setVisible(false);
}
/// Destructeur
@ -110,6 +119,12 @@ TitleBlockProperties TitleBlockPropertiesWidget::titleBlockProperties() const {
prop.useDate = TitleBlockProperties::CurrentDate;
prop.date = QDate::currentDate();
}
int index = titleblock_template_name -> currentIndex();
if (index != -1) {
prop.template_name = titleblock_template_name -> itemData(index).toString();
}
return(prop);
}
@ -146,6 +161,13 @@ void TitleBlockPropertiesWidget::setTitleBlockProperties(const TitleBlockPropert
}
}
}
if (!titleblock.template_name.isEmpty()) {
int matching_index = titleblock_template_name -> findData(titleblock.template_name);
if (matching_index != -1) {
titleblock_template_name -> setCurrentIndex(matching_index);
}
}
}
/**
@ -174,4 +196,27 @@ void TitleBlockPropertiesWidget::setReadOnly(bool ro) {
titleblock_no_date -> setDisabled(ro);
titleblock_current_date -> setDisabled(ro);
titleblock_fixed_date -> setDisabled(ro);
titleblock_template_label -> setDisabled(ro);
titleblock_template_name -> setDisabled(ro);
}
/**
@param templates List of template names the dedicated combo box should
display.
*/
void TitleBlockPropertiesWidget::setTitleBlockTemplatesList(const QList<QString> &templates) {
titleblock_template_name -> clear();
titleblock_template_name -> addItem(QET::Icons::TitleBlock, tr("Mod\350le par d\351faut"), QString());
foreach (QString template_name, templates) {
titleblock_template_name -> addItem(QET::Icons::TitleBlock, template_name, template_name);
}
}
/**
@param visible true to display the title block templates list, false to
hide it.
*/
void TitleBlockPropertiesWidget::setTitleBlockTemplatesVisible(bool visible) {
titleblock_template_name -> setVisible(visible);
titleblock_template_label -> setVisible(visible);
}

View File

@ -39,6 +39,8 @@ class TitleBlockPropertiesWidget : public QWidget {
bool displayCurrentDate() const;
bool isReadOnly() const;
void setReadOnly(bool);
void setTitleBlockTemplatesList(const QList<QString> &);
void setTitleBlockTemplatesVisible(bool);
// attributs
private:
@ -51,5 +53,7 @@ class TitleBlockPropertiesWidget : public QWidget {
QRadioButton *titleblock_current_date;
QRadioButton *titleblock_fixed_date;
bool display_current_date;
QLabel *titleblock_template_label;
QComboBox *titleblock_template_name;
};
#endif

View File

@ -66,6 +66,10 @@ bool TitleBlockTemplate::loadFromXmlElement(const QDomElement &xml_element) {
if (xml_element.tagName() != "titleblocktemplate") {
return(false);
}
if (!xml_element.hasAttribute("name")) {
return(false);
}
name_ = xml_element.attribute("name");
loadLogos(xml_element, true);
loadGrid(xml_element);
@ -421,6 +425,13 @@ QString TitleBlockTemplate::toString() const {
return(str);
}
/**
@return the name of this template
*/
QString TitleBlockTemplate::name() const {
return(name_);
}
/**
@param total_width The total width of the titleblock to render
@return the list of the columns widths for this rendering

View File

@ -57,8 +57,7 @@ class TitleBlockTemplate : public QObject {
public:
bool loadFromXmlFile(const QString &);
bool loadFromXmlElement(const QDomElement &);
void setContext(const DiagramContext &);
QString name() const;
QList<int> columnsWidth(int) const;
int height() const;
@ -83,6 +82,7 @@ class TitleBlockTemplate : public QObject {
// attributs
private:
QDomDocument xml_description_;
QString name_;
QHash<QString, QSvgRenderer *> vector_logos_;
QHash<QString, QPixmap *> bitmap_logos_;
QList<int> rows_heights_;