From 6922c512ff6d9326701bfc85dba95b5eb71bd5d9 Mon Sep 17 00:00:00 2001 From: romanodanilo <62891297+romanodanilo@users.noreply.github.com> Date: Thu, 30 May 2024 14:21:37 +0200 Subject: [PATCH] Remove runtime from Configuration GUI (#64) Signed-off-by: romanodanilo Signed-off-by: romanodanilo <62891297+romanodanilo@users.noreply.github.com> --- src/runtime/CMakeLists.txt | 5 - src/runtime/res/POC_Runtime.qrc | 6 - src/runtime/res/icons/pause.png | Bin 1680 -> 0 bytes src/runtime/res/icons/run.png | Bin 3991 -> 0 bytes src/runtime/src/runtime.cpp | 29 +--- src/runtime/src/runtime.h | 2 +- src/runtime/src/ui/c_process_log.cpp | 150 ----------------- src/runtime/src/ui/c_process_log.h | 102 ------------ src/runtime/src/ui/c_runtime_control.cpp | 65 -------- src/runtime/src/ui/c_runtime_control.h | 43 ----- src/runtime/src/ui/c_runtime_thread.cpp | 159 ------------------ src/runtime/src/ui/c_runtime_thread.h | 69 -------- src/runtime/src/ui/c_runtime_window.cpp | 162 +++++-------------- src/runtime/src/ui/c_runtime_window.h | 28 +--- test/function/runtime/src/runtime_tester.cpp | 20 --- 15 files changed, 52 insertions(+), 788 deletions(-) delete mode 100644 src/runtime/res/POC_Runtime.qrc delete mode 100644 src/runtime/res/icons/pause.png delete mode 100644 src/runtime/res/icons/run.png delete mode 100644 src/runtime/src/ui/c_process_log.cpp delete mode 100644 src/runtime/src/ui/c_process_log.h delete mode 100644 src/runtime/src/ui/c_runtime_control.cpp delete mode 100644 src/runtime/src/ui/c_runtime_control.h delete mode 100644 src/runtime/src/ui/c_runtime_thread.cpp delete mode 100644 src/runtime/src/ui/c_runtime_thread.h diff --git a/src/runtime/CMakeLists.txt b/src/runtime/CMakeLists.txt index 6055d5bd..009733c6 100644 --- a/src/runtime/CMakeLists.txt +++ b/src/runtime/CMakeLists.txt @@ -8,7 +8,6 @@ set(RUNTIME_PROJECT "ConfigGUI") project(${RUNTIME_PROJECT}) set(CMAKE_AUTOMOC ON) -qt5_add_resources(Resources res/POC_Runtime.qrc) add_executable(${RUNTIME_PROJECT} src/c_configuration_validator.cpp @@ -21,12 +20,8 @@ add_executable(${RUNTIME_PROJECT} src/ui/c_param_dialog.cpp src/ui/c_local_param_dialog.cpp src/ui/c_global_param_dialog.cpp - src/ui/c_process_log.cpp src/ui/c_process_view.cpp - src/ui/c_runtime_control.cpp - src/ui/c_runtime_thread.cpp src/ui/c_runtime_window.cpp - ${Resources} ) target_link_libraries(${RUNTIME_PROJECT} PRIVATE diff --git a/src/runtime/res/POC_Runtime.qrc b/src/runtime/res/POC_Runtime.qrc deleted file mode 100644 index d5e87eed..00000000 --- a/src/runtime/res/POC_Runtime.qrc +++ /dev/null @@ -1,6 +0,0 @@ - - - icons/run.png - icons/pause.png - - diff --git a/src/runtime/res/icons/pause.png b/src/runtime/res/icons/pause.png deleted file mode 100644 index d7cbb8f8fea4c7448bf95753b83c2d274974d8c0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1680 zcmeAS@N?(olHy`uVBq!ia0vp^4InJQ1|%o1+uH%8SkfJR9T^xl_H+M9WCijSl0AZa z85pY6fa+Qp7=D4&zhGb}HDF+PmB7GYHG_dcykO3*KpUV0TavfC3y=napU%7MffQ$f zM`SUOjsoKXCF+@3CuAr-gYUccKNQYv%&ZRZ1L6*b$6$IdPR-kS}xyJA_Ub~L(#9LX@*-PaRnt}3y_ zT+kxT)vYtaJ2&89REUIN(zSPQX3j0%wTXLihirOX^|#-3e_7{$e){2=3@6YT*np4O zx$g~WuV0?dJ(VA^#jieN*}5}(7i4yctg8yI*P8OWDmZhi=gY_U*sh6ct~wjOpl~a{ z_?O+cL}kxv1o`H@|NeBl_wVj%yZSTVW!1ZW`{xDgG4%hLB7JK8`Fjt_RxViQv}RS1 zROJ`rr6QU|k@tW9+wP(1`cacLEByJs-6bmTy32F^E~u%xU;1}?xcHBG-}86WZ}OSR z@MX@4+NtYP!e4}nemPg2E^=b!zMK=^*Lg4V-FPT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?|W=JRAz%q4?xBO!g#MEL~fH+FFh)8*#TR6(W}qPVtx>lD8ZoG@WQvZrP|aVwJ+kA z_2gSBGk)8UWrYP#MY{4DU79FA_>RsE`!}wEq!6xoQ+HBHzNLP6@BQD`1|ahmX?@bn zqcN&5`?fsRVy&NT%K{r)_j+9lcu~yF&xj% zAK|bHzDk(^1Kj&EjpVwZX<2HyJ|Pw4;luQ7GHjj2+DDF# zEcs^e>TzXzL_t7~8cL)P&zMG zcQp@TAyd*U0g!>_@kVLxk4jX(;z8!v*Y=uu9P8=w4Q2kp3~IQ55B0jQM9JA;Plk`$l3ACc$3lWk{PT?65_JG) zrl7AnQXKPh)Y2W+6ouNr7W_%^=UXYn7R^s|?}deMaUGQZQ*i1D32u9oT%pEAQ1=k! zWmD6oiEocgr(Az~oILZAEY?=HOJ2FLtp`_N6d1cMzg70^xAURO&-|xMLOj+bFR*c^GY5Gn+G~hmM?zDcGaW!aLTe_>ZO*p*O z`{j&98_SJ&^l{>_E|5g3#QZ3L4BnD8eKLeyN`%OU{UXqN`6G7ym!; -#include - -cProcessLog::cProcessLog(QWidget *parent) : QPlainTextEdit(parent) -{ - QFont font; - font.setFamily("Courier"); - font.setFixedPitch(true); - font.setPointSize(10); - - _metrics = new QFontMetrics(font); - - setWordWrapMode(QTextOption::NoWrap); - setFont(font); - setTabStopWidth(2 * _metrics->width(' ')); - setLineWrapMode(QPlainTextEdit::LineWrapMode::NoWrap); - - _lineNumberArea = new cLineNumberArea(this); - connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(UpdateLineNumberAreaWidth(int))); - connect(this, SIGNAL(updateRequest(QRect, int)), this, SLOT(UpdateLineNumberArea(QRect, int))); - - UpdateLineNumberAreaWidth(3); - setReadOnly(true); -} - -cProcessLog::~cProcessLog() -{ - if (_lineNumberArea != nullptr) - delete _lineNumberArea; - - if (_metrics != nullptr) - delete _metrics; -} - -void cProcessLog::SaveToFile(const QString &filepath) const -{ - QFile file(filepath); - if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) - return; - - QTextStream out(&file); - out << toPlainText(); - - file.close(); -} - -void cProcessLog::Clear() -{ - clear(); -} - -void cProcessLog::Log(const QString &log) -{ - appendPlainText(log); -} - -void cProcessLog::LineNumberAreaPaintEvent(QPaintEvent *event) -{ - assert(_metrics != nullptr); - assert(_lineNumberArea != nullptr); - - QPainter painter(_lineNumberArea); - painter.fillRect(event->rect(), QColor(240, 240, 240)); - - const int height = _metrics->height(); - const int width = _lineNumberArea->width(); - - painter.setPen(Qt::black); - QTextBlock block = firstVisibleBlock(); - int lineno = 1 + block.blockNumber(); - for (; block.isValid() && block.isVisible(); block = block.next(), ++lineno) - { - auto ypos = static_cast(blockBoundingGeometry(block).translated(contentOffset()).top()); - painter.drawText(0, ypos, _lineNumberArea->width(), height, Qt::AlignRight, QString::number(lineno)); - } -} - -int cProcessLog::LineNumberAreaWidth() const -{ - float no_blocks = static_cast(qMax(1, blockCount())); - int digits = 1 + static_cast(std::log10(no_blocks)); - int space = 3 + _metrics->width('9') * digits; - return qMax(3, space); -} - -void cProcessLog::UpdateLineNumberArea(const QRect &rect, int dy) -{ - assert(_lineNumberArea != nullptr); - - if (dy) - _lineNumberArea->scroll(0, dy); - else - { - _lineNumberArea->update(0, rect.y(), _lineNumberArea->width(), rect.height()); - } - - if (rect.contains(viewport()->rect())) - UpdateLineNumberAreaWidth(0); -} - -void cProcessLog::UpdateLineNumberAreaWidth(int /* newBlockCount */) -{ - setViewportMargins(LineNumberAreaWidth() + 10, 0, 10, 0); -} - -void cProcessLog::resizeEvent(QResizeEvent *event) -{ - assert(_lineNumberArea != nullptr); - - QPlainTextEdit::resizeEvent(event); - - QRect cr = contentsRect(); - _lineNumberArea->setGeometry(QRect(cr.left() + 2, cr.top(), LineNumberAreaWidth() + 2, cr.height())); -} diff --git a/src/runtime/src/ui/c_process_log.h b/src/runtime/src/ui/c_process_log.h deleted file mode 100644 index 5336f514..00000000 --- a/src/runtime/src/ui/c_process_log.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2023 CARIAD SE. - * - * This Source Code Form is subject to the terms of the Mozilla - * Public License, v. 2.0. If a copy of the MPL was not distributed - * with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -/* - * Copyright 2023 CARIAD SE. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef CPROCESS_LOG_H -#define CPROCESS_LOG_H - -#include -#include -#include -#include - -class cProcessLog : public QPlainTextEdit -{ - Q_OBJECT - - protected: - public: - cProcessLog(QWidget *parent = 0); - virtual ~cProcessLog(); - - // Dumps the console output into a file - void SaveToFile(const QString &filepath) const; - - // Clears the console - void Clear(); - - // Paints the lins number are - void LineNumberAreaPaintEvent(QPaintEvent *event); - - // Returns the width od the line numer area - int LineNumberAreaWidth() const; - - public slots: - void Log(const QString &log); - - void UpdateLineNumberArea(const QRect &rect, int dy); - - void UpdateLineNumberAreaWidth(int); - - protected: - void resizeEvent(QResizeEvent *event) override; - - private: - QWidget *_lineNumberArea{nullptr}; - QFontMetrics *_metrics{nullptr}; -}; - -class cLineNumberArea : public QWidget -{ - public: - cLineNumberArea(cProcessLog *editor) : QWidget(editor), codeEditor(editor) - { - // codeEditor = editor; - } - - QSize sizeHint() const override - { - return QSize(codeEditor->LineNumberAreaWidth(), 0); - } - - protected: - void paintEvent(QPaintEvent *event) override - { - codeEditor->LineNumberAreaPaintEvent(event); - } - - private: - cProcessLog *codeEditor; -}; - -#endif diff --git a/src/runtime/src/ui/c_runtime_control.cpp b/src/runtime/src/ui/c_runtime_control.cpp deleted file mode 100644 index 12b22d7d..00000000 --- a/src/runtime/src/ui/c_runtime_control.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2023 CARIAD SE. - * - * This Source Code Form is subject to the terms of the Mozilla - * Public License, v. 2.0. If a copy of the MPL was not distributed - * with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ -#include "c_runtime_control.h" - -cRuntimeControl::cRuntimeControl(QWidget *parent) : QWidget(parent) -{ - QHBoxLayout *runtimeLayout = new QHBoxLayout; - runtimeBtn = new QLabel(this); - - runtimeLayout->addWidget(runtimeBtn, 100, Qt::AlignCenter); - - setLayout(runtimeLayout); - - isRunning = false; - UpdateControl(); -} - -void cRuntimeControl::mousePressEvent(QMouseEvent *event) -{ - if (isRunning) - { - emit Abort(); - isRunning = false; - } - else - { - isRunning = true; - emit Run(); - } - - UpdateControl(); -} -void cRuntimeControl::UpdateControl() -{ - if (isRunning) - { - QPixmap pixmap(":/icons/pause.png"); - - runtimeBtn->setPixmap(pixmap); - runtimeBtn->setMask(pixmap.mask()); - } - else - { - QPixmap pixmap(":/icons/run.png"); - - runtimeBtn->setPixmap(pixmap); - runtimeBtn->setMask(pixmap.mask()); - } -} - -bool cRuntimeControl::IsRunning() const -{ - return isRunning; -} - -void cRuntimeControl::FinishedExecution() -{ - isRunning = false; - UpdateControl(); -} diff --git a/src/runtime/src/ui/c_runtime_control.h b/src/runtime/src/ui/c_runtime_control.h deleted file mode 100644 index 9c3280b2..00000000 --- a/src/runtime/src/ui/c_runtime_control.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2023 CARIAD SE. - * - * This Source Code Form is subject to the terms of the Mozilla - * Public License, v. 2.0. If a copy of the MPL was not distributed - * with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ -#ifndef CRUNTIME_CONTROL_H -#define CRUNTIME_CONTROL_H - -#include -#include -#include -#include - -class cRuntimeControl : public QWidget -{ - Q_OBJECT - - protected: - QLabel *runtimeBtn; - - public: - cRuntimeControl(QWidget *parent = 0); - - bool IsRunning() const; - signals: - void Abort(); - - void Run(); - - public slots: - void FinishedExecution(); - - protected: - void mousePressEvent(QMouseEvent *event); - - void UpdateControl(); - - bool isRunning; -}; - -#endif diff --git a/src/runtime/src/ui/c_runtime_thread.cpp b/src/runtime/src/ui/c_runtime_thread.cpp deleted file mode 100644 index ccf2b07b..00000000 --- a/src/runtime/src/ui/c_runtime_thread.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright 2023 CARIAD SE. - * - * This Source Code Form is subject to the terms of the Mozilla - * Public License, v. 2.0. If a copy of the MPL was not distributed - * with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ -#include "c_runtime_thread.h" - -#include "c_process_log.h" -#include "common/config_format/c_configuration.h" -#include "common/config_format/c_configuration_checker_bundle.h" -#include "common/config_format/c_configuration_report_module.h" - -void cRuntimeThread::Initialize(cProcessLog *const processLog, cConfiguration *const configuration, - const QString &configurationPath) -{ - _abortExecution = false; - _myConfiguration = configuration; - _myConfigurationPath = configurationPath; - _myLog = processLog; -} - -const QString cRuntimeThread::GetApplicationDir() -{ - return QCoreApplication::applicationDirPath() + "/"; -} - -const fs::path cRuntimeThread::GetWorkingDir() -{ - return fs::current_path(); -} - -void cRuntimeThread::Abort() -{ - _abortExecution = true; -} - -bool cRuntimeThread::IsRunning() const -{ - return isRunning(); -} - -void cRuntimeThread::run() -{ - if (nullptr == _myConfiguration) - return; - - emit Log(QString("-------------------------------------------------------------")); - emit Log(QString("---- Cleanup ------------------------------------------------")); - emit Log(QString("-------------------------------------------------------------")); - - for (auto &pFilePath : fs::directory_iterator(GetWorkingDir())) - { - std::string strFileName = pFilePath.path().string(); - GetFileName(&strFileName, false); - - if (StringEndsWith(strFileName, ".xqar")) - { - QString output = QString(" > Delete '%1'.").arg(strFileName.c_str()); - - emit Log(output); - - // Delete file - QFile file(strFileName.c_str()); - file.remove(); - } - } - - emit Log(""); - - // Process CheckerBundles - std::vector checkerBundle = _myConfiguration->GetCheckerBundles(); - std::vector::const_iterator bundleIt = checkerBundle.cbegin(); - - QStringList defaultParams; - defaultParams.append(_myConfigurationPath); - - for (; bundleIt != checkerBundle.cend() && !_abortExecution; bundleIt++) - { - ExecuteProcess(GetApplicationDir() + (*bundleIt)->GetCheckerBundleApplication().c_str(), defaultParams); - } - - // Process ResultPooling - ExecuteProcess(GetApplicationDir() + "ResultPooling.exe", {""}); - - // Process ReportModules - std::vector reportModules = _myConfiguration->GetReportModules(); - std::vector::const_iterator reportModuleIt = reportModules.cbegin(); - - for (; reportModuleIt != reportModules.cend() && !_abortExecution; reportModuleIt++) - { - ExecuteProcess(GetApplicationDir() + (*reportModuleIt)->GetReportModuleApplication().c_str(), defaultParams); - } - - emit Log(""); - emit Log(QString("-------------------------------------------------------------")); - emit Log(QString("---- Finished -----------------------------------------------")); - emit Log(QString("-------------------------------------------------------------")); - - emit Finished(); -} - -int cRuntimeThread::ExecuteProcess(const QString &processName, const QStringList ¶ms) -{ - QProcess process; - - emit Log(QString("-------------------------------------------------------------")); - emit Log(QString("---- Run %1").arg(processName.toLocal8Bit().data())); - emit Log(QString("-------------------------------------------------------------")); - - std::string processExec = processName.toLocal8Bit().data(); - - if (!StringEndsWith(processExec, ".exe")) - processExec = processExec.append(".exe"); - - if (!CheckIfFileExists(processExec)) - { - emit Log(""); - emit Log(QString("Executeable '%1' not found. Abort.").arg(processName.toLocal8Bit().data())); - emit Log(""); - } - - process.start(processName, params); - process.waitForStarted(); - - while (process.state() == QProcess::Running) - { - if (_abortExecution) - { - process.terminate(); - process.waitForFinished(); - - QString stdOut = QString(process.readAllStandardOutput()); - QString stdErr = QString(process.readAllStandardError()); - - if (stdOut.count() > 0) - emit Log(stdOut); - - if (stdErr.count() > 0) - emit Log(stdErr); - - return -1; - } - - process.waitForFinished(1000); - - QString stdOut = QString(process.readAllStandardOutput()); - QString stdErr = QString(process.readAllStandardError()); - - if (stdOut.count() > 0) - emit Log(stdOut); - - if (stdErr.count() > 0) - emit Log(stdErr); - } - - return 0; -} diff --git a/src/runtime/src/ui/c_runtime_thread.h b/src/runtime/src/ui/c_runtime_thread.h deleted file mode 100644 index 3d6da609..00000000 --- a/src/runtime/src/ui/c_runtime_thread.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2023 CARIAD SE. - * - * This Source Code Form is subject to the terms of the Mozilla - * Public License, v. 2.0. If a copy of the MPL was not distributed - * with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ -#ifndef CRUNTIME_THREAD_H -#define CRUNTIME_THREAD_H - -#include -#include -#include - -#include "common/qc4openx_filesystem.h" - -class cConfiguration; -class cProcessLog; - -// Implementation of the thread which runs the execution -class cRuntimeThread : public QThread -{ - Q_OBJECT - - public: - void Initialize(cProcessLog *const, cConfiguration *const, const QString &); - - void Abort(); - - bool IsRunning() const; - - /*! - * Executes a Process with a given name and params - * - * \param processName - * \param params - * \return - */ - int ExecuteProcess(const QString &processName, const QStringList ¶ms); - - signals: - void Log(QString log); - - void Finished(); - - protected: - void run(); - - bool _abortExecution{false}; - const cConfiguration *_myConfiguration{nullptr}; - const cProcessLog *_myLog{nullptr}; - QString _myConfigurationPath; - - /** - * Get application directory - * - * @return directory, where the application is installed - */ - const QString GetApplicationDir(); - - /** - * Get working directory - * - * @return directory, from where the application is started - */ - const fs::path GetWorkingDir(); -}; - -#endif diff --git a/src/runtime/src/ui/c_runtime_window.cpp b/src/runtime/src/ui/c_runtime_window.cpp index d0ab268a..5fe8e492 100644 --- a/src/runtime/src/ui/c_runtime_window.cpp +++ b/src/runtime/src/ui/c_runtime_window.cpp @@ -20,18 +20,15 @@ #include "common/result_format/c_result_container.h" #include "../c_configuration_validator.h" -#include "c_process_log.h" #include "c_process_view.h" -#include "c_runtime_control.h" const QString cRuntimeWindow::DEFAULT_XODR_CONFIG = "DefaultXodrConfiguration.xml"; const QString cRuntimeWindow::DEFAULT_XOSC_CONFIG = "DefaultXoscConfiguration.xml"; cRuntimeWindow::cRuntimeWindow(const std::string &strConfigurationFilepath, const std::string &xodrFile, - const std::string &xoscFile, const bool bAutostart, QWidget *parent) + const std::string &xoscFile, QWidget *parent) : QMainWindow(parent) { - _autostart = bAutostart; QAction *newAction = new QAction(tr("&New"), this); newAction->setShortcuts(QKeySequence::New); @@ -52,24 +49,12 @@ cRuntimeWindow::cRuntimeWindow(const std::string &strConfigurationFilepath, cons saveAsAction->setStatusTip(tr("Save configuration")); connect(saveAsAction, &QAction::triggered, this, &cRuntimeWindow::SaveAsConfigurationFile); - QAction *clearConsoleAction = new QAction(tr("Clear"), this); - clearConsoleAction->setStatusTip(tr("Clear console")); - connect(clearConsoleAction, &QAction::triggered, this, &cRuntimeWindow::ClearConsole); - - QAction *saveConsoleAction = new QAction(tr("Save"), this); - saveConsoleAction->setStatusTip(tr("Save console output")); - connect(saveConsoleAction, &QAction::triggered, this, &cRuntimeWindow::SaveConsole); - auto fileMenu = menuBar()->addMenu(tr("&File")); fileMenu->addAction(newAction); fileMenu->addAction(openAction); fileMenu->addAction(saveAction); fileMenu->addAction(saveAsAction); - auto consoleMenu = menuBar()->addMenu(tr("&Console")); - consoleMenu->addAction(clearConsoleAction); - consoleMenu->addAction(saveConsoleAction); - QSplitter *splitter = new QSplitter(Qt::Horizontal); QWidget *processWidget = new QWidget(this); @@ -99,24 +84,15 @@ cRuntimeWindow::cRuntimeWindow(const std::string &strConfigurationFilepath, cons _processView->setRootIsDecorated(true); _processView->setHeaderHidden(true); - auto runtimeControl = new cRuntimeControl(this); - processLayout->addWidget(processLabel); processLayout->addWidget(_processView, 2); processLayout->addWidget(processButtonBar, 0); - processLayout->addWidget(runtimeControl, 0); processLayout->setContentsMargins(3, 6, 3, 3); processWidget->setLayout(processLayout); splitter->addWidget(processWidget); QWidget *outputWidget = new QWidget(this); QVBoxLayout *outputLayout = new QVBoxLayout; - QLabel *outputLabel = new QLabel(outputWidget); - outputLabel->setText("Console Output"); - outputLabel->setStyleSheet("font-weight: bold;"); - _processLog = new cProcessLog(this); - outputLayout->addWidget(outputLabel); - outputLayout->addWidget(_processLog); outputLayout->setContentsMargins(3, 6, 3, 3); outputWidget->setLayout(outputLayout); splitter->addWidget(outputWidget); @@ -132,16 +108,6 @@ cRuntimeWindow::cRuntimeWindow(const std::string &strConfigurationFilepath, cons connect(_processView, SIGNAL(ExecuteProcessAndAddConfiguration(QString)), this, SLOT(ExecuteProcessAndAddConfiguration(QString))); - connect(runtimeControl, &cRuntimeControl::Run, this, &cRuntimeWindow::Run); - connect(runtimeControl, &cRuntimeControl::Abort, this, &cRuntimeWindow::Abort); - - connect(&_runningThread, SIGNAL(Log(QString)), _processLog, SLOT(Log(QString))); - connect(this, SIGNAL(Log(QString)), _processLog, SLOT(Log(QString))); - - connect(&_runningThread, SIGNAL(Finished()), runtimeControl, SLOT(FinishedExecution())); - connect(&_runningThread, SIGNAL(Finished()), runtimeControl, SLOT(FinishedExecution())); - connect(this, SIGNAL(Finished()), runtimeControl, SLOT(FinishedExecution())); - // Set the size of the application of the half size of desktop QSize quarterDesktopSize = QDesktopWidget().availableGeometry(this).size() * 0.5f; resize(quarterDesktopSize); @@ -191,6 +157,27 @@ const QString cRuntimeWindow::GetWorkingDir() return QString::fromStdString(fs::current_path().string()); } + +bool cRuntimeWindow::ValidateAndWrite(cConfiguration& configuration, const std::string& filePath){ + std::string message = ""; + if (!cConfigurationValidator::ValidateConfiguration(&configuration, + message)) { + std::stringstream ssDetails; + + ssDetails << "Configuration is invalid." << std::endl << std::endl; + ssDetails << "Message: " << std::endl; + ssDetails << message; + ssDetails << std::endl << std::endl; + ssDetails << "Please fix it before saving configuration file"; + + QMessageBox::warning(this, tr("Error"), tr(ssDetails.str().c_str()), + QMessageBox::Ok); + return false; + } + configuration.WriteConfigurationToFile(filePath); + return true; +} + void cRuntimeWindow::OpenConfigurationFile() { QString filePath = @@ -200,7 +187,7 @@ void cRuntimeWindow::OpenConfigurationFile() ShowConfiguration(&_currentConfiguration); } -bool cRuntimeWindow::SaveConfigurationFile(const bool bAutostart) +bool cRuntimeWindow::SaveConfigurationFile() { if (!_currentConfigurationPath.isEmpty()) { @@ -218,18 +205,18 @@ bool cRuntimeWindow::SaveConfigurationFile(const bool bAutostart) else { QMessageBox::StandardButton reply = QMessageBox::NoButton; - if (!bAutostart) - { - reply = QMessageBox::question(this, "Overwrite Configuration", - "Do you want to overwrite:\n" + fileInfo.fileName(), - QMessageBox::Yes | QMessageBox::No); - } + reply = QMessageBox::question(this, "Overwrite Configuration", + "Do you want to overwrite:\n" + fileInfo.fileName(), + QMessageBox::Yes | QMessageBox::No); - if (bAutostart || reply == QMessageBox::Yes) + if (reply == QMessageBox::Yes) { UpdateConfiguration(); - _currentConfiguration.WriteConfigurationToFile(_currentConfigurationPath.toLocal8Bit().data()); - + bool validation_result = false; + validation_result = ValidateAndWrite(_currentConfiguration, _currentConfigurationPath.toLocal8Bit().data()); + if (!validation_result){ + return false; + } _configurationChanged = false; SetupWindowTitle(); return true; @@ -248,6 +235,7 @@ bool cRuntimeWindow::SaveConfigurationFile(const bool bAutostart) return SaveAsConfigurationFile(); } + bool cRuntimeWindow::SaveAsConfigurationFile() { QString filePath = @@ -273,7 +261,11 @@ bool cRuntimeWindow::SaveAsConfigurationFile() UpdateConfiguration(); _currentConfigurationPath = filePath; - _currentConfiguration.WriteConfigurationToFile(filePath.toLocal8Bit().data()); + bool validation_result = false; + validation_result = ValidateAndWrite(_currentConfiguration, filePath.toLocal8Bit().data()); + if (!validation_result){ + return false; + } _configurationChanged = false; SetupWindowTitle(); @@ -343,7 +335,6 @@ void cRuntimeWindow::CreateNewConfiguration(cConfiguration *const configuration) void cRuntimeWindow::ShowConfiguration(cConfiguration *const configurationToBeShown) { - _processLog->clear(); _processView->LoadConfiguration(configurationToBeShown); @@ -356,26 +347,6 @@ void cRuntimeWindow::NewConfiguration() ShowConfiguration(&_currentConfiguration); } -void cRuntimeWindow::closeEvent(QCloseEvent * /*event*/) -{ - _runningThread.Abort(); - _runningThread.wait(); -} - -void cRuntimeWindow::ClearConsole() -{ - _processLog->Clear(); -} - -void cRuntimeWindow::SaveConsole() -{ - QString filePath = QFileDialog::getSaveFileName(this, tr("Console Dump"), GetWorkingDir(), tr("Log (*.log)")); - - if (!filePath.isEmpty()) - { - _processLog->SaveToFile(filePath); - } -} void cRuntimeWindow::OnChangeConfiguration() { @@ -384,63 +355,6 @@ void cRuntimeWindow::OnChangeConfiguration() SetupWindowTitle(); } -void cRuntimeWindow::Run() -{ - UpdateConfiguration(); - - std::string message = ""; - if (!cConfigurationValidator::ValidateConfiguration(&_currentConfiguration, message)) - { - std::stringstream ssDetails; - - ssDetails << "Configuration is invalid." << std::endl << std::endl; - ssDetails << "Message: " << std::endl; - ssDetails << message; - ssDetails << std::endl << std::endl; - ssDetails << "Please fix. Skip execution."; - - if (!_autostart) - { - QMessageBox::warning(this, tr("Error"), tr(ssDetails.str().c_str()), QMessageBox::Ok); - } - else - std::cerr << ssDetails.str(); - - emit Finished(); - return; - } - - // Save configuration if not saved - bool saved = SaveConfigurationFile(_autostart); - - if (!saved) - { - QMessageBox::warning(this, tr("Error"), tr("Skip execution. Please save the configuration first."), - QMessageBox::Ok); - - emit Finished(); - return; - } - - _processLog->Clear(); - - if (_runningThread.IsRunning()) - _runningThread.Abort(); - - _runningThread.Initialize(_processLog, &_currentConfiguration, _currentConfigurationPath); - - _runningThread.start(); -} - -void cRuntimeWindow::Abort() -{ - _runningThread.Abort(); -} - -bool cRuntimeWindow::IsRunning() const -{ - return _runningThread.IsRunning(); -} int cRuntimeWindow::ExecuteProcessAndAddConfiguration(const QString &processPath) { diff --git a/src/runtime/src/ui/c_runtime_window.h b/src/runtime/src/ui/c_runtime_window.h index f8c908ab..5a72254e 100644 --- a/src/runtime/src/ui/c_runtime_window.h +++ b/src/runtime/src/ui/c_runtime_window.h @@ -10,8 +10,8 @@ #include -#include "c_runtime_thread.h" #include "common/config_format/c_configuration.h" +#include "common/qc4openx_filesystem.h" class cProcessView; class cProcessLog; @@ -24,18 +24,15 @@ class cRuntimeWindow : public QMainWindow protected: cProcessView *_processView{nullptr}; - cProcessLog *_processLog{nullptr}; cConfiguration _currentConfiguration; QString _currentConfigurationPath; - cRuntimeThread _runningThread; bool _configurationChanged{false}; - bool _autostart{true}; public: cRuntimeWindow(const std::string &configurationFilePath, const std::string &xodrFile, const std::string &xoscFile, - const bool bAutostart, QWidget *parent = 0); + QWidget *parent = 0); /* * Loads a configuration from file to datastructure @@ -52,15 +49,6 @@ class cRuntimeWindow : public QMainWindow // Updates the internal configuration void UpdateConfiguration(); - // Returns true if the execution thread is running - bool IsRunning() const; - - public slots: - // Runs the process - void Run(); - - // Aborts the running process - void Abort(); private slots: // Open result file @@ -69,14 +57,10 @@ class cRuntimeWindow : public QMainWindow // SaveAs configuration file bool SaveAsConfigurationFile(); - // Save configuration file - bool SaveConfigurationFile(const bool); + bool ValidateAndWrite(cConfiguration& , const std::string&); - // Saves the console output - void SaveConsole(); - - // Clear the console output - void ClearConsole(); + // Save configuration file + bool SaveConfigurationFile(); // Creates a new Configuration void NewConfiguration(); @@ -118,8 +102,6 @@ class cRuntimeWindow : public QMainWindow */ const QString GetWorkingDir(); - // Handle application close - void closeEvent(QCloseEvent *bar); // Changes the window title of the application void SetupWindowTitle(); diff --git a/test/function/runtime/src/runtime_tester.cpp b/test/function/runtime/src/runtime_tester.cpp index 07b2f2c8..7c2fd7f8 100644 --- a/test/function/runtime/src/runtime_tester.cpp +++ b/test/function/runtime/src/runtime_tester.cpp @@ -30,23 +30,3 @@ TEST_F(cTesterRuntime, CmdHelp) ASSERT_TRUE_EXT(nRes == TestResult::ERR_NOERROR, strResultMessage.c_str()); } -TEST_F(cTesterRuntime, CmdConfig) -{ - // Implicit tested with PCB Test dbqa_roundtrip test_config_gui -} - -TEST_F(cTesterRuntime, CmdConfigAutostart) -{ - std::string strResultMessage; - - std::string strConfigFilePath = strTestFilesDir + "/" + "DemoCheckerBundle_config.xml"; - std::string strResultFilePath = strWorkingDir + "/" + "Result.xqar"; - - TestResult nRes = ExecuteCommand(strResultMessage, MODULE_NAME, "-config " + strConfigFilePath + " -autostart"); - ASSERT_TRUE_EXT(nRes == TestResult::ERR_NOERROR, strResultMessage.c_str()); - - // DemoCheckerBundle not found in bin (is in examples) --> no DemoCheckerBundle.xqar --> Result.xqar with no entries - - nRes |= CheckFileExists(strResultMessage, strResultFilePath); - ASSERT_TRUE_EXT(nRes == TestResult::ERR_NOERROR, strResultMessage.c_str()); -}