Refactored Insight GUI to accommodate the many changes made to Bloom's internals

Also lots of tidying.
This commit is contained in:
Nav
2024-12-24 18:27:59 +00:00
parent 28e0a6d9e4
commit 7fe5b88dd8
195 changed files with 3449 additions and 3171 deletions

View File

@@ -29,14 +29,11 @@ target_sources(
${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/InsightWorkerTask.cpp ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/InsightWorkerTask.cpp
${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/ReadTargetRegisters.cpp ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/ReadTargetRegisters.cpp
${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/WriteTargetRegister.cpp ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/WriteTargetRegister.cpp
${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/RefreshTargetPinStates.cpp ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/ReadTargetGpioPadStates.cpp
${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/SetTargetPinState.cpp ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/SetTargetGpioPadState.cpp
${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/ReadTargetMemory.cpp ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/ReadTargetMemory.cpp
${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/WriteTargetMemory.cpp ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/WriteTargetMemory.cpp
${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/ReadStackPointer.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/ConstructHexViewerTopLevelGroupItem.cpp
${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/CaptureMemorySnapshot.cpp ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/CaptureMemorySnapshot.cpp
${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/RetrieveMemorySnapshots.cpp ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/RetrieveMemorySnapshots.cpp
@@ -73,6 +70,7 @@ target_sources(
# Target register side pane # Target register side pane
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.cpp ${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/RegisterGroupItem.cpp
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/RegisterItem.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 ${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/BitsetWidget/BitBodyWidget.cpp
# Target memory inspection pane # 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/TargetMemoryInspectionPane.cpp
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerWidget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/HexViewerWidget.cpp
${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ItemGraphicsView.cpp

View File

@@ -5,17 +5,14 @@
#include <QJsonDocument> #include <QJsonDocument>
#include "src/Services/PathService.hpp" #include "src/Services/PathService.hpp"
#include "src/Logger/Logger.hpp"
#include "src/EventManager/EventManager.hpp" #include "src/EventManager/EventManager.hpp"
#include "UserInterfaces/InsightWindow/BloomProxyStyle.hpp" #include "UserInterfaces/InsightWindow/BloomProxyStyle.hpp"
#include "src/Logger/Logger.hpp"
#include "src/Application.hpp" #include "src/Application.hpp"
#include "InsightWorker/Tasks/GetTargetState.hpp"
#include "InsightWorker/Tasks/GetTargetDescriptor.hpp"
using namespace Exceptions; using namespace Exceptions;
using Targets::TargetState; using Targets::TargetExecutionState;
Insight::Insight( Insight::Insight(
EventListener& eventListener, EventListener& eventListener,
@@ -31,15 +28,13 @@ Insight::Insight(
, environmentConfig(environmentConfig) , environmentConfig(environmentConfig)
, insightConfig(insightConfig) , insightConfig(insightConfig)
, insightProjectSettings(insightProjectSettings) , insightProjectSettings(insightProjectSettings)
, targetDescriptor(this->targetControllerService.getTargetDescriptor())
, targetState(this->targetControllerService.getTargetState())
{ {
Logger::info("Starting Insight"); Logger::info("Starting Insight");
this->eventListener.registerCallbackForEventType<Events::TargetExecutionStopped>( this->eventListener.registerCallbackForEventType<Events::TargetStateChanged>(
std::bind(&Insight::onTargetStoppedEvent, this, std::placeholders::_1) std::bind(&Insight::onTargetStateChangedEvent, this, std::placeholders::_1)
);
this->eventListener.registerCallbackForEventType<Events::TargetExecutionResumed>(
std::bind(&Insight::onTargetResumedEvent, this, std::placeholders::_1)
); );
this->eventListener.registerCallbackForEventType<Events::TargetReset>( this->eventListener.registerCallbackForEventType<Events::TargetReset>(
@@ -63,13 +58,11 @@ Insight::Insight(
); );
QApplication::setQuitOnLastWindowClosed(false); QApplication::setQuitOnLastWindowClosed(false);
QApplication::setStyle(new BloomProxyStyle()); QApplication::setStyle(new BloomProxyStyle{});
qRegisterMetaType<Targets::TargetDescriptor>(); qRegisterMetaType<Targets::TargetDescriptor>();
qRegisterMetaType<Targets::TargetPinDescriptor>(); qRegisterMetaType<Targets::TargetPinDescriptor>();
qRegisterMetaType<Targets::TargetPinState>();
qRegisterMetaType<Targets::TargetState>(); qRegisterMetaType<Targets::TargetState>();
qRegisterMetaType<std::map<int, Targets::TargetPinState>>();
// Load Ubuntu fonts // Load Ubuntu fonts
QFontDatabase::addApplicationFont( QFontDatabase::addApplicationFont(
@@ -115,22 +108,23 @@ Insight::Insight(
QString::fromStdString(Services::PathService::resourcesDirPath() + "/fonts/Ubuntu/Ubuntu-Th.ttf") QString::fromStdString(Services::PathService::resourcesDirPath() + "/fonts/Ubuntu/Ubuntu-Th.ttf")
); );
auto globalStylesheet = QFile( auto globalStylesheet = QFile{
QString::fromStdString( 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)) { 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(); this->globalStylesheet = globalStylesheet.readAll();
// Construct and start worker threads // Construct and start worker threads
for (std::uint8_t i = 0; i < Insight::INSIGHT_WORKER_COUNT; ++i) { for (auto i = std::uint8_t{0}; i < Insight::INSIGHT_WORKER_COUNT; ++i) {
auto* insightWorker = new InsightWorker(); auto* insightWorker = new InsightWorker{};
auto* workerThread = new QThread(); auto* workerThread = new QThread{};
workerThread->setObjectName("IW" + QString::number(insightWorker->id)); workerThread->setObjectName("IW" + QString::number(insightWorker->id));
insightWorker->moveToThread(workerThread); insightWorker->moveToThread(workerThread);
@@ -138,7 +132,7 @@ Insight::Insight(
QObject::connect(workerThread, &QThread::finished, insightWorker, &QObject::deleteLater); QObject::connect(workerThread, &QThread::finished, insightWorker, &QObject::deleteLater);
QObject::connect(workerThread, &QThread::finished, workerThread, &QThread::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)); Logger::debug("Starting InsightWorker" + std::to_string(insightWorker->id));
workerThread->start(); workerThread->start();
@@ -149,18 +143,16 @@ Insight::Insight(
void Insight::activateMainWindow() { void Insight::activateMainWindow() {
if (this->mainWindow == nullptr) { if (this->mainWindow == nullptr) {
this->mainWindow = new InsightWindow( this->mainWindow = new InsightWindow{
this->insightProjectSettings, this->insightProjectSettings,
this->insightConfig, this->insightConfig,
this->environmentConfig, this->environmentConfig,
this->targetDescriptor this->targetDescriptor,
); this->targetState
};
this->mainWindow->setStyleSheet(this->globalStylesheet); this->mainWindow->setStyleSheet(this->globalStylesheet);
QObject::connect(this->mainWindow, &QObject::destroyed, this, &Insight::onInsightWindowDestroyed); QObject::connect(this->mainWindow, &QObject::destroyed, this, &Insight::onInsightWindowDestroyed);
this->refreshTargetState();
} }
this->mainWindow->show(); this->mainWindow->show();
@@ -186,77 +178,39 @@ void Insight::shutdown() {
} }
} }
void Insight::refreshTargetState() {
const auto getTargetStateTask = QSharedPointer<GetTargetState>(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() { void Insight::onInsightWindowDestroyed() {
this->mainWindow = nullptr; this->mainWindow = nullptr;
EventManager::triggerEvent(std::make_shared<Events::InsightMainWindowClosed>()); EventManager::triggerEvent(std::make_shared<Events::InsightMainWindowClosed>());
} }
void Insight::onTargetStoppedEvent(const Events::TargetExecutionStopped& event) { void Insight::onTargetStateChangedEvent(const Events::TargetStateChanged& event) {
if (this->lastTargetState == TargetState::STOPPED) { if (event.previousState.mode != event.newState.mode) {
return; if (event.newState.mode == Targets::TargetMode::PROGRAMMING) {
} emit this->insightSignals->programmingModeEnabled();
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);
});
} }
this->targetResumeTimer->start(1500); if (event.newState.mode == Targets::TargetMode::DEBUGGING) {
emit this->insightSignals->programmingModeDisabled();
}
}
if (event.previousState.executionState == event.newState.executionState) {
return; return;
} }
if (this->targetResumeTimer != nullptr && this->targetResumeTimer->isActive()) { emit this->insightSignals->targetStateUpdated(event.newState, event.previousState);
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);
}
} }
void Insight::onTargetResetEvent(const Events::TargetReset& event) { void Insight::onTargetResetEvent(const Events::TargetReset& event) {
try { try {
if (this->lastTargetState != TargetState::STOPPED) { if (this->targetState.executionState != TargetExecutionState::STOPPED) {
this->lastTargetState = TargetState::STOPPED; // Reset event came in too late, target has already resumed execution. Ignore
emit this->insightSignals->targetStateUpdated(TargetState::STOPPED); return;
} }
emit this->insightSignals->targetReset(); emit this->insightSignals->targetReset();
} catch (const Exceptions::Exception& exception) { } catch (const Exception& exception) {
Logger::debug("Error handling TargetReset event - " + exception.getMessage()); 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) { void Insight::onTargetMemoryWrittenEvent(const Events::MemoryWrittenToTarget& event) {
emit this->insightSignals->targetMemoryWritten( emit this->insightSignals->targetMemoryWritten(
event.memoryType, event.addressSpaceDescriptor,
Targets::TargetMemoryAddressRange(event.startAddress, event.startAddress + (event.size - 1)) event.memorySegmentDescriptor,
Targets::TargetMemoryAddressRange{event.startAddress, event.startAddress + (event.size - 1)}
); );
} }

View File

@@ -6,7 +6,6 @@
#include <map> #include <map>
#include <utility> #include <utility>
#include <QThread> #include <QThread>
#include <QTimer>
#include "src/Helpers/Thread.hpp" #include "src/Helpers/Thread.hpp"
#include "src/Services/PathService.hpp" #include "src/Services/PathService.hpp"
@@ -75,25 +74,20 @@ private:
InsightProjectSettings& insightProjectSettings; 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; QString globalStylesheet;
std::map<decltype(InsightWorker::id), std::pair<InsightWorker*, QThread*>> insightWorkersById; std::map<decltype(InsightWorker::id), std::pair<InsightWorker*, QThread*>> insightWorkersById;
InsightWindow* mainWindow = nullptr; InsightWindow* mainWindow = nullptr;
Targets::TargetState lastTargetState = Targets::TargetState::UNKNOWN;
bool targetStepping = false;
QTimer* targetResumeTimer = nullptr;
InsightSignals* insightSignals = InsightSignals::instance(); InsightSignals* insightSignals = InsightSignals::instance();
void refreshTargetState();
void onInsightWindowDestroyed(); void onInsightWindowDestroyed();
void onTargetStoppedEvent(const Events::TargetExecutionStopped& event); void onTargetStateChangedEvent(const Events::TargetStateChanged& event);
void onTargetResumedEvent(const Events::TargetExecutionResumed& event);
void onTargetResetEvent(const Events::TargetReset& event); void onTargetResetEvent(const Events::TargetReset& event);
void onTargetRegistersWrittenEvent(const Events::RegistersWrittenToTarget& event); void onTargetRegistersWrittenEvent(const Events::RegistersWrittenToTarget& event);
void onTargetMemoryWrittenEvent(const Events::MemoryWrittenToTarget& event); void onTargetMemoryWrittenEvent(const Events::MemoryWrittenToTarget& event);

View File

@@ -5,9 +5,12 @@
#include <QSharedPointer> #include <QSharedPointer>
#include "src/Targets/TargetState.hpp" #include "src/Targets/TargetState.hpp"
#include "src/Targets/TargetDescriptor.hpp"
#include "src/Targets/TargetRegisterDescriptor.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" #include "InsightWorker/Tasks/InsightWorkerTask.hpp"
/** /**
@@ -20,7 +23,7 @@ class InsightSignals: public QObject
public: public:
static InsightSignals* instance() { static InsightSignals* instance() {
static auto instance = InsightSignals(); static auto instance = InsightSignals{};
return &instance; return &instance;
} }
@@ -31,10 +34,14 @@ signals:
void taskQueued(QSharedPointer<InsightWorkerTask> task); void taskQueued(QSharedPointer<InsightWorkerTask> task);
void taskProcessed(QSharedPointer<InsightWorkerTask> task); void taskProcessed(QSharedPointer<InsightWorkerTask> task);
void targetStateUpdated(Targets::TargetState newState); void targetStateUpdated(Targets::TargetState newState, Targets::TargetState previousState);
void targetReset(); void targetReset();
void targetRegistersWritten(const Targets::TargetRegisters& targetRegisters, const QDateTime& timestamp); void targetRegistersWritten(const Targets::TargetRegisterDescriptorAndValuePairs& targetRegisters, const QDateTime& timestamp);
void targetMemoryWritten(Targets::TargetMemoryType memoryType, Targets::TargetMemoryAddressRange addressRange); void targetMemoryWritten(
const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor,
const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor,
Targets::TargetMemoryAddressRange addressRange
);
void programmingModeEnabled(); void programmingModeEnabled();
void programmingModeDisabled(); void programmingModeDisabled();

View File

@@ -69,7 +69,7 @@ void InsightWorker::executeTasks() {
return std::nullopt; return std::nullopt;
}; };
auto queuedTask = std::optional<QSharedPointer<InsightWorkerTask>>(); auto queuedTask = std::optional<QSharedPointer<InsightWorkerTask>>{};
while ((queuedTask = getQueuedTask())) { while ((queuedTask = getQueuedTask())) {
auto& task = *queuedTask; auto& task = *queuedTask;

View File

@@ -37,7 +37,7 @@ private:
static inline Synchronised<std::map<InsightWorkerTask::IdType, QSharedPointer<InsightWorkerTask>>> queuedTasksById = {}; static inline Synchronised<std::map<InsightWorkerTask::IdType, QSharedPointer<InsightWorkerTask>>> queuedTasksById = {};
static inline Synchronised<TaskGroups> taskGroupsInExecution = {}; static inline Synchronised<TaskGroups> taskGroupsInExecution = {};
Services::TargetControllerService targetControllerService = Services::TargetControllerService(); Services::TargetControllerService targetControllerService = {};
void executeTasks(); void executeTasks();
}; };

View File

@@ -13,52 +13,58 @@ using Services::TargetControllerService;
CaptureMemorySnapshot::CaptureMemorySnapshot( CaptureMemorySnapshot::CaptureMemorySnapshot(
const QString& name, const QString& name,
const QString& description, const QString& description,
Targets::TargetMemoryType memoryType, const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor,
const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor,
const std::vector<FocusedMemoryRegion>& focusedRegions, const std::vector<FocusedMemoryRegion>& focusedRegions,
const std::vector<ExcludedMemoryRegion>& excludedRegions, const std::vector<ExcludedMemoryRegion>& excludedRegions,
const std::optional<Targets::TargetMemoryBuffer>& data const std::optional<Targets::TargetMemoryBuffer>& data
) )
: name(name) : name(name)
, description(description) , description(description)
, memoryType(memoryType) , addressSpaceDescriptor(addressSpaceDescriptor)
, memorySegmentDescriptor(memorySegmentDescriptor)
, focusedRegions(focusedRegions) , focusedRegions(focusedRegions)
, excludedRegions(excludedRegions) , excludedRegions(excludedRegions)
, data(data) , data(data)
{} {}
QString CaptureMemorySnapshot::brief() const {
return "Capturing memory snapshot";
}
TaskGroups CaptureMemorySnapshot::taskGroups() const {
return {
TaskGroup::USES_TARGET_CONTROLLER,
};
}
void CaptureMemorySnapshot::run(TargetControllerService& targetControllerService) { void CaptureMemorySnapshot::run(TargetControllerService& targetControllerService) {
using Targets::TargetMemorySize; using Targets::TargetMemorySize;
Logger::info("Capturing snapshot"); Logger::info("Capturing snapshot");
const auto& targetDescriptor = targetControllerService.getTargetDescriptor(); const auto memorySize = this->memorySegmentDescriptor.size();
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();
if (!this->data.has_value()) { if (!this->data.has_value()) {
Logger::info("Reading data for snapshot capture"); Logger::info("Reading data for snapshot capture");
this->data = Targets::TargetMemoryBuffer(); this->data = Targets::TargetMemoryBuffer{};
this->data->reserve(memorySize); this->data->reserve(memorySize);
const auto readSize = std::max( const auto readSize = std::max(
TargetMemorySize(256), TargetMemorySize{256},
memoryDescriptor.pageSize.value_or(TargetMemorySize(0)) this->memorySegmentDescriptor.pageSize.value_or(TargetMemorySize{0})
); );
const auto readsRequired = static_cast<std::uint32_t>( const auto readsRequired = static_cast<std::uint32_t>(
std::ceil(static_cast<float>(memorySize) / static_cast<float>(readSize)) std::ceil(static_cast<float>(memorySize) / static_cast<float>(readSize))
); );
for (std::uint32_t i = 0; i < readsRequired; i++) { for (auto i = std::size_t{0}; i < readsRequired; i++) {
auto dataSegment = targetControllerService.readMemory( auto dataSegment = targetControllerService.readMemory(
this->memoryType, this->addressSpaceDescriptor,
memoryDescriptor.addressRange.startAddress + static_cast<Targets::TargetMemoryAddress>(readSize * i), this->memorySegmentDescriptor,
this->memorySegmentDescriptor.addressRange.startAddress
+ static_cast<Targets::TargetMemoryAddress>(readSize * i),
(memorySize - this->data->size()) >= readSize (memorySize - this->data->size()) >= readSize
? readSize ? readSize
: static_cast<Targets::TargetMemorySize>(memorySize - this->data->size()), : static_cast<Targets::TargetMemorySize>(memorySize - this->data->size()),
@@ -75,32 +81,31 @@ void CaptureMemorySnapshot::run(TargetControllerService& targetControllerService
assert(this->data->size() == memorySize); assert(this->data->size() == memorySize);
auto snapshot = MemorySnapshot( auto snapshot = MemorySnapshot{
std::move(this->name), this->name,
std::move(this->description), this->description,
this->memoryType, QString::fromStdString(this->addressSpaceDescriptor.key),
std::move(*this->data), QString::fromStdString(this->memorySegmentDescriptor.key),
*this->data,
targetControllerService.getProgramCounter(), targetControllerService.getProgramCounter(),
targetControllerService.getStackPointer(), targetControllerService.getStackPointer(),
std::move(this->focusedRegions), this->focusedRegions,
std::move(this->excludedRegions) this->excludedRegions
); };
const auto snapshotDirPath = QString::fromStdString(Services::PathService::projectSettingsDirPath())
+ "/memory_snapshots/" + EnumToStringMappings::targetMemoryTypes.at(snapshot.memoryType);
const auto snapshotDirPath = QString::fromStdString(Services::PathService::memorySnapshotsPath());
QDir().mkpath(snapshotDirPath); QDir().mkpath(snapshotDirPath);
const auto snapshotFilePath = snapshotDirPath + "/" + snapshot.id + ".json"; const auto snapshotFilePath = snapshotDirPath + "/" + snapshot.id + ".json";
auto outputFile = QFile(snapshotFilePath); auto outputFile = QFile{snapshotFilePath};
if (!outputFile.open(QIODevice::ReadWrite | QIODevice::Truncate | QIODevice::Text)) { if (!outputFile.open(QIODevice::ReadWrite | QIODevice::Truncate | QIODevice::Text)) {
Logger::error("Failed to save snapshot - cannot open " + snapshotFilePath.toStdString()); Logger::error("Failed to save snapshot - cannot open " + snapshotFilePath.toStdString());
return; return;
} }
outputFile.write(QJsonDocument(snapshot.toJson()).toJson(QJsonDocument::JsonFormat::Compact)); outputFile.write(QJsonDocument{snapshot.toJson()}.toJson(QJsonDocument::JsonFormat::Compact));
outputFile.close(); outputFile.close();
Logger::info("Snapshot captured - UUID: " + snapshot.id.toStdString()); Logger::info("Snapshot captured - UUID: " + snapshot.id.toStdString());

View File

@@ -6,6 +6,9 @@
#include "InsightWorkerTask.hpp" #include "InsightWorkerTask.hpp"
#include "src/Targets/TargetMemory.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" #include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemorySnapshot.hpp"
class CaptureMemorySnapshot: public InsightWorkerTask class CaptureMemorySnapshot: public InsightWorkerTask
@@ -16,21 +19,15 @@ public:
CaptureMemorySnapshot( CaptureMemorySnapshot(
const QString& name, const QString& name,
const QString& description, const QString& description,
Targets::TargetMemoryType memoryType, const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor,
const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor,
const std::vector<FocusedMemoryRegion>& focusedRegions, const std::vector<FocusedMemoryRegion>& focusedRegions,
const std::vector<ExcludedMemoryRegion>& excludedRegions, const std::vector<ExcludedMemoryRegion>& excludedRegions,
const std::optional<Targets::TargetMemoryBuffer>& data const std::optional<Targets::TargetMemoryBuffer>& data
); );
QString brief() const override { [[nodiscard]] QString brief() const override;
return "Capturing memory snapshot"; [[nodiscard]] TaskGroups taskGroups() const override;
}
TaskGroups taskGroups() const override {
return TaskGroups({
TaskGroup::USES_TARGET_CONTROLLER,
});
};
signals: signals:
void memorySnapshotCaptured(MemorySnapshot snapshot); void memorySnapshotCaptured(MemorySnapshot snapshot);
@@ -41,7 +38,8 @@ protected:
private: private:
QString name; QString name;
QString description; QString description;
Targets::TargetMemoryType memoryType; const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor;
const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor;
std::vector<FocusedMemoryRegion> focusedRegions; std::vector<FocusedMemoryRegion> focusedRegions;
std::vector<ExcludedMemoryRegion> excludedRegions; std::vector<ExcludedMemoryRegion> excludedRegions;

View File

@@ -10,6 +10,10 @@ ConstructHexViewerTopLevelGroupItem::ConstructHexViewerTopLevelGroupItem(
, hexViewerState(hexViewerState) , hexViewerState(hexViewerState)
{} {}
QString ConstructHexViewerTopLevelGroupItem::brief() const {
return "Preparing hex viewer";
}
void ConstructHexViewerTopLevelGroupItem::run(Services::TargetControllerService&) { void ConstructHexViewerTopLevelGroupItem::run(Services::TargetControllerService&) {
auto* item = new Widgets::TopLevelGroupItem( auto* item = new Widgets::TopLevelGroupItem(
this->focusedMemoryRegions, this->focusedMemoryRegions,

View File

@@ -18,14 +18,7 @@ public:
const std::vector<ExcludedMemoryRegion>& excludedMemoryRegions, const std::vector<ExcludedMemoryRegion>& excludedMemoryRegions,
const Widgets::HexViewerSharedState& hexViewerState const Widgets::HexViewerSharedState& hexViewerState
); );
QString brief() const override;
QString brief() const override {
return "Preparing hex viewer";
}
TaskGroups taskGroups() const override {
return TaskGroups();
};
signals: signals:
void topLevelGroupItem(Widgets::TopLevelGroupItem* item); void topLevelGroupItem(Widgets::TopLevelGroupItem* item);

View File

@@ -3,30 +3,25 @@
#include <QFile> #include <QFile>
#include "src/Services/PathService.hpp" #include "src/Services/PathService.hpp"
#include "src/Helpers/EnumToStringMappings.hpp"
#include "src/Logger/Logger.hpp" #include "src/Logger/Logger.hpp"
using Services::TargetControllerService; using Services::TargetControllerService;
DeleteMemorySnapshot::DeleteMemorySnapshot( DeleteMemorySnapshot::DeleteMemorySnapshot(const QString& snapshotId)
const QString& snapshotId,
Targets::TargetMemoryType memoryType
)
: snapshotId(snapshotId) : snapshotId(snapshotId)
, memoryType(memoryType)
{} {}
void DeleteMemorySnapshot::run(TargetControllerService&) { QString DeleteMemorySnapshot::brief() const {
using Targets::TargetMemorySize; return "Deleting memory snapshot " + this->snapshotId;
}
void DeleteMemorySnapshot::run(TargetControllerService&) {
Logger::info("Deleting snapshot " + this->snapshotId.toStdString()); Logger::info("Deleting snapshot " + this->snapshotId.toStdString());
const auto snapshotFilePath = QString::fromStdString(Services::PathService::projectSettingsDirPath()) const auto snapshotFilePath = QString::fromStdString(Services::PathService::memorySnapshotsPath())
+ "/memory_snapshots/" + EnumToStringMappings::targetMemoryTypes.at(this->memoryType) + "/" + this->snapshotId + ".json";
+ this->snapshotId + ".json";
auto snapshotFile = QFile(snapshotFilePath);
auto snapshotFile = QFile{snapshotFilePath};
if (!snapshotFile.exists()) { if (!snapshotFile.exists()) {
Logger::warning( Logger::warning(
"Could not find snapshot file for " + this->snapshotId.toStdString() + " - expected path: " "Could not find snapshot file for " + this->snapshotId.toStdString() + " - expected path: "

View File

@@ -4,23 +4,17 @@
#include "InsightWorkerTask.hpp" #include "InsightWorkerTask.hpp"
#include "src/Targets/TargetMemory.hpp"
class DeleteMemorySnapshot: public InsightWorkerTask class DeleteMemorySnapshot: public InsightWorkerTask
{ {
Q_OBJECT Q_OBJECT
public: public:
DeleteMemorySnapshot(const QString& snapshotId, Targets::TargetMemoryType memoryType); explicit DeleteMemorySnapshot(const QString& snapshotId);
[[nodiscard]] QString brief() const override ;
QString brief() const override {
return "Deleting memory snapshot " + this->snapshotId;
}
protected: protected:
void run(Services::TargetControllerService& targetControllerService) override; void run(Services::TargetControllerService& targetControllerService) override;
private: private:
QString snapshotId; QString snapshotId;
Targets::TargetMemoryType memoryType;
}; };

View File

@@ -1,7 +0,0 @@
#include "GetTargetDescriptor.hpp"
using Services::TargetControllerService;
void GetTargetDescriptor::run(TargetControllerService& targetControllerService) {
emit this->targetDescriptor(targetControllerService.getTargetDescriptor());
}

View File

@@ -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;
};

View File

@@ -1,7 +0,0 @@
#include "GetTargetState.hpp"
using Services::TargetControllerService;
void GetTargetState::run(TargetControllerService& targetControllerService) {
emit this->targetState(targetControllerService.getTargetState());
}

View File

@@ -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;
};

View File

@@ -8,6 +8,10 @@ InsightWorkerTask::InsightWorkerTask()
: QObject(nullptr) : QObject(nullptr)
{} {}
TaskGroups InsightWorkerTask::taskGroups() const {
return {};
}
void InsightWorkerTask::execute(TargetControllerService& targetControllerService) { void InsightWorkerTask::execute(TargetControllerService& targetControllerService) {
try { try {
this->state = InsightWorkerTaskState::STARTED; this->state = InsightWorkerTaskState::STARTED;
@@ -19,7 +23,7 @@ void InsightWorkerTask::execute(TargetControllerService& targetControllerService
this->setProgressPercentage(100); this->setProgressPercentage(100);
emit this->completed(); emit this->completed();
} catch (std::exception& exception) { } catch (const std::exception& exception) {
this->state = InsightWorkerTaskState::FAILED; this->state = InsightWorkerTaskState::FAILED;
Logger::debug("InsightWorker task failed - " + std::string(exception.what())); Logger::debug("InsightWorker task failed - " + std::string(exception.what()));
emit this->failed(QString::fromStdString(exception.what())); emit this->failed(QString::fromStdString(exception.what()));

View File

@@ -30,12 +30,8 @@ public:
std::atomic<std::uint8_t> progressPercentage = 0; std::atomic<std::uint8_t> progressPercentage = 0;
InsightWorkerTask(); InsightWorkerTask();
[[nodiscard]] virtual QString brief() const = 0;
virtual QString brief() const = 0; [[nodiscard]] virtual TaskGroups taskGroups() const;
virtual TaskGroups taskGroups() const {
return TaskGroups();
};
void execute(Services::TargetControllerService& targetControllerService); void execute(Services::TargetControllerService& targetControllerService);

View File

@@ -1,7 +0,0 @@
#include "ReadProgramCounter.hpp"
using Services::TargetControllerService;
void ReadProgramCounter::run(TargetControllerService& targetControllerService) {
emit this->programCounterRead(targetControllerService.getProgramCounter());
}

View File

@@ -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;
};

View File

@@ -2,6 +2,16 @@
using Services::TargetControllerService; 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) { void ReadStackPointer::run(TargetControllerService& targetControllerService) {
emit this->stackPointerRead(targetControllerService.getStackPointer()); emit this->stackPointerRead(targetControllerService.getStackPointer());
} }

View File

@@ -10,16 +10,8 @@ class ReadStackPointer: public InsightWorkerTask
public: public:
ReadStackPointer() = default; ReadStackPointer() = default;
[[nodiscard]] QString brief() const override;
QString brief() const override { [[nodiscard]] TaskGroups taskGroups() const override;
return "Reading stack pointer";
}
TaskGroups taskGroups() const override {
return TaskGroups({
TaskGroup::USES_TARGET_CONTROLLER,
});
};
signals: signals:
void stackPointerRead(Targets::TargetStackPointer stackPointer); void stackPointerRead(Targets::TargetStackPointer stackPointer);

View File

@@ -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));
}

View File

@@ -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;
};

View File

@@ -1,25 +1,43 @@
#include "ReadTargetMemory.hpp" #include "ReadTargetMemory.hpp"
#include <cstdint>
#include <QLocale>
#include <cmath> #include <cmath>
#include <algorithm> #include <algorithm>
#include "src/Targets/TargetMemory.hpp"
#include "src/Exceptions/Exception.hpp" #include "src/Exceptions/Exception.hpp"
using Services::TargetControllerService; using Services::TargetControllerService;
ReadTargetMemory::ReadTargetMemory(
const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor,
const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor,
Targets::TargetMemoryAddress startAddress,
Targets::TargetMemorySize size,
const std::set<Targets::TargetMemoryAddressRange>& 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) { void ReadTargetMemory::run(TargetControllerService& targetControllerService) {
using Targets::TargetMemorySize; 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. * 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. * command timeouts when we're reading lots of data.
*/ */
const auto readSize = std::max( const auto readSize = std::max(
TargetMemorySize(256), TargetMemorySize{256},
memoryDescriptor.pageSize.value_or(TargetMemorySize(0)) this->memorySegmentDescriptor.pageSize.value_or(TargetMemorySize{0})
); );
const auto readsRequired = static_cast<std::uint32_t>( const auto readsRequired = static_cast<std::uint32_t>(
std::ceil(static_cast<float>(this->size) / static_cast<float>(readSize)) std::ceil(static_cast<float>(this->size) / static_cast<float>(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( auto dataSegment = targetControllerService.readMemory(
this->memoryType, this->addressSpaceDescriptor,
this->memorySegmentDescriptor,
this->startAddress + static_cast<Targets::TargetMemoryAddress>(readSize * i), this->startAddress + static_cast<Targets::TargetMemoryAddress>(readSize * i),
(this->size - data.size()) >= readSize (this->size - data.size()) >= readSize ? readSize : static_cast<TargetMemorySize>(this->size - data.size()),
? readSize
: static_cast<Targets::TargetMemorySize>(this->size - data.size()),
true, true,
this->excludedAddressRanges this->excludedAddressRanges
); );
std::move(dataSegment.begin(), dataSegment.end(), std::back_inserter(data)); data.insert(data.end(), dataSegment.begin(), dataSegment.end());
this->setProgressPercentage(static_cast<std::uint8_t>( this->setProgressPercentage(static_cast<std::uint8_t>(
(static_cast<float>(i) + 1) / (static_cast<float>(readsRequired) / 100) (static_cast<float>(i) + 1) / (static_cast<float>(readsRequired) / 100)
)); ));

View File

@@ -1,11 +1,10 @@
#pragma once #pragma once
#include <cstdint>
#include "InsightWorkerTask.hpp" #include "InsightWorkerTask.hpp"
#include "src/Targets/TargetMemory.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 class ReadTargetMemory: public InsightWorkerTask
{ {
@@ -13,26 +12,14 @@ class ReadTargetMemory: public InsightWorkerTask
public: public:
ReadTargetMemory( ReadTargetMemory(
Targets::TargetMemoryType memoryType, const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor,
const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor,
Targets::TargetMemoryAddress startAddress, Targets::TargetMemoryAddress startAddress,
Targets::TargetMemorySize size, Targets::TargetMemorySize size,
const std::set<Targets::TargetMemoryAddressRange>& excludedAddressRanges = {} const std::set<Targets::TargetMemoryAddressRange>& excludedAddressRanges = {}
) );
: memoryType(memoryType) [[nodiscard]] QString brief() const override ;
, startAddress(startAddress) [[nodiscard]] TaskGroups taskGroups() const override;
, 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,
});
};
signals: signals:
void targetMemoryRead(Targets::TargetMemoryBuffer buffer); void targetMemoryRead(Targets::TargetMemoryBuffer buffer);
@@ -41,7 +28,8 @@ protected:
void run(Services::TargetControllerService& targetControllerService) override; void run(Services::TargetControllerService& targetControllerService) override;
private: private:
Targets::TargetMemoryType memoryType; const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor;
const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor;
Targets::TargetMemoryAddress startAddress; Targets::TargetMemoryAddress startAddress;
Targets::TargetMemorySize size; Targets::TargetMemorySize size;
std::set<Targets::TargetMemoryAddressRange> excludedAddressRanges; std::set<Targets::TargetMemoryAddressRange> excludedAddressRanges;

View File

@@ -1,7 +1,25 @@
#include "ReadTargetRegisters.hpp" #include "ReadTargetRegisters.hpp"
#include <QLocale>
using Services::TargetControllerService; using Services::TargetControllerService;
void ReadTargetRegisters::run(TargetControllerService& targetControllerService) { ReadTargetRegisters::ReadTargetRegisters(const Targets::TargetRegisterDescriptors& descriptors)
emit this->targetRegistersRead(targetControllerService.readRegisters(this->descriptorIds)); : 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));
} }

View File

@@ -2,33 +2,22 @@
#include "InsightWorkerTask.hpp" #include "InsightWorkerTask.hpp"
#include "src/Targets/TargetRegisterDescriptor.hpp" #include "src/Targets/TargetRegisterDescriptor.hpp"
#include "src/Targets/TargetRegister.hpp"
class ReadTargetRegisters: public InsightWorkerTask class ReadTargetRegisters: public InsightWorkerTask
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit ReadTargetRegisters(const Targets::TargetRegisterDescriptorIds& descriptorIds) explicit ReadTargetRegisters(const Targets::TargetRegisterDescriptors& descriptors);
: descriptorIds(descriptorIds) [[nodiscard]] QString brief() const override;
{} [[nodiscard]] TaskGroups taskGroups() const override;
QString brief() const override {
return "Reading " + QString::number(this->descriptorIds.size()) + " target register(s)";
}
TaskGroups taskGroups() const override {
return TaskGroups({
TaskGroup::USES_TARGET_CONTROLLER,
});
};
signals: signals:
void targetRegistersRead(Targets::TargetRegisters registers); void targetRegistersRead(Targets::TargetRegisterDescriptorAndValuePairs registers);
protected: protected:
void run(Services::TargetControllerService& targetControllerService) override; void run(Services::TargetControllerService& targetControllerService) override;
private: private:
Targets::TargetRegisterDescriptorIds descriptorIds; Targets::TargetRegisterDescriptors descriptors;
}; };

View File

@@ -1,7 +0,0 @@
#include "RefreshTargetPinStates.hpp"
using Services::TargetControllerService;
void RefreshTargetPinStates::run(TargetControllerService& targetControllerService) {
emit this->targetPinStatesRetrieved(targetControllerService.getPinStates(this->variantId));
}

View File

@@ -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;
};

View File

@@ -2,48 +2,74 @@
#include <QFile> #include <QFile>
#include <QDir> #include <QDir>
#include <QStringList> #include <QDirIterator>
#include <QJsonDocument> #include <QJsonDocument>
#include <algorithm>
#include <utility>
#include "src/Services/PathService.hpp" #include "src/Services/PathService.hpp"
#include "src/Helpers/EnumToStringMappings.hpp"
#include "src/Exceptions/Exception.hpp"
#include "src/Logger/Logger.hpp" #include "src/Logger/Logger.hpp"
#include "src/Exceptions/Exception.hpp"
using Services::TargetControllerService; using Services::TargetControllerService;
RetrieveMemorySnapshots::RetrieveMemorySnapshots(Targets::TargetMemoryType memoryType) RetrieveMemorySnapshots::RetrieveMemorySnapshots(
: memoryType(memoryType) const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor,
const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor,
const Targets::TargetDescriptor& targetDescriptor
)
: addressSpaceDescriptor(addressSpaceDescriptor)
, memorySegmentDescriptor(memorySegmentDescriptor)
, targetDescriptor(targetDescriptor)
{} {}
void RetrieveMemorySnapshots::run(TargetControllerService& targetControllerService) { QString RetrieveMemorySnapshots::brief() const {
emit this->memorySnapshotsRetrieved(this->getSnapshots(this->memoryType)); return "Loading \"" + QString::fromStdString(this->memorySegmentDescriptor.name)
+ "\" memory snapshots";
} }
std::vector<MemorySnapshot> RetrieveMemorySnapshots::getSnapshots(Targets::TargetMemoryType memoryType) { void RetrieveMemorySnapshots::run(TargetControllerService& targetControllerService) {
constexpr auto MAX_SNAPSHOTS = 30; if (
auto snapshotDir = QDir(QString::fromStdString(Services::PathService::projectSettingsDirPath()) this->targetDescriptor.family == Targets::TargetFamily::AVR_8
+ "/memory_snapshots/" + EnumToStringMappings::targetMemoryTypes.at(memoryType)); && (
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<MemorySnapshot> RetrieveMemorySnapshots::getSnapshots() {
constexpr auto MAX_SNAPSHOTS = 30;
const auto snapshotDir = QDir{QString::fromStdString(Services::PathService::memorySnapshotsPath())};
if (!snapshotDir.exists()) { if (!snapshotDir.exists()) {
return {}; return {};
} }
auto snapshots = std::vector<MemorySnapshot>();
const auto snapshotFileEntries = snapshotDir.entryInfoList( const auto snapshotFileEntries = snapshotDir.entryInfoList(
QStringList("*.json"), {"*.json"},
QDir::Files, QDir::Files,
QDir::SortFlag::Time QDir::SortFlag::Time
); );
auto snapshots = std::vector<MemorySnapshot>{};
for (const auto& snapshotFileEntry : snapshotFileEntries) { for (const auto& snapshotFileEntry : snapshotFileEntries) {
auto snapshotFile = QFile(snapshotFileEntry.absoluteFilePath()); auto snapshotFile = QFile{snapshotFileEntry.absoluteFilePath()};
if (snapshots.size() >= MAX_SNAPSHOTS) { if (snapshots.size() >= MAX_SNAPSHOTS) {
Logger::warning( Logger::warning(
"The total number of " + EnumToStringMappings::targetMemoryTypes.at(memoryType).toUpper().toStdString() "The total number of \"" + this->memorySegmentDescriptor.key
+ " snapshots exceeds the hard limit of " + std::to_string(MAX_SNAPSHOTS) + "\" snapshots exceeds the hard limit of " + std::to_string(MAX_SNAPSHOTS)
+ ". Only the most recent " + std::to_string(MAX_SNAPSHOTS) + " snapshots will be loaded." + ". Only the most recent " + std::to_string(MAX_SNAPSHOTS) + " snapshots will be loaded."
); );
break; break;
@@ -51,10 +77,18 @@ std::vector<MemorySnapshot> RetrieveMemorySnapshots::getSnapshots(Targets::Targe
try { try {
if (!snapshotFile.open(QIODevice::ReadOnly | QIODevice::Text)) { 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) { } catch (const Exceptions::Exception& exception) {
Logger::error( Logger::error(
@@ -68,3 +102,70 @@ std::vector<MemorySnapshot> RetrieveMemorySnapshots::getSnapshots(Targets::Targe
return snapshots; 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();
// }
}

View File

@@ -1,10 +1,16 @@
#pragma once #pragma once
#include <vector> #include <vector>
#include <QFileInfo>
#include <QString>
#include "InsightWorkerTask.hpp" #include "InsightWorkerTask.hpp"
#include "src/Targets/TargetMemory.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/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/MemorySnapshot.hpp"
#include "src/Helpers/EnumToStringMappings.hpp" #include "src/Helpers/EnumToStringMappings.hpp"
@@ -13,12 +19,12 @@ class RetrieveMemorySnapshots: public InsightWorkerTask
Q_OBJECT Q_OBJECT
public: public:
RetrieveMemorySnapshots(Targets::TargetMemoryType memoryType); RetrieveMemorySnapshots(
const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor,
QString brief() const override { const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor,
return "Loading saved " + EnumToStringMappings::targetMemoryTypes.at(this->memoryType).toUpper() const Targets::TargetDescriptor& targetDescriptor
+ " memory snapshots"; );
} [[nodiscard]] QString brief() const override;
signals: signals:
void memorySnapshotsRetrieved(std::vector<MemorySnapshot> snapshots); void memorySnapshotsRetrieved(std::vector<MemorySnapshot> snapshots);
@@ -27,7 +33,10 @@ protected:
void run(Services::TargetControllerService& targetControllerService) override; void run(Services::TargetControllerService& targetControllerService) override;
private: private:
Targets::TargetMemoryType memoryType; const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor;
const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor;
const Targets::TargetDescriptor& targetDescriptor;
std::vector<MemorySnapshot> getSnapshots(Targets::TargetMemoryType memoryType); std::vector<MemorySnapshot> getSnapshots();
void migrateOldSnapshotFiles();
}; };

View File

@@ -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);
}

View File

@@ -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;
};

View File

@@ -1,7 +0,0 @@
#include "SetTargetPinState.hpp"
using Services::TargetControllerService;
void SetTargetPinState::run(TargetControllerService& targetControllerService) {
targetControllerService.setPinState(this->pinDescriptor, this->pinState);
}

View File

@@ -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;
};

View File

@@ -1,18 +1,52 @@
#include "WriteTargetMemory.hpp" #include "WriteTargetMemory.hpp"
#include <cmath> #include <cmath>
#include <QLocale>
#include <algorithm> #include <algorithm>
#include <numeric> #include <numeric>
#include "src/Exceptions/Exception.hpp" #include "src/Exceptions/Exception.hpp"
using Services::TargetControllerService; using Services::TargetControllerService;
using Targets::TargetMemorySize;
WriteTargetMemory::WriteTargetMemory(
const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor,
const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor,
std::vector<Block>&& 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<Block>{{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) { void WriteTargetMemory::run(TargetControllerService& targetControllerService) {
using Targets::TargetMemorySize; if (!this->memorySegmentDescriptor.debugModeAccess.writeable) {
throw Exceptions::Exception{"Invalid request - cannot write to this memory segment during a debug session."};
if (!this->memoryDescriptor.access.writeableDuringDebugSession) {
throw Exceptions::Exception("Invalid request - cannot write to this memory type during a debug session.");
} }
/* /*
@@ -23,20 +57,12 @@ void WriteTargetMemory::run(TargetControllerService& targetControllerService) {
* command timeouts when we're writing lots of data. * command timeouts when we're writing lots of data.
*/ */
const auto maxBlockSize = std::max( const auto maxBlockSize = std::max(
TargetMemorySize(256), TargetMemorySize{256},
this->memoryDescriptor.pageSize.value_or(TargetMemorySize(0)) this->memorySegmentDescriptor.pageSize.value_or(TargetMemorySize{0})
); );
const TargetMemorySize totalBytesToWrite = std::accumulate( const auto writeSize = this->totalSize();
this->blocks.begin(), auto totalBytesWritten = TargetMemorySize{0};
this->blocks.end(),
TargetMemorySize{0},
[] (TargetMemorySize bytes, const Block& block) {
return bytes + block.data.size();
}
);
TargetMemorySize totalBytesWritten = 0;
for (const auto& block : this->blocks) { for (const auto& block : this->blocks) {
const auto totalBytes = block.data.size(); const auto totalBytes = block.data.size();
@@ -50,22 +76,34 @@ void WriteTargetMemory::run(TargetControllerService& targetControllerService) {
); );
targetControllerService.writeMemory( targetControllerService.writeMemory(
this->memoryDescriptor.type, this->addressSpaceDescriptor,
this->memorySegmentDescriptor,
block.startAddress + bytesWritten, block.startAddress + bytesWritten,
Targets::TargetMemoryBuffer( Targets::TargetMemoryBuffer{
block.data.begin() + bytesWritten, block.data.begin() + bytesWritten,
block.data.begin() + bytesWritten + bytesToWrite block.data.begin() + bytesWritten + bytesToWrite
) }
); );
bytesWritten += bytesToWrite; bytesWritten += bytesToWrite;
totalBytesWritten += bytesToWrite; totalBytesWritten += bytesToWrite;
this->setProgressPercentage(static_cast<std::uint8_t>( this->setProgressPercentage(static_cast<std::uint8_t>(
(static_cast<float>(totalBytesWritten) + 1) / (static_cast<float>(totalBytesToWrite) / 100) (static_cast<float>(totalBytesWritten) + 1) / (static_cast<float>(writeSize) / 100)
)); ));
} }
} }
emit this->targetMemoryWritten(totalBytesWritten); 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();
}
);
}

View File

@@ -5,7 +5,8 @@
#include "InsightWorkerTask.hpp" #include "InsightWorkerTask.hpp"
#include "src/Targets/TargetMemory.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 class WriteTargetMemory: public InsightWorkerTask
{ {
@@ -30,33 +31,18 @@ public:
}; };
WriteTargetMemory( WriteTargetMemory(
const Targets::TargetMemoryDescriptor& memoryDescriptor, const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor,
const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor,
std::vector<Block>&& blocks std::vector<Block>&& blocks
) );
: memoryDescriptor(memoryDescriptor)
, blocks(std::move(blocks))
{}
WriteTargetMemory( WriteTargetMemory(
const Targets::TargetMemoryDescriptor& memoryDescriptor, const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor,
const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor,
Targets::TargetMemoryAddress startAddress, Targets::TargetMemoryAddress startAddress,
const Targets::TargetMemoryBuffer& data const Targets::TargetMemoryBuffer& data
) );
: WriteTargetMemory(memoryDescriptor, std::vector<Block>({{startAddress, data}})) [[nodiscard]] QString brief() const override;
{} [[nodiscard]] TaskGroups taskGroups() const override;
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,
});
}
signals: signals:
void targetMemoryWritten(Targets::TargetMemorySize bytesWritten); void targetMemoryWritten(Targets::TargetMemorySize bytesWritten);
@@ -65,6 +51,9 @@ protected:
void run(Services::TargetControllerService& targetControllerService) override; void run(Services::TargetControllerService& targetControllerService) override;
private: private:
Targets::TargetMemoryDescriptor memoryDescriptor; const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor;
const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor;
std::vector<Block> blocks; std::vector<Block> blocks;
[[nodiscard]] Targets::TargetMemorySize totalSize() const;
}; };

View File

@@ -2,6 +2,20 @@
using Services::TargetControllerService; using Services::TargetControllerService;
void WriteTargetRegister::run(TargetControllerService& targetControllerService) { WriteTargetRegister::WriteTargetRegister(const Targets::TargetRegisterDescriptorAndValuePair& registerPair)
targetControllerService.writeRegisters({this->targetRegister}); : 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});
} }

View File

@@ -1,30 +1,20 @@
#pragma once #pragma once
#include "InsightWorkerTask.hpp" #include "InsightWorkerTask.hpp"
#include "src/Targets/TargetRegister.hpp" #include "src/Targets/TargetRegisterDescriptor.hpp"
class WriteTargetRegister: public InsightWorkerTask class WriteTargetRegister: public InsightWorkerTask
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit WriteTargetRegister(const Targets::TargetRegister& targetRegister) explicit WriteTargetRegister(const Targets::TargetRegisterDescriptorAndValuePair& registerPair);
: targetRegister(targetRegister) [[nodiscard]] QString brief() const override;
{} [[nodiscard]] TaskGroups taskGroups() const override;
QString brief() const override {
return "Writing target register";
}
TaskGroups taskGroups() const override {
return TaskGroups({
TaskGroup::USES_TARGET_CONTROLLER,
});
};
protected: protected:
void run(Services::TargetControllerService& targetControllerService) override; void run(Services::TargetControllerService& targetControllerService) override;
private: private:
Targets::TargetRegister targetRegister; Targets::TargetRegisterDescriptorAndValuePair registerPair;
}; };

View File

@@ -11,26 +11,28 @@
using namespace Exceptions; using namespace Exceptions;
AboutWindow::AboutWindow(QWidget* parent): QObject(parent) { AboutWindow::AboutWindow(QWidget* parent): QObject(parent) {
auto aboutWindowUiFile = QFile(QString::fromStdString( auto aboutWindowUiFile = QFile{
QString::fromStdString(
Services::PathService::compiledResourcesPath() 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() Services::PathService::compiledResourcesPath()
+ "/src/Insight/UserInterfaces/InsightWindow/Stylesheets/AboutWindow.qss" + "/src/Insight/UserInterfaces/InsightWindow/Stylesheets/AboutWindow.qss"
) )
); };
if (!aboutWindowUiFile.open(QFile::ReadOnly)) { 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)) { 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 = uiLoader.load(&aboutWindowUiFile, parent);
this->windowWidget->setStyleSheet(aboutWindowStylesheet.readAll()); this->windowWidget->setStyleSheet(aboutWindowStylesheet.readAll());
this->windowWidget->setFixedSize(400, 300); this->windowWidget->setFixedSize(400, 300);

File diff suppressed because it is too large Load Diff

View File

@@ -12,6 +12,8 @@
#include "src/Targets/TargetDescriptor.hpp" #include "src/Targets/TargetDescriptor.hpp"
#include "src/Targets/TargetMemory.hpp" #include "src/Targets/TargetMemory.hpp"
#include "src/Targets/TargetVariantDescriptor.hpp"
#include "src/Targets/TargetPinoutDescriptor.hpp"
#include "Widgets/Label.hpp" #include "Widgets/Label.hpp"
#include "Widgets/SvgToolButton.hpp" #include "Widgets/SvgToolButton.hpp"
@@ -20,6 +22,7 @@
#include "Widgets/PanelWidget.hpp" #include "Widgets/PanelWidget.hpp"
#include "Widgets/TargetRegistersPane/TargetRegistersPaneWidget.hpp" #include "Widgets/TargetRegistersPane/TargetRegistersPaneWidget.hpp"
#include "Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.hpp" #include "Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.hpp"
#include "Widgets/TargetMemoryInspectionPane/ToolButton.hpp"
#include "Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPaneSettings.hpp" #include "Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPaneSettings.hpp"
#include "Widgets/TaskIndicator/TaskIndicator.hpp" #include "Widgets/TaskIndicator/TaskIndicator.hpp"
#include "AboutWindow.hpp" #include "AboutWindow.hpp"
@@ -33,7 +36,8 @@ public:
InsightProjectSettings& insightProjectSettings, InsightProjectSettings& insightProjectSettings,
const InsightConfig& insightConfig, const InsightConfig& insightConfig,
const EnvironmentConfig& environmentConfig, const EnvironmentConfig& environmentConfig,
const Targets::TargetDescriptor& targetDescriptor const Targets::TargetDescriptor& targetDescriptor,
const Targets::TargetState& targetState
); );
protected: protected:
@@ -49,7 +53,7 @@ private:
TargetConfig targetConfig; TargetConfig targetConfig;
const Targets::TargetDescriptor& targetDescriptor; const Targets::TargetDescriptor& targetDescriptor;
Targets::TargetState targetState = Targets::TargetState::UNKNOWN; const Targets::TargetState& targetState;
QWidget* windowContainer = nullptr; QWidget* windowContainer = nullptr;
QMenuBar* mainMenuBar = nullptr; QMenuBar* mainMenuBar = nullptr;
@@ -68,60 +72,46 @@ private:
Widgets::TargetRegistersPaneWidget* targetRegistersSidePane = nullptr; Widgets::TargetRegistersPaneWidget* targetRegistersSidePane = nullptr;
QToolButton* targetRegistersButton = nullptr; QToolButton* targetRegistersButton = nullptr;
Widgets::Label* ioUnavailableWidget = nullptr;
Widgets::InsightTargetWidgets::TargetPackageWidgetContainer* ioContainerWidget = nullptr; Widgets::InsightTargetWidgets::TargetPackageWidgetContainer* ioContainerWidget = nullptr;
Widgets::InsightTargetWidgets::TargetPackageWidget* targetPackageWidget = nullptr; Widgets::InsightTargetWidgets::TargetPackageWidget* targetPackageWidget = nullptr;
QWidget* bottomMenuBar = nullptr; QWidget* bottomMenuBar = nullptr;
QHBoxLayout* bottomMenuBarLayout = nullptr;
Widgets::PanelWidget* bottomPanel = nullptr; Widgets::PanelWidget* bottomPanel = nullptr;
Widgets::TargetMemoryInspectionPane* ramInspectionPane = nullptr; std::vector<Widgets::TargetMemoryInspectionPane*> memoryInspectionPaneWidgets = {};
Widgets::TargetMemoryInspectionPane* eepromInspectionPane = nullptr;
Widgets::TargetMemoryInspectionPane* flashInspectionPane = nullptr;
std::map<
Targets::TargetMemoryType,
Widgets::TargetMemoryInspectionPaneSettings
> memoryInspectionPaneSettingsByMemoryType;
QToolButton* ramInspectionButton = nullptr;
QToolButton* eepromInspectionButton = nullptr;
QToolButton* flashInspectionButton = nullptr;
QWidget* footer = nullptr; QWidget* footer = nullptr;
Widgets::Label* targetStatusLabel = nullptr; Widgets::Label* targetStatusLabel = nullptr;
Widgets::Label* programCounterValueLabel = nullptr; Widgets::Label* programCounterValueLabel = nullptr;
Widgets::TaskIndicator* taskIndicator = nullptr; Widgets::TaskIndicator* taskIndicator = nullptr;
std::map<QString, Targets::TargetVariant> supportedVariantsByName; const Targets::TargetVariantDescriptor* selectedVariantDescriptor = nullptr;
const Targets::TargetVariant* selectedVariant = nullptr;
std::optional<Targets::TargetVariant> previouslySelectedVariant;
bool uiDisabled = false; bool uiDisabled = false;
static bool isVariantSupported(const Targets::TargetVariant& variant); static bool isPinoutSupported(const Targets::TargetPinoutDescriptor& pinoutDescriptor);
void setUiDisabled(bool disable); void setUiDisabled(bool disable);
void populateVariantMenu(); void populateVariantMenu();
void selectDefaultVariant(); void selectDefaultVariant();
void selectVariant(const Targets::TargetVariant* variant); void selectVariant(const Targets::TargetVariantDescriptor* variantDescriptor);
void createPanes(); void createPanes();
void adjustPanels(); void adjustPanels();
void adjustMinimumSize(); void adjustMinimumSize();
void onTargetStateUpdate(Targets::TargetState newState); void onTargetStateUpdate(Targets::TargetState newState, Targets::TargetState previousState);
void refresh(); void refresh();
void refreshPinStates(); void refreshPadStates();
void refreshProgramCounter(std::optional<std::function<void(void)>> callback = std::nullopt);
void openReportIssuesUrl(); void openReportIssuesUrl();
void openGettingStartedUrl(); void openGettingStartedUrl();
void openAboutWindow(); void openAboutWindow();
void toggleTargetRegistersPane(); void toggleTargetRegistersPane();
void toggleRamInspectionPane(); void toggleMemoryInspectionPane(Widgets::TargetMemoryInspectionPane* pane);
void toggleEepromInspectionPane(); void toggleEepromInspectionPane();
void toggleFlashInspectionPane(); void toggleFlashInspectionPane();
void onRegistersPaneStateChanged(); void onRegistersPaneStateChanged();
void onRamInspectionPaneStateChanged(); void onMemoryInspectionPaneStateChanged(Widgets::TargetMemoryInspectionPane* pane, Widgets::ToolButton* toolBtn);
void onEepromInspectionPaneStateChanged();
void onFlashInspectionPaneStateChanged();
void onProgrammingModeEnabled(); void onProgrammingModeEnabled();
void onProgrammingModeDisabled(); void onProgrammingModeDisabled();
}; };

View File

@@ -188,38 +188,14 @@ QToolTip {
border-top: 1px solid #2F2F2D; border-top: 1px solid #2F2F2D;
} }
#bottom-menu-bar #ram-inspection-btn, #bottom-menu-bar QToolButton {
#bottom-menu-bar #eeprom-inspection-btn,
#bottom-menu-bar #flash-inspection-btn {
position: relative; position: relative;
border: none; border: none;
min-height: 22px; min-height: 22px;
} }
#bottom-menu-bar #ram-inspection-btn { #bottom-menu-bar QToolButton QLabel {
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 {
color: #999a9d; color: #999a9d;
margin-left: 5px;
} }
#bottom-menu-bar QToolButton:hover, #bottom-menu-bar QToolButton:hover,

View File

@@ -250,159 +250,6 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item>
<widget class="QToolButton" name="ram-inspection-btn">
<property name="toolTip">
<string>Inspect RAM</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="disabled">
<bool>false</bool>
</property>
<layout class="QHBoxLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item alignment="Qt::AlignLeft">
<widget class="SvgWidget" name="ram-inspection-btn-icon">
<property name="containerHeight">
<number>22</number>
</property>
<property name="containerWidth">
<number>26</number>
</property>
<property name="svgFilePath">
<string>:/compiled/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/Images/memory-inspection-icon.svg</string>
</property>
<property name="disabledSvgFilePath">
<string>:/compiled/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/Images/memory-inspection-icon-disabled.svg</string>
</property>
</widget>
</item>
<item alignment="Qt::AlignLeft">
<widget class="Label" name="ram-inspection-btn-label">
<property name="text">
<string>RAM</string>
</property>
</widget>
</item>
<item alignment="Qt::AlignLeft">
<spacer name="horizontal-spacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QToolButton" name="eeprom-inspection-btn">
<property name="toolTip">
<string>Inspect EEPROM</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="disabled">
<bool>false</bool>
</property>
<layout class="QHBoxLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item alignment="Qt::AlignLeft">
<widget class="SvgWidget" name="eeprom-inspection-btn-icon">
<property name="containerHeight">
<number>22</number>
</property>
<property name="containerWidth">
<number>26</number>
</property>
<property name="svgFilePath">
<string>:/compiled/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/Images/memory-inspection-icon.svg</string>
</property>
<property name="disabledSvgFilePath">
<string>:/compiled/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/Images/memory-inspection-icon-disabled.svg</string>
</property>
</widget>
</item>
<item alignment="Qt::AlignLeft">
<widget class="Label" name="eeprom-inspection-btn-label">
<property name="text">
<string>EEPROM</string>
</property>
</widget>
</item>
<item alignment="Qt::AlignLeft">
<spacer name="horizontal-spacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QToolButton" name="flash-inspection-btn">
<property name="toolTip">
<string>Inspect FLASH</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="disabled">
<bool>false</bool>
</property>
<layout class="QHBoxLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item alignment="Qt::AlignLeft">
<widget class="SvgWidget" name="flash-inspection-btn-icon">
<property name="containerHeight">
<number>22</number>
</property>
<property name="containerWidth">
<number>26</number>
</property>
<property name="svgFilePath">
<string>:/compiled/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/Images/memory-inspection-icon.svg</string>
</property>
<property name="disabledSvgFilePath">
<string>:/compiled/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/Images/memory-inspection-icon-disabled.svg</string>
</property>
</widget>
</item>
<item alignment="Qt::AlignLeft">
<widget class="Label" name="flash-inspection-btn-label">
<property name="text">
<string>FLASH</string>
</property>
</widget>
</item>
<item alignment="Qt::AlignLeft">
<spacer name="horizontal-spacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item> <item>
<spacer name="horizontal-spacer"> <spacer name="horizontal-spacer">
<property name="orientation"> <property name="orientation">

View File

@@ -16,12 +16,14 @@
using namespace Widgets; using namespace Widgets;
UiLoader::UiLoader(QObject* parent): QUiLoader(parent) { UiLoader::UiLoader(QObject* parent)
: QUiLoader(parent)
{
this->customWidgetConstructorsByWidgetName = { this->customWidgetConstructorsByWidgetName = {
{ {
"Label", "Label",
[this] (QWidget* parent, const QString& name) { [this] (QWidget* parent, const QString& name) {
auto* widget = new Label(parent); auto* widget = new Label{parent};
widget->setObjectName(name); widget->setObjectName(name);
widget->setStyleSheet(parent->styleSheet()); widget->setStyleSheet(parent->styleSheet());
return widget; return widget;
@@ -30,7 +32,7 @@ UiLoader::UiLoader(QObject* parent): QUiLoader(parent) {
{ {
"RotatableLabel", "RotatableLabel",
[this] (QWidget* parent, const QString& name) { [this] (QWidget* parent, const QString& name) {
auto* widget = new RotatableLabel("", parent); auto* widget = new RotatableLabel{"", parent};
widget->setObjectName(name); widget->setObjectName(name);
widget->setStyleSheet(parent->styleSheet()); widget->setStyleSheet(parent->styleSheet());
return widget; return widget;
@@ -39,7 +41,7 @@ UiLoader::UiLoader(QObject* parent): QUiLoader(parent) {
{ {
"LabeledSeparator", "LabeledSeparator",
[this] (QWidget* parent, const QString& name) { [this] (QWidget* parent, const QString& name) {
auto* widget = new LabeledSeparator(parent); auto* widget = new LabeledSeparator{parent};
widget->setObjectName(name); widget->setObjectName(name);
widget->setStyleSheet(parent->styleSheet()); widget->setStyleSheet(parent->styleSheet());
return widget; return widget;
@@ -48,7 +50,7 @@ UiLoader::UiLoader(QObject* parent): QUiLoader(parent) {
{ {
"TextInput", "TextInput",
[this] (QWidget* parent, const QString& name) { [this] (QWidget* parent, const QString& name) {
auto* widget = new TextInput(parent); auto* widget = new TextInput{parent};
widget->setObjectName(name); widget->setObjectName(name);
widget->setStyleSheet(parent->styleSheet()); widget->setStyleSheet(parent->styleSheet());
return widget; return widget;
@@ -57,7 +59,7 @@ UiLoader::UiLoader(QObject* parent): QUiLoader(parent) {
{ {
"PlainTextEdit", "PlainTextEdit",
[this] (QWidget* parent, const QString& name) { [this] (QWidget* parent, const QString& name) {
auto* widget = new PlainTextEdit(parent); auto* widget = new PlainTextEdit{parent};
widget->setObjectName(name); widget->setObjectName(name);
widget->setStyleSheet(parent->styleSheet()); widget->setStyleSheet(parent->styleSheet());
return widget; return widget;
@@ -66,7 +68,7 @@ UiLoader::UiLoader(QObject* parent): QUiLoader(parent) {
{ {
"PushButton", "PushButton",
[this] (QWidget* parent, const QString& name) { [this] (QWidget* parent, const QString& name) {
auto* widget = new PushButton(parent); auto* widget = new PushButton{parent};
widget->setObjectName(name); widget->setObjectName(name);
widget->setStyleSheet(parent->styleSheet()); widget->setStyleSheet(parent->styleSheet());
return widget; return widget;
@@ -75,7 +77,7 @@ UiLoader::UiLoader(QObject* parent): QUiLoader(parent) {
{ {
"ExpandingHeightScrollAreaWidget", "ExpandingHeightScrollAreaWidget",
[this] (QWidget* parent, const QString& name) { [this] (QWidget* parent, const QString& name) {
auto* widget = new ExpandingHeightScrollAreaWidget(parent); auto* widget = new ExpandingHeightScrollAreaWidget{parent};
widget->setObjectName(name); widget->setObjectName(name);
widget->setStyleSheet(parent->styleSheet()); widget->setStyleSheet(parent->styleSheet());
return widget; return widget;
@@ -84,7 +86,7 @@ UiLoader::UiLoader(QObject* parent): QUiLoader(parent) {
{ {
"SvgWidget", "SvgWidget",
[this] (QWidget* parent, const QString& name) { [this] (QWidget* parent, const QString& name) {
auto* widget = new SvgWidget(parent); auto* widget = new SvgWidget{parent};
widget->setObjectName(name); widget->setObjectName(name);
widget->setStyleSheet(parent->styleSheet()); widget->setStyleSheet(parent->styleSheet());
return widget; return widget;
@@ -93,7 +95,7 @@ UiLoader::UiLoader(QObject* parent): QUiLoader(parent) {
{ {
"SvgToolButton", "SvgToolButton",
[this] (QWidget* parent, const QString& name) { [this] (QWidget* parent, const QString& name) {
auto* widget = new SvgToolButton(parent); auto* widget = new SvgToolButton{parent};
widget->setObjectName(name); widget->setObjectName(name);
widget->setStyleSheet(parent->styleSheet()); widget->setStyleSheet(parent->styleSheet());
return widget; return widget;
@@ -102,7 +104,7 @@ UiLoader::UiLoader(QObject* parent): QUiLoader(parent) {
{ {
"TargetPackageWidgetContainer", "TargetPackageWidgetContainer",
[this] (QWidget* parent, const QString& name) { [this] (QWidget* parent, const QString& name) {
auto* widget = new InsightTargetWidgets::TargetPackageWidgetContainer(parent); auto* widget = new InsightTargetWidgets::TargetPackageWidgetContainer{parent};
widget->setObjectName(name); widget->setObjectName(name);
widget->setStyleSheet(parent->styleSheet()); widget->setStyleSheet(parent->styleSheet());
return widget; return widget;

View File

@@ -11,7 +11,9 @@ namespace Widgets
Q_OBJECT Q_OBJECT
public: public:
explicit ClickableWidget(QWidget* parent): QFrame(parent) {}; explicit ClickableWidget(QWidget* parent)
: QFrame(parent)
{};
signals: signals:
void rightClicked(); void rightClicked();

View File

@@ -26,7 +26,7 @@ namespace Widgets
void aborted(); void aborted();
protected: protected:
PushButton* confirmButton = new PushButton(this); PushButton* confirmButton = new PushButton{this};
PushButton* cancelButton = new PushButton(this); PushButton* cancelButton = new PushButton{this};
}; };
} }

View File

@@ -21,29 +21,29 @@ namespace Widgets
this->setAttribute(Qt::WA_DeleteOnClose, true); this->setAttribute(Qt::WA_DeleteOnClose, true);
this->setWindowTitle(windowTitle); this->setWindowTitle(windowTitle);
auto dialogUiFile = QFile( auto dialogUiFile = QFile{
QString::fromStdString(Services::PathService::compiledResourcesPath() QString::fromStdString(Services::PathService::compiledResourcesPath()
+ "/src/Insight/UserInterfaces/InsightWindow/Widgets/Dialog/UiFiles/Dialog.ui" + "/src/Insight/UserInterfaces/InsightWindow/Widgets/Dialog/UiFiles/Dialog.ui"
) )
); };
auto dialogStylesheet = QFile( auto dialogStylesheet = QFile{
QString::fromStdString(Services::PathService::compiledResourcesPath() QString::fromStdString(Services::PathService::compiledResourcesPath()
+ "/src/Insight/UserInterfaces/InsightWindow/Widgets/Dialog/Stylesheets/Dialog.qss" + "/src/Insight/UserInterfaces/InsightWindow/Widgets/Dialog/Stylesheets/Dialog.qss"
) )
); };
if (!dialogUiFile.open(QFile::ReadOnly)) { 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)) { 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()); this->setStyleSheet(dialogStylesheet.readAll());
auto uiLoader = UiLoader(this); auto uiLoader = UiLoader{this};
this->container = uiLoader.load(&dialogUiFile, this); this->container = uiLoader.load(&dialogUiFile, this);
this->textLabel = this->container->findChild<Label*>("text-label"); this->textLabel = this->container->findChild<Label*>("text-label");
@@ -58,10 +58,10 @@ namespace Widgets
void Dialog::showEvent(QShowEvent* event) { void Dialog::showEvent(QShowEvent* event) {
const auto containerSize = this->container->sizeHint(); const auto containerSize = this->container->sizeHint();
const auto windowSize = QSize( const auto windowSize = QSize{
std::max(containerSize.width(), 500), std::max(containerSize.width(), 500),
std::max(containerSize.height(), 100) std::max(containerSize.height(), 100)
); };
this->setFixedSize(windowSize); this->setFixedSize(windowSize);
this->container->setFixedSize(windowSize); this->container->setFixedSize(windowSize);

View File

@@ -22,29 +22,29 @@ namespace Widgets
this->setAttribute(Qt::WA_DeleteOnClose, true); this->setAttribute(Qt::WA_DeleteOnClose, true);
this->setWindowTitle(windowTitle); this->setWindowTitle(windowTitle);
auto dialogueUiFile = QFile( auto dialogueUiFile = QFile{
QString::fromStdString(Services::PathService::compiledResourcesPath() QString::fromStdString(Services::PathService::compiledResourcesPath()
+ "/src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/UiFiles/ErrorDialogue.ui" + "/src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/UiFiles/ErrorDialogue.ui"
) )
); };
auto dialogueStylesheet = QFile( auto dialogueStylesheet = QFile{
QString::fromStdString(Services::PathService::compiledResourcesPath() QString::fromStdString(Services::PathService::compiledResourcesPath()
+ "/src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/Stylesheets/ErrorDialogue.qss" + "/src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/Stylesheets/ErrorDialogue.qss"
) )
); };
if (!dialogueUiFile.open(QFile::ReadOnly)) { 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)) { 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()); this->setStyleSheet(dialogueStylesheet.readAll());
auto uiLoader = UiLoader(this); auto uiLoader = UiLoader{this};
this->container = uiLoader.load(&dialogueUiFile, this); this->container = uiLoader.load(&dialogueUiFile, this);
this->errorMessageDescriptionLabel = this->container->findChild<Label*>( this->errorMessageDescriptionLabel = this->container->findChild<Label*>(
@@ -61,10 +61,10 @@ namespace Widgets
void ErrorDialogue::showEvent(QShowEvent* event) { void ErrorDialogue::showEvent(QShowEvent* event) {
const auto containerSize = this->container->sizeHint(); const auto containerSize = this->container->sizeHint();
const auto windowSize = QSize( const auto windowSize = QSize{
std::max(containerSize.width(), 500), std::max(containerSize.width(), 500),
std::max(containerSize.height(), 100) std::max(containerSize.height(), 100)
); };
this->setFixedSize(windowSize); this->setFixedSize(windowSize);
this->container->setFixedSize(windowSize); this->container->setFixedSize(windowSize);

View File

@@ -11,7 +11,9 @@ namespace Widgets
Q_OBJECT Q_OBJECT
public: public:
explicit ExpandingHeightScrollAreaWidget(QWidget* parent): QScrollArea(parent) {}; explicit ExpandingHeightScrollAreaWidget(QWidget* parent)
: QScrollArea(parent)
{};
protected: protected:
[[nodiscard]] QSize scrollAreaSize() const { [[nodiscard]] QSize scrollAreaSize() const {

View File

@@ -11,25 +11,25 @@ namespace Widgets
} }
void LabeledSeparator::paintEvent(QPaintEvent* event) { void LabeledSeparator::paintEvent(QPaintEvent* event) {
auto painter = QPainter(this); auto painter = QPainter{this};
this->drawWidget(painter); this->drawWidget(painter);
} }
void LabeledSeparator::drawWidget(QPainter& painter) { void LabeledSeparator::drawWidget(QPainter& painter) {
const auto fontMetrics = painter.fontMetrics(); const auto fontMetrics = painter.fontMetrics();
const auto titleSize = fontMetrics.size(Qt::TextFlag::TextSingleLine, this->title); const auto titleSize = fontMetrics.size(Qt::TextFlag::TextSingleLine, this->title);
const auto titleRect = QRect( const auto titleRect = QRect{
QPoint(this->marginLeft, (this->height() - titleSize.height()) / 2), QPoint{this->marginLeft, (this->height() - titleSize.height()) / 2},
titleSize titleSize
); };
const auto lineYPosition = titleRect.y() + (titleRect.height() / 2); const auto lineYPosition = titleRect.y() + (titleRect.height() / 2);
const auto line = QLine( const auto line = QLine{
titleRect.right() + 8, titleRect.right() + 8,
lineYPosition, lineYPosition,
this->width() - this->marginRight, this->width() - this->marginRight,
lineYPosition lineYPosition
); };
painter.drawText(titleRect, Qt::AlignCenter, this->title); painter.drawText(titleRect, Qt::AlignCenter, this->title);

View File

@@ -60,7 +60,7 @@ namespace Widgets
static constexpr int DEFAULT_HEIGHT = 20; static constexpr int DEFAULT_HEIGHT = 20;
QString title; QString title;
QColor lineColor = QColor(0x4A, 0x4A, 0x4A); QColor lineColor = QColor{0x4A, 0x4A, 0x4A};
int marginLeft = 0; int marginLeft = 0;
int marginRight = 10; int marginRight = 10;
}; };

View File

@@ -7,26 +7,36 @@
#include <QWidget> #include <QWidget>
#include <QGraphicsView> #include <QGraphicsView>
#include <QGraphicsScene> #include <QGraphicsScene>
#include <set>
#include "src/Helpers/DereferenceLessComparator.hpp"
namespace Widgets namespace Widgets
{ {
class ListItem: public QGraphicsItem class ListItem: public QGraphicsItem
{ {
public: public:
using ListItemSetType = std::set<ListItem*, DereferenceLessComparator<ListItem*>>;
bool selected = false; bool selected = false;
QSize size = QSize(); bool excluded = false;
QSize size = {};
ListItem() = default; ListItem() = default;
explicit ListItem(QGraphicsItem* parent)
: QGraphicsItem(parent)
{}
[[nodiscard]] QRectF boundingRect() const override { [[nodiscard]] QRectF boundingRect() const override {
return QRectF(QPointF(0, 0), this->size); return QRectF{QPointF{0, 0}, this->size};
} }
virtual void onGeometryChanged() { virtual void onGeometryChanged() {}
return;
}
virtual bool operator < (const ListItem& rhs) const = 0; virtual bool operator < (const ListItem& rhs) const {
return true;
}
bool operator > (const ListItem& rhs) const { bool operator > (const ListItem& rhs) const {
return rhs < *this; return rhs < *this;

View File

@@ -8,15 +8,12 @@
namespace Widgets namespace Widgets
{ {
ListScene::ListScene( ListScene::ListScene(const ListItem::ListItemSetType& items, QGraphicsView* parent)
ListScene::ListItemSetType&& items,
QGraphicsView* parent
)
: QGraphicsScene(parent) : QGraphicsScene(parent)
, parent(parent) , parent(parent)
{ {
this->setItemIndexMethod(QGraphicsScene::NoIndex); this->setItemIndexMethod(QGraphicsScene::NoIndex);
this->setItems(std::move(items)); this->setItems(items);
} }
void ListScene::setSelectionLimit(std::uint8_t selectionLimit) { void ListScene::setSelectionLimit(std::uint8_t selectionLimit) {
@@ -32,7 +29,7 @@ namespace Widgets
auto startYPosition = this->margins.top(); auto startYPosition = this->margins.top();
for (auto& listItem : this->listItems) { for (auto& listItem : this->listItems) {
if (!listItem->isVisible()) { if (listItem->excluded || !listItem->isVisible()) {
continue; continue;
} }
@@ -54,7 +51,7 @@ namespace Widgets
this->update(); this->update();
} }
void ListScene::setItems(const ListScene::ListItemSetType& items) { void ListScene::setItems(const ListItem::ListItemSetType& items) {
this->clearListItems(); this->clearListItems();
this->listItems = items; this->listItems = items;

View File

@@ -13,7 +13,6 @@
#include <QPointF> #include <QPointF>
#include "ListItem.hpp" #include "ListItem.hpp"
#include "src/Helpers/DereferenceLessComparator.hpp"
namespace Widgets namespace Widgets
{ {
@@ -22,17 +21,16 @@ namespace Widgets
Q_OBJECT Q_OBJECT
public: public:
using ListItemSetType = std::set<ListItem*, DereferenceLessComparator<ListItem*>>; QMargins margins = {0, 0, 0, 10};
QMargins margins = QMargins(0, 0, 0, 10);
ListScene( ListScene(
ListScene::ListItemSetType&& items, const ListItem::ListItemSetType& items,
QGraphicsView* parent QGraphicsView* parent
); );
void refreshGeometry(); void refreshGeometry();
void setSelectionLimit(std::uint8_t selectionLimit); void setSelectionLimit(std::uint8_t selectionLimit);
void setItems(const ListScene::ListItemSetType& items); void setItems(const ListItem::ListItemSetType& items);
void addListItem(ListItem* item); void addListItem(ListItem* item);
void removeListItem(ListItem* item); void removeListItem(ListItem* item);
void clearListItems(); void clearListItems();
@@ -53,7 +51,7 @@ namespace Widgets
void keyPressEvent(QKeyEvent* keyEvent) override; void keyPressEvent(QKeyEvent* keyEvent) override;
private: private:
ListScene::ListItemSetType listItems; ListItem::ListItemSetType listItems;
QGraphicsView* const parent; QGraphicsView* const parent;
bool enabled = false; bool enabled = false;
bool keyNavigationEnabled = true; bool keyNavigationEnabled = true;

View File

@@ -3,7 +3,7 @@
namespace Widgets namespace Widgets
{ {
ListView::ListView( ListView::ListView(
ListScene::ListItemSetType&& items, ListItem::ListItemSetType&& items,
QWidget* parent QWidget* parent
) )
: QGraphicsView(parent) : QGraphicsView(parent)
@@ -19,7 +19,7 @@ namespace Widgets
this->setCacheMode(QGraphicsView::CacheModeFlag::CacheNone); this->setCacheMode(QGraphicsView::CacheModeFlag::CacheNone);
this->setFocusPolicy(Qt::StrongFocus); this->setFocusPolicy(Qt::StrongFocus);
this->scene = new ListScene(std::move(items), this); this->scene = new ListScene{std::move(items), this};
this->setScene(this->scene); this->setScene(this->scene);
} }

View File

@@ -15,7 +15,7 @@ namespace Widgets
public: public:
ListView( ListView(
ListScene::ListItemSetType&& items, ListItem::ListItemSetType&& items,
QWidget* parent QWidget* parent
); );

View File

@@ -8,6 +8,9 @@ namespace Widgets
bool open = false; bool open = false;
PanelState() = default; PanelState() = default;
PanelState(int size, bool open): size(size), open(open) {}; PanelState(int size, bool open)
: size(size)
, open(open)
{};
}; };
} }

View File

@@ -20,7 +20,7 @@ namespace Widgets
this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
this->setMaximumResize(this->window()->height() - 100); this->setMaximumResize(this->window()->height() - 100);
auto* layout = new QHBoxLayout(this); auto* layout = new QHBoxLayout{this};
layout->setSpacing(0); layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0); layout->setContentsMargins(0, 0, 0, 0);
this->setLayout(layout); this->setLayout(layout);
@@ -30,7 +30,7 @@ namespace Widgets
this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::MinimumExpanding); this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::MinimumExpanding);
this->setMaximumResize(this->window()->width() - 100); this->setMaximumResize(this->window()->width() - 100);
auto* layout = new QVBoxLayout(this); auto* layout = new QVBoxLayout{this};
layout->setSpacing(0); layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0); layout->setContentsMargins(0, 0, 0, 0);
this->setLayout(layout); this->setLayout(layout);
@@ -83,8 +83,6 @@ namespace Widgets
} }
bool PanelWidget::eventFilter(QObject* object, QEvent* event) { bool PanelWidget::eventFilter(QObject* object, QEvent* event) {
const auto eventType = event->type();
if (event->isSinglePointEvent()) { if (event->isSinglePointEvent()) {
auto* pointerEvent = dynamic_cast<QSinglePointEvent*>(event); auto* pointerEvent = dynamic_cast<QSinglePointEvent*>(event);
@@ -168,23 +166,23 @@ namespace Widgets
switch (this->panelType) { switch (this->panelType) {
case PanelWidgetType::LEFT: { case PanelWidgetType::LEFT: {
return std::pair( return std::pair{
QPoint(currentSize.width() - this->handleSize, 0), QPoint{currentSize.width() - this->handleSize, 0},
QPoint(currentSize.width(), currentSize.height()) QPoint{currentSize.width(), currentSize.height()}
); };
} }
case PanelWidgetType::RIGHT: { case PanelWidgetType::RIGHT: {
return std::pair( return std::pair{
QPoint(0, 0), QPoint{0, 0},
QPoint(this->handleSize, currentSize.height()) QPoint{this->handleSize, currentSize.height()}
); };
} }
case PanelWidgetType::BOTTOM: case PanelWidgetType::BOTTOM:
default: { default: {
return std::pair( return std::pair{
QPoint(0, 0), QPoint{0, 0},
QPoint(currentSize.width(), this->handleSize) QPoint{currentSize.width(), this->handleSize}
); };
} }
} }
} }
@@ -192,9 +190,8 @@ namespace Widgets
bool PanelWidget::isPositionWithinHandleArea(const QPoint& position) const { bool PanelWidget::isPositionWithinHandleArea(const QPoint& position) const {
const auto handleArea = this->getHandleArea(); const auto handleArea = this->getHandleArea();
return ( return
position.x() >= handleArea.first.x() && position.x() <= handleArea.second.x() 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();
);
} }
} }

View File

@@ -5,7 +5,7 @@
namespace Widgets namespace Widgets
{ {
void RotatableLabel::paintEvent(QPaintEvent* event) { void RotatableLabel::paintEvent(QPaintEvent* event) {
auto painter = QPainter(this); auto painter = QPainter{this};
const auto containerSize = this->getContainerSize(); const auto containerSize = this->getContainerSize();
const auto textSize = QLabel::minimumSizeHint(); const auto textSize = QLabel::minimumSizeHint();
const auto margins = this->contentsMargins(); const auto margins = this->contentsMargins();
@@ -13,7 +13,7 @@ namespace Widgets
painter.setClipRect(0, 0, containerSize.width(), containerSize.height()); painter.setClipRect(0, 0, containerSize.width(), containerSize.height());
painter.save(); painter.save();
painter.setPen(Qt::PenStyle::SolidLine); 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.translate(std::ceil(containerSize.width() / 2), std::ceil(containerSize.height() / 2));
painter.rotate(this->angle); painter.rotate(this->angle);
painter.drawText( painter.drawText(
@@ -29,7 +29,7 @@ namespace Widgets
} }
QSize RotatableLabel::getContainerSize() const { QSize RotatableLabel::getContainerSize() const {
auto size = QSize(); auto size = QSize{};
auto textSize = QLabel::sizeHint(); auto textSize = QLabel::sizeHint();
if (this->angle % 360 == 0 || this->angle % 180 == 0) { if (this->angle % 360 == 0 || this->angle % 180 == 0) {
@@ -52,11 +52,11 @@ namespace Widgets
size.setWidth(static_cast<int>( size.setWidth(static_cast<int>(
std::cos(angleRadians) * textSize.width() std::cos(angleRadians) * textSize.width()
+ std::ceil(std::sin(angleRadians) * textSize.height()) + std::ceil(std::sin(angleRadians) * textSize.height())
)); ));
size.setHeight(static_cast<int>( size.setHeight(static_cast<int>(
std::sin(angleRadians) * textSize.width() std::sin(angleRadians) * textSize.width()
+ std::ceil(std::cos(angleRadians) * textSize.height()) + std::ceil(std::cos(angleRadians) * textSize.height())
)); ));
} }

View File

@@ -28,7 +28,7 @@ namespace Widgets
void SvgToolButton::contextMenuEvent(QContextMenuEvent* event) { void SvgToolButton::contextMenuEvent(QContextMenuEvent* event) {
if (this->contextMenu != nullptr) { if (this->contextMenu != nullptr) {
this->contextMenu->exec(this->mapToGlobal(QPoint(0, this->height()))); this->contextMenu->exec(this->mapToGlobal(QPoint{0, this->height()}));
} }
} }
} }

View File

@@ -6,12 +6,12 @@
namespace Widgets namespace Widgets
{ {
SvgWidget::SvgWidget(QWidget* parent): QFrame(parent) { SvgWidget::SvgWidget(QWidget* parent): QFrame(parent) {
this->renderer.setAspectRatioMode(Qt::AspectRatioMode::KeepAspectRatioByExpanding); this->renderer->setAspectRatioMode(Qt::AspectRatioMode::KeepAspectRatioByExpanding);
} }
void SvgWidget::startSpin() { void SvgWidget::startSpin() {
if (this->spinningAnimation == nullptr) { if (this->spinningAnimation == nullptr) {
this->spinningAnimation = new QPropertyAnimation(this, "angle", this); this->spinningAnimation = new QPropertyAnimation{this, "angle", this};
this->spinningAnimation->setDuration(2000); this->spinningAnimation->setDuration(2000);
this->spinningAnimation->setStartValue(0); this->spinningAnimation->setStartValue(0);
this->spinningAnimation->setEndValue(360); this->spinningAnimation->setEndValue(360);
@@ -33,7 +33,7 @@ namespace Widgets
void SvgWidget::paintEvent(QPaintEvent* paintEvent) { void SvgWidget::paintEvent(QPaintEvent* paintEvent) {
auto painter = QPainter(this); auto painter = QPainter(this);
auto svgSize = this->renderer.defaultSize(); auto svgSize = this->renderer->defaultSize();
auto margins = this->contentsMargins(); auto margins = this->contentsMargins();
const auto containerSize = this->frameSize(); const auto containerSize = this->frameSize();
@@ -51,7 +51,7 @@ namespace Widgets
); );
} }
this->renderer.render(&painter, QRectF( this->renderer->render(&painter, QRectF(
std::ceil( std::ceil(
static_cast<float>(containerSize.width() - svgSize.width()) / 2 + static_cast<float>(margins.left()) static_cast<float>(containerSize.width() - svgSize.width()) / 2 + static_cast<float>(margins.left())
), ),
@@ -66,10 +66,10 @@ namespace Widgets
void SvgWidget::changeEvent(QEvent* event) { void SvgWidget::changeEvent(QEvent* event) {
if (event->type() == QEvent::EnabledChange && !this->disabledSvgFilePath.isEmpty()) { if (event->type() == QEvent::EnabledChange && !this->disabledSvgFilePath.isEmpty()) {
if (!this->isEnabled()) { if (!this->isEnabled()) {
this->renderer.load(this->disabledSvgFilePath); this->renderer->load(this->disabledSvgFilePath);
} else { } else {
this->renderer.load(this->svgFilePath); this->renderer->load(this->svgFilePath);
} }
this->repaint(); this->repaint();

View File

@@ -23,7 +23,7 @@ namespace Widgets
void setSvgFilePath(const QString& svgFilePath) { void setSvgFilePath(const QString& svgFilePath) {
this->svgFilePath = svgFilePath; this->svgFilePath = svgFilePath;
this->renderer.load(this->svgFilePath); this->renderer->load(this->svgFilePath);
} }
QString getSvgFilePath() { QString getSvgFilePath() {
@@ -86,7 +86,7 @@ namespace Widgets
void changeEvent(QEvent* event) override; void changeEvent(QEvent* event) override;
private: private:
QSvgRenderer renderer = new QSvgRenderer(this); QSvgRenderer* renderer = new QSvgRenderer{this};
QString svgFilePath; QString svgFilePath;
QString disabledSvgFilePath; QString disabledSvgFilePath;
int containerWidth = 0; int containerWidth = 0;

View File

@@ -4,16 +4,19 @@
ExcludedMemoryRegion::ExcludedMemoryRegion( ExcludedMemoryRegion::ExcludedMemoryRegion(
const QString& name, const QString& name,
Targets::TargetMemoryType memoryType,
const Targets::TargetMemoryAddressRange& addressRange const Targets::TargetMemoryAddressRange& addressRange
) )
: MemoryRegion(name, memoryType, MemoryRegionType::EXCLUDED, addressRange) : MemoryRegion(
name,
MemoryRegionType::EXCLUDED,
addressRange
)
{} {}
ExcludedMemoryRegion::ExcludedMemoryRegion(const QJsonObject& jsonObject) ExcludedMemoryRegion::ExcludedMemoryRegion(const QJsonObject& jsonObject)
: MemoryRegion(jsonObject) : MemoryRegion(jsonObject)
{ {
if (this->type != MemoryRegionType::EXCLUDED) { if (this->type != MemoryRegionType::EXCLUDED) {
throw Exceptions::Exception("Invalid memory region type"); throw Exceptions::Exception{"Invalid memory region type"};
} }
} }

View File

@@ -7,9 +7,8 @@ class ExcludedMemoryRegion: public MemoryRegion
public: public:
ExcludedMemoryRegion( ExcludedMemoryRegion(
const QString& name, const QString& name,
Targets::TargetMemoryType memoryType,
const Targets::TargetMemoryAddressRange& addressRange const Targets::TargetMemoryAddressRange& addressRange
); );
ExcludedMemoryRegion(const QJsonObject& jsonObject); explicit ExcludedMemoryRegion(const QJsonObject& jsonObject);
}; };

View File

@@ -4,10 +4,13 @@
FocusedMemoryRegion::FocusedMemoryRegion( FocusedMemoryRegion::FocusedMemoryRegion(
const QString& name, const QString& name,
Targets::TargetMemoryType memoryType,
const Targets::TargetMemoryAddressRange& addressRange const Targets::TargetMemoryAddressRange& addressRange
) )
: MemoryRegion(name, memoryType, MemoryRegionType::FOCUSED, addressRange) : MemoryRegion(
name,
MemoryRegionType::FOCUSED,
addressRange
)
{} {}
FocusedMemoryRegion::FocusedMemoryRegion(const QJsonObject& jsonObject) FocusedMemoryRegion::FocusedMemoryRegion(const QJsonObject& jsonObject)
@@ -16,11 +19,11 @@ FocusedMemoryRegion::FocusedMemoryRegion(const QJsonObject& jsonObject)
using Exceptions::Exception; using Exceptions::Exception;
if (this->type != MemoryRegionType::FOCUSED) { if (this->type != MemoryRegionType::FOCUSED) {
throw Exception("Invalid memory region type"); throw Exception{"Invalid memory region type"};
} }
if (!jsonObject.contains("dataType") || !jsonObject.contains("endianness")) { if (!jsonObject.contains("dataType") || !jsonObject.contains("endianness")) {
throw Exception("Missing data"); throw Exception{"Missing data"};
} }
this->dataType = FocusedMemoryRegion::regionDataTypesByName.at(jsonObject.find("dataType")->toString()); this->dataType = FocusedMemoryRegion::regionDataTypesByName.at(jsonObject.find("dataType")->toString());

View File

@@ -22,12 +22,10 @@ public:
FocusedMemoryRegion( FocusedMemoryRegion(
const QString& name, const QString& name,
Targets::TargetMemoryType memoryType,
const Targets::TargetMemoryAddressRange& addressRange const Targets::TargetMemoryAddressRange& addressRange
); );
FocusedMemoryRegion(const QJsonObject& jsonObject); explicit FocusedMemoryRegion(const QJsonObject& jsonObject);
QJsonObject toJson() const override; QJsonObject toJson() const override;
private: private:

View File

@@ -10,7 +10,7 @@ namespace Widgets
static constexpr int leftMargin = 10; static constexpr int leftMargin = 10;
const auto addressItemCount = this->addressItems.size(); 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) { for (const auto& byteItem : firstByteItemByLine) {
auto addressItem = addressItemCount > 0 && rowIndex <= addressItemCount - 1 auto addressItem = addressItemCount > 0 && rowIndex <= addressItemCount - 1
@@ -49,8 +49,8 @@ namespace Widgets
} }
void ByteAddressContainer::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { void ByteAddressContainer::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {
static const auto backgroundColor = QColor(0x35, 0x36, 0x33); static const auto backgroundColor = QColor{0x35, 0x36, 0x33};
static const auto borderColor = QColor(0x41, 0x42, 0x3F); static const auto borderColor = QColor{0x41, 0x42, 0x3F};
painter->setPen(Qt::PenStyle::NoPen); painter->setPen(Qt::PenStyle::NoPen);
painter->setBrush(backgroundColor); painter->setBrush(backgroundColor);

View File

@@ -15,15 +15,10 @@ namespace Widgets
public: public:
static constexpr int WIDTH = 88; static constexpr int WIDTH = 88;
ByteAddressContainer(const HexViewerSharedState& hexViewerState); explicit ByteAddressContainer(const HexViewerSharedState& hexViewerState);
[[nodiscard]] QRectF boundingRect() const override { [[nodiscard]] QRectF boundingRect() const override {
return QRectF( return {0, 0, ByteAddressContainer::WIDTH, this->scene()->height()};
0,
0,
ByteAddressContainer::WIDTH,
this->scene()->height()
);
} }
void adjustAddressLabels(const std::vector<const ByteItem*>& firstByteItemByLine); void adjustAddressLabels(const std::vector<const ByteItem*>& firstByteItemByLine);

View File

@@ -8,8 +8,8 @@ namespace Widgets
{} {}
void ByteAddressItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { void ByteAddressItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {
static auto fontColor = QColor(0x8F, 0x91, 0x92); static auto fontColor = QColor{0x8F, 0x91, 0x92};
static auto font = QFont("'Ubuntu', sans-serif"); static auto font = QFont{"'Ubuntu', sans-serif"};
font.setPixelSize(12); font.setPixelSize(12);
painter->setRenderHints( painter->setRenderHints(
@@ -28,7 +28,7 @@ namespace Widgets
Qt::AlignLeft, Qt::AlignLeft,
this->hexViewerState.settings.addressLabelType == AddressType::RELATIVE this->hexViewerState.settings.addressLabelType == AddressType::RELATIVE
? "0x" + QString::number( ? "0x" + QString::number(
this->address - this->hexViewerState.memoryDescriptor.addressRange.startAddress, this->address - this->hexViewerState.memorySegmentDescriptor.addressRange.startAddress,
16 16
).rightJustified(8, '0').toUpper() ).rightJustified(8, '0').toUpper()
: "0x" + QString::number(this->address, 16).rightJustified(8, '0').toUpper() : "0x" + QString::number(this->address, 16).rightJustified(8, '0').toUpper()

View File

@@ -3,6 +3,8 @@
#include <QGraphicsItem> #include <QGraphicsItem>
#include <QPainter> #include <QPainter>
#include "src/Targets/TargetMemory.hpp"
#include "ByteItem.hpp" #include "ByteItem.hpp"
#include "HexViewerSharedState.hpp" #include "HexViewerSharedState.hpp"
@@ -19,12 +21,7 @@ namespace Widgets
explicit ByteAddressItem(const HexViewerSharedState& hexViewerState, QGraphicsItem* parent); explicit ByteAddressItem(const HexViewerSharedState& hexViewerState, QGraphicsItem* parent);
[[nodiscard]] QRectF boundingRect() const override { [[nodiscard]] QRectF boundingRect() const override {
return { return {0, 0, ByteAddressItem::WIDTH, ByteAddressItem::HEIGHT};
0,
0,
ByteAddressItem::WIDTH,
ByteAddressItem::HEIGHT
};
} }
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override; void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override;

View File

@@ -29,8 +29,8 @@ namespace Widgets
explicit ByteItem(Targets::TargetMemoryAddress address); explicit ByteItem(Targets::TargetMemoryAddress address);
QSize size() const override { [[nodiscard]] QSize size() const override {
return QSize(ByteItem::WIDTH, ByteItem::HEIGHT); return {ByteItem::WIDTH, ByteItem::HEIGHT};
} }
}; };
#pragma pack(pop) #pragma pack(pop)

View File

@@ -56,11 +56,11 @@ namespace Widgets
const auto regionStartAddress = this->focusedMemoryRegion.addressRange.startAddress; const auto regionStartAddress = this->focusedMemoryRegion.addressRange.startAddress;
const auto regionEndAddress = this->focusedMemoryRegion.addressRange.endAddress; const auto regionEndAddress = this->focusedMemoryRegion.addressRange.endAddress;
const auto startIndex = regionStartAddress - hexViewerState.memoryDescriptor.addressRange.startAddress; const auto startIndex = regionStartAddress - hexViewerState.memorySegmentDescriptor.addressRange.startAddress;
auto value = Targets::TargetMemoryBuffer( auto value = Targets::TargetMemoryBuffer{
hexViewerState.data->begin() + startIndex, hexViewerState.data->begin() + startIndex,
hexViewerState.data->begin() + startIndex + (regionEndAddress - regionStartAddress + 1) hexViewerState.data->begin() + startIndex + (regionEndAddress - regionStartAddress + 1)
); };
if (this->focusedMemoryRegion.endianness == Targets::TargetMemoryEndianness::LITTLE) { if (this->focusedMemoryRegion.endianness == Targets::TargetMemoryEndianness::LITTLE) {
std::reverse(value.begin(), value.end()); std::reverse(value.begin(), value.end());
@@ -90,7 +90,7 @@ namespace Widgets
} }
if (valueSize <= 4) { if (valueSize <= 4) {
std::int32_t integerValue = 0; auto integerValue = std::int32_t{0};
for (const auto& byte : value) { for (const auto& byte : value) {
integerValue = (integerValue << 8) | byte; integerValue = (integerValue << 8) | byte;
} }
@@ -99,7 +99,7 @@ namespace Widgets
break; break;
} }
std::int64_t integerValue = 0; auto integerValue = std::int64_t{0};
for (const auto& byte : value) { for (const auto& byte : value) {
integerValue = (integerValue << 8) | byte; integerValue = (integerValue << 8) | byte;
} }
@@ -138,40 +138,40 @@ namespace Widgets
QMargins FocusedRegionGroupItem::groupMargins( QMargins FocusedRegionGroupItem::groupMargins(
const HexViewerSharedState* hexViewerState, const HexViewerSharedState* hexViewerState,
const int maximumWidth int maximumWidth
) const { ) const {
if (hexViewerState->settings.displayAnnotations) { if (!hexViewerState->settings.displayAnnotations) {
constexpr auto averageSymbolWidth = 8; return QMargins{0, 0, 0, 0};
const auto nameLabelWidth = static_cast<int>(this->focusedMemoryRegion.name.size() * averageSymbolWidth);
const auto valueLabelWidth = static_cast<int>(
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<int>(
byteItemSize * (ByteItem::WIDTH + ByteItem::RIGHT_MARGIN) - ByteItem::RIGHT_MARGIN
);
const auto annotationMargin = std::min(
static_cast<int>(
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
);
} }
return QMargins(0, 0, 0, 0); constexpr auto averageSymbolWidth = 8;
const auto nameLabelWidth = static_cast<int>(this->focusedMemoryRegion.name.size() * averageSymbolWidth);
const auto valueLabelWidth = static_cast<int>(
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<int>(
byteItemSize * (ByteItem::WIDTH + ByteItem::RIGHT_MARGIN) - ByteItem::RIGHT_MARGIN
);
const auto annotationMargin = std::min(
static_cast<int>(
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
};
} }
} }

View File

@@ -30,6 +30,6 @@ namespace Widgets
void refreshValue(const HexViewerSharedState& hexViewerState); void refreshValue(const HexViewerSharedState& hexViewerState);
protected: protected:
QMargins groupMargins(const HexViewerSharedState* hexViewerState, const int maximumWidth) const override; QMargins groupMargins(const HexViewerSharedState* hexViewerState, int maximumWidth) const override;
}; };
} }

View File

@@ -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); const auto margins = this->groupMargins(hexViewerState, maximumWidth);
int width = margins.left(); int width = margins.left();
int height = margins.top(); int height = margins.top();
this->multiLine = false; this->multiLine = false;
auto position = QPoint(margins.left(), margins.top()); auto position = QPoint{margins.left(), margins.top()};
auto currentLineItems = std::vector<HexViewerItem*>(); auto currentLineItems = std::vector<HexViewerItem*>{};
const ByteItem* lastByteItem = nullptr; const ByteItem* lastByteItem = nullptr;
for (const auto& item : this->items) { for (const auto& item : this->items) {
@@ -69,11 +69,11 @@ namespace Widgets
lastByteItem = byteItem; lastByteItem = byteItem;
} }
this->groupSize = QSize(width + margins.right(), height + margins.bottom()); this->groupSize = QSize{width + margins.right(), height + margins.bottom()};
} }
std::vector<HexViewerItem*> GroupItem::flattenedItems() const { std::vector<HexViewerItem*> GroupItem::flattenedItems() const {
auto flattenedItems = std::vector<HexViewerItem*>(); auto flattenedItems = std::vector<HexViewerItem*>{};
for (const auto& item : this->items) { for (const auto& item : this->items) {
flattenedItems.push_back(item); flattenedItems.push_back(item);
@@ -88,10 +88,7 @@ namespace Widgets
return flattenedItems; return flattenedItems;
} }
GroupItem::GroupItem( GroupItem::GroupItem(Targets::TargetMemoryAddress startAddress, HexViewerItem* parent)
Targets::TargetMemoryAddress startAddress,
HexViewerItem* parent
)
: HexViewerItem(startAddress, parent) : HexViewerItem(startAddress, parent)
{} {}

View File

@@ -22,29 +22,29 @@ namespace Widgets
~GroupItem(); ~GroupItem();
QSize size() const override { [[nodiscard]] QSize size() const override {
return this->groupSize; return this->groupSize;
} }
virtual void adjustItemPositions(const int maximumWidth, const HexViewerSharedState* hexViewerState); virtual void adjustItemPositions(int maximumWidth, const HexViewerSharedState* hexViewerState);
[[nodiscard]] std::vector<HexViewerItem*> flattenedItems() const; [[nodiscard]] std::vector<HexViewerItem*> flattenedItems() const;
protected: protected:
GroupItem( explicit GroupItem(
Targets::TargetMemoryAddress startAddress, Targets::TargetMemoryAddress startAddress,
HexViewerItem* parent = nullptr HexViewerItem* parent = nullptr
); );
virtual QMargins groupMargins(const HexViewerSharedState* hexViewerState, const int maximumWidth) const { virtual QMargins groupMargins(const HexViewerSharedState* hexViewerState, int maximumWidth) const {
return QMargins(0, 0, 0, 0); return {0, 0, 0, 0};
} }
virtual bool positionOnNewLine(const int maximumWidth) { virtual bool positionOnNewLine(const int maximumWidth) {
return this->multiLine; return this->multiLine;
} }
ByteItem* firstByteItem() const; [[nodiscard]] ByteItem* firstByteItem() const;
void sortItems(); void sortItems();
}; };

View File

@@ -18,15 +18,15 @@ namespace Widgets
static constexpr int RIGHT_MARGIN = 5; static constexpr int RIGHT_MARGIN = 5;
static constexpr int BOTTOM_MARGIN = 5; static constexpr int BOTTOM_MARGIN = 5;
const Targets::TargetMemoryAddress startAddress = 0; const Targets::TargetMemoryAddress startAddress;
HexViewerItem* parent = nullptr; HexViewerItem* parent = nullptr;
QPoint relativePosition = {}; QPoint relativePosition = {};
HexViewerItem(Targets::TargetMemoryAddress startAddress, HexViewerItem* parent = nullptr); explicit HexViewerItem(Targets::TargetMemoryAddress startAddress, HexViewerItem* parent = nullptr);
QPoint position() const; [[nodiscard]] QPoint position() const;
virtual QSize size() const = 0; [[nodiscard]] virtual QSize size() const = 0;
}; };
#pragma pack(pop) #pragma pack(pop)
} }

View File

@@ -32,7 +32,7 @@ namespace Widgets
); );
if (startGridPointIndex >= gridPointCount) { if (startGridPointIndex >= gridPointCount) {
return HexViewerItemIndex::ItemRangeType(); return HexViewerItemIndex::ItemRangeType{};
} }
const auto endGridPointIndex = static_cast<decltype(this->byteItemGrid)::size_type>(std::min( const auto endGridPointIndex = static_cast<decltype(this->byteItemGrid)::size_type>(std::min(
@@ -44,12 +44,12 @@ namespace Widgets
gridPointCount - 1 gridPointCount - 1
)); ));
return HexViewerItemIndex::ItemRangeType( return HexViewerItemIndex::ItemRangeType{
this->byteItemGrid[startGridPointIndex], this->byteItemGrid[startGridPointIndex],
endGridPointIndex == gridPointCount - 1 endGridPointIndex == gridPointCount - 1
? this->flattenedItems.end() ? this->flattenedItems.end()
: this->byteItemGrid[endGridPointIndex] : this->byteItemGrid[endGridPointIndex]
); };
} }
ByteItem* HexViewerItemIndex::byteItemAt(const QPointF& position) const { ByteItem* HexViewerItemIndex::byteItemAt(const QPointF& position) const {
@@ -115,11 +115,11 @@ namespace Widgets
// Sanity check // Sanity check
assert(gridPointCount > gridPointIndex); assert(gridPointCount > gridPointIndex);
return static_cast<ByteItem*>(*(this->byteItemGrid[gridPointIndex])); return dynamic_cast<ByteItem*>(*(this->byteItemGrid[gridPointIndex]));
} }
std::vector<ByteItem*> HexViewerItemIndex::intersectingByteItems(const QRectF& rect) const { std::vector<ByteItem*> HexViewerItemIndex::intersectingByteItems(const QRectF& rect) const {
auto output = std::vector<ByteItem*>(); auto output = std::vector<ByteItem*>{};
const auto yStart = static_cast<int>(std::max(rect.y(), static_cast<qreal>(0))); const auto yStart = static_cast<int>(std::max(rect.y(), static_cast<qreal>(0)));
const auto yEnd = static_cast<int>(std::max(rect.y() + rect.height(), static_cast<qreal>(0))); const auto yEnd = static_cast<int>(std::max(rect.y() + rect.height(), static_cast<qreal>(0)));
@@ -127,7 +127,7 @@ namespace Widgets
const auto items = this->items(yStart, yEnd); const auto items = this->items(yStart, yEnd);
for (auto& item : items) { for (auto& item : items) {
const auto itemRect = QRectF(item->position(), item->size()); const auto itemRect = QRectF{item->position(), item->size()};
if (itemRect.y() > yEnd) { if (itemRect.y() > yEnd) {
break; break;
@@ -252,7 +252,7 @@ namespace Widgets
if (itemYEndPosition >= currentByteItemGridPoint) { if (itemYEndPosition >= currentByteItemGridPoint) {
// This byte item is the first to exceed or intersect with the 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; currentByteItemGridPoint += HexViewerItemIndex::GRID_SIZE;
} }
} }

View File

@@ -74,7 +74,7 @@ namespace Widgets
this->hexViewerState.hoveredByteItem != nullptr this->hexViewerState.hoveredByteItem != nullptr
&& this->hexViewerState.settings.highlightHoveredRowAndCol && 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->setBrush(hoverRectBackgroundColor);
painter->setPen(Qt::NoPen); painter->setPen(Qt::NoPen);
@@ -108,7 +108,7 @@ namespace Widgets
void HexViewerItemRenderer::paintByteItem(const ByteItem* item, QPainter* painter) { void HexViewerItemRenderer::paintByteItem(const ByteItem* item, QPainter* painter) {
const auto position = item->position(); 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( painter->setOpacity(
!this->isEnabled() !this->isEnabled()
@@ -133,7 +133,8 @@ namespace Widgets
return; 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 value = (*(this->hexViewerState.data))[byteIndex];
const auto hoveredPrimary = this->hexViewerState.hoveredByteItem == item; const auto hoveredPrimary = this->hexViewerState.hoveredByteItem == item;
@@ -257,7 +258,7 @@ namespace Widgets
const auto endItemPos = endItem->position(); const auto endItemPos = endItem->position();
const auto endItemSize = endItem->size(); const auto endItemSize = endItem->size();
auto painterPath = QPainterPath(); auto painterPath = QPainterPath{};
if (startItemPos.y() != endItemPos.y()) { if (startItemPos.y() != endItemPos.y()) {
// The highlighted range spans more than one line - draw the border around all lines containing the range // 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->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->setBrush(Qt::BrushStyle::NoBrush);
painter->drawPath(painterPath); painter->drawPath(painterPath);
} }
@@ -304,10 +305,10 @@ namespace Widgets
{ {
auto labelText = item->focusedMemoryRegion.name; auto labelText = item->focusedMemoryRegion.name;
static constexpr auto lineColor = QColor(0x4F, 0x4F, 0x4F); static constexpr auto lineColor = QColor{0x4F, 0x4F, 0x4F};
static constexpr auto labelFontColor = QColor(0x68, 0x68, 0x68); 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); labelFont.setPixelSize(12);
painter->setFont(labelFont); painter->setFont(labelFont);
@@ -329,51 +330,50 @@ namespace Widgets
const auto verticalLineYStart = position.y() + static_cast<int>(heightOffset); const auto verticalLineYStart = position.y() + static_cast<int>(heightOffset);
const auto verticalLineYEnd = position.y() + static_cast<int>(heightOffset + 5); const auto verticalLineYEnd = position.y() + static_cast<int>(heightOffset + 5);
const auto labelRect = QRect( const auto labelRect = QRect{
position.x() + (groupWidth - labelSize.width()) / 2, position.x() + (groupWidth - labelSize.width()) / 2,
verticalLineYEnd + 10, verticalLineYEnd + 10,
labelSize.width(), labelSize.width(),
labelSize.height() labelSize.height()
); };
painter->setPen(lineColor); painter->setPen(lineColor);
if (item->focusedMemoryRegion.addressRange.startAddress != if (item->focusedMemoryRegion.addressRange.startAddress != item->focusedMemoryRegion.addressRange.endAddress) {
item->focusedMemoryRegion.addressRange.endAddress) {
const auto lineStartX = const auto lineStartX =
position.x() + item->items.front()->relativePosition.x() + (ByteItem::WIDTH / 2); position.x() + item->items.front()->relativePosition.x() + (ByteItem::WIDTH / 2);
const auto lineEndX = item->multiLine const auto lineEndX = item->multiLine
? position.x() + groupWidth - (ByteItem::WIDTH / 2) ? position.x() + groupWidth - (ByteItem::WIDTH / 2)
: position.x() + item->items.back()->relativePosition.x() + (ByteItem::WIDTH / 2); : position.x() + item->items.back()->relativePosition.x() + (ByteItem::WIDTH / 2);
painter->drawLine(QLine( painter->drawLine(QLine{
lineStartX, lineStartX,
verticalLineYStart, verticalLineYStart,
lineStartX, lineStartX,
verticalLineYEnd verticalLineYEnd
)); });
painter->drawLine(QLine( painter->drawLine(QLine{
lineEndX, lineEndX,
verticalLineYStart, verticalLineYStart,
lineEndX, lineEndX,
verticalLineYEnd verticalLineYEnd
)); });
painter->drawLine(QLine( painter->drawLine(QLine{
lineStartX, lineStartX,
verticalLineYEnd, verticalLineYEnd,
lineEndX, lineEndX,
verticalLineYEnd verticalLineYEnd
)); });
} }
painter->drawLine(QLine( painter->drawLine(QLine{
position.x() + groupWidth / 2, position.x() + groupWidth / 2,
verticalLineYEnd, verticalLineYEnd,
position.x() + groupWidth / 2, position.x() + groupWidth / 2,
verticalLineYEnd + 4 verticalLineYEnd + 4
)); });
painter->setPen(labelFontColor); painter->setPen(labelFontColor);
painter->drawText(labelRect, Qt::AlignCenter, labelText); painter->drawText(labelRect, Qt::AlignCenter, labelText);
@@ -385,10 +385,10 @@ namespace Widgets
auto labelText = item->valueLabel.value_or("??"); auto labelText = item->valueLabel.value_or("??");
static const auto lineColor = QColor(0x4F, 0x4F, 0x4F); static const auto lineColor = QColor{0x4F, 0x4F, 0x4F};
static const auto labelFontColor = QColor(0x94, 0x6F, 0x30); 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.setPixelSize(12);
labelFont.setItalic(true); labelFont.setItalic(true);
@@ -399,11 +399,7 @@ namespace Widgets
auto labelSize = fontMetrics.size(Qt::TextSingleLine, labelText); auto labelSize = fontMetrics.size(Qt::TextSingleLine, labelText);
if (labelSize.width() > groupWidth) { if (labelSize.width() > groupWidth) {
labelSize.setWidth(groupWidth); labelSize.setWidth(groupWidth);
labelText = fontMetrics.elidedText( labelText = fontMetrics.elidedText(labelText, Qt::TextElideMode::ElideRight, groupWidth);
labelText,
Qt::TextElideMode::ElideRight,
groupWidth
);
} }
const auto heightOffset = FocusedRegionGroupItem::ANNOTATION_HEIGHT - 4; const auto heightOffset = FocusedRegionGroupItem::ANNOTATION_HEIGHT - 4;
@@ -411,12 +407,12 @@ namespace Widgets
const auto verticalLineYStart = position.y() + static_cast<int>(heightOffset - 5); const auto verticalLineYStart = position.y() + static_cast<int>(heightOffset - 5);
const auto verticalLineYEnd = position.y() + static_cast<int>(heightOffset); const auto verticalLineYEnd = position.y() + static_cast<int>(heightOffset);
const auto labelRect = QRect( const auto labelRect = QRect{
position.x() + (groupWidth - labelSize.width()) / 2, position.x() + (groupWidth - labelSize.width()) / 2,
verticalLineYStart - 10 - labelSize.height(), verticalLineYStart - 10 - labelSize.height(),
labelSize.width(), labelSize.width(),
labelSize.height() labelSize.height()
); };
painter->setPen(lineColor); painter->setPen(lineColor);
@@ -426,26 +422,26 @@ namespace Widgets
? position.x() + groupWidth - + (ByteItem::WIDTH / 2) ? position.x() + groupWidth - + (ByteItem::WIDTH / 2)
: position.x() + item->items.back()->relativePosition.x() + (ByteItem::WIDTH / 2); : position.x() + item->items.back()->relativePosition.x() + (ByteItem::WIDTH / 2);
painter->drawLine(QLine( painter->drawLine(QLine{
lineStartX, lineStartX,
verticalLineYStart, verticalLineYStart,
lineStartX, lineStartX,
verticalLineYEnd verticalLineYEnd
)); });
painter->drawLine(QLine( painter->drawLine(QLine{
lineEndX, lineEndX,
verticalLineYStart, verticalLineYStart,
lineEndX, lineEndX,
verticalLineYEnd verticalLineYEnd
)); });
painter->drawLine(QLine( painter->drawLine(QLine{
lineStartX, lineStartX,
verticalLineYStart, verticalLineYStart,
lineEndX, lineEndX,
verticalLineYStart verticalLineYStart
)); });
/* /*
* Draw a circle just above the first byte item of the region, to indicate the first byte used to generate * 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; constexpr auto radius = 2;
painter->drawEllipse( painter->drawEllipse(
QPoint( QPoint{
item->focusedMemoryRegion.endianness == TargetMemoryEndianness::BIG ? lineStartX : lineEndX, item->focusedMemoryRegion.endianness == TargetMemoryEndianness::BIG ? lineStartX : lineEndX,
!item->multiLine || item->focusedMemoryRegion.endianness == TargetMemoryEndianness::BIG !item->multiLine || item->focusedMemoryRegion.endianness == TargetMemoryEndianness::BIG
? verticalLineYStart ? verticalLineYStart
: position.y() + item->groupSize.height() - FocusedRegionGroupItem::ANNOTATION_HEIGHT + 4 + 5 : position.y() + item->groupSize.height() - FocusedRegionGroupItem::ANNOTATION_HEIGHT + 4 + 5
), },
radius, radius,
radius radius
); );
} }
painter->drawLine(QLine( painter->drawLine(QLine{
position.x() + groupWidth / 2, position.x() + groupWidth / 2,
verticalLineYStart - 4, verticalLineYStart - 4,
position.x() + groupWidth / 2, position.x() + groupWidth / 2,
verticalLineYStart verticalLineYStart
)); });
painter->setPen(labelFontColor); painter->setPen(labelFontColor);
painter->drawText(labelRect, Qt::AlignCenter, labelText); painter->drawText(labelRect, Qt::AlignCenter, labelText);
@@ -481,30 +477,31 @@ namespace Widgets
void HexViewerItemRenderer::paintStackMemoryGroupItem(const StackMemoryGroupItem* item, QPainter* painter) { void HexViewerItemRenderer::paintStackMemoryGroupItem(const StackMemoryGroupItem* item, QPainter* painter) {
const auto position = item->position(); 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 stackSize = this->hexViewerState.memorySegmentDescriptor.addressRange.endAddress
const auto& memoryCapacity = this->hexViewerState.memoryDescriptor.size(); - 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) (" const auto stackSizeValueText = QString::number(stackSize) + " byte(s) ("
+ QString::number(static_cast<float>(stackSize) / static_cast<float>(memoryCapacity / 100), 'f' , 1) + QString::number(static_cast<float>(stackSize) / static_cast<float>(memoryCapacity / 100), 'f' , 1)
+ "% of memory capacity)"; + "% of memory capacity)";
const auto stackPointerHeadingText = QString("Stack pointer:"); const auto stackPointerHeadingText = QString{"Stack pointer:"};
const auto stackPointerValueText = "0x" + QString::number( const auto stackPointerValueText = "0x" + QString::number(
item->stackPointer, item->stackPointer,
16 16
).rightJustified(8, '0').toUpper(); ).rightJustified(8, '0').toUpper();
static constexpr auto lineColor = QColor(0x4F, 0x4F, 0x4F); static constexpr auto lineColor = QColor{0x4F, 0x4F, 0x4F};
static constexpr auto headingLabelFontColor = QColor(0x6F, 0x6F, 0x6F); static constexpr auto headingLabelFontColor = QColor{0x6F, 0x6F, 0x6F};
static constexpr auto valueLabelFontColor = QColor(0x94, 0x6F, 0x30, 230); 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); headingLabelFont.setPixelSize(13);
static auto valueFont = QFont("'Ubuntu', sans-serif"); static auto valueFont = QFont{"'Ubuntu', sans-serif"};
valueFont.setPixelSize(13); valueFont.setPixelSize(13);
valueFont.setItalic(true); valueFont.setItalic(true);
@@ -534,75 +531,75 @@ namespace Widgets
const auto lineStartX = position.x() + ByteItem::WIDTH / 2; const auto lineStartX = position.x() + ByteItem::WIDTH / 2;
const auto lineEndX = position.x() + groupWidth - (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, position.x() + (groupWidth - headingLabelSize.width()) / 2,
verticalLineYStart - stackPointerHeadingLabelSize.height() - stackSizeHeadingLabelSize.height() verticalLineYStart - stackPointerHeadingLabelSize.height() - stackSizeHeadingLabelSize.height()
- headingLabelSize.height() - labelLineHeight - (labelBottomMargin * 2) - 3, - headingLabelSize.height() - labelLineHeight - (labelBottomMargin * 2) - 3,
headingLabelSize.width(), headingLabelSize.width(),
headingLabelSize.height() headingLabelSize.height()
); };
const auto stackPointerHeadingLabelRect = QRect( const auto stackPointerHeadingLabelRect = QRect{
labelRect.left() + (labelRect.width() / 2) - ( labelRect.left() + (labelRect.width() / 2) - (
(stackPointerHeadingLabelSize.width() + stackPointerLabelSize.width()) / 2 (stackPointerHeadingLabelSize.width() + stackPointerLabelSize.width()) / 2
), ),
labelRect.bottom() + labelBottomMargin, labelRect.bottom() + labelBottomMargin,
stackPointerHeadingLabelSize.width(), stackPointerHeadingLabelSize.width(),
stackPointerHeadingLabelSize.height() stackPointerHeadingLabelSize.height()
); };
const auto stackPointerValueLabelRect = QRect( const auto stackPointerValueLabelRect = QRect{
stackPointerHeadingLabelRect.right() + labelRightMargin, stackPointerHeadingLabelRect.right() + labelRightMargin,
labelRect.bottom() + labelBottomMargin, labelRect.bottom() + labelBottomMargin,
stackPointerLabelSize.width(), stackPointerLabelSize.width(),
stackPointerLabelSize.height() stackPointerLabelSize.height()
); };
const auto stackSizeHeadingLabelRect = QRect( const auto stackSizeHeadingLabelRect = QRect{
labelRect.left() + (labelRect.width() / 2) - ( labelRect.left() + (labelRect.width() / 2) - (
(stackSizeHeadingLabelSize.width() + stackSizeLabelSize.width()) / 2 (stackSizeHeadingLabelSize.width() + stackSizeLabelSize.width()) / 2
), ),
stackPointerHeadingLabelRect.bottom() + labelBottomMargin, stackPointerHeadingLabelRect.bottom() + labelBottomMargin,
stackSizeHeadingLabelSize.width(), stackSizeHeadingLabelSize.width(),
stackSizeHeadingLabelSize.height() stackSizeHeadingLabelSize.height()
); };
const auto stackSizeValueLabelRect = QRect( const auto stackSizeValueLabelRect = QRect{
stackSizeHeadingLabelRect.right() + labelRightMargin, stackSizeHeadingLabelRect.right() + labelRightMargin,
stackPointerHeadingLabelRect.bottom() + labelBottomMargin, stackPointerHeadingLabelRect.bottom() + labelBottomMargin,
stackSizeLabelSize.width(), stackSizeLabelSize.width(),
stackSizeLabelSize.height() stackSizeLabelSize.height()
); };
painter->setPen(lineColor); painter->setPen(lineColor);
painter->drawLine(QLine( painter->drawLine(QLine{
lineStartX, lineStartX,
verticalLineYStart, verticalLineYStart,
lineStartX, lineStartX,
verticalLineYEnd verticalLineYEnd
)); });
painter->drawLine(QLine( painter->drawLine(QLine{
lineEndX, lineEndX,
verticalLineYStart, verticalLineYStart,
lineEndX, lineEndX,
verticalLineYEnd verticalLineYEnd
)); });
painter->drawLine(QLine( painter->drawLine(QLine{
lineStartX, lineStartX,
verticalLineYStart, verticalLineYStart,
lineEndX, lineEndX,
verticalLineYStart verticalLineYStart
)); });
painter->drawLine(QLine( painter->drawLine(QLine{
position.x() + groupWidth / 2, position.x() + groupWidth / 2,
verticalLineYStart - labelLineHeight, verticalLineYStart - labelLineHeight,
position.x() + groupWidth / 2, position.x() + groupWidth / 2,
verticalLineYStart verticalLineYStart
)); });
painter->setPen(headingLabelFontColor); painter->setPen(headingLabelFontColor);
@@ -623,77 +620,77 @@ namespace Widgets
return; return;
} }
static constexpr auto standardBackgroundColor = QColor(0x32, 0x33, 0x30, 0); static constexpr auto standardBackgroundColor = QColor{0x32, 0x33, 0x30, 0};
static constexpr auto selectedBackgroundColor = QColor(0x3C, 0x59, 0x5C, 255); static constexpr auto selectedBackgroundColor = QColor{0x3C, 0x59, 0x5C, 255};
static constexpr auto primaryHighlightedBackgroundColor = QColor(0x3B, 0x59, 0x37, 255); static constexpr auto primaryHighlightedBackgroundColor = QColor{0x3B, 0x59, 0x37, 255};
static constexpr auto groupedBackgroundColor = QColor(0x44, 0x44, 0x41, 255); static constexpr auto groupedBackgroundColor = QColor{0x44, 0x44, 0x41, 255};
static constexpr auto stackMemoryBackgroundColor = QColor(0x44, 0x44, 0x41, 200); static constexpr auto stackMemoryBackgroundColor = QColor{0x44, 0x44, 0x41, 200};
static constexpr auto stackMemoryBarColor = QColor(0x67, 0x57, 0x20, 255); static constexpr auto stackMemoryBarColor = QColor{0x67, 0x57, 0x20, 255};
static constexpr auto changedMemoryBackgroundColor = QColor(0x5C, 0x49, 0x5D, 200); static constexpr auto changedMemoryBackgroundColor = QColor{0x5C, 0x49, 0x5D, 200};
static constexpr auto changedMemoryFadedBackgroundColor = QColor(0x5C, 0x49, 0x5D, 125); static constexpr auto changedMemoryFadedBackgroundColor = QColor{0x5C, 0x49, 0x5D, 125};
static const auto hoveredStackMemoryBackgroundColor = QColor( static const auto hoveredStackMemoryBackgroundColor = QColor{
stackMemoryBackgroundColor.red(), stackMemoryBackgroundColor.red(),
stackMemoryBackgroundColor.green(), stackMemoryBackgroundColor.green(),
stackMemoryBackgroundColor.blue(), stackMemoryBackgroundColor.blue(),
255 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 standardFontColor = QColor{0xAF, 0xB1, 0xB3};
static constexpr auto fadedFontColor = QColor(0xAF, 0xB1, 0xB3, 100); static constexpr auto fadedFontColor = QColor{0xAF, 0xB1, 0xB3, 100};
static constexpr auto asciiFontColor = QColor(0xA7, 0x77, 0x26); static constexpr auto asciiFontColor = QColor{0xA7, 0x77, 0x26};
static constexpr auto changedMemoryAsciiFontColor = QColor(0xB7, 0x7F, 0x21); 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(); const auto byteItemSize = byteItemRect.size();
auto standardTemplatePixmap = QPixmap(byteItemSize); auto standardTemplatePixmap = QPixmap{byteItemSize};
standardTemplatePixmap.fill(standardBackgroundColor); standardTemplatePixmap.fill(standardBackgroundColor);
auto primaryHighlightedTemplatePixmap = QPixmap(byteItemSize); auto primaryHighlightedTemplatePixmap = QPixmap{byteItemSize};
primaryHighlightedTemplatePixmap.fill(primaryHighlightedBackgroundColor); primaryHighlightedTemplatePixmap.fill(primaryHighlightedBackgroundColor);
auto selectedTemplatePixmap = QPixmap(byteItemSize); auto selectedTemplatePixmap = QPixmap{byteItemSize};
selectedTemplatePixmap.fill(selectedBackgroundColor); selectedTemplatePixmap.fill(selectedBackgroundColor);
auto groupedTemplatePixmap = QPixmap(byteItemSize); auto groupedTemplatePixmap = QPixmap{byteItemSize};
groupedTemplatePixmap.fill(groupedBackgroundColor); groupedTemplatePixmap.fill(groupedBackgroundColor);
auto stackMemoryTemplatePixmap = QPixmap(byteItemSize); auto stackMemoryTemplatePixmap = QPixmap{byteItemSize};
stackMemoryTemplatePixmap.fill(stackMemoryBackgroundColor); stackMemoryTemplatePixmap.fill(stackMemoryBackgroundColor);
{ {
auto painter = QPainter(&stackMemoryTemplatePixmap); auto painter = QPainter{&stackMemoryTemplatePixmap};
painter.setBrush(stackMemoryBarColor); painter.setBrush(stackMemoryBarColor);
painter.setPen(Qt::PenStyle::NoPen); painter.setPen(Qt::PenStyle::NoPen);
painter.drawRect(0, byteItemSize.height() - 3, byteItemSize.width(), 3); painter.drawRect(0, byteItemSize.height() - 3, byteItemSize.width(), 3);
} }
auto changedMemoryTemplatePixmap = QPixmap(byteItemSize); auto changedMemoryTemplatePixmap = QPixmap{byteItemSize};
changedMemoryTemplatePixmap.fill(changedMemoryBackgroundColor); changedMemoryTemplatePixmap.fill(changedMemoryBackgroundColor);
auto changedMemoryFadedTemplatePixmap = QPixmap(byteItemSize); auto changedMemoryFadedTemplatePixmap = QPixmap{byteItemSize};
changedMemoryFadedTemplatePixmap.fill(changedMemoryFadedBackgroundColor); changedMemoryFadedTemplatePixmap.fill(changedMemoryFadedBackgroundColor);
auto hoveredStackMemoryTemplatePixmap = QPixmap(byteItemSize); auto hoveredStackMemoryTemplatePixmap = QPixmap{byteItemSize};
hoveredStackMemoryTemplatePixmap.fill(hoveredStackMemoryBackgroundColor); hoveredStackMemoryTemplatePixmap.fill(hoveredStackMemoryBackgroundColor);
auto hoveredPrimaryTemplatePixmap = QPixmap(byteItemSize); auto hoveredPrimaryTemplatePixmap = QPixmap{byteItemSize};
hoveredPrimaryTemplatePixmap.fill(hoveredBackgroundColor); 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 hexValue = QString::number(value, 16).rightJustified(2, '0').toUpper();
const auto asciiValue = value >= 32 && value <= 126 const auto asciiValue = value >= 32 && value <= 126
? std::optional("'" + QString(QChar(value)) + "'") ? std::optional{"'" + QString{QChar{value}} + "'"}
: std::nullopt; : std::nullopt;
{ {
auto standardPixmap = standardTemplatePixmap; auto standardPixmap = standardTemplatePixmap;
auto painter = QPainter(&standardPixmap); auto painter = QPainter{&standardPixmap};
painter.setFont(font); painter.setFont(font);
painter.setPen(standardFontColor); painter.setPen(standardFontColor);
painter.drawText(byteItemRect, Qt::AlignCenter, hexValue); painter.drawText(byteItemRect, Qt::AlignCenter, hexValue);
@@ -703,7 +700,7 @@ namespace Widgets
{ {
auto selectedPixmap = selectedTemplatePixmap; auto selectedPixmap = selectedTemplatePixmap;
auto painter = QPainter(&selectedPixmap); auto painter = QPainter{&selectedPixmap};
painter.setFont(font); painter.setFont(font);
painter.setPen(standardFontColor); painter.setPen(standardFontColor);
painter.drawText(byteItemRect, Qt::AlignCenter, hexValue); painter.drawText(byteItemRect, Qt::AlignCenter, hexValue);
@@ -713,7 +710,7 @@ namespace Widgets
{ {
auto primaryHighlightedPixmap = primaryHighlightedTemplatePixmap; auto primaryHighlightedPixmap = primaryHighlightedTemplatePixmap;
auto painter = QPainter(&primaryHighlightedPixmap); auto painter = QPainter{&primaryHighlightedPixmap};
painter.setFont(font); painter.setFont(font);
painter.setPen(standardFontColor); painter.setPen(standardFontColor);
painter.drawText(byteItemRect, Qt::AlignCenter, hexValue); painter.drawText(byteItemRect, Qt::AlignCenter, hexValue);
@@ -723,7 +720,7 @@ namespace Widgets
{ {
auto groupedPixmap = groupedTemplatePixmap; auto groupedPixmap = groupedTemplatePixmap;
auto painter = QPainter(&groupedPixmap); auto painter = QPainter{&groupedPixmap};
painter.setFont(font); painter.setFont(font);
painter.setPen(standardFontColor); painter.setPen(standardFontColor);
painter.drawText(byteItemRect, Qt::AlignCenter, hexValue); painter.drawText(byteItemRect, Qt::AlignCenter, hexValue);
@@ -733,7 +730,7 @@ namespace Widgets
{ {
auto stackMemoryPixmap = stackMemoryTemplatePixmap; auto stackMemoryPixmap = stackMemoryTemplatePixmap;
auto painter = QPainter(&stackMemoryPixmap); auto painter = QPainter{&stackMemoryPixmap};
painter.setFont(font); painter.setFont(font);
painter.setPen(standardFontColor); painter.setPen(standardFontColor);
painter.drawText(byteItemRect, Qt::AlignCenter, hexValue); painter.drawText(byteItemRect, Qt::AlignCenter, hexValue);
@@ -743,7 +740,7 @@ namespace Widgets
{ {
auto changedMemoryPixmap = changedMemoryTemplatePixmap; auto changedMemoryPixmap = changedMemoryTemplatePixmap;
auto painter = QPainter(&changedMemoryPixmap); auto painter = QPainter{&changedMemoryPixmap};
painter.setFont(font); painter.setFont(font);
painter.setPen(standardFontColor); painter.setPen(standardFontColor);
painter.drawText(byteItemRect, Qt::AlignCenter, hexValue); painter.drawText(byteItemRect, Qt::AlignCenter, hexValue);
@@ -753,7 +750,7 @@ namespace Widgets
{ {
auto hoveredPrimaryPixmap = hoveredPrimaryTemplatePixmap; auto hoveredPrimaryPixmap = hoveredPrimaryTemplatePixmap;
auto painter = QPainter(&hoveredPrimaryPixmap); auto painter = QPainter{&hoveredPrimaryPixmap};
painter.setFont(font); painter.setFont(font);
painter.setPen(standardFontColor); painter.setPen(standardFontColor);
painter.drawText(byteItemRect, Qt::AlignCenter, hexValue); painter.drawText(byteItemRect, Qt::AlignCenter, hexValue);
@@ -763,7 +760,7 @@ namespace Widgets
{ {
auto standardAsciiPixmap = standardTemplatePixmap; auto standardAsciiPixmap = standardTemplatePixmap;
auto painter = QPainter(&standardAsciiPixmap); auto painter = QPainter{&standardAsciiPixmap};
painter.setFont(font); painter.setFont(font);
painter.setPen(asciiValue.has_value() ? asciiFontColor : fadedFontColor); painter.setPen(asciiValue.has_value() ? asciiFontColor : fadedFontColor);
painter.drawText(byteItemRect, Qt::AlignCenter, asciiValue.value_or(hexValue)); painter.drawText(byteItemRect, Qt::AlignCenter, asciiValue.value_or(hexValue));
@@ -773,7 +770,7 @@ namespace Widgets
{ {
auto selectedAsciiPixmap = selectedTemplatePixmap; auto selectedAsciiPixmap = selectedTemplatePixmap;
auto painter = QPainter(&selectedAsciiPixmap); auto painter = QPainter{&selectedAsciiPixmap};
painter.setFont(font); painter.setFont(font);
painter.setPen(asciiValue.has_value() ? asciiFontColor : fadedFontColor); painter.setPen(asciiValue.has_value() ? asciiFontColor : fadedFontColor);
painter.drawText(byteItemRect, Qt::AlignCenter, asciiValue.value_or(hexValue)); painter.drawText(byteItemRect, Qt::AlignCenter, asciiValue.value_or(hexValue));
@@ -783,7 +780,7 @@ namespace Widgets
{ {
auto primaryHighlightedAsciiPixmap = primaryHighlightedTemplatePixmap; auto primaryHighlightedAsciiPixmap = primaryHighlightedTemplatePixmap;
auto painter = QPainter(&primaryHighlightedAsciiPixmap); auto painter = QPainter{&primaryHighlightedAsciiPixmap};
painter.setFont(font); painter.setFont(font);
painter.setPen(asciiValue.has_value() ? asciiFontColor : fadedFontColor); painter.setPen(asciiValue.has_value() ? asciiFontColor : fadedFontColor);
painter.drawText(byteItemRect, Qt::AlignCenter, asciiValue.value_or(hexValue)); painter.drawText(byteItemRect, Qt::AlignCenter, asciiValue.value_or(hexValue));
@@ -795,7 +792,7 @@ namespace Widgets
{ {
auto groupedAsciiPixmap = groupedTemplatePixmap; auto groupedAsciiPixmap = groupedTemplatePixmap;
auto painter = QPainter(&groupedAsciiPixmap); auto painter = QPainter{&groupedAsciiPixmap};
painter.setFont(font); painter.setFont(font);
painter.setPen(asciiValue.has_value() ? asciiFontColor : fadedFontColor); painter.setPen(asciiValue.has_value() ? asciiFontColor : fadedFontColor);
painter.drawText(byteItemRect, Qt::AlignCenter, asciiValue.value_or(hexValue)); painter.drawText(byteItemRect, Qt::AlignCenter, asciiValue.value_or(hexValue));
@@ -805,7 +802,7 @@ namespace Widgets
{ {
auto stackMemoryAsciiPixmap = stackMemoryTemplatePixmap; auto stackMemoryAsciiPixmap = stackMemoryTemplatePixmap;
auto painter = QPainter(&stackMemoryAsciiPixmap); auto painter = QPainter{&stackMemoryAsciiPixmap};
painter.setFont(font); painter.setFont(font);
painter.setPen(asciiValue.has_value() ? asciiFontColor : fadedFontColor); painter.setPen(asciiValue.has_value() ? asciiFontColor : fadedFontColor);
painter.drawText(byteItemRect, Qt::AlignCenter, asciiValue.value_or(hexValue)); painter.drawText(byteItemRect, Qt::AlignCenter, asciiValue.value_or(hexValue));
@@ -818,7 +815,7 @@ namespace Widgets
? changedMemoryTemplatePixmap ? changedMemoryTemplatePixmap
: changedMemoryFadedTemplatePixmap; : changedMemoryFadedTemplatePixmap;
auto painter = QPainter(&changedMemoryAsciiPixmap); auto painter = QPainter{&changedMemoryAsciiPixmap};
painter.setFont(font); painter.setFont(font);
painter.setPen(asciiValue.has_value() ? changedMemoryAsciiFontColor : fadedFontColor); painter.setPen(asciiValue.has_value() ? changedMemoryAsciiFontColor : fadedFontColor);
painter.drawText(byteItemRect, Qt::AlignCenter, asciiValue.value_or(hexValue)); painter.drawText(byteItemRect, Qt::AlignCenter, asciiValue.value_or(hexValue));
@@ -828,7 +825,7 @@ namespace Widgets
{ {
auto hoveredPrimaryAsciiPixmap = hoveredPrimaryTemplatePixmap; auto hoveredPrimaryAsciiPixmap = hoveredPrimaryTemplatePixmap;
auto painter = QPainter(&hoveredPrimaryAsciiPixmap); auto painter = QPainter{&hoveredPrimaryAsciiPixmap};
painter.setFont(font); painter.setFont(font);
painter.setPen(asciiValue.has_value() ? asciiFontColor : fadedFontColor); painter.setPen(asciiValue.has_value() ? asciiFontColor : fadedFontColor);
painter.drawText(byteItemRect, Qt::AlignCenter, asciiValue.value_or(hexValue)); painter.drawText(byteItemRect, Qt::AlignCenter, asciiValue.value_or(hexValue));
@@ -839,7 +836,7 @@ namespace Widgets
{ {
HexViewerItemRenderer::missingDataPixmap = standardTemplatePixmap; HexViewerItemRenderer::missingDataPixmap = standardTemplatePixmap;
auto painter = QPainter(&HexViewerItemRenderer::missingDataPixmap.value()); auto painter = QPainter{&HexViewerItemRenderer::missingDataPixmap.value()};
painter.setFont(font); painter.setFont(font);
painter.setPen(standardFontColor); painter.setPen(standardFontColor);
painter.drawText(byteItemRect, Qt::AlignCenter, "??"); painter.drawText(byteItemRect, Qt::AlignCenter, "??");
@@ -847,7 +844,7 @@ namespace Widgets
{ {
HexViewerItemRenderer::selectedMissingDataPixmap = selectedTemplatePixmap; HexViewerItemRenderer::selectedMissingDataPixmap = selectedTemplatePixmap;
auto painter = QPainter(&HexViewerItemRenderer::selectedMissingDataPixmap.value()); auto painter = QPainter{&HexViewerItemRenderer::selectedMissingDataPixmap.value()};
painter.setFont(font); painter.setFont(font);
painter.setPen(standardFontColor); painter.setPen(standardFontColor);
painter.drawText(byteItemRect, Qt::AlignCenter, "??"); painter.drawText(byteItemRect, Qt::AlignCenter, "??");
@@ -855,7 +852,7 @@ namespace Widgets
{ {
HexViewerItemRenderer::primaryHighlightedMissingDataPixmap = primaryHighlightedTemplatePixmap; HexViewerItemRenderer::primaryHighlightedMissingDataPixmap = primaryHighlightedTemplatePixmap;
auto painter = QPainter(&HexViewerItemRenderer::primaryHighlightedMissingDataPixmap.value()); auto painter = QPainter{&HexViewerItemRenderer::primaryHighlightedMissingDataPixmap.value()};
painter.setFont(font); painter.setFont(font);
painter.setPen(standardFontColor); painter.setPen(standardFontColor);
painter.drawText(byteItemRect, Qt::AlignCenter, "??"); painter.drawText(byteItemRect, Qt::AlignCenter, "??");

View File

@@ -37,7 +37,7 @@ namespace Widgets
); );
[[nodiscard]] QRectF boundingRect() const override { [[nodiscard]] QRectF boundingRect() const override {
return QRectF(0, 0, this->size.width(), this->size.height()); return QRectF{0, 0, static_cast<qreal>(this->size.width()), static_cast<qreal>(this->size.height())};
} }
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override; void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override;

View File

@@ -3,6 +3,9 @@
#include <optional> #include <optional>
#include "src/Targets/TargetMemory.hpp" #include "src/Targets/TargetMemory.hpp"
#include "src/Targets/TargetAddressSpaceDescriptor.hpp"
#include "src/Targets/TargetMemorySegmentDescriptor.hpp"
#include "HexViewerWidgetSettings.hpp" #include "HexViewerWidgetSettings.hpp"
namespace Widgets namespace Widgets
@@ -12,7 +15,9 @@ namespace Widgets
struct HexViewerSharedState struct HexViewerSharedState
{ {
public: public:
const Targets::TargetMemoryDescriptor& memoryDescriptor; const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor;
const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor;
const std::optional<Targets::TargetMemoryBuffer>& data; const std::optional<Targets::TargetMemoryBuffer>& data;
HexViewerWidgetSettings& settings; HexViewerWidgetSettings& settings;
@@ -23,11 +28,13 @@ namespace Widgets
std::set<Targets::TargetMemoryAddressRange> highlightedPrimaryAddressRanges; std::set<Targets::TargetMemoryAddressRange> highlightedPrimaryAddressRanges;
HexViewerSharedState( HexViewerSharedState(
const Targets::TargetMemoryDescriptor& memoryDescriptor, const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor,
const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor,
const std::optional<Targets::TargetMemoryBuffer>& data, const std::optional<Targets::TargetMemoryBuffer>& data,
HexViewerWidgetSettings& settings HexViewerWidgetSettings& settings
) )
: memoryDescriptor(memoryDescriptor) : addressSpaceDescriptor(addressSpaceDescriptor)
, memorySegmentDescriptor(memorySegmentDescriptor)
, data(data) , data(data)
, settings(settings) , settings(settings)
{} {}

View File

@@ -14,10 +14,14 @@ namespace Widgets
{ {
using namespace Exceptions; using namespace Exceptions;
using Targets::TargetMemoryDescriptor; using Targets::TargetAddressSpaceDescriptor;
using Targets::TargetMemorySegmentDescriptor;
using Targets::TargetState;
HexViewerWidget::HexViewerWidget( HexViewerWidget::HexViewerWidget(
const TargetMemoryDescriptor& targetMemoryDescriptor, const TargetAddressSpaceDescriptor& addressSpaceDescriptor,
const TargetMemorySegmentDescriptor& memorySegmentDescriptor,
const TargetState& targetState,
const std::optional<Targets::TargetMemoryBuffer>& data, const std::optional<Targets::TargetMemoryBuffer>& data,
HexViewerWidgetSettings& settings, HexViewerWidgetSettings& settings,
const std::vector<FocusedMemoryRegion>& focusedMemoryRegions, const std::vector<FocusedMemoryRegion>& focusedMemoryRegions,
@@ -25,7 +29,9 @@ namespace Widgets
QWidget* parent QWidget* parent
) )
: QWidget(parent) : QWidget(parent)
, targetMemoryDescriptor(targetMemoryDescriptor) , addressSpaceDescriptor(addressSpaceDescriptor)
, memorySegmentDescriptor(memorySegmentDescriptor)
, targetState(targetState)
, data(data) , data(data)
, settings(settings) , settings(settings)
, focusedMemoryRegions(focusedMemoryRegions) , focusedMemoryRegions(focusedMemoryRegions)
@@ -34,29 +40,29 @@ namespace Widgets
this->setObjectName("hex-viewer-widget"); this->setObjectName("hex-viewer-widget");
this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
auto widgetUiFile = QFile( auto widgetUiFile = QFile{
QString::fromStdString(Services::PathService::compiledResourcesPath() QString::fromStdString(Services::PathService::compiledResourcesPath()
+ "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget" + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget"
+ "/UiFiles/HexViewerWidget.ui" + "/UiFiles/HexViewerWidget.ui"
) )
); };
auto stylesheetFile = QFile( auto stylesheetFile = QFile{
QString::fromStdString(Services::PathService::compiledResourcesPath() QString::fromStdString(Services::PathService::compiledResourcesPath()
+ "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget" + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget"
+ "/Stylesheets/HexViewerWidget.qss" + "/Stylesheets/HexViewerWidget.qss"
) )
); };
if (!widgetUiFile.open(QFile::ReadOnly)) { 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)) { 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->container = uiLoader.load(&widgetUiFile, this);
this->setStyleSheet(stylesheetFile.readAll()); this->setStyleSheet(stylesheetFile.readAll());
this->container->setFixedSize(this->size()); this->container->setFixedSize(this->size());
@@ -95,7 +101,7 @@ namespace Widgets
this->setAnnotationsEnabled(this->settings.displayAnnotations); this->setAnnotationsEnabled(this->settings.displayAnnotations);
this->setDisplayAsciiEnabled(this->settings.displayAsciiValues); this->setDisplayAsciiEnabled(this->settings.displayAsciiValues);
if (this->targetMemoryDescriptor.type == Targets::TargetMemoryType::RAM) { if (this->memorySegmentDescriptor.type == Targets::TargetMemorySegmentType::RAM) {
this->groupStackMemoryButton->show(); this->groupStackMemoryButton->show();
this->setStackMemoryGroupingEnabled(this->settings.groupStackMemory); this->setStackMemoryGroupingEnabled(this->settings.groupStackMemory);
@@ -163,25 +169,20 @@ namespace Widgets
&HexViewerWidget::onGoToAddressInputChanged &HexViewerWidget::onGoToAddressInputChanged
); );
QObject::connect(
InsightSignals::instance(),
&InsightSignals::targetStateUpdated,
this,
&HexViewerWidget::onTargetStateChanged
);
this->show(); this->show();
} }
void HexViewerWidget::init() { void HexViewerWidget::init() {
this->byteItemGraphicsView = new ItemGraphicsView( this->byteItemGraphicsView = new ItemGraphicsView{
this->targetMemoryDescriptor, this->addressSpaceDescriptor,
this->memorySegmentDescriptor,
this->targetState,
this->data, this->data,
this->focusedMemoryRegions, this->focusedMemoryRegions,
this->excludedMemoryRegions, this->excludedMemoryRegions,
this->settings, this->settings,
this->container this->container
); };
this->byteItemGraphicsView->hide(); this->byteItemGraphicsView->hide();
@@ -271,11 +272,6 @@ namespace Widgets
QWidget::showEvent(event); QWidget::showEvent(event);
} }
void HexViewerWidget::onTargetStateChanged(Targets::TargetState newState) {
using Targets::TargetState;
this->targetState = newState;
}
void HexViewerWidget::setStackMemoryGroupingEnabled(bool enabled) { void HexViewerWidget::setStackMemoryGroupingEnabled(bool enabled) {
this->groupStackMemoryButton->setChecked(enabled); this->groupStackMemoryButton->setChecked(enabled);
this->settings.groupStackMemory = enabled; this->settings.groupStackMemory = enabled;
@@ -336,12 +332,14 @@ namespace Widgets
return; return;
} }
auto addressConversionOk = false; auto conversionStatus = false;
const auto address = this->goToAddressInput->text().toUInt(&addressConversionOk, 16); const auto address = this->goToAddressInput->text().toUInt(&conversionStatus, 16);
const auto& memoryAddressRange = this->targetMemoryDescriptor.addressRange; if (
conversionStatus
if (addressConversionOk && memoryAddressRange.contains(address) && this->goToAddressInput->hasFocus()) { && this->memorySegmentDescriptor.addressRange.contains(address)
&& this->goToAddressInput->hasFocus()
) {
this->byteItemGraphicsScene->selectByteItems({address}); this->byteItemGraphicsScene->selectByteItems({address});
this->byteItemGraphicsView->scrollToByteItemAtAddress(address); this->byteItemGraphicsView->scrollToByteItemAtAddress(address);
return; return;
@@ -361,7 +359,7 @@ namespace Widgets
16 16
).rightJustified(8, '0').toUpper(); ).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( const auto relativeAddressHex = "0x" + QString::number(
relativeAddress, relativeAddress,
16 16
@@ -383,7 +381,7 @@ namespace Widgets
} }
this->selectionCountLabel->setText( this->selectionCountLabel->setText(
QLocale(QLocale::English).toString(selectionCount) + " " + QString(selectionCount == 1 ? "byte" : "bytes") QLocale{QLocale::English}.toString(selectionCount) + " " + QString(selectionCount == 1 ? "byte" : "bytes")
+ " selected" + " selected"
); );
this->selectionCountLabel->show(); this->selectionCountLabel->show();
@@ -392,7 +390,7 @@ namespace Widgets
std::set<Targets::TargetMemoryAddress> HexViewerWidget::addressRangesToAddresses( std::set<Targets::TargetMemoryAddress> HexViewerWidget::addressRangesToAddresses(
const std::set<Targets::TargetMemoryAddressRange>& addressRanges const std::set<Targets::TargetMemoryAddressRange>& addressRanges
) { ) {
auto addresses = std::set<Targets::TargetMemoryAddress>(); auto addresses = std::set<Targets::TargetMemoryAddress>{};
auto addressesIt = addresses.end(); auto addressesIt = addresses.end();
for (const auto& range : addressRanges) { for (const auto& range : addressRanges) {

View File

@@ -7,6 +7,8 @@
#include <optional> #include <optional>
#include "src/Targets/TargetMemory.hpp" #include "src/Targets/TargetMemory.hpp"
#include "src/Targets/TargetAddressSpaceDescriptor.hpp"
#include "src/Targets/TargetMemorySegmentDescriptor.hpp"
#include "src/Targets/TargetState.hpp" #include "src/Targets/TargetState.hpp"
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/Label.hpp" #include "src/Insight/UserInterfaces/InsightWindow/Widgets/Label.hpp"
@@ -29,7 +31,9 @@ namespace Widgets
public: public:
HexViewerWidget( HexViewerWidget(
const Targets::TargetMemoryDescriptor& targetMemoryDescriptor, const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor,
const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor,
const Targets::TargetState& targetState,
const std::optional<Targets::TargetMemoryBuffer>& data, const std::optional<Targets::TargetMemoryBuffer>& data,
HexViewerWidgetSettings& settings, HexViewerWidgetSettings& settings,
const std::vector<FocusedMemoryRegion>& focusedMemoryRegions, const std::vector<FocusedMemoryRegion>& focusedMemoryRegions,
@@ -52,7 +56,9 @@ namespace Widgets
void settingsChanged(const HexViewerWidgetSettings& settings); void settingsChanged(const HexViewerWidgetSettings& settings);
protected: protected:
const Targets::TargetMemoryDescriptor& targetMemoryDescriptor; const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor;
const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor;
const Targets::TargetState& targetState;
const std::optional<Targets::TargetMemoryBuffer>& data; const std::optional<Targets::TargetMemoryBuffer>& data;
HexViewerWidgetSettings& settings; HexViewerWidgetSettings& settings;
@@ -78,8 +84,6 @@ namespace Widgets
TextInput* goToAddressInput = nullptr; TextInput* goToAddressInput = nullptr;
Targets::TargetState targetState = Targets::TargetState::UNKNOWN;
void resizeEvent(QResizeEvent* event) override; void resizeEvent(QResizeEvent* event) override;
void showEvent(QShowEvent* event) override; void showEvent(QShowEvent* event) override;
void onTargetStateChanged(Targets::TargetState newState); void onTargetStateChanged(Targets::TargetState newState);

View File

@@ -11,14 +11,14 @@
#include <algorithm> #include <algorithm>
#include "src/Insight/InsightWorker/InsightWorker.hpp" #include "src/Insight/InsightWorker/InsightWorker.hpp"
#include "src/Insight/InsightSignals.hpp"
#include "src/Insight/InsightWorker/Tasks/ConstructHexViewerTopLevelGroupItem.hpp" #include "src/Insight/InsightWorker/Tasks/ConstructHexViewerTopLevelGroupItem.hpp"
namespace Widgets namespace Widgets
{ {
ItemGraphicsScene::ItemGraphicsScene( ItemGraphicsScene::ItemGraphicsScene(
const Targets::TargetMemoryDescriptor& targetMemoryDescriptor, const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor,
const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor,
const Targets::TargetState& targetState,
const std::optional<Targets::TargetMemoryBuffer>& data, const std::optional<Targets::TargetMemoryBuffer>& data,
const std::vector<FocusedMemoryRegion>& focusedMemoryRegions, const std::vector<FocusedMemoryRegion>& focusedMemoryRegions,
const std::vector<ExcludedMemoryRegion>& excludedMemoryRegions, const std::vector<ExcludedMemoryRegion>& excludedMemoryRegions,
@@ -27,19 +27,21 @@ namespace Widgets
) )
: QGraphicsScene(parent) : QGraphicsScene(parent)
, state( , state(
HexViewerSharedState( HexViewerSharedState{
targetMemoryDescriptor, addressSpaceDescriptor,
memorySegmentDescriptor,
data, data,
settings settings
) }
) )
, targetState(targetState)
, focusedMemoryRegions(focusedMemoryRegions) , focusedMemoryRegions(focusedMemoryRegions)
, excludedMemoryRegions(excludedMemoryRegions) , excludedMemoryRegions(excludedMemoryRegions)
, parent(parent) , parent(parent)
{ {
this->setObjectName("byte-widget-container"); this->setObjectName("byte-widget-container");
this->byteAddressContainer = new ByteAddressContainer(this->state); this->byteAddressContainer = new ByteAddressContainer{this->state};
this->addItem(this->byteAddressContainer); this->addItem(this->byteAddressContainer);
this->displayRelativeAddressAction->setCheckable(true); this->displayRelativeAddressAction->setCheckable(true);
@@ -48,13 +50,6 @@ namespace Widgets
this->setAddressType(this->state.settings.addressLabelType); this->setAddressType(this->state.settings.addressLabelType);
this->setItemIndexMethod(QGraphicsScene::ItemIndexMethod::NoIndex); this->setItemIndexMethod(QGraphicsScene::ItemIndexMethod::NoIndex);
QObject::connect(
InsightSignals::instance(),
&InsightSignals::targetStateUpdated,
this,
&ItemGraphicsScene::onTargetStateChanged
);
QObject::connect( QObject::connect(
this->displayRelativeAddressAction, this->displayRelativeAddressAction,
&QAction::triggered, &QAction::triggered,
@@ -168,14 +163,14 @@ namespace Widgets
void ItemGraphicsScene::init() { void ItemGraphicsScene::init() {
this->byteAddressContainer->setPos(this->addressContainerPosition()); this->byteAddressContainer->setPos(this->addressContainerPosition());
const auto constructHexViewerTopLevelGroupItem = QSharedPointer<ConstructHexViewerTopLevelGroupItem>( const auto constructHexViewerTopLevelGroupItem = QSharedPointer<ConstructHexViewerTopLevelGroupItem>{
new ConstructHexViewerTopLevelGroupItem( new ConstructHexViewerTopLevelGroupItem{
this->focusedMemoryRegions, this->focusedMemoryRegions,
this->excludedMemoryRegions, this->excludedMemoryRegions,
this->state this->state
), },
&QObject::deleteLater &QObject::deleteLater
); };
QObject::connect( QObject::connect(
constructHexViewerTopLevelGroupItem.get(), constructHexViewerTopLevelGroupItem.get(),
@@ -186,7 +181,7 @@ namespace Widgets
this->topLevelGroup.reset(item); this->topLevelGroup.reset(item);
this->topLevelGroup->setPosition( this->topLevelGroup->setPosition(
QPoint(ByteAddressContainer::WIDTH + margins.left(), margins.top()) QPoint{ByteAddressContainer::WIDTH + margins.left(), margins.top()}
); );
this->itemIndex = std::make_unique<HexViewerItemIndex>(this->topLevelGroup.get(), this); this->itemIndex = std::make_unique<HexViewerItemIndex>(this->topLevelGroup.get(), this);
@@ -267,14 +262,13 @@ namespace Widgets
this->topLevelGroup->adjustItemPositions(availableWidth); this->topLevelGroup->adjustItemPositions(availableWidth);
this->itemIndex->refreshIndex(); this->itemIndex->refreshIndex();
const auto sceneSize = QSize( const auto sceneSize = QSize{
width, width,
std::max( std::max(
static_cast<int>(this->topLevelGroup->size().height()) static_cast<int>(this->topLevelGroup->size().height()) + margins.top() + margins.bottom(),
+ margins.top() + margins.bottom(),
this->parent->height() this->parent->height()
) )
); };
this->setSceneRect( this->setSceneRect(
0, 0,
0, 0,
@@ -317,7 +311,7 @@ namespace Widgets
return byteItemIt->second.position(); return byteItemIt->second.position();
} }
return QPointF(); return QPointF{};
} }
void ItemGraphicsScene::addExternalContextMenuAction(ContextMenuAction* action) { void ItemGraphicsScene::addExternalContextMenuAction(ContextMenuAction* action) {
@@ -329,22 +323,22 @@ namespace Widgets
} }
void ItemGraphicsScene::initRenderer() { void ItemGraphicsScene::initRenderer() {
this->renderer = new HexViewerItemRenderer( this->renderer = new HexViewerItemRenderer{
this->state, this->state,
*(this->topLevelGroup.get()), *(this->topLevelGroup.get()),
*(this->itemIndex.get()), *(this->itemIndex.get()),
this->views().first() this->views().first()
); };
this->renderer->setPos(0, 0); this->renderer->setPos(0, 0);
this->addItem(this->renderer); this->addItem(this->renderer);
} }
QMargins ItemGraphicsScene::margins() { QMargins ItemGraphicsScene::margins() {
return QMargins(10, 10, 10, 10); return QMargins{10, 10, 10, 10};
} }
QPointF ItemGraphicsScene::addressContainerPosition() { QPointF ItemGraphicsScene::addressContainerPosition() {
return QPointF(0, 0); return QPointF{0, 0};
} }
bool ItemGraphicsScene::event(QEvent* event) { bool ItemGraphicsScene::event(QEvent* event) {
@@ -360,8 +354,8 @@ namespace Widgets
} }
void ItemGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent* mouseEvent) { void ItemGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent* mouseEvent) {
static const auto rubberBandRectBackgroundColor = QColor(0x3C, 0x59, 0x5C, 0x82); static const auto rubberBandRectBackgroundColor = QColor{0x3C, 0x59, 0x5C, 0x82};
static const auto rubberBandRectBorderColor = QColor(0x3C, 0x59, 0x5C, 255); static const auto rubberBandRectBorderColor = QColor{0x3C, 0x59, 0x5C, 255};
const auto button = mouseEvent->button(); const auto button = mouseEvent->button();
const auto mousePosition = mouseEvent->buttonDownScenePos(button); const auto mousePosition = mouseEvent->buttonDownScenePos(button);
@@ -377,7 +371,7 @@ namespace Widgets
this->update(); this->update();
if (button == Qt::MouseButton::RightButton) { if (button == Qt::MouseButton::RightButton) {
ByteItem* clickedByteItem = this->itemIndex->byteItemAt(mousePosition); auto* clickedByteItem = this->itemIndex->byteItemAt(mousePosition);
if (clickedByteItem == nullptr || clickedByteItem->selected) { if (clickedByteItem == nullptr || clickedByteItem->selected) {
return; return;
@@ -389,12 +383,12 @@ namespace Widgets
this->clearSelectionRectItem(); this->clearSelectionRectItem();
this->rubberBandInitPoint = std::move(mousePosition); this->rubberBandInitPoint = std::move(mousePosition);
this->rubberBandRectItem = new QGraphicsRectItem( this->rubberBandRectItem = new QGraphicsRectItem{
this->rubberBandInitPoint->x(), this->rubberBandInitPoint->x(),
this->rubberBandInitPoint->y(), this->rubberBandInitPoint->y(),
1, 1,
1 1
); };
this->rubberBandRectItem->setBrush(rubberBandRectBackgroundColor); this->rubberBandRectItem->setBrush(rubberBandRectBackgroundColor);
this->rubberBandRectItem->setPen(rubberBandRectBorderColor); this->rubberBandRectItem->setPen(rubberBandRectBorderColor);
this->addItem(this->rubberBandRectItem); this->addItem(this->rubberBandRectItem);
@@ -409,7 +403,7 @@ namespace Widgets
if ((modifiers & Qt::ShiftModifier) != 0) { if ((modifiers & Qt::ShiftModifier) != 0) {
for ( for (
auto i = static_cast<std::int64_t>(clickedByteItem->startAddress); auto i = static_cast<std::int64_t>(clickedByteItem->startAddress);
i >= this->state.memoryDescriptor.addressRange.startAddress; i >= this->state.memorySegmentDescriptor.addressRange.startAddress;
--i --i
) { ) {
auto& byteItem = this->topLevelGroup->byteItemsByAddress.at( auto& byteItem = this->topLevelGroup->byteItemsByAddress.at(
@@ -500,11 +494,11 @@ namespace Widgets
void ItemGraphicsScene::contextMenuEvent(QGraphicsSceneContextMenuEvent* event) { void ItemGraphicsScene::contextMenuEvent(QGraphicsSceneContextMenuEvent* event) {
if (event->scenePos().x() <= ByteAddressContainer::WIDTH) { if (event->scenePos().x() <= ByteAddressContainer::WIDTH) {
auto* menu = new QMenu(this->parent); auto* menu = new QMenu{this->parent};
menu->setLayoutDirection(Qt::LayoutDirection::LeftToRight); menu->setLayoutDirection(Qt::LayoutDirection::LeftToRight);
menu->setObjectName("byte-item-address-container-context-menu"); 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->displayAbsoluteAddressAction);
addressTypeMenu->addAction(this->displayRelativeAddressAction); addressTypeMenu->addAction(this->displayRelativeAddressAction);
menu->addMenu(addressTypeMenu); menu->addMenu(addressTypeMenu);
@@ -515,13 +509,13 @@ namespace Widgets
const auto itemsSelected = !this->selectedByteItemAddresses.empty(); const auto itemsSelected = !this->selectedByteItemAddresses.empty();
auto* menu = new QMenu(this->parent); auto* menu = new QMenu{this->parent};
menu->setLayoutDirection(Qt::LayoutDirection::LeftToRight); menu->setLayoutDirection(Qt::LayoutDirection::LeftToRight);
menu->addAction(this->selectAllByteItemsAction); menu->addAction(this->selectAllByteItemsAction);
menu->addAction(this->deselectByteItemsAction); menu->addAction(this->deselectByteItemsAction);
menu->addSeparator(); menu->addSeparator();
auto* copyMenu = new QMenu("Copy Selection", menu); auto* copyMenu = new QMenu{"Copy Selection", menu};
copyMenu->addAction(this->copyAbsoluteAddressAction); copyMenu->addAction(this->copyAbsoluteAddressAction);
copyMenu->addAction(this->copyRelativeAddressAction); copyMenu->addAction(this->copyRelativeAddressAction);
copyMenu->addSeparator(); copyMenu->addSeparator();
@@ -561,10 +555,6 @@ namespace Widgets
return this->views().first()->verticalScrollBar()->value(); return this->views().first()->verticalScrollBar()->value();
} }
void ItemGraphicsScene::onTargetStateChanged(Targets::TargetState newState) {
this->targetState = newState;
}
void ItemGraphicsScene::onByteItemEnter(ByteItem& byteItem) { void ItemGraphicsScene::onByteItemEnter(ByteItem& byteItem) {
if (this->state.hoveredByteItem != nullptr) { if (this->state.hoveredByteItem != nullptr) {
if (this->state.hoveredByteItem == &byteItem) { if (this->state.hoveredByteItem == &byteItem) {
@@ -646,7 +636,7 @@ namespace Widgets
} }
std::set<Targets::TargetMemoryAddress> ItemGraphicsScene::excludedAddresses() { std::set<Targets::TargetMemoryAddress> ItemGraphicsScene::excludedAddresses() {
auto output = std::set<Targets::TargetMemoryAddress>(); auto output = std::set<Targets::TargetMemoryAddress>{};
for (const auto& excludedRegion : this->excludedMemoryRegions) { for (const auto& excludedRegion : this->excludedMemoryRegions) {
const auto regionAddresses = excludedRegion.addressRange.addresses(); const auto regionAddresses = excludedRegion.addressRange.addresses();
@@ -661,8 +651,8 @@ namespace Widgets
return; return;
} }
auto data = QString(); auto data = QString{};
const auto memoryStartAddress = this->state.memoryDescriptor.addressRange.startAddress; const auto memoryStartAddress = this->state.memorySegmentDescriptor.addressRange.startAddress;
for (const auto& address : this->selectedByteItemAddresses) { for (const auto& address : this->selectedByteItemAddresses) {
data.append( data.append(
@@ -684,12 +674,12 @@ namespace Widgets
} }
const auto excludedAddresses = this->excludedAddresses(); const auto excludedAddresses = this->excludedAddresses();
auto data = QString(); auto data = QString{};
for (const auto& address : this->selectedByteItemAddresses) { for (const auto& address : this->selectedByteItemAddresses) {
const unsigned char byteValue = excludedAddresses.contains(address) const unsigned char byteValue = excludedAddresses.contains(address)
? 0x00 ? 0x00
: (*this->state.data)[address - this->state.memoryDescriptor.addressRange.startAddress]; : (*this->state.data)[address - this->state.memorySegmentDescriptor.addressRange.startAddress];
data.append( data.append(
withDelimiters withDelimiters
@@ -707,12 +697,12 @@ namespace Widgets
} }
const auto excludedAddresses = this->excludedAddresses(); const auto excludedAddresses = this->excludedAddresses();
auto data = QString(); auto data = QString{};
for (const auto& address : this->selectedByteItemAddresses) { for (const auto& address : this->selectedByteItemAddresses) {
const unsigned char byteValue = excludedAddresses.contains(address) const unsigned char byteValue = excludedAddresses.contains(address)
? 0x00 ? 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"); data.append(QString::number(byteValue, 10) + "\n");
} }
@@ -725,12 +715,12 @@ namespace Widgets
} }
const auto excludedAddresses = this->excludedAddresses(); const auto excludedAddresses = this->excludedAddresses();
auto data = QString(); auto data = QString{};
for (const auto& address : this->selectedByteItemAddresses) { for (const auto& address : this->selectedByteItemAddresses) {
const unsigned char byteValue = excludedAddresses.contains(address) const unsigned char byteValue = excludedAddresses.contains(address)
? 0x00 ? 0x00
: (*this->state.data)[address - this->state.memoryDescriptor.addressRange.startAddress]; : (*this->state.data)[address - this->state.memorySegmentDescriptor.addressRange.startAddress];
data.append( data.append(
withDelimiters withDelimiters
@@ -748,12 +738,12 @@ namespace Widgets
} }
const auto excludedAddresses = this->excludedAddresses(); const auto excludedAddresses = this->excludedAddresses();
auto data = QJsonObject(); auto data = QJsonObject{};
for (const auto& address : this->selectedByteItemAddresses) { for (const auto& address : this->selectedByteItemAddresses) {
const unsigned char byteValue = excludedAddresses.contains(address) const unsigned char byteValue = excludedAddresses.contains(address)
? 0x00 ? 0x00
: (*this->state.data)[address - this->state.memoryDescriptor.addressRange.startAddress]; : (*this->state.data)[address - this->state.memorySegmentDescriptor.addressRange.startAddress];
data.insert( data.insert(
"0x" + QString::number(address, 16).rightJustified(8, '0').toUpper(), "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() { void ItemGraphicsScene::copyAsciiValueToClipboard() {
@@ -770,17 +760,17 @@ namespace Widgets
} }
const auto excludedAddresses = this->excludedAddresses(); const auto excludedAddresses = this->excludedAddresses();
auto data = QString(); auto data = QString{};
for (const auto& address : this->selectedByteItemAddresses) { for (const auto& address : this->selectedByteItemAddresses) {
const unsigned char byteValue = 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) { if (excludedAddresses.contains(address) || byteValue < 32 || byteValue > 126) {
continue; continue;
} }
data.append(QChar(byteValue)); data.append(QChar{byteValue});
} }
QApplication::clipboard()->setText(std::move(data)); QApplication::clipboard()->setText(std::move(data));
@@ -789,7 +779,7 @@ namespace Widgets
std::set<Targets::TargetMemoryAddress> ItemGraphicsScene::addressRangesToAddresses( std::set<Targets::TargetMemoryAddress> ItemGraphicsScene::addressRangesToAddresses(
const std::set<Targets::TargetMemoryAddressRange>& addressRanges const std::set<Targets::TargetMemoryAddressRange>& addressRanges
) { ) {
auto addresses = std::set<Targets::TargetMemoryAddress>(); auto addresses = std::set<Targets::TargetMemoryAddress>{};
for (const auto& range : addressRanges) { for (const auto& range : addressRanges) {
const auto rangeAddresses = range.addresses(); const auto rangeAddresses = range.addresses();

View File

@@ -18,6 +18,8 @@
#include <QTimer> #include <QTimer>
#include "src/Targets/TargetMemory.hpp" #include "src/Targets/TargetMemory.hpp"
#include "src/Targets/TargetAddressSpaceDescriptor.hpp"
#include "src/Targets/TargetMemorySegmentDescriptor.hpp"
#include "src/Targets/TargetState.hpp" #include "src/Targets/TargetState.hpp"
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/Label.hpp" #include "src/Insight/UserInterfaces/InsightWindow/Widgets/Label.hpp"
@@ -45,7 +47,9 @@ namespace Widgets
public: public:
ItemGraphicsScene( ItemGraphicsScene(
const Targets::TargetMemoryDescriptor& targetMemoryDescriptor, const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor,
const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor,
const Targets::TargetState& targetState,
const std::optional<Targets::TargetMemoryBuffer>& data, const std::optional<Targets::TargetMemoryBuffer>& data,
const std::vector<FocusedMemoryRegion>& focusedMemoryRegions, const std::vector<FocusedMemoryRegion>& focusedMemoryRegions,
const std::vector<ExcludedMemoryRegion>& excludedMemoryRegions, const std::vector<ExcludedMemoryRegion>& excludedMemoryRegions,
@@ -76,6 +80,7 @@ namespace Widgets
bool enabled = true; bool enabled = true;
HexViewerSharedState state; HexViewerSharedState state;
const Targets::TargetState& targetState;
const std::vector<FocusedMemoryRegion>& focusedMemoryRegions; const std::vector<FocusedMemoryRegion>& focusedMemoryRegions;
const std::vector<ExcludedMemoryRegion>& excludedMemoryRegions; const std::vector<ExcludedMemoryRegion>& excludedMemoryRegions;
@@ -85,8 +90,6 @@ namespace Widgets
HexViewerItemRenderer* renderer = nullptr; HexViewerItemRenderer* renderer = nullptr;
Targets::TargetState targetState = Targets::TargetState::UNKNOWN;
QGraphicsView* parent = nullptr; QGraphicsView* parent = nullptr;
ByteAddressContainer* byteAddressContainer = nullptr; ByteAddressContainer* byteAddressContainer = nullptr;
@@ -143,7 +146,6 @@ namespace Widgets
void keyPressEvent(QKeyEvent* keyEvent) override; void keyPressEvent(QKeyEvent* keyEvent) override;
void contextMenuEvent(QGraphicsSceneContextMenuEvent* event) override; void contextMenuEvent(QGraphicsSceneContextMenuEvent* event) override;
int getScrollbarValue(); int getScrollbarValue();
void onTargetStateChanged(Targets::TargetState newState);
void onByteItemEnter(ByteItem& byteItem); void onByteItemEnter(ByteItem& byteItem);
void onByteItemLeave(); void onByteItemLeave();
void clearSelectionRectItem(); void clearSelectionRectItem();

View File

@@ -6,10 +6,12 @@
namespace Widgets namespace Widgets
{ {
using Targets::TargetMemoryDescriptor; using Targets::TargetMemorySegmentDescriptor;
ItemGraphicsView::ItemGraphicsView( ItemGraphicsView::ItemGraphicsView(
const TargetMemoryDescriptor& targetMemoryDescriptor, const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor,
const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor,
const Targets::TargetState& targetState,
const std::optional<Targets::TargetMemoryBuffer>& data, const std::optional<Targets::TargetMemoryBuffer>& data,
const std::vector<FocusedMemoryRegion>& focusedMemoryRegions, const std::vector<FocusedMemoryRegion>& focusedMemoryRegions,
const std::vector<ExcludedMemoryRegion>& excludedMemoryRegions, const std::vector<ExcludedMemoryRegion>& excludedMemoryRegions,
@@ -17,7 +19,9 @@ namespace Widgets
QWidget* parent QWidget* parent
) )
: QGraphicsView(parent) : QGraphicsView(parent)
, targetMemoryDescriptor(targetMemoryDescriptor) , addressSpaceDescriptor(addressSpaceDescriptor)
, memorySegmentDescriptor(memorySegmentDescriptor)
, targetState(targetState)
, data(data) , data(data)
, focusedMemoryRegions(focusedMemoryRegions) , focusedMemoryRegions(focusedMemoryRegions)
, excludedMemoryRegions(excludedMemoryRegions) , excludedMemoryRegions(excludedMemoryRegions)
@@ -40,14 +44,16 @@ namespace Widgets
} }
void ItemGraphicsView::initScene() { void ItemGraphicsView::initScene() {
this->scene = new ItemGraphicsScene( this->scene = new ItemGraphicsScene{
this->targetMemoryDescriptor, this->addressSpaceDescriptor,
this->memorySegmentDescriptor,
this->targetState,
this->data, this->data,
this->focusedMemoryRegions, this->focusedMemoryRegions,
this->excludedMemoryRegions, this->excludedMemoryRegions,
this->settings, this->settings,
this this
); };
this->setScene(this->scene); this->setScene(this->scene);

View File

@@ -8,6 +8,10 @@
#include "ItemGraphicsScene.hpp" #include "ItemGraphicsScene.hpp"
#include "src/Targets/TargetMemory.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" #include "src/Insight/UserInterfaces/InsightWindow/Widgets/Label.hpp"
namespace Widgets namespace Widgets
@@ -18,7 +22,9 @@ namespace Widgets
public: public:
ItemGraphicsView( ItemGraphicsView(
const Targets::TargetMemoryDescriptor& targetMemoryDescriptor, const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor,
const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor,
const Targets::TargetState& targetState,
const std::optional<Targets::TargetMemoryBuffer>& data, const std::optional<Targets::TargetMemoryBuffer>& data,
const std::vector<FocusedMemoryRegion>& focusedMemoryRegions, const std::vector<FocusedMemoryRegion>& focusedMemoryRegions,
const std::vector<ExcludedMemoryRegion>& excludedMemoryRegions, const std::vector<ExcludedMemoryRegion>& excludedMemoryRegions,
@@ -38,7 +44,10 @@ namespace Widgets
void sceneReady(); void sceneReady();
protected: protected:
const Targets::TargetMemoryDescriptor& targetMemoryDescriptor; const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor;
const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor;
const Targets::TargetState& targetState;
const std::optional<Targets::TargetMemoryBuffer>& data; const std::optional<Targets::TargetMemoryBuffer>& data;
const std::vector<FocusedMemoryRegion>& focusedMemoryRegions; const std::vector<FocusedMemoryRegion>& focusedMemoryRegions;
const std::vector<ExcludedMemoryRegion>& excludedMemoryRegions; const std::vector<ExcludedMemoryRegion>& excludedMemoryRegions;

View File

@@ -16,7 +16,7 @@ namespace Widgets
, hexViewerState(hexViewerState) , hexViewerState(hexViewerState)
{ {
const auto startAddress = this->startAddress; const auto startAddress = this->startAddress;
const auto endAddress = this->hexViewerState.memoryDescriptor.addressRange.endAddress; const auto endAddress = this->hexViewerState.memorySegmentDescriptor.addressRange.endAddress;
// Sanity check // Sanity check
assert(byteItemsByAddress.contains(startAddress) && byteItemsByAddress.contains(endAddress)); assert(byteItemsByAddress.contains(startAddress) && byteItemsByAddress.contains(endAddress));
@@ -74,10 +74,7 @@ namespace Widgets
updateChildItems(this->items, updateChildItems); updateChildItems(this->items, updateChildItems);
} }
void StackMemoryGroupItem::adjustItemPositions( void StackMemoryGroupItem::adjustItemPositions(int maximumWidth, const HexViewerSharedState* hexViewerState) {
const int maximumWidth,
const HexViewerSharedState* hexViewerState
) {
GroupItem::adjustItemPositions(maximumWidth, hexViewerState); GroupItem::adjustItemPositions(maximumWidth, hexViewerState);
this->groupSize.setWidth(maximumWidth); this->groupSize.setWidth(maximumWidth);
} }
@@ -88,10 +85,7 @@ namespace Widgets
} }
} }
QMargins StackMemoryGroupItem::groupMargins( QMargins StackMemoryGroupItem::groupMargins(const HexViewerSharedState* hexViewerState, int maximumWidth) const {
const HexViewerSharedState* hexViewerState, return {0, 100, 0, 20};
const int maximumWidth
) const {
return QMargins(0, 100, 0, 20);
} }
} }

View File

@@ -26,12 +26,12 @@ namespace Widgets
~StackMemoryGroupItem(); ~StackMemoryGroupItem();
void adjustItemPositions(const int maximumWidth, const HexViewerSharedState* hexViewerState) override; void adjustItemPositions(int maximumWidth, const HexViewerSharedState* hexViewerState) override;
void refreshValues(); void refreshValues();
protected: 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 { bool positionOnNewLine(const int maximumWidth) override {
return true; return true;

View File

@@ -12,8 +12,8 @@ namespace Widgets
, excludedMemoryRegions(excludedMemoryRegions) , excludedMemoryRegions(excludedMemoryRegions)
, hexViewerState(hexViewerState) , hexViewerState(hexViewerState)
{ {
const auto memorySize = this->hexViewerState.memoryDescriptor.size(); const auto memorySize = this->hexViewerState.memorySegmentDescriptor.size();
const auto startAddress = this->hexViewerState.memoryDescriptor.addressRange.startAddress; const auto startAddress = this->hexViewerState.memorySegmentDescriptor.addressRange.startAddress;
for (Targets::TargetMemorySize i = 0; i < memorySize; i++) { for (Targets::TargetMemorySize i = 0; i < memorySize; i++) {
const auto address = startAddress + i; const auto address = startAddress + i;
@@ -29,8 +29,8 @@ namespace Widgets
const auto& currentStackPointer = this->hexViewerState.currentStackPointer; const auto& currentStackPointer = this->hexViewerState.currentStackPointer;
const auto stackGroupingRequired = currentStackPointer.has_value() const auto stackGroupingRequired = currentStackPointer.has_value()
&& this->hexViewerState.settings.groupStackMemory && this->hexViewerState.settings.groupStackMemory
&& *currentStackPointer >= this->hexViewerState.memoryDescriptor.addressRange.startAddress && *currentStackPointer >= this->hexViewerState.memorySegmentDescriptor.addressRange.startAddress
&& (*currentStackPointer + 1) <= this->hexViewerState.memoryDescriptor.addressRange.endAddress; && (*currentStackPointer + 1) <= this->hexViewerState.memorySegmentDescriptor.addressRange.endAddress;
for (const auto& focusedRegion : this->focusedMemoryRegions) { for (const auto& focusedRegion : this->focusedMemoryRegions) {
if ( if (
@@ -48,7 +48,7 @@ namespace Widgets
} }
this->focusedRegionGroupItems.emplace_back(focusedRegion, this->byteItemsByAddress, this); this->focusedRegionGroupItems.emplace_back(focusedRegion, this->byteItemsByAddress, this);
items.emplace_back(&(this->focusedRegionGroupItems.back())); this->items.emplace_back(&(this->focusedRegionGroupItems.back()));
} }
if (stackGroupingRequired) { if (stackGroupingRequired) {

View File

@@ -32,7 +32,7 @@ namespace Widgets
void refreshValues(); void refreshValues();
void adjustItemPositions(const int maximumWidth) { void adjustItemPositions(int maximumWidth) {
GroupItem::adjustItemPositions(maximumWidth, &(this->hexViewerState)); GroupItem::adjustItemPositions(maximumWidth, &(this->hexViewerState));
} }

View File

@@ -1,19 +1,18 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg <svg
xmlns:dc="http://purl.org/dc/elements/1.1/" width="14"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="20"
height="16" height="16"
viewBox="0 0 5.2916667 4.2333333" viewBox="0 0 3.7041667 4.2333333"
version="1.1" version="1.1"
id="svg974" id="svg974"
sodipodi:docname="memory-inspection-icon.svg" sodipodi:docname="memory-inspection-icon.svg"
inkscape:version="1.0.1 (1.0.1+r75)"> 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#">
<defs <defs
id="defs968" /> id="defs968" />
<sodipodi:namedview <sodipodi:namedview
@@ -24,33 +23,29 @@
inkscape:pageopacity="0" inkscape:pageopacity="0"
inkscape:pageshadow="2" inkscape:pageshadow="2"
inkscape:zoom="44.8" inkscape:zoom="44.8"
inkscape:cx="19.284495" inkscape:cx="19.0625"
inkscape:cy="7.1191996" inkscape:cy="7.1205357"
inkscape:document-units="px" inkscape:document-units="px"
inkscape:current-layer="layer2" inkscape:current-layer="layer2"
inkscape:document-rotation="0" inkscape:document-rotation="0"
showgrid="false" showgrid="false"
units="px" units="px"
inkscape:snap-page="true" inkscape:snap-page="true"
inkscape:window-width="2560" inkscape:window-width="3440"
inkscape:window-height="1353" inkscape:window-height="1353"
inkscape:window-x="0" inkscape:window-x="2560"
inkscape:window-y="34" inkscape:window-y="34"
inkscape:window-maximized="1" inkscape:window-maximized="1"
inkscape:snap-smooth-nodes="true" inkscape:snap-smooth-nodes="true"
inkscape:snap-bbox="true" inkscape:snap-bbox="true"
inkscape:snap-bbox-midpoints="true" inkscape:snap-bbox-midpoints="true"
inkscape:snap-bbox-edge-midpoints="true" /> inkscape:snap-bbox-edge-midpoints="true"
inkscape:pagecheckerboard="0" />
<metadata <metadata
id="metadata971"> id="metadata971">
<rdf:RDF> <rdf:RDF>
<cc:Work <cc:Work
rdf:about=""> rdf:about="" />
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF> </rdf:RDF>
</metadata> </metadata>
<g <g
@@ -66,105 +61,105 @@
id="rect1537-3" id="rect1537-3"
width="0.52916664" width="0.52916664"
height="0.5291667" height="0.5291667"
x="1.5874999" x="0.79374993"
y="1.058333" /> y="1.058333" />
<rect <rect
style="fill:#7f7f7e;fill-opacity:1;stroke-width:0.0368284" style="fill:#7f7f7e;fill-opacity:1;stroke-width:0.0368284"
id="rect1537-3-6" id="rect1537-3-6"
width="0.52916664" width="0.52916664"
height="0.5291667" height="0.5291667"
x="0.79374987" x="-1.4002266e-07"
y="1.058333" /> y="1.058333" />
<rect <rect
style="fill:#7f7f7e;fill-opacity:1;stroke-width:0.0368284" style="fill:#7f7f7e;fill-opacity:1;stroke-width:0.0368284"
id="rect1537-3-7" id="rect1537-3-7"
width="0.52916664" width="0.52916664"
height="0.5291667" height="0.5291667"
x="2.3812499" x="1.5875"
y="1.058333" /> y="1.058333" />
<rect <rect
style="fill:#7f7f7e;fill-opacity:1;stroke-width:0.0368284" style="fill:#7f7f7e;fill-opacity:1;stroke-width:0.0368284"
id="rect1537-3-5" id="rect1537-3-5"
width="0.52916664" width="0.52916664"
height="0.5291667" height="0.5291667"
x="1.5875001" x="0.79375017"
y="1.8520831" /> y="1.8520831" />
<rect <rect
style="fill:#7f7f7e;fill-opacity:1;stroke-width:0.0368284" style="fill:#7f7f7e;fill-opacity:1;stroke-width:0.0368284"
id="rect1537-3-5-6" id="rect1537-3-5-6"
width="0.52916664" width="0.52916664"
height="0.5291667" height="0.5291667"
x="2.3812501" x="1.5875002"
y="1.8520831" /> y="1.8520831" />
<rect <rect
style="fill:#7f7f7e;fill-opacity:1;stroke-width:0.0368284" style="fill:#7f7f7e;fill-opacity:1;stroke-width:0.0368284"
id="rect1537-3-5-2" id="rect1537-3-5-2"
width="0.52916664" width="0.52916664"
height="0.5291667" height="0.5291667"
x="0.79374987" x="-1.4002266e-07"
y="1.8520831" /> y="1.8520831" />
<rect <rect
style="fill:#7f7f7e;fill-opacity:1;stroke-width:0.0368284" style="fill:#7f7f7e;fill-opacity:1;stroke-width:0.0368284"
id="rect1537-3-5-9" id="rect1537-3-5-9"
width="0.52916664" width="0.52916664"
height="0.5291667" height="0.5291667"
x="1.5875003" x="0.79375041"
y="2.6458333" /> y="2.6458333" />
<rect <rect
style="fill:#7f7f7e;fill-opacity:1;stroke-width:0.0368284" style="fill:#7f7f7e;fill-opacity:1;stroke-width:0.0368284"
id="rect1537-3-5-6-1" id="rect1537-3-5-6-1"
width="0.52916664" width="0.52916664"
height="0.5291667" height="0.5291667"
x="2.3812501" x="1.5875002"
y="2.6458333" /> y="2.6458333" />
<rect <rect
style="fill:#7f7f7e;fill-opacity:1;stroke-width:0.0368284" style="fill:#7f7f7e;fill-opacity:1;stroke-width:0.0368284"
id="rect1537-3-5-2-2" id="rect1537-3-5-2-2"
width="0.52916664" width="0.52916664"
height="0.5291667" height="0.5291667"
x="0.79374987" x="-1.4002266e-07"
y="2.6458333" /> y="2.6458333" />
<rect <rect
style="fill:#7f7f7e;fill-opacity:1;stroke-width:0.0368284" style="fill:#7f7f7e;fill-opacity:1;stroke-width:0.0368284"
id="rect1537-3-70" id="rect1537-3-70"
width="0.52916664" width="0.52916664"
height="0.5291667" height="0.5291667"
x="3.175" x="2.3812499"
y="1.058333" /> y="1.058333" />
<rect <rect
style="fill:#7f7f7e;fill-opacity:1;stroke-width:0.0368284" style="fill:#7f7f7e;fill-opacity:1;stroke-width:0.0368284"
id="rect1537-3-7-9" id="rect1537-3-7-9"
width="0.52916664" width="0.52916664"
height="0.5291667" height="0.5291667"
x="3.9687502" x="3.1750002"
y="1.058333" /> y="1.058333" />
<rect <rect
style="fill:#7f7f7e;fill-opacity:1;stroke-width:0.0368284" style="fill:#7f7f7e;fill-opacity:1;stroke-width:0.0368284"
id="rect1537-3-5-3" id="rect1537-3-5-3"
width="0.52916664" width="0.52916664"
height="0.5291667" height="0.5291667"
x="3.1750002" x="2.3812501"
y="1.8520831" /> y="1.8520831" />
<rect <rect
style="fill:#7f7f7e;fill-opacity:1;stroke-width:0.0368284" style="fill:#7f7f7e;fill-opacity:1;stroke-width:0.0368284"
id="rect1537-3-5-6-6" id="rect1537-3-5-6-6"
width="0.52916664" width="0.52916664"
height="0.5291667" height="0.5291667"
x="3.9687502" x="3.1750002"
y="1.8520831" /> y="1.8520831" />
<rect <rect
style="fill:#7f7f7e;fill-opacity:1;stroke-width:0.0368284" style="fill:#7f7f7e;fill-opacity:1;stroke-width:0.0368284"
id="rect1537-3-5-9-0" id="rect1537-3-5-9-0"
width="0.52916664" width="0.52916664"
height="0.5291667" height="0.5291667"
x="3.1750004" x="2.3812504"
y="2.6458335" /> y="2.6458335" />
<rect <rect
style="fill:#7f7f7e;fill-opacity:1;stroke-width:0.0368284" style="fill:#7f7f7e;fill-opacity:1;stroke-width:0.0368284"
id="rect1537-3-5-6-1-6" id="rect1537-3-5-6-1-6"
width="0.52916664" width="0.52916664"
height="0.5291667" height="0.5291667"
x="3.9687502" x="3.1750002"
y="2.6458335" /> y="2.6458335" />
</g> </g>
</svg> </svg>

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB

View File

@@ -5,12 +5,10 @@
MemoryRegion::MemoryRegion( MemoryRegion::MemoryRegion(
const QString& name, const QString& name,
Targets::TargetMemoryType memoryType,
MemoryRegionType type, MemoryRegionType type,
const Targets::TargetMemoryAddressRange& addressRange const Targets::TargetMemoryAddressRange& addressRange
) )
: name(name) : name(name)
, memoryType(memoryType)
, type(type) , type(type)
, addressRange(addressRange) , addressRange(addressRange)
{} {}
@@ -20,45 +18,38 @@ MemoryRegion::MemoryRegion(const QJsonObject& jsonObject) {
if ( if (
!jsonObject.contains("name") !jsonObject.contains("name")
|| !jsonObject.contains("memoryType")
|| !jsonObject.contains("type") || !jsonObject.contains("type")
|| !jsonObject.contains("createdTimestamp") || !jsonObject.contains("createdTimestamp")
|| !jsonObject.contains("addressInputType") || !jsonObject.contains("addressInputType")
|| !jsonObject.contains("addressRange") || !jsonObject.contains("addressRange")
) { ) {
throw Exception("Missing data"); throw Exception{"Missing data"};
} }
const auto addressRangeObj = jsonObject.find("addressRange")->toObject(); const auto addressRangeObj = jsonObject.find("addressRange")->toObject();
if ( if (!addressRangeObj.contains("startAddress") || !addressRangeObj.contains("endAddress")) {
!addressRangeObj.contains("startAddress") throw Exception{"Missing address range data"};
|| !addressRangeObj.contains("endAddress")
) {
throw Exception("Missing address range data");
} }
this->name = jsonObject.find("name")->toString(); 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->type = MemoryRegion::memoryRegionTypesByName.at(jsonObject.find("type")->toString());
this->createdDate.setSecsSinceEpoch(jsonObject.find("createdTimestamp")->toInteger()); this->createdDate.setSecsSinceEpoch(jsonObject.find("createdTimestamp")->toInteger());
this->addressRangeInputType = MemoryRegion::addressTypesByName.at(jsonObject.find("addressInputType")->toString()); this->addressRangeInputType = MemoryRegion::addressTypesByName.at(jsonObject.find("addressInputType")->toString());
this->addressRange = { this->addressRange = {
static_cast<std::uint32_t>(addressRangeObj.find("startAddress")->toInteger()), static_cast<Targets::TargetMemoryAddress>(addressRangeObj.find("startAddress")->toInteger()),
static_cast<std::uint32_t>(addressRangeObj.find("endAddress")->toInteger()), static_cast<Targets::TargetMemoryAddress>(addressRangeObj.find("endAddress")->toInteger()),
}; };
} }
QJsonObject MemoryRegion::toJson() const { QJsonObject MemoryRegion::toJson() const {
return QJsonObject({ return {
{"name", this->name}, {"name", this->name},
{"memoryType", EnumToStringMappings::targetMemoryTypes.at(this->memoryType)},
{"type", MemoryRegion::memoryRegionTypesByName.at(this->type)}, {"type", MemoryRegion::memoryRegionTypesByName.at(this->type)},
{"createdTimestamp", this->createdDate.toSecsSinceEpoch()}, {"createdTimestamp", this->createdDate.toSecsSinceEpoch()},
{"addressInputType", MemoryRegion::addressTypesByName.at(this->addressRangeInputType)}, {"addressInputType", MemoryRegion::addressTypesByName.at(this->addressRangeInputType)},
{"addressRange", QJsonObject({ {"addressRange", QJsonObject{
{"startAddress", static_cast<qint64>(this->addressRange.startAddress)}, {"startAddress", static_cast<qint64>(this->addressRange.startAddress)},
{"endAddress", static_cast<qint64>(this->addressRange.endAddress)}, {"endAddress", static_cast<qint64>(this->addressRange.endAddress)},
})}, }},
}); };
} }

View File

@@ -30,7 +30,6 @@ class MemoryRegion
public: public:
QString name; QString name;
QDateTime createdDate = Services::DateTimeService::currentDateTime(); QDateTime createdDate = Services::DateTimeService::currentDateTime();
Targets::TargetMemoryType memoryType;
MemoryRegionType type; MemoryRegionType type;
/** /**
@@ -54,12 +53,11 @@ public:
MemoryRegion( MemoryRegion(
const QString& name, const QString& name,
Targets::TargetMemoryType memoryType,
MemoryRegionType type, MemoryRegionType type,
const Targets::TargetMemoryAddressRange& addressRange const Targets::TargetMemoryAddressRange& addressRange
); );
MemoryRegion(const QJsonObject& jsonObject); explicit MemoryRegion(const QJsonObject& jsonObject);
virtual QJsonObject toJson() const; virtual QJsonObject toJson() const;

View File

@@ -10,41 +10,39 @@ namespace Widgets
{ {
ExcludedRegionItem::ExcludedRegionItem( ExcludedRegionItem::ExcludedRegionItem(
const ExcludedMemoryRegion& region, const ExcludedMemoryRegion& region,
const Targets::TargetMemoryDescriptor& memoryDescriptor, const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor,
QWidget* parent QWidget* parent
) )
: RegionItem(region, memoryDescriptor, parent) : RegionItem(region, memorySegmentDescriptor, parent)
, memoryRegion(region) , memoryRegion(region)
{ {
auto formUiFile = QFile( auto formUiFile = QFile{
QString::fromStdString(Services::PathService::compiledResourcesPath() QString::fromStdString(Services::PathService::compiledResourcesPath()
+ "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane" + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane"
+ "/MemoryRegionManager/UiFiles/ExcludedMemoryRegionForm.ui" + "/MemoryRegionManager/UiFiles/ExcludedMemoryRegionForm.ui"
) )
); };
if (!formUiFile.open(QFile::ReadOnly)) { 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->formWidget = uiLoader.load(&formUiFile, this);
this->initFormInputs(); this->initFormInputs();
} }
void ExcludedRegionItem::applyChanges() { void ExcludedRegionItem::applyChanges() {
using Targets::TargetMemoryAddressRange;
this->memoryRegion.name = this->nameInput->text(); this->memoryRegion.name = this->nameInput->text();
const auto inputAddressRange = TargetMemoryAddressRange( const auto inputAddressRange = Targets::TargetMemoryAddressRange{
this->startAddressInput->text().toUInt(nullptr, 16), this->startAddressInput->text().toUInt(nullptr, 16),
this->endAddressInput->text().toUInt(nullptr, 16) this->endAddressInput->text().toUInt(nullptr, 16)
); };
this->memoryRegion.addressRangeInputType = this->getSelectedAddressInputType(); this->memoryRegion.addressRangeInputType = this->getSelectedAddressInputType();
this->memoryRegion.addressRange = this->memoryRegion.addressRange = this->memoryRegion.addressRangeInputType == AddressType::RELATIVE
this->memoryRegion.addressRangeInputType == AddressType::RELATIVE ? ? this->convertRelativeToAbsoluteAddressRange(inputAddressRange)
this->convertRelativeToAbsoluteAddressRange(inputAddressRange) : inputAddressRange; : inputAddressRange;
} }
} }

View File

@@ -12,7 +12,7 @@ namespace Widgets
public: public:
ExcludedRegionItem( ExcludedRegionItem(
const ExcludedMemoryRegion& region, const ExcludedMemoryRegion& region,
const Targets::TargetMemoryDescriptor& memoryDescriptor, const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor,
QWidget *parent QWidget *parent
); );

View File

@@ -12,24 +12,24 @@ namespace Widgets
FocusedRegionItem::FocusedRegionItem( FocusedRegionItem::FocusedRegionItem(
const FocusedMemoryRegion& region, const FocusedMemoryRegion& region,
const Targets::TargetMemoryDescriptor& memoryDescriptor, const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor,
QWidget* parent QWidget* parent
) )
: RegionItem(region, memoryDescriptor, parent) : RegionItem(region, memorySegmentDescriptor, parent)
, memoryRegion(region) , memoryRegion(region)
{ {
auto formUiFile = QFile( auto formUiFile = QFile{
QString::fromStdString(Services::PathService::compiledResourcesPath() QString::fromStdString(Services::PathService::compiledResourcesPath()
+ "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane" + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane"
+ "/MemoryRegionManager/UiFiles/FocusedMemoryRegionForm.ui" + "/MemoryRegionManager/UiFiles/FocusedMemoryRegionForm.ui"
) )
); };
if (!formUiFile.open(QFile::ReadOnly)) { 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->formWidget = uiLoader.load(&formUiFile, this);
this->initFormInputs(); this->initFormInputs();
@@ -38,10 +38,10 @@ namespace Widgets
void FocusedRegionItem::applyChanges() { void FocusedRegionItem::applyChanges() {
this->memoryRegion.name = this->nameInput->text(); this->memoryRegion.name = this->nameInput->text();
const auto inputAddressRange = TargetMemoryAddressRange( const auto inputAddressRange = Targets::TargetMemoryAddressRange{
this->startAddressInput->text().toUInt(nullptr, 16), this->startAddressInput->text().toUInt(nullptr, 16),
this->endAddressInput->text().toUInt(nullptr, 16) this->endAddressInput->text().toUInt(nullptr, 16)
); };
this->memoryRegion.addressRangeInputType = this->getSelectedAddressInputType(); this->memoryRegion.addressRangeInputType = this->getSelectedAddressInputType();
this->memoryRegion.addressRange = this->memoryRegion.addressRangeInputType == AddressType::RELATIVE this->memoryRegion.addressRange = this->memoryRegion.addressRangeInputType == AddressType::RELATIVE
? this->convertRelativeToAbsoluteAddressRange(inputAddressRange) ? this->convertRelativeToAbsoluteAddressRange(inputAddressRange)

View File

@@ -34,7 +34,7 @@ namespace Widgets
public: public:
FocusedRegionItem( FocusedRegionItem(
const FocusedMemoryRegion& region, const FocusedMemoryRegion& region,
const Targets::TargetMemoryDescriptor& memoryDescriptor, const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor,
QWidget *parent QWidget *parent
); );
@@ -52,20 +52,16 @@ namespace Widgets
QComboBox* dataTypeInput = nullptr; QComboBox* dataTypeInput = nullptr;
QComboBox* endiannessInput = nullptr; QComboBox* endiannessInput = nullptr;
static const inline std::map<QString, DataTypeOption> dataTypeOptionsByName = std::map< static const inline std::map<QString, DataTypeOption> dataTypeOptionsByName = {
QString, DataTypeOption {"other", DataTypeOption{"Other", MemoryRegionDataType::UNKNOWN}},
>({ {"unsigned_integer", DataTypeOption{"Unsigned Integer", MemoryRegionDataType::UNSIGNED_INTEGER}},
{"other", DataTypeOption("Other", MemoryRegionDataType::UNKNOWN)}, {"signed_integer", DataTypeOption{"Signed Integer", MemoryRegionDataType::SIGNED_INTEGER}},
{"unsigned_integer", DataTypeOption("Unsigned Integer", MemoryRegionDataType::UNSIGNED_INTEGER)}, {"ascii", DataTypeOption{"ASCII String", MemoryRegionDataType::ASCII_STRING}},
{"signed_integer", DataTypeOption("Signed Integer", MemoryRegionDataType::SIGNED_INTEGER)}, };
{"ascii", DataTypeOption("ASCII String", MemoryRegionDataType::ASCII_STRING)},
});
static const inline std::map<QString, EndiannessOption> endiannessOptionsByName = std::map< static const inline std::map<QString, EndiannessOption> endiannessOptionsByName = {
QString, EndiannessOption {"little", EndiannessOption{"Little-endian", Targets::TargetMemoryEndianness::LITTLE}},
>({ {"big", EndiannessOption{"Big-endian", Targets::TargetMemoryEndianness::BIG}},
{"little", EndiannessOption("Little-endian", Targets::TargetMemoryEndianness::LITTLE)}, };
{"big", EndiannessOption("Big-endian", Targets::TargetMemoryEndianness::BIG)},
});
}; };
} }

View File

@@ -16,48 +16,50 @@ namespace Widgets
using Exceptions::Exception; using Exceptions::Exception;
MemoryRegionManagerWindow::MemoryRegionManagerWindow( MemoryRegionManagerWindow::MemoryRegionManagerWindow(
const Targets::TargetMemoryDescriptor& memoryDescriptor, const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor,
const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor,
std::vector<FocusedMemoryRegion>& focusedMemoryRegions, std::vector<FocusedMemoryRegion>& focusedMemoryRegions,
std::vector<ExcludedMemoryRegion>& excludedMemoryRegions, std::vector<ExcludedMemoryRegion>& excludedMemoryRegions,
QWidget* parent QWidget* parent
) )
: QWidget(parent) : QWidget(parent)
, memoryDescriptor(memoryDescriptor) , addressSpaceDescriptor(addressSpaceDescriptor)
, memorySegmentDescriptor(memorySegmentDescriptor)
, focusedMemoryRegions(focusedMemoryRegions) , focusedMemoryRegions(focusedMemoryRegions)
, excludedMemoryRegions(excludedMemoryRegions) , excludedMemoryRegions(excludedMemoryRegions)
{ {
this->setWindowFlag(Qt::Window); this->setWindowFlag(Qt::Window);
this->setObjectName("memory-region-manager-window"); this->setObjectName("memory-region-manager-window");
this->setWindowTitle( 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() QString::fromStdString(Services::PathService::compiledResourcesPath()
+ "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane" + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane"
+ "/MemoryRegionManager/UiFiles/MemoryRegionManagerWindow.ui" + "/MemoryRegionManager/UiFiles/MemoryRegionManagerWindow.ui"
) )
); };
auto windowStylesheet = QFile( auto windowStylesheet = QFile{
QString::fromStdString(Services::PathService::compiledResourcesPath() QString::fromStdString(Services::PathService::compiledResourcesPath()
+ "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane" + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane"
+ "/MemoryRegionManager/Stylesheets/MemoryRegionManagerWindow.qss" + "/MemoryRegionManager/Stylesheets/MemoryRegionManagerWindow.qss"
) )
); };
if (!windowUiFile.open(QFile::ReadOnly)) { 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)) { 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->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 = uiLoader.load(&windowUiFile, this);
this->container->setFixedSize(this->size()); this->container->setFixedSize(this->size());
@@ -210,11 +212,11 @@ namespace Widgets
} }
FocusedRegionItem* MemoryRegionManagerWindow::addFocusedRegion(const FocusedMemoryRegion& region) { FocusedRegionItem* MemoryRegionManagerWindow::addFocusedRegion(const FocusedMemoryRegion& region) {
auto* focusedRegionItem = new FocusedRegionItem( auto* focusedRegionItem = new FocusedRegionItem{
region, region,
this->memoryDescriptor, this->memorySegmentDescriptor,
this->regionItemScrollAreaViewport this->regionItemScrollAreaViewport
); };
this->focusedRegionItems.insert(focusedRegionItem); this->focusedRegionItems.insert(focusedRegionItem);
this->regionItemScrollAreaViewportLayout->addWidget(focusedRegionItem); this->regionItemScrollAreaViewportLayout->addWidget(focusedRegionItem);
@@ -231,11 +233,11 @@ namespace Widgets
} }
ExcludedRegionItem* MemoryRegionManagerWindow::addExcludedRegion(const ExcludedMemoryRegion& region) { ExcludedRegionItem* MemoryRegionManagerWindow::addExcludedRegion(const ExcludedMemoryRegion& region) {
auto* excludedRegionItem = new ExcludedRegionItem( auto* excludedRegionItem = new ExcludedRegionItem{
region, region,
this->memoryDescriptor, this->memorySegmentDescriptor,
this->regionItemScrollAreaViewport this->regionItemScrollAreaViewport
); };
this->excludedRegionItems.insert(excludedRegionItem); this->excludedRegionItems.insert(excludedRegionItem);
this->regionItemScrollAreaViewportLayout->addWidget(excludedRegionItem); this->regionItemScrollAreaViewportLayout->addWidget(excludedRegionItem);
@@ -263,14 +265,15 @@ namespace Widgets
void MemoryRegionManagerWindow::onNewFocusedRegionTrigger() { void MemoryRegionManagerWindow::onNewFocusedRegionTrigger() {
using Targets::TargetMemoryAddressRange; using Targets::TargetMemoryAddressRange;
auto* region = this->addFocusedRegion(FocusedMemoryRegion( auto* region = this->addFocusedRegion(
"Untitled Region", FocusedMemoryRegion{
this->memoryDescriptor.type, "Untitled Region",
TargetMemoryAddressRange( TargetMemoryAddressRange{
this->memoryDescriptor.addressRange.startAddress, this->memorySegmentDescriptor.addressRange.startAddress,
this->memoryDescriptor.addressRange.startAddress + 10 this->memorySegmentDescriptor.addressRange.startAddress + 10
) }
)); }
);
region->setSelected(true); region->setSelected(true);
} }
@@ -278,14 +281,15 @@ namespace Widgets
void MemoryRegionManagerWindow::onNewExcludedRegionTrigger() { void MemoryRegionManagerWindow::onNewExcludedRegionTrigger() {
using Targets::TargetMemoryAddressRange; using Targets::TargetMemoryAddressRange;
auto* region = this->addExcludedRegion(ExcludedMemoryRegion( auto* region = this->addExcludedRegion(
"Untitled Region", ExcludedMemoryRegion{
this->memoryDescriptor.type, "Untitled Region",
TargetMemoryAddressRange( TargetMemoryAddressRange{
this->memoryDescriptor.addressRange.startAddress, this->memorySegmentDescriptor.addressRange.startAddress,
this->memoryDescriptor.addressRange.startAddress + 10 this->memorySegmentDescriptor.addressRange.startAddress + 10
) }
)); }
);
region->setSelected(true); region->setSelected(true);
} }
@@ -331,19 +335,19 @@ namespace Widgets
} }
void MemoryRegionManagerWindow::applyChanges() { void MemoryRegionManagerWindow::applyChanges() {
auto processedFocusedMemoryRegions = std::vector<FocusedMemoryRegion>(); auto processedFocusedMemoryRegions = std::vector<FocusedMemoryRegion>{};
auto processedExcludedMemoryRegions = std::vector<ExcludedMemoryRegion>(); auto processedExcludedMemoryRegions = std::vector<ExcludedMemoryRegion>{};
for (auto* focusedRegionItem : this->focusedRegionItems) { for (auto* focusedRegionItem : this->focusedRegionItems) {
const auto validationFailures = focusedRegionItem->getValidationFailures(); const auto validationFailures = focusedRegionItem->getValidationFailures();
if (!validationFailures.empty()) { if (!validationFailures.empty()) {
auto* errorDialogue = new ErrorDialogue( auto* errorDialogue = new ErrorDialogue{
"Invalid Memory Region", "Invalid Memory Region",
"Invalid memory region \"" + focusedRegionItem->getRegionNameInputValue() + "\"" "Invalid memory region \"" + focusedRegionItem->getRegionNameInputValue() + "\""
+ "\n\n- " + validationFailures.join("\n- "), + "\n\n- " + validationFailures.join("\n- "),
this this
); };
errorDialogue->show(); errorDialogue->show();
return; return;
} }
@@ -352,13 +356,13 @@ namespace Widgets
const auto& focusedRegion = focusedRegionItem->getMemoryRegion(); const auto& focusedRegion = focusedRegionItem->getMemoryRegion();
for (const auto& processedFocusedRegion : processedFocusedMemoryRegions) { for (const auto& processedFocusedRegion : processedFocusedMemoryRegions) {
if (processedFocusedRegion.intersectsWith(focusedRegion)) { if (processedFocusedRegion.intersectsWith(focusedRegion)) {
auto* errorDialogue = new ErrorDialogue( auto* errorDialogue = new ErrorDialogue{
"Intersecting Region Found", "Intersecting Region Found",
"Region \"" + focusedRegionItem->getRegionNameInputValue() "Region \"" + focusedRegionItem->getRegionNameInputValue()
+ "\" intersects with region \"" + processedFocusedRegion.name + "\". " + "\" intersects with region \"" + processedFocusedRegion.name + "\". "
+ "Regions cannot intersect. Please review the relevant address ranges.", + "Regions cannot intersect. Please review the relevant address ranges.",
this this
); };
errorDialogue->show(); errorDialogue->show();
return; return;
} }
@@ -371,12 +375,12 @@ namespace Widgets
const auto validationFailures = excludedRegionItem->getValidationFailures(); const auto validationFailures = excludedRegionItem->getValidationFailures();
if (!validationFailures.empty()) { if (!validationFailures.empty()) {
auto* errorDialogue = new ErrorDialogue( auto* errorDialogue = new ErrorDialogue{
"Invalid Memory Region", "Invalid Memory Region",
"Invalid memory region \"" + excludedRegionItem->getRegionNameInputValue() + "\"" "Invalid memory region \"" + excludedRegionItem->getRegionNameInputValue() + "\""
+ "<br/><br/>- " + validationFailures.join("<br/>- "), + "<br/><br/>- " + validationFailures.join("<br/>- "),
this this
); };
errorDialogue->show(); errorDialogue->show();
return; return;
} }
@@ -385,13 +389,13 @@ namespace Widgets
auto excludedRegion = excludedRegionItem->getMemoryRegion(); auto excludedRegion = excludedRegionItem->getMemoryRegion();
for (const auto& processedFocusedRegion : processedFocusedMemoryRegions) { for (const auto& processedFocusedRegion : processedFocusedMemoryRegions) {
if (processedFocusedRegion.intersectsWith(excludedRegion)) { if (processedFocusedRegion.intersectsWith(excludedRegion)) {
auto* errorDialogue = new ErrorDialogue( auto* errorDialogue = new ErrorDialogue{
"Intersecting Region Found", "Intersecting Region Found",
"Region \"" + excludedRegionItem->getRegionNameInputValue() "Region \"" + excludedRegionItem->getRegionNameInputValue()
+ "\" intersects with region \"" + processedFocusedRegion.name + "\". " + "\" intersects with region \"" + processedFocusedRegion.name + "\". "
+ "Regions cannot intersect. Please review the relevant address ranges.", + "Regions cannot intersect. Please review the relevant address ranges.",
this this
); };
errorDialogue->show(); errorDialogue->show();
return; return;
} }
@@ -399,13 +403,13 @@ namespace Widgets
for (const auto& processedExcludedRegion : processedExcludedMemoryRegions) { for (const auto& processedExcludedRegion : processedExcludedMemoryRegions) {
if (processedExcludedRegion.intersectsWith(excludedRegion)) { if (processedExcludedRegion.intersectsWith(excludedRegion)) {
auto* errorDialogue = new ErrorDialogue( auto* errorDialogue = new ErrorDialogue{
"Intersecting Region Found", "Intersecting Region Found",
"Region \"" + excludedRegionItem->getRegionNameInputValue() "Region \"" + excludedRegionItem->getRegionNameInputValue()
+ "\" intersects with region \"" + processedExcludedRegion.name + "\". " + "\" intersects with region \"" + processedExcludedRegion.name + "\". "
+ "Regions cannot intersect. Please review the relevant address ranges.", + "Regions cannot intersect. Please review the relevant address ranges.",
this this
); };
errorDialogue->show(); errorDialogue->show();
return; return;
} }
@@ -422,7 +426,7 @@ namespace Widgets
void MemoryRegionManagerWindow::openHelpPage() { void MemoryRegionManagerWindow::openHelpPage() {
QDesktopServices::openUrl( QDesktopServices::openUrl(
QUrl(QString::fromStdString(Services::PathService::homeDomainName() + "/docs/manage-memory-regions")) QUrl{QString::fromStdString(Services::PathService::homeDomainName() + "/docs/manage-memory-regions")}
); );
} }
} }

Some files were not shown because too many files have changed in this diff Show More