[qet] [1477] The panel now highlights unused title block templates.

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


Revision: 1477
Author:   xavier
Date:     2012-01-23 21:36:51 +0100 (Mon, 23 Jan 2012)
Log Message:
-----------
The panel now highlights unused title block templates.

Modified Paths:
--------------
    branches/0.3/sources/diagram.cpp
    branches/0.3/sources/diagram.h
    branches/0.3/sources/elementspanel.cpp
    branches/0.3/sources/elementspanel.h
    branches/0.3/sources/qetproject.cpp
    branches/0.3/sources/qetproject.h
    branches/0.3/sources/titleblock/templatelocation.cpp
    branches/0.3/sources/titleblock/templatelocation.h

Modified: branches/0.3/sources/diagram.cpp
===================================================================
--- branches/0.3/sources/diagram.cpp	2012-01-23 07:22:07 UTC (rev 1476)
+++ branches/0.3/sources/diagram.cpp	2012-01-23 20:36:51 UTC (rev 1477)
@@ -761,6 +761,10 @@
 	QString current_name = border_and_titleblock.titleBlockTemplateName();
 	const TitleBlockTemplate *titleblock_template = project_ -> getTemplateByName(template_name);
 	border_and_titleblock.titleBlockTemplateRemoved(current_name, titleblock_template);
