mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-20 16:20:52 +01:00
Elements collection widget : improve the search
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4550 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -49,6 +49,12 @@ ElementsCollectionWidget::ElementsCollectionWidget(QWidget *parent):
|
|||||||
setUpWidget();
|
setUpWidget();
|
||||||
setUpAction();
|
setUpAction();
|
||||||
setUpConnection();
|
setUpConnection();
|
||||||
|
|
||||||
|
//Timer is used to avoid launching a new search for each letter typed by user
|
||||||
|
//Timer is started or restarted at every time user type a new letter.
|
||||||
|
//When the timer emit timeout, we start the search.
|
||||||
|
m_search_timer.setInterval(500);
|
||||||
|
m_search_timer.setSingleShot(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -148,7 +154,8 @@ void ElementsCollectionWidget::setUpWidget()
|
|||||||
void ElementsCollectionWidget::setUpConnection()
|
void ElementsCollectionWidget::setUpConnection()
|
||||||
{
|
{
|
||||||
connect(m_tree_view, &QTreeView::customContextMenuRequested, this, &ElementsCollectionWidget::customContextMenu);
|
connect(m_tree_view, &QTreeView::customContextMenuRequested, this, &ElementsCollectionWidget::customContextMenu);
|
||||||
connect(m_search_field, &QLineEdit::textEdited, this, &ElementsCollectionWidget::search);
|
connect(m_search_field, &QLineEdit::textEdited, [this]() {m_search_timer.start();});
|
||||||
|
connect(&m_search_timer, &QTimer::timeout, this, &ElementsCollectionWidget::search);
|
||||||
connect(m_open_dir, &QAction::triggered, this, &ElementsCollectionWidget::openDir);
|
connect(m_open_dir, &QAction::triggered, this, &ElementsCollectionWidget::openDir);
|
||||||
connect(m_edit_element, &QAction::triggered, this, &ElementsCollectionWidget::editElement);
|
connect(m_edit_element, &QAction::triggered, this, &ElementsCollectionWidget::editElement);
|
||||||
connect(m_delete_element, &QAction::triggered, this, &ElementsCollectionWidget::deleteElement);
|
connect(m_delete_element, &QAction::triggered, this, &ElementsCollectionWidget::deleteElement);
|
||||||
@@ -413,7 +420,7 @@ void ElementsCollectionWidget::showThisDir()
|
|||||||
ElementCollectionItem *eci = elementCollectionItemForIndex(m_showed_index);
|
ElementCollectionItem *eci = elementCollectionItemForIndex(m_showed_index);
|
||||||
if (eci)
|
if (eci)
|
||||||
eci->setBackground(QBrush(Qt::yellow));
|
eci->setBackground(QBrush(Qt::yellow));
|
||||||
search(m_search_field->text());
|
search();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
resetShowThisDir();
|
resetShowThisDir();
|
||||||
@@ -434,7 +441,7 @@ void ElementsCollectionWidget::resetShowThisDir()
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_showed_index = QModelIndex();
|
m_showed_index = QModelIndex();
|
||||||
search(m_search_field->text());
|
search();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -476,12 +483,12 @@ void ElementsCollectionWidget::reload()
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ElementsCollectionWidget::search
|
* @brief ElementsCollectionWidget::search
|
||||||
* Search every item (directory or element) that match the string @text
|
* Search every item (directory or element) that match the text of m_search_field
|
||||||
* and display it, other item who does not match @text is hidden
|
* and display it, other item who does not match @text is hidden
|
||||||
* @param text
|
|
||||||
*/
|
*/
|
||||||
void ElementsCollectionWidget::search(const QString &text)
|
void ElementsCollectionWidget::search()
|
||||||
{
|
{
|
||||||
|
QString text = m_search_field->text();
|
||||||
//Reset the search
|
//Reset the search
|
||||||
if (text.isEmpty())
|
if (text.isEmpty())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QModelIndex>
|
#include <QModelIndex>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
class ElementsCollectionModel;
|
class ElementsCollectionModel;
|
||||||
class QVBoxLayout;
|
class QVBoxLayout;
|
||||||
@@ -65,7 +66,7 @@ class ElementsCollectionWidget : public QWidget
|
|||||||
void newElement();
|
void newElement();
|
||||||
void showThisDir();
|
void showThisDir();
|
||||||
void resetShowThisDir();
|
void resetShowThisDir();
|
||||||
void search(const QString &text);
|
void search();
|
||||||
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 parent = true, bool child = false);
|
void showAndExpandItem (const QModelIndex &index, bool parent = true, bool child = false);
|
||||||
@@ -78,6 +79,7 @@ class ElementsCollectionWidget : public QWidget
|
|||||||
private:
|
private:
|
||||||
ElementsCollectionModel *m_model;
|
ElementsCollectionModel *m_model;
|
||||||
QLineEdit *m_search_field;
|
QLineEdit *m_search_field;
|
||||||
|
QTimer m_search_timer;
|
||||||
ElementsTreeView *m_tree_view;
|
ElementsTreeView *m_tree_view;
|
||||||
QVBoxLayout *m_main_vlayout;
|
QVBoxLayout *m_main_vlayout;
|
||||||
QMenu *m_context_menu;
|
QMenu *m_context_menu;
|
||||||
|
|||||||
Reference in New Issue
Block a user