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 SOURCES
clangfileinfo.h clangfileinfo.h
clangfixitsrefactoringchanges.cpp clangfixitsrefactoringchanges.h clangfixitsrefactoringchanges.cpp clangfixitsrefactoringchanges.h
clangselectablefilesdialog.cpp clangselectablefilesdialog.h clangselectablefilesdialog.ui clangselectablefilesdialog.cpp clangselectablefilesdialog.h
clangtidyclazyrunner.cpp clangtidyclazyrunner.h clangtidyclazyrunner.cpp clangtidyclazyrunner.h
clangtool.cpp clangtool.h clangtool.cpp clangtool.h
clangtoolruncontrol.cpp clangtoolruncontrol.h clangtoolruncontrol.cpp clangtoolruncontrol.h

View File

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

View File

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