Constructing Insight settings from project settings json
This commit is contained in:
@@ -25,7 +25,6 @@ namespace Bloom
|
|||||||
class MemoryRegion
|
class MemoryRegion
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::size_t id = MemoryRegion::lastId++;
|
|
||||||
QString name;
|
QString name;
|
||||||
QDateTime createdDate = DateTime::currentDateTime();
|
QDateTime createdDate = DateTime::currentDateTime();
|
||||||
MemoryRegionType type;
|
MemoryRegionType type;
|
||||||
@@ -63,19 +62,8 @@ namespace Bloom
|
|||||||
MemoryRegion& operator = (const MemoryRegion& other) = default;
|
MemoryRegion& operator = (const MemoryRegion& other) = default;
|
||||||
MemoryRegion& operator = (MemoryRegion&& other) = default;
|
MemoryRegion& operator = (MemoryRegion&& other) = default;
|
||||||
|
|
||||||
bool operator == (const MemoryRegion& other) const {
|
|
||||||
return this->id == other.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator != (const MemoryRegion& other) const {
|
|
||||||
return !(*this == other);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] bool intersectsWith(const MemoryRegion& other) const {
|
[[nodiscard]] bool intersectsWith(const MemoryRegion& other) const {
|
||||||
return this->addressRange.intersectsWith(other.addressRange);
|
return this->addressRange.intersectsWith(other.addressRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
static inline std::atomic<std::size_t> lastId = 0;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ void MemoryRegionManagerWindow::sortRegionItems() {
|
|||||||
* layout, and then re-inserting them in the correct order.
|
* layout, and then re-inserting them in the correct order.
|
||||||
*/
|
*/
|
||||||
auto regionItemCompare = [] (RegionItem* itemA, RegionItem* itemB) {
|
auto regionItemCompare = [] (RegionItem* itemA, RegionItem* itemB) {
|
||||||
return itemA->getMemoryRegion().id < itemB->getMemoryRegion().id;
|
return itemA->getMemoryRegion().createdDate < itemB->getMemoryRegion().createdDate;
|
||||||
};
|
};
|
||||||
auto sortedRegionItems = std::set<RegionItem*, decltype(regionItemCompare)>(regionItemCompare);
|
auto sortedRegionItems = std::set<RegionItem*, decltype(regionItemCompare)>(regionItemCompare);
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,262 @@
|
|||||||
#include "ProjectSettings.hpp"
|
#include "ProjectSettings.hpp"
|
||||||
|
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
#include "src/Logger/Logger.hpp"
|
#include "src/Logger/Logger.hpp"
|
||||||
|
|
||||||
using namespace Bloom;
|
using namespace Bloom;
|
||||||
|
|
||||||
ProjectSettings::ProjectSettings(const QJsonObject& jsonObject) {
|
ProjectSettings::ProjectSettings(const QJsonObject& jsonObject) {
|
||||||
|
if (jsonObject.contains("insight")) {
|
||||||
|
this->insightSettings = InsightProjectSettings(jsonObject.find("insight")->toObject());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject ProjectSettings::toJson() const {
|
||||||
|
auto projectSettingsObj = QJsonObject();
|
||||||
|
|
||||||
|
projectSettingsObj.insert("insight", this->insightSettings.toJson());
|
||||||
|
|
||||||
|
return projectSettingsObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
InsightProjectSettings::InsightProjectSettings(const QJsonObject& jsonObject) {
|
||||||
|
if (jsonObject.contains("mainWindowSize")) {
|
||||||
|
const auto mainWindowSizeObj = jsonObject.find("mainWindowSize")->toObject();
|
||||||
|
|
||||||
|
if (mainWindowSizeObj.contains("width") && mainWindowSizeObj.contains("height")) {
|
||||||
|
this->mainWindowSize = QSize(
|
||||||
|
mainWindowSizeObj.find("width")->toInt(),
|
||||||
|
mainWindowSizeObj.find("height")->toInt()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (jsonObject.contains("memoryInspectionPaneSettings")) {
|
||||||
|
const auto settingsMappingObj = jsonObject.find("memoryInspectionPaneSettings")->toObject();
|
||||||
|
|
||||||
|
for (auto settingsIt = settingsMappingObj.begin(); settingsIt != settingsMappingObj.end(); settingsIt++) {
|
||||||
|
const auto settingsObj = settingsIt.value().toObject();
|
||||||
|
const auto memoryTypeName = settingsIt.key();
|
||||||
|
|
||||||
|
if (!InsightProjectSettings::memoryTypesByName.contains(memoryTypeName)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto memoryType = InsightProjectSettings::memoryTypesByName.at(memoryTypeName);
|
||||||
|
auto inspectionPaneSettings = Widgets::TargetMemoryInspectionPaneSettings();
|
||||||
|
|
||||||
|
if (settingsObj.contains("hexViewerSettings")) {
|
||||||
|
auto& hexViewerSettings = inspectionPaneSettings.hexViewerWidgetSettings;
|
||||||
|
const auto hexViewerSettingsObj = settingsObj.find("hexViewerSettings")->toObject();
|
||||||
|
|
||||||
|
if (hexViewerSettingsObj.contains("highlightStackMemory")) {
|
||||||
|
hexViewerSettings.highlightStackMemory =
|
||||||
|
hexViewerSettingsObj.value("highlightStackMemory").toBool();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hexViewerSettingsObj.contains("highlightFocusedMemory")) {
|
||||||
|
hexViewerSettings.highlightFocusedMemory =
|
||||||
|
hexViewerSettingsObj.value("highlightFocusedMemory").toBool();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hexViewerSettingsObj.contains("highlightHoveredRowAndCol")) {
|
||||||
|
hexViewerSettings.highlightHoveredRowAndCol =
|
||||||
|
hexViewerSettingsObj.value("highlightHoveredRowAndCol").toBool();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hexViewerSettingsObj.contains("displayAsciiValues")) {
|
||||||
|
hexViewerSettings.displayAsciiValues =
|
||||||
|
hexViewerSettingsObj.value("displayAsciiValues").toBool();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hexViewerSettingsObj.contains("displayAnnotations")) {
|
||||||
|
hexViewerSettings.displayAnnotations =
|
||||||
|
hexViewerSettingsObj.value("displayAnnotations").toBool();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settingsObj.contains("focusedRegions")) {
|
||||||
|
const auto focusedRegions = settingsObj.find("focusedRegions")->toArray();
|
||||||
|
|
||||||
|
for (const auto& regionValue : focusedRegions) {
|
||||||
|
const auto regionObj = regionValue.toObject();
|
||||||
|
|
||||||
|
if (!regionObj.contains("name")
|
||||||
|
|| !regionObj.contains("addressRange")
|
||||||
|
|| !regionObj.contains("addressInputType")
|
||||||
|
|| !regionObj.contains("createdTimestamp")
|
||||||
|
|| !regionObj.contains("dataType")
|
||||||
|
) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto addressRangeObj = regionObj.find("addressRange")->toObject();
|
||||||
|
if (!addressRangeObj.contains("startAddress") || !addressRangeObj.contains("endAddress")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto region = FocusedMemoryRegion(
|
||||||
|
regionObj.find("name")->toString(),
|
||||||
|
{
|
||||||
|
static_cast<std::uint32_t>(addressRangeObj.find("startAddress")->toInteger()),
|
||||||
|
static_cast<std::uint32_t>(addressRangeObj.find("endAddress")->toInteger()),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
region.createdDate.setSecsSinceEpoch(regionObj.find("createdTimestamp")->toInteger());
|
||||||
|
|
||||||
|
const auto addressInputType = InsightProjectSettings::addressRangeInputTypesByName.valueAt(
|
||||||
|
regionObj.find("addressInputType")->toString()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (addressInputType.has_value()) {
|
||||||
|
region.addressRangeInputType = addressInputType.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto dataType = InsightProjectSettings::regionDataTypesByName.valueAt(
|
||||||
|
regionObj.find("dataType")->toString()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (dataType.has_value()) {
|
||||||
|
region.dataType = dataType.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
inspectionPaneSettings.focusedMemoryRegions.emplace_back(region);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settingsObj.contains("excludedRegions")) {
|
||||||
|
const auto excludedRegions = settingsObj.find("excludedRegions")->toArray();
|
||||||
|
|
||||||
|
for (const auto& regionValue : excludedRegions) {
|
||||||
|
const auto regionObj = regionValue.toObject();
|
||||||
|
|
||||||
|
if (!regionObj.contains("name")
|
||||||
|
|| !regionObj.contains("addressRange")
|
||||||
|
|| !regionObj.contains("addressInputType")
|
||||||
|
|| !regionObj.contains("createdTimestamp")
|
||||||
|
) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto addressRangeObj = regionObj.find("addressRange")->toObject();
|
||||||
|
if (!addressRangeObj.contains("startAddress") || !addressRangeObj.contains("endAddress")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto region = ExcludedMemoryRegion(
|
||||||
|
regionObj.find("name")->toString(),
|
||||||
|
{
|
||||||
|
static_cast<std::uint32_t>(addressRangeObj.find("startAddress")->toInteger()),
|
||||||
|
static_cast<std::uint32_t>(addressRangeObj.find("endAddress")->toInteger()),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
region.createdDate.setSecsSinceEpoch(regionObj.find("createdTimestamp")->toInteger());
|
||||||
|
|
||||||
|
const auto addressInputType = InsightProjectSettings::addressRangeInputTypesByName.valueAt(
|
||||||
|
regionObj.find("addressInputType")->toString()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (addressInputType.has_value()) {
|
||||||
|
region.addressRangeInputType = addressInputType.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
inspectionPaneSettings.excludedMemoryRegions.emplace_back(region);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this->memoryInspectionPaneSettingsByMemoryType.insert(std::pair(memoryType, inspectionPaneSettings));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject InsightProjectSettings::toJson() const {
|
||||||
|
auto insightObj = QJsonObject();
|
||||||
|
|
||||||
|
if (this->mainWindowSize.has_value()) {
|
||||||
|
insightObj.insert("mainWindowSize", QJsonObject({
|
||||||
|
{"width", this->mainWindowSize->width()},
|
||||||
|
{"height", this->mainWindowSize->height()},
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
auto memoryInspectionPaneSettingsObj = QJsonObject();
|
||||||
|
|
||||||
|
for (const auto& [memoryType, inspectionPaneSettings] : this->memoryInspectionPaneSettingsByMemoryType) {
|
||||||
|
if (!InsightProjectSettings::memoryTypesByName.contains(memoryType)) {
|
||||||
|
// This is just a precaution - all known memory types should be in the mapping.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto settingsObj = QJsonObject();
|
||||||
|
|
||||||
|
const auto& hexViewerSettings = inspectionPaneSettings.hexViewerWidgetSettings;
|
||||||
|
settingsObj.insert("hexViewerSettings", QJsonObject({
|
||||||
|
{"highlightStackMemory", hexViewerSettings.highlightStackMemory},
|
||||||
|
{"highlightFocusedMemory", hexViewerSettings.highlightFocusedMemory},
|
||||||
|
{"highlightHoveredRowAndCol", hexViewerSettings.highlightHoveredRowAndCol},
|
||||||
|
{"displayAsciiValues", hexViewerSettings.displayAsciiValues},
|
||||||
|
{"displayAnnotations", hexViewerSettings.displayAnnotations},
|
||||||
|
}));
|
||||||
|
|
||||||
|
const auto& regionDataTypesByName = InsightProjectSettings::regionDataTypesByName;
|
||||||
|
const auto& addressRangeInputTypesByName = InsightProjectSettings::addressRangeInputTypesByName;
|
||||||
|
|
||||||
|
auto focusedRegions = QJsonArray();
|
||||||
|
for (const auto& focusedRegion : inspectionPaneSettings.focusedMemoryRegions) {
|
||||||
|
if (!regionDataTypesByName.contains(focusedRegion.dataType)
|
||||||
|
|| !addressRangeInputTypesByName.contains(focusedRegion.addressRangeInputType)
|
||||||
|
) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto addressRangeObj = QJsonObject({
|
||||||
|
{"startAddress", static_cast<qint64>(focusedRegion.addressRange.startAddress)},
|
||||||
|
{"endAddress", static_cast<qint64>(focusedRegion.addressRange.endAddress)},
|
||||||
|
});
|
||||||
|
|
||||||
|
auto regionObj = QJsonObject({
|
||||||
|
{"name", focusedRegion.name},
|
||||||
|
{"addressRange", addressRangeObj},
|
||||||
|
{"createdTimestamp", focusedRegion.createdDate.toSecsSinceEpoch()},
|
||||||
|
{"addressInputType", addressRangeInputTypesByName.at(focusedRegion.addressRangeInputType)},
|
||||||
|
{"dataType", regionDataTypesByName.at(focusedRegion.dataType)},
|
||||||
|
});
|
||||||
|
|
||||||
|
focusedRegions.push_back(regionObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto excludedRegions = QJsonArray();
|
||||||
|
for (const auto& excludedRegion : inspectionPaneSettings.excludedMemoryRegions) {
|
||||||
|
if (!addressRangeInputTypesByName.contains(excludedRegion.addressRangeInputType)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto addressRangeObj = QJsonObject({
|
||||||
|
{"startAddress", static_cast<qint64>(excludedRegion.addressRange.startAddress)},
|
||||||
|
{"endAddress", static_cast<qint64>(excludedRegion.addressRange.endAddress)},
|
||||||
|
});
|
||||||
|
|
||||||
|
auto regionObj = QJsonObject({
|
||||||
|
{"name", excludedRegion.name},
|
||||||
|
{"addressRange", addressRangeObj},
|
||||||
|
{"createdTimestamp", excludedRegion.createdDate.toSecsSinceEpoch()},
|
||||||
|
{"addressInputType", addressRangeInputTypesByName.at(excludedRegion.addressRangeInputType)},
|
||||||
|
});
|
||||||
|
|
||||||
|
excludedRegions.push_back(regionObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
settingsObj.insert("focusedRegions", focusedRegions);
|
||||||
|
settingsObj.insert("excludedRegions", excludedRegions);
|
||||||
|
memoryInspectionPaneSettingsObj.insert(
|
||||||
|
InsightProjectSettings::memoryTypesByName.at(memoryType),
|
||||||
|
settingsObj
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
insightObj.insert("memoryInspectionPaneSettings", memoryInspectionPaneSettingsObj);
|
||||||
|
return insightObj;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,22 +3,48 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <optional>
|
||||||
|
#include <QSize>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
|
||||||
#include "src/Targets/TargetMemory.hpp"
|
#include "src/Targets/TargetMemory.hpp"
|
||||||
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPaneSettings.hpp"
|
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPaneSettings.hpp"
|
||||||
|
|
||||||
|
#include "src/Helpers/BiMap.hpp"
|
||||||
|
|
||||||
namespace Bloom
|
namespace Bloom
|
||||||
{
|
{
|
||||||
struct InsightProjectSettings
|
struct InsightProjectSettings
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
std::optional<QSize> mainWindowSize;
|
||||||
|
|
||||||
std::map<
|
std::map<
|
||||||
Targets::TargetMemoryType,
|
Targets::TargetMemoryType,
|
||||||
Widgets::TargetMemoryInspectionPaneSettings
|
Widgets::TargetMemoryInspectionPaneSettings
|
||||||
> memoryInspectionPaneSettingsByMemoryType;
|
> memoryInspectionPaneSettingsByMemoryType;
|
||||||
|
|
||||||
InsightProjectSettings() = default;
|
InsightProjectSettings() = default;
|
||||||
InsightProjectSettings(const QJsonObject& jsonObject);
|
explicit InsightProjectSettings(const QJsonObject& jsonObject);
|
||||||
|
|
||||||
|
[[nodiscard]] QJsonObject toJson() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static const inline BiMap<Targets::TargetMemoryType, QString> memoryTypesByName = {
|
||||||
|
{Targets::TargetMemoryType::RAM, "ram"},
|
||||||
|
{Targets::TargetMemoryType::EEPROM, "eeprom"},
|
||||||
|
};
|
||||||
|
|
||||||
|
static const inline BiMap<MemoryRegionDataType, QString> regionDataTypesByName = {
|
||||||
|
{MemoryRegionDataType::UNKNOWN, "other"},
|
||||||
|
{MemoryRegionDataType::UNSIGNED_INTEGER, "unsigned_int"},
|
||||||
|
{MemoryRegionDataType::ASCII_STRING, "ascii_string"},
|
||||||
|
};
|
||||||
|
|
||||||
|
static const inline BiMap<MemoryRegionAddressInputType, QString> addressRangeInputTypesByName = {
|
||||||
|
{MemoryRegionAddressInputType::ABSOLUTE, "absolute"},
|
||||||
|
{MemoryRegionAddressInputType::RELATIVE, "relative"},
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ProjectSettings
|
struct ProjectSettings
|
||||||
@@ -27,5 +53,7 @@ namespace Bloom
|
|||||||
|
|
||||||
ProjectSettings() = default;
|
ProjectSettings() = default;
|
||||||
explicit ProjectSettings(const QJsonObject& jsonObject);
|
explicit ProjectSettings(const QJsonObject& jsonObject);
|
||||||
|
|
||||||
|
[[nodiscard]] QJsonObject toJson() const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user