+	
+	if (template_name != current_name) {
+		emit(usedTitleBlockTemplateChanged(template_name));
+	}
 }
 
 /**
@@ -901,6 +905,15 @@
 }
 
 /**
+	@param a title block template name
+	@return true if the provided template is used by this diagram, false
+	otherwise.
+*/
+bool Diagram::usesTitleBlockTemplate(const QString &name) {
+	return(name == border_and_titleblock.titleBlockTemplateName());
+}
+
+/**
 	Cette methode permet d'appliquer de nouvelles options de rendu tout en
 	accedant aux proprietes de rendu en cours.
 	@param new_properties Nouvelles options de rendu a appliquer

Modified: branches/0.3/sources/diagram.h
===================================================================
--- branches/0.3/sources/diagram.h	2012-01-23 07:22:07 UTC (rev 1476)
+++ branches/0.3/sources/diagram.h	2012-01-23 20:36:51 UTC (rev 1477)
@@ -165,6 +165,7 @@
 	void continueMoveElementTexts(const QPointF &);
 	void endMoveElementTexts();
 	bool usesElement(const ElementsLocation &);
+	bool usesTitleBlockTemplate(const QString &);
 	
 	QUndoStack &undoStack();
 	QGIManager &qgiManager();
@@ -183,6 +184,7 @@
 	signals:
 	void written();
 	void readOnlyChanged(bool);
+	void usedTitleBlockTemplateChanged(const QString &);
 };
 
 /**

Modified: branches/0.3/sources/elementspanel.cpp
===================================================================
--- branches/0.3/sources/elementspanel.cpp	2012-01-23 07:22:07 UTC (rev 1476)
+++ branches/0.3/sources/elementspanel.cpp	2012-01-23 20:36:51 UTC (rev 1477)
@@ -760,11 +760,7 @@
 	if (QETProject *element_project = element -> location().project()) {
 		// affiche en rouge les elements inutilises dans un projet
 		if (!element_project -> usesElement(element -> location())) {
-			QLinearGradient t(0, 0, 200, 0);
-			t.setColorAt(0, QColor("#ffc0c0"));
-			t.setColorAt(1, QColor("#ffffff"));
-			qtwi -> setBackground(0, QBrush(t));
-			qtwi -> setToolTip(0, QString(tr("%1 [non utilis\351 dans le projet]")).arg(qtwi -> toolTip(0)));
+			markItemAsUnused(qtwi);
 		}
 	}
 	locations_.insert(qtwi, element -> location());
@@ -788,6 +784,8 @@
 ) {
 	if (!collection) return(0);
 	
+	QString selected_template;
+	
 	// check whether we have an item for the given collection
 	QTreeWidgetItem *qtwi_tbt_collection = title_blocks_collections_.key(collection);
 	if (!qtwi_tbt_collection) {
@@ -809,7 +807,24 @@
 			this,
 			SLOT(titleBlockTemplatesCollectionChanged(TitleBlockTemplatesCollection*, const QString &))
 		);
+		// if the added collection is rattached to a project, we're interested in
+		// knowing how many times each template is used.
+		if (QETProject *project = collection -> parentProject()) {
+			connect(
+				project, SIGNAL(diagramUsedTemplate(TitleBlockTemplatesCollection *, const QString &)),
+				this, SLOT(titleBlockTemplatesCollectionChanged(TitleBlockTemplatesCollection *, const QString &))
+			);
+		}
 	} else {
+		// save the currently selected template, if any
+		if (QTreeWidgetItem *current_qtwi = currentItem()) {
+			for (int i = 0 ; i < qtwi_tbt_collection -> childCount() ; ++ i) {
+				if (qtwi_tbt_collection -> child(i) == current_qtwi) {
+					selected_template = nameOfTitleBlockTemplate(qtwi_tbt_collection -> child(i));
+				}
+			}
+		}
+		
 		// the collection has already been added
 		// remove the child title block templates
 		foreach(QTreeWidgetItem *qtwi_tbt, qtwi_tbt_collection -> takeChildren()) {
@@ -839,8 +854,26 @@
 		);
 		qtwi_tbt -> setToolTip(0, template_location.toString());
 		qtwi_tbt -> setIcon(0, QET::Icons::TitleBlock);
+		
+		// special action for templates that belong to a project
+		if (QETProject *tbt_project = template_location.parentProject()) {
+			// display unused templates using a red background
+			if (!tbt_project -> usesTitleBlockTemplate(template_location)) {
+				markItemAsUnused(qtwi_tbt);
+			}
+		}
+		
 		title_blocks_.insert(qtwi_tbt, template_location);
 	}
+	
+	// restore the previously selected template, if any
+	if (!selected_template.isEmpty()) {
+		TitleBlockTemplateLocation location = collection -> location(selected_template);
+		QTreeWidgetItem *previously_selected_item = title_blocks_.key(location, 0);
+		if (previously_selected_item) {
+			setCurrentItem(previously_selected_item);
+		}
+	}
 	return(qtwi_tbt_collection);
 }
 
@@ -892,6 +925,11 @@
 	}
 	
 	// vide l'arbre et le hash
+	foreach (TitleBlockTemplatesCollection *tbt_collection, title_blocks_collections_) {
+		if (QETProject *project = tbt_collection -> parentProject()) {
+			disconnect(project, 0, this, 0);
+		}
+	}
 	clear();
 	locations_.clear();
 	projects_.clear();
@@ -1399,3 +1437,15 @@
 	}
 }
 
+/**
+	Mark the provided QTreeWidgetItem as unused in its parent project.
+	@param qtwi A QTreeWidgetItem
+*/
+void ElementsPanel::markItemAsUnused(QTreeWidgetItem *qtwi) {
+	QLinearGradient t(0, 0, 200, 0);
+	t.setColorAt(0, QColor("#ffc0c0"));
+	t.setColorAt(1, QColor("#ffffff"));
+	qtwi -> setBackground(0, QBrush(t));
+	qtwi -> setToolTip(0, QString(tr("%1 [non utilis\351 dans le projet]")).arg(qtwi -> toolTip(0)));
+}
+

Modified: branches/0.3/sources/elementspanel.h
===================================================================
--- branches/0.3/sources/elementspanel.h	2012-01-23 07:22:07 UTC (rev 1476)
+++ branches/0.3/sources/elementspanel.h	2012-01-23 20:36:51 UTC (rev 1477)
@@ -137,6 +137,7 @@
 	QString diagramTitleToDisplay(Diagram *) const;
 	QString titleBlockTemplateNameToDisplay(const QString &) const;
 	void ensureHierarchyIsVisible(QList<QTreeWidgetItem *>);
+	void markItemAsUnused(QTreeWidgetItem *);
 	
 	// attributs
 	private:

