forked from qt-creator/qt-creator
ClangTools: Make diagnostic view sortable
Fixes: QTCREATORBUG-20660 Change-Id: I57ed5c4071d7db8143e9e1e31d8b86a4d59d33ff Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -210,10 +210,13 @@ ClangTidyClazyTool::ClangTidyClazyTool()
|
|||||||
|
|
||||||
m_diagnosticFilterModel = new DiagnosticFilterModel(this);
|
m_diagnosticFilterModel = new DiagnosticFilterModel(this);
|
||||||
m_diagnosticFilterModel->setSourceModel(m_diagnosticModel);
|
m_diagnosticFilterModel->setSourceModel(m_diagnosticModel);
|
||||||
|
m_diagnosticFilterModel->setDynamicSortFilter(true);
|
||||||
|
|
||||||
m_diagnosticView = new DiagnosticView;
|
m_diagnosticView = new DiagnosticView;
|
||||||
initDiagnosticView();
|
initDiagnosticView();
|
||||||
m_diagnosticView->setModel(m_diagnosticFilterModel);
|
m_diagnosticView->setModel(m_diagnosticFilterModel);
|
||||||
|
m_diagnosticView->setSortingEnabled(true);
|
||||||
|
m_diagnosticView->sortByColumn(Debugger::DetailedErrorView::LocationColumn, Qt::AscendingOrder);
|
||||||
m_diagnosticView->setObjectName(QLatin1String("ClangTidyClazyIssuesView"));
|
m_diagnosticView->setObjectName(QLatin1String("ClangTidyClazyIssuesView"));
|
||||||
m_diagnosticView->setWindowTitle(tr("Clang-Tidy and Clazy Issues"));
|
m_diagnosticView->setWindowTitle(tr("Clang-Tidy and Clazy Issues"));
|
||||||
|
|
||||||
|
@@ -70,8 +70,9 @@ protected:
|
|||||||
option.rect = QRect(rect.left() + 1, 1, side - 3, side - 3);
|
option.rect = QRect(rect.left() + 1, 1, side - 3, side - 3);
|
||||||
option.state = state;
|
option.state = state;
|
||||||
painter->save();
|
painter->save();
|
||||||
painter->translate(QPoint(side - 2, 0));
|
const int shift = side - 2;
|
||||||
QHeaderView::paintSection(painter, rect, logicalIndex);
|
painter->translate(QPoint(shift, 0));
|
||||||
|
QHeaderView::paintSection(painter, rect.adjusted(0, 0, -shift, 0), logicalIndex);
|
||||||
painter->restore();
|
painter->restore();
|
||||||
style()->drawPrimitive(QStyle::PE_IndicatorCheckBox, &option, painter);
|
style()->drawPrimitive(QStyle::PE_IndicatorCheckBox, &option, painter);
|
||||||
}
|
}
|
||||||
@@ -79,10 +80,15 @@ protected:
|
|||||||
|
|
||||||
void mouseReleaseEvent(QMouseEvent *event) override
|
void mouseReleaseEvent(QMouseEvent *event) override
|
||||||
{
|
{
|
||||||
if (event->localPos().x() > sectionPosition(DiagnosticView::FixItColumn)) {
|
const int x = event->localPos().x();
|
||||||
|
const int fixItColumnX = sectionPosition(DiagnosticView::FixItColumn);
|
||||||
|
const bool isWithinFixitCheckBox = x > fixItColumnX
|
||||||
|
&& x < fixItColumnX + sizeHint().height() - 3;
|
||||||
|
if (isWithinFixitCheckBox) {
|
||||||
state = (state != QStyle::State_On) ? QStyle::State_On : QStyle::State_Off;
|
state = (state != QStyle::State_On) ? QStyle::State_On : QStyle::State_Off;
|
||||||
viewport()->update();
|
viewport()->update();
|
||||||
emit fixItColumnClicked(state == QStyle::State_On);
|
emit fixItColumnClicked(state == QStyle::State_On);
|
||||||
|
return; // Avoid changing sort order
|
||||||
}
|
}
|
||||||
QHeaderView::mouseReleaseEvent(event);
|
QHeaderView::mouseReleaseEvent(event);
|
||||||
}
|
}
|
||||||
@@ -168,16 +174,19 @@ void DiagnosticView::setSelectedFixItsCount(int fixItsCount)
|
|||||||
clickableFixItHeader->viewport()->update();
|
clickableFixItHeader->viewport()->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiagnosticView::setModel(QAbstractItemModel *model)
|
void DiagnosticView::setModel(QAbstractItemModel *theProxyModel)
|
||||||
{
|
{
|
||||||
Debugger::DetailedErrorView::setModel(model);
|
const auto proxyModel = static_cast<QSortFilterProxyModel *>(theProxyModel);
|
||||||
|
QAbstractItemModel *sourceModel = proxyModel->sourceModel();
|
||||||
|
|
||||||
|
Debugger::DetailedErrorView::setModel(proxyModel);
|
||||||
auto *clickableFixItHeader = new ClickableFixItHeader(Qt::Horizontal, this);
|
auto *clickableFixItHeader = new ClickableFixItHeader(Qt::Horizontal, this);
|
||||||
connect(clickableFixItHeader, &ClickableFixItHeader::fixItColumnClicked,
|
connect(clickableFixItHeader, &ClickableFixItHeader::fixItColumnClicked,
|
||||||
this, [=](bool checked) {
|
this, [=](bool checked) {
|
||||||
m_ignoreSetSelectedFixItsCount = true;
|
m_ignoreSetSelectedFixItsCount = true;
|
||||||
for (int row = 0; row < model->rowCount(); ++row) {
|
for (int row = 0; row < sourceModel->rowCount(); ++row) {
|
||||||
QModelIndex index = model->index(row, FixItColumn, QModelIndex());
|
QModelIndex index = sourceModel->index(row, FixItColumn, QModelIndex());
|
||||||
model->setData(index, checked ? Qt::Checked : Qt::Unchecked, Qt::CheckStateRole);
|
sourceModel->setData(index, checked ? Qt::Checked : Qt::Unchecked, Qt::CheckStateRole);
|
||||||
}
|
}
|
||||||
m_ignoreSetSelectedFixItsCount = false;
|
m_ignoreSetSelectedFixItsCount = false;
|
||||||
});
|
});
|
||||||
@@ -189,7 +198,7 @@ void DiagnosticView::setModel(QAbstractItemModel *model)
|
|||||||
|
|
||||||
const int fixitColumnWidth = clickableFixItHeader->sectionSizeHint(DiagnosticView::FixItColumn);
|
const int fixitColumnWidth = clickableFixItHeader->sectionSizeHint(DiagnosticView::FixItColumn);
|
||||||
const int checkboxWidth = clickableFixItHeader->height();
|
const int checkboxWidth = clickableFixItHeader->height();
|
||||||
clickableFixItHeader->setMinimumSectionSize(fixitColumnWidth + checkboxWidth);
|
clickableFixItHeader->setMinimumSectionSize(fixitColumnWidth + 1.2 * checkboxWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -48,7 +48,7 @@ private:
|
|||||||
|
|
||||||
QList<QAction *> customActions() const override;
|
QList<QAction *> customActions() const override;
|
||||||
bool eventFilter(QObject *watched, QEvent *event) override;
|
bool eventFilter(QObject *watched, QEvent *event) override;
|
||||||
void setModel(QAbstractItemModel *model) override;
|
void setModel(QAbstractItemModel *theProxyModel) override;
|
||||||
|
|
||||||
QAction *m_suppressAction;
|
QAction *m_suppressAction;
|
||||||
bool m_ignoreSetSelectedFixItsCount = false;
|
bool m_ignoreSetSelectedFixItsCount = false;
|
||||||
|
Reference in New Issue
Block a user