CppEditor: Inline cpppreprocessordialog.ui

Change-Id: I2941e6fd3da93d1a71fb7d98e6d39634ae957d42
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
hjk
2022-09-30 10:27:20 +02:00
parent 5ff70b6f99
commit 57b32ed773
5 changed files with 41 additions and 103 deletions

View File

@@ -65,7 +65,7 @@ add_qtc_plugin(CppEditor
cppoutlinemodel.cpp cppoutlinemodel.h
cppparsecontext.cpp cppparsecontext.h
cpppointerdeclarationformatter.cpp cpppointerdeclarationformatter.h
cpppreprocessordialog.cpp cpppreprocessordialog.h cpppreprocessordialog.ui
cpppreprocessordialog.cpp cpppreprocessordialog.h
cppprojectfile.cpp cppprojectfile.h
cppprojectfilecategorizer.cpp cppprojectfilecategorizer.h
cppprojectinfogenerator.cpp cppprojectinfogenerator.h

View File

@@ -150,7 +150,6 @@ QtcPlugin {
"cppprojectpartchooser.h",
"cpppreprocessordialog.cpp",
"cpppreprocessordialog.h",
"cpppreprocessordialog.ui",
"cppprojectfile.cpp",
"cppprojectfile.h",
"cppprojectfilecategorizer.cpp",

View File

@@ -2,7 +2,6 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
#include "cpppreprocessordialog.h"
#include "ui_cpppreprocessordialog.h"
#include "cppeditorwidget.h"
#include "cppeditorconstants.h"
@@ -10,28 +9,47 @@
#include <projectexplorer/session.h>
using namespace CppEditor::Internal;
#include <texteditor/snippets/snippeteditor.h>
#include <utils/layoutbuilder.h>
#include <QDialogButtonBox>
using namespace Utils;
namespace CppEditor::Internal {
CppPreProcessorDialog::CppPreProcessorDialog(const QString &filePath, QWidget *parent)
: QDialog(parent)
, m_ui(new Ui::CppPreProcessorDialog())
, m_filePath(filePath)
{
m_ui->setupUi(this);
m_ui->editorLabel->setText(m_ui->editorLabel->text().arg(Utils::FilePath::fromString(m_filePath).fileName()));
m_ui->editWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
decorateCppEditor(m_ui->editWidget);
resize(400, 300);
setWindowTitle(tr("Additional C++ Preprocessor Directives"));
const QString key = Constants::EXTRA_PREPROCESSOR_DIRECTIVES + m_filePath;
const QString directives = ProjectExplorer::SessionManager::value(key).toString();
m_ui->editWidget->setPlainText(directives);
m_editWidget = new TextEditor::SnippetEditorWidget;
m_editWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
m_editWidget->setPlainText(directives);
decorateCppEditor(m_editWidget);
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
using namespace Layouting;
Column {
tr("Additional C++ Preprocessor Directives for %1:")
.arg(Utils::FilePath::fromString(m_filePath).fileName()),
m_editWidget,
buttonBox,
}.attachTo(this);
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
}
CppPreProcessorDialog::~CppPreProcessorDialog()
{
delete m_ui;
}
CppPreProcessorDialog::~CppPreProcessorDialog() = default;
int CppPreProcessorDialog::exec()
{
@@ -46,5 +64,7 @@ int CppPreProcessorDialog::exec()
QString CppPreProcessorDialog::extraPreprocessorDirectives() const
{
return m_ui->editWidget->toPlainText();
return m_editWidget->toPlainText();
}
} // CppEditor::Internal

View File

@@ -6,9 +6,9 @@
#include <QDialog>
#include <QString>
namespace CppEditor {
namespace Internal {
namespace Ui { class CppPreProcessorDialog; }
namespace TextEditor { class SnippetEditorWidget; }
namespace CppEditor::Internal {
class CppPreProcessorDialog : public QDialog
{
@@ -23,10 +23,10 @@ public:
QString extraPreprocessorDirectives() const;
private:
Ui::CppPreProcessorDialog *m_ui;
const QString m_filePath;
const QString m_projectPartId;
TextEditor::SnippetEditorWidget *m_editWidget;
};
} // namespace Internal
} // namespace CppEditor
} // CppEditor::Internal

View File

@@ -1,81 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CppEditor::Internal::CppPreProcessorDialog</class>
<widget class="QDialog" name="CppEditor::Internal::CppPreProcessorDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Additional C++ Preprocessor Directives</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="editorLabel">
<property name="text">
<string>Additional C++ Preprocessor Directives for %1:</string>
</property>
</widget>
</item>
<item>
<widget class="TextEditor::SnippetEditorWidget" name="editWidget"/>
</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>
<customwidgets>
<customwidget>
<class>TextEditor::SnippetEditorWidget</class>
<extends>QPlainTextEdit</extends>
<header location="global">texteditor/snippets/snippeteditor.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>CppEditor::Internal::CppPreProcessorDialog</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>CppEditor::Internal::CppPreProcessorDialog</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>