#include <ui_mainwindow.h>
#include <iostream>
-#include <sstream>
#include "model.h"
-#include "../accumulatedtracedata.h"
using namespace std;
-namespace {
-QString generateSummary(const AccumulatedTraceData& data)
-{
- stringstream stream;
- const double totalTimeS = 0.001 * data.totalTime;
- stream << "<qt>"
- << "<strong>total runtime</strong>: " << fixed << totalTimeS << "s.<br/>"
- << "<strong>bytes allocated in total</strong> (ignoring deallocations): " << formatBytes(data.totalAllocated)
- << " (" << formatBytes(data.totalAllocated / totalTimeS) << "/s)<br/>"
- << "<strong>calls to allocation functions</strong>: " << data.totalAllocations
- << " (" << size_t(data.totalAllocations / totalTimeS) << "/s)<br/>"
- << "<strong>peak heap memory consumption</strong>: " << formatBytes(data.peak) << "<br/>"
- << "<strong>total memory leaked</strong>: " << formatBytes(data.leaked) << "<br/>";
- stream << "</qt>";
- return QString::fromStdString(stream.str());
-}
-}
-
MainWindow::MainWindow(QWidget* parent)
: m_ui(new Ui::MainWindow)
, m_model(new Model(this))
{
m_ui->setupUi(this);
m_ui->results->setModel(m_model);
+ connect(m_model, &Model::dataReady,
+ this, &MainWindow::dataReady);
}
MainWindow::~MainWindow()
{
}
+void MainWindow::dataReady(const QString& summary)
+{
+ m_ui->summary->setText(summary);
+}
+
void MainWindow::loadFile(const QString& file)
{
cout << "Loading file " << qPrintable(file) << ", this might take some time - please wait." << endl;
- AccumulatedTraceData data;
- data.read(file.toStdString());
- m_ui->summary->setText(generateSummary(data));
+ m_model->loadFile(file);
}
void loadFile(const QString& path);
+private slots:
+ void dataReady(const QString& summary);
+
private:
QScopedPointer<Ui::MainWindow> m_ui;
Model* m_model;
#include "model.h"
+#include <sstream>
+
+using namespace std;
+
+namespace {
+QString generateSummary(const AccumulatedTraceData& data)
+{
+ stringstream stream;
+ const double totalTimeS = 0.001 * data.totalTime;
+ stream << "<qt>"
+ << "<strong>total runtime</strong>: " << fixed << totalTimeS << "s.<br/>"
+ << "<strong>bytes allocated in total</strong> (ignoring deallocations): " << formatBytes(data.totalAllocated)
+ << " (" << formatBytes(data.totalAllocated / totalTimeS) << "/s)<br/>"
+ << "<strong>calls to allocation functions</strong>: " << data.totalAllocations
+ << " (" << size_t(data.totalAllocations / totalTimeS) << "/s)<br/>"
+ << "<strong>peak heap memory consumption</strong>: " << formatBytes(data.peak) << "<br/>"
+ << "<strong>total memory leaked</strong>: " << formatBytes(data.leaked) << "<br/>";
+ stream << "</qt>";
+ return QString::fromStdString(stream.str());
+}
+}
+
Model::Model(QObject* parent)
{
{
return NUM_COLUMNS;
}
+
+void Model::loadFile(const QString& file)
+{
+ m_data.read(file.toStdString());
+ emit dataReady(generateSummary(m_data));
+}
#include <QAbstractItemModel>
+#include "../accumulatedtracedata.h"
+
class Model : public QAbstractItemModel
{
Q_OBJECT
};
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
- QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
- QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
- QModelIndex parent(const QModelIndex &child) const override;
- int rowCount(const QModelIndex &parent = QModelIndex()) const override;
- int columnCount(const QModelIndex &parent = QModelIndex()) const override;
+ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
+ QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
+ QModelIndex parent(const QModelIndex& child) const override;
+ int rowCount(const QModelIndex& parent = QModelIndex()) const override;
+ int columnCount(const QModelIndex& parent = QModelIndex()) const override;
-private:
+ void loadFile(const QString& file);
+signals:
+ void dataReady(const QString& summary);
+
+private:
+ AccumulatedTraceData m_data;
};
#endif // MODEL_H