[qet] [1892] Introduced project-wide properties, i.e. |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 1892
Author: xavier
Date: 2012-07-01 23:54:07 +0200 (Sun, 01 Jul 2012)
Log Message:
-----------
Introduced project-wide properties, i.e. key/value pairs defined at the project scope available in all child diagrams.
Modified Paths:
--------------
trunk/sources/bordertitleblock.cpp
trunk/sources/bordertitleblock.h
trunk/sources/projectconfigpages.cpp
trunk/sources/projectconfigpages.h
trunk/sources/qetproject.cpp
trunk/sources/qetproject.h
Modified: trunk/sources/bordertitleblock.cpp
===================================================================
--- trunk/sources/bordertitleblock.cpp 2012-07-01 21:54:06 UTC (rev 1891)
+++ trunk/sources/bordertitleblock.cpp 2012-07-01 21:54:07 UTC (rev 1892)
@@ -192,8 +192,8 @@
setFolio(ip.folio);
additional_fields_ = ip.context;
- emit(needFolioData());
- updateDiagramContextForTitleBlock();
+ emit(needFolioData()); // Note: we expect additional data to be provided
+ // through setFolioData(), which in turn calls updateDiagramContextForTitleBlock().
emit(needTitleBlockTemplate(ip.template_name));
}
@@ -572,10 +572,16 @@
/**
Update the informations given to the titleblock template by regenerating a
DiagramContext object.
+ @param initial_context Base diagram context that will be overridden by
+ diagram-wide values
*/
-void BorderTitleBlock::updateDiagramContextForTitleBlock() {
- // our final DiagramContext object is the "additional fields" one
- DiagramContext context = additional_fields_;
+void BorderTitleBlock::updateDiagramContextForTitleBlock(const DiagramContext &initial_context) {
+ // Our final DiagramContext is the initial one (which is supposed to bring
+ // 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
context.addValue("author", bi_author);
@@ -609,8 +615,9 @@
/**
@param index numero du schema (de 1 a total)
@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;
// memorise les informations
@@ -622,5 +629,5 @@
bi_final_folio.replace("%id", QString::number(folio_index_));
bi_final_folio.replace("%total", QString::number(folio_total_));
- updateDiagramContextForTitleBlock();
+ updateDiagramContextForTitleBlock(project_properties);
}
Modified: trunk/sources/bordertitleblock.h
===================================================================
--- trunk/sources/bordertitleblock.h 2012-07-01 21:54:06 UTC (rev 1891)
+++ trunk/sources/bordertitleblock.h 2012-07-01 21:54:07 UTC (rev 1892)
@@ -142,7 +142,7 @@
}
/// @param folio le nouveau contenu du champ "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"
void setFileName (const QString &filename) { bi_filename = filename; }
@@ -172,7 +172,7 @@
private:
void updateRectangles();
- void updateDiagramContextForTitleBlock();
+ void updateDiagramContextForTitleBlock(const DiagramContext & = DiagramContext());
QString incrementLetters(const QString &);
// signaux
Modified: trunk/sources/projectconfigpages.cpp
===================================================================
--- trunk/sources/projectconfigpages.cpp 2012-07-01 21:54:06 UTC (rev 1891)
+++ trunk/sources/projectconfigpages.cpp 2012-07-01 21:54:07 UTC (rev 1892)
@@ -3,6 +3,7 @@
#include "qetproject.h"
#include "borderpropertieswidget.h"
#include "conductorpropertieswidget.h"
+#include "diagramcontextwidget.h"
#include "titleblockpropertieswidget.h"
#include <QtGui>
@@ -105,6 +106,7 @@
*/
void ProjectMainConfigPage::applyProjectConf() {
project_ -> setTitle(title_value_ -> text());
+ project_ -> setProjectProperties(project_variables_ -> context());
}
/**
@@ -120,6 +122,14 @@
void ProjectMainConfigPage::initWidgets() {
title_label_ = new QLabel(tr("Titre du projet\240:", "label when configuring"));
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 @@
title_layout0 -> addWidget(title_label_);
title_layout0 -> addWidget(title_value_);
main_layout0 -> addLayout(title_layout0);
- main_layout0 -> addStretch();
+ main_layout0 -> addWidget(project_variables_label_);
+ main_layout0 -> addWidget(project_variables_);
setLayout(main_layout0);
}
@@ -140,6 +151,7 @@
*/
void ProjectMainConfigPage::readValuesFromProject() {
title_value_ -> setText(project_ -> title());
+ project_variables_ -> setContext(project_ -> projectProperties());
}
/**
Modified: trunk/sources/projectconfigpages.h
===================================================================
--- trunk/sources/projectconfigpages.h 2012-07-01 21:54:06 UTC (rev 1891)
+++ trunk/sources/projectconfigpages.h 2012-07-01 21:54:07 UTC (rev 1892)
@@ -7,6 +7,7 @@
class BorderPropertiesWidget;
class TitleBlockPropertiesWidget;
class ConductorPropertiesWidget;
+class DiagramContextWidget;
/**
This class, derived from ConfigPage, aims at providing the basic skeleton
@@ -88,6 +89,8 @@
protected:
QLabel *title_label_;
QLineEdit *title_value_;
+ QLabel *project_variables_label_;
+ DiagramContextWidget *project_variables_;
};
/**
Modified: trunk/sources/qetproject.cpp
===================================================================
--- trunk/sources/qetproject.cpp 2012-07-01 21:54:06 UTC (rev 1891)
+++ trunk/sources/qetproject.cpp 2012-07-01 21:54:07 UTC (rev 1892)
@@ -417,6 +417,11 @@
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
QDomElement new_diagrams_properties = xml_doc.createElement("newdiagrams");
writeDefaultPropertiesXml(new_diagrams_properties);
@@ -900,6 +905,9 @@
state_ = ProjectParsingFailed;
}
+ // load the project-wide properties
+ readProjectPropertiesXml();
+
// charge les proprietes par defaut pour les nouveaux schemas
readDefaultPropertiesXml();
@@ -980,6 +988,22 @@
}
/**
+ 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
XML du projet :
* dimensions
@@ -1140,6 +1164,21 @@
}
/**
+ @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
que l'on obtient en faisant Fichier > Nouveau.
@return true si les schemas, la collection embarquee ou les proprietes de ce
@@ -1166,7 +1205,7 @@
void QETProject::updateDiagramsFolioData() {
int total_folio = diagrams_.count();
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_);
}
}
Modified: trunk/sources/qetproject.h
===================================================================
--- trunk/sources/qetproject.h 2012-07-01 21:54:06 UTC (rev 1891)
+++ trunk/sources/qetproject.h 2012-07-01 21:54:07 UTC (rev 1892)
@@ -115,6 +115,8 @@
bool projectWasModified();
bool embeddedCollectionWasModified();
bool diagramsWereModified();
+ DiagramContext projectProperties();
+ void setProjectProperties(const DiagramContext &);
public slots:
void componentWritten();
@@ -146,6 +148,8 @@
void readDiagramsXml();
void readElementsCollectionXml();
void readEmbeddedTemplatesXml();
+ void readProjectPropertiesXml();
+ void writeProjectPropertiesXml(QDomElement &);
void readDefaultPropertiesXml();
void writeDefaultPropertiesXml(QDomElement &);
void addDiagram(Diagram *);
@@ -182,6 +186,8 @@
TitleBlockProperties default_titleblock_properties_;
/// Embedded title block templates collection
TitleBlockTemplatesProjectCollection titleblocks_;
+ /// project-wide variables that will be made available to child diagrams
+ DiagramContext project_properties_;
};
Q_DECLARE_METATYPE(QETProject *)
#endif