ClangTools: inline clangselectablefilesdialog.ui

Just a Vbox.

Change-Id: I27618d7ba9a22011dff8c3486a944fbbdaf90a1c
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2022-07-12 17:05:07 +02:00
parent 802de0eb5e
commit 6f6d4015ea
5 changed files with 41 additions and 67 deletions

View File

@@ -16,7 +16,7 @@ add_qtc_plugin(ClangTools
SOURCES
clangfileinfo.h
clangfixitsrefactoringchanges.cpp clangfixitsrefactoringchanges.h
clangselectablefilesdialog.cpp clangselectablefilesdialog.h clangselectablefilesdialog.ui
clangselectablefilesdialog.cpp clangselectablefilesdialog.h
clangtidyclazyrunner.cpp clangtidyclazyrunner.h
clangtool.cpp clangtool.h
clangtoolruncontrol.cpp clangtoolruncontrol.h

View File

@@ -25,8 +25,6 @@
#include "clangselectablefilesdialog.h"
#include "ui_clangselectablefilesdialog.h"
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/find/itemviewfind.h>
#include <cppeditor/projectinfo.h>
@@ -34,8 +32,10 @@
#include <texteditor/textdocument.h>
#include <utils/algorithm.h>
#include <utils/layoutbuilder.h>
#include <utils/qtcassert.h>
#include <QComboBox>
#include <QDialogButtonBox>
#include <QPushButton>
#include <QSortFilterProxyModel>
@@ -268,56 +268,68 @@ SelectableFilesDialog::SelectableFilesDialog(Project *project,
const FileInfoProviders &fileInfoProviders,
int initialProviderIndex)
: QDialog(nullptr)
, m_ui(new Ui::SelectableFilesDialog)
, m_filesModel(new SelectableFilesModel)
, m_fileInfoProviders(fileInfoProviders)
, m_project(project)
, m_analyzeButton(new QPushButton(tr("Analyze"), this))
{
m_ui->setupUi(this);
setWindowTitle(tr("Files to Analyze"));
resize(700, 600);
m_fileFilterComboBox = new QComboBox(this);
m_fileFilterComboBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
// Files View
// Make find actions available in this dialog, e.g. Strg+F for the view.
addAction(Core::ActionManager::command(Core::Constants::FIND_IN_DOCUMENT)->action());
addAction(Core::ActionManager::command(Core::Constants::FIND_NEXT)->action());
addAction(Core::ActionManager::command(Core::Constants::FIND_PREVIOUS)->action());
m_fileView = new QTreeView;
m_fileView->setHeaderHidden(true);
m_fileView->setModel(m_filesModel.get());
m_ui->verticalLayout->addWidget(
Core::ItemViewFind::createSearchableWrapper(m_fileView, Core::ItemViewFind::LightColored));
// Filter combo box
for (const FileInfoProvider &provider : m_fileInfoProviders) {
m_ui->fileFilterComboBox->addItem(provider.displayName);
m_fileFilterComboBox->addItem(provider.displayName);
// Disable item if it has no file infos
auto *model = qobject_cast<QStandardItemModel *>(m_ui->fileFilterComboBox->model());
QStandardItem *item = model->item(m_ui->fileFilterComboBox->count() - 1);
auto *model = qobject_cast<QStandardItemModel *>(m_fileFilterComboBox->model());
QStandardItem *item = model->item(m_fileFilterComboBox->count() - 1);
item->setFlags(provider.fileInfos.empty() ? item->flags() & ~Qt::ItemIsEnabled
: item->flags() | Qt::ItemIsEnabled);
}
int providerIndex = initialProviderIndex;
if (m_fileInfoProviders[providerIndex].fileInfos.empty())
providerIndex = 0;
m_ui->fileFilterComboBox->setCurrentIndex(providerIndex);
m_fileFilterComboBox->setCurrentIndex(providerIndex);
onFileFilterChanged(providerIndex);
connect(m_ui->fileFilterComboBox,
QOverload<int>::of(&QComboBox::currentIndexChanged),
this,
&SelectableFilesDialog::onFileFilterChanged);
connect(m_fileFilterComboBox, &QComboBox::currentIndexChanged,
this, &SelectableFilesDialog::onFileFilterChanged);
auto analyzeButton = new QPushButton(tr("Analyze"), this);
analyzeButton->setEnabled(m_filesModel->hasCheckedFiles());
// Buttons
m_buttons = new QDialogButtonBox;
m_buttons->setStandardButtons(QDialogButtonBox::Cancel);
m_buttons->addButton(m_analyzeButton, QDialogButtonBox::AcceptRole);\
connect(m_buttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(m_buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
m_analyzeButton->setEnabled(m_filesModel->hasCheckedFiles());
connect(m_filesModel.get(), &QAbstractItemModel::dataChanged, [this]() {
m_analyzeButton->setEnabled(m_filesModel->hasCheckedFiles());
auto buttons = new QDialogButtonBox;
buttons->setStandardButtons(QDialogButtonBox::Cancel);
buttons->addButton(analyzeButton, QDialogButtonBox::AcceptRole);
connect(m_filesModel.get(), &QAbstractItemModel::dataChanged, [this, analyzeButton] {
analyzeButton->setEnabled(m_filesModel->hasCheckedFiles());
});
m_ui->verticalLayout->addWidget(m_buttons);
connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
using namespace Layouting;
Column {
m_fileFilterComboBox,
Core::ItemViewFind::createSearchableWrapper(m_fileView, Core::ItemViewFind::LightColored),
buttons
}.attachTo(this);
}
SelectableFilesDialog::~SelectableFilesDialog() = default;
@@ -329,7 +341,7 @@ FileInfos SelectableFilesDialog::fileInfos() const
int SelectableFilesDialog::currentProviderIndex() const
{
return m_ui->fileFilterComboBox->currentIndex();
return m_fileFilterComboBox->currentIndex();
}
void SelectableFilesDialog::onFileFilterChanged(int index)
@@ -360,7 +372,7 @@ void SelectableFilesDialog::accept()
{
FileInfoSelection selection;
m_filesModel->minimalSelection(selection);
FileInfoProvider &provider = m_fileInfoProviders[m_ui->fileFilterComboBox->currentIndex()];
FileInfoProvider &provider = m_fileInfoProviders[m_fileFilterComboBox->currentIndex()];
provider.onSelectionAccepted(selection);
QDialog::accept();

View File

@@ -30,16 +30,12 @@
#include <QDialog>
QT_BEGIN_NAMESPACE
class QDialogButtonBox;
class QPushButton;
class QComboBox;
QT_END_NAMESPACE
namespace CppEditor { class ProjectInfo; }
namespace ClangTools {
namespace Internal {
namespace Ui { class SelectableFilesDialog; }
class SelectableFilesModel;
class SelectableFilesDialog : public QDialog
@@ -59,16 +55,14 @@ private:
void onFileFilterChanged(int index);
void accept() override;
std::unique_ptr<Ui::SelectableFilesDialog> m_ui;
QTreeView *m_fileView = nullptr;
QDialogButtonBox *m_buttons = nullptr;
std::unique_ptr<SelectableFilesModel> m_filesModel;
FileInfoProviders m_fileInfoProviders;
int m_previousProviderIndex = -1;
ProjectExplorer::Project *m_project;
QPushButton *m_analyzeButton = nullptr;
QComboBox *m_fileFilterComboBox;
};
} // namespace Internal

View File

@@ -1,31 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ClangTools::Internal::SelectableFilesDialog</class>
<widget class="QDialog" name="ClangTools::Internal::SelectableFilesDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>700</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>Files to Analyze</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QComboBox" name="fileFilterComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -28,7 +28,6 @@ QtcPlugin {
"clangfixitsrefactoringchanges.h",
"clangselectablefilesdialog.cpp",
"clangselectablefilesdialog.h",
"clangselectablefilesdialog.ui",
"clangtidyclazyrunner.cpp",
"clangtidyclazyrunner.h",
"clangtool.cpp",