forked from qt-creator/qt-creator
ClangTools: Adapt button state to checked fixits
"Apply Fixits" is disabled by default and enabled as soon as some fixits are checked by the user. Change-Id: I7e1345512b206f52d1e8628705c81c6b34dfb9ba Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -161,6 +161,10 @@ ClangTidyClazyTool::ClangTidyClazyTool()
|
|||||||
// Apply fixits button
|
// Apply fixits button
|
||||||
m_applyFixitsButton = new QToolButton;
|
m_applyFixitsButton = new QToolButton;
|
||||||
m_applyFixitsButton->setText(tr("Apply Fixits"));
|
m_applyFixitsButton->setText(tr("Apply Fixits"));
|
||||||
|
m_applyFixitsButton->setEnabled(false);
|
||||||
|
connect(m_diagnosticModel,
|
||||||
|
&ClangToolsDiagnosticModel::fixItsToApplyCountChanged,
|
||||||
|
[this](int c) { m_applyFixitsButton->setEnabled(c); });
|
||||||
connect(m_applyFixitsButton, &QToolButton::clicked, [this]() {
|
connect(m_applyFixitsButton, &QToolButton::clicked, [this]() {
|
||||||
QVector<Diagnostic> diagnosticsWithFixits;
|
QVector<Diagnostic> diagnosticsWithFixits;
|
||||||
|
|
||||||
|
|||||||
@@ -61,8 +61,13 @@ ClangToolsDiagnosticModel::ClangToolsDiagnosticModel(QObject *parent)
|
|||||||
|
|
||||||
void ClangToolsDiagnosticModel::addDiagnostics(const QList<Diagnostic> &diagnostics)
|
void ClangToolsDiagnosticModel::addDiagnostics(const QList<Diagnostic> &diagnostics)
|
||||||
{
|
{
|
||||||
foreach (const Diagnostic &d, diagnostics)
|
const auto onFixItChanged = [this](bool checked){
|
||||||
rootItem()->appendChild(new DiagnosticItem(d));
|
m_fixItsToApplyCount += checked ? +1 : -1;
|
||||||
|
emit fixItsToApplyCountChanged(m_fixItsToApplyCount);
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const Diagnostic &d : diagnostics)
|
||||||
|
rootItem()->appendChild(new DiagnosticItem(d, onFixItChanged));
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<Diagnostic> ClangToolsDiagnosticModel::diagnostics() const
|
QList<Diagnostic> ClangToolsDiagnosticModel::diagnostics() const
|
||||||
@@ -199,7 +204,9 @@ static QString fullText(const Diagnostic &diagnostic)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DiagnosticItem::DiagnosticItem(const Diagnostic &diag) : m_diagnostic(diag)
|
DiagnosticItem::DiagnosticItem(const Diagnostic &diag, const OnCheckedFixit &onCheckedFixit)
|
||||||
|
: m_diagnostic(diag)
|
||||||
|
, m_onCheckedFixit(onCheckedFixit)
|
||||||
{
|
{
|
||||||
// Don't show explaining steps if they add no information.
|
// Don't show explaining steps if they add no information.
|
||||||
if (diag.explainingSteps.count() == 1) {
|
if (diag.explainingSteps.count() == 1) {
|
||||||
@@ -277,6 +284,8 @@ bool DiagnosticItem::setData(int column, const QVariant &data, int role)
|
|||||||
if (column == DiagnosticView::FixItColumn && role == Qt::CheckStateRole) {
|
if (column == DiagnosticView::FixItColumn && role == Qt::CheckStateRole) {
|
||||||
m_applyFixits = data.value<Qt::CheckState>() == Qt::Checked ? true : false;
|
m_applyFixits = data.value<Qt::CheckState>() == Qt::Checked ? true : false;
|
||||||
update();
|
update();
|
||||||
|
if (m_onCheckedFixit)
|
||||||
|
m_onCheckedFixit(m_applyFixits);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,8 @@
|
|||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
namespace ProjectExplorer { class Project; }
|
namespace ProjectExplorer { class Project; }
|
||||||
|
|
||||||
namespace ClangTools {
|
namespace ClangTools {
|
||||||
@@ -43,7 +45,8 @@ namespace Internal {
|
|||||||
class DiagnosticItem : public Utils::TreeItem
|
class DiagnosticItem : public Utils::TreeItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DiagnosticItem(const Diagnostic &diag);
|
using OnCheckedFixit = std::function<void(bool)>;
|
||||||
|
DiagnosticItem(const Diagnostic &diag, const OnCheckedFixit &onCheckedFixit);
|
||||||
|
|
||||||
Diagnostic diagnostic() const { return m_diagnostic; }
|
Diagnostic diagnostic() const { return m_diagnostic; }
|
||||||
bool applyFixits() const { return m_applyFixits; }
|
bool applyFixits() const { return m_applyFixits; }
|
||||||
@@ -56,6 +59,7 @@ private:
|
|||||||
private:
|
private:
|
||||||
const Diagnostic m_diagnostic;
|
const Diagnostic m_diagnostic;
|
||||||
bool m_applyFixits = false;
|
bool m_applyFixits = false;
|
||||||
|
OnCheckedFixit m_onCheckedFixit;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ClangToolsDiagnosticModel : public Utils::TreeModel<>
|
class ClangToolsDiagnosticModel : public Utils::TreeModel<>
|
||||||
@@ -71,6 +75,12 @@ public:
|
|||||||
enum ItemRole {
|
enum ItemRole {
|
||||||
DiagnosticRole = Debugger::DetailedErrorView::FullTextRole + 1
|
DiagnosticRole = Debugger::DetailedErrorView::FullTextRole + 1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void fixItsToApplyCountChanged(int count);
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_fixItsToApplyCount = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DiagnosticFilterModel : public QSortFilterProxyModel
|
class DiagnosticFilterModel : public QSortFilterProxyModel
|
||||||
|
|||||||
Reference in New Issue
Block a user