[qet] [4264] Clean some code

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


Revision: 4264
Author:   blacksun
Date:     2015-11-16 09:59:43 +0100 (Mon, 16 Nov 2015)
Log Message:
-----------
Clean some code

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

Modified: trunk/sources/diagram.cpp
===================================================================
--- trunk/sources/diagram.cpp	2015-11-15 19:47:15 UTC (rev 4263)
+++ trunk/sources/diagram.cpp	2015-11-16 08:59:43 UTC (rev 4264)
@@ -929,10 +929,10 @@
 	@param template_name Name of the title block template that has changed
 	@param new_template (Optional) Name of the title block template to use instead
 */
-void Diagram::titleBlockTemplateRemoved(const QString &template_name, const QString &new_template) {
-	if (border_and_titleblock.titleBlockTemplateName() != template_name) return;
-	
-	const TitleBlockTemplate *final_template = project_ -> getTemplateByName(new_template);
+void Diagram::titleBlockTemplateRemoved(const QString &template_name, const QString &new_template)
+{
+	if (border_and_titleblock.titleBlockTemplateName() != template_name) return;	
+	const TitleBlockTemplate *final_template = project_->embeddedTitleBlockTemplatesCollection()->getTemplate(new_template);
 	border_and_titleblock.titleBlockTemplateRemoved(template_name, final_template);
 	update();
 }
@@ -941,16 +941,16 @@
 	Set the template to use to render the title block of this diagram.
 	@param template_name Name of the title block template.
 */
-void Diagram::setTitleBlockTemplate(const QString &template_name) {
+void Diagram::setTitleBlockTemplate(const QString &template_name)
+{
 	if (!project_) return;
 	
 	QString current_name = border_and_titleblock.titleBlockTemplateName();
-	const TitleBlockTemplate *titleblock_template = project_ -> getTemplateByName(template_name);
+	const TitleBlockTemplate *titleblock_template = project_->embeddedTitleBlockTemplatesCollection()->getTemplate(template_name);
 	border_and_titleblock.titleBlockTemplateRemoved(current_name, titleblock_template);
 	
-	if (template_name != current_name) {
+	if (template_name != current_name)
 		emit(usedTitleBlockTemplateChanged(template_name));
-	}
 }
 
 /**

Modified: trunk/sources/projectview.cpp
===================================================================
--- trunk/sources/projectview.cpp	2015-11-15 19:47:15 UTC (rev 4263)
+++ trunk/sources/projectview.cpp	2015-11-16 08:59:43 UTC (rev 4264)
@@ -726,9 +726,10 @@
 	connect(buttons, SIGNAL(rejected()), &clean_dialog, SLOT(reject()));
 	
 	int clean_count = 0;
-	if (clean_dialog.exec() == QDialog::Accepted) {
+	if (clean_dialog.exec() == QDialog::Accepted)
+	{
 		if (clean_tbt -> isChecked()) {
-			project_ -> cleanUnusedTitleBlocKTemplates();
+			project_->embeddedTitleBlockTemplatesCollection()->deleteUnusedTitleBlocKTemplates();
 		}
 		if (clean_elements -> isChecked()) {
 			InteractiveMoveElementsHandler *handler = new InteractiveMoveElementsHandler(this);

Modified: trunk/sources/qetproject.cpp
===================================================================
--- trunk/sources/qetproject.cpp	2015-11-15 19:47:15 UTC (rev 4263)
+++ trunk/sources/qetproject.cpp	2015-11-16 08:59:43 UTC (rev 4264)
@@ -338,53 +338,6 @@
 }
 
 /**
-	@return the list of the titleblock templates embedded within this project 
-*/
-QList<QString> QETProject::embeddedTitleBlockTemplates() {
-	return(titleblocks_.templates());
-}
-
-/**
-	@param template_name Name of the requested template
-	@return the requested template, or 0 if there is no valid template of this
-	name within the project
-*/
-const TitleBlockTemplate *QETProject::getTemplateByName(const QString &template_name) {
-	return(titleblocks_.getTemplate(template_name));
-}
-
-/**
-	@param template_name Name of the requested template
-	@return the XML description of the requested template, or a null QDomElement
-	if the project does not have such an titleblock template
-*/
-QDomElement QETProject::getTemplateXmlDescriptionByName(const QString &template_name) {
-	return(titleblocks_.getTemplateXmlDescription(template_name));
-}
-
-/**
-	This methods allows adding or modifying a template embedded within the
-	project.
-	@param template_name Name / Identifier of the template - will be used to
-	determine whether the given description will be added or will replace an
-	existing one.
-	@param xml_elmt An \<titleblocktemplate\> XML element describing the
-	template. Its "name" attribute must equal to template_name.
-	@return false if a problem occured, true otherwise
-*/
-bool QETProject::setTemplateXmlDescription(const QString &template_name, const QDomElement &xml_elmt) {
-	return(titleblocks_.setTemplateXmlDescription(template_name, xml_elmt));
-}
-
-/**
-	This methods allows removing a template embedded within the project.
-	@param template_name Name of the template to be removed
-*/
-void QETProject::removeTemplateByName(const QString &template_name) {
-	return(titleblocks_.removeTemplate(template_name));
-}
-
-/**
 	@return les dimensions par defaut utilisees lors de la creation d'un
 	nouveau schema dans ce projet.
 */
@@ -839,11 +792,8 @@
 		}
 	}
 	
