Revert the design choice of making the PythonCaller a static singleton
This commit is contained in:
@@ -45,12 +45,6 @@
|
||||
#include <QDebug>
|
||||
#include <QApplication>
|
||||
|
||||
PythonCaller &PythonCaller::instance()
|
||||
{
|
||||
static PythonCaller instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
PythonCaller::PythonCaller() :
|
||||
metricModuleName("metrics"),
|
||||
metricFunctionName("calculateMetrics"),
|
||||
|
||||
@@ -54,7 +54,8 @@
|
||||
class PythonCaller
|
||||
{
|
||||
public:
|
||||
static PythonCaller &instance();
|
||||
PythonCaller();
|
||||
~PythonCaller();
|
||||
|
||||
TraceCalculatedMetrics calculateMetricsOnTrace(QString pathToTrace,
|
||||
std::vector<long> list);
|
||||
@@ -65,11 +66,6 @@ public:
|
||||
QString exportAsVcd(QString pathToTrace);
|
||||
|
||||
private:
|
||||
PythonCaller();
|
||||
~PythonCaller();
|
||||
PythonCaller(const PythonCaller &other) = delete;
|
||||
PythonCaller &operator=(const PythonCaller &other) = delete;
|
||||
|
||||
PyObject *pCalculateMetricsFunction, *pGetMetricsFunction;
|
||||
PyObject *pGenPlotsFunction;
|
||||
PyObject *pVcdExportFunction = nullptr;
|
||||
|
||||
@@ -53,9 +53,9 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
EvaluationTool::EvaluationTool(QWidget *parent) :
|
||||
EvaluationTool::EvaluationTool(PythonCaller &pythonCaller, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::EvaluationTool), resourcesRelPath("/../../dram/resources/scripts""")
|
||||
ui(new Ui::EvaluationTool), resourcesRelPath("/../../dram/resources/scripts"""), pythonCaller(pythonCaller)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
traceFilesModel = new QStandardItemModel(this);
|
||||
@@ -93,7 +93,7 @@ vector<string> EvaluationTool::getMetrics()
|
||||
vector<string> metrics;
|
||||
for (int row = 0; row < traceFilesModel->rowCount(); ++row) {
|
||||
TraceFileItem *item = static_cast<TraceFileItem *>(traceFilesModel->item(row));
|
||||
vector<string> result = PythonCaller::instance().getMetrics(item->getPath());
|
||||
vector<string> result = pythonCaller.getMetrics(item->getPath());
|
||||
if (result.size() > metrics.size())
|
||||
metrics = result;
|
||||
}
|
||||
@@ -141,7 +141,7 @@ void EvaluationTool::calculateMetrics(vector<long> selectedMetrics)
|
||||
TraceFileItem *item = static_cast<TraceFileItem *>(traceFilesModel->item(row));
|
||||
if (item->checkState() == Qt::Checked)
|
||||
{
|
||||
TraceCalculatedMetrics result = PythonCaller::instance().calculateMetricsOnTrace(
|
||||
TraceCalculatedMetrics result = pythonCaller.calculateMetricsOnTrace(
|
||||
item->getPath(), selectedMetrics);
|
||||
calculatedMetrics.push_back(result);
|
||||
ui->traceMetricTreeWidget->addTraceMetricResults(result);
|
||||
@@ -196,7 +196,7 @@ void EvaluationTool::genPlots()
|
||||
{
|
||||
ui->traceMetricTreeWidget->addTracePlotResults(QFileInfo(
|
||||
item->getPath()).baseName(),
|
||||
PythonCaller::instance().generatePlotsOnTrace(item->getPath()));
|
||||
pythonCaller.generatePlotsOnTrace(item->getPath()));
|
||||
}
|
||||
}
|
||||
ui->traceMetricTreeWidget->expandAll();
|
||||
|
||||
@@ -61,7 +61,7 @@ class EvaluationTool : public QWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit EvaluationTool(QWidget *parent = 0);
|
||||
explicit EvaluationTool(PythonCaller &pythonCaller, QWidget *parent = nullptr);
|
||||
~EvaluationTool();
|
||||
|
||||
void showForFiles(QList<QString> paths);
|
||||
@@ -87,6 +87,8 @@ private:
|
||||
QString resourcesRelPath;
|
||||
SelectMetrics *selectMetrics;
|
||||
|
||||
PythonCaller &pythonCaller;
|
||||
|
||||
class TraceFileItem : public QStandardItem
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -63,7 +63,8 @@ void TraceAnalyzer::setUpGui()
|
||||
|
||||
TraceAnalyzer::TraceAnalyzer(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::TraceAnalyzer)
|
||||
ui(new Ui::TraceAnalyzer),
|
||||
evaluationTool(pythonCaller)
|
||||
{
|
||||
setUpGui();
|
||||
}
|
||||
@@ -71,7 +72,8 @@ TraceAnalyzer::TraceAnalyzer(QWidget *parent) :
|
||||
TraceAnalyzer::TraceAnalyzer(QSet<QString> paths, StartupOption option,
|
||||
QWidget *parent):
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::TraceAnalyzer)
|
||||
ui(new Ui::TraceAnalyzer),
|
||||
evaluationTool(pythonCaller)
|
||||
{
|
||||
setUpGui();
|
||||
|
||||
@@ -99,7 +101,7 @@ void TraceAnalyzer::on_actionOpen_triggered()
|
||||
|
||||
TraceFileTab *TraceAnalyzer::createTraceFileTab(const QString &path)
|
||||
{
|
||||
TraceFileTab *traceFileTab = new TraceFileTab(this, path);
|
||||
TraceFileTab *traceFileTab = new TraceFileTab(path.toStdString(), pythonCaller, this);
|
||||
|
||||
connect(traceFileTab, &TraceFileTab::statusChanged, this, &TraceAnalyzer::statusChanged);
|
||||
|
||||
@@ -125,7 +127,7 @@ void TraceAnalyzer::on_menuFile_aboutToShow()
|
||||
ui->actionQuit->setEnabled(true);
|
||||
|
||||
bool tabsOpen = ui->traceFileTabs->count() > 0;
|
||||
bool exportAsVcdAvailable = PythonCaller::instance().vcdExportDependenciesAvailable();
|
||||
bool exportAsVcdAvailable = pythonCaller.vcdExportDependenciesAvailable();
|
||||
|
||||
ui->actionSave->setEnabled(tabsOpen);
|
||||
ui->actionSave_all->setEnabled(tabsOpen);
|
||||
|
||||
@@ -60,12 +60,10 @@ class TraceAnalyzer : public QMainWindow
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TraceAnalyzer(QWidget *parent = 0);
|
||||
explicit TraceAnalyzer(QWidget *parent = nullptr);
|
||||
explicit TraceAnalyzer(QSet<QString> paths, StartupOption option,
|
||||
QWidget *parent = 0);
|
||||
|
||||
QWidget *parent = nullptr);
|
||||
~TraceAnalyzer();
|
||||
EvaluationTool evaluationTool;
|
||||
|
||||
void setUpStatusBar();
|
||||
void setUpGui();
|
||||
@@ -81,6 +79,8 @@ private:
|
||||
|
||||
QLabel *statusLabel;
|
||||
QSet<QString> openedTraceFiles;
|
||||
EvaluationTool evaluationTool;
|
||||
PythonCaller pythonCaller;
|
||||
|
||||
private Q_SLOTS:
|
||||
void on_menuFile_aboutToShow();
|
||||
|
||||
@@ -38,52 +38,50 @@
|
||||
*/
|
||||
|
||||
#include "tracefiletab.h"
|
||||
#include "QFileInfo"
|
||||
#include "businessObjects/commentmodel.h"
|
||||
#include "businessObjects/configmodels.h"
|
||||
#include "businessObjects/dramTimeDependencies/phasedependenciestracker.h"
|
||||
#include "businessObjects/pythoncaller.h"
|
||||
#include "businessObjects/traceplotlinemodel.h"
|
||||
#include "businessObjects/tracetime.h"
|
||||
#include "businessObjects/dramTimeDependencies/phasedependenciestracker.h"
|
||||
#include "qmessagebox.h"
|
||||
#include "queryeditor.h"
|
||||
#include "qwt_legend.h"
|
||||
#include "qwt_plot_canvas.h"
|
||||
#include "qwt_plot_curve.h"
|
||||
#include "qwt_plot_histogram.h"
|
||||
#include "qwt_plot_layout.h"
|
||||
#include "qwt_plot_magnifier.h"
|
||||
#include "qwt_plot_panner.h"
|
||||
#include "qwt_scale_draw.h"
|
||||
#include "qwt_scale_widget.h"
|
||||
#include "traceanalyzer.h"
|
||||
#include "ui_tracefiletab.h"
|
||||
|
||||
#include <QCloseEvent>
|
||||
#include <QDebug>
|
||||
#include <QFileDialog>
|
||||
#include <QFileInfo>
|
||||
#include <QItemDelegate>
|
||||
#include <QMessageBox>
|
||||
#include <QStandardItemModel>
|
||||
#include <QString>
|
||||
#include <QTextStream>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
#include <iostream>
|
||||
#include <qwt_legend.h>
|
||||
#include <qwt_plot_canvas.h>
|
||||
#include <qwt_plot_curve.h>
|
||||
#include <qwt_plot_histogram.h>
|
||||
#include <qwt_plot_layout.h>
|
||||
#include <qwt_plot_magnifier.h>
|
||||
#include <qwt_plot_panner.h>
|
||||
#include <qwt_scale_draw.h>
|
||||
#include <qwt_scale_widget.h>
|
||||
|
||||
TraceFileTab::TraceFileTab(QWidget *parent, const QString &path)
|
||||
TraceFileTab::TraceFileTab(std::string_view traceFilePath, PythonCaller &pythonCaller, QWidget *parent)
|
||||
: QWidget(parent), ui(new Ui::TraceFileTab), commentModel(new CommentModel(this)),
|
||||
navigator(new TraceNavigator(path, commentModel, this)),
|
||||
navigator(new TraceNavigator(traceFilePath.data(), commentModel, this)),
|
||||
mcConfigModel(new McConfigModel(navigator->TraceFile(), this)),
|
||||
memSpecModel(new MemSpecModel(navigator->TraceFile(), this)),
|
||||
availableRowsModel(new AvailableTracePlotLineModel(navigator->GeneralTraceInfo(), this)),
|
||||
selectedRowsModel(new SelectedTracePlotLineModel(navigator->GeneralTraceInfo(), this)),
|
||||
tracePlotLineDataSource(new TracePlotLineDataSource(selectedRowsModel, this)),
|
||||
depInfosView(new DependencyInfosModel(navigator->TraceFile(), this)),
|
||||
savingChangesToDB(false)
|
||||
depInfosView(new DependencyInfosModel(navigator->TraceFile(), this)), savingChangesToDB(false),
|
||||
pythonCaller(pythonCaller), traceFilePath(traceFilePath)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->path = path;
|
||||
|
||||
std::cout << "Opening new tab for \"" << path.toStdString() << "\"" <<
|
||||
std::cout << "Opening new tab for \"" << traceFilePath << "\"" <<
|
||||
std::endl;
|
||||
|
||||
ui->mcConfigView->setModel(mcConfigModel);
|
||||
@@ -96,8 +94,8 @@ TraceFileTab::TraceFileTab(QWidget *parent, const QString &path)
|
||||
ui->depInfosView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
|
||||
setUpTraceSelector();
|
||||
initNavigatorAndItsDependentWidgets(path);
|
||||
setUpFileWatcher(path);
|
||||
initNavigatorAndItsDependentWidgets(traceFilePath.data());
|
||||
setUpFileWatcher(traceFilePath.data());
|
||||
setUpTraceplotScrollbar();
|
||||
setUpCommentView();
|
||||
|
||||
@@ -122,7 +120,7 @@ void TraceFileTab::exportAsVCD()
|
||||
QString filename = QFileDialog::getSaveFileName(this, "Export to VCD", "",
|
||||
"VCD files (*.vcd)");
|
||||
auto dumpVcd = [=]() {
|
||||
QString dump = PythonCaller::instance().exportAsVcd(path);
|
||||
QString dump = pythonCaller.exportAsVcd(traceFilePath.data());
|
||||
|
||||
QFile file(filename);
|
||||
file.open(QIODevice::WriteOnly | QIODevice::Text);
|
||||
@@ -249,7 +247,7 @@ void TraceFileTab::closeEvent(QCloseEvent *event)
|
||||
if (navigator->existChangesToCommit())
|
||||
{
|
||||
QMessageBox saveDialog;
|
||||
saveDialog.setWindowTitle(QFileInfo(path).baseName());
|
||||
saveDialog.setWindowTitle(QFileInfo(traceFilePath.data()).baseName());
|
||||
saveDialog.setText("The trace file has been modified.");
|
||||
saveDialog.setInformativeText("Do you want to save your changes?<br><b>Unsaved changes will be lost.</b>");
|
||||
saveDialog.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
class CommentModel;
|
||||
class McConfigModel;
|
||||
class MemSpecModel;
|
||||
class PythonCaller;
|
||||
|
||||
namespace Ui {
|
||||
class TraceFileTab;
|
||||
@@ -65,7 +66,7 @@ class TraceFileTab : public QWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TraceFileTab(QWidget *parent, const QString &path);
|
||||
explicit TraceFileTab(std::string_view traceFilePath, PythonCaller &pythonCaller, QWidget *parent);
|
||||
~TraceFileTab();
|
||||
|
||||
void setUpFileWatcher(QString filename);
|
||||
@@ -75,10 +76,7 @@ public:
|
||||
void setUpPossiblePhases();
|
||||
|
||||
void initNavigatorAndItsDependentWidgets(QString path);
|
||||
QString getPathToTraceFile()
|
||||
{
|
||||
return path;
|
||||
}
|
||||
QString getPathToTraceFile() { return traceFilePath.data(); }
|
||||
void commitChangesToDB(void);
|
||||
void exportAsVCD();
|
||||
|
||||
@@ -101,7 +99,7 @@ protected:
|
||||
bool eventFilter(QObject *object, QEvent *event) override;
|
||||
|
||||
private:
|
||||
QString path;
|
||||
std::string traceFilePath;
|
||||
Ui::TraceFileTab *ui;
|
||||
QFileSystemWatcher *fileWatcher;
|
||||
|
||||
@@ -117,6 +115,8 @@ private:
|
||||
|
||||
QAbstractItemModel *depInfosView;
|
||||
|
||||
PythonCaller &pythonCaller;
|
||||
|
||||
void setUpQueryEditor(QString path);
|
||||
bool savingChangesToDB;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user