[qet] [3313] Minor code improvent in creation of diagram folio list

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


Revision: 3313
Author:   blacksun
Date:     2014-09-18 20:12:05 +0200 (Thu, 18 Sep 2014)
Log Message:
-----------
Minor code improvent in creation of diagram folio list

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

Modified: trunk/sources/projectview.cpp
===================================================================
--- trunk/sources/projectview.cpp	2014-09-18 16:42:20 UTC (rev 3312)
+++ trunk/sources/projectview.cpp	2014-09-18 18:12:05 UTC (rev 3313)
@@ -295,8 +295,9 @@
 }
 
 /**
-	Ajoute un nouveau schema au ProjectView
-*/
+ * @brief ProjectView::addNewDiagram
+ * Add new diagram to project view
+ */
 void ProjectView::addNewDiagram() {
 	if (project_ -> isReadOnly()) return;
 	
@@ -309,13 +310,20 @@
 	showDiagram(new_diagram_view);
 }
 
+/**
+ * @brief ProjectView::addNewDiagramFolioList
+ * Add new diagram folio list to project
+ */
 void ProjectView::addNewDiagramFolioList() {
 	if (project_ -> isReadOnly()) return;
 
-	Diagram *new_diagram = project_ -> addNewDiagramFolioList();
-	DiagramView *new_diagram_view = new DiagramView(new_diagram);
-	addDiagram(new_diagram_view, true);
-	showDiagram(new_diagram_view);
+	QList <Diagram *> list = project_ -> addNewDiagramFolioList();
+	int size = list.size();
+	for (int i = 0; i < size; i++) {
+		DiagramView *new_diagram_view = new DiagramView(list.takeLast());
+		addDiagram(new_diagram_view, true);
+		showDiagram(new_diagram_view);
+	}
 }
 
 /**
@@ -352,8 +360,7 @@
 	emit(diagramAdded(diagram));
 	// move tab to front if wanted
 	if (front) {
-		tabs_->moveTab(tabs_->count()-1, project_ -> getFolioSheetsQuantity()-1);
-		//diagram -> diagram() -> project() -> setFolioSheetsQuantity(true);
+		tabs_->moveTab(tabs_->count()-1, 0);
 	}
 }
 

Modified: trunk/sources/qetdiagrameditor.cpp
===================================================================
--- trunk/sources/qetdiagrameditor.cpp	2014-09-18 16:42:20 UTC (rev 3312)
+++ trunk/sources/qetdiagrameditor.cpp	2014-09-18 18:12:05 UTC (rev 3313)
@@ -1698,15 +1698,13 @@
 	}
 }
 
+/**
+ * @brief QETDiagramEditor::addDiagramFolioListToProject
+ * Add new folio list to project
+ */
 void QETDiagramEditor::addDiagramFolioListToProject() {
-	ProjectView *current_project = currentProject();
-	if (current_project && current_project -> project() -> getFolioSheetsQuantity() == 0) {
-
-		// The number of folio sheets depend on the number of diagrams in the project.
-		int diagram_qty = current_project -> diagrams().size();
-		for (int i = 0; i <= diagram_qty/58; i++)
+	if (ProjectView *current_project = currentProject())
 			current_project -> addNewDiagramFolioList();
-	}
 }
 
 /**

Modified: trunk/sources/qetproject.cpp
===================================================================
--- trunk/sources/qetproject.cpp	2014-09-18 16:42:20 UTC (rev 3312)
+++ trunk/sources/qetproject.cpp	2014-09-18 18:12:05 UTC (rev 3313)
@@ -914,29 +914,39 @@
  * Add new diagram folio list
  * @return the created diagram
  */
