ClangTools: Inline filterdialog.ui

Change-Id: I6304ac50b34e43ab4b5c26b7dc2b7ab7f77618f7
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
hjk
2022-09-26 15:40:12 +02:00
parent c06fab97f1
commit b72ae58629
5 changed files with 59 additions and 138 deletions

View File

@@ -39,7 +39,7 @@ add_qtc_plugin(ClangTools
documentclangtoolrunner.cpp documentclangtoolrunner.h
documentquickfixfactory.cpp documentquickfixfactory.h
executableinfo.cpp executableinfo.h
filterdialog.cpp filterdialog.h filterdialog.ui
filterdialog.cpp filterdialog.h
runsettingswidget.cpp runsettingswidget.h runsettingswidget.ui
settingswidget.cpp settingswidget.h settingswidget.ui
tidychecks.ui

View File

@@ -69,7 +69,6 @@ QtcPlugin {
"executableinfo.h",
"filterdialog.cpp",
"filterdialog.h",
"filterdialog.ui",
"runsettingswidget.cpp",
"runsettingswidget.h",
"runsettingswidget.ui",

View File

@@ -2,15 +2,20 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
#include "filterdialog.h"
#include "ui_filterdialog.h"
#include <utils/algorithm.h>
#include <utils/layoutbuilder.h>
#include <utils/treemodel.h>
#include <QApplication>
#include <QDialog>
#include <QDialogButtonBox>
#include <QHeaderView>
#include <QItemSelectionModel>
#include <QPushButton>
#include <QTreeView>
namespace ClangTools {
namespace Internal {
namespace ClangTools::Internal {
enum Columns { CheckName, Count };
@@ -59,61 +64,76 @@ public:
FilterDialog::FilterDialog(const Checks &checks, QWidget *parent)
: QDialog(parent)
, m_ui(new Ui::FilterDialog)
{
m_ui->setupUi(this);
resize(400, 400);
setWindowTitle(tr("Filter Diagnostics"));
auto selectAll = new QPushButton(tr("Select All"));
auto selectWithFixits = new QPushButton(tr("Select All with Fixits"));
auto selectNone = new QPushButton(tr("Clear Selection"));
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
m_model = new FilterChecksModel(checks);
// View
m_ui->view->setModel(m_model);
m_ui->view->header()->setStretchLastSection(false);
m_ui->view->header()->setSectionResizeMode(Columns::CheckName, QHeaderView::Stretch);
m_ui->view->header()->setSectionResizeMode(Columns::Count, QHeaderView::ResizeToContents);
m_ui->view->setSelectionMode(QAbstractItemView::MultiSelection);
m_ui->view->setSelectionBehavior(QAbstractItemView::SelectRows);
m_ui->view->setIndentation(0);
connect(m_ui->view->selectionModel(), &QItemSelectionModel::selectionChanged, this, [&](){
const bool hasSelection = !m_ui->view->selectionModel()->selectedRows().isEmpty();
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(hasSelection);
m_view = new QTreeView(this);
m_view->setModel(m_model);
m_view->header()->setStretchLastSection(false);
m_view->header()->setSectionResizeMode(Columns::CheckName, QHeaderView::Stretch);
m_view->header()->setSectionResizeMode(Columns::Count, QHeaderView::ResizeToContents);
m_view->setSelectionMode(QAbstractItemView::MultiSelection);
m_view->setSelectionBehavior(QAbstractItemView::SelectRows);
m_view->setIndentation(0);
using namespace Utils::Layouting;
Column {
tr("Select the diagnostics to display."),
Row { selectAll, selectWithFixits, selectNone, st },
m_view,
buttonBox,
}.attachTo(this);
connect(m_view->selectionModel(), &QItemSelectionModel::selectionChanged, this, [&] {
const bool hasSelection = !m_view->selectionModel()->selectedRows().isEmpty();
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(hasSelection);
});
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
// Buttons
connect(m_ui->selectNone, &QPushButton::clicked, m_ui->view, &QTreeView::clearSelection);
connect(m_ui->selectAll, &QPushButton::clicked, m_ui->view, &QTreeView::selectAll);
connect(m_ui->selectWithFixits, &QPushButton::clicked, m_ui->view, [this] {
m_ui->view->clearSelection();
connect(selectNone, &QPushButton::clicked, m_view, &QTreeView::clearSelection);
connect(selectAll, &QPushButton::clicked, m_view, &QTreeView::selectAll);
connect(selectWithFixits, &QPushButton::clicked, m_view, [this] {
m_view->clearSelection();
m_model->forItemsAtLevel<1>([&](CheckItem *item) {
if (item->check.hasFixit)
m_ui->view->selectionModel()->select(item->index(), selectionFlags());
m_view->selectionModel()->select(item->index(), selectionFlags());
});
});
m_ui->selectWithFixits->setEnabled(
selectWithFixits->setEnabled(
Utils::anyOf(checks, [](const Check &c) { return c.hasFixit; }));
// Select checks that are not filtered out
m_model->forItemsAtLevel<1>([this](CheckItem *item) {
if (item->check.isShown)
m_ui->view->selectionModel()->select(item->index(), selectionFlags());
m_view->selectionModel()->select(item->index(), selectionFlags());
});
}
FilterDialog::~FilterDialog()
{
delete m_ui;
}
FilterDialog::~FilterDialog() = default;
QSet<QString> FilterDialog::selectedChecks() const
{
QSet<QString> checks;
m_model->forItemsAtLevel<1>([&](CheckItem *item) {
if (m_ui->view->selectionModel()->isSelected(item->index()))
if (m_view->selectionModel()->isSelected(item->index()))
checks << item->check.name;
});
return checks;
}
} // namespace Internal
} // namespace ClangTools
} // ClangTools::Internal
#include "filterdialog.moc"

View File

@@ -5,14 +5,16 @@
#include <QDialog>
namespace ClangTools {
namespace Internal {
QT_BEGIN_NAMESPACE
class QTreeView;
QT_END_NAMESPACE
namespace Ui { class FilterDialog; }
namespace ClangTools::Internal {
class FilterChecksModel;
class Check {
class Check
{
public:
QString name;
QString displayName;
@@ -33,9 +35,8 @@ public:
QSet<QString> selectedChecks() const;
private:
Ui::FilterDialog *m_ui;
FilterChecksModel *m_model;
QTreeView *m_view;
};
} // namespace Internal
} // namespace ClangTools
} // ClangTools::Internal

View File

@@ -1,99 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ClangTools::Internal::FilterDialog</class>
<widget class="QDialog" name="ClangTools::Internal::FilterDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>400</height>
</rect>
</property>
<property name="windowTitle">
<string>Filter Diagnostics</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Select the diagnostics to display.</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="selectAll">
<property name="text">
<string>Select All</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="selectWithFixits">
<property name="text">
<string>Select All with Fixits</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="selectNone">
<property name="text">
<string>Clear Selection</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTreeView" name="view"/>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ClangTools::Internal::FilterDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ClangTools::Internal::FilterDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>