forked from qt-creator/qt-creator
Clang: Add checkbox for fix-its column header
Make possible to select or deselect all fix-its. Change-Id: I2ff88afb0c451092752ee2cd7c9f083e24033500 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -251,7 +251,10 @@ ClangTidyClazyTool::ClangTidyClazyTool()
|
||||
m_applyFixitsButton->setEnabled(false);
|
||||
connect(m_diagnosticModel,
|
||||
&ClangToolsDiagnosticModel::fixItsToApplyCountChanged,
|
||||
[this](int c) { m_applyFixitsButton->setEnabled(c); });
|
||||
[this](int c) {
|
||||
m_applyFixitsButton->setEnabled(c);
|
||||
static_cast<DiagnosticView *>(m_diagnosticView)->setSelectedFixItsCount(c);
|
||||
});
|
||||
connect(m_applyFixitsButton, &QToolButton::clicked, [this]() {
|
||||
QVector<DiagnosticItem *> diagnosticItems;
|
||||
m_diagnosticModel->rootItem()->forChildrenAtLevel(1, [&](TreeItem *item){
|
||||
|
@@ -328,6 +328,9 @@ QVariant DiagnosticItem::data(int column, int role) const
|
||||
bool DiagnosticItem::setData(int column, const QVariant &data, int role)
|
||||
{
|
||||
if (column == DiagnosticView::FixItColumn && role == Qt::CheckStateRole) {
|
||||
if (m_fixitStatus != FixitStatus::Scheduled && m_fixitStatus != FixitStatus::NotScheduled)
|
||||
return false;
|
||||
|
||||
const FixitStatus newStatus = data.value<Qt::CheckState>() == Qt::Checked
|
||||
? FixitStatus::Scheduled
|
||||
: FixitStatus::NotScheduled;
|
||||
|
@@ -35,12 +35,60 @@
|
||||
#include <QAction>
|
||||
#include <QDebug>
|
||||
#include <QHeaderView>
|
||||
#include <QPainter>
|
||||
|
||||
using namespace Debugger;
|
||||
|
||||
namespace ClangTools {
|
||||
namespace Internal {
|
||||
|
||||
class ClickableFixItHeader : public QHeaderView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ClickableFixItHeader(Qt::Orientation orientation, QWidget *parent = 0)
|
||||
: QHeaderView(orientation, parent)
|
||||
{
|
||||
}
|
||||
|
||||
void setState(QFlags<QStyle::StateFlag> newState)
|
||||
{
|
||||
state = newState;
|
||||
}
|
||||
|
||||
protected:
|
||||
void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const
|
||||
{
|
||||
painter->save();
|
||||
QHeaderView::paintSection(painter, rect, logicalIndex);
|
||||
painter->restore();
|
||||
if (logicalIndex == DiagnosticView::FixItColumn) {
|
||||
QStyleOptionButton option;
|
||||
const int side = sizeHint().height();
|
||||
option.rect = QRect(rect.left() + 1, 1, side - 3, side - 3);
|
||||
option.state = state;
|
||||
style()->drawPrimitive(QStyle::PE_IndicatorCheckBox, &option, painter);
|
||||
}
|
||||
}
|
||||
|
||||
void mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->localPos().x() > sectionPosition(DiagnosticView::FixItColumn)) {
|
||||
state = (state != QStyle::State_On) ? QStyle::State_On : QStyle::State_Off;
|
||||
viewport()->update();
|
||||
emit fixItColumnClicked(state == QStyle::State_On);
|
||||
}
|
||||
QHeaderView::mousePressEvent(event);
|
||||
}
|
||||
|
||||
signals:
|
||||
void fixItColumnClicked(bool checked);
|
||||
|
||||
private:
|
||||
QFlags<QStyle::StateFlag> state = QStyle::State_Off;
|
||||
};
|
||||
|
||||
DiagnosticView::DiagnosticView(QWidget *parent)
|
||||
: Debugger::DetailedErrorView(parent)
|
||||
{
|
||||
@@ -104,12 +152,36 @@ bool DiagnosticView::eventFilter(QObject *watched, QEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
void DiagnosticView::setSelectedFixItsCount(int fixItsCount)
|
||||
{
|
||||
if (m_ignoreSetSelectedFixItsCount)
|
||||
return;
|
||||
auto *clickableFixItHeader = static_cast<ClickableFixItHeader *>(header());
|
||||
clickableFixItHeader->setState(fixItsCount
|
||||
? (QStyle::State_NoChange | QStyle::State_On | QStyle::State_Off)
|
||||
: QStyle::State_Off);
|
||||
clickableFixItHeader->viewport()->update();
|
||||
}
|
||||
|
||||
void DiagnosticView::setModel(QAbstractItemModel *model)
|
||||
{
|
||||
Debugger::DetailedErrorView::setModel(model);
|
||||
auto *clickableFixItHeader = new ClickableFixItHeader(Qt::Horizontal, this);
|
||||
connect(clickableFixItHeader, &ClickableFixItHeader::fixItColumnClicked,
|
||||
this, [=](bool checked) {
|
||||
m_ignoreSetSelectedFixItsCount = true;
|
||||
for (int row = 0; row < model->rowCount(); ++row) {
|
||||
QModelIndex index = model->index(row, FixItColumn, QModelIndex());
|
||||
model->setData(index, checked ? Qt::Checked : Qt::Unchecked, Qt::CheckStateRole);
|
||||
}
|
||||
m_ignoreSetSelectedFixItsCount = false;
|
||||
});
|
||||
setHeader(clickableFixItHeader);
|
||||
header()->setStretchLastSection(false);
|
||||
header()->setSectionResizeMode(0, QHeaderView::Stretch);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace ClangTools
|
||||
|
||||
#include "clangtoolsdiagnosticview.moc"
|
||||
|
@@ -41,6 +41,8 @@ public:
|
||||
FixItColumn = LocationColumn + 1,
|
||||
};
|
||||
|
||||
void setSelectedFixItsCount(int fixItsCount);
|
||||
|
||||
private:
|
||||
void suppressCurrentDiagnostic();
|
||||
|
||||
@@ -49,6 +51,7 @@ private:
|
||||
void setModel(QAbstractItemModel *model) override;
|
||||
|
||||
QAction *m_suppressAction;
|
||||
bool m_ignoreSetSelectedFixItsCount = false;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
Reference in New Issue
Block a user