From 34d7d134d3833726397d1c036330802e06d51beb Mon Sep 17 00:00:00 2001 From: blacksun Date: Sun, 5 Mar 2017 13:10:47 +0000 Subject: [PATCH] Simplify how the diagrams are saved git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4927 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/diagram.cpp | 43 ---------------------- sources/diagram.h | 4 -- sources/projectview.cpp | 23 ------------ sources/projectview.h | 1 - sources/qetproject.cpp | 81 +++++++++++++++++++---------------------- sources/qetproject.h | 3 +- 6 files changed, 39 insertions(+), 116 deletions(-) diff --git a/sources/diagram.cpp b/sources/diagram.cpp index f5e0dde8f..1a955b533 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -675,12 +675,6 @@ bool Diagram::initFromXml(QDomElement &document, QPointF position, bool consider // import le contenu et les proprietes du schema depuis l'element XML fourni en parametre bool from_xml = fromXml(document, position, consider_informations, content_ptr); - // initialise le document XML interne a partir de l'element XML fourni en parametre - if (from_xml) { - xml_document_.clear(); - xml_document_.appendChild(xml_document_.importNode(document, true)); - // a ce stade, le document XML interne contient le code XML qui a ete importe, et non pas une version re-exporte par la methode toXml() - } return(from_xml); } @@ -744,7 +738,6 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf // if child haven't got a child, loading is finish (diagram is empty) if (root.firstChild().isNull()) { - write(document); return(true); } @@ -937,42 +930,6 @@ void Diagram::folioSequentialsFromXml(const QDomElement &root, QHash*, QDomElement *, QString, QString, QDomDocument *); void folioSequentialsFromXml(const QDomElement&, QHash*, QString, QString, QString, QString); @@ -245,7 +242,6 @@ class Diagram : public QGraphicsScene signals: void showDiagram (Diagram *); - void written(); void usedTitleBlockTemplateChanged(const QString &); void diagramTitleChanged(Diagram *, const QString &); void findElementRequired(const ElementsLocation &); /// Signal emitted when users wish to locate an element from the diagram within elements collection diff --git a/sources/projectview.cpp b/sources/projectview.cpp index 8b9c5cb02..6771f8c19 100644 --- a/sources/projectview.cpp +++ b/sources/projectview.cpp @@ -297,10 +297,6 @@ int ProjectView::tryClosingDiagrams() { | QMessageBox::Cancel, QMessageBox::Save); - if (close_dialog == QMessageBox::Save) { - saveDiagrams(project()->diagrams()); - } - return(close_dialog); } @@ -708,9 +704,6 @@ QETResult ProjectView::doSave() return(saveAs()); } - // look for diagrams matching the required save options - saveDiagrams(m_project->diagrams()); - // write to file QETResult result = m_project -> write(); updateWindowTitle(); @@ -718,22 +711,6 @@ QETResult ProjectView::doSave() return(result); } -/** - Save \a diagrams without emitting the written() signal and without writing - the project file itself. -*/ -void ProjectView::saveDiagrams(const QList &diagrams) { - foreach (Diagram *diagram, diagrams) { - // Diagram::write() emits the written() signal, which is connected - // to QETProject::write() through QETProject::componentWritten(). - // We do not want to write the project immediately, so we block - // this signal. - diagram -> blockSignals(true); - diagram -> write(); - diagram -> blockSignals(false); - } -} - /** Allow the user to clean the project, which includes: * deleting unused title block templates diff --git a/sources/projectview.h b/sources/projectview.h index 4e30fa0e3..8dd788e22 100644 --- a/sources/projectview.h +++ b/sources/projectview.h @@ -85,7 +85,6 @@ class ProjectView : public QWidget QETResult save(); QETResult saveAs(); QETResult doSave(); - void saveDiagrams(const QList &); int cleanProject(); void updateWindowTitle(); void updateTabTitle(DiagramView *); diff --git a/sources/qetproject.cpp b/sources/qetproject.cpp index 0806bd16c..ce33e4a0d 100644 --- a/sources/qetproject.cpp +++ b/sources/qetproject.cpp @@ -121,7 +121,7 @@ QETProject::QETProject(const QString &path, QObject *parent) : */ QETProject::~QETProject() { - qDeleteAll(diagrams_); + qDeleteAll(m_diagrams_list); delete undo_stack_; } @@ -154,7 +154,7 @@ void QETProject::setFolioSheetsQuantity(int quantity) { @return la liste des schemas de ce projet */ QList QETProject::diagrams() const { - return(diagrams_); + return(m_diagrams_list); } /** @@ -165,7 +165,7 @@ QList QETProject::diagrams() const { */ int QETProject::folioIndex(const Diagram *diagram) const { // QList::indexOf returns -1 if no item matched. - return(diagrams_.indexOf(const_cast(diagram))); + return(m_diagrams_list.indexOf(const_cast(diagram))); } /** @@ -601,7 +601,7 @@ NumerotationContext QETProject::folioAutoNum (const QString &key) const { */ void QETProject::freezeExistentConductorLabel(bool freeze, int from, int to) { for (int i = from; i <= to; i++) { - diagrams_.at(i)->freezeConductors(freeze); + m_diagrams_list.at(i)->freezeConductors(freeze); } } @@ -613,7 +613,7 @@ void QETProject::freezeExistentConductorLabel(bool freeze, int from, int to) { */ void QETProject::freezeNewConductorLabel(bool freeze, int from, int to) { for (int i = from; i <= to; i++) { - diagrams_.at(i)->setFreezeNewConductors(freeze); + m_diagrams_list.at(i)->setFreezeNewConductors(freeze); } } @@ -641,7 +641,7 @@ void QETProject::setFreezeNewConductors(bool set) { */ void QETProject::freezeExistentElementLabel(bool freeze, int from, int to) { for (int i = from; i <= to; i++) { - diagrams_.at(i)->freezeElements(freeze); + m_diagrams_list.at(i)->freezeElements(freeze); } } @@ -653,7 +653,7 @@ void QETProject::freezeExistentElementLabel(bool freeze, int from, int to) { */ void QETProject::freezeNewElementLabel(bool freeze, int from, int to) { for (int i = from; i <= to; i++) { - diagrams_.at(i)->setFreezeNewElements(freeze); + m_diagrams_list.at(i)->setFreezeNewElements(freeze); } } @@ -710,16 +710,16 @@ void QETProject::autoFolioNumberingNewFolios(){ * rename folios with selected autonum */ void QETProject::autoFolioNumberingSelectedFolios(int from, int to, QString autonum){ - int total_folio = diagrams_.count(); + int total_folio = m_diagrams_list.count(); DiagramContext project_wide_properties = project_properties_; for (int i=from; i<=to; i++) { - QString title = diagrams_[i] -> title(); + QString title = m_diagrams_list[i] -> title(); NumerotationContext nC = folioAutoNum(autonum); NumerotationContextCommands nCC = NumerotationContextCommands(nC); - diagrams_[i] -> border_and_titleblock.setFolio("%autonum"); - diagrams_[i] -> border_and_titleblock.setFolioData(i + 1, total_folio, nCC.toRepresentedString(), project_wide_properties); - diagrams_[i] -> project() -> addFolioAutoNum(autonum,nCC.next()); - diagrams_[i] -> update(); + m_diagrams_list[i] -> border_and_titleblock.setFolio("%autonum"); + m_diagrams_list[i] -> border_and_titleblock.setFolioData(i + 1, total_folio, nCC.toRepresentedString(), project_wide_properties); + m_diagrams_list[i] -> project() -> addFolioAutoNum(autonum,nCC.next()); + m_diagrams_list[i] -> update(); } } @@ -761,13 +761,18 @@ QDomDocument QETProject::toXml() { // qDebug() << "Export XML de" << diagrams_.count() << "schemas"; int order_num = 1; - foreach(Diagram *diagram, diagrams_) { - + const QList diagrams_list = m_diagrams_list; + for(Diagram *diagram : diagrams_list) + { // Write the diagram to XML only if it is not of type DiagramFolioList. DiagramFolioList *ptr = dynamic_cast(diagram); - if ( !ptr ) { + if ( !ptr ) + { qDebug() << qPrintable(QString("QETProject::toXml() : exporting diagram \"%1\"").arg(diagram -> title())) << "[" << diagram << "]"; - QDomNode appended_diagram = project_root.appendChild(diagram -> writeXml(xml_doc)); + QDomElement xml_diagram = diagram->toXml().documentElement(); + QDomNode xml_node = xml_doc.importNode(xml_diagram, true); + + QDomNode appended_diagram = project_root.appendChild(xml_node); appended_diagram.toElement().setAttribute("order", order_num ++); } } @@ -851,7 +856,7 @@ bool QETProject::isEmpty() const { // compte le nombre de schemas non vides int pertinent_diagrams = 0; - foreach(Diagram *diagram, diagrams_) { + foreach(Diagram *diagram, m_diagrams_list) { if (!diagram -> isEmpty()) ++ pertinent_diagrams; } @@ -1034,14 +1039,6 @@ bool QETProject::usesTitleBlockTemplate(const TitleBlockTemplateLocation &locati return(false); } -/** - Gere la reecriture du projet -*/ -void QETProject::componentWritten() { - // reecrit tout le projet - write(); -} - /** Ajoute un nouveau schema au projet et emet le signal diagramAdded */ @@ -1110,9 +1107,9 @@ QList QETProject::addNewDiagramFolioList() { void QETProject::removeDiagram(Diagram *diagram) { // ne fait rien si le projet est en lecture seule if (isReadOnly()) return; - if (!diagram || !diagrams_.contains(diagram)) return; + if (!diagram || !m_diagrams_list.contains(diagram)) return; - if (diagrams_.removeAll(diagram)) { + if (m_diagrams_list.removeAll(diagram)) { emit(diagramRemoved(this, diagram)); delete diagram; } @@ -1131,10 +1128,10 @@ void QETProject::removeDiagram(Diagram *diagram) { void QETProject::diagramOrderChanged(int old_index, int new_index) { if (old_index < 0 || new_index < 0) return; - int diagram_max_index = diagrams_.size() - 1; + int diagram_max_index = m_diagrams_list.size() - 1; if (old_index > diagram_max_index || new_index > diagram_max_index) return; - diagrams_.move(old_index, new_index); + m_diagrams_list.move(old_index, new_index); updateDiagramsFolioData(); setModified(true); emit(projectDiagramsOrderChanged(this, old_index, new_index)); @@ -1528,8 +1525,6 @@ void QETProject::addDiagram(Diagram *diagram) { // Ensure diagram know is parent project diagram -> setProject(this); - // If diagram is write, we must rewrite the project - connect(diagram, SIGNAL(written()), this, SLOT(componentWritten())); connect( &(diagram -> border_and_titleblock), SIGNAL(needFolioData()), @@ -1542,7 +1537,7 @@ void QETProject::addDiagram(Diagram *diagram) { ); // add diagram to project - diagrams_ << diagram; + m_diagrams_list << diagram; updateDiagramsFolioData(); } @@ -1626,24 +1621,24 @@ bool QETProject::projectWasModified() { folio le projet contient. */ void QETProject::updateDiagramsFolioData() { - int total_folio = diagrams_.count(); + int total_folio = m_diagrams_list.count(); DiagramContext project_wide_properties = project_properties_; project_wide_properties.addValue("projecttitle", title()); for (int i = 0 ; i < total_folio ; ++ i) { - QString title = diagrams_[i] -> title(); - QString autopagenum = diagrams_[i]->border_and_titleblock.autoPageNum(); + QString title = m_diagrams_list[i] -> title(); + QString autopagenum = m_diagrams_list[i]->border_and_titleblock.autoPageNum(); NumerotationContext nC = folioAutoNum(autopagenum); NumerotationContextCommands nCC = NumerotationContextCommands(nC); - if((diagrams_[i]->border_and_titleblock.folio().contains("%autonum"))&&(!autopagenum.isNull())){ - diagrams_[i] -> border_and_titleblock.setFolioData(i + 1, total_folio, nCC.toRepresentedString(), project_wide_properties); - diagrams_[i]->project()->addFolioAutoNum(autopagenum,nCC.next()); + 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{ - diagrams_[i] -> border_and_titleblock.setFolioData(i + 1, total_folio, NULL, project_wide_properties); + m_diagrams_list[i] -> border_and_titleblock.setFolioData(i + 1, total_folio, NULL, project_wide_properties); } - diagrams_[i] -> update(); + m_diagrams_list[i] -> update(); } } @@ -1655,7 +1650,7 @@ void QETProject::updateDiagramsFolioData() { void QETProject::updateDiagramsTitleBlockTemplate(TitleBlockTemplatesCollection *collection, const QString &template_name) { Q_UNUSED(collection) - foreach (Diagram *diagram, diagrams_) { + foreach (Diagram *diagram, m_diagrams_list) { diagram -> titleBlockTemplateChanged(template_name); } } @@ -1669,7 +1664,7 @@ void QETProject::removeDiagramsTitleBlockTemplate(TitleBlockTemplatesCollection Q_UNUSED(collection) // warn diagrams that the given template is about to be removed - foreach (Diagram *diagram, diagrams_) { + foreach (Diagram *diagram, m_diagrams_list) { diagram -> titleBlockTemplateRemoved(template_name); } } diff --git a/sources/qetproject.h b/sources/qetproject.h index aafd5a282..b7204e195 100644 --- a/sources/qetproject.h +++ b/sources/qetproject.h @@ -166,7 +166,6 @@ class QETProject : public QObject QUndoStack* undoStack() {return undo_stack_;} public slots: - void componentWritten(); Diagram *addNewDiagram(); QList addNewDiagramFolioList(); void removeDiagram(Diagram *); @@ -224,7 +223,7 @@ class QETProject : public QObject /// Current state of the project ProjectState state_; /// Diagrams carried by the project - QList diagrams_; + QList m_diagrams_list; /// Project title QString project_title_; /// QElectroTech version declared in the XML document at opening time