From 9b5cfb96d39dbc2aebafbb37a15e8dd78d9b5be0 Mon Sep 17 00:00:00 2001 From: Iakov 'Jake' Kirilenko Date: Sat, 23 May 2020 14:00:48 +0300 Subject: [PATCH] Fix different coding/C++ issues --- qslog/QsLog.cpp | 21 ++++++++--------- qslog/QsLog.h | 1 + qslog/QsLogDest.h | 2 ++ qslog/QsLogDestFile.h | 3 +++ .../differentOwnedPointerTest.cpp | 6 +++-- trikCommunicator/src/trikCommunicator.cpp | 2 +- .../src/abstractVirtualSensorWorker.cpp | 2 +- trikControl/src/configurerHelper.cpp | 4 ++-- trikControl/src/fifo.h | 2 +- trikControl/src/guiWorker.cpp | 2 +- trikControl/src/gyroSensor.cpp | 2 +- trikControl/src/tonePlayer.cpp | 6 ++--- trikGui/openSocketIndicator.cpp | 6 ++--- trikGui/openSocketIndicator.h | 4 ++-- trikHal/include/trikHal/mspUsbInterface.h | 1 + trikHal/src/stub/stubSystemConsole.h | 2 +- trikHal/src/trik/trikEventFile.cpp | 2 +- trikHal/src/trik/trikI2c.cpp | 4 ++-- .../src/trik/usbMsp/usbMSP430Interface.cpp | 23 ++++++++++--------- .../trikKernel/deinitializationHelper.h | 3 +++ .../trikKernel/differentOwnerPointer.h | 2 ++ trikKernel/include/trikKernel/version.h | 2 +- trikKernel/src/applicationInitHelper.cpp | 2 +- trikKernel/src/configurer.cpp | 10 ++------ trikNetwork/src/connection.cpp | 2 +- trikNetwork/src/mailboxServer.cpp | 6 ++--- trikNetwork/src/mailboxServer.h | 2 +- trikNetwork/src/trikServer.cpp | 6 ++--- .../PyTrikControl/PyTrikControl0.h | 4 ++-- trikScriptRunner/src/pythonEngineWorker.cpp | 3 +-- trikScriptRunner/src/pythonEngineWorker.h | 2 +- trikScriptRunner/src/scriptEngineWorker.cpp | 5 +--- trikScriptRunner/src/scriptThread.cpp | 4 ++-- trikScriptRunner/src/threading.cpp | 3 +-- trikScriptRunner/src/trikScriptRunner.cpp | 4 ++-- trikScriptRunner/src/trikVariablesServer.cpp | 2 +- 36 files changed, 80 insertions(+), 77 deletions(-) diff --git a/qslog/QsLog.cpp b/qslog/QsLog.cpp index c8a021eab..49bde023a 100644 --- a/qslog/QsLog.cpp +++ b/qslog/QsLog.cpp @@ -37,7 +37,7 @@ namespace QsLogging { -typedef QVector DestinationList; +using DestinationList = QVector; static const char TraceString[] = "TRACE"; static const char DebugString[] = "DEBUG"; @@ -47,7 +47,7 @@ static const char ErrorString[] = "ERROR"; static const char FatalString[] = "FATAL"; // not using Qt::ISODate because we need the milliseconds too -static const QString fmtDateTime("yyyy-MM-ddThh:mm:ss.zzz"); +static auto fmtDateTime = "yyyy-MM-ddThh:mm:ss.zzz"; static Logger* sInstance = 0; @@ -77,9 +77,10 @@ static const char* LevelToText(Level theLevel) class LogWriterRunnable : public QRunnable { + Q_DISABLE_COPY(LogWriterRunnable) public: LogWriterRunnable(QString message, Level level); - virtual void run(); + void run() override; private: QString mMessage; @@ -90,16 +91,16 @@ class LoggerImpl { public: LoggerImpl(); - + friend class Logger; +private: QThreadPool threadPool; QMutex logMutex; - Level level; + Level level { Level::InfoLevel }; DestinationList destList; }; LogWriterRunnable::LogWriterRunnable(QString message, Level level) - : QRunnable() - , mMessage(message) + : mMessage(message) , mLevel(level) { } @@ -111,7 +112,6 @@ void LogWriterRunnable::run() LoggerImpl::LoggerImpl() - : level(InfoLevel) { // assume at least file + console destList.reserve(2); @@ -224,9 +224,8 @@ void Logger::enqueueWrite(const QString& message, Level level) void Logger::write(const QString& message, Level level) { QMutexLocker lock(&d->logMutex); - for (DestinationList::iterator it = d->destList.begin(), - endIt = d->destList.end();it != endIt;++it) { - (*it)->write(message, level); + for (auto &it:d->destList) { + it->write(message, level); } } diff --git a/qslog/QsLog.h b/qslog/QsLog.h index 6e5bd28d9..71e0e4b23 100644 --- a/qslog/QsLog.h +++ b/qslog/QsLog.h @@ -57,6 +57,7 @@ class QSLOG_SHARED_OBJECT Logger /// log message. class QSLOG_SHARED_OBJECT Helper { + Q_DISABLE_COPY (Helper) public: explicit Helper(Level logLevel) : level(logLevel), diff --git a/qslog/QsLogDest.h b/qslog/QsLogDest.h index 4bb116875..800da949f 100644 --- a/qslog/QsLogDest.h +++ b/qslog/QsLogDest.h @@ -44,10 +44,12 @@ namespace QsLogging class QSLOG_SHARED_OBJECT Destination { + Q_DISABLE_COPY(Destination) public: typedef void (*LogFunction)(const QString &message, Level level); public: + Destination() = default; virtual ~Destination(); virtual void write(const QString& message, Level level) = 0; virtual bool isValid() = 0; // returns whether the destination was created correctly diff --git a/qslog/QsLogDestFile.h b/qslog/QsLogDestFile.h index a1e515c3a..bd8cc7b31 100644 --- a/qslog/QsLogDestFile.h +++ b/qslog/QsLogDestFile.h @@ -35,7 +35,9 @@ namespace QsLogging { class RotationStrategy { + Q_DISABLE_COPY(RotationStrategy) public: + RotationStrategy() = default; virtual ~RotationStrategy(); virtual void setInitialInfo(const QFile &file) = 0; @@ -49,6 +51,7 @@ class RotationStrategy class NullRotationStrategy : public RotationStrategy { public: + NullRotationStrategy() = default; virtual void setInitialInfo(const QFile &) {} virtual void includeMessageInCalculation(const QString &) {} virtual bool shouldRotate() { return false; } diff --git a/tests/trikKernelTests/differentOwnedPointerTest.cpp b/tests/trikKernelTests/differentOwnedPointerTest.cpp index 546921189..6875a36b4 100644 --- a/tests/trikKernelTests/differentOwnedPointerTest.cpp +++ b/tests/trikKernelTests/differentOwnedPointerTest.cpp @@ -21,13 +21,14 @@ using namespace trikKernel; /// Helper class that provides something to construct and destruct and a means to verify its destruction. class TestHelper { + Q_DISABLE_COPY(TestHelper) public: /// Class that can report that it was destroyed. class Destructable { + Q_DISABLE_COPY(Destructable) public: - Destructable(TestHelper &parent) - : mParent(parent) + explicit Destructable(TestHelper &parent) : mParent(parent) { } @@ -40,6 +41,7 @@ class TestHelper TestHelper &mParent; }; + TestHelper() = default; ~TestHelper() { if (!mDestroyed) diff --git a/trikCommunicator/src/trikCommunicator.cpp b/trikCommunicator/src/trikCommunicator.cpp index 5e728f31b..16257dce7 100644 --- a/trikCommunicator/src/trikCommunicator.cpp +++ b/trikCommunicator/src/trikCommunicator.cpp @@ -47,7 +47,7 @@ TrikCommunicator::TrikCommunicator(const trikKernel::DifferentOwnerPointer #include -#include +#include #include diff --git a/trikControl/src/configurerHelper.cpp b/trikControl/src/configurerHelper.cpp index 9c732d126..64f530f9a 100644 --- a/trikControl/src/configurerHelper.cpp +++ b/trikControl/src/configurerHelper.cpp @@ -32,7 +32,7 @@ int ConfigurerHelper::configureInt(const trikKernel::Configurer &configurer, Dev bool ok = false; int parameter = configurer.attributeByPort(port, parameterName).toInt(&ok, 0); if (!ok) { - QLOG_ERROR() << QString("Incorrect configuration for parameter \"%1\" for port \"%2\": \"%3\" ") + QLOG_ERROR() << QString(R"(Incorrect configuration for parameter "%1" for port "%2": "%3" )") .arg(parameterName).arg(port).arg(configurer.attributeByPort(port, parameterName)); state.fail(); return 0; @@ -52,7 +52,7 @@ qreal ConfigurerHelper::configureReal(const trikKernel::Configurer &configurer, bool ok = false; const qreal parameter = configurer.attributeByPort(port, parameterName).toDouble(&ok); if (!ok) { - QLOG_ERROR() << QString("Incorrect configuration for parameter \"%1\" for port \"%2\": \"%3\" ") + QLOG_ERROR() << QString(R"(Incorrect configuration for parameter "%1" for port "%2": "%3" )") .arg(parameterName).arg(port).arg(configurer.attributeByPort(port, parameterName)); state.fail(); diff --git a/trikControl/src/fifo.h b/trikControl/src/fifo.h index 6b0e70698..b30b2c121 100644 --- a/trikControl/src/fifo.h +++ b/trikControl/src/fifo.h @@ -66,7 +66,7 @@ public slots: bool hasData() const override; private slots: - void onNewLine(const QString &data); + void onNewLine(const QString &line); void onNewData(const QVector &data); void onReadError(); diff --git a/trikControl/src/guiWorker.cpp b/trikControl/src/guiWorker.cpp index 78c763684..04630f153 100644 --- a/trikControl/src/guiWorker.cpp +++ b/trikControl/src/guiWorker.cpp @@ -185,5 +185,5 @@ void GuiWorker::repaintGraphicsWidget() QColor GuiWorker::colorByName(const QString &name) { - return QColor(name.toLower()); + return {name.toLower()}; } diff --git a/trikControl/src/gyroSensor.cpp b/trikControl/src/gyroSensor.cpp index 79795ee6d..9e35ccca5 100644 --- a/trikControl/src/gyroSensor.cpp +++ b/trikControl/src/gyroSensor.cpp @@ -292,5 +292,5 @@ QVector3D GyroSensor::getEulerAngles(const QQuaternion &q) pitch = pitch * RAD_TO_MDEG; yaw = yaw * RAD_TO_MDEG; roll = roll * RAD_TO_MDEG; - return QVector3D(pitch, roll, yaw); + return {pitch, roll, yaw}; } diff --git a/trikControl/src/tonePlayer.cpp b/trikControl/src/tonePlayer.cpp index 8604516ca..7137e7f8d 100644 --- a/trikControl/src/tonePlayer.cpp +++ b/trikControl/src/tonePlayer.cpp @@ -48,9 +48,9 @@ void TonePlayer::initializeAudio() } } -void TonePlayer::play(int hzFreq, int msDuration) +void TonePlayer::play(int freqHz, int durationMs) { - mDevice->start(hzFreq); + mDevice->start(freqHz); const auto state = mOutput->state(); QLOG_INFO() << "Device started. Output state is" << state; switch (state) { @@ -74,7 +74,7 @@ void TonePlayer::play(int hzFreq, int msDuration) break; } - mTimer.setInterval(msDuration); + mTimer.setInterval(durationMs); mTimer.start(); } diff --git a/trikGui/openSocketIndicator.cpp b/trikGui/openSocketIndicator.cpp index 572b0b5e0..a4092f099 100644 --- a/trikGui/openSocketIndicator.cpp +++ b/trikGui/openSocketIndicator.cpp @@ -16,13 +16,13 @@ using namespace trikGui; -OpenSocketIndicator::OpenSocketIndicator(const QString &openPicFile +OpenSocketIndicator::OpenSocketIndicator(const QString &openFilePic , bool status , QWidget *parent) : QLabel(parent) - , mOpenPic(openPicFile) + , mOpenPic(openFilePic) { - setPixmap(openPicFile); + setPixmap(openFilePic); status ? show() : hide(); } diff --git a/trikGui/openSocketIndicator.h b/trikGui/openSocketIndicator.h index f2da2a683..bae4207c9 100644 --- a/trikGui/openSocketIndicator.h +++ b/trikGui/openSocketIndicator.h @@ -29,9 +29,9 @@ class OpenSocketIndicator : public QLabel { Q_OBJECT public: - /// @param openFile, closedFile - paths to pictures for open and closed connection status + /// @param openFilePic - path to picture for open connection status /// @param status - initial connection status - OpenSocketIndicator(const QString &openFile, bool status, QWidget *parent = 0); + OpenSocketIndicator(const QString &openFilePic, bool status, QWidget *parent = 0); public slots: /// Changes status of indicator to a given value. diff --git a/trikHal/include/trikHal/mspUsbInterface.h b/trikHal/include/trikHal/mspUsbInterface.h index 7f8df815e..9f9b368af 100644 --- a/trikHal/include/trikHal/mspUsbInterface.h +++ b/trikHal/include/trikHal/mspUsbInterface.h @@ -21,6 +21,7 @@ namespace trikHal { /// Communicates with MSP processor over USB bus. class MspUsbInterface { + Q_DISABLE_COPY(MspUsbInterface) public: MspUsbInterface() = default; virtual ~MspUsbInterface() = default; diff --git a/trikHal/src/stub/stubSystemConsole.h b/trikHal/src/stub/stubSystemConsole.h index 6c23ef24b..d547904ae 100644 --- a/trikHal/src/stub/stubSystemConsole.h +++ b/trikHal/src/stub/stubSystemConsole.h @@ -26,7 +26,7 @@ class StubSystemConsole : public SystemConsoleInterface int system(const QString &command) override; bool startProcess(const QString &processName, const QStringList &arguments) override; bool startProcessSynchronously(const QString &processName, const QStringList &arguments - , QString * output = nullptr) override; + , QString * output) override; }; } diff --git a/trikHal/src/trik/trikEventFile.cpp b/trikHal/src/trik/trikEventFile.cpp index 80f31f578..b4b1ab486 100644 --- a/trikHal/src/trik/trikEventFile.cpp +++ b/trikHal/src/trik/trikEventFile.cpp @@ -91,7 +91,7 @@ bool TrikEventFile::close() } if (::close(mEventFileDescriptor) != 0) { - QLOG_ERROR() << QString("%1: close failed: %2").arg(mFileName).arg(strerror(errno)); + QLOG_ERROR() << QString("%1: close failed: %2").arg(mFileName, strerror(errno)); return false; } diff --git a/trikHal/src/trik/trikI2c.cpp b/trikHal/src/trik/trikI2c.cpp index 62b00cfb3..9ee378837 100644 --- a/trikHal/src/trik/trikI2c.cpp +++ b/trikHal/src/trik/trikI2c.cpp @@ -101,8 +101,8 @@ int TrikI2c::read(const QByteArray &data) if (data.size() == 2) { return i2c_smbus_read_word_data(mDeviceFileDescriptor, data[0]); } else { - __u8 buffer[4] = {0}; - i2c_smbus_read_i2c_block_data(mDeviceFileDescriptor, data[0], 4, buffer); + std::array buffer {}; + i2c_smbus_read_i2c_block_data(mDeviceFileDescriptor, data[0], 4, buffer.data()); return buffer[3] << 24 | buffer[2] << 16 | buffer[1] << 8 | buffer[0]; } } diff --git a/trikHal/src/trik/usbMsp/usbMSP430Interface.cpp b/trikHal/src/trik/usbMsp/usbMSP430Interface.cpp index dcfadb5e9..b91c39dd8 100644 --- a/trikHal/src/trik/usbMsp/usbMSP430Interface.cpp +++ b/trikHal/src/trik/usbMsp/usbMSP430Interface.cpp @@ -15,13 +15,13 @@ * Author: Rostislav Varzar */ -#include -#include -#include -#include +#include +#include +#include +#include #include #include -#include +#include #include #include @@ -53,6 +53,7 @@ uint8_t addr_table_i2c_usb[84] = // Correspondence address table (between I2C an /// Delays class class Sleeper : public QThread { + Q_OBJECT public: static void usleep(unsigned long usecs){QThread::usleep(usecs);} static void msleep(unsigned long msecs){QThread::msleep(msecs);} @@ -717,20 +718,20 @@ uint32_t read_URM04_dist(uint8_t dev_addr, uint8_t urm04_addr) uint8_t pack2[6] = {0x55, 0xAA, urm04_addr, 0x00, 0x02, crc_b}; uint8_t buf1[8] = {0}; // Trigger device - for (int i = 0; i < 6; i++) + for (auto x : pack1) { - makeWriteRegPacket(s1, dev_addr, UUDAT, pack1[i]); + makeWriteRegPacket(s1, dev_addr, UUDAT, x); sendUSBPacket(s1, s1); } // Wait about 400 ms Sleeper::msleep(400); // Read distance - for (int i = 0; i < 6; i++) + for (auto x: pack2) { - makeWriteRegPacket(s1, dev_addr, UUDAT, pack2[i]); + makeWriteRegPacket(s1, dev_addr, UUDAT, x); sendUSBPacket(s1, s1); } - for (int i = 0; i < 8; i++) + for (auto &x: buf1) { do { @@ -739,7 +740,7 @@ uint32_t read_URM04_dist(uint8_t dev_addr, uint8_t urm04_addr) errcode = decodeReceivedPacket(s2, devaddr, funccode, regaddr, regval); tmout ++; } while (((devaddr != dev_addr) || (regaddr != UUDAT)) && (tmout < TIME_OUT)); - buf1[i] = regval; + x = regval; } crc1 = buf1[0] + buf1[1] + buf1[2] + buf1[3] + buf1[4] + buf1[5] + buf1[6]; if (crc1 != buf1[7]) diff --git a/trikKernel/include/trikKernel/deinitializationHelper.h b/trikKernel/include/trikKernel/deinitializationHelper.h index 18d7920aa..803d27c4d 100644 --- a/trikKernel/include/trikKernel/deinitializationHelper.h +++ b/trikKernel/include/trikKernel/deinitializationHelper.h @@ -13,6 +13,7 @@ * limitations under the License. */ #pragma once +#include namespace trikKernel { @@ -21,7 +22,9 @@ namespace trikKernel { /// shuts down. class DeinitializationHelper { + Q_DISABLE_COPY(DeinitializationHelper) public: + DeinitializationHelper() = default; /// Here is all the magic - runs zero-time event loop when this object is destroyed. ~DeinitializationHelper(); }; diff --git a/trikKernel/include/trikKernel/differentOwnerPointer.h b/trikKernel/include/trikKernel/differentOwnerPointer.h index 6e65b54a8..19685a893 100644 --- a/trikKernel/include/trikKernel/differentOwnerPointer.h +++ b/trikKernel/include/trikKernel/differentOwnerPointer.h @@ -24,6 +24,8 @@ namespace trikKernel { template class DifferentOwnerPointer { public: + ~DifferentOwnerPointer() = default; + /// Copy constructor. Preserves ownership semantics of a copied object. DifferentOwnerPointer(const DifferentOwnerPointer &other) : mPointer(other.mPointer) diff --git a/trikKernel/include/trikKernel/version.h b/trikKernel/include/trikKernel/version.h index 1f1ca1535..dfcc5a5a5 100644 --- a/trikKernel/include/trikKernel/version.h +++ b/trikKernel/include/trikKernel/version.h @@ -18,6 +18,6 @@ namespace trikKernel { -const QString version = "3.1.4"; +const auto version = "3.1.4"; } diff --git a/trikKernel/src/applicationInitHelper.cpp b/trikKernel/src/applicationInitHelper.cpp index 9faafe4cb..f5f53e0e1 100644 --- a/trikKernel/src/applicationInitHelper.cpp +++ b/trikKernel/src/applicationInitHelper.cpp @@ -46,7 +46,7 @@ ApplicationInitHelper::ApplicationInitHelper(QCoreApplication &app) trikKernel::TranslationsHelper::initLocale(app.arguments().contains("--no-locale") || app.arguments().contains("-no-locale")); - QApplication *guiApp = dynamic_cast(&app); + auto *guiApp = qobject_cast(&app); if (guiApp) { QFont font(guiApp->font()); font.setPixelSize(18); diff --git a/trikKernel/src/configurer.cpp b/trikKernel/src/configurer.cpp index 59a9d7424..a68a2587f 100644 --- a/trikKernel/src/configurer.cpp +++ b/trikKernel/src/configurer.cpp @@ -22,13 +22,7 @@ #include "exceptions/malformedConfigException.h" #include "fileUtils.h" -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - #define QDomNamedNodeMapLengthType unsigned -#else - #define QDomNamedNodeMapLengthType int -#endif - - +using QDomNamedNodeMapLengthType = int; using namespace trikKernel; Configurer::Configurer(const QString &systemConfigFileName, const QString &modelConfigFileName) @@ -36,7 +30,7 @@ Configurer::Configurer(const QString &systemConfigFileName, const QString &model const QDomElement systemConfig = trikKernel::FileUtils::readXmlFile(systemConfigFileName); const QDomElement modelConfig = trikKernel::FileUtils::readXmlFile(modelConfigFileName); - auto parseSection = [&systemConfig](const QString §ionName, std::function action) { + auto parseSection = [&systemConfig](const QString §ionName, const std::function &action) { const QDomNodeList section = systemConfig.elementsByTagName(sectionName); if (section.size() != 1) { throw MalformedConfigException("'" + sectionName + "' element shall appear exactly once in config"); diff --git a/trikNetwork/src/connection.cpp b/trikNetwork/src/connection.cpp index 6b6f342eb..b4dcea0a9 100644 --- a/trikNetwork/src/connection.cpp +++ b/trikNetwork/src/connection.cpp @@ -207,7 +207,7 @@ void Connection::handleIncomingData(const QByteArray &data) if (data == "keepalive") { return; } if (data == "version") { - send(QString("version: " + trikKernel::version).toUtf8()); + send(QString("version: %1").arg(trikKernel::version).toUtf8()); } else { processData(data); } diff --git a/trikNetwork/src/mailboxServer.cpp b/trikNetwork/src/mailboxServer.cpp index eed0c9e2a..3cf40f351 100644 --- a/trikNetwork/src/mailboxServer.cpp +++ b/trikNetwork/src/mailboxServer.cpp @@ -41,7 +41,7 @@ bool MailboxServer::isConnected() mKnownRobotsLock.lockForRead(); for (auto &&endpoint : mKnownRobots) { Connection * const connection = this->connection(endpoint.ip, endpoint.port); - MailboxConnection * const mailboxConnection = dynamic_cast(connection); + auto *mailboxConnection = qobject_cast(connection); if (mailboxConnection && mailboxConnection->isConnected()) { result = true; break; @@ -271,7 +271,7 @@ void MailboxServer::send(const QString &message) void MailboxServer::onConnectionInfo(const QHostAddress &ip, int port, int hullNumber) { - QList toDelete; + QVector toDelete; mKnownRobotsLock.lockForRead(); for (auto &&endpoint : mKnownRobots) { if (endpoint == Endpoint{ip, port}) { @@ -357,7 +357,7 @@ void MailboxServer::saveSettings() mAuxiliaryInformationLock.unlock(); } -void MailboxServer::forEveryConnection(std::function method, int hullNumber) +void MailboxServer::forEveryConnection(const std::function &method, int hullNumber) { mKnownRobotsLock.lockForRead(); const auto endpoints = hullNumber == -1 ? mKnownRobots.values() : mKnownRobots.values(hullNumber); diff --git a/trikNetwork/src/mailboxServer.h b/trikNetwork/src/mailboxServer.h index 5dc847872..c0b60fc04 100644 --- a/trikNetwork/src/mailboxServer.h +++ b/trikNetwork/src/mailboxServer.h @@ -103,7 +103,7 @@ private slots: void loadSettings(); void saveSettings(); - void forEveryConnection(std::function method, int hullNumber = -1); + void forEveryConnection(const std::function &method, int hullNumber = -1); int mHullNumber; QHostAddress mMyIp; diff --git a/trikNetwork/src/trikServer.cpp b/trikNetwork/src/trikServer.cpp index 1ddf57fdd..c2fff2133 100644 --- a/trikNetwork/src/trikServer.cpp +++ b/trikNetwork/src/trikServer.cpp @@ -24,7 +24,7 @@ TrikServer::TrikServer(const std::function &connectionFactory) { qRegisterMetaType("qintptr"); qRegisterMetaType("quint16"); - connect(this, &TrikServer::startedConnection, [this](Connection *c) { + connect(this, &TrikServer::startedConnection, this, [this](Connection *c) { const bool firstConnection = mConnections.isEmpty(); mConnections.insert(c->thread(), c); if (firstConnection) { @@ -43,7 +43,7 @@ TrikServer::~TrikServer() } } - qDeleteAll(mConnections.keys()); + qDeleteAll(mConnections.keyBegin(), mConnections.keyEnd()); } void TrikServer::startServer(quint16 port) @@ -86,7 +86,7 @@ void TrikServer::startConnection(Connection * const connectionWorker) connect(connectionThread, &QThread::finished, connectionWorker, &Connection::deleteLater); connect(connectionThread, &QThread::finished, connectionThread, &QThread::deleteLater); connect(connectionThread, &QThread::started, this, [this, connectionWorker]() { - startedConnection(connectionWorker); + Q_EMIT startedConnection(connectionWorker); }); connect(connectionWorker, &Connection::disconnected, this, &TrikServer::onConnectionClosed); diff --git a/trikScriptRunner/PyTrikControl/PyTrikControl0.h b/trikScriptRunner/PyTrikControl/PyTrikControl0.h index adb3ee4e6..4c4dad7f7 100644 --- a/trikScriptRunner/PyTrikControl/PyTrikControl0.h +++ b/trikScriptRunner/PyTrikControl/PyTrikControl0.h @@ -99,7 +99,7 @@ inline trikControl::LedInterface* py_q_led() { return this->led(); } inline trikControl::LineSensorInterface* py_q_lineSensor(const QString& port) { return this->lineSensor(port); } inline trikControl::MarkerInterface* py_q_marker() { return this->marker(); } inline trikControl::MotorInterface* py_q_motor(const QString& port) { return this->motor(port); } -inline QStringList py_q_motorPorts(trikControl::MotorInterface::Type type) const { return this->motorPorts(type); } +inline QStringList py_q_motorPorts(trikControl::MotorInterface::Type type) { return this->motorPorts(type); } inline trikControl::ObjectSensorInterface* py_q_objectSensor(const QString& port) { return this->objectSensor(port); } inline void py_q_playSound(const QString& soundFileName) { this->playSound(soundFileName); } inline void py_q_playTone(int hzFreq, int msDuration) { this->playTone(hzFreq, msDuration); } @@ -108,7 +108,7 @@ inline QStringList py_q_pwmCapturePorts() const { return this->pwmCapturePorts( inline void py_q_reset() { this->reset(); } inline void py_q_say(const QString& text) { this->say(text); } inline trikControl::SensorInterface* py_q_sensor(const QString& port) { return this->sensor(port); } -inline QStringList py_q_sensorPorts(trikControl::SensorInterface::Type type) const { return this->sensorPorts(type); } +inline QStringList py_q_sensorPorts(trikControl::SensorInterface::Type type) { return this->sensorPorts(type); } inline trikControl::SoundSensorInterface* py_q_soundSensor(const QString& port) { return this->soundSensor(port); } inline void py_q_stop() { this->stop(); } inline void py_q_stopEventDevice(const QString& deviceFile) { this->stopEventDevice(deviceFile); } diff --git a/trikScriptRunner/src/pythonEngineWorker.cpp b/trikScriptRunner/src/pythonEngineWorker.cpp index 00848d463..2d30b3d30 100644 --- a/trikScriptRunner/src/pythonEngineWorker.cpp +++ b/trikScriptRunner/src/pythonEngineWorker.cpp @@ -48,7 +48,6 @@ PythonEngineWorker::PythonEngineWorker(trikControl::BrickInterface &brick : mBrick(brick) , mScriptExecutionControl(new ScriptExecutionControl(brick)) , mMailbox(mailbox) - , mState(ready) , mWorkingDirectory(trikKernel::Paths::userScriptsPath()) {} @@ -123,7 +122,7 @@ void PythonEngineWorker::init() PythonQt::init(PythonQt::RedirectStdOut | PythonQt::PythonAlreadyInitialized); connect(PythonQt::self(), &PythonQt::pythonStdErr, this, &PythonEngineWorker::updateErrorMessage); connect(PythonQt::self(), &PythonQt::pythonStdOut, this, [this](const QString& str){ - QTimer::singleShot(0, this, [this, str](){this->textInStdOut(str);}); + QTimer::singleShot(0, this, [this, str](){ Q_EMIT this->textInStdOut(str);}); mScriptExecutionControl->wait(0); }); PythonQtRegisterListTemplateConverter(QVector, uint8_t) diff --git a/trikScriptRunner/src/pythonEngineWorker.h b/trikScriptRunner/src/pythonEngineWorker.h index d8a09ce8b..d1533ddd5 100644 --- a/trikScriptRunner/src/pythonEngineWorker.h +++ b/trikScriptRunner/src/pythonEngineWorker.h @@ -152,7 +152,7 @@ private slots: QScopedPointer mScriptExecutionControl; trikNetwork::MailboxInterface * const mMailbox; // Does not have ownership. - State mState = State::ready; + State mState { State::ready }; /// Ensures that there is only one instance of StopScript running at any given time, to prevent unpredicted /// behavior when programs are started and stopped actively. diff --git a/trikScriptRunner/src/scriptEngineWorker.cpp b/trikScriptRunner/src/scriptEngineWorker.cpp index 0a0f9aeb0..60da19d8b 100644 --- a/trikScriptRunner/src/scriptEngineWorker.cpp +++ b/trikScriptRunner/src/scriptEngineWorker.cpp @@ -90,7 +90,7 @@ QScriptValue print(QScriptContext *context, QScriptEngine *engine) if (auto script = qobject_cast (scriptValue.toQObject())) { result.append('\n'); - QTimer::singleShot(0, script, [script, result](){script->textInStdOut(result);}); + QTimer::singleShot(0, script, [script, result](){ Q_EMIT script->textInStdOut(result);}); /// In case of user loop with `print' this gives some time for events to be processed script->wait(0); } @@ -112,9 +112,6 @@ ScriptEngineWorker::ScriptEngineWorker(trikControl::BrickInterface &brick , mMailbox(mailbox) , mScriptControl(scriptControl) , mThreading(this, scriptControl) - , mDirectScriptsEngine(nullptr) - , mScriptId(0) - , mState(ready) , mWorkingDirectory(trikKernel::Paths::userScriptsPath()) { connect(&mScriptControl, &ScriptExecutionControl::quitSignal, diff --git a/trikScriptRunner/src/scriptThread.cpp b/trikScriptRunner/src/scriptThread.cpp index b290149a8..48b91e5ab 100644 --- a/trikScriptRunner/src/scriptThread.cpp +++ b/trikScriptRunner/src/scriptThread.cpp @@ -85,8 +85,8 @@ bool ScriptThread::isEvaluating() const return mEngine->isEvaluating(); } - -/* TODO: Fix design error. This slot is called on wrong thread (probably) */ +// TODO: Fix design error. This slot is called on wrong thread (probably) +// mEngine must be accessed from the correct worker thread instead void ScriptThread::onGetVariables(const QString &propertyName) { if (mEngine != nullptr) { diff --git a/trikScriptRunner/src/threading.cpp b/trikScriptRunner/src/threading.cpp index cfb99f55a..73b3edd34 100644 --- a/trikScriptRunner/src/threading.cpp +++ b/trikScriptRunner/src/threading.cpp @@ -28,7 +28,6 @@ using namespace trikScriptRunner; Threading::Threading(ScriptEngineWorker *scriptWorker, ScriptExecutionControl &scriptControl) : QObject(scriptWorker) - , mResetStarted(false) , mScriptWorker(scriptWorker) , mScriptControl(scriptControl) , mMainScriptEngine(nullptr) @@ -47,7 +46,7 @@ void Threading::startMainThread(const QString &script) mFinishedThreads.clear(); mPreventFromStart.clear(); - const QRegExp mainRegexp("(.*var main\\s*=\\s*\\w*\\s*function\\(.*\\).*)|(.*function\\s+%1\\s*\\(.*\\).*)"); + const QRegExp mainRegexp(R"#((.*var main\s*=\s*\w*\s*function\(.*\).*)|(.*function\s+%1\s*\(.*\).*))#"); const bool needCallMain = mainRegexp.exactMatch(script) && !script.trimmed().endsWith("main();"); mMainScriptEngine = mScriptWorker->createScriptEngine(); diff --git a/trikScriptRunner/src/trikScriptRunner.cpp b/trikScriptRunner/src/trikScriptRunner.cpp index 3b10c3e30..27b24e6e7 100644 --- a/trikScriptRunner/src/trikScriptRunner.cpp +++ b/trikScriptRunner/src/trikScriptRunner.cpp @@ -90,9 +90,9 @@ QStringList TrikScriptRunner::knownMethodNames() const return mScriptRunnerArray[to_underlying(mLastRunner)]->knownMethodNames(); } -QStringList TrikScriptRunner::knownMethodNamesFor(ScriptType r) +QStringList TrikScriptRunner::knownMethodNamesFor(ScriptType t) { - return fetchRunner(r)->knownMethodNames(); + return fetchRunner(t)->knownMethodNames(); } void TrikScriptRunner::run(const QString &script, const QString &fileName) diff --git a/trikScriptRunner/src/trikVariablesServer.cpp b/trikScriptRunner/src/trikVariablesServer.cpp index e4fe87fe8..07ed26797 100644 --- a/trikScriptRunner/src/trikVariablesServer.cpp +++ b/trikScriptRunner/src/trikVariablesServer.cpp @@ -65,7 +65,7 @@ void TrikVariablesServer::processHTTPRequest() list.append(data); } - const QString cleanString = list.join("").remove(QRegExp("[\\n\\t\\r]")); + const QString cleanString = list.join("").remove(QRegExp(R"([\n\t\r])")); const QStringList words = cleanString.split(QRegExp("\\s+"), QString::SkipEmptyParts); if (words[1] == "/web/") {