-Diagram *QETProject::addNewDiagramFolioList() {
-	// do nothing if project is read only
-	if (isReadOnly()) return(0);
+QList <Diagram *> QETProject::addNewDiagramFolioList() {
+	// do nothing if project is read only or folio sheet is alredy created
+	QList <Diagram *> diagram_list;
 
-	//create new diagram
-	Diagram *diagram_folio_list = new DiagramFolioList(this);
+	if (!isReadOnly() && getFolioSheetsQuantity() == 0) {
 
-	// setup default properties
-	diagram_folio_list -> border_and_titleblock.importBorder(defaultBorderProperties());
-	diagram_folio_list -> border_and_titleblock.importTitleBlock(defaultTitleBlockProperties());
-	diagram_folio_list -> defaultConductorProperties = defaultConductorProperties();
+		//reset the number of folio sheet
+		setFolioSheetsQuantity(0);
 
-	diagram_folio_list -> border_and_titleblock.setTitle(tr("Liste des Sch\351mas"));
-	// no need to display rows and columns
-	diagram_folio_list -> border_and_titleblock.displayRows(false);
-	diagram_folio_list -> border_and_titleblock.displayColumns(false);
+		int diagCount = diagrams().size();
+		for (int i = 0; i <= diagCount/58; i++) {
 
+			//create new diagram
+			Diagram *diagram_folio_list = new DiagramFolioList(this);
 
-	addDiagram(diagram_folio_list);
-	setFolioSheetsQuantity( getFolioSheetsQuantity()+1 );
+			// setup default properties
+			diagram_folio_list -> border_and_titleblock.importBorder(defaultBorderProperties());
+			diagram_folio_list -> border_and_titleblock.importTitleBlock(defaultTitleBlockProperties());
+			diagram_folio_list -> defaultConductorProperties = defaultConductorProperties();
 
-	emit(diagramAdded(this, diagram_folio_list));
-	return(diagram_folio_list);
+			diagram_folio_list -> border_and_titleblock.setTitle(tr("Liste des Sch\351mas"));
+			// no need to display rows and columns
+			diagram_folio_list -> border_and_titleblock.displayRows(false);
+			diagram_folio_list -> border_and_titleblock.displayColumns(false);
+
+			addDiagram(diagram_folio_list);
+			setFolioSheetsQuantity( getFolioSheetsQuantity()+1 );
+			emit(diagramAdded(this, diagram_folio_list));
+			diagram_list << diagram_folio_list;
+		}
+	}
+
+	return(diagram_list);
 }
 
 /**
@@ -1027,7 +1037,6 @@
 	// la racine du document XML est sensee etre un element "project"
 	if (root_elmt.tagName() == "project") {
 
-
 		// mode d'ouverture normal
 		if (root_elmt.hasAttribute("version")) {
 			bool conv_ok;
@@ -1063,15 +1072,10 @@
 	
 	// load the project-wide properties
 	readProjectPropertiesXml();
-
+	
 	// charge les proprietes par defaut pour les nouveaux schemas
 	readDefaultPropertiesXml();
 	
-	// if there is an attribute for folioSheetQuantity, then set it accordingly.
-	// If not, then the value remains at the initial value of zero.
-	if (root_elmt.hasAttribute("folioSheetQuantity"))
-		addNewDiagramFolioList();
-
 	// load the embedded titleblock templates
 	readEmbeddedTemplatesXml();
 	
@@ -1081,6 +1085,12 @@
 	// charge les schemas
 	readDiagramsXml();
 
+	// if there is an attribute for folioSheetQuantity, then set it accordingly.
+	// If not, then the value remains at the initial value of zero.
+	if (root_elmt.attribute("folioSheetQuantity","0").toInt()) {
+		addNewDiagramFolioList();
+	}
+	
 	state_ = Ok;
 }
 

Modified: trunk/sources/qetproject.h
===================================================================
--- trunk/sources/qetproject.h	2014-09-18 16:42:20 UTC (rev 3312)
+++ trunk/sources/qetproject.h	2014-09-18 18:12:05 UTC (rev 3313)
@@ -145,7 +145,7 @@
 	public slots:
 	void componentWritten();
 	Diagram *addNewDiagram();
-	Diagram *addNewDiagramFolioList();
+	QList <Diagram *> addNewDiagramFolioList();
 	void removeDiagram(Diagram *);
 	void diagramOrderChanged(int, int);
 	void setModified(bool);


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