[qet] qet/qet: [4927] Simplify how the diagrams are saved

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 4927
Author:   blacksun
Date:     2017-03-05 14:10:47 +0100 (Sun, 05 Mar 2017)
Log Message:
-----------
Simplify how the diagrams are saved

Modified Paths:
--------------
    trunk/sources/diagram.cpp
    trunk/sources/diagram.h
    trunk/sources/projectview.cpp
    trunk/sources/projectview.h
    trunk/sources/qetproject.cpp
    trunk/sources/qetproject.h

Modified: trunk/sources/diagram.cpp
===================================================================
--- trunk/sources/diagram.cpp	2017-03-05 12:24:33 UTC (rev 4926)
+++ trunk/sources/diagram.cpp	2017-03-05 13:10:47 UTC (rev 4927)
@@ -675,12 +675,6 @@
 	// 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 @@
 
 	// if child haven't got a child, loading is finish (diagram is empty)
 	if (root.firstChild().isNull()) {
-		write(document);
 		return(true);
 	}
 	
@@ -938,42 +931,6 @@
 }
 
 /**
-	Enregistre le schema XML dans son document XML interne et emet le signal
-	written().
-*/
-void Diagram::write()
-{
-	qDebug() << qPrintable(QString("Diagram::write() : saving changes from diagram \"%1\"").arg(title())) << "[" << this << "]";
-	write(toXml().documentElement());
-}
-
-/**
-	Enregistre un element XML dans son document XML interne et emet le signal
-	written().
-	@param element xml a enregistrer
-*/
-void Diagram::write(const QDomElement &element) {
-	xml_document_.clear();
-	xml_document_.appendChild(xml_document_.importNode(element, true));
-	emit(written());
-}
-
-/**
-	@return le schema en XML tel qu'il doit etre enregistre dans le fichier projet
-	@param xml_doc document XML a utiliser pour creer l'element
-*/
-QDomElement Diagram::writeXml(QDomDocument &xml_doc) const
-{
-		//If diagram was not explicitely saved, we write nothing.
-	if (xml_document_.isNull())
-		return(QDomElement());
-	
-	QDomElement diagram_elmt = xml_document_.documentElement();
-	QDomNode new_node = xml_doc.importNode(diagram_elmt, true);
-	return(new_node.toElement());
-}
-
-/**
  * @brief Diagram::refreshContents
  * refresh all content of diagram.
  * - refresh conductor text.

Modified: trunk/sources/diagram.h
===================================================================
--- trunk/sources/diagram.h	2017-03-05 12:24:33 UTC (rev 4926)
+++ trunk/sources/diagram.h	2017-03-05 13:10:47 UTC (rev 4927)
@@ -155,9 +155,6 @@
 		bool initFromXml(QDomElement &, QPointF = QPointF(), bool = true, DiagramContent * = 0);
 		bool fromXml(QDomDocument &, QPointF = QPointF(), bool = true, DiagramContent * = 0);
 		bool fromXml(QDomElement &, QPointF = QPointF(), bool = true, DiagramContent * = 0);
-		void write();
-		void write(const QDomElement &);
-		QDomElement writeXml(QDomDocument &) const;
 		void folioSequentialsToXml(QHash<QString, QStringList>*, QDomElement *, QString, QString, QDomDocument *);
 		void folioSequentialsFromXml(const QDomElement&, QHash<QString, QStringList>*, QString, QString, QString, QString);
 	
@@ -245,7 +242,6 @@
 
 	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

Modified: trunk/sources/projectview.cpp
===================================================================
--- trunk/sources/projectview.cpp	2017-03-05 12:24:33 UTC (rev 4926)
+++ trunk/sources/projectview.cpp	2017-03-05 13:10:47 UTC (rev 4927)
@@ -297,10 +297,6 @@
 								   | QMessageBox::Cancel,
 								   QMessageBox::Save);
 
-	if (close_dialog == QMessageBox::Save) {
-		saveDiagrams(project()->diagrams());
-	}
-
 	return(close_dialog);
 }
 
@@ -708,9 +704,6 @@
 		return(saveAs());
 	}
 
-	// look for diagrams matching the required save options
-	saveDiagrams(m_project->diagrams());
-
 	// write to file
 	QETResult result = m_project -> write();
 	updateWindowTitle();
@@ -719,22 +712,6 @@
 }
 
 /**
-	Save \a diagrams without emitting the written() signal and without writing
-	the project file itself.
-*/
-void ProjectView::saveDiagrams(const QList<Diagram *> &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
 	  * deleting unused elements

Modified: trunk/sources/projectview.h
===================================================================
--- trunk/sources/projectview.h	2017-03-05 12:24:33 UTC (rev 4926)
+++ trunk/sources/projectview.h	2017-03-05 13:10:47 UTC (rev 4927)
@@ -85,7 +85,6 @@
 		QETResult save();
 		QETResult saveAs();
 		QETResult doSave();
-		void saveDiagrams(const QList<Diagram *> &);
 		int cleanProject();
 		void updateWindowTitle();
 		void updateTabTitle(DiagramView *);

Modified: trunk/sources/qetproject.cpp
===================================================================
--- trunk/sources/qetproject.cpp	2017-03-05 12:24:33 UTC (rev 4926)
+++ trunk/sources/qetproject.cpp	2017-03-05 13:10:47 UTC (rev 4927)
@@ -121,7 +121,7 @@
  */
 QETProject::~QETProject()
 {
-	qDeleteAll(diagrams_);
+	qDeleteAll(m_diagrams_list);
 	delete undo_stack_;
 }
 
@@ -154,7 +154,7 @@
 	@return la liste des schemas de ce projet
 */
 QList<Diagram *> QETProject::diagrams() const {
-	return(diagrams_);
+	return(m_diagrams_list);
 }
 
 /**
@@ -165,7 +165,7 @@
 */
 int QETProject::folioIndex(const Diagram *diagram) const {
 	// QList::indexOf returns -1 if no item matched.
-	return(diagrams_.indexOf(const_cast<Diagram *>(diagram)));
+	return(m_diagrams_list.indexOf(const_cast<Diagram *>(diagram)));
 }
 
 /**
@@ -601,7 +601,7 @@
  */
 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::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::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::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 @@
  * 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 @@
 	
 	// qDebug() << "Export XML de" << diagrams_.count() << "schemas";
 	int order_num = 1;
-	foreach(Diagram *diagram, diagrams_) {
-
+	const QList<Diagram *> 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<DiagramFolioList *>(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 @@
 	
 	// 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;
 	}
 	
@@ -1035,14 +1040,6 @@
 }
 
 /**
-	Gere la reecriture du projet
-*/
-void QETProject::componentWritten() {
-	// reecrit tout le projet
-	write();
-}
-
-/**
 	Ajoute un nouveau schema au projet et emet le signal diagramAdded
 */
 Diagram *QETProject::addNewDiagram() {
@@ -1110,9 +1107,9 @@
 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::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 @@
 	// 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 @@
 	);
 	
 	// add diagram to project
-		diagrams_ << diagram;
+		m_diagrams_list << diagram;
 	
 	updateDiagramsFolioData();
 }
@@ -1626,24 +1621,24 @@
 	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::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 @@
 	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);
 	}
 }

Modified: trunk/sources/qetproject.h
===================================================================
--- trunk/sources/qetproject.h	2017-03-05 12:24:33 UTC (rev 4926)
+++ trunk/sources/qetproject.h	2017-03-05 13:10:47 UTC (rev 4927)
@@ -166,7 +166,6 @@
 		QUndoStack* undoStack() {return undo_stack_;}
 	
 	public slots:
-		void componentWritten();
 		Diagram *addNewDiagram();
 		QList <Diagram *> addNewDiagramFolioList();
 		void removeDiagram(Diagram *);
@@ -224,7 +223,7 @@
 			/// Current state of the project
 		ProjectState state_;
 			/// Diagrams carried by the project
-		QList<Diagram *> diagrams_;
+		QList<Diagram *> m_diagrams_list;
 			/// Project title
 		QString project_title_;
 			/// QElectroTech version declared in the XML document at opening time


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/