diff --git a/src/Insight/CMakeLists.txt b/src/Insight/CMakeLists.txt index d596fc73..fa28394f 100755 --- a/src/Insight/CMakeLists.txt +++ b/src/Insight/CMakeLists.txt @@ -29,14 +29,11 @@ target_sources( ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/InsightWorkerTask.cpp ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/ReadTargetRegisters.cpp ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/WriteTargetRegister.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/RefreshTargetPinStates.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/SetTargetPinState.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/ReadTargetGpioPadStates.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/SetTargetGpioPadState.cpp ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/ReadTargetMemory.cpp ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/WriteTargetMemory.cpp ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/ReadStackPointer.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/ReadProgramCounter.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/GetTargetState.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/GetTargetDescriptor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/ConstructHexViewerTopLevelGroupItem.cpp ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/CaptureMemorySnapshot.cpp ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/RetrieveMemorySnapshots.cpp @@ -73,6 +70,7 @@ target_sources( # Target register side pane ${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/PeripheralItem.cpp ${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/RegisterGroupItem.cpp ${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/RegisterItem.cpp @@ -87,6 +85,7 @@ target_sources( ${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/BitsetWidget/BitBodyWidget.cpp # Target memory inspection pane + ${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/ToolButton.cpp ${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp ${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerWidget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsView.cpp diff --git a/src/Insight/Insight.cpp b/src/Insight/Insight.cpp index 8b9ef158..ee6a5b69 100644 --- a/src/Insight/Insight.cpp +++ b/src/Insight/Insight.cpp @@ -5,17 +5,14 @@ #include #include "src/Services/PathService.hpp" -#include "src/Logger/Logger.hpp" #include "src/EventManager/EventManager.hpp" #include "UserInterfaces/InsightWindow/BloomProxyStyle.hpp" +#include "src/Logger/Logger.hpp" #include "src/Application.hpp" -#include "InsightWorker/Tasks/GetTargetState.hpp" -#include "InsightWorker/Tasks/GetTargetDescriptor.hpp" - using namespace Exceptions; -using Targets::TargetState; +using Targets::TargetExecutionState; Insight::Insight( EventListener& eventListener, @@ -31,15 +28,13 @@ Insight::Insight( , environmentConfig(environmentConfig) , insightConfig(insightConfig) , insightProjectSettings(insightProjectSettings) + , targetDescriptor(this->targetControllerService.getTargetDescriptor()) + , targetState(this->targetControllerService.getTargetState()) { Logger::info("Starting Insight"); - this->eventListener.registerCallbackForEventType( - std::bind(&Insight::onTargetStoppedEvent, this, std::placeholders::_1) - ); - - this->eventListener.registerCallbackForEventType( - std::bind(&Insight::onTargetResumedEvent, this, std::placeholders::_1) + this->eventListener.registerCallbackForEventType( + std::bind(&Insight::onTargetStateChangedEvent, this, std::placeholders::_1) ); this->eventListener.registerCallbackForEventType( @@ -63,13 +58,11 @@ Insight::Insight( ); QApplication::setQuitOnLastWindowClosed(false); - QApplication::setStyle(new BloomProxyStyle()); + QApplication::setStyle(new BloomProxyStyle{}); qRegisterMetaType(); qRegisterMetaType(); - qRegisterMetaType(); qRegisterMetaType(); - qRegisterMetaType>(); // Load Ubuntu fonts QFontDatabase::addApplicationFont( @@ -115,22 +108,23 @@ Insight::Insight( QString::fromStdString(Services::PathService::resourcesDirPath() + "/fonts/Ubuntu/Ubuntu-Th.ttf") ); - auto globalStylesheet = QFile( + auto globalStylesheet = QFile{ QString::fromStdString( - Services::PathService::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Stylesheets/Global.qss" + Services::PathService::compiledResourcesPath() + + "/src/Insight/UserInterfaces/InsightWindow/Stylesheets/Global.qss" ) - ); + }; if (!globalStylesheet.open(QFile::ReadOnly)) { - throw Exception("Failed to open global stylesheet file"); + throw Exception{"Failed to open global stylesheet file"}; } this->globalStylesheet = globalStylesheet.readAll(); // Construct and start worker threads - for (std::uint8_t i = 0; i < Insight::INSIGHT_WORKER_COUNT; ++i) { - auto* insightWorker = new InsightWorker(); - auto* workerThread = new QThread(); + for (auto i = std::uint8_t{0}; i < Insight::INSIGHT_WORKER_COUNT; ++i) { + auto* insightWorker = new InsightWorker{}; + auto* workerThread = new QThread{}; workerThread->setObjectName("IW" + QString::number(insightWorker->id)); insightWorker->moveToThread(workerThread); @@ -138,7 +132,7 @@ Insight::Insight( QObject::connect(workerThread, &QThread::finished, insightWorker, &QObject::deleteLater); QObject::connect(workerThread, &QThread::finished, workerThread, &QThread::deleteLater); - this->insightWorkersById[insightWorker->id] = std::pair(insightWorker, workerThread); + this->insightWorkersById[insightWorker->id] = std::pair{insightWorker, workerThread}; Logger::debug("Starting InsightWorker" + std::to_string(insightWorker->id)); workerThread->start(); @@ -149,18 +143,16 @@ Insight::Insight( void Insight::activateMainWindow() { if (this->mainWindow == nullptr) { - this->mainWindow = new InsightWindow( + this->mainWindow = new InsightWindow{ this->insightProjectSettings, this->insightConfig, this->environmentConfig, - this->targetDescriptor - ); + this->targetDescriptor, + this->targetState + }; this->mainWindow->setStyleSheet(this->globalStylesheet); - QObject::connect(this->mainWindow, &QObject::destroyed, this, &Insight::onInsightWindowDestroyed); - - this->refreshTargetState(); } this->mainWindow->show(); @@ -186,77 +178,39 @@ void Insight::shutdown() { } } -void Insight::refreshTargetState() { - const auto getTargetStateTask = QSharedPointer(new GetTargetState(), &QObject::deleteLater); - QObject::connect( - getTargetStateTask.get(), - &GetTargetState::targetState, - this, - [this] (Targets::TargetState targetState) { - this->lastTargetState = targetState; - emit this->insightSignals->targetStateUpdated(this->lastTargetState); - } - ); - - InsightWorker::queueTask(getTargetStateTask); -} - void Insight::onInsightWindowDestroyed() { this->mainWindow = nullptr; EventManager::triggerEvent(std::make_shared()); } -void Insight::onTargetStoppedEvent(const Events::TargetExecutionStopped& event) { - if (this->lastTargetState == TargetState::STOPPED) { - return; - } - - this->lastTargetState = TargetState::STOPPED; - - if (this->targetStepping) { - if (this->targetResumeTimer == nullptr) { - this->targetResumeTimer = new QTimer(this); - this->targetResumeTimer->setSingleShot(true); - - this->targetResumeTimer->callOnTimeout(this, [this] { - if (this->lastTargetState != TargetState::STOPPED) { - return; - } - - emit this->insightSignals->targetStateUpdated(TargetState::STOPPED); - }); +void Insight::onTargetStateChangedEvent(const Events::TargetStateChanged& event) { + if (event.previousState.mode != event.newState.mode) { + if (event.newState.mode == Targets::TargetMode::PROGRAMMING) { + emit this->insightSignals->programmingModeEnabled(); } - this->targetResumeTimer->start(1500); + if (event.newState.mode == Targets::TargetMode::DEBUGGING) { + emit this->insightSignals->programmingModeDisabled(); + } + } + + if (event.previousState.executionState == event.newState.executionState) { return; } - if (this->targetResumeTimer != nullptr && this->targetResumeTimer->isActive()) { - this->targetResumeTimer->stop(); - } - - emit this->insightSignals->targetStateUpdated(TargetState::STOPPED); -} - -void Insight::onTargetResumedEvent(const Events::TargetExecutionResumed& event) { - this->targetStepping = event.stepping; - - if (this->lastTargetState != TargetState::RUNNING) { - this->lastTargetState = TargetState::RUNNING; - emit this->insightSignals->targetStateUpdated(TargetState::RUNNING); - } + emit this->insightSignals->targetStateUpdated(event.newState, event.previousState); } void Insight::onTargetResetEvent(const Events::TargetReset& event) { try { - if (this->lastTargetState != TargetState::STOPPED) { - this->lastTargetState = TargetState::STOPPED; - emit this->insightSignals->targetStateUpdated(TargetState::STOPPED); + if (this->targetState.executionState != TargetExecutionState::STOPPED) { + // Reset event came in too late, target has already resumed execution. Ignore + return; } emit this->insightSignals->targetReset(); - } catch (const Exceptions::Exception& exception) { + } catch (const Exception& exception) { Logger::debug("Error handling TargetReset event - " + exception.getMessage()); } } @@ -267,8 +221,9 @@ void Insight::onTargetRegistersWrittenEvent(const Events::RegistersWrittenToTarg void Insight::onTargetMemoryWrittenEvent(const Events::MemoryWrittenToTarget& event) { emit this->insightSignals->targetMemoryWritten( - event.memoryType, - Targets::TargetMemoryAddressRange(event.startAddress, event.startAddress + (event.size - 1)) + event.addressSpaceDescriptor, + event.memorySegmentDescriptor, + Targets::TargetMemoryAddressRange{event.startAddress, event.startAddress + (event.size - 1)} ); } diff --git a/src/Insight/Insight.hpp b/src/Insight/Insight.hpp index 70f5646d..75b6813f 100644 --- a/src/Insight/Insight.hpp +++ b/src/Insight/Insight.hpp @@ -6,7 +6,6 @@ #include #include #include -#include #include "src/Helpers/Thread.hpp" #include "src/Services/PathService.hpp" @@ -75,25 +74,20 @@ private: InsightProjectSettings& insightProjectSettings; - Services::TargetControllerService targetControllerService = Services::TargetControllerService(); + Services::TargetControllerService targetControllerService = {}; - Targets::TargetDescriptor targetDescriptor = this->targetControllerService.getTargetDescriptor(); + const Targets::TargetDescriptor& targetDescriptor; + const Targets::TargetState& targetState; QString globalStylesheet; std::map> insightWorkersById; InsightWindow* mainWindow = nullptr; - Targets::TargetState lastTargetState = Targets::TargetState::UNKNOWN; - bool targetStepping = false; - QTimer* targetResumeTimer = nullptr; - InsightSignals* insightSignals = InsightSignals::instance(); - void refreshTargetState(); void onInsightWindowDestroyed(); - void onTargetStoppedEvent(const Events::TargetExecutionStopped& event); - void onTargetResumedEvent(const Events::TargetExecutionResumed& event); + void onTargetStateChangedEvent(const Events::TargetStateChanged& event); void onTargetResetEvent(const Events::TargetReset& event); void onTargetRegistersWrittenEvent(const Events::RegistersWrittenToTarget& event); void onTargetMemoryWrittenEvent(const Events::MemoryWrittenToTarget& event); diff --git a/src/Insight/InsightSignals.hpp b/src/Insight/InsightSignals.hpp index 749800ba..f0396e15 100644 --- a/src/Insight/InsightSignals.hpp +++ b/src/Insight/InsightSignals.hpp @@ -5,9 +5,12 @@ #include #include "src/Targets/TargetState.hpp" -#include "src/Targets/TargetDescriptor.hpp" #include "src/Targets/TargetRegisterDescriptor.hpp" +#include "src/Targets/TargetMemory.hpp" +#include "src/Targets/TargetAddressSpaceDescriptor.hpp" +#include "src/Targets/TargetMemorySegmentDescriptor.hpp" + #include "InsightWorker/Tasks/InsightWorkerTask.hpp" /** @@ -20,7 +23,7 @@ class InsightSignals: public QObject public: static InsightSignals* instance() { - static auto instance = InsightSignals(); + static auto instance = InsightSignals{}; return &instance; } @@ -31,10 +34,14 @@ signals: void taskQueued(QSharedPointer task); void taskProcessed(QSharedPointer task); - void targetStateUpdated(Targets::TargetState newState); + void targetStateUpdated(Targets::TargetState newState, Targets::TargetState previousState); void targetReset(); - void targetRegistersWritten(const Targets::TargetRegisters& targetRegisters, const QDateTime& timestamp); - void targetMemoryWritten(Targets::TargetMemoryType memoryType, Targets::TargetMemoryAddressRange addressRange); + void targetRegistersWritten(const Targets::TargetRegisterDescriptorAndValuePairs& targetRegisters, const QDateTime& timestamp); + void targetMemoryWritten( + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, + Targets::TargetMemoryAddressRange addressRange + ); void programmingModeEnabled(); void programmingModeDisabled(); diff --git a/src/Insight/InsightWorker/InsightWorker.cpp b/src/Insight/InsightWorker/InsightWorker.cpp index 6913c71c..bb9250ec 100644 --- a/src/Insight/InsightWorker/InsightWorker.cpp +++ b/src/Insight/InsightWorker/InsightWorker.cpp @@ -69,7 +69,7 @@ void InsightWorker::executeTasks() { return std::nullopt; }; - auto queuedTask = std::optional>(); + auto queuedTask = std::optional>{}; while ((queuedTask = getQueuedTask())) { auto& task = *queuedTask; diff --git a/src/Insight/InsightWorker/InsightWorker.hpp b/src/Insight/InsightWorker/InsightWorker.hpp index 9bd846c0..fbdb5fa0 100644 --- a/src/Insight/InsightWorker/InsightWorker.hpp +++ b/src/Insight/InsightWorker/InsightWorker.hpp @@ -37,7 +37,7 @@ private: static inline Synchronised>> queuedTasksById = {}; static inline Synchronised taskGroupsInExecution = {}; - Services::TargetControllerService targetControllerService = Services::TargetControllerService(); + Services::TargetControllerService targetControllerService = {}; void executeTasks(); }; diff --git a/src/Insight/InsightWorker/Tasks/CaptureMemorySnapshot.cpp b/src/Insight/InsightWorker/Tasks/CaptureMemorySnapshot.cpp index 27e9d2e0..8cba8f38 100644 --- a/src/Insight/InsightWorker/Tasks/CaptureMemorySnapshot.cpp +++ b/src/Insight/InsightWorker/Tasks/CaptureMemorySnapshot.cpp @@ -13,52 +13,58 @@ using Services::TargetControllerService; CaptureMemorySnapshot::CaptureMemorySnapshot( const QString& name, const QString& description, - Targets::TargetMemoryType memoryType, + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, const std::vector& focusedRegions, const std::vector& excludedRegions, const std::optional& data ) : name(name) , description(description) - , memoryType(memoryType) + , addressSpaceDescriptor(addressSpaceDescriptor) + , memorySegmentDescriptor(memorySegmentDescriptor) , focusedRegions(focusedRegions) , excludedRegions(excludedRegions) , data(data) {} +QString CaptureMemorySnapshot::brief() const { + return "Capturing memory snapshot"; +} + +TaskGroups CaptureMemorySnapshot::taskGroups() const { + return { + TaskGroup::USES_TARGET_CONTROLLER, + }; +} + void CaptureMemorySnapshot::run(TargetControllerService& targetControllerService) { using Targets::TargetMemorySize; Logger::info("Capturing snapshot"); - const auto& targetDescriptor = targetControllerService.getTargetDescriptor(); - const auto memoryDescriptorIt = targetDescriptor.memoryDescriptorsByType.find(this->memoryType); - - if (memoryDescriptorIt == targetDescriptor.memoryDescriptorsByType.end()) { - throw Exceptions::Exception("Invalid memory type"); - } - - const auto& memoryDescriptor = memoryDescriptorIt->second; - const auto memorySize = memoryDescriptor.size(); + const auto memorySize = this->memorySegmentDescriptor.size(); if (!this->data.has_value()) { Logger::info("Reading data for snapshot capture"); - this->data = Targets::TargetMemoryBuffer(); + this->data = Targets::TargetMemoryBuffer{}; this->data->reserve(memorySize); const auto readSize = std::max( - TargetMemorySize(256), - memoryDescriptor.pageSize.value_or(TargetMemorySize(0)) + TargetMemorySize{256}, + this->memorySegmentDescriptor.pageSize.value_or(TargetMemorySize{0}) ); const auto readsRequired = static_cast( std::ceil(static_cast(memorySize) / static_cast(readSize)) ); - for (std::uint32_t i = 0; i < readsRequired; i++) { + for (auto i = std::size_t{0}; i < readsRequired; i++) { auto dataSegment = targetControllerService.readMemory( - this->memoryType, - memoryDescriptor.addressRange.startAddress + static_cast(readSize * i), + this->addressSpaceDescriptor, + this->memorySegmentDescriptor, + this->memorySegmentDescriptor.addressRange.startAddress + + static_cast(readSize * i), (memorySize - this->data->size()) >= readSize ? readSize : static_cast(memorySize - this->data->size()), @@ -75,32 +81,31 @@ void CaptureMemorySnapshot::run(TargetControllerService& targetControllerService assert(this->data->size() == memorySize); - auto snapshot = MemorySnapshot( - std::move(this->name), - std::move(this->description), - this->memoryType, - std::move(*this->data), + auto snapshot = MemorySnapshot{ + this->name, + this->description, + QString::fromStdString(this->addressSpaceDescriptor.key), + QString::fromStdString(this->memorySegmentDescriptor.key), + *this->data, targetControllerService.getProgramCounter(), targetControllerService.getStackPointer(), - std::move(this->focusedRegions), - std::move(this->excludedRegions) - ); - - const auto snapshotDirPath = QString::fromStdString(Services::PathService::projectSettingsDirPath()) - + "/memory_snapshots/" + EnumToStringMappings::targetMemoryTypes.at(snapshot.memoryType); + this->focusedRegions, + this->excludedRegions + }; + const auto snapshotDirPath = QString::fromStdString(Services::PathService::memorySnapshotsPath()); QDir().mkpath(snapshotDirPath); const auto snapshotFilePath = snapshotDirPath + "/" + snapshot.id + ".json"; - auto outputFile = QFile(snapshotFilePath); + auto outputFile = QFile{snapshotFilePath}; if (!outputFile.open(QIODevice::ReadWrite | QIODevice::Truncate | QIODevice::Text)) { Logger::error("Failed to save snapshot - cannot open " + snapshotFilePath.toStdString()); return; } - outputFile.write(QJsonDocument(snapshot.toJson()).toJson(QJsonDocument::JsonFormat::Compact)); + outputFile.write(QJsonDocument{snapshot.toJson()}.toJson(QJsonDocument::JsonFormat::Compact)); outputFile.close(); Logger::info("Snapshot captured - UUID: " + snapshot.id.toStdString()); diff --git a/src/Insight/InsightWorker/Tasks/CaptureMemorySnapshot.hpp b/src/Insight/InsightWorker/Tasks/CaptureMemorySnapshot.hpp index 13f43d14..df954907 100644 --- a/src/Insight/InsightWorker/Tasks/CaptureMemorySnapshot.hpp +++ b/src/Insight/InsightWorker/Tasks/CaptureMemorySnapshot.hpp @@ -6,6 +6,9 @@ #include "InsightWorkerTask.hpp" #include "src/Targets/TargetMemory.hpp" +#include "src/Targets/TargetAddressSpaceDescriptor.hpp" +#include "src/Targets/TargetMemorySegmentDescriptor.hpp" + #include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemorySnapshot.hpp" class CaptureMemorySnapshot: public InsightWorkerTask @@ -16,21 +19,15 @@ public: CaptureMemorySnapshot( const QString& name, const QString& description, - Targets::TargetMemoryType memoryType, + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, const std::vector& focusedRegions, const std::vector& excludedRegions, const std::optional& data ); - QString brief() const override { - return "Capturing memory snapshot"; - } - - TaskGroups taskGroups() const override { - return TaskGroups({ - TaskGroup::USES_TARGET_CONTROLLER, - }); - }; + [[nodiscard]] QString brief() const override; + [[nodiscard]] TaskGroups taskGroups() const override; signals: void memorySnapshotCaptured(MemorySnapshot snapshot); @@ -41,7 +38,8 @@ protected: private: QString name; QString description; - Targets::TargetMemoryType memoryType; + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor; + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor; std::vector focusedRegions; std::vector excludedRegions; diff --git a/src/Insight/InsightWorker/Tasks/ConstructHexViewerTopLevelGroupItem.cpp b/src/Insight/InsightWorker/Tasks/ConstructHexViewerTopLevelGroupItem.cpp index 889c9339..405d6f0c 100644 --- a/src/Insight/InsightWorker/Tasks/ConstructHexViewerTopLevelGroupItem.cpp +++ b/src/Insight/InsightWorker/Tasks/ConstructHexViewerTopLevelGroupItem.cpp @@ -10,6 +10,10 @@ ConstructHexViewerTopLevelGroupItem::ConstructHexViewerTopLevelGroupItem( , hexViewerState(hexViewerState) {} +QString ConstructHexViewerTopLevelGroupItem::brief() const { + return "Preparing hex viewer"; +} + void ConstructHexViewerTopLevelGroupItem::run(Services::TargetControllerService&) { auto* item = new Widgets::TopLevelGroupItem( this->focusedMemoryRegions, diff --git a/src/Insight/InsightWorker/Tasks/ConstructHexViewerTopLevelGroupItem.hpp b/src/Insight/InsightWorker/Tasks/ConstructHexViewerTopLevelGroupItem.hpp index 576b9c28..5d690351 100644 --- a/src/Insight/InsightWorker/Tasks/ConstructHexViewerTopLevelGroupItem.hpp +++ b/src/Insight/InsightWorker/Tasks/ConstructHexViewerTopLevelGroupItem.hpp @@ -18,14 +18,7 @@ public: const std::vector& excludedMemoryRegions, const Widgets::HexViewerSharedState& hexViewerState ); - - QString brief() const override { - return "Preparing hex viewer"; - } - - TaskGroups taskGroups() const override { - return TaskGroups(); - }; + QString brief() const override; signals: void topLevelGroupItem(Widgets::TopLevelGroupItem* item); diff --git a/src/Insight/InsightWorker/Tasks/DeleteMemorySnapshot.cpp b/src/Insight/InsightWorker/Tasks/DeleteMemorySnapshot.cpp index 5e248a55..f0503f31 100644 --- a/src/Insight/InsightWorker/Tasks/DeleteMemorySnapshot.cpp +++ b/src/Insight/InsightWorker/Tasks/DeleteMemorySnapshot.cpp @@ -3,30 +3,25 @@ #include #include "src/Services/PathService.hpp" -#include "src/Helpers/EnumToStringMappings.hpp" #include "src/Logger/Logger.hpp" using Services::TargetControllerService; -DeleteMemorySnapshot::DeleteMemorySnapshot( - const QString& snapshotId, - Targets::TargetMemoryType memoryType -) +DeleteMemorySnapshot::DeleteMemorySnapshot(const QString& snapshotId) : snapshotId(snapshotId) - , memoryType(memoryType) {} -void DeleteMemorySnapshot::run(TargetControllerService&) { - using Targets::TargetMemorySize; +QString DeleteMemorySnapshot::brief() const { + return "Deleting memory snapshot " + this->snapshotId; +} +void DeleteMemorySnapshot::run(TargetControllerService&) { Logger::info("Deleting snapshot " + this->snapshotId.toStdString()); - const auto snapshotFilePath = QString::fromStdString(Services::PathService::projectSettingsDirPath()) - + "/memory_snapshots/" + EnumToStringMappings::targetMemoryTypes.at(this->memoryType) + "/" - + this->snapshotId + ".json"; - - auto snapshotFile = QFile(snapshotFilePath); + const auto snapshotFilePath = QString::fromStdString(Services::PathService::memorySnapshotsPath()) + + this->snapshotId + ".json"; + auto snapshotFile = QFile{snapshotFilePath}; if (!snapshotFile.exists()) { Logger::warning( "Could not find snapshot file for " + this->snapshotId.toStdString() + " - expected path: " diff --git a/src/Insight/InsightWorker/Tasks/DeleteMemorySnapshot.hpp b/src/Insight/InsightWorker/Tasks/DeleteMemorySnapshot.hpp index 62cb14be..72a012be 100644 --- a/src/Insight/InsightWorker/Tasks/DeleteMemorySnapshot.hpp +++ b/src/Insight/InsightWorker/Tasks/DeleteMemorySnapshot.hpp @@ -4,23 +4,17 @@ #include "InsightWorkerTask.hpp" -#include "src/Targets/TargetMemory.hpp" - class DeleteMemorySnapshot: public InsightWorkerTask { Q_OBJECT public: - DeleteMemorySnapshot(const QString& snapshotId, Targets::TargetMemoryType memoryType); - - QString brief() const override { - return "Deleting memory snapshot " + this->snapshotId; - } + explicit DeleteMemorySnapshot(const QString& snapshotId); + [[nodiscard]] QString brief() const override ; protected: void run(Services::TargetControllerService& targetControllerService) override; private: QString snapshotId; - Targets::TargetMemoryType memoryType; }; diff --git a/src/Insight/InsightWorker/Tasks/GetTargetDescriptor.cpp b/src/Insight/InsightWorker/Tasks/GetTargetDescriptor.cpp deleted file mode 100644 index 2cb472bc..00000000 --- a/src/Insight/InsightWorker/Tasks/GetTargetDescriptor.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "GetTargetDescriptor.hpp" - -using Services::TargetControllerService; - -void GetTargetDescriptor::run(TargetControllerService& targetControllerService) { - emit this->targetDescriptor(targetControllerService.getTargetDescriptor()); -} diff --git a/src/Insight/InsightWorker/Tasks/GetTargetDescriptor.hpp b/src/Insight/InsightWorker/Tasks/GetTargetDescriptor.hpp deleted file mode 100644 index 7364fe2e..00000000 --- a/src/Insight/InsightWorker/Tasks/GetTargetDescriptor.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include "InsightWorkerTask.hpp" - -#include "src/Targets/TargetDescriptor.hpp" - -class GetTargetDescriptor: public InsightWorkerTask -{ - Q_OBJECT - -public: - GetTargetDescriptor() = default; - - QString brief() const override { - return "Obtaining target descriptor"; - } - - TaskGroups taskGroups() const override { - return TaskGroups({ - TaskGroup::USES_TARGET_CONTROLLER, - }); - }; - -signals: - void targetDescriptor(Targets::TargetDescriptor targetDescriptor); - -protected: - void run(Services::TargetControllerService& targetControllerService) override; -}; diff --git a/src/Insight/InsightWorker/Tasks/GetTargetState.cpp b/src/Insight/InsightWorker/Tasks/GetTargetState.cpp deleted file mode 100644 index 1713c6dc..00000000 --- a/src/Insight/InsightWorker/Tasks/GetTargetState.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "GetTargetState.hpp" - -using Services::TargetControllerService; - -void GetTargetState::run(TargetControllerService& targetControllerService) { - emit this->targetState(targetControllerService.getTargetState()); -} diff --git a/src/Insight/InsightWorker/Tasks/GetTargetState.hpp b/src/Insight/InsightWorker/Tasks/GetTargetState.hpp deleted file mode 100644 index b56ce07a..00000000 --- a/src/Insight/InsightWorker/Tasks/GetTargetState.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include "InsightWorkerTask.hpp" - -#include "src/Targets/TargetState.hpp" - -class GetTargetState: public InsightWorkerTask -{ - Q_OBJECT - -public: - GetTargetState() = default; - - QString brief() const override { - return "Obtaining target state"; - } - - TaskGroups taskGroups() const override { - return TaskGroups({ - TaskGroup::USES_TARGET_CONTROLLER, - }); - }; - -signals: - void targetState(Targets::TargetState state); - -protected: - void run(Services::TargetControllerService& targetControllerService) override; -}; diff --git a/src/Insight/InsightWorker/Tasks/InsightWorkerTask.cpp b/src/Insight/InsightWorker/Tasks/InsightWorkerTask.cpp index b913dcc1..ee566822 100644 --- a/src/Insight/InsightWorker/Tasks/InsightWorkerTask.cpp +++ b/src/Insight/InsightWorker/Tasks/InsightWorkerTask.cpp @@ -8,6 +8,10 @@ InsightWorkerTask::InsightWorkerTask() : QObject(nullptr) {} +TaskGroups InsightWorkerTask::taskGroups() const { + return {}; +} + void InsightWorkerTask::execute(TargetControllerService& targetControllerService) { try { this->state = InsightWorkerTaskState::STARTED; @@ -19,7 +23,7 @@ void InsightWorkerTask::execute(TargetControllerService& targetControllerService this->setProgressPercentage(100); emit this->completed(); - } catch (std::exception& exception) { + } catch (const std::exception& exception) { this->state = InsightWorkerTaskState::FAILED; Logger::debug("InsightWorker task failed - " + std::string(exception.what())); emit this->failed(QString::fromStdString(exception.what())); diff --git a/src/Insight/InsightWorker/Tasks/InsightWorkerTask.hpp b/src/Insight/InsightWorker/Tasks/InsightWorkerTask.hpp index f4e946c8..b58bb9ed 100644 --- a/src/Insight/InsightWorker/Tasks/InsightWorkerTask.hpp +++ b/src/Insight/InsightWorker/Tasks/InsightWorkerTask.hpp @@ -30,12 +30,8 @@ public: std::atomic progressPercentage = 0; InsightWorkerTask(); - - virtual QString brief() const = 0; - - virtual TaskGroups taskGroups() const { - return TaskGroups(); - }; + [[nodiscard]] virtual QString brief() const = 0; + [[nodiscard]] virtual TaskGroups taskGroups() const; void execute(Services::TargetControllerService& targetControllerService); diff --git a/src/Insight/InsightWorker/Tasks/ReadProgramCounter.cpp b/src/Insight/InsightWorker/Tasks/ReadProgramCounter.cpp deleted file mode 100644 index 7075fa3a..00000000 --- a/src/Insight/InsightWorker/Tasks/ReadProgramCounter.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "ReadProgramCounter.hpp" - -using Services::TargetControllerService; - -void ReadProgramCounter::run(TargetControllerService& targetControllerService) { - emit this->programCounterRead(targetControllerService.getProgramCounter()); -} diff --git a/src/Insight/InsightWorker/Tasks/ReadProgramCounter.hpp b/src/Insight/InsightWorker/Tasks/ReadProgramCounter.hpp deleted file mode 100644 index eaaefc2d..00000000 --- a/src/Insight/InsightWorker/Tasks/ReadProgramCounter.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include "InsightWorkerTask.hpp" - -#include "src/Targets/TargetMemory.hpp" - -class ReadProgramCounter: public InsightWorkerTask -{ - Q_OBJECT - -public: - ReadProgramCounter() = default; - - QString brief() const override { - return "Reading program counter"; - } - - TaskGroups taskGroups() const override { - return TaskGroups({ - TaskGroup::USES_TARGET_CONTROLLER, - }); - }; - -signals: - void programCounterRead(Targets::TargetMemoryAddress programCounter); - -protected: - void run(Services::TargetControllerService& targetControllerService) override; -}; diff --git a/src/Insight/InsightWorker/Tasks/ReadStackPointer.cpp b/src/Insight/InsightWorker/Tasks/ReadStackPointer.cpp index 8cc0308d..3ef11a5e 100644 --- a/src/Insight/InsightWorker/Tasks/ReadStackPointer.cpp +++ b/src/Insight/InsightWorker/Tasks/ReadStackPointer.cpp @@ -2,6 +2,16 @@ using Services::TargetControllerService; +QString ReadStackPointer::brief() const { + return "Reading stack pointer"; +} + +TaskGroups ReadStackPointer::taskGroups() const { + return { + TaskGroup::USES_TARGET_CONTROLLER, + }; +} + void ReadStackPointer::run(TargetControllerService& targetControllerService) { emit this->stackPointerRead(targetControllerService.getStackPointer()); } diff --git a/src/Insight/InsightWorker/Tasks/ReadStackPointer.hpp b/src/Insight/InsightWorker/Tasks/ReadStackPointer.hpp index 99fa3ecf..b3c2bd73 100644 --- a/src/Insight/InsightWorker/Tasks/ReadStackPointer.hpp +++ b/src/Insight/InsightWorker/Tasks/ReadStackPointer.hpp @@ -10,16 +10,8 @@ class ReadStackPointer: public InsightWorkerTask public: ReadStackPointer() = default; - - QString brief() const override { - return "Reading stack pointer"; - } - - TaskGroups taskGroups() const override { - return TaskGroups({ - TaskGroup::USES_TARGET_CONTROLLER, - }); - }; + [[nodiscard]] QString brief() const override; + [[nodiscard]] TaskGroups taskGroups() const override; signals: void stackPointerRead(Targets::TargetStackPointer stackPointer); diff --git a/src/Insight/InsightWorker/Tasks/ReadTargetGpioPadStates.cpp b/src/Insight/InsightWorker/Tasks/ReadTargetGpioPadStates.cpp new file mode 100644 index 00000000..217ff72b --- /dev/null +++ b/src/Insight/InsightWorker/Tasks/ReadTargetGpioPadStates.cpp @@ -0,0 +1,21 @@ +#include "ReadTargetGpioPadStates.hpp" + +using Services::TargetControllerService; + +ReadTargetGpioPadStates::ReadTargetGpioPadStates(const Targets::TargetPadDescriptors& padDescriptors) + : padDescriptors(padDescriptors) +{} + +QString ReadTargetGpioPadStates::brief() const { + return "Reading target pin states"; +} + +TaskGroups ReadTargetGpioPadStates::taskGroups() const { + return { + TaskGroup::USES_TARGET_CONTROLLER, + }; +} + +void ReadTargetGpioPadStates::run(TargetControllerService& targetControllerService) { + emit this->targetGpioPadStatesRead(targetControllerService.getGpioPadStates(this->padDescriptors)); +} diff --git a/src/Insight/InsightWorker/Tasks/ReadTargetGpioPadStates.hpp b/src/Insight/InsightWorker/Tasks/ReadTargetGpioPadStates.hpp new file mode 100644 index 00000000..e9072bc6 --- /dev/null +++ b/src/Insight/InsightWorker/Tasks/ReadTargetGpioPadStates.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include "InsightWorkerTask.hpp" + +#include "src/Targets/TargetPadDescriptor.hpp" +#include "src/Targets/TargetGpioPadState.hpp" + +class ReadTargetGpioPadStates: public InsightWorkerTask +{ + Q_OBJECT + +public: + explicit ReadTargetGpioPadStates(const Targets::TargetPadDescriptors& padDescriptors); + [[nodiscard]] QString brief() const override; + [[nodiscard]] TaskGroups taskGroups() const override; + +signals: + void targetGpioPadStatesRead(Targets::TargetGpioPadDescriptorAndStatePairs pairs); + +protected: + void run(Services::TargetControllerService& targetControllerService) override; + +private: + const Targets::TargetPadDescriptors& padDescriptors; +}; diff --git a/src/Insight/InsightWorker/Tasks/ReadTargetMemory.cpp b/src/Insight/InsightWorker/Tasks/ReadTargetMemory.cpp index bf67f86b..64738aed 100644 --- a/src/Insight/InsightWorker/Tasks/ReadTargetMemory.cpp +++ b/src/Insight/InsightWorker/Tasks/ReadTargetMemory.cpp @@ -1,25 +1,43 @@ #include "ReadTargetMemory.hpp" +#include +#include #include #include -#include "src/Targets/TargetMemory.hpp" #include "src/Exceptions/Exception.hpp" using Services::TargetControllerService; +ReadTargetMemory::ReadTargetMemory( + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, + Targets::TargetMemoryAddress startAddress, + Targets::TargetMemorySize size, + const std::set& excludedAddressRanges +) + : addressSpaceDescriptor(addressSpaceDescriptor) + , memorySegmentDescriptor(memorySegmentDescriptor) + , startAddress(startAddress) + , size(size) + , excludedAddressRanges(excludedAddressRanges) +{} + +QString ReadTargetMemory::brief() const { + return "Reading " + QLocale{QLocale::English}.toString(this->size) + " byte(s) from \"" + + QString::fromStdString(this->memorySegmentDescriptor.name) + "\" segment, via \"" + + QString::fromStdString(this->addressSpaceDescriptor.key) + "\" address space"; +} + +TaskGroups ReadTargetMemory::taskGroups() const { + return { + TaskGroup::USES_TARGET_CONTROLLER, + }; +} + void ReadTargetMemory::run(TargetControllerService& targetControllerService) { using Targets::TargetMemorySize; - const auto& targetDescriptor = targetControllerService.getTargetDescriptor(); - const auto memoryDescriptorIt = targetDescriptor.memoryDescriptorsByType.find(this->memoryType); - - if (memoryDescriptorIt == targetDescriptor.memoryDescriptorsByType.end()) { - throw Exceptions::Exception("Invalid memory type"); - } - - const auto& memoryDescriptor = memoryDescriptorIt->second; - /* * To prevent locking up the TargetController for too long, we split the read into numerous reads. * @@ -27,27 +45,27 @@ void ReadTargetMemory::run(TargetControllerService& targetControllerService) { * command timeouts when we're reading lots of data. */ const auto readSize = std::max( - TargetMemorySize(256), - memoryDescriptor.pageSize.value_or(TargetMemorySize(0)) + TargetMemorySize{256}, + this->memorySegmentDescriptor.pageSize.value_or(TargetMemorySize{0}) ); const auto readsRequired = static_cast( std::ceil(static_cast(this->size) / static_cast(readSize)) ); - Targets::TargetMemoryBuffer data; + auto data = Targets::TargetMemoryBuffer{}; + data.reserve(this->size); - for (std::uint32_t i = 0; i < readsRequired; i++) { + for (auto i = std::size_t{0}; i < readsRequired; i++) { auto dataSegment = targetControllerService.readMemory( - this->memoryType, + this->addressSpaceDescriptor, + this->memorySegmentDescriptor, this->startAddress + static_cast(readSize * i), - (this->size - data.size()) >= readSize - ? readSize - : static_cast(this->size - data.size()), + (this->size - data.size()) >= readSize ? readSize : static_cast(this->size - data.size()), true, this->excludedAddressRanges ); - std::move(dataSegment.begin(), dataSegment.end(), std::back_inserter(data)); + data.insert(data.end(), dataSegment.begin(), dataSegment.end()); this->setProgressPercentage(static_cast( (static_cast(i) + 1) / (static_cast(readsRequired) / 100) )); diff --git a/src/Insight/InsightWorker/Tasks/ReadTargetMemory.hpp b/src/Insight/InsightWorker/Tasks/ReadTargetMemory.hpp index 84867474..9ab4a9f5 100644 --- a/src/Insight/InsightWorker/Tasks/ReadTargetMemory.hpp +++ b/src/Insight/InsightWorker/Tasks/ReadTargetMemory.hpp @@ -1,11 +1,10 @@ #pragma once -#include - #include "InsightWorkerTask.hpp" #include "src/Targets/TargetMemory.hpp" -#include "src/Helpers/EnumToStringMappings.hpp" +#include "src/Targets/TargetAddressSpaceDescriptor.hpp" +#include "src/Targets/TargetMemorySegmentDescriptor.hpp" class ReadTargetMemory: public InsightWorkerTask { @@ -13,26 +12,14 @@ class ReadTargetMemory: public InsightWorkerTask public: ReadTargetMemory( - Targets::TargetMemoryType memoryType, + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, Targets::TargetMemoryAddress startAddress, Targets::TargetMemorySize size, const std::set& excludedAddressRanges = {} - ) - : memoryType(memoryType) - , startAddress(startAddress) - , size(size) - , excludedAddressRanges(excludedAddressRanges) - {} - - QString brief() const override { - return "Reading target " + EnumToStringMappings::targetMemoryTypes.at(this->memoryType).toUpper(); - } - - TaskGroups taskGroups() const override { - return TaskGroups({ - TaskGroup::USES_TARGET_CONTROLLER, - }); - }; + ); + [[nodiscard]] QString brief() const override ; + [[nodiscard]] TaskGroups taskGroups() const override; signals: void targetMemoryRead(Targets::TargetMemoryBuffer buffer); @@ -41,7 +28,8 @@ protected: void run(Services::TargetControllerService& targetControllerService) override; private: - Targets::TargetMemoryType memoryType; + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor; + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor; Targets::TargetMemoryAddress startAddress; Targets::TargetMemorySize size; std::set excludedAddressRanges; diff --git a/src/Insight/InsightWorker/Tasks/ReadTargetRegisters.cpp b/src/Insight/InsightWorker/Tasks/ReadTargetRegisters.cpp index cce5dd2a..aeadf646 100644 --- a/src/Insight/InsightWorker/Tasks/ReadTargetRegisters.cpp +++ b/src/Insight/InsightWorker/Tasks/ReadTargetRegisters.cpp @@ -1,7 +1,25 @@ #include "ReadTargetRegisters.hpp" +#include + using Services::TargetControllerService; -void ReadTargetRegisters::run(TargetControllerService& targetControllerService) { - emit this->targetRegistersRead(targetControllerService.readRegisters(this->descriptorIds)); +ReadTargetRegisters::ReadTargetRegisters(const Targets::TargetRegisterDescriptors& descriptors) + : descriptors(descriptors) +{} + +QString ReadTargetRegisters::brief() const { + return this->descriptors.size() == 1 + ? "Reading \"" + QString::fromStdString(this->descriptors.front()->name) + "\" target register" + : "Reading " + QLocale{QLocale::English}.toString(this->descriptors.size()) + " target registers"; +} + +TaskGroups ReadTargetRegisters::taskGroups() const { + return { + TaskGroup::USES_TARGET_CONTROLLER, + }; +} + +void ReadTargetRegisters::run(TargetControllerService& targetControllerService) { + emit this->targetRegistersRead(targetControllerService.readRegisters(this->descriptors)); } diff --git a/src/Insight/InsightWorker/Tasks/ReadTargetRegisters.hpp b/src/Insight/InsightWorker/Tasks/ReadTargetRegisters.hpp index aef9142b..a5df0f3e 100644 --- a/src/Insight/InsightWorker/Tasks/ReadTargetRegisters.hpp +++ b/src/Insight/InsightWorker/Tasks/ReadTargetRegisters.hpp @@ -2,33 +2,22 @@ #include "InsightWorkerTask.hpp" #include "src/Targets/TargetRegisterDescriptor.hpp" -#include "src/Targets/TargetRegister.hpp" class ReadTargetRegisters: public InsightWorkerTask { Q_OBJECT public: - explicit ReadTargetRegisters(const Targets::TargetRegisterDescriptorIds& descriptorIds) - : descriptorIds(descriptorIds) - {} - - QString brief() const override { - return "Reading " + QString::number(this->descriptorIds.size()) + " target register(s)"; - } - - TaskGroups taskGroups() const override { - return TaskGroups({ - TaskGroup::USES_TARGET_CONTROLLER, - }); - }; + explicit ReadTargetRegisters(const Targets::TargetRegisterDescriptors& descriptors); + [[nodiscard]] QString brief() const override; + [[nodiscard]] TaskGroups taskGroups() const override; signals: - void targetRegistersRead(Targets::TargetRegisters registers); + void targetRegistersRead(Targets::TargetRegisterDescriptorAndValuePairs registers); protected: void run(Services::TargetControllerService& targetControllerService) override; private: - Targets::TargetRegisterDescriptorIds descriptorIds; + Targets::TargetRegisterDescriptors descriptors; }; diff --git a/src/Insight/InsightWorker/Tasks/RefreshTargetPinStates.cpp b/src/Insight/InsightWorker/Tasks/RefreshTargetPinStates.cpp deleted file mode 100644 index bfda2bcb..00000000 --- a/src/Insight/InsightWorker/Tasks/RefreshTargetPinStates.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "RefreshTargetPinStates.hpp" - -using Services::TargetControllerService; - -void RefreshTargetPinStates::run(TargetControllerService& targetControllerService) { - emit this->targetPinStatesRetrieved(targetControllerService.getPinStates(this->variantId)); -} diff --git a/src/Insight/InsightWorker/Tasks/RefreshTargetPinStates.hpp b/src/Insight/InsightWorker/Tasks/RefreshTargetPinStates.hpp deleted file mode 100644 index 88704d46..00000000 --- a/src/Insight/InsightWorker/Tasks/RefreshTargetPinStates.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include "InsightWorkerTask.hpp" -#include "src/Targets/TargetPinDescriptor.hpp" - -class RefreshTargetPinStates: public InsightWorkerTask -{ - Q_OBJECT - -public: - explicit RefreshTargetPinStates(int variantId) - : variantId(variantId) - {} - - QString brief() const override { - return "Reading target pin states"; - } - - TaskGroups taskGroups() const override { - return TaskGroups({ - TaskGroup::USES_TARGET_CONTROLLER, - }); - }; - -signals: - void targetPinStatesRetrieved(Targets::TargetPinStateMapping pinStatesByNumber); - -protected: - void run(Services::TargetControllerService& targetControllerService) override; - -private: - int variantId; -}; diff --git a/src/Insight/InsightWorker/Tasks/RetrieveMemorySnapshots.cpp b/src/Insight/InsightWorker/Tasks/RetrieveMemorySnapshots.cpp index 3a9d9522..0e973c6f 100644 --- a/src/Insight/InsightWorker/Tasks/RetrieveMemorySnapshots.cpp +++ b/src/Insight/InsightWorker/Tasks/RetrieveMemorySnapshots.cpp @@ -2,48 +2,74 @@ #include #include -#include +#include #include +#include +#include #include "src/Services/PathService.hpp" -#include "src/Helpers/EnumToStringMappings.hpp" -#include "src/Exceptions/Exception.hpp" #include "src/Logger/Logger.hpp" +#include "src/Exceptions/Exception.hpp" + using Services::TargetControllerService; -RetrieveMemorySnapshots::RetrieveMemorySnapshots(Targets::TargetMemoryType memoryType) - : memoryType(memoryType) +RetrieveMemorySnapshots::RetrieveMemorySnapshots( + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, + const Targets::TargetDescriptor& targetDescriptor +) + : addressSpaceDescriptor(addressSpaceDescriptor) + , memorySegmentDescriptor(memorySegmentDescriptor) + , targetDescriptor(targetDescriptor) {} -void RetrieveMemorySnapshots::run(TargetControllerService& targetControllerService) { - emit this->memorySnapshotsRetrieved(this->getSnapshots(this->memoryType)); +QString RetrieveMemorySnapshots::brief() const { + return "Loading \"" + QString::fromStdString(this->memorySegmentDescriptor.name) + + "\" memory snapshots"; } -std::vector RetrieveMemorySnapshots::getSnapshots(Targets::TargetMemoryType memoryType) { - constexpr auto MAX_SNAPSHOTS = 30; - auto snapshotDir = QDir(QString::fromStdString(Services::PathService::projectSettingsDirPath()) - + "/memory_snapshots/" + EnumToStringMappings::targetMemoryTypes.at(memoryType)); +void RetrieveMemorySnapshots::run(TargetControllerService& targetControllerService) { + if ( + this->targetDescriptor.family == Targets::TargetFamily::AVR_8 + && ( + this->memorySegmentDescriptor.type == Targets::TargetMemorySegmentType::FLASH + || this->memorySegmentDescriptor.type == Targets::TargetMemorySegmentType::EEPROM + || this->memorySegmentDescriptor.type == Targets::TargetMemorySegmentType::RAM + ) + ) { + /* + * Support for RISC-V targets was introduced in the same release as the new snapshots, so all old snapshots + * will be for AVR targets. This is why we only need to perform snapshot migration for AVR targets. + */ + this->migrateOldSnapshotFiles(); + } + emit this->memorySnapshotsRetrieved(this->getSnapshots()); +} + +std::vector RetrieveMemorySnapshots::getSnapshots() { + constexpr auto MAX_SNAPSHOTS = 30; + + const auto snapshotDir = QDir{QString::fromStdString(Services::PathService::memorySnapshotsPath())}; if (!snapshotDir.exists()) { return {}; } - auto snapshots = std::vector(); - const auto snapshotFileEntries = snapshotDir.entryInfoList( - QStringList("*.json"), + {"*.json"}, QDir::Files, QDir::SortFlag::Time ); + auto snapshots = std::vector{}; for (const auto& snapshotFileEntry : snapshotFileEntries) { - auto snapshotFile = QFile(snapshotFileEntry.absoluteFilePath()); + auto snapshotFile = QFile{snapshotFileEntry.absoluteFilePath()}; if (snapshots.size() >= MAX_SNAPSHOTS) { Logger::warning( - "The total number of " + EnumToStringMappings::targetMemoryTypes.at(memoryType).toUpper().toStdString() - + " snapshots exceeds the hard limit of " + std::to_string(MAX_SNAPSHOTS) + "The total number of \"" + this->memorySegmentDescriptor.key + + "\" snapshots exceeds the hard limit of " + std::to_string(MAX_SNAPSHOTS) + ". Only the most recent " + std::to_string(MAX_SNAPSHOTS) + " snapshots will be loaded." ); break; @@ -51,10 +77,18 @@ std::vector RetrieveMemorySnapshots::getSnapshots(Targets::Targe try { if (!snapshotFile.open(QIODevice::ReadOnly | QIODevice::Text)) { - throw Exceptions::Exception("Failed to open snapshot file"); + throw Exceptions::Exception{"Failed to open snapshot file"}; } - snapshots.emplace_back(QJsonDocument::fromJson(snapshotFile.readAll()).object()); + auto snapshot = MemorySnapshot{QJsonDocument::fromJson(snapshotFile.readAll()).object(), targetDescriptor}; + if ( + snapshot.addressSpaceKey != QString::fromStdString(this->addressSpaceDescriptor.key) + || snapshot.memorySegmentKey != QString::fromStdString(this->memorySegmentDescriptor.key) + ) { + continue; + } + + snapshots.emplace_back(std::move(snapshot)); } catch (const Exceptions::Exception& exception) { Logger::error( @@ -68,3 +102,70 @@ std::vector RetrieveMemorySnapshots::getSnapshots(Targets::Targe return snapshots; } + +void RetrieveMemorySnapshots::migrateOldSnapshotFiles() { + const auto newSnapshotDirPath = QString::fromStdString(Services::PathService::memorySnapshotsPath()); + auto oldSnapshotDir = QDir{ + this->memorySegmentDescriptor.type == Targets::TargetMemorySegmentType::FLASH + ? QString::fromStdString(Services::PathService::memorySnapshotsPath()) + "/flash/" + : this->memorySegmentDescriptor.type == Targets::TargetMemorySegmentType::EEPROM + ? QString::fromStdString(Services::PathService::memorySnapshotsPath()) + "/eeprom/" + : QString::fromStdString(Services::PathService::memorySnapshotsPath()) + "/ram/" + }; + + if (!oldSnapshotDir.exists()) { + return; + } + + const auto snapshotFileEntries = oldSnapshotDir.entryInfoList( + {"*.json"}, + QDir::Files, + QDir::SortFlag::Time + ); + + for (const auto& snapshotFileEntry : snapshotFileEntries) { + auto snapshotFile = QFile{snapshotFileEntry.absoluteFilePath()}; + Logger::info("Migrating memory snapshot file \"" + snapshotFileEntry.absoluteFilePath().toStdString() + "\""); + + try { + if (!snapshotFile.open(QIODevice::ReadOnly | QIODevice::Text)) { + throw Exceptions::Exception{"Failed to open snapshot file"}; + } + + auto snapshot = MemorySnapshot{QJsonDocument::fromJson(snapshotFile.readAll()).object(), targetDescriptor}; + if ( + snapshot.addressSpaceKey != QString::fromStdString(this->addressSpaceDescriptor.key) + || snapshot.memorySegmentKey != QString::fromStdString(this->memorySegmentDescriptor.key) + ) { + continue; + } + + const auto snapshotFilePath = newSnapshotDirPath + "/" + snapshot.id + ".json"; + Logger::info("Saving new memory snapshot file to \"" + snapshotFilePath.toStdString() + "\""); + + auto outputFile = QFile{snapshotFilePath}; + if (!outputFile.open(QIODevice::ReadWrite | QIODevice::Truncate | QIODevice::Text)) { + Logger::error("Failed to save snapshot - cannot open " + snapshotFilePath.toStdString()); + return; + } + + outputFile.write(QJsonDocument{snapshot.toJson()}.toJson(QJsonDocument::JsonFormat::Compact)); + outputFile.close(); + + snapshotFile.remove(); + + } catch (const Exceptions::Exception& exception) { + Logger::error( + "Failed to migrate snapshot file " + snapshotFileEntry.absoluteFilePath().toStdString() + " - " + + exception.getMessage() + ); + } + + snapshotFile.close(); + } + +// if (oldSnapshotDir.isEmpty()) { +// Logger::info("Deleting old snapshot directory: \"" + oldSnapshotDir.absolutePath().toStdString() + "\""); +// oldSnapshotDir.removeRecursively(); +// } +} diff --git a/src/Insight/InsightWorker/Tasks/RetrieveMemorySnapshots.hpp b/src/Insight/InsightWorker/Tasks/RetrieveMemorySnapshots.hpp index 67e3813d..bce5dfc0 100644 --- a/src/Insight/InsightWorker/Tasks/RetrieveMemorySnapshots.hpp +++ b/src/Insight/InsightWorker/Tasks/RetrieveMemorySnapshots.hpp @@ -1,10 +1,16 @@ #pragma once #include +#include +#include #include "InsightWorkerTask.hpp" #include "src/Targets/TargetMemory.hpp" +#include "src/Targets/TargetAddressSpaceDescriptor.hpp" +#include "src/Targets/TargetMemorySegmentDescriptor.hpp" +#include "src/Targets/TargetDescriptor.hpp" + #include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemorySnapshot.hpp" #include "src/Helpers/EnumToStringMappings.hpp" @@ -13,12 +19,12 @@ class RetrieveMemorySnapshots: public InsightWorkerTask Q_OBJECT public: - RetrieveMemorySnapshots(Targets::TargetMemoryType memoryType); - - QString brief() const override { - return "Loading saved " + EnumToStringMappings::targetMemoryTypes.at(this->memoryType).toUpper() - + " memory snapshots"; - } + RetrieveMemorySnapshots( + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, + const Targets::TargetDescriptor& targetDescriptor + ); + [[nodiscard]] QString brief() const override; signals: void memorySnapshotsRetrieved(std::vector snapshots); @@ -27,7 +33,10 @@ protected: void run(Services::TargetControllerService& targetControllerService) override; private: - Targets::TargetMemoryType memoryType; + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor; + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor; + const Targets::TargetDescriptor& targetDescriptor; - std::vector getSnapshots(Targets::TargetMemoryType memoryType); + std::vector getSnapshots(); + void migrateOldSnapshotFiles(); }; diff --git a/src/Insight/InsightWorker/Tasks/SetTargetGpioPadState.cpp b/src/Insight/InsightWorker/Tasks/SetTargetGpioPadState.cpp new file mode 100644 index 00000000..669356aa --- /dev/null +++ b/src/Insight/InsightWorker/Tasks/SetTargetGpioPadState.cpp @@ -0,0 +1,25 @@ +#include "SetTargetGpioPadState.hpp" + +using Services::TargetControllerService; + +SetTargetGpioPadState::SetTargetGpioPadState( + const Targets::TargetPadDescriptor& padDescriptor, + const Targets::TargetGpioPadState& state +) + : padDescriptor(padDescriptor) + , state(state) +{} + +QString SetTargetGpioPadState::brief() const { + return "Updating target pin state"; +} + +TaskGroups SetTargetGpioPadState::taskGroups() const { + return { + TaskGroup::USES_TARGET_CONTROLLER, + }; +} + +void SetTargetGpioPadState::run(TargetControllerService& targetControllerService) { + targetControllerService.setGpioPadState(this->padDescriptor, this->state); +} diff --git a/src/Insight/InsightWorker/Tasks/SetTargetGpioPadState.hpp b/src/Insight/InsightWorker/Tasks/SetTargetGpioPadState.hpp new file mode 100644 index 00000000..552ad8c0 --- /dev/null +++ b/src/Insight/InsightWorker/Tasks/SetTargetGpioPadState.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include "InsightWorkerTask.hpp" +#include "src/Targets/TargetPadDescriptor.hpp" +#include "src/Targets/TargetGpioPadState.hpp" + +class SetTargetGpioPadState: public InsightWorkerTask +{ + Q_OBJECT + +public: + SetTargetGpioPadState(const Targets::TargetPadDescriptor& padDescriptor, const Targets::TargetGpioPadState& state); + [[nodiscard]] QString brief() const override; + [[nodiscard]] TaskGroups taskGroups() const override; + +protected: + void run(Services::TargetControllerService& targetControllerService) override; + +private: + const Targets::TargetPadDescriptor& padDescriptor; + Targets::TargetGpioPadState state; +}; diff --git a/src/Insight/InsightWorker/Tasks/SetTargetPinState.cpp b/src/Insight/InsightWorker/Tasks/SetTargetPinState.cpp deleted file mode 100644 index 9bee8418..00000000 --- a/src/Insight/InsightWorker/Tasks/SetTargetPinState.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "SetTargetPinState.hpp" - -using Services::TargetControllerService; - -void SetTargetPinState::run(TargetControllerService& targetControllerService) { - targetControllerService.setPinState(this->pinDescriptor, this->pinState); -} diff --git a/src/Insight/InsightWorker/Tasks/SetTargetPinState.hpp b/src/Insight/InsightWorker/Tasks/SetTargetPinState.hpp deleted file mode 100644 index 58407dc8..00000000 --- a/src/Insight/InsightWorker/Tasks/SetTargetPinState.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include "InsightWorkerTask.hpp" -#include "src/Targets/TargetPinDescriptor.hpp" - -class SetTargetPinState: public InsightWorkerTask -{ - Q_OBJECT - -public: - SetTargetPinState(const Targets::TargetPinDescriptor& pinDescriptor, const Targets::TargetPinState& pinState) - : pinDescriptor(pinDescriptor) - , pinState(pinState) - {} - - QString brief() const override { - return "Updating target pin state"; - } - - TaskGroups taskGroups() const override { - return TaskGroups({ - TaskGroup::USES_TARGET_CONTROLLER, - }); - }; - -protected: - void run(Services::TargetControllerService& targetControllerService) override; - -private: - Targets::TargetPinDescriptor pinDescriptor; - Targets::TargetPinState pinState; -}; diff --git a/src/Insight/InsightWorker/Tasks/WriteTargetMemory.cpp b/src/Insight/InsightWorker/Tasks/WriteTargetMemory.cpp index 02a03aa7..5929d3b2 100644 --- a/src/Insight/InsightWorker/Tasks/WriteTargetMemory.cpp +++ b/src/Insight/InsightWorker/Tasks/WriteTargetMemory.cpp @@ -1,18 +1,52 @@ #include "WriteTargetMemory.hpp" #include +#include #include #include #include "src/Exceptions/Exception.hpp" using Services::TargetControllerService; +using Targets::TargetMemorySize; + +WriteTargetMemory::WriteTargetMemory( + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, + std::vector&& blocks +) + : addressSpaceDescriptor(addressSpaceDescriptor) + , memorySegmentDescriptor(memorySegmentDescriptor) + , blocks(std::move(blocks)) +{} + +WriteTargetMemory::WriteTargetMemory( + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, + Targets::TargetMemoryAddress startAddress, + const Targets::TargetMemoryBuffer& data +) + : WriteTargetMemory( + addressSpaceDescriptor, + memorySegmentDescriptor, + std::vector{{startAddress, data}} + ) +{} + +QString WriteTargetMemory::brief() const { + return "Writing " + QLocale{QLocale::English}.toString(this->totalSize()) + " byte(s) to \"" + + QString::fromStdString(this->memorySegmentDescriptor.name) + "\""; +} + +TaskGroups WriteTargetMemory::taskGroups() const { + return { + TaskGroup::USES_TARGET_CONTROLLER, + }; +} void WriteTargetMemory::run(TargetControllerService& targetControllerService) { - using Targets::TargetMemorySize; - - if (!this->memoryDescriptor.access.writeableDuringDebugSession) { - throw Exceptions::Exception("Invalid request - cannot write to this memory type during a debug session."); + if (!this->memorySegmentDescriptor.debugModeAccess.writeable) { + throw Exceptions::Exception{"Invalid request - cannot write to this memory segment during a debug session."}; } /* @@ -23,20 +57,12 @@ void WriteTargetMemory::run(TargetControllerService& targetControllerService) { * command timeouts when we're writing lots of data. */ const auto maxBlockSize = std::max( - TargetMemorySize(256), - this->memoryDescriptor.pageSize.value_or(TargetMemorySize(0)) + TargetMemorySize{256}, + this->memorySegmentDescriptor.pageSize.value_or(TargetMemorySize{0}) ); - const TargetMemorySize totalBytesToWrite = std::accumulate( - this->blocks.begin(), - this->blocks.end(), - TargetMemorySize{0}, - [] (TargetMemorySize bytes, const Block& block) { - return bytes + block.data.size(); - } - ); - - TargetMemorySize totalBytesWritten = 0; + const auto writeSize = this->totalSize(); + auto totalBytesWritten = TargetMemorySize{0}; for (const auto& block : this->blocks) { const auto totalBytes = block.data.size(); @@ -50,22 +76,34 @@ void WriteTargetMemory::run(TargetControllerService& targetControllerService) { ); targetControllerService.writeMemory( - this->memoryDescriptor.type, + this->addressSpaceDescriptor, + this->memorySegmentDescriptor, block.startAddress + bytesWritten, - Targets::TargetMemoryBuffer( + Targets::TargetMemoryBuffer{ block.data.begin() + bytesWritten, block.data.begin() + bytesWritten + bytesToWrite - ) + } ); bytesWritten += bytesToWrite; totalBytesWritten += bytesToWrite; this->setProgressPercentage(static_cast( - (static_cast(totalBytesWritten) + 1) / (static_cast(totalBytesToWrite) / 100) + (static_cast(totalBytesWritten) + 1) / (static_cast(writeSize) / 100) )); } } emit this->targetMemoryWritten(totalBytesWritten); } + +TargetMemorySize WriteTargetMemory::totalSize() const { + return std::accumulate( + this->blocks.begin(), + this->blocks.end(), + TargetMemorySize{0}, + [] (TargetMemorySize bytes, const Block& block) { + return bytes + block.data.size(); + } + ); +} diff --git a/src/Insight/InsightWorker/Tasks/WriteTargetMemory.hpp b/src/Insight/InsightWorker/Tasks/WriteTargetMemory.hpp index 8f1ddd5b..5c30f071 100644 --- a/src/Insight/InsightWorker/Tasks/WriteTargetMemory.hpp +++ b/src/Insight/InsightWorker/Tasks/WriteTargetMemory.hpp @@ -5,7 +5,8 @@ #include "InsightWorkerTask.hpp" #include "src/Targets/TargetMemory.hpp" -#include "src/Helpers/EnumToStringMappings.hpp" +#include "src/Targets/TargetAddressSpaceDescriptor.hpp" +#include "src/Targets/TargetMemorySegmentDescriptor.hpp" class WriteTargetMemory: public InsightWorkerTask { @@ -30,33 +31,18 @@ public: }; WriteTargetMemory( - const Targets::TargetMemoryDescriptor& memoryDescriptor, + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, std::vector&& blocks - ) - : memoryDescriptor(memoryDescriptor) - , blocks(std::move(blocks)) - {} - + ); WriteTargetMemory( - const Targets::TargetMemoryDescriptor& memoryDescriptor, + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, Targets::TargetMemoryAddress startAddress, const Targets::TargetMemoryBuffer& data - ) - : WriteTargetMemory(memoryDescriptor, std::vector({{startAddress, data}})) - {} - - QString brief() const override { - return - "Writing to target " + EnumToStringMappings::targetMemoryTypes.at( - this->memoryDescriptor.type - ).toUpper(); - } - - TaskGroups taskGroups() const override { - return TaskGroups({ - TaskGroup::USES_TARGET_CONTROLLER, - }); - } + ); + [[nodiscard]] QString brief() const override; + [[nodiscard]] TaskGroups taskGroups() const override; signals: void targetMemoryWritten(Targets::TargetMemorySize bytesWritten); @@ -65,6 +51,9 @@ protected: void run(Services::TargetControllerService& targetControllerService) override; private: - Targets::TargetMemoryDescriptor memoryDescriptor; + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor; + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor; std::vector blocks; + + [[nodiscard]] Targets::TargetMemorySize totalSize() const; }; diff --git a/src/Insight/InsightWorker/Tasks/WriteTargetRegister.cpp b/src/Insight/InsightWorker/Tasks/WriteTargetRegister.cpp index bfd43266..1728d5ed 100644 --- a/src/Insight/InsightWorker/Tasks/WriteTargetRegister.cpp +++ b/src/Insight/InsightWorker/Tasks/WriteTargetRegister.cpp @@ -2,6 +2,20 @@ using Services::TargetControllerService; -void WriteTargetRegister::run(TargetControllerService& targetControllerService) { - targetControllerService.writeRegisters({this->targetRegister}); +WriteTargetRegister::WriteTargetRegister(const Targets::TargetRegisterDescriptorAndValuePair& registerPair) + : registerPair(registerPair) +{} + +QString WriteTargetRegister::brief() const { + return "Writing to target register \"" + QString::fromStdString(this->registerPair.first.name) + "\""; +} + +TaskGroups WriteTargetRegister::taskGroups() const { + return { + TaskGroup::USES_TARGET_CONTROLLER, + }; +} + +void WriteTargetRegister::run(TargetControllerService& targetControllerService) { + targetControllerService.writeRegisters({this->registerPair}); } diff --git a/src/Insight/InsightWorker/Tasks/WriteTargetRegister.hpp b/src/Insight/InsightWorker/Tasks/WriteTargetRegister.hpp index 0eb2d681..655366ee 100644 --- a/src/Insight/InsightWorker/Tasks/WriteTargetRegister.hpp +++ b/src/Insight/InsightWorker/Tasks/WriteTargetRegister.hpp @@ -1,30 +1,20 @@ #pragma once #include "InsightWorkerTask.hpp" -#include "src/Targets/TargetRegister.hpp" +#include "src/Targets/TargetRegisterDescriptor.hpp" class WriteTargetRegister: public InsightWorkerTask { Q_OBJECT public: - explicit WriteTargetRegister(const Targets::TargetRegister& targetRegister) - : targetRegister(targetRegister) - {} - - QString brief() const override { - return "Writing target register"; - } - - TaskGroups taskGroups() const override { - return TaskGroups({ - TaskGroup::USES_TARGET_CONTROLLER, - }); - }; + explicit WriteTargetRegister(const Targets::TargetRegisterDescriptorAndValuePair& registerPair); + [[nodiscard]] QString brief() const override; + [[nodiscard]] TaskGroups taskGroups() const override; protected: void run(Services::TargetControllerService& targetControllerService) override; private: - Targets::TargetRegister targetRegister; + Targets::TargetRegisterDescriptorAndValuePair registerPair; }; diff --git a/src/Insight/UserInterfaces/InsightWindow/AboutWindow.cpp b/src/Insight/UserInterfaces/InsightWindow/AboutWindow.cpp index 8cc4ab07..f4de1b20 100644 --- a/src/Insight/UserInterfaces/InsightWindow/AboutWindow.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/AboutWindow.cpp @@ -11,26 +11,28 @@ using namespace Exceptions; AboutWindow::AboutWindow(QWidget* parent): QObject(parent) { - auto aboutWindowUiFile = QFile(QString::fromStdString( + auto aboutWindowUiFile = QFile{ + QString::fromStdString( Services::PathService::compiledResourcesPath() - + "/src/Insight/UserInterfaces/InsightWindow/UiFiles/AboutWindow.ui" + + "/src/Insight/UserInterfaces/InsightWindow/UiFiles/AboutWindow.ui" ) - ); - auto aboutWindowStylesheet = QFile(QString::fromStdString( + }; + auto aboutWindowStylesheet = QFile{ + QString::fromStdString( Services::PathService::compiledResourcesPath() - + "/src/Insight/UserInterfaces/InsightWindow/Stylesheets/AboutWindow.qss" + + "/src/Insight/UserInterfaces/InsightWindow/Stylesheets/AboutWindow.qss" ) - ); + }; if (!aboutWindowUiFile.open(QFile::ReadOnly)) { - throw Exception("Failed to open AboutWindow UI file"); + throw Exception{"Failed to open AboutWindow UI file"}; } if (!aboutWindowStylesheet.open(QFile::ReadOnly)) { - throw Exception("Failed to open AboutWindow QSS file"); + throw Exception{"Failed to open AboutWindow QSS file"}; } - auto uiLoader = UiLoader(this); + auto uiLoader = UiLoader{this}; this->windowWidget = uiLoader.load(&aboutWindowUiFile, parent); this->windowWidget->setStyleSheet(aboutWindowStylesheet.readAll()); this->windowWidget->setFixedSize(400, 300); diff --git a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp index c07a432f..baa3a22d 100644 --- a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp @@ -10,30 +10,29 @@ #include "Widgets/TargetWidgets/DIP/DualInlinePackageWidget.hpp" #include "Widgets/TargetWidgets/QFP/QuadFlatPackageWidget.hpp" +#include "Widgets/TargetMemoryInspectionPane/ToolButton.hpp" + #include "src/Logger/Logger.hpp" #include "src/Exceptions/Exception.hpp" #include "src/Services/PathService.hpp" #include "src/Insight/InsightSignals.hpp" #include "src/Insight/InsightWorker/InsightWorker.hpp" -#include "src/Insight/InsightWorker/Tasks/ReadProgramCounter.hpp" using namespace Exceptions; using namespace Widgets; using Targets::TargetDescriptor; using Targets::TargetState; -using Targets::TargetPinState; -using Targets::TargetVariant; -using Targets::TargetPackage; +using Targets::TargetExecutionState; using Targets::TargetPinDescriptor; -using Targets::TargetMemoryType; InsightWindow::InsightWindow( InsightProjectSettings& insightProjectSettings, const InsightConfig& insightConfig, const EnvironmentConfig& environmentConfig, - const Targets::TargetDescriptor& targetDescriptor + const TargetDescriptor& targetDescriptor, + const TargetState& targetState ) : QMainWindow(nullptr) , insightProjectSettings(insightProjectSettings) @@ -41,55 +40,56 @@ InsightWindow::InsightWindow( , environmentConfig(environmentConfig) , targetConfig(environmentConfig.targetConfig) , targetDescriptor(targetDescriptor) + , targetState(targetState) { this->setObjectName("main-window"); this->setAttribute(Qt::WA_DeleteOnClose, true); this->setWindowTitle("Bloom Insight"); - auto windowSize = QSize(1000, 500); + constexpr auto defaultWindowSize = QSize{1000, 500}; - if (this->insightProjectSettings.mainWindowSize.has_value()) { - windowSize = QSize( - std::max(this->insightProjectSettings.mainWindowSize->width(), windowSize.width()), - std::max(this->insightProjectSettings.mainWindowSize->height(), windowSize.height()) - ); - } + const auto windowSize = this->insightProjectSettings.mainWindowSize.has_value() + ? QSize{ + std::max(this->insightProjectSettings.mainWindowSize->width(), defaultWindowSize.width()), + std::max(this->insightProjectSettings.mainWindowSize->height(), defaultWindowSize.height()) + } + : defaultWindowSize; this->setFixedSize(windowSize); this->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); this->setMinimumSize(0, 0); - auto mainWindowUiFile = QFile( + auto mainWindowUiFile = QFile{ QString::fromStdString(Services::PathService::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/UiFiles/InsightWindow.ui" ) - ); - auto mainWindowStylesheet = QFile( + }; + auto mainWindowStylesheet = QFile{ QString::fromStdString(Services::PathService::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Stylesheets/InsightWindow.qss" ) - ); + }; if (!mainWindowUiFile.open(QFile::ReadOnly)) { - throw Exception("Failed to open InsightWindow UI file"); + throw Exception{"Failed to open InsightWindow UI file"}; } if (!mainWindowStylesheet.open(QFile::ReadOnly)) { - throw Exception("Failed to open InsightWindow stylesheet file"); + throw Exception{"Failed to open InsightWindow stylesheet file"}; } - auto uiLoader = UiLoader(this); + auto uiLoader = UiLoader{this}; this->windowContainer = uiLoader.load(&mainWindowUiFile, this); this->windowContainer->setStyleSheet(mainWindowStylesheet.readAll()); mainWindowUiFile.close(); mainWindowStylesheet.close(); - QApplication::setWindowIcon(QIcon( + QApplication::setWindowIcon(QIcon{ QString::fromStdString(Services::PathService::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Images/bloom-icon.svg" ) - )); + }); this->layoutContainer = this->windowContainer->findChild("layout-container"); this->mainMenuBar = this->windowContainer->findChild("menu-bar"); @@ -98,7 +98,6 @@ InsightWindow::InsightWindow( this->ioContainerWidget = this->windowContainer->findChild( "io-container" ); - this->ioUnavailableWidget = this->windowContainer->findChild("io-inspection-unavailable"); auto* horizontalContentLayout = this->container->findChild("horizontal-content-layout"); auto* verticalContentLayout = this->container->findChild("vertical-content-layout"); @@ -115,19 +114,19 @@ InsightWindow::InsightWindow( // Create panel states if (!this->insightProjectSettings.leftPanelState.has_value()) { - this->insightProjectSettings.leftPanelState = PanelState(); + this->insightProjectSettings.leftPanelState = PanelState{}; } if (!this->insightProjectSettings.bottomPanelState.has_value()) { - this->insightProjectSettings.bottomPanelState = PanelState(); + this->insightProjectSettings.bottomPanelState = PanelState{}; } this->leftMenuBar = this->container->findChild("left-side-menu-bar"); - this->leftPanel = new PanelWidget( + this->leftPanel = new PanelWidget{ PanelWidgetType::LEFT, this->insightProjectSettings.leftPanelState.value(), this->container - ); + }; this->leftPanel->setObjectName("left-panel"); this->leftPanel->setHandleSize(6); this->leftPanel->setMinimumResize(300); @@ -135,25 +134,22 @@ InsightWindow::InsightWindow( this->targetRegistersButton = this->container->findChild("target-registers-btn"); auto* targetRegisterButtonLayout = this->targetRegistersButton->findChild(); - auto* registersBtnLabel = new RotatableLabel(270, "Registers", this->targetRegistersButton); + auto* registersBtnLabel = new RotatableLabel{270, "Registers", this->targetRegistersButton}; registersBtnLabel->setObjectName("target-registers-btn-label"); registersBtnLabel->setContentsMargins(4, 4, 10, 2); targetRegisterButtonLayout->insertWidget(0, registersBtnLabel, 0, Qt::AlignTop); this->bottomMenuBar = this->container->findChild("bottom-menu-bar"); - this->bottomPanel = new PanelWidget( + this->bottomMenuBarLayout = this->bottomMenuBar->findChild(); + this->bottomPanel = new PanelWidget{ PanelWidgetType::BOTTOM, this->insightProjectSettings.bottomPanelState.value(), this->container - ); + }; this->bottomPanel->setObjectName("bottom-panel"); this->bottomPanel->setHandleSize(10); verticalContentLayout->insertWidget(1, this->bottomPanel); - this->ramInspectionButton = this->container->findChild("ram-inspection-btn"); - this->eepromInspectionButton = this->container->findChild("eeprom-inspection-btn"); - this->flashInspectionButton = this->container->findChild("flash-inspection-btn"); - this->footer = this->windowContainer->findChild("footer"); this->targetStatusLabel = this->footer->findChild("target-state"); this->programCounterValueLabel = this->footer->findChild("target-program-counter-value"); @@ -161,7 +157,7 @@ InsightWindow::InsightWindow( this->targetIdLabel = this->footer->findChild("target-id"); this->variantMenu = this->footer->findChild("target-variant-menu"); - this->taskIndicator = new TaskIndicator(this); + this->taskIndicator = new TaskIndicator{this}; auto* footerLayout = this->footer->findChild(); footerLayout->insertWidget(2, this->taskIndicator); @@ -177,14 +173,6 @@ InsightWindow::InsightWindow( this, &InsightWindow::onTargetStateUpdate ); - QObject::connect( - insightSignals, - &InsightSignals::targetReset, - this, - [this] { - this->refreshProgramCounter(); - } - ); QObject::connect( insightSignals, @@ -200,30 +188,11 @@ InsightWindow::InsightWindow( ); this->targetNameLabel->setText(QString::fromStdString(this->targetDescriptor.name)); - this->targetIdLabel->setText("0x" + QString::fromStdString(this->targetDescriptor.id).remove("0x").toUpper()); - - this->ioUnavailableWidget->hide(); + this->targetIdLabel->setText(QString::fromStdString(this->targetDescriptor.marketId)); this->populateVariantMenu(); this->variantMenu->setEnabled(true); - - Logger::debug("Number of target variants supported by Insight: " - + std::to_string(supportedVariantsByName.size())); - - if (this->supportedVariantsByName.empty()) { - if (this->targetDescriptor.variants.empty()) { - this->variantMenu->parentWidget()->hide(); - } - - this->ioUnavailableWidget->setText( - "GPIO inspection is not available for this target. " - "Please report this to Bloom developers by clicking Help -> Report An Issue" - ); - this->ioUnavailableWidget->show(); - - } else { - this->selectDefaultVariant(); - } + this->selectDefaultVariant(); this->createPanes(); this->setUiDisabled(true); @@ -295,24 +264,8 @@ InsightWindow::InsightWindow( this, &InsightWindow::toggleTargetRegistersPane ); - QObject::connect( - this->ramInspectionButton, - &QToolButton::clicked, - this, - &InsightWindow::toggleRamInspectionPane - ); - QObject::connect( - this->eepromInspectionButton, - &QToolButton::clicked, - this, - &InsightWindow::toggleEepromInspectionPane - ); - QObject::connect( - this->flashInspectionButton, - &QToolButton::clicked, - this, - &InsightWindow::toggleFlashInspectionPane - ); + + this->onTargetStateUpdate(this->targetState, {}); } void InsightWindow::resizeEvent(QResizeEvent* event) { @@ -335,51 +288,40 @@ void InsightWindow::closeEvent(QCloseEvent* event) { return QMainWindow::closeEvent(event); } -bool InsightWindow::isVariantSupported(const TargetVariant& variant) { - const auto pinCount = variant.pinDescriptorsByNumber.size(); +bool InsightWindow::isPinoutSupported(const Targets::TargetPinoutDescriptor& pinoutDescriptor) { + using Targets::TargetPinoutType; + + const auto pinCount = pinoutDescriptor.pinDescriptors.size(); - /* - * Because the size of the pin body widget is fixed, for all of our target package widgets, we run out of screen - * estate for target variants with more than 100 pins. - * - * This will be addressed at some point, but for now, we just won't support variants with more than 100 pins. - * - * I don't think there are any AVR targets with variants with more than 100 pins, so this isn't a problem anyway. - */ if (pinCount > 100) { return false; } if ( - variant.package != TargetPackage::DIP - && variant.package != TargetPackage::SOIC - && variant.package != TargetPackage::SSOP - && variant.package != TargetPackage::QFP - && variant.package != TargetPackage::QFN + pinoutDescriptor.type != TargetPinoutType::DIP + && pinoutDescriptor.type != TargetPinoutType::SOIC + && pinoutDescriptor.type != TargetPinoutType::SSOP + && pinoutDescriptor.type != TargetPinoutType::QFP + && pinoutDescriptor.type != TargetPinoutType::QFN ) { return false; } if ( ( - variant.package == TargetPackage::DIP - || variant.package == TargetPackage::SOIC - || variant.package == TargetPackage::SSOP + pinoutDescriptor.type == TargetPinoutType::DIP + || pinoutDescriptor.type == TargetPinoutType::SOIC + || pinoutDescriptor.type == TargetPinoutType::SSOP ) && pinCount % 2 != 0 ) { - // All DIP, SOIC and SSOP variants must have a pin count that is a multiple of two return false; } if ( - (variant.package == TargetPackage::QFP || variant.package == TargetPackage::QFN) + (pinoutDescriptor.type == TargetPinoutType::QFP || pinoutDescriptor.type == TargetPinoutType::QFN) && (pinCount % 4 != 0 || pinCount <= 4) ) { - /* - * All QFP and QFN variants must have a pin count that is a multiple of four. And there must be - * more than one pin per side. - */ return false; } @@ -396,56 +338,25 @@ void InsightWindow::setUiDisabled(bool disable) { } void InsightWindow::populateVariantMenu() { - /* - * We don't want to present the user with duplicate target variants. - * - * In the context of the Insight window, two variants are considered to be duplicates if they do not differ in - * package type and pinout configuration. - */ - auto processedVariants = std::vector(); - const auto isDuplicateVariant = [&processedVariants] (const TargetVariant& variantA) { - return std::ranges::any_of( - processedVariants.begin(), - processedVariants.end(), - [&variantA, &processedVariants] (const TargetVariant& variantB) { - if (variantA.package != variantB.package) { - return false; - } + for (const auto& [variantKey, variantDescriptor] : this->targetDescriptor.variantDescriptorsByKey) { + const auto& pinoutDescriptor = this->targetDescriptor.getPinoutDescriptor(variantDescriptor.pinoutKey); - if (variantA.pinDescriptorsByNumber.size() != variantB.pinDescriptorsByNumber.size()) { - return false; - } - - if (variantA.pinDescriptorsByNumber != variantB.pinDescriptorsByNumber) { - return false; - } - - return true; - } - ); - }; - - for (const auto& targetVariant: this->targetDescriptor.variants) { - if (isDuplicateVariant(targetVariant)) { - continue; - } - - auto* variantAction = new QAction(this->variantMenu); + auto* variantAction = new QAction{this->variantMenu}; variantAction->setText( - QString::fromStdString(targetVariant.name + " (" + targetVariant.packageName + ")") + QString::fromStdString(variantDescriptor.name + " (" + pinoutDescriptor.name + ")") ); - if (InsightWindow::isVariantSupported(targetVariant)) { - auto* supportedVariantPtr = &(this->supportedVariantsByName.insert( - std::pair(QString::fromStdString(targetVariant.name).toLower(), targetVariant) - ).first->second); - + if (InsightWindow::isPinoutSupported(pinoutDescriptor)) { QObject::connect( variantAction, &QAction::triggered, this, - [this, supportedVariantPtr] { - this->selectVariant(supportedVariantPtr); + [this, &variantDescriptor] { + this->selectVariant(&variantDescriptor); + + if (this->targetState.executionState == TargetExecutionState::STOPPED) { + this->refreshPadStates(); + } } ); @@ -455,60 +366,87 @@ void InsightWindow::populateVariantMenu() { } this->variantMenu->addAction(variantAction); - processedVariants.push_back(targetVariant); } } void InsightWindow::selectDefaultVariant() { - if (this->supportedVariantsByName.empty()) { + if (this->targetDescriptor.variantDescriptorsByKey.empty()) { return; } - std::optional previouslySelectedVariantName = (this->previouslySelectedVariant.has_value()) - ? std::optional(QString::fromStdString(this->previouslySelectedVariant->name).toLower()) - : std::nullopt; - - if (previouslySelectedVariantName.has_value()) { - const auto previouslySelectedVariantIt = this->supportedVariantsByName.find(*previouslySelectedVariantName); - - if (previouslySelectedVariantIt != this->supportedVariantsByName.end()) { - this->selectVariant(&(previouslySelectedVariantIt->second)); - return; - } - } - - if (this->targetConfig.variantName.has_value()) { - const auto variantIt = this->supportedVariantsByName.find( - QString::fromStdString(*this->targetConfig.variantName) + // Try the user provided variant key, if provided + if (this->insightConfig.defaultVariantKey.has_value()) { + const auto variantDescriptor = this->targetDescriptor.tryGetVariantDescriptor( + *(this->insightConfig.defaultVariantKey) ); - if (variantIt != this->supportedVariantsByName.end()) { - // The user has specified a valid variant name in their config file, so use that as the default - this->selectVariant(&(variantIt->second)); + if (variantDescriptor.has_value()) { + const auto& descriptor = variantDescriptor->get(); + const auto& pinoutDescriptor = this->targetDescriptor.getPinoutDescriptor(descriptor.pinoutKey); + + if (InsightWindow::isPinoutSupported(pinoutDescriptor)) { + this->selectVariant(&descriptor); + return; + + } else { + Logger::error( + "Unsupported target variant (\"" + descriptor.name + + "\") provided via 'defaultVariantKey' parameter" + ); + } } else { Logger::error( - "Invalid target variant name \"" + this->targetConfig.variantName.value() - + "\" - no such variant with the given name was found." + "Invalid target variant key \"" + *(this->insightConfig.defaultVariantKey) + + "\" - no such variant with the given key was found" ); } } + // Try the previously selected variant + if (this->insightProjectSettings.selectedVariantKey.has_value()) { + const auto variantDescriptor = this->targetDescriptor.tryGetVariantDescriptor( + *(this->insightProjectSettings.selectedVariantKey) + ); + + if (variantDescriptor.has_value()) { + const auto& descriptor = variantDescriptor->get(); + const auto& pinoutDescriptor = this->targetDescriptor.getPinoutDescriptor(descriptor.pinoutKey); + + if (InsightWindow::isPinoutSupported(pinoutDescriptor)) { + this->selectVariant(&descriptor); + return; + } + } + } + /* * Given that we haven't been able to select a variant at this point, we will just fall back to the first * one that is available. */ - this->selectVariant(&(this->supportedVariantsByName.begin()->second)); + for (const auto& [variantKey, variantDescriptor] : this->targetDescriptor.variantDescriptorsByKey) { + const auto& pinoutDescriptor = this->targetDescriptor.getPinoutDescriptor(variantDescriptor.pinoutKey); + + if (InsightWindow::isPinoutSupported(pinoutDescriptor)) { + this->selectVariant(&variantDescriptor); + return; + } + } + + Logger::error("Failed to select a target variant - no supported variants"); } -void InsightWindow::selectVariant(const TargetVariant* variant) { - if (!this->isVariantSupported(*variant)) { - Logger::error("Attempted to select unsupported target variant."); +void InsightWindow::selectVariant(const Targets::TargetVariantDescriptor* variantDescriptor) { + using Targets::TargetPinoutType; + + if (this->selectedVariantDescriptor != nullptr && this->selectedVariantDescriptor == variantDescriptor) { + // The variant is already selected. return; } - if (this->selectedVariant != nullptr && this->selectedVariant->id == variant->id) { - // The variant is already selected. + const auto& pinoutDescriptor = this->targetDescriptor.getPinoutDescriptor(variantDescriptor->pinoutKey); + if (!InsightWindow::isPinoutSupported(pinoutDescriptor)) { + Logger::error("Attempted to select unsupported target variant."); return; } @@ -519,33 +457,35 @@ void InsightWindow::selectVariant(const TargetVariant* variant) { this->ioContainerWidget->setPackageWidget(this->targetPackageWidget); } - this->selectedVariant = variant; - this->variantMenu->setTitle(QString::fromStdString(variant->name + " (" + variant->packageName + ")")); + this->selectedVariantDescriptor = variantDescriptor; + this->insightProjectSettings.selectedVariantKey = variantDescriptor->key; + this->variantMenu->setTitle(QString::fromStdString(variantDescriptor->name + " (" + pinoutDescriptor.name + ")")); if ( - variant->package == TargetPackage::DIP - || variant->package == TargetPackage::SOIC - || variant->package == TargetPackage::SSOP + pinoutDescriptor.type == TargetPinoutType::DIP + || pinoutDescriptor.type == TargetPinoutType::SOIC + || pinoutDescriptor.type == TargetPinoutType::SSOP ) { - this->targetPackageWidget = new InsightTargetWidgets::Dip::DualInlinePackageWidget( - *variant, + this->targetPackageWidget = new InsightTargetWidgets::Dip::DualInlinePackageWidget{ + *variantDescriptor, + pinoutDescriptor, + this->targetDescriptor, + this->targetState, this->ioContainerWidget - ); + }; - } else if (variant->package == TargetPackage::QFP || variant->package == TargetPackage::QFN) { - this->targetPackageWidget = new InsightTargetWidgets::Qfp::QuadFlatPackageWidget( - *variant, + } else if (pinoutDescriptor.type == TargetPinoutType::QFP || pinoutDescriptor.type == TargetPinoutType::QFN) { + this->targetPackageWidget = new InsightTargetWidgets::Qfp::QuadFlatPackageWidget{ + *variantDescriptor, + pinoutDescriptor, + this->targetDescriptor, + this->targetState, this->ioContainerWidget - ); + }; } if (this->targetPackageWidget != nullptr) { this->ioContainerWidget->setPackageWidget(this->targetPackageWidget); - this->targetPackageWidget->setTargetState(this->targetState); - - if (this->targetState == TargetState::STOPPED) { - this->refreshPinStates(); - } this->adjustPanels(); this->adjustMinimumSize(); @@ -556,15 +496,16 @@ void InsightWindow::selectVariant(const TargetVariant* variant) { void InsightWindow::createPanes() { // Target registers pane if (!this->insightProjectSettings.registersPaneState.has_value()) { - this->insightProjectSettings.registersPaneState = PaneState(false, true, std::nullopt); + this->insightProjectSettings.registersPaneState = PaneState{false, true, std::nullopt}; } auto* leftPanelLayout = this->leftPanel->layout(); - this->targetRegistersSidePane = new TargetRegistersPaneWidget( + this->targetRegistersSidePane = new TargetRegistersPaneWidget{ this->targetDescriptor, + this->targetState, *(this->insightProjectSettings.registersPaneState), this->leftPanel - ); + }; leftPanelLayout->addWidget(this->targetRegistersSidePane); QObject::connect( @@ -583,143 +524,82 @@ void InsightWindow::createPanes() { this->targetRegistersButton->setDisabled(false); this->onRegistersPaneStateChanged(); - auto& memoryInspectionPaneSettingsByMemoryType = - this->insightProjectSettings.memoryInspectionPaneSettingsByMemoryType; - // Target memory inspection panes auto* bottomPanelLayout = this->bottomPanel->layout(); - const auto ramDescriptorIt = this->targetDescriptor.memoryDescriptorsByType.find(TargetMemoryType::RAM); - const auto eepromDescriptorIt = this->targetDescriptor.memoryDescriptorsByType.find(TargetMemoryType::EEPROM); - const auto flashDescriptorIt = this->targetDescriptor.memoryDescriptorsByType.find(TargetMemoryType::FLASH); + for (const auto& [addressSpaceKey, addressSpaceDescriptor] : this->targetDescriptor.addressSpaceDescriptorsByKey) { + for (const auto& [segmentKey, segmentDescriptor] : addressSpaceDescriptor.segmentDescriptorsByKey) { + if (!segmentDescriptor.inspectionEnabled) { + continue; + } - if (ramDescriptorIt != this->targetDescriptor.memoryDescriptorsByType.end()) { - if (!this->insightProjectSettings.ramInspectionPaneState.has_value()) { - this->insightProjectSettings.ramInspectionPaneState = PaneState(false, true, std::nullopt); + auto* inspectionPane = new TargetMemoryInspectionPane{ + addressSpaceDescriptor, + segmentDescriptor, + this->targetDescriptor, + this->targetState, + this->insightProjectSettings.findOrCreateMemoryInspectionPaneSettings( + QString::fromStdString(addressSpaceDescriptor.key), + QString::fromStdString(segmentDescriptor.key) + ), + this->insightProjectSettings.findOrCreateMemoryInspectionPaneState( + QString::fromStdString(addressSpaceDescriptor.key), + QString::fromStdString(segmentDescriptor.key) + ), + this->bottomPanel + }; + + this->memoryInspectionPaneWidgets.push_back(inspectionPane); + bottomPanelLayout->addWidget(inspectionPane); + + auto* inspectionPaneBtn = new ToolButton{ + QString::fromStdString(segmentDescriptor.name), + this->bottomMenuBar + }; + + QObject::connect( + inspectionPaneBtn, + &QToolButton::clicked, + this, + [this, inspectionPane] { + this->toggleMemoryInspectionPane(inspectionPane); + } + ); + + const auto onPaneStateChanged = [this, inspectionPane, inspectionPaneBtn] { + this->onMemoryInspectionPaneStateChanged(inspectionPane, inspectionPaneBtn); + }; + + QObject::connect( + inspectionPane, + &PaneWidget::paneActivated, + this, + onPaneStateChanged + ); + QObject::connect( + inspectionPane, + &PaneWidget::paneDeactivated, + this, + onPaneStateChanged + ); + QObject::connect( + inspectionPane, + &PaneWidget::paneAttached, + this, + onPaneStateChanged + ); + + this->bottomMenuBarLayout->insertWidget(1, inspectionPaneBtn); + this->onMemoryInspectionPaneStateChanged(inspectionPane, inspectionPaneBtn); } - - if (!memoryInspectionPaneSettingsByMemoryType.contains(TargetMemoryType::RAM)) { - memoryInspectionPaneSettingsByMemoryType[TargetMemoryType::RAM] = TargetMemoryInspectionPaneSettings(); - } - - this->ramInspectionPane = new TargetMemoryInspectionPane( - ramDescriptorIt->second, - memoryInspectionPaneSettingsByMemoryType[TargetMemoryType::RAM], - *(this->insightProjectSettings.ramInspectionPaneState), - this->bottomPanel - ); - - bottomPanelLayout->addWidget(this->ramInspectionPane); - - QObject::connect( - this->ramInspectionPane, - &PaneWidget::paneActivated, - this, - &InsightWindow::onRamInspectionPaneStateChanged - ); - QObject::connect( - this->ramInspectionPane, - &PaneWidget::paneDeactivated, - this, - &InsightWindow::onRamInspectionPaneStateChanged - ); - QObject::connect( - this->ramInspectionPane, - &PaneWidget::paneAttached, - this, - &InsightWindow::onRamInspectionPaneStateChanged - ); - - this->ramInspectionButton->setDisabled(false); - this->onRamInspectionPaneStateChanged(); } - if (eepromDescriptorIt != this->targetDescriptor.memoryDescriptorsByType.end()) { - if (!this->insightProjectSettings.eepromInspectionPaneState.has_value()) { - this->insightProjectSettings.eepromInspectionPaneState = PaneState(false, true, std::nullopt); - } - - if (!memoryInspectionPaneSettingsByMemoryType.contains(TargetMemoryType::EEPROM)) { - memoryInspectionPaneSettingsByMemoryType[TargetMemoryType::EEPROM] = TargetMemoryInspectionPaneSettings(); - } - - this->eepromInspectionPane = new TargetMemoryInspectionPane( - eepromDescriptorIt->second, - memoryInspectionPaneSettingsByMemoryType[TargetMemoryType::EEPROM], - *(this->insightProjectSettings.eepromInspectionPaneState), - this->bottomPanel - ); - - bottomPanelLayout->addWidget(this->eepromInspectionPane); - - QObject::connect( - this->eepromInspectionPane, - &PaneWidget::paneActivated, - this, - &InsightWindow::onEepromInspectionPaneStateChanged - ); - QObject::connect( - this->eepromInspectionPane, - &PaneWidget::paneDeactivated, - this, - &InsightWindow::onEepromInspectionPaneStateChanged - ); - QObject::connect( - this->eepromInspectionPane, - &PaneWidget::paneAttached, - this, - &InsightWindow::onEepromInspectionPaneStateChanged - ); - - this->eepromInspectionButton->setDisabled(false); - this->onEepromInspectionPaneStateChanged(); - } - - if (flashDescriptorIt != this->targetDescriptor.memoryDescriptorsByType.end()) { - if (!this->insightProjectSettings.flashInspectionPaneState.has_value()) { - this->insightProjectSettings.flashInspectionPaneState = PaneState(false, true, std::nullopt); - } - - if (!memoryInspectionPaneSettingsByMemoryType.contains(TargetMemoryType::FLASH)) { - memoryInspectionPaneSettingsByMemoryType[TargetMemoryType::FLASH] = TargetMemoryInspectionPaneSettings(); - } - - this->flashInspectionPane = new TargetMemoryInspectionPane( - flashDescriptorIt->second, - memoryInspectionPaneSettingsByMemoryType[TargetMemoryType::FLASH], - *(this->insightProjectSettings.flashInspectionPaneState), - this->bottomPanel - ); - - bottomPanelLayout->addWidget(this->flashInspectionPane); - - QObject::connect( - this->flashInspectionPane, - &PaneWidget::paneActivated, - this, - &InsightWindow::onFlashInspectionPaneStateChanged - ); - QObject::connect( - this->flashInspectionPane, - &PaneWidget::paneDeactivated, - this, - &InsightWindow::onFlashInspectionPaneStateChanged - ); - QObject::connect( - this->flashInspectionPane, - &PaneWidget::paneAttached, - this, - &InsightWindow::onFlashInspectionPaneStateChanged - ); - - this->flashInspectionButton->setDisabled(false); - this->onFlashInspectionPaneStateChanged(); - } + this->bottomPanel->updateVisibility(); } void InsightWindow::adjustPanels() { const auto targetPackageWidgetSize = (this->targetPackageWidget != nullptr) - ? this->targetPackageWidget->size() : QSize(); + ? this->targetPackageWidget->size() : QSize{}; const auto containerSize = this->size(); if (!this->isVisible()) { @@ -752,7 +632,7 @@ void InsightWindow::adjustPanels() { } void InsightWindow::adjustMinimumSize() { - static const auto absoluteMinimum = QSize(900, 400); + static const auto absoluteMinimum = QSize{900, 400}; /* * On X11, the QScreen::availableGeometry() function may return the full geometry of the screen, without @@ -763,9 +643,9 @@ void InsightWindow::adjustMinimumSize() { * enough. */ const auto screenSize = this->screen()->availableGeometry().size(); - const auto absoluteMaximum = QSize(screenSize.width() - 200, screenSize.height() - 200); + const auto absoluteMaximum = QSize{screenSize.width() - 200, screenSize.height() - 200}; - auto minSize = QSize(); + auto minSize = QSize{}; if (this->targetPackageWidget != nullptr) { minSize.setWidth(this->targetPackageWidget->width() + 250); @@ -786,31 +666,41 @@ void InsightWindow::adjustMinimumSize() { ); } -void InsightWindow::onTargetStateUpdate(TargetState newState) { - this->targetState = newState; +void InsightWindow::onTargetStateUpdate(TargetState newState, Targets::TargetState previousState) { + const auto targetStopped = newState.executionState == TargetExecutionState::STOPPED; + this->setUiDisabled(!targetStopped); - if (newState == TargetState::RUNNING) { - this->targetStatusLabel->setText("Running"); - this->programCounterValueLabel->setText("-"); - this->setUiDisabled(true); - - if (this->targetPackageWidget != nullptr) { - this->targetPackageWidget->setDisabled(true); - } - - } else if (newState == TargetState::STOPPED) { - this->targetStatusLabel->setText("Stopped"); - this->refresh(); - - } else { - this->targetStatusLabel->setText("Unknown"); - this->programCounterValueLabel->setText("-"); + if (this->targetPackageWidget != nullptr) { + this->targetPackageWidget->setDisabled(!targetStopped); } + + switch (newState.executionState) { + case TargetExecutionState::STOPPED: { + this->targetStatusLabel->setText("Stopped"); + break; + } + case TargetExecutionState::RUNNING: + case TargetExecutionState::STEPPING: { + this->targetStatusLabel->setText("Running"); + break; + } + default: { + this->targetStatusLabel->setText("Unknown"); + break; + } + } + + const auto pc = this->targetState.programCounter.load(); + this->programCounterValueLabel->setText( + pc.has_value() + ? "0x" + QString::number(*pc, 16).toUpper() + " (" + QString::number(*pc) + ")" + : "-" + ); } void InsightWindow::refresh() { - if (this->targetState != TargetState::STOPPED || this->selectedVariant == nullptr) { + if (this->targetState.executionState != TargetExecutionState::STOPPED) { return; } @@ -818,77 +708,49 @@ void InsightWindow::refresh() { this->refreshIoInspectionButton->setDisabled(true); if (this->targetPackageWidget != nullptr) { - this->refreshPinStates(); + this->refreshPadStates(); } + const auto callback = [this] { + this->refreshIoInspectionButton->stopSpin(); + this->refreshIoInspectionButton->setDisabled( + this->targetState.executionState != TargetExecutionState::STOPPED + ); + }; + if (this->targetRegistersSidePane != nullptr && this->targetRegistersSidePane->state.activated) { - this->targetRegistersSidePane->refreshRegisterValues(); + this->targetRegistersSidePane->refreshRegisterValues(std::nullopt, callback); + + } else { + callback(); } - - this->refreshProgramCounter([this] { - this->refreshIoInspectionButton->stopSpin(); - - if (this->targetState == TargetState::STOPPED) { - this->refreshIoInspectionButton->setDisabled(false); - } - }); } -void InsightWindow::refreshPinStates() { +void InsightWindow::refreshPadStates() { this->targetPackageWidget->setDisabled(true); - this->targetPackageWidget->refreshPinStates([this] { - if (this->targetState == TargetState::STOPPED) { + this->targetPackageWidget->refreshPadStates([this] { + if (this->targetState.executionState == TargetExecutionState::STOPPED) { this->targetPackageWidget->setDisabled(false); } }); } -void InsightWindow::refreshProgramCounter(std::optional> callback) { - const auto readProgramCounterTask = QSharedPointer( - new ReadProgramCounter(), - &QObject::deleteLater - ); - - QObject::connect( - readProgramCounterTask.get(), - &ReadProgramCounter::programCounterRead, - this, - [this] (Targets::TargetMemoryAddress programCounter) { - this->programCounterValueLabel->setText( - "0x" + QString::number(programCounter, 16).toUpper() + " (" + QString::number(programCounter) + ")" - ); - } - ); - - if (callback.has_value()) { - QObject::connect( - readProgramCounterTask.get(), - &ReadProgramCounter::finished, - this, - callback.value() - ); - } - - InsightWorker::queueTask(readProgramCounterTask); -} - void InsightWindow::openReportIssuesUrl() { - auto url = QUrl(QString::fromStdString(Services::PathService::homeDomainName() + "/report-issue")); + auto url = QUrl{QString::fromStdString(Services::PathService::homeDomainName() + "/report-issue")}; /* * The https://bloom.oscillate.io/report-issue URL just redirects to the Bloom GitHub issue page. * * We can use query parameters in the URL to pre-fill the body of the issue. We use this to include some * target information. */ - auto urlQuery = QUrlQuery(); - auto issueBody = QString("Issue reported via Bloom Insight.\nTarget name: " - + QString::fromStdString(this->targetDescriptor.name) + "\n" - + "Target ID: " + QString::fromStdString(this->targetDescriptor.id) + "\n" - ); + auto urlQuery = QUrlQuery{}; + auto issueBody = QString{ + "Issue reported via Bloom Insight.\nTarget name: " + QString::fromStdString(this->targetDescriptor.name) + "\n" + }; - if (this->selectedVariant != nullptr) { - issueBody += "Target variant: " + QString::fromStdString(this->selectedVariant->name) + "\n"; + if (this->selectedVariantDescriptor != nullptr) { + issueBody += "Target variant: " + QString::fromStdString(this->selectedVariantDescriptor->name) + "\n"; } issueBody += "\nPlease describe your issue below. Include as much detail as possible."; @@ -900,13 +762,13 @@ void InsightWindow::openReportIssuesUrl() { void InsightWindow::openGettingStartedUrl() { QDesktopServices::openUrl( - QUrl(QString::fromStdString(Services::PathService::homeDomainName() + "/docs/getting-started")) + QUrl{QString::fromStdString(Services::PathService::homeDomainName() + "/docs/getting-started")} ); } void InsightWindow::openAboutWindow() { if (this->aboutWindowWidget == nullptr) { - this->aboutWindowWidget = new AboutWindow(this); + this->aboutWindowWidget = new AboutWindow{this}; } this->aboutWindowWidget->show(); @@ -921,180 +783,49 @@ void InsightWindow::toggleTargetRegistersPane() { } } -void InsightWindow::toggleRamInspectionPane() { - if (this->ramInspectionPane->state.activated) { - if (!this->ramInspectionPane->state.attached) { - this->ramInspectionPane->activateWindow(); - this->ramInspectionButton->setChecked(true); +void InsightWindow::toggleMemoryInspectionPane(Widgets::TargetMemoryInspectionPane* pane) { + if (pane->state.activated) { + if (!pane->state.attached) { + pane->activateWindow(); return; } - this->ramInspectionPane->deactivate(); + pane->deactivate(); return; } - if (this->ramInspectionPane->state.attached) { - if ( - this->eepromInspectionPane != nullptr - && this->eepromInspectionPane->state.activated - && this->eepromInspectionPane->state.attached - ) { - this->eepromInspectionPane->deactivate(); - } - - if ( - this->flashInspectionPane != nullptr - && this->flashInspectionPane->state.activated - && this->flashInspectionPane->state.attached - ) { - this->flashInspectionPane->deactivate(); - } - } - - this->ramInspectionPane->activate(); -} - -void InsightWindow::toggleEepromInspectionPane() { - if (this->eepromInspectionPane->state.activated) { - if (!this->eepromInspectionPane->state.attached) { - this->eepromInspectionPane->activateWindow(); - this->eepromInspectionButton->setChecked(true); - - return; - } - - this->eepromInspectionPane->deactivate(); - return; - } - - if (this->eepromInspectionPane->state.attached) { - if ( - this->ramInspectionPane != nullptr - && this->ramInspectionPane->state.activated - && this->ramInspectionPane->state.attached - ) { - this->ramInspectionPane->deactivate(); - } - - if ( - this->flashInspectionPane != nullptr - && this->flashInspectionPane->state.activated - && this->flashInspectionPane->state.attached - ) { - this->flashInspectionPane->deactivate(); - } - } - - this->eepromInspectionPane->activate(); -} - -void InsightWindow::toggleFlashInspectionPane() { - if (this->flashInspectionPane->state.activated) { - if (!this->flashInspectionPane->state.attached) { - this->flashInspectionPane->activateWindow(); - this->flashInspectionButton->setChecked(true); - - return; - } - - this->flashInspectionPane->deactivate(); - return; - } - - if (this->flashInspectionPane->state.attached) { - if ( - this->ramInspectionPane != nullptr - && this->ramInspectionPane->state.activated - && this->ramInspectionPane->state.attached - ) { - this->ramInspectionPane->deactivate(); - } - - if ( - this->eepromInspectionPane != nullptr - && this->eepromInspectionPane->state.activated - && this->eepromInspectionPane->state.attached - ) { - this->eepromInspectionPane->deactivate(); - } - } - - this->flashInspectionPane->activate(); + pane->activate(); } void InsightWindow::onRegistersPaneStateChanged() { this->targetRegistersButton->setChecked(this->targetRegistersSidePane->state.activated); - if (this->targetState == Targets::TargetState::STOPPED && this->targetRegistersSidePane->state.activated) { + if ( + this->targetState.executionState == TargetExecutionState::STOPPED + && this->targetRegistersSidePane->state.activated + ) { this->targetRegistersSidePane->refreshRegisterValues(); } } -void InsightWindow::onRamInspectionPaneStateChanged() { - this->ramInspectionButton->setChecked(this->ramInspectionPane->state.activated); +void InsightWindow::onMemoryInspectionPaneStateChanged( + Widgets::TargetMemoryInspectionPane* pane, + Widgets::ToolButton* toolBtn +) { + toolBtn->setChecked(pane->state.activated); - if (this->ramInspectionPane->state.activated && this->ramInspectionPane->state.attached) { - if ( - this->eepromInspectionPane != nullptr - && this->eepromInspectionPane->state.activated - && this->eepromInspectionPane->state.attached - ) { - this->eepromInspectionPane->deactivate(); + if (pane->state.activated && pane->state.attached) { + // Deactivate other attached memory inspection panes + for (auto* otherPane : this->memoryInspectionPaneWidgets) { + if (otherPane == pane) { + continue; + } + + if (otherPane->state.activated && otherPane->state.attached) { + otherPane->deactivate(); + } } - - if ( - this->flashInspectionPane != nullptr - && this->flashInspectionPane->state.activated - && this->flashInspectionPane->state.attached - ) { - this->flashInspectionPane->deactivate(); - } - } -} - -void InsightWindow::onEepromInspectionPaneStateChanged() { - this->eepromInspectionButton->setChecked(this->eepromInspectionPane->state.activated); - - if (this->eepromInspectionPane->state.activated && this->eepromInspectionPane->state.attached) { - if ( - this->ramInspectionPane != nullptr - && this->ramInspectionPane->state.activated - && this->ramInspectionPane->state.attached - ) { - this->ramInspectionPane->deactivate(); - } - - if ( - this->flashInspectionPane != nullptr - && this->flashInspectionPane->state.activated - && this->flashInspectionPane->state.attached - ) { - this->flashInspectionPane->deactivate(); - } - } -} - -void InsightWindow::onFlashInspectionPaneStateChanged() { - this->flashInspectionButton->setChecked(this->flashInspectionPane->state.activated); - - if (this->flashInspectionPane->state.activated && this->flashInspectionPane->state.attached) { - if ( - this->ramInspectionPane != nullptr - && this->ramInspectionPane->state.activated - && this->ramInspectionPane->state.attached - ) { - this->ramInspectionPane->deactivate(); - } - - if ( - this->eepromInspectionPane != nullptr - && this->eepromInspectionPane->state.activated - && this->eepromInspectionPane->state.attached - ) { - this->eepromInspectionPane->deactivate(); - } - } } @@ -1104,5 +835,5 @@ void InsightWindow::onProgrammingModeEnabled() { } void InsightWindow::onProgrammingModeDisabled() { - this->onTargetStateUpdate(this->targetState); + this->onTargetStateUpdate(this->targetState, this->targetState); } diff --git a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.hpp b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.hpp index 7d6cd20f..a5158ee6 100644 --- a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.hpp @@ -12,6 +12,8 @@ #include "src/Targets/TargetDescriptor.hpp" #include "src/Targets/TargetMemory.hpp" +#include "src/Targets/TargetVariantDescriptor.hpp" +#include "src/Targets/TargetPinoutDescriptor.hpp" #include "Widgets/Label.hpp" #include "Widgets/SvgToolButton.hpp" @@ -20,6 +22,7 @@ #include "Widgets/PanelWidget.hpp" #include "Widgets/TargetRegistersPane/TargetRegistersPaneWidget.hpp" #include "Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.hpp" +#include "Widgets/TargetMemoryInspectionPane/ToolButton.hpp" #include "Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPaneSettings.hpp" #include "Widgets/TaskIndicator/TaskIndicator.hpp" #include "AboutWindow.hpp" @@ -33,7 +36,8 @@ public: InsightProjectSettings& insightProjectSettings, const InsightConfig& insightConfig, const EnvironmentConfig& environmentConfig, - const Targets::TargetDescriptor& targetDescriptor + const Targets::TargetDescriptor& targetDescriptor, + const Targets::TargetState& targetState ); protected: @@ -49,7 +53,7 @@ private: TargetConfig targetConfig; const Targets::TargetDescriptor& targetDescriptor; - Targets::TargetState targetState = Targets::TargetState::UNKNOWN; + const Targets::TargetState& targetState; QWidget* windowContainer = nullptr; QMenuBar* mainMenuBar = nullptr; @@ -68,60 +72,46 @@ private: Widgets::TargetRegistersPaneWidget* targetRegistersSidePane = nullptr; QToolButton* targetRegistersButton = nullptr; - Widgets::Label* ioUnavailableWidget = nullptr; Widgets::InsightTargetWidgets::TargetPackageWidgetContainer* ioContainerWidget = nullptr; Widgets::InsightTargetWidgets::TargetPackageWidget* targetPackageWidget = nullptr; QWidget* bottomMenuBar = nullptr; + QHBoxLayout* bottomMenuBarLayout = nullptr; Widgets::PanelWidget* bottomPanel = nullptr; - Widgets::TargetMemoryInspectionPane* ramInspectionPane = nullptr; - Widgets::TargetMemoryInspectionPane* eepromInspectionPane = nullptr; - Widgets::TargetMemoryInspectionPane* flashInspectionPane = nullptr; - std::map< - Targets::TargetMemoryType, - Widgets::TargetMemoryInspectionPaneSettings - > memoryInspectionPaneSettingsByMemoryType; - QToolButton* ramInspectionButton = nullptr; - QToolButton* eepromInspectionButton = nullptr; - QToolButton* flashInspectionButton = nullptr; + std::vector memoryInspectionPaneWidgets = {}; QWidget* footer = nullptr; Widgets::Label* targetStatusLabel = nullptr; Widgets::Label* programCounterValueLabel = nullptr; Widgets::TaskIndicator* taskIndicator = nullptr; - std::map supportedVariantsByName; - const Targets::TargetVariant* selectedVariant = nullptr; - std::optional previouslySelectedVariant; + const Targets::TargetVariantDescriptor* selectedVariantDescriptor = nullptr; bool uiDisabled = false; - static bool isVariantSupported(const Targets::TargetVariant& variant); + static bool isPinoutSupported(const Targets::TargetPinoutDescriptor& pinoutDescriptor); void setUiDisabled(bool disable); void populateVariantMenu(); void selectDefaultVariant(); - void selectVariant(const Targets::TargetVariant* variant); + void selectVariant(const Targets::TargetVariantDescriptor* variantDescriptor); void createPanes(); void adjustPanels(); void adjustMinimumSize(); - void onTargetStateUpdate(Targets::TargetState newState); + void onTargetStateUpdate(Targets::TargetState newState, Targets::TargetState previousState); void refresh(); - void refreshPinStates(); - void refreshProgramCounter(std::optional> callback = std::nullopt); + void refreshPadStates(); void openReportIssuesUrl(); void openGettingStartedUrl(); void openAboutWindow(); void toggleTargetRegistersPane(); - void toggleRamInspectionPane(); + void toggleMemoryInspectionPane(Widgets::TargetMemoryInspectionPane* pane); void toggleEepromInspectionPane(); void toggleFlashInspectionPane(); void onRegistersPaneStateChanged(); - void onRamInspectionPaneStateChanged(); - void onEepromInspectionPaneStateChanged(); - void onFlashInspectionPaneStateChanged(); + void onMemoryInspectionPaneStateChanged(Widgets::TargetMemoryInspectionPane* pane, Widgets::ToolButton* toolBtn); void onProgrammingModeEnabled(); void onProgrammingModeDisabled(); }; diff --git a/src/Insight/UserInterfaces/InsightWindow/Stylesheets/InsightWindow.qss b/src/Insight/UserInterfaces/InsightWindow/Stylesheets/InsightWindow.qss index 2d8b47e2..2ad74ea0 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Stylesheets/InsightWindow.qss +++ b/src/Insight/UserInterfaces/InsightWindow/Stylesheets/InsightWindow.qss @@ -188,38 +188,14 @@ QToolTip { border-top: 1px solid #2F2F2D; } -#bottom-menu-bar #ram-inspection-btn, -#bottom-menu-bar #eeprom-inspection-btn, -#bottom-menu-bar #flash-inspection-btn { +#bottom-menu-bar QToolButton { position: relative; border: none; min-height: 22px; } -#bottom-menu-bar #ram-inspection-btn { - min-width: 73px; -} - -#bottom-menu-bar #eeprom-inspection-btn { - min-width: 99px; -} - -#bottom-menu-bar #flash-inspection-btn { - min-width: 85px; -} - -#bottom-menu-bar #ram-inspection-btn #ram-inspection-btn-icon, -#bottom-menu-bar #eeprom-inspection-btn #eeprom-inspection-btn-icon, -#bottom-menu-bar #flash-inspection-btn #flash-inspection-btn-icon { - margin-left: 6px; - margin-top: 1px; -} - -#bottom-menu-bar #ram-inspection-btn #ram-inspection-btn-label, -#bottom-menu-bar #eeprom-inspection-btn #eeprom-inspection-btn-label, -#bottom-menu-bar #flash-inspection-btn #flash-inspection-btn-label { +#bottom-menu-bar QToolButton QLabel { color: #999a9d; - margin-left: 5px; } #bottom-menu-bar QToolButton:hover, diff --git a/src/Insight/UserInterfaces/InsightWindow/UiFiles/InsightWindow.ui b/src/Insight/UserInterfaces/InsightWindow/UiFiles/InsightWindow.ui index 8c3961d3..0f80dfa4 100644 --- a/src/Insight/UserInterfaces/InsightWindow/UiFiles/InsightWindow.ui +++ b/src/Insight/UserInterfaces/InsightWindow/UiFiles/InsightWindow.ui @@ -250,159 +250,6 @@ - - - - Inspect RAM - - - true - - - false - - - - 0 - - - 0 - - - - - 22 - - - 26 - - - :/compiled/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/Images/memory-inspection-icon.svg - - - :/compiled/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/Images/memory-inspection-icon-disabled.svg - - - - - - - RAM - - - - - - - Qt::Horizontal - - - - - - - - - - Inspect EEPROM - - - true - - - false - - - - 0 - - - 0 - - - - - 22 - - - 26 - - - :/compiled/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/Images/memory-inspection-icon.svg - - - :/compiled/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/Images/memory-inspection-icon-disabled.svg - - - - - - - EEPROM - - - - - - - Qt::Horizontal - - - - - - - - - - Inspect FLASH - - - true - - - false - - - - 0 - - - 0 - - - - - 22 - - - 26 - - - :/compiled/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/Images/memory-inspection-icon.svg - - - :/compiled/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/Images/memory-inspection-icon-disabled.svg - - - - - - - FLASH - - - - - - - Qt::Horizontal - - - - - - diff --git a/src/Insight/UserInterfaces/InsightWindow/UiLoader.cpp b/src/Insight/UserInterfaces/InsightWindow/UiLoader.cpp index edf6b799..b02edb65 100644 --- a/src/Insight/UserInterfaces/InsightWindow/UiLoader.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/UiLoader.cpp @@ -16,12 +16,14 @@ using namespace Widgets; -UiLoader::UiLoader(QObject* parent): QUiLoader(parent) { +UiLoader::UiLoader(QObject* parent) + : QUiLoader(parent) +{ this->customWidgetConstructorsByWidgetName = { { "Label", [this] (QWidget* parent, const QString& name) { - auto* widget = new Label(parent); + auto* widget = new Label{parent}; widget->setObjectName(name); widget->setStyleSheet(parent->styleSheet()); return widget; @@ -30,7 +32,7 @@ UiLoader::UiLoader(QObject* parent): QUiLoader(parent) { { "RotatableLabel", [this] (QWidget* parent, const QString& name) { - auto* widget = new RotatableLabel("", parent); + auto* widget = new RotatableLabel{"", parent}; widget->setObjectName(name); widget->setStyleSheet(parent->styleSheet()); return widget; @@ -39,7 +41,7 @@ UiLoader::UiLoader(QObject* parent): QUiLoader(parent) { { "LabeledSeparator", [this] (QWidget* parent, const QString& name) { - auto* widget = new LabeledSeparator(parent); + auto* widget = new LabeledSeparator{parent}; widget->setObjectName(name); widget->setStyleSheet(parent->styleSheet()); return widget; @@ -48,7 +50,7 @@ UiLoader::UiLoader(QObject* parent): QUiLoader(parent) { { "TextInput", [this] (QWidget* parent, const QString& name) { - auto* widget = new TextInput(parent); + auto* widget = new TextInput{parent}; widget->setObjectName(name); widget->setStyleSheet(parent->styleSheet()); return widget; @@ -57,7 +59,7 @@ UiLoader::UiLoader(QObject* parent): QUiLoader(parent) { { "PlainTextEdit", [this] (QWidget* parent, const QString& name) { - auto* widget = new PlainTextEdit(parent); + auto* widget = new PlainTextEdit{parent}; widget->setObjectName(name); widget->setStyleSheet(parent->styleSheet()); return widget; @@ -66,7 +68,7 @@ UiLoader::UiLoader(QObject* parent): QUiLoader(parent) { { "PushButton", [this] (QWidget* parent, const QString& name) { - auto* widget = new PushButton(parent); + auto* widget = new PushButton{parent}; widget->setObjectName(name); widget->setStyleSheet(parent->styleSheet()); return widget; @@ -75,7 +77,7 @@ UiLoader::UiLoader(QObject* parent): QUiLoader(parent) { { "ExpandingHeightScrollAreaWidget", [this] (QWidget* parent, const QString& name) { - auto* widget = new ExpandingHeightScrollAreaWidget(parent); + auto* widget = new ExpandingHeightScrollAreaWidget{parent}; widget->setObjectName(name); widget->setStyleSheet(parent->styleSheet()); return widget; @@ -84,7 +86,7 @@ UiLoader::UiLoader(QObject* parent): QUiLoader(parent) { { "SvgWidget", [this] (QWidget* parent, const QString& name) { - auto* widget = new SvgWidget(parent); + auto* widget = new SvgWidget{parent}; widget->setObjectName(name); widget->setStyleSheet(parent->styleSheet()); return widget; @@ -93,7 +95,7 @@ UiLoader::UiLoader(QObject* parent): QUiLoader(parent) { { "SvgToolButton", [this] (QWidget* parent, const QString& name) { - auto* widget = new SvgToolButton(parent); + auto* widget = new SvgToolButton{parent}; widget->setObjectName(name); widget->setStyleSheet(parent->styleSheet()); return widget; @@ -102,7 +104,7 @@ UiLoader::UiLoader(QObject* parent): QUiLoader(parent) { { "TargetPackageWidgetContainer", [this] (QWidget* parent, const QString& name) { - auto* widget = new InsightTargetWidgets::TargetPackageWidgetContainer(parent); + auto* widget = new InsightTargetWidgets::TargetPackageWidgetContainer{parent}; widget->setObjectName(name); widget->setStyleSheet(parent->styleSheet()); return widget; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/ClickableWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/ClickableWidget.hpp index ed3b1ba9..b1dc5ece 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/ClickableWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/ClickableWidget.hpp @@ -11,7 +11,9 @@ namespace Widgets Q_OBJECT public: - explicit ClickableWidget(QWidget* parent): QFrame(parent) {}; + explicit ClickableWidget(QWidget* parent) + : QFrame(parent) + {}; signals: void rightClicked(); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/ConfirmationDialog.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/ConfirmationDialog.hpp index 388a0ff8..04cf1b8c 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/ConfirmationDialog.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/ConfirmationDialog.hpp @@ -26,7 +26,7 @@ namespace Widgets void aborted(); protected: - PushButton* confirmButton = new PushButton(this); - PushButton* cancelButton = new PushButton(this); + PushButton* confirmButton = new PushButton{this}; + PushButton* cancelButton = new PushButton{this}; }; } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/Dialog/Dialog.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/Dialog/Dialog.cpp index cd1b77eb..4dee590f 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/Dialog/Dialog.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/Dialog/Dialog.cpp @@ -21,29 +21,29 @@ namespace Widgets this->setAttribute(Qt::WA_DeleteOnClose, true); this->setWindowTitle(windowTitle); - auto dialogUiFile = QFile( + auto dialogUiFile = QFile{ QString::fromStdString(Services::PathService::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Widgets/Dialog/UiFiles/Dialog.ui" ) - ); + }; - auto dialogStylesheet = QFile( + auto dialogStylesheet = QFile{ QString::fromStdString(Services::PathService::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Widgets/Dialog/Stylesheets/Dialog.qss" ) - ); + }; if (!dialogUiFile.open(QFile::ReadOnly)) { - throw Exception("Failed to open Dialog UI file"); + throw Exception{"Failed to open Dialog UI file"}; } if (!dialogStylesheet.open(QFile::ReadOnly)) { - throw Exception("Failed to open Dialog stylesheet file"); + throw Exception{"Failed to open Dialog stylesheet file"}; } this->setStyleSheet(dialogStylesheet.readAll()); - auto uiLoader = UiLoader(this); + auto uiLoader = UiLoader{this}; this->container = uiLoader.load(&dialogUiFile, this); this->textLabel = this->container->findChild("text-label"); @@ -58,10 +58,10 @@ namespace Widgets void Dialog::showEvent(QShowEvent* event) { const auto containerSize = this->container->sizeHint(); - const auto windowSize = QSize( + const auto windowSize = QSize{ std::max(containerSize.width(), 500), std::max(containerSize.height(), 100) - ); + }; this->setFixedSize(windowSize); this->container->setFixedSize(windowSize); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/ErrorDialogue.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/ErrorDialogue.cpp index ea0cd345..88bc0af2 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/ErrorDialogue.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/ErrorDialogue.cpp @@ -22,29 +22,29 @@ namespace Widgets this->setAttribute(Qt::WA_DeleteOnClose, true); this->setWindowTitle(windowTitle); - auto dialogueUiFile = QFile( + auto dialogueUiFile = QFile{ QString::fromStdString(Services::PathService::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/UiFiles/ErrorDialogue.ui" ) - ); + }; - auto dialogueStylesheet = QFile( + auto dialogueStylesheet = QFile{ QString::fromStdString(Services::PathService::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/Stylesheets/ErrorDialogue.qss" ) - ); + }; if (!dialogueUiFile.open(QFile::ReadOnly)) { - throw Exception("Failed to open ErrorDialogue UI file"); + throw Exception{"Failed to open ErrorDialogue UI file"}; } if (!dialogueStylesheet.open(QFile::ReadOnly)) { - throw Exception("Failed to open ErrorDialogue stylesheet file"); + throw Exception{"Failed to open ErrorDialogue stylesheet file"}; } this->setStyleSheet(dialogueStylesheet.readAll()); - auto uiLoader = UiLoader(this); + auto uiLoader = UiLoader{this}; this->container = uiLoader.load(&dialogueUiFile, this); this->errorMessageDescriptionLabel = this->container->findChild( @@ -61,10 +61,10 @@ namespace Widgets void ErrorDialogue::showEvent(QShowEvent* event) { const auto containerSize = this->container->sizeHint(); - const auto windowSize = QSize( + const auto windowSize = QSize{ std::max(containerSize.width(), 500), std::max(containerSize.height(), 100) - ); + }; this->setFixedSize(windowSize); this->container->setFixedSize(windowSize); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/ExpandingHeightScrollAreaWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/ExpandingHeightScrollAreaWidget.hpp index eb202bf3..6dbc44eb 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/ExpandingHeightScrollAreaWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/ExpandingHeightScrollAreaWidget.hpp @@ -11,7 +11,9 @@ namespace Widgets Q_OBJECT public: - explicit ExpandingHeightScrollAreaWidget(QWidget* parent): QScrollArea(parent) {}; + explicit ExpandingHeightScrollAreaWidget(QWidget* parent) + : QScrollArea(parent) + {}; protected: [[nodiscard]] QSize scrollAreaSize() const { diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/LabeledSeparator.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/LabeledSeparator.cpp index 8a73fbe7..acb4276c 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/LabeledSeparator.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/LabeledSeparator.cpp @@ -11,25 +11,25 @@ namespace Widgets } void LabeledSeparator::paintEvent(QPaintEvent* event) { - auto painter = QPainter(this); + auto painter = QPainter{this}; this->drawWidget(painter); } void LabeledSeparator::drawWidget(QPainter& painter) { const auto fontMetrics = painter.fontMetrics(); const auto titleSize = fontMetrics.size(Qt::TextFlag::TextSingleLine, this->title); - const auto titleRect = QRect( - QPoint(this->marginLeft, (this->height() - titleSize.height()) / 2), + const auto titleRect = QRect{ + QPoint{this->marginLeft, (this->height() - titleSize.height()) / 2}, titleSize - ); + }; const auto lineYPosition = titleRect.y() + (titleRect.height() / 2); - const auto line = QLine( + const auto line = QLine{ titleRect.right() + 8, lineYPosition, this->width() - this->marginRight, lineYPosition - ); + }; painter.drawText(titleRect, Qt::AlignCenter, this->title); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/LabeledSeparator.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/LabeledSeparator.hpp index 14a57f6a..8ffad3a6 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/LabeledSeparator.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/LabeledSeparator.hpp @@ -60,7 +60,7 @@ namespace Widgets static constexpr int DEFAULT_HEIGHT = 20; QString title; - QColor lineColor = QColor(0x4A, 0x4A, 0x4A); + QColor lineColor = QColor{0x4A, 0x4A, 0x4A}; int marginLeft = 0; int marginRight = 10; }; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListItem.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListItem.hpp index ea4ed82d..07e52368 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListItem.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListItem.hpp @@ -7,26 +7,36 @@ #include #include #include +#include + +#include "src/Helpers/DereferenceLessComparator.hpp" namespace Widgets { class ListItem: public QGraphicsItem { public: + using ListItemSetType = std::set>; + bool selected = false; - QSize size = QSize(); + bool excluded = false; + QSize size = {}; ListItem() = default; + explicit ListItem(QGraphicsItem* parent) + : QGraphicsItem(parent) + {} + [[nodiscard]] QRectF boundingRect() const override { - return QRectF(QPointF(0, 0), this->size); + return QRectF{QPointF{0, 0}, this->size}; } - virtual void onGeometryChanged() { - return; - } + virtual void onGeometryChanged() {} - virtual bool operator < (const ListItem& rhs) const = 0; + virtual bool operator < (const ListItem& rhs) const { + return true; + } bool operator > (const ListItem& rhs) const { return rhs < *this; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListScene.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListScene.cpp index 28740191..52ff96a4 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListScene.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListScene.cpp @@ -8,15 +8,12 @@ namespace Widgets { - ListScene::ListScene( - ListScene::ListItemSetType&& items, - QGraphicsView* parent - ) + ListScene::ListScene(const ListItem::ListItemSetType& items, QGraphicsView* parent) : QGraphicsScene(parent) , parent(parent) { this->setItemIndexMethod(QGraphicsScene::NoIndex); - this->setItems(std::move(items)); + this->setItems(items); } void ListScene::setSelectionLimit(std::uint8_t selectionLimit) { @@ -32,7 +29,7 @@ namespace Widgets auto startYPosition = this->margins.top(); for (auto& listItem : this->listItems) { - if (!listItem->isVisible()) { + if (listItem->excluded || !listItem->isVisible()) { continue; } @@ -54,7 +51,7 @@ namespace Widgets this->update(); } - void ListScene::setItems(const ListScene::ListItemSetType& items) { + void ListScene::setItems(const ListItem::ListItemSetType& items) { this->clearListItems(); this->listItems = items; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListScene.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListScene.hpp index 2c6f6a00..a6d455ed 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListScene.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListScene.hpp @@ -13,7 +13,6 @@ #include #include "ListItem.hpp" -#include "src/Helpers/DereferenceLessComparator.hpp" namespace Widgets { @@ -22,17 +21,16 @@ namespace Widgets Q_OBJECT public: - using ListItemSetType = std::set>; - QMargins margins = QMargins(0, 0, 0, 10); + QMargins margins = {0, 0, 0, 10}; ListScene( - ListScene::ListItemSetType&& items, + const ListItem::ListItemSetType& items, QGraphicsView* parent ); void refreshGeometry(); void setSelectionLimit(std::uint8_t selectionLimit); - void setItems(const ListScene::ListItemSetType& items); + void setItems(const ListItem::ListItemSetType& items); void addListItem(ListItem* item); void removeListItem(ListItem* item); void clearListItems(); @@ -53,7 +51,7 @@ namespace Widgets void keyPressEvent(QKeyEvent* keyEvent) override; private: - ListScene::ListItemSetType listItems; + ListItem::ListItemSetType listItems; QGraphicsView* const parent; bool enabled = false; bool keyNavigationEnabled = true; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListView.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListView.cpp index 3ce34ec4..72815ec5 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListView.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListView.cpp @@ -3,7 +3,7 @@ namespace Widgets { ListView::ListView( - ListScene::ListItemSetType&& items, + ListItem::ListItemSetType&& items, QWidget* parent ) : QGraphicsView(parent) @@ -19,7 +19,7 @@ namespace Widgets this->setCacheMode(QGraphicsView::CacheModeFlag::CacheNone); this->setFocusPolicy(Qt::StrongFocus); - this->scene = new ListScene(std::move(items), this); + this->scene = new ListScene{std::move(items), this}; this->setScene(this->scene); } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListView.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListView.hpp index a7a6bd29..0f845c41 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListView.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListView.hpp @@ -15,7 +15,7 @@ namespace Widgets public: ListView( - ListScene::ListItemSetType&& items, + ListItem::ListItemSetType&& items, QWidget* parent ); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/PanelState.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/PanelState.hpp index bb9f41ba..c1abd686 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/PanelState.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/PanelState.hpp @@ -8,6 +8,9 @@ namespace Widgets bool open = false; PanelState() = default; - PanelState(int size, bool open): size(size), open(open) {}; + PanelState(int size, bool open) + : size(size) + , open(open) + {}; }; } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/PanelWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/PanelWidget.cpp index bc457f63..55687b27 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/PanelWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/PanelWidget.cpp @@ -20,7 +20,7 @@ namespace Widgets this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); this->setMaximumResize(this->window()->height() - 100); - auto* layout = new QHBoxLayout(this); + auto* layout = new QHBoxLayout{this}; layout->setSpacing(0); layout->setContentsMargins(0, 0, 0, 0); this->setLayout(layout); @@ -30,7 +30,7 @@ namespace Widgets this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::MinimumExpanding); this->setMaximumResize(this->window()->width() - 100); - auto* layout = new QVBoxLayout(this); + auto* layout = new QVBoxLayout{this}; layout->setSpacing(0); layout->setContentsMargins(0, 0, 0, 0); this->setLayout(layout); @@ -83,8 +83,6 @@ namespace Widgets } bool PanelWidget::eventFilter(QObject* object, QEvent* event) { - const auto eventType = event->type(); - if (event->isSinglePointEvent()) { auto* pointerEvent = dynamic_cast(event); @@ -168,23 +166,23 @@ namespace Widgets switch (this->panelType) { case PanelWidgetType::LEFT: { - return std::pair( - QPoint(currentSize.width() - this->handleSize, 0), - QPoint(currentSize.width(), currentSize.height()) - ); + return std::pair{ + QPoint{currentSize.width() - this->handleSize, 0}, + QPoint{currentSize.width(), currentSize.height()} + }; } case PanelWidgetType::RIGHT: { - return std::pair( - QPoint(0, 0), - QPoint(this->handleSize, currentSize.height()) - ); + return std::pair{ + QPoint{0, 0}, + QPoint{this->handleSize, currentSize.height()} + }; } case PanelWidgetType::BOTTOM: default: { - return std::pair( - QPoint(0, 0), - QPoint(currentSize.width(), this->handleSize) - ); + return std::pair{ + QPoint{0, 0}, + QPoint{currentSize.width(), this->handleSize} + }; } } } @@ -192,9 +190,8 @@ namespace Widgets bool PanelWidget::isPositionWithinHandleArea(const QPoint& position) const { const auto handleArea = this->getHandleArea(); - return ( + return position.x() >= handleArea.first.x() && position.x() <= handleArea.second.x() - && position.y() >= handleArea.first.y() && position.y() <= handleArea.second.y() - ); + && position.y() >= handleArea.first.y() && position.y() <= handleArea.second.y(); } } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/RotatableLabel.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/RotatableLabel.cpp index afa905a6..383082fc 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/RotatableLabel.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/RotatableLabel.cpp @@ -5,7 +5,7 @@ namespace Widgets { void RotatableLabel::paintEvent(QPaintEvent* event) { - auto painter = QPainter(this); + auto painter = QPainter{this}; const auto containerSize = this->getContainerSize(); const auto textSize = QLabel::minimumSizeHint(); const auto margins = this->contentsMargins(); @@ -13,7 +13,7 @@ namespace Widgets painter.setClipRect(0, 0, containerSize.width(), containerSize.height()); painter.save(); painter.setPen(Qt::PenStyle::SolidLine); - painter.setPen(QColor(this->isEnabled() ? "#999a9d" : "#808484")); + painter.setPen(QColor{this->isEnabled() ? "#999a9d" : "#808484"}); painter.translate(std::ceil(containerSize.width() / 2), std::ceil(containerSize.height() / 2)); painter.rotate(this->angle); painter.drawText( @@ -29,7 +29,7 @@ namespace Widgets } QSize RotatableLabel::getContainerSize() const { - auto size = QSize(); + auto size = QSize{}; auto textSize = QLabel::sizeHint(); if (this->angle % 360 == 0 || this->angle % 180 == 0) { @@ -52,11 +52,11 @@ namespace Widgets size.setWidth(static_cast( std::cos(angleRadians) * textSize.width() - + std::ceil(std::sin(angleRadians) * textSize.height()) + + std::ceil(std::sin(angleRadians) * textSize.height()) )); size.setHeight(static_cast( std::sin(angleRadians) * textSize.width() - + std::ceil(std::cos(angleRadians) * textSize.height()) + + std::ceil(std::cos(angleRadians) * textSize.height()) )); } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/SvgToolButton.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/SvgToolButton.cpp index 4349e891..03558e38 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/SvgToolButton.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/SvgToolButton.cpp @@ -28,7 +28,7 @@ namespace Widgets void SvgToolButton::contextMenuEvent(QContextMenuEvent* event) { if (this->contextMenu != nullptr) { - this->contextMenu->exec(this->mapToGlobal(QPoint(0, this->height()))); + this->contextMenu->exec(this->mapToGlobal(QPoint{0, this->height()})); } } } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/SvgWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/SvgWidget.cpp index bcf423cc..e65ae30b 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/SvgWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/SvgWidget.cpp @@ -6,12 +6,12 @@ namespace Widgets { SvgWidget::SvgWidget(QWidget* parent): QFrame(parent) { - this->renderer.setAspectRatioMode(Qt::AspectRatioMode::KeepAspectRatioByExpanding); + this->renderer->setAspectRatioMode(Qt::AspectRatioMode::KeepAspectRatioByExpanding); } void SvgWidget::startSpin() { if (this->spinningAnimation == nullptr) { - this->spinningAnimation = new QPropertyAnimation(this, "angle", this); + this->spinningAnimation = new QPropertyAnimation{this, "angle", this}; this->spinningAnimation->setDuration(2000); this->spinningAnimation->setStartValue(0); this->spinningAnimation->setEndValue(360); @@ -33,7 +33,7 @@ namespace Widgets void SvgWidget::paintEvent(QPaintEvent* paintEvent) { auto painter = QPainter(this); - auto svgSize = this->renderer.defaultSize(); + auto svgSize = this->renderer->defaultSize(); auto margins = this->contentsMargins(); const auto containerSize = this->frameSize(); @@ -51,7 +51,7 @@ namespace Widgets ); } - this->renderer.render(&painter, QRectF( + this->renderer->render(&painter, QRectF( std::ceil( static_cast(containerSize.width() - svgSize.width()) / 2 + static_cast(margins.left()) ), @@ -66,10 +66,10 @@ namespace Widgets void SvgWidget::changeEvent(QEvent* event) { if (event->type() == QEvent::EnabledChange && !this->disabledSvgFilePath.isEmpty()) { if (!this->isEnabled()) { - this->renderer.load(this->disabledSvgFilePath); + this->renderer->load(this->disabledSvgFilePath); } else { - this->renderer.load(this->svgFilePath); + this->renderer->load(this->svgFilePath); } this->repaint(); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/SvgWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/SvgWidget.hpp index 71c390af..1623c3e9 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/SvgWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/SvgWidget.hpp @@ -23,7 +23,7 @@ namespace Widgets void setSvgFilePath(const QString& svgFilePath) { this->svgFilePath = svgFilePath; - this->renderer.load(this->svgFilePath); + this->renderer->load(this->svgFilePath); } QString getSvgFilePath() { @@ -86,7 +86,7 @@ namespace Widgets void changeEvent(QEvent* event) override; private: - QSvgRenderer renderer = new QSvgRenderer(this); + QSvgRenderer* renderer = new QSvgRenderer{this}; QString svgFilePath; QString disabledSvgFilePath; int containerWidth = 0; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/ExcludedMemoryRegion.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/ExcludedMemoryRegion.cpp index 870a386d..034856c2 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/ExcludedMemoryRegion.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/ExcludedMemoryRegion.cpp @@ -4,16 +4,19 @@ ExcludedMemoryRegion::ExcludedMemoryRegion( const QString& name, - Targets::TargetMemoryType memoryType, const Targets::TargetMemoryAddressRange& addressRange ) - : MemoryRegion(name, memoryType, MemoryRegionType::EXCLUDED, addressRange) + : MemoryRegion( + name, + MemoryRegionType::EXCLUDED, + addressRange + ) {} ExcludedMemoryRegion::ExcludedMemoryRegion(const QJsonObject& jsonObject) : MemoryRegion(jsonObject) { if (this->type != MemoryRegionType::EXCLUDED) { - throw Exceptions::Exception("Invalid memory region type"); + throw Exceptions::Exception{"Invalid memory region type"}; } } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/ExcludedMemoryRegion.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/ExcludedMemoryRegion.hpp index ebf8f5a0..d37a6e95 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/ExcludedMemoryRegion.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/ExcludedMemoryRegion.hpp @@ -7,9 +7,8 @@ class ExcludedMemoryRegion: public MemoryRegion public: ExcludedMemoryRegion( const QString& name, - Targets::TargetMemoryType memoryType, const Targets::TargetMemoryAddressRange& addressRange ); - ExcludedMemoryRegion(const QJsonObject& jsonObject); + explicit ExcludedMemoryRegion(const QJsonObject& jsonObject); }; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/FocusedMemoryRegion.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/FocusedMemoryRegion.cpp index d7494903..45407654 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/FocusedMemoryRegion.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/FocusedMemoryRegion.cpp @@ -4,10 +4,13 @@ FocusedMemoryRegion::FocusedMemoryRegion( const QString& name, - Targets::TargetMemoryType memoryType, const Targets::TargetMemoryAddressRange& addressRange ) - : MemoryRegion(name, memoryType, MemoryRegionType::FOCUSED, addressRange) + : MemoryRegion( + name, + MemoryRegionType::FOCUSED, + addressRange + ) {} FocusedMemoryRegion::FocusedMemoryRegion(const QJsonObject& jsonObject) @@ -16,11 +19,11 @@ FocusedMemoryRegion::FocusedMemoryRegion(const QJsonObject& jsonObject) using Exceptions::Exception; if (this->type != MemoryRegionType::FOCUSED) { - throw Exception("Invalid memory region type"); + throw Exception{"Invalid memory region type"}; } if (!jsonObject.contains("dataType") || !jsonObject.contains("endianness")) { - throw Exception("Missing data"); + throw Exception{"Missing data"}; } this->dataType = FocusedMemoryRegion::regionDataTypesByName.at(jsonObject.find("dataType")->toString()); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/FocusedMemoryRegion.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/FocusedMemoryRegion.hpp index a7699ad9..9f4cc0ac 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/FocusedMemoryRegion.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/FocusedMemoryRegion.hpp @@ -22,12 +22,10 @@ public: FocusedMemoryRegion( const QString& name, - Targets::TargetMemoryType memoryType, const Targets::TargetMemoryAddressRange& addressRange ); - FocusedMemoryRegion(const QJsonObject& jsonObject); - + explicit FocusedMemoryRegion(const QJsonObject& jsonObject); QJsonObject toJson() const override; private: diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressContainer.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressContainer.cpp index 5dc00334..35588df7 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressContainer.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressContainer.cpp @@ -10,7 +10,7 @@ namespace Widgets static constexpr int leftMargin = 10; const auto addressItemCount = this->addressItems.size(); - decltype(this->addressItems)::size_type rowIndex = 0; + auto rowIndex = decltype(this->addressItems)::size_type{0}; for (const auto& byteItem : firstByteItemByLine) { auto addressItem = addressItemCount > 0 && rowIndex <= addressItemCount - 1 @@ -49,8 +49,8 @@ namespace Widgets } void ByteAddressContainer::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { - static const auto backgroundColor = QColor(0x35, 0x36, 0x33); - static const auto borderColor = QColor(0x41, 0x42, 0x3F); + static const auto backgroundColor = QColor{0x35, 0x36, 0x33}; + static const auto borderColor = QColor{0x41, 0x42, 0x3F}; painter->setPen(Qt::PenStyle::NoPen); painter->setBrush(backgroundColor); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressContainer.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressContainer.hpp index be7acce3..90bb4365 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressContainer.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressContainer.hpp @@ -15,15 +15,10 @@ namespace Widgets public: static constexpr int WIDTH = 88; - ByteAddressContainer(const HexViewerSharedState& hexViewerState); + explicit ByteAddressContainer(const HexViewerSharedState& hexViewerState); [[nodiscard]] QRectF boundingRect() const override { - return QRectF( - 0, - 0, - ByteAddressContainer::WIDTH, - this->scene()->height() - ); + return {0, 0, ByteAddressContainer::WIDTH, this->scene()->height()}; } void adjustAddressLabels(const std::vector& firstByteItemByLine); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressItem.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressItem.cpp index 47249baf..0c13e6ec 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressItem.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressItem.cpp @@ -8,8 +8,8 @@ namespace Widgets {} void ByteAddressItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { - static auto fontColor = QColor(0x8F, 0x91, 0x92); - static auto font = QFont("'Ubuntu', sans-serif"); + static auto fontColor = QColor{0x8F, 0x91, 0x92}; + static auto font = QFont{"'Ubuntu', sans-serif"}; font.setPixelSize(12); painter->setRenderHints( @@ -28,7 +28,7 @@ namespace Widgets Qt::AlignLeft, this->hexViewerState.settings.addressLabelType == AddressType::RELATIVE ? "0x" + QString::number( - this->address - this->hexViewerState.memoryDescriptor.addressRange.startAddress, + this->address - this->hexViewerState.memorySegmentDescriptor.addressRange.startAddress, 16 ).rightJustified(8, '0').toUpper() : "0x" + QString::number(this->address, 16).rightJustified(8, '0').toUpper() diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressItem.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressItem.hpp index da7ffaac..97f44e06 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressItem.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressItem.hpp @@ -3,6 +3,8 @@ #include #include +#include "src/Targets/TargetMemory.hpp" + #include "ByteItem.hpp" #include "HexViewerSharedState.hpp" @@ -19,12 +21,7 @@ namespace Widgets explicit ByteAddressItem(const HexViewerSharedState& hexViewerState, QGraphicsItem* parent); [[nodiscard]] QRectF boundingRect() const override { - return { - 0, - 0, - ByteAddressItem::WIDTH, - ByteAddressItem::HEIGHT - }; + return {0, 0, ByteAddressItem::WIDTH, ByteAddressItem::HEIGHT}; } void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItem.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItem.hpp index cb780680..2232f8a4 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItem.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItem.hpp @@ -29,8 +29,8 @@ namespace Widgets explicit ByteItem(Targets::TargetMemoryAddress address); - QSize size() const override { - return QSize(ByteItem::WIDTH, ByteItem::HEIGHT); + [[nodiscard]] QSize size() const override { + return {ByteItem::WIDTH, ByteItem::HEIGHT}; } }; #pragma pack(pop) diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/FocusedRegionGroupItem.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/FocusedRegionGroupItem.cpp index 82a61635..da8b71f9 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/FocusedRegionGroupItem.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/FocusedRegionGroupItem.cpp @@ -56,11 +56,11 @@ namespace Widgets const auto regionStartAddress = this->focusedMemoryRegion.addressRange.startAddress; const auto regionEndAddress = this->focusedMemoryRegion.addressRange.endAddress; - const auto startIndex = regionStartAddress - hexViewerState.memoryDescriptor.addressRange.startAddress; - auto value = Targets::TargetMemoryBuffer( + const auto startIndex = regionStartAddress - hexViewerState.memorySegmentDescriptor.addressRange.startAddress; + auto value = Targets::TargetMemoryBuffer{ hexViewerState.data->begin() + startIndex, hexViewerState.data->begin() + startIndex + (regionEndAddress - regionStartAddress + 1) - ); + }; if (this->focusedMemoryRegion.endianness == Targets::TargetMemoryEndianness::LITTLE) { std::reverse(value.begin(), value.end()); @@ -90,7 +90,7 @@ namespace Widgets } if (valueSize <= 4) { - std::int32_t integerValue = 0; + auto integerValue = std::int32_t{0}; for (const auto& byte : value) { integerValue = (integerValue << 8) | byte; } @@ -99,7 +99,7 @@ namespace Widgets break; } - std::int64_t integerValue = 0; + auto integerValue = std::int64_t{0}; for (const auto& byte : value) { integerValue = (integerValue << 8) | byte; } @@ -138,40 +138,40 @@ namespace Widgets QMargins FocusedRegionGroupItem::groupMargins( const HexViewerSharedState* hexViewerState, - const int maximumWidth + int maximumWidth ) const { - if (hexViewerState->settings.displayAnnotations) { - constexpr auto averageSymbolWidth = 8; - const auto nameLabelWidth = static_cast(this->focusedMemoryRegion.name.size() * averageSymbolWidth); - const auto valueLabelWidth = static_cast( - this->valueLabel.has_value() ? this->valueLabel->size() * averageSymbolWidth : 0 - ); - - const auto minimumWidth = std::min(std::max(nameLabelWidth, valueLabelWidth), maximumWidth); - - const auto byteItemSize = (this->focusedMemoryRegion.addressRange.endAddress - - this->focusedMemoryRegion.addressRange.startAddress + 1); - const auto estimatedWidth = static_cast( - byteItemSize * (ByteItem::WIDTH + ByteItem::RIGHT_MARGIN) - ByteItem::RIGHT_MARGIN - ); - - const auto annotationMargin = std::min( - static_cast( - estimatedWidth < minimumWidth ? minimumWidth - estimatedWidth : 0 - ), - std::max(maximumWidth - estimatedWidth, 0) - ); - - return QMargins( - annotationMargin / 2, - this->focusedMemoryRegion.dataType != MemoryRegionDataType::UNKNOWN - ? FocusedRegionGroupItem::ANNOTATION_HEIGHT - : 0, - annotationMargin / 2, - FocusedRegionGroupItem::ANNOTATION_HEIGHT - ); + if (!hexViewerState->settings.displayAnnotations) { + return QMargins{0, 0, 0, 0}; } - return QMargins(0, 0, 0, 0); + constexpr auto averageSymbolWidth = 8; + const auto nameLabelWidth = static_cast(this->focusedMemoryRegion.name.size() * averageSymbolWidth); + const auto valueLabelWidth = static_cast( + this->valueLabel.has_value() ? this->valueLabel->size() * averageSymbolWidth : 0 + ); + + const auto minimumWidth = std::min(std::max(nameLabelWidth, valueLabelWidth), maximumWidth); + + const auto byteItemSize = (this->focusedMemoryRegion.addressRange.endAddress + - this->focusedMemoryRegion.addressRange.startAddress + 1); + const auto estimatedWidth = static_cast( + byteItemSize * (ByteItem::WIDTH + ByteItem::RIGHT_MARGIN) - ByteItem::RIGHT_MARGIN + ); + + const auto annotationMargin = std::min( + static_cast( + estimatedWidth < minimumWidth ? minimumWidth - estimatedWidth : 0 + ), + std::max(maximumWidth - estimatedWidth, 0) + ); + + return QMargins{ + annotationMargin / 2, + this->focusedMemoryRegion.dataType != MemoryRegionDataType::UNKNOWN + ? FocusedRegionGroupItem::ANNOTATION_HEIGHT + : 0, + annotationMargin / 2, + FocusedRegionGroupItem::ANNOTATION_HEIGHT + }; } } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/FocusedRegionGroupItem.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/FocusedRegionGroupItem.hpp index 04a5889a..96d1943f 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/FocusedRegionGroupItem.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/FocusedRegionGroupItem.hpp @@ -30,6 +30,6 @@ namespace Widgets void refreshValue(const HexViewerSharedState& hexViewerState); protected: - QMargins groupMargins(const HexViewerSharedState* hexViewerState, const int maximumWidth) const override; + QMargins groupMargins(const HexViewerSharedState* hexViewerState, int maximumWidth) const override; }; } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/GroupItem.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/GroupItem.cpp index 030d2e56..8a0bac60 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/GroupItem.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/GroupItem.cpp @@ -8,16 +8,16 @@ namespace Widgets } } - void GroupItem::adjustItemPositions(const int maximumWidth, const HexViewerSharedState* hexViewerState) { + void GroupItem::adjustItemPositions(int maximumWidth, const HexViewerSharedState* hexViewerState) { const auto margins = this->groupMargins(hexViewerState, maximumWidth); int width = margins.left(); int height = margins.top(); this->multiLine = false; - auto position = QPoint(margins.left(), margins.top()); + auto position = QPoint{margins.left(), margins.top()}; - auto currentLineItems = std::vector(); + auto currentLineItems = std::vector{}; const ByteItem* lastByteItem = nullptr; for (const auto& item : this->items) { @@ -69,11 +69,11 @@ namespace Widgets lastByteItem = byteItem; } - this->groupSize = QSize(width + margins.right(), height + margins.bottom()); + this->groupSize = QSize{width + margins.right(), height + margins.bottom()}; } std::vector GroupItem::flattenedItems() const { - auto flattenedItems = std::vector(); + auto flattenedItems = std::vector{}; for (const auto& item : this->items) { flattenedItems.push_back(item); @@ -88,10 +88,7 @@ namespace Widgets return flattenedItems; } - GroupItem::GroupItem( - Targets::TargetMemoryAddress startAddress, - HexViewerItem* parent - ) + GroupItem::GroupItem(Targets::TargetMemoryAddress startAddress, HexViewerItem* parent) : HexViewerItem(startAddress, parent) {} diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/GroupItem.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/GroupItem.hpp index 008ce1f3..cbf18f94 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/GroupItem.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/GroupItem.hpp @@ -22,29 +22,29 @@ namespace Widgets ~GroupItem(); - QSize size() const override { + [[nodiscard]] QSize size() const override { return this->groupSize; } - virtual void adjustItemPositions(const int maximumWidth, const HexViewerSharedState* hexViewerState); + virtual void adjustItemPositions(int maximumWidth, const HexViewerSharedState* hexViewerState); [[nodiscard]] std::vector flattenedItems() const; protected: - GroupItem( + explicit GroupItem( Targets::TargetMemoryAddress startAddress, HexViewerItem* parent = nullptr ); - virtual QMargins groupMargins(const HexViewerSharedState* hexViewerState, const int maximumWidth) const { - return QMargins(0, 0, 0, 0); + virtual QMargins groupMargins(const HexViewerSharedState* hexViewerState, int maximumWidth) const { + return {0, 0, 0, 0}; } virtual bool positionOnNewLine(const int maximumWidth) { return this->multiLine; } - ByteItem* firstByteItem() const; + [[nodiscard]] ByteItem* firstByteItem() const; void sortItems(); }; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerItem.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerItem.hpp index b98b57e6..47730b6f 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerItem.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerItem.hpp @@ -18,15 +18,15 @@ namespace Widgets static constexpr int RIGHT_MARGIN = 5; static constexpr int BOTTOM_MARGIN = 5; - const Targets::TargetMemoryAddress startAddress = 0; + const Targets::TargetMemoryAddress startAddress; HexViewerItem* parent = nullptr; QPoint relativePosition = {}; - HexViewerItem(Targets::TargetMemoryAddress startAddress, HexViewerItem* parent = nullptr); - QPoint position() const; - virtual QSize size() const = 0; + explicit HexViewerItem(Targets::TargetMemoryAddress startAddress, HexViewerItem* parent = nullptr); + [[nodiscard]] QPoint position() const; + [[nodiscard]] virtual QSize size() const = 0; }; #pragma pack(pop) } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerItemIndex.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerItemIndex.cpp index d374b498..75d56ea0 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerItemIndex.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerItemIndex.cpp @@ -32,7 +32,7 @@ namespace Widgets ); if (startGridPointIndex >= gridPointCount) { - return HexViewerItemIndex::ItemRangeType(); + return HexViewerItemIndex::ItemRangeType{}; } const auto endGridPointIndex = static_castbyteItemGrid)::size_type>(std::min( @@ -44,12 +44,12 @@ namespace Widgets gridPointCount - 1 )); - return HexViewerItemIndex::ItemRangeType( + return HexViewerItemIndex::ItemRangeType{ this->byteItemGrid[startGridPointIndex], endGridPointIndex == gridPointCount - 1 ? this->flattenedItems.end() : this->byteItemGrid[endGridPointIndex] - ); + }; } ByteItem* HexViewerItemIndex::byteItemAt(const QPointF& position) const { @@ -115,11 +115,11 @@ namespace Widgets // Sanity check assert(gridPointCount > gridPointIndex); - return static_cast(*(this->byteItemGrid[gridPointIndex])); + return dynamic_cast(*(this->byteItemGrid[gridPointIndex])); } std::vector HexViewerItemIndex::intersectingByteItems(const QRectF& rect) const { - auto output = std::vector(); + auto output = std::vector{}; const auto yStart = static_cast(std::max(rect.y(), static_cast(0))); const auto yEnd = static_cast(std::max(rect.y() + rect.height(), static_cast(0))); @@ -127,7 +127,7 @@ namespace Widgets const auto items = this->items(yStart, yEnd); for (auto& item : items) { - const auto itemRect = QRectF(item->position(), item->size()); + const auto itemRect = QRectF{item->position(), item->size()}; if (itemRect.y() > yEnd) { break; @@ -252,7 +252,7 @@ namespace Widgets if (itemYEndPosition >= currentByteItemGridPoint) { // This byte item is the first to exceed or intersect with the currentByteItemGridPoint - this->byteItemGrid.push_back(itemIt); + this->byteItemGrid.emplace_back(itemIt); currentByteItemGridPoint += HexViewerItemIndex::GRID_SIZE; } } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerItemRenderer.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerItemRenderer.cpp index 15b2e89c..789744ba 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerItemRenderer.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerItemRenderer.cpp @@ -74,7 +74,7 @@ namespace Widgets this->hexViewerState.hoveredByteItem != nullptr && this->hexViewerState.settings.highlightHoveredRowAndCol ) { - static const auto hoverRectBackgroundColor = QColor(0x8E, 0x8B, 0x83, 45); + static const auto hoverRectBackgroundColor = QColor{0x8E, 0x8B, 0x83, 45}; painter->setBrush(hoverRectBackgroundColor); painter->setPen(Qt::NoPen); @@ -108,7 +108,7 @@ namespace Widgets void HexViewerItemRenderer::paintByteItem(const ByteItem* item, QPainter* painter) { const auto position = item->position(); - const auto boundingRect = QRect(position.x(), position.y(), ByteItem::WIDTH, ByteItem::HEIGHT); + const auto boundingRect = QRect{position.x(), position.y(), ByteItem::WIDTH, ByteItem::HEIGHT}; painter->setOpacity( !this->isEnabled() @@ -133,7 +133,8 @@ namespace Widgets return; } - const auto byteIndex = item->startAddress - this->hexViewerState.memoryDescriptor.addressRange.startAddress; + const auto byteIndex = item->startAddress + - this->hexViewerState.memorySegmentDescriptor.addressRange.startAddress; const auto value = (*(this->hexViewerState.data))[byteIndex]; const auto hoveredPrimary = this->hexViewerState.hoveredByteItem == item; @@ -257,7 +258,7 @@ namespace Widgets const auto endItemPos = endItem->position(); const auto endItemSize = endItem->size(); - auto painterPath = QPainterPath(); + auto painterPath = QPainterPath{}; if (startItemPos.y() != endItemPos.y()) { // The highlighted range spans more than one line - draw the border around all lines containing the range @@ -288,7 +289,7 @@ namespace Widgets } painter->setRenderHints(QPainter::RenderHint::Antialiasing | QPainter::RenderHint::SmoothPixmapTransform, true); - painter->setPen(QPen(QColor(0x58, 0x58, 0x58), 2)); + painter->setPen(QPen{QColor{0x58, 0x58, 0x58}, 2}); painter->setBrush(Qt::BrushStyle::NoBrush); painter->drawPath(painterPath); } @@ -304,10 +305,10 @@ namespace Widgets { auto labelText = item->focusedMemoryRegion.name; - static constexpr auto lineColor = QColor(0x4F, 0x4F, 0x4F); - static constexpr auto labelFontColor = QColor(0x68, 0x68, 0x68); + static constexpr auto lineColor = QColor{0x4F, 0x4F, 0x4F}; + static constexpr auto labelFontColor = QColor{0x68, 0x68, 0x68}; - static auto labelFont = QFont("'Ubuntu', sans-serif"); + static auto labelFont = QFont{"'Ubuntu', sans-serif"}; labelFont.setPixelSize(12); painter->setFont(labelFont); @@ -329,51 +330,50 @@ namespace Widgets const auto verticalLineYStart = position.y() + static_cast(heightOffset); const auto verticalLineYEnd = position.y() + static_cast(heightOffset + 5); - const auto labelRect = QRect( + const auto labelRect = QRect{ position.x() + (groupWidth - labelSize.width()) / 2, verticalLineYEnd + 10, labelSize.width(), labelSize.height() - ); + }; painter->setPen(lineColor); - if (item->focusedMemoryRegion.addressRange.startAddress != - item->focusedMemoryRegion.addressRange.endAddress) { + if (item->focusedMemoryRegion.addressRange.startAddress != item->focusedMemoryRegion.addressRange.endAddress) { const auto lineStartX = position.x() + item->items.front()->relativePosition.x() + (ByteItem::WIDTH / 2); const auto lineEndX = item->multiLine ? position.x() + groupWidth - (ByteItem::WIDTH / 2) : position.x() + item->items.back()->relativePosition.x() + (ByteItem::WIDTH / 2); - painter->drawLine(QLine( + painter->drawLine(QLine{ lineStartX, verticalLineYStart, lineStartX, verticalLineYEnd - )); + }); - painter->drawLine(QLine( + painter->drawLine(QLine{ lineEndX, verticalLineYStart, lineEndX, verticalLineYEnd - )); + }); - painter->drawLine(QLine( + painter->drawLine(QLine{ lineStartX, verticalLineYEnd, lineEndX, verticalLineYEnd - )); + }); } - painter->drawLine(QLine( + painter->drawLine(QLine{ position.x() + groupWidth / 2, verticalLineYEnd, position.x() + groupWidth / 2, verticalLineYEnd + 4 - )); + }); painter->setPen(labelFontColor); painter->drawText(labelRect, Qt::AlignCenter, labelText); @@ -385,10 +385,10 @@ namespace Widgets auto labelText = item->valueLabel.value_or("??"); - static const auto lineColor = QColor(0x4F, 0x4F, 0x4F); - static const auto labelFontColor = QColor(0x94, 0x6F, 0x30); + static const auto lineColor = QColor{0x4F, 0x4F, 0x4F}; + static const auto labelFontColor = QColor{0x94, 0x6F, 0x30}; - static auto labelFont = QFont("'Ubuntu', sans-serif"); + static auto labelFont = QFont{"'Ubuntu', sans-serif"}; labelFont.setPixelSize(12); labelFont.setItalic(true); @@ -399,11 +399,7 @@ namespace Widgets auto labelSize = fontMetrics.size(Qt::TextSingleLine, labelText); if (labelSize.width() > groupWidth) { labelSize.setWidth(groupWidth); - labelText = fontMetrics.elidedText( - labelText, - Qt::TextElideMode::ElideRight, - groupWidth - ); + labelText = fontMetrics.elidedText(labelText, Qt::TextElideMode::ElideRight, groupWidth); } const auto heightOffset = FocusedRegionGroupItem::ANNOTATION_HEIGHT - 4; @@ -411,12 +407,12 @@ namespace Widgets const auto verticalLineYStart = position.y() + static_cast(heightOffset - 5); const auto verticalLineYEnd = position.y() + static_cast(heightOffset); - const auto labelRect = QRect( + const auto labelRect = QRect{ position.x() + (groupWidth - labelSize.width()) / 2, verticalLineYStart - 10 - labelSize.height(), labelSize.width(), labelSize.height() - ); + }; painter->setPen(lineColor); @@ -426,26 +422,26 @@ namespace Widgets ? position.x() + groupWidth - + (ByteItem::WIDTH / 2) : position.x() + item->items.back()->relativePosition.x() + (ByteItem::WIDTH / 2); - painter->drawLine(QLine( + painter->drawLine(QLine{ lineStartX, verticalLineYStart, lineStartX, verticalLineYEnd - )); + }); - painter->drawLine(QLine( + painter->drawLine(QLine{ lineEndX, verticalLineYStart, lineEndX, verticalLineYEnd - )); + }); - painter->drawLine(QLine( + painter->drawLine(QLine{ lineStartX, verticalLineYStart, lineEndX, verticalLineYStart - )); + }); /* * Draw a circle just above the first byte item of the region, to indicate the first byte used to generate @@ -455,23 +451,23 @@ namespace Widgets constexpr auto radius = 2; painter->drawEllipse( - QPoint( + QPoint{ item->focusedMemoryRegion.endianness == TargetMemoryEndianness::BIG ? lineStartX : lineEndX, !item->multiLine || item->focusedMemoryRegion.endianness == TargetMemoryEndianness::BIG ? verticalLineYStart : position.y() + item->groupSize.height() - FocusedRegionGroupItem::ANNOTATION_HEIGHT + 4 + 5 - ), + }, radius, radius ); } - painter->drawLine(QLine( + painter->drawLine(QLine{ position.x() + groupWidth / 2, verticalLineYStart - 4, position.x() + groupWidth / 2, verticalLineYStart - )); + }); painter->setPen(labelFontColor); painter->drawText(labelRect, Qt::AlignCenter, labelText); @@ -481,30 +477,31 @@ namespace Widgets void HexViewerItemRenderer::paintStackMemoryGroupItem(const StackMemoryGroupItem* item, QPainter* painter) { const auto position = item->position(); - const auto headingText = QString("Stack Memory"); + const auto headingText = QString{"Stack Memory"}; - const auto stackSize = this->hexViewerState.memoryDescriptor.addressRange.endAddress - item->startAddress + 1; - const auto& memoryCapacity = this->hexViewerState.memoryDescriptor.size(); + const auto stackSize = this->hexViewerState.memorySegmentDescriptor.addressRange.endAddress + - item->startAddress + 1; + const auto& memoryCapacity = this->hexViewerState.memorySegmentDescriptor.size(); - const auto stackSizeHeadingText = QString("Stack size:"); + const auto stackSizeHeadingText = QString{"Stack size:"}; const auto stackSizeValueText = QString::number(stackSize) + " byte(s) (" + QString::number(static_cast(stackSize) / static_cast(memoryCapacity / 100), 'f' , 1) + "% of memory capacity)"; - const auto stackPointerHeadingText = QString("Stack pointer:"); + const auto stackPointerHeadingText = QString{"Stack pointer:"}; const auto stackPointerValueText = "0x" + QString::number( item->stackPointer, 16 ).rightJustified(8, '0').toUpper(); - static constexpr auto lineColor = QColor(0x4F, 0x4F, 0x4F); - static constexpr auto headingLabelFontColor = QColor(0x6F, 0x6F, 0x6F); - static constexpr auto valueLabelFontColor = QColor(0x94, 0x6F, 0x30, 230); + static constexpr auto lineColor = QColor{0x4F, 0x4F, 0x4F}; + static constexpr auto headingLabelFontColor = QColor{0x6F, 0x6F, 0x6F}; + static constexpr auto valueLabelFontColor = QColor{0x94, 0x6F, 0x30, 230}; - static auto headingLabelFont = QFont("'Ubuntu', sans-serif"); + static auto headingLabelFont = QFont{"'Ubuntu', sans-serif"}; headingLabelFont.setPixelSize(13); - static auto valueFont = QFont("'Ubuntu', sans-serif"); + static auto valueFont = QFont{"'Ubuntu', sans-serif"}; valueFont.setPixelSize(13); valueFont.setItalic(true); @@ -534,75 +531,75 @@ namespace Widgets const auto lineStartX = position.x() + ByteItem::WIDTH / 2; const auto lineEndX = position.x() + groupWidth - (ByteItem::WIDTH / 2); - const auto labelRect = QRect( + const auto labelRect = QRect{ position.x() + (groupWidth - headingLabelSize.width()) / 2, verticalLineYStart - stackPointerHeadingLabelSize.height() - stackSizeHeadingLabelSize.height() - headingLabelSize.height() - labelLineHeight - (labelBottomMargin * 2) - 3, headingLabelSize.width(), headingLabelSize.height() - ); + }; - const auto stackPointerHeadingLabelRect = QRect( + const auto stackPointerHeadingLabelRect = QRect{ labelRect.left() + (labelRect.width() / 2) - ( (stackPointerHeadingLabelSize.width() + stackPointerLabelSize.width()) / 2 ), labelRect.bottom() + labelBottomMargin, stackPointerHeadingLabelSize.width(), stackPointerHeadingLabelSize.height() - ); + }; - const auto stackPointerValueLabelRect = QRect( + const auto stackPointerValueLabelRect = QRect{ stackPointerHeadingLabelRect.right() + labelRightMargin, labelRect.bottom() + labelBottomMargin, stackPointerLabelSize.width(), stackPointerLabelSize.height() - ); + }; - const auto stackSizeHeadingLabelRect = QRect( + const auto stackSizeHeadingLabelRect = QRect{ labelRect.left() + (labelRect.width() / 2) - ( (stackSizeHeadingLabelSize.width() + stackSizeLabelSize.width()) / 2 ), stackPointerHeadingLabelRect.bottom() + labelBottomMargin, stackSizeHeadingLabelSize.width(), stackSizeHeadingLabelSize.height() - ); + }; - const auto stackSizeValueLabelRect = QRect( + const auto stackSizeValueLabelRect = QRect{ stackSizeHeadingLabelRect.right() + labelRightMargin, stackPointerHeadingLabelRect.bottom() + labelBottomMargin, stackSizeLabelSize.width(), stackSizeLabelSize.height() - ); + }; painter->setPen(lineColor); - painter->drawLine(QLine( + painter->drawLine(QLine{ lineStartX, verticalLineYStart, lineStartX, verticalLineYEnd - )); + }); - painter->drawLine(QLine( + painter->drawLine(QLine{ lineEndX, verticalLineYStart, lineEndX, verticalLineYEnd - )); + }); - painter->drawLine(QLine( + painter->drawLine(QLine{ lineStartX, verticalLineYStart, lineEndX, verticalLineYStart - )); + }); - painter->drawLine(QLine( + painter->drawLine(QLine{ position.x() + groupWidth / 2, verticalLineYStart - labelLineHeight, position.x() + groupWidth / 2, verticalLineYStart - )); + }); painter->setPen(headingLabelFontColor); @@ -623,77 +620,77 @@ namespace Widgets return; } - static constexpr auto standardBackgroundColor = QColor(0x32, 0x33, 0x30, 0); - static constexpr auto selectedBackgroundColor = QColor(0x3C, 0x59, 0x5C, 255); - static constexpr auto primaryHighlightedBackgroundColor = QColor(0x3B, 0x59, 0x37, 255); - static constexpr auto groupedBackgroundColor = QColor(0x44, 0x44, 0x41, 255); - static constexpr auto stackMemoryBackgroundColor = QColor(0x44, 0x44, 0x41, 200); - static constexpr auto stackMemoryBarColor = QColor(0x67, 0x57, 0x20, 255); - static constexpr auto changedMemoryBackgroundColor = QColor(0x5C, 0x49, 0x5D, 200); - static constexpr auto changedMemoryFadedBackgroundColor = QColor(0x5C, 0x49, 0x5D, 125); + static constexpr auto standardBackgroundColor = QColor{0x32, 0x33, 0x30, 0}; + static constexpr auto selectedBackgroundColor = QColor{0x3C, 0x59, 0x5C, 255}; + static constexpr auto primaryHighlightedBackgroundColor = QColor{0x3B, 0x59, 0x37, 255}; + static constexpr auto groupedBackgroundColor = QColor{0x44, 0x44, 0x41, 255}; + static constexpr auto stackMemoryBackgroundColor = QColor{0x44, 0x44, 0x41, 200}; + static constexpr auto stackMemoryBarColor = QColor{0x67, 0x57, 0x20, 255}; + static constexpr auto changedMemoryBackgroundColor = QColor{0x5C, 0x49, 0x5D, 200}; + static constexpr auto changedMemoryFadedBackgroundColor = QColor{0x5C, 0x49, 0x5D, 125}; - static const auto hoveredStackMemoryBackgroundColor = QColor( + static const auto hoveredStackMemoryBackgroundColor = QColor{ stackMemoryBackgroundColor.red(), stackMemoryBackgroundColor.green(), stackMemoryBackgroundColor.blue(), 255 - ); + }; - static constexpr auto hoveredBackgroundColor = QColor(0x8E, 0x8B, 0x83, 70); + static constexpr auto hoveredBackgroundColor = QColor{0x8E, 0x8B, 0x83, 70}; - static constexpr auto standardFontColor = QColor(0xAF, 0xB1, 0xB3); - static constexpr auto fadedFontColor = QColor(0xAF, 0xB1, 0xB3, 100); - static constexpr auto asciiFontColor = QColor(0xA7, 0x77, 0x26); - static constexpr auto changedMemoryAsciiFontColor = QColor(0xB7, 0x7F, 0x21); + static constexpr auto standardFontColor = QColor{0xAF, 0xB1, 0xB3}; + static constexpr auto fadedFontColor = QColor{0xAF, 0xB1, 0xB3, 100}; + static constexpr auto asciiFontColor = QColor{0xA7, 0x77, 0x26}; + static constexpr auto changedMemoryAsciiFontColor = QColor{0xB7, 0x7F, 0x21}; - const auto byteItemRect = QRect(0, 0, ByteItem::WIDTH, ByteItem::HEIGHT); + const auto byteItemRect = QRect{0, 0, ByteItem::WIDTH, ByteItem::HEIGHT}; const auto byteItemSize = byteItemRect.size(); - auto standardTemplatePixmap = QPixmap(byteItemSize); + auto standardTemplatePixmap = QPixmap{byteItemSize}; standardTemplatePixmap.fill(standardBackgroundColor); - auto primaryHighlightedTemplatePixmap = QPixmap(byteItemSize); + auto primaryHighlightedTemplatePixmap = QPixmap{byteItemSize}; primaryHighlightedTemplatePixmap.fill(primaryHighlightedBackgroundColor); - auto selectedTemplatePixmap = QPixmap(byteItemSize); + auto selectedTemplatePixmap = QPixmap{byteItemSize}; selectedTemplatePixmap.fill(selectedBackgroundColor); - auto groupedTemplatePixmap = QPixmap(byteItemSize); + auto groupedTemplatePixmap = QPixmap{byteItemSize}; groupedTemplatePixmap.fill(groupedBackgroundColor); - auto stackMemoryTemplatePixmap = QPixmap(byteItemSize); + auto stackMemoryTemplatePixmap = QPixmap{byteItemSize}; stackMemoryTemplatePixmap.fill(stackMemoryBackgroundColor); { - auto painter = QPainter(&stackMemoryTemplatePixmap); + auto painter = QPainter{&stackMemoryTemplatePixmap}; painter.setBrush(stackMemoryBarColor); painter.setPen(Qt::PenStyle::NoPen); painter.drawRect(0, byteItemSize.height() - 3, byteItemSize.width(), 3); } - auto changedMemoryTemplatePixmap = QPixmap(byteItemSize); + auto changedMemoryTemplatePixmap = QPixmap{byteItemSize}; changedMemoryTemplatePixmap.fill(changedMemoryBackgroundColor); - auto changedMemoryFadedTemplatePixmap = QPixmap(byteItemSize); + auto changedMemoryFadedTemplatePixmap = QPixmap{byteItemSize}; changedMemoryFadedTemplatePixmap.fill(changedMemoryFadedBackgroundColor); - auto hoveredStackMemoryTemplatePixmap = QPixmap(byteItemSize); + auto hoveredStackMemoryTemplatePixmap = QPixmap{byteItemSize}; hoveredStackMemoryTemplatePixmap.fill(hoveredStackMemoryBackgroundColor); - auto hoveredPrimaryTemplatePixmap = QPixmap(byteItemSize); + auto hoveredPrimaryTemplatePixmap = QPixmap{byteItemSize}; hoveredPrimaryTemplatePixmap.fill(hoveredBackgroundColor); - static auto font = QFont("'Ubuntu', sans-serif", 8); + static auto font = QFont{"'Ubuntu', sans-serif", 8}; - for (std::uint16_t value = 0x00; value <= 0xFF; ++value) { + for (auto value = std::uint16_t{0}; value <= 0xFF; ++value) { const auto hexValue = QString::number(value, 16).rightJustified(2, '0').toUpper(); const auto asciiValue = value >= 32 && value <= 126 - ? std::optional("'" + QString(QChar(value)) + "'") + ? std::optional{"'" + QString{QChar{value}} + "'"} : std::nullopt; { auto standardPixmap = standardTemplatePixmap; - auto painter = QPainter(&standardPixmap); + auto painter = QPainter{&standardPixmap}; painter.setFont(font); painter.setPen(standardFontColor); painter.drawText(byteItemRect, Qt::AlignCenter, hexValue); @@ -703,7 +700,7 @@ namespace Widgets { auto selectedPixmap = selectedTemplatePixmap; - auto painter = QPainter(&selectedPixmap); + auto painter = QPainter{&selectedPixmap}; painter.setFont(font); painter.setPen(standardFontColor); painter.drawText(byteItemRect, Qt::AlignCenter, hexValue); @@ -713,7 +710,7 @@ namespace Widgets { auto primaryHighlightedPixmap = primaryHighlightedTemplatePixmap; - auto painter = QPainter(&primaryHighlightedPixmap); + auto painter = QPainter{&primaryHighlightedPixmap}; painter.setFont(font); painter.setPen(standardFontColor); painter.drawText(byteItemRect, Qt::AlignCenter, hexValue); @@ -723,7 +720,7 @@ namespace Widgets { auto groupedPixmap = groupedTemplatePixmap; - auto painter = QPainter(&groupedPixmap); + auto painter = QPainter{&groupedPixmap}; painter.setFont(font); painter.setPen(standardFontColor); painter.drawText(byteItemRect, Qt::AlignCenter, hexValue); @@ -733,7 +730,7 @@ namespace Widgets { auto stackMemoryPixmap = stackMemoryTemplatePixmap; - auto painter = QPainter(&stackMemoryPixmap); + auto painter = QPainter{&stackMemoryPixmap}; painter.setFont(font); painter.setPen(standardFontColor); painter.drawText(byteItemRect, Qt::AlignCenter, hexValue); @@ -743,7 +740,7 @@ namespace Widgets { auto changedMemoryPixmap = changedMemoryTemplatePixmap; - auto painter = QPainter(&changedMemoryPixmap); + auto painter = QPainter{&changedMemoryPixmap}; painter.setFont(font); painter.setPen(standardFontColor); painter.drawText(byteItemRect, Qt::AlignCenter, hexValue); @@ -753,7 +750,7 @@ namespace Widgets { auto hoveredPrimaryPixmap = hoveredPrimaryTemplatePixmap; - auto painter = QPainter(&hoveredPrimaryPixmap); + auto painter = QPainter{&hoveredPrimaryPixmap}; painter.setFont(font); painter.setPen(standardFontColor); painter.drawText(byteItemRect, Qt::AlignCenter, hexValue); @@ -763,7 +760,7 @@ namespace Widgets { auto standardAsciiPixmap = standardTemplatePixmap; - auto painter = QPainter(&standardAsciiPixmap); + auto painter = QPainter{&standardAsciiPixmap}; painter.setFont(font); painter.setPen(asciiValue.has_value() ? asciiFontColor : fadedFontColor); painter.drawText(byteItemRect, Qt::AlignCenter, asciiValue.value_or(hexValue)); @@ -773,7 +770,7 @@ namespace Widgets { auto selectedAsciiPixmap = selectedTemplatePixmap; - auto painter = QPainter(&selectedAsciiPixmap); + auto painter = QPainter{&selectedAsciiPixmap}; painter.setFont(font); painter.setPen(asciiValue.has_value() ? asciiFontColor : fadedFontColor); painter.drawText(byteItemRect, Qt::AlignCenter, asciiValue.value_or(hexValue)); @@ -783,7 +780,7 @@ namespace Widgets { auto primaryHighlightedAsciiPixmap = primaryHighlightedTemplatePixmap; - auto painter = QPainter(&primaryHighlightedAsciiPixmap); + auto painter = QPainter{&primaryHighlightedAsciiPixmap}; painter.setFont(font); painter.setPen(asciiValue.has_value() ? asciiFontColor : fadedFontColor); painter.drawText(byteItemRect, Qt::AlignCenter, asciiValue.value_or(hexValue)); @@ -795,7 +792,7 @@ namespace Widgets { auto groupedAsciiPixmap = groupedTemplatePixmap; - auto painter = QPainter(&groupedAsciiPixmap); + auto painter = QPainter{&groupedAsciiPixmap}; painter.setFont(font); painter.setPen(asciiValue.has_value() ? asciiFontColor : fadedFontColor); painter.drawText(byteItemRect, Qt::AlignCenter, asciiValue.value_or(hexValue)); @@ -805,7 +802,7 @@ namespace Widgets { auto stackMemoryAsciiPixmap = stackMemoryTemplatePixmap; - auto painter = QPainter(&stackMemoryAsciiPixmap); + auto painter = QPainter{&stackMemoryAsciiPixmap}; painter.setFont(font); painter.setPen(asciiValue.has_value() ? asciiFontColor : fadedFontColor); painter.drawText(byteItemRect, Qt::AlignCenter, asciiValue.value_or(hexValue)); @@ -818,7 +815,7 @@ namespace Widgets ? changedMemoryTemplatePixmap : changedMemoryFadedTemplatePixmap; - auto painter = QPainter(&changedMemoryAsciiPixmap); + auto painter = QPainter{&changedMemoryAsciiPixmap}; painter.setFont(font); painter.setPen(asciiValue.has_value() ? changedMemoryAsciiFontColor : fadedFontColor); painter.drawText(byteItemRect, Qt::AlignCenter, asciiValue.value_or(hexValue)); @@ -828,7 +825,7 @@ namespace Widgets { auto hoveredPrimaryAsciiPixmap = hoveredPrimaryTemplatePixmap; - auto painter = QPainter(&hoveredPrimaryAsciiPixmap); + auto painter = QPainter{&hoveredPrimaryAsciiPixmap}; painter.setFont(font); painter.setPen(asciiValue.has_value() ? asciiFontColor : fadedFontColor); painter.drawText(byteItemRect, Qt::AlignCenter, asciiValue.value_or(hexValue)); @@ -839,7 +836,7 @@ namespace Widgets { HexViewerItemRenderer::missingDataPixmap = standardTemplatePixmap; - auto painter = QPainter(&HexViewerItemRenderer::missingDataPixmap.value()); + auto painter = QPainter{&HexViewerItemRenderer::missingDataPixmap.value()}; painter.setFont(font); painter.setPen(standardFontColor); painter.drawText(byteItemRect, Qt::AlignCenter, "??"); @@ -847,7 +844,7 @@ namespace Widgets { HexViewerItemRenderer::selectedMissingDataPixmap = selectedTemplatePixmap; - auto painter = QPainter(&HexViewerItemRenderer::selectedMissingDataPixmap.value()); + auto painter = QPainter{&HexViewerItemRenderer::selectedMissingDataPixmap.value()}; painter.setFont(font); painter.setPen(standardFontColor); painter.drawText(byteItemRect, Qt::AlignCenter, "??"); @@ -855,7 +852,7 @@ namespace Widgets { HexViewerItemRenderer::primaryHighlightedMissingDataPixmap = primaryHighlightedTemplatePixmap; - auto painter = QPainter(&HexViewerItemRenderer::primaryHighlightedMissingDataPixmap.value()); + auto painter = QPainter{&HexViewerItemRenderer::primaryHighlightedMissingDataPixmap.value()}; painter.setFont(font); painter.setPen(standardFontColor); painter.drawText(byteItemRect, Qt::AlignCenter, "??"); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerItemRenderer.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerItemRenderer.hpp index 028b315b..e786e9d2 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerItemRenderer.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerItemRenderer.hpp @@ -37,7 +37,7 @@ namespace Widgets ); [[nodiscard]] QRectF boundingRect() const override { - return QRectF(0, 0, this->size.width(), this->size.height()); + return QRectF{0, 0, static_cast(this->size.width()), static_cast(this->size.height())}; } void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerSharedState.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerSharedState.hpp index eb01890d..9cfa8824 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerSharedState.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerSharedState.hpp @@ -3,6 +3,9 @@ #include #include "src/Targets/TargetMemory.hpp" +#include "src/Targets/TargetAddressSpaceDescriptor.hpp" +#include "src/Targets/TargetMemorySegmentDescriptor.hpp" + #include "HexViewerWidgetSettings.hpp" namespace Widgets @@ -12,7 +15,9 @@ namespace Widgets struct HexViewerSharedState { public: - const Targets::TargetMemoryDescriptor& memoryDescriptor; + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor; + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor; + const std::optional& data; HexViewerWidgetSettings& settings; @@ -23,11 +28,13 @@ namespace Widgets std::set highlightedPrimaryAddressRanges; HexViewerSharedState( - const Targets::TargetMemoryDescriptor& memoryDescriptor, + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, const std::optional& data, HexViewerWidgetSettings& settings ) - : memoryDescriptor(memoryDescriptor) + : addressSpaceDescriptor(addressSpaceDescriptor) + , memorySegmentDescriptor(memorySegmentDescriptor) , data(data) , settings(settings) {} diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerWidget.cpp index 7d651686..030d5789 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerWidget.cpp @@ -14,10 +14,14 @@ namespace Widgets { using namespace Exceptions; - using Targets::TargetMemoryDescriptor; + using Targets::TargetAddressSpaceDescriptor; + using Targets::TargetMemorySegmentDescriptor; + using Targets::TargetState; HexViewerWidget::HexViewerWidget( - const TargetMemoryDescriptor& targetMemoryDescriptor, + const TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const TargetMemorySegmentDescriptor& memorySegmentDescriptor, + const TargetState& targetState, const std::optional& data, HexViewerWidgetSettings& settings, const std::vector& focusedMemoryRegions, @@ -25,7 +29,9 @@ namespace Widgets QWidget* parent ) : QWidget(parent) - , targetMemoryDescriptor(targetMemoryDescriptor) + , addressSpaceDescriptor(addressSpaceDescriptor) + , memorySegmentDescriptor(memorySegmentDescriptor) + , targetState(targetState) , data(data) , settings(settings) , focusedMemoryRegions(focusedMemoryRegions) @@ -34,29 +40,29 @@ namespace Widgets this->setObjectName("hex-viewer-widget"); this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); - auto widgetUiFile = QFile( + auto widgetUiFile = QFile{ QString::fromStdString(Services::PathService::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget" + "/UiFiles/HexViewerWidget.ui" ) - ); + }; - auto stylesheetFile = QFile( + auto stylesheetFile = QFile{ QString::fromStdString(Services::PathService::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget" + "/Stylesheets/HexViewerWidget.qss" ) - ); + }; if (!widgetUiFile.open(QFile::ReadOnly)) { - throw Exception("Failed to open HexViewerWidget UI file"); + throw Exception{"Failed to open HexViewerWidget UI file"}; } if (!stylesheetFile.open(QFile::ReadOnly)) { - throw Exception("Failed to open HexViewerWidget stylesheet file"); + throw Exception{"Failed to open HexViewerWidget stylesheet file"}; } - auto uiLoader = UiLoader(this); + auto uiLoader = UiLoader{this}; this->container = uiLoader.load(&widgetUiFile, this); this->setStyleSheet(stylesheetFile.readAll()); this->container->setFixedSize(this->size()); @@ -95,7 +101,7 @@ namespace Widgets this->setAnnotationsEnabled(this->settings.displayAnnotations); this->setDisplayAsciiEnabled(this->settings.displayAsciiValues); - if (this->targetMemoryDescriptor.type == Targets::TargetMemoryType::RAM) { + if (this->memorySegmentDescriptor.type == Targets::TargetMemorySegmentType::RAM) { this->groupStackMemoryButton->show(); this->setStackMemoryGroupingEnabled(this->settings.groupStackMemory); @@ -163,25 +169,20 @@ namespace Widgets &HexViewerWidget::onGoToAddressInputChanged ); - QObject::connect( - InsightSignals::instance(), - &InsightSignals::targetStateUpdated, - this, - &HexViewerWidget::onTargetStateChanged - ); - this->show(); } void HexViewerWidget::init() { - this->byteItemGraphicsView = new ItemGraphicsView( - this->targetMemoryDescriptor, + this->byteItemGraphicsView = new ItemGraphicsView{ + this->addressSpaceDescriptor, + this->memorySegmentDescriptor, + this->targetState, this->data, this->focusedMemoryRegions, this->excludedMemoryRegions, this->settings, this->container - ); + }; this->byteItemGraphicsView->hide(); @@ -271,11 +272,6 @@ namespace Widgets QWidget::showEvent(event); } - void HexViewerWidget::onTargetStateChanged(Targets::TargetState newState) { - using Targets::TargetState; - this->targetState = newState; - } - void HexViewerWidget::setStackMemoryGroupingEnabled(bool enabled) { this->groupStackMemoryButton->setChecked(enabled); this->settings.groupStackMemory = enabled; @@ -336,12 +332,14 @@ namespace Widgets return; } - auto addressConversionOk = false; - const auto address = this->goToAddressInput->text().toUInt(&addressConversionOk, 16); + auto conversionStatus = false; + const auto address = this->goToAddressInput->text().toUInt(&conversionStatus, 16); - const auto& memoryAddressRange = this->targetMemoryDescriptor.addressRange; - - if (addressConversionOk && memoryAddressRange.contains(address) && this->goToAddressInput->hasFocus()) { + if ( + conversionStatus + && this->memorySegmentDescriptor.addressRange.contains(address) + && this->goToAddressInput->hasFocus() + ) { this->byteItemGraphicsScene->selectByteItems({address}); this->byteItemGraphicsView->scrollToByteItemAtAddress(address); return; @@ -361,7 +359,7 @@ namespace Widgets 16 ).rightJustified(8, '0').toUpper(); - const auto relativeAddress = *address - this->targetMemoryDescriptor.addressRange.startAddress; + const auto relativeAddress = *address - this->memorySegmentDescriptor.addressRange.startAddress; const auto relativeAddressHex = "0x" + QString::number( relativeAddress, 16 @@ -383,7 +381,7 @@ namespace Widgets } this->selectionCountLabel->setText( - QLocale(QLocale::English).toString(selectionCount) + " " + QString(selectionCount == 1 ? "byte" : "bytes") + QLocale{QLocale::English}.toString(selectionCount) + " " + QString(selectionCount == 1 ? "byte" : "bytes") + " selected" ); this->selectionCountLabel->show(); @@ -392,7 +390,7 @@ namespace Widgets std::set HexViewerWidget::addressRangesToAddresses( const std::set& addressRanges ) { - auto addresses = std::set(); + auto addresses = std::set{}; auto addressesIt = addresses.end(); for (const auto& range : addressRanges) { diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerWidget.hpp index a5083708..70e9da85 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerWidget.hpp @@ -7,6 +7,8 @@ #include #include "src/Targets/TargetMemory.hpp" +#include "src/Targets/TargetAddressSpaceDescriptor.hpp" +#include "src/Targets/TargetMemorySegmentDescriptor.hpp" #include "src/Targets/TargetState.hpp" #include "src/Insight/UserInterfaces/InsightWindow/Widgets/Label.hpp" @@ -29,7 +31,9 @@ namespace Widgets public: HexViewerWidget( - const Targets::TargetMemoryDescriptor& targetMemoryDescriptor, + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, + const Targets::TargetState& targetState, const std::optional& data, HexViewerWidgetSettings& settings, const std::vector& focusedMemoryRegions, @@ -52,7 +56,9 @@ namespace Widgets void settingsChanged(const HexViewerWidgetSettings& settings); protected: - const Targets::TargetMemoryDescriptor& targetMemoryDescriptor; + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor; + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor; + const Targets::TargetState& targetState; const std::optional& data; HexViewerWidgetSettings& settings; @@ -78,8 +84,6 @@ namespace Widgets TextInput* goToAddressInput = nullptr; - Targets::TargetState targetState = Targets::TargetState::UNKNOWN; - void resizeEvent(QResizeEvent* event) override; void showEvent(QShowEvent* event) override; void onTargetStateChanged(Targets::TargetState newState); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.cpp index 39289365..bbf9ae24 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.cpp @@ -11,14 +11,14 @@ #include #include "src/Insight/InsightWorker/InsightWorker.hpp" -#include "src/Insight/InsightSignals.hpp" - #include "src/Insight/InsightWorker/Tasks/ConstructHexViewerTopLevelGroupItem.hpp" namespace Widgets { ItemGraphicsScene::ItemGraphicsScene( - const Targets::TargetMemoryDescriptor& targetMemoryDescriptor, + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, + const Targets::TargetState& targetState, const std::optional& data, const std::vector& focusedMemoryRegions, const std::vector& excludedMemoryRegions, @@ -27,19 +27,21 @@ namespace Widgets ) : QGraphicsScene(parent) , state( - HexViewerSharedState( - targetMemoryDescriptor, + HexViewerSharedState{ + addressSpaceDescriptor, + memorySegmentDescriptor, data, settings - ) + } ) + , targetState(targetState) , focusedMemoryRegions(focusedMemoryRegions) , excludedMemoryRegions(excludedMemoryRegions) , parent(parent) { this->setObjectName("byte-widget-container"); - this->byteAddressContainer = new ByteAddressContainer(this->state); + this->byteAddressContainer = new ByteAddressContainer{this->state}; this->addItem(this->byteAddressContainer); this->displayRelativeAddressAction->setCheckable(true); @@ -48,13 +50,6 @@ namespace Widgets this->setAddressType(this->state.settings.addressLabelType); this->setItemIndexMethod(QGraphicsScene::ItemIndexMethod::NoIndex); - QObject::connect( - InsightSignals::instance(), - &InsightSignals::targetStateUpdated, - this, - &ItemGraphicsScene::onTargetStateChanged - ); - QObject::connect( this->displayRelativeAddressAction, &QAction::triggered, @@ -168,14 +163,14 @@ namespace Widgets void ItemGraphicsScene::init() { this->byteAddressContainer->setPos(this->addressContainerPosition()); - const auto constructHexViewerTopLevelGroupItem = QSharedPointer( - new ConstructHexViewerTopLevelGroupItem( + const auto constructHexViewerTopLevelGroupItem = QSharedPointer{ + new ConstructHexViewerTopLevelGroupItem{ this->focusedMemoryRegions, this->excludedMemoryRegions, this->state - ), + }, &QObject::deleteLater - ); + }; QObject::connect( constructHexViewerTopLevelGroupItem.get(), @@ -186,7 +181,7 @@ namespace Widgets this->topLevelGroup.reset(item); this->topLevelGroup->setPosition( - QPoint(ByteAddressContainer::WIDTH + margins.left(), margins.top()) + QPoint{ByteAddressContainer::WIDTH + margins.left(), margins.top()} ); this->itemIndex = std::make_unique(this->topLevelGroup.get(), this); @@ -267,14 +262,13 @@ namespace Widgets this->topLevelGroup->adjustItemPositions(availableWidth); this->itemIndex->refreshIndex(); - const auto sceneSize = QSize( + const auto sceneSize = QSize{ width, std::max( - static_cast(this->topLevelGroup->size().height()) - + margins.top() + margins.bottom(), + static_cast(this->topLevelGroup->size().height()) + margins.top() + margins.bottom(), this->parent->height() ) - ); + }; this->setSceneRect( 0, 0, @@ -317,7 +311,7 @@ namespace Widgets return byteItemIt->second.position(); } - return QPointF(); + return QPointF{}; } void ItemGraphicsScene::addExternalContextMenuAction(ContextMenuAction* action) { @@ -329,22 +323,22 @@ namespace Widgets } void ItemGraphicsScene::initRenderer() { - this->renderer = new HexViewerItemRenderer( + this->renderer = new HexViewerItemRenderer{ this->state, *(this->topLevelGroup.get()), *(this->itemIndex.get()), this->views().first() - ); + }; this->renderer->setPos(0, 0); this->addItem(this->renderer); } QMargins ItemGraphicsScene::margins() { - return QMargins(10, 10, 10, 10); + return QMargins{10, 10, 10, 10}; } QPointF ItemGraphicsScene::addressContainerPosition() { - return QPointF(0, 0); + return QPointF{0, 0}; } bool ItemGraphicsScene::event(QEvent* event) { @@ -360,8 +354,8 @@ namespace Widgets } void ItemGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent* mouseEvent) { - static const auto rubberBandRectBackgroundColor = QColor(0x3C, 0x59, 0x5C, 0x82); - static const auto rubberBandRectBorderColor = QColor(0x3C, 0x59, 0x5C, 255); + static const auto rubberBandRectBackgroundColor = QColor{0x3C, 0x59, 0x5C, 0x82}; + static const auto rubberBandRectBorderColor = QColor{0x3C, 0x59, 0x5C, 255}; const auto button = mouseEvent->button(); const auto mousePosition = mouseEvent->buttonDownScenePos(button); @@ -377,7 +371,7 @@ namespace Widgets this->update(); if (button == Qt::MouseButton::RightButton) { - ByteItem* clickedByteItem = this->itemIndex->byteItemAt(mousePosition); + auto* clickedByteItem = this->itemIndex->byteItemAt(mousePosition); if (clickedByteItem == nullptr || clickedByteItem->selected) { return; @@ -389,12 +383,12 @@ namespace Widgets this->clearSelectionRectItem(); this->rubberBandInitPoint = std::move(mousePosition); - this->rubberBandRectItem = new QGraphicsRectItem( + this->rubberBandRectItem = new QGraphicsRectItem{ this->rubberBandInitPoint->x(), this->rubberBandInitPoint->y(), 1, 1 - ); + }; this->rubberBandRectItem->setBrush(rubberBandRectBackgroundColor); this->rubberBandRectItem->setPen(rubberBandRectBorderColor); this->addItem(this->rubberBandRectItem); @@ -409,7 +403,7 @@ namespace Widgets if ((modifiers & Qt::ShiftModifier) != 0) { for ( auto i = static_cast(clickedByteItem->startAddress); - i >= this->state.memoryDescriptor.addressRange.startAddress; + i >= this->state.memorySegmentDescriptor.addressRange.startAddress; --i ) { auto& byteItem = this->topLevelGroup->byteItemsByAddress.at( @@ -500,11 +494,11 @@ namespace Widgets void ItemGraphicsScene::contextMenuEvent(QGraphicsSceneContextMenuEvent* event) { if (event->scenePos().x() <= ByteAddressContainer::WIDTH) { - auto* menu = new QMenu(this->parent); + auto* menu = new QMenu{this->parent}; menu->setLayoutDirection(Qt::LayoutDirection::LeftToRight); menu->setObjectName("byte-item-address-container-context-menu"); - auto* addressTypeMenu = new QMenu("Address Type", menu); + auto* addressTypeMenu = new QMenu{"Address Type", menu}; addressTypeMenu->addAction(this->displayAbsoluteAddressAction); addressTypeMenu->addAction(this->displayRelativeAddressAction); menu->addMenu(addressTypeMenu); @@ -515,13 +509,13 @@ namespace Widgets const auto itemsSelected = !this->selectedByteItemAddresses.empty(); - auto* menu = new QMenu(this->parent); + auto* menu = new QMenu{this->parent}; menu->setLayoutDirection(Qt::LayoutDirection::LeftToRight); menu->addAction(this->selectAllByteItemsAction); menu->addAction(this->deselectByteItemsAction); menu->addSeparator(); - auto* copyMenu = new QMenu("Copy Selection", menu); + auto* copyMenu = new QMenu{"Copy Selection", menu}; copyMenu->addAction(this->copyAbsoluteAddressAction); copyMenu->addAction(this->copyRelativeAddressAction); copyMenu->addSeparator(); @@ -561,10 +555,6 @@ namespace Widgets return this->views().first()->verticalScrollBar()->value(); } - void ItemGraphicsScene::onTargetStateChanged(Targets::TargetState newState) { - this->targetState = newState; - } - void ItemGraphicsScene::onByteItemEnter(ByteItem& byteItem) { if (this->state.hoveredByteItem != nullptr) { if (this->state.hoveredByteItem == &byteItem) { @@ -646,7 +636,7 @@ namespace Widgets } std::set ItemGraphicsScene::excludedAddresses() { - auto output = std::set(); + auto output = std::set{}; for (const auto& excludedRegion : this->excludedMemoryRegions) { const auto regionAddresses = excludedRegion.addressRange.addresses(); @@ -661,8 +651,8 @@ namespace Widgets return; } - auto data = QString(); - const auto memoryStartAddress = this->state.memoryDescriptor.addressRange.startAddress; + auto data = QString{}; + const auto memoryStartAddress = this->state.memorySegmentDescriptor.addressRange.startAddress; for (const auto& address : this->selectedByteItemAddresses) { data.append( @@ -684,12 +674,12 @@ namespace Widgets } const auto excludedAddresses = this->excludedAddresses(); - auto data = QString(); + auto data = QString{}; for (const auto& address : this->selectedByteItemAddresses) { const unsigned char byteValue = excludedAddresses.contains(address) ? 0x00 - : (*this->state.data)[address - this->state.memoryDescriptor.addressRange.startAddress]; + : (*this->state.data)[address - this->state.memorySegmentDescriptor.addressRange.startAddress]; data.append( withDelimiters @@ -707,12 +697,12 @@ namespace Widgets } const auto excludedAddresses = this->excludedAddresses(); - auto data = QString(); + auto data = QString{}; for (const auto& address : this->selectedByteItemAddresses) { const unsigned char byteValue = excludedAddresses.contains(address) ? 0x00 - : (*this->state.data)[address - this->state.memoryDescriptor.addressRange.startAddress]; + : (*this->state.data)[address - this->state.memorySegmentDescriptor.addressRange.startAddress]; data.append(QString::number(byteValue, 10) + "\n"); } @@ -725,12 +715,12 @@ namespace Widgets } const auto excludedAddresses = this->excludedAddresses(); - auto data = QString(); + auto data = QString{}; for (const auto& address : this->selectedByteItemAddresses) { const unsigned char byteValue = excludedAddresses.contains(address) ? 0x00 - : (*this->state.data)[address - this->state.memoryDescriptor.addressRange.startAddress]; + : (*this->state.data)[address - this->state.memorySegmentDescriptor.addressRange.startAddress]; data.append( withDelimiters @@ -748,12 +738,12 @@ namespace Widgets } const auto excludedAddresses = this->excludedAddresses(); - auto data = QJsonObject(); + auto data = QJsonObject{}; for (const auto& address : this->selectedByteItemAddresses) { const unsigned char byteValue = excludedAddresses.contains(address) ? 0x00 - : (*this->state.data)[address - this->state.memoryDescriptor.addressRange.startAddress]; + : (*this->state.data)[address - this->state.memorySegmentDescriptor.addressRange.startAddress]; data.insert( "0x" + QString::number(address, 16).rightJustified(8, '0').toUpper(), @@ -761,7 +751,7 @@ namespace Widgets ); } - QApplication::clipboard()->setText(QJsonDocument(data).toJson(QJsonDocument::JsonFormat::Indented)); + QApplication::clipboard()->setText(QJsonDocument{data}.toJson(QJsonDocument::JsonFormat::Indented)); } void ItemGraphicsScene::copyAsciiValueToClipboard() { @@ -770,17 +760,17 @@ namespace Widgets } const auto excludedAddresses = this->excludedAddresses(); - auto data = QString(); + auto data = QString{}; for (const auto& address : this->selectedByteItemAddresses) { const unsigned char byteValue = - (*this->state.data)[address - this->state.memoryDescriptor.addressRange.startAddress]; + (*this->state.data)[address - this->state.memorySegmentDescriptor.addressRange.startAddress]; if (excludedAddresses.contains(address) || byteValue < 32 || byteValue > 126) { continue; } - data.append(QChar(byteValue)); + data.append(QChar{byteValue}); } QApplication::clipboard()->setText(std::move(data)); @@ -789,7 +779,7 @@ namespace Widgets std::set ItemGraphicsScene::addressRangesToAddresses( const std::set& addressRanges ) { - auto addresses = std::set(); + auto addresses = std::set{}; for (const auto& range : addressRanges) { const auto rangeAddresses = range.addresses(); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.hpp index 6e780fc5..28b62b5c 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsScene.hpp @@ -18,6 +18,8 @@ #include #include "src/Targets/TargetMemory.hpp" +#include "src/Targets/TargetAddressSpaceDescriptor.hpp" +#include "src/Targets/TargetMemorySegmentDescriptor.hpp" #include "src/Targets/TargetState.hpp" #include "src/Insight/UserInterfaces/InsightWindow/Widgets/Label.hpp" @@ -45,7 +47,9 @@ namespace Widgets public: ItemGraphicsScene( - const Targets::TargetMemoryDescriptor& targetMemoryDescriptor, + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, + const Targets::TargetState& targetState, const std::optional& data, const std::vector& focusedMemoryRegions, const std::vector& excludedMemoryRegions, @@ -76,6 +80,7 @@ namespace Widgets bool enabled = true; HexViewerSharedState state; + const Targets::TargetState& targetState; const std::vector& focusedMemoryRegions; const std::vector& excludedMemoryRegions; @@ -85,8 +90,6 @@ namespace Widgets HexViewerItemRenderer* renderer = nullptr; - Targets::TargetState targetState = Targets::TargetState::UNKNOWN; - QGraphicsView* parent = nullptr; ByteAddressContainer* byteAddressContainer = nullptr; @@ -143,7 +146,6 @@ namespace Widgets void keyPressEvent(QKeyEvent* keyEvent) override; void contextMenuEvent(QGraphicsSceneContextMenuEvent* event) override; int getScrollbarValue(); - void onTargetStateChanged(Targets::TargetState newState); void onByteItemEnter(ByteItem& byteItem); void onByteItemLeave(); void clearSelectionRectItem(); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsView.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsView.cpp index 6ad113aa..2ced4bed 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsView.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsView.cpp @@ -6,10 +6,12 @@ namespace Widgets { - using Targets::TargetMemoryDescriptor; + using Targets::TargetMemorySegmentDescriptor; ItemGraphicsView::ItemGraphicsView( - const TargetMemoryDescriptor& targetMemoryDescriptor, + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, + const Targets::TargetState& targetState, const std::optional& data, const std::vector& focusedMemoryRegions, const std::vector& excludedMemoryRegions, @@ -17,7 +19,9 @@ namespace Widgets QWidget* parent ) : QGraphicsView(parent) - , targetMemoryDescriptor(targetMemoryDescriptor) + , addressSpaceDescriptor(addressSpaceDescriptor) + , memorySegmentDescriptor(memorySegmentDescriptor) + , targetState(targetState) , data(data) , focusedMemoryRegions(focusedMemoryRegions) , excludedMemoryRegions(excludedMemoryRegions) @@ -40,14 +44,16 @@ namespace Widgets } void ItemGraphicsView::initScene() { - this->scene = new ItemGraphicsScene( - this->targetMemoryDescriptor, + this->scene = new ItemGraphicsScene{ + this->addressSpaceDescriptor, + this->memorySegmentDescriptor, + this->targetState, this->data, this->focusedMemoryRegions, this->excludedMemoryRegions, this->settings, this - ); + }; this->setScene(this->scene); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsView.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsView.hpp index 375142ac..eb7062e7 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsView.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsView.hpp @@ -8,6 +8,10 @@ #include "ItemGraphicsScene.hpp" #include "src/Targets/TargetMemory.hpp" +#include "src/Targets/TargetAddressSpaceDescriptor.hpp" +#include "src/Targets/TargetMemorySegmentDescriptor.hpp" +#include "src/Targets/TargetState.hpp" + #include "src/Insight/UserInterfaces/InsightWindow/Widgets/Label.hpp" namespace Widgets @@ -18,7 +22,9 @@ namespace Widgets public: ItemGraphicsView( - const Targets::TargetMemoryDescriptor& targetMemoryDescriptor, + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, + const Targets::TargetState& targetState, const std::optional& data, const std::vector& focusedMemoryRegions, const std::vector& excludedMemoryRegions, @@ -38,7 +44,10 @@ namespace Widgets void sceneReady(); protected: - const Targets::TargetMemoryDescriptor& targetMemoryDescriptor; + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor; + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor; + const Targets::TargetState& targetState; + const std::optional& data; const std::vector& focusedMemoryRegions; const std::vector& excludedMemoryRegions; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/StackMemoryGroupItem.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/StackMemoryGroupItem.cpp index b61d6751..5114abf0 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/StackMemoryGroupItem.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/StackMemoryGroupItem.cpp @@ -16,7 +16,7 @@ namespace Widgets , hexViewerState(hexViewerState) { const auto startAddress = this->startAddress; - const auto endAddress = this->hexViewerState.memoryDescriptor.addressRange.endAddress; + const auto endAddress = this->hexViewerState.memorySegmentDescriptor.addressRange.endAddress; // Sanity check assert(byteItemsByAddress.contains(startAddress) && byteItemsByAddress.contains(endAddress)); @@ -74,10 +74,7 @@ namespace Widgets updateChildItems(this->items, updateChildItems); } - void StackMemoryGroupItem::adjustItemPositions( - const int maximumWidth, - const HexViewerSharedState* hexViewerState - ) { + void StackMemoryGroupItem::adjustItemPositions(int maximumWidth, const HexViewerSharedState* hexViewerState) { GroupItem::adjustItemPositions(maximumWidth, hexViewerState); this->groupSize.setWidth(maximumWidth); } @@ -88,10 +85,7 @@ namespace Widgets } } - QMargins StackMemoryGroupItem::groupMargins( - const HexViewerSharedState* hexViewerState, - const int maximumWidth - ) const { - return QMargins(0, 100, 0, 20); + QMargins StackMemoryGroupItem::groupMargins(const HexViewerSharedState* hexViewerState, int maximumWidth) const { + return {0, 100, 0, 20}; } } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/StackMemoryGroupItem.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/StackMemoryGroupItem.hpp index af72ba3c..62c0b85a 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/StackMemoryGroupItem.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/StackMemoryGroupItem.hpp @@ -26,12 +26,12 @@ namespace Widgets ~StackMemoryGroupItem(); - void adjustItemPositions(const int maximumWidth, const HexViewerSharedState* hexViewerState) override; + void adjustItemPositions(int maximumWidth, const HexViewerSharedState* hexViewerState) override; void refreshValues(); protected: - QMargins groupMargins(const HexViewerSharedState* hexViewerState, const int maximumWidth) const override; + QMargins groupMargins(const HexViewerSharedState* hexViewerState, int maximumWidth) const override; bool positionOnNewLine(const int maximumWidth) override { return true; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/TopLevelGroupItem.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/TopLevelGroupItem.cpp index 1d8c30eb..012c685b 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/TopLevelGroupItem.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/TopLevelGroupItem.cpp @@ -12,8 +12,8 @@ namespace Widgets , excludedMemoryRegions(excludedMemoryRegions) , hexViewerState(hexViewerState) { - const auto memorySize = this->hexViewerState.memoryDescriptor.size(); - const auto startAddress = this->hexViewerState.memoryDescriptor.addressRange.startAddress; + const auto memorySize = this->hexViewerState.memorySegmentDescriptor.size(); + const auto startAddress = this->hexViewerState.memorySegmentDescriptor.addressRange.startAddress; for (Targets::TargetMemorySize i = 0; i < memorySize; i++) { const auto address = startAddress + i; @@ -29,8 +29,8 @@ namespace Widgets const auto& currentStackPointer = this->hexViewerState.currentStackPointer; const auto stackGroupingRequired = currentStackPointer.has_value() && this->hexViewerState.settings.groupStackMemory - && *currentStackPointer >= this->hexViewerState.memoryDescriptor.addressRange.startAddress - && (*currentStackPointer + 1) <= this->hexViewerState.memoryDescriptor.addressRange.endAddress; + && *currentStackPointer >= this->hexViewerState.memorySegmentDescriptor.addressRange.startAddress + && (*currentStackPointer + 1) <= this->hexViewerState.memorySegmentDescriptor.addressRange.endAddress; for (const auto& focusedRegion : this->focusedMemoryRegions) { if ( @@ -48,7 +48,7 @@ namespace Widgets } this->focusedRegionGroupItems.emplace_back(focusedRegion, this->byteItemsByAddress, this); - items.emplace_back(&(this->focusedRegionGroupItems.back())); + this->items.emplace_back(&(this->focusedRegionGroupItems.back())); } if (stackGroupingRequired) { diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/TopLevelGroupItem.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/TopLevelGroupItem.hpp index e3953c86..4cf3f20c 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/TopLevelGroupItem.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/TopLevelGroupItem.hpp @@ -32,7 +32,7 @@ namespace Widgets void refreshValues(); - void adjustItemPositions(const int maximumWidth) { + void adjustItemPositions(int maximumWidth) { GroupItem::adjustItemPositions(maximumWidth, &(this->hexViewerState)); } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/Images/memory-inspection-icon.svg b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/Images/memory-inspection-icon.svg index b53033a7..478efc48 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/Images/memory-inspection-icon.svg +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/Images/memory-inspection-icon.svg @@ -1,19 +1,18 @@ + inkscape:version="1.1.2 (0a00cf5339, 2022-02-04)" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns="http://www.w3.org/2000/svg" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:cc="http://creativecommons.org/ns#"> + inkscape:snap-bbox-edge-midpoints="true" + inkscape:pagecheckerboard="0" /> - image/svg+xml - - - + rdf:about="" /> diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.cpp index 3c7bf7a9..eda8369e 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.cpp @@ -5,12 +5,10 @@ MemoryRegion::MemoryRegion( const QString& name, - Targets::TargetMemoryType memoryType, MemoryRegionType type, const Targets::TargetMemoryAddressRange& addressRange ) : name(name) - , memoryType(memoryType) , type(type) , addressRange(addressRange) {} @@ -20,45 +18,38 @@ MemoryRegion::MemoryRegion(const QJsonObject& jsonObject) { if ( !jsonObject.contains("name") - || !jsonObject.contains("memoryType") || !jsonObject.contains("type") || !jsonObject.contains("createdTimestamp") || !jsonObject.contains("addressInputType") || !jsonObject.contains("addressRange") ) { - throw Exception("Missing data"); + throw Exception{"Missing data"}; } const auto addressRangeObj = jsonObject.find("addressRange")->toObject(); - if ( - !addressRangeObj.contains("startAddress") - || !addressRangeObj.contains("endAddress") - ) { - throw Exception("Missing address range data"); + if (!addressRangeObj.contains("startAddress") || !addressRangeObj.contains("endAddress")) { + throw Exception{"Missing address range data"}; } this->name = jsonObject.find("name")->toString(); - this->memoryType = EnumToStringMappings::targetMemoryTypes.at(jsonObject.find("memoryType")->toString()); this->type = MemoryRegion::memoryRegionTypesByName.at(jsonObject.find("type")->toString()); this->createdDate.setSecsSinceEpoch(jsonObject.find("createdTimestamp")->toInteger()); this->addressRangeInputType = MemoryRegion::addressTypesByName.at(jsonObject.find("addressInputType")->toString()); - this->addressRange = { - static_cast(addressRangeObj.find("startAddress")->toInteger()), - static_cast(addressRangeObj.find("endAddress")->toInteger()), + static_cast(addressRangeObj.find("startAddress")->toInteger()), + static_cast(addressRangeObj.find("endAddress")->toInteger()), }; } QJsonObject MemoryRegion::toJson() const { - return QJsonObject({ + return { {"name", this->name}, - {"memoryType", EnumToStringMappings::targetMemoryTypes.at(this->memoryType)}, {"type", MemoryRegion::memoryRegionTypesByName.at(this->type)}, {"createdTimestamp", this->createdDate.toSecsSinceEpoch()}, {"addressInputType", MemoryRegion::addressTypesByName.at(this->addressRangeInputType)}, - {"addressRange", QJsonObject({ + {"addressRange", QJsonObject{ {"startAddress", static_cast(this->addressRange.startAddress)}, {"endAddress", static_cast(this->addressRange.endAddress)}, - })}, - }); + }}, + }; } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.hpp index 2da37099..ad42ec9f 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.hpp @@ -30,7 +30,6 @@ class MemoryRegion public: QString name; QDateTime createdDate = Services::DateTimeService::currentDateTime(); - Targets::TargetMemoryType memoryType; MemoryRegionType type; /** @@ -54,12 +53,11 @@ public: MemoryRegion( const QString& name, - Targets::TargetMemoryType memoryType, MemoryRegionType type, const Targets::TargetMemoryAddressRange& addressRange ); - MemoryRegion(const QJsonObject& jsonObject); + explicit MemoryRegion(const QJsonObject& jsonObject); virtual QJsonObject toJson() const; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/ExcludedRegionItem.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/ExcludedRegionItem.cpp index 8a1e6f34..c23bdba7 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/ExcludedRegionItem.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/ExcludedRegionItem.cpp @@ -10,41 +10,39 @@ namespace Widgets { ExcludedRegionItem::ExcludedRegionItem( const ExcludedMemoryRegion& region, - const Targets::TargetMemoryDescriptor& memoryDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, QWidget* parent ) - : RegionItem(region, memoryDescriptor, parent) + : RegionItem(region, memorySegmentDescriptor, parent) , memoryRegion(region) { - auto formUiFile = QFile( + auto formUiFile = QFile{ QString::fromStdString(Services::PathService::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane" - + "/MemoryRegionManager/UiFiles/ExcludedMemoryRegionForm.ui" + + "/MemoryRegionManager/UiFiles/ExcludedMemoryRegionForm.ui" ) - ); + }; if (!formUiFile.open(QFile::ReadOnly)) { - throw Exceptions::Exception("Failed to open excluded region item form UI file"); + throw Exceptions::Exception{"Failed to open excluded region item form UI file"}; } - auto uiLoader = UiLoader(this); + auto uiLoader = UiLoader{this}; this->formWidget = uiLoader.load(&formUiFile, this); this->initFormInputs(); } void ExcludedRegionItem::applyChanges() { - using Targets::TargetMemoryAddressRange; - this->memoryRegion.name = this->nameInput->text(); - const auto inputAddressRange = TargetMemoryAddressRange( + const auto inputAddressRange = Targets::TargetMemoryAddressRange{ this->startAddressInput->text().toUInt(nullptr, 16), this->endAddressInput->text().toUInt(nullptr, 16) - ); + }; this->memoryRegion.addressRangeInputType = this->getSelectedAddressInputType(); - this->memoryRegion.addressRange = - this->memoryRegion.addressRangeInputType == AddressType::RELATIVE ? - this->convertRelativeToAbsoluteAddressRange(inputAddressRange) : inputAddressRange; + this->memoryRegion.addressRange = this->memoryRegion.addressRangeInputType == AddressType::RELATIVE + ? this->convertRelativeToAbsoluteAddressRange(inputAddressRange) + : inputAddressRange; } } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/ExcludedRegionItem.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/ExcludedRegionItem.hpp index 53a50394..5a71eab1 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/ExcludedRegionItem.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/ExcludedRegionItem.hpp @@ -12,7 +12,7 @@ namespace Widgets public: ExcludedRegionItem( const ExcludedMemoryRegion& region, - const Targets::TargetMemoryDescriptor& memoryDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, QWidget *parent ); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/FocusedRegionItem.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/FocusedRegionItem.cpp index 1c8cf8ce..cefd66fe 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/FocusedRegionItem.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/FocusedRegionItem.cpp @@ -12,24 +12,24 @@ namespace Widgets FocusedRegionItem::FocusedRegionItem( const FocusedMemoryRegion& region, - const Targets::TargetMemoryDescriptor& memoryDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, QWidget* parent ) - : RegionItem(region, memoryDescriptor, parent) + : RegionItem(region, memorySegmentDescriptor, parent) , memoryRegion(region) { - auto formUiFile = QFile( + auto formUiFile = QFile{ QString::fromStdString(Services::PathService::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane" - + "/MemoryRegionManager/UiFiles/FocusedMemoryRegionForm.ui" + + "/MemoryRegionManager/UiFiles/FocusedMemoryRegionForm.ui" ) - ); + }; if (!formUiFile.open(QFile::ReadOnly)) { - throw Exceptions::Exception("Failed to open focused region item form UI file"); + throw Exceptions::Exception{"Failed to open focused region item form UI file"}; } - auto uiLoader = UiLoader(this); + auto uiLoader = UiLoader{this}; this->formWidget = uiLoader.load(&formUiFile, this); this->initFormInputs(); @@ -38,10 +38,10 @@ namespace Widgets void FocusedRegionItem::applyChanges() { this->memoryRegion.name = this->nameInput->text(); - const auto inputAddressRange = TargetMemoryAddressRange( + const auto inputAddressRange = Targets::TargetMemoryAddressRange{ this->startAddressInput->text().toUInt(nullptr, 16), this->endAddressInput->text().toUInt(nullptr, 16) - ); + }; this->memoryRegion.addressRangeInputType = this->getSelectedAddressInputType(); this->memoryRegion.addressRange = this->memoryRegion.addressRangeInputType == AddressType::RELATIVE ? this->convertRelativeToAbsoluteAddressRange(inputAddressRange) diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/FocusedRegionItem.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/FocusedRegionItem.hpp index 01f04229..b8adef1e 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/FocusedRegionItem.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/FocusedRegionItem.hpp @@ -34,7 +34,7 @@ namespace Widgets public: FocusedRegionItem( const FocusedMemoryRegion& region, - const Targets::TargetMemoryDescriptor& memoryDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, QWidget *parent ); @@ -52,20 +52,16 @@ namespace Widgets QComboBox* dataTypeInput = nullptr; QComboBox* endiannessInput = nullptr; - static const inline std::map dataTypeOptionsByName = std::map< - QString, DataTypeOption - >({ - {"other", DataTypeOption("Other", MemoryRegionDataType::UNKNOWN)}, - {"unsigned_integer", DataTypeOption("Unsigned Integer", MemoryRegionDataType::UNSIGNED_INTEGER)}, - {"signed_integer", DataTypeOption("Signed Integer", MemoryRegionDataType::SIGNED_INTEGER)}, - {"ascii", DataTypeOption("ASCII String", MemoryRegionDataType::ASCII_STRING)}, - }); + static const inline std::map dataTypeOptionsByName = { + {"other", DataTypeOption{"Other", MemoryRegionDataType::UNKNOWN}}, + {"unsigned_integer", DataTypeOption{"Unsigned Integer", MemoryRegionDataType::UNSIGNED_INTEGER}}, + {"signed_integer", DataTypeOption{"Signed Integer", MemoryRegionDataType::SIGNED_INTEGER}}, + {"ascii", DataTypeOption{"ASCII String", MemoryRegionDataType::ASCII_STRING}}, + }; - static const inline std::map endiannessOptionsByName = std::map< - QString, EndiannessOption - >({ - {"little", EndiannessOption("Little-endian", Targets::TargetMemoryEndianness::LITTLE)}, - {"big", EndiannessOption("Big-endian", Targets::TargetMemoryEndianness::BIG)}, - }); + static const inline std::map endiannessOptionsByName = { + {"little", EndiannessOption{"Little-endian", Targets::TargetMemoryEndianness::LITTLE}}, + {"big", EndiannessOption{"Big-endian", Targets::TargetMemoryEndianness::BIG}}, + }; }; } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/MemoryRegionManagerWindow.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/MemoryRegionManagerWindow.cpp index 390502fd..ec977c74 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/MemoryRegionManagerWindow.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/MemoryRegionManagerWindow.cpp @@ -16,48 +16,50 @@ namespace Widgets using Exceptions::Exception; MemoryRegionManagerWindow::MemoryRegionManagerWindow( - const Targets::TargetMemoryDescriptor& memoryDescriptor, + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, std::vector& focusedMemoryRegions, std::vector& excludedMemoryRegions, QWidget* parent ) : QWidget(parent) - , memoryDescriptor(memoryDescriptor) + , addressSpaceDescriptor(addressSpaceDescriptor) + , memorySegmentDescriptor(memorySegmentDescriptor) , focusedMemoryRegions(focusedMemoryRegions) , excludedMemoryRegions(excludedMemoryRegions) { this->setWindowFlag(Qt::Window); this->setObjectName("memory-region-manager-window"); this->setWindowTitle( - "Memory Regions - " + EnumToStringMappings::targetMemoryTypes.at(this->memoryDescriptor.type).toUpper() + "Memory Regions - " + QString::fromStdString(this->memorySegmentDescriptor.name) ); - auto windowUiFile = QFile( + auto windowUiFile = QFile{ QString::fromStdString(Services::PathService::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane" + "/MemoryRegionManager/UiFiles/MemoryRegionManagerWindow.ui" ) - ); + }; - auto windowStylesheet = QFile( + auto windowStylesheet = QFile{ QString::fromStdString(Services::PathService::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane" + "/MemoryRegionManager/Stylesheets/MemoryRegionManagerWindow.qss" ) - ); + }; if (!windowUiFile.open(QFile::ReadOnly)) { - throw Exception("Failed to open MemoryRegionManagerWindow UI file"); + throw Exception{"Failed to open MemoryRegionManagerWindow UI file"}; } if (!windowStylesheet.open(QFile::ReadOnly)) { - throw Exception("Failed to open MemoryRegionManagerWindow stylesheet file"); + throw Exception{"Failed to open MemoryRegionManagerWindow stylesheet file"}; } this->setStyleSheet(windowStylesheet.readAll()); - this->setFixedSize(QSize(970, 540)); + this->setFixedSize(QSize{970, 540}); - auto uiLoader = UiLoader(this); + auto uiLoader = UiLoader{this}; this->container = uiLoader.load(&windowUiFile, this); this->container->setFixedSize(this->size()); @@ -210,11 +212,11 @@ namespace Widgets } FocusedRegionItem* MemoryRegionManagerWindow::addFocusedRegion(const FocusedMemoryRegion& region) { - auto* focusedRegionItem = new FocusedRegionItem( + auto* focusedRegionItem = new FocusedRegionItem{ region, - this->memoryDescriptor, + this->memorySegmentDescriptor, this->regionItemScrollAreaViewport - ); + }; this->focusedRegionItems.insert(focusedRegionItem); this->regionItemScrollAreaViewportLayout->addWidget(focusedRegionItem); @@ -231,11 +233,11 @@ namespace Widgets } ExcludedRegionItem* MemoryRegionManagerWindow::addExcludedRegion(const ExcludedMemoryRegion& region) { - auto* excludedRegionItem = new ExcludedRegionItem( + auto* excludedRegionItem = new ExcludedRegionItem{ region, - this->memoryDescriptor, + this->memorySegmentDescriptor, this->regionItemScrollAreaViewport - ); + }; this->excludedRegionItems.insert(excludedRegionItem); this->regionItemScrollAreaViewportLayout->addWidget(excludedRegionItem); @@ -263,14 +265,15 @@ namespace Widgets void MemoryRegionManagerWindow::onNewFocusedRegionTrigger() { using Targets::TargetMemoryAddressRange; - auto* region = this->addFocusedRegion(FocusedMemoryRegion( - "Untitled Region", - this->memoryDescriptor.type, - TargetMemoryAddressRange( - this->memoryDescriptor.addressRange.startAddress, - this->memoryDescriptor.addressRange.startAddress + 10 - ) - )); + auto* region = this->addFocusedRegion( + FocusedMemoryRegion{ + "Untitled Region", + TargetMemoryAddressRange{ + this->memorySegmentDescriptor.addressRange.startAddress, + this->memorySegmentDescriptor.addressRange.startAddress + 10 + } + } + ); region->setSelected(true); } @@ -278,14 +281,15 @@ namespace Widgets void MemoryRegionManagerWindow::onNewExcludedRegionTrigger() { using Targets::TargetMemoryAddressRange; - auto* region = this->addExcludedRegion(ExcludedMemoryRegion( - "Untitled Region", - this->memoryDescriptor.type, - TargetMemoryAddressRange( - this->memoryDescriptor.addressRange.startAddress, - this->memoryDescriptor.addressRange.startAddress + 10 - ) - )); + auto* region = this->addExcludedRegion( + ExcludedMemoryRegion{ + "Untitled Region", + TargetMemoryAddressRange{ + this->memorySegmentDescriptor.addressRange.startAddress, + this->memorySegmentDescriptor.addressRange.startAddress + 10 + } + } + ); region->setSelected(true); } @@ -331,19 +335,19 @@ namespace Widgets } void MemoryRegionManagerWindow::applyChanges() { - auto processedFocusedMemoryRegions = std::vector(); - auto processedExcludedMemoryRegions = std::vector(); + auto processedFocusedMemoryRegions = std::vector{}; + auto processedExcludedMemoryRegions = std::vector{}; for (auto* focusedRegionItem : this->focusedRegionItems) { const auto validationFailures = focusedRegionItem->getValidationFailures(); if (!validationFailures.empty()) { - auto* errorDialogue = new ErrorDialogue( + auto* errorDialogue = new ErrorDialogue{ "Invalid Memory Region", "Invalid memory region \"" + focusedRegionItem->getRegionNameInputValue() + "\"" + "\n\n- " + validationFailures.join("\n- "), this - ); + }; errorDialogue->show(); return; } @@ -352,13 +356,13 @@ namespace Widgets const auto& focusedRegion = focusedRegionItem->getMemoryRegion(); for (const auto& processedFocusedRegion : processedFocusedMemoryRegions) { if (processedFocusedRegion.intersectsWith(focusedRegion)) { - auto* errorDialogue = new ErrorDialogue( + auto* errorDialogue = new ErrorDialogue{ "Intersecting Region Found", "Region \"" + focusedRegionItem->getRegionNameInputValue() + "\" intersects with region \"" + processedFocusedRegion.name + "\". " + "Regions cannot intersect. Please review the relevant address ranges.", this - ); + }; errorDialogue->show(); return; } @@ -371,12 +375,12 @@ namespace Widgets const auto validationFailures = excludedRegionItem->getValidationFailures(); if (!validationFailures.empty()) { - auto* errorDialogue = new ErrorDialogue( + auto* errorDialogue = new ErrorDialogue{ "Invalid Memory Region", "Invalid memory region \"" + excludedRegionItem->getRegionNameInputValue() + "\"" + "

- " + validationFailures.join("
- "), this - ); + }; errorDialogue->show(); return; } @@ -385,13 +389,13 @@ namespace Widgets auto excludedRegion = excludedRegionItem->getMemoryRegion(); for (const auto& processedFocusedRegion : processedFocusedMemoryRegions) { if (processedFocusedRegion.intersectsWith(excludedRegion)) { - auto* errorDialogue = new ErrorDialogue( + auto* errorDialogue = new ErrorDialogue{ "Intersecting Region Found", "Region \"" + excludedRegionItem->getRegionNameInputValue() + "\" intersects with region \"" + processedFocusedRegion.name + "\". " + "Regions cannot intersect. Please review the relevant address ranges.", this - ); + }; errorDialogue->show(); return; } @@ -399,13 +403,13 @@ namespace Widgets for (const auto& processedExcludedRegion : processedExcludedMemoryRegions) { if (processedExcludedRegion.intersectsWith(excludedRegion)) { - auto* errorDialogue = new ErrorDialogue( + auto* errorDialogue = new ErrorDialogue{ "Intersecting Region Found", "Region \"" + excludedRegionItem->getRegionNameInputValue() + "\" intersects with region \"" + processedExcludedRegion.name + "\". " + "Regions cannot intersect. Please review the relevant address ranges.", this - ); + }; errorDialogue->show(); return; } @@ -422,7 +426,7 @@ namespace Widgets void MemoryRegionManagerWindow::openHelpPage() { QDesktopServices::openUrl( - QUrl(QString::fromStdString(Services::PathService::homeDomainName() + "/docs/manage-memory-regions")) + QUrl{QString::fromStdString(Services::PathService::homeDomainName() + "/docs/manage-memory-regions")} ); } } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/MemoryRegionManagerWindow.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/MemoryRegionManagerWindow.hpp index 4b7d0cee..197ba8cf 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/MemoryRegionManagerWindow.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/MemoryRegionManagerWindow.hpp @@ -11,6 +11,8 @@ #include #include "src/Targets/TargetMemory.hpp" +#include "src/Targets/TargetAddressSpaceDescriptor.hpp" +#include "src/Targets/TargetMemorySegmentDescriptor.hpp" #include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.hpp" #include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/FocusedMemoryRegion.hpp" @@ -30,7 +32,8 @@ namespace Widgets public: explicit MemoryRegionManagerWindow( - const Targets::TargetMemoryDescriptor& memoryDescriptor, + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, std::vector& focusedMemoryRegions, std::vector& excludedMemoryRegions, QWidget* parent = nullptr @@ -46,7 +49,8 @@ namespace Widgets void keyPressEvent(QKeyEvent* event) override; private: - const Targets::TargetMemoryDescriptor& memoryDescriptor; + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor; + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor; std::vector& focusedMemoryRegions; std::vector& excludedMemoryRegions; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/RegionItem.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/RegionItem.cpp index b3054766..2b2147a2 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/RegionItem.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/RegionItem.cpp @@ -9,11 +9,11 @@ namespace Widgets RegionItem::RegionItem( const MemoryRegion& region, - const Targets::TargetMemoryDescriptor& memoryDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, QWidget* parent ) : ClickableWidget(parent) - , memoryDescriptor(memoryDescriptor) + , memorySegmentDescriptor(memorySegmentDescriptor) { this->setObjectName("region-item"); this->setFixedHeight(50); @@ -36,14 +36,14 @@ namespace Widgets ); this->addressRangeLabel->setObjectName("address-label"); - auto* topLabelLayout = new QHBoxLayout(); + auto* topLabelLayout = new QHBoxLayout{}; topLabelLayout->setSpacing(0); topLabelLayout->setContentsMargins(0, 0, 0, 0); topLabelLayout->addWidget(this->nameLabel, 0, Qt::AlignmentFlag::AlignLeft); topLabelLayout->addStretch(1); topLabelLayout->addWidget(this->typeLabel, 0, Qt::AlignmentFlag::AlignRight); - auto* bottomLabelLayout = new QHBoxLayout(); + auto* bottomLabelLayout = new QHBoxLayout{}; bottomLabelLayout->setSpacing(0); bottomLabelLayout->setContentsMargins(0, 0, 0, 0); bottomLabelLayout->addWidget(this->addressRangeLabel, 0, Qt::AlignmentFlag::AlignLeft); @@ -77,7 +77,7 @@ namespace Widgets } QStringList RegionItem::getValidationFailures() const { - auto validationFailures = QStringList(); + auto validationFailures = QStringList{}; if (this->nameInput->text().isEmpty()) { validationFailures.emplace_back("Missing region name."); @@ -85,12 +85,12 @@ namespace Widgets bool conversionOk = false; - std::uint32_t startAddress = this->startAddressInput->text().toUInt(&conversionOk, 16); + const auto startAddress = this->startAddressInput->text().toUInt(&conversionOk, 16); if (!conversionOk) { validationFailures.emplace_back("Invalid start address."); } - std::uint32_t endAddress = this->endAddressInput->text().toUInt(&conversionOk, 16); + const auto endAddress = this->endAddressInput->text().toUInt(&conversionOk, 16); if (!conversionOk) { validationFailures.emplace_back("Invalid end address."); } @@ -100,16 +100,16 @@ namespace Widgets } auto addressType = this->getSelectedAddressInputType(); - const auto memoryAddressRange = this->memoryDescriptor.addressRange; + const auto memoryAddressRange = this->memorySegmentDescriptor.addressRange; - const auto memoryAddressRangeStr = QString( + const auto memoryAddressRangeStr = QString{ "0x" + QString::number(memoryAddressRange.startAddress, 16).toUpper() + QString(" -> ") + "0x" + QString::number(memoryAddressRange.endAddress, 16).toUpper() - ); + }; const auto absoluteAddressRange = addressType == AddressType::RELATIVE - ? this->convertRelativeToAbsoluteAddressRange(TargetMemoryAddressRange(startAddress, endAddress)) - : TargetMemoryAddressRange(startAddress, endAddress); + ? this->convertRelativeToAbsoluteAddressRange(TargetMemoryAddressRange{startAddress, endAddress}) + : TargetMemoryAddressRange{startAddress, endAddress}; if (absoluteAddressRange.startAddress < memoryAddressRange.startAddress || absoluteAddressRange.startAddress > memoryAddressRange.endAddress @@ -191,26 +191,26 @@ namespace Widgets TargetMemoryAddressRange RegionItem::convertAbsoluteToRelativeAddressRange( const TargetMemoryAddressRange& absoluteAddressRange ) const { - return TargetMemoryAddressRange( - absoluteAddressRange.startAddress - this->memoryDescriptor.addressRange.startAddress, - absoluteAddressRange.endAddress - this->memoryDescriptor.addressRange.startAddress - ); + return TargetMemoryAddressRange{ + absoluteAddressRange.startAddress - this->memorySegmentDescriptor.addressRange.startAddress, + absoluteAddressRange.endAddress - this->memorySegmentDescriptor.addressRange.startAddress + }; } TargetMemoryAddressRange RegionItem::convertRelativeToAbsoluteAddressRange( const TargetMemoryAddressRange& relativeAddressRange ) const { - return TargetMemoryAddressRange( - relativeAddressRange.startAddress + this->memoryDescriptor.addressRange.startAddress, - relativeAddressRange.endAddress + this->memoryDescriptor.addressRange.startAddress - ); + return TargetMemoryAddressRange{ + relativeAddressRange.startAddress + this->memorySegmentDescriptor.addressRange.startAddress, + relativeAddressRange.endAddress + this->memorySegmentDescriptor.addressRange.startAddress + }; } void RegionItem::onAddressRangeInputChange() { - bool startAddressConversionOk = false; - bool endAddressConversionOk = false; - std::uint32_t startAddress = this->startAddressInput->text().toUInt(&startAddressConversionOk, 16); - std::uint32_t endAddress = this->endAddressInput->text().toUInt(&endAddressConversionOk, 16); + auto startAddressConversionOk = false; + auto endAddressConversionOk = false; + const auto startAddress = this->startAddressInput->text().toUInt(&startAddressConversionOk, 16); + const auto endAddress = this->endAddressInput->text().toUInt(&endAddressConversionOk, 16); if (startAddressConversionOk && endAddressConversionOk && startAddress <= endAddress) { this->sizeInput->setText(QString::number((endAddress - startAddress) + 1)); @@ -218,10 +218,10 @@ namespace Widgets } void RegionItem::onSizeInputChange() { - bool startAddressConversionOk = false; - bool sizeConversionOk = false; - std::uint32_t startAddress = this->startAddressInput->text().toUInt(&startAddressConversionOk, 16); - std::uint32_t size = this->sizeInput->text().toUInt(&sizeConversionOk, 10); + auto startAddressConversionOk = false; + auto sizeConversionOk = false; + const auto startAddress = this->startAddressInput->text().toUInt(&startAddressConversionOk, 16); + const auto size = this->sizeInput->text().toUInt(&sizeConversionOk, 10); if (startAddressConversionOk && sizeConversionOk && size > 0) { this->endAddressInput->setText("0x" + QString::number((startAddress + size) - 1, 16).toUpper()); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/RegionItem.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/RegionItem.hpp index fc2098c5..4f7ae186 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/RegionItem.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegionManager/RegionItem.hpp @@ -12,7 +12,9 @@ #include "src/Insight/UserInterfaces/InsightWindow/Widgets/TextInput.hpp" #include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemoryRegion.hpp" + #include "src/Targets/TargetMemory.hpp" +#include "src/Targets/TargetMemorySegmentDescriptor.hpp" namespace Widgets { @@ -34,7 +36,7 @@ namespace Widgets public: RegionItem( const MemoryRegion& region, - const Targets::TargetMemoryDescriptor& memoryDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, QWidget *parent ); void setSelected(bool selected); @@ -56,7 +58,7 @@ namespace Widgets protected: static constexpr int NAME_LABEL_MAX_LENGTH = 34; - const Targets::TargetMemoryDescriptor& memoryDescriptor; + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor; QWidget* formWidget = nullptr; TextInput* nameInput = nullptr; @@ -86,8 +88,8 @@ namespace Widgets static const inline std::map addressRangeTypeOptionsByName = std::map< QString, AddressRangeTypeOption >({ - {"absolute", AddressRangeTypeOption("Absolute", AddressType::ABSOLUTE)}, - {"relative", AddressRangeTypeOption("Relative", AddressType::RELATIVE)}, + {"absolute", AddressRangeTypeOption{"Absolute", AddressType::ABSOLUTE}}, + {"relative", AddressRangeTypeOption{"Relative", AddressType::RELATIVE}}, }); void onAddressRangeInputChange(); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemorySnapshot.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemorySnapshot.cpp index 887bbbf7..b45b72cc 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemorySnapshot.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemorySnapshot.cpp @@ -4,13 +4,13 @@ #include #include -#include "src/Helpers/EnumToStringMappings.hpp" #include "src/Exceptions/Exception.hpp" MemorySnapshot::MemorySnapshot( const QString& name, const QString& description, - Targets::TargetMemoryType memoryType, + const QString& addressSpaceKey, + const QString& memorySegmentKey, const Targets::TargetMemoryBuffer& data, Targets::TargetMemoryAddress programCounter, Targets::TargetStackPointer stackPointer, @@ -20,7 +20,8 @@ MemorySnapshot::MemorySnapshot( : id(QUuid::createUuid().toString(QUuid::StringFormat::WithoutBraces)) , name(name) , description(description) - , memoryType(memoryType) + , addressSpaceKey(addressSpaceKey) + , memorySegmentKey(memorySegmentKey) , data(data) , programCounter(programCounter) , stackPointer(stackPointer) @@ -28,14 +29,17 @@ MemorySnapshot::MemorySnapshot( , excludedRegions(excludedRegions) {} -MemorySnapshot::MemorySnapshot(const QJsonObject& jsonObject) { +MemorySnapshot::MemorySnapshot(const QJsonObject& jsonObject, const Targets::TargetDescriptor& targetDescriptor) { using Exceptions::Exception; if ( !jsonObject.contains("id") || !jsonObject.contains("name") || !jsonObject.contains("description") - || !jsonObject.contains("memoryType") + || ( + !jsonObject.contains("memoryType") + && (!jsonObject.contains("addressSpaceKey") || !jsonObject.contains("memorySegmentKey")) + ) || !jsonObject.contains("hexData") || !jsonObject.contains("programCounter") || !jsonObject.contains("stackPointer") @@ -43,27 +47,62 @@ MemorySnapshot::MemorySnapshot(const QJsonObject& jsonObject) { || !jsonObject.contains("focusedRegions") || !jsonObject.contains("excludedRegions") ) { - throw Exception("Missing data"); + throw Exception{"Missing data"}; } this->id = jsonObject.find("id")->toString(); this->name = jsonObject.find("name")->toString(); this->description = jsonObject.find("description")->toString(); - this->memoryType = EnumToStringMappings::targetMemoryTypes.at(jsonObject.find("memoryType")->toString()); + + if (!jsonObject.contains("addressSpaceKey") || !jsonObject.contains("memorySegmentKey")) { + /* + * Temporary fallback for backwards compatability with snapshot files that were created by a version prior + * to v2.0.0. Those files will contain a 'memoryType' field, which we map to AVR address spaces and memory + * segments here. + * + * Bloom only supported AVR targets before v2.0.0, which is why we only need to be concerned with AVR address + * spaces and memory segments, here. + * + * @TODO: Bin this after a few versions from v2.0.0. + */ + + const auto memoryType = jsonObject.find("memoryType")->toString(); + + if (memoryType == "ram") { + this->addressSpaceKey = "data"; + this->memorySegmentKey = "internal_ram"; + + } else if (memoryType == "eeprom") { + // Some AVR targets have a separate address space for EEPROM, others use the `data` address space. + this->addressSpaceKey = targetDescriptor.tryGetAddressSpaceDescriptor("eeprom").has_value() + ? "eeprom" + : "data"; + this->memorySegmentKey = "internal_eeprom"; + + } else if (memoryType == "flash") { + this->addressSpaceKey = "prog"; + this->memorySegmentKey = "internal_program_memory"; + } + + } else { + this->addressSpaceKey = jsonObject.find("addressSpaceKey")->toString(); + this->memorySegmentKey = jsonObject.find("memorySegmentKey")->toString(); + } + this->programCounter = static_cast(jsonObject.find("programCounter")->toInteger()); this->stackPointer = static_cast(jsonObject.find("stackPointer")->toInteger()); this->createdDate.setSecsSinceEpoch(jsonObject.find("createdTimestamp")->toInteger()); const auto hexData = QByteArray::fromHex(jsonObject.find("hexData")->toString().toUtf8()); - this->data = Targets::TargetMemoryBuffer(hexData.begin(), hexData.end()); + this->data = Targets::TargetMemoryBuffer{hexData.begin(), hexData.end()}; if (jsonObject.contains("focusedRegions")) { for (const auto& regionValue : jsonObject.find("focusedRegions")->toArray()) { try { this->focusedRegions.emplace_back(regionValue.toObject()); - } catch (Exception exception) { - throw Exception("Invalid focused memory region"); + } catch (const Exception& exception) { + throw Exception{"Invalid focused memory region"}; } } } @@ -73,65 +112,57 @@ MemorySnapshot::MemorySnapshot(const QJsonObject& jsonObject) { try { this->excludedRegions.emplace_back(regionValue.toObject()); - } catch (Exception exception) { - throw Exception("Invalid excluded memory region"); + } catch (const Exception& exception) { + throw Exception{"Invalid excluded memory region"}; } } } } QJsonObject MemorySnapshot::toJson() const { - auto focusedRegions = QJsonArray(); + auto focusedRegions = QJsonArray{}; for (const auto& focusedRegion : this->focusedRegions) { focusedRegions.push_back(focusedRegion.toJson()); } - auto excludedRegions = QJsonArray(); + auto excludedRegions = QJsonArray{}; for (const auto& excludedRegion : this->excludedRegions) { excludedRegions.push_back(excludedRegion.toJson()); } - return QJsonObject({ + return QJsonObject{ {"id", this->id}, {"name", this->name}, {"description", this->description}, - {"memoryType", EnumToStringMappings::targetMemoryTypes.at(this->memoryType)}, - {"hexData", QString(QByteArray( - reinterpret_cast(this->data.data()), - static_cast(this->data.size()) - ).toHex())}, + {"addressSpaceKey", this->addressSpaceKey}, + {"memorySegmentKey", this->memorySegmentKey}, + {"hexData", QString{ + QByteArray{ + reinterpret_cast(this->data.data()), + static_cast(this->data.size()) + }.toHex() + }}, {"programCounter", static_cast(this->programCounter)}, {"stackPointer", static_cast(this->stackPointer)}, {"createdTimestamp", this->createdDate.toSecsSinceEpoch()}, {"focusedRegions", focusedRegions}, {"excludedRegions", excludedRegions}, - }); + }; } -bool MemorySnapshot::isCompatible(const Targets::TargetMemoryDescriptor& memoryDescriptor) const { - if (this->memoryType != memoryDescriptor.type) { +bool MemorySnapshot::isCompatible(const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor) const { + if (this->data.size() != memorySegmentDescriptor.size()) { return false; } - if (this->data.size() != memoryDescriptor.size()) { - return false; - } - - const auto& memoryAddressRange = memoryDescriptor.addressRange; for (const auto& focusedRegion : this->focusedRegions) { - if ( - focusedRegion.addressRange.startAddress < memoryAddressRange.startAddress - || focusedRegion.addressRange.endAddress > memoryAddressRange.endAddress - ) { + if (!memorySegmentDescriptor.addressRange.contains(focusedRegion.addressRange)) { return false; } } for (const auto& excludedRegion : this->excludedRegions) { - if ( - excludedRegion.addressRange.startAddress < memoryAddressRange.startAddress - || excludedRegion.addressRange.endAddress > memoryAddressRange.endAddress - ) { + if (!memorySegmentDescriptor.addressRange.contains(excludedRegion.addressRange)) { return false; } } @@ -140,7 +171,7 @@ bool MemorySnapshot::isCompatible(const Targets::TargetMemoryDescriptor& memoryD } std::set MemorySnapshot::excludedAddresses() const { - auto output = std::set(); + auto output = std::set{}; for (const auto& excludedRegion : this->excludedRegions) { const auto regionAddresses = excludedRegion.addressRange.addresses(); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemorySnapshot.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemorySnapshot.hpp index 95abd448..26f26366 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemorySnapshot.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemorySnapshot.hpp @@ -7,6 +7,8 @@ #include #include "src/Targets/TargetMemory.hpp" +#include "src/Targets/TargetDescriptor.hpp" +#include "src/Targets/TargetMemorySegmentDescriptor.hpp" #include "src/Services/DateTimeService.hpp" #include "FocusedMemoryRegion.hpp" @@ -18,7 +20,8 @@ public: QString id; QString name; QString description; - Targets::TargetMemoryType memoryType; + QString addressSpaceKey; + QString memorySegmentKey; Targets::TargetMemoryBuffer data; Targets::TargetMemoryAddress programCounter; Targets::TargetStackPointer stackPointer; @@ -30,7 +33,8 @@ public: MemorySnapshot( const QString& name, const QString& description, - Targets::TargetMemoryType memoryType, + const QString& addressSpaceKey, + const QString& memorySegmentKey, const Targets::TargetMemoryBuffer& data, Targets::TargetMemoryAddress programCounter, Targets::TargetStackPointer stackPointer, @@ -38,11 +42,11 @@ public: const std::vector& excludedRegions ); - MemorySnapshot(const QJsonObject& jsonObject); + MemorySnapshot(const QJsonObject& jsonObject, const Targets::TargetDescriptor& targetDescriptor); QJsonObject toJson() const; - bool isCompatible(const Targets::TargetMemoryDescriptor& memoryDescriptor) const; + bool isCompatible(const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor) const; std::set excludedAddresses() const; virtual ~MemorySnapshot() = default; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/CreateSnapshotWindow/CreateSnapshotWindow.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/CreateSnapshotWindow/CreateSnapshotWindow.cpp index e8ddda86..a3b0fb4e 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/CreateSnapshotWindow/CreateSnapshotWindow.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/CreateSnapshotWindow/CreateSnapshotWindow.cpp @@ -17,35 +17,40 @@ namespace Widgets using Exceptions::Exception; CreateSnapshotWindow::CreateSnapshotWindow( - Targets::TargetMemoryType memoryType, + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, + const Targets::TargetState& targetState, const std::optional& data, const bool& staleData, QWidget* parent ) : QWidget(parent) + , addressSpaceDescriptor(addressSpaceDescriptor) + , memorySegmentDescriptor(memorySegmentDescriptor) + , targetState(targetState) , data(data) , staleData(staleData) { this->setWindowFlag(Qt::Window); this->setObjectName("create-snapshot-window"); this->setWindowTitle( - "New Snapshot - " + EnumToStringMappings::targetMemoryTypes.at(memoryType).toUpper() + "New Snapshot - " + QString::fromStdString(this->memorySegmentDescriptor.name) ); - auto windowUiFile = QFile( + auto windowUiFile = QFile{ QString::fromStdString(Services::PathService::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane" + "/SnapshotManager/CreateSnapshotWindow/UiFiles/CreateSnapshotWindow.ui" ) - ); + }; if (!windowUiFile.open(QFile::ReadOnly)) { - throw Exception("Failed to open CreateSnapshotWindow UI file"); + throw Exception{"Failed to open CreateSnapshotWindow UI file"}; } - this->setFixedSize(QSize(500, 300)); + this->setFixedSize(QSize{500, 300}); - auto uiLoader = UiLoader(this); + auto uiLoader = UiLoader{this}; this->container = uiLoader.load(&windowUiFile, this); this->container->setFixedSize(this->size()); @@ -74,14 +79,11 @@ namespace Widgets QObject::connect(this->captureButton, &QPushButton::clicked, this, &CreateSnapshotWindow::issueCaptureRequest); QObject::connect(this->closeButton, &QPushButton::clicked, this, &QWidget::close); - auto* insightSignals = InsightSignals::instance(); - QObject::connect( - insightSignals, + InsightSignals::instance(), &InsightSignals::targetStateUpdated, this, - [this] (Targets::TargetState newState) { - this->targetState = newState; + [this] () { this->refreshForm(); } ); @@ -119,7 +121,7 @@ namespace Widgets } bool CreateSnapshotWindow::captureEnabled() { - if (this->targetState != Targets::TargetState::STOPPED) { + if (this->targetState.executionState != Targets::TargetExecutionState::STOPPED) { return false; } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/CreateSnapshotWindow/CreateSnapshotWindow.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/CreateSnapshotWindow/CreateSnapshotWindow.hpp index 6684aa54..31a770b2 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/CreateSnapshotWindow/CreateSnapshotWindow.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/CreateSnapshotWindow/CreateSnapshotWindow.hpp @@ -11,6 +11,8 @@ #include "src/Insight/UserInterfaces/InsightWindow/Widgets/PushButton.hpp" #include "src/Targets/TargetMemory.hpp" +#include "src/Targets/TargetAddressSpaceDescriptor.hpp" +#include "src/Targets/TargetMemorySegmentDescriptor.hpp" #include "src/Targets/TargetState.hpp" namespace Widgets @@ -21,7 +23,9 @@ namespace Widgets public: explicit CreateSnapshotWindow( - Targets::TargetMemoryType memoryType, + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, + const Targets::TargetState& targetState, const std::optional& data, const bool& staleData, QWidget* parent = nullptr @@ -42,6 +46,10 @@ namespace Widgets void keyPressEvent(QKeyEvent* event) override; private: + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor; + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor; + const Targets::TargetState& targetState; + QWidget* container = nullptr; TextInput* nameInput = nullptr; QPlainTextEdit* descriptionInput = nullptr; @@ -56,7 +64,6 @@ namespace Widgets const std::optional& data; const bool& staleData; - Targets::TargetState targetState = Targets::TargetState::UNKNOWN; bool captureEnabled(); void resetForm(); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/MemorySnapshotItem.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/MemorySnapshotItem.cpp index 5d45224b..51d2a892 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/MemorySnapshotItem.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/MemorySnapshotItem.cpp @@ -7,7 +7,7 @@ namespace Widgets MemorySnapshotItem::MemorySnapshotItem(const MemorySnapshot& memorySnapshot) : memorySnapshot(memorySnapshot) { - this->size = QSize(0, MemorySnapshotItem::HEIGHT); + this->size = QSize{0, MemorySnapshotItem::HEIGHT}; this->nameText = memorySnapshot.name; this->programCounterText = "0x" + QString::number(this->memorySnapshot.programCounter, 16).toUpper(); @@ -19,22 +19,22 @@ namespace Widgets } void MemorySnapshotItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { - static constexpr auto margins = QMargins(5, 5, 5, 0); + static constexpr auto margins = QMargins{5, 5, 5, 0}; - static auto font = QFont("'Ubuntu', sans-serif"); + static auto font = QFont{"'Ubuntu', sans-serif"}; font.setPixelSize(14); - static auto secondaryFont = QFont("'Ubuntu', sans-serif"); + static auto secondaryFont = QFont{"'Ubuntu', sans-serif"}; secondaryFont.setPixelSize(13); - static constexpr auto fontColor = QColor(0xAF, 0xB1, 0xB3); - static constexpr auto secondaryFontColor = QColor(0x8A, 0x8A, 0x8D); + static constexpr auto fontColor = QColor{0xAF, 0xB1, 0xB3}; + static constexpr auto secondaryFontColor = QColor{0x8A, 0x8A, 0x8D}; if (this->selected) { - static constexpr auto selectedBackgroundColor = QColor(0x3C, 0x59, 0x5C); + static constexpr auto selectedBackgroundColor = QColor{0x3C, 0x59, 0x5C}; painter->setBrush(selectedBackgroundColor); painter->setPen(Qt::PenStyle::NoPen); - painter->drawRect(QRect(QPoint(0, 0), this->size)); + painter->drawRect(QRect{QPoint{0, 0}, this->size}); } painter->setFont(font); @@ -56,41 +56,39 @@ namespace Widgets ); const auto nameTextSize = fontMetrics.size(Qt::TextSingleLine, nameText); - const auto nameTextRect = QRect( + const auto nameTextRect = QRect{ margins.left(), margins.top(), nameTextSize.width(), nameTextSize.height() - ); + }; painter->drawText(nameTextRect, Qt::AlignLeft, nameText); - painter->setFont(secondaryFont); if (!this->selected) { painter->setPen(secondaryFontColor); } - const auto programCounterTextRect = QRect( + const auto programCounterTextRect = QRect{ this->size.width() - margins.right() - programCounterTextSize.width(), margins.top(), programCounterTextSize.width(), programCounterTextSize.height() - ); + }; painter->drawText(programCounterTextRect, Qt::AlignLeft, this->programCounterText); - const auto createdDateTextRect = QRect( + const auto createdDateTextRect = QRect{ margins.left(), nameTextRect.bottom() + 5, createdDateTextSize.width(), createdDateTextSize.height() - ); + }; painter->drawText(createdDateTextRect, Qt::AlignLeft, this->createdDateText); - static constexpr auto borderColor = QColor(0x2E, 0x2E, 0x2E); - + static constexpr auto borderColor = QColor{0x2E, 0x2E, 0x2E}; painter->setPen(borderColor); painter->drawLine(0, this->size.height() - 1, this->size.width(), this->size.height() - 1); } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/MemorySnapshotItem.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/MemorySnapshotItem.hpp index d1161eda..fbce9520 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/MemorySnapshotItem.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/MemorySnapshotItem.hpp @@ -3,9 +3,7 @@ #include #include "src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListItem.hpp" - #include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemorySnapshot.hpp" -#include "src/Targets/TargetMemory.hpp" namespace Widgets { @@ -17,8 +15,8 @@ namespace Widgets MemorySnapshotItem(const MemorySnapshot& memorySnapshot); bool operator < (const ListItem& rhs) const override { - const auto& rhsSnapshotItem = dynamic_cast(rhs); - return this->memorySnapshot.createdDate > rhsSnapshotItem.memorySnapshot.createdDate; + return this->memorySnapshot.createdDate > + dynamic_cast(rhs).memorySnapshot.createdDate; } void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/ChangeListPane/ChangeListItem.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/ChangeListPane/ChangeListItem.cpp index 8c41a8b4..bcf9fe30 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/ChangeListPane/ChangeListItem.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/ChangeListPane/ChangeListItem.cpp @@ -8,26 +8,26 @@ namespace Widgets ChangeListItem::ChangeListItem(const Targets::TargetMemoryAddressRange& addressRange) : addressRange(addressRange) { - this->size = QSize(0, ChangeListItem::HEIGHT); + this->size = QSize{0, ChangeListItem::HEIGHT}; } void ChangeListItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { - static constexpr auto margins = QMargins(7, 5, 7, 0); + static constexpr auto margins = QMargins{7, 5, 7, 0}; - static auto font = QFont("'Ubuntu', sans-serif"); + static auto font = QFont{"'Ubuntu', sans-serif"}; font.setPixelSize(14); - static auto secondaryFont = QFont("'Ubuntu', sans-serif"); + static auto secondaryFont = QFont{"'Ubuntu', sans-serif"}; secondaryFont.setPixelSize(13); - static constexpr auto fontColor = QColor(0xAF, 0xB1, 0xB3); - static constexpr auto secondaryFontColor = QColor(0x8A, 0x8A, 0x8D); + static constexpr auto fontColor = QColor{0xAF, 0xB1, 0xB3}; + static constexpr auto secondaryFontColor = QColor{0x8A, 0x8A, 0x8D}; if (this->selected) { - static constexpr auto selectedBackgroundColor = QColor(0x3C, 0x59, 0x5C); + static constexpr auto selectedBackgroundColor = QColor{0x3C, 0x59, 0x5C}; painter->setBrush(selectedBackgroundColor); painter->setPen(Qt::PenStyle::NoPen); - painter->drawRect(QRect(QPoint(0, 0), this->size)); + painter->drawRect(QRect{QPoint{0, 0}, this->size}); } painter->setFont(font); @@ -36,16 +36,16 @@ namespace Widgets auto fontMetrics = painter->fontMetrics(); const auto byteCount = this->addressRange.endAddress - this->addressRange.startAddress + 1; - const auto byteCountText = QLocale(QLocale::English).toString(byteCount) + const auto byteCountText = QLocale{QLocale::English}.toString(byteCount) + (byteCount == 1 ? " byte" : " bytes"); const auto byteCountTextSize = fontMetrics.size(Qt::TextSingleLine, byteCountText); - const auto byteCountTextRect = QRect( + const auto byteCountTextRect = QRect{ margins.left(), margins.top(), byteCountTextSize.width(), byteCountTextSize.height() - ); + }; painter->drawText(byteCountTextRect, Qt::AlignLeft, byteCountText); @@ -77,16 +77,16 @@ namespace Widgets ); const auto addressRangeTextSize = fontMetrics.size(Qt::TextSingleLine, addressRangeText); - const auto addressRangeTextRect = QRect( + const auto addressRangeTextRect = QRect{ margins.left(), byteCountTextRect.bottom() + 5, addressRangeTextSize.width(), addressRangeTextSize.height() - ); + }; painter->drawText(addressRangeTextRect, Qt::AlignLeft, addressRangeText); - static constexpr auto borderColor = QColor(0x41, 0x42, 0x3F); + static constexpr auto borderColor = QColor{0x41, 0x42, 0x3F}; painter->setPen(borderColor); painter->drawLine(0, this->size.height() - 1, this->size.width(), this->size.height() - 1); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/ChangeListPane/ChangeListItem.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/ChangeListPane/ChangeListItem.hpp index c2399c94..ce0145f1 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/ChangeListPane/ChangeListItem.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/ChangeListPane/ChangeListItem.hpp @@ -11,7 +11,7 @@ namespace Widgets public: Targets::TargetMemoryAddressRange addressRange; - ChangeListItem(const Targets::TargetMemoryAddressRange& addressRange); + explicit ChangeListItem(const Targets::TargetMemoryAddressRange& addressRange); bool operator < (const ListItem& rhs) const override { const auto& rhsSnapshotItem = dynamic_cast(rhs); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/ChangeListPane/ChangeListPane.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/ChangeListPane/ChangeListPane.cpp index 7c727971..d008b800 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/ChangeListPane/ChangeListPane.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/ChangeListPane/ChangeListPane.cpp @@ -27,18 +27,18 @@ namespace Widgets this->setObjectName("change-list-pane"); this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); - auto widgetUiFile = QFile( + auto widgetUiFile = QFile{ QString::fromStdString(Services::PathService::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager" + "/SnapshotDiff/ChangeListPane/UiFiles/ChangeListPane.ui" ) - ); + }; if (!widgetUiFile.open(QFile::ReadOnly)) { - throw Exception("Failed to open ChangeListPane UI file"); + throw Exception{"Failed to open ChangeListPane UI file"}; } - auto uiLoader = UiLoader(this); + auto uiLoader = UiLoader{this}; this->container = uiLoader.load(&widgetUiFile, this); this->container->setFixedSize(this->size()); @@ -48,7 +48,7 @@ namespace Widgets auto* containerLayout = this->container->findChild(); - this->changeListView = new ListView({}, this); + this->changeListView = new ListView{{}, this}; this->changeListView->viewport()->installEventFilter(parent); this->changeListView->setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAsNeeded); @@ -113,7 +113,7 @@ namespace Widgets this->changeListScene->clearListItems(); for (const auto& diffRange : diffRanges) { - this->changeListScene->addListItem(new ChangeListItem(diffRange)); + this->changeListScene->addListItem(new ChangeListItem{diffRange}); } this->changeListScene->refreshGeometry(); @@ -167,7 +167,7 @@ namespace Widgets return; } - auto* menu = new QMenu(this); + auto* menu = new QMenu{this}; menu->addAction(this->selectBytesAction); menu->addSeparator(); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/ChangeListPane/ChangeListPane.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/ChangeListPane/ChangeListPane.hpp index df46c486..18a6b039 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/ChangeListPane/ChangeListPane.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/ChangeListPane/ChangeListPane.hpp @@ -50,8 +50,8 @@ namespace Widgets const ChangeListItem* selectedChangeListItem = nullptr; - QAction* selectBytesAction = new QAction("Select", this); - QAction* restoreBytesAction = new QAction("Restore", this); + QAction* selectBytesAction = new QAction{"Select", this}; + QAction* restoreBytesAction = new QAction{"Restore", this}; bool restoreEnabled = false; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialHexViewerSharedState.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialHexViewerSharedState.hpp index 5f2d1e46..5362ab0d 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialHexViewerSharedState.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialHexViewerSharedState.hpp @@ -2,6 +2,8 @@ #include +#include "src/Targets/TargetMemory.hpp" + namespace Widgets { struct DifferentialHexViewerSharedState diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialHexViewerWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialHexViewerWidget.cpp index 35091a9d..a3dbc9a4 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialHexViewerWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialHexViewerWidget.cpp @@ -9,7 +9,9 @@ namespace Widgets DifferentialHexViewerWidgetType type, DifferentialHexViewerSharedState& state, const SnapshotDiffSettings& snapshotDiffSettings, - const Targets::TargetMemoryDescriptor& targetMemoryDescriptor, + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, + const Targets::TargetState& targetState, const std::optional& data, HexViewerWidgetSettings& settings, const std::vector& focusedMemoryRegions, @@ -17,7 +19,9 @@ namespace Widgets QWidget* parent ) : HexViewerWidget( - targetMemoryDescriptor, + addressSpaceDescriptor, + memorySegmentDescriptor, + targetState, data, settings, focusedMemoryRegions, @@ -30,17 +34,19 @@ namespace Widgets {} void DifferentialHexViewerWidget::init() { - this->differentialView = new DifferentialItemGraphicsView( + this->differentialView = new DifferentialItemGraphicsView{ this->type, this->state, this->snapshotDiffSettings, - this->targetMemoryDescriptor, + this->addressSpaceDescriptor, + this->memorySegmentDescriptor, + this->targetState, this->data, this->focusedMemoryRegions, this->excludedMemoryRegions, this->settings, this->container - ); + }; if (this->type == DifferentialHexViewerWidgetType::PRIMARY) { this->differentialView->setLayoutDirection(Qt::LayoutDirection::RightToLeft); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialHexViewerWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialHexViewerWidget.hpp index a2c20cca..91537995 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialHexViewerWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialHexViewerWidget.hpp @@ -19,7 +19,9 @@ namespace Widgets DifferentialHexViewerWidgetType type, DifferentialHexViewerSharedState& state, const SnapshotDiffSettings& snapshotDiffSettings, - const Targets::TargetMemoryDescriptor& targetMemoryDescriptor, + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, + const Targets::TargetState& targetState, const std::optional& data, HexViewerWidgetSettings& settings, const std::vector& focusedMemoryRegions, diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialItemGraphicsScene.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialItemGraphicsScene.cpp index 610b2fbf..7c66dbd4 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialItemGraphicsScene.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialItemGraphicsScene.cpp @@ -8,7 +8,9 @@ namespace Widgets DifferentialHexViewerWidgetType differentialHexViewerWidgetType, DifferentialHexViewerSharedState& state, const SnapshotDiffSettings& snapshotDiffSettings, - const Targets::TargetMemoryDescriptor& targetMemoryDescriptor, + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, + const Targets::TargetState& targetState, const std::optional& data, const std::vector& focusedMemoryRegions, const std::vector& excludedMemoryRegions, @@ -16,7 +18,9 @@ namespace Widgets QGraphicsView* parent ) : ItemGraphicsScene( - targetMemoryDescriptor, + addressSpaceDescriptor, + memorySegmentDescriptor, + targetState, data, focusedMemoryRegions, excludedMemoryRegions, diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialItemGraphicsScene.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialItemGraphicsScene.hpp index f33b02ec..0175f73e 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialItemGraphicsScene.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialItemGraphicsScene.hpp @@ -18,7 +18,9 @@ namespace Widgets DifferentialHexViewerWidgetType differentialHexViewerWidgetType, DifferentialHexViewerSharedState& state, const SnapshotDiffSettings& snapshotDiffSettings, - const Targets::TargetMemoryDescriptor& targetMemoryDescriptor, + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, + const Targets::TargetState& targetState, const std::optional& data, const std::vector& focusedMemoryRegions, const std::vector& excludedMemoryRegions, diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialItemGraphicsView.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialItemGraphicsView.cpp index a80bd71f..4e1b0ed6 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialItemGraphicsView.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialItemGraphicsView.cpp @@ -6,7 +6,9 @@ namespace Widgets DifferentialHexViewerWidgetType differentialHexViewerWidgetType, DifferentialHexViewerSharedState& state, const SnapshotDiffSettings& snapshotDiffSettings, - const Targets::TargetMemoryDescriptor& targetMemoryDescriptor, + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, + const Targets::TargetState& targetState, const std::optional& data, const std::vector& focusedMemoryRegions, const std::vector& excludedMemoryRegions, @@ -14,7 +16,9 @@ namespace Widgets QWidget* parent ) : ItemGraphicsView( - targetMemoryDescriptor, + addressSpaceDescriptor, + memorySegmentDescriptor, + targetState, data, focusedMemoryRegions, excludedMemoryRegions, @@ -27,17 +31,19 @@ namespace Widgets {} void DifferentialItemGraphicsView::initScene() { - this->differentialScene = new DifferentialItemGraphicsScene( + this->differentialScene = new DifferentialItemGraphicsScene{ this->differentialHexViewerWidgetType, this->state, this->snapshotDiffSettings, - this->targetMemoryDescriptor, + this->addressSpaceDescriptor, + this->memorySegmentDescriptor, + this->targetState, this->data, this->focusedMemoryRegions, this->excludedMemoryRegions, this->settings, this - ); + }; this->scene = this->differentialScene; this->setScene(this->scene); @@ -47,7 +53,7 @@ namespace Widgets &ItemGraphicsScene::ready, this, [this] { - this->differentialScene->updateByteItemChangedStates(); + this->differentialScene->updateByteItemChangedStates(); this->scene->setEnabled(this->isEnabled()); emit this->sceneReady(); } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialItemGraphicsView.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialItemGraphicsView.hpp index 2019fb5d..53c0fa20 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialItemGraphicsView.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/DifferentialHexViewerWidget/DifferentialItemGraphicsView.hpp @@ -19,7 +19,9 @@ namespace Widgets DifferentialHexViewerWidgetType differentialHexViewerWidgetType, DifferentialHexViewerSharedState& state, const SnapshotDiffSettings& snapshotDiffSettings, - const Targets::TargetMemoryDescriptor& targetMemoryDescriptor, + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, + const Targets::TargetState& targetState, const std::optional& data, const std::vector& focusedMemoryRegions, const std::vector& excludedMemoryRegions, diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/SnapshotDiff.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/SnapshotDiff.cpp index 47b8b089..43f3a682 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/SnapshotDiff.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/SnapshotDiff.cpp @@ -26,12 +26,15 @@ namespace Widgets SnapshotDiff::SnapshotDiff( MemorySnapshot& snapshotA, MemorySnapshot& snapshotB, - const Targets::TargetMemoryDescriptor& memoryDescriptor, - Targets::TargetState currentTargetState, + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, + const Targets::TargetState& targetState, QWidget* parent ) : QWidget(parent) - , memoryDescriptor(memoryDescriptor) + , addressSpaceDescriptor(addressSpaceDescriptor) + , memorySegmentDescriptor(memorySegmentDescriptor) + , targetState(targetState) , hexViewerDataA(snapshotA.data) , focusedRegionsA(snapshotA.focusedRegions) , excludedRegionsA(snapshotA.excludedRegions) @@ -43,11 +46,9 @@ namespace Widgets , comparingWithCurrent(false) { this->init(); - this->onTargetStateChanged(currentTargetState); + this->onTargetStateChanged(); - this->setWindowTitle( - "Comparing snapshot \"" + snapshotA.name + "\" with snapshot \"" + snapshotB.name + "\"" - ); + this->setWindowTitle("Comparing snapshot \"" + snapshotA.name + "\" with snapshot \"" + snapshotB.name + "\""); this->dataAPrimaryLabel->setText(snapshotA.name); this->dataBPrimaryLabel->setText(snapshotB.name); @@ -61,12 +62,15 @@ namespace Widgets std::vector focusedRegionsB, std::vector excludedRegionsB, Targets::TargetStackPointer stackPointerB, - const Targets::TargetMemoryDescriptor& memoryDescriptor, - Targets::TargetState currentTargetState, + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, + const Targets::TargetState& targetState, QWidget* parent ) : QWidget(parent) - , memoryDescriptor(memoryDescriptor) + , addressSpaceDescriptor(addressSpaceDescriptor) + , memorySegmentDescriptor(memorySegmentDescriptor) + , targetState(targetState) , hexViewerDataA(snapshotA.data) , focusedRegionsA(snapshotA.focusedRegions) , excludedRegionsA(snapshotA.excludedRegions) @@ -78,26 +82,24 @@ namespace Widgets , comparingWithCurrent(true) { this->init(); - this->onTargetStateChanged(currentTargetState); + this->onTargetStateChanged(); - this->setWindowTitle( - "Comparing snapshot \"" + snapshotA.name + "\" with current memory" - ); + this->setWindowTitle("Comparing snapshot \"" + snapshotA.name + "\" with current memory"); this->dataAPrimaryLabel->setText(snapshotA.name); this->dataBPrimaryLabel->setText("Current"); this->dataASecondaryLabel->setText(snapshotA.createdDate.toString("dd/MM/yyyy hh:mm")); this->dataBSecondaryLabel->setVisible(false); - this->restoreBytesAction = new ContextMenuAction( + this->restoreBytesAction = new ContextMenuAction{ "Restore Selection", [this] (const std::set&) { return - this->memoryDescriptor.access.writeableDuringDebugSession - && this->targetState == Targets::TargetState::STOPPED; + this->memorySegmentDescriptor.debugModeAccess.writeable + && this->targetState.executionState == Targets::TargetExecutionState::STOPPED; }, this - ); + }; QObject::connect( this->restoreBytesAction, @@ -129,7 +131,7 @@ namespace Widgets this->excludedRegionsB = excludedRegions; this->stackPointerB = stackPointer; - if (this->memoryDescriptor.type == Targets::TargetMemoryType::RAM) { + if (this->memorySegmentDescriptor.type == Targets::TargetMemorySegmentType::RAM) { this->hexViewerWidgetB->setStackPointer(this->stackPointerB); } @@ -170,26 +172,26 @@ namespace Widgets this->setWindowFlag(Qt::Window); this->setObjectName("snapshot-diff"); - auto windowUiFile = QFile( + auto windowUiFile = QFile{ QString::fromStdString(Services::PathService::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane" + "/SnapshotManager/SnapshotDiff/UiFiles/SnapshotDiff.ui" ) - ); + }; - auto stylesheetFile = QFile( + auto stylesheetFile = QFile{ QString::fromStdString(Services::PathService::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane" + "/SnapshotManager/SnapshotDiff/Stylesheets/SnapshotDiff.qss" ) - ); + }; if (!windowUiFile.open(QFile::ReadOnly)) { - throw Exception("Failed to open SnapshotDiff UI file"); + throw Exception{"Failed to open SnapshotDiff UI file"}; } if (!stylesheetFile.open(QFile::ReadOnly)) { - throw Exception("Failed to open SnapshotDiff stylesheet file"); + throw Exception{"Failed to open SnapshotDiff stylesheet file"}; } // Set ideal window size @@ -197,7 +199,7 @@ namespace Widgets this->setMinimumSize(800, 600); this->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); - auto uiLoader = UiLoader(this); + auto uiLoader = UiLoader{this}; const auto styleSheet = stylesheetFile.readAll(); this->container = uiLoader.load(&windowUiFile, this); this->container->setStyleSheet(styleSheet); @@ -216,7 +218,7 @@ namespace Widgets "sub-container" )->findChild("sub-layout"); - this->leftPanel = new PanelWidget(PanelWidgetType::LEFT, this->leftPanelState, this); + this->leftPanel = new PanelWidget{PanelWidgetType::LEFT, this->leftPanelState, this}; this->leftPanel->setObjectName("left-panel"); this->leftPanel->setMinimumResize(200); this->leftPanel->setHandleSize(6); @@ -233,29 +235,33 @@ namespace Widgets auto snapshotAContainerLayout = this->dataAContainer->findChild(); auto snapshotBContainerLayout = this->dataBContainer->findChild(); - this->hexViewerWidgetA = new DifferentialHexViewerWidget( + this->hexViewerWidgetA = new DifferentialHexViewerWidget{ DifferentialHexViewerWidgetType::PRIMARY, this->differentialHexViewerSharedState, this->settings, - this->memoryDescriptor, + this->addressSpaceDescriptor, + this->memorySegmentDescriptor, + this->targetState, this->hexViewerDataA, this->hexViewerWidgetSettingsA, this->focusedRegionsA, this->excludedRegionsA, this - ); + }; - this->hexViewerWidgetB = new DifferentialHexViewerWidget( + this->hexViewerWidgetB = new DifferentialHexViewerWidget{ DifferentialHexViewerWidgetType::SECONDARY, this->differentialHexViewerSharedState, this->settings, - this->memoryDescriptor, + this->addressSpaceDescriptor, + this->memorySegmentDescriptor, + this->targetState, this->hexViewerDataB, this->hexViewerWidgetSettingsB, this->focusedRegionsB, this->excludedRegionsB, this - ); + }; this->hexViewerWidgetA->setObjectName("differential-hex-viewer-widget-a"); this->hexViewerWidgetB->setObjectName("differential-hex-viewer-widget-b"); @@ -266,17 +272,17 @@ namespace Widgets snapshotAContainerLayout->addWidget(this->hexViewerWidgetA); snapshotBContainerLayout->addWidget(this->hexViewerWidgetB); - this->changeListPane = new ChangeListPane( + this->changeListPane = new ChangeListPane{ this->hexViewerWidgetA, this->hexViewerWidgetB, this->changeListPaneState, this->leftPanel - ); + }; this->changeListPane->setRestoreEnabled( this->comparingWithCurrent - && this->memoryDescriptor.access.writeableDuringDebugSession - && this->targetState == Targets::TargetState::STOPPED + && this->memorySegmentDescriptor.debugModeAccess.writeable + && this->targetState.executionState == Targets::TargetExecutionState::STOPPED ); this->leftPanel->layout()->addWidget(this->changeListPane); @@ -286,15 +292,13 @@ namespace Widgets this->bottomBarLayout = this->bottomBar->findChild(); this->memoryCapacityLabel = this->bottomBar->findChild("memory-capacity-label"); - this->memoryTypeLabel = this->bottomBar->findChild("memory-type-label"); + this->memorySegmentNameLabel = this->bottomBar->findChild("memory-segment-name-label"); this->diffCountLabel = this->bottomBar->findChild("diff-count-label"); - this->memoryCapacityLabel->setText(QLocale(QLocale::English).toString(this->hexViewerDataA->size()) + " bytes"); - this->memoryTypeLabel->setText(EnumToStringMappings::targetMemoryTypes.at( - this->memoryDescriptor.type).toUpper() - ); + this->memoryCapacityLabel->setText(QLocale{QLocale::English}.toString(this->hexViewerDataA->size()) + " bytes"); + this->memorySegmentNameLabel->setText(QString::fromStdString(this->memorySegmentDescriptor.name)); - this->taskProgressIndicator = new TaskProgressIndicator(this); + this->taskProgressIndicator = new TaskProgressIndicator{this}; this->bottomBarLayout->insertWidget(7, this->taskProgressIndicator); this->setSyncHexViewerSettingsEnabled(this->settings.syncHexViewerSettings); @@ -345,10 +349,8 @@ namespace Widgets } ); - auto* insightSignals = InsightSignals::instance(); - QObject::connect( - insightSignals, + InsightSignals::instance(), &InsightSignals::targetStateUpdated, this, &SnapshotDiff::onTargetStateChanged @@ -372,7 +374,7 @@ namespace Widgets this->hexViewerWidgetA->addExternalContextMenuAction(this->restoreBytesAction); } - if (this->memoryDescriptor.type == Targets::TargetMemoryType::RAM) { + if (this->memorySegmentDescriptor.type == Targets::TargetMemorySegmentType::RAM) { this->hexViewerWidgetA->setStackPointer(this->stackPointerA); } } @@ -380,7 +382,7 @@ namespace Widgets void SnapshotDiff::onHexViewerBReady() { this->hexViewerWidgetA->setOther(this->hexViewerWidgetB); - if (this->memoryDescriptor.type == Targets::TargetMemoryType::RAM) { + if (this->memorySegmentDescriptor.type == Targets::TargetMemorySegmentType::RAM) { this->hexViewerWidgetB->setStackPointer(this->stackPointerB); } } @@ -392,7 +394,7 @@ namespace Widgets assert(this->hexViewerDataB.has_value()); this->differentialHexViewerSharedState.differences.clear(); - auto diffRanges = std::vector(); + auto diffRanges = std::vector{}; const auto& dataA = *(this->hexViewerDataA); const auto& dataB = *(this->hexViewerDataB); @@ -413,10 +415,10 @@ namespace Widgets return false; }; - const auto& memoryStartAddress = this->memoryDescriptor.addressRange.startAddress; - auto lastDiffRange = std::optional(); + const auto& memoryStartAddress = this->memorySegmentDescriptor.addressRange.startAddress; + auto lastDiffRange = std::optional{}; - for (Targets::TargetMemoryBuffer::size_type i = 0; i < dataA.size(); ++i) { + for (auto i = Targets::TargetMemoryBuffer::size_type{0}; i < dataA.size(); ++i) { const auto address = memoryStartAddress + static_cast(i); if (dataA[i] != dataB[i] && !isAddressExcluded(address)) { @@ -430,7 +432,7 @@ namespace Widgets diffRanges.push_back(*lastDiffRange); } - lastDiffRange = TargetMemoryAddressRange(address, address); + lastDiffRange = TargetMemoryAddressRange{address, address}; } } } @@ -445,7 +447,7 @@ namespace Widgets this->diffCountLabel->setText( diffCount == 0 ? "Contents are identical" - : QLocale(QLocale::English).toString(diffCount) + (diffCount == 1 ? " difference" : " differences") + : QLocale{QLocale::English}.toString(diffCount) + (diffCount == 1 ? " difference" : " differences") ); } @@ -484,7 +486,7 @@ namespace Widgets std::set addresses, bool confirmationPromptEnabled ) { - auto excludedAddresses = std::set(); + auto excludedAddresses = std::set{}; for (const auto& excludedRegion : this->excludedRegionsA) { const auto regionAddresses = excludedRegion.addressRange.addresses(); excludedAddresses.insert(regionAddresses.begin(), regionAddresses.end()); @@ -500,15 +502,15 @@ namespace Widgets } if (confirmationPromptEnabled) { - auto* confirmationDialog = new ConfirmationDialog( + auto* confirmationDialog = new ConfirmationDialog{ "Restore selected bytes", - "This operation will write " + QString::number(addresses.size()) + " byte(s) to the target's " - + EnumToStringMappings::targetMemoryTypes.at(this->memoryDescriptor.type).toUpper() - + ".

Are you sure you want to proceed?", + "This operation will write " + QString::number(addresses.size()) + " byte(s) to the target's \"" + + QString::fromStdString(this->memorySegmentDescriptor.name) + + "\" segment.

Are you sure you want to proceed?", "Proceed", std::nullopt, this - ); + }; QObject::connect( confirmationDialog, @@ -523,23 +525,23 @@ namespace Widgets return; } - auto writeBlocks = std::vector(); + auto writeBlocks = std::vector{}; - Targets::TargetMemoryAddress blockStartAddress = *(addresses.begin()); - Targets::TargetMemoryAddress blockEndAddress = blockStartAddress; + auto blockStartAddress = *(addresses.begin()); + auto blockEndAddress = blockStartAddress; for (const auto& address : addresses) { if (address > (blockEndAddress + 1)) { // Commit the block - const auto dataBeginOffset = blockStartAddress - this->memoryDescriptor.addressRange.startAddress; - const auto dataEndOffset = blockEndAddress - this->memoryDescriptor.addressRange.startAddress + 1; + const auto dataBeginOffset = blockStartAddress - this->memorySegmentDescriptor.addressRange.startAddress; + const auto dataEndOffset = blockEndAddress - this->memorySegmentDescriptor.addressRange.startAddress + 1; writeBlocks.emplace_back( blockStartAddress, - Targets::TargetMemoryBuffer( + Targets::TargetMemoryBuffer{ this->hexViewerDataA->begin() + dataBeginOffset, this->hexViewerDataA->begin() + dataEndOffset - ) + } ); blockStartAddress = address; @@ -551,15 +553,16 @@ namespace Widgets } { - const auto dataBeginOffset = blockStartAddress - this->memoryDescriptor.addressRange.startAddress; - const auto dataEndOffset = blockEndAddress - this->memoryDescriptor.addressRange.startAddress + 1; + // Last block + const auto dataBeginOffset = blockStartAddress - this->memorySegmentDescriptor.addressRange.startAddress; + const auto dataEndOffset = blockEndAddress - this->memorySegmentDescriptor.addressRange.startAddress + 1; writeBlocks.emplace_back( blockStartAddress, - Targets::TargetMemoryBuffer( + Targets::TargetMemoryBuffer{ this->hexViewerDataA->begin() + dataBeginOffset, this->hexViewerDataA->begin() + dataEndOffset - ) + } ); } @@ -571,7 +574,7 @@ namespace Widgets writeBlock.data.begin(), writeBlock.data.end(), hexViewerDataB.begin() - + (writeBlock.startAddress - this->memoryDescriptor.addressRange.startAddress) + + (writeBlock.startAddress - this->memorySegmentDescriptor.addressRange.startAddress) ); } @@ -580,10 +583,14 @@ namespace Widgets this->hexViewerWidgetB->updateValues(); }; - const auto writeMemoryTask = QSharedPointer( - new WriteTargetMemory(this->memoryDescriptor, std::move(writeBlocks)), + const auto writeMemoryTask = QSharedPointer{ + new WriteTargetMemory{ + this->addressSpaceDescriptor, + this->memorySegmentDescriptor, + std::move(writeBlocks) + }, &QObject::deleteLater - ); + }; QObject::connect(writeMemoryTask.get(), &WriteTargetMemory::targetMemoryWritten, this, after); @@ -591,13 +598,11 @@ namespace Widgets InsightWorker::queueTask(writeMemoryTask); } - void SnapshotDiff::onTargetStateChanged(Targets::TargetState newState) { - this->targetState = newState; - + void SnapshotDiff::onTargetStateChanged() { this->changeListPane->setRestoreEnabled( this->comparingWithCurrent - && this->memoryDescriptor.access.writeableDuringDebugSession - && this->targetState == Targets::TargetState::STOPPED + && this->memorySegmentDescriptor.debugModeAccess.writeable + && this->targetState.executionState == Targets::TargetExecutionState::STOPPED ); } } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/SnapshotDiff.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/SnapshotDiff.hpp index 59629b45..981ae9f7 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/SnapshotDiff.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/SnapshotDiff.hpp @@ -16,6 +16,9 @@ #include "src/Insight/UserInterfaces/InsightWindow/Widgets/TaskProgressIndicator/TaskProgressIndicator.hpp" #include "src/Targets/TargetMemory.hpp" +#include "src/Targets/TargetAddressSpaceDescriptor.hpp" +#include "src/Targets/TargetMemorySegmentDescriptor.hpp" +#include "src/Targets/TargetState.hpp" #include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemorySnapshot.hpp" #include "DifferentialHexViewerWidget/DifferentialHexViewerWidget.hpp" @@ -32,8 +35,9 @@ namespace Widgets SnapshotDiff( MemorySnapshot& snapshotA, MemorySnapshot& snapshotB, - const Targets::TargetMemoryDescriptor& memoryDescriptor, - Targets::TargetState currentTargetState, + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, + const Targets::TargetState& targetState, QWidget* parent = nullptr ); @@ -43,8 +47,9 @@ namespace Widgets std::vector focusedRegionsB, std::vector excludedRegionsB, Targets::TargetStackPointer stackPointerB, - const Targets::TargetMemoryDescriptor& memoryDescriptor, - Targets::TargetState currentTargetState, + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, + const Targets::TargetState& targetState, QWidget* parent = nullptr ); @@ -63,8 +68,9 @@ namespace Widgets private: SnapshotDiffSettings settings; - const Targets::TargetMemoryDescriptor& memoryDescriptor; - Targets::TargetState targetState = Targets::TargetState::UNKNOWN; + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor; + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor; + const Targets::TargetState& targetState; QWidget* container = nullptr; @@ -76,7 +82,7 @@ namespace Widgets QToolButton* viewChangeListButton = nullptr; PanelWidget* leftPanel = nullptr; - PanelState leftPanelState = PanelState(300, true); + PanelState leftPanelState = {300, true}; PaneState changeListPaneState = PaneState(true, true, std::nullopt); ChangeListPane* changeListPane = nullptr; @@ -113,7 +119,7 @@ namespace Widgets QWidget* bottomBar = nullptr; QHBoxLayout* bottomBarLayout = nullptr; Label* memoryCapacityLabel = nullptr; - Label* memoryTypeLabel = nullptr; + Label* memorySegmentNameLabel = nullptr; Label* diffCountLabel = nullptr; TaskProgressIndicator* taskProgressIndicator = nullptr; @@ -137,6 +143,6 @@ namespace Widgets bool confirmationPromptEnabled ); - void onTargetStateChanged(Targets::TargetState newState); + void onTargetStateChanged(); }; } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/Stylesheets/SnapshotDiff.qss b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/Stylesheets/SnapshotDiff.qss index f18263b1..6122abdd 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/Stylesheets/SnapshotDiff.qss +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/Stylesheets/SnapshotDiff.qss @@ -142,6 +142,7 @@ #snapshot-diff #memory-capacity-label, #snapshot-diff #memory-type-label, +#snapshot-diff #memory-segment-name-label, #snapshot-diff #diff-count-label { padding: 1px 5px; color: #8a8a8d; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/UiFiles/SnapshotDiff.ui b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/UiFiles/SnapshotDiff.ui index b2a933c5..1dbb6230 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/UiFiles/SnapshotDiff.ui +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotDiff/UiFiles/SnapshotDiff.ui @@ -454,7 +454,7 @@
- + diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotManager.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotManager.cpp index 4c6dcddb..55db3e51 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotManager.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotManager.cpp @@ -6,7 +6,6 @@ #include "src/Insight/UserInterfaces/InsightWindow/UiLoader.hpp" #include "src/Insight/UserInterfaces/InsightWindow/Widgets/ConfirmationDialog.hpp" -#include "src/Insight/InsightSignals.hpp" #include "src/Insight/InsightWorker/Tasks/RetrieveMemorySnapshots.hpp" #include "src/Insight/InsightWorker/Tasks/CaptureMemorySnapshot.hpp" #include "src/Insight/InsightWorker/Tasks/DeleteMemorySnapshot.hpp" @@ -23,7 +22,10 @@ namespace Widgets using Exceptions::Exception; SnapshotManager::SnapshotManager( - const Targets::TargetMemoryDescriptor& memoryDescriptor, + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, + const Targets::TargetDescriptor& targetDescriptor, + const Targets::TargetState& targetState, const std::optional& data, const bool& staleData, const std::vector& focusedMemoryRegions, @@ -33,7 +35,10 @@ namespace Widgets PanelWidget* parent ) : PaneWidget(state, parent) - , memoryDescriptor(memoryDescriptor) + , addressSpaceDescriptor(addressSpaceDescriptor) + , memorySegmentDescriptor(memorySegmentDescriptor) + , targetDescriptor(targetDescriptor) + , targetState(targetState) , data(data) , staleData(staleData) , focusedMemoryRegions(focusedMemoryRegions) @@ -43,18 +48,18 @@ namespace Widgets this->setObjectName("snapshot-manager"); this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); - auto widgetUiFile = QFile( + auto widgetUiFile = QFile{ QString::fromStdString(Services::PathService::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane" - + "/SnapshotManager/UiFiles/SnapshotManager.ui" + + "/SnapshotManager/UiFiles/SnapshotManager.ui" ) - ); + }; if (!widgetUiFile.open(QFile::ReadOnly)) { - throw Exception("Failed to open SnapshotManager UI file"); + throw Exception{"Failed to open SnapshotManager UI file"}; } - auto uiLoader = UiLoader(this); + auto uiLoader = UiLoader{this}; this->container = uiLoader.load(&widgetUiFile, this); this->container->setFixedSize(this->size()); @@ -66,7 +71,7 @@ namespace Widgets auto* containerLayout = this->container->findChild(); - this->snapshotListView = new ListView({}, this); + this->snapshotListView = new ListView{{}, this}; this->snapshotListView->viewport()->installEventFilter(parent); this->snapshotListView->setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAsNeeded); @@ -75,12 +80,14 @@ namespace Widgets containerLayout->addWidget(this->snapshotListView); - this->createSnapshotWindow = new CreateSnapshotWindow( - this->memoryDescriptor.type, + this->createSnapshotWindow = new CreateSnapshotWindow{ + this->addressSpaceDescriptor, + this->memorySegmentDescriptor, + this->targetState, this->data, this->staleData, this - ); + }; QObject::connect( this->createSnapshotWindow, @@ -200,19 +207,14 @@ namespace Widgets } ); - auto* insightSignals = InsightSignals::instance(); - - QObject::connect( - insightSignals, - &InsightSignals::targetStateUpdated, - this, - &SnapshotManager::onTargetStateChanged - ); - - const auto retrieveSnapshotsTask = QSharedPointer( - new RetrieveMemorySnapshots(this->memoryDescriptor.type), + const auto retrieveSnapshotsTask = QSharedPointer{ + new RetrieveMemorySnapshots{ + this->addressSpaceDescriptor, + this->memorySegmentDescriptor, + this->targetDescriptor + }, &QObject::deleteLater - ); + }; QObject::connect( retrieveSnapshotsTask.get(), @@ -220,7 +222,7 @@ namespace Widgets this, [this] (std::vector snapshots) { for (auto& snapshot : snapshots) { - if (!snapshot.isCompatible(this->memoryDescriptor)) { + if (!snapshot.isCompatible(this->memorySegmentDescriptor)) { Logger::warning( "Ignoring snapshot " + snapshot.id.toStdString() + " - snapshot incompatible with current memory descriptor" @@ -275,17 +277,18 @@ namespace Widgets bool captureFocusedRegions, bool captureDirectlyFromTarget ) { - const auto captureTask = QSharedPointer( - new CaptureMemorySnapshot( + const auto captureTask = QSharedPointer{ + new CaptureMemorySnapshot{ std::move(name), std::move(description), - this->memoryDescriptor.type, + this->addressSpaceDescriptor, + this->memorySegmentDescriptor, captureFocusedRegions ? this->focusedMemoryRegions : std::vector(), this->excludedMemoryRegions, captureDirectlyFromTarget ? std::nullopt : this->data - ), + }, &QObject::deleteLater - ); + }; QObject::connect( captureTask.get(), @@ -298,7 +301,6 @@ namespace Widgets ); emit this->insightWorkerTaskCreated(captureTask); - InsightWorker::queueTask(captureTask); } @@ -306,7 +308,7 @@ namespace Widgets const auto snapshotIt = this->snapshotsById.insert(snapshotTmp.id, std::move(snapshotTmp)); const auto& snapshot = *snapshotIt; - const auto snapshotItemIt = this->snapshotItemsById.insert(snapshot.id, new MemorySnapshotItem(snapshot)); + const auto snapshotItemIt = this->snapshotItemsById.insert(snapshot.id, new MemorySnapshotItem{snapshot}); auto& snapshotItem = *snapshotItemIt; this->snapshotListScene->addListItem(snapshotItem); @@ -337,7 +339,13 @@ namespace Widgets snapshotViewerIt = this->snapshotViewersById.insert( snapshotId, - new SnapshotViewer(snapshotIt.value(), this->memoryDescriptor, this) + new SnapshotViewer{ + snapshotIt.value(), + this->addressSpaceDescriptor, + this->memorySegmentDescriptor, + this->targetState, + this + } ); } @@ -360,13 +368,14 @@ namespace Widgets snapshotDiffIt = this->snapshotDiffs.insert( diffKey, - new SnapshotDiff( + new SnapshotDiff{ snapshotItA.value(), snapshotItB.value(), - this->memoryDescriptor, + this->addressSpaceDescriptor, + this->memorySegmentDescriptor, this->targetState, this - ) + } ); } @@ -405,16 +414,17 @@ namespace Widgets snapshotDiffIt = this->snapshotCurrentDiffsBySnapshotAId.insert( snapshotIdA, - new SnapshotDiff( + new SnapshotDiff{ snapshotItA.value(), *(this->data), this->focusedMemoryRegions, this->excludedMemoryRegions, this->stackPointer.value_or(0), - this->memoryDescriptor, + this->addressSpaceDescriptor, + this->memorySegmentDescriptor, this->targetState, this - ) + } ); auto* snapshotDiff = snapshotDiffIt.value(); @@ -432,13 +442,13 @@ namespace Widgets const auto& snapshot = snapshotIt.value(); if (confirmationPromptEnabled) { - auto* confirmationDialog = new ConfirmationDialog( + auto* confirmationDialog = new ConfirmationDialog{ "Delete snapshot " + snapshot.id, "This operation will permanently delete the selected snapshot.

Are you sure you want to proceed?", "Proceed", std::nullopt, this - ); + }; QObject::connect( confirmationDialog, @@ -453,10 +463,10 @@ namespace Widgets return; } - const auto deleteSnapshotTask = QSharedPointer( - new DeleteMemorySnapshot(snapshot.id, snapshot.memoryType), + const auto deleteSnapshotTask = QSharedPointer{ + new DeleteMemorySnapshot{snapshot.id}, &QObject::deleteLater - ); + }; QObject::connect( deleteSnapshotTask.get(), @@ -508,15 +518,15 @@ namespace Widgets const auto& snapshot = snapshotIt.value(); if (confirmationPromptEnabled) { - auto* confirmationDialog = new ConfirmationDialog( + auto* confirmationDialog = new ConfirmationDialog{ "Restore snapshot", - "This operation will overwrite the entire address range of the target's " - + EnumToStringMappings::targetMemoryTypes.at(this->memoryDescriptor.type).toUpper() - + " with the contents of the selected snapshot.

Are you sure you want to proceed?", + "This operation will overwrite the entire address range of the target's \"" + + QString::fromStdString(this->memorySegmentDescriptor.name) + + "\" segment, with the contents of the selected snapshot.

Are you sure you want to proceed?", "Proceed", std::nullopt, this - ); + }; QObject::connect( confirmationDialog, @@ -535,52 +545,58 @@ namespace Widgets * We don't restore any excluded regions from the snapshot, so we split the write operation into blocks of * contiguous data, leaving out any address range that is part of an excluded region. */ - auto writeBlocks = std::vector(); + auto writeBlocks = std::vector{}; - auto sortedExcludedRegions = std::map(); + auto sortedExcludedRegions = std::map{}; std::transform( snapshot.excludedRegions.begin(), snapshot.excludedRegions.end(), std::inserter(sortedExcludedRegions, sortedExcludedRegions.end()), [] (const ExcludedMemoryRegion& excludedMemoryRegion) { - return std::pair(excludedMemoryRegion.addressRange.startAddress, &excludedMemoryRegion); + return std::pair{excludedMemoryRegion.addressRange.startAddress, &excludedMemoryRegion}; } ); - auto blockStartAddress = this->memoryDescriptor.addressRange.startAddress; + auto blockStartAddress = this->memorySegmentDescriptor.addressRange.startAddress; for (const auto& [excludedRegionStartAddress, excludedRegion] : sortedExcludedRegions) { - assert(excludedRegionStartAddress >= this->memoryDescriptor.addressRange.startAddress); - assert(excludedRegion->addressRange.endAddress <= this->memoryDescriptor.addressRange.endAddress); + assert(excludedRegionStartAddress >= this->memorySegmentDescriptor.addressRange.startAddress); + assert(excludedRegion->addressRange.endAddress <= this->memorySegmentDescriptor.addressRange.endAddress); - const auto dataBeginOffset = blockStartAddress - this->memoryDescriptor.addressRange.startAddress; - const auto dataEndOffset = excludedRegionStartAddress - this->memoryDescriptor.addressRange.startAddress; + const auto dataBeginOffset = blockStartAddress - this->memorySegmentDescriptor.addressRange.startAddress; + const auto dataEndOffset = excludedRegionStartAddress + - this->memorySegmentDescriptor.addressRange.startAddress; writeBlocks.emplace_back( blockStartAddress, - Targets::TargetMemoryBuffer( + Targets::TargetMemoryBuffer{ snapshot.data.begin() + dataBeginOffset, snapshot.data.begin() + dataEndOffset - ) + } ); blockStartAddress = excludedRegion->addressRange.endAddress + 1; } - if (blockStartAddress < this->memoryDescriptor.addressRange.endAddress) { + if (blockStartAddress < this->memorySegmentDescriptor.addressRange.endAddress) { writeBlocks.emplace_back( blockStartAddress, - Targets::TargetMemoryBuffer( - snapshot.data.begin() + (blockStartAddress - this->memoryDescriptor.addressRange.startAddress), + Targets::TargetMemoryBuffer{ + snapshot.data.begin() + + (blockStartAddress - this->memorySegmentDescriptor.addressRange.startAddress), snapshot.data.end() - ) + } ); } - const auto writeMemoryTask = QSharedPointer( - new WriteTargetMemory(this->memoryDescriptor, std::move(writeBlocks)), + const auto writeMemoryTask = QSharedPointer{ + new WriteTargetMemory{ + this->addressSpaceDescriptor, + this->memorySegmentDescriptor, + std::move(writeBlocks) + }, &QObject::deleteLater - ); + }; QObject::connect( writeMemoryTask.get(), @@ -606,7 +622,7 @@ namespace Widgets return; } - auto* menu = new QMenu(this); + auto* menu = new QMenu{this}; menu->addAction(this->openSnapshotViewerAction); menu->addAction(this->deleteSnapshotAction); @@ -627,15 +643,11 @@ namespace Widgets && this->data.has_value() ); this->restoreSnapshotAction->setEnabled( - this->memoryDescriptor.access.writeableDuringDebugSession + this->memorySegmentDescriptor.debugModeAccess.writeable && this->selectedSnapshotItems.size() == 1 - && this->targetState == Targets::TargetState::STOPPED + && this->targetState.executionState == Targets::TargetExecutionState::STOPPED ); menu->exec(sourcePosition); } - - void SnapshotManager::onTargetStateChanged(Targets::TargetState newState) { - this->targetState = newState; - } } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotManager.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotManager.hpp index 27d9d194..e13feaf5 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotManager.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotManager.hpp @@ -12,8 +12,12 @@ #include "src/Insight/UserInterfaces/InsightWindow/Widgets/SvgToolButton.hpp" #include "src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListView.hpp" -#include "src/Targets/TargetState.hpp" #include "src/Targets/TargetMemory.hpp" +#include "src/Targets/TargetAddressSpaceDescriptor.hpp" +#include "src/Targets/TargetMemorySegmentDescriptor.hpp" +#include "src/Targets/TargetState.hpp" +#include "src/Targets/TargetDescriptor.hpp" + #include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemorySnapshot.hpp" #include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/FocusedMemoryRegion.hpp" #include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/ExcludedMemoryRegion.hpp" @@ -35,7 +39,10 @@ namespace Widgets CreateSnapshotWindow* createSnapshotWindow = nullptr; explicit SnapshotManager( - const Targets::TargetMemoryDescriptor& memoryDescriptor, + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, + const Targets::TargetDescriptor& targetDescriptor, + const Targets::TargetState& targetState, const std::optional& data, const bool& staleData, const std::vector& focusedMemoryRegions, @@ -56,7 +63,11 @@ namespace Widgets void showEvent(QShowEvent* event) override; private: - const Targets::TargetMemoryDescriptor& memoryDescriptor; + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor; + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor; + const Targets::TargetDescriptor& targetDescriptor; + const Targets::TargetState& targetState; + const std::optional& data; const bool& staleData; @@ -64,8 +75,6 @@ namespace Widgets const std::vector& excludedMemoryRegions; const std::optional& stackPointer; - Targets::TargetState targetState = Targets::TargetState::UNKNOWN; - QMap snapshotsById; QMap snapshotItemsById; QMap snapshotViewersById; @@ -83,11 +92,11 @@ namespace Widgets std::list selectedSnapshotItems; - QAction* openSnapshotViewerAction = new QAction("Open", this); - QAction* openSnapshotDiffAction = new QAction("Compare Selection", this); - QAction* openSnapshotCurrentDiffAction = new QAction("Compare with Current", this); - QAction* deleteSnapshotAction = new QAction("Delete", this); - QAction* restoreSnapshotAction = new QAction("Restore", this); + QAction* openSnapshotViewerAction = new QAction{"Open", this}; + QAction* openSnapshotDiffAction = new QAction{"Compare Selection", this}; + QAction* openSnapshotCurrentDiffAction = new QAction{"Compare with Current", this}; + QAction* deleteSnapshotAction = new QAction{"Delete", this}; + QAction* restoreSnapshotAction = new QAction{"Restore", this}; void createSnapshot( const QString& name, @@ -105,6 +114,5 @@ namespace Widgets void restoreSnapshot(const QString& snapshotId, bool confirmationPromptEnabled); void onSnapshotItemDoubleClick(MemorySnapshotItem* item); void onSnapshotItemContextMenu(ListItem* item, QPoint sourcePosition); - void onTargetStateChanged(Targets::TargetState newState); }; } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotViewer/MemoryRegionItem.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotViewer/MemoryRegionItem.cpp index 58f68ccf..63a1a65d 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotViewer/MemoryRegionItem.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotViewer/MemoryRegionItem.cpp @@ -7,11 +7,11 @@ namespace Widgets MemoryRegionItem::MemoryRegionItem(const MemoryRegion& memoryRegion) : memoryRegion(memoryRegion) { - this->size = QSize(0, MemoryRegionItem::HEIGHT); + this->size = QSize{0, MemoryRegionItem::HEIGHT}; this->nameText = memoryRegion.name; this->addressRangeText = "0x" + QString::number(this->memoryRegion.addressRange.startAddress, 16).toUpper() - + QString(" -> ") + "0x" + QString::number(this->memoryRegion.addressRange.endAddress, 16).toUpper(); + + QString{" -> "} + "0x" + QString::number(this->memoryRegion.addressRange.endAddress, 16).toUpper(); this->regionTypeText = this->memoryRegion.type == MemoryRegionType::EXCLUDED ? "Excluded" : "Focused"; this->createdDateText = memoryRegion.createdDate.toString( memoryRegion.createdDate.date() == Services::DateTimeService::currentDate() @@ -23,16 +23,16 @@ namespace Widgets } void MemoryRegionItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { - static constexpr auto margins = QMargins(10, 5, 10, 0); + static constexpr auto margins = QMargins{10, 5, 10, 0}; painter->setOpacity(0.7); - static auto font = QFont("'Ubuntu', sans-serif"); + static auto font = QFont{"'Ubuntu', sans-serif"}; font.setPixelSize(14); - static auto secondaryFont = QFont("'Ubuntu', sans-serif"); + static auto secondaryFont = QFont{"'Ubuntu', sans-serif"}; secondaryFont.setPixelSize(13); - static constexpr auto fontColor = QColor(0xAF, 0xB1, 0xB3); - static constexpr auto secondaryFontColor = QColor(0x8A, 0x8A, 0x8D); + static constexpr auto fontColor = QColor{0xAF, 0xB1, 0xB3}; + static constexpr auto secondaryFontColor = QColor{0x8A, 0x8A, 0x8D}; painter->setFont(font); painter->setPen(fontColor); @@ -54,46 +54,46 @@ namespace Widgets ); const auto nameTextSize = fontMetrics.size(Qt::TextSingleLine, nameText); - const auto nameTextRect = QRect( + const auto nameTextRect = QRect{ margins.left(), margins.top(), nameTextSize.width(), nameTextSize.height() - ); + }; painter->drawText(nameTextRect, Qt::AlignLeft, nameText); painter->setFont(secondaryFont); painter->setPen(secondaryFontColor); - const auto addressRangeTextRect = QRect( + const auto addressRangeTextRect = QRect{ margins.left(), nameTextRect.bottom() + 5, addressRangeTextSize.width(), addressRangeTextSize.height() - ); + }; painter->drawText(addressRangeTextRect, Qt::AlignLeft, this->addressRangeText); - const auto regionTypeTextRect = QRect( + const auto regionTypeTextRect = QRect{ this->size.width() - margins.right() - regionTypeTextSize.width(), margins.top(), regionTypeTextSize.width(), regionTypeTextSize.height() - ); + }; painter->drawText(regionTypeTextRect, Qt::AlignRight, this->regionTypeText); - const auto createdDateTextRect = QRect( + const auto createdDateTextRect = QRect{ this->size.width() - margins.right() - createdDateTextSize.width(), nameTextRect.bottom() + 5, createdDateTextSize.width(), createdDateTextSize.height() - ); + }; painter->drawText(createdDateTextRect, Qt::AlignRight, this->createdDateText); - static constexpr auto borderColor = QColor(0x41, 0x42, 0x3F); + static constexpr auto borderColor = QColor{0x41, 0x42, 0x3F}; painter->setPen(borderColor); painter->drawLine(0, this->size.height() - 1, this->size.width(), this->size.height() - 1); } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotViewer/MemoryRegionItem.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotViewer/MemoryRegionItem.hpp index 4646c2fb..cf819c34 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotViewer/MemoryRegionItem.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotViewer/MemoryRegionItem.hpp @@ -17,8 +17,7 @@ namespace Widgets MemoryRegionItem(const MemoryRegion& memoryRegion); bool operator < (const ListItem& rhs) const override { - const auto& rhsRegionItem = dynamic_cast(rhs); - return this->memoryRegion.createdDate < rhsRegionItem.memoryRegion.createdDate; + return this->memoryRegion.createdDate < dynamic_cast(rhs).memoryRegion.createdDate; } void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotViewer/SnapshotViewer.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotViewer/SnapshotViewer.cpp index e7840fbf..1253c696 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotViewer/SnapshotViewer.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotViewer/SnapshotViewer.cpp @@ -29,38 +29,41 @@ namespace Widgets SnapshotViewer::SnapshotViewer( MemorySnapshot& snapshot, - const Targets::TargetMemoryDescriptor& memoryDescriptor, + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, + const Targets::TargetState& targetState, QWidget* parent ) : QWidget(parent) , snapshot(snapshot) - , memoryDescriptor(memoryDescriptor) + , addressSpaceDescriptor(addressSpaceDescriptor) + , memorySegmentDescriptor(memorySegmentDescriptor) , hexViewerData(snapshot.data) { this->setWindowFlag(Qt::Window); this->setObjectName("snapshot-viewer"); this->setWindowTitle(this->snapshot.name + " (" + this->snapshot.id + ")"); - auto windowUiFile = QFile( + auto windowUiFile = QFile{ QString::fromStdString(Services::PathService::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane" + "/SnapshotManager/SnapshotViewer/UiFiles/SnapshotViewer.ui" ) - ); + }; - auto stylesheetFile = QFile( + auto stylesheetFile = QFile{ QString::fromStdString(Services::PathService::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane" + "/SnapshotManager/SnapshotViewer/Stylesheets/SnapshotViewer.qss" ) - ); + }; if (!windowUiFile.open(QFile::ReadOnly)) { - throw Exception("Failed to open SnapshotViewer UI file"); + throw Exception{"Failed to open SnapshotViewer UI file"}; } if (!stylesheetFile.open(QFile::ReadOnly)) { - throw Exception("Failed to open SnapshotViewer stylesheet file"); + throw Exception{"Failed to open SnapshotViewer stylesheet file"}; } // Set ideal window size @@ -68,7 +71,7 @@ namespace Widgets this->setMinimumSize(700, 600); this->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); - auto uiLoader = UiLoader(this); + auto uiLoader = UiLoader{this}; this->setStyleSheet(stylesheetFile.readAll()); this->container = uiLoader.load(&windowUiFile, this); @@ -97,7 +100,7 @@ namespace Widgets this->snapshot.focusedRegions.end(), std::back_inserter(this->memoryRegionItems), [] (const MemoryRegion& focusedRegion) { - return new MemoryRegionItem(focusedRegion); + return new MemoryRegionItem{focusedRegion}; } ); @@ -106,40 +109,42 @@ namespace Widgets this->snapshot.excludedRegions.end(), std::back_inserter(this->memoryRegionItems), [] (const MemoryRegion& excludedRegion) { - return new MemoryRegionItem(excludedRegion); + return new MemoryRegionItem{excludedRegion}; } ); - this->memoryRegionListView = new ListView( - ListScene::ListItemSetType(this->memoryRegionItems.begin(), this->memoryRegionItems.end()), + this->memoryRegionListView = new ListView{ + ListItem::ListItemSetType{this->memoryRegionItems.begin(), this->memoryRegionItems.end()}, this - ); + }; this->memoryRegionListView->setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAsNeeded); this->memoryRegionListScene = this->memoryRegionListView->listScene(); - this->memoryRegionListScene->margins = QMargins(0, 5, 0, 5); + this->memoryRegionListScene->margins = QMargins{0, 5, 0, 5}; this->memoryRegionListScene->setSelectionLimit(2); noMemoryRegionsLabel->hide(); memoryRegionsLayout->insertWidget(0, this->memoryRegionListView); } - this->restoreBytesAction = new ContextMenuAction( + this->restoreBytesAction = new ContextMenuAction{ "Restore Selection", [this] (const std::set&) { - return this->memoryDescriptor.access.writeableDuringDebugSession; + return this->memorySegmentDescriptor.debugModeAccess.writeable; }, this - ); + }; - this->hexViewerWidget = new HexViewerWidget( - this->memoryDescriptor, + this->hexViewerWidget = new HexViewerWidget{ + this->addressSpaceDescriptor, + this->memorySegmentDescriptor, + targetState, this->hexViewerData, this->hexViewerWidgetSettings, this->snapshot.focusedRegions, this->snapshot.excludedRegions, this - ); + }; containerLayout->insertWidget(1, this->hexViewerWidget); @@ -151,7 +156,9 @@ namespace Widgets auto* programCounterLabel = this->bottomBar->findChild("program-counter-label"); auto* dateLabel = this->bottomBar->findChild("date-label"); - memoryCapacityLabel->setText(QLocale(QLocale::English).toString(this->memoryDescriptor.size()) + " bytes"); + memoryCapacityLabel->setText( + QLocale{QLocale::English}.toString(this->memorySegmentDescriptor.size()) + " bytes" + ); snapshotIdLabel->setText(this->snapshot.id); programCounterLabel->setText( "0x" + QString::number(this->snapshot.programCounter, 16).rightJustified(8, '0').toUpper() @@ -161,11 +168,9 @@ namespace Widgets this->nameInput->setText(this->snapshot.name); this->descriptionInput->setPlainText(this->snapshot.description); - this->taskProgressIndicator = new TaskProgressIndicator(this); + this->taskProgressIndicator = new TaskProgressIndicator{this}; this->bottomBarLayout->insertWidget(2, this->taskProgressIndicator); - auto* insightSignals = InsightSignals::instance(); - QObject::connect( this->restoreBytesAction, &ContextMenuAction::invoked, @@ -187,7 +192,6 @@ namespace Widgets void SnapshotViewer::resizeEvent(QResizeEvent* event) { this->container->setFixedSize(this->size()); - QWidget::resizeEvent(event); } @@ -211,15 +215,15 @@ namespace Widgets } if (confirmationPromptEnabled) { - auto* confirmationDialog = new ConfirmationDialog( + auto* confirmationDialog = new ConfirmationDialog{ "Restore selected bytes", - "This operation will write " + QString::number(addresses.size()) + " byte(s) to the target's " - + EnumToStringMappings::targetMemoryTypes.at(this->memoryDescriptor.type).toUpper() - + ".

Are you sure you want to proceed?", + "This operation will write " + QString::number(addresses.size()) + " byte(s) to the target's \"" + + QString::fromStdString(this->memorySegmentDescriptor.name) + + "\" segment.

Are you sure you want to proceed?", "Proceed", std::nullopt, this - ); + }; QObject::connect( confirmationDialog, @@ -234,23 +238,23 @@ namespace Widgets return; } - auto writeBlocks = std::vector(); + auto writeBlocks = std::vector{}; - Targets::TargetMemoryAddress blockStartAddress = *(addresses.begin()); - Targets::TargetMemoryAddress blockEndAddress = blockStartAddress; + auto blockStartAddress = *(addresses.begin()); + auto blockEndAddress = blockStartAddress; for (const auto& address : addresses) { if (address > (blockEndAddress + 1)) { // Commit the block - const auto dataBeginOffset = blockStartAddress - this->memoryDescriptor.addressRange.startAddress; - const auto dataEndOffset = blockEndAddress - this->memoryDescriptor.addressRange.startAddress + 1; + const auto dataBeginOffset = blockStartAddress - this->memorySegmentDescriptor.addressRange.startAddress; + const auto dataEndOffset = blockEndAddress - this->memorySegmentDescriptor.addressRange.startAddress + 1; writeBlocks.emplace_back( blockStartAddress, - Targets::TargetMemoryBuffer( + Targets::TargetMemoryBuffer{ this->snapshot.data.begin() + dataBeginOffset, this->snapshot.data.begin() + dataEndOffset - ) + } ); blockStartAddress = address; @@ -262,22 +266,22 @@ namespace Widgets } { - const auto dataBeginOffset = blockStartAddress - this->memoryDescriptor.addressRange.startAddress; - const auto dataEndOffset = blockEndAddress - this->memoryDescriptor.addressRange.startAddress + 1; + const auto dataBeginOffset = blockStartAddress - this->memorySegmentDescriptor.addressRange.startAddress; + const auto dataEndOffset = blockEndAddress - this->memorySegmentDescriptor.addressRange.startAddress + 1; writeBlocks.emplace_back( blockStartAddress, - Targets::TargetMemoryBuffer( + Targets::TargetMemoryBuffer{ this->snapshot.data.begin() + dataBeginOffset, this->snapshot.data.begin() + dataEndOffset - ) + } ); } - const auto writeMemoryTask = QSharedPointer( - new WriteTargetMemory(this->memoryDescriptor, std::move(writeBlocks)), + const auto writeMemoryTask = QSharedPointer{ + new WriteTargetMemory{this->addressSpaceDescriptor, this->memorySegmentDescriptor, std::move(writeBlocks)}, &QObject::deleteLater - ); + }; this->taskProgressIndicator->addTask(writeMemoryTask); InsightWorker::queueTask(writeMemoryTask); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotViewer/SnapshotViewer.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotViewer/SnapshotViewer.hpp index 6e743e1e..fd7be548 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotViewer/SnapshotViewer.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/SnapshotManager/SnapshotViewer/SnapshotViewer.hpp @@ -13,6 +13,9 @@ #include "src/Insight/UserInterfaces/InsightWindow/Widgets/TaskProgressIndicator/TaskProgressIndicator.hpp" #include "src/Targets/TargetMemory.hpp" +#include "src/Targets/TargetAddressSpaceDescriptor.hpp" +#include "src/Targets/TargetMemorySegmentDescriptor.hpp" +#include "src/Targets/TargetState.hpp" #include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemorySnapshot.hpp" #include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerWidget.hpp" @@ -28,7 +31,9 @@ namespace Widgets public: SnapshotViewer( MemorySnapshot& snapshot, - const Targets::TargetMemoryDescriptor& memoryDescriptor, + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, + const Targets::TargetState& targetState, QWidget* parent = nullptr ); @@ -38,7 +43,8 @@ namespace Widgets private: MemorySnapshot& snapshot; - const Targets::TargetMemoryDescriptor& memoryDescriptor; + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor; + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor; QWidget* container = nullptr; @@ -52,7 +58,7 @@ namespace Widgets std::optional hexViewerData; HexViewerWidget* hexViewerWidget = nullptr; - HexViewerWidgetSettings hexViewerWidgetSettings = HexViewerWidgetSettings(); + HexViewerWidgetSettings hexViewerWidgetSettings = {}; ContextMenuAction* restoreBytesAction = nullptr; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp index af22ac77..4a802e58 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp @@ -20,50 +20,52 @@ namespace Widgets { using namespace Exceptions; - using Targets::TargetMemoryDescriptor; - using Targets::TargetMemoryType; using Targets::TargetMemoryAddressRange; TargetMemoryInspectionPane::TargetMemoryInspectionPane( - const TargetMemoryDescriptor& targetMemoryDescriptor, + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, + const Targets::TargetDescriptor& targetDescriptor, + const Targets::TargetState& targetState, TargetMemoryInspectionPaneSettings& settings, PaneState& paneState, PanelWidget* parent ) : PaneWidget(paneState, parent) - , targetMemoryDescriptor(targetMemoryDescriptor) + , addressSpaceDescriptor(addressSpaceDescriptor) + , memorySegmentDescriptor(memorySegmentDescriptor) + , targetDescriptor(targetDescriptor) + , targetState(targetState) , settings(settings) { this->setObjectName("target-memory-inspection-pane"); - const auto memoryName = "Internal " + EnumToStringMappings::targetMemoryTypes.at( - this->targetMemoryDescriptor.type - ).toUpper(); + const auto memoryName = QString::fromStdString(this->memorySegmentDescriptor.name); this->setWindowTitle("Memory Inspection - " + memoryName); this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); - auto uiFile = QFile( + auto uiFile = QFile{ QString::fromStdString(Services::PathService::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/UiFiles/TargetMemoryInspectionPane.ui" ) - ); + }; - auto stylesheetFile = QFile( + auto stylesheetFile = QFile{ QString::fromStdString(Services::PathService::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/Stylesheets/TargetMemoryInspectionPane.qss" ) - ); + }; if (!uiFile.open(QFile::ReadOnly)) { - throw Exception("Failed to open MemoryInspectionPane UI file"); + throw Exception{"Failed to open MemoryInspectionPane UI file"}; } if (!stylesheetFile.open(QFile::ReadOnly)) { - throw Exception("Failed to open MemoryInspectionPane stylesheet file"); + throw Exception{"Failed to open MemoryInspectionPane stylesheet file"}; } - auto uiLoader = UiLoader(this); + auto uiLoader = UiLoader{this}; this->container = uiLoader.load(&uiFile, this); this->container->setStyleSheet(stylesheetFile.readAll()); this->container->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); @@ -94,35 +96,42 @@ namespace Widgets titleLabel->setText(memoryName); auto* memoryCapacityLabel = this->container->findChild("memory-capacity-label"); - memoryCapacityLabel->setText(QLocale(QLocale::English).toString(this->targetMemoryDescriptor.size()) + " bytes"); + memoryCapacityLabel->setText( + QLocale{QLocale::English}.toString(this->memorySegmentDescriptor.size()) + " bytes" + ); // Quick sanity check to ensure the validity of persisted settings. this->sanitiseSettings(); this->refreshButton->setDisabled(true); - this->hexViewerWidget = new HexViewerWidget( - this->targetMemoryDescriptor, + this->hexViewerWidget = new HexViewerWidget{ + this->addressSpaceDescriptor, + this->memorySegmentDescriptor, + this->targetState, this->data, this->settings.hexViewerWidgetSettings, this->settings.focusedMemoryRegions, this->settings.excludedMemoryRegions, this - ); + }; this->hexViewerWidget->setDisabled(true); this->subContainerLayout->insertWidget(1, this->hexViewerWidget); this->hexViewerWidget->init(); - this->rightPanel = new PanelWidget(PanelWidgetType::RIGHT, this->settings.rightPanelState, this); + this->rightPanel = new PanelWidget{PanelWidgetType::RIGHT, this->settings.rightPanelState, this}; this->rightPanel->setObjectName("right-panel"); this->rightPanel->setMinimumResize(200); this->rightPanel->setHandleSize(6); this->subContainerLayout->insertWidget(2, this->rightPanel); - this->snapshotManager = new SnapshotManager( - this->targetMemoryDescriptor, + this->snapshotManager = new SnapshotManager{ + this->addressSpaceDescriptor, + this->memorySegmentDescriptor, + this->targetDescriptor, + this->targetState, this->data, this->staleData, this->settings.focusedMemoryRegions, @@ -130,13 +139,13 @@ namespace Widgets this->stackPointer, this->settings.snapshotManagerState, this->rightPanel - ); + }; this->rightPanel->layout()->addWidget(this->snapshotManager); this->setRefreshOnTargetStopEnabled(this->settings.refreshOnTargetStop); this->setRefreshOnActivationEnabled(this->settings.refreshOnActivation); - this->taskProgressIndicator = new TaskProgressIndicator(this); + this->taskProgressIndicator = new TaskProgressIndicator{this}; this->bottomBarLayout->insertWidget(5, this->taskProgressIndicator); QObject::connect( @@ -313,7 +322,7 @@ namespace Widgets this->refreshButton->setDisabled(true); this->refreshButton->startSpin(); - auto excludedAddressRanges = std::set(); + auto excludedAddressRanges = std::set{}; std::transform( this->settings.excludedMemoryRegions.begin(), this->settings.excludedMemoryRegions.end(), @@ -323,15 +332,16 @@ namespace Widgets } ); - const auto readMemoryTask = QSharedPointer( - new ReadTargetMemory( - this->targetMemoryDescriptor.type, - this->targetMemoryDescriptor.addressRange.startAddress, - this->targetMemoryDescriptor.size(), + const auto readMemoryTask = QSharedPointer{ + new ReadTargetMemory{ + this->addressSpaceDescriptor, + this->memorySegmentDescriptor, + this->memorySegmentDescriptor.addressRange.startAddress, + this->memorySegmentDescriptor.size(), excludedAddressRanges - ), + }, &QObject::deleteLater - ); + }; QObject::connect( readMemoryTask.get(), @@ -341,11 +351,11 @@ namespace Widgets this->onMemoryRead(data); // Refresh the stack pointer if this is RAM. - if (this->targetMemoryDescriptor.type == Targets::TargetMemoryType::RAM) { - const auto readStackPointerTask = QSharedPointer( - new ReadStackPointer(), + if (this->memorySegmentDescriptor.type == Targets::TargetMemorySegmentType::RAM) { + const auto readStackPointerTask = QSharedPointer{ + new ReadStackPointer{}, &QObject::deleteLater - ); + }; QObject::connect( readStackPointerTask.get(), @@ -366,7 +376,7 @@ namespace Widgets this->refreshButton->stopSpin(); - if (this->targetState == Targets::TargetState::STOPPED) { + if (this->targetState.executionState == Targets::TargetExecutionState::STOPPED) { this->refreshButton->setDisabled(false); } } @@ -402,7 +412,7 @@ namespace 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) { + if (this->memorySegmentDescriptor.type != Targets::TargetMemorySegmentType::RAM) { QObject::connect( readMemoryTask.get(), &InsightWorkerTask::finished, @@ -410,7 +420,7 @@ namespace Widgets [this] { this->refreshButton->stopSpin(); - if (this->targetState == Targets::TargetState::STOPPED) { + if (this->targetState.executionState == Targets::TargetExecutionState::STOPPED) { this->refreshButton->setDisabled(false); } } @@ -433,7 +443,7 @@ namespace Widgets [this] { this->refreshButton->stopSpin(); - if (this->targetState == Targets::TargetState::STOPPED) { + if (this->targetState.executionState == Targets::TargetExecutionState::STOPPED) { this->refreshButton->setDisabled(false); } } @@ -462,7 +472,7 @@ namespace Widgets } void TargetMemoryInspectionPane::postActivate() { - if (this->targetState == Targets::TargetState::STOPPED) { + if (this->targetState.executionState == Targets::TargetExecutionState::STOPPED) { if ( !this->activeRefreshTask.has_value() && (this->settings.refreshOnActivation || !this->data.has_value()) @@ -494,8 +504,8 @@ namespace Widgets void TargetMemoryInspectionPane::sanitiseSettings() { // Remove any invalid memory regions. It's very unlikely that there will be any, but not impossible. - auto processedFocusedMemoryRegions = std::vector(); - auto processedExcludedMemoryRegions = std::vector(); + auto processedFocusedMemoryRegions = std::vector{}; + auto processedExcludedMemoryRegions = std::vector{}; const auto regionIntersects = [ &processedFocusedMemoryRegions, @@ -518,7 +528,7 @@ namespace Widgets for (const auto& focusedRegion : this->settings.focusedMemoryRegions) { if ( - !this->targetMemoryDescriptor.addressRange.contains(focusedRegion.addressRange) + !this->memorySegmentDescriptor.addressRange.contains(focusedRegion.addressRange) || regionIntersects(focusedRegion) ) { continue; @@ -529,7 +539,7 @@ namespace Widgets for (const auto& excludedRegion : this->settings.excludedMemoryRegions) { if ( - !this->targetMemoryDescriptor.addressRange.contains(excludedRegion.addressRange) + !this->memorySegmentDescriptor.addressRange.contains(excludedRegion.addressRange) || regionIntersects(excludedRegion) ) { continue; @@ -542,15 +552,17 @@ namespace Widgets this->settings.excludedMemoryRegions = std::move(processedExcludedMemoryRegions); } - void TargetMemoryInspectionPane::onTargetStateChanged(Targets::TargetState newState) { - if (this->targetState == newState) { + void TargetMemoryInspectionPane::onTargetStateChanged( + Targets::TargetState newState, + Targets::TargetState previousState + ) { + if (newState.executionState == previousState.executionState) { return; } - using Targets::TargetState; - this->targetState = newState; + using Targets::TargetExecutionState; - if (newState == TargetState::STOPPED) { + if (newState.executionState == TargetExecutionState::STOPPED) { if (this->state.activated && (this->settings.refreshOnTargetStop || !this->data.has_value())) { this->refreshMemoryValues([this] { this->hexViewerWidget->setDisabled(false); @@ -562,7 +574,7 @@ namespace Widgets } } - if (newState == TargetState::RUNNING) { + if (newState.executionState == TargetExecutionState::RUNNING) { this->hexViewerWidget->setDisabled(true); this->refreshButton->setDisabled(true); @@ -585,7 +597,7 @@ namespace Widgets } void TargetMemoryInspectionPane::onMemoryRead(const Targets::TargetMemoryBuffer& data) { - assert(data.size() == this->targetMemoryDescriptor.size()); + assert(data.size() == this->memorySegmentDescriptor.size()); this->data = data; this->hexViewerWidget->updateValues(); @@ -594,12 +606,13 @@ namespace Widgets void TargetMemoryInspectionPane::openMemoryRegionManagerWindow() { if (this->memoryRegionManagerWindow == nullptr) { - this->memoryRegionManagerWindow = new MemoryRegionManagerWindow( - this->targetMemoryDescriptor, + this->memoryRegionManagerWindow = new MemoryRegionManagerWindow{ + this->addressSpaceDescriptor, + this->memorySegmentDescriptor, this->settings.focusedMemoryRegions, this->settings.excludedMemoryRegions, this - ); + }; QObject::connect( this->memoryRegionManagerWindow, @@ -647,16 +660,18 @@ namespace Widgets } void TargetMemoryInspectionPane::onProgrammingModeDisabled() { - const auto disabled = this->targetState != Targets::TargetState::STOPPED || !this->data.has_value(); + const auto disabled = this->targetState.executionState != Targets::TargetExecutionState::STOPPED + || !this->data.has_value(); this->hexViewerWidget->setDisabled(disabled); this->refreshButton->setDisabled(disabled); } void TargetMemoryInspectionPane::onTargetMemoryWritten( - TargetMemoryType memoryType, - TargetMemoryAddressRange + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, + Targets::TargetMemoryAddressRange addressRange ) { - if (memoryType == this->targetMemoryDescriptor.type && this->data.has_value()) { + if (memorySegmentDescriptor == this->memorySegmentDescriptor && this->data.has_value()) { this->setStaleData(true); this->snapshotManager->createSnapshotWindow->refreshForm(); } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.hpp index cb4c3195..435711fe 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.hpp @@ -12,8 +12,10 @@ #include "src/Insight/UserInterfaces/InsightWindow/Widgets/PaneWidget.hpp" #include "src/Targets/TargetMemory.hpp" - +#include "src/Targets/TargetAddressSpaceDescriptor.hpp" +#include "src/Targets/TargetMemorySegmentDescriptor.hpp" #include "src/Targets/TargetState.hpp" + #include "src/Insight/UserInterfaces/InsightWindow/Widgets/PanelWidget.hpp" #include "src/Insight/UserInterfaces/InsightWindow/Widgets/SvgToolButton.hpp" #include "src/Insight/UserInterfaces/InsightWindow/Widgets/Label.hpp" @@ -36,7 +38,10 @@ namespace Widgets public: TargetMemoryInspectionPane( - const Targets::TargetMemoryDescriptor& targetMemoryDescriptor, + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, + const Targets::TargetDescriptor& targetDescriptor, + const Targets::TargetState& targetState, TargetMemoryInspectionPaneSettings& settings, PaneState& paneState, PanelWidget* parent @@ -54,7 +59,10 @@ namespace Widgets void postDetach(); private: - const Targets::TargetMemoryDescriptor& targetMemoryDescriptor; + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor; + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor; + const Targets::TargetDescriptor& targetDescriptor; + const Targets::TargetState& targetState; TargetMemoryInspectionPaneSettings& settings; @@ -86,14 +94,12 @@ namespace Widgets TaskProgressIndicator* taskProgressIndicator = nullptr; QWidget* staleDataLabelContainer = nullptr; - Targets::TargetState targetState = Targets::TargetState::UNKNOWN; - MemoryRegionManagerWindow* memoryRegionManagerWindow = nullptr; bool staleData = false; void sanitiseSettings(); - void onTargetStateChanged(Targets::TargetState newState); + void onTargetStateChanged(Targets::TargetState newState, Targets::TargetState previousState); void setRefreshOnTargetStopEnabled(bool enabled); void setRefreshOnActivationEnabled(bool enabled); void onMemoryRead(const Targets::TargetMemoryBuffer& data); @@ -104,7 +110,8 @@ namespace Widgets void onProgrammingModeEnabled(); void onProgrammingModeDisabled(); void onTargetMemoryWritten( - Targets::TargetMemoryType memoryType, + const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, + const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor, Targets::TargetMemoryAddressRange addressRange ); void onSubtaskCreated(const QSharedPointer& task); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPaneSettings.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPaneSettings.hpp index d5c3ec3d..cfa9fcc4 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPaneSettings.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPaneSettings.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include "FocusedMemoryRegion.hpp" @@ -14,6 +15,8 @@ namespace Widgets { struct TargetMemoryInspectionPaneSettings { + QString addressSpaceKey; + QString memorySegmentKey; bool refreshOnTargetStop = false; bool refreshOnActivation = false; @@ -22,7 +25,12 @@ namespace Widgets std::vector focusedMemoryRegions; std::vector excludedMemoryRegions; - PanelState rightPanelState = PanelState(300, true); - PaneState snapshotManagerState = PaneState(true, true, std::nullopt); + PanelState rightPanelState = {300, true}; + PaneState snapshotManagerState = {true, true, std::nullopt}; + + TargetMemoryInspectionPaneSettings(const QString& addressSpaceKey, const QString& memorySegmentKey) + : addressSpaceKey(addressSpaceKey) + , memorySegmentKey(memorySegmentKey) + {} }; } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/ToolButton.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/ToolButton.cpp new file mode 100644 index 00000000..061e9038 --- /dev/null +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/ToolButton.cpp @@ -0,0 +1,44 @@ +#include "ToolButton.hpp" + +#include +#include + +#include "src/Services/PathService.hpp" +#include "src/Logger/Logger.hpp" + +namespace Widgets +{ + ToolButton::ToolButton(QString&& label, QWidget* parent) + : QToolButton(parent) + , layout(new QHBoxLayout{this}) + , icon(new SvgWidget{this}) + , label(new Label{label, this}) + { + this->setCheckable(true); + this->setToolTip(label); + this->setLayout(this->layout); + + this->icon->setSvgFilePath( + QString::fromStdString(Services::PathService::compiledResourcesPath() + + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/Images/memory-inspection-icon.svg" + ) + ); + this->icon->setContainerHeight(22); + this->icon->setContainerWidth(14); + + this->layout->addWidget(this->icon); + this->layout->addWidget(this->label); + + this->layout->setContentsMargins(10, 0, 10, 0); + this->layout->setSpacing(8); + + this->label->setContentsMargins(0, 0, 0, 0); + this->icon->setContentsMargins(0, 1, 0, 0); + + this->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding); + } + + QSize ToolButton::minimumSizeHint() const { + return this->layout->minimumSize(); + } +} diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/ToolButton.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/ToolButton.hpp new file mode 100644 index 00000000..c1c7d462 --- /dev/null +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/ToolButton.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include +#include +#include + +#include "src/Insight/UserInterfaces/InsightWindow/Widgets/SvgWidget.hpp" +#include "src/Insight/UserInterfaces/InsightWindow/Widgets/Label.hpp" + +namespace Widgets +{ + class ToolButton: public QToolButton + { + Q_OBJECT + + public: + ToolButton(QString&& label, QWidget* parent); + QSize minimumSizeHint() const override; + + private: + QHBoxLayout* layout; + SvgWidget* icon; + Label* label; + }; +} diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/BitsetWidget/BitBodyWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/BitsetWidget/BitBodyWidget.cpp index 639689f3..8136a97f 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/BitsetWidget/BitBodyWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/BitsetWidget/BitBodyWidget.cpp @@ -11,7 +11,12 @@ namespace Widgets std::bitset::digits>::reference bit, bool readOnly, QWidget* parent - ): ClickableWidget(parent), bitIndex(bitIndex), bit(bit), readOnly(readOnly) { + ) + : ClickableWidget(parent) + , bitIndex(bitIndex) + , bit(bit) + , readOnly(readOnly) + { this->setFixedSize(BitBodyWidget::WIDTH, BitBodyWidget::HEIGHT); this->setContentsMargins(0, 0, 0, 0); } @@ -50,7 +55,7 @@ namespace Widgets } void BitBodyWidget::paintEvent(QPaintEvent* event) { - auto painter = QPainter(this); + auto painter = QPainter{this}; this->drawWidget(painter); } @@ -60,7 +65,7 @@ namespace Widgets true ); - auto bodyColor = QColor(this->bit == true ? "#7B5E38" : "#908D85"); + auto bodyColor = QColor{this->bit ? "#7B5E38" : "#908D85"}; if (!this->isEnabled()) { bodyColor.setAlpha(100); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/BitsetWidget/BitBodyWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/BitsetWidget/BitBodyWidget.hpp index 2008e7a7..5dead5c8 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/BitsetWidget/BitBodyWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/BitsetWidget/BitBodyWidget.hpp @@ -18,7 +18,7 @@ namespace Widgets public: static constexpr int WIDTH = 19; - static constexpr int HEIGHT = 28; + static constexpr int HEIGHT = 29; BitBodyWidget( int bitIndex, diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/BitsetWidget/BitWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/BitsetWidget/BitWidget.cpp index dcd46628..a3bfa841 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/BitsetWidget/BitWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/BitsetWidget/BitWidget.cpp @@ -14,22 +14,28 @@ namespace Widgets std::bitset::digits>& bitset, bool readOnly, QWidget* parent - ): QWidget(parent), bitIndex(bitIndex), bitNumber(bitNumber), bitset(bitset), readOnly(readOnly) { + ) + : QWidget(parent) + , bitIndex(bitIndex) + , bitNumber(bitNumber) + , bitset(bitset) + , readOnly(readOnly) + { this->setFixedSize(BitWidget::WIDTH, BitWidget::HEIGHT); - auto* layout = new QVBoxLayout(this); + auto* layout = new QVBoxLayout{this}; layout->setSpacing(0); layout->setContentsMargins(0, 0, 0, 0); layout->setAlignment(Qt::AlignmentFlag::AlignTop); - this->body = new BitBodyWidget( + this->body = new BitBodyWidget{ this->bitIndex, this->bitset[static_cast(this->bitIndex)], this->readOnly, this - ); + }; - this->bitNumberLabel = new Label(QString::number(this->bitNumber), this); + this->bitNumberLabel = new Label{QString::number(this->bitNumber), this}; this->bitNumberLabel->setObjectName("register-bit-number-label"); this->bitNumberLabel->setFixedHeight(BitWidget::LABEL_HEIGHT); this->bitNumberLabel->setAlignment(Qt::AlignmentFlag::AlignCenter); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/BitsetWidget/BitWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/BitsetWidget/BitWidget.hpp index 38b06b42..ba54b885 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/BitsetWidget/BitWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/BitsetWidget/BitWidget.hpp @@ -27,7 +27,7 @@ namespace Widgets static constexpr int WIDTH = BitBodyWidget::WIDTH; static constexpr int HEIGHT = BitBodyWidget::HEIGHT + BitWidget::LABEL_HEIGHT + BitWidget::VERTICAL_SPACING; - static constexpr int SPACING = 5; + static constexpr int SPACING = 3; BitWidget( int bitIndex, diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/BitsetWidget/BitsetWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/BitsetWidget/BitsetWidget.cpp index a247e53a..f762a6dd 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/BitsetWidget/BitsetWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/BitsetWidget/BitsetWidget.cpp @@ -11,9 +11,13 @@ namespace Widgets { BitsetWidget::BitsetWidget(int byteNumber, unsigned char& byte, bool readOnly, QWidget* parent) - : QWidget(parent), byteNumber(byteNumber), byte(byte), readOnly(readOnly) { + : QWidget(parent) + , byteNumber(byteNumber) + , byte(byte) + , readOnly(readOnly) + { this->setObjectName("bitset-widget"); - auto* bitLayout = new QHBoxLayout(this); + auto* bitLayout = new QHBoxLayout{this}; bitLayout->setSpacing(BitWidget::SPACING); bitLayout->setContentsMargins(0, 0, 0, 0); this->setContentsMargins(0, 0, 0, 0); @@ -23,13 +27,13 @@ namespace Widgets ); for (int bitIndex = (std::numeric_limits::digits - 1); bitIndex >= 0; bitIndex--) { - auto* bitWidget = new BitWidget( + auto* bitWidget = new BitWidget{ bitIndex, (this->byteNumber * 8) + bitIndex, this->bitset, this->readOnly, this - ); + }; bitLayout->addWidget(bitWidget, 0, Qt::AlignmentFlag::AlignHCenter | Qt::AlignmentFlag::AlignTop); QObject::connect( @@ -52,56 +56,64 @@ namespace Widgets void BitsetWidget::paintEvent(QPaintEvent* event) { QWidget::paintEvent(event); - auto painter = QPainter(this); + auto painter = QPainter{this}; this->drawWidget(painter); } void BitsetWidget::drawWidget(QPainter& painter) { auto byteHex = "0x" + QString::number(this->byte, 16).toUpper(); - painter.setPen(QColor("#474747")); + painter.setPen(QColor{"#474747"}); constexpr int labelHeight = 11; int containerWidth = this->width(); constexpr int charWidth = 6; auto labelWidth = static_cast(charWidth * byteHex.size()) + 13; auto width = containerWidth - BitWidget::WIDTH; - painter.drawLine(QLine( - BitWidget::WIDTH / 2, - BitWidget::HEIGHT, - BitWidget::WIDTH / 2, - BitWidget::HEIGHT + BitsetWidget::VALUE_GRAPHIC_HEIGHT - )); + painter.drawLine( + QLine{ + BitWidget::WIDTH / 2, + BitWidget::HEIGHT, + BitWidget::WIDTH / 2, + BitWidget::HEIGHT + BitsetWidget::VALUE_GRAPHIC_HEIGHT + } + ); - painter.drawLine(QLine( - containerWidth - (BitWidget::WIDTH / 2) - 1, - BitWidget::HEIGHT, - containerWidth - (BitWidget::WIDTH / 2) - 1, - BitWidget::HEIGHT + BitsetWidget::VALUE_GRAPHIC_HEIGHT - )); + painter.drawLine( + QLine{ + containerWidth - (BitWidget::WIDTH / 2) - 1, + BitWidget::HEIGHT, + containerWidth - (BitWidget::WIDTH / 2) - 1, + BitWidget::HEIGHT + BitsetWidget::VALUE_GRAPHIC_HEIGHT + } + ); - painter.drawLine(QLine( - BitWidget::WIDTH / 2, - BitWidget::HEIGHT + BitsetWidget::VALUE_GRAPHIC_HEIGHT, - static_cast((BitWidget::WIDTH / 2) + width), - BitWidget::HEIGHT + BitsetWidget::VALUE_GRAPHIC_HEIGHT - )); + painter.drawLine( + QLine{ + BitWidget::WIDTH / 2, + BitWidget::HEIGHT + BitsetWidget::VALUE_GRAPHIC_HEIGHT, + static_cast((BitWidget::WIDTH / 2) + width), + BitWidget::HEIGHT + BitsetWidget::VALUE_GRAPHIC_HEIGHT + } + ); - painter.drawLine(QLine( - static_cast((BitWidget::WIDTH / 2) + (width / 2)), - BitWidget::HEIGHT + BitsetWidget::VALUE_GRAPHIC_HEIGHT, - static_cast((BitWidget::WIDTH / 2) + (width / 2)), - BitWidget::HEIGHT + BitsetWidget::VALUE_GRAPHIC_HEIGHT + 4 - )); + painter.drawLine( + QLine{ + static_cast((BitWidget::WIDTH / 2) + (width / 2)), + BitWidget::HEIGHT + BitsetWidget::VALUE_GRAPHIC_HEIGHT, + static_cast((BitWidget::WIDTH / 2) + (width / 2)), + BitWidget::HEIGHT + BitsetWidget::VALUE_GRAPHIC_HEIGHT + 4 + } + ); - painter.setPen(QColor("#8a8a8d")); + painter.setPen(QColor{"#8a8a8d"}); painter.drawText( - QRect( + QRect{ static_cast((BitWidget::WIDTH / 2) + (width / 2) - (labelWidth / 2)), BitWidget::HEIGHT + BitsetWidget::VALUE_GRAPHIC_HEIGHT + 7, labelWidth, labelHeight - ), + }, Qt::AlignCenter, byteHex ); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/CurrentItem.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/CurrentItem.cpp index 11ba49d1..b3aa8c19 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/CurrentItem.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/CurrentItem.cpp @@ -5,14 +5,13 @@ namespace Widgets { - CurrentItem::CurrentItem( - const Targets::TargetMemoryBuffer& registerValue, - QWidget* parent - ): Item(registerValue, parent) { + CurrentItem::CurrentItem(const Targets::TargetMemoryBuffer& registerValue, QWidget* parent) + : Item(registerValue, parent) + { this->setObjectName("current-item"); this->setFixedHeight(30); this->titleLabel->setText("Current Value"); - this->layout->addWidget(titleLabel, 0, Qt::AlignmentFlag::AlignLeft); + this->layout->addWidget(this->titleLabel, 0, Qt::AlignmentFlag::AlignLeft); this->layout->setContentsMargins(5, 0, 5, 0); } } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/CurrentItem.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/CurrentItem.hpp index 78d716c0..1ee9e1f8 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/CurrentItem.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/CurrentItem.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include "Item.hpp" @@ -16,13 +15,10 @@ namespace Widgets Q_OBJECT public: - CurrentItem( - const Targets::TargetMemoryBuffer& registerValue, - QWidget *parent - ); + CurrentItem(const Targets::TargetMemoryBuffer& registerValue, QWidget* parent); private: - QHBoxLayout* layout = new QHBoxLayout(this); - Label* titleLabel = new Label(this); + QHBoxLayout* layout = new QHBoxLayout{this}; + Label* titleLabel = new Label{this}; }; } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/Item.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/Item.cpp index 8d921c42..487ef564 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/Item.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/Item.cpp @@ -5,7 +5,9 @@ namespace Widgets { Item::Item(const Targets::TargetMemoryBuffer& registerValue, QWidget* parent) - : ClickableWidget(parent), registerValue(registerValue) { + : ClickableWidget(parent) + , registerValue(registerValue) + { auto onClick = [this] { this->setSelected(true); }; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/Item.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/Item.hpp index b972a715..390e2125 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/Item.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/Item.hpp @@ -11,7 +11,7 @@ namespace Widgets Q_OBJECT public: Targets::TargetMemoryBuffer registerValue; - Item(const Targets::TargetMemoryBuffer& registerValue, QWidget *parent); + Item(const Targets::TargetMemoryBuffer& registerValue, QWidget* parent); public slots: void setSelected(bool selected); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/RegisterHistoryItem.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/RegisterHistoryItem.cpp index ee24b9cd..0fcce402 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/RegisterHistoryItem.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/RegisterHistoryItem.cpp @@ -10,7 +10,9 @@ namespace Widgets const Targets::TargetMemoryBuffer& registerValue, const QDateTime& changeDate, QWidget* parent - ): Item(registerValue, parent) { + ) + : Item(registerValue, parent) + { this->setObjectName("register-history-item"); this->setFixedHeight(50); this->layout->setContentsMargins(5, 8, 5, 0); @@ -18,16 +20,16 @@ namespace Widgets this->dateLabel->setText(changeDate.toString("dd/MM/yyyy hh:mm:ss")); this->dateLabel->setObjectName("date-label"); - this->valueLabel->setText("0x" + QString(QByteArray( - reinterpret_cast(registerValue.data()), - static_cast(registerValue.size()) - ).toHex()).toUpper()); + this->valueLabel->setText("0x" + QString{QByteArray{ + reinterpret_cast(registerValue.data()), + static_cast(registerValue.size()) + }.toHex()}.toUpper()); this->valueLabel->setObjectName("value-label"); this->descriptionLabel->setText("Register Written"); this->descriptionLabel->setObjectName("description-label"); - auto* subLabelLayout = new QHBoxLayout(); + auto* subLabelLayout = new QHBoxLayout{}; subLabelLayout->setSpacing(0); subLabelLayout->setContentsMargins(0, 0, 0, 0); subLabelLayout->addWidget(this->valueLabel, 0, Qt::AlignmentFlag::AlignLeft); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/RegisterHistoryItem.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/RegisterHistoryItem.hpp index 6c821446..592788e1 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/RegisterHistoryItem.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/RegisterHistoryItem.hpp @@ -20,9 +20,9 @@ namespace Widgets ); private: - QVBoxLayout* layout = new QVBoxLayout(this); - Label* dateLabel = new Label(this); - Label* valueLabel = new Label(this); - Label* descriptionLabel = new Label(this); + QVBoxLayout* layout = new QVBoxLayout{this}; + Label* dateLabel = new Label{this}; + Label* valueLabel = new Label{this}; + Label* descriptionLabel = new Label{this}; }; } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/RegisterHistoryWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/RegisterHistoryWidget.cpp index d3997d4a..a511699d 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/RegisterHistoryWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/RegisterHistoryWidget.cpp @@ -35,18 +35,18 @@ namespace Widgets this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); - auto widgetUiFile = QFile( + auto widgetUiFile = QFile{ QString::fromStdString(Services::PathService::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget" + "/UiFiles/RegisterHistoryWidget.ui" ) - ); + }; if (!widgetUiFile.open(QFile::ReadOnly)) { - throw Exception("Failed to open RegisterHistoryWidget UI file"); + throw Exception{"Failed to open RegisterHistoryWidget UI file"}; } - auto uiLoader = UiLoader(this); + auto uiLoader = UiLoader{this}; this->container = uiLoader.load(&widgetUiFile, this); this->container->setMinimumSize(this->size()); this->container->setContentsMargins(1, 1, 1, 1); @@ -59,30 +59,21 @@ namespace Widgets titleBar->setContentsMargins(0, 0, 0, 0); title->setFixedHeight(titleBar->height()); - auto* insightSignals = InsightSignals::instance(); - QObject::connect( - insightSignals, - &InsightSignals::targetStateUpdated, - this, - &RegisterHistoryWidget::onTargetStateChanged - ); - - QObject::connect( - insightSignals, + InsightSignals::instance(), &InsightSignals::targetRegistersWritten, this, &RegisterHistoryWidget::onRegistersWritten ); - this->currentItem = new CurrentItem(currentValue, this); + this->currentItem = new CurrentItem{currentValue, this}; QObject::connect(this->currentItem, &Item::selected, this, &RegisterHistoryWidget::onItemSelectionChange); this->itemContainerLayout->addWidget(this->currentItem); this->currentItem->setSelected(true); - auto* separatorWidget = new QWidget(this); - auto* separatorLayout = new QHBoxLayout(separatorWidget); - auto* separatorLabel = new Label("Select an item to restore", separatorWidget); + auto* separatorWidget = new QWidget{this}; + auto* separatorLayout = new QHBoxLayout{separatorWidget}; + auto* separatorLabel = new Label{"Select an item to restore", separatorWidget}; separatorWidget->setFixedHeight(40); separatorWidget->setObjectName("separator-widget"); separatorLayout->setContentsMargins(0, 10, 0, 10); @@ -106,7 +97,7 @@ namespace Widgets } void RegisterHistoryWidget::addItem(const Targets::TargetMemoryBuffer& registerValue, const QDateTime& changeDate) { - auto* item = new RegisterHistoryItem(registerValue, changeDate, this->itemContainer); + auto* item = new RegisterHistoryItem{registerValue, changeDate, this->itemContainer}; QObject::connect(item, &Item::selected, this, &RegisterHistoryWidget::onItemSelectionChange); this->itemContainerLayout->insertWidget(2, item); } @@ -118,11 +109,6 @@ namespace Widgets ); } - void RegisterHistoryWidget::onTargetStateChanged(Targets::TargetState newState) { - using Targets::TargetState; - this->targetState = newState; - } - void RegisterHistoryWidget::onItemSelectionChange(Item* newlySelectedWidget) { if (this->selectedItemWidget != newlySelectedWidget) { if (this->selectedItemWidget != nullptr) { @@ -136,13 +122,13 @@ namespace Widgets } void RegisterHistoryWidget::onRegistersWritten( - Targets::TargetRegisters targetRegisters, + const Targets::TargetRegisterDescriptorAndValuePairs& targetRegisters, const QDateTime& changeDate ) { - for (const auto& targetRegister : targetRegisters) { - if (targetRegister.descriptorId == this->registerDescriptor.id) { - this->addItem(targetRegister.value, changeDate); - this->updateCurrentItemValue(targetRegister.value); + for (const auto& [descriptor, value] : targetRegisters) { + if (descriptor == this->registerDescriptor) { + this->addItem(value, changeDate); + this->updateCurrentItemValue(value); } } } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/RegisterHistoryWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/RegisterHistoryWidget.hpp index a8e031d0..6fd04701 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/RegisterHistoryWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/RegisterHistoryWidget.hpp @@ -9,9 +9,7 @@ #include #include "src/Targets/TargetRegisterDescriptor.hpp" -#include "src/Targets/TargetRegister.hpp" #include "src/Targets/TargetMemory.hpp" -#include "src/Targets/TargetState.hpp" #include "Item.hpp" #include "CurrentItem.hpp" @@ -47,19 +45,20 @@ namespace Widgets void resizeEvent(QResizeEvent* event) override; private: - Targets::TargetRegisterDescriptor registerDescriptor; + const Targets::TargetRegisterDescriptor& registerDescriptor; QWidget* container = nullptr; QWidget* itemContainer = nullptr; QVBoxLayout* itemContainerLayout = nullptr; - Targets::TargetState targetState = Targets::TargetState::UNKNOWN; CurrentItem* currentItem = nullptr; Item* selectedItemWidget = nullptr; private slots: - void onTargetStateChanged(Targets::TargetState newState); void onItemSelectionChange(Item* newlySelectedWidget); - void onRegistersWritten(Targets::TargetRegisters targetRegisters, const QDateTime& changeDate); + void onRegistersWritten( + const Targets::TargetRegisterDescriptorAndValuePairs& targetRegisters, + const QDateTime& changeDate + ); }; } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/TargetRegisterInspectorWindow.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/TargetRegisterInspectorWindow.cpp index cbdb26c9..737021ac 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/TargetRegisterInspectorWindow.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/TargetRegisterInspectorWindow.cpp @@ -10,7 +10,6 @@ #include "src/Insight/UserInterfaces/InsightWindow/Widgets/PlainTextEdit.hpp" #include "src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/ErrorDialogue.hpp" - #include "src/Services/PathService.hpp" #include "src/Exceptions/Exception.hpp" @@ -24,51 +23,53 @@ namespace Widgets using Targets::TargetRegisterDescriptors; using Targets::TargetRegisterType; using Targets::TargetState; + using Targets::TargetExecutionState; TargetRegisterInspectorWindow::TargetRegisterInspectorWindow( const Targets::TargetRegisterDescriptor& registerDescriptor, - TargetState currentTargetState, + const TargetState& targetState, QWidget* parent ) : QWidget(parent) , registerDescriptor(registerDescriptor) + , targetState(targetState) , registerValue(Targets::TargetMemoryBuffer(registerDescriptor.size, 0)) { this->setWindowFlag(Qt::Window); - auto registerName = QString::fromStdString(this->registerDescriptor.name.value()).toUpper(); + auto registerName = QString::fromStdString(this->registerDescriptor.name).toUpper(); this->setObjectName("target-register-inspector-window"); this->setWindowTitle("Inspect Register"); - auto windowUiFile = QFile( + auto windowUiFile = QFile{ QString::fromStdString(Services::PathService::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/UiFiles/" - "TargetRegisterInspectorWindow.ui" + "TargetRegisterInspectorWindow.ui" ) - ); + }; - auto windowStylesheet = QFile( + auto windowStylesheet = QFile{ QString::fromStdString(Services::PathService::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/Stylesheets/" - "TargetRegisterInspectorWindow.qss" + "TargetRegisterInspectorWindow.qss" ) - ); + }; if (!windowUiFile.open(QFile::ReadOnly)) { - throw Exception("Failed to open TargetRegisterInspectorWindow UI file"); + throw Exception{"Failed to open TargetRegisterInspectorWindow UI file"}; } if (!windowStylesheet.open(QFile::ReadOnly)) { - throw Exception("Failed to open TargetRegisterInspectorWindow stylesheet file"); + throw Exception{"Failed to open TargetRegisterInspectorWindow stylesheet file"}; } this->setStyleSheet(windowStylesheet.readAll()); this->setFixedSize(1120, 610); - auto uiLoader = UiLoader(this); + auto uiLoader = UiLoader{this}; this->container = uiLoader.load(&windowUiFile, this); this->container->setMinimumSize(this->size()); - this->container->setContentsMargins(QMargins(0, 0, 0, 0)); + this->container->setContentsMargins(QMargins{0, 0, 0, 0}); this->contentContainer = this->container->findChild("content-container"); auto* contentContainerViewport = this->contentContainer->widget(); @@ -86,11 +87,11 @@ namespace Widgets this->helpButton = this->container->findChild("help-btn"); this->closeButton = this->container->findChild("close-btn"); - this->registerHistoryWidget = new RegisterHistoryWidget( + this->registerHistoryWidget = new RegisterHistoryWidget{ this->registerDescriptor, this->registerValue, this->container - ); + }; auto* contentLayout = this->container->findChild("content-layout"); contentLayout->insertWidget(0, this->registerHistoryWidget, 0); @@ -111,7 +112,7 @@ namespace Widgets ); registerDetailsNameInput->setText(registerName); registerDetailsStartAddressInput->setText( - "0x" + QString::number(this->registerDescriptor.startAddress.value(), 16).toUpper() + "0x" + QString::number(this->registerDescriptor.startAddress, 16).toUpper() ); registerDetailsSizeInput->setText(QString::number(this->registerDescriptor.size)); registerDetailsDescriptionInput->setPlainText( @@ -136,19 +137,19 @@ namespace Widgets * Each row of the BitsetWidget container should hold two BitsetWidgets. So we have a horizontal layout nested * within a vertical layout. */ - auto* bitsetSingleHorizontalLayout = new QHBoxLayout(); + auto* bitsetSingleHorizontalLayout = new QHBoxLayout{}; bitsetSingleHorizontalLayout->setSpacing(BitWidget::SPACING); bitsetSingleHorizontalLayout->setContentsMargins(0, 0, 0, 0); // The register value will be in MSB, which is OK for us as we present the bit widgets in MSB. auto byteNumber = static_cast(this->registerValue.size() - 1); for (std::uint32_t registerByteIndex = 0; registerByteIndex < this->registerValue.size(); registerByteIndex++) { - auto* bitsetWidget = new BitsetWidget( + auto* bitsetWidget = new BitsetWidget{ byteNumber, this->registerValue.at(registerByteIndex), !this->registerDescriptor.access.writable, this - ); + }; bitsetSingleHorizontalLayout->addWidget(bitsetWidget, 0, Qt::AlignmentFlag::AlignLeft); QObject::connect( @@ -162,7 +163,7 @@ namespace Widgets if (((registerByteIndex + 1) % 4) == 0) { bitsetSingleHorizontalLayout->addStretch(1); registerBitsetWidgetLayout->addLayout(bitsetSingleHorizontalLayout); - bitsetSingleHorizontalLayout = new QHBoxLayout(); + bitsetSingleHorizontalLayout = new QHBoxLayout{}; bitsetSingleHorizontalLayout->setSpacing(BitWidget::SPACING); bitsetSingleHorizontalLayout->setContentsMargins(0, 0, 0, 0); } @@ -206,7 +207,6 @@ namespace Widgets ); this->updateRegisterValueInputField(); - this->onTargetStateChanged(currentTargetState); // Position the inspection window at the center of the main Insight window this->move(parent->window()->geometry().center() - this->rect().center()); @@ -283,18 +283,18 @@ namespace Widgets } } - void TargetRegisterInspectorWindow::onTargetStateChanged(TargetState newState) { - if (this->targetState == newState) { + void TargetRegisterInspectorWindow::onTargetStateChanged(TargetState newState, TargetState previousState) { + if (newState.executionState == previousState.executionState) { return; } - if (newState != TargetState::STOPPED) { + if (newState.executionState != TargetExecutionState::STOPPED) { this->registerValueTextInput->setDisabled(true); this->registerValueBitsetWidgetContainer->setDisabled(true); this->applyButton->setDisabled(true); this->refreshValueButton->setDisabled(true); - } else if (this->targetState != TargetState::STOPPED && this->registerValueContainer->isEnabled()) { + } else if (this->registerValueContainer->isEnabled()) { this->registerValueBitsetWidgetContainer->setDisabled(false); this->refreshValueButton->setDisabled(false); @@ -303,8 +303,6 @@ namespace Widgets this->applyButton->setDisabled(false); } } - - this->targetState = newState; } void TargetRegisterInspectorWindow::onHistoryItemSelected( @@ -322,12 +320,14 @@ namespace Widgets } void TargetRegisterInspectorWindow::updateRegisterValueInputField() { - auto value = QByteArray( - reinterpret_cast(this->registerValue.data()), - static_cast(this->registerValue.size()) + this->registerValueTextInput->setText( + "0x" + QString{ + QByteArray{ + reinterpret_cast(this->registerValue.data()), + static_cast(this->registerValue.size()) + }.toHex() + }.toUpper() ); - - this->registerValueTextInput->setText("0x" + QString(value.toHex()).toUpper()); } void TargetRegisterInspectorWindow::updateRegisterValueBitsetWidgets() { @@ -343,21 +343,21 @@ namespace Widgets void TargetRegisterInspectorWindow::refreshRegisterValue() { this->registerValueContainer->setDisabled(true); - const auto readTargetRegisterTask = QSharedPointer( - new ReadTargetRegisters({this->registerDescriptor.id}), + const auto readTargetRegisterTask = QSharedPointer{ + new ReadTargetRegisters{{&(this->registerDescriptor)}}, &QObject::deleteLater - ); + }; QObject::connect( readTargetRegisterTask.get(), &ReadTargetRegisters::targetRegistersRead, this, - [this] (Targets::TargetRegisters targetRegisters) { + [this] (const Targets::TargetRegisterDescriptorAndValuePairs& pairs) { this->registerValueContainer->setDisabled(false); - for (const auto& targetRegister : targetRegisters) { - if (targetRegister.descriptorId == this->registerDescriptor.id) { - this->setValue(targetRegister.value); + for (const auto& [descriptor, value] : pairs) { + if (descriptor.id == this->registerDescriptor.id) { + this->setValue(value); } } } @@ -377,30 +377,27 @@ namespace Widgets void TargetRegisterInspectorWindow::applyChanges() { this->registerValueContainer->setDisabled(true); - const auto targetRegister = Targets::TargetRegister( - this->registerDescriptor.id, - this->registerValue - ); - const auto writeRegisterTask = QSharedPointer( - new WriteTargetRegister(targetRegister), - &QObject::deleteLater - ); - QObject::connect(writeRegisterTask.get(), &InsightWorkerTask::completed, this, [this, targetRegister] { + const auto pair = Targets::TargetRegisterDescriptorAndValuePair{this->registerDescriptor, this->registerValue}; + const auto writeRegisterTask = QSharedPointer{ + new WriteTargetRegister{pair}, + &QObject::deleteLater + }; + + QObject::connect(writeRegisterTask.get(), &InsightWorkerTask::completed, this, [this, pair] { this->registerValueContainer->setDisabled(false); - this->registerHistoryWidget->updateCurrentItemValue(targetRegister.value); + this->registerHistoryWidget->updateCurrentItemValue(pair.second); this->registerHistoryWidget->selectCurrentItem(); }); QObject::connect(writeRegisterTask.get(), &InsightWorkerTask::failed, this, [this] (QString errorMessage) { this->registerValueContainer->setDisabled(false); - auto* errorDialogue = new ErrorDialogue( + auto* errorDialogue = new ErrorDialogue{ "Error", - "Failed to update " + QString::fromStdString( - this->registerDescriptor.name.value_or("") - ).toUpper() + " register value - " + errorMessage, + "Failed to update " + QString::fromStdString(this->registerDescriptor.name).toUpper() + + " register value - " + errorMessage, this - ); + }; errorDialogue->show(); }); @@ -409,7 +406,7 @@ namespace Widgets void TargetRegisterInspectorWindow::openHelpPage() { QDesktopServices::openUrl( - QUrl(QString::fromStdString(Services::PathService::homeDomainName() + "/docs/register-inspection")) + QUrl{QString::fromStdString(Services::PathService::homeDomainName() + "/docs/register-inspection")} ); } } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/TargetRegisterInspectorWindow.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/TargetRegisterInspectorWindow.hpp index 967a1b47..e300502a 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/TargetRegisterInspectorWindow.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/TargetRegisterInspectorWindow.hpp @@ -27,7 +27,7 @@ namespace Widgets public: TargetRegisterInspectorWindow( const Targets::TargetRegisterDescriptor& registerDescriptor, - Targets::TargetState currentTargetState, + const Targets::TargetState& targetState, QWidget* parent = nullptr ); @@ -40,7 +40,9 @@ namespace Widgets void keyPressEvent(QKeyEvent* event) override; private: - Targets::TargetRegisterDescriptor registerDescriptor; + const Targets::TargetRegisterDescriptor& registerDescriptor; + const Targets::TargetState& targetState; + Targets::TargetMemoryBuffer registerValue; QWidget* container = nullptr; @@ -60,11 +62,9 @@ namespace Widgets PushButton* helpButton = nullptr; PushButton* closeButton = nullptr; - Targets::TargetState targetState = Targets::TargetState::UNKNOWN; - private slots: void onValueTextInputChanged(QString text); - void onTargetStateChanged(Targets::TargetState newState); + void onTargetStateChanged(Targets::TargetState newState, Targets::TargetState previousState); void onHistoryItemSelected(const Targets::TargetMemoryBuffer& selectedRegisterValue); void updateRegisterValueInputField(); void updateRegisterValueBitsetWidgets(); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/PeripheralItem.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/PeripheralItem.cpp new file mode 100644 index 00000000..e0db9db5 --- /dev/null +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/PeripheralItem.cpp @@ -0,0 +1,213 @@ +#include "PeripheralItem.hpp" + +#include +#include +#include +#include +#include +#include +#include + +#include "src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListScene.hpp" +#include "src/Services/PathService.hpp" +#include "src/Logger/Logger.hpp" + +namespace Widgets +{ + PeripheralItem::PeripheralItem( + const Targets::TargetPeripheralDescriptor& peripheralDescriptor, + std::unordered_map& flattenedRegisterItemsByRegisterIds, + Targets::TargetRegisterDescriptors& flattenedRegisterDescriptors + ) + : peripheralDescriptor(peripheralDescriptor) + , name(QString::fromStdString(this->peripheralDescriptor.name)) + , searchKeywords(this->name + " " + QString::fromStdString(this->peripheralDescriptor.description)) + { + for (const auto& [groupKey, groupDescriptor] : this->peripheralDescriptor.registerGroupDescriptorsByKey) { + auto* registerGroupItem = new RegisterGroupItem{ + groupDescriptor, + 1, + flattenedRegisterItemsByRegisterIds, + flattenedRegisterDescriptors, + this + }; + registerGroupItem->setVisible(this->expanded); + + this->registerGroupItems.push_back(registerGroupItem); + } + + std::sort( + this->registerGroupItems.begin(), + this->registerGroupItems.end(), + [] (const RegisterGroupItem* itemA, const RegisterGroupItem* itemB) { + return itemA->startAddress < itemB->startAddress; + } + ); + + if (!PeripheralItem::peripheralIconPixmap.has_value()) { + this->generatePixmaps(); + } + } + + void PeripheralItem::setExpanded(bool expanded) { + if (expanded == this->expanded) { + return; + } + + this->expanded = expanded; + + for (auto& groupItem : this->registerGroupItems) { + groupItem->setVisible(this->expanded); + } + } + + void PeripheralItem::setAllExpanded(bool expanded) { + this->expanded = expanded; + + for (auto& groupItem : this->registerGroupItems) { + groupItem->setVisible(this->expanded); + groupItem->setAllExpanded(this->expanded); + } + } + + void PeripheralItem::refreshGeometry() { + const auto groupWidth = this->size.width(); + + const auto startXPosition = 0; + auto startYPosition = PeripheralItem::LIST_ITEM_HEIGHT; + + if (this->expanded) { + for (auto& groupItem : this->registerGroupItems) { + if (groupItem->excluded || !groupItem->isVisible()) { + continue; + } + + groupItem->size.setWidth(groupWidth); + groupItem->setPos(startXPosition, startYPosition); + + groupItem->onGeometryChanged(); + + startYPosition += groupItem->size.height(); + } + } + + this->size.setHeight(startYPosition); + } + + void PeripheralItem::applyFilter(const QString& keyword) { + const auto displayEntirePeripheral = keyword.isEmpty() + || this->searchKeywords.contains(keyword, Qt::CaseInsensitive); + + auto visibleChildItems = std::size_t{0}; + + for (auto* groupItem : this->registerGroupItems) { + groupItem->applyFilter(keyword, displayEntirePeripheral); + + if (!groupItem->excluded) { + ++visibleChildItems; + } + } + + this->setExpanded(visibleChildItems > 0 && !keyword.isEmpty()); + this->excluded = visibleChildItems == 0 && !keyword.isEmpty(); + } + + void PeripheralItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { + if (this->excluded) { + return; + } + + static constexpr auto selectedBackgroundColor = QColor{0x3C, 0x59, 0x5C}; + + static constexpr auto itemLeftPadding = 3; + static constexpr auto itemTopPadding = 4; + static constexpr auto iconLeftMargin = 5; + static constexpr auto labelLeftMargin = 6; + + static const auto nameLabelFont = QFont{"'Ubuntu', sans-serif", 11}; + static constexpr auto nameLabelFontColor = QColor{0xAF, 0xB1, 0xB3}; + + if (this->selected) { + painter->setBrush(selectedBackgroundColor); + painter->setPen(Qt::PenStyle::NoPen); + painter->drawRect(0, 0, this->size.width(), PeripheralItem::LIST_ITEM_HEIGHT); + } + + const auto& collapsedArrowIconPixmap = *(PeripheralItem::collapsedArrowIconPixmap); + const auto& expandedArrowIconPixmap = *(PeripheralItem::expandedArrowIconPixmap); + const auto& peripheralIconPixmap = *(PeripheralItem::peripheralIconPixmap); + + const QPixmap& arrowPixmap = this->expanded ? expandedArrowIconPixmap : collapsedArrowIconPixmap; + + painter->drawPixmap(itemLeftPadding, itemTopPadding + 2, arrowPixmap); + painter->drawPixmap( + arrowPixmap.width() + itemLeftPadding + iconLeftMargin, + itemTopPadding + 1, + peripheralIconPixmap + ); + + painter->setFont(nameLabelFont); + painter->setPen(nameLabelFontColor); + + const auto fontMetrics = painter->fontMetrics(); + + const auto nameLabelSize = fontMetrics.size(Qt::TextSingleLine, this->name); + const auto nameLabelRect = QRect{ + arrowPixmap.width() + itemLeftPadding + peripheralIconPixmap.width() + itemLeftPadding + labelLeftMargin, + itemTopPadding, + nameLabelSize.width(), + nameLabelSize.height() + }; + + painter->drawText(nameLabelRect, Qt::AlignLeft, this->name); + } + + void PeripheralItem::generatePixmaps() const { + auto svgRenderer = QSvgRenderer{}; + + { + svgRenderer.load(QString::fromStdString( + Services::PathService::compiledResourcesPath() + + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/Images/register-group.svg" + )); + + auto peripheralIconPixmap = QPixmap{svgRenderer.defaultSize()}; + peripheralIconPixmap.fill(Qt::GlobalColor::transparent); + + auto painter = QPainter{&peripheralIconPixmap}; + svgRenderer.render(&painter); + + PeripheralItem::peripheralIconPixmap = peripheralIconPixmap; + } + + { + svgRenderer.load(QString::fromStdString( + Services::PathService::compiledResourcesPath() + + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/Images/arrow.svg" + )); + + const auto iconSize = svgRenderer.defaultSize(); + auto arrowIconPixmap = QPixmap{iconSize}; + arrowIconPixmap.fill(Qt::GlobalColor::transparent); + + auto painter = QPainter{&arrowIconPixmap}; + svgRenderer.render(&painter); + + PeripheralItem::collapsedArrowIconPixmap = arrowIconPixmap; + + painter.translate( + std::ceil(static_cast(iconSize.width() / 2)), + std::ceil(static_cast(iconSize.height() / 2)) + ); + painter.rotate(90); + painter.translate( + -std::ceil(static_cast(iconSize.width() / 2)), + -std::ceil(static_cast(iconSize.height() / 2)) + ); + arrowIconPixmap.fill(Qt::GlobalColor::transparent); + svgRenderer.render(&painter); + + PeripheralItem::expandedArrowIconPixmap = arrowIconPixmap; + } + } +} diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/PeripheralItem.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/PeripheralItem.hpp new file mode 100644 index 00000000..7382c5d4 --- /dev/null +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/PeripheralItem.hpp @@ -0,0 +1,60 @@ +#pragma once + +#include +#include +#include +#include +#include + +#include "src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListItem.hpp" + +#include "RegisterGroupItem.hpp" +#include "src/Targets/TargetPeripheralDescriptor.hpp" +#include "src/Targets/TargetRegisterDescriptor.hpp" + +namespace Widgets +{ + class PeripheralItem: public ListItem + { + public: + const Targets::TargetPeripheralDescriptor& peripheralDescriptor; + const QString name; + const QString searchKeywords; + std::vector registerGroupItems; + + PeripheralItem( + const Targets::TargetPeripheralDescriptor& peripheralDescriptor, + std::unordered_map& flattenedRegisterItemsByRegisterIds, + Targets::TargetRegisterDescriptors& flattenedRegisterDescriptors + ); + + bool isExpanded() const { + return this->expanded; + } + void setExpanded(bool expanded); + void setAllExpanded(bool expanded); + + void onGeometryChanged() override { + return this->refreshGeometry(); + } + void refreshGeometry(); + + bool operator < (const ListItem& rhs) const override { + return this->name < dynamic_cast(rhs).name; + } + + void applyFilter(const QString& keyword); + + void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override; + + private: + static constexpr int LIST_ITEM_HEIGHT = 25; + static inline std::optional peripheralIconPixmap = std::nullopt; + static inline std::optional collapsedArrowIconPixmap = std::nullopt; + static inline std::optional expandedArrowIconPixmap = std::nullopt; + + bool expanded = false; + + void generatePixmaps() const; + }; +} diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/RegisterGroupItem.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/RegisterGroupItem.cpp index d807e271..d8f6bbfe 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/RegisterGroupItem.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/RegisterGroupItem.cpp @@ -6,28 +6,70 @@ #include #include #include +#include #include "src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListScene.hpp" #include "src/Services/PathService.hpp" +#include "src/Logger/Logger.hpp" namespace Widgets { RegisterGroupItem::RegisterGroupItem( - QString name, - const std::set& registerDescriptors, - std::unordered_map& registerItemsByDescriptorIds + const Targets::TargetRegisterGroupDescriptor& registerGroupDescriptor, + std::size_t nestedLevel, + std::unordered_map& flattenedRegisterItemsByRegisterIds, + Targets::TargetRegisterDescriptors& flattenedRegisterDescriptors, + QGraphicsItem* parent ) - : groupName(name) + : ListItem(parent) + , registerGroupDescriptor(registerGroupDescriptor) + , nestedLevel(nestedLevel) + , startAddress(this->registerGroupDescriptor.startAddress()) + , name(QString::fromStdString(this->registerGroupDescriptor.name)) + , searchKeywords( + this->name + " " + QString::fromStdString(this->registerGroupDescriptor.description.value_or("")) + ) { - for (const auto& registerDescriptor : registerDescriptors) { - auto* registerItem = new RegisterItem(registerDescriptor); - registerItem->setParentItem(this); - registerItem->setVisible(this->isExpanded()); + for (const auto& [groupKey, groupDescriptor] : this->registerGroupDescriptor.subgroupDescriptorsByKey) { + auto* subgroupItem = new RegisterGroupItem{ + groupDescriptor, + this->nestedLevel + 1, + flattenedRegisterItemsByRegisterIds, + flattenedRegisterDescriptors, + this + }; + subgroupItem->setVisible(this->expanded); - this->registerItems.push_back(registerItem); - registerItemsByDescriptorIds.insert(std::pair(registerDescriptor.id, registerItem)); + this->childItems.emplace_back(subgroupItem); } + for (const auto& [registerKey, registerDescriptor] : this->registerGroupDescriptor.registerDescriptorsByKey) { + auto* registerItem = new RegisterItem{registerDescriptor, this->nestedLevel + 1, this}; + registerItem->setVisible(this->expanded); + + this->childItems.emplace_back(registerItem); + flattenedRegisterItemsByRegisterIds.emplace(registerDescriptor.id, registerItem); + flattenedRegisterDescriptors.emplace_back(®isterDescriptor); + } + + std::sort( + this->childItems.begin(), + this->childItems.end(), + [] (const ListItem* itemA, const ListItem* itemB) { + const auto* registerItemA = dynamic_cast(itemA); + const auto startAddressA = registerItemA != nullptr + ? registerItemA->registerDescriptor.startAddress + : dynamic_cast(itemA)->startAddress; + + const auto* registerItemB = dynamic_cast(itemB); + const auto startAddressB = registerItemB != nullptr + ? registerItemB->registerDescriptor.startAddress + : dynamic_cast(itemB)->startAddress; + + return startAddressA < startAddressB; + } + ); + if (!RegisterGroupItem::registerGroupIconPixmap.has_value()) { this->generatePixmaps(); } @@ -40,8 +82,21 @@ namespace Widgets this->expanded = expanded; - for (auto& registerItem : this->registerItems) { - registerItem->setVisible(this->expanded); + for (auto* childItem : this->childItems) { + childItem->setVisible(expanded); + } + } + + void RegisterGroupItem::setAllExpanded(bool expanded) { + this->expanded = expanded; + + for (auto* childItem : this->childItems) { + childItem->setVisible(expanded); + + auto* groupItem = dynamic_cast(childItem); + if (groupItem != nullptr) { + groupItem->setAllExpanded(expanded); + } } } @@ -51,34 +106,80 @@ namespace Widgets const auto startXPosition = 0; auto startYPosition = RegisterGroupItem::GROUP_LIST_ITEM_HEIGHT; - if (this->isExpanded()) { - for (auto& registerItem : this->registerItems) { - if (!registerItem->isVisible() || registerItem->excluded) { + if (this->expanded) { + for (auto& childItem : this->childItems) { + if (childItem->excluded || !childItem->isVisible()) { continue; } - registerItem->size.setWidth(groupWidth); - registerItem->setPos(startXPosition, startYPosition); + auto* groupItem = dynamic_cast(childItem); + if (groupItem != nullptr) { + groupItem->refreshGeometry(); + } - registerItem->onGeometryChanged(); + childItem->size.setWidth(groupWidth); + childItem->setPos(startXPosition, startYPosition); - startYPosition += registerItem->size.height(); + childItem->onGeometryChanged(); + + startYPosition += childItem->size.height(); } } this->size.setHeight(startYPosition); } - void RegisterGroupItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { - static constexpr auto selectedBackgroundColor = QColor(0x3C, 0x59, 0x5C); + void RegisterGroupItem::applyFilter(const QString& keyword, bool displayEntirePeripheral) { + const auto displayEntireGroup = displayEntirePeripheral || keyword.isEmpty() + || this->searchKeywords.contains(keyword, Qt::CaseInsensitive); + + auto visibleChildCount = std::size_t{0}; + for (auto* childItem : this->childItems) { + auto* groupItem = dynamic_cast(childItem); + if (groupItem != nullptr) { + groupItem->applyFilter(keyword, displayEntirePeripheral); + + if (!groupItem->excluded) { + ++visibleChildCount; + } + continue; + } + + auto* registerItem = dynamic_cast(childItem); + if (registerItem != nullptr) { + registerItem->excluded = !displayEntireGroup + && !registerItem->searchKeywords.contains(keyword, Qt::CaseInsensitive); + + if (!registerItem->excluded) { + ++visibleChildCount; + } + } + } + + this->excluded = !displayEntireGroup && visibleChildCount == 0 && !keyword.isEmpty(); + this->setExpanded((displayEntireGroup || visibleChildCount > 0) && !keyword.isEmpty()); + } + + void RegisterGroupItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { + if (this->excluded) { + return; + } + + const auto& collapsedArrowIconPixmap = *(RegisterGroupItem::collapsedArrowIconPixmap); + const auto& expandedArrowIconPixmap = *(RegisterGroupItem::expandedArrowIconPixmap); + const auto& registerGroupIconPixmap = *(RegisterGroupItem::registerGroupIconPixmap); + + static constexpr auto selectedBackgroundColor = QColor{0x3C, 0x59, 0x5C}; - static constexpr auto itemLeftPadding = 3; static constexpr auto itemTopPadding = 4; static constexpr auto iconLeftMargin = 5; static constexpr auto labelLeftMargin = 6; + const auto itemLeftPadding = ( + (expandedArrowIconPixmap.width() + iconLeftMargin) * static_cast(this->nestedLevel) + ) + 3; - static const auto nameLabelFont = QFont("'Ubuntu', sans-serif", 11); - static constexpr auto nameLabelFontColor = QColor(0xAF, 0xB1, 0xB3); + static const auto nameLabelFont = QFont{"'Ubuntu', sans-serif", 11}; + static constexpr auto nameLabelFontColor = QColor{0xAF, 0xB1, 0xB3}; if (this->selected) { painter->setBrush(selectedBackgroundColor); @@ -86,15 +187,11 @@ namespace Widgets painter->drawRect(0, 0, this->size.width(), RegisterGroupItem::GROUP_LIST_ITEM_HEIGHT); } - const auto& collapsedArrowIconPixmap = *(RegisterGroupItem::collapsedArrowIconPixmap); - const auto& expandedArrowIconPixmap = *(RegisterGroupItem::expandedArrowIconPixmap); - const auto& registerGroupIconPixmap = *(RegisterGroupItem::registerGroupIconPixmap); - - const QPixmap& arrowPixmap = this->isExpanded() ? expandedArrowIconPixmap : collapsedArrowIconPixmap; + const auto& arrowPixmap = this->isExpanded() ? expandedArrowIconPixmap : collapsedArrowIconPixmap; painter->drawPixmap(itemLeftPadding, itemTopPadding + 2, arrowPixmap); painter->drawPixmap( - arrowPixmap.width() + itemLeftPadding + iconLeftMargin, + itemLeftPadding + arrowPixmap.width() + iconLeftMargin, itemTopPadding + 1, registerGroupIconPixmap ); @@ -104,19 +201,19 @@ namespace Widgets const auto fontMetrics = painter->fontMetrics(); - const auto nameLabelSize = fontMetrics.size(Qt::TextSingleLine, this->groupName); - const auto nameLabelRect = QRect( - arrowPixmap.width() + itemLeftPadding + registerGroupIconPixmap.width() + itemLeftPadding + labelLeftMargin, + const auto nameLabelSize = fontMetrics.size(Qt::TextSingleLine, this->name); + const auto nameLabelRect = QRect{ + itemLeftPadding + arrowPixmap.width() + iconLeftMargin + registerGroupIconPixmap.width() + labelLeftMargin, itemTopPadding, nameLabelSize.width(), nameLabelSize.height() - ); + }; - painter->drawText(nameLabelRect, Qt::AlignLeft, this->groupName); + painter->drawText(nameLabelRect, Qt::AlignLeft, this->name); } void RegisterGroupItem::generatePixmaps() const { - auto svgRenderer = QSvgRenderer(); + auto svgRenderer = QSvgRenderer{}; { svgRenderer.load(QString::fromStdString( @@ -124,10 +221,10 @@ namespace Widgets + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/Images/register-group.svg" )); - auto registerGroupIconPixmap = QPixmap(svgRenderer.defaultSize()); + auto registerGroupIconPixmap = QPixmap{svgRenderer.defaultSize()}; registerGroupIconPixmap.fill(Qt::GlobalColor::transparent); - auto painter = QPainter(®isterGroupIconPixmap); + auto painter = QPainter{®isterGroupIconPixmap}; svgRenderer.render(&painter); RegisterGroupItem::registerGroupIconPixmap = registerGroupIconPixmap; @@ -140,10 +237,10 @@ namespace Widgets )); const auto iconSize = svgRenderer.defaultSize(); - auto arrowIconPixmap = QPixmap(iconSize); + auto arrowIconPixmap = QPixmap{iconSize}; arrowIconPixmap.fill(Qt::GlobalColor::transparent); - auto painter = QPainter(&arrowIconPixmap); + auto painter = QPainter{&arrowIconPixmap}; svgRenderer.render(&painter); RegisterGroupItem::collapsedArrowIconPixmap = arrowIconPixmap; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/RegisterGroupItem.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/RegisterGroupItem.hpp index b3f2e520..0b2755ba 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/RegisterGroupItem.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/RegisterGroupItem.hpp @@ -9,6 +9,7 @@ #include "src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListItem.hpp" #include "RegisterItem.hpp" +#include "src/Targets/TargetRegisterGroupDescriptor.hpp" #include "src/Targets/TargetRegisterDescriptor.hpp" namespace Widgets @@ -16,42 +17,43 @@ namespace Widgets class RegisterGroupItem: public ListItem { public: - const QString groupName; - std::vector registerItems; - - explicit RegisterGroupItem( - QString name, - const std::set& registerDescriptors, - std::unordered_map& registerItemsByDescriptorIds - ); - - bool isExpanded() const { - return this->expanded; - } - - void setExpanded(bool expanded); - - void onGeometryChanged() override { - return this->refreshGeometry(); - } - - void refreshGeometry(); - - bool operator < (const ListItem& rhs) const override { - const auto& rhsRegisterGroupItem = dynamic_cast(rhs); - return this->groupName < rhsRegisterGroupItem.groupName; - } - - void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override; - - private: static constexpr int GROUP_LIST_ITEM_HEIGHT = 25; static inline std::optional registerGroupIconPixmap = std::nullopt; static inline std::optional collapsedArrowIconPixmap = std::nullopt; static inline std::optional expandedArrowIconPixmap = std::nullopt; - bool expanded = false; + const Targets::TargetRegisterGroupDescriptor& registerGroupDescriptor; + std::size_t nestedLevel; + const Targets::TargetMemoryAddress startAddress; + const QString name; + const QString searchKeywords; + std::vector childItems; + explicit RegisterGroupItem( + const Targets::TargetRegisterGroupDescriptor& registerGroupDescriptor, + std::size_t nestedLevel, + std::unordered_map& flattenedRegisterItemsByRegisterIds, + Targets::TargetRegisterDescriptors& flattenedRegisterDescriptors, + QGraphicsItem* parent + ); + + [[nodiscard]] bool isExpanded() const { + return this->expanded; + } + void setExpanded(bool expanded); + void setAllExpanded(bool expanded); + + void onGeometryChanged() override { + return this->refreshGeometry(); + } + void refreshGeometry(); + + void applyFilter(const QString& keyword, bool displayEntirePeripheral); + + void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override; + + private: + bool expanded = false; void generatePixmaps() const; }; } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/RegisterItem.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/RegisterItem.cpp index 139e4bc4..7f9b1494 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/RegisterItem.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/RegisterItem.cpp @@ -7,18 +7,23 @@ #include #include +#include "RegisterGroupItem.hpp" #include "src/Services/PathService.hpp" namespace Widgets { RegisterItem::RegisterItem( - const Targets::TargetRegisterDescriptor& registerDescriptor + const Targets::TargetRegisterDescriptor& registerDescriptor, + std::size_t nestedLevel, + QGraphicsItem* parent ) - : registerDescriptor(registerDescriptor) - , registerName(QString::fromStdString(registerDescriptor.name.value()).toUpper()) + : ListItem(parent) + , registerDescriptor(registerDescriptor) + , nestedLevel(nestedLevel) + , registerName(QString::fromStdString(registerDescriptor.name).toUpper()) , searchKeywords(this->registerName + " " + QString::fromStdString(registerDescriptor.description.value_or(""))) { - this->size = QSize(0, RegisterItem::HEIGHT); + this->size = QSize{0, RegisterItem::HEIGHT}; if (!RegisterItem::registerIconPixmap.has_value()) { this->generatePixmaps(); @@ -26,17 +31,17 @@ namespace Widgets } void RegisterItem::setValue(const Targets::TargetMemoryBuffer& value) { - const auto valueByteArray = QByteArray( + const auto valueByteArray = QByteArray{ reinterpret_cast(value.data()), static_cast(value.size()) - ); + }; auto hexValueByteArray = valueByteArray.toHex(); - this->valueText = ": 0x" + QString(hexValueByteArray).toUpper() + this->valueText = ": 0x" + QString{hexValueByteArray}.toUpper() + " | " + QString::number(hexValueByteArray.toUInt(nullptr, 16)); if (value.size() == 1 && value[0] >= 32 && value[0] <= 126) { - this->valueText += " | '" + QString(valueByteArray) + "'"; + this->valueText += " | '" + QString{valueByteArray} + "'"; } } @@ -45,22 +50,29 @@ namespace Widgets return; } - static constexpr auto selectedBackgroundColor = QColor(0x3C, 0x59, 0x5C); + const auto& expandedArrowIconPixmap = *(RegisterGroupItem::expandedArrowIconPixmap); + const auto& registerGroupIconPixmap = *(RegisterGroupItem::registerGroupIconPixmap); + + static constexpr auto selectedBackgroundColor = QColor{0x3C, 0x59, 0x5C}; - static constexpr auto itemLeftPadding = 41; static constexpr auto itemTopPadding = 4; + static constexpr auto iconLeftMargin = 5; static constexpr auto labelLeftMargin = 5; - static const auto nameLabelFont = QFont("'Ubuntu', sans-serif", 11); - static constexpr auto primaryFontColor = QColor(0xAF, 0xB1, 0xB3); - static const auto valueLabelFont = QFont("'Ubuntu', sans-serif", 10, -1, true); - static constexpr auto secondaryFontColor = QColor(0x8A, 0x8A, 0x8D); - static constexpr auto highlightedValueLabelFontColor = QColor(0x54, 0x7F, 0xBA); + const auto itemLeftPadding = ( + (expandedArrowIconPixmap.width() + iconLeftMargin) * static_cast(this->nestedLevel) + ) + (registerGroupIconPixmap.width() + iconLeftMargin) + 3; + + static const auto nameLabelFont = QFont{"'Ubuntu', sans-serif", 11}; + static constexpr auto primaryFontColor = QColor{0xAF, 0xB1, 0xB3}; + static const auto valueLabelFont = QFont{"'Ubuntu', sans-serif", 10, -1, true}; + static constexpr auto secondaryFontColor = QColor{0x8A, 0x8A, 0x8D}; + static constexpr auto highlightedValueLabelFontColor = QColor{0x54, 0x7F, 0xBA}; if (this->selected) { painter->setBrush(selectedBackgroundColor); painter->setPen(Qt::PenStyle::NoPen); - painter->drawRect(QRect(QPoint(0, 0), this->size)); + painter->drawRect(QRect{QPoint{0, 0}, this->size}); } const auto& registerIconPixmap = *(RegisterItem::registerIconPixmap); @@ -72,12 +84,12 @@ namespace Widgets const auto fontMetrics = painter->fontMetrics(); const auto nameLabelSize = fontMetrics.size(Qt::TextSingleLine, this->registerName); - const auto nameLabelRect = QRect( + const auto nameLabelRect = QRect{ registerIconPixmap.width() + itemLeftPadding + labelLeftMargin, itemTopPadding, nameLabelSize.width(), nameLabelSize.height() - ); + }; painter->drawText(nameLabelRect, Qt::AlignLeft, this->registerName); @@ -92,29 +104,31 @@ namespace Widgets const auto fontMetrics = painter->fontMetrics(); const auto valueLabelSize = fontMetrics.size(Qt::TextSingleLine, this->valueText); - const auto valueLabelRect = QRect( + const auto valueLabelRect = QRect{ nameLabelRect.right() + labelLeftMargin, itemTopPadding + 1, valueLabelSize.width(), valueLabelSize.height() - ); + }; painter->drawText(valueLabelRect, Qt::AlignLeft, this->valueText); } } void RegisterItem::generatePixmaps() const { - auto svgRegisterIconRenderer = QSvgRenderer(QString::fromStdString( - Services::PathService::compiledResourcesPath() - + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/Images/register.svg" - )); + auto svgRegisterIconRenderer = QSvgRenderer{ + QString::fromStdString( + Services::PathService::compiledResourcesPath() + + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/Images/register.svg" + ) + }; const auto registerIconSize = svgRegisterIconRenderer.defaultSize(); auto registerIconPixmap = QPixmap(registerIconSize); registerIconPixmap.fill(Qt::GlobalColor::transparent); - auto painter = QPainter(®isterIconPixmap); + auto painter = QPainter{®isterIconPixmap}; svgRegisterIconRenderer.render(&painter); RegisterItem::registerIconPixmap = registerIconPixmap; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/RegisterItem.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/RegisterItem.hpp index 54fa762c..823d3eda 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/RegisterItem.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/RegisterItem.hpp @@ -13,14 +13,16 @@ namespace Widgets class RegisterItem: public ListItem { public: - const Targets::TargetRegisterDescriptor registerDescriptor; + const Targets::TargetRegisterDescriptor& registerDescriptor; + std::size_t nestedLevel; const QString registerName; const QString searchKeywords; - bool excluded = false; bool valueChanged = false; explicit RegisterItem( - const Targets::TargetRegisterDescriptor& registerDescriptor + const Targets::TargetRegisterDescriptor& registerDescriptor, + std::size_t nestedLevel, + QGraphicsItem* parent ); void setValue(const Targets::TargetMemoryBuffer& value); @@ -31,7 +33,7 @@ namespace Widgets bool operator < (const ListItem& rhs) const override { const auto& rhsRegisterItem = dynamic_cast(rhs); - return this->registerName < rhsRegisterItem.registerName; + return this->registerDescriptor.startAddress < rhsRegisterItem.registerDescriptor.startAddress; } void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override; @@ -40,7 +42,7 @@ namespace Widgets static constexpr int HEIGHT = 25; static inline std::optional registerIconPixmap = std::nullopt; - QString valueText = ""; + QString valueText = {}; void generatePixmaps() const; }; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.cpp index 36b64aa1..8af1618a 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.cpp @@ -27,31 +27,33 @@ namespace Widgets TargetRegistersPaneWidget::TargetRegistersPaneWidget( const TargetDescriptor& targetDescriptor, + const Targets::TargetState& targetState, PaneState& paneState, PanelWidget* parent ) : PaneWidget(paneState, parent) , targetDescriptor(targetDescriptor) + , targetState(targetState) { this->setObjectName("target-registers-side-pane"); - auto targetRegistersPaneUiFile = QFile( + auto targetRegistersPaneUiFile = QFile{ QString::fromStdString(Services::PathService::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/UiFiles/" - "TargetRegistersSidePane.ui" + "TargetRegistersSidePane.ui" ) - ); + }; if (!targetRegistersPaneUiFile.open(QFile::ReadOnly)) { - throw Exception("Failed to open TargetRegistersSidePane UI file"); + throw Exception{"Failed to open TargetRegistersSidePane UI file"}; } - auto uiLoader = UiLoader(this); + auto uiLoader = UiLoader{this}; this->container = uiLoader.load(&targetRegistersPaneUiFile, this); this->container->setFixedSize(parent->width(), parent->maximumHeight()); auto* containerLayout = this->container->findChild(); - auto* layout = new QVBoxLayout(this); + auto* layout = new QVBoxLayout{this}; layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(this->container); @@ -61,6 +63,18 @@ namespace Widgets this->toolBar->layout()->setContentsMargins(5, 0, 5, 0); this->searchInput = this->container->findChild("search-input"); + this->contextMenu->addAction(this->openInspectionWindowAction); + this->contextMenu->addAction(this->refreshValueAction); + this->contextMenu->addSeparator(); + + this->copyMenu->addAction(this->copyNameAction); + this->copyMenu->addSeparator(); + this->copyMenu->addAction(this->copyValueDecimalAction); + this->copyMenu->addAction(this->copyValueHexAction); + this->copyMenu->addAction(this->copyValueBinaryAction); + + this->contextMenu->addMenu(this->copyMenu); + QObject::connect(this->expandAllButton, &QToolButton::clicked, [this] { this->expandAllRegisterGroups(); }); @@ -73,42 +87,20 @@ namespace Widgets this->filterRegisters(this->searchInput->text()); }); - const auto& registerDescriptors = targetDescriptor.registerDescriptorsById; - - auto registerDescriptorsByGroupName = std::map>(); - - for (const auto& [descriptorId, descriptor] : registerDescriptors) { - if ( - descriptor.type != TargetRegisterType::GENERAL_PURPOSE_REGISTER - && descriptor.type != TargetRegisterType::PORT_REGISTER - && descriptor.type != TargetRegisterType::OTHER - ) { - continue; - } - - const auto groupName = descriptor.type == TargetRegisterType::GENERAL_PURPOSE_REGISTER - ? "CPU General Purpose" - : QString::fromStdString(descriptor.groupName.value_or("other")).toUpper(); - - registerDescriptorsByGroupName[groupName].insert(descriptor); - this->registerDescriptors.insert(descriptor); - - } - - for (const auto& [groupName, registerDescriptors] : registerDescriptorsByGroupName) { - this->registerGroupItems.emplace_back( - new RegisterGroupItem( - groupName, - registerDescriptors, - this->registerItemsByDescriptorId - ) + for (const auto& [peripheralKey, peripheralDescriptor] : this->targetDescriptor.peripheralDescriptorsByKey) { + this->peripheralItems.emplace_back( + new PeripheralItem{ + peripheralDescriptor, + this->flattenedRegisterItemsByRegisterId, + this->flattenedRegisterDescriptors + } ); } - this->registerListView = new ListView( - ListScene::ListItemSetType(this->registerGroupItems.begin(), this->registerGroupItems.end()), + this->registerListView = new ListView{ + ListItem::ListItemSetType{this->peripheralItems.begin(), this->peripheralItems.end()}, this - ); + }; this->registerListScene = this->registerListView->listScene(); this->registerListScene->setKeyNavigationEnabled(false); @@ -146,7 +138,7 @@ namespace Widgets this, [this] { if (this->contextMenuRegisterItem != nullptr) { - this->refreshRegisterValues(this->contextMenuRegisterItem->registerDescriptor.id, std::nullopt); + this->refreshRegisterValues(this->contextMenuRegisterItem->registerDescriptor, std::nullopt); } } ); @@ -224,70 +216,45 @@ namespace Widgets } void TargetRegistersPaneWidget::filterRegisters(const QString& keyword) { - for (const auto& groupItem : this->registerGroupItems) { - auto visibleItems = std::uint32_t{0}; - auto displayEntireGroup = keyword.isEmpty() || groupItem->groupName.contains(keyword, Qt::CaseInsensitive); - - for (auto& registerItem : groupItem->registerItems) { - registerItem->excluded = !displayEntireGroup - && !registerItem->searchKeywords.contains(keyword, Qt::CaseInsensitive); - - if (!registerItem->excluded) { - ++visibleItems; - } - } - - groupItem->setVisible(visibleItems > 0 || keyword.isEmpty()); - groupItem->setExpanded(visibleItems > 0 && !keyword.isEmpty()); + for (auto* peripheralItem : this->peripheralItems) { + peripheralItem->applyFilter(keyword); } this->registerListScene->refreshGeometry(); } void TargetRegistersPaneWidget::collapseAllRegisterGroups() { - for (auto& registerGroupItem : this->registerGroupItems) { - registerGroupItem->setExpanded(false); + for (auto& registerGroupItem : this->peripheralItems) { + registerGroupItem->setAllExpanded(false); } this->registerListScene->refreshGeometry(); } void TargetRegistersPaneWidget::expandAllRegisterGroups() { - for (auto& registerGroupItem : this->registerGroupItems) { - registerGroupItem->setExpanded(true); + for (auto& registerGroupItem : this->peripheralItems) { + registerGroupItem->setAllExpanded(true); } this->registerListScene->refreshGeometry(); } void TargetRegistersPaneWidget::refreshRegisterValues( - std::optional registerDescriptorId, + std::optional> registerDescriptor, std::optional> callback ) { - if (!registerDescriptorId.has_value() && this->registerDescriptors.empty()) { + if (!registerDescriptor.has_value() && this->flattenedRegisterDescriptors.empty()) { return; } - auto descriptorIds = Targets::TargetRegisterDescriptorIds(); - - if (registerDescriptorId.has_value()) { - descriptorIds.insert(*registerDescriptorId); - - } else { - std::transform( - this->registerDescriptors.begin(), - this->registerDescriptors.end(), - std::inserter(descriptorIds, descriptorIds.end()), - [] (const Targets::TargetRegisterDescriptor& descriptor) { - return descriptor.id; - } - ); - } - - const auto readRegisterTask = QSharedPointer( - new ReadTargetRegisters(descriptorIds), + const auto readRegisterTask = QSharedPointer{ + new ReadTargetRegisters{ + registerDescriptor.has_value() + ? Targets::TargetRegisterDescriptors{&(registerDescriptor->get())} + : this->flattenedRegisterDescriptors + }, &QObject::deleteLater - ); + }; QObject::connect( readRegisterTask.get(), @@ -324,11 +291,20 @@ namespace Widgets } void TargetRegistersPaneWidget::onItemDoubleClicked(ListItem* clickedItem) { + auto* peripheralItem = dynamic_cast(clickedItem); + + if (peripheralItem != nullptr) { + peripheralItem->setExpanded(!peripheralItem->isExpanded()); + this->registerListScene->refreshGeometry(); + return; + } + auto* registerGroupItem = dynamic_cast(clickedItem); if (registerGroupItem != nullptr) { registerGroupItem->setExpanded(!registerGroupItem->isExpanded()); this->registerListScene->refreshGeometry(); + return; } auto* registerItem = dynamic_cast(clickedItem); @@ -347,70 +323,59 @@ namespace Widgets this->contextMenuRegisterItem = registerItem; - auto* menu = new QMenu(this); - menu->addAction(this->openInspectionWindowAction); - menu->addAction(this->refreshValueAction); - menu->addSeparator(); - - auto* copyMenu = new QMenu("Copy", this); - copyMenu->addAction(this->copyNameAction); - copyMenu->addSeparator(); - copyMenu->addAction(this->copyValueDecimalAction); - copyMenu->addAction(this->copyValueHexAction); - copyMenu->addAction(this->copyValueBinaryAction); - - menu->addMenu(copyMenu); - this->openInspectionWindowAction->setEnabled( TargetRegisterInspectorWindow::registerSupported(this->contextMenuRegisterItem->registerDescriptor) ); - const auto targetStopped = this->targetState == Targets::TargetState::STOPPED; - const auto targetStoppedAndValuePresent = targetStopped - && this->currentRegisterValuesByDescriptorId.contains(this->contextMenuRegisterItem->registerDescriptor.id); + const auto targetStopped = this->targetState.executionState == Targets::TargetExecutionState::STOPPED; + const auto valuePresent = this->currentRegisterValuesByRegisterId.contains( + this->contextMenuRegisterItem->registerDescriptor.id + ); this->refreshValueAction->setEnabled(targetStopped); - this->copyValueDecimalAction->setEnabled(targetStoppedAndValuePresent); - this->copyValueHexAction->setEnabled(targetStoppedAndValuePresent); - this->copyValueBinaryAction->setEnabled(targetStoppedAndValuePresent); + this->copyValueDecimalAction->setEnabled(targetStopped && valuePresent); + this->copyValueHexAction->setEnabled(targetStopped && valuePresent); + this->copyValueBinaryAction->setEnabled(targetStopped && valuePresent); - menu->exec(sourcePosition); + this->contextMenu->exec(sourcePosition); } - void TargetRegistersPaneWidget::onTargetStateChanged(Targets::TargetState newState) { - if (this->targetState == newState) { + void TargetRegistersPaneWidget::onTargetStateChanged( + const Targets::TargetState& newState, + const Targets::TargetState& previousState + ) { + if (previousState.executionState == newState.executionState) { return; } - this->targetState = newState; - - if (this->targetState != Targets::TargetState::STOPPED) { + if (this->targetState.executionState != Targets::TargetExecutionState ::STOPPED) { this->clearInlineRegisterValues(); } } - void TargetRegistersPaneWidget::onRegistersRead(const Targets::TargetRegisters& registers) { - for (const auto& targetRegister : registers) { - const auto& previousValueIt = this->currentRegisterValuesByDescriptorId.find(targetRegister.descriptorId); - const auto& registerItemIt = this->registerItemsByDescriptorId.find(targetRegister.descriptorId); + void TargetRegistersPaneWidget::onRegistersRead( + const Targets::TargetRegisterDescriptorAndValuePairs& registerPairs + ) { + for (const auto& [descriptor, value] : registerPairs) { + const auto& previousValueIt = this->currentRegisterValuesByRegisterId.find(descriptor.id); + const auto& registerItemIt = this->flattenedRegisterItemsByRegisterId.find(descriptor.id); - if (registerItemIt != this->registerItemsByDescriptorId.end()) { + if (registerItemIt != this->flattenedRegisterItemsByRegisterId.end()) { auto& registerItem = registerItemIt->second; - registerItem->setValue(targetRegister.value); - registerItem->valueChanged = previousValueIt != this->currentRegisterValuesByDescriptorId.end() - ? previousValueIt->second != targetRegister.value - : false; + registerItem->setValue(value); + registerItem->valueChanged = previousValueIt != this->currentRegisterValuesByRegisterId.end() + && previousValueIt->second != value; } - this->currentRegisterValuesByDescriptorId[targetRegister.descriptorId] = targetRegister.value; + this->currentRegisterValuesByRegisterId[descriptor.id] = value; } this->registerListScene->update(); } void TargetRegistersPaneWidget::clearInlineRegisterValues() { - for (auto& [registerDescriptorId, registerItem] : this->registerItemsByDescriptorId) { + for (auto& [registerDescriptorId, registerItem] : this->flattenedRegisterItemsByRegisterId) { registerItem->clearValue(); } @@ -424,26 +389,22 @@ namespace Widgets TargetRegisterInspectorWindow* inspectionWindow = nullptr; - const auto& currentValueIt = this->currentRegisterValuesByDescriptorId.find(registerDescriptor.id); - const auto& inspectionWindowIt = this->inspectionWindowsByDescriptorId.find(registerDescriptor.id); - - if (inspectionWindowIt != this->inspectionWindowsByDescriptorId.end()) { + const auto& inspectionWindowIt = this->inspectionWindowsByRegisterId.find(registerDescriptor.id); + if (inspectionWindowIt != this->inspectionWindowsByRegisterId.end()) { inspectionWindow = inspectionWindowIt->second; } else { - inspectionWindow = new TargetRegisterInspectorWindow( + inspectionWindow = new TargetRegisterInspectorWindow{ registerDescriptor, this->targetState, this - ); + }; - this->inspectionWindowsByDescriptorId.insert(std::pair( - registerDescriptor.id, - inspectionWindow - )); + this->inspectionWindowsByRegisterId.emplace(registerDescriptor.id, inspectionWindow); } - if (currentValueIt != this->currentRegisterValuesByDescriptorId.end()) { + const auto& currentValueIt = this->currentRegisterValuesByRegisterId.find(registerDescriptor.id); + if (currentValueIt != this->currentRegisterValuesByRegisterId.end()) { inspectionWindow->setValue(currentValueIt->second); } @@ -452,53 +413,50 @@ namespace Widgets } void TargetRegistersPaneWidget::copyRegisterName(const TargetRegisterDescriptor& registerDescriptor) { - QApplication::clipboard()->setText(QString::fromStdString(registerDescriptor.name.value_or("")).toUpper()); + QApplication::clipboard()->setText(QString::fromStdString(registerDescriptor.name).toUpper()); } void TargetRegistersPaneWidget::copyRegisterValueHex(const TargetRegisterDescriptor& registerDescriptor) { - const auto& valueIt = this->currentRegisterValuesByDescriptorId.find(registerDescriptor.id); - - if (valueIt == this->currentRegisterValuesByDescriptorId.end()) { + const auto& valueIt = this->currentRegisterValuesByRegisterId.find(registerDescriptor.id); + if (valueIt == this->currentRegisterValuesByRegisterId.end()) { return; } const auto& value = valueIt->second; - const auto valueByteArray = QByteArray( - reinterpret_cast(value.data()), + const auto valueByteArray = QByteArray{ + reinterpret_cast(value.data()), static_cast(value.size()) - ).toHex(); + }.toHex(); - QApplication::clipboard()->setText(QString(valueByteArray).toUpper()); + QApplication::clipboard()->setText(QString{valueByteArray}.toUpper()); } void TargetRegistersPaneWidget::copyRegisterValueDecimal(const TargetRegisterDescriptor& registerDescriptor) { - const auto& valueIt = this->currentRegisterValuesByDescriptorId.find(registerDescriptor.id); - - if (valueIt == this->currentRegisterValuesByDescriptorId.end()) { + const auto& valueIt = this->currentRegisterValuesByRegisterId.find(registerDescriptor.id); + if (valueIt == this->currentRegisterValuesByRegisterId.end()) { return; } const auto& value = valueIt->second; - const auto valueByteArray = QByteArray( - reinterpret_cast(value.data()), + const auto valueByteArray = QByteArray{ + reinterpret_cast(value.data()), static_cast(value.size()) - ).toHex(); + }.toHex(); QApplication::clipboard()->setText(QString::number(valueByteArray.toUInt(nullptr, 16))); } void TargetRegistersPaneWidget::copyRegisterValueBinary(const TargetRegisterDescriptor& registerDescriptor) { - const auto& valueIt = this->currentRegisterValuesByDescriptorId.find(registerDescriptor.id); - - if (valueIt == this->currentRegisterValuesByDescriptorId.end()) { + const auto& valueIt = this->currentRegisterValuesByRegisterId.find(registerDescriptor.id); + if (valueIt == this->currentRegisterValuesByRegisterId.end()) { return; } const auto& value = valueIt->second; - const auto valueByteArray = QByteArray( - reinterpret_cast(value.data()), + const auto valueByteArray = QByteArray{ + reinterpret_cast(value.data()), static_cast(value.size()) - ).toHex(); + }.toHex(); auto bitString = QString::number(valueByteArray.toUInt(nullptr, 16), 2); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.hpp index b91fbc8f..0281e147 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.hpp @@ -10,12 +10,14 @@ #include #include #include +#include #include "src/Insight/UserInterfaces/InsightWindow/Widgets/PaneWidget.hpp" #include "src/Insight/UserInterfaces/InsightWindow/Widgets/PanelWidget.hpp" -#include "RegisterItem.hpp" +#include "PeripheralItem.hpp" #include "RegisterGroupItem.hpp" +#include "RegisterItem.hpp" #include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/TargetRegisterInspectorWindow.hpp" #include "src/Insight/UserInterfaces/InsightWindow/Widgets/ListView/ListView.hpp" #include "src/Insight/UserInterfaces/InsightWindow/Widgets/SvgToolButton.hpp" @@ -31,6 +33,7 @@ namespace Widgets public: TargetRegistersPaneWidget( const Targets::TargetDescriptor& targetDescriptor, + const Targets::TargetState& targetState, PaneState& paneState, PanelWidget *parent ); @@ -40,7 +43,7 @@ namespace Widgets void expandAllRegisterGroups(); void refreshRegisterValues( - std::optional registerDescriptorId = std::nullopt, + std::optional> registerDescriptor = std::nullopt, std::optional> callback = std::nullopt ); @@ -49,6 +52,7 @@ namespace Widgets private: const Targets::TargetDescriptor& targetDescriptor; + const Targets::TargetState& targetState; QWidget* container = nullptr; @@ -60,28 +64,29 @@ namespace Widgets ListView* registerListView = nullptr; ListScene* registerListScene = nullptr; - Targets::TargetRegisterDescriptors registerDescriptors; - std::vector registerGroupItems; - std::unordered_map registerItemsByDescriptorId; - std::unordered_map inspectionWindowsByDescriptorId; - std::unordered_map currentRegisterValuesByDescriptorId; + Targets::TargetRegisterDescriptors flattenedRegisterDescriptors; - Targets::TargetState targetState = Targets::TargetState::UNKNOWN; + std::vector peripheralItems; + std::unordered_map flattenedRegisterItemsByRegisterId; + std::unordered_map inspectionWindowsByRegisterId; + std::unordered_map currentRegisterValuesByRegisterId; - // Context-menu actions - QAction* openInspectionWindowAction = new QAction("Inspect", this); - QAction* refreshValueAction = new QAction("Refresh Value", this); - QAction* copyNameAction = new QAction("Register Name", this); - QAction* copyValueDecimalAction = new QAction("Value as Decimal", this); - QAction* copyValueHexAction = new QAction("...as Hex String", this); - QAction* copyValueBinaryAction = new QAction("...as Binary Bit String", this); + // Context menus and actions + QMenu* contextMenu = new QMenu{this}; + QMenu* copyMenu = new QMenu{"Copy", this}; + QAction* openInspectionWindowAction = new QAction{"Inspect", this}; + QAction* refreshValueAction = new QAction{"Refresh Value", this}; + QAction* copyNameAction = new QAction{"Register Name", this}; + QAction* copyValueDecimalAction = new QAction{"Value as Decimal", this}; + QAction* copyValueHexAction = new QAction{"...as Hex String", this}; + QAction* copyValueBinaryAction = new QAction{"...as Binary Bit String", this}; RegisterItem* contextMenuRegisterItem = nullptr; void onItemDoubleClicked(ListItem* clickedItem); void onItemContextMenu(ListItem* item, QPoint sourcePosition); - void onTargetStateChanged(Targets::TargetState newState); - void onRegistersRead(const Targets::TargetRegisters& registers); + void onTargetStateChanged(const Targets::TargetState& newState, const Targets::TargetState& previousState); + void onRegistersRead(const Targets::TargetRegisterDescriptorAndValuePairs& registerPairs); void clearInlineRegisterValues(); void openInspectionWindow(const Targets::TargetRegisterDescriptor& registerDescriptor); void copyRegisterName(const Targets::TargetRegisterDescriptor& registerDescriptor); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/BodyWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/BodyWidget.cpp index 5d385b8a..5364c3d8 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/BodyWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/BodyWidget.cpp @@ -2,7 +2,9 @@ namespace Widgets::InsightTargetWidgets::Dip { - BodyWidget::BodyWidget(QWidget* parent, std::size_t pinCount): QWidget(parent) { + BodyWidget::BodyWidget(QWidget* parent, std::size_t pinCount) + : QWidget(parent) + { this->setObjectName("target-body"); /* @@ -32,7 +34,7 @@ namespace Widgets::InsightTargetWidgets::Dip } void BodyWidget::paintEvent(QPaintEvent* event) { - auto painter = QPainter(this); + auto painter = QPainter{this}; this->drawWidget(painter); } @@ -68,7 +70,7 @@ namespace Widgets::InsightTargetWidgets::Dip this->orientationIndicatorDiameter ); - static const auto backgroundColor = QColor(0x37, 0x38, 0x35); + static const auto backgroundColor = QColor{0x37, 0x38, 0x35}; auto targetBodyColor = this->getBodyColor(); if (!this->isEnabled()) { diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/BodyWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/BodyWidget.hpp index 49a41d4e..81bf2a51 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/BodyWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/BodyWidget.hpp @@ -41,7 +41,7 @@ namespace Widgets::InsightTargetWidgets::Dip static constexpr int MINIMUM_FIRST_PIN_INDICATOR_HEIGHT = 12; // These properties can be modified via Qt style sheets (see Stylesheets/DualInlinePackage.qss) - QColor bodyColor = QColor("#8E8B83"); + QColor bodyColor = {"#8E8B83"}; int disableAlphaLevel = 100; int firstPinIndicatorDiameter = 14; int orientationIndicatorDiameter = 16; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/DualInlinePackageWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/DualInlinePackageWidget.cpp index 3cd29d9e..918c70eb 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/DualInlinePackageWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/DualInlinePackageWidget.cpp @@ -10,50 +10,69 @@ namespace Widgets::InsightTargetWidgets::Dip { - using Targets::TargetVariant; - DualInlinePackageWidget::DualInlinePackageWidget( - const TargetVariant& targetVariant, + const Targets::TargetVariantDescriptor& variantDescriptor, + const Targets::TargetPinoutDescriptor& pinoutDescriptor, + const Targets::TargetDescriptor& targetDescriptor, + const Targets::TargetState& targetState, QWidget* parent ) - : TargetPackageWidget(targetVariant, parent) + : TargetPackageWidget( + variantDescriptor, + pinoutDescriptor, + targetState, + parent + ) { - auto stylesheetFile = QFile(QString::fromStdString( - Services::PathService::compiledResourcesPath() + auto stylesheetFile = QFile{QString::fromStdString( + Services::PathService::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/Stylesheets/" "DualInlinePackage.qss" ) - ); + }; stylesheetFile.open(QFile::ReadOnly); this->setStyleSheet(stylesheetFile.readAll()); - this->pinWidgets.reserve(targetVariant.pinDescriptorsByNumber.size()); - this->layout = new QVBoxLayout(); + this->pinWidgets.reserve(this->pinoutDescriptor.pinDescriptors.size()); + this->layout = new QVBoxLayout{}; this->layout->setSpacing(PinWidget::WIDTH_SPACING); this->layout->setContentsMargins(0, 0, 0, 0); this->layout->setAlignment(Qt::AlignmentFlag::AlignVCenter); - this->topPinLayout = new QHBoxLayout(); + this->topPinLayout = new QHBoxLayout{}; this->topPinLayout->setSpacing(PinWidget::WIDTH_SPACING); this->topPinLayout->setDirection(QBoxLayout::Direction::RightToLeft); this->topPinLayout->setAlignment(Qt::AlignmentFlag::AlignHCenter); - this->bottomPinLayout = new QHBoxLayout(); + this->bottomPinLayout = new QHBoxLayout{}; this->bottomPinLayout->setSpacing(PinWidget::WIDTH_SPACING); this->bottomPinLayout->setAlignment(Qt::AlignmentFlag::AlignHCenter); - for (const auto& [targetPinNumber, targetPinDescriptor]: targetVariant.pinDescriptorsByNumber) { - auto* pinWidget = new PinWidget(targetPinDescriptor, targetVariant, this); + for (const auto& pinDescriptor : this->pinoutDescriptor.pinDescriptors) { + auto* pinWidget = new PinWidget{ + pinDescriptor, + pinDescriptor.padKey.has_value() + ? targetDescriptor.tryGetPadDescriptor(*(pinDescriptor.padKey)) + : std::nullopt, + this->pinoutDescriptor, + this + }; this->pinWidgets.push_back(pinWidget); - TargetPackageWidget::pinWidgets.push_back(pinWidget); + TargetPackageWidget::pinWidgetsByPosition.emplace(pinDescriptor.numericPosition, pinWidget); - if (targetPinNumber <= (targetVariant.pinDescriptorsByNumber.size() / 2)) { + if (pinWidget->padDescriptor.has_value()) { + const auto& padDescriptor = pinWidget->padDescriptor->get(); + TargetPackageWidget::pinWidgetsByPadId.emplace(padDescriptor.id, pinWidget); + TargetPackageWidget::padDescriptors.push_back(&padDescriptor); + } + + if (pinDescriptor.numericPosition <= (this->pinoutDescriptor.pinDescriptors.size() / 2)) { this->bottomPinLayout->addWidget(pinWidget, 0, Qt::AlignmentFlag::AlignHCenter); } else { this->topPinLayout->addWidget(pinWidget, 0, Qt::AlignmentFlag::AlignHCenter); } } - this->bodyWidget = new BodyWidget(this, targetVariant.pinDescriptorsByNumber.size()); + this->bodyWidget = new BodyWidget{this, this->pinoutDescriptor.pinDescriptors.size()}; this->layout->addLayout(this->topPinLayout); this->layout->addWidget(this->bodyWidget, 0, Qt::AlignmentFlag::AlignVCenter); @@ -80,7 +99,7 @@ namespace Widgets::InsightTargetWidgets::Dip ) ) * 2) + bodyWidgetHeight; - this->topPinLayout->setGeometry(QRect(0, 0, width, PinWidget::MAXIMUM_HEIGHT)); + this->topPinLayout->setGeometry(QRect{0, 0, width, PinWidget::MAXIMUM_HEIGHT}); this->bottomPinLayout->setGeometry( QRect( 0, @@ -103,30 +122,28 @@ namespace Widgets::InsightTargetWidgets::Dip } void DualInlinePackageWidget::paintEvent(QPaintEvent* event) { - auto painter = QPainter(this); + auto painter = QPainter{this}; this->drawWidget(painter); } void DualInlinePackageWidget::drawWidget(QPainter& painter) { - using Targets::TargetPinState; + using Targets::TargetGpioPadState; - static auto pinNameFont = QFont("'Ubuntu', sans-serif"); + static auto pinNameFont = QFont{"'Ubuntu', sans-serif"}; static auto pinDirectionFont = pinNameFont; pinNameFont.setPixelSize(11); pinDirectionFont.setPixelSize(10); - static const auto lineColor = QColor(0x4F, 0x4F, 0x4F); - static const auto pinNameFontColor = QColor(0xA6, 0xA7, 0xAA); - static const auto pinDirectionFontColor = QColor(0x8A, 0x8A, 0x8D); - static const auto pinChangedFontColor = QColor(0x4D, 0x7B, 0xBA); + static const auto lineColor = QColor{0x4F, 0x4F, 0x4F}; + static const auto pinNameFontColor = QColor{0xA6, 0xA7, 0xAA}; + static const auto pinDirectionFontColor = QColor{0x8A, 0x8A, 0x8D}; + static const auto pinChangedFontColor = QColor{0x4D, 0x7B, 0xBA}; - static const auto inDirectionText = QString("IN"); - static const auto outDirectionText = QString("OUT"); + static const auto inDirectionText = QString{"IN"}; + static const auto outDirectionText = QString{"OUT"}; for (const auto* pinWidget : this->pinWidgets) { const auto pinGeoPosition = pinWidget->pos(); - const auto& pinState = pinWidget->getPinState(); - const auto pinStateChanged = pinWidget->hasPinStateChanged(); painter.setFont(pinNameFont); @@ -148,7 +165,7 @@ namespace Widgets::InsightTargetWidgets::Dip pinGeoPosition.y() )); - painter.setPen(pinStateChanged ? pinChangedFontColor : pinNameFontColor); + painter.setPen(pinWidget->padStateChanged ? pinChangedFontColor : pinNameFontColor); painter.drawText( QRect( pinGeoPosition.x() + (PinWidget::MINIMUM_WIDTH / 2) @@ -161,7 +178,7 @@ namespace Widgets::InsightTargetWidgets::Dip pinWidget->pinNameLabelText ); - if (pinState.has_value() && pinState->ioDirection.has_value()) { + if (pinWidget->padState.has_value()) { painter.setFont(pinDirectionFont); painter.setPen(lineColor); @@ -184,7 +201,9 @@ namespace Widgets::InsightTargetWidgets::Dip PinWidget::MAXIMUM_LABEL_HEIGHT ), Qt::AlignCenter, - pinState->ioDirection == TargetPinState::IoDirection::INPUT ? inDirectionText : outDirectionText + pinWidget->padState->direction == TargetGpioPadState::DataDirection::INPUT + ? inDirectionText + : outDirectionText ); } @@ -206,7 +225,7 @@ namespace Widgets::InsightTargetWidgets::Dip pinGeoPosition.y() + PinWidget::MAXIMUM_HEIGHT + pinNameLabelLineLength )); - painter.setPen(pinStateChanged ? pinChangedFontColor : pinNameFontColor); + painter.setPen(pinWidget->padStateChanged ? pinChangedFontColor : pinNameFontColor); painter.drawText( QRect( pinGeoPosition.x() + (PinWidget::MINIMUM_WIDTH / 2) @@ -219,7 +238,7 @@ namespace Widgets::InsightTargetWidgets::Dip pinWidget->pinNameLabelText ); - if (pinState.has_value() && pinState->ioDirection.has_value()) { + if (pinWidget->padState.has_value()) { painter.setFont(pinDirectionFont); painter.setPen(lineColor); @@ -243,7 +262,9 @@ namespace Widgets::InsightTargetWidgets::Dip PinWidget::MAXIMUM_LABEL_HEIGHT ), Qt::AlignCenter, - pinState->ioDirection == TargetPinState::IoDirection::INPUT ? inDirectionText : outDirectionText + pinWidget->padState->direction == TargetGpioPadState::DataDirection::INPUT + ? inDirectionText + : outDirectionText ); } } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/DualInlinePackageWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/DualInlinePackageWidget.hpp index f3968579..8f5a8258 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/DualInlinePackageWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/DualInlinePackageWidget.hpp @@ -12,6 +12,8 @@ #include "PinWidget.hpp" #include "BodyWidget.hpp" +#include "src/Targets/TargetDescriptor.hpp" + namespace Widgets::InsightTargetWidgets::Dip { /** @@ -23,7 +25,10 @@ namespace Widgets::InsightTargetWidgets::Dip public: DualInlinePackageWidget( - const Targets::TargetVariant& targetVariant, + const Targets::TargetVariantDescriptor& variantDescriptor, + const Targets::TargetPinoutDescriptor& pinoutDescriptor, + const Targets::TargetDescriptor& targetDescriptor, + const Targets::TargetState& targetState, QWidget* parent ); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinBodyWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinBodyWidget.cpp index fceb1022..8e3579ac 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinBodyWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinBodyWidget.cpp @@ -6,13 +6,22 @@ namespace Widgets::InsightTargetWidgets::Dip { using namespace Targets; - PinBodyWidget::PinBodyWidget(QWidget* parent, Targets::TargetPinDescriptor pinDescriptor) - : TargetPinBodyWidget(parent, std::move(pinDescriptor)) { + PinBodyWidget::PinBodyWidget( + const Targets::TargetPinDescriptor& pinDescriptor, + std::optional> padDescriptor, + QWidget* parent + ) + : TargetPinBodyWidget( + pinDescriptor, + padDescriptor, + parent + ) + { this->setFixedSize(PinBodyWidget::WIDTH, PinBodyWidget::HEIGHT); } void PinBodyWidget::paintEvent(QPaintEvent* event) { - auto painter = QPainter(this); + auto painter = QPainter{this}; this->drawWidget(painter); } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinBodyWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinBodyWidget.hpp index 1deb5444..c8eccc83 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinBodyWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinBodyWidget.hpp @@ -17,7 +17,11 @@ namespace Widgets::InsightTargetWidgets::Dip static const int WIDTH = 19; static const int HEIGHT = 28; - PinBodyWidget(QWidget* parent, Targets::TargetPinDescriptor pinDescriptor); + PinBodyWidget( + const Targets::TargetPinDescriptor& pinDescriptor, + std::optional> padDescriptor, + QWidget* parent + ); protected: void paintEvent(QPaintEvent* event) override; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinWidget.cpp index 280e3c9b..2894c2f8 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinWidget.cpp @@ -6,19 +6,25 @@ namespace Widgets::InsightTargetWidgets::Dip PinWidget::PinWidget( const TargetPinDescriptor& pinDescriptor, - const TargetVariant& targetVariant, + std::optional> padDescriptor, + const Targets::TargetPinoutDescriptor& pinoutDescriptor, QWidget* parent ) - : TargetPinWidget(pinDescriptor, targetVariant, parent) + : TargetPinWidget( + pinDescriptor, + padDescriptor, + pinoutDescriptor, + parent + ) { this->setFixedSize(PinWidget::MINIMUM_WIDTH, PinWidget::MAXIMUM_HEIGHT); - this->layout = new QVBoxLayout(); + this->layout = new QVBoxLayout{}; this->layout->setContentsMargins(0, 0, 0, 0); this->layout->setSpacing(0); - this->bodyWidget = new PinBodyWidget(this, this->pinDescriptor); - this->position = (pinDescriptor.number > (targetVariant.pinDescriptorsByNumber.size() / 2)) + this->bodyWidget = new PinBodyWidget{this->pinDescriptor, padDescriptor, this}; + this->position = (pinDescriptor.numericPosition > (pinoutDescriptor.pinDescriptors.size() / 2)) ? Position::TOP : Position::BOTTOM; const bool isTopWidget = this->position == Position::TOP; @@ -26,12 +32,14 @@ namespace Widgets::InsightTargetWidgets::Dip this->layout->setAlignment(isTopWidget ? (Qt::AlignmentFlag::AlignHCenter | Qt::AlignmentFlag::AlignBottom) : (Qt::AlignmentFlag::AlignHCenter | Qt::AlignmentFlag::AlignTop)); - this->pinNameLabelText = QString::fromStdString(pinDescriptor.name).toUpper(); + this->pinNameLabelText = QString::fromStdString( + this->padDescriptor.has_value() ? padDescriptor->get().name : "NC" + ); this->pinNameLabelText.truncate(5); - this->pinNumberLabel = new Label(this); + this->pinNumberLabel = new Label{this}; this->pinNumberLabel->setObjectName("target-pin-number"); - this->pinNumberLabel->setText(QString::number(pinDescriptor.number)); + this->pinNumberLabel->setText(QString::number(pinDescriptor.numericPosition)); this->pinNumberLabel->setAlignment(Qt::AlignmentFlag::AlignCenter); if (isTopWidget) { diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinWidget.hpp index 43a10de1..40d767ff 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinWidget.hpp @@ -41,15 +41,16 @@ namespace Widgets::InsightTargetWidgets::Dip PinWidget( const Targets::TargetPinDescriptor& pinDescriptor, - const Targets::TargetVariant& targetVariant, + std::optional> padDescriptor, + const Targets::TargetPinoutDescriptor& pinoutDescriptor, QWidget* parent ); - void updatePinState(const Targets::TargetPinState& pinState) override { - TargetPinWidget::updatePinState(pinState); + void updatePadState(const Targets::TargetGpioPadState& padState) override { + TargetPinWidget::updatePadState(padState); if (this->bodyWidget != nullptr) { - this->bodyWidget->setPinState(pinState); + this->bodyWidget->setPadState(padState); } } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/BodyWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/BodyWidget.cpp index 47e0cf72..086dddd4 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/BodyWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/BodyWidget.cpp @@ -5,7 +5,7 @@ namespace Widgets::InsightTargetWidgets::Qfp { void BodyWidget::paintEvent(QPaintEvent* event) { - auto painter = QPainter(this); + auto painter = QPainter{this}; this->drawWidget(painter); } @@ -16,7 +16,7 @@ namespace Widgets::InsightTargetWidgets::Qfp ); auto targetBodyColor = this->getBodyColor(); - auto backgroundColor = QColor("#373835"); + auto backgroundColor = QColor{"#373835"}; if (!this->isEnabled()) { targetBodyColor.setAlpha(this->getDisableAlphaLevel()); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/BodyWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/BodyWidget.hpp index a278e942..34ef8d50 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/BodyWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/BodyWidget.hpp @@ -37,7 +37,7 @@ namespace Widgets::InsightTargetWidgets::Qfp private: // These properties can be modified via Qt style sheets (see Stylesheets/QuadFlatPackage.qss) - QColor bodyColor = QColor("#8E8B83"); + QColor bodyColor = {"#8E8B83"}; int disableAlphaLevel = 100; }; } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/PinBodyWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/PinBodyWidget.cpp index ca025038..3517b072 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/PinBodyWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/PinBodyWidget.cpp @@ -7,8 +7,19 @@ namespace Widgets::InsightTargetWidgets::Qfp { using namespace Targets; - PinBodyWidget::PinBodyWidget(QWidget* parent, Targets::TargetPinDescriptor pinDescriptor, bool isVertical) - : TargetPinBodyWidget(parent, std::move(pinDescriptor)), isVertical(isVertical) { + PinBodyWidget::PinBodyWidget( + const Targets::TargetPinDescriptor& pinDescriptor, + std::optional> padDescriptor, + bool isVertical, + QWidget* parent + ) + : TargetPinBodyWidget( + pinDescriptor, + padDescriptor, + parent + ) + , isVertical(isVertical) + { if (isVertical) { this->setFixedSize(PinBodyWidget::WIDTH, PinBodyWidget::HEIGHT); @@ -18,7 +29,7 @@ namespace Widgets::InsightTargetWidgets::Qfp } void PinBodyWidget::paintEvent(QPaintEvent* event) { - auto painter = QPainter(this); + auto painter = QPainter{this}; this->drawWidget(painter); } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/PinBodyWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/PinBodyWidget.hpp index 0e2b49fe..d1445b6b 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/PinBodyWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/PinBodyWidget.hpp @@ -18,7 +18,12 @@ namespace Widgets::InsightTargetWidgets::Qfp static const int WIDTH = 17; static const int HEIGHT = 26; - PinBodyWidget(QWidget* parent, Targets::TargetPinDescriptor pinDescriptor, bool isVertical); + PinBodyWidget( + const Targets::TargetPinDescriptor& pinDescriptor, + std::optional> padDescriptor, + bool isVertical, + QWidget* parent + ); protected: void paintEvent(QPaintEvent* event) override; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/PinWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/PinWidget.cpp index e7d9a0fb..0a17c67a 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/PinWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/PinWidget.cpp @@ -12,43 +12,55 @@ namespace Widgets::InsightTargetWidgets::Qfp using namespace Targets; PinWidget::PinWidget( - const TargetPinDescriptor& pinDescriptor, - const TargetVariant& targetVariant, + const Targets::TargetPinDescriptor& pinDescriptor, + std::optional> padDescriptor, + const Targets::TargetPinoutDescriptor& pinoutDescriptor, QWidget* parent - ): TargetPinWidget(pinDescriptor, targetVariant, parent) { - this->layout = new QBoxLayout(QBoxLayout::TopToBottom); + ) + : TargetPinWidget( + pinDescriptor, + padDescriptor, + pinoutDescriptor, + parent + ) + { + this->layout = new QBoxLayout{QBoxLayout::TopToBottom}; this->layout->setContentsMargins(0, 0, 0, 0); this->layout->setSpacing(0); + const auto pinNumber = pinDescriptor.numericPosition; - auto pinCountPerLayout = (targetVariant.pinDescriptorsByNumber.size() / 4); + auto pinCountPerLayout = (pinoutDescriptor.pinDescriptors.size() / 4); - if (pinDescriptor.number <= pinCountPerLayout) { + if (pinNumber <= pinCountPerLayout) { this->position = Position::LEFT; - } else if (pinDescriptor.number > pinCountPerLayout && pinDescriptor.number <= (pinCountPerLayout * 2)) { + } else if (pinNumber > pinCountPerLayout && pinNumber <= (pinCountPerLayout * 2)) { this->position = Position::BOTTOM; - } else if (pinDescriptor.number > (pinCountPerLayout * 2) && pinDescriptor.number <= (pinCountPerLayout * 3)) { + } else if (pinNumber > (pinCountPerLayout * 2) && pinNumber <= (pinCountPerLayout * 3)) { this->position = Position::RIGHT; - } else if (pinDescriptor.number > (pinCountPerLayout * 3) && pinDescriptor.number <= (pinCountPerLayout * 4)) { + } else if (pinNumber > (pinCountPerLayout * 3) && pinNumber <= (pinCountPerLayout * 4)) { this->position = Position::TOP; } - this->bodyWidget = new PinBodyWidget( - this, + this->bodyWidget = new PinBodyWidget{ this->pinDescriptor, - (this->position == Position::TOP || this->position == Position::BOTTOM) - ); + padDescriptor, + (this->position == Position::TOP || this->position == Position::BOTTOM), + this + }; - this->pinNameLabelText = QString::fromStdString(pinDescriptor.name).toUpper(); + this->pinNameLabelText = QString::fromStdString( + this->padDescriptor.has_value() ? padDescriptor->get().name : "NC" + ); this->pinNameLabelText.truncate(5); - this->pinNumberLabel = new Label(this); + this->pinNumberLabel = new Label{this}; this->pinNumberLabel->setObjectName("target-pin-number"); - auto pinNumberText = QString::number(pinDescriptor.number); + auto pinNumberText = QString::number(pinNumber); pinNumberText.truncate(5); - this->pinNumberLabel->setText(QString::number(pinDescriptor.number)); + this->pinNumberLabel->setText(QString::number(pinNumber)); this->pinNumberLabel->setAlignment(Qt::AlignmentFlag::AlignCenter); if (this->position == Position::LEFT) { @@ -92,11 +104,11 @@ namespace Widgets::InsightTargetWidgets::Qfp connect(this->bodyWidget, &PinBodyWidget::clicked, this, &TargetPinWidget::onWidgetBodyClicked); } - void PinWidget::updatePinState(const Targets::TargetPinState& pinState) { - TargetPinWidget::updatePinState(pinState); + void PinWidget::updatePadState(const Targets::TargetGpioPadState& padState) { + TargetPinWidget::updatePadState(padState); if (this->bodyWidget != nullptr) { - this->bodyWidget->setPinState(pinState); + this->bodyWidget->setPadState(padState); } } } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/PinWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/PinWidget.hpp index c2b4df1f..7b2acad5 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/PinWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/PinWidget.hpp @@ -46,11 +46,12 @@ namespace Widgets::InsightTargetWidgets::Qfp PinWidget( const Targets::TargetPinDescriptor& pinDescriptor, - const Targets::TargetVariant& targetVariant, + std::optional> padDescriptor, + const Targets::TargetPinoutDescriptor& pinoutDescriptor, QWidget* parent ); - void updatePinState(const Targets::TargetPinState& pinState) override; + void updatePadState(const Targets::TargetGpioPadState& padState) override; private: QBoxLayout* layout = nullptr; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/QuadFlatPackageWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/QuadFlatPackageWidget.cpp index 4b97d305..6f2f16cb 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/QuadFlatPackageWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/QuadFlatPackageWidget.cpp @@ -16,30 +16,40 @@ namespace Widgets::InsightTargetWidgets::Qfp using namespace Targets; QuadFlatPackageWidget::QuadFlatPackageWidget( - const TargetVariant& targetVariant, + const Targets::TargetVariantDescriptor& variantDescriptor, + const Targets::TargetPinoutDescriptor& pinoutDescriptor, + const Targets::TargetDescriptor& targetDescriptor, + const Targets::TargetState& targetState, QWidget* parent - ): TargetPackageWidget(targetVariant, parent) { - assert((targetVariant.pinDescriptorsByNumber.size() % 4) == 0); + ) + : TargetPackageWidget( + variantDescriptor, + pinoutDescriptor, + targetState, + parent + ) + { + assert((this->pinoutDescriptor.pinDescriptors.size() % 4) == 0); - auto stylesheetFile = QFile(QString::fromStdString( + auto stylesheetFile = QFile{QString::fromStdString( Services::PathService::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/Stylesheets/QuadFlatPackage.qss" ) - ); + }; stylesheetFile.open(QFile::ReadOnly); this->setStyleSheet(stylesheetFile.readAll()); - this->pinWidgets.reserve(targetVariant.pinDescriptorsByNumber.size()); - this->layout = new QVBoxLayout(); + this->pinWidgets.reserve(this->pinoutDescriptor.pinDescriptors.size()); + this->layout = new QVBoxLayout{}; this->layout->setSpacing(0); this->layout->setContentsMargins(0, 0, 0, 0); - this->horizontalLayout = new QHBoxLayout(); + this->horizontalLayout = new QHBoxLayout{}; this->horizontalLayout->setSpacing(0); this->horizontalLayout->setDirection(QBoxLayout::Direction::LeftToRight); this->horizontalLayout->setAlignment(Qt::AlignmentFlag::AlignHCenter); - this->topPinLayout = new QHBoxLayout(); + this->topPinLayout = new QHBoxLayout{}; this->topPinLayout->setSpacing(PinWidget::WIDTH_SPACING); this->topPinLayout->setDirection(QBoxLayout::Direction::RightToLeft); this->topPinLayout->setAlignment(Qt::AlignmentFlag::AlignHCenter); @@ -49,21 +59,34 @@ namespace Widgets::InsightTargetWidgets::Qfp this->rightPinLayout->setDirection(QBoxLayout::Direction::BottomToTop); this->rightPinLayout->setAlignment(Qt::AlignmentFlag::AlignVCenter); - this->bottomPinLayout = new QHBoxLayout(); + this->bottomPinLayout = new QHBoxLayout{}; this->bottomPinLayout->setSpacing(PinWidget::WIDTH_SPACING); this->bottomPinLayout->setDirection(QBoxLayout::Direction::LeftToRight); this->bottomPinLayout->setAlignment(Qt::AlignmentFlag::AlignHCenter); - this->leftPinLayout = new QVBoxLayout(); + this->leftPinLayout = new QVBoxLayout{}; this->leftPinLayout->setSpacing(PinWidget::WIDTH_SPACING); this->leftPinLayout->setDirection(QBoxLayout::Direction::TopToBottom); this->leftPinLayout->setAlignment(Qt::AlignmentFlag::AlignVCenter); - const auto pinCountPerLayout = static_cast(targetVariant.pinDescriptorsByNumber.size() / 4); - for (const auto& [targetPinNumber, targetPinDescriptor]: targetVariant.pinDescriptorsByNumber) { - auto* pinWidget = new PinWidget(targetPinDescriptor, targetVariant, this); + const auto pinCountPerLayout = static_cast(this->pinoutDescriptor.pinDescriptors.size() / 4); + for (const auto& pinDescriptor: this->pinoutDescriptor.pinDescriptors) { + auto* pinWidget = new PinWidget{ + pinDescriptor, + pinDescriptor.padKey.has_value() + ? targetDescriptor.tryGetPadDescriptor(*(pinDescriptor.padKey)) + : std::nullopt, + this->pinoutDescriptor, + this + }; this->pinWidgets.push_back(pinWidget); - TargetPackageWidget::pinWidgets.push_back(pinWidget); + TargetPackageWidget::pinWidgetsByPosition.emplace(pinDescriptor.numericPosition, pinWidget); + + if (pinWidget->padDescriptor.has_value()) { + const auto& padDescriptor = pinWidget->padDescriptor->get(); + TargetPackageWidget::pinWidgetsByPadId.emplace(padDescriptor.id, pinWidget); + TargetPackageWidget::padDescriptors.push_back(&padDescriptor); + } if (pinWidget->position == Position::LEFT) { this->leftPinLayout->addWidget(pinWidget, 0, Qt::AlignmentFlag::AlignRight); @@ -79,7 +102,7 @@ namespace Widgets::InsightTargetWidgets::Qfp } } - this->bodyWidget = new BodyWidget(this); + this->bodyWidget = new BodyWidget{this}; this->layout->addLayout(this->topPinLayout); this->horizontalLayout->addLayout(this->leftPinLayout); this->horizontalLayout->addWidget(this->bodyWidget); @@ -185,41 +208,41 @@ namespace Widgets::InsightTargetWidgets::Qfp } void QuadFlatPackageWidget::paintEvent(QPaintEvent* event) { - auto painter = QPainter(this); + auto painter = QPainter{this}; this->drawWidget(painter); } void QuadFlatPackageWidget::drawWidget(QPainter& painter) { - static auto pinNameFont = QFont("'Ubuntu', sans-serif"); + static auto pinNameFont = QFont{"'Ubuntu', sans-serif"}; static auto pinDirectionFont = pinNameFont; pinNameFont.setPixelSize(11); pinDirectionFont.setPixelSize(10); - static const auto lineColor = QColor(0x4F, 0x4F, 0x4F); - static const auto pinNameFontColor = QColor(0xA6, 0xA7, 0xAA); - static const auto pinDirectionFontColor = QColor(0x8A, 0x8A, 0x8D); - static const auto pinChangedFontColor = QColor(0x4D, 0x7B, 0xBA); + static const auto lineColor = QColor{0x4F, 0x4F, 0x4F}; + static const auto pinNameFontColor = QColor{0xA6, 0xA7, 0xAA}; + static const auto pinDirectionFontColor = QColor{0x8A, 0x8A, 0x8D}; + static const auto pinChangedFontColor = QColor{0x4D, 0x7B, 0xBA}; - static const auto inDirectionText = QString("IN"); - static const auto outDirectionText = QString("OUT"); + static const auto inDirectionText = QString{"IN"}; + static const auto outDirectionText = QString{"OUT"}; for (const auto* pinWidget : this->pinWidgets) { const auto pinGeoPosition = pinWidget->pos(); - const auto& pinState = pinWidget->getPinState(); - const auto pinStateChanged = pinWidget->hasPinStateChanged(); + const auto& padState = pinWidget->getPadState(); + const auto padStateChanged = pinWidget->hasPadStateChanged(); painter.setFont(pinNameFont); if (pinWidget->position == Position::LEFT) { painter.setPen(lineColor); - painter.drawLine(QLine( + painter.drawLine(QLine{ pinGeoPosition.x() - PinWidget::PIN_NAME_LABEL_LONG_LINE_LENGTH, pinGeoPosition.y() + (PinWidget::MAXIMUM_HORIZONTAL_HEIGHT / 2), pinGeoPosition.x(), pinGeoPosition.y() + (PinWidget::MAXIMUM_HORIZONTAL_HEIGHT / 2) - )); + }); - painter.setPen(pinStateChanged ? pinChangedFontColor : pinNameFontColor); + painter.setPen(padStateChanged ? pinChangedFontColor : pinNameFontColor); painter.drawText( QRect( pinGeoPosition.x() - PinWidget::PIN_NAME_LABEL_LONG_LINE_LENGTH @@ -233,7 +256,7 @@ namespace Widgets::InsightTargetWidgets::Qfp pinWidget->pinNameLabelText ); - if (pinState.has_value() && pinState->ioDirection.has_value()) { + if (padState.has_value()) { painter.setFont(pinDirectionFont); painter.setPen(pinDirectionFontColor); @@ -248,21 +271,23 @@ namespace Widgets::InsightTargetWidgets::Qfp PinWidget::MAXIMUM_LABEL_HEIGHT ), Qt::AlignCenter, - pinState->ioDirection == TargetPinState::IoDirection::INPUT ? inDirectionText : outDirectionText + padState->direction == TargetGpioPadState::DataDirection::INPUT + ? inDirectionText + : outDirectionText ); } } else if (pinWidget->position == Position::RIGHT) { painter.setPen(lineColor); - painter.drawLine(QLine( + painter.drawLine(QLine{ pinGeoPosition.x() + PinWidget::MAXIMUM_HORIZONTAL_WIDTH, pinGeoPosition.y() + (PinWidget::MAXIMUM_VERTICAL_WIDTH / 2), pinGeoPosition.x() + PinWidget::MAXIMUM_HORIZONTAL_WIDTH + PinWidget::PIN_NAME_LABEL_LONG_LINE_LENGTH, pinGeoPosition.y() + (PinWidget::MAXIMUM_VERTICAL_WIDTH / 2) - )); + }); - painter.setPen(pinStateChanged ? pinChangedFontColor : pinNameFontColor); + painter.setPen(padStateChanged ? pinChangedFontColor : pinNameFontColor); painter.drawText( QRect( pinGeoPosition.x() + PinWidget::MAXIMUM_HORIZONTAL_WIDTH @@ -276,7 +301,7 @@ namespace Widgets::InsightTargetWidgets::Qfp pinWidget->pinNameLabelText ); - if (pinState.has_value() && pinState->ioDirection.has_value()) { + if (padState.has_value()) { painter.setFont(pinDirectionFont); painter.setPen(pinDirectionFontColor); @@ -291,7 +316,9 @@ namespace Widgets::InsightTargetWidgets::Qfp PinWidget::MAXIMUM_LABEL_HEIGHT ), Qt::AlignCenter, - pinState->ioDirection == TargetPinState::IoDirection::INPUT ? inDirectionText : outDirectionText + padState->direction == TargetGpioPadState::DataDirection::INPUT + ? inDirectionText + : outDirectionText ); } @@ -306,14 +333,14 @@ namespace Widgets::InsightTargetWidgets::Qfp : PinWidget::PIN_DIRECTION_LABEL_LONG_LINE_LENGTH ); - painter.drawLine(QLine( + painter.drawLine(QLine{ pinGeoPosition.x() + (PinWidget::MAXIMUM_VERTICAL_WIDTH / 2), pinGeoPosition.y() - pinNameLabelLineLength, pinGeoPosition.x() + (PinWidget::MAXIMUM_VERTICAL_WIDTH / 2), pinGeoPosition.y() - )); + }); - painter.setPen(pinStateChanged ? pinChangedFontColor : pinNameFontColor); + painter.setPen(padStateChanged ? pinChangedFontColor : pinNameFontColor); painter.drawText( QRect( pinGeoPosition.x() + (PinWidget::MAXIMUM_VERTICAL_WIDTH / 2) @@ -326,17 +353,17 @@ namespace Widgets::InsightTargetWidgets::Qfp pinWidget->pinNameLabelText ); - if (pinState.has_value() && pinState->ioDirection.has_value()) { + if (padState.has_value()) { painter.setFont(pinDirectionFont); painter.setPen(lineColor); - painter.drawLine(QLine( + painter.drawLine(QLine{ pinGeoPosition.x() + (PinWidget::MAXIMUM_VERTICAL_WIDTH / 2), pinGeoPosition.y() - pinNameLabelLineLength - PinWidget::MAXIMUM_LABEL_HEIGHT - pinDirectionLabelLineLength, pinGeoPosition.x() + (PinWidget::MAXIMUM_VERTICAL_WIDTH / 2), pinGeoPosition.y() - pinNameLabelLineLength - PinWidget::MAXIMUM_LABEL_HEIGHT - )); + }); painter.setPen(pinDirectionFontColor); painter.drawText( @@ -349,7 +376,9 @@ namespace Widgets::InsightTargetWidgets::Qfp PinWidget::MAXIMUM_LABEL_HEIGHT ), Qt::AlignCenter, - pinState->ioDirection == TargetPinState::IoDirection::INPUT ? inDirectionText : outDirectionText + padState->direction == TargetGpioPadState::DataDirection::INPUT + ? inDirectionText + : outDirectionText ); } @@ -364,14 +393,14 @@ namespace Widgets::InsightTargetWidgets::Qfp : PinWidget::PIN_DIRECTION_LABEL_LONG_LINE_LENGTH ); - painter.drawLine(QLine( + painter.drawLine(QLine{ pinGeoPosition.x() + (PinWidget::MAXIMUM_VERTICAL_WIDTH / 2), pinGeoPosition.y() + PinWidget::MAXIMUM_VERTICAL_HEIGHT, pinGeoPosition.x() + (PinWidget::MAXIMUM_VERTICAL_WIDTH / 2), pinGeoPosition.y() + PinWidget::MAXIMUM_VERTICAL_HEIGHT + pinNameLabelLineLength - )); + }); - painter.setPen(pinStateChanged ? pinChangedFontColor : pinNameFontColor); + painter.setPen(padStateChanged ? pinChangedFontColor : pinNameFontColor); painter.drawText( QRect( pinGeoPosition.x() + (PinWidget::MAXIMUM_VERTICAL_WIDTH / 2) @@ -384,18 +413,18 @@ namespace Widgets::InsightTargetWidgets::Qfp pinWidget->pinNameLabelText ); - if (pinState.has_value() && pinState->ioDirection.has_value()) { + if (padState.has_value()) { painter.setFont(pinDirectionFont); painter.setPen(lineColor); - painter.drawLine(QLine( + painter.drawLine(QLine{ pinGeoPosition.x() + (PinWidget::MAXIMUM_VERTICAL_WIDTH / 2), pinGeoPosition.y() + PinWidget::MAXIMUM_VERTICAL_HEIGHT + pinNameLabelLineLength + PinWidget::MAXIMUM_LABEL_HEIGHT, pinGeoPosition.x() + (PinWidget::MAXIMUM_VERTICAL_WIDTH / 2), pinGeoPosition.y() + PinWidget::MAXIMUM_VERTICAL_HEIGHT + pinNameLabelLineLength + PinWidget::MAXIMUM_LABEL_HEIGHT + pinDirectionLabelLineLength - )); + }); painter.setPen(pinDirectionFontColor); painter.drawText( @@ -408,7 +437,9 @@ namespace Widgets::InsightTargetWidgets::Qfp PinWidget::MAXIMUM_LABEL_HEIGHT ), Qt::AlignCenter, - pinState->ioDirection == TargetPinState::IoDirection::INPUT ? inDirectionText : outDirectionText + padState->direction == TargetGpioPadState::DataDirection::INPUT + ? inDirectionText + : outDirectionText ); } } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/QuadFlatPackageWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/QuadFlatPackageWidget.hpp index ae4d9fe0..63c4aff2 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/QuadFlatPackageWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/QuadFlatPackageWidget.hpp @@ -9,6 +9,8 @@ #include "PinWidget.hpp" #include "BodyWidget.hpp" +#include "src/Targets/TargetDescriptor.hpp" + namespace Widgets::InsightTargetWidgets::Qfp { /** @@ -20,7 +22,10 @@ namespace Widgets::InsightTargetWidgets::Qfp public: QuadFlatPackageWidget( - const Targets::TargetVariant& targetVariant, + const Targets::TargetVariantDescriptor& variantDescriptor, + const Targets::TargetPinoutDescriptor& pinoutDescriptor, + const Targets::TargetDescriptor& targetDescriptor, + const Targets::TargetState& targetState, QWidget* parent ); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPackageWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPackageWidget.cpp index c949b5ca..2dcd51c2 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPackageWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPackageWidget.cpp @@ -4,28 +4,26 @@ #include "src/Insight/InsightSignals.hpp" #include "src/Insight/InsightWorker/InsightWorker.hpp" -#include "src/Insight/InsightWorker/Tasks/RefreshTargetPinStates.hpp" +#include "src/Insight/InsightWorker/Tasks/ReadTargetGpioPadStates.hpp" namespace Widgets::InsightTargetWidgets { using Targets::TargetState; + using Targets::TargetExecutionState; TargetPackageWidget::TargetPackageWidget( - Targets::TargetVariant targetVariant, + const Targets::TargetVariantDescriptor& variantDescriptor, + const Targets::TargetPinoutDescriptor& pinoutDescriptor, + const Targets::TargetState& targetState, QWidget* parent ) : QWidget(parent) - , targetVariant(std::move(targetVariant)) + , variantDescriptor(variantDescriptor) + , pinoutDescriptor(pinoutDescriptor) + , targetState(targetState) { auto* insightSignals = InsightSignals::instance(); - QObject::connect( - insightSignals, - &InsightSignals::targetStateUpdated, - this, - &TargetPackageWidget::onTargetStateChanged - ); - QObject::connect( insightSignals, &InsightSignals::programmingModeEnabled, @@ -43,17 +41,17 @@ namespace Widgets::InsightTargetWidgets this->setDisabled(true); } - void TargetPackageWidget::refreshPinStates(std::optional> callback) { - const auto refreshTask = QSharedPointer( - new RefreshTargetPinStates(this->targetVariant.id), + void TargetPackageWidget::refreshPadStates(std::optional> callback) { + const auto refreshTask = QSharedPointer{ + new ReadTargetGpioPadStates{this->padDescriptors}, &QObject::deleteLater - ); + }; QObject::connect( refreshTask.get(), - &RefreshTargetPinStates::targetPinStatesRetrieved, + &ReadTargetGpioPadStates::targetGpioPadStatesRead, this, - &TargetPackageWidget::updatePinStates + &TargetPackageWidget::updatePadStates ); if (callback.has_value()) { @@ -68,34 +66,27 @@ namespace Widgets::InsightTargetWidgets InsightWorker::queueTask(refreshTask); } - void TargetPackageWidget::updatePinStates(const Targets::TargetPinStateMapping& pinStatesByNumber) { - for (auto& pinWidget : this->pinWidgets) { - const auto pinStateIt = pinStatesByNumber.find(pinWidget->getPinNumber()); - - if (pinStateIt != pinStatesByNumber.end()) { - pinWidget->updatePinState(pinStateIt->second); + void TargetPackageWidget::updatePadStates(const Targets::TargetGpioPadDescriptorAndStatePairs& padStatePairs) { + for (const auto& [padDescriptor, padState] : padStatePairs) { + const auto widgetIt = this->pinWidgetsByPadId.find(padDescriptor.id); + if (widgetIt == this->pinWidgetsByPadId.end()) { + continue; } + + widgetIt->second->updatePadState(padState); } this->update(); } - void TargetPackageWidget::onTargetStateChanged(TargetState newState) { - if (this->targetState == newState) { - return; - } - - this->targetState = newState; - } - void TargetPackageWidget::onProgrammingModeEnabled() { - if (this->targetState == TargetState::STOPPED) { + if (this->targetState.executionState == TargetExecutionState::STOPPED) { this->setDisabled(true); } } void TargetPackageWidget::onProgrammingModeDisabled() { - if (this->targetState == TargetState::STOPPED) { + if (this->targetState.executionState == TargetExecutionState::STOPPED) { this->setDisabled(false); } } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPackageWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPackageWidget.hpp index f186abf5..152bae19 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPackageWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPackageWidget.hpp @@ -2,13 +2,17 @@ #include #include -#include -#include +#include #include -#include "TargetPinWidget.hpp" +#include "src/Targets/TargetVariantDescriptor.hpp" +#include "src/Targets/TargetPinoutDescriptor.hpp" +#include "src/Targets/TargetPadDescriptor.hpp" +#include "src/Targets/TargetGpioPadState.hpp" #include "src/Targets/TargetState.hpp" +#include "TargetPinWidget.hpp" + namespace Widgets::InsightTargetWidgets { /** @@ -19,12 +23,13 @@ namespace Widgets::InsightTargetWidgets Q_OBJECT public: - TargetPackageWidget(Targets::TargetVariant targetVariant, QWidget* parent); - virtual void refreshPinStates(std::optional> callback = std::nullopt); - - virtual void setTargetState(Targets::TargetState targetState) { - this->targetState = targetState; - } + TargetPackageWidget( + const Targets::TargetVariantDescriptor& variantDescriptor, + const Targets::TargetPinoutDescriptor& pinoutDescriptor, + const Targets::TargetState& targetState, + QWidget* parent + ); + virtual void refreshPadStates(std::optional> callback = std::nullopt); QSize sizeHint() const override { return this->minimumSize(); @@ -35,13 +40,15 @@ namespace Widgets::InsightTargetWidgets } protected: - Targets::TargetVariant targetVariant; - std::vector pinWidgets; + const Targets::TargetVariantDescriptor& variantDescriptor; + const Targets::TargetPinoutDescriptor& pinoutDescriptor; + const Targets::TargetState& targetState; - Targets::TargetState targetState = Targets::TargetState::UNKNOWN; + std::unordered_map pinWidgetsByPosition; + std::unordered_map pinWidgetsByPadId; + Targets::TargetPadDescriptors padDescriptors; - virtual void updatePinStates(const Targets::TargetPinStateMapping& pinStatesByNumber); - void onTargetStateChanged(Targets::TargetState newState); + virtual void updatePadStates(const Targets::TargetGpioPadDescriptorAndStatePairs& padStatePairs); void onProgrammingModeEnabled(); void onProgrammingModeDisabled(); }; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinBodyWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinBodyWidget.cpp index 48ee7b90..dfb92097 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinBodyWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinBodyWidget.cpp @@ -6,40 +6,57 @@ namespace Widgets::InsightTargetWidgets { using namespace Targets; - TargetPinBodyWidget::TargetPinBodyWidget(QWidget* parent, Targets::TargetPinDescriptor pinDescriptor) - : QWidget(parent), pinDescriptor(std::move(pinDescriptor)) { + TargetPinBodyWidget::TargetPinBodyWidget( + const Targets::TargetPinDescriptor& pinDescriptor, + std::optional> padDescriptor, + QWidget* parent + ) + : QWidget(parent) + , pinDescriptor(pinDescriptor) + , padDescriptor(padDescriptor) + { this->setObjectName("target-pin-body"); - this->setToolTip(QString::fromStdString(this->pinDescriptor.name).toUpper()); + this->setToolTip( + this->padDescriptor.has_value() + ? QString::fromStdString(this->padDescriptor->get().name).toUpper() + : "Not connected" + ); } QColor TargetPinBodyWidget::getBodyColor() { + using Targets::TargetGpioPadState; + auto pinColor = this->defaultBodyColor; - if (this->pinDescriptor.type == TargetPinType::VCC) { - pinColor = this->vccBodyColor; + if (this->padDescriptor.has_value()) { + const auto& padDescriptor = this->padDescriptor->get(); - } else if (this->pinDescriptor.type == TargetPinType::GND) { - pinColor = this->gndBodyColor; + if (padDescriptor.type == TargetPadType::VCC) { + pinColor = this->vccBodyColor; - } else if (this->pinDescriptor.type == TargetPinType::GPIO) { - if (this->pinState.has_value() - && this->pinState->ioState.has_value() - && this->pinState->ioDirection.has_value() - ) { - const auto ioDirection = this->pinState->ioDirection.value(); - const auto ioState = this->pinState->ioState.value(); + } else if (padDescriptor.type == TargetPadType::GND) { + pinColor = this->gndBodyColor; - if (this->pinState->ioState.value() == TargetPinState::IoState::HIGH) { - pinColor = ioDirection == TargetPinState::IoDirection::OUTPUT ? - this->outputHighBodyColor : this->inputHighBodyColor; - } + } else if (padDescriptor.type == TargetPadType::GPIO) { + if (this->padState.has_value()) { + if (this->padState->value == TargetGpioPadState::State::HIGH) { + pinColor = this->padState->direction == TargetGpioPadState::DataDirection::OUTPUT + ? this->outputHighBodyColor + : this->inputHighBodyColor; + } - if (( - ioDirection == TargetPinState::IoDirection::OUTPUT - || (ioDirection == TargetPinState::IoDirection::INPUT && ioState == TargetPinState::IoState::LOW) - ) && !this->hoverActive - ) { - pinColor.setAlpha(220); + if ( + ( + this->padState->direction == TargetGpioPadState::DataDirection::OUTPUT + || ( + this->padState->direction == TargetGpioPadState::DataDirection::INPUT + && this->padState->value == TargetGpioPadState::State::LOW + ) + ) + && !this->hoverActive + ) { + pinColor.setAlpha(220); + } } } } @@ -52,7 +69,7 @@ namespace Widgets::InsightTargetWidgets } bool TargetPinBodyWidget::event(QEvent* event) { - if (this->pinState.has_value() && this->pinState->ioDirection == TargetPinState::IoDirection::OUTPUT) { + if (this->padState.has_value() && this->padState->direction == TargetGpioPadState::DataDirection::OUTPUT) { switch (event->type()) { case QEvent::Enter: { this->hoverActive = true; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinBodyWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinBodyWidget.hpp index ad27d5ab..0da87a9c 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinBodyWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinBodyWidget.hpp @@ -3,8 +3,12 @@ #include #include #include +#include +#include #include "src/Targets/TargetPinDescriptor.hpp" +#include "src/Targets/TargetPadDescriptor.hpp" +#include "src/Targets/TargetGpioPadState.hpp" namespace Widgets::InsightTargetWidgets { @@ -23,10 +27,14 @@ namespace Widgets::InsightTargetWidgets Q_PROPERTY(int disableAlphaLevel READ getDisableAlphaLevel WRITE setDisableAlphaLevel DESIGNABLE true) public: - TargetPinBodyWidget(QWidget* parent, Targets::TargetPinDescriptor pinDescriptor); + TargetPinBodyWidget( + const Targets::TargetPinDescriptor& pinDescriptor, + std::optional> padDescriptor, + QWidget* parent + ); - void setPinState(const Targets::TargetPinState& pinState) { - this->pinState = pinState; + void setPadState(const Targets::TargetGpioPadState& padState) { + this->padState = padState; } const QColor& getDefaultBodyColor() const { @@ -81,16 +89,17 @@ namespace Widgets::InsightTargetWidgets void clicked(); protected: - Targets::TargetPinDescriptor pinDescriptor; - std::optional pinState; + const Targets::TargetPinDescriptor& pinDescriptor; + std::optional> padDescriptor; + std::optional padState; bool hoverActive = false; - QColor defaultBodyColor = QColor("#908D85"); - QColor vccBodyColor = QColor("#70383A"); - QColor gndBodyColor = QColor("#484A4B"); - QColor outputHighBodyColor = QColor("#3C5E62"); - QColor inputHighBodyColor = QColor("#7B5E38"); + QColor defaultBodyColor = {"#908D85"}; + QColor vccBodyColor = {"#70383A"}; + QColor gndBodyColor = {"#484A4B"}; + QColor outputHighBodyColor = {"#3C5E62"}; + QColor inputHighBodyColor = {"#7B5E38"}; int disableAlphaLevel = 100; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinWidget.cpp index 1f7fa575..b82dcd38 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinWidget.cpp @@ -1,54 +1,56 @@ #include "TargetPinWidget.hpp" #include "src/Insight/InsightWorker/InsightWorker.hpp" -#include "src/Insight/InsightWorker/Tasks/SetTargetPinState.hpp" +#include "src/Insight/InsightWorker/Tasks/SetTargetGpioPadState.hpp" namespace Widgets::InsightTargetWidgets { - using Targets::TargetVariant; - using Targets::TargetPinDescriptor; - using Targets::TargetPinType; - using Targets::TargetPinState; - TargetPinWidget::TargetPinWidget( - Targets::TargetPinDescriptor pinDescriptor, - Targets::TargetVariant targetVariant, + const Targets::TargetPinDescriptor& pinDescriptor, + std::optional> padDescriptor, + const Targets::TargetPinoutDescriptor& pinoutDescriptor, QWidget* parent ) : QWidget(parent) - , targetVariant(std::move(targetVariant)) - , pinDescriptor(std::move(pinDescriptor) - ) { - if (this->pinDescriptor.type == TargetPinType::UNKNOWN) { + , pinDescriptor(pinDescriptor) + , padDescriptor(padDescriptor) + , pinoutDescriptor(pinoutDescriptor) + { + if (!this->padDescriptor.has_value() || this->padDescriptor->get().type == Targets::TargetPadType::OTHER) { this->setDisabled(true); } } 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) { + using Targets::TargetGpioPadState; + + if ( + this->padDescriptor.has_value() + && this->padState.has_value() + && this->padState->direction == TargetGpioPadState::DataDirection::OUTPUT + ) { this->setDisabled(true); - auto pinState = this->pinState.value(); - pinState.ioState = (pinState.ioState == TargetPinState::IoState::HIGH) - ? TargetPinState::IoState::LOW - : TargetPinState::IoState::HIGH; + auto newPadState = *this->padState; + newPadState.value = this->padState->value == TargetGpioPadState::State::HIGH + ? TargetGpioPadState::State::LOW + : TargetGpioPadState::State::HIGH; - const auto setPinStateTask = QSharedPointer( - new SetTargetPinState(this->pinDescriptor, pinState), + const auto setPadStateTask = QSharedPointer{ + new SetTargetGpioPadState{this->padDescriptor->get(), newPadState}, &QObject::deleteLater - ); + }; - QObject::connect(setPinStateTask.get(), &InsightWorkerTask::completed, this, [this, pinState] { - this->updatePinState(pinState); + QObject::connect(setPadStateTask.get(), &InsightWorkerTask::completed, this, [this, newPadState] { + this->updatePadState(newPadState); this->setDisabled(false); }); - QObject::connect(setPinStateTask.get(), &InsightWorkerTask::failed, this, [this] { + QObject::connect(setPadStateTask.get(), &InsightWorkerTask::failed, this, [this] { this->setDisabled(false); }); - InsightWorker::queueTask(setPinStateTask); + InsightWorker::queueTask(setPadStateTask); } } } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinWidget.hpp index 17eaa483..12bfdc23 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinWidget.hpp @@ -3,8 +3,14 @@ #include #include #include +#include #include "src/Targets/TargetPinDescriptor.hpp" +#include "src/Targets/TargetPadDescriptor.hpp" +#include "src/Targets/TargetPinoutDescriptor.hpp" +#include "src/Targets/TargetGpioPadState.hpp" + +#include "src/Services/StringService.hpp" namespace Widgets::InsightTargetWidgets { @@ -13,39 +19,37 @@ namespace Widgets::InsightTargetWidgets Q_OBJECT public: + const Targets::TargetPinDescriptor& pinDescriptor; + std::optional> padDescriptor; + const Targets::TargetPinoutDescriptor& pinoutDescriptor; + std::optional padState; + bool padStateChanged = false; + TargetPinWidget( - Targets::TargetPinDescriptor pinDescriptor, - Targets::TargetVariant targetVariant, + const Targets::TargetPinDescriptor& pinDescriptor, + std::optional> padDescriptor, + const Targets::TargetPinoutDescriptor& pinoutDescriptor, QWidget* parent ); int getPinNumber() const { - return this->pinDescriptor.number; + return Services::StringService::toUint8(this->pinDescriptor.position, 10); } - const std::optional& getPinState() const { - return this->pinState; + const std::optional& getPadState() const { + return this->padState; } - virtual void updatePinState(const Targets::TargetPinState& pinState) { - this->pinStateChanged = !this->pinState.has_value() - || this->pinState->ioState != pinState.ioState - || this->pinState->ioDirection != pinState.ioDirection; - - this->pinState = pinState; + virtual void updatePadState(const Targets::TargetGpioPadState& padState) { + this->padStateChanged = !this->padState.has_value() || this->padState != padState; + this->padState = padState; } - bool hasPinStateChanged() const { - return this->pinStateChanged; + bool hasPadStateChanged() const { + return this->padStateChanged; } public slots: virtual void onWidgetBodyClicked(); - - protected: - Targets::TargetVariant targetVariant; - Targets::TargetPinDescriptor pinDescriptor; - std::optional pinState; - bool pinStateChanged = false; }; } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TaskIndicator/TaskIndicator.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TaskIndicator/TaskIndicator.cpp index 01d90759..c9c08da3 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TaskIndicator/TaskIndicator.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TaskIndicator/TaskIndicator.cpp @@ -13,7 +13,7 @@ namespace Widgets this->setObjectName("task-indicator"); this->setFixedSize(50, 26); - this->taskWindow = new TaskWindow(this); + this->taskWindow = new TaskWindow{this}; auto* insightSignals = InsightSignals::instance(); @@ -50,13 +50,13 @@ namespace Widgets } void TaskIndicator::paintEvent(QPaintEvent* event) { - auto painter = QPainter(this); + auto painter = QPainter{this}; painter.setPen(Qt::PenStyle::NoPen); const auto size = this->size(); - static constexpr auto activeItemColor = QColor(0x7C, 0x5D, 0x3B); - static constexpr auto inactiveItemColor = QColor(0x83, 0x83, 0x82); + static constexpr auto activeItemColor = QColor{0x7C, 0x5D, 0x3B}; + static constexpr auto inactiveItemColor = QColor{0x83, 0x83, 0x82}; static constexpr auto itemSize = QSize(3, 3); static constexpr auto rowCount = 3; @@ -66,7 +66,7 @@ namespace Widgets static constexpr auto itemBottomMargin = 2; if (this->hovered) { - static constexpr auto hoveredBackgroundColor = QColor(0x45, 0x45, 0x41); + static constexpr auto hoveredBackgroundColor = QColor{0x45, 0x45, 0x41}; painter.setBrush(hoveredBackgroundColor); painter.drawRect(0, 1, size.width(), size.height() - 1); } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TaskProgressIndicator/TaskProgressIndicator.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TaskProgressIndicator/TaskProgressIndicator.cpp index cdeacf90..a0e297a2 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TaskProgressIndicator/TaskProgressIndicator.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TaskProgressIndicator/TaskProgressIndicator.cpp @@ -76,15 +76,15 @@ namespace Widgets return; } - auto painter = QPainter(this); + auto painter = QPainter{this}; const auto size = this->size(); - static constexpr auto backgroundBarColor = QColor(0x8E, 0x8B, 0x83, 40); - static constexpr auto barColor = QColor(0x8E, 0x8B, 0x83, 90); - static constexpr auto fontColor = QColor(0x99, 0x9a, 0x9d); + static constexpr auto backgroundBarColor = QColor{0x8E, 0x8B, 0x83, 40}; + static constexpr auto barColor = QColor{0x8E, 0x8B, 0x83, 90}; + static constexpr auto fontColor = QColor{0x99, 0x9a, 0x9d}; - static const auto font = QFont("'Ubuntu', sans-serif", 9); + static const auto font = QFont{"'Ubuntu', sans-serif", 9}; painter.setFont(font); painter.setPen(fontColor); @@ -95,13 +95,13 @@ namespace Widgets if (taskCount == 1) { auto* task = this->tasksById.begin()->second.get(); - const auto status = QString( + const auto status = QString{ task->state == InsightWorkerTaskState::FAILED ? " - Failed" : task->state == InsightWorkerTaskState::COMPLETED ? " - Completed" : "" - ); + }; painter.drawText( 0, diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TaskProgressIndicator/TaskProgressIndicator.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TaskProgressIndicator/TaskProgressIndicator.hpp index 23306d8b..f4696f5b 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TaskProgressIndicator/TaskProgressIndicator.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TaskProgressIndicator/TaskProgressIndicator.hpp @@ -27,7 +27,7 @@ namespace Widgets std::unordered_map> tasksById; std::uint8_t progressPercentage = 0; - QTimer* clearCompletedTasksTimer = new QTimer(this); + QTimer* clearCompletedTasksTimer = new QTimer{this}; void clearCompletedTasks(); void refreshProgressPercentage(); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TaskWindow/Task.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TaskWindow/Task.cpp index ce5e0f97..f8eb5c11 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TaskWindow/Task.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TaskWindow/Task.cpp @@ -6,10 +6,7 @@ namespace Widgets { - Task::Task( - const QSharedPointer& task, - QWidget* parent - ) + Task::Task(const QSharedPointer& task, QWidget* parent) : QWidget(parent) , task(task) { @@ -56,20 +53,20 @@ namespace Widgets } void Task::paintEvent(QPaintEvent* event) { - auto painter = QPainter(this); + auto painter = QPainter{this}; const auto margins = this->contentsMargins(); const auto size = this->size(); - static constexpr auto backgroundBarColor = QColor(0x8E, 0x8B, 0x83, 40); - static constexpr auto barColor = QColor(0x8E, 0x8B, 0x83, 90); - static constexpr auto fontColor = QColor(0x99, 0x9a, 0x9d); - static constexpr auto statusFontColor = QColor(0x99, 0x9a, 0x9d, 200); + static constexpr auto backgroundBarColor = QColor{0x8E, 0x8B, 0x83, 40}; + static constexpr auto barColor = QColor{0x8E, 0x8B, 0x83, 90}; + static constexpr auto fontColor = QColor{0x99, 0x9a, 0x9d}; + static constexpr auto statusFontColor = QColor{0x99, 0x9a, 0x9d, 200}; - static auto font = QFont("'Ubuntu', sans-serif"); + static auto font = QFont{"'Ubuntu', sans-serif"}; font.setPixelSize(14); - static auto statusFont = QFont("'Ubuntu', sans-serif"); + static auto statusFont = QFont{"'Ubuntu', sans-serif"}; statusFont.setPixelSize(12); painter.setFont(font); @@ -84,7 +81,7 @@ namespace Widgets this->task->brief() ); - const auto status = QString( + const auto status = QString{ this->task->state == InsightWorkerTaskState::FAILED ? "Failed" : this->task->state == InsightWorkerTaskState::COMPLETED @@ -92,7 +89,7 @@ namespace Widgets : this->task->state == InsightWorkerTaskState::STARTED ? "Running" : "Queued" - ); + }; painter.setFont(statusFont); painter.setPen(statusFontColor); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TaskWindow/TaskWindow.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TaskWindow/TaskWindow.cpp index a2631390..0a4791cd 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TaskWindow/TaskWindow.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TaskWindow/TaskWindow.cpp @@ -1,6 +1,7 @@ #include "TaskWindow.hpp" #include +#include #include #include "src/Insight/UserInterfaces/InsightWindow/UiLoader.hpp" @@ -21,27 +22,27 @@ namespace Widgets this->setWindowFlag(Qt::Window); this->setWindowTitle("Background Tasks"); - auto windowUiFile = QFile( + auto windowUiFile = QFile{ QString::fromStdString(Services::PathService::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TaskWindow/UiFiles/TaskWindow.ui" ) - ); + }; - auto stylesheetFile = QFile( + auto stylesheetFile = QFile{ QString::fromStdString(Services::PathService::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TaskWindow/Stylesheets/TaskWindow.qss" ) - ); + }; if (!windowUiFile.open(QFile::ReadOnly)) { - throw Exceptions::Exception("Failed to open TaskWindow UI file"); + throw Exceptions::Exception{"Failed to open TaskWindow UI file"}; } if (!stylesheetFile.open(QFile::ReadOnly)) { - throw Exceptions::Exception("Failed to open TaskWindow stylesheet file"); + throw Exceptions::Exception{"Failed to open TaskWindow stylesheet file"}; } - auto uiLoader = UiLoader(this); + auto uiLoader = UiLoader{this}; this->container = uiLoader.load(&windowUiFile, this); this->container->setStyleSheet(stylesheetFile.readAll()); @@ -50,10 +51,8 @@ namespace Widgets this->taskWidgetLayout = this->container->findChild(); this->taskPlaceholderLabel = this->container->findChild("loading-placeholder-label"); - auto* insightSignals = InsightSignals::instance(); - QObject::connect( - insightSignals, + InsightSignals::instance(), &InsightSignals::taskQueued, this, &TaskWindow::onTaskQueued @@ -65,11 +64,11 @@ namespace Widgets } void TaskWindow::onTaskQueued(const QSharedPointer& task) { - auto* taskWidget = new Task(task, this); + auto* taskWidget = new Task{task, this}; this->taskWidgetLayout->insertWidget(0, taskWidget); QObject::connect(taskWidget, &Task::taskComplete, this, [this] (InsightWorkerTask::IdType taskId) { - auto* finishedSignalTimer = new QTimer(); + auto* finishedSignalTimer = new QTimer{}; finishedSignalTimer->setSingleShot(true); finishedSignalTimer->setInterval(10000); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TextInput.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TextInput.cpp index 24f0c902..2424a3f9 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TextInput.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TextInput.cpp @@ -15,7 +15,7 @@ namespace Widgets // Remove default icons for (auto& action : menu->actions()) { - action->setIcon(QIcon()); + action->setIcon(QIcon{}); } menu->popup(event->globalPos()); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TextInput.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TextInput.hpp index 3e9bba7f..fc2462ef 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TextInput.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TextInput.hpp @@ -20,6 +20,5 @@ namespace Widgets void contextMenuEvent(QContextMenuEvent* event) override; void focusInEvent(QFocusEvent* event) override; void focusOutEvent(QFocusEvent* event) override; - }; } diff --git a/src/ProjectConfig.cpp b/src/ProjectConfig.cpp index bec0ce38..1d67af77 100644 --- a/src/ProjectConfig.cpp +++ b/src/ProjectConfig.cpp @@ -93,6 +93,10 @@ InsightConfig::InsightConfig(const YAML::Node& insightNode) { if (insightNode["shutdown_on_close"]) { this->shutdownOnClose = insightNode["shutdown_on_close"].as(this->shutdownOnClose); } + + if (insightNode["default_variant_key"]) { + this->defaultVariantKey = insightNode["default_variant_key"].as(); + } } EnvironmentConfig::EnvironmentConfig(std::string name, const YAML::Node& environmentNode) @@ -191,7 +195,10 @@ TargetConfig::TargetConfig(const YAML::Node& targetNode) { this->physicalInterface = physicalInterfaceIt->second; if (targetNode["variantName"]) { - this->variantName = StringService::asciiToLower(targetNode["variantName"].as()); + Logger::warning( + "The 'variantName' target configuration parameter was removed in v2.0.0. Please use the " + "'default_variant_key' insight configuration parameter." + ); } if (targetNode["hardware_breakpoints"]) { diff --git a/src/ProjectConfig.hpp b/src/ProjectConfig.hpp index bda75a61..d825416d 100644 --- a/src/ProjectConfig.hpp +++ b/src/ProjectConfig.hpp @@ -52,13 +52,6 @@ struct TargetConfig */ Targets::TargetPhysicalInterface physicalInterface; - /** - * The name of the selected target variant. - * - * Insight uses this to determine which variant to select on start up. - */ - std::optional variantName; - /** * Determines whether Bloom will make use of the target's hardware breakpoint resources (if available). */ @@ -157,6 +150,11 @@ struct InsightConfig */ bool shutdownOnClose = false; + /** + * The key of the variant to select by default, in the Insight GUi. + */ + std::optional defaultVariantKey; + InsightConfig() = default; /** diff --git a/src/ProjectSettings.cpp b/src/ProjectSettings.cpp index d7ca1421..ea7637f5 100644 --- a/src/ProjectSettings.cpp +++ b/src/ProjectSettings.cpp @@ -16,7 +16,7 @@ ProjectSettings::ProjectSettings(const QJsonObject& jsonObject) { } QJsonObject ProjectSettings::toJson() const { - auto projectSettingsObj = QJsonObject(); + auto projectSettingsObj = QJsonObject{}; #ifndef EXCLUDE_INSIGHT projectSettingsObj.insert("insight", this->insightSettings.toJson()); @@ -31,63 +31,47 @@ InsightProjectSettings::InsightProjectSettings(const QJsonObject& jsonObject) { const auto mainWindowSizeObj = jsonObject.find("mainWindowSize")->toObject(); if (mainWindowSizeObj.contains("width") && mainWindowSizeObj.contains("height")) { - this->mainWindowSize = QSize( + this->mainWindowSize = QSize{ mainWindowSizeObj.find("width")->toInt(), mainWindowSizeObj.find("height")->toInt() - ); + }; } } if (jsonObject.contains("leftPanelState")) { - this->leftPanelState = this->panelStateFromJson( - jsonObject.find("leftPanelState")->toObject() - ); + this->leftPanelState = this->panelStateFromJson(jsonObject.find("leftPanelState")->toObject()); } if (jsonObject.contains("bottomPanelState")) { - this->bottomPanelState = this->panelStateFromJson( - jsonObject.find("bottomPanelState")->toObject() - ); + this->bottomPanelState = this->panelStateFromJson(jsonObject.find("bottomPanelState")->toObject()); } if (jsonObject.contains("registersPaneState")) { - this->registersPaneState = this->paneStateFromJson( - jsonObject.find("registersPaneState")->toObject() - ); + this->registersPaneState = this->paneStateFromJson(jsonObject.find("registersPaneState")->toObject()); } - if (jsonObject.contains("ramInspectionPaneState")) { - this->ramInspectionPaneState = this->paneStateFromJson( - jsonObject.find("ramInspectionPaneState")->toObject() - ); + if (jsonObject.contains("selectedVariantKey")) { + this->selectedVariantKey = jsonObject.find("selectedVariantKey")->toString().toStdString(); } - if (jsonObject.contains("eepromInspectionPaneState")) { - this->eepromInspectionPaneState = this->paneStateFromJson( - jsonObject.find("eepromInspectionPaneState")->toObject() - ); + if (jsonObject.contains("memoryInspectionPaneStatesByKey")) { + const auto stateMappingObj = jsonObject.find("memoryInspectionPaneStatesByKey")->toObject(); + + for (auto stateIt = stateMappingObj.begin(); stateIt != stateMappingObj.end(); stateIt++) { + this->memoryInspectionPaneStatesByKey.emplace( + stateIt.key(), + this->paneStateFromJson(stateIt.value().toObject()) + ); + } } - if (jsonObject.contains("flashInspectionPaneState")) { - this->flashInspectionPaneState = this->paneStateFromJson( - jsonObject.find("flashInspectionPaneState")->toObject() - ); - } - - if (jsonObject.contains("memoryInspectionPaneSettings")) { - const auto settingsMappingObj = jsonObject.find("memoryInspectionPaneSettings")->toObject(); + if (jsonObject.contains("memoryInspectionSettingsByKey")) { + const auto settingsMappingObj = jsonObject.find("memoryInspectionSettingsByKey")->toObject(); for (auto settingsIt = settingsMappingObj.begin(); settingsIt != settingsMappingObj.end(); settingsIt++) { - const auto settingsObj = settingsIt.value().toObject(); - const auto memoryTypeName = settingsIt.key(); - - if (!EnumToStringMappings::targetMemoryTypes.contains(memoryTypeName)) { - continue; - } - - this->memoryInspectionPaneSettingsByMemoryType.emplace( - EnumToStringMappings::targetMemoryTypes.at(memoryTypeName), - this->memoryInspectionPaneSettingsFromJson(settingsObj) + this->memoryInspectionSettingsByKey.emplace( + settingsIt.key(), + this->memoryInspectionPaneSettingsFromJson(settingsIt.value().toObject()) ); } } @@ -103,73 +87,82 @@ QJsonObject InsightProjectSettings::toJson() const { }); } - auto memoryInspectionPaneSettingsObj = QJsonObject{}; - - for (const auto& [memoryType, inspectionPaneSettings] : this->memoryInspectionPaneSettingsByMemoryType) { - if (!EnumToStringMappings::targetMemoryTypes.contains(memoryType)) { - // This is just a precaution - all known memory types should be in the mapping. - continue; - } - - memoryInspectionPaneSettingsObj.insert( - EnumToStringMappings::targetMemoryTypes.at(memoryType), - this->memoryInspectionPaneSettingsToJson(inspectionPaneSettings) - ); - } - - insightObj.insert("memoryInspectionPaneSettings", memoryInspectionPaneSettingsObj); - if (this->leftPanelState.has_value()) { - insightObj.insert( - "leftPanelState", - this->panelStateToJson(this->leftPanelState.value()) - ); + insightObj.insert("leftPanelState", this->panelStateToJson(this->leftPanelState.value())); } if (this->bottomPanelState.has_value()) { - insightObj.insert( - "bottomPanelState", - this->panelStateToJson(this->bottomPanelState.value()) - ); + insightObj.insert("bottomPanelState", this->panelStateToJson(this->bottomPanelState.value())); } if (this->registersPaneState.has_value()) { - insightObj.insert( - "registersPaneState", - this->paneStateToJson(this->registersPaneState.value()) - ); + insightObj.insert("registersPaneState", this->paneStateToJson(this->registersPaneState.value())); } - if (this->ramInspectionPaneState.has_value()) { - insightObj.insert( - "ramInspectionPaneState", - this->paneStateToJson(this->ramInspectionPaneState.value()) - ); + if (this->selectedVariantKey.has_value()) { + insightObj.insert("selectedVariantKey", QString::fromStdString(this->selectedVariantKey.value())); } - if (this->eepromInspectionPaneState.has_value()) { - insightObj.insert( - "eepromInspectionPaneState", - this->paneStateToJson(this->eepromInspectionPaneState.value()) - ); + auto memoryInspectionPaneStates = QJsonObject{}; + for (const auto& [key, paneState] : this->memoryInspectionPaneStatesByKey) { + memoryInspectionPaneStates.insert(key, this->paneStateToJson(paneState)); } - if (this->flashInspectionPaneState.has_value()) { - insightObj.insert( - "flashInspectionPaneState", - this->paneStateToJson(this->flashInspectionPaneState.value()) - ); + insightObj.insert("memoryInspectionPaneStatesByKey", memoryInspectionPaneStates); + + auto memoryInspectionSettings = QJsonObject{}; + for (const auto& [key, settings] : this->memoryInspectionSettingsByKey) { + memoryInspectionSettings.insert(key, this->memoryInspectionPaneSettingsToJson(settings)); } + insightObj.insert("memoryInspectionSettingsByKey", memoryInspectionSettings); + return insightObj; } +Widgets::PaneState& InsightProjectSettings::findOrCreateMemoryInspectionPaneState( + const QString& addressSpaceKey, + const QString& memorySegmentKey +) { + auto key = addressSpaceKey + "." + memorySegmentKey; + for (auto& [paneStateKey, paneState] : this->memoryInspectionPaneStatesByKey) { + if (paneStateKey == key) { + return paneState; + } + } + + return this->memoryInspectionPaneStatesByKey.emplace( + std::move(key), + Widgets::PaneState{false, true, std::nullopt} + ).first->second; +} + +Widgets::TargetMemoryInspectionPaneSettings& InsightProjectSettings::findOrCreateMemoryInspectionPaneSettings( + const QString& addressSpaceKey, + const QString& memorySegmentKey +) { + auto key = addressSpaceKey + "." + memorySegmentKey; + for (auto& [settingsKey, settings] : this->memoryInspectionSettingsByKey) { + if (settingsKey == key) { + return settings; + } + } + + return this->memoryInspectionSettingsByKey.emplace( + std::move(key), + Widgets::TargetMemoryInspectionPaneSettings{addressSpaceKey, memorySegmentKey} + ).first->second; +} + Widgets::TargetMemoryInspectionPaneSettings InsightProjectSettings::memoryInspectionPaneSettingsFromJson( const QJsonObject& jsonObject ) const { using Exceptions::Exception; - auto inspectionPaneSettings = Widgets::TargetMemoryInspectionPaneSettings{}; + auto inspectionPaneSettings = Widgets::TargetMemoryInspectionPaneSettings{ + jsonObject.value("addressSpaceKey").toString(), + jsonObject.value("memorySegmentKey").toString() + }; if (jsonObject.contains("refreshOnTargetStop")) { inspectionPaneSettings.refreshOnTargetStop = jsonObject.value("refreshOnTargetStop").toBool(); @@ -217,7 +210,7 @@ Widgets::TargetMemoryInspectionPaneSettings InsightProjectSettings::memoryInspec try { inspectionPaneSettings.focusedMemoryRegions.emplace_back(regionValue.toObject()); - } catch (Exception exception) { + } catch (const Exception& exception) { Logger::warning( "Failed to parse focused memory region from project settings file - " + exception.getMessage() + " - region will be ignored." @@ -231,7 +224,7 @@ Widgets::TargetMemoryInspectionPaneSettings InsightProjectSettings::memoryInspec try { inspectionPaneSettings.excludedMemoryRegions.emplace_back(regionValue.toObject()); - } catch (Exception exception) { + } catch (const Exception& exception) { Logger::warning( "Failed to parse excluded memory region from project settings file - " + exception.getMessage() + " - region will be ignored." @@ -260,18 +253,18 @@ Widgets::PaneState InsightProjectSettings::paneStateFromJson(const QJsonObject& if (detachedWindowStateObject.contains("size")) { const auto sizeObject = detachedWindowStateObject.value("size").toObject(); - detachedWindowState->size = QSize( + detachedWindowState->size = QSize{ sizeObject.value("width").toInt(0), sizeObject.value("height").toInt(0) - ); + }; } if (detachedWindowStateObject.contains("position")) { const auto positionObject = detachedWindowStateObject.value("position").toObject(); - detachedWindowState->position = QPoint( + detachedWindowState->position = QPoint{ positionObject.value("x").toInt(0), positionObject.value("y").toInt(0) - ); + }; } } diff --git a/src/ProjectSettings.hpp b/src/ProjectSettings.hpp index 00cb731f..88b4f477 100644 --- a/src/ProjectSettings.hpp +++ b/src/ProjectSettings.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "src/Targets/TargetMemory.hpp" @@ -25,27 +26,31 @@ public: std::optional leftPanelState; std::optional bottomPanelState; std::optional registersPaneState; - std::optional ramInspectionPaneState; - std::optional eepromInspectionPaneState; - std::optional flashInspectionPaneState; - std::map< - Targets::TargetMemoryType, - Widgets::TargetMemoryInspectionPaneSettings - > memoryInspectionPaneSettingsByMemoryType; + /** + * The key of the previously selected variant + */ + std::optional selectedVariantKey; + + std::map memoryInspectionPaneStatesByKey; + std::map memoryInspectionSettingsByKey; InsightProjectSettings() = default; explicit InsightProjectSettings(const QJsonObject& jsonObject); [[nodiscard]] QJsonObject toJson() const; -private: - static const inline BiMap memoryTypesByName = { - {Targets::TargetMemoryType::RAM, "ram"}, - {Targets::TargetMemoryType::EEPROM, "eeprom"}, - {Targets::TargetMemoryType::FLASH, "flash"}, - }; + Widgets::TargetMemoryInspectionPaneSettings& findOrCreateMemoryInspectionPaneSettings( + const QString& addressSpaceKey, + const QString& memorySegmentKey + ); + Widgets::PaneState& findOrCreateMemoryInspectionPaneState( + const QString& addressSpaceKey, + const QString& memorySegmentKey + ); + +private: static const inline BiMap addressTypesByName = { {AddressType::ABSOLUTE, "absolute"}, {AddressType::RELATIVE, "relative"}, diff --git a/src/Services/PathService.hpp b/src/Services/PathService.hpp index 2273b2f1..c817c0e8 100644 --- a/src/Services/PathService.hpp +++ b/src/Services/PathService.hpp @@ -69,6 +69,10 @@ namespace Services return PathService::projectSettingsDirPath() + "/settings.json"; } + static std::string memorySnapshotsPath() { + return PathService::projectSettingsDirPath() + "/memory_snapshots/"; + } + /** * Returns the path to Bloom's compiled resources. * diff --git a/src/Targets/TargetAddressSpaceDescriptor.cpp b/src/Targets/TargetAddressSpaceDescriptor.cpp index 667b2b9d..8fb04a87 100644 --- a/src/Targets/TargetAddressSpaceDescriptor.cpp +++ b/src/Targets/TargetAddressSpaceDescriptor.cpp @@ -47,6 +47,18 @@ namespace Targets return std::cref(segmentIt->second); } + std::optional< + std::reference_wrapper + > TargetAddressSpaceDescriptor::tryGetMemorySegmentDescriptor(const std::string& key) { + const auto segmentIt = this->segmentDescriptorsByKey.find(key); + + if (segmentIt == this->segmentDescriptorsByKey.end()) { + return std::nullopt; + } + + return std::ref(segmentIt->second); + } + const TargetMemorySegmentDescriptor& TargetAddressSpaceDescriptor::getMemorySegmentDescriptor( const std::string& key ) const { @@ -61,6 +73,12 @@ namespace Targets return segment->get(); } + TargetMemorySegmentDescriptor& TargetAddressSpaceDescriptor::getMemorySegmentDescriptor(const std::string& key) { + return const_cast( + const_cast(this)->getMemorySegmentDescriptor(key) + ); + } + std::vector< const TargetMemorySegmentDescriptor* > TargetAddressSpaceDescriptor::getIntersectingMemorySegmentDescriptors( diff --git a/src/Targets/TargetAddressSpaceDescriptor.hpp b/src/Targets/TargetAddressSpaceDescriptor.hpp index 46c3e4d0..01ee4c06 100644 --- a/src/Targets/TargetAddressSpaceDescriptor.hpp +++ b/src/Targets/TargetAddressSpaceDescriptor.hpp @@ -63,9 +63,12 @@ namespace Targets * @return * A reference wrapper of the memory segment descriptor, if found. Otherwise, std::nullopt. */ - std::optional> tryGetMemorySegmentDescriptor( - const std::string& key - ) const; + [[nodiscard]] std::optional< + std::reference_wrapper + > tryGetMemorySegmentDescriptor(const std::string& key) const; + [[nodiscard]] std::optional< + std::reference_wrapper + > tryGetMemorySegmentDescriptor(const std::string& key); /** * Fetches a memory segment descriptor with the given key. If the descriptor doesn't exist, an @@ -77,7 +80,8 @@ namespace Targets * @return * A reference to the memory segment descriptor. */ - const TargetMemorySegmentDescriptor& getMemorySegmentDescriptor(const std::string& key) const; + [[nodiscard]] const TargetMemorySegmentDescriptor& getMemorySegmentDescriptor(const std::string& key) const; + TargetMemorySegmentDescriptor& getMemorySegmentDescriptor(const std::string& key); /** * Fetches all memory segments in the address space that intersect with the given address range. @@ -88,7 +92,7 @@ namespace Targets * @return * Pointers to descriptors of all intersecting memory segments. */ - std::vector getIntersectingMemorySegmentDescriptors( + [[nodiscard]] std::vector getIntersectingMemorySegmentDescriptors( const TargetMemoryAddressRange& addressRange ) const; diff --git a/src/Targets/TargetPadDescriptor.hpp b/src/Targets/TargetPadDescriptor.hpp index 0fbac939..e0c80317 100644 --- a/src/Targets/TargetPadDescriptor.hpp +++ b/src/Targets/TargetPadDescriptor.hpp @@ -41,5 +41,5 @@ namespace Targets static TargetPadId generateId(const std::string& padKey); }; - using TargetPadDescriptors = std::vector; + using TargetPadDescriptors = std::vector; }