-	bool integration = setTemplateXmlDescription(
-		target_name,
-		src_tbt.getTemplateXmlDescription()
-	);
-	if (!integration) {
+	if (!titleblocks_.setTemplateXmlDescription(target_name, src_tbt.getTemplateXmlDescription()))
+	{
 		handler -> errorWithATemplate(src_tbt, tr("Une erreur s'est produite durant l'intégration du modèle.", "error message"));
 		target_name = QString();
 	}
@@ -883,13 +833,6 @@
 }
 
 /**
-	Delete all title block templates not used in the project
-*/
-void QETProject::cleanUnusedTitleBlocKTemplates() {
-	titleblocks_.deleteUnusedTitleBlocKTemplates();
-}
-
-/**
 	Supprime tous les elements inutilises dans le projet
 	@param handler Gestionnaire d'erreur
 */
@@ -1112,7 +1055,7 @@
 		//Load the default properties for the new diagrams
 	readDefaultPropertiesXml(xml_project);
 		//load the embedded titleblock templates
-	readEmbeddedTemplatesXml(xml_project);
+	titleblocks_.fromXml(xml_project.documentElement());
 		//Load the embedded elements collection
 	readElementsCollectionXml(xml_project);
 		//Load the diagrams
@@ -1181,15 +1124,6 @@
 }
 
 /**
- * @brief QETProject::readEmbeddedTemplatesXml
- * Loads the embedded template from the XML description of the project
- * @param xml_project : the xml description of the project
- */
-void QETProject::readEmbeddedTemplatesXml(QDomDocument &xml_project) {
-	titleblocks_.fromXml(xml_project.documentElement());
-}
-
-/**
  * @brief QETProject::readElementsCollectionXml
  * Load the diagrams from the xml description of the project
  * @param xml_project : the xml description of the project
@@ -1462,16 +1396,6 @@
 }
 
 /**
-	@return true if the embedded title block templates collection was modified,
-	false otherwise.
-*/
-bool QETProject::titleBlockTemplateCollectionWasModified() {
-	// we do not expect a new project to embed any title block template (this may
-	// change in the future though).
-	return(titleblocks_.templates().count());
-}
-
-/**
 	@return the project-wide properties made available to child diagrams.
 */
 DiagramContext QETProject::projectProperties() {
@@ -1500,7 +1424,7 @@
 	if ( projectOptionsWereModified()    ||
 		 !undo_stack_ -> isClean()       ||
 		 embeddedCollectionWasModified() ||
-		 titleBlockTemplateCollectionWasModified() )
+		 titleblocks_.templates().count() )
 		return(true);
 	
 	else

