diff --git a/extensions/apps/traceAnalyzer/businessObjects/pythoncaller.cpp b/extensions/apps/traceAnalyzer/businessObjects/pythoncaller.cpp index fa21e2c8..29941fd3 100644 --- a/extensions/apps/traceAnalyzer/businessObjects/pythoncaller.cpp +++ b/extensions/apps/traceAnalyzer/businessObjects/pythoncaller.cpp @@ -45,12 +45,6 @@ #include #include -PythonCaller &PythonCaller::instance() -{ - static PythonCaller instance; - return instance; -} - PythonCaller::PythonCaller() : metricModuleName("metrics"), metricFunctionName("calculateMetrics"), diff --git a/extensions/apps/traceAnalyzer/businessObjects/pythoncaller.h b/extensions/apps/traceAnalyzer/businessObjects/pythoncaller.h index 3b6a84d8..30bd8d8a 100644 --- a/extensions/apps/traceAnalyzer/businessObjects/pythoncaller.h +++ b/extensions/apps/traceAnalyzer/businessObjects/pythoncaller.h @@ -54,7 +54,8 @@ class PythonCaller { public: - static PythonCaller &instance(); + PythonCaller(); + ~PythonCaller(); TraceCalculatedMetrics calculateMetricsOnTrace(QString pathToTrace, std::vector 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; diff --git a/extensions/apps/traceAnalyzer/evaluationtool.cpp b/extensions/apps/traceAnalyzer/evaluationtool.cpp index 0bfd9693..078ea775 100644 --- a/extensions/apps/traceAnalyzer/evaluationtool.cpp +++ b/extensions/apps/traceAnalyzer/evaluationtool.cpp @@ -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 EvaluationTool::getMetrics() vector metrics; for (int row = 0; row < traceFilesModel->rowCount(); ++row) { TraceFileItem *item = static_cast(traceFilesModel->item(row)); - vector result = PythonCaller::instance().getMetrics(item->getPath()); + vector result = pythonCaller.getMetrics(item->getPath()); if (result.size() > metrics.size()) metrics = result; } @@ -141,7 +141,7 @@ void EvaluationTool::calculateMetrics(vector selectedMetrics) TraceFileItem *item = static_cast(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(); diff --git a/extensions/apps/traceAnalyzer/evaluationtool.h b/extensions/apps/traceAnalyzer/evaluationtool.h index 45dc3a89..6c32d487 100644 --- a/extensions/apps/traceAnalyzer/evaluationtool.h +++ b/extensions/apps/traceAnalyzer/evaluationtool.h @@ -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 paths); @@ -87,6 +87,8 @@ private: QString resourcesRelPath; SelectMetrics *selectMetrics; + PythonCaller &pythonCaller; + class TraceFileItem : public QStandardItem { public: diff --git a/extensions/apps/traceAnalyzer/traceanalyzer.cpp b/extensions/apps/traceAnalyzer/traceanalyzer.cpp index 3dbb2000..499ea212 100644 --- a/extensions/apps/traceAnalyzer/traceanalyzer.cpp +++ b/extensions/apps/traceAnalyzer/traceanalyzer.cpp @@ -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 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); diff --git a/extensions/apps/traceAnalyzer/traceanalyzer.h b/extensions/apps/traceAnalyzer/traceanalyzer.h index 8320fe07..2e943f5d 100644 --- a/extensions/apps/traceAnalyzer/traceanalyzer.h +++ b/extensions/apps/traceAnalyzer/traceanalyzer.h @@ -60,12 +60,10 @@ class TraceAnalyzer : public QMainWindow Q_OBJECT public: - explicit TraceAnalyzer(QWidget *parent = 0); + explicit TraceAnalyzer(QWidget *parent = nullptr); explicit TraceAnalyzer(QSet paths, StartupOption option, - QWidget *parent = 0); - + QWidget *parent = nullptr); ~TraceAnalyzer(); - EvaluationTool evaluationTool; void setUpStatusBar(); void setUpGui(); @@ -81,6 +79,8 @@ private: QLabel *statusLabel; QSet openedTraceFiles; + EvaluationTool evaluationTool; + PythonCaller pythonCaller; private Q_SLOTS: void on_menuFile_aboutToShow(); diff --git a/extensions/apps/traceAnalyzer/tracefiletab.cpp b/extensions/apps/traceAnalyzer/tracefiletab.cpp index 282df492..d5d0feb9 100644 --- a/extensions/apps/traceAnalyzer/tracefiletab.cpp +++ b/extensions/apps/traceAnalyzer/tracefiletab.cpp @@ -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 #include #include +#include #include #include #include #include #include #include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -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?
Unsaved changes will be lost."); saveDialog.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); diff --git a/extensions/apps/traceAnalyzer/tracefiletab.h b/extensions/apps/traceAnalyzer/tracefiletab.h index a59e6dbe..2fa3d683 100644 --- a/extensions/apps/traceAnalyzer/tracefiletab.h +++ b/extensions/apps/traceAnalyzer/tracefiletab.h @@ -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;