[qet] [1496] The elements panel now applies again the filter when the panel content is changed .

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


Revision: 1496
Author:   xavier
Date:     2012-02-12 16:33:04 +0100 (Sun, 12 Feb 2012)
Log Message:
-----------
The elements panel now applies again the filter when the panel content is changed.

Modified Paths:
--------------
    branches/0.3/sources/elementspanel.cpp
    branches/0.3/sources/elementspanel.h

Modified: branches/0.3/sources/elementspanel.cpp
===================================================================
--- branches/0.3/sources/elementspanel.cpp	2012-02-12 15:29:57 UTC (rev 1495)
+++ branches/0.3/sources/elementspanel.cpp	2012-02-12 15:33:04 UTC (rev 1496)
@@ -120,6 +120,7 @@
 	);
 	
 	connect(this, SIGNAL(firstActivated()), this, SLOT(firstActivation()));
+	connect(this, SIGNAL(panelContentChanged()), this, SLOT(panelContentChange()));
 	
 	// emet un signal au lieu de gerer son menu contextuel
 	setContextMenuPolicy(Qt::CustomContextMenu);
@@ -371,6 +372,15 @@
 }
 
 /**
+	Ensure the filter is applied again after the panel content has changed.
+*/
+void ElementsPanel::panelContentChange() {
+	if (!filter_.isEmpty()) {
+		filter(filter_);
+	}
+}
+
+/**
 	Methode permettant d'ajouter un projet au panel d'elements.
 	@param qtwi_parent QTreeWidgetItem parent sous lequel sera insere le projet
 	@param project Projet a inserer dans le panel d'elements
@@ -449,6 +459,20 @@
 }
 
 /**
+	@return true if \a item matches the current filter, false otherwise
+*/
+bool ElementsPanel::matchesCurrentFilter(const QTreeWidgetItem *item) const {
+	if (!item) return(false);
+	
+	// no filter => we consider the item matches
+	if (filter_.isEmpty()) return(true);
+	
+	bool item_matches = item -> text(0).contains(filter_, Qt::CaseInsensitive);
+	
+	return(item_matches);
+}
+
+/**
 	Reloads the following collections:
 	  * common collection
 	  * custom collection
@@ -628,15 +652,10 @@
 	}
 	
 	if (filtering != QET::EndFilter) {
-		// repere les items correspondant au filtre
-		QList<QTreeWidgetItem *> matching_items;
-		foreach (QTreeWidgetItem *item, items) {
-			bool item_matches = item -> text(0).contains(m, Qt::CaseInsensitive);
-			if (item_matches) matching_items << item;
-			item -> setHidden(!item_matches);
-		}
-		ensureHierarchyIsVisible(matching_items);
+		filter_ = m;
+		applyCurrentFilter(items);
 	} else { // filtering == QET::EndFilter
+		filter_ = QString();
 		QTreeWidgetItem *current_item = currentItem();
 		
 		// restore the tree as it was before the filtering
@@ -691,10 +710,24 @@
 }
 
 /**
+	Apply the current filter to a given item.
+*/
+void ElementsPanel::applyCurrentFilter(const QList<QTreeWidgetItem *> &items) {
+	if (filter_.isEmpty()) return;
+	QList<QTreeWidgetItem *> matching_items;
+	foreach (QTreeWidgetItem *item, items) {
+		bool item_matches = matchesCurrentFilter(item);
+		if (item_matches) matching_items << item;
+		item -> setHidden(!item_matches);
+	}
+	ensureHierarchyIsVisible(matching_items);
+}
+
+/**
 	@param items une liste de QTreeWidgetItem pour lesquels il faut s'assurer
 	que eux et leurs parents sont visibles
 */
-void ElementsPanel::ensureHierarchyIsVisible(QList<QTreeWidgetItem *> items) {
+void ElementsPanel::ensureHierarchyIsVisible(const QList<QTreeWidgetItem *> &items) {
 	// remonte l'arborescence pour lister les categories contenant les elements filtres
 	QSet<QTreeWidgetItem *> parent_items;
 	foreach(QTreeWidgetItem *item, items) {

Modified: branches/0.3/sources/elementspanel.h
===================================================================
--- branches/0.3/sources/elementspanel.h	2012-02-12 15:29:57 UTC (rev 1495)
+++ branches/0.3/sources/elementspanel.h	2012-02-12 15:33:04 UTC (rev 1496)
@@ -78,6 +78,8 @@
 	void projectWasOpened(QETProject *);
 	void projectWasClosed(QETProject *);
 	bool scrollToElement(const ElementsLocation &);
+	void applyCurrentFilter(const QList<QTreeWidgetItem *> &);
+	void ensureHierarchyIsVisible(const QList<QTreeWidgetItem *> &);
 	
 	protected:
 	void dragEnterEvent(QDragEnterEvent *);
@@ -86,9 +88,11 @@
 	void startDrag(Qt::DropActions);
 	void startElementDrag(const ElementsLocation &);
 	void startTitleBlockTemplateDrag(const TitleBlockTemplateLocation &);
+	bool matchesCurrentFilter(const QTreeWidgetItem *) const;
 	
 	protected slots:
 	void firstActivation();
+	void panelContentChange();
 	
 	private:
 	QTreeWidgetItem *addProject   (QETProject *);
@@ -97,8 +101,6 @@
 	QTreeWidgetItem *updateElementsCategoryItem(QTreeWidgetItem *, ElementsCategory *,  PanelOptions, bool = false);
 	QTreeWidgetItem *updateElementItem         (QTreeWidgetItem *, ElementDefinition *, PanelOptions, bool = false);
 	
-	void ensureHierarchyIsVisible(QList<QTreeWidgetItem *>);
-	
 	// attributes
 	private:
 	QSet<QETProject *> projects_to_display_;       ///< list of projects that have been added to this panel
@@ -108,5 +110,6 @@
 	QTreeWidgetItem *custom_tbt_collection_item_;  ///< pointer to the item representing the user templates collection
 	int loading_progress_;                         ///< used to track the loading progress of elements collections
 	bool first_reload_;                            ///< used to distinguish the first time this panel is reloaded
+	QString filter_;                               ///< Currently applied filter
 };
 #endif


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