mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
Introduced project-wide properties, i.e. key/value pairs defined at the project scope available in all child diagrams.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@1892 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -192,8 +192,8 @@ void BorderTitleBlock::importTitleBlock(const TitleBlockProperties &ip) {
|
|||||||
setFolio(ip.folio);
|
setFolio(ip.folio);
|
||||||
additional_fields_ = ip.context;
|
additional_fields_ = ip.context;
|
||||||
|
|
||||||
emit(needFolioData());
|
emit(needFolioData()); // Note: we expect additional data to be provided
|
||||||
updateDiagramContextForTitleBlock();
|
// through setFolioData(), which in turn calls updateDiagramContextForTitleBlock().
|
||||||
emit(needTitleBlockTemplate(ip.template_name));
|
emit(needTitleBlockTemplate(ip.template_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -572,10 +572,16 @@ DiagramPosition BorderTitleBlock::convertPosition(const QPointF &pos) {
|
|||||||
/**
|
/**
|
||||||
Update the informations given to the titleblock template by regenerating a
|
Update the informations given to the titleblock template by regenerating a
|
||||||
DiagramContext object.
|
DiagramContext object.
|
||||||
|
@param initial_context Base diagram context that will be overridden by
|
||||||
|
diagram-wide values
|
||||||
*/
|
*/
|
||||||
void BorderTitleBlock::updateDiagramContextForTitleBlock() {
|
void BorderTitleBlock::updateDiagramContextForTitleBlock(const DiagramContext &initial_context) {
|
||||||
// our final DiagramContext object is the "additional fields" one
|
// Our final DiagramContext is the initial one (which is supposed to bring
|
||||||
DiagramContext context = additional_fields_;
|
// project-wide properties), overridden by the "additional fields" one...
|
||||||
|
DiagramContext context = initial_context;
|
||||||
|
foreach (QString key, additional_fields_.keys()) {
|
||||||
|
context.addValue(key, additional_fields_[key]);
|
||||||
|
}
|
||||||
|
|
||||||
// ... overridden by the historical and/or dynamically generated fields
|
// ... overridden by the historical and/or dynamically generated fields
|
||||||
context.addValue("author", bi_author);
|
context.addValue("author", bi_author);
|
||||||
@@ -609,8 +615,9 @@ QString BorderTitleBlock::incrementLetters(const QString &string) {
|
|||||||
/**
|
/**
|
||||||
@param index numero du schema (de 1 a total)
|
@param index numero du schema (de 1 a total)
|
||||||
@param total nombre total de schemas dans le projet
|
@param total nombre total de schemas dans le projet
|
||||||
|
@param project_properties Project-wide properties, to be merged with diagram-wide ones.
|
||||||
*/
|
*/
|
||||||
void BorderTitleBlock::setFolioData(int index, int total) {
|
void BorderTitleBlock::setFolioData(int index, int total, const DiagramContext &project_properties) {
|
||||||
if (index < 1 || total < 1 || index > total) return;
|
if (index < 1 || total < 1 || index > total) return;
|
||||||
|
|
||||||
// memorise les informations
|
// memorise les informations
|
||||||
@@ -622,5 +629,5 @@ void BorderTitleBlock::setFolioData(int index, int total) {
|
|||||||
bi_final_folio.replace("%id", QString::number(folio_index_));
|
bi_final_folio.replace("%id", QString::number(folio_index_));
|
||||||
bi_final_folio.replace("%total", QString::number(folio_total_));
|
bi_final_folio.replace("%total", QString::number(folio_total_));
|
||||||
|
|
||||||
updateDiagramContextForTitleBlock();
|
updateDiagramContextForTitleBlock(project_properties);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ class BorderTitleBlock : public QObject {
|
|||||||
}
|
}
|
||||||
/// @param folio le nouveau contenu du champ "Folio"
|
/// @param folio le nouveau contenu du champ "Folio"
|
||||||
void setFolio (const QString &folio) { bi_folio = folio; }
|
void setFolio (const QString &folio) { bi_folio = folio; }
|
||||||
void setFolioData(int, int);
|
void setFolioData(int, int, const DiagramContext & = DiagramContext());
|
||||||
/// @param filename le nouveau contenu du champ "Fichier"
|
/// @param filename le nouveau contenu du champ "Fichier"
|
||||||
void setFileName (const QString &filename) { bi_filename = filename; }
|
void setFileName (const QString &filename) { bi_filename = filename; }
|
||||||
|
|
||||||
@@ -172,7 +172,7 @@ class BorderTitleBlock : public QObject {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void updateRectangles();
|
void updateRectangles();
|
||||||
void updateDiagramContextForTitleBlock();
|
void updateDiagramContextForTitleBlock(const DiagramContext & = DiagramContext());
|
||||||
QString incrementLetters(const QString &);
|
QString incrementLetters(const QString &);
|
||||||
|
|
||||||
// signaux
|
// signaux
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "qetproject.h"
|
#include "qetproject.h"
|
||||||
#include "borderpropertieswidget.h"
|
#include "borderpropertieswidget.h"
|
||||||
#include "conductorpropertieswidget.h"
|
#include "conductorpropertieswidget.h"
|
||||||
|
#include "diagramcontextwidget.h"
|
||||||
#include "titleblockpropertieswidget.h"
|
#include "titleblockpropertieswidget.h"
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
|
|
||||||
@@ -105,6 +106,7 @@ QIcon ProjectMainConfigPage::icon() const {
|
|||||||
*/
|
*/
|
||||||
void ProjectMainConfigPage::applyProjectConf() {
|
void ProjectMainConfigPage::applyProjectConf() {
|
||||||
project_ -> setTitle(title_value_ -> text());
|
project_ -> setTitle(title_value_ -> text());
|
||||||
|
project_ -> setProjectProperties(project_variables_ -> context());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -120,6 +122,14 @@ QString ProjectMainConfigPage::projectTitle() const {
|
|||||||
void ProjectMainConfigPage::initWidgets() {
|
void ProjectMainConfigPage::initWidgets() {
|
||||||
title_label_ = new QLabel(tr("Titre du projet\240:", "label when configuring"));
|
title_label_ = new QLabel(tr("Titre du projet\240:", "label when configuring"));
|
||||||
title_value_ = new QLineEdit();
|
title_value_ = new QLineEdit();
|
||||||
|
project_variables_label_ = new QLabel(
|
||||||
|
tr(
|
||||||
|
"Vous pouvez d\351finir ci-dessous des variables qui seront disponibles pour tous les sch\351mas de ce projet (typiquement pour les cartouches).",
|
||||||
|
"informative label"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
project_variables_ = new DiagramContextWidget();
|
||||||
|
project_variables_ -> setContext(DiagramContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -131,7 +141,8 @@ void ProjectMainConfigPage::initLayout() {
|
|||||||
title_layout0 -> addWidget(title_label_);
|
title_layout0 -> addWidget(title_label_);
|
||||||
title_layout0 -> addWidget(title_value_);
|
title_layout0 -> addWidget(title_value_);
|
||||||
main_layout0 -> addLayout(title_layout0);
|
main_layout0 -> addLayout(title_layout0);
|
||||||
main_layout0 -> addStretch();
|
main_layout0 -> addWidget(project_variables_label_);
|
||||||
|
main_layout0 -> addWidget(project_variables_);
|
||||||
setLayout(main_layout0);
|
setLayout(main_layout0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,6 +151,7 @@ void ProjectMainConfigPage::initLayout() {
|
|||||||
*/
|
*/
|
||||||
void ProjectMainConfigPage::readValuesFromProject() {
|
void ProjectMainConfigPage::readValuesFromProject() {
|
||||||
title_value_ -> setText(project_ -> title());
|
title_value_ -> setText(project_ -> title());
|
||||||
|
project_variables_ -> setContext(project_ -> projectProperties());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ class QETProject;
|
|||||||
class BorderPropertiesWidget;
|
class BorderPropertiesWidget;
|
||||||
class TitleBlockPropertiesWidget;
|
class TitleBlockPropertiesWidget;
|
||||||
class ConductorPropertiesWidget;
|
class ConductorPropertiesWidget;
|
||||||
|
class DiagramContextWidget;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This class, derived from ConfigPage, aims at providing the basic skeleton
|
This class, derived from ConfigPage, aims at providing the basic skeleton
|
||||||
@@ -88,6 +89,8 @@ class ProjectMainConfigPage : public ProjectConfigPage {
|
|||||||
protected:
|
protected:
|
||||||
QLabel *title_label_;
|
QLabel *title_label_;
|
||||||
QLineEdit *title_value_;
|
QLineEdit *title_value_;
|
||||||
|
QLabel *project_variables_label_;
|
||||||
|
DiagramContextWidget *project_variables_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -417,6 +417,11 @@ QDomDocument QETProject::toXml() {
|
|||||||
project_root.appendChild(titleblocktemplates_elmt);
|
project_root.appendChild(titleblocktemplates_elmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// project-wide properties
|
||||||
|
QDomElement project_properties = xml_doc.createElement("properties");
|
||||||
|
writeProjectPropertiesXml(project_properties);
|
||||||
|
project_root.appendChild(project_properties);
|
||||||
|
|
||||||
// proprietes pour les nouveaux schemas
|
// proprietes pour les nouveaux schemas
|
||||||
QDomElement new_diagrams_properties = xml_doc.createElement("newdiagrams");
|
QDomElement new_diagrams_properties = xml_doc.createElement("newdiagrams");
|
||||||
writeDefaultPropertiesXml(new_diagrams_properties);
|
writeDefaultPropertiesXml(new_diagrams_properties);
|
||||||
@@ -900,6 +905,9 @@ void QETProject::readProjectXml() {
|
|||||||
state_ = ProjectParsingFailed;
|
state_ = ProjectParsingFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// load the project-wide properties
|
||||||
|
readProjectPropertiesXml();
|
||||||
|
|
||||||
// charge les proprietes par defaut pour les nouveaux schemas
|
// charge les proprietes par defaut pour les nouveaux schemas
|
||||||
readDefaultPropertiesXml();
|
readDefaultPropertiesXml();
|
||||||
|
|
||||||
@@ -979,6 +987,22 @@ void QETProject::readElementsCollectionXml() {
|
|||||||
connect(collection_, SIGNAL(written()), this, SLOT(componentWritten()));
|
connect(collection_, SIGNAL(written()), this, SLOT(componentWritten()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Load project properties from the XML description of the project
|
||||||
|
*/
|
||||||
|
void QETProject::readProjectPropertiesXml() {
|
||||||
|
foreach (QDomElement e, QET::findInDomElement(document_root_.documentElement(), "properties")) {
|
||||||
|
project_properties_.fromXml(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Export project properties under the \a xml_element XML element.
|
||||||
|
*/
|
||||||
|
void QETProject::writeProjectPropertiesXml(QDomElement &xml_element) {
|
||||||
|
project_properties_.toXml(xml_element);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Charge les proprietes par defaut des nouveaux schemas depuis la description
|
Charge les proprietes par defaut des nouveaux schemas depuis la description
|
||||||
XML du projet :
|
XML du projet :
|
||||||
@@ -1139,6 +1163,21 @@ bool QETProject::diagramsWereModified() {
|
|||||||
return(!(diagrams_[0] -> undoStack().isClean()));
|
return(!(diagrams_[0] -> undoStack().isClean()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@return the project-wide properties made available to child diagrams.
|
||||||
|
*/
|
||||||
|
DiagramContext QETProject::projectProperties() {
|
||||||
|
return(project_properties_);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Use \a context as project-wide properties made available to child diagrams.
|
||||||
|
*/
|
||||||
|
void QETProject::setProjectProperties(const DiagramContext &context) {
|
||||||
|
project_properties_ = context;
|
||||||
|
updateDiagramsFolioData();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Cette methode sert a reperer un projet vide, c-a-d un projet identique a ce
|
Cette methode sert a reperer un projet vide, c-a-d un projet identique a ce
|
||||||
que l'on obtient en faisant Fichier > Nouveau.
|
que l'on obtient en faisant Fichier > Nouveau.
|
||||||
@@ -1166,7 +1205,7 @@ bool QETProject::projectWasModified() {
|
|||||||
void QETProject::updateDiagramsFolioData() {
|
void QETProject::updateDiagramsFolioData() {
|
||||||
int total_folio = diagrams_.count();
|
int total_folio = diagrams_.count();
|
||||||
for (int i = 0 ; i < total_folio ; ++ i) {
|
for (int i = 0 ; i < total_folio ; ++ i) {
|
||||||
diagrams_[i] -> border_and_titleblock.setFolioData(i + 1, total_folio);
|
diagrams_[i] -> border_and_titleblock.setFolioData(i + 1, total_folio, project_properties_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -115,6 +115,8 @@ class QETProject : public QObject {
|
|||||||
bool projectWasModified();
|
bool projectWasModified();
|
||||||
bool embeddedCollectionWasModified();
|
bool embeddedCollectionWasModified();
|
||||||
bool diagramsWereModified();
|
bool diagramsWereModified();
|
||||||
|
DiagramContext projectProperties();
|
||||||
|
void setProjectProperties(const DiagramContext &);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void componentWritten();
|
void componentWritten();
|
||||||
@@ -146,6 +148,8 @@ class QETProject : public QObject {
|
|||||||
void readDiagramsXml();
|
void readDiagramsXml();
|
||||||
void readElementsCollectionXml();
|
void readElementsCollectionXml();
|
||||||
void readEmbeddedTemplatesXml();
|
void readEmbeddedTemplatesXml();
|
||||||
|
void readProjectPropertiesXml();
|
||||||
|
void writeProjectPropertiesXml(QDomElement &);
|
||||||
void readDefaultPropertiesXml();
|
void readDefaultPropertiesXml();
|
||||||
void writeDefaultPropertiesXml(QDomElement &);
|
void writeDefaultPropertiesXml(QDomElement &);
|
||||||
void addDiagram(Diagram *);
|
void addDiagram(Diagram *);
|
||||||
@@ -182,6 +186,8 @@ class QETProject : public QObject {
|
|||||||
TitleBlockProperties default_titleblock_properties_;
|
TitleBlockProperties default_titleblock_properties_;
|
||||||
/// Embedded title block templates collection
|
/// Embedded title block templates collection
|
||||||
TitleBlockTemplatesProjectCollection titleblocks_;
|
TitleBlockTemplatesProjectCollection titleblocks_;
|
||||||
|
/// project-wide variables that will be made available to child diagrams
|
||||||
|
DiagramContext project_properties_;
|
||||||
};
|
};
|
||||||
Q_DECLARE_METATYPE(QETProject *)
|
Q_DECLARE_METATYPE(QETProject *)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user