forked from qt-creator/qt-creator
Utils: Add a simple way to make a Utils::TreeView searchable
Call setSearchRole(...) to create a suitable find aggregate. Use it in a few places. Change-Id: Iaa663d13bbc7776019e7b18ea720cc2411e0b691 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -15,12 +15,14 @@
|
||||
#include "findtoolbar.h"
|
||||
#include "findtoolwindow.h"
|
||||
#include "ifindfilter.h"
|
||||
#include "itemviewfind.h"
|
||||
#include "searchresultwindow.h"
|
||||
#include "textfindconstants.h"
|
||||
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/itemviews.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QApplication>
|
||||
@@ -261,6 +263,10 @@ void Find::initialize()
|
||||
&FindPrivate::writeSettings);
|
||||
QObject::connect(
|
||||
SessionManager::instance(), &SessionManager::sessionLoaded, d, &FindPrivate::readSettings);
|
||||
|
||||
Utils::Internal::setViewSearchCallback([](QAbstractItemView *view, int role) {
|
||||
Aggregation::aggregate({view, new ItemViewFind(view, role)});
|
||||
});
|
||||
}
|
||||
|
||||
void Find::extensionsInitialized()
|
||||
|
||||
@@ -45,6 +45,10 @@ SearchResultTreeView::SearchResultTreeView(QWidget *parent)
|
||||
setItemDelegate(new SearchResultTreeItemDelegate(8, this));
|
||||
setIndentation(14);
|
||||
setExpandsOnDoubleClick(true);
|
||||
setFrameStyle(QFrame::NoFrame);
|
||||
setAttribute(Qt::WA_MacShowFocusRect, false);
|
||||
setSearchRole(ItemDataRoles::ResultLineRole);
|
||||
|
||||
header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
header()->setStretchLastSection(false);
|
||||
header()->hide();
|
||||
|
||||
@@ -110,15 +110,11 @@ SearchResultWidget::SearchResultWidget(QWidget *parent) :
|
||||
m_messageWidget->setVisible(false);
|
||||
|
||||
m_searchResultTreeView = new SearchResultTreeView(this);
|
||||
m_searchResultTreeView->setFrameStyle(QFrame::NoFrame);
|
||||
m_searchResultTreeView->setAttribute(Qt::WA_MacShowFocusRect, false);
|
||||
connect(m_searchResultTreeView, &SearchResultTreeView::filterInvalidated,
|
||||
this, &SearchResultWidget::filterInvalidated);
|
||||
connect(m_searchResultTreeView, &SearchResultTreeView::filterChanged,
|
||||
this, &SearchResultWidget::filterChanged);
|
||||
|
||||
auto find = new ItemViewFind(m_searchResultTreeView, ItemDataRoles::ResultLineRole);
|
||||
Aggregation::aggregate({m_searchResultTreeView, find});
|
||||
layout->addWidget(m_searchResultTreeView);
|
||||
|
||||
m_infoBarDisplay.setTarget(layout, 2);
|
||||
|
||||
@@ -14,9 +14,6 @@
|
||||
|
||||
#include <utils/utilsicons.h>
|
||||
|
||||
#include <aggregation/aggregate.h>
|
||||
#include <coreplugin/find/itemviewfind.h>
|
||||
|
||||
#include <QAction>
|
||||
#include <QToolButton>
|
||||
#include <QLabel>
|
||||
@@ -77,8 +74,7 @@ Console::Console()
|
||||
connect(m_consoleView->selectionModel(), &QItemSelectionModel::currentChanged,
|
||||
itemDelegate, &ConsoleItemDelegate::currentChanged);
|
||||
m_consoleView->setItemDelegate(itemDelegate);
|
||||
|
||||
Aggregation::aggregate({m_consoleView, new Core::ItemViewFind(m_consoleView)});
|
||||
m_consoleView->setSearchRole(Qt::DisplayRole);
|
||||
|
||||
vbox->addWidget(m_consoleView);
|
||||
vbox->addWidget(new Core::FindToolBarPlaceHolder(m_consoleWidget));
|
||||
|
||||
@@ -172,9 +172,7 @@ TaskWindow::TaskWindow() : d(std::make_unique<TaskWindowPrivate>())
|
||||
d->m_filter = new Internal::TaskFilterModel(d->m_model);
|
||||
d->m_filter->setAutoAcceptChildRows(true);
|
||||
|
||||
auto find = new Core::ItemViewFind(&d->m_treeView, TaskModel::Description);
|
||||
Aggregation::aggregate({&d->m_treeView, find});
|
||||
|
||||
d->m_treeView.setSearchRole(TaskModel::Description);
|
||||
d->m_treeView.setHeaderHidden(true);
|
||||
d->m_treeView.setExpandsOnDoubleClick(false);
|
||||
d->m_treeView.setAlternatingRowColors(true);
|
||||
|
||||
@@ -10,10 +10,7 @@
|
||||
#include "todooutputtreeview.h"
|
||||
#include "todotr.h"
|
||||
|
||||
#include <aggregation/aggregate.h>
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/find/itemviewfind.h>
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <QIcon>
|
||||
@@ -214,8 +211,6 @@ void TodoOutputPane::createTreeView()
|
||||
m_todoTreeView = new TodoOutputTreeView();
|
||||
m_todoTreeView->setModel(m_filteredTodoItemsModel);
|
||||
|
||||
Aggregation::aggregate({m_todoTreeView, new Core::ItemViewFind(m_todoTreeView)});
|
||||
|
||||
connect(m_todoTreeView, &TodoOutputTreeView::activated, this, &TodoOutputPane::todoTreeViewClicked);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ TodoOutputTreeView::TodoOutputTreeView(QWidget *parent) :
|
||||
setAttribute(Qt::WA_MacShowFocusRect, false);
|
||||
setSelectionBehavior(QTreeView::SelectRows);
|
||||
setItemDelegate(new TodoOutputTreeViewDelegate(this));
|
||||
setSearchRole(Qt::DisplayRole);
|
||||
|
||||
header()->setSectionResizeMode(QHeaderView::Interactive);
|
||||
header()->setStretchLastSection(true);
|
||||
|
||||
Reference in New Issue
Block a user