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:
@@ -53,12 +53,39 @@ namespace Utils {
|
|||||||
Also adds sane keyboard navigation for mac.
|
Also adds sane keyboard navigation for mac.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
static Internal::ViewSearchCallback &viewSearchCallback()
|
||||||
|
{
|
||||||
|
static Internal::ViewSearchCallback theViewSearchCallback;
|
||||||
|
return theViewSearchCallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void makeViewSearchable(QAbstractItemView *view, int role)
|
||||||
|
{
|
||||||
|
if (viewSearchCallback())
|
||||||
|
viewSearchCallback()(view, role);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\internal
|
||||||
|
|
||||||
|
\note Only use once from Core initialization.
|
||||||
|
*/
|
||||||
|
void Internal::setViewSearchCallback(const ViewSearchCallback &cb)
|
||||||
|
{
|
||||||
|
viewSearchCallback() = cb;
|
||||||
|
}
|
||||||
|
|
||||||
TreeView::TreeView(QWidget *parent)
|
TreeView::TreeView(QWidget *parent)
|
||||||
: View<QTreeView>(parent)
|
: View<QTreeView>(parent)
|
||||||
{
|
{
|
||||||
setUniformRowHeights(true);
|
setUniformRowHeights(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TreeView::setSearchRole(int role)
|
||||||
|
{
|
||||||
|
makeViewSearchable(this, role);
|
||||||
|
}
|
||||||
|
|
||||||
TreeWidget::TreeWidget(QWidget *parent)
|
TreeWidget::TreeWidget(QWidget *parent)
|
||||||
: View<QTreeWidget>(parent)
|
: View<QTreeWidget>(parent)
|
||||||
{
|
{
|
||||||
|
@@ -28,6 +28,7 @@ public:
|
|||||||
View(QWidget *parent = nullptr)
|
View(QWidget *parent = nullptr)
|
||||||
: BaseT(parent)
|
: BaseT(parent)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void setActivationMode(ActivationMode mode)
|
void setActivationMode(ActivationMode mode)
|
||||||
{
|
{
|
||||||
if (mode == PlatformDefaultActivation)
|
if (mode == PlatformDefaultActivation)
|
||||||
@@ -81,6 +82,8 @@ class QTCREATOR_UTILS_EXPORT TreeView : public View<QTreeView>
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TreeView(QWidget *parent = nullptr);
|
TreeView(QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
void setSearchRole(int role);
|
||||||
};
|
};
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT TreeWidget : public View<QTreeWidget>
|
class QTCREATOR_UTILS_EXPORT TreeWidget : public View<QTreeWidget>
|
||||||
@@ -101,4 +104,11 @@ public:
|
|||||||
ListWidget(QWidget *parent = nullptr);
|
ListWidget(QWidget *parent = nullptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
using ViewSearchCallback = std::function<void(QAbstractItemView *view, int role)>;
|
||||||
|
QTCREATOR_UTILS_EXPORT void setViewSearchCallback(const ViewSearchCallback &cb);
|
||||||
|
|
||||||
|
} // Internal
|
||||||
|
|
||||||
} // Utils
|
} // Utils
|
||||||
|
@@ -15,12 +15,14 @@
|
|||||||
#include "findtoolbar.h"
|
#include "findtoolbar.h"
|
||||||
#include "findtoolwindow.h"
|
#include "findtoolwindow.h"
|
||||||
#include "ifindfilter.h"
|
#include "ifindfilter.h"
|
||||||
|
#include "itemviewfind.h"
|
||||||
#include "searchresultwindow.h"
|
#include "searchresultwindow.h"
|
||||||
#include "textfindconstants.h"
|
#include "textfindconstants.h"
|
||||||
|
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
|
#include <utils/itemviews.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
@@ -261,6 +263,10 @@ void Find::initialize()
|
|||||||
&FindPrivate::writeSettings);
|
&FindPrivate::writeSettings);
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
SessionManager::instance(), &SessionManager::sessionLoaded, d, &FindPrivate::readSettings);
|
SessionManager::instance(), &SessionManager::sessionLoaded, d, &FindPrivate::readSettings);
|
||||||
|
|
||||||
|
Utils::Internal::setViewSearchCallback([](QAbstractItemView *view, int role) {
|
||||||
|
Aggregation::aggregate({view, new ItemViewFind(view, role)});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Find::extensionsInitialized()
|
void Find::extensionsInitialized()
|
||||||
|
@@ -45,6 +45,10 @@ SearchResultTreeView::SearchResultTreeView(QWidget *parent)
|
|||||||
setItemDelegate(new SearchResultTreeItemDelegate(8, this));
|
setItemDelegate(new SearchResultTreeItemDelegate(8, this));
|
||||||
setIndentation(14);
|
setIndentation(14);
|
||||||
setExpandsOnDoubleClick(true);
|
setExpandsOnDoubleClick(true);
|
||||||
|
setFrameStyle(QFrame::NoFrame);
|
||||||
|
setAttribute(Qt::WA_MacShowFocusRect, false);
|
||||||
|
setSearchRole(ItemDataRoles::ResultLineRole);
|
||||||
|
|
||||||
header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||||
header()->setStretchLastSection(false);
|
header()->setStretchLastSection(false);
|
||||||
header()->hide();
|
header()->hide();
|
||||||
|
@@ -110,15 +110,11 @@ SearchResultWidget::SearchResultWidget(QWidget *parent) :
|
|||||||
m_messageWidget->setVisible(false);
|
m_messageWidget->setVisible(false);
|
||||||
|
|
||||||
m_searchResultTreeView = new SearchResultTreeView(this);
|
m_searchResultTreeView = new SearchResultTreeView(this);
|
||||||
m_searchResultTreeView->setFrameStyle(QFrame::NoFrame);
|
|
||||||
m_searchResultTreeView->setAttribute(Qt::WA_MacShowFocusRect, false);
|
|
||||||
connect(m_searchResultTreeView, &SearchResultTreeView::filterInvalidated,
|
connect(m_searchResultTreeView, &SearchResultTreeView::filterInvalidated,
|
||||||
this, &SearchResultWidget::filterInvalidated);
|
this, &SearchResultWidget::filterInvalidated);
|
||||||
connect(m_searchResultTreeView, &SearchResultTreeView::filterChanged,
|
connect(m_searchResultTreeView, &SearchResultTreeView::filterChanged,
|
||||||
this, &SearchResultWidget::filterChanged);
|
this, &SearchResultWidget::filterChanged);
|
||||||
|
|
||||||
auto find = new ItemViewFind(m_searchResultTreeView, ItemDataRoles::ResultLineRole);
|
|
||||||
Aggregation::aggregate({m_searchResultTreeView, find});
|
|
||||||
layout->addWidget(m_searchResultTreeView);
|
layout->addWidget(m_searchResultTreeView);
|
||||||
|
|
||||||
m_infoBarDisplay.setTarget(layout, 2);
|
m_infoBarDisplay.setTarget(layout, 2);
|
||||||
|
@@ -14,9 +14,6 @@
|
|||||||
|
|
||||||
#include <utils/utilsicons.h>
|
#include <utils/utilsicons.h>
|
||||||
|
|
||||||
#include <aggregation/aggregate.h>
|
|
||||||
#include <coreplugin/find/itemviewfind.h>
|
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
@@ -77,8 +74,7 @@ Console::Console()
|
|||||||
connect(m_consoleView->selectionModel(), &QItemSelectionModel::currentChanged,
|
connect(m_consoleView->selectionModel(), &QItemSelectionModel::currentChanged,
|
||||||
itemDelegate, &ConsoleItemDelegate::currentChanged);
|
itemDelegate, &ConsoleItemDelegate::currentChanged);
|
||||||
m_consoleView->setItemDelegate(itemDelegate);
|
m_consoleView->setItemDelegate(itemDelegate);
|
||||||
|
m_consoleView->setSearchRole(Qt::DisplayRole);
|
||||||
Aggregation::aggregate({m_consoleView, new Core::ItemViewFind(m_consoleView)});
|
|
||||||
|
|
||||||
vbox->addWidget(m_consoleView);
|
vbox->addWidget(m_consoleView);
|
||||||
vbox->addWidget(new Core::FindToolBarPlaceHolder(m_consoleWidget));
|
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 = new Internal::TaskFilterModel(d->m_model);
|
||||||
d->m_filter->setAutoAcceptChildRows(true);
|
d->m_filter->setAutoAcceptChildRows(true);
|
||||||
|
|
||||||
auto find = new Core::ItemViewFind(&d->m_treeView, TaskModel::Description);
|
d->m_treeView.setSearchRole(TaskModel::Description);
|
||||||
Aggregation::aggregate({&d->m_treeView, find});
|
|
||||||
|
|
||||||
d->m_treeView.setHeaderHidden(true);
|
d->m_treeView.setHeaderHidden(true);
|
||||||
d->m_treeView.setExpandsOnDoubleClick(false);
|
d->m_treeView.setExpandsOnDoubleClick(false);
|
||||||
d->m_treeView.setAlternatingRowColors(true);
|
d->m_treeView.setAlternatingRowColors(true);
|
||||||
|
@@ -10,10 +10,7 @@
|
|||||||
#include "todooutputtreeview.h"
|
#include "todooutputtreeview.h"
|
||||||
#include "todotr.h"
|
#include "todotr.h"
|
||||||
|
|
||||||
#include <aggregation/aggregate.h>
|
|
||||||
|
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
#include <coreplugin/find/itemviewfind.h>
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
@@ -214,8 +211,6 @@ void TodoOutputPane::createTreeView()
|
|||||||
m_todoTreeView = new TodoOutputTreeView();
|
m_todoTreeView = new TodoOutputTreeView();
|
||||||
m_todoTreeView->setModel(m_filteredTodoItemsModel);
|
m_todoTreeView->setModel(m_filteredTodoItemsModel);
|
||||||
|
|
||||||
Aggregation::aggregate({m_todoTreeView, new Core::ItemViewFind(m_todoTreeView)});
|
|
||||||
|
|
||||||
connect(m_todoTreeView, &TodoOutputTreeView::activated, this, &TodoOutputPane::todoTreeViewClicked);
|
connect(m_todoTreeView, &TodoOutputTreeView::activated, this, &TodoOutputPane::todoTreeViewClicked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -26,6 +26,7 @@ TodoOutputTreeView::TodoOutputTreeView(QWidget *parent) :
|
|||||||
setAttribute(Qt::WA_MacShowFocusRect, false);
|
setAttribute(Qt::WA_MacShowFocusRect, false);
|
||||||
setSelectionBehavior(QTreeView::SelectRows);
|
setSelectionBehavior(QTreeView::SelectRows);
|
||||||
setItemDelegate(new TodoOutputTreeViewDelegate(this));
|
setItemDelegate(new TodoOutputTreeViewDelegate(this));
|
||||||
|
setSearchRole(Qt::DisplayRole);
|
||||||
|
|
||||||
header()->setSectionResizeMode(QHeaderView::Interactive);
|
header()->setSectionResizeMode(QHeaderView::Interactive);
|
||||||
header()->setStretchLastSection(true);
|
header()->setStretchLastSection(true);
|
||||||
|
Reference in New Issue
Block a user