Modified: trunk/sources/qetproject.h
===================================================================
--- trunk/sources/qetproject.h	2015-11-15 19:47:15 UTC (rev 4263)
+++ trunk/sources/qetproject.h	2015-11-16 08:59:43 UTC (rev 4264)
@@ -93,11 +93,6 @@
 		QString title() const;
 		qreal declaredQElectroTechVersion();
 		void setTitle(const QString &);
-		QList<QString> embeddedTitleBlockTemplates();
-		const TitleBlockTemplate *getTemplateByName(const QString &template_name);
-		QDomElement getTemplateXmlDescriptionByName(const QString &);
-		bool setTemplateXmlDescription(const QString &, const QDomElement &);
-		void removeTemplateByName(const QString &);
 
 			///DEFAULT PROPERTIES
 		BorderProperties defaultBorderProperties() const;
@@ -138,13 +133,11 @@
 		QString integrateTitleBlockTemplate(const TitleBlockTemplateLocation &, MoveTitleBlockTemplatesHandler *handler);
 		bool usesElement(const ElementsLocation &);
 		bool usesTitleBlockTemplate(const TitleBlockTemplateLocation &);
-		void cleanUnusedTitleBlocKTemplates();
 		void cleanUnusedElements(MoveElementsHandler *);
 		void cleanEmptyCategories(MoveElementsHandler *);
 		bool projectWasModified();
 		bool projectOptionsWereModified();
 		bool embeddedCollectionWasModified();
-		bool titleBlockTemplateCollectionWasModified();
 		DiagramContext projectProperties();
 		void setProjectProperties(const DiagramContext &);
 		QUndoStack* undoStack() {return undo_stack_;}
@@ -184,7 +177,6 @@
 
 		void readProjectXml(QDomDocument &xml_project);
 		void readDiagramsXml(QDomDocument &xml_project);
-		void readEmbeddedTemplatesXml(QDomDocument &xml_project);
 		void readElementsCollectionXml(QDomDocument &xml_project);
 		void readProjectPropertiesXml(QDomDocument &xml_project);
 		void readDefaultPropertiesXml(QDomDocument &xml_project);

Modified: trunk/sources/titleblock/qettemplateeditor.cpp
===================================================================
--- trunk/sources/titleblock/qettemplateeditor.cpp	2015-11-15 19:47:15 UTC (rev 4263)
+++ trunk/sources/titleblock/qettemplateeditor.cpp	2015-11-16 08:59:43 UTC (rev 4264)
@@ -210,19 +210,23 @@
 	@param template_name Name of the template to edit within its parent project.
 	@return true if this editor was able to edit the given template, false otherwise
 */
-bool QETTitleBlockTemplateEditor::edit(QETProject *project, const QString &template_name) {
-	// we require a project we will rattach templates to
+bool QETTitleBlockTemplateEditor::edit(QETProject *project, const QString &template_name)
+{
+		// we require a project we will rattach templates to
 	if (!project) return(false);
 	
-	// the template name may be empty to create a new one
+		// the template name may be empty to create a new one
 	const TitleBlockTemplate *tb_template_orig;
-	if (template_name.isEmpty()) {
-		// loads the default title block template provided by the application
-		// it will be used as a start point to design the title block
+	if (template_name.isEmpty())
+	{
+			// loads the default title block template provided by the application
+			// it will be used as a start point to design the title block
 		tb_template_orig = QETApp::defaultTitleBlockTemplate();
-	} else {
-		tb_template_orig = project -> getTemplateByName(template_name);
 	}
+	else
+	{
+		tb_template_orig = project->embeddedTitleBlockTemplatesCollection()->getTemplate(template_name);
+	}
 	
 	if (!tb_template_orig) {
 		/// TODO The TBT does not exist, manage error


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