From 4895b2c9198efdfd52f61604c0a0f1d6df25180d Mon Sep 17 00:00:00 2001 From: Nav Date: Mon, 13 Mar 2023 00:45:26 +0000 Subject: [PATCH] Tidying --- src/Insight/Insight.cpp | 11 ++++--- src/Insight/InsightWorker/InsightWorker.cpp | 9 +++-- src/Insight/InsightWorker/InsightWorker.hpp | 2 +- .../InsightWindow/InsightWindow.cpp | 9 +++-- .../HexViewerWidget/ItemGraphicsScene.cpp | 7 ++-- .../SnapshotManager/SnapshotManager.cpp | 26 +++++++++------ .../TargetMemoryInspectionPane.cpp | 33 +++++++++++-------- .../TargetRegisterInspectorWindow.cpp | 18 ++++++---- .../TargetRegistersPaneWidget.cpp | 15 +++++---- .../TargetWidgets/TargetPackageWidget.cpp | 10 ++++-- .../Widgets/TargetWidgets/TargetPinWidget.cpp | 19 ++++++----- 11 files changed, 98 insertions(+), 61 deletions(-) diff --git a/src/Insight/Insight.cpp b/src/Insight/Insight.cpp index dd2e1881..ceb3df5e 100644 --- a/src/Insight/Insight.cpp +++ b/src/Insight/Insight.cpp @@ -265,9 +265,9 @@ namespace Bloom } void Insight::onInsightWindowActivated() { - auto* getTargetStateTask = new GetTargetState(); + const auto getTargetStateTask = QSharedPointer(new GetTargetState(), &QObject::deleteLater); QObject::connect( - getTargetStateTask, + getTargetStateTask.get(), &GetTargetState::targetState, this, [this] (Targets::TargetState targetState) { @@ -354,10 +354,13 @@ namespace Bloom } if (event.state == TargetControllerState::ACTIVE) { - auto* getTargetDescriptorTask = new GetTargetDescriptor(); + const auto getTargetDescriptorTask = QSharedPointer( + new GetTargetDescriptor(), + &QObject::deleteLater + ); QObject::connect( - getTargetDescriptorTask, + getTargetDescriptorTask.get(), &GetTargetDescriptor::targetDescriptor, this, [this] (Targets::TargetDescriptor targetDescriptor) { diff --git a/src/Insight/InsightWorker/InsightWorker.cpp b/src/Insight/InsightWorker/InsightWorker.cpp index 975e5bee..e11a4bc5 100644 --- a/src/Insight/InsightWorker/InsightWorker.cpp +++ b/src/Insight/InsightWorker/InsightWorker.cpp @@ -33,16 +33,15 @@ namespace Bloom emit this->ready(); } - void InsightWorker::queueTask(InsightWorkerTask* task) { - const auto taskPtr = QSharedPointer(task, &QObject::deleteLater); - taskPtr->moveToThread(nullptr); + void InsightWorker::queueTask(const QSharedPointer& task) { + task->moveToThread(nullptr); { const auto taskQueueLock = InsightWorker::queuedTasksById.acquireLock(); - InsightWorker::queuedTasksById.getValue().emplace(taskPtr->id, taskPtr); + InsightWorker::queuedTasksById.getValue().emplace(task->id, task); } - emit InsightSignals::instance()->taskQueued(taskPtr); + emit InsightSignals::instance()->taskQueued(task); } void InsightWorker::executeTasks() { diff --git a/src/Insight/InsightWorker/InsightWorker.hpp b/src/Insight/InsightWorker/InsightWorker.hpp index 1f9142c7..0b796122 100644 --- a/src/Insight/InsightWorker/InsightWorker.hpp +++ b/src/Insight/InsightWorker/InsightWorker.hpp @@ -29,7 +29,7 @@ namespace Bloom InsightWorker() = default; void startup(); - static void queueTask(InsightWorkerTask* task); + static void queueTask(const QSharedPointer& task); signals: void ready(); diff --git a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp index 7d4c4a2a..4fa741bc 100644 --- a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp @@ -915,10 +915,13 @@ namespace Bloom } void InsightWindow::refreshProgramCounter(std::optional> callback) { - auto* readProgramCounterTask = new ReadProgramCounter(); + const auto readProgramCounterTask = QSharedPointer( + new ReadProgramCounter(), + &QObject::deleteLater + ); QObject::connect( - readProgramCounterTask, + readProgramCounterTask.get(), &ReadProgramCounter::programCounterRead, this, [this] (Targets::TargetProgramCounter programCounter) { @@ -930,7 +933,7 @@ namespace Bloom if (callback.has_value()) { QObject::connect( - readProgramCounterTask, + readProgramCounterTask.get(), &ReadProgramCounter::finished, this, callback.value() diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.cpp index 4c0098dc..f3e93a8f 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.cpp @@ -137,10 +137,13 @@ namespace Bloom::Widgets } void ItemGraphicsScene::init() { - auto* constructHexViewerTopLevelGroupItem = new ConstructHexViewerTopLevelGroupItem(this->focusedMemoryRegions, this->state); + const auto constructHexViewerTopLevelGroupItem = QSharedPointer( + new ConstructHexViewerTopLevelGroupItem(this->focusedMemoryRegions, this->state), + &QObject::deleteLater + ); QObject::connect( - constructHexViewerTopLevelGroupItem, + constructHexViewerTopLevelGroupItem.get(), &ConstructHexViewerTopLevelGroupItem::topLevelGroupItem, this, [this] (TopLevelGroupItem* item) { diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotManager.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotManager.cpp index c44c8323..1caf0ca9 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotManager.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotManager.cpp @@ -92,10 +92,13 @@ namespace Bloom::Widgets } ); - auto* retrieveSnapshotsTask = new RetrieveMemorySnapshots(this->memoryDescriptor.type); + const auto retrieveSnapshotsTask = QSharedPointer( + new RetrieveMemorySnapshots(this->memoryDescriptor.type), + &QObject::deleteLater + ); QObject::connect( - retrieveSnapshotsTask, + retrieveSnapshotsTask.get(), &RetrieveMemorySnapshots::memorySnapshotsRetrieved, this, [this] (std::vector snapshots) { @@ -136,17 +139,20 @@ namespace Bloom::Widgets bool captureFocusedRegions, bool captureDirectlyFromTarget ) { - auto* captureTask = new CaptureMemorySnapshot( - std::move(name), - std::move(description), - this->memoryDescriptor.type, - {}, - {}, - captureDirectlyFromTarget ? std::nullopt : this->data + const auto captureTask = QSharedPointer( + new CaptureMemorySnapshot( + std::move(name), + std::move(description), + this->memoryDescriptor.type, + {}, + {}, + captureDirectlyFromTarget ? std::nullopt : this->data + ), + &QObject::deleteLater ); QObject::connect( - captureTask, + captureTask.get(), &CaptureMemorySnapshot::memorySnapshotCaptured, this, [this] (MemorySnapshot snapshot) { diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp index 4552b55f..0d2dda1c 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp @@ -298,15 +298,18 @@ namespace Bloom::Widgets } ); - auto* readMemoryTask = new ReadTargetMemory( - this->targetMemoryDescriptor.type, - this->targetMemoryDescriptor.addressRange.startAddress, - this->targetMemoryDescriptor.size(), - excludedAddressRanges + const auto readMemoryTask = QSharedPointer( + new ReadTargetMemory( + this->targetMemoryDescriptor.type, + this->targetMemoryDescriptor.addressRange.startAddress, + this->targetMemoryDescriptor.size(), + excludedAddressRanges + ), + &QObject::deleteLater ); QObject::connect( - readMemoryTask, + readMemoryTask.get(), &ReadTargetMemory::targetMemoryRead, this, [this, callback] (const Targets::TargetMemoryBuffer& data) { @@ -314,9 +317,13 @@ namespace Bloom::Widgets // Refresh the stack pointer if this is RAM. if (this->targetMemoryDescriptor.type == Targets::TargetMemoryType::RAM) { - auto* readStackPointerTask = new ReadStackPointer(); + const auto readStackPointerTask = QSharedPointer( + new ReadStackPointer(), + &QObject::deleteLater + ); + QObject::connect( - readStackPointerTask, + readStackPointerTask.get(), &ReadStackPointer::stackPointerRead, this, [this] (Targets::TargetStackPointer stackPointer) { @@ -325,7 +332,7 @@ namespace Bloom::Widgets ); QObject::connect( - readStackPointerTask, + readStackPointerTask.get(), &InsightWorkerTask::finished, this, [this] { @@ -339,7 +346,7 @@ namespace Bloom::Widgets if (callback.has_value()) { QObject::connect( - readStackPointerTask, + readStackPointerTask.get(), &InsightWorkerTask::completed, this, callback.value() @@ -354,7 +361,7 @@ namespace Bloom::Widgets // If we're refreshing RAM, the UI should only be updated once we've retrieved the current stack pointer. if (this->targetMemoryDescriptor.type != Targets::TargetMemoryType::RAM) { QObject::connect( - readMemoryTask, + readMemoryTask.get(), &InsightWorkerTask::finished, this, [this] { @@ -368,7 +375,7 @@ namespace Bloom::Widgets if (callback.has_value()) { QObject::connect( - readMemoryTask, + readMemoryTask.get(), &InsightWorkerTask::completed, this, callback.value() @@ -377,7 +384,7 @@ namespace Bloom::Widgets } else { QObject::connect( - readMemoryTask, + readMemoryTask.get(), &InsightWorkerTask::failed, this, [this] { diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/TargetRegisterInspectorWindow.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/TargetRegisterInspectorWindow.cpp index 36a7cf7a..2ff66e81 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/TargetRegisterInspectorWindow.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/TargetRegisterInspectorWindow.cpp @@ -317,10 +317,13 @@ namespace Bloom::Widgets void TargetRegisterInspectorWindow::refreshRegisterValue() { this->registerValueContainer->setDisabled(true); - auto* readTargetRegisterTask = new ReadTargetRegisters({this->registerDescriptor}); + const auto readTargetRegisterTask = QSharedPointer( + new ReadTargetRegisters({this->registerDescriptor}), + &QObject::deleteLater + ); QObject::connect( - readTargetRegisterTask, + readTargetRegisterTask.get(), &ReadTargetRegisters::targetRegistersRead, this, [this] (Targets::TargetRegisters targetRegisters) { @@ -335,7 +338,7 @@ namespace Bloom::Widgets ); QObject::connect( - readTargetRegisterTask, + readTargetRegisterTask.get(), &InsightWorkerTask::failed, this, [this] { @@ -352,15 +355,18 @@ namespace Bloom::Widgets this->registerDescriptor, this->registerValue ); - auto* writeRegisterTask = new WriteTargetRegister(targetRegister); + const auto writeRegisterTask = QSharedPointer( + new WriteTargetRegister(targetRegister), + &QObject::deleteLater + ); - QObject::connect(writeRegisterTask, &InsightWorkerTask::completed, this, [this, targetRegister] { + QObject::connect(writeRegisterTask.get(), &InsightWorkerTask::completed, this, [this, targetRegister] { this->registerValueContainer->setDisabled(false); this->registerHistoryWidget->updateCurrentItemValue(targetRegister.value); this->registerHistoryWidget->selectCurrentItem(); }); - QObject::connect(writeRegisterTask, &InsightWorkerTask::failed, this, [this] (QString errorMessage) { + QObject::connect(writeRegisterTask.get(), &InsightWorkerTask::failed, this, [this] (QString errorMessage) { this->registerValueContainer->setDisabled(false); auto* errorDialogue = new ErrorDialogue( "Error", diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.cpp index f5e6e0f2..f7ea954f 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.cpp @@ -266,14 +266,17 @@ namespace Bloom::Widgets return; } - auto* readRegisterTask = new ReadTargetRegisters( - registerDescriptor.has_value() - ? Targets::TargetRegisterDescriptors({*registerDescriptor}) - : this->registerDescriptors + const auto readRegisterTask = QSharedPointer( + new ReadTargetRegisters( + registerDescriptor.has_value() + ? Targets::TargetRegisterDescriptors({*registerDescriptor}) + : this->registerDescriptors + ), + &QObject::deleteLater ); QObject::connect( - readRegisterTask, + readRegisterTask.get(), &ReadTargetRegisters::targetRegistersRead, this, &TargetRegistersPaneWidget::onRegistersRead @@ -281,7 +284,7 @@ namespace Bloom::Widgets if (callback.has_value()) { QObject::connect( - readRegisterTask, + readRegisterTask.get(), &InsightWorkerTask::completed, this, callback.value() diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPackageWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPackageWidget.cpp index 288a3b43..84e3f0c4 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPackageWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPackageWidget.cpp @@ -51,9 +51,13 @@ namespace Bloom::Widgets::InsightTargetWidgets } void TargetPackageWidget::refreshPinStates(std::optional> callback) { - auto* refreshTask = new RefreshTargetPinStates(this->targetVariant.id); + const auto refreshTask = QSharedPointer( + new RefreshTargetPinStates(this->targetVariant.id), + &QObject::deleteLater + ); + QObject::connect( - refreshTask, + refreshTask.get(), &RefreshTargetPinStates::targetPinStatesRetrieved, this, &TargetPackageWidget::updatePinStates @@ -61,7 +65,7 @@ namespace Bloom::Widgets::InsightTargetWidgets if (callback.has_value()) { QObject::connect( - refreshTask, + refreshTask.get(), &InsightWorkerTask::completed, this, callback.value() diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinWidget.cpp index 90d21af7..7b208e8c 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinWidget.cpp @@ -26,22 +26,25 @@ namespace Bloom::Widgets::InsightTargetWidgets void TargetPinWidget::onWidgetBodyClicked() { // Currently, we only allow users to toggle the IO state of output pins - if (this->pinState.has_value() - && this->pinState.value().ioDirection == TargetPinState::IoDirection::OUTPUT - ) { + if (this->pinState.has_value() && this->pinState.value().ioDirection == TargetPinState::IoDirection::OUTPUT) { this->setDisabled(true); auto pinState = this->pinState.value(); - pinState.ioState = (pinState.ioState == TargetPinState::IoState::HIGH) ? - TargetPinState::IoState::LOW : TargetPinState::IoState::HIGH; + pinState.ioState = (pinState.ioState == TargetPinState::IoState::HIGH) + ? TargetPinState::IoState::LOW + : TargetPinState::IoState::HIGH; - auto* setPinStateTask = new SetTargetPinState(this->pinDescriptor, pinState); - QObject::connect(setPinStateTask, &InsightWorkerTask::completed, this, [this, pinState] { + const auto setPinStateTask = QSharedPointer( + new SetTargetPinState(this->pinDescriptor, pinState), + &QObject::deleteLater + ); + + QObject::connect(setPinStateTask.get(), &InsightWorkerTask::completed, this, [this, pinState] { this->updatePinState(pinState); this->setDisabled(false); }); - QObject::connect(setPinStateTask, &InsightWorkerTask::failed, this, [this] { + QObject::connect(setPinStateTask.get(), &InsightWorkerTask::failed, this, [this] { this->setDisabled(false); });