mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 05:00:33 +01:00
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:
@@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "elementcollectionitem.h"
|
#include "elementcollectionitem.h"
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
|
#include <QBrush>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ElementCollectionItem::ElementCollectionItem
|
* @brief ElementCollectionItem::ElementCollectionItem
|
||||||
@@ -206,9 +207,23 @@ int ElementCollectionItem::columnCount() const {
|
|||||||
* @param role
|
* @param role
|
||||||
* @return the data at @column and @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(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();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,6 +368,19 @@ int ElementCollectionItem::indexOfChild(ElementCollectionItem *child) const {
|
|||||||
return m_child_items.indexOf(child);
|
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
|
* @brief ElementCollectionItem::canRemoveContent
|
||||||
* @return true if this item can remove the content that he represent
|
* @return true if this item can remove the content that he represent
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ class ElementCollectionItem : public QObject
|
|||||||
QList<ElementCollectionItem *> elementsChild() const;
|
QList<ElementCollectionItem *> elementsChild() const;
|
||||||
QList<ElementCollectionItem *> directoriesChild() const;
|
QList<ElementCollectionItem *> directoriesChild() const;
|
||||||
int indexOfChild(ElementCollectionItem *child) const;
|
int indexOfChild(ElementCollectionItem *child) const;
|
||||||
|
void setBackgroundColor(Qt::GlobalColor color, bool show);
|
||||||
|
|
||||||
|
|
||||||
virtual bool canRemoveContent();
|
virtual bool canRemoveContent();
|
||||||
@@ -84,6 +85,8 @@ class ElementCollectionItem : public QObject
|
|||||||
ElementCollectionItem *m_parent_item;
|
ElementCollectionItem *m_parent_item;
|
||||||
QList <ElementCollectionItem *> m_child_items;
|
QList <ElementCollectionItem *> m_child_items;
|
||||||
QString m_name;
|
QString m_name;
|
||||||
|
Qt::GlobalColor m_bg_color;
|
||||||
|
bool m_show_bg_color = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ELEMENTCOLLECTIONITEM_H
|
#endif // ELEMENTCOLLECTIONITEM_H
|
||||||
|
|||||||
@@ -92,6 +92,8 @@ void ElementsCollectionWidget::setUpAction()
|
|||||||
m_edit_dir = new QAction(QET::Icons::FolderEdit, tr("Éditer le dossier"), this);
|
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_directory = new QAction(QET::Icons::FolderNew, tr("Nouveau dossier"), this);
|
||||||
m_new_element = new QAction(QET::Icons::ElementNew, tr("Nouvel élément"), 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_edit_dir, &QAction::triggered, this, &ElementsCollectionWidget::editDirectory);
|
||||||
connect(m_new_directory, &QAction::triggered, this, &ElementsCollectionWidget::newDirectory);
|
connect(m_new_directory, &QAction::triggered, this, &ElementsCollectionWidget::newDirectory);
|
||||||
connect(m_new_element, &QAction::triggered, this, &ElementsCollectionWidget::newElement);
|
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) {
|
connect(m_tree_view, &QTreeView::doubleClicked, [this](const QModelIndex &index) {
|
||||||
this->m_index_at_context_menu = index ;
|
this->m_index_at_context_menu = index ;
|
||||||
@@ -197,6 +201,13 @@ void ElementsCollectionWidget::customContextMenu(const QPoint &point)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_context_menu->addSeparator();
|
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)
|
if (add_open_dir)
|
||||||
m_context_menu->addAction(m_open_dir);
|
m_context_menu->addAction(m_open_dir);
|
||||||
m_context_menu->addAction(m_reload);
|
m_context_menu->addAction(m_reload);
|
||||||
@@ -351,6 +362,52 @@ void ElementsCollectionWidget::newElement()
|
|||||||
elmt_wizard.exec();
|
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.
|
* @brief ElementsCollectionWidget::reload, the displayed collections.
|
||||||
*/
|
*/
|
||||||
@@ -393,8 +450,17 @@ void ElementsCollectionWidget::search(const QString &text)
|
|||||||
if (text.isEmpty())
|
if (text.isEmpty())
|
||||||
{
|
{
|
||||||
QModelIndex current_index = m_tree_view->currentIndex();
|
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
|
//Expand the tree and scroll to the last selected index
|
||||||
if (current_index.isValid())
|
if (current_index.isValid())
|
||||||
@@ -407,7 +473,8 @@ void ElementsCollectionWidget::search(const QString &text)
|
|||||||
}
|
}
|
||||||
|
|
||||||
hideCollection(true);
|
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)
|
foreach(QModelIndex index, match_index)
|
||||||
showAndExpandItem(index);
|
showAndExpandItem(index);
|
||||||
}
|
}
|
||||||
@@ -442,16 +509,18 @@ void ElementsCollectionWidget::hideItem(bool hide, const QModelIndex &index, boo
|
|||||||
/**
|
/**
|
||||||
* @brief ElementsCollectionWidget::showAndExpandItem
|
* @brief ElementsCollectionWidget::showAndExpandItem
|
||||||
* Show the item @index and expand it.
|
* 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 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())
|
if (parent && index.isValid())
|
||||||
showAndExpandItem(index.parent(), recursive);
|
showAndExpandItem(index.parent(), parent);
|
||||||
|
|
||||||
m_tree_view->setRowHidden(index.row(), index.parent(), false);
|
hideItem(false, index, child);
|
||||||
m_tree_view->expand(index);
|
m_tree_view->expand(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,11 +61,13 @@ class ElementsCollectionWidget : public QWidget
|
|||||||
void editDirectory();
|
void editDirectory();
|
||||||
void newDirectory();
|
void newDirectory();
|
||||||
void newElement();
|
void newElement();
|
||||||
|
void showThisDir();
|
||||||
|
void resetShowThisDir();
|
||||||
void reload();
|
void reload();
|
||||||
void search(const QString &text);
|
void search(const QString &text);
|
||||||
void hideCollection(bool hide = true);
|
void hideCollection(bool hide = true);
|
||||||
void hideItem(bool hide, const QModelIndex &index = QModelIndex(), bool recursive = 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);
|
ElementCollectionItem *elementCollectionItemForIndex (const QModelIndex &index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -75,6 +77,7 @@ class ElementsCollectionWidget : public QWidget
|
|||||||
QVBoxLayout *m_main_vlayout;
|
QVBoxLayout *m_main_vlayout;
|
||||||
QMenu *m_context_menu;
|
QMenu *m_context_menu;
|
||||||
QModelIndex m_index_at_context_menu;
|
QModelIndex m_index_at_context_menu;
|
||||||
|
QModelIndex m_showed_index;
|
||||||
QProgressBar *m_progress_bar;
|
QProgressBar *m_progress_bar;
|
||||||
|
|
||||||
QAction *m_open_dir,
|
QAction *m_open_dir,
|
||||||
@@ -84,7 +87,9 @@ class ElementsCollectionWidget : public QWidget
|
|||||||
*m_reload,
|
*m_reload,
|
||||||
*m_edit_dir,
|
*m_edit_dir,
|
||||||
*m_new_directory,
|
*m_new_directory,
|
||||||
*m_new_element;
|
*m_new_element,
|
||||||
|
*m_show_this_dir,
|
||||||
|
*m_show_all_dir;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ELEMENTSCOLLECTIONWIDGET_H
|
#endif // ELEMENTSCOLLECTIONWIDGET_H
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ QVariant FileElementCollectionItem::data(int column, int role)
|
|||||||
return collectionPath();
|
return collectionPath();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return QVariant();
|
return ElementCollectionItem::data(column, role);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ QVariant XmlProjectElementCollectionItem::data(int column, int role)
|
|||||||
return collectionPath();
|
return collectionPath();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return QVariant();
|
return ElementCollectionItem::data(column, role);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user