forked from qt-creator/qt-creator
Git: Add quick filter for branches panel
Change-Id: Idef4ab2db69f24bb004c00fa010b814fdaa7d56d Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
committed by
Orgad Shaneh
parent
170e599a11
commit
a9ac438ad8
@@ -123,8 +123,6 @@ public:
|
|||||||
|
|
||||||
QStringList fullName(bool includePrefix = false) const
|
QStringList fullName(bool includePrefix = false) const
|
||||||
{
|
{
|
||||||
QTC_ASSERT(isLeaf(), return QStringList());
|
|
||||||
|
|
||||||
QStringList fn;
|
QStringList fn;
|
||||||
QList<const BranchNode *> nodes;
|
QList<const BranchNode *> nodes;
|
||||||
const BranchNode *current = this;
|
const BranchNode *current = this;
|
||||||
|
@@ -37,6 +37,7 @@
|
|||||||
#include <coreplugin/documentmanager.h>
|
#include <coreplugin/documentmanager.h>
|
||||||
#include <coreplugin/inavigationwidgetfactory.h>
|
#include <coreplugin/inavigationwidgetfactory.h>
|
||||||
#include <utils/elidinglabel.h>
|
#include <utils/elidinglabel.h>
|
||||||
|
#include <utils/fancylineedit.h>
|
||||||
#include <utils/navigationtreeview.h>
|
#include <utils/navigationtreeview.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/utilsicons.h>
|
#include <utils/utilsicons.h>
|
||||||
@@ -48,6 +49,7 @@
|
|||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QPoint>
|
#include <QPoint>
|
||||||
|
#include <QSortFilterProxyModel>
|
||||||
#include <QTreeView>
|
#include <QTreeView>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
@@ -57,6 +59,21 @@ using namespace Core;
|
|||||||
namespace Git {
|
namespace Git {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
|
class BranchFilterModel : public QSortFilterProxyModel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BranchFilterModel(QObject *parent) : QSortFilterProxyModel(parent) {}
|
||||||
|
protected:
|
||||||
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
|
||||||
|
{
|
||||||
|
QAbstractItemModel *m = sourceModel();
|
||||||
|
// Filter leaves only. The root node and all intermediate nodes should always be visible
|
||||||
|
if (!sourceParent.isValid() || m->rowCount(m->index(sourceRow, 0, sourceParent)) > 0)
|
||||||
|
return true;
|
||||||
|
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
BranchView::BranchView() :
|
BranchView::BranchView() :
|
||||||
m_includeOldEntriesAction(new QAction(tr("Include Old Entries"), this)),
|
m_includeOldEntriesAction(new QAction(tr("Include Old Entries"), this)),
|
||||||
m_includeTagsAction(new QAction(tr("Include Tags"), this)),
|
m_includeTagsAction(new QAction(tr("Include Tags"), this)),
|
||||||
@@ -64,7 +81,8 @@ BranchView::BranchView() :
|
|||||||
m_refreshButton(new QToolButton(this)),
|
m_refreshButton(new QToolButton(this)),
|
||||||
m_repositoryLabel(new Utils::ElidingLabel(this)),
|
m_repositoryLabel(new Utils::ElidingLabel(this)),
|
||||||
m_branchView(new Utils::NavigationTreeView(this)),
|
m_branchView(new Utils::NavigationTreeView(this)),
|
||||||
m_model(new BranchModel(GitPlugin::client(), this))
|
m_model(new BranchModel(GitPlugin::client(), this)),
|
||||||
|
m_filterModel(new BranchFilterModel(this))
|
||||||
{
|
{
|
||||||
m_addButton->setIcon(Utils::Icons::PLUS_TOOLBAR.icon());
|
m_addButton->setIcon(Utils::Icons::PLUS_TOOLBAR.icon());
|
||||||
m_addButton->setProperty("noArrow", true);
|
m_addButton->setProperty("noArrow", true);
|
||||||
@@ -75,12 +93,21 @@ BranchView::BranchView() :
|
|||||||
m_refreshButton->setProperty("noArrow", true);
|
m_refreshButton->setProperty("noArrow", true);
|
||||||
connect(m_refreshButton, &QToolButton::clicked, this, &BranchView::refreshCurrentRepository);
|
connect(m_refreshButton, &QToolButton::clicked, this, &BranchView::refreshCurrentRepository);
|
||||||
|
|
||||||
m_branchView->setModel(m_model);
|
|
||||||
m_branchView->setHeaderHidden(true);
|
m_branchView->setHeaderHidden(true);
|
||||||
setFocus();
|
setFocus();
|
||||||
|
|
||||||
m_repositoryLabel->setElideMode(Qt::ElideLeft);
|
m_repositoryLabel->setElideMode(Qt::ElideLeft);
|
||||||
|
|
||||||
|
m_filterModel->setSourceModel(m_model);
|
||||||
|
m_filterModel->setFilterRole(Qt::EditRole);
|
||||||
|
m_filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||||
|
m_branchView->setModel(m_filterModel);
|
||||||
|
auto filterEdit = new Utils::FancyLineEdit(this);
|
||||||
|
filterEdit->setFiltering(true);
|
||||||
|
connect(filterEdit, &Utils::FancyLineEdit::textChanged,
|
||||||
|
m_filterModel, QOverload<const QString &>::of(&BranchFilterModel::setFilterRegExp));
|
||||||
auto layout = new QVBoxLayout(this);
|
auto layout = new QVBoxLayout(this);
|
||||||
|
layout->addWidget(filterEdit);
|
||||||
layout->addWidget(m_repositoryLabel);
|
layout->addWidget(m_repositoryLabel);
|
||||||
layout->addWidget(m_branchView);
|
layout->addWidget(m_branchView);
|
||||||
layout->setContentsMargins(0, 2, 0, 0);
|
layout->setContentsMargins(0, 2, 0, 0);
|
||||||
@@ -100,7 +127,7 @@ BranchView::BranchView() :
|
|||||||
|
|
||||||
m_branchView->setContextMenuPolicy(Qt::CustomContextMenu);
|
m_branchView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
connect(m_branchView, &QAbstractItemView::doubleClicked,
|
connect(m_branchView, &QAbstractItemView::doubleClicked,
|
||||||
this, &BranchView::log);
|
this, [this](const QModelIndex &idx) { log(m_filterModel->mapToSource(idx)); });
|
||||||
connect(m_branchView, &QWidget::customContextMenuRequested,
|
connect(m_branchView, &QWidget::customContextMenuRequested,
|
||||||
this, &BranchView::slotCustomContextMenu);
|
this, &BranchView::slotCustomContextMenu);
|
||||||
connect(m_model, &QAbstractItemModel::modelReset,
|
connect(m_model, &QAbstractItemModel::modelReset,
|
||||||
@@ -161,10 +188,11 @@ void BranchView::resizeColumns()
|
|||||||
|
|
||||||
void BranchView::slotCustomContextMenu(const QPoint &point)
|
void BranchView::slotCustomContextMenu(const QPoint &point)
|
||||||
{
|
{
|
||||||
const QModelIndex index = m_branchView->indexAt(point);
|
const QModelIndex filteredIndex = m_branchView->indexAt(point);
|
||||||
if (!index.isValid())
|
if (!filteredIndex.isValid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
const QModelIndex index = m_filterModel->mapToSource(filteredIndex);
|
||||||
const QModelIndex currentBranch = m_model->currentBranch();
|
const QModelIndex currentBranch = m_model->currentBranch();
|
||||||
const bool currentSelected = index.row() == currentBranch.row();
|
const bool currentSelected = index.row() == currentBranch.row();
|
||||||
const bool isLocal = m_model->isLocal(index);
|
const bool isLocal = m_model->isLocal(index);
|
||||||
@@ -246,7 +274,7 @@ QModelIndex BranchView::selectedIndex()
|
|||||||
QModelIndexList selected = m_branchView->selectionModel()->selectedIndexes();
|
QModelIndexList selected = m_branchView->selectionModel()->selectedIndexes();
|
||||||
if (selected.isEmpty())
|
if (selected.isEmpty())
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
return selected.at(0);
|
return m_filterModel->mapToSource(selected.at(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BranchView::add()
|
bool BranchView::add()
|
||||||
|
@@ -46,6 +46,7 @@ namespace Git {
|
|||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class BranchModel;
|
class BranchModel;
|
||||||
|
class BranchFilterModel;
|
||||||
|
|
||||||
class BranchView : public QWidget
|
class BranchView : public QWidget
|
||||||
{
|
{
|
||||||
@@ -87,6 +88,7 @@ private:
|
|||||||
Utils::ElidingLabel *m_repositoryLabel = nullptr;
|
Utils::ElidingLabel *m_repositoryLabel = nullptr;
|
||||||
Utils::NavigationTreeView *m_branchView = nullptr;
|
Utils::NavigationTreeView *m_branchView = nullptr;
|
||||||
BranchModel *m_model = nullptr;
|
BranchModel *m_model = nullptr;
|
||||||
|
BranchFilterModel *m_filterModel = nullptr;
|
||||||
QString m_repository;
|
QString m_repository;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user