-
-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use columns for file name, directory, and state when files are shown as a list in TreeViews. Resolves Dense layout issue #547 #632
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,6 @@ | |
#include "StatePushButton.h" | ||
#include "TreeProxy.h" | ||
#include "TreeView.h" | ||
#include "ViewDelegate.h" | ||
#include "Debug.h" | ||
#include "conf/Settings.h" | ||
#include "DiffView/DiffView.h" | ||
|
@@ -98,6 +97,7 @@ DoubleTreeWidget::DoubleTreeWidget(const git::Repository &repo, QWidget *parent) | |
listView->setChecked(Settings::instance() | ||
->value(Setting::Id::ShowChangedFilesAsList, false) | ||
.toBool()); | ||
RepoView::parentView(this)->refresh(); | ||
connect(listView, &QAction::triggered, this, [this](bool checked) { | ||
Settings::instance()->setValue(Setting::Id::ShowChangedFilesAsList, | ||
checked); | ||
|
@@ -160,13 +160,8 @@ DoubleTreeWidget::DoubleTreeWidget(const git::Repository &repo, QWidget *parent) | |
repoView->updateSubmodules(submodules, recursive, init, | ||
force_checkout); | ||
}); | ||
TreeProxy *treewrapperStaged = new TreeProxy(true, this); | ||
treewrapperStaged->setSourceModel(mDiffTreeModel); | ||
stagedFiles->setModel(treewrapperStaged); | ||
stagedFiles->setHeaderHidden(true); | ||
ViewDelegate *stagedDelegate = new ViewDelegate(); | ||
stagedDelegate->setDrawArrow(false); | ||
stagedFiles->setItemDelegateForColumn(0, stagedDelegate); | ||
|
||
stagedFiles->setModel(new TreeProxy(true, mDiffTreeModel, this)); | ||
|
||
QHBoxLayout *hBoxLayout = new QHBoxLayout(); | ||
QLabel *label = new QLabel(kStagedFiles); | ||
|
@@ -192,13 +187,7 @@ DoubleTreeWidget::DoubleTreeWidget(const git::Repository &repo, QWidget *parent) | |
showFileContextMenu(pos, repoView, unstagedFiles, false); | ||
}); | ||
|
||
TreeProxy *treewrapperUnstaged = new TreeProxy(false, this); | ||
treewrapperUnstaged->setSourceModel(mDiffTreeModel); | ||
unstagedFiles->setModel(treewrapperUnstaged); | ||
unstagedFiles->setHeaderHidden(true); | ||
ViewDelegate *unstagedDelegate = new ViewDelegate(); | ||
unstagedDelegate->setDrawArrow(false); | ||
unstagedFiles->setItemDelegateForColumn(0, unstagedDelegate); | ||
Comment on lines
-195
to
-201
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fine |
||
unstagedFiles->setModel(new TreeProxy(false, mDiffTreeModel, this)); | ||
|
||
hBoxLayout = new QHBoxLayout(); | ||
mUnstagedCommitedFiles = new QLabel(kUnstagedFiles); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,8 +23,10 @@ const QString kLinkFmt = "<a href='%1'>%2</a>"; | |
|
||
} // namespace | ||
|
||
TreeProxy::TreeProxy(bool staged, QObject *parent) | ||
: QSortFilterProxyModel(parent), mStaged(staged) {} | ||
Comment on lines
-26
to
-27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fine |
||
TreeProxy::TreeProxy(bool staged, QAbstractItemModel *model, QObject *parent) | ||
: mStaged(staged), QSortFilterProxyModel(parent) { | ||
setSourceModel(model); | ||
} | ||
|
||
TreeProxy::~TreeProxy() {} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,9 @@ | |
#include "RepoView.h" | ||
#include <QMessageBox> | ||
#include <QPushButton> | ||
#include "conf/Settings.h" | ||
#include <QAbstractItemModel> | ||
#include <memory> | ||
|
||
#ifdef Q_OS_WIN | ||
#define ICON_SIZE 48 | ||
|
@@ -41,8 +44,29 @@ const QString kLabelFmt = "<p style='color: gray; font-weight: bold'>%1</p>"; | |
} // namespace | ||
|
||
TreeView::TreeView(QWidget *parent, const QString &name) | ||
: QTreeView(parent), mSharedDelegate(new ViewDelegate(this)), mName(name) { | ||
: QTreeView(parent), mDelegateCol(0), | ||
mFileListDelegatePtr(std::make_unique<ViewDelegate>(this, true)), | ||
mFileTreeDelegatePtr(std::make_unique<ViewDelegate>(this)), mName(name) { | ||
setObjectName(name); | ||
connect(RepoView::parentView(this)->repo().notifier(), | ||
&git::RepositoryNotifier::referenceUpdated, this, | ||
&TreeView::updateView); | ||
Comment on lines
+51
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you need this explicitly? An update comes from the DoubleTreewidget |
||
} | ||
|
||
void TreeView::updateView() { | ||
QAbstractItemModel *itemModel = model(); | ||
if (!itemModel) | ||
return; | ||
|
||
// Remove any previous delegate on the current column, get the new current | ||
// column, and set the delegate on that. | ||
setItemDelegateForColumn(mDelegateCol, nullptr); | ||
mDelegateCol = itemModel->columnCount() - 1; | ||
setItemDelegateForColumn(mDelegateCol, mDelegateCol | ||
? mFileListDelegatePtr.get() | ||
: mFileTreeDelegatePtr.get()); | ||
|
||
setHeaderHidden(mDelegateCol ? false : true); | ||
} | ||
|
||
void TreeView::setModel(QAbstractItemModel *model) { | ||
|
@@ -57,6 +81,10 @@ void TreeView::setModel(QAbstractItemModel *model) { | |
connect(model, &QAbstractItemModel::rowsInserted, this, | ||
QOverload<const QModelIndex &, int, int>::of( | ||
&TreeView::updateCollapseCount)); | ||
|
||
// Allow column sorting and set the default column and sort order. | ||
setSortingEnabled(true); | ||
sortByColumn(0, Qt::AscendingOrder); | ||
} | ||
|
||
void TreeView::discard(const QModelIndex &index, const bool force) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,37 +10,6 @@ void ViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, | |
QStyleOptionViewItem opt = option; | ||
drawBackground(painter, opt, index); | ||
|
||
// Draw >. | ||
if (mDrawArrow && index.model()->hasChildren(index)) { | ||
painter->save(); | ||
painter->setRenderHint(QPainter::Antialiasing, true); | ||
|
||
QColor color = opt.palette.color(QPalette::Active, QPalette::BrightText); | ||
if (opt.state & QStyle::State_Selected) | ||
color = | ||
!opt.showDecorationSelected | ||
? opt.palette.color(QPalette::Active, QPalette::WindowText) | ||
: opt.palette.color(QPalette::Active, QPalette::HighlightedText); | ||
|
||
painter->setPen(color); | ||
painter->setBrush(color); | ||
|
||
int x = opt.rect.x() + opt.rect.width() - 3; | ||
int y = opt.rect.y() + (opt.rect.height() / 2); | ||
|
||
QPainterPath path; | ||
path.moveTo(x, y); | ||
path.lineTo(x - 5, y - 3); | ||
path.lineTo(x - 5, y + 3); | ||
path.closeSubpath(); | ||
painter->drawPath(path); | ||
|
||
painter->restore(); | ||
|
||
// Adjust rect to exclude the arrow. | ||
opt.rect.adjust(0, 0, -11, 0); | ||
} | ||
|
||
Comment on lines
-13
to
-43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fine, can be removed because it will be set always to false in the DoubleTreeWidget |
||
// Draw badges. | ||
QString status = index.data(TreeModel::StatusRole).toString(); | ||
if (!status.isEmpty()) { | ||
|
@@ -49,19 +18,30 @@ void ViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, | |
int width = size.width(); | ||
int height = size.height(); | ||
|
||
auto startIter = status.cbegin(), endIter = status.cend(); | ||
int leftAdjust = 0, rightAdjust = -3, leftWidth = 0, rightWidth = -width; | ||
if (mMultiColumn) { | ||
Murmele marked this conversation as resolved.
Show resolved
Hide resolved
|
||
leftAdjust = 3; | ||
rightAdjust = 0; | ||
leftWidth = width; | ||
rightWidth = 0; | ||
std::reverse(status.begin(), status.end()); | ||
} | ||
|
||
// Add extra space. | ||
opt.rect.adjust(0, 0, -3, 0); | ||
opt.rect.adjust(leftAdjust, 0, rightAdjust, 0); | ||
|
||
for (int i = 0; i < status.count(); ++i) { | ||
int x = opt.rect.x() + opt.rect.width(); | ||
int y = opt.rect.y() + (opt.rect.height() / 2); | ||
QRect rect(x - width, y - (height / 2), width, height); | ||
QRect rect(mMultiColumn ? opt.rect.x() : x - width, y - (height / 2), | ||
width, height); | ||
Badge::paint(painter, | ||
{Badge::Label(Badge::Label::Type::Status, status.at(i))}, | ||
rect, &opt); | ||
|
||
// Adjust rect. | ||
opt.rect.adjust(0, 0, -width - 3, 0); | ||
opt.rect.adjust(leftWidth + leftAdjust, 0, rightWidth + rightAdjust, 0); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fine