The elements panel now applies again the filter when the panel content is changed.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1496 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
xavier
2012-02-12 15:33:04 +00:00
parent bde78d0412
commit 39c75e0136
2 changed files with 47 additions and 11 deletions

View File

@@ -120,6 +120,7 @@ ElementsPanel::ElementsPanel(QWidget *parent) :
); );
connect(this, SIGNAL(firstActivated()), this, SLOT(firstActivation())); connect(this, SIGNAL(firstActivated()), this, SLOT(firstActivation()));
connect(this, SIGNAL(panelContentChanged()), this, SLOT(panelContentChange()));
// emet un signal au lieu de gerer son menu contextuel // emet un signal au lieu de gerer son menu contextuel
setContextMenuPolicy(Qt::CustomContextMenu); setContextMenuPolicy(Qt::CustomContextMenu);
@@ -370,6 +371,15 @@ void ElementsPanel::firstActivation() {
QTimer::singleShot(250, this, SLOT(reload())); QTimer::singleShot(250, this, SLOT(reload()));
} }
/**
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. Methode permettant d'ajouter un projet au panel d'elements.
@param qtwi_parent QTreeWidgetItem parent sous lequel sera insere le projet @param qtwi_parent QTreeWidgetItem parent sous lequel sera insere le projet
@@ -448,6 +458,20 @@ QTreeWidgetItem *ElementsPanel::updateElementItem(QTreeWidgetItem *element_qtwi,
return(item); return(item);
} }
/**
@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: Reloads the following collections:
* common collection * common collection
@@ -628,15 +652,10 @@ void ElementsPanel::filter(const QString &m, QET::Filtering filtering) {
} }
if (filtering != QET::EndFilter) { if (filtering != QET::EndFilter) {
// repere les items correspondant au filtre filter_ = m;
QList<QTreeWidgetItem *> matching_items; applyCurrentFilter(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);
} else { // filtering == QET::EndFilter } else { // filtering == QET::EndFilter
filter_ = QString();
QTreeWidgetItem *current_item = currentItem(); QTreeWidgetItem *current_item = currentItem();
// restore the tree as it was before the filtering // restore the tree as it was before the filtering
@@ -690,11 +709,25 @@ bool ElementsPanel::scrollToElement(const ElementsLocation &location) {
return(true); return(true);
} }
/**
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 @param items une liste de QTreeWidgetItem pour lesquels il faut s'assurer
que eux et leurs parents sont visibles 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 // remonte l'arborescence pour lister les categories contenant les elements filtres
QSet<QTreeWidgetItem *> parent_items; QSet<QTreeWidgetItem *> parent_items;
foreach(QTreeWidgetItem *item, items) { foreach(QTreeWidgetItem *item, items) {

View File

@@ -78,6 +78,8 @@ class ElementsPanel : public GenericPanel {
void projectWasOpened(QETProject *); void projectWasOpened(QETProject *);
void projectWasClosed(QETProject *); void projectWasClosed(QETProject *);
bool scrollToElement(const ElementsLocation &); bool scrollToElement(const ElementsLocation &);
void applyCurrentFilter(const QList<QTreeWidgetItem *> &);
void ensureHierarchyIsVisible(const QList<QTreeWidgetItem *> &);
protected: protected:
void dragEnterEvent(QDragEnterEvent *); void dragEnterEvent(QDragEnterEvent *);
@@ -86,9 +88,11 @@ class ElementsPanel : public GenericPanel {
void startDrag(Qt::DropActions); void startDrag(Qt::DropActions);
void startElementDrag(const ElementsLocation &); void startElementDrag(const ElementsLocation &);
void startTitleBlockTemplateDrag(const TitleBlockTemplateLocation &); void startTitleBlockTemplateDrag(const TitleBlockTemplateLocation &);
bool matchesCurrentFilter(const QTreeWidgetItem *) const;
protected slots: protected slots:
void firstActivation(); void firstActivation();
void panelContentChange();
private: private:
QTreeWidgetItem *addProject (QETProject *); QTreeWidgetItem *addProject (QETProject *);
@@ -97,8 +101,6 @@ class ElementsPanel : public GenericPanel {
QTreeWidgetItem *updateElementsCategoryItem(QTreeWidgetItem *, ElementsCategory *, PanelOptions, bool = false); QTreeWidgetItem *updateElementsCategoryItem(QTreeWidgetItem *, ElementsCategory *, PanelOptions, bool = false);
QTreeWidgetItem *updateElementItem (QTreeWidgetItem *, ElementDefinition *, PanelOptions, bool = false); QTreeWidgetItem *updateElementItem (QTreeWidgetItem *, ElementDefinition *, PanelOptions, bool = false);
void ensureHierarchyIsVisible(QList<QTreeWidgetItem *>);
// attributes // attributes
private: private:
QSet<QETProject *> projects_to_display_; ///< list of projects that have been added to this panel QSet<QETProject *> projects_to_display_; ///< list of projects that have been added to this panel
@@ -108,5 +110,6 @@ class ElementsPanel : public GenericPanel {
QTreeWidgetItem *custom_tbt_collection_item_; ///< pointer to the item representing the user templates collection 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 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 bool first_reload_; ///< used to distinguish the first time this panel is reloaded
QString filter_; ///< Currently applied filter
}; };
#endif #endif