Skip to content

Commit

Permalink
add custom dialog for diffing
Browse files Browse the repository at this point in the history
  • Loading branch information
lievenhey committed Dec 15, 2021
1 parent 48de8e4 commit e385487
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ set(hotspot_SRCS
perfoutputwidgettext.cpp
perfoutputwidgetkonsole.cpp
costcontextmenu.cpp
diffdialog.cpp

# ui files:
mainwindow.ui
Expand All @@ -66,6 +67,7 @@ set(hotspot_SRCS
settingsdialog.ui
flamegraphsettings.ui
debuginfoddialog.ui
diffdialog.ui

# resources:
resources.qrc
Expand Down
27 changes: 27 additions & 0 deletions src/diffdialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "diffdialog.h"
#include "ui_diffdialog.h"

DiffDialog::DiffDialog(QWidget* parent)
: QDialog(parent)
, ui(new Ui::DiffDialog)
{
ui->setupUi(this);
const auto filterString = QLatin1String("perf*.data\nperf.data*");
ui->file_a->setFilter(filterString);
ui->file_b->setFilter(filterString);

connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accepted);
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::close);
}

DiffDialog::~DiffDialog() = default;

QString DiffDialog::fileA() const
{
return ui->file_a->url().path();
}

QString DiffDialog::fileB() const
{
return ui->file_b->url().path();
}
23 changes: 23 additions & 0 deletions src/diffdialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef DIFFDIALOG_H
#define DIFFDIALOG_H

#include <QDialog>

namespace Ui {
class DiffDialog;
}

class DiffDialog : public QDialog
{
public:
explicit DiffDialog(QWidget* parent = nullptr);
~DiffDialog();

QString fileA() const;
QString fileB() const;

private:
QScopedPointer<Ui::DiffDialog> ui;
};

#endif // DIFFDIALOG_H
70 changes: 70 additions & 0 deletions src/diffdialog.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DiffDialog</class>
<widget class="QDialog" name="DiffDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Diff two files</string>
</property>
<property name="sizeGripEnabled">
<bool>false</bool>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="leftMargin">
<number>6</number>
</property>
<property name="topMargin">
<number>6</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<property name="bottomMargin">
<number>6</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>File A:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>File B:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="KUrlRequester" name="file_a"/>
</item>
<item row="1" column="1">
<widget class="KUrlRequester" name="file_b"/>
</item>
<item row="2" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Open</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KUrlRequester</class>
<extends>QWidget</extends>
<header>kurlrequester.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
20 changes: 7 additions & 13 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "mainwindow.h"
#include "costcontextmenu.h"
#include "diffdialog.h"
#include "recordpage.h"
#include "resultspage.h"
#include "settings.h"
Expand Down Expand Up @@ -116,6 +117,7 @@ MainWindow::MainWindow(QWidget* parent)
, m_recordPage(new RecordPage(this))
, m_resultsPage(new ResultsPage(m_parser, this))
, m_settingsDialog(new SettingsDialog(this))
, m_diffDialog(new DiffDialog(this))
{
ui->setupUi(this);

Expand Down Expand Up @@ -149,21 +151,13 @@ MainWindow::MainWindow(QWidget* parent)
connect(m_startPage, &StartPage::recordButtonClicked, this, &MainWindow::onRecordButtonClicked);
connect(m_startPage, &StartPage::stopParseButtonClicked, this,
static_cast<void (MainWindow::*)()>(&MainWindow::clear));
connect(m_startPage, &StartPage::diffButtonClicked, this, [this] {
const auto fileNameA = QFileDialog::getOpenFileName(this, tr("Open File A"), QDir::currentPath(),
tr("Data Files (perf*.data perf.data.*);;All Files (*)"));
if (fileNameA.isEmpty()) {
return;
}

const auto fileNameB = QFileDialog::getOpenFileName(this, tr("Open File B"), QDir::currentPath(),
tr("Data Files (perf*.data perf.data.*);;All Files (*)"));
if (fileNameB.isEmpty()) {
return;
}

openFile(fileNameA, false, fileNameB);
connect(m_startPage, &StartPage::diffButtonClicked, this, [this] { m_diffDialog->open(); });
connect(m_diffDialog, &QDialog::accepted, this, [this] {
m_diffDialog->close();
openFile(m_diffDialog->fileA(), false, m_diffDialog->fileB());
});

connect(m_parser, &PerfParser::progress, m_startPage, &StartPage::onParseFileProgress);
connect(this, &MainWindow::openFileError, m_startPage, &StartPage::onOpenFileError);
connect(m_recordPage, &RecordPage::homeButtonClicked, this, &MainWindow::onHomeButtonClicked);
Expand Down
2 changes: 2 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class StartPage;
class ResultsPage;
class RecordPage;
class SettingsDialog;
class DiffDialog;

class MainWindow : public KParts::MainWindow
{
Expand Down Expand Up @@ -90,6 +91,7 @@ public slots:
RecordPage* m_recordPage;
ResultsPage* m_resultsPage;
SettingsDialog* m_settingsDialog;
DiffDialog* m_diffDialog;

QString m_lastUsedSettings;
KRecentFilesAction* m_recentFilesAction = nullptr;
Expand Down

0 comments on commit e385487

Please sign in to comment.