loaded_diagrams;
//@TODO try to solve a weird bug (dialog is black) since port to Qt5 with the DialogWaiting
//show DialogWaiting
DialogWaiting *dlgWaiting = nullptr;
if(DialogWaiting::hasInstance())
{
dlgWaiting = DialogWaiting::instance();
dlgWaiting -> setModal(true);
dlgWaiting -> show();
dlgWaiting -> setTitle( tr(""
"Ouverture du projet en cours...
"
"Création des folios"
"
"));
}
//Search the diagrams in the project
QDomNodeList diagram_nodes = xml_project.elementsByTagName("diagram");
if(dlgWaiting)
dlgWaiting->setProgressBarRange(0, diagram_nodes.length()*3);
for (int i = 0 ; i < diagram_nodes.length() ; ++ i)
{
if(dlgWaiting)
dlgWaiting->setProgressBar(i+1);
if (diagram_nodes.at(i).isElement())
{
QDomElement diagram_xml_element = diagram_nodes.at(i).toElement();
Diagram *diagram = new Diagram(this);
bool diagram_loading = diagram -> initFromXml(diagram_xml_element);
if (diagram_loading)
{
if(dlgWaiting)
dlgWaiting->setDetail( diagram->title() );
//Get the attribute "order" of the diagram
int diagram_order = -1;
if (!QET::attributeIsAnInteger(diagram_xml_element, "order", &diagram_order)) diagram_order = 500000;
loaded_diagrams.insert(diagram_order, diagram);
}
else
{
delete diagram;
}
}
}
//Add the diagrams according to there "order" attribute
foreach(Diagram *diagram, loaded_diagrams.values())
addDiagram(diagram);
//Initialise links between elements in this project
//and refresh the text of conductor
if(dlgWaiting)
{
dlgWaiting->setTitle( tr(""
"Ouverture du projet en cours...
"
"Mise en place des références croisées"
"
"));
}
m_data_base.updateDB(); //All diagrams and items are created we need to update the database
for(Diagram *d : diagrams())
{
if(dlgWaiting)
{
dlgWaiting->setProgressBar(dlgWaiting->progressBarValue()+1);
dlgWaiting->setDetail(d->title());
}
d->refreshContents();
}
}
/**
* @brief QETProject::readElementsCollectionXml
* Load the diagrams from the xml description of the project
* @param xml_project : the xml description of the project
*/
void QETProject::readElementsCollectionXml(QDomDocument &xml_project)
{
//Get the embedded elements collection of the project
QDomNodeList collection_roots = xml_project.elementsByTagName("collection");
QDomElement collection_root;
if (!collection_roots.isEmpty())
{
//Only the first found collection is take
collection_root = collection_roots.at(0).toElement();
}
//Make an empty collection
if (collection_root.isNull()) {
m_elements_collection = new XmlElementCollection(this);
}
//Read the collection
else {
m_elements_collection = new XmlElementCollection(collection_root, this);
}
}
/**
* @brief QETProject::readProjectPropertiesXml
* Load project properties from the XML description of the project
* @param xml_project : the xml description of the project
*/
void QETProject::readProjectPropertiesXml(QDomDocument &xml_project)
{
foreach (QDomElement e, QET::findInDomElement(xml_project.documentElement(), "properties"))
m_project_properties.fromXml(e);
}
/**
* @brief QETProject::readDefaultPropertiesXml
* load default properties for new diagram, found in the xml of this project
* or by default find in the QElectroTech global conf
* @param xml_project : the xml description of the project
*/
void QETProject::readDefaultPropertiesXml(QDomDocument &xml_project)
{
// Find xml element where is stored properties for new diagram
QDomNodeList newdiagrams_nodes = xml_project.elementsByTagName("newdiagrams");
if (newdiagrams_nodes.isEmpty()) return;
QDomElement newdiagrams_elmt = newdiagrams_nodes.at(0).toElement();
// By default, use value find in the global conf of QElectroTech
default_border_properties_ = BorderProperties:: defaultProperties();
default_titleblock_properties_ = TitleBlockProperties::defaultProperties();
default_conductor_properties_ = ConductorProperties:: defaultProperties();
m_default_report_properties = ReportProperties:: defaultProperties();
m_default_xref_properties = XRefProperties:: defaultProperties();
//Read values indicate in project
QDomElement border_elmt, titleblock_elmt, conductors_elmt, report_elmt, xref_elmt, conds_autonums, folio_autonums, element_autonums;
for (QDomNode child = newdiagrams_elmt.firstChild() ; !child.isNull() ; child = child.nextSibling())
{
QDomElement child_elmt = child.toElement();
if (child_elmt.isNull()) continue;
if (child_elmt.tagName() == "border")
border_elmt = child_elmt;
else if (child_elmt.tagName() == "inset")
titleblock_elmt = child_elmt;
else if (child_elmt.tagName() == "conductors")
conductors_elmt = child_elmt;
else if (child_elmt.tagName() == "report")
report_elmt = child_elmt;
else if (child_elmt.tagName() == "xrefs")
xref_elmt = child_elmt;
else if (child_elmt.tagName() == "conductors_autonums")
conds_autonums = child_elmt;
else if (child_elmt.tagName()== "folio_autonums")
folio_autonums = child_elmt;
else if (child_elmt.tagName()== "element_autonums")
element_autonums = child_elmt;
}
// size, titleblock, conductor, report, conductor autonum, folio autonum, element autonum
if (!border_elmt.isNull()) default_border_properties_.fromXml(border_elmt);
if (!titleblock_elmt.isNull()) default_titleblock_properties_.fromXml(titleblock_elmt);
if (!conductors_elmt.isNull()) default_conductor_properties_.fromXml(conductors_elmt);
if (!report_elmt.isNull()) setDefaultReportProperties(report_elmt.attribute("label"));
if (!xref_elmt.isNull())
{
foreach(QDomElement elmt, QET::findInDomElement(xref_elmt, "xref"))
{
XRefProperties xrp;
xrp.fromXml(elmt);
m_default_xref_properties.insert(elmt.attribute("type"), xrp);
}
}
if (!conds_autonums.isNull())
{
m_current_conductor_autonum = conds_autonums.attribute("current_autonum");
m_freeze_new_conductors = conds_autonums.attribute("freeze_new_conductors") == "true";
foreach (QDomElement elmt, QET::findInDomElement(conds_autonums, "conductor_autonum"))
{
NumerotationContext nc;
nc.fromXml(elmt);
m_conductor_autonum.insert(elmt.attribute("title"), nc);
}
}
if (!folio_autonums.isNull())
{
foreach (QDomElement elmt, QET::findInDomElement(folio_autonums, "folio_autonum"))
{
NumerotationContext nc;
nc.fromXml(elmt);
m_folio_autonum.insert(elmt.attribute("title"), nc);
}
}
if (!element_autonums.isNull())
{
m_current_element_autonum = element_autonums.attribute("current_autonum");
m_freeze_new_elements = element_autonums.attribute("freeze_new_elements") == "true";
foreach (QDomElement elmt, QET::findInDomElement(element_autonums, "element_autonum"))
{
NumerotationContext nc;
nc.fromXml(elmt);
m_element_autonum.insert(elmt.attribute("title"), nc);
}
}
}
/**
Export project properties under the \a xml_element XML element.
*/
void QETProject::writeProjectPropertiesXml(QDomElement &xml_element) {
m_project_properties.toXml(xml_element);
}
/**
* @brief QETProject::writeDefaultPropertiesXml
* Export all defaults properties used by a new diagram and his content
* #size of border
* #content of titleblock
* #default conductor
* #defaut folio report
* #default Xref
* @param xml_element xml element to use for store default propertie.
*/
void QETProject::writeDefaultPropertiesXml(QDomElement &xml_element) {
QDomDocument xml_document = xml_element.ownerDocument();
// export size of border
QDomElement border_elmt = xml_document.createElement("border");
default_border_properties_.toXml(border_elmt);
xml_element.appendChild(border_elmt);
// export content of titleblock
QDomElement titleblock_elmt = xml_document.createElement("inset");
default_titleblock_properties_.toXml(titleblock_elmt);
xml_element.appendChild(titleblock_elmt);
// exporte default conductor
QDomElement conductor_elmt = xml_document.createElement("conductors");
default_conductor_properties_.toXml(conductor_elmt);
xml_element.appendChild(conductor_elmt);
// export default report properties
QDomElement report_elmt = xml_document.createElement("report");
report_elmt.setAttribute("label", defaultReportProperties());
xml_element.appendChild(report_elmt);
// export default XRef properties
QDomElement xrefs_elmt = xml_document.createElement("xrefs");
foreach (QString key, defaultXRefProperties().keys()) {
QDomElement xref_elmt = xml_document.createElement("xref");
xref_elmt.setAttribute("type", key);
defaultXRefProperties()[key].toXml(xref_elmt);
xrefs_elmt.appendChild(xref_elmt);
}
xml_element.appendChild(xrefs_elmt);
//Export Conductor Autonums
QDomElement conductor_autonums = xml_document.createElement("conductors_autonums");
conductor_autonums.setAttribute("current_autonum", m_current_conductor_autonum);
conductor_autonums.setAttribute("freeze_new_conductors", m_freeze_new_conductors ? "true" : "false");
foreach (QString key, conductorAutoNum().keys()) {
QDomElement conductor_autonum = conductorAutoNum(key).toXml(xml_document, "conductor_autonum");
if (key != "" && conductorAutoNumFormula(key) != "") {
conductor_autonum.setAttribute("title", key);
conductor_autonum.setAttribute("formula", conductorAutoNumFormula(key));
conductor_autonums.appendChild(conductor_autonum);
}
}
xml_element.appendChild(conductor_autonums);
//Export Folio Autonums
QDomElement folio_autonums = xml_document.createElement("folio_autonums");
foreach (QString key, folioAutoNum().keys()) {
QDomElement folio_autonum = folioAutoNum(key).toXml(xml_document, "folio_autonum");
folio_autonum.setAttribute("title", key);
folio_autonums.appendChild(folio_autonum);
}
xml_element.appendChild(folio_autonums);
//Export Element Autonums
QDomElement element_autonums = xml_document.createElement("element_autonums");
element_autonums.setAttribute("current_autonum", m_current_element_autonum);
element_autonums.setAttribute("freeze_new_elements", m_freeze_new_elements ? "true" : "false");
foreach (QString key, elementAutoNum().keys()) {
QDomElement element_autonum = elementAutoNum(key).toXml(xml_document, "element_autonum");
if (key != "" && elementAutoNumFormula(key) != "") {
element_autonum.setAttribute("title", key);
element_autonum.setAttribute("formula", elementAutoNumFormula(key));
element_autonums.appendChild(element_autonum);
}
}
xml_element.appendChild(element_autonums);
}
/**
* @brief QETProject::addDiagram
* Add a diagram in this project
* @param diagram added diagram
* @param pos postion of the new diagram, by default at the end
*/
void QETProject::addDiagram(Diagram *diagram, int pos)
{
if (!diagram) {
return;
}
// Ensure diagram know is parent project
diagram->setProject(this);
connect(&diagram->border_and_titleblock, &BorderTitleBlock::needFolioData, this, &QETProject::updateDiagramsFolioData);
connect(diagram, &Diagram::usedTitleBlockTemplateChanged, this, &QETProject::usedTitleBlockTemplateChanged);
if (pos == -1) {
m_diagrams_list << diagram;
} else {
m_diagrams_list.insert(pos, diagram);
}
updateDiagramsFolioData();
}
/**
@return La liste des noms a utiliser pour la categorie dediee aux elements
integres automatiquement dans le projet.
*/
NamesList QETProject::namesListForIntegrationCategory() {
NamesList names;
const QChar russian_data[24] = { 0x0418, 0x043C, 0x043F, 0x043E, 0x0440, 0x0442, 0x0438, 0x0440, 0x043E, 0x0432, 0x0430, 0x043D, 0x043D, 0x044B, 0x0435, 0x0020, 0x044D, 0x043B, 0x0435, 0x043C, 0x0435, 0x043D, 0x0442, 0x044B };
const QChar greek_data[18] = { 0x0395, 0x03b9, 0x03c3, 0x03b7, 0x03b3, 0x03bc, 0x03ad, 0x03bd, 0x03b1, 0x0020, 0x03c3, 0x03c4, 0x03bf, 0x03b9, 0x03c7, 0x03b5, 0x03af, 0x03b1 };
names.addName("fr", "Éléments importés");
names.addName("en", "Imported elements");
names.addName("de", "Importierte elemente");
names.addName("es", "Elementos importados");
names.addName("ru", QString(russian_data, 24));
names.addName("cs", "Zavedené prvky");
names.addName("pl", "Elementy importowane");
names.addName("pt", "elementos importados");
names.addName("it", "Elementi importati");
names.addName("el", QString(greek_data, 18));
names.addName("nl", "Elementen geïmporteerd");
names.addName("hr", "Uvezeni elementi");
names.addName("ca", "Elements importats");
names.addName("ro", "Elemente importate");
return(names);
}
/**
* @brief QETProject::writeBackup
* Write a backup file of this project, in the case that QET crash
*/
void QETProject::writeBackup()
{
if (!m_backup_file ||
(!m_backup_file->isOpen() && !m_backup_file->open(QIODevice::ReadWrite))) {
return;
}
QDomDocument xml_project(toXml());
QET::writeToFile(xml_project, m_backup_file);
}
/**
@return true if project options (title, project-wide properties, settings
for new diagrams, diagrams order...) were modified, false otherwise.
*/
bool QETProject::projectOptionsWereModified() {
// unlike similar methods, this method does not compare the content against
// expected values; instead, we just check whether we have been set as modified.
return(m_modified);
}
/**
@return the project-wide properties made available to child diagrams.
*/
DiagramContext QETProject::projectProperties() {
return(m_project_properties);
}
/**
Use \a context as project-wide properties made available to child diagrams.
*/
void QETProject::setProjectProperties(const DiagramContext &context) {
m_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
projet ont ete modifies.
Concretement, le projet doit avoir un titre vide et ni ses schemas ni sa
collection embarquee ne doivent avoir ete modifies.
@see diagramsWereModified(), embeddedCollectionWasModified()
*/
bool QETProject::projectWasModified() {
if ( projectOptionsWereModified() ||
!m_undo_stack -> isClean() ||
m_titleblocks_collection.templates().count() )
return(true);
else
return(false);
}
/**
Indique a chaque schema du projet quel est son numero de folio et combien de
folio le projet contient.
*/
void QETProject::updateDiagramsFolioData()
{
int total_folio = m_diagrams_list.count();
DiagramContext project_wide_properties = m_project_properties;
project_wide_properties.addValue("projecttitle", title());
project_wide_properties.addValue("projectpath", filePath());
project_wide_properties.addValue("projectfilename", QFileInfo(filePath()).baseName());
for (int i = 0 ; i < total_folio ; ++ i)
{
QString autopagenum = m_diagrams_list[i]->border_and_titleblock.autoPageNum();
NumerotationContext nC = folioAutoNum(autopagenum);
NumerotationContextCommands nCC = NumerotationContextCommands(nC);
if ((m_diagrams_list[i]->border_and_titleblock.folio().contains("%autonum")) &&
(!autopagenum.isNull()))
{
m_diagrams_list[i] -> border_and_titleblock.setFolioData(i + 1, total_folio, nCC.toRepresentedString(), project_wide_properties);
m_diagrams_list[i]->project()->addFolioAutoNum(autopagenum,nCC.next());
}
else {
m_diagrams_list[i] -> border_and_titleblock.setFolioData(i + 1, total_folio, nullptr, project_wide_properties);
}
if (i > 0)
{
m_diagrams_list.at(i)->border_and_titleblock.setPreviousFolioNum(m_diagrams_list.at(i-1)->border_and_titleblock.finalfolio());
m_diagrams_list.at(i-1)->border_and_titleblock.setNextFolioNum(m_diagrams_list.at(i)->border_and_titleblock.finalfolio());
if (i == total_folio-1) {
m_diagrams_list.at(i)->border_and_titleblock.setNextFolioNum(QString());
}
}
else {
m_diagrams_list.at(i)->border_and_titleblock.setPreviousFolioNum(QString());
}
}
for (Diagram *d : m_diagrams_list) {
d->update();
}
}
/**
Inform each diagram that the \a template_name title block changed.
@param collection Title block templates collection
@param template_name Name of the changed template
*/
void QETProject::updateDiagramsTitleBlockTemplate(TitleBlockTemplatesCollection *collection, const QString &template_name) {
Q_UNUSED(collection)
foreach (Diagram *diagram, m_diagrams_list) {
diagram -> titleBlockTemplateChanged(template_name);
}
}
/**
Inform each diagram that the \a template_name title block is about to be removed.
@param collection Title block templates collection
@param template_name Name of the removed template
*/
void QETProject::removeDiagramsTitleBlockTemplate(TitleBlockTemplatesCollection *collection, const QString &template_name) {
Q_UNUSED(collection)
// warn diagrams that the given template is about to be removed
foreach (Diagram *diagram, m_diagrams_list) {
diagram -> titleBlockTemplateRemoved(template_name);
}
}
/**
Handles the fact a digram changed the title block template it used
@param template_name Name of the template
*/
void QETProject::usedTitleBlockTemplateChanged(const QString &template_name) {
emit(diagramUsedTemplate(embeddedTitleBlockTemplatesCollection(), template_name));
}