[qet] [4355] New element panel : add a "show only this dir" Qaction. |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 4355
Author: blacksun
Date: 2016-02-26 10:58:55 +0100 (Fri, 26 Feb 2016)
Log Message:
-----------
New element panel : add a "show only this dir" Qaction.
Modified Paths:
--------------
trunk/sources/ElementsCollection/elementcollectionitem.cpp
trunk/sources/ElementsCollection/elementcollectionitem.h
trunk/sources/ElementsCollection/elementscollectionwidget.cpp
trunk/sources/ElementsCollection/elementscollectionwidget.h
trunk/sources/ElementsCollection/fileelementcollectionitem.cpp
trunk/sources/ElementsCollection/xmlprojectelementcollectionitem.cpp
Modified: trunk/sources/ElementsCollection/elementcollectionitem.cpp
===================================================================
--- trunk/sources/ElementsCollection/elementcollectionitem.cpp 2016-02-25 16:48:44 UTC (rev 4354)
+++ trunk/sources/ElementsCollection/elementcollectionitem.cpp 2016-02-26 09:58:55 UTC (rev 4355)
@@ -17,6 +17,7 @@
*/
#include "elementcollectionitem.h"
#include <QMimeData>
+#include <QBrush>
/**
* @brief ElementCollectionItem::ElementCollectionItem
@@ -206,9 +207,23 @@
* @param role
* @return the data at @column and @role.
*/
-QVariant ElementCollectionItem::data(int column, int role) {
+QVariant ElementCollectionItem::data(int column, int role)
+{
Q_UNUSED(column);
- Q_UNUSED(role);
+
+ switch (role)
+ {
+ case Qt::BackgroundRole:
+ {
+ if(m_show_bg_color)
+ return QBrush(m_bg_color);
+ else
+ return QVariant();
+ }
+ default:
+ return QVariant();
+ }
+
return QVariant();
}
@@ -354,6 +369,19 @@
}
/**
+ * @brief ElementCollectionItem::setBackgroundColor
+ * Set the background color for this item to @color
+ * if @show is true, use the background color, else let's Qt use the appropriate color
+ * @param color
+ * @param show
+ */
+void ElementCollectionItem::setBackgroundColor(Qt::GlobalColor color, bool show)
+{
+ m_bg_color = color;
+ m_show_bg_color = show;
+}
+
+/**
* @brief ElementCollectionItem::canRemoveContent
* @return true if this item can remove the content that he represent
* By default return false.
Modified: trunk/sources/ElementsCollection/elementcollectionitem.h
===================================================================
--- trunk/sources/ElementsCollection/elementcollectionitem.h 2016-02-25 16:48:44 UTC (rev 4354)
+++ trunk/sources/ElementsCollection/elementcollectionitem.h 2016-02-26 09:58:55 UTC (rev 4355)
@@ -69,6 +69,7 @@
QList<ElementCollectionItem *> elementsChild() const;
QList<ElementCollectionItem *> directoriesChild() const;
int indexOfChild(ElementCollectionItem *child) const;
+ void setBackgroundColor(Qt::GlobalColor color, bool show);
virtual bool canRemoveContent();
@@ -84,6 +85,8 @@
ElementCollectionItem *m_parent_item;
QList <ElementCollectionItem *> m_child_items;
QString m_name;
+ Qt::GlobalColor m_bg_color;
+ bool m_show_bg_color = false;
};
#endif // ELEMENTCOLLECTIONITEM_H
Modified: trunk/sources/ElementsCollection/elementscollectionwidget.cpp
===================================================================
--- trunk/sources/ElementsCollection/elementscollectionwidget.cpp 2016-02-25 16:48:44 UTC (rev 4354)
+++ trunk/sources/ElementsCollection/elementscollectionwidget.cpp 2016-02-26 09:58:55 UTC (rev 4355)
@@ -92,6 +92,8 @@
m_edit_dir = new QAction(QET::Icons::FolderEdit, tr("Éditer le dossier"), this);
m_new_directory = new QAction(QET::Icons::FolderNew, tr("Nouveau dossier"), this);
m_new_element = new QAction(QET::Icons::ElementNew, tr("Nouvel élément"), this);
+ m_show_this_dir = new QAction(QET::Icons::ZoomDraw, tr("Afficher uniquement ce dossier"), this);
+ m_show_all_dir = new QAction(QET::Icons::ZoomOriginal, tr("Afficher tous les dossiers"), this);
}
/**
@@ -145,6 +147,8 @@
connect(m_edit_dir, &QAction::triggered, this, &ElementsCollectionWidget::editDirectory);
connect(m_new_directory, &QAction::triggered, this, &ElementsCollectionWidget::newDirectory);
connect(m_new_element, &QAction::triggered, this, &ElementsCollectionWidget::newElement);
+ connect(m_show_this_dir, &QAction::triggered, this, &ElementsCollectionWidget::showThisDir);
+ connect(m_show_all_dir, &QAction::triggered, this, &ElementsCollectionWidget::resetShowThisDir);
connect(m_tree_view, &QTreeView::doubleClicked, [this](const QModelIndex &index) {
this->m_index_at_context_menu = index ;
@@ -197,6 +201,13 @@
}
m_context_menu->addSeparator();
+ if (eci->isDir())
+ {
+ m_context_menu->addAction(m_show_this_dir);
+ //there is a current filtered dir, add entry to reset it
+ if (m_showed_index.isValid())
+ m_context_menu->addAction(m_show_all_dir);
+ }
if (add_open_dir)
m_context_menu->addAction(m_open_dir);
m_context_menu->addAction(m_reload);
@@ -352,6 +363,52 @@
}
/**
+ * @brief ElementsCollectionWidget::showThisDir
+ * Hide all directories except the pointed dir;
+ */
+void ElementsCollectionWidget::showThisDir()
+{
+ //Disable the yellow background of the previous index
+ if (m_showed_index.isValid())
+ {
+ ElementCollectionItem *eci = elementCollectionItemForIndex(m_showed_index);
+ if (eci)
+ eci->setBackgroundColor(Qt::yellow, false);
+ }
+
+ m_showed_index = m_index_at_context_menu;
+ if (m_showed_index.isValid())
+ {
+ hideCollection(true);
+ showAndExpandItem(m_showed_index, true, true);
+ ElementCollectionItem *eci = elementCollectionItemForIndex(m_showed_index);
+ if (eci)
+ eci->setBackgroundColor(Qt::yellow, true);
+ search(m_search_field->text());
+ }
+ else
+ resetShowThisDir();
+}
+
+/**
+ * @brief ElementsCollectionWidget::resetShowThisDir
+ * reset show this dir, all collection are show.
+ * If search field isn't empty, apply the search after show all collection
+ */
+void ElementsCollectionWidget::resetShowThisDir()
+{
+ if (m_showed_index.isValid())
+ {
+ ElementCollectionItem *eci = elementCollectionItemForIndex(m_showed_index);
+ if (eci)
+ eci->setBackgroundColor(Qt::yellow, false);
+ }
+
+ m_showed_index = QModelIndex();
+ search(m_search_field->text());
+}
+
+/**
* @brief ElementsCollectionWidget::reload, the displayed collections.
*/
void ElementsCollectionWidget::reload()
@@ -393,9 +450,18 @@
if (text.isEmpty())
{
QModelIndex current_index = m_tree_view->currentIndex();
- m_tree_view->reset();
- expandFirstItems();
+ if (m_showed_index.isValid())
+ {
+ hideCollection(true);
+ showAndExpandItem(m_showed_index, true, true);
+ }
+ else
+ {
+ m_tree_view->reset();
+ expandFirstItems();
+ }
+
//Expand the tree and scroll to the last selected index
if (current_index.isValid())
{
@@ -407,7 +473,8 @@
}
hideCollection(true);
- QModelIndexList match_index = m_model->match(m_model->index(0,0), Qt::DisplayRole, QVariant(text), -1, Qt::MatchContains | Qt::MatchRecursive);
+ QModelIndexList match_index = m_model->match(m_showed_index.isValid() ? m_model->index(0,0,m_showed_index) : m_model->index(0,0),
+ Qt::DisplayRole, QVariant(text), -1, Qt::MatchContains | Qt::MatchRecursive);
foreach(QModelIndex index, match_index)
showAndExpandItem(index);
}
@@ -442,16 +509,18 @@
/**
* @brief ElementsCollectionWidget::showAndExpandItem
* Show the item @index and expand it.
- * If recursive is true, ensure parents of @index is show and expanded
+ * If parent is true, ensure parents of @index is show and expanded
+ * If child is true, ensure all childs of @index is show and expended
* @param index- index to show
- * @param recursive- Apply to parent
+ * @param parent- Apply to parent
+ * @param child- Apply to all childs
*/
-void ElementsCollectionWidget::showAndExpandItem(const QModelIndex &index, bool recursive)
+void ElementsCollectionWidget::showAndExpandItem(const QModelIndex &index, bool parent, bool child)
{
- if (recursive && index.isValid())
- showAndExpandItem(index.parent(), recursive);
+ if (parent && index.isValid())
+ showAndExpandItem(index.parent(), parent);
- m_tree_view->setRowHidden(index.row(), index.parent(), false);
+ hideItem(false, index, child);
m_tree_view->expand(index);
}
Modified: trunk/sources/ElementsCollection/elementscollectionwidget.h
===================================================================
--- trunk/sources/ElementsCollection/elementscollectionwidget.h 2016-02-25 16:48:44 UTC (rev 4354)
+++ trunk/sources/ElementsCollection/elementscollectionwidget.h 2016-02-26 09:58:55 UTC (rev 4355)
@@ -61,11 +61,13 @@
void editDirectory();
void newDirectory();
void newElement();
+ void showThisDir();
+ void resetShowThisDir();
void reload();
void search(const QString &text);
void hideCollection(bool hide = true);
void hideItem(bool hide, const QModelIndex &index = QModelIndex(), bool recursive = true);
- void showAndExpandItem (const QModelIndex &index, bool recursive = true);
+ void showAndExpandItem (const QModelIndex &index, bool parent = true, bool child = false);
ElementCollectionItem *elementCollectionItemForIndex (const QModelIndex &index);
private:
@@ -75,6 +77,7 @@
QVBoxLayout *m_main_vlayout;
QMenu *m_context_menu;
QModelIndex m_index_at_context_menu;
+ QModelIndex m_showed_index;
QProgressBar *m_progress_bar;
QAction *m_open_dir,
@@ -84,7 +87,9 @@
*m_reload,
*m_edit_dir,
*m_new_directory,
- *m_new_element;
+ *m_new_element,
+ *m_show_this_dir,
+ *m_show_all_dir;
};
#endif // ELEMENTSCOLLECTIONWIDGET_H
Modified: trunk/sources/ElementsCollection/fileelementcollectionitem.cpp
===================================================================
--- trunk/sources/ElementsCollection/fileelementcollectionitem.cpp 2016-02-25 16:48:44 UTC (rev 4354)
+++ trunk/sources/ElementsCollection/fileelementcollectionitem.cpp 2016-02-26 09:58:55 UTC (rev 4355)
@@ -177,7 +177,7 @@
return collectionPath();
break;
default:
- return QVariant();
+ return ElementCollectionItem::data(column, role);
break;
}
}
Modified: trunk/sources/ElementsCollection/xmlprojectelementcollectionitem.cpp
===================================================================
--- trunk/sources/ElementsCollection/xmlprojectelementcollectionitem.cpp 2016-02-25 16:48:44 UTC (rev 4354)
+++ trunk/sources/ElementsCollection/xmlprojectelementcollectionitem.cpp 2016-02-26 09:58:55 UTC (rev 4355)
@@ -99,7 +99,7 @@
return collectionPath();
break;
default:
- return QVariant();
+ return ElementCollectionItem::data(column, role);
}
}