Modified: branches/0.3/sources/qetproject.cpp
===================================================================
--- branches/0.3/sources/qetproject.cpp	2012-01-23 07:22:07 UTC (rev 1476)
+++ branches/0.3/sources/qetproject.cpp	2012-01-23 20:36:51 UTC (rev 1477)
@@ -724,6 +724,23 @@
 }
 
 /**
+	@param location Location of a title block template
+	@return true if the provided template is used by at least one diagram
+	within this project, false otherwise
+*/
+bool QETProject::usesTitleBlockTemplate(const TitleBlockTemplateLocation &location) {
+	// a diagram can only use a title block template embedded wihtin its parent project
+	if (location.parentProject() != this) return(false);
+	
+	foreach (Diagram *diagram, diagrams()) {
+		if (diagram -> usesTitleBlockTemplate(location.name())) {
+			return(true);
+		}
+	}
+	return(false);
+}
+
+/**
 	Supprime tous les elements inutilises dans le projet
 	@param handler Gestionnaire d'erreur
 */
@@ -1047,6 +1064,10 @@
 		this,
 		SLOT(updateDiagramsFolioData())
 	);
+	connect(
+		diagram, SIGNAL(usedTitleBlockTemplateChanged(const QString &)),
+		this, SLOT(usedTitleBlockTemplateChanged(const QString &))
+	);
 	
 	// ajoute le schema au projet
 	diagrams_ << diagram;
@@ -1176,6 +1197,14 @@
 }
 
 /**
+	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));
+}
+
+/**
 	Copie l'element integ_elmt dans la categorie target_cat en utilisant le
 	gestionnaire handler ; en cas d'erreur, error_message est rempli.
 	@return l'emplacement de l'element cree

Modified: branches/0.3/sources/qetproject.h
===================================================================
--- branches/0.3/sources/qetproject.h	2012-01-23 07:22:07 UTC (rev 1476)
+++ branches/0.3/sources/qetproject.h	2012-01-23 20:36:51 UTC (rev 1477)
@@ -108,6 +108,7 @@
 	QString integrateElement(const QString &, MoveElementsHandler *, QString &);
 	QString integrateTitleBlockTemplate(const TitleBlockTemplateLocation &, MoveTitleBlockTemplatesHandler *handler);
 	bool usesElement(const ElementsLocation &);
+	bool usesTitleBlockTemplate(const TitleBlockTemplateLocation &);
 	void cleanUnusedElements(MoveElementsHandler *);
 	void cleanEmptyCategories(MoveElementsHandler *);
 	bool projectWasModified();
@@ -126,12 +127,14 @@
 	void projectInformationsChanged(QETProject *);
 	void diagramAdded(QETProject *, Diagram *);
 	void diagramRemoved(QETProject *, Diagram *);
+	void diagramUsedTemplate(TitleBlockTemplatesCollection *, const QString &);
 	void readOnlyChanged(QETProject *, bool);
 	
 	private slots:
 	void updateDiagramsFolioData();
 	void updateDiagramsTitleBlockTemplate(TitleBlockTemplatesCollection *, const QString &);
 	void removeDiagramsTitleBlockTemplate(TitleBlockTemplatesCollection *, const QString &);
+	void usedTitleBlockTemplateChanged(const QString &);
 	
 	private:
 	void setupTitleBlockTemplatesCollection();

Modified: branches/0.3/sources/titleblock/templatelocation.cpp
===================================================================
--- branches/0.3/sources/titleblock/templatelocation.cpp	2012-01-23 07:22:07 UTC (rev 1476)
+++ branches/0.3/sources/titleblock/templatelocation.cpp	2012-01-23 20:36:51 UTC (rev 1477)
@@ -153,3 +153,12 @@
 	if (!collection_) return(false);
 	return(collection_ -> isReadOnly(name_));
 }
+
+/**
+	@param location other location that should be compared to this one
+	@return true if locations are equal, false otherwise
+*/
+bool TitleBlockTemplateLocation::operator==(const TitleBlockTemplateLocation &location) const {
+	return(location.collection_ == collection_ && location.name_ == name_);
+}
+

Modified: branches/0.3/sources/titleblock/templatelocation.h
===================================================================
--- branches/0.3/sources/titleblock/templatelocation.h	2012-01-23 07:22:07 UTC (rev 1476)
+++ branches/0.3/sources/titleblock/templatelocation.h	2012-01-23 20:36:51 UTC (rev 1477)
@@ -50,6 +50,7 @@
 	QDomElement getTemplateXmlDescription() const;
 	TitleBlockTemplate *getTemplate() const;
 	bool isReadOnly() const;
+	bool operator==(const TitleBlockTemplateLocation &) const;
 	
 	// attributes
 	private:


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