From 62a7ae5e306fa17b27f9fe4cc49476ba71eee714 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Fri, 19 Aug 2022 17:46:05 +0200 Subject: [PATCH] PerfProfiler: inline perftracepointdialog.ui Change-Id: I138d3a4aeae2eef0e2127e8770961109d252ec98 Reviewed-by: hjk Reviewed-by: --- src/plugins/perfprofiler/CMakeLists.txt | 2 +- src/plugins/perfprofiler/perfprofiler.qbs | 1 - .../perfprofiler/perftracepointdialog.cpp | 68 ++++++++---- .../perfprofiler/perftracepointdialog.h | 12 +- .../perfprofiler/perftracepointdialog.ui | 104 ------------------ 5 files changed, 59 insertions(+), 128 deletions(-) delete mode 100644 src/plugins/perfprofiler/perftracepointdialog.ui diff --git a/src/plugins/perfprofiler/CMakeLists.txt b/src/plugins/perfprofiler/CMakeLists.txt index f1667687e3b..9204f18fd19 100644 --- a/src/plugins/perfprofiler/CMakeLists.txt +++ b/src/plugins/perfprofiler/CMakeLists.txt @@ -36,7 +36,7 @@ set(PERFPROFILER_CPP_SOURCES perftimelinemodel.cpp perftimelinemodel.h perftimelinemodelmanager.cpp perftimelinemodelmanager.h perftimelineresourcesrenderpass.cpp perftimelineresourcesrenderpass.h - perftracepointdialog.cpp perftracepointdialog.h perftracepointdialog.ui + perftracepointdialog.cpp perftracepointdialog.h ) add_qtc_plugin(PerfProfiler diff --git a/src/plugins/perfprofiler/perfprofiler.qbs b/src/plugins/perfprofiler/perfprofiler.qbs index e53f9db564c..f3151ae0a63 100644 --- a/src/plugins/perfprofiler/perfprofiler.qbs +++ b/src/plugins/perfprofiler/perfprofiler.qbs @@ -65,7 +65,6 @@ QtcPlugin { "perfsettings.h", "perftracepointdialog.cpp", "perftracepointdialog.h", - "perftracepointdialog.ui", "perfprofiler.qrc", ] diff --git a/src/plugins/perfprofiler/perftracepointdialog.cpp b/src/plugins/perfprofiler/perftracepointdialog.cpp index 9b98d2f319b..fc4b704e5fe 100644 --- a/src/plugins/perfprofiler/perftracepointdialog.cpp +++ b/src/plugins/perfprofiler/perftracepointdialog.cpp @@ -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 "perftracepointdialog.h" -#include "ui_perftracepointdialog.h" #include #include @@ -14,20 +13,43 @@ #include #include +#include +#include +#include +#include #include +#include #include +const char ELEVATE_METHOD_NA[] = "n.a"; +const char ELEVATE_METHOD_PKEXEC[] = "pkexec"; +const char ELEVATE_METHOD_SUDO[] = "sudo"; + using namespace ProjectExplorer; using namespace Utils; namespace PerfProfiler { namespace Internal { -PerfTracePointDialog::PerfTracePointDialog() : - m_ui(new Ui::PerfTracePointDialog) +PerfTracePointDialog::PerfTracePointDialog() { - m_ui->setupUi(this); + resize(400, 300); + m_label = new QLabel(tr("Run the following script as root to create trace points?")); + m_textEdit = new QTextEdit; + m_privilegesChooser = new QComboBox; + m_privilegesChooser->addItems({ELEVATE_METHOD_NA, ELEVATE_METHOD_PKEXEC, ELEVATE_METHOD_SUDO}); + m_buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + + using namespace Utils::Layouting; + Column { + m_label, + m_textEdit, + Form { + tr("Elevate privileges using:"), m_privilegesChooser, br, + }, + m_buttonBox, + }.attachTo(this); if (const Target *target = SessionManager::startupTarget()) { const Kit *kit = target->kit(); @@ -35,7 +57,7 @@ PerfTracePointDialog::PerfTracePointDialog() : m_device = DeviceKitAspect::device(kit); if (!m_device) { - m_ui->textEdit->setPlainText(tr("Error: No device available for active target.")); + m_textEdit->setPlainText(tr("Error: No device available for active target.")); return; } } @@ -48,31 +70,35 @@ PerfTracePointDialog::PerfTracePointDialog() : QFile file(":/perfprofiler/tracepoints.sh"); if (file.open(QIODevice::ReadOnly)) { - m_ui->textEdit->setPlainText(QString::fromUtf8(file.readAll())); + m_textEdit->setPlainText(QString::fromUtf8(file.readAll())); } else { - m_ui->textEdit->setPlainText(tr("Error: Failed to load trace point script %1: %2.") + m_textEdit->setPlainText(tr("Error: Failed to load trace point script %1: %2.") .arg(file.fileName()).arg(file.errorString())); } - m_ui->privilegesChooser->setCurrentText(m_device->type() == Constants::DESKTOP_DEVICE_TYPE - ? QLatin1String("pkexec") : QLatin1String("n.a.")); + m_privilegesChooser->setCurrentText( + QLatin1String(m_device->type() == Constants::DESKTOP_DEVICE_TYPE + ? ELEVATE_METHOD_PKEXEC : ELEVATE_METHOD_NA)); + + connect(m_buttonBox, &QDialogButtonBox::accepted, this, &PerfTracePointDialog::accept); + connect(m_buttonBox, &QDialogButtonBox::rejected, this, &PerfTracePointDialog::reject); } PerfTracePointDialog::~PerfTracePointDialog() = default; void PerfTracePointDialog::runScript() { - m_ui->label->setText(tr("Executing script...")); - m_ui->textEdit->setReadOnly(true); - m_ui->privilegesChooser->setEnabled(false); - m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); + m_label->setText(tr("Executing script...")); + m_textEdit->setReadOnly(true); + m_privilegesChooser->setEnabled(false); + m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); m_process.reset(new QtcProcess(this)); - m_process->setWriteData(m_ui->textEdit->toPlainText().toUtf8()); - m_ui->textEdit->clear(); + m_process->setWriteData(m_textEdit->toPlainText().toUtf8()); + m_textEdit->clear(); - const QString elevate = m_ui->privilegesChooser->currentText(); - if (elevate != QLatin1String("n.a.")) + const QString elevate = m_privilegesChooser->currentText(); + if (elevate != QLatin1String(ELEVATE_METHOD_NA)) m_process->setCommand({m_device->filePath(elevate), {"sh"}}); else m_process->setCommand({m_device->filePath("sh"), {}}); @@ -93,10 +119,10 @@ void PerfTracePointDialog::handleProcessDone() message = tr("Created trace points for: %1").arg(QString::fromUtf8( m_process->readAllStandardOutput().trimmed().replace('\n', ", "))); } - m_ui->label->setText(message); - m_ui->textEdit->setHtml(QString::fromUtf8(m_process->readAllStandardError())); - m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); - m_ui->buttonBox->button(QDialogButtonBox::Cancel)->setEnabled(false); + m_label->setText(message); + m_textEdit->setHtml(QString::fromUtf8(m_process->readAllStandardError())); + m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); + m_buttonBox->button(QDialogButtonBox::Cancel)->setEnabled(false); } void PerfTracePointDialog::accept() diff --git a/src/plugins/perfprofiler/perftracepointdialog.h b/src/plugins/perfprofiler/perftracepointdialog.h index 6cbefaf60d6..8562ed7b35c 100644 --- a/src/plugins/perfprofiler/perftracepointdialog.h +++ b/src/plugins/perfprofiler/perftracepointdialog.h @@ -8,6 +8,13 @@ #include #include +QT_BEGIN_NAMESPACE +class QComboBox; +class QDialogButtonBox; +class QLabel; +class QTextEdit; +QT_END_NAMESPACE + namespace Utils { class QtcProcess; } namespace PerfProfiler { @@ -28,7 +35,10 @@ private: void handleProcessDone(); void finish(); - Ui::PerfTracePointDialog *m_ui; + QLabel *m_label; + QTextEdit *m_textEdit; + QComboBox *m_privilegesChooser; + QDialogButtonBox *m_buttonBox; ProjectExplorer::IDeviceConstPtr m_device; std::unique_ptr m_process; diff --git a/src/plugins/perfprofiler/perftracepointdialog.ui b/src/plugins/perfprofiler/perftracepointdialog.ui deleted file mode 100644 index ce2f1f4c408..00000000000 --- a/src/plugins/perfprofiler/perftracepointdialog.ui +++ /dev/null @@ -1,104 +0,0 @@ - - - PerfProfiler::Internal::PerfTracePointDialog - - - - 0 - 0 - 400 - 300 - - - - Creating Memory Trace Points - - - - - - Run the following script as root to create trace points? - - - - - - - - - - - - Elevate privileges using: - - - - - - - - n.a. - - - - - pkexec - - - - - sudo - - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - buttonBox - accepted() - PerfProfiler::Internal::PerfTracePointDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - PerfProfiler::Internal::PerfTracePointDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - -