New element panel : add a "show only this dir" Qaction.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4355 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2016-02-26 09:58:55 +00:00
parent a545791b71
commit 52b588ea50
6 changed files with 120 additions and 15 deletions

View File

@@ -17,6 +17,7 @@
*/
#include "elementcollectionitem.h"
#include <QMimeData>
#include <QBrush>
/**
* @brief ElementCollectionItem::ElementCollectionItem
@@ -206,9 +207,23 @@ int ElementCollectionItem::columnCount() const {
* @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();
}
@@ -353,6 +368,19 @@ int ElementCollectionItem::indexOfChild(ElementCollectionItem *child) const {
return m_child_items.indexOf(child);
}
/**
* @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

View File

@@ -69,6 +69,7 @@ class ElementCollectionItem : public QObject
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 @@ class ElementCollectionItem : public QObject
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

View File

@@ -92,6 +92,8 @@ void ElementsCollectionWidget::setUpAction()
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 @@ void ElementsCollectionWidget::setUpConnection()
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 @@ void ElementsCollectionWidget::customContextMenu(const QPoint &point)
}
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);
@@ -351,6 +362,52 @@ void ElementsCollectionWidget::newElement()
elmt_wizard.exec();
}
/**
* @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.
*/
@@ -393,8 +450,17 @@ void ElementsCollectionWidget::search(const QString &text)
if (text.isEmpty())
{
QModelIndex current_index = m_tree_view->currentIndex();
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 @@ void ElementsCollectionWidget::search(const QString &text)
}
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 @@ void ElementsCollectionWidget::hideItem(bool hide, const QModelIndex &index, boo
/**
* @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);
}

View File

@@ -61,11 +61,13 @@ class ElementsCollectionWidget : public QWidget
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 @@ class ElementsCollectionWidget : public QWidget
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 @@ class ElementsCollectionWidget : public QWidget
*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

View File

@@ -177,7 +177,7 @@ QVariant FileElementCollectionItem::data(int column, int role)
return collectionPath();
break;
default:
return QVariant();
return ElementCollectionItem::data(column, role);
break;
}
}

View File

@@ -99,7 +99,7 @@ QVariant XmlProjectElementCollectionItem::data(int column, int role)
return collectionPath();
break;
default:
return QVariant();
return ElementCollectionItem::data(column, role);
}
}