mirror of
https://github.com/NohamR/Reclass.git
synced 2026-05-10 19:59:21 +00:00
Compare commits
37 Commits
v2027.02.1
...
snapshot-1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e3ff4dfe71 | ||
|
|
735e4ea9f7 | ||
|
|
d937d2f42e | ||
|
|
3685530287 | ||
|
|
9e90f66ca0 | ||
|
|
f53fa84a15 | ||
|
|
13e28e8791 | ||
|
|
079b3121ce | ||
|
|
5e40349768 | ||
|
|
8dd6110ec6 | ||
|
|
eb27fc7988 | ||
|
|
85994d68b9 | ||
|
|
55dc5d5875 | ||
|
|
3a92336132 | ||
|
|
f9b33f2ba7 | ||
|
|
f2dab07870 | ||
|
|
9d22a5ed69 | ||
|
|
193ab81ecf | ||
|
|
aa0840b332 | ||
|
|
f3631f17ff | ||
|
|
42e9bde7ba | ||
|
|
07fedf0ae8 | ||
|
|
2e02a01495 | ||
|
|
71bc51cbab | ||
|
|
60a97ab81b | ||
|
|
bb00e75019 | ||
|
|
c038c59e34 | ||
|
|
862f76b984 | ||
|
|
818285a76e | ||
|
|
ef5e2ebdb9 | ||
|
|
75fedd2222 | ||
|
|
389745e501 | ||
|
|
1473a58742 | ||
|
|
4192a4dad3 | ||
|
|
4c6bb9564f | ||
|
|
0ef9841f90 | ||
|
|
0a8244dad4 |
271
.github/workflows/build.yml
vendored
Normal file
271
.github/workflows/build.yml
vendored
Normal file
@@ -0,0 +1,271 @@
|
|||||||
|
name: Build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
windows:
|
||||||
|
runs-on: windows-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
|
||||||
|
- name: Install Qt6
|
||||||
|
uses: jurplel/install-qt-action@v4
|
||||||
|
with:
|
||||||
|
version: '6.8.1'
|
||||||
|
arch: 'win64_msvc2022_64'
|
||||||
|
cache: true
|
||||||
|
aqtversion: '==3.1.21'
|
||||||
|
|
||||||
|
- uses: ilammy/msvc-dev-cmd@v1
|
||||||
|
with:
|
||||||
|
arch: x64
|
||||||
|
|
||||||
|
- name: Configure
|
||||||
|
run: cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: cmake --build build
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: ctest --test-dir build --output-on-failure --exclude-regex "test_editor|test_windbg_provider|test_com_security"
|
||||||
|
|
||||||
|
- name: Upload artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
if: always()
|
||||||
|
with:
|
||||||
|
name: Reclass-win64-qt6
|
||||||
|
path: |
|
||||||
|
build/Reclass.exe
|
||||||
|
build/ReclassMcpBridge.exe
|
||||||
|
build/Plugins/*.dll
|
||||||
|
build/*.dll
|
||||||
|
build/platforms/
|
||||||
|
build/styles/
|
||||||
|
build/imageformats/
|
||||||
|
build/iconengines/
|
||||||
|
build/themes/
|
||||||
|
build/screenshot.png
|
||||||
|
|
||||||
|
- name: Get date tag
|
||||||
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||||
|
id: date
|
||||||
|
shell: bash
|
||||||
|
run: echo "tag=$(date +'%d-%m-%Y')" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- name: Package release zip
|
||||||
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
mkdir -p release
|
||||||
|
cp build/Reclass.exe release/
|
||||||
|
cp build/ReclassMcpBridge.exe release/
|
||||||
|
cp build/*.dll release/ 2>/dev/null || true
|
||||||
|
cp -r build/platforms release/ 2>/dev/null || true
|
||||||
|
cp -r build/styles release/ 2>/dev/null || true
|
||||||
|
cp -r build/imageformats release/ 2>/dev/null || true
|
||||||
|
cp -r build/iconengines release/ 2>/dev/null || true
|
||||||
|
mkdir -p release/Plugins
|
||||||
|
cp build/Plugins/*.dll release/Plugins/ 2>/dev/null || true
|
||||||
|
cp -r build/themes release/ 2>/dev/null || true
|
||||||
|
cp build/screenshot.png release/ 2>/dev/null || true
|
||||||
|
cd release && 7z a ../Reclass-win64-qt6.zip *
|
||||||
|
|
||||||
|
- name: Upload release asset
|
||||||
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||||
|
uses: softprops/action-gh-release@v2
|
||||||
|
with:
|
||||||
|
tag_name: snapshot-${{ steps.date.outputs.tag }}
|
||||||
|
name: Snapshot ${{ steps.date.outputs.tag }}
|
||||||
|
body: |
|
||||||
|
Automated snapshot from main branch.
|
||||||
|
Commit: ${{ github.sha }}
|
||||||
|
prerelease: false
|
||||||
|
files: Reclass-win64-qt6.zip
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
linux:
|
||||||
|
needs: windows
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
|
||||||
|
- name: Install Qt6
|
||||||
|
uses: jurplel/install-qt-action@v4
|
||||||
|
with:
|
||||||
|
version: '6.8.1'
|
||||||
|
cache: true
|
||||||
|
aqtversion: '==3.1.21'
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y ninja-build libgl1-mesa-dev libfuse2 libxcb-cursor0
|
||||||
|
|
||||||
|
- name: Configure
|
||||||
|
run: cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: cmake --build build
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: xvfb-run ctest --test-dir build --output-on-failure --exclude-regex "test_editor"
|
||||||
|
env:
|
||||||
|
QT_QPA_PLATFORM: offscreen
|
||||||
|
|
||||||
|
- name: Create AppImage
|
||||||
|
run: |
|
||||||
|
# Download linuxdeploy and Qt plugin
|
||||||
|
wget -q https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage
|
||||||
|
wget -q https://github.com/linuxdeploy/linuxdeploy-plugin-qt/releases/download/continuous/linuxdeploy-plugin-qt-x86_64.AppImage
|
||||||
|
chmod +x linuxdeploy-x86_64.AppImage linuxdeploy-plugin-qt-x86_64.AppImage
|
||||||
|
|
||||||
|
# Build AppDir structure
|
||||||
|
mkdir -p AppDir/usr/bin AppDir/usr/share/icons/hicolor/256x256/apps
|
||||||
|
cp build/Reclass AppDir/usr/bin/
|
||||||
|
cp build/ReclassMcpBridge AppDir/usr/bin/
|
||||||
|
cp -r build/themes AppDir/usr/bin/ 2>/dev/null || true
|
||||||
|
mkdir -p AppDir/usr/bin/Plugins
|
||||||
|
cp build/Plugins/*.so AppDir/usr/bin/Plugins/ 2>/dev/null || true
|
||||||
|
cp src/icons/class.png AppDir/usr/share/icons/hicolor/256x256/apps/reclass.png
|
||||||
|
|
||||||
|
# Create AppImage with Qt libs bundled
|
||||||
|
# install-qt-action adds Qt bin to PATH; find qmake there
|
||||||
|
QMAKE_BIN=$(which qmake 2>/dev/null || which qmake6 2>/dev/null || find "$RUNNER_WORKSPACE" -name qmake -path "*/bin/*" | head -1)
|
||||||
|
echo "Found qmake at: $QMAKE_BIN"
|
||||||
|
export QMAKE="$QMAKE_BIN"
|
||||||
|
QT_ROOT=$(dirname "$(dirname "$QMAKE_BIN")")
|
||||||
|
export LD_LIBRARY_PATH="$QT_ROOT/lib:$LD_LIBRARY_PATH"
|
||||||
|
export EXTRA_QT_PLUGINS="svg;iconengines"
|
||||||
|
./linuxdeploy-x86_64.AppImage --appdir AppDir \
|
||||||
|
--desktop-file deploy/Reclass.desktop \
|
||||||
|
--icon-file AppDir/usr/share/icons/hicolor/256x256/apps/reclass.png \
|
||||||
|
--plugin qt \
|
||||||
|
--output appimage
|
||||||
|
# Rename to final name
|
||||||
|
ls Reclass-*.AppImage
|
||||||
|
mv Reclass-*.AppImage Reclass-linux64-qt6.AppImage
|
||||||
|
|
||||||
|
- name: Upload artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
if: always()
|
||||||
|
with:
|
||||||
|
name: Reclass-linux64-qt6
|
||||||
|
path: Reclass-linux64-qt6.AppImage
|
||||||
|
|
||||||
|
- name: Get date tag
|
||||||
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||||
|
id: date
|
||||||
|
shell: bash
|
||||||
|
run: echo "tag=$(date +'%d-%m-%Y')" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- name: Upload release asset
|
||||||
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||||
|
uses: softprops/action-gh-release@v2
|
||||||
|
with:
|
||||||
|
tag_name: snapshot-${{ steps.date.outputs.tag }}
|
||||||
|
name: Snapshot ${{ steps.date.outputs.tag }}
|
||||||
|
body: |
|
||||||
|
Automated snapshot from main branch.
|
||||||
|
Commit: ${{ github.sha }}
|
||||||
|
prerelease: false
|
||||||
|
files: Reclass-linux64-qt6.AppImage
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
windows-qt5:
|
||||||
|
needs: linux
|
||||||
|
runs-on: windows-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
|
||||||
|
- name: Install Qt5
|
||||||
|
uses: jurplel/install-qt-action@v4
|
||||||
|
with:
|
||||||
|
version: '5.15.2'
|
||||||
|
arch: 'win64_msvc2019_64'
|
||||||
|
cache: true
|
||||||
|
|
||||||
|
- uses: ilammy/msvc-dev-cmd@v1
|
||||||
|
with:
|
||||||
|
arch: x64
|
||||||
|
|
||||||
|
- name: Configure
|
||||||
|
run: cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: cmake --build build
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: ctest --test-dir build --output-on-failure --exclude-regex "test_editor|test_windbg_provider|test_com_security|test_format|test_command_row|test_type_selector"
|
||||||
|
|
||||||
|
- name: Upload artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
if: always()
|
||||||
|
with:
|
||||||
|
name: Reclass-win64-qt5
|
||||||
|
path: |
|
||||||
|
build/Reclass.exe
|
||||||
|
build/ReclassMcpBridge.exe
|
||||||
|
build/Plugins/*.dll
|
||||||
|
build/*.dll
|
||||||
|
build/platforms/
|
||||||
|
build/styles/
|
||||||
|
build/imageformats/
|
||||||
|
build/iconengines/
|
||||||
|
build/themes/
|
||||||
|
build/screenshot.png
|
||||||
|
|
||||||
|
- name: Get date tag
|
||||||
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||||
|
id: date
|
||||||
|
shell: bash
|
||||||
|
run: echo "tag=$(date +'%d-%m-%Y')" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- name: Package release zip
|
||||||
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
mkdir -p release
|
||||||
|
cp build/Reclass.exe release/
|
||||||
|
cp build/ReclassMcpBridge.exe release/
|
||||||
|
cp build/*.dll release/ 2>/dev/null || true
|
||||||
|
cp -r build/platforms release/ 2>/dev/null || true
|
||||||
|
cp -r build/styles release/ 2>/dev/null || true
|
||||||
|
cp -r build/imageformats release/ 2>/dev/null || true
|
||||||
|
cp -r build/iconengines release/ 2>/dev/null || true
|
||||||
|
mkdir -p release/Plugins
|
||||||
|
cp build/Plugins/*.dll release/Plugins/ 2>/dev/null || true
|
||||||
|
cp -r build/themes release/ 2>/dev/null || true
|
||||||
|
cp build/screenshot.png release/ 2>/dev/null || true
|
||||||
|
cd release && 7z a ../Reclass-win64-qt5.zip *
|
||||||
|
|
||||||
|
- name: Upload release asset
|
||||||
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||||
|
uses: softprops/action-gh-release@v2
|
||||||
|
with:
|
||||||
|
tag_name: snapshot-${{ steps.date.outputs.tag }}
|
||||||
|
name: Snapshot ${{ steps.date.outputs.tag }}
|
||||||
|
body: |
|
||||||
|
Automated snapshot from main branch.
|
||||||
|
Commit: ${{ github.sha }}
|
||||||
|
prerelease: false
|
||||||
|
files: Reclass-win64-qt5.zip
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
@@ -60,6 +60,8 @@ add_executable(Reclass
|
|||||||
src/themes/themeeditor.h
|
src/themes/themeeditor.h
|
||||||
src/themes/themeeditor.cpp
|
src/themes/themeeditor.cpp
|
||||||
src/mainwindow.h
|
src/mainwindow.h
|
||||||
|
src/optionsdialog.h
|
||||||
|
src/optionsdialog.cpp
|
||||||
src/titlebar.h
|
src/titlebar.h
|
||||||
src/titlebar.cpp
|
src/titlebar.cpp
|
||||||
src/mcp/mcp_bridge.h
|
src/mcp/mcp_bridge.h
|
||||||
@@ -95,12 +97,14 @@ endforeach()
|
|||||||
|
|
||||||
include(deploy)
|
include(deploy)
|
||||||
|
|
||||||
add_custom_target(screenshot ALL
|
if(TARGET deploy)
|
||||||
COMMAND Reclass --screenshot ${CMAKE_BINARY_DIR}/screenshot.png
|
add_custom_target(screenshot ALL
|
||||||
DEPENDS Reclass deploy
|
COMMAND Reclass --screenshot ${CMAKE_BINARY_DIR}/screenshot.png
|
||||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
DEPENDS Reclass deploy
|
||||||
COMMENT "Capturing UI screenshot with class open..."
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||||
)
|
COMMENT "Capturing UI screenshot with class open..."
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
set(_combine_script "${CMAKE_BINARY_DIR}/combine_sources.cmake")
|
set(_combine_script "${CMAKE_BINARY_DIR}/combine_sources.cmake")
|
||||||
file(WRITE ${_combine_script} "
|
file(WRITE ${_combine_script} "
|
||||||
@@ -257,15 +261,20 @@ if(BUILD_TESTING)
|
|||||||
target_link_libraries(test_theme PRIVATE ${QT}::Widgets ${QT}::Test)
|
target_link_libraries(test_theme PRIVATE ${QT}::Widgets ${QT}::Test)
|
||||||
add_test(NAME test_theme COMMAND test_theme)
|
add_test(NAME test_theme COMMAND test_theme)
|
||||||
|
|
||||||
add_executable(test_windbg_provider tests/test_windbg_provider.cpp
|
add_executable(test_options_dialog tests/test_options_dialog.cpp
|
||||||
plugins/WinDbgMemory/WinDbgMemoryPlugin.cpp)
|
src/optionsdialog.cpp src/themes/theme.cpp src/themes/thememanager.cpp)
|
||||||
target_include_directories(test_windbg_provider PRIVATE src plugins/WinDbgMemory)
|
target_include_directories(test_options_dialog PRIVATE src)
|
||||||
target_link_libraries(test_windbg_provider PRIVATE
|
target_link_libraries(test_options_dialog PRIVATE ${QT}::Widgets ${QT}::Test)
|
||||||
${QT}::Widgets ${QT}::Concurrent ${QT}::Test)
|
add_test(NAME test_options_dialog COMMAND test_options_dialog)
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
target_link_libraries(test_windbg_provider PRIVATE dbgeng ole32)
|
add_executable(test_windbg_provider tests/test_windbg_provider.cpp
|
||||||
|
plugins/WinDbgMemory/WinDbgMemoryPlugin.cpp)
|
||||||
|
target_include_directories(test_windbg_provider PRIVATE src plugins/WinDbgMemory)
|
||||||
|
target_link_libraries(test_windbg_provider PRIVATE
|
||||||
|
${QT}::Widgets ${QT}::Concurrent ${QT}::Test dbgeng ole32)
|
||||||
|
add_test(NAME test_windbg_provider COMMAND test_windbg_provider)
|
||||||
endif()
|
endif()
|
||||||
add_test(NAME test_windbg_provider COMMAND test_windbg_provider)
|
|
||||||
|
|
||||||
# Standalone test: proves whether CoInitializeSecurity is needed for DebugConnect
|
# Standalone test: proves whether CoInitializeSecurity is needed for DebugConnect
|
||||||
# Requires a running WinDbg debug server on port 5055
|
# Requires a running WinDbg debug server on port 5055
|
||||||
@@ -288,5 +297,7 @@ if(BUILD_TESTING)
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
add_subdirectory(plugins/ProcessMemoryWindows)
|
add_subdirectory(plugins/ProcessMemory)
|
||||||
add_subdirectory(plugins/WinDbgMemory)
|
if(WIN32)
|
||||||
|
add_subdirectory(plugins/WinDbgMemory)
|
||||||
|
endif()
|
||||||
|
|||||||
@@ -15,10 +15,6 @@ This tool helps you inspect raw bytes and interpret them as types (structs, arra
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
- Plugin system is partially implemented. Some UI bugs exist.
|
|
||||||
- Vector/Matrix improvements have been made but are not entirely complete.
|
|
||||||
- Every edit goes through a full undo/redo system.
|
|
||||||
|
|
||||||
## Build
|
## Build
|
||||||
|
|
||||||
1. Prerequisites
|
1. Prerequisites
|
||||||
|
|||||||
8
deploy/Reclass.desktop
Normal file
8
deploy/Reclass.desktop
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[Desktop Entry]
|
||||||
|
Type=Application
|
||||||
|
Name=Reclass
|
||||||
|
Comment=Memory structure reverse engineering tool
|
||||||
|
Exec=Reclass
|
||||||
|
Icon=reclass
|
||||||
|
Categories=Development;Debugger;
|
||||||
|
Terminal=false
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
cmake_minimum_required(VERSION 3.20)
|
cmake_minimum_required(VERSION 3.20)
|
||||||
project(ProcessMemoryWindowsPlugin LANGUAGES CXX)
|
project(ProcessMemoryPlugin LANGUAGES CXX)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
@@ -12,36 +12,36 @@ set(CMAKE_AUTOUIC ON)
|
|||||||
|
|
||||||
# Plugin sources
|
# Plugin sources
|
||||||
set(PLUGIN_SOURCES
|
set(PLUGIN_SOURCES
|
||||||
ProcessMemoryWindowsPlugin.h
|
ProcessMemoryPlugin.h
|
||||||
ProcessMemoryWindowsPlugin.cpp
|
ProcessMemoryPlugin.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../src/processpicker.h
|
${CMAKE_CURRENT_SOURCE_DIR}/../../src/processpicker.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../src/processpicker.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/../../src/processpicker.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../src/processpicker.ui
|
${CMAKE_CURRENT_SOURCE_DIR}/../../src/processpicker.ui
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create shared library (DLL)
|
# Create shared library (DLL)
|
||||||
add_library(ProcessMemoryWindowsPlugin SHARED ${PLUGIN_SOURCES})
|
add_library(ProcessMemoryPlugin SHARED ${PLUGIN_SOURCES})
|
||||||
|
|
||||||
# Link Qt
|
# Link Qt
|
||||||
target_link_libraries(ProcessMemoryWindowsPlugin PRIVATE ${QT}::Widgets ${_QT_WINEXTRAS})
|
target_link_libraries(ProcessMemoryPlugin PRIVATE ${QT}::Widgets ${_QT_WINEXTRAS})
|
||||||
|
|
||||||
# Platform-specific linking
|
# Platform-specific linking
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
target_link_libraries(ProcessMemoryWindowsPlugin PRIVATE psapi shell32)
|
target_link_libraries(ProcessMemoryPlugin PRIVATE psapi shell32)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# On Linux, hide all symbols by default so only RCX_PLUGIN_EXPORT-marked ones are exported
|
# On Linux, hide all symbols by default so only RCX_PLUGIN_EXPORT-marked ones are exported
|
||||||
if(UNIX AND NOT APPLE)
|
if(UNIX AND NOT APPLE)
|
||||||
target_compile_options(ProcessMemoryWindowsPlugin PRIVATE -fvisibility=hidden)
|
target_compile_options(ProcessMemoryPlugin PRIVATE -fvisibility=hidden)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Include directories
|
# Include directories
|
||||||
target_include_directories(ProcessMemoryWindowsPlugin PRIVATE
|
target_include_directories(ProcessMemoryPlugin PRIVATE
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../src
|
${CMAKE_CURRENT_SOURCE_DIR}/../../src
|
||||||
)
|
)
|
||||||
|
|
||||||
# Output to Plugins folder
|
# Output to Plugins folder
|
||||||
set_target_properties(ProcessMemoryWindowsPlugin PROPERTIES
|
set_target_properties(ProcessMemoryPlugin PROPERTIES
|
||||||
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/Plugins"
|
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/Plugins"
|
||||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/Plugins"
|
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/Plugins"
|
||||||
)
|
)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "ProcessMemoryWindowsPlugin.h"
|
#include "ProcessMemoryPlugin.h"
|
||||||
|
|
||||||
#include "../../src/processpicker.h"
|
#include "../../src/processpicker.h"
|
||||||
|
|
||||||
@@ -32,12 +32,12 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// ──────────────────────────────────────────────────────────────────────────
|
// ──────────────────────────────────────────────────────────────────────────
|
||||||
// ProcessMemoryWindowsProvider implementation
|
// ProcessMemoryProvider implementation
|
||||||
// ──────────────────────────────────────────────────────────────────────────
|
// ──────────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
ProcessMemoryWindowsProvider::ProcessMemoryWindowsProvider(uint32_t pid, const QString& processName)
|
ProcessMemoryProvider::ProcessMemoryProvider(uint32_t pid, const QString& processName)
|
||||||
: m_handle(nullptr)
|
: m_handle(nullptr)
|
||||||
, m_pid(pid)
|
, m_pid(pid)
|
||||||
, m_processName(processName)
|
, m_processName(processName)
|
||||||
@@ -60,7 +60,7 @@ ProcessMemoryWindowsProvider::ProcessMemoryWindowsProvider(uint32_t pid, const Q
|
|||||||
cacheModules();
|
cacheModules();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProcessMemoryWindowsProvider::read(uint64_t addr, void* buf, int len) const
|
bool ProcessMemoryProvider::read(uint64_t addr, void* buf, int len) const
|
||||||
{
|
{
|
||||||
if (!m_handle || len <= 0) return false;
|
if (!m_handle || len <= 0) return false;
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ bool ProcessMemoryWindowsProvider::read(uint64_t addr, void* buf, int len) const
|
|||||||
return bytesRead > 0;
|
return bytesRead > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProcessMemoryWindowsProvider::write(uint64_t addr, const void* buf, int len)
|
bool ProcessMemoryProvider::write(uint64_t addr, const void* buf, int len)
|
||||||
{
|
{
|
||||||
if (!m_handle || !m_writable || len <= 0) return false;
|
if (!m_handle || !m_writable || len <= 0) return false;
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ bool ProcessMemoryWindowsProvider::write(uint64_t addr, const void* buf, int len
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ProcessMemoryWindowsProvider::getSymbol(uint64_t addr) const
|
QString ProcessMemoryProvider::getSymbol(uint64_t addr) const
|
||||||
{
|
{
|
||||||
for (const auto& mod : m_modules)
|
for (const auto& mod : m_modules)
|
||||||
{
|
{
|
||||||
@@ -96,7 +96,7 @@ QString ProcessMemoryWindowsProvider::getSymbol(uint64_t addr) const
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessMemoryWindowsProvider::cacheModules()
|
void ProcessMemoryProvider::cacheModules()
|
||||||
{
|
{
|
||||||
HMODULE mods[1024];
|
HMODULE mods[1024];
|
||||||
DWORD needed = 0;
|
DWORD needed = 0;
|
||||||
@@ -126,7 +126,7 @@ void ProcessMemoryWindowsProvider::cacheModules()
|
|||||||
|
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
|
|
||||||
ProcessMemoryWindowsProvider::ProcessMemoryWindowsProvider(uint32_t pid, const QString& processName)
|
ProcessMemoryProvider::ProcessMemoryProvider(uint32_t pid, const QString& processName)
|
||||||
: m_fd(-1)
|
: m_fd(-1)
|
||||||
, m_pid(pid)
|
, m_pid(pid)
|
||||||
, m_processName(processName)
|
, m_processName(processName)
|
||||||
@@ -152,7 +152,7 @@ ProcessMemoryWindowsProvider::ProcessMemoryWindowsProvider(uint32_t pid, const Q
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProcessMemoryWindowsProvider::read(uint64_t addr, void* buf, int len) const
|
bool ProcessMemoryProvider::read(uint64_t addr, void* buf, int len) const
|
||||||
{
|
{
|
||||||
if (m_fd < 0 || len <= 0) return false;
|
if (m_fd < 0 || len <= 0) return false;
|
||||||
|
|
||||||
@@ -176,7 +176,7 @@ bool ProcessMemoryWindowsProvider::read(uint64_t addr, void* buf, int len) const
|
|||||||
return nread == static_cast<ssize_t>(len);
|
return nread == static_cast<ssize_t>(len);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProcessMemoryWindowsProvider::write(uint64_t addr, const void* buf, int len)
|
bool ProcessMemoryProvider::write(uint64_t addr, const void* buf, int len)
|
||||||
{
|
{
|
||||||
if (m_fd < 0 || !m_writable || len <= 0) return false;
|
if (m_fd < 0 || !m_writable || len <= 0) return false;
|
||||||
|
|
||||||
@@ -200,7 +200,7 @@ bool ProcessMemoryWindowsProvider::write(uint64_t addr, const void* buf, int len
|
|||||||
return nwritten == static_cast<ssize_t>(len);
|
return nwritten == static_cast<ssize_t>(len);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ProcessMemoryWindowsProvider::getSymbol(uint64_t addr) const
|
QString ProcessMemoryProvider::getSymbol(uint64_t addr) const
|
||||||
{
|
{
|
||||||
for (const auto& mod : m_modules)
|
for (const auto& mod : m_modules)
|
||||||
{
|
{
|
||||||
@@ -215,7 +215,7 @@ QString ProcessMemoryWindowsProvider::getSymbol(uint64_t addr) const
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessMemoryWindowsProvider::cacheModules()
|
void ProcessMemoryProvider::cacheModules()
|
||||||
{
|
{
|
||||||
// Parse /proc/<pid>/maps to discover loaded modules
|
// Parse /proc/<pid>/maps to discover loaded modules
|
||||||
QString mapsPath = QStringLiteral("/proc/%1/maps").arg(m_pid);
|
QString mapsPath = QStringLiteral("/proc/%1/maps").arg(m_pid);
|
||||||
@@ -288,7 +288,7 @@ void ProcessMemoryWindowsProvider::cacheModules()
|
|||||||
|
|
||||||
#endif // platform
|
#endif // platform
|
||||||
|
|
||||||
ProcessMemoryWindowsProvider::~ProcessMemoryWindowsProvider()
|
ProcessMemoryProvider::~ProcessMemoryProvider()
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (m_handle)
|
if (m_handle)
|
||||||
@@ -299,7 +299,7 @@ ProcessMemoryWindowsProvider::~ProcessMemoryWindowsProvider()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int ProcessMemoryWindowsProvider::size() const
|
int ProcessMemoryProvider::size() const
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
return m_handle ? 0x10000 : 0;
|
return m_handle ? 0x10000 : 0;
|
||||||
@@ -309,22 +309,22 @@ int ProcessMemoryWindowsProvider::size() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ──────────────────────────────────────────────────────────────────────────
|
// ──────────────────────────────────────────────────────────────────────────
|
||||||
// ProcessMemoryWindowsPlugin implementation
|
// ProcessMemoryPlugin implementation
|
||||||
// ──────────────────────────────────────────────────────────────────────────
|
// ──────────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
QIcon ProcessMemoryWindowsPlugin::Icon() const
|
QIcon ProcessMemoryPlugin::Icon() const
|
||||||
{
|
{
|
||||||
return qApp->style()->standardIcon(QStyle::SP_ComputerIcon);
|
return qApp->style()->standardIcon(QStyle::SP_ComputerIcon);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProcessMemoryWindowsPlugin::canHandle(const QString& target) const
|
bool ProcessMemoryPlugin::canHandle(const QString& target) const
|
||||||
{
|
{
|
||||||
// Target format: "pid:name" or just "pid"
|
// Target format: "pid:name" or just "pid"
|
||||||
QRegularExpression re("^\\d+");
|
QRegularExpression re("^\\d+");
|
||||||
return re.match(target).hasMatch();
|
return re.match(target).hasMatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<rcx::Provider> ProcessMemoryWindowsPlugin::createProvider(const QString& target, QString* errorMsg)
|
std::unique_ptr<rcx::Provider> ProcessMemoryPlugin::createProvider(const QString& target, QString* errorMsg)
|
||||||
{
|
{
|
||||||
// Parse target: "pid:name" or just "pid"
|
// Parse target: "pid:name" or just "pid"
|
||||||
QStringList parts = target.split(':');
|
QStringList parts = target.split(':');
|
||||||
@@ -339,7 +339,7 @@ std::unique_ptr<rcx::Provider> ProcessMemoryWindowsPlugin::createProvider(const
|
|||||||
|
|
||||||
QString name = parts.size() > 1 ? parts[1] : QString("PID %1").arg(pid);
|
QString name = parts.size() > 1 ? parts[1] : QString("PID %1").arg(pid);
|
||||||
|
|
||||||
auto provider = std::make_unique<ProcessMemoryWindowsProvider>(pid, name);
|
auto provider = std::make_unique<ProcessMemoryProvider>(pid, name);
|
||||||
if (!provider->isValid())
|
if (!provider->isValid())
|
||||||
{
|
{
|
||||||
if (errorMsg)
|
if (errorMsg)
|
||||||
@@ -352,7 +352,7 @@ std::unique_ptr<rcx::Provider> ProcessMemoryWindowsPlugin::createProvider(const
|
|||||||
return provider;
|
return provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t ProcessMemoryWindowsPlugin::getInitialBaseAddress(const QString& target) const
|
uint64_t ProcessMemoryPlugin::getInitialBaseAddress(const QString& target) const
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
// Parse PID from target
|
// Parse PID from target
|
||||||
@@ -409,7 +409,7 @@ uint64_t ProcessMemoryWindowsPlugin::getInitialBaseAddress(const QString& target
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProcessMemoryWindowsPlugin::selectTarget(QWidget* parent, QString* target)
|
bool ProcessMemoryPlugin::selectTarget(QWidget* parent, QString* target)
|
||||||
{
|
{
|
||||||
// Use custom process enumeration from plugin
|
// Use custom process enumeration from plugin
|
||||||
QVector<PluginProcessInfo> pluginProcesses = enumerateProcesses();
|
QVector<PluginProcessInfo> pluginProcesses = enumerateProcesses();
|
||||||
@@ -440,7 +440,7 @@ bool ProcessMemoryWindowsPlugin::selectTarget(QWidget* parent, QString* target)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<PluginProcessInfo> ProcessMemoryWindowsPlugin::enumerateProcesses()
|
QVector<PluginProcessInfo> ProcessMemoryPlugin::enumerateProcesses()
|
||||||
{
|
{
|
||||||
QVector<PluginProcessInfo> processes;
|
QVector<PluginProcessInfo> processes;
|
||||||
|
|
||||||
@@ -543,5 +543,5 @@ QVector<PluginProcessInfo> ProcessMemoryWindowsPlugin::enumerateProcesses()
|
|||||||
|
|
||||||
extern "C" RCX_PLUGIN_EXPORT IPlugin* CreatePlugin()
|
extern "C" RCX_PLUGIN_EXPORT IPlugin* CreatePlugin()
|
||||||
{
|
{
|
||||||
return new ProcessMemoryWindowsPlugin();
|
return new ProcessMemoryPlugin();
|
||||||
}
|
}
|
||||||
@@ -5,14 +5,14 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process memory provider (Windows)
|
* Process memory provider
|
||||||
* Reads/writes memory from a live process using Windows platform APIs
|
* Reads/writes memory from a live process using platform APIs
|
||||||
*/
|
*/
|
||||||
class ProcessMemoryWindowsProvider : public rcx::Provider
|
class ProcessMemoryProvider : public rcx::Provider
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ProcessMemoryWindowsProvider(uint32_t pid, const QString& processName);
|
ProcessMemoryProvider(uint32_t pid, const QString& processName);
|
||||||
~ProcessMemoryWindowsProvider() override;
|
~ProcessMemoryProvider() override;
|
||||||
|
|
||||||
// Required overrides
|
// Required overrides
|
||||||
bool read(uint64_t addr, void* buf, int len) const override;
|
bool read(uint64_t addr, void* buf, int len) const override;
|
||||||
@@ -57,15 +57,15 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plugin that provides ProcessMemoryWindowsProvider
|
* Plugin that provides ProcessMemoryProvider
|
||||||
*/
|
*/
|
||||||
class ProcessMemoryWindowsPlugin : public IProviderPlugin
|
class ProcessMemoryPlugin : public IProviderPlugin
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string Name() const override { return "Process Memory Windows"; }
|
std::string Name() const override { return "Process Memory"; }
|
||||||
std::string Version() const override { return "1.0.0"; }
|
std::string Version() const override { return "1.0.0"; }
|
||||||
std::string Author() const override { return "Reclass"; }
|
std::string Author() const override { return "Reclass"; }
|
||||||
std::string Description() const override { return "Read and write memory from local running processes (Windows)"; }
|
std::string Description() const override { return "Read and write memory from local running processes"; }
|
||||||
k_ELoadType LoadType() const override { return k_ELoadTypeAuto; }
|
k_ELoadType LoadType() const override { return k_ELoadTypeAuto; }
|
||||||
QIcon Icon() const override;
|
QIcon Icon() const override;
|
||||||
|
|
||||||
BIN
screenshot.png
BIN
screenshot.png
Binary file not shown.
|
Before Width: | Height: | Size: 60 KiB After Width: | Height: | Size: 63 KiB |
@@ -14,8 +14,9 @@ constexpr uint64_t kGoldenRatio = 0x9E3779B97F4A7C15ULL;
|
|||||||
struct ComposeState {
|
struct ComposeState {
|
||||||
QString text;
|
QString text;
|
||||||
QVector<LineMeta> meta;
|
QVector<LineMeta> meta;
|
||||||
QSet<uint64_t> visiting; // cycle detection for struct recursion
|
QSet<uint64_t> visiting; // cycle detection for struct recursion
|
||||||
QSet<qulonglong> ptrVisiting; // cycle guard for pointer expansions
|
QSet<qulonglong> ptrVisiting; // cycle guard for pointer expansions
|
||||||
|
QSet<uint64_t> virtualPtrRefs; // refIds currently being virtually expanded via pointer deref
|
||||||
int currentLine = 0;
|
int currentLine = 0;
|
||||||
int typeW = kColType; // global type column width (fallback)
|
int typeW = kColType; // global type column width (fallback)
|
||||||
int nameW = kColName; // global name column width (fallback)
|
int nameW = kColName; // global name column width (fallback)
|
||||||
@@ -64,7 +65,6 @@ uint32_t computeMarkers(const Node& node, const Provider& /*prov*/,
|
|||||||
uint64_t /*addr*/, bool isCont, int /*depth*/) {
|
uint64_t /*addr*/, bool isCont, int /*depth*/) {
|
||||||
uint32_t mask = 0;
|
uint32_t mask = 0;
|
||||||
if (isCont) mask |= (1u << M_CONT);
|
if (isCont) mask |= (1u << M_CONT);
|
||||||
if (node.kind == NodeKind::Padding) mask |= (1u << M_PAD);
|
|
||||||
// No ambient validation markers — errors only shown during inline editing.
|
// No ambient validation markers — errors only shown during inline editing.
|
||||||
return mask;
|
return mask;
|
||||||
}
|
}
|
||||||
@@ -118,14 +118,7 @@ void composeLeaf(ComposeState& state, const NodeTree& tree,
|
|||||||
int typeW = state.effectiveTypeW(scopeId);
|
int typeW = state.effectiveTypeW(scopeId);
|
||||||
int nameW = state.effectiveNameW(scopeId);
|
int nameW = state.effectiveNameW(scopeId);
|
||||||
|
|
||||||
// Line count: padding wraps at 8 bytes per line
|
int numLines = linesForKind(node.kind);
|
||||||
int numLines;
|
|
||||||
if (node.kind == NodeKind::Padding) {
|
|
||||||
int totalBytes = qMax(1, node.arrayLen);
|
|
||||||
numLines = (totalBytes + 7) / 8;
|
|
||||||
} else {
|
|
||||||
numLines = linesForKind(node.kind);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resolve pointer target name for display
|
// Resolve pointer target name for display
|
||||||
QString ptrTypeOverride;
|
QString ptrTypeOverride;
|
||||||
@@ -156,12 +149,7 @@ void composeLeaf(ComposeState& state, const NodeTree& tree,
|
|||||||
|
|
||||||
// Set byte count for hex preview lines (used for per-byte change highlighting)
|
// Set byte count for hex preview lines (used for per-byte change highlighting)
|
||||||
if (isHexPreview(node.kind)) {
|
if (isHexPreview(node.kind)) {
|
||||||
if (node.kind == NodeKind::Padding) {
|
lm.lineByteCount = sizeForKind(node.kind);
|
||||||
int totalSz = qMax(1, node.arrayLen);
|
|
||||||
lm.lineByteCount = qMin(8, totalSz - sub * 8);
|
|
||||||
} else {
|
|
||||||
lm.lineByteCount = sizeForKind(node.kind);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString lineText = fmt::fmtNodeLine(node, prov, absAddr, depth, sub,
|
QString lineText = fmt::fmtNodeLine(node, prov, absAddr, depth, sub,
|
||||||
@@ -430,29 +418,42 @@ void composeNode(ComposeState& state, const NodeTree& tree,
|
|||||||
QString ptrTargetName = resolvePointerTarget(tree, node.refId);
|
QString ptrTargetName = resolvePointerTarget(tree, node.refId);
|
||||||
QString ptrTypeOverride = fmt::pointerTypeName(node.kind, ptrTargetName);
|
QString ptrTypeOverride = fmt::pointerTypeName(node.kind, ptrTargetName);
|
||||||
|
|
||||||
|
// Check if this pointer has materialized children (from materializeRefChildren)
|
||||||
|
QVector<int> ptrChildren = state.childMap.value(node.id);
|
||||||
|
bool hasMaterialized = !ptrChildren.isEmpty();
|
||||||
|
|
||||||
|
// Force collapsed if this refId is already being virtually expanded
|
||||||
|
// (prevents infinite recursion in virtual expansion mode).
|
||||||
|
// Materialized children bypass this — they are real tree nodes with
|
||||||
|
// independent collapsed state, so recursion is bounded by the tree.
|
||||||
|
bool forceCollapsed = !hasMaterialized
|
||||||
|
&& state.virtualPtrRefs.contains(node.refId);
|
||||||
|
bool effectiveCollapsed = node.collapsed || forceCollapsed;
|
||||||
|
|
||||||
// Emit merged fold header: "Type* Name {" (expanded) or "Type* Name -> val" (collapsed)
|
// Emit merged fold header: "Type* Name {" (expanded) or "Type* Name -> val" (collapsed)
|
||||||
{
|
{
|
||||||
LineMeta lm;
|
LineMeta lm;
|
||||||
lm.nodeIdx = nodeIdx;
|
lm.nodeIdx = nodeIdx;
|
||||||
lm.nodeId = node.id;
|
lm.nodeId = node.id;
|
||||||
lm.depth = depth;
|
lm.depth = depth;
|
||||||
lm.lineKind = node.collapsed ? LineKind::Field : LineKind::Header;
|
lm.lineKind = effectiveCollapsed ? LineKind::Field : LineKind::Header;
|
||||||
lm.offsetText = fmt::fmtOffsetMargin(tree.baseAddress + absAddr, false, state.offsetHexDigits);
|
lm.offsetText = fmt::fmtOffsetMargin(tree.baseAddress + absAddr, false, state.offsetHexDigits);
|
||||||
lm.offsetAddr = tree.baseAddress + absAddr;
|
lm.offsetAddr = tree.baseAddress + absAddr;
|
||||||
lm.nodeKind = node.kind;
|
lm.nodeKind = node.kind;
|
||||||
lm.foldHead = true;
|
lm.foldHead = true;
|
||||||
lm.foldCollapsed = node.collapsed;
|
lm.foldCollapsed = effectiveCollapsed;
|
||||||
lm.foldLevel = computeFoldLevel(depth, true);
|
lm.foldLevel = computeFoldLevel(depth, true);
|
||||||
lm.markerMask = computeMarkers(node, prov, absAddr, false, depth);
|
lm.markerMask = computeMarkers(node, prov, absAddr, false, depth);
|
||||||
|
if (forceCollapsed) lm.markerMask |= (1u << M_CYCLE);
|
||||||
lm.effectiveTypeW = typeW;
|
lm.effectiveTypeW = typeW;
|
||||||
lm.effectiveNameW = nameW;
|
lm.effectiveNameW = nameW;
|
||||||
lm.pointerTargetName = ptrTargetName;
|
lm.pointerTargetName = ptrTargetName;
|
||||||
state.emitLine(fmt::fmtPointerHeader(node, depth, node.collapsed,
|
state.emitLine(fmt::fmtPointerHeader(node, depth, effectiveCollapsed,
|
||||||
prov, absAddr, ptrTypeOverride,
|
prov, absAddr, ptrTypeOverride,
|
||||||
typeW, nameW), lm);
|
typeW, nameW), lm);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!node.collapsed) {
|
if (!effectiveCollapsed) {
|
||||||
int sz = node.byteSize();
|
int sz = node.byteSize();
|
||||||
uint64_t ptrVal = 0;
|
uint64_t ptrVal = 0;
|
||||||
if (prov.isValid() && sz > 0 && prov.isReadable(absAddr, sz)) {
|
if (prov.isValid() && sz > 0 && prov.isReadable(absAddr, sz)) {
|
||||||
@@ -480,18 +481,42 @@ void composeNode(ComposeState& state, const NodeTree& tree,
|
|||||||
if (!ptrReadable)
|
if (!ptrReadable)
|
||||||
pBase = (uint64_t)0 - tree.baseAddress;
|
pBase = (uint64_t)0 - tree.baseAddress;
|
||||||
|
|
||||||
qulonglong key = pBase ^ (node.refId * kGoldenRatio);
|
if (hasMaterialized) {
|
||||||
if (!state.ptrVisiting.contains(key)) {
|
// Render materialized children at the pointer target address.
|
||||||
state.ptrVisiting.insert(key);
|
// These are real tree nodes with independent state — use rootId
|
||||||
int refIdx = tree.indexOfId(node.refId);
|
// so resolveAddr computes offsets relative to the pointer target.
|
||||||
if (refIdx >= 0) {
|
std::sort(ptrChildren.begin(), ptrChildren.end(), [&](int a, int b) {
|
||||||
const Node& ref = tree.nodes[refIdx];
|
return tree.nodes[a].offset < tree.nodes[b].offset;
|
||||||
if (ref.kind == NodeKind::Struct || ref.kind == NodeKind::Array)
|
});
|
||||||
composeParent(state, tree, childProv, refIdx,
|
for (int childIdx : ptrChildren) {
|
||||||
depth, pBase, ref.id,
|
composeNode(state, tree, childProv, childIdx, depth + 1,
|
||||||
/*isArrayChild=*/true);
|
pBase, node.id, false, node.id);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Virtual expansion via ref struct definition.
|
||||||
|
// Temporarily remove the ref struct from visiting so composeParent
|
||||||
|
// doesn't hit the struct-level cycle guard. The ptrVisiting mechanism
|
||||||
|
// handles actual address-level pointer cycles, and virtualPtrRefs
|
||||||
|
// prevents infinite virtual recursion (inner self-referential pointers
|
||||||
|
// are force-collapsed with M_CYCLE for the user to materialize).
|
||||||
|
qulonglong key = pBase ^ (node.refId * kGoldenRatio);
|
||||||
|
if (!state.ptrVisiting.contains(key)) {
|
||||||
|
state.ptrVisiting.insert(key);
|
||||||
|
int refIdx = tree.indexOfId(node.refId);
|
||||||
|
if (refIdx >= 0) {
|
||||||
|
const Node& ref = tree.nodes[refIdx];
|
||||||
|
if (ref.kind == NodeKind::Struct || ref.kind == NodeKind::Array) {
|
||||||
|
bool wasVisiting = state.visiting.remove(node.refId);
|
||||||
|
state.virtualPtrRefs.insert(node.refId);
|
||||||
|
composeParent(state, tree, childProv, refIdx,
|
||||||
|
depth, pBase, ref.id,
|
||||||
|
/*isArrayChild=*/true);
|
||||||
|
state.virtualPtrRefs.remove(node.refId);
|
||||||
|
if (wasVisiting) state.visiting.insert(node.refId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
state.ptrVisiting.remove(key);
|
||||||
}
|
}
|
||||||
state.ptrVisiting.remove(key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Footer for pointer fold
|
// Footer for pointer fold
|
||||||
@@ -571,7 +596,7 @@ ComposeResult compose(const NodeTree& tree, const Provider& prov, uint64_t viewR
|
|||||||
// Include struct/array names - they now use columnar layout too
|
// Include struct/array names - they now use columnar layout too
|
||||||
int maxNameLen = kMinNameW;
|
int maxNameLen = kMinNameW;
|
||||||
for (const Node& node : tree.nodes) {
|
for (const Node& node : tree.nodes) {
|
||||||
// Skip hex/padding (they show ASCII preview, not name column)
|
// Skip hex (they show ASCII preview, not name column)
|
||||||
if (isHexPreview(node.kind)) continue;
|
if (isHexPreview(node.kind)) continue;
|
||||||
maxNameLen = qMax(maxNameLen, (int)node.name.size());
|
maxNameLen = qMax(maxNameLen, (int)node.name.size());
|
||||||
}
|
}
|
||||||
@@ -590,7 +615,7 @@ ComposeResult compose(const NodeTree& tree, const Provider& prov, uint64_t viewR
|
|||||||
const Node& child = tree.nodes[childIdx];
|
const Node& child = tree.nodes[childIdx];
|
||||||
scopeMaxType = qMax(scopeMaxType, (int)nodeTypeName(child).size());
|
scopeMaxType = qMax(scopeMaxType, (int)nodeTypeName(child).size());
|
||||||
|
|
||||||
// Name width (skip hex/padding, but include containers)
|
// Name width (skip hex, but include containers)
|
||||||
if (!isHexPreview(child.kind)) {
|
if (!isHexPreview(child.kind)) {
|
||||||
scopeMaxName = qMax(scopeMaxName, (int)child.name.size());
|
scopeMaxName = qMax(scopeMaxName, (int)child.name.size());
|
||||||
}
|
}
|
||||||
@@ -622,7 +647,7 @@ ComposeResult compose(const NodeTree& tree, const Provider& prov, uint64_t viewR
|
|||||||
const Node& child = tree.nodes[childIdx];
|
const Node& child = tree.nodes[childIdx];
|
||||||
rootMaxType = qMax(rootMaxType, (int)nodeTypeName(child).size());
|
rootMaxType = qMax(rootMaxType, (int)nodeTypeName(child).size());
|
||||||
|
|
||||||
// Name width (skip hex/padding, include containers)
|
// Name width (skip hex, include containers)
|
||||||
if (!isHexPreview(child.kind)) {
|
if (!isHexPreview(child.kind)) {
|
||||||
rootMaxName = qMax(rootMaxName, (int)child.name.size());
|
rootMaxName = qMax(rootMaxName, (int)child.name.size());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -178,6 +178,14 @@ RcxEditor* RcxController::addSplitEditor(QWidget* parent) {
|
|||||||
editor->applyDocument(m_lastResult);
|
editor->applyDocument(m_lastResult);
|
||||||
}
|
}
|
||||||
updateCommandRow();
|
updateCommandRow();
|
||||||
|
|
||||||
|
// Eagerly pre-warm the type popup so first click isn't slow (~350ms cold start).
|
||||||
|
if (!m_cachedPopup) {
|
||||||
|
QTimer::singleShot(0, this, [this, editor]() {
|
||||||
|
if (!m_cachedPopup && !m_editors.isEmpty())
|
||||||
|
ensurePopup(editor);
|
||||||
|
});
|
||||||
|
}
|
||||||
return editor;
|
return editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,8 +234,9 @@ void RcxController::connectEditor(RcxEditor* editor) {
|
|||||||
switch (target) {
|
switch (target) {
|
||||||
case EditTarget::Name: {
|
case EditTarget::Name: {
|
||||||
if (text.isEmpty()) break;
|
if (text.isEmpty()) break;
|
||||||
|
if (nodeIdx >= m_doc->tree.nodes.size()) break;
|
||||||
const Node& node = m_doc->tree.nodes[nodeIdx];
|
const Node& node = m_doc->tree.nodes[nodeIdx];
|
||||||
// ASCII edit on Hex/Padding nodes
|
// ASCII edit on Hex nodes
|
||||||
if (isHexPreview(node.kind)) {
|
if (isHexPreview(node.kind)) {
|
||||||
setNodeValue(nodeIdx, subLine, text, /*isAscii=*/true);
|
setNodeValue(nodeIdx, subLine, text, /*isAscii=*/true);
|
||||||
} else {
|
} else {
|
||||||
@@ -602,7 +611,7 @@ void RcxController::refresh() {
|
|||||||
|
|
||||||
if (isHexPreview(node.kind)) {
|
if (isHexPreview(node.kind)) {
|
||||||
// Per-byte tracking for hex preview nodes
|
// Per-byte tracking for hex preview nodes
|
||||||
int lineOff = (node.kind == NodeKind::Padding) ? lm.subLine * 8 : 0;
|
int lineOff = 0;
|
||||||
int byteCount = lm.lineByteCount;
|
int byteCount = lm.lineByteCount;
|
||||||
for (int b = 0; b < byteCount; b++) {
|
for (int b = 0; b < byteCount; b++) {
|
||||||
if (m_changedOffsets.contains(offset + lineOff + b)) {
|
if (m_changedOffsets.contains(offset + lineOff + b)) {
|
||||||
@@ -799,38 +808,52 @@ void RcxController::materializeRefChildren(int nodeIdx) {
|
|||||||
if (nodeIdx < 0 || nodeIdx >= m_doc->tree.nodes.size()) return;
|
if (nodeIdx < 0 || nodeIdx >= m_doc->tree.nodes.size()) return;
|
||||||
auto& tree = m_doc->tree;
|
auto& tree = m_doc->tree;
|
||||||
|
|
||||||
// Snapshot values before addNode invalidates references
|
// Snapshot values before any mutation invalidates references
|
||||||
const uint64_t parentId = tree.nodes[nodeIdx].id;
|
const uint64_t parentId = tree.nodes[nodeIdx].id;
|
||||||
const uint64_t refId = tree.nodes[nodeIdx].refId;
|
const uint64_t refId = tree.nodes[nodeIdx].refId;
|
||||||
const NodeKind parentKind = tree.nodes[nodeIdx].kind;
|
const NodeKind parentKind = tree.nodes[nodeIdx].kind;
|
||||||
const QString parentName = tree.nodes[nodeIdx].name;
|
const QString parentName = tree.nodes[nodeIdx].name;
|
||||||
|
|
||||||
if (refId == 0) return;
|
if (refId == 0) return;
|
||||||
if (!tree.childrenOf(parentId).isEmpty()) return; // already materialized
|
if (!tree.childrenOf(parentId).isEmpty()) return; // already materialized
|
||||||
|
|
||||||
// Clone all children of the referenced struct as real children of this struct
|
// Collect children to clone (copy by value to avoid reference invalidation)
|
||||||
QVector<int> refChildren = tree.childrenOf(refId);
|
QVector<int> refChildren = tree.childrenOf(refId);
|
||||||
|
if (refChildren.isEmpty()) return;
|
||||||
|
|
||||||
|
QVector<Node> clones;
|
||||||
|
clones.reserve(refChildren.size());
|
||||||
for (int ci : refChildren) {
|
for (int ci : refChildren) {
|
||||||
Node copy = tree.nodes[ci];
|
Node copy = tree.nodes[ci]; // copy by value before any mutation
|
||||||
copy.id = 0; // auto-assign new ID
|
copy.id = tree.reserveId();
|
||||||
copy.parentId = parentId;
|
copy.parentId = parentId;
|
||||||
copy.collapsed = true; // start collapsed
|
copy.collapsed = true;
|
||||||
tree.addNode(copy);
|
clones.append(copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wrap all mutations in an undo macro
|
||||||
|
bool wasSuppressed = m_suppressRefresh;
|
||||||
|
m_suppressRefresh = true;
|
||||||
|
m_doc->undoStack.beginMacro(QStringLiteral("Materialize ref children"));
|
||||||
|
|
||||||
|
for (const Node& clone : clones) {
|
||||||
|
m_doc->undoStack.push(new RcxCommand(this,
|
||||||
|
cmd::Insert{clone, {}}));
|
||||||
}
|
}
|
||||||
tree.invalidateIdCache();
|
|
||||||
|
|
||||||
// Auto-expand the self-referential child (the one that was the cycle)
|
// Auto-expand the self-referential child (the one that was the cycle)
|
||||||
// so the user gets expand in a single click
|
// so the user gets expand in a single click
|
||||||
QVector<int> newChildren = tree.childrenOf(parentId);
|
for (const Node& clone : clones) {
|
||||||
for (int ci : newChildren) {
|
if (clone.kind == parentKind && clone.name == parentName && clone.refId == refId) {
|
||||||
auto& c = tree.nodes[ci];
|
m_doc->undoStack.push(new RcxCommand(this,
|
||||||
if (c.kind == parentKind && c.name == parentName && c.refId == refId) {
|
cmd::Collapse{clone.id, true, false}));
|
||||||
c.collapsed = false;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
refresh();
|
m_doc->undoStack.endMacro();
|
||||||
|
m_suppressRefresh = wasSuppressed;
|
||||||
|
if (!m_suppressRefresh) refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RcxController::applyCommand(const Command& command, bool isUndo) {
|
void RcxController::applyCommand(const Command& command, bool isUndo) {
|
||||||
@@ -1093,23 +1116,23 @@ void RcxController::showContextMenu(RcxEditor* editor, int line, int nodeIdx,
|
|||||||
// Quick-convert suggestions for Hex nodes
|
// Quick-convert suggestions for Hex nodes
|
||||||
bool addedQuickConvert = false;
|
bool addedQuickConvert = false;
|
||||||
if (node.kind == NodeKind::Hex64) {
|
if (node.kind == NodeKind::Hex64) {
|
||||||
menu.addAction(icon("symbol-numeric.svg"), "Change to uint64_t", [this, nodeId]() {
|
menu.addAction("Change to uint64_t", [this, nodeId]() {
|
||||||
int ni = m_doc->tree.indexOfId(nodeId);
|
int ni = m_doc->tree.indexOfId(nodeId);
|
||||||
if (ni >= 0) changeNodeKind(ni, NodeKind::UInt64);
|
if (ni >= 0) changeNodeKind(ni, NodeKind::UInt64);
|
||||||
});
|
});
|
||||||
menu.addAction(icon("symbol-numeric.svg"), "Change to uint32_t", [this, nodeId]() {
|
menu.addAction("Change to uint32_t", [this, nodeId]() {
|
||||||
int ni = m_doc->tree.indexOfId(nodeId);
|
int ni = m_doc->tree.indexOfId(nodeId);
|
||||||
if (ni >= 0) changeNodeKind(ni, NodeKind::UInt32);
|
if (ni >= 0) changeNodeKind(ni, NodeKind::UInt32);
|
||||||
});
|
});
|
||||||
addedQuickConvert = true;
|
addedQuickConvert = true;
|
||||||
} else if (node.kind == NodeKind::Hex32) {
|
} else if (node.kind == NodeKind::Hex32) {
|
||||||
menu.addAction(icon("symbol-numeric.svg"), "Change to uint32_t", [this, nodeId]() {
|
menu.addAction("Change to uint32_t", [this, nodeId]() {
|
||||||
int ni = m_doc->tree.indexOfId(nodeId);
|
int ni = m_doc->tree.indexOfId(nodeId);
|
||||||
if (ni >= 0) changeNodeKind(ni, NodeKind::UInt32);
|
if (ni >= 0) changeNodeKind(ni, NodeKind::UInt32);
|
||||||
});
|
});
|
||||||
addedQuickConvert = true;
|
addedQuickConvert = true;
|
||||||
} else if (node.kind == NodeKind::Hex16) {
|
} else if (node.kind == NodeKind::Hex16) {
|
||||||
menu.addAction(icon("symbol-numeric.svg"), "Change to int16_t", [this, nodeId]() {
|
menu.addAction("Change to int16_t", [this, nodeId]() {
|
||||||
int ni = m_doc->tree.indexOfId(nodeId);
|
int ni = m_doc->tree.indexOfId(nodeId);
|
||||||
if (ni >= 0) changeNodeKind(ni, NodeKind::Int16);
|
if (ni >= 0) changeNodeKind(ni, NodeKind::Int16);
|
||||||
});
|
});
|
||||||
@@ -1119,7 +1142,6 @@ void RcxController::showContextMenu(RcxEditor* editor, int line, int nodeIdx,
|
|||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
|
|
||||||
bool isEditable = node.kind != NodeKind::Struct && node.kind != NodeKind::Array
|
bool isEditable = node.kind != NodeKind::Struct && node.kind != NodeKind::Array
|
||||||
&& node.kind != NodeKind::Padding
|
|
||||||
&& m_doc->provider->isWritable();
|
&& m_doc->provider->isWritable();
|
||||||
if (isEditable) {
|
if (isEditable) {
|
||||||
menu.addAction(icon("edit.svg"), "Edit &Value\tEnter", [editor, line]() {
|
menu.addAction(icon("edit.svg"), "Edit &Value\tEnter", [editor, line]() {
|
||||||
@@ -1135,6 +1157,51 @@ void RcxController::showContextMenu(RcxEditor* editor, int line, int nodeIdx,
|
|||||||
editor->beginInlineEdit(EditTarget::Type, line);
|
editor->beginInlineEdit(EditTarget::Type, line);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Convert to Hex nodes (decompose non-hex types into Hex64/32/16/8)
|
||||||
|
if (!isHexNode(node.kind) && node.kind != NodeKind::Struct && node.kind != NodeKind::Array) {
|
||||||
|
menu.addAction("Convert to &Hex", [this, nodeId]() {
|
||||||
|
int ni = m_doc->tree.indexOfId(nodeId);
|
||||||
|
if (ni < 0) return;
|
||||||
|
const Node& n = m_doc->tree.nodes[ni];
|
||||||
|
int totalSize = n.byteSize();
|
||||||
|
if (totalSize <= 0) return;
|
||||||
|
|
||||||
|
uint64_t parentId = n.parentId;
|
||||||
|
int baseOffset = n.offset;
|
||||||
|
|
||||||
|
bool wasSuppressed = m_suppressRefresh;
|
||||||
|
m_suppressRefresh = true;
|
||||||
|
m_doc->undoStack.beginMacro(QStringLiteral("Convert to Hex"));
|
||||||
|
|
||||||
|
// Remove the original node
|
||||||
|
QVector<Node> subtree;
|
||||||
|
subtree.append(n);
|
||||||
|
m_doc->undoStack.push(new RcxCommand(this,
|
||||||
|
cmd::Remove{nodeId, subtree, {}}));
|
||||||
|
|
||||||
|
// Insert hex nodes to fill the space (largest first)
|
||||||
|
int padOffset = baseOffset;
|
||||||
|
int gap = totalSize;
|
||||||
|
while (gap > 0) {
|
||||||
|
NodeKind padKind;
|
||||||
|
int padSize;
|
||||||
|
if (gap >= 8) { padKind = NodeKind::Hex64; padSize = 8; }
|
||||||
|
else if (gap >= 4) { padKind = NodeKind::Hex32; padSize = 4; }
|
||||||
|
else if (gap >= 2) { padKind = NodeKind::Hex16; padSize = 2; }
|
||||||
|
else { padKind = NodeKind::Hex8; padSize = 1; }
|
||||||
|
|
||||||
|
insertNode(parentId, padOffset, padKind,
|
||||||
|
QString("pad_%1").arg(padOffset, 2, 16, QChar('0')));
|
||||||
|
padOffset += padSize;
|
||||||
|
gap -= padSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_doc->undoStack.endMacro();
|
||||||
|
m_suppressRefresh = wasSuppressed;
|
||||||
|
if (!m_suppressRefresh) refresh();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
|
|
||||||
if (node.kind == NodeKind::Struct || node.kind == NodeKind::Array) {
|
if (node.kind == NodeKind::Struct || node.kind == NodeKind::Array) {
|
||||||
@@ -1396,17 +1463,17 @@ void RcxController::performRealignment(uint64_t structId, int targetAlign) {
|
|||||||
return tree.nodes[a].offset < tree.nodes[b].offset;
|
return tree.nodes[a].offset < tree.nodes[b].offset;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Separate into real nodes (non-Padding) and padding nodes
|
// Separate into real nodes (non-hex) and hex filler nodes
|
||||||
struct NodeInfo { uint64_t id; int offset; int size; };
|
struct NodeInfo { uint64_t id; int offset; int size; };
|
||||||
QVector<NodeInfo> realNodes;
|
QVector<NodeInfo> realNodes;
|
||||||
QVector<uint64_t> padIds;
|
QVector<uint64_t> hexIds;
|
||||||
|
|
||||||
for (int ci : kids) {
|
for (int ci : kids) {
|
||||||
const Node& child = tree.nodes[ci];
|
const Node& child = tree.nodes[ci];
|
||||||
int sz = (child.kind == NodeKind::Struct || child.kind == NodeKind::Array)
|
int sz = (child.kind == NodeKind::Struct || child.kind == NodeKind::Array)
|
||||||
? tree.structSpan(child.id) : child.byteSize();
|
? tree.structSpan(child.id) : child.byteSize();
|
||||||
if (child.kind == NodeKind::Padding)
|
if (isHexNode(child.kind))
|
||||||
padIds.append(child.id);
|
hexIds.append(child.id);
|
||||||
else
|
else
|
||||||
realNodes.append({child.id, child.offset, sz});
|
realNodes.append({child.id, child.offset, sz});
|
||||||
}
|
}
|
||||||
@@ -1439,7 +1506,7 @@ void RcxController::performRealignment(uint64_t structId, int targetAlign) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if anything actually changes
|
// Check if anything actually changes
|
||||||
if (offChanges.isEmpty() && padIds.isEmpty() && padsNeeded.isEmpty())
|
if (offChanges.isEmpty() && hexIds.isEmpty() && padsNeeded.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Apply as undoable macro
|
// Apply as undoable macro
|
||||||
@@ -1447,14 +1514,14 @@ void RcxController::performRealignment(uint64_t structId, int targetAlign) {
|
|||||||
m_suppressRefresh = true;
|
m_suppressRefresh = true;
|
||||||
m_doc->undoStack.beginMacro(QStringLiteral("Realign to %1").arg(targetAlign));
|
m_doc->undoStack.beginMacro(QStringLiteral("Realign to %1").arg(targetAlign));
|
||||||
|
|
||||||
// 1. Remove all existing Padding nodes (no offset adjustments — we recompute)
|
// 1. Remove all existing hex filler nodes (no offset adjustments — we recompute)
|
||||||
for (uint64_t pid : padIds) {
|
for (uint64_t hid : hexIds) {
|
||||||
int idx = tree.indexOfId(pid);
|
int idx = tree.indexOfId(hid);
|
||||||
if (idx < 0) continue;
|
if (idx < 0) continue;
|
||||||
QVector<Node> subtree;
|
QVector<Node> subtree;
|
||||||
subtree.append(tree.nodes[idx]);
|
subtree.append(tree.nodes[idx]);
|
||||||
m_doc->undoStack.push(new RcxCommand(this,
|
m_doc->undoStack.push(new RcxCommand(this,
|
||||||
cmd::Remove{pid, subtree, {}}));
|
cmd::Remove{hid, subtree, {}}));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Reposition real nodes
|
// 2. Reposition real nodes
|
||||||
@@ -1463,15 +1530,28 @@ void RcxController::performRealignment(uint64_t structId, int targetAlign) {
|
|||||||
cmd::ChangeOffset{oc.id, oc.oldOff, oc.newOff}));
|
cmd::ChangeOffset{oc.id, oc.oldOff, oc.newOff}));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Insert new padding in gaps
|
// 3. Insert hex nodes to fill gaps (largest first for alignment)
|
||||||
for (const auto& pi : padsNeeded) {
|
for (const auto& pi : padsNeeded) {
|
||||||
Node pad;
|
int padOffset = pi.offset;
|
||||||
pad.kind = NodeKind::Padding;
|
int gap = pi.size;
|
||||||
pad.parentId = structId;
|
while (gap > 0) {
|
||||||
pad.offset = pi.offset;
|
NodeKind padKind;
|
||||||
pad.arrayLen = pi.size;
|
int padSize;
|
||||||
pad.id = tree.reserveId();
|
if (gap >= 8) { padKind = NodeKind::Hex64; padSize = 8; }
|
||||||
m_doc->undoStack.push(new RcxCommand(this, cmd::Insert{pad}));
|
else if (gap >= 4) { padKind = NodeKind::Hex32; padSize = 4; }
|
||||||
|
else if (gap >= 2) { padKind = NodeKind::Hex16; padSize = 2; }
|
||||||
|
else { padKind = NodeKind::Hex8; padSize = 1; }
|
||||||
|
|
||||||
|
Node pad;
|
||||||
|
pad.kind = padKind;
|
||||||
|
pad.parentId = structId;
|
||||||
|
pad.offset = padOffset;
|
||||||
|
pad.name = QString("pad_%1").arg(padOffset, 2, 16, QChar('0'));
|
||||||
|
pad.id = tree.reserveId();
|
||||||
|
m_doc->undoStack.push(new RcxCommand(this, cmd::Insert{pad}));
|
||||||
|
padOffset += padSize;
|
||||||
|
gap -= padSize;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_doc->undoStack.endMacro();
|
m_doc->undoStack.endMacro();
|
||||||
@@ -1575,7 +1655,6 @@ void RcxController::showTypePopup(RcxEditor* editor, TypePopupMode mode,
|
|||||||
|
|
||||||
auto addPrimitives = [&](bool enabled, bool excludeStructArrayPad) {
|
auto addPrimitives = [&](bool enabled, bool excludeStructArrayPad) {
|
||||||
for (const auto& m : kKindMeta) {
|
for (const auto& m : kKindMeta) {
|
||||||
if (m.kind == NodeKind::Padding) continue;
|
|
||||||
if (excludeStructArrayPad &&
|
if (excludeStructArrayPad &&
|
||||||
(m.kind == NodeKind::Struct || m.kind == NodeKind::Array))
|
(m.kind == NodeKind::Struct || m.kind == NodeKind::Array))
|
||||||
continue;
|
continue;
|
||||||
@@ -1710,6 +1789,10 @@ void RcxController::showTypePopup(RcxEditor* editor, TypePopupMode mode,
|
|||||||
});
|
});
|
||||||
connect(popup, &TypeSelectorPopup::createNewTypeRequested,
|
connect(popup, &TypeSelectorPopup::createNewTypeRequested,
|
||||||
this, [this, mode, nodeIdx]() {
|
this, [this, mode, nodeIdx]() {
|
||||||
|
bool wasSuppressed = m_suppressRefresh;
|
||||||
|
m_suppressRefresh = true;
|
||||||
|
m_doc->undoStack.beginMacro(QStringLiteral("Create new type"));
|
||||||
|
|
||||||
Node n;
|
Node n;
|
||||||
n.kind = NodeKind::Struct;
|
n.kind = NodeKind::Struct;
|
||||||
n.name = QString();
|
n.name = QString();
|
||||||
@@ -1717,6 +1800,16 @@ void RcxController::showTypePopup(RcxEditor* editor, TypePopupMode mode,
|
|||||||
n.offset = 0;
|
n.offset = 0;
|
||||||
n.id = m_doc->tree.reserveId();
|
n.id = m_doc->tree.reserveId();
|
||||||
m_doc->undoStack.push(new RcxCommand(this, cmd::Insert{n}));
|
m_doc->undoStack.push(new RcxCommand(this, cmd::Insert{n}));
|
||||||
|
|
||||||
|
// Populate with default hex nodes (8 x Hex64 = 64 bytes)
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
insertNode(n.id, i * 8, NodeKind::Hex64,
|
||||||
|
QString("field_%1").arg(i * 8, 2, 16, QChar('0')));
|
||||||
|
}
|
||||||
|
|
||||||
|
m_doc->undoStack.endMacro();
|
||||||
|
m_suppressRefresh = wasSuppressed;
|
||||||
|
|
||||||
TypeEntry newEntry;
|
TypeEntry newEntry;
|
||||||
newEntry.entryKind = TypeEntry::Composite;
|
newEntry.entryKind = TypeEntry::Composite;
|
||||||
newEntry.structId = n.id;
|
newEntry.structId = n.id;
|
||||||
@@ -1735,14 +1828,22 @@ void RcxController::applyTypePopupResult(TypePopupMode mode, int nodeIdx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (nodeIdx < 0 || nodeIdx >= m_doc->tree.nodes.size()) return;
|
if (nodeIdx < 0 || nodeIdx >= m_doc->tree.nodes.size()) return;
|
||||||
const Node& node = m_doc->tree.nodes[nodeIdx];
|
|
||||||
|
// BUG-1 fix: Copy needed fields to locals before any mutation.
|
||||||
|
// changeNodeKind() can trigger insertNode() → addNode() → nodes.append(),
|
||||||
|
// which may reallocate the QVector, invalidating any reference into it.
|
||||||
|
const uint64_t nodeId = m_doc->tree.nodes[nodeIdx].id;
|
||||||
|
const NodeKind nodeKind = m_doc->tree.nodes[nodeIdx].kind;
|
||||||
|
const NodeKind elemKind = m_doc->tree.nodes[nodeIdx].elementKind;
|
||||||
|
const uint64_t nodeRefId = m_doc->tree.nodes[nodeIdx].refId;
|
||||||
|
const int arrLen = m_doc->tree.nodes[nodeIdx].arrayLen;
|
||||||
|
|
||||||
// Parse the full text for modifiers (e.g. "int32_t[10]", "Ball*")
|
// Parse the full text for modifiers (e.g. "int32_t[10]", "Ball*")
|
||||||
TypeSpec spec = parseTypeSpec(fullText);
|
TypeSpec spec = parseTypeSpec(fullText);
|
||||||
|
|
||||||
if (mode == TypePopupMode::FieldType) {
|
if (mode == TypePopupMode::FieldType) {
|
||||||
if (entry.entryKind == TypeEntry::Primitive) {
|
if (entry.entryKind == TypeEntry::Primitive) {
|
||||||
if (entry.primitiveKind != node.kind)
|
if (entry.primitiveKind != nodeKind)
|
||||||
changeNodeKind(nodeIdx, entry.primitiveKind);
|
changeNodeKind(nodeIdx, entry.primitiveKind);
|
||||||
} else if (entry.entryKind == TypeEntry::Composite) {
|
} else if (entry.entryKind == TypeEntry::Composite) {
|
||||||
bool wasSuppressed = m_suppressRefresh;
|
bool wasSuppressed = m_suppressRefresh;
|
||||||
@@ -1751,34 +1852,34 @@ void RcxController::applyTypePopupResult(TypePopupMode mode, int nodeIdx,
|
|||||||
|
|
||||||
if (spec.isPointer) {
|
if (spec.isPointer) {
|
||||||
// Pointer modifier: e.g. "Material*" → Pointer64 + refId
|
// Pointer modifier: e.g. "Material*" → Pointer64 + refId
|
||||||
if (node.kind != NodeKind::Pointer64)
|
if (nodeKind != NodeKind::Pointer64)
|
||||||
changeNodeKind(nodeIdx, NodeKind::Pointer64);
|
changeNodeKind(nodeIdx, NodeKind::Pointer64);
|
||||||
int idx = m_doc->tree.indexOfId(node.id);
|
int idx = m_doc->tree.indexOfId(nodeId);
|
||||||
if (idx >= 0 && m_doc->tree.nodes[idx].refId != entry.structId)
|
if (idx >= 0 && m_doc->tree.nodes[idx].refId != entry.structId)
|
||||||
m_doc->undoStack.push(new RcxCommand(this,
|
m_doc->undoStack.push(new RcxCommand(this,
|
||||||
cmd::ChangePointerRef{node.id, m_doc->tree.nodes[idx].refId, entry.structId}));
|
cmd::ChangePointerRef{nodeId, m_doc->tree.nodes[idx].refId, entry.structId}));
|
||||||
|
|
||||||
} else if (spec.arrayCount > 0) {
|
} else if (spec.arrayCount > 0) {
|
||||||
// Array modifier: e.g. "Material[10]" → Array + Struct element
|
// Array modifier: e.g. "Material[10]" → Array + Struct element
|
||||||
if (node.kind != NodeKind::Array)
|
if (nodeKind != NodeKind::Array)
|
||||||
changeNodeKind(nodeIdx, NodeKind::Array);
|
changeNodeKind(nodeIdx, NodeKind::Array);
|
||||||
int idx = m_doc->tree.indexOfId(node.id);
|
int idx = m_doc->tree.indexOfId(nodeId);
|
||||||
if (idx >= 0) {
|
if (idx >= 0) {
|
||||||
auto& n = m_doc->tree.nodes[idx];
|
auto& n = m_doc->tree.nodes[idx];
|
||||||
if (n.elementKind != NodeKind::Struct || n.arrayLen != spec.arrayCount)
|
if (n.elementKind != NodeKind::Struct || n.arrayLen != spec.arrayCount)
|
||||||
m_doc->undoStack.push(new RcxCommand(this,
|
m_doc->undoStack.push(new RcxCommand(this,
|
||||||
cmd::ChangeArrayMeta{node.id, n.elementKind, NodeKind::Struct,
|
cmd::ChangeArrayMeta{nodeId, n.elementKind, NodeKind::Struct,
|
||||||
n.arrayLen, spec.arrayCount}));
|
n.arrayLen, spec.arrayCount}));
|
||||||
if (n.refId != entry.structId)
|
if (n.refId != entry.structId)
|
||||||
m_doc->undoStack.push(new RcxCommand(this,
|
m_doc->undoStack.push(new RcxCommand(this,
|
||||||
cmd::ChangePointerRef{node.id, n.refId, entry.structId}));
|
cmd::ChangePointerRef{nodeId, n.refId, entry.structId}));
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Plain struct: e.g. "Material" → Struct + structTypeName + refId + collapsed
|
// Plain struct: e.g. "Material" → Struct + structTypeName + refId + collapsed
|
||||||
if (node.kind != NodeKind::Struct)
|
if (nodeKind != NodeKind::Struct)
|
||||||
changeNodeKind(nodeIdx, NodeKind::Struct);
|
changeNodeKind(nodeIdx, NodeKind::Struct);
|
||||||
int idx = m_doc->tree.indexOfId(node.id);
|
int idx = m_doc->tree.indexOfId(nodeId);
|
||||||
if (idx >= 0) {
|
if (idx >= 0) {
|
||||||
int refIdx = m_doc->tree.indexOfId(entry.structId);
|
int refIdx = m_doc->tree.indexOfId(entry.structId);
|
||||||
QString targetName;
|
QString targetName;
|
||||||
@@ -1789,11 +1890,11 @@ void RcxController::applyTypePopupResult(TypePopupMode mode, int nodeIdx,
|
|||||||
QString oldTypeName = m_doc->tree.nodes[idx].structTypeName;
|
QString oldTypeName = m_doc->tree.nodes[idx].structTypeName;
|
||||||
if (oldTypeName != targetName)
|
if (oldTypeName != targetName)
|
||||||
m_doc->undoStack.push(new RcxCommand(this,
|
m_doc->undoStack.push(new RcxCommand(this,
|
||||||
cmd::ChangeStructTypeName{node.id, oldTypeName, targetName}));
|
cmd::ChangeStructTypeName{nodeId, oldTypeName, targetName}));
|
||||||
// Set refId so compose can expand the referenced struct's children
|
// Set refId so compose can expand the referenced struct's children
|
||||||
if (m_doc->tree.nodes[idx].refId != entry.structId)
|
if (m_doc->tree.nodes[idx].refId != entry.structId)
|
||||||
m_doc->undoStack.push(new RcxCommand(this,
|
m_doc->undoStack.push(new RcxCommand(this,
|
||||||
cmd::ChangePointerRef{node.id, m_doc->tree.nodes[idx].refId, entry.structId}));
|
cmd::ChangePointerRef{nodeId, m_doc->tree.nodes[idx].refId, entry.structId}));
|
||||||
// ChangePointerRef auto-sets collapsed=true when refId != 0
|
// ChangePointerRef auto-sets collapsed=true when refId != 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1804,33 +1905,32 @@ void RcxController::applyTypePopupResult(TypePopupMode mode, int nodeIdx,
|
|||||||
}
|
}
|
||||||
} else if (mode == TypePopupMode::ArrayElement) {
|
} else if (mode == TypePopupMode::ArrayElement) {
|
||||||
if (entry.entryKind == TypeEntry::Primitive) {
|
if (entry.entryKind == TypeEntry::Primitive) {
|
||||||
if (entry.primitiveKind != node.elementKind) {
|
if (entry.primitiveKind != elemKind) {
|
||||||
m_doc->undoStack.push(new RcxCommand(this,
|
m_doc->undoStack.push(new RcxCommand(this,
|
||||||
cmd::ChangeArrayMeta{node.id,
|
cmd::ChangeArrayMeta{nodeId,
|
||||||
node.elementKind, entry.primitiveKind,
|
elemKind, entry.primitiveKind,
|
||||||
node.arrayLen, node.arrayLen}));
|
arrLen, arrLen}));
|
||||||
}
|
}
|
||||||
} else if (entry.entryKind == TypeEntry::Composite) {
|
} else if (entry.entryKind == TypeEntry::Composite) {
|
||||||
if (node.elementKind != NodeKind::Struct || node.refId != entry.structId) {
|
if (elemKind != NodeKind::Struct || nodeRefId != entry.structId) {
|
||||||
m_doc->undoStack.push(new RcxCommand(this,
|
m_doc->undoStack.push(new RcxCommand(this,
|
||||||
cmd::ChangeArrayMeta{node.id,
|
cmd::ChangeArrayMeta{nodeId,
|
||||||
node.elementKind, NodeKind::Struct,
|
elemKind, NodeKind::Struct,
|
||||||
node.arrayLen, node.arrayLen}));
|
arrLen, arrLen}));
|
||||||
if (node.refId != entry.structId) {
|
if (nodeRefId != entry.structId) {
|
||||||
m_doc->undoStack.push(new RcxCommand(this,
|
m_doc->undoStack.push(new RcxCommand(this,
|
||||||
cmd::ChangePointerRef{node.id, node.refId, entry.structId}));
|
cmd::ChangePointerRef{nodeId, nodeRefId, entry.structId}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (mode == TypePopupMode::PointerTarget) {
|
} else if (mode == TypePopupMode::PointerTarget) {
|
||||||
// "void" entry → refId 0; composite entry → real structId
|
// "void" entry → refId 0; composite entry → real structId
|
||||||
uint64_t realRefId = (entry.entryKind == TypeEntry::Composite) ? entry.structId : 0;
|
uint64_t realRefId = (entry.entryKind == TypeEntry::Composite) ? entry.structId : 0;
|
||||||
if (realRefId != node.refId) {
|
if (realRefId != nodeRefId) {
|
||||||
m_doc->undoStack.push(new RcxCommand(this,
|
m_doc->undoStack.push(new RcxCommand(this,
|
||||||
cmd::ChangePointerRef{node.id, node.refId, realRefId}));
|
cmd::ChangePointerRef{nodeId, nodeRefId, realRefId}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
refresh();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RcxController::attachViaPlugin(const QString& providerIdentifier, const QString& target) {
|
void RcxController::attachViaPlugin(const QString& providerIdentifier, const QString& target) {
|
||||||
@@ -1913,11 +2013,11 @@ void RcxController::setupAutoRefresh() {
|
|||||||
void RcxController::collectPointerRanges(
|
void RcxController::collectPointerRanges(
|
||||||
uint64_t structId, uint64_t memBase,
|
uint64_t structId, uint64_t memBase,
|
||||||
int depth, int maxDepth,
|
int depth, int maxDepth,
|
||||||
QSet<uint64_t>& visited,
|
QSet<QPair<uint64_t,uint64_t>>& visited,
|
||||||
QVector<QPair<uint64_t,int>>& ranges) const
|
QVector<QPair<uint64_t,int>>& ranges) const
|
||||||
{
|
{
|
||||||
if (depth >= maxDepth) return;
|
if (depth >= maxDepth) return;
|
||||||
uint64_t key = memBase ^ (structId * 0x9E3779B97F4A7C15ULL);
|
QPair<uint64_t,uint64_t> key{structId, memBase};
|
||||||
if (visited.contains(key)) return;
|
if (visited.contains(key)) return;
|
||||||
visited.insert(key);
|
visited.insert(key);
|
||||||
|
|
||||||
@@ -1974,11 +2074,11 @@ void RcxController::onRefreshTick() {
|
|||||||
ranges.append({0, extent});
|
ranges.append({0, extent});
|
||||||
|
|
||||||
if (m_snapshotProv) {
|
if (m_snapshotProv) {
|
||||||
QSet<uint64_t> visited;
|
QSet<QPair<uint64_t,uint64_t>> visited;
|
||||||
uint64_t rootId = m_viewRootId;
|
uint64_t rootId = m_viewRootId;
|
||||||
if (rootId == 0 && !m_doc->tree.nodes.isEmpty())
|
if (rootId == 0 && !m_doc->tree.nodes.isEmpty())
|
||||||
rootId = m_doc->tree.nodes[0].id;
|
rootId = m_doc->tree.nodes[0].id;
|
||||||
collectPointerRanges(rootId, 0, 0, 4, visited, ranges);
|
collectPointerRanges(rootId, 0, 0, 99, visited, ranges);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_readInFlight = true;
|
m_readInFlight = true;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include <QUndoCommand>
|
#include <QUndoCommand>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QFutureWatcher>
|
#include <QFutureWatcher>
|
||||||
|
#include <QPointer>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace rcx {
|
namespace rcx {
|
||||||
@@ -138,7 +139,7 @@ private:
|
|||||||
int m_activeSourceIdx = -1;
|
int m_activeSourceIdx = -1;
|
||||||
|
|
||||||
// ── Cached type selector popup (avoids ~350ms cold-start on first show) ──
|
// ── Cached type selector popup (avoids ~350ms cold-start on first show) ──
|
||||||
TypeSelectorPopup* m_cachedPopup = nullptr;
|
QPointer<TypeSelectorPopup> m_cachedPopup;
|
||||||
|
|
||||||
// ── Auto-refresh state ──
|
// ── Auto-refresh state ──
|
||||||
using PageMap = QHash<uint64_t, QByteArray>;
|
using PageMap = QHash<uint64_t, QByteArray>;
|
||||||
@@ -169,7 +170,7 @@ private:
|
|||||||
void resetSnapshot();
|
void resetSnapshot();
|
||||||
void collectPointerRanges(uint64_t structId, uint64_t memBase,
|
void collectPointerRanges(uint64_t structId, uint64_t memBase,
|
||||||
int depth, int maxDepth,
|
int depth, int maxDepth,
|
||||||
QSet<uint64_t>& visited,
|
QSet<QPair<uint64_t,uint64_t>>& visited,
|
||||||
QVector<QPair<uint64_t,int>>& ranges) const;
|
QVector<QPair<uint64_t,int>>& ranges) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
34
src/core.h
34
src/core.h
@@ -27,21 +27,20 @@ enum class NodeKind : uint8_t {
|
|||||||
Pointer32, Pointer64,
|
Pointer32, Pointer64,
|
||||||
Vec2, Vec3, Vec4, Mat4x4,
|
Vec2, Vec3, Vec4, Mat4x4,
|
||||||
UTF8, UTF16,
|
UTF8, UTF16,
|
||||||
Padding,
|
|
||||||
Struct, Array
|
Struct, Array
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace rcx (temporarily close for qHash)
|
} // namespace rcx (temporarily close for qHash)
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||||
inline uint qHash(rcx::NodeKind key, uint seed = 0) { return ::qHash(static_cast<uint8_t>(key), seed); }
|
inline uint qHash(rcx::NodeKind key, uint seed = 0) { return qHash(static_cast<int>(key), seed); }
|
||||||
#endif
|
#endif
|
||||||
namespace rcx { // reopen
|
namespace rcx { // reopen
|
||||||
|
|
||||||
// ── Kind flags (replaces repeated Hex/Padding switches) ──
|
// ── Kind flags (replaces repeated Hex switches) ──
|
||||||
|
|
||||||
enum KindFlags : uint32_t {
|
enum KindFlags : uint32_t {
|
||||||
KF_None = 0,
|
KF_None = 0,
|
||||||
KF_HexPreview = 1 << 0, // Hex8..Hex64 + Padding (ASCII+hex layout)
|
KF_HexPreview = 1 << 0, // Hex8..Hex64 (ASCII+hex layout)
|
||||||
KF_Container = 1 << 1, // Struct/Array
|
KF_Container = 1 << 1, // Struct/Array
|
||||||
KF_String = 1 << 2, // UTF8/UTF16
|
KF_String = 1 << 2, // UTF8/UTF16
|
||||||
KF_Vector = 1 << 3, // Vec2/3/4
|
KF_Vector = 1 << 3, // Vec2/3/4
|
||||||
@@ -84,7 +83,6 @@ inline constexpr KindMeta kKindMeta[] = {
|
|||||||
{NodeKind::Mat4x4, "Mat4x4", "mat4x4", 64, 4, 4, KF_None},
|
{NodeKind::Mat4x4, "Mat4x4", "mat4x4", 64, 4, 4, KF_None},
|
||||||
{NodeKind::UTF8, "UTF8", "char[]", 1, 1, 1, KF_String},
|
{NodeKind::UTF8, "UTF8", "char[]", 1, 1, 1, KF_String},
|
||||||
{NodeKind::UTF16, "UTF16", "wchar_t[]", 2, 1, 2, KF_String},
|
{NodeKind::UTF16, "UTF16", "wchar_t[]", 2, 1, 2, KF_String},
|
||||||
{NodeKind::Padding, "Padding", "pad", 1, 1, 1, KF_HexPreview},
|
|
||||||
{NodeKind::Struct, "Struct", "struct", 0, 1, 1, KF_Container},
|
{NodeKind::Struct, "Struct", "struct", 0, 1, 1, KF_Container},
|
||||||
{NodeKind::Array, "Array", "array", 0, 1, 1, KF_Container},
|
{NodeKind::Array, "Array", "array", 0, 1, 1, KF_Container},
|
||||||
};
|
};
|
||||||
@@ -155,7 +153,6 @@ inline QStringList allTypeNamesForUI(bool stripBrackets = false) {
|
|||||||
|
|
||||||
enum Marker : int {
|
enum Marker : int {
|
||||||
M_CONT = 0,
|
M_CONT = 0,
|
||||||
M_PAD = 1,
|
|
||||||
M_PTR0 = 2,
|
M_PTR0 = 2,
|
||||||
M_CYCLE = 3,
|
M_CYCLE = 3,
|
||||||
M_ERR = 4,
|
M_ERR = 4,
|
||||||
@@ -187,9 +184,12 @@ struct Node {
|
|||||||
int byteSize() const {
|
int byteSize() const {
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
case NodeKind::UTF8: return strLen;
|
case NodeKind::UTF8: return strLen;
|
||||||
case NodeKind::UTF16: return strLen * 2;
|
case NodeKind::UTF16: return qMin(strLen, INT_MAX / 2) * 2;
|
||||||
case NodeKind::Padding: return qMax(1, arrayLen);
|
case NodeKind::Array: {
|
||||||
case NodeKind::Array: return arrayLen * sizeForKind(elementKind);
|
int elemSz = sizeForKind(elementKind);
|
||||||
|
if (elemSz <= 0) return 0;
|
||||||
|
return qMin(arrayLen, INT_MAX / elemSz) * elemSz;
|
||||||
|
}
|
||||||
default: return sizeForKind(kind);
|
default: return sizeForKind(kind);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -221,8 +221,8 @@ struct Node {
|
|||||||
n.classKeyword = o["classKeyword"].toString();
|
n.classKeyword = o["classKeyword"].toString();
|
||||||
n.parentId = o["parentId"].toString("0").toULongLong();
|
n.parentId = o["parentId"].toString("0").toULongLong();
|
||||||
n.offset = o["offset"].toInt(0);
|
n.offset = o["offset"].toInt(0);
|
||||||
n.arrayLen = o["arrayLen"].toInt(1);
|
n.arrayLen = qBound(1, o["arrayLen"].toInt(1), 1000000);
|
||||||
n.strLen = o["strLen"].toInt(64);
|
n.strLen = qBound(1, o["strLen"].toInt(64), 1000000);
|
||||||
n.collapsed = o["collapsed"].toBool(false);
|
n.collapsed = o["collapsed"].toBool(false);
|
||||||
n.refId = o["refId"].toString("0").toULongLong();
|
n.refId = o["refId"].toString("0").toULongLong();
|
||||||
n.elementKind = kindFromString(o["elementKind"].toString("UInt8"));
|
n.elementKind = kindFromString(o["elementKind"].toString("UInt8"));
|
||||||
@@ -535,7 +535,7 @@ inline ColumnSpan nameSpanFor(const LineMeta& lm, int typeW = kColType, int name
|
|||||||
int ind = kFoldCol + lm.depth * 3;
|
int ind = kFoldCol + lm.depth * 3;
|
||||||
int start = ind + typeW + kSepWidth;
|
int start = ind + typeW + kSepWidth;
|
||||||
|
|
||||||
// Hex/Padding: ASCII preview occupies the name column (padded to nameW)
|
// Hex: ASCII preview occupies the name column (padded to nameW)
|
||||||
if (isHexPreview(lm.nodeKind))
|
if (isHexPreview(lm.nodeKind))
|
||||||
return {start, start + nameW, true};
|
return {start, start + nameW, true};
|
||||||
|
|
||||||
@@ -547,9 +547,9 @@ inline ColumnSpan valueSpanFor(const LineMeta& lm, int /*lineLength*/, int typeW
|
|||||||
lm.lineKind == LineKind::ArrayElementSeparator) return {};
|
lm.lineKind == LineKind::ArrayElementSeparator) return {};
|
||||||
int ind = kFoldCol + lm.depth * 3;
|
int ind = kFoldCol + lm.depth * 3;
|
||||||
|
|
||||||
// Hex/Padding uses nameW for ASCII column (same as regular name column)
|
// Hex uses nameW for ASCII column (same as regular name column)
|
||||||
bool isHexPad = isHexPreview(lm.nodeKind);
|
bool isHex = isHexPreview(lm.nodeKind);
|
||||||
int valWidth = isHexPad ? 23 : kColValue;
|
int valWidth = isHex ? 23 : kColValue;
|
||||||
|
|
||||||
int prefixW = typeW + nameW + 2 * kSepWidth;
|
int prefixW = typeW + nameW + 2 * kSepWidth;
|
||||||
|
|
||||||
@@ -567,8 +567,8 @@ inline ColumnSpan commentSpanFor(const LineMeta& lm, int lineLength, int typeW =
|
|||||||
if (lm.lineKind == LineKind::Header || lm.lineKind == LineKind::Footer) return {};
|
if (lm.lineKind == LineKind::Header || lm.lineKind == LineKind::Footer) return {};
|
||||||
int ind = kFoldCol + lm.depth * 3;
|
int ind = kFoldCol + lm.depth * 3;
|
||||||
|
|
||||||
bool isHexPad = isHexPreview(lm.nodeKind);
|
bool isHex = isHexPreview(lm.nodeKind);
|
||||||
int valWidth = isHexPad ? 23 : kColValue;
|
int valWidth = isHex ? 23 : kColValue;
|
||||||
|
|
||||||
int prefixW = typeW + nameW + 2 * kSepWidth;
|
int prefixW = typeW + nameW + 2 * kSepWidth;
|
||||||
int start;
|
int start;
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ void RcxEditor::setupScintilla() {
|
|||||||
m_sci->SendScintilla(QsciScintillaBase::SCI_INDICSETSTYLE,
|
m_sci->SendScintilla(QsciScintillaBase::SCI_INDICSETSTYLE,
|
||||||
IND_EDITABLE, 5 /*INDIC_HIDDEN*/);
|
IND_EDITABLE, 5 /*INDIC_HIDDEN*/);
|
||||||
|
|
||||||
// Hex/Padding node dim indicator — overrides text color
|
// Hex node dim indicator — overrides text color
|
||||||
m_sci->SendScintilla(QsciScintillaBase::SCI_INDICSETSTYLE,
|
m_sci->SendScintilla(QsciScintillaBase::SCI_INDICSETSTYLE,
|
||||||
IND_HEX_DIM, 17 /*INDIC_TEXTFORE*/);
|
IND_HEX_DIM, 17 /*INDIC_TEXTFORE*/);
|
||||||
|
|
||||||
@@ -241,9 +241,6 @@ void RcxEditor::setupMarkers() {
|
|||||||
// M_CONT (0): continuation line (metadata only, no visual)
|
// M_CONT (0): continuation line (metadata only, no visual)
|
||||||
m_sci->markerDefine(QsciScintilla::Invisible, M_CONT);
|
m_sci->markerDefine(QsciScintilla::Invisible, M_CONT);
|
||||||
|
|
||||||
// M_PAD (1): padding line (metadata only, no visual)
|
|
||||||
m_sci->markerDefine(QsciScintilla::Invisible, M_PAD);
|
|
||||||
|
|
||||||
// M_PTR0 (2): right triangle
|
// M_PTR0 (2): right triangle
|
||||||
m_sci->markerDefine(QsciScintilla::RightTriangle, M_PTR0);
|
m_sci->markerDefine(QsciScintilla::RightTriangle, M_PTR0);
|
||||||
|
|
||||||
@@ -1038,9 +1035,6 @@ bool RcxEditor::resolvedSpanFor(int line, EditTarget t,
|
|||||||
|
|
||||||
if (lm->nodeIdx < 0) return false;
|
if (lm->nodeIdx < 0) return false;
|
||||||
|
|
||||||
// Padding: reject value editing (hex bytes are display-only)
|
|
||||||
if (t == EditTarget::Value && lm->nodeKind == NodeKind::Padding)
|
|
||||||
return false;
|
|
||||||
// Hex nodes: only Type is editable (ASCII preview + hex bytes are display-only)
|
// Hex nodes: only Type is editable (ASCII preview + hex bytes are display-only)
|
||||||
if ((t == EditTarget::Name || t == EditTarget::Value) && isHexNode(lm->nodeKind))
|
if ((t == EditTarget::Name || t == EditTarget::Value) && isHexNode(lm->nodeKind))
|
||||||
return false;
|
return false;
|
||||||
@@ -1221,9 +1215,6 @@ static bool hitTestTarget(QsciScintilla* sci,
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Padding nodes: hex bytes are display-only, not editable
|
|
||||||
if (outTarget == EditTarget::Value && lm.nodeKind == NodeKind::Padding)
|
|
||||||
return false;
|
|
||||||
// Hex nodes: only Type is editable (ASCII preview + hex bytes are display-only)
|
// Hex nodes: only Type is editable (ASCII preview + hex bytes are display-only)
|
||||||
if ((outTarget == EditTarget::Name || outTarget == EditTarget::Value) && isHexNode(lm.nodeKind))
|
if ((outTarget == EditTarget::Name || outTarget == EditTarget::Value) && isHexNode(lm.nodeKind))
|
||||||
return false;
|
return false;
|
||||||
@@ -1330,7 +1321,15 @@ bool RcxEditor::eventFilter(QObject* obj, QEvent* event) {
|
|||||||
// Single-click on editable token of already-selected node → edit
|
// Single-click on editable token of already-selected node → edit
|
||||||
int tLine, tCol; EditTarget t;
|
int tLine, tCol; EditTarget t;
|
||||||
if (hitTestTarget(m_sci, m_meta, me->pos(), tLine, tCol, t)) {
|
if (hitTestTarget(m_sci, m_meta, me->pos(), tLine, tCol, t)) {
|
||||||
if (alreadySelected && plain) {
|
// Type/ArrayElementType/PointerTarget open a dismissible popup
|
||||||
|
// (not inline text edit), so allow on first click without
|
||||||
|
// requiring the node to be pre-selected.
|
||||||
|
bool isPopupTarget = (t == EditTarget::Type
|
||||||
|
|| t == EditTarget::ArrayElementType
|
||||||
|
|| t == EditTarget::PointerTarget);
|
||||||
|
if ((alreadySelected || isPopupTarget) && plain) {
|
||||||
|
if (!alreadySelected)
|
||||||
|
emit nodeClicked(h.line, h.nodeId, me->modifiers());
|
||||||
m_pendingClickNodeId = 0;
|
m_pendingClickNodeId = 0;
|
||||||
return beginInlineEdit(t, tLine, tCol);
|
return beginInlineEdit(t, tLine, tCol);
|
||||||
}
|
}
|
||||||
@@ -1402,7 +1401,11 @@ bool RcxEditor::eventFilter(QObject* obj, QEvent* event) {
|
|||||||
auto* me = static_cast<QMouseEvent*>(event);
|
auto* me = static_cast<QMouseEvent*>(event);
|
||||||
int margin0Width = (int)m_sci->SendScintilla(
|
int margin0Width = (int)m_sci->SendScintilla(
|
||||||
QsciScintillaBase::SCI_GETMARGINWIDTHN, 0UL, 0L);
|
QsciScintillaBase::SCI_GETMARGINWIDTHN, 0UL, 0L);
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||||
if ((int)me->position().x() < margin0Width) {
|
if ((int)me->position().x() < margin0Width) {
|
||||||
|
#else
|
||||||
|
if ((int)me->pos().x() < margin0Width) {
|
||||||
|
#endif
|
||||||
m_relativeOffsets = !m_relativeOffsets;
|
m_relativeOffsets = !m_relativeOffsets;
|
||||||
reformatMargins();
|
reformatMargins();
|
||||||
return true;
|
return true;
|
||||||
@@ -1673,9 +1676,6 @@ bool RcxEditor::beginInlineEdit(EditTarget target, int line, int col) {
|
|||||||
(target == EditTarget::BaseAddress || target == EditTarget::Source
|
(target == EditTarget::BaseAddress || target == EditTarget::Source
|
||||||
|| target == EditTarget::RootClassType || target == EditTarget::RootClassName)))
|
|| target == EditTarget::RootClassType || target == EditTarget::RootClassName)))
|
||||||
return false;
|
return false;
|
||||||
// Padding: reject value editing (display-only hex bytes)
|
|
||||||
if (target == EditTarget::Value && lm->nodeKind == NodeKind::Padding)
|
|
||||||
return false;
|
|
||||||
// Hex nodes: only Type is editable (ASCII preview + hex bytes are display-only)
|
// Hex nodes: only Type is editable (ASCII preview + hex bytes are display-only)
|
||||||
if ((target == EditTarget::Name || target == EditTarget::Value) && isHexNode(lm->nodeKind))
|
if ((target == EditTarget::Name || target == EditTarget::Value) && isHexNode(lm->nodeKind))
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -293,7 +293,6 @@ static QString readValueImpl(const Node& node, const Provider& prov,
|
|||||||
line += QStringLiteral("]");
|
line += QStringLiteral("]");
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
case NodeKind::Padding: return display ? hexVal(prov.readU8(addr)) : rawHex(prov.readU8(addr), 2);
|
|
||||||
case NodeKind::UTF8: {
|
case NodeKind::UTF8: {
|
||||||
QByteArray bytes = prov.readBytes(addr, node.strLen);
|
QByteArray bytes = prov.readBytes(addr, node.strLen);
|
||||||
int end = bytes.indexOf('\0');
|
int end = bytes.indexOf('\0');
|
||||||
@@ -344,21 +343,8 @@ QString fmtNodeLine(const Node& node, const Provider& prov,
|
|||||||
return ind + QString(prefixW, ' ') + val + cmtSuffix;
|
return ind + QString(prefixW, ' ') + val + cmtSuffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hex nodes and Padding: hex byte preview (ASCII padded to colName to align with value column)
|
// Hex nodes: hex byte preview (ASCII padded to colName to align with value column)
|
||||||
if (isHexPreview(node.kind)) {
|
if (isHexPreview(node.kind)) {
|
||||||
if (node.kind == NodeKind::Padding) {
|
|
||||||
const int totalSz = qMax(1, node.arrayLen);
|
|
||||||
const int lineOff = subLine * 8;
|
|
||||||
const int lineBytes = qMin(8, totalSz - lineOff);
|
|
||||||
QByteArray b = prov.isReadable(addr + lineOff, lineBytes)
|
|
||||||
? prov.readBytes(addr + lineOff, lineBytes) : QByteArray(lineBytes, '\0');
|
|
||||||
QString ascii = bytesToAscii(b, lineBytes).leftJustified(colName, ' ');
|
|
||||||
QString hex = bytesToHex(b, lineBytes).leftJustified(23, ' '); // 8*3-1
|
|
||||||
if (subLine == 0)
|
|
||||||
return ind + type + SEP + ascii + SEP + hex + cmtSuffix;
|
|
||||||
return ind + QString(colType + (int)SEP.size(), ' ') + ascii + SEP + hex + cmtSuffix;
|
|
||||||
}
|
|
||||||
// Hex8..Hex64: single line, ASCII padded to colName so hex column aligns with value column
|
|
||||||
const int sz = sizeForKind(node.kind);
|
const int sz = sizeForKind(node.kind);
|
||||||
QByteArray b = prov.isReadable(addr, sz)
|
QByteArray b = prov.isReadable(addr, sz)
|
||||||
? prov.readBytes(addr, sz) : QByteArray(sz, '\0');
|
? prov.readBytes(addr, sz) : QByteArray(sz, '\0');
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ static QString cTypeName(NodeKind kind) {
|
|||||||
case NodeKind::Mat4x4: return QStringLiteral("float");
|
case NodeKind::Mat4x4: return QStringLiteral("float");
|
||||||
case NodeKind::UTF8: return QStringLiteral("char");
|
case NodeKind::UTF8: return QStringLiteral("char");
|
||||||
case NodeKind::UTF16: return QStringLiteral("wchar_t");
|
case NodeKind::UTF16: return QStringLiteral("wchar_t");
|
||||||
case NodeKind::Padding: return QStringLiteral("uint8_t");
|
|
||||||
default: return QStringLiteral("uint8_t");
|
default: return QStringLiteral("uint8_t");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -123,8 +122,6 @@ static QString emitField(GenContext& ctx, const Node& node) {
|
|||||||
return QStringLiteral(" %1 %2[%3];").arg(ctx.cType(NodeKind::UTF8), name).arg(node.strLen) + oc;
|
return QStringLiteral(" %1 %2[%3];").arg(ctx.cType(NodeKind::UTF8), name).arg(node.strLen) + oc;
|
||||||
case NodeKind::UTF16:
|
case NodeKind::UTF16:
|
||||||
return QStringLiteral(" %1 %2[%3];").arg(ctx.cType(NodeKind::UTF16), name).arg(node.strLen) + oc;
|
return QStringLiteral(" %1 %2[%3];").arg(ctx.cType(NodeKind::UTF16), name).arg(node.strLen) + oc;
|
||||||
case NodeKind::Padding:
|
|
||||||
return QStringLiteral(" %1 %2[%3];").arg(ctx.cType(NodeKind::Padding), name).arg(qMax(1, node.arrayLen)) + oc;
|
|
||||||
case NodeKind::Pointer32: {
|
case NodeKind::Pointer32: {
|
||||||
if (node.refId != 0) {
|
if (node.refId != 0) {
|
||||||
int refIdx = tree.indexOfId(node.refId);
|
int refIdx = tree.indexOfId(node.refId);
|
||||||
@@ -169,7 +166,7 @@ static void emitStructBody(GenContext& ctx, uint64_t structId) {
|
|||||||
auto emitPadRun = [&](int offset, int size) {
|
auto emitPadRun = [&](int offset, int size) {
|
||||||
if (size <= 0) return;
|
if (size <= 0) return;
|
||||||
ctx.output += QStringLiteral(" %1 %2[0x%3];%4\n")
|
ctx.output += QStringLiteral(" %1 %2[0x%3];%4\n")
|
||||||
.arg(ctx.cType(NodeKind::Padding))
|
.arg(QStringLiteral("uint8_t"))
|
||||||
.arg(ctx.uniquePadName())
|
.arg(ctx.uniquePadName())
|
||||||
.arg(QString::number(size, 16).toUpper())
|
.arg(QString::number(size, 16).toUpper())
|
||||||
.arg(offsetComment(offset));
|
.arg(offsetComment(offset));
|
||||||
|
|||||||
311
src/main.cpp
311
src/main.cpp
@@ -43,6 +43,7 @@
|
|||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include "themes/thememanager.h"
|
#include "themes/thememanager.h"
|
||||||
#include "themes/themeeditor.h"
|
#include "themes/themeeditor.h"
|
||||||
|
#include "optionsdialog.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
@@ -141,7 +142,9 @@ public:
|
|||||||
if ((w->windowFlags() & Qt::Window) == Qt::Window
|
if ((w->windowFlags() & Qt::Window) == Qt::Window
|
||||||
&& !w->property("DarkTitleBar").toBool()) {
|
&& !w->property("DarkTitleBar").toBool()) {
|
||||||
w->setProperty("DarkTitleBar", true);
|
w->setProperty("DarkTitleBar", true);
|
||||||
|
#ifdef _WIN32
|
||||||
setDarkTitleBar(w);
|
setDarkTitleBar(w);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return QApplication::notify(receiver, event);
|
return QApplication::notify(receiver, event);
|
||||||
@@ -160,6 +163,13 @@ public:
|
|||||||
s = QSize(s.width() + 24, s.height() + 4);
|
s = QSize(s.width() + 24, s.height() + 4);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
int pixelMetric(PixelMetric metric, const QStyleOption* opt,
|
||||||
|
const QWidget* w) const override {
|
||||||
|
// Kill the 1px frame margin Fusion reserves around QMenu contents
|
||||||
|
if (metric == PM_MenuPanelWidth)
|
||||||
|
return 0;
|
||||||
|
return QProxyStyle::pixelMetric(metric, opt, w);
|
||||||
|
}
|
||||||
void drawPrimitive(PrimitiveElement elem, const QStyleOption* opt,
|
void drawPrimitive(PrimitiveElement elem, const QStyleOption* opt,
|
||||||
QPainter* p, const QWidget* w) const override {
|
QPainter* p, const QWidget* w) const override {
|
||||||
// Kill Fusion's 3D bevel on QMenu — the OS drop shadow is enough
|
// Kill Fusion's 3D bevel on QMenu — the OS drop shadow is enough
|
||||||
@@ -205,13 +215,13 @@ static void applyGlobalTheme(const rcx::Theme& theme) {
|
|||||||
QPalette pal;
|
QPalette pal;
|
||||||
pal.setColor(QPalette::Window, theme.background);
|
pal.setColor(QPalette::Window, theme.background);
|
||||||
pal.setColor(QPalette::WindowText, theme.text);
|
pal.setColor(QPalette::WindowText, theme.text);
|
||||||
pal.setColor(QPalette::Base, theme.backgroundAlt);
|
pal.setColor(QPalette::Base, theme.background);
|
||||||
pal.setColor(QPalette::AlternateBase, theme.surface);
|
pal.setColor(QPalette::AlternateBase, theme.surface);
|
||||||
pal.setColor(QPalette::Text, theme.text);
|
pal.setColor(QPalette::Text, theme.text);
|
||||||
pal.setColor(QPalette::Button, theme.button);
|
pal.setColor(QPalette::Button, theme.button);
|
||||||
pal.setColor(QPalette::ButtonText, theme.text);
|
pal.setColor(QPalette::ButtonText, theme.text);
|
||||||
pal.setColor(QPalette::Highlight, theme.hover);
|
pal.setColor(QPalette::Highlight, theme.selection);
|
||||||
pal.setColor(QPalette::HighlightedText, theme.indHoverSpan);
|
pal.setColor(QPalette::HighlightedText, theme.text);
|
||||||
pal.setColor(QPalette::ToolTipBase, theme.backgroundAlt);
|
pal.setColor(QPalette::ToolTipBase, theme.backgroundAlt);
|
||||||
pal.setColor(QPalette::ToolTipText, theme.text);
|
pal.setColor(QPalette::ToolTipText, theme.text);
|
||||||
pal.setColor(QPalette::Mid, theme.border);
|
pal.setColor(QPalette::Mid, theme.border);
|
||||||
@@ -301,6 +311,13 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) {
|
|||||||
createMenus();
|
createMenus();
|
||||||
createStatusBar();
|
createStatusBar();
|
||||||
|
|
||||||
|
// Restore menu bar title case setting (after menus are created)
|
||||||
|
{
|
||||||
|
QSettings s("Reclass", "Reclass");
|
||||||
|
m_titleBar->setMenuBarTitleCase(s.value("menuBarTitleCase", true).toBool());
|
||||||
|
if (s.value("showIcon", false).toBool())
|
||||||
|
m_titleBar->setShowIcon(true);
|
||||||
|
}
|
||||||
|
|
||||||
// MenuBarStyle is set as app style in main() — covers both QMenuBar and QMenu
|
// MenuBarStyle is set as app style in main() — covers both QMenuBar and QMenu
|
||||||
|
|
||||||
@@ -310,9 +327,10 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) {
|
|||||||
// Load plugins
|
// Load plugins
|
||||||
m_pluginManager.LoadPlugins();
|
m_pluginManager.LoadPlugins();
|
||||||
|
|
||||||
// MCP bridge (on by default)
|
// Start MCP bridge
|
||||||
m_mcp = new McpBridge(this, this);
|
m_mcp = new McpBridge(this, this);
|
||||||
m_mcp->start();
|
if (QSettings("Reclass", "Reclass").value("autoStartMcp", false).toBool())
|
||||||
|
m_mcp->start();
|
||||||
|
|
||||||
connect(m_mdiArea, &QMdiArea::subWindowActivated,
|
connect(m_mdiArea, &QMdiArea::subWindowActivated,
|
||||||
this, [this](QMdiSubWindow*) {
|
this, [this](QMdiSubWindow*) {
|
||||||
@@ -338,33 +356,48 @@ QIcon MainWindow::makeIcon(const QString& svgPath) {
|
|||||||
return QIcon(svgPath);
|
return QIcon(svgPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template < typename...Args >
|
||||||
|
inline QAction* Qt5Qt6AddAction(QMenu* menu, const QString &text, const QKeySequence &shortcut, const QIcon &icon, Args&&...args)
|
||||||
|
{
|
||||||
|
QAction *result = menu->addAction(icon, text);
|
||||||
|
if (!shortcut.isEmpty())
|
||||||
|
result->setShortcut(shortcut);
|
||||||
|
QObject::connect(result, &QAction::triggered, std::forward<Args>(args)...);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::createMenus() {
|
void MainWindow::createMenus() {
|
||||||
// File
|
// File
|
||||||
auto* file = m_titleBar->menuBar()->addMenu("&File");
|
auto* file = m_titleBar->menuBar()->addMenu("&File");
|
||||||
file->addAction("&New", this, &MainWindow::newDocument, QKeySequence::New);
|
Qt5Qt6AddAction(file, "&New", QKeySequence::New, QIcon(), this, &MainWindow::newDocument);
|
||||||
file->addAction("New &Tab", this, &MainWindow::newFile, QKeySequence(Qt::CTRL | Qt::Key_T));
|
Qt5Qt6AddAction(file, "New &Tab", QKeySequence(Qt::CTRL | Qt::Key_T), QIcon(), this, &MainWindow::newFile);
|
||||||
file->addAction(makeIcon(":/vsicons/folder-opened.svg"), "&Open...", this, &MainWindow::openFile, QKeySequence::Open);
|
Qt5Qt6AddAction(file, "&Open...", QKeySequence::Open, makeIcon(":/vsicons/folder-opened.svg"), this, &MainWindow::openFile);
|
||||||
file->addSeparator();
|
file->addSeparator();
|
||||||
file->addAction(makeIcon(":/vsicons/save.svg"), "&Save", this, &MainWindow::saveFile, QKeySequence::Save);
|
Qt5Qt6AddAction(file, "&Save", QKeySequence::Save, makeIcon(":/vsicons/save.svg"), this, &MainWindow::saveFile);
|
||||||
file->addAction(makeIcon(":/vsicons/save-as.svg"), "Save &As...", this, &MainWindow::saveFileAs, QKeySequence::SaveAs);
|
Qt5Qt6AddAction(file, "Save &As...", QKeySequence::SaveAs, makeIcon(":/vsicons/save-as.svg"), this, &MainWindow::saveFileAs);
|
||||||
file->addSeparator();
|
file->addSeparator();
|
||||||
file->addAction(makeIcon(":/vsicons/export.svg"), "Export &C++ Header...", this, &MainWindow::exportCpp);
|
Qt5Qt6AddAction(file, "&Unload Project", QKeySequence(Qt::CTRL | Qt::Key_W), QIcon(), this, &MainWindow::closeFile);
|
||||||
file->addSeparator();
|
file->addSeparator();
|
||||||
m_mcpAction = file->addAction("Stop &MCP Server", this, &MainWindow::toggleMcp);
|
Qt5Qt6AddAction(file, "Export &C++ Header...", QKeySequence::UnknownKey, makeIcon(":/vsicons/export.svg"), this, &MainWindow::exportCpp);
|
||||||
file->addSeparator();
|
file->addSeparator();
|
||||||
file->addAction(makeIcon(":/vsicons/close.svg"), "E&xit", this, &QMainWindow::close, QKeySequence(Qt::Key_Close));
|
const auto itemName = QSettings("Reclass", "Reclass").value("autoStartMcp", false).toBool() ? "Stop &MCP Server" : "Start &MCP Server";
|
||||||
|
m_mcpAction = Qt5Qt6AddAction(file, itemName, QKeySequence::UnknownKey, QIcon(), this, &MainWindow::toggleMcp);
|
||||||
|
file->addSeparator();
|
||||||
|
Qt5Qt6AddAction(file, "&Options...", QKeySequence::UnknownKey, makeIcon(":/vsicons/settings-gear.svg"), this, &MainWindow::showOptionsDialog);
|
||||||
|
file->addSeparator();
|
||||||
|
Qt5Qt6AddAction(file, "E&xit", QKeySequence(Qt::Key_Close), makeIcon(":/vsicons/close.svg"), this, &QMainWindow::close);
|
||||||
|
|
||||||
// Edit
|
// Edit
|
||||||
auto* edit = m_titleBar->menuBar()->addMenu("&Edit");
|
auto* edit = m_titleBar->menuBar()->addMenu("&Edit");
|
||||||
edit->addAction(makeIcon(":/vsicons/arrow-left.svg"), "&Undo", this, &MainWindow::undo, QKeySequence::Undo);
|
Qt5Qt6AddAction(edit, "&Undo", QKeySequence::Undo, makeIcon(":/vsicons/arrow-left.svg"), this, &MainWindow::undo);
|
||||||
edit->addAction(makeIcon(":/vsicons/arrow-right.svg"), "&Redo", this, &MainWindow::redo, QKeySequence::Redo);
|
Qt5Qt6AddAction(edit, "&Redo", QKeySequence::Redo, makeIcon(":/vsicons/arrow-right.svg"), this, &MainWindow::redo);
|
||||||
edit->addSeparator();
|
edit->addSeparator();
|
||||||
edit->addAction("&Type Aliases...", this, &MainWindow::showTypeAliasesDialog);
|
Qt5Qt6AddAction(edit, "&Type Aliases...", QKeySequence::UnknownKey, QIcon(), this, &MainWindow::showTypeAliasesDialog);
|
||||||
|
|
||||||
// View
|
// View
|
||||||
auto* view = m_titleBar->menuBar()->addMenu("&View");
|
auto* view = m_titleBar->menuBar()->addMenu("&View");
|
||||||
view->addAction(makeIcon(":/vsicons/split-horizontal.svg"), "Split &Horizontal", this, &MainWindow::splitView);
|
Qt5Qt6AddAction(view, "Split &Horizontal", QKeySequence::UnknownKey, makeIcon(":/vsicons/split-horizontal.svg"), this, &MainWindow::splitView);
|
||||||
view->addAction(makeIcon(":/vsicons/chrome-close.svg"), "&Unsplit", this, &MainWindow::unsplitView);
|
Qt5Qt6AddAction(view, "&Unsplit", QKeySequence::UnknownKey, makeIcon(":/vsicons/chrome-close.svg"), this, &MainWindow::unsplitView);
|
||||||
view->addSeparator();
|
view->addSeparator();
|
||||||
auto* fontMenu = view->addMenu(makeIcon(":/vsicons/text-size.svg"), "&Font");
|
auto* fontMenu = view->addMenu(makeIcon(":/vsicons/text-size.svg"), "&Font");
|
||||||
auto* fontGroup = new QActionGroup(this);
|
auto* fontGroup = new QActionGroup(this);
|
||||||
@@ -399,35 +432,18 @@ void MainWindow::createMenus() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
themeMenu->addSeparator();
|
themeMenu->addSeparator();
|
||||||
themeMenu->addAction("Edit Theme...", this, &MainWindow::editTheme);
|
Qt5Qt6AddAction(themeMenu, "Edit Theme...", QKeySequence::UnknownKey, QIcon(), this, &MainWindow::editTheme);
|
||||||
|
|
||||||
view->addSeparator();
|
view->addSeparator();
|
||||||
auto* actShowIcon = view->addAction("Show &Icon");
|
|
||||||
actShowIcon->setCheckable(true);
|
|
||||||
actShowIcon->setChecked(settings.value("showIcon", false).toBool());
|
|
||||||
if (actShowIcon->isChecked()) m_titleBar->setShowIcon(true);
|
|
||||||
connect(actShowIcon, &QAction::toggled, this, [this](bool checked) {
|
|
||||||
m_titleBar->setShowIcon(checked);
|
|
||||||
QSettings s("Reclass", "Reclass");
|
|
||||||
s.setValue("showIcon", checked);
|
|
||||||
});
|
|
||||||
view->addAction(m_workspaceDock->toggleViewAction());
|
view->addAction(m_workspaceDock->toggleViewAction());
|
||||||
|
|
||||||
// Node
|
|
||||||
auto* node = m_titleBar->menuBar()->addMenu("&Node");
|
|
||||||
node->addAction(makeIcon(":/vsicons/add.svg"), "&Add Field", this, &MainWindow::addNode, QKeySequence(Qt::Key_Insert));
|
|
||||||
node->addAction(makeIcon(":/vsicons/remove.svg"), "&Remove Field", this, &MainWindow::removeNode, QKeySequence::Delete);
|
|
||||||
node->addAction(makeIcon(":/vsicons/symbol-structure.svg"), "Change &Type", this, &MainWindow::changeNodeType, QKeySequence(Qt::Key_T));
|
|
||||||
node->addAction(makeIcon(":/vsicons/edit.svg"), "Re&name", this, &MainWindow::renameNodeAction, QKeySequence(Qt::Key_F2));
|
|
||||||
node->addAction(makeIcon(":/vsicons/files.svg"), "D&uplicate", this, &MainWindow::duplicateNodeAction)->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_D));
|
|
||||||
|
|
||||||
// Plugins
|
// Plugins
|
||||||
auto* plugins = m_titleBar->menuBar()->addMenu("&Plugins");
|
auto* plugins = m_titleBar->menuBar()->addMenu("&Plugins");
|
||||||
plugins->addAction("&Manage Plugins...", this, &MainWindow::showPluginsDialog);
|
Qt5Qt6AddAction(plugins, "&Manage Plugins...", QKeySequence::UnknownKey, QIcon(), this, &MainWindow::showPluginsDialog);
|
||||||
|
|
||||||
// Help
|
// Help
|
||||||
auto* help = m_titleBar->menuBar()->addMenu("&Help");
|
auto* help = m_titleBar->menuBar()->addMenu("&Help");
|
||||||
help->addAction(makeIcon(":/vsicons/question.svg"), "&About Reclass", this, &MainWindow::about);
|
Qt5Qt6AddAction(help, "&About Reclass", QKeySequence::UnknownKey, makeIcon(":/vsicons/question.svg"), this, &MainWindow::about);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::createStatusBar() {
|
void MainWindow::createStatusBar() {
|
||||||
@@ -665,6 +681,7 @@ QMdiSubWindow* MainWindow::createTab(RcxDocument* doc) {
|
|||||||
sub->setWindowTitle(rootName(it2->doc->tree, it2->ctrl->viewRootId()));
|
sub->setWindowTitle(rootName(it2->doc->tree, it2->ctrl->viewRootId()));
|
||||||
}
|
}
|
||||||
updateWindowTitle();
|
updateWindowTitle();
|
||||||
|
rebuildWorkspaceModel();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -737,6 +754,25 @@ static void buildBallDemo(NodeTree& tree) {
|
|||||||
|
|
||||||
// Material[2] materials at offset 128 (112 + 16 for float[4])
|
// Material[2] materials at offset 128 (112 + 16 for float[4])
|
||||||
{ Node n; n.kind = NodeKind::Array; n.name = "materials"; n.parentId = ballId; n.offset = 128; n.elementKind = NodeKind::Struct; n.arrayLen = 2; n.refId = matId; tree.addNode(n); }
|
{ Node n; n.kind = NodeKind::Array; n.name = "materials"; n.parentId = ballId; n.offset = 128; n.elementKind = NodeKind::Struct; n.arrayLen = 2; n.refId = matId; tree.addNode(n); }
|
||||||
|
|
||||||
|
// Unnamed struct (128 bytes of hex64 fields)
|
||||||
|
Node unnamed;
|
||||||
|
unnamed.kind = NodeKind::Struct;
|
||||||
|
unnamed.name = "instance";
|
||||||
|
unnamed.structTypeName = "Unnamed";
|
||||||
|
unnamed.parentId = 0;
|
||||||
|
unnamed.offset = 0;
|
||||||
|
int ui = tree.addNode(unnamed);
|
||||||
|
uint64_t unnamedId = tree.nodes[ui].id;
|
||||||
|
|
||||||
|
for (int i = 0; i < 16; i++) {
|
||||||
|
Node n;
|
||||||
|
n.kind = NodeKind::Hex64;
|
||||||
|
n.name = QStringLiteral("field_%1").arg(i * 8, 2, 16, QChar('0'));
|
||||||
|
n.parentId = unnamedId;
|
||||||
|
n.offset = i * 8;
|
||||||
|
tree.addNode(n);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::newFile() {
|
void MainWindow::newFile() {
|
||||||
@@ -785,41 +821,7 @@ void MainWindow::newDocument() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::selfTest() {
|
void MainWindow::selfTest() {
|
||||||
// Tab 1: Ball demo
|
|
||||||
project_new();
|
project_new();
|
||||||
|
|
||||||
// Tab 2: Unnamed struct with hex64 fields
|
|
||||||
{
|
|
||||||
auto* doc = new RcxDocument(this);
|
|
||||||
QByteArray data(256, '\0');
|
|
||||||
doc->loadData(data);
|
|
||||||
doc->tree.baseAddress = 0x00400000;
|
|
||||||
|
|
||||||
Node s;
|
|
||||||
s.kind = NodeKind::Struct;
|
|
||||||
s.name = "instance";
|
|
||||||
s.structTypeName = "Unnamed";
|
|
||||||
s.parentId = 0;
|
|
||||||
s.offset = 0;
|
|
||||||
int si = doc->tree.addNode(s);
|
|
||||||
uint64_t sId = doc->tree.nodes[si].id;
|
|
||||||
|
|
||||||
for (int i = 0; i < 16; i++) {
|
|
||||||
Node n;
|
|
||||||
n.kind = NodeKind::Hex64;
|
|
||||||
n.name = QStringLiteral("field_%1").arg(i * 8, 2, 16, QChar('0'));
|
|
||||||
n.parentId = sId;
|
|
||||||
n.offset = i * 8;
|
|
||||||
doc->tree.addNode(n);
|
|
||||||
}
|
|
||||||
|
|
||||||
createTab(doc);
|
|
||||||
rebuildWorkspaceModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Focus Ball tab
|
|
||||||
if (auto* first = m_mdiArea->subWindowList().value(0))
|
|
||||||
m_mdiArea->setActiveSubWindow(first);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::openFile() {
|
void MainWindow::openFile() {
|
||||||
@@ -834,6 +836,10 @@ void MainWindow::saveFileAs() {
|
|||||||
project_save(nullptr, true);
|
project_save(nullptr, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::closeFile() {
|
||||||
|
project_close();
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::addNode() {
|
void MainWindow::addNode() {
|
||||||
auto* ctrl = activeController();
|
auto* ctrl = activeController();
|
||||||
if (!ctrl) return;
|
if (!ctrl) return;
|
||||||
@@ -1005,6 +1011,13 @@ void MainWindow::applyTheme(const Theme& theme) {
|
|||||||
statusBar()->setPalette(sbPal);
|
statusBar()->setPalette(sbPal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Workspace tree: text color matches menu bar
|
||||||
|
if (m_workspaceTree) {
|
||||||
|
QPalette tp = m_workspaceTree->palette();
|
||||||
|
tp.setColor(QPalette::Text, theme.textDim);
|
||||||
|
m_workspaceTree->setPalette(tp);
|
||||||
|
}
|
||||||
|
|
||||||
// Split pane tab widgets
|
// Split pane tab widgets
|
||||||
for (auto& state : m_tabs) {
|
for (auto& state : m_tabs) {
|
||||||
for (auto& pane : state.panes) {
|
for (auto& pane : state.panes) {
|
||||||
@@ -1024,6 +1037,45 @@ void MainWindow::editTheme() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: when adding more and more options, this func becomes very clunky. Fix
|
||||||
|
void MainWindow::showOptionsDialog() {
|
||||||
|
auto& tm = ThemeManager::instance();
|
||||||
|
OptionsResult current;
|
||||||
|
current.themeIndex = tm.currentIndex();
|
||||||
|
current.fontName = QSettings("Reclass", "Reclass").value("font", "JetBrains Mono").toString();
|
||||||
|
current.menuBarTitleCase = m_titleBar->menuBarTitleCase();
|
||||||
|
current.showIcon = QSettings("Reclass", "Reclass").value("showIcon", false).toBool();
|
||||||
|
current.safeMode = QSettings("Reclass", "Reclass").value("safeMode", false).toBool();
|
||||||
|
current.autoStartMcp = QSettings("Reclass", "Reclass").value("autoStartMcp", false).toBool();
|
||||||
|
|
||||||
|
OptionsDialog dlg(current, this);
|
||||||
|
if (dlg.exec() != QDialog::Accepted) return; // OptionsDialog doesn't apply anything. Only apply on OK
|
||||||
|
|
||||||
|
auto r = dlg.result();
|
||||||
|
|
||||||
|
if (r.themeIndex != current.themeIndex)
|
||||||
|
tm.setCurrent(r.themeIndex);
|
||||||
|
|
||||||
|
if (r.fontName != current.fontName)
|
||||||
|
setEditorFont(r.fontName);
|
||||||
|
|
||||||
|
if (r.menuBarTitleCase != current.menuBarTitleCase) {
|
||||||
|
m_titleBar->setMenuBarTitleCase(r.menuBarTitleCase);
|
||||||
|
QSettings("Reclass", "Reclass").setValue("menuBarTitleCase", r.menuBarTitleCase);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (r.showIcon != current.showIcon) {
|
||||||
|
m_titleBar->setShowIcon(r.showIcon);
|
||||||
|
QSettings("Reclass", "Reclass").setValue("showIcon", r.showIcon);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (r.safeMode != current.safeMode)
|
||||||
|
QSettings("Reclass", "Reclass").setValue("safeMode", r.safeMode);
|
||||||
|
|
||||||
|
if (r.autoStartMcp != current.autoStartMcp)
|
||||||
|
QSettings("Reclass", "Reclass").setValue("autoStartMcp", r.autoStartMcp);
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::setEditorFont(const QString& fontName) {
|
void MainWindow::setEditorFont(const QString& fontName) {
|
||||||
QSettings settings("Reclass", "Reclass");
|
QSettings settings("Reclass", "Reclass");
|
||||||
settings.setValue("font", fontName);
|
settings.setValue("font", fontName);
|
||||||
@@ -1348,6 +1400,10 @@ QMdiSubWindow* MainWindow::project_open(const QString& path) {
|
|||||||
delete doc;
|
delete doc;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close all existing tabs so the project replaces the current state
|
||||||
|
m_mdiArea->closeAllSubWindows();
|
||||||
|
|
||||||
auto* sub = createTab(doc);
|
auto* sub = createTab(doc);
|
||||||
rebuildWorkspaceModel();
|
rebuildWorkspaceModel();
|
||||||
return sub;
|
return sub;
|
||||||
@@ -1380,7 +1436,7 @@ void MainWindow::project_close(QMdiSubWindow* sub) {
|
|||||||
// ── Workspace Dock ──
|
// ── Workspace Dock ──
|
||||||
|
|
||||||
void MainWindow::createWorkspaceDock() {
|
void MainWindow::createWorkspaceDock() {
|
||||||
m_workspaceDock = new QDockWidget("Workspace", this);
|
m_workspaceDock = new QDockWidget("Project Tree", this);
|
||||||
m_workspaceDock->setObjectName("WorkspaceDock");
|
m_workspaceDock->setObjectName("WorkspaceDock");
|
||||||
m_workspaceDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
|
m_workspaceDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
|
||||||
|
|
||||||
@@ -1390,81 +1446,76 @@ void MainWindow::createWorkspaceDock() {
|
|||||||
m_workspaceTree->setModel(m_workspaceModel);
|
m_workspaceTree->setModel(m_workspaceModel);
|
||||||
m_workspaceTree->setHeaderHidden(true);
|
m_workspaceTree->setHeaderHidden(true);
|
||||||
m_workspaceTree->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
m_workspaceTree->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||||
|
m_workspaceTree->setExpandsOnDoubleClick(false);
|
||||||
|
m_workspaceTree->setMouseTracking(true);
|
||||||
|
|
||||||
// Match editor font
|
m_workspaceTree->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
{
|
connect(m_workspaceTree, &QWidget::customContextMenuRequested, this, [this](const QPoint& pos) {
|
||||||
QSettings settings("Reclass", "Reclass");
|
QModelIndex index = m_workspaceTree->indexAt(pos);
|
||||||
QString fontName = settings.value("font", "JetBrains Mono").toString();
|
if (!index.isValid()) return;
|
||||||
QFont f(fontName, 12);
|
|
||||||
f.setFixedPitch(true);
|
auto structIdVar = index.data(Qt::UserRole + 1);
|
||||||
m_workspaceTree->setFont(f);
|
uint64_t structId = structIdVar.isValid() ? structIdVar.toULongLong() : 0;
|
||||||
}
|
if (structId == 0 || structId == rcx::kGroupSentinel) return;
|
||||||
|
|
||||||
|
auto subVar = index.data(Qt::UserRole);
|
||||||
|
if (!subVar.isValid()) return;
|
||||||
|
auto* sub = static_cast<QMdiSubWindow*>(subVar.value<void*>());
|
||||||
|
if (!sub || !m_tabs.contains(sub)) return;
|
||||||
|
|
||||||
|
QMenu menu;
|
||||||
|
auto* deleteAction = menu.addAction(QIcon(":/vsicons/remove.svg"), "Delete");
|
||||||
|
if (menu.exec(m_workspaceTree->viewport()->mapToGlobal(pos)) == deleteAction) {
|
||||||
|
auto& tab = m_tabs[sub];
|
||||||
|
int ni = tab.doc->tree.indexOfId(structId);
|
||||||
|
if (ni >= 0) {
|
||||||
|
tab.ctrl->removeNode(ni);
|
||||||
|
rebuildWorkspaceModel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
m_workspaceDock->setWidget(m_workspaceTree);
|
m_workspaceDock->setWidget(m_workspaceTree);
|
||||||
addDockWidget(Qt::LeftDockWidgetArea, m_workspaceDock);
|
addDockWidget(Qt::LeftDockWidgetArea, m_workspaceDock);
|
||||||
m_workspaceDock->hide();
|
m_workspaceDock->hide();
|
||||||
|
|
||||||
connect(m_workspaceTree, &QTreeView::doubleClicked, this, [this](const QModelIndex& index) {
|
connect(m_workspaceTree, &QTreeView::doubleClicked, this, [this](const QModelIndex& index) {
|
||||||
// Data roles: UserRole=QMdiSubWindow*, UserRole+1=structId, UserRole+2=nodeId
|
auto structIdVar = index.data(Qt::UserRole + 1);
|
||||||
|
uint64_t structId = structIdVar.isValid() ? structIdVar.toULongLong() : 0;
|
||||||
|
|
||||||
|
if (structId == rcx::kGroupSentinel) {
|
||||||
|
// "Project" folder: toggle expand/collapse
|
||||||
|
m_workspaceTree->setExpanded(index, !m_workspaceTree->isExpanded(index));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto subVar = index.data(Qt::UserRole);
|
auto subVar = index.data(Qt::UserRole);
|
||||||
if (!subVar.isValid()) return;
|
if (!subVar.isValid()) return;
|
||||||
|
|
||||||
auto* sub = static_cast<QMdiSubWindow*>(subVar.value<void*>());
|
auto* sub = static_cast<QMdiSubWindow*>(subVar.value<void*>());
|
||||||
if (!sub || !m_tabs.contains(sub)) return;
|
if (!sub || !m_tabs.contains(sub)) return;
|
||||||
|
|
||||||
m_mdiArea->setActiveSubWindow(sub);
|
m_mdiArea->setActiveSubWindow(sub);
|
||||||
|
|
||||||
auto structIdVar = index.data(Qt::UserRole + 1);
|
// Type/Enum node: navigate to it
|
||||||
auto nodeIdVar = index.data(Qt::UserRole + 2);
|
auto& tree = m_tabs[sub].doc->tree;
|
||||||
|
int ni = tree.indexOfId(structId);
|
||||||
if (structIdVar.isValid()) {
|
if (ni >= 0) tree.nodes[ni].collapsed = false;
|
||||||
// Double-clicked a struct: set as view root
|
m_tabs[sub].ctrl->setViewRootId(structId);
|
||||||
uint64_t structId = structIdVar.toULongLong();
|
m_tabs[sub].ctrl->scrollToNodeId(structId);
|
||||||
auto& tree = m_tabs[sub].doc->tree;
|
|
||||||
int ni = tree.indexOfId(structId);
|
|
||||||
if (ni >= 0) tree.nodes[ni].collapsed = false;
|
|
||||||
m_tabs[sub].ctrl->setViewRootId(structId);
|
|
||||||
m_tabs[sub].ctrl->scrollToNodeId(structId);
|
|
||||||
} else if (nodeIdVar.isValid()) {
|
|
||||||
// Double-clicked a field: find its root struct, set as view root, scroll to field
|
|
||||||
uint64_t nodeId = nodeIdVar.toULongLong();
|
|
||||||
auto& tree = m_tabs[sub].doc->tree;
|
|
||||||
// Walk up to find root struct
|
|
||||||
uint64_t rootId = 0;
|
|
||||||
uint64_t cur = nodeId;
|
|
||||||
while (cur != 0) {
|
|
||||||
int idx = tree.indexOfId(cur);
|
|
||||||
if (idx < 0) break;
|
|
||||||
if (tree.nodes[idx].parentId == 0) { rootId = cur; break; }
|
|
||||||
cur = tree.nodes[idx].parentId;
|
|
||||||
}
|
|
||||||
if (rootId != 0) {
|
|
||||||
int ri = tree.indexOfId(rootId);
|
|
||||||
if (ri >= 0) tree.nodes[ri].collapsed = false;
|
|
||||||
m_tabs[sub].ctrl->setViewRootId(rootId);
|
|
||||||
}
|
|
||||||
m_tabs[sub].ctrl->scrollToNodeId(nodeId);
|
|
||||||
} else if (!index.parent().isValid()) {
|
|
||||||
// Double-clicked project root: clear view root to show all
|
|
||||||
m_tabs[sub].ctrl->setViewRootId(0);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::rebuildWorkspaceModel() {
|
void MainWindow::rebuildWorkspaceModel() {
|
||||||
m_workspaceModel->clear();
|
QVector<rcx::TabInfo> tabs;
|
||||||
|
for (auto it = m_tabs.begin(); it != m_tabs.end(); ++it) {
|
||||||
auto* sub = m_mdiArea->activeSubWindow();
|
TabState& tab = it.value();
|
||||||
if (!sub || !m_tabs.contains(sub)) return;
|
QString name = tab.doc->filePath.isEmpty()
|
||||||
|
? rootName(tab.doc->tree, tab.ctrl->viewRootId())
|
||||||
TabState& tab = m_tabs[sub];
|
: QFileInfo(tab.doc->filePath).fileName();
|
||||||
QString tabName = tab.doc->filePath.isEmpty()
|
tabs.append({ &tab.doc->tree, name, static_cast<void*>(it.key()) });
|
||||||
? rootName(tab.doc->tree, tab.ctrl->viewRootId())
|
}
|
||||||
: QFileInfo(tab.doc->filePath).fileName();
|
rcx::buildProjectExplorer(m_workspaceModel, tabs);
|
||||||
|
m_workspaceTree->expandToDepth(1);
|
||||||
buildWorkspaceModel(m_workspaceModel, tab.doc->tree, tabName,
|
|
||||||
static_cast<void*>(sub));
|
|
||||||
m_workspaceTree->expandAll();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::showPluginsDialog() {
|
void MainWindow::showPluginsDialog() {
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ private slots:
|
|||||||
void openFile();
|
void openFile();
|
||||||
void saveFile();
|
void saveFile();
|
||||||
void saveFileAs();
|
void saveFileAs();
|
||||||
|
void closeFile();
|
||||||
|
|
||||||
void addNode();
|
void addNode();
|
||||||
void removeNode();
|
void removeNode();
|
||||||
@@ -49,6 +49,7 @@ private slots:
|
|||||||
void exportCpp();
|
void exportCpp();
|
||||||
void showTypeAliasesDialog();
|
void showTypeAliasesDialog();
|
||||||
void editTheme();
|
void editTheme();
|
||||||
|
void showOptionsDialog();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Project Lifecycle API
|
// Project Lifecycle API
|
||||||
|
|||||||
@@ -248,7 +248,7 @@ QJsonObject McpBridge::handleToolsList(const QJsonValue& id) {
|
|||||||
"collapse: {op:'collapse', nodeId:'ID', collapsed:true}. "
|
"collapse: {op:'collapse', nodeId:'ID', collapsed:true}. "
|
||||||
"Insert ops get auto-assigned IDs; use $0, $1 etc. to reference them in later ops. "
|
"Insert ops get auto-assigned IDs; use $0, $1 etc. to reference them in later ops. "
|
||||||
"Kinds: Hex8 Hex16 Hex32 Hex64 Int8 Int16 Int32 Int64 UInt8 UInt16 UInt32 UInt64 "
|
"Kinds: Hex8 Hex16 Hex32 Hex64 Int8 Int16 Int32 Int64 UInt8 UInt16 UInt32 UInt64 "
|
||||||
"Float Double Bool Pointer32 Pointer64 Vec2 Vec3 Vec4 Mat4x4 UTF8 UTF16 Padding Struct Array"},
|
"Float Double Bool Pointer32 Pointer64 Vec2 Vec3 Vec4 Mat4x4 UTF8 UTF16 Struct Array"},
|
||||||
{"inputSchema", QJsonObject{
|
{"inputSchema", QJsonObject{
|
||||||
{"type", "object"},
|
{"type", "object"},
|
||||||
{"properties", QJsonObject{
|
{"properties", QJsonObject{
|
||||||
@@ -793,7 +793,7 @@ QJsonObject McpBridge::toolSourceSwitch(const QJsonObject& args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (args.contains("pid")) {
|
if (args.contains("pid")) {
|
||||||
uint32_t pid = (uint32_t)args.value("pid").toInteger();
|
uint32_t pid = (uint32_t)args.value("pid").toInt();
|
||||||
QString name = args.value("processName").toString();
|
QString name = args.value("processName").toString();
|
||||||
if (name.isEmpty()) name = QString("PID %1").arg(pid);
|
if (name.isEmpty()) name = QString("PID %1").arg(pid);
|
||||||
QString target = QString("%1:%2").arg(pid).arg(name);
|
QString target = QString("%1:%2").arg(pid).arg(name);
|
||||||
|
|||||||
237
src/optionsdialog.cpp
Normal file
237
src/optionsdialog.cpp
Normal file
@@ -0,0 +1,237 @@
|
|||||||
|
#include "optionsdialog.h"
|
||||||
|
#include "themes/thememanager.h"
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QFormLayout>
|
||||||
|
#include <QDialogButtonBox>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QGroupBox>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QTreeWidgetItem>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
namespace rcx {
|
||||||
|
|
||||||
|
OptionsDialog::OptionsDialog(const OptionsResult& current, QWidget* parent)
|
||||||
|
: QDialog(parent)
|
||||||
|
{
|
||||||
|
setWindowTitle("Options");
|
||||||
|
setFixedSize(700, 450);
|
||||||
|
|
||||||
|
auto* mainLayout = new QVBoxLayout(this);
|
||||||
|
mainLayout->setSpacing(8);
|
||||||
|
mainLayout->setContentsMargins(10, 10, 10, 10);
|
||||||
|
|
||||||
|
// -- Middle: left column (search + tree) | right column (pages) --
|
||||||
|
auto* middleLayout = new QHBoxLayout;
|
||||||
|
middleLayout->setSpacing(8);
|
||||||
|
|
||||||
|
// Left column: search bar + tree
|
||||||
|
auto* leftColumn = new QVBoxLayout;
|
||||||
|
leftColumn->setSpacing(4);
|
||||||
|
|
||||||
|
m_search = new QLineEdit;
|
||||||
|
m_search->setPlaceholderText("Search Options (Ctrl+E)");
|
||||||
|
m_search->setClearButtonEnabled(true);
|
||||||
|
connect(m_search, &QLineEdit::textChanged, this, &OptionsDialog::filterTree);
|
||||||
|
leftColumn->addWidget(m_search);
|
||||||
|
|
||||||
|
m_tree = new QTreeWidget;
|
||||||
|
m_tree->setHeaderHidden(true);
|
||||||
|
m_tree->setRootIsDecorated(true);
|
||||||
|
m_tree->setFixedWidth(200);
|
||||||
|
|
||||||
|
auto* envItem = new QTreeWidgetItem(m_tree, {"Environment"});
|
||||||
|
auto* generalItem = new QTreeWidgetItem(envItem, {"General"});
|
||||||
|
m_tree->expandAll();
|
||||||
|
m_tree->setCurrentItem(generalItem);
|
||||||
|
leftColumn->addWidget(m_tree, 1);
|
||||||
|
|
||||||
|
middleLayout->addLayout(leftColumn);
|
||||||
|
|
||||||
|
// Right column: stacked pages with group boxes
|
||||||
|
m_pages = new QStackedWidget;
|
||||||
|
|
||||||
|
// -- General page --
|
||||||
|
auto* generalPage = new QWidget;
|
||||||
|
auto* generalLayout = new QVBoxLayout(generalPage);
|
||||||
|
generalLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
generalLayout->setSpacing(8);
|
||||||
|
|
||||||
|
// Visual Experience group box
|
||||||
|
auto* visualGroup = new QGroupBox("Visual Experience");
|
||||||
|
auto* visualLayout = new QFormLayout(visualGroup);
|
||||||
|
visualLayout->setSpacing(8);
|
||||||
|
visualLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
|
||||||
|
|
||||||
|
m_themeCombo = new QComboBox;
|
||||||
|
auto& tm = ThemeManager::instance();
|
||||||
|
for (const auto& theme : tm.themes())
|
||||||
|
m_themeCombo->addItem(theme.name);
|
||||||
|
m_themeCombo->setCurrentIndex(current.themeIndex);
|
||||||
|
m_themeCombo->setObjectName("themeCombo");
|
||||||
|
visualLayout->addRow("Color theme:", m_themeCombo);
|
||||||
|
|
||||||
|
m_fontCombo = new QComboBox;
|
||||||
|
m_fontCombo->addItem("JetBrains Mono");
|
||||||
|
m_fontCombo->addItem("Consolas");
|
||||||
|
m_fontCombo->setCurrentText(current.fontName);
|
||||||
|
m_fontCombo->setObjectName("fontCombo");
|
||||||
|
visualLayout->addRow("Editor Font:", m_fontCombo);
|
||||||
|
|
||||||
|
m_titleCaseCheck = new QCheckBox("Apply title case styling to menu bar");
|
||||||
|
m_titleCaseCheck->setChecked(current.menuBarTitleCase);
|
||||||
|
visualLayout->addRow(m_titleCaseCheck);
|
||||||
|
|
||||||
|
m_showIconCheck = new QCheckBox("Show icon in title bar");
|
||||||
|
m_showIconCheck->setChecked(current.showIcon);
|
||||||
|
visualLayout->addRow(m_showIconCheck);
|
||||||
|
|
||||||
|
generalLayout->addWidget(visualGroup);
|
||||||
|
|
||||||
|
// Safe Mode group box
|
||||||
|
auto* safeModeGroup = new QGroupBox("Preview Features");
|
||||||
|
auto* safeModeLayout = new QVBoxLayout(safeModeGroup);
|
||||||
|
safeModeLayout->setSpacing(4);
|
||||||
|
|
||||||
|
m_safeModeCheck = new QCheckBox("Safe Mode");
|
||||||
|
m_safeModeCheck->setChecked(current.safeMode);
|
||||||
|
safeModeLayout->addWidget(m_safeModeCheck);
|
||||||
|
|
||||||
|
auto* safeModeDesc = new QLabel(
|
||||||
|
"Enable to use the default OS icon for this application and "
|
||||||
|
"create the window with the name of the executable file.");
|
||||||
|
safeModeDesc->setWordWrap(true);
|
||||||
|
safeModeDesc->setContentsMargins(20, 0, 0, 0); // indent under checkbox
|
||||||
|
safeModeLayout->addWidget(safeModeDesc);
|
||||||
|
|
||||||
|
generalLayout->addWidget(safeModeGroup);
|
||||||
|
generalLayout->addStretch();
|
||||||
|
|
||||||
|
m_pages->addWidget(generalPage); // index 0
|
||||||
|
m_pageKeywords[generalItem] = collectPageKeywords(generalPage);
|
||||||
|
|
||||||
|
// -- AI Features page --
|
||||||
|
auto* aiItem = new QTreeWidgetItem(envItem, {"AI Features"});
|
||||||
|
|
||||||
|
auto* aiPage = new QWidget;
|
||||||
|
auto* aiLayout = new QVBoxLayout(aiPage);
|
||||||
|
aiLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
aiLayout->setSpacing(8);
|
||||||
|
|
||||||
|
auto* mcpGroup = new QGroupBox("MCP Server");
|
||||||
|
auto* mcpLayout = new QVBoxLayout(mcpGroup);
|
||||||
|
mcpLayout->setSpacing(4);
|
||||||
|
|
||||||
|
m_autoMcpCheck = new QCheckBox("Auto-start MCP server");
|
||||||
|
m_autoMcpCheck->setChecked(current.autoStartMcp);
|
||||||
|
mcpLayout->addWidget(m_autoMcpCheck);
|
||||||
|
|
||||||
|
auto* mcpDesc = new QLabel(
|
||||||
|
"Automatically start the MCP bridge server when the application launches, "
|
||||||
|
"allowing external AI tools to connect and interact with the editor.");
|
||||||
|
mcpDesc->setWordWrap(true);
|
||||||
|
mcpDesc->setContentsMargins(20, 0, 0, 0);
|
||||||
|
mcpLayout->addWidget(mcpDesc);
|
||||||
|
|
||||||
|
aiLayout->addWidget(mcpGroup);
|
||||||
|
aiLayout->addStretch();
|
||||||
|
|
||||||
|
m_pages->addWidget(aiPage); // index 1
|
||||||
|
m_pageKeywords[aiItem] = collectPageKeywords(aiPage);
|
||||||
|
|
||||||
|
// -- Generator page --
|
||||||
|
auto* generatorItem = new QTreeWidgetItem(envItem, {"Generator"});
|
||||||
|
|
||||||
|
auto* generatorPage = new QWidget;
|
||||||
|
auto* generatorLayout = new QVBoxLayout(generatorPage);
|
||||||
|
generatorLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
generatorLayout->setSpacing(8);
|
||||||
|
generatorLayout->addStretch();
|
||||||
|
|
||||||
|
m_pages->addWidget(generatorPage); // index 2
|
||||||
|
m_pageKeywords[generatorItem] = collectPageKeywords(generatorPage);
|
||||||
|
|
||||||
|
middleLayout->addWidget(m_pages, 1);
|
||||||
|
|
||||||
|
mainLayout->addLayout(middleLayout, 1);
|
||||||
|
|
||||||
|
// Tree <-> page connection
|
||||||
|
m_itemPageIndex[generalItem] = 0;
|
||||||
|
m_itemPageIndex[aiItem] = 1;
|
||||||
|
m_itemPageIndex[generatorItem] = 2;
|
||||||
|
connect(m_tree, &QTreeWidget::currentItemChanged, this,
|
||||||
|
[this](QTreeWidgetItem* item, QTreeWidgetItem*) {
|
||||||
|
if (!item) return;
|
||||||
|
auto it = m_itemPageIndex.find(item);
|
||||||
|
if (it != m_itemPageIndex.end())
|
||||||
|
m_pages->setCurrentIndex(it.value());
|
||||||
|
});
|
||||||
|
|
||||||
|
// -- Button box --
|
||||||
|
auto* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||||
|
connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||||
|
connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||||
|
mainLayout->addWidget(buttons);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
OptionsResult OptionsDialog::result() const {
|
||||||
|
OptionsResult r;
|
||||||
|
r.themeIndex = m_themeCombo->currentIndex();
|
||||||
|
r.fontName = m_fontCombo->currentText();
|
||||||
|
r.menuBarTitleCase = m_titleCaseCheck->isChecked();
|
||||||
|
r.showIcon = m_showIconCheck->isChecked();
|
||||||
|
r.safeMode = m_safeModeCheck->isChecked();
|
||||||
|
r.autoStartMcp = m_autoMcpCheck->isChecked();
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList OptionsDialog::collectPageKeywords(QWidget* page) {
|
||||||
|
QStringList keywords;
|
||||||
|
for (auto* child : page->findChildren<QWidget*>()) {
|
||||||
|
if (auto* label = qobject_cast<QLabel*>(child))
|
||||||
|
keywords << label->text();
|
||||||
|
else if (auto* cb = qobject_cast<QCheckBox*>(child))
|
||||||
|
keywords << cb->text();
|
||||||
|
else if (auto* gb = qobject_cast<QGroupBox*>(child))
|
||||||
|
keywords << gb->title();
|
||||||
|
else if (auto* combo = qobject_cast<QComboBox*>(child)) {
|
||||||
|
for (int i = 0; i < combo->count(); ++i)
|
||||||
|
keywords << combo->itemText(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return keywords;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionsDialog::filterTree(const QString& text) {
|
||||||
|
std::function<bool(QTreeWidgetItem*)> filter = [&](QTreeWidgetItem* item) -> bool {
|
||||||
|
bool anyChildVisible = false;
|
||||||
|
for (int i = 0; i < item->childCount(); ++i) {
|
||||||
|
if (filter(item->child(i)))
|
||||||
|
anyChildVisible = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool selfMatch = item->text(0).contains(text, Qt::CaseInsensitive);
|
||||||
|
if (!selfMatch) {
|
||||||
|
for (const auto& kw : m_pageKeywords.value(item)) {
|
||||||
|
if (kw.contains(text, Qt::CaseInsensitive)) {
|
||||||
|
selfMatch = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bool visible = selfMatch || anyChildVisible;
|
||||||
|
item->setHidden(!visible);
|
||||||
|
|
||||||
|
if (visible && item->childCount() > 0)
|
||||||
|
item->setExpanded(true);
|
||||||
|
|
||||||
|
return visible;
|
||||||
|
};
|
||||||
|
|
||||||
|
for (int i = 0; i < m_tree->topLevelItemCount(); ++i)
|
||||||
|
filter(m_tree->topLevelItem(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace rcx
|
||||||
48
src/optionsdialog.h
Normal file
48
src/optionsdialog.h
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QTreeWidget>
|
||||||
|
#include <QStackedWidget>
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QCheckBox>
|
||||||
|
#include <QHash>
|
||||||
|
|
||||||
|
namespace rcx {
|
||||||
|
|
||||||
|
struct OptionsResult {
|
||||||
|
int themeIndex = 0;
|
||||||
|
QString fontName;
|
||||||
|
bool menuBarTitleCase = true;
|
||||||
|
bool showIcon = false;
|
||||||
|
bool safeMode = false;
|
||||||
|
bool autoStartMcp = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
class OptionsDialog : public QDialog {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit OptionsDialog(const OptionsResult& current, QWidget* parent = nullptr);
|
||||||
|
|
||||||
|
OptionsResult result() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void filterTree(const QString& text);
|
||||||
|
static QStringList collectPageKeywords(QWidget* page);
|
||||||
|
|
||||||
|
QLineEdit* m_search = nullptr;
|
||||||
|
QTreeWidget* m_tree = nullptr;
|
||||||
|
QStackedWidget* m_pages = nullptr;
|
||||||
|
QComboBox* m_themeCombo = nullptr;
|
||||||
|
QComboBox* m_fontCombo = nullptr;
|
||||||
|
QCheckBox* m_titleCaseCheck = nullptr;
|
||||||
|
QCheckBox* m_showIconCheck = nullptr;
|
||||||
|
QCheckBox* m_safeModeCheck = nullptr;
|
||||||
|
QCheckBox* m_autoMcpCheck = nullptr;
|
||||||
|
|
||||||
|
// searchable keywords per leaf tree item
|
||||||
|
QHash<QTreeWidgetItem*, QStringList> m_pageKeywords;
|
||||||
|
// tree item → stacked widget page index
|
||||||
|
QHash<QTreeWidgetItem*, int> m_itemPageIndex;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace rcx
|
||||||
@@ -47,5 +47,9 @@
|
|||||||
<file alias="selection.svg">vsicons/list-selection.svg</file>
|
<file alias="selection.svg">vsicons/list-selection.svg</file>
|
||||||
<file alias="symbol-numeric.svg">vsicons/symbol-numeric.svg</file>
|
<file alias="symbol-numeric.svg">vsicons/symbol-numeric.svg</file>
|
||||||
<file alias="symbol-ruler.svg">vsicons/symbol-ruler.svg</file>
|
<file alias="symbol-ruler.svg">vsicons/symbol-ruler.svg</file>
|
||||||
|
<file alias="settings-gear.svg">vsicons/settings-gear.svg</file>
|
||||||
|
<file alias="chevron-down.svg">vsicons/chevron-down.svg</file>
|
||||||
|
<file alias="folder.svg">vsicons/folder.svg</file>
|
||||||
|
<file alias="symbol-enum.svg">vsicons/symbol-enum.svg</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
"textDim": "#858585",
|
"textDim": "#858585",
|
||||||
"textMuted": "#585858",
|
"textMuted": "#585858",
|
||||||
"textFaint": "#505050",
|
"textFaint": "#505050",
|
||||||
"hover": "#2b2b2b",
|
"hover": "#1e1e1e",
|
||||||
"selected": "#232323",
|
"selected": "#1e1e1e",
|
||||||
"selection": "#2b2b2b",
|
"selection": "#2b2b2b",
|
||||||
"syntaxKeyword": "#569cd6",
|
"syntaxKeyword": "#569cd6",
|
||||||
"syntaxNumber": "#b5cea8",
|
"syntaxNumber": "#b5cea8",
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
"textDim": "#858585",
|
"textDim": "#858585",
|
||||||
"textMuted": "#636369",
|
"textMuted": "#636369",
|
||||||
"textFaint": "#4d4d55",
|
"textFaint": "#4d4d55",
|
||||||
"hover": "#3e3e42",
|
"hover": "#2c2c2f",
|
||||||
"selected": "#2d2d30",
|
"selected": "#262629",
|
||||||
"selection": "#264f78",
|
"selection": "#264f78",
|
||||||
"syntaxKeyword": "#569cd6",
|
"syntaxKeyword": "#569cd6",
|
||||||
"syntaxNumber": "#b5cea8",
|
"syntaxNumber": "#b5cea8",
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
"textDim": "#7a7a6e",
|
"textDim": "#7a7a6e",
|
||||||
"textMuted": "#555550",
|
"textMuted": "#555550",
|
||||||
"textFaint": "#464646",
|
"textFaint": "#464646",
|
||||||
"hover": "#373737",
|
"hover": "#282828",
|
||||||
"selected": "#2d2d2d",
|
"selected": "#262626",
|
||||||
"selection": "#21213A",
|
"selection": "#21213A",
|
||||||
"syntaxKeyword": "#AA9565",
|
"syntaxKeyword": "#AA9565",
|
||||||
"syntaxNumber": "#AAA98C",
|
"syntaxNumber": "#AAA98C",
|
||||||
|
|||||||
@@ -114,6 +114,33 @@ void TitleBarWidget::setShowIcon(bool show) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TitleBarWidget::setMenuBarTitleCase(bool titleCase) {
|
||||||
|
m_titleCase = titleCase;
|
||||||
|
for (QAction* action : m_menuBar->actions()) {
|
||||||
|
QString text = action->text();
|
||||||
|
QString clean = text;
|
||||||
|
clean.remove('&');
|
||||||
|
|
||||||
|
if (titleCase) {
|
||||||
|
action->setText("&" + clean.toUpper());
|
||||||
|
} else {
|
||||||
|
QString result;
|
||||||
|
bool capitalizeNext = true;
|
||||||
|
for (int i = 0; i < clean.length(); ++i) {
|
||||||
|
QChar ch = clean[i];
|
||||||
|
if (ch.isLetter()) {
|
||||||
|
result += capitalizeNext ? ch.toUpper() : ch.toLower();
|
||||||
|
capitalizeNext = false;
|
||||||
|
} else {
|
||||||
|
result += ch;
|
||||||
|
if (ch.isSpace()) capitalizeNext = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
action->setText("&" + result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TitleBarWidget::updateMaximizeIcon() {
|
void TitleBarWidget::updateMaximizeIcon() {
|
||||||
if (window()->isMaximized())
|
if (window()->isMaximized())
|
||||||
m_btnMax->setIcon(QIcon(":/vsicons/chrome-restore.svg"));
|
m_btnMax->setIcon(QIcon(":/vsicons/chrome-restore.svg"));
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ public:
|
|||||||
QMenuBar* menuBar() const { return m_menuBar; }
|
QMenuBar* menuBar() const { return m_menuBar; }
|
||||||
void applyTheme(const Theme& theme);
|
void applyTheme(const Theme& theme);
|
||||||
void setShowIcon(bool show);
|
void setShowIcon(bool show);
|
||||||
|
void setMenuBarTitleCase(bool titleCase);
|
||||||
|
bool menuBarTitleCase() const { return m_titleCase; }
|
||||||
|
|
||||||
void updateMaximizeIcon();
|
void updateMaximizeIcon();
|
||||||
|
|
||||||
@@ -32,6 +34,7 @@ private:
|
|||||||
QToolButton* m_btnClose = nullptr;
|
QToolButton* m_btnClose = nullptr;
|
||||||
|
|
||||||
Theme m_theme;
|
Theme m_theme;
|
||||||
|
bool m_titleCase = true;
|
||||||
|
|
||||||
QToolButton* makeChromeButton(const QString& iconPath);
|
QToolButton* makeChromeButton(const QString& iconPath);
|
||||||
void toggleMaximize();
|
void toggleMaximize();
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
#include <QIntValidator>
|
#include <QIntValidator>
|
||||||
|
#include <QElapsedTimer>
|
||||||
#include "themes/thememanager.h"
|
#include "themes/thememanager.h"
|
||||||
|
|
||||||
namespace rcx {
|
namespace rcx {
|
||||||
@@ -121,7 +122,7 @@ public:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 18px gutter: side triangle if current
|
// Gutter: side triangle if current
|
||||||
if (m_hasCurrent && m_filtered && row >= 0 && row < m_filtered->size()) {
|
if (m_hasCurrent && m_filtered && row >= 0 && row < m_filtered->size()) {
|
||||||
const TypeEntry& entry = (*m_filtered)[row];
|
const TypeEntry& entry = (*m_filtered)[row];
|
||||||
bool isCurrent = false;
|
bool isCurrent = false;
|
||||||
@@ -130,13 +131,13 @@ public:
|
|||||||
else if (m_current->entryKind == TypeEntry::Composite && entry.entryKind == TypeEntry::Composite)
|
else if (m_current->entryKind == TypeEntry::Composite && entry.entryKind == TypeEntry::Composite)
|
||||||
isCurrent = (entry.structId == m_current->structId);
|
isCurrent = (entry.structId == m_current->structId);
|
||||||
if (isCurrent) {
|
if (isCurrent) {
|
||||||
painter->setPen(t.syntaxType);
|
painter->setPen(t.text);
|
||||||
painter->setFont(m_font);
|
painter->setFont(m_font);
|
||||||
painter->drawText(QRect(x, y, 18, h), Qt::AlignCenter,
|
painter->drawText(QRect(x, y, 10, h), Qt::AlignCenter,
|
||||||
QString(QChar(0x25B8)));
|
QString(QChar(0x25B8)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
x += 18;
|
x += 10;
|
||||||
|
|
||||||
// Icon 16x16 — only for composite entries
|
// Icon 16x16 — only for composite entries
|
||||||
bool hasIcon = (m_filtered && row >= 0 && row < m_filtered->size()
|
bool hasIcon = (m_filtered && row >= 0 && row < m_filtered->size()
|
||||||
@@ -368,6 +369,7 @@ TypeSelectorPopup::TypeSelectorPopup(QWidget* parent)
|
|||||||
m_listView->setFrameShape(QFrame::NoFrame);
|
m_listView->setFrameShape(QFrame::NoFrame);
|
||||||
m_listView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
m_listView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
m_listView->setMouseTracking(true);
|
m_listView->setMouseTracking(true);
|
||||||
|
m_listView->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||||
m_listView->viewport()->setAttribute(Qt::WA_Hover, true);
|
m_listView->viewport()->setAttribute(Qt::WA_Hover, true);
|
||||||
m_listView->installEventFilter(this);
|
m_listView->installEventFilter(this);
|
||||||
|
|
||||||
@@ -384,10 +386,33 @@ TypeSelectorPopup::TypeSelectorPopup(QWidget* parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TypeSelectorPopup::warmUp() {
|
void TypeSelectorPopup::warmUp() {
|
||||||
|
// One-time per-process cost (~170ms): Qt lazily initializes the style/font/DLL
|
||||||
|
// subsystem the first time a popup with complex children is shown. Pre-pay it
|
||||||
|
// by briefly showing a throwaway dummy popup with a QListView, then show+hide
|
||||||
|
// ourselves.
|
||||||
|
{
|
||||||
|
auto* primer = new QFrame(nullptr, Qt::Popup | Qt::FramelessWindowHint);
|
||||||
|
primer->resize(300, 400);
|
||||||
|
auto* lay = new QVBoxLayout(primer);
|
||||||
|
lay->addWidget(new QLabel(QStringLiteral("x")));
|
||||||
|
lay->addWidget(new QLineEdit);
|
||||||
|
auto* model = new QStringListModel(primer);
|
||||||
|
QStringList items; for (int i = 0; i < 10; i++) items << QStringLiteral("x");
|
||||||
|
model->setStringList(items);
|
||||||
|
auto* lv = new QListView;
|
||||||
|
lv->setModel(model);
|
||||||
|
lay->addWidget(lv);
|
||||||
|
primer->show();
|
||||||
|
QApplication::processEvents();
|
||||||
|
primer->hide();
|
||||||
|
QApplication::processEvents();
|
||||||
|
delete primer;
|
||||||
|
}
|
||||||
|
|
||||||
TypeEntry dummy;
|
TypeEntry dummy;
|
||||||
dummy.entryKind = TypeEntry::Primitive;
|
dummy.entryKind = TypeEntry::Primitive;
|
||||||
dummy.primitiveKind = NodeKind::Hex8;
|
dummy.primitiveKind = NodeKind::Hex8;
|
||||||
dummy.displayName = "warmup";
|
dummy.displayName = QStringLiteral("warmup");
|
||||||
setTypes({dummy});
|
setTypes({dummy});
|
||||||
popup(QPoint(-9999, -9999));
|
popup(QPoint(-9999, -9999));
|
||||||
hide();
|
hide();
|
||||||
@@ -467,7 +492,7 @@ void TypeSelectorPopup::popup(const QPoint& globalPos) {
|
|||||||
QString text = t.classKeyword.isEmpty()
|
QString text = t.classKeyword.isEmpty()
|
||||||
? t.displayName
|
? t.displayName
|
||||||
: (t.classKeyword + QStringLiteral(" ") + t.displayName);
|
: (t.classKeyword + QStringLiteral(" ") + t.displayName);
|
||||||
int w = 18 + 20 + fm.horizontalAdvance(text) + 16;
|
int w = 10 + 20 + fm.horizontalAdvance(text) + 16;
|
||||||
if (w > maxTextW) maxTextW = w;
|
if (w > maxTextW) maxTextW = w;
|
||||||
}
|
}
|
||||||
int popupW = qBound(280, maxTextW + 24, 500);
|
int popupW = qBound(280, maxTextW + 24, 500);
|
||||||
|
|||||||
@@ -1,62 +1,76 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
|
#include <QIcon>
|
||||||
#include <QStandardItemModel>
|
#include <QStandardItemModel>
|
||||||
#include <QStandardItem>
|
#include <QStandardItem>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
namespace rcx {
|
namespace rcx {
|
||||||
|
|
||||||
// Recursively add children of parentId as tree items under parentItem.
|
struct TabInfo {
|
||||||
inline void addWorkspaceChildren(QStandardItem* parentItem,
|
const NodeTree* tree;
|
||||||
const NodeTree& tree,
|
QString name;
|
||||||
uint64_t parentId,
|
void* subPtr; // QMdiSubWindow* as void*
|
||||||
void* subPtr) {
|
};
|
||||||
QVector<int> children = tree.childrenOf(parentId);
|
|
||||||
std::sort(children.begin(), children.end(), [&](int a, int b) {
|
|
||||||
return tree.nodes[a].offset < tree.nodes[b].offset;
|
|
||||||
});
|
|
||||||
|
|
||||||
for (int idx : children) {
|
// Sentinel value stored in UserRole+1 to mark the Project group node.
|
||||||
const Node& node = tree.nodes[idx];
|
static constexpr uint64_t kGroupSentinel = ~uint64_t(0);
|
||||||
|
|
||||||
// Skip hex preview nodes — they are padding/filler, not meaningful fields
|
inline void buildProjectExplorer(QStandardItemModel* model,
|
||||||
if (isHexNode(node.kind)) continue;
|
const QVector<TabInfo>& tabs) {
|
||||||
|
|
||||||
QString display;
|
|
||||||
if (node.kind == NodeKind::Struct) {
|
|
||||||
QString typeName = node.structTypeName.isEmpty()
|
|
||||||
? node.name : node.structTypeName;
|
|
||||||
display = QStringLiteral("%1 (%2)")
|
|
||||||
.arg(typeName, node.resolvedClassKeyword());
|
|
||||||
} else {
|
|
||||||
display = QStringLiteral("%1 (%2)")
|
|
||||||
.arg(node.name, QString::fromLatin1(kindToString(node.kind)));
|
|
||||||
}
|
|
||||||
|
|
||||||
auto* item = new QStandardItem(display);
|
|
||||||
item->setData(QVariant::fromValue(subPtr), Qt::UserRole);
|
|
||||||
if (node.kind == NodeKind::Struct)
|
|
||||||
item->setData(QVariant::fromValue(node.id), Qt::UserRole + 1);
|
|
||||||
item->setData(QVariant::fromValue(node.id), Qt::UserRole + 2); // nodeId for scroll
|
|
||||||
|
|
||||||
if (node.kind == NodeKind::Struct)
|
|
||||||
addWorkspaceChildren(item, tree, node.id, subPtr);
|
|
||||||
|
|
||||||
parentItem->appendRow(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void buildWorkspaceModel(QStandardItemModel* model,
|
|
||||||
const NodeTree& tree,
|
|
||||||
const QString& projectName,
|
|
||||||
void* subPtr = nullptr) {
|
|
||||||
model->clear();
|
model->clear();
|
||||||
model->setHorizontalHeaderLabels({QStringLiteral("Name")});
|
model->setHorizontalHeaderLabels({QStringLiteral("Name")});
|
||||||
|
|
||||||
auto* projectItem = new QStandardItem(projectName);
|
// Single "Project" root with folder icon
|
||||||
projectItem->setData(QVariant::fromValue(subPtr), Qt::UserRole);
|
void* firstSub = tabs.isEmpty() ? nullptr : tabs[0].subPtr;
|
||||||
|
auto* projectItem = new QStandardItem(QIcon(":/vsicons/folder.svg"),
|
||||||
|
QStringLiteral("Project"));
|
||||||
|
projectItem->setData(QVariant::fromValue(firstSub), Qt::UserRole);
|
||||||
|
projectItem->setData(QVariant::fromValue(kGroupSentinel), Qt::UserRole + 1);
|
||||||
|
|
||||||
addWorkspaceChildren(projectItem, tree, 0, subPtr);
|
// Collect all top-level structs/enums across all tabs
|
||||||
|
QVector<std::pair<const Node*, void*>> types, enums;
|
||||||
|
for (const auto& tab : tabs) {
|
||||||
|
QVector<int> topLevel = tab.tree->childrenOf(0);
|
||||||
|
for (int idx : topLevel) {
|
||||||
|
const Node& n = tab.tree->nodes[idx];
|
||||||
|
if (n.kind != NodeKind::Struct) continue;
|
||||||
|
if (n.resolvedClassKeyword() == QStringLiteral("enum"))
|
||||||
|
enums.append({&n, tab.subPtr});
|
||||||
|
else
|
||||||
|
types.append({&n, tab.subPtr});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto nameOf = [](const Node* n) {
|
||||||
|
return n->structTypeName.isEmpty() ? n->name : n->structTypeName;
|
||||||
|
};
|
||||||
|
auto cmpName = [&](const std::pair<const Node*, void*>& a,
|
||||||
|
const std::pair<const Node*, void*>& b) {
|
||||||
|
return nameOf(a.first).compare(nameOf(b.first), Qt::CaseInsensitive) < 0;
|
||||||
|
};
|
||||||
|
std::sort(types.begin(), types.end(), cmpName);
|
||||||
|
std::sort(enums.begin(), enums.end(), cmpName);
|
||||||
|
|
||||||
|
for (const auto& [n, subPtr] : types) {
|
||||||
|
QString display = QStringLiteral("%1 (%2)")
|
||||||
|
.arg(nameOf(n), n->resolvedClassKeyword());
|
||||||
|
auto* item = new QStandardItem(
|
||||||
|
QIcon(":/vsicons/symbol-structure.svg"), display);
|
||||||
|
item->setData(QVariant::fromValue(subPtr), Qt::UserRole);
|
||||||
|
item->setData(QVariant::fromValue(n->id), Qt::UserRole + 1);
|
||||||
|
projectItem->appendRow(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto& [n, subPtr] : enums) {
|
||||||
|
QString display = QStringLiteral("%1 (%2)")
|
||||||
|
.arg(nameOf(n), n->resolvedClassKeyword());
|
||||||
|
auto* item = new QStandardItem(
|
||||||
|
QIcon(":/vsicons/symbol-enum.svg"), display);
|
||||||
|
item->setData(QVariant::fromValue(subPtr), Qt::UserRole);
|
||||||
|
item->setData(QVariant::fromValue(n->id), Qt::UserRole + 1);
|
||||||
|
projectItem->appendRow(item);
|
||||||
|
}
|
||||||
|
|
||||||
model->appendRow(projectItem);
|
model->appendRow(projectItem);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ private slots:
|
|||||||
QCOMPARE(result.meta[2].lineKind, LineKind::Footer);
|
QCOMPARE(result.meta[2].lineKind, LineKind::Footer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void testPaddingMarker() {
|
void testHexNodeCompose() {
|
||||||
NodeTree tree;
|
NodeTree tree;
|
||||||
tree.baseAddress = 0;
|
tree.baseAddress = 0;
|
||||||
|
|
||||||
@@ -100,19 +100,18 @@ private slots:
|
|||||||
int ri = tree.addNode(root);
|
int ri = tree.addNode(root);
|
||||||
uint64_t rootId = tree.nodes[ri].id;
|
uint64_t rootId = tree.nodes[ri].id;
|
||||||
|
|
||||||
Node pad;
|
Node hex;
|
||||||
pad.kind = NodeKind::Padding;
|
hex.kind = NodeKind::Hex8;
|
||||||
pad.name = "pad";
|
hex.name = "pad";
|
||||||
pad.parentId = rootId;
|
hex.parentId = rootId;
|
||||||
pad.offset = 0;
|
hex.offset = 0;
|
||||||
tree.addNode(pad);
|
tree.addNode(hex);
|
||||||
|
|
||||||
NullProvider prov;
|
NullProvider prov;
|
||||||
ComposeResult result = compose(tree, prov);
|
ComposeResult result = compose(tree, prov);
|
||||||
|
|
||||||
// CommandRow + padding + root footer = 3
|
// CommandRow + hex node + root footer = 3
|
||||||
QCOMPARE(result.meta.size(), 3);
|
QCOMPARE(result.meta.size(), 3);
|
||||||
QVERIFY(result.meta[1].markerMask & (1u << M_PAD));
|
|
||||||
QCOMPARE(result.meta[1].depth, 1);
|
QCOMPARE(result.meta[1].depth, 1);
|
||||||
|
|
||||||
// Line 2 is root footer
|
// Line 2 is root footer
|
||||||
|
|||||||
@@ -34,9 +34,8 @@ static void buildSmallTree(NodeTree& tree) {
|
|||||||
field(0, NodeKind::UInt32, "field_u32"); // 4 bytes
|
field(0, NodeKind::UInt32, "field_u32"); // 4 bytes
|
||||||
field(4, NodeKind::Float, "field_float"); // 4 bytes
|
field(4, NodeKind::Float, "field_float"); // 4 bytes
|
||||||
field(8, NodeKind::UInt8, "field_u8"); // 1 byte
|
field(8, NodeKind::UInt8, "field_u8"); // 1 byte
|
||||||
field(9, NodeKind::Padding, "pad0"); // 3 bytes padding
|
field(9, NodeKind::Hex16, "pad0"); // 2 bytes
|
||||||
// Set padding arrayLen = 3 for 3-byte padding
|
field(11, NodeKind::Hex8, "pad1"); // 1 byte
|
||||||
tree.nodes.last().arrayLen = 3;
|
|
||||||
field(12, NodeKind::Hex32, "field_hex"); // 4 bytes
|
field(12, NodeKind::Hex32, "field_hex"); // 4 bytes
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,47 +281,6 @@ private slots:
|
|||||||
QVERIFY(newIdx >= 0);
|
QVERIFY(newIdx >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Test: Padding value edit is effectively blocked at controller level ──
|
|
||||||
void testPaddingValueEditIsBlocked() {
|
|
||||||
// Find the padding node
|
|
||||||
int padIdx = -1;
|
|
||||||
for (int i = 0; i < m_doc->tree.nodes.size(); i++) {
|
|
||||||
if (m_doc->tree.nodes[i].kind == NodeKind::Padding) { padIdx = i; break; }
|
|
||||||
}
|
|
||||||
QVERIFY(padIdx >= 0);
|
|
||||||
uint64_t addr = m_doc->tree.computeOffset(padIdx);
|
|
||||||
|
|
||||||
// Read original data at padding offset
|
|
||||||
int padSize = m_doc->tree.nodes[padIdx].byteSize();
|
|
||||||
QByteArray origData = m_doc->provider->readBytes(addr, padSize);
|
|
||||||
|
|
||||||
// The context menu blocks Padding editing, so the controller's setNodeValue
|
|
||||||
// would only be called if the editing UI somehow allows it. But let's verify
|
|
||||||
// the editor correctly blocks it.
|
|
||||||
// Find padding line in composed output
|
|
||||||
ComposeResult result = m_doc->compose();
|
|
||||||
int paddingLine = -1;
|
|
||||||
for (int i = 0; i < result.meta.size(); i++) {
|
|
||||||
if (result.meta[i].nodeKind == NodeKind::Padding &&
|
|
||||||
result.meta[i].lineKind == LineKind::Field) {
|
|
||||||
paddingLine = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
QVERIFY(paddingLine >= 0);
|
|
||||||
|
|
||||||
m_editor->applyDocument(result);
|
|
||||||
QApplication::processEvents();
|
|
||||||
|
|
||||||
// beginInlineEdit(Value) on Padding line must be rejected
|
|
||||||
QVERIFY(!m_editor->beginInlineEdit(EditTarget::Value, paddingLine));
|
|
||||||
QVERIFY(!m_editor->isEditing());
|
|
||||||
|
|
||||||
// Data must be unchanged
|
|
||||||
QByteArray afterData = m_doc->provider->readBytes(addr, padSize);
|
|
||||||
QCOMPARE(afterData, origData);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Test: setNodeValue with Hex32 (space-separated hex bytes) ──
|
// ── Test: setNodeValue with Hex32 (space-separated hex bytes) ──
|
||||||
void testSetNodeValueHex() {
|
void testSetNodeValueHex() {
|
||||||
int idx = -1;
|
int idx = -1;
|
||||||
|
|||||||
@@ -170,9 +170,10 @@ static NodeTree makeTestTree() {
|
|||||||
n.parentId = rootId; n.offset = off;
|
n.parentId = rootId; n.offset = off;
|
||||||
tree.addNode(n);
|
tree.addNode(n);
|
||||||
};
|
};
|
||||||
auto pad = [&](int off, int len, const char* name) {
|
auto pad = [&](int off, int /*len*/, const char* name) {
|
||||||
Node n; n.kind = NodeKind::Padding; n.name = name;
|
// 4-byte padding → Hex32 (all usages in this test pass len=4)
|
||||||
n.parentId = rootId; n.offset = off; n.arrayLen = len;
|
Node n; n.kind = NodeKind::Hex32; n.name = name;
|
||||||
|
n.parentId = rootId; n.offset = off;
|
||||||
tree.addNode(n);
|
tree.addNode(n);
|
||||||
};
|
};
|
||||||
auto arr = [&](int off, NodeKind ek, int len, const char* name) {
|
auto arr = [&](int off, NodeKind ek, int len, const char* name) {
|
||||||
@@ -278,8 +279,8 @@ static NodeTree makeTestTree() {
|
|||||||
|
|
||||||
n.kind = NodeKind::UInt16; n.name = "Length"; n.offset = 0; tree.addNode(n);
|
n.kind = NodeKind::UInt16; n.name = "Length"; n.offset = 0; tree.addNode(n);
|
||||||
n.kind = NodeKind::UInt16; n.name = "MaximumLength"; n.offset = 2; tree.addNode(n);
|
n.kind = NodeKind::UInt16; n.name = "MaximumLength"; n.offset = 2; tree.addNode(n);
|
||||||
n.kind = NodeKind::Padding; n.name = "Pad";
|
n.kind = NodeKind::Hex32; n.name = "Pad";
|
||||||
n.offset = 4; n.arrayLen = 4; tree.addNode(n);
|
n.offset = 4; n.arrayLen = 1; tree.addNode(n);
|
||||||
n.kind = NodeKind::Pointer64; n.name = "Buffer"; n.offset = 8; n.arrayLen = 1;
|
n.kind = NodeKind::Pointer64; n.name = "Buffer"; n.offset = 8; n.arrayLen = 1;
|
||||||
tree.addNode(n);
|
tree.addNode(n);
|
||||||
}
|
}
|
||||||
@@ -751,70 +752,6 @@ private slots:
|
|||||||
m_editor->applyDocument(m_result);
|
m_editor->applyDocument(m_result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Test: Padding line rejects value editing ──
|
|
||||||
void testPaddingLineRejectsValueEdit() {
|
|
||||||
m_editor->applyDocument(m_result);
|
|
||||||
|
|
||||||
// Find a Padding line in the composed output
|
|
||||||
int paddingLine = -1;
|
|
||||||
for (int i = 0; i < m_result.meta.size(); i++) {
|
|
||||||
if (m_result.meta[i].nodeKind == NodeKind::Padding &&
|
|
||||||
m_result.meta[i].lineKind == LineKind::Field) {
|
|
||||||
paddingLine = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
QVERIFY2(paddingLine >= 0, "Should have at least one Padding line in test tree");
|
|
||||||
|
|
||||||
const LineMeta* lm = m_editor->metaForLine(paddingLine);
|
|
||||||
QVERIFY(lm);
|
|
||||||
QCOMPARE(lm->nodeKind, NodeKind::Padding);
|
|
||||||
|
|
||||||
// Value edit on Padding MUST be rejected (the bug fix)
|
|
||||||
QVERIFY2(!m_editor->beginInlineEdit(EditTarget::Value, paddingLine),
|
|
||||||
"Value edit should be rejected on Padding lines");
|
|
||||||
QVERIFY(!m_editor->isEditing());
|
|
||||||
|
|
||||||
// Name edit on Padding SHOULD succeed (ASCII preview column is editable)
|
|
||||||
bool ok = m_editor->beginInlineEdit(EditTarget::Name, paddingLine);
|
|
||||||
QVERIFY2(ok, "Name edit should be allowed on Padding lines (ASCII preview)");
|
|
||||||
QVERIFY(m_editor->isEditing());
|
|
||||||
m_editor->cancelInlineEdit();
|
|
||||||
|
|
||||||
// Type edit on Padding SHOULD succeed (emits popup signal)
|
|
||||||
QSignalSpy typeSpy(m_editor, &RcxEditor::typePickerRequested);
|
|
||||||
ok = m_editor->beginInlineEdit(EditTarget::Type, paddingLine);
|
|
||||||
QVERIFY2(ok, "Type edit should be allowed on Padding lines");
|
|
||||||
QCOMPARE(typeSpy.count(), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Test: resolvedSpanFor rejects Value on Padding (defense-in-depth) ──
|
|
||||||
void testPaddingLineRejectsValueSpan() {
|
|
||||||
m_editor->applyDocument(m_result);
|
|
||||||
|
|
||||||
// Find a Padding line
|
|
||||||
int paddingLine = -1;
|
|
||||||
for (int i = 0; i < m_result.meta.size(); i++) {
|
|
||||||
if (m_result.meta[i].nodeKind == NodeKind::Padding &&
|
|
||||||
m_result.meta[i].lineKind == LineKind::Field) {
|
|
||||||
paddingLine = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
QVERIFY(paddingLine >= 0);
|
|
||||||
|
|
||||||
const LineMeta* lm = m_editor->metaForLine(paddingLine);
|
|
||||||
QVERIFY(lm);
|
|
||||||
|
|
||||||
// valueSpanFor returns valid (shared with Hex via KF_HexPreview)
|
|
||||||
ColumnSpan vs = RcxEditor::valueSpan(*lm, 200);
|
|
||||||
QVERIFY2(vs.valid, "valueSpanFor should return valid for Padding (shared HexPreview flag)");
|
|
||||||
|
|
||||||
// But beginInlineEdit should still reject it
|
|
||||||
QVERIFY(!m_editor->beginInlineEdit(EditTarget::Value, paddingLine));
|
|
||||||
QVERIFY(!m_editor->isEditing());
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Test: value edit commit fires signal with typed text ──
|
// ── Test: value edit commit fires signal with typed text ──
|
||||||
void testValueEditCommitUpdatesSignal() {
|
void testValueEditCommitUpdatesSignal() {
|
||||||
m_editor->applyDocument(m_result);
|
m_editor->applyDocument(m_result);
|
||||||
@@ -823,8 +760,6 @@ private slots:
|
|||||||
const LineMeta* lm = m_editor->metaForLine(kFirstDataLine);
|
const LineMeta* lm = m_editor->metaForLine(kFirstDataLine);
|
||||||
QVERIFY(lm);
|
QVERIFY(lm);
|
||||||
QCOMPARE(lm->lineKind, LineKind::Field);
|
QCOMPARE(lm->lineKind, LineKind::Field);
|
||||||
QVERIFY(lm->nodeKind != NodeKind::Padding);
|
|
||||||
|
|
||||||
// Begin value edit
|
// Begin value edit
|
||||||
bool ok = m_editor->beginInlineEdit(EditTarget::Value, kFirstDataLine);
|
bool ok = m_editor->beginInlineEdit(EditTarget::Value, kFirstDataLine);
|
||||||
QVERIFY(ok);
|
QVERIFY(ok);
|
||||||
|
|||||||
@@ -418,30 +418,6 @@ private slots:
|
|||||||
QVERIFY(result.contains("wchar_t wname[32];"));
|
QVERIFY(result.contains("wchar_t wname[32];"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Padding node ──
|
|
||||||
|
|
||||||
void testPaddingNode() {
|
|
||||||
rcx::NodeTree tree;
|
|
||||||
rcx::Node root;
|
|
||||||
root.kind = rcx::NodeKind::Struct;
|
|
||||||
root.name = "PadTest";
|
|
||||||
root.structTypeName = "PadTest";
|
|
||||||
root.parentId = 0;
|
|
||||||
int ri = tree.addNode(root);
|
|
||||||
uint64_t rootId = tree.nodes[ri].id;
|
|
||||||
|
|
||||||
rcx::Node pad;
|
|
||||||
pad.kind = rcx::NodeKind::Padding;
|
|
||||||
pad.name = "reserved";
|
|
||||||
pad.parentId = rootId;
|
|
||||||
pad.offset = 0;
|
|
||||||
pad.arrayLen = 16;
|
|
||||||
tree.addNode(pad);
|
|
||||||
|
|
||||||
QString result = rcx::renderCpp(tree, rootId);
|
|
||||||
QVERIFY(result.contains("uint8_t reserved[16];"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Full SDK export (multiple root structs) ──
|
// ── Full SDK export (multiple root structs) ──
|
||||||
|
|
||||||
void testFullSdkExport() {
|
void testFullSdkExport() {
|
||||||
|
|||||||
@@ -304,39 +304,6 @@ private slots:
|
|||||||
QVERIFY(result.contains("float speed;"));
|
QVERIFY(result.contains("float speed;"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void testGenerator_typeAliases_padding() {
|
|
||||||
// Padding gap and tail padding should use aliased uint8_t
|
|
||||||
NodeTree tree;
|
|
||||||
Node root;
|
|
||||||
root.kind = NodeKind::Struct;
|
|
||||||
root.name = "PadTest";
|
|
||||||
root.structTypeName = "PadTest";
|
|
||||||
root.parentId = 0;
|
|
||||||
int ri = tree.addNode(root);
|
|
||||||
uint64_t rootId = tree.nodes[ri].id;
|
|
||||||
|
|
||||||
Node f1;
|
|
||||||
f1.kind = NodeKind::UInt32;
|
|
||||||
f1.name = "a";
|
|
||||||
f1.parentId = rootId;
|
|
||||||
f1.offset = 0;
|
|
||||||
tree.addNode(f1);
|
|
||||||
|
|
||||||
Node f2;
|
|
||||||
f2.kind = NodeKind::UInt32;
|
|
||||||
f2.name = "b";
|
|
||||||
f2.parentId = rootId;
|
|
||||||
f2.offset = 8; // gap of 4 bytes at offset 4
|
|
||||||
tree.addNode(f2);
|
|
||||||
|
|
||||||
QHash<NodeKind, QString> aliases;
|
|
||||||
aliases[NodeKind::Padding] = "BYTE";
|
|
||||||
|
|
||||||
QString result = renderCpp(tree, rootId, &aliases);
|
|
||||||
// Padding gap should use the alias
|
|
||||||
QVERIFY(result.contains("BYTE _pad"));
|
|
||||||
}
|
|
||||||
|
|
||||||
void testGenerator_typeAliases_array() {
|
void testGenerator_typeAliases_array() {
|
||||||
// Array element type should use alias
|
// Array element type should use alias
|
||||||
NodeTree tree;
|
NodeTree tree;
|
||||||
@@ -547,134 +514,92 @@ private slots:
|
|||||||
void testWorkspace_simpleTree() {
|
void testWorkspace_simpleTree() {
|
||||||
auto tree = makeSimpleTree();
|
auto tree = makeSimpleTree();
|
||||||
QStandardItemModel model;
|
QStandardItemModel model;
|
||||||
buildWorkspaceModel(&model, tree, "TestProject.rcx");
|
QVector<TabInfo> tabs = {{ &tree, "TestProject.rcx", nullptr }};
|
||||||
|
buildProjectExplorer(&model, tabs);
|
||||||
|
|
||||||
// 1 top-level item (the project)
|
// Single "Project" root
|
||||||
QCOMPARE(model.rowCount(), 1);
|
QCOMPARE(model.rowCount(), 1);
|
||||||
QStandardItem* project = model.item(0);
|
QStandardItem* project = model.item(0);
|
||||||
QCOMPARE(project->text(), QString("TestProject.rcx"));
|
QCOMPARE(project->text(), QString("Project"));
|
||||||
|
|
||||||
// Project has 1 child: the Player struct
|
// 1 type directly under Project: Player (no member fields)
|
||||||
QCOMPARE(project->rowCount(), 1);
|
QCOMPARE(project->rowCount(), 1);
|
||||||
QStandardItem* player = project->child(0);
|
QVERIFY(project->child(0)->text().contains("Player"));
|
||||||
QVERIFY(player->text().contains("Player"));
|
QVERIFY(project->child(0)->text().contains("struct"));
|
||||||
QVERIFY(player->text().contains("struct"));
|
QCOMPARE(project->child(0)->rowCount(), 0);
|
||||||
|
|
||||||
// Player struct has 2 children: health, speed
|
|
||||||
QCOMPARE(player->rowCount(), 2);
|
|
||||||
QVERIFY(player->child(0)->text().contains("health"));
|
|
||||||
QVERIFY(player->child(1)->text().contains("speed"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void testWorkspace_twoRootTree() {
|
void testWorkspace_twoRootTree() {
|
||||||
auto tree = makeTwoRootTree();
|
auto tree = makeTwoRootTree();
|
||||||
QStandardItemModel model;
|
QStandardItemModel model;
|
||||||
buildWorkspaceModel(&model, tree, "TwoRoot.rcx");
|
QVector<TabInfo> tabs = {{ &tree, "TwoRoot.rcx", nullptr }};
|
||||||
|
buildProjectExplorer(&model, tabs);
|
||||||
|
|
||||||
QCOMPARE(model.rowCount(), 1);
|
QCOMPARE(model.rowCount(), 1);
|
||||||
QStandardItem* project = model.item(0);
|
QStandardItem* project = model.item(0);
|
||||||
|
|
||||||
// 2 root struct children: Alpha and Bravo
|
// 2 types sorted alphabetically: Alpha, Bravo (no field children)
|
||||||
QCOMPARE(project->rowCount(), 2);
|
QCOMPARE(project->rowCount(), 2);
|
||||||
QVERIFY(project->child(0)->text().contains("Alpha"));
|
QVERIFY(project->child(0)->text().contains("Alpha"));
|
||||||
QVERIFY(project->child(1)->text().contains("Bravo"));
|
QVERIFY(project->child(1)->text().contains("Bravo"));
|
||||||
|
QCOMPARE(project->child(0)->rowCount(), 0);
|
||||||
// Each has 1 field child
|
QCOMPARE(project->child(1)->rowCount(), 0);
|
||||||
QCOMPARE(project->child(0)->rowCount(), 1);
|
|
||||||
QVERIFY(project->child(0)->child(0)->text().contains("flagsA"));
|
|
||||||
QCOMPARE(project->child(1)->rowCount(), 1);
|
|
||||||
QVERIFY(project->child(1)->child(0)->text().contains("flagsB"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void testWorkspace_richTree_rootCount() {
|
void testWorkspace_richTree_rootCount() {
|
||||||
auto tree = makeRichTree();
|
auto tree = makeRichTree();
|
||||||
QStandardItemModel model;
|
QStandardItemModel model;
|
||||||
buildWorkspaceModel(&model, tree, "Rich.rcx");
|
QVector<TabInfo> tabs = {{ &tree, "Rich.rcx", nullptr }};
|
||||||
|
buildProjectExplorer(&model, tabs);
|
||||||
|
|
||||||
QStandardItem* project = model.item(0);
|
QStandardItem* project = model.item(0);
|
||||||
QCOMPARE(project->rowCount(), 3); // Pet, Cat, Ball
|
QCOMPARE(project->rowCount(), 3); // Ball, Cat, Pet (sorted)
|
||||||
}
|
}
|
||||||
|
|
||||||
void testWorkspace_richTree_petChildren() {
|
void testWorkspace_richTree_sorted() {
|
||||||
auto tree = makeRichTree();
|
auto tree = makeRichTree();
|
||||||
QStandardItemModel model;
|
QStandardItemModel model;
|
||||||
buildWorkspaceModel(&model, tree, "Rich.rcx");
|
QVector<TabInfo> tabs = {{ &tree, "Rich.rcx", nullptr }};
|
||||||
|
buildProjectExplorer(&model, tabs);
|
||||||
|
|
||||||
QStandardItem* pet = model.item(0)->child(0);
|
QStandardItem* project = model.item(0);
|
||||||
QVERIFY(pet->text().contains("Pet"));
|
// Sorted alphabetically: Ball, Cat, Pet
|
||||||
// Pet has 2 non-hex children: name (UTF8), owner (Pointer64)
|
QVERIFY(project->child(0)->text().contains("Ball"));
|
||||||
QCOMPARE(pet->rowCount(), 2);
|
QVERIFY(project->child(1)->text().contains("Cat"));
|
||||||
QVERIFY(pet->child(0)->text().contains("name"));
|
QVERIFY(project->child(2)->text().contains("Pet"));
|
||||||
QVERIFY(pet->child(1)->text().contains("owner"));
|
// No member fields under type nodes
|
||||||
}
|
QCOMPARE(project->child(0)->rowCount(), 0);
|
||||||
|
QCOMPARE(project->child(1)->rowCount(), 0);
|
||||||
void testWorkspace_richTree_catNesting() {
|
QCOMPARE(project->child(2)->rowCount(), 0);
|
||||||
auto tree = makeRichTree();
|
|
||||||
QStandardItemModel model;
|
|
||||||
buildWorkspaceModel(&model, tree, "Rich.rcx");
|
|
||||||
|
|
||||||
QStandardItem* cat = model.item(0)->child(1);
|
|
||||||
QVERIFY(cat->text().contains("Cat"));
|
|
||||||
|
|
||||||
// Find the nested "Pet" struct child (base)
|
|
||||||
QStandardItem* base = nullptr;
|
|
||||||
for (int i = 0; i < cat->rowCount(); i++) {
|
|
||||||
if (cat->child(i)->text().contains("Pet") &&
|
|
||||||
cat->child(i)->text().contains("struct")) {
|
|
||||||
base = cat->child(i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
QVERIFY2(base != nullptr, "Cat should have a nested Pet struct child");
|
|
||||||
|
|
||||||
// base has structId set
|
|
||||||
QVERIFY(base->data(Qt::UserRole + 1).isValid());
|
|
||||||
|
|
||||||
// base should have its own children (name + owner)
|
|
||||||
QCOMPARE(base->rowCount(), 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
void testWorkspace_richTree_ballChildren() {
|
|
||||||
auto tree = makeRichTree();
|
|
||||||
QStandardItemModel model;
|
|
||||||
buildWorkspaceModel(&model, tree, "Rich.rcx");
|
|
||||||
|
|
||||||
QStandardItem* ball = model.item(0)->child(2);
|
|
||||||
QVERIFY(ball->text().contains("Ball"));
|
|
||||||
|
|
||||||
// Ball has 3 non-hex children: speed, position, color
|
|
||||||
QCOMPARE(ball->rowCount(), 3);
|
|
||||||
QVERIFY(ball->child(0)->text().contains("speed"));
|
|
||||||
QVERIFY(ball->child(1)->text().contains("position"));
|
|
||||||
QVERIFY(ball->child(2)->text().contains("color"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void testWorkspace_emptyTree() {
|
void testWorkspace_emptyTree() {
|
||||||
NodeTree tree;
|
NodeTree tree;
|
||||||
QStandardItemModel model;
|
QStandardItemModel model;
|
||||||
buildWorkspaceModel(&model, tree, "Empty.rcx");
|
QVector<TabInfo> tabs = {{ &tree, "Empty.rcx", nullptr }};
|
||||||
|
buildProjectExplorer(&model, tabs);
|
||||||
|
|
||||||
|
// Still has the "Project" root, just no children
|
||||||
QCOMPARE(model.rowCount(), 1);
|
QCOMPARE(model.rowCount(), 1);
|
||||||
|
QCOMPARE(model.item(0)->text(), QString("Project"));
|
||||||
QCOMPARE(model.item(0)->rowCount(), 0);
|
QCOMPARE(model.item(0)->rowCount(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void testWorkspace_structIdRole() {
|
void testWorkspace_structIdRole() {
|
||||||
auto tree = makeSimpleTree();
|
auto tree = makeSimpleTree();
|
||||||
QStandardItemModel model;
|
QStandardItemModel model;
|
||||||
buildWorkspaceModel(&model, tree, "Test.rcx");
|
QVector<TabInfo> tabs = {{ &tree, "Test.rcx", nullptr }};
|
||||||
|
buildProjectExplorer(&model, tabs);
|
||||||
|
|
||||||
QStandardItem* project = model.item(0);
|
QStandardItem* project = model.item(0);
|
||||||
// Project item should NOT have structId
|
// Project root has kGroupSentinel
|
||||||
QVERIFY(!project->data(Qt::UserRole + 1).isValid());
|
QCOMPARE(project->data(Qt::UserRole + 1).toULongLong(), kGroupSentinel);
|
||||||
|
|
||||||
// Player struct should have structId
|
// Player type item should have structId
|
||||||
QStandardItem* player = project->child(0);
|
QStandardItem* player = project->child(0);
|
||||||
QVERIFY(player->data(Qt::UserRole + 1).isValid());
|
QVERIFY(player->data(Qt::UserRole + 1).isValid());
|
||||||
QVERIFY(player->data(Qt::UserRole + 1).toULongLong() > 0);
|
QVERIFY(player->data(Qt::UserRole + 1).toULongLong() > 0);
|
||||||
|
QVERIFY(player->data(Qt::UserRole + 1).toULongLong() != kGroupSentinel);
|
||||||
// health field should NOT have structId
|
|
||||||
QStandardItem* health = player->child(0);
|
|
||||||
QVERIFY(!health->data(Qt::UserRole + 1).isValid());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ═══════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════
|
||||||
|
|||||||
251
tests/test_options_dialog.cpp
Normal file
251
tests/test_options_dialog.cpp
Normal file
@@ -0,0 +1,251 @@
|
|||||||
|
#include <QtTest/QTest>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QCheckBox>
|
||||||
|
#include <QTreeWidget>
|
||||||
|
#include <QStackedWidget>
|
||||||
|
#include <QDialogButtonBox>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QGroupBox>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QLabel>
|
||||||
|
#include "optionsdialog.h"
|
||||||
|
#include "themes/thememanager.h"
|
||||||
|
|
||||||
|
using namespace rcx;
|
||||||
|
|
||||||
|
// Helper: apply the global palette the same way main.cpp does
|
||||||
|
static void applyGlobalTheme(const Theme& theme) {
|
||||||
|
QPalette pal;
|
||||||
|
pal.setColor(QPalette::Window, theme.background);
|
||||||
|
pal.setColor(QPalette::WindowText, theme.text);
|
||||||
|
pal.setColor(QPalette::Base, theme.background);
|
||||||
|
pal.setColor(QPalette::AlternateBase, theme.surface);
|
||||||
|
pal.setColor(QPalette::Text, theme.text);
|
||||||
|
pal.setColor(QPalette::Button, theme.button);
|
||||||
|
pal.setColor(QPalette::ButtonText, theme.text);
|
||||||
|
pal.setColor(QPalette::Highlight, theme.selection);
|
||||||
|
pal.setColor(QPalette::HighlightedText, theme.text);
|
||||||
|
pal.setColor(QPalette::ToolTipBase, theme.backgroundAlt);
|
||||||
|
pal.setColor(QPalette::ToolTipText, theme.text);
|
||||||
|
pal.setColor(QPalette::Mid, theme.border);
|
||||||
|
pal.setColor(QPalette::Dark, theme.background);
|
||||||
|
pal.setColor(QPalette::Light, theme.textFaint);
|
||||||
|
pal.setColor(QPalette::Link, theme.indHoverSpan);
|
||||||
|
|
||||||
|
pal.setColor(QPalette::Disabled, QPalette::WindowText, theme.textMuted);
|
||||||
|
pal.setColor(QPalette::Disabled, QPalette::Text, theme.textMuted);
|
||||||
|
pal.setColor(QPalette::Disabled, QPalette::ButtonText, theme.textMuted);
|
||||||
|
pal.setColor(QPalette::Disabled, QPalette::HighlightedText, theme.textMuted);
|
||||||
|
pal.setColor(QPalette::Disabled, QPalette::Light, theme.background);
|
||||||
|
|
||||||
|
qApp->setPalette(pal);
|
||||||
|
qApp->setStyleSheet(QString());
|
||||||
|
}
|
||||||
|
|
||||||
|
class TestOptionsDialog : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
private slots:
|
||||||
|
|
||||||
|
void initTestCase() {
|
||||||
|
// Apply theme palette so dialog inherits real colors
|
||||||
|
auto& tm = ThemeManager::instance();
|
||||||
|
applyGlobalTheme(tm.current());
|
||||||
|
}
|
||||||
|
|
||||||
|
void dialogCreatesAllWidgets() {
|
||||||
|
OptionsResult defaults;
|
||||||
|
defaults.themeIndex = 0;
|
||||||
|
defaults.fontName = "JetBrains Mono";
|
||||||
|
defaults.menuBarTitleCase = true;
|
||||||
|
defaults.safeMode = false;
|
||||||
|
defaults.autoStartMcp = false;
|
||||||
|
|
||||||
|
OptionsDialog dlg(defaults);
|
||||||
|
|
||||||
|
// Core widgets exist
|
||||||
|
auto* tree = dlg.findChild<QTreeWidget*>();
|
||||||
|
QVERIFY(tree);
|
||||||
|
auto* pages = dlg.findChild<QStackedWidget*>();
|
||||||
|
QVERIFY(pages);
|
||||||
|
QCOMPARE(pages->count(), 3);
|
||||||
|
|
||||||
|
auto* themeCombo = dlg.findChild<QComboBox*>("themeCombo");
|
||||||
|
QVERIFY(themeCombo);
|
||||||
|
QVERIFY(themeCombo->count() >= 3);
|
||||||
|
|
||||||
|
auto* fontCombo = dlg.findChild<QComboBox*>("fontCombo");
|
||||||
|
QVERIFY(fontCombo);
|
||||||
|
QCOMPARE(fontCombo->count(), 2);
|
||||||
|
|
||||||
|
auto* showIconCheck = dlg.findChild<QCheckBox*>();
|
||||||
|
QVERIFY(showIconCheck);
|
||||||
|
|
||||||
|
auto* buttons = dlg.findChild<QDialogButtonBox*>();
|
||||||
|
QVERIFY(buttons);
|
||||||
|
QVERIFY(buttons->button(QDialogButtonBox::Ok));
|
||||||
|
QVERIFY(buttons->button(QDialogButtonBox::Cancel));
|
||||||
|
}
|
||||||
|
|
||||||
|
void resultReflectsInput() {
|
||||||
|
OptionsResult input;
|
||||||
|
input.themeIndex = 1;
|
||||||
|
input.fontName = "Consolas";
|
||||||
|
input.menuBarTitleCase = false;
|
||||||
|
input.safeMode = true;
|
||||||
|
input.autoStartMcp = true;
|
||||||
|
|
||||||
|
OptionsDialog dlg(input);
|
||||||
|
auto r = dlg.result();
|
||||||
|
|
||||||
|
QCOMPARE(r.themeIndex, 1);
|
||||||
|
QCOMPARE(r.fontName, QString("Consolas"));
|
||||||
|
QCOMPARE(r.menuBarTitleCase, false);
|
||||||
|
QCOMPARE(r.safeMode, true);
|
||||||
|
QCOMPARE(r.autoStartMcp, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void noStyleSheetOnDialog() {
|
||||||
|
OptionsResult defaults;
|
||||||
|
OptionsDialog dlg(defaults);
|
||||||
|
|
||||||
|
// Dialog itself must have no stylesheet override
|
||||||
|
QVERIFY(dlg.styleSheet().isEmpty());
|
||||||
|
|
||||||
|
// Combo boxes must have no stylesheet override
|
||||||
|
auto* themeCombo = dlg.findChild<QComboBox*>("themeCombo");
|
||||||
|
QVERIFY(themeCombo->styleSheet().isEmpty());
|
||||||
|
auto* fontCombo = dlg.findChild<QComboBox*>("fontCombo");
|
||||||
|
QVERIFY(fontCombo->styleSheet().isEmpty());
|
||||||
|
|
||||||
|
// No child widget should have a stylesheet set
|
||||||
|
for (auto* child : dlg.findChildren<QWidget*>()) {
|
||||||
|
QVERIFY2(child->styleSheet().isEmpty(),
|
||||||
|
qPrintable(QString("Widget %1 (%2) has unexpected stylesheet: %3")
|
||||||
|
.arg(child->objectName(),
|
||||||
|
child->metaObject()->className(),
|
||||||
|
child->styleSheet())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void highlightColorDiffersFromBackground() {
|
||||||
|
// Verify the palette Highlight is distinguishable from Window background
|
||||||
|
// This is the root cause of broken hover: if they're the same, hover is invisible
|
||||||
|
auto& tm = ThemeManager::instance();
|
||||||
|
const auto themes = tm.themes();
|
||||||
|
for (const auto& theme : themes) {
|
||||||
|
QVERIFY2(theme.selection != theme.background,
|
||||||
|
qPrintable(QString("Theme '%1': selection == background (%2)")
|
||||||
|
.arg(theme.name, theme.background.name())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void paletteHighlightIsSelection() {
|
||||||
|
// After applying theme, QPalette::Highlight must be theme.selection (not theme.hover)
|
||||||
|
auto& tm = ThemeManager::instance();
|
||||||
|
const auto& theme = tm.current();
|
||||||
|
applyGlobalTheme(theme);
|
||||||
|
|
||||||
|
QPalette pal = qApp->palette();
|
||||||
|
QCOMPARE(pal.color(QPalette::Highlight), theme.selection);
|
||||||
|
}
|
||||||
|
|
||||||
|
void treePageSwitching() {
|
||||||
|
OptionsResult defaults;
|
||||||
|
OptionsDialog dlg(defaults);
|
||||||
|
|
||||||
|
auto* tree = dlg.findChild<QTreeWidget*>();
|
||||||
|
auto* pages = dlg.findChild<QStackedWidget*>();
|
||||||
|
QVERIFY(tree && pages);
|
||||||
|
|
||||||
|
// General is selected by default -> page 0
|
||||||
|
QCOMPARE(pages->currentIndex(), 0);
|
||||||
|
|
||||||
|
// Find "AI Features" item and select it
|
||||||
|
auto* envItem = tree->topLevelItem(0);
|
||||||
|
QVERIFY(envItem);
|
||||||
|
QTreeWidgetItem* aiItem = nullptr;
|
||||||
|
for (int i = 0; i < envItem->childCount(); ++i) {
|
||||||
|
if (envItem->child(i)->text(0) == "AI Features") {
|
||||||
|
aiItem = envItem->child(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QVERIFY(aiItem);
|
||||||
|
tree->setCurrentItem(aiItem);
|
||||||
|
QCOMPARE(pages->currentIndex(), 1);
|
||||||
|
|
||||||
|
// Switch back to General
|
||||||
|
QTreeWidgetItem* generalItem = nullptr;
|
||||||
|
for (int i = 0; i < envItem->childCount(); ++i) {
|
||||||
|
if (envItem->child(i)->text(0) == "General") {
|
||||||
|
generalItem = envItem->child(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QVERIFY(generalItem);
|
||||||
|
tree->setCurrentItem(generalItem);
|
||||||
|
QCOMPARE(pages->currentIndex(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void searchFilterHidesItems() {
|
||||||
|
OptionsResult defaults;
|
||||||
|
OptionsDialog dlg(defaults);
|
||||||
|
|
||||||
|
auto* search = dlg.findChild<QLineEdit*>();
|
||||||
|
auto* tree = dlg.findChild<QTreeWidget*>();
|
||||||
|
QVERIFY(search && tree);
|
||||||
|
|
||||||
|
auto* envItem = tree->topLevelItem(0);
|
||||||
|
QVERIFY(envItem);
|
||||||
|
|
||||||
|
// All children visible initially
|
||||||
|
for (int i = 0; i < envItem->childCount(); ++i)
|
||||||
|
QVERIFY(!envItem->child(i)->isHidden());
|
||||||
|
|
||||||
|
// Search for "MCP" - should hide General, show AI Features
|
||||||
|
search->setText("MCP");
|
||||||
|
QTreeWidgetItem* generalItem = nullptr;
|
||||||
|
QTreeWidgetItem* aiItem = nullptr;
|
||||||
|
for (int i = 0; i < envItem->childCount(); ++i) {
|
||||||
|
auto* child = envItem->child(i);
|
||||||
|
if (child->text(0) == "General") generalItem = child;
|
||||||
|
if (child->text(0) == "AI Features") aiItem = child;
|
||||||
|
}
|
||||||
|
QVERIFY(generalItem && aiItem);
|
||||||
|
QVERIFY(generalItem->isHidden());
|
||||||
|
QVERIFY(!aiItem->isHidden());
|
||||||
|
|
||||||
|
// Clear search - all visible again
|
||||||
|
search->setText("");
|
||||||
|
QVERIFY(!generalItem->isHidden());
|
||||||
|
QVERIFY(!aiItem->isHidden());
|
||||||
|
}
|
||||||
|
|
||||||
|
void dialogInheritsPalette() {
|
||||||
|
auto& tm = ThemeManager::instance();
|
||||||
|
const auto& theme = tm.current();
|
||||||
|
applyGlobalTheme(theme);
|
||||||
|
|
||||||
|
OptionsResult defaults;
|
||||||
|
OptionsDialog dlg(defaults);
|
||||||
|
dlg.show();
|
||||||
|
QTest::qWaitForWindowExposed(&dlg);
|
||||||
|
|
||||||
|
// Dialog's effective palette should match the app palette
|
||||||
|
QPalette dlgPal = dlg.palette();
|
||||||
|
QPalette appPal = qApp->palette();
|
||||||
|
|
||||||
|
QCOMPARE(dlgPal.color(QPalette::Window), appPal.color(QPalette::Window));
|
||||||
|
QCOMPARE(dlgPal.color(QPalette::WindowText), appPal.color(QPalette::WindowText));
|
||||||
|
QCOMPARE(dlgPal.color(QPalette::Highlight), appPal.color(QPalette::Highlight));
|
||||||
|
QCOMPARE(dlgPal.color(QPalette::Button), appPal.color(QPalette::Button));
|
||||||
|
QCOMPARE(dlgPal.color(QPalette::ButtonText), appPal.color(QPalette::ButtonText));
|
||||||
|
|
||||||
|
// Highlight must be visible against background
|
||||||
|
QVERIFY(dlgPal.color(QPalette::Highlight) != dlgPal.color(QPalette::Window));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
QTEST_MAIN(TestOptionsDialog)
|
||||||
|
#include "test_options_dialog.moc"
|
||||||
@@ -8,6 +8,8 @@
|
|||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QListView>
|
#include <QListView>
|
||||||
#include <QStringListModel>
|
#include <QStringListModel>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QFrame>
|
||||||
#include <Qsci/qsciscintilla.h>
|
#include <Qsci/qsciscintilla.h>
|
||||||
#include "controller.h"
|
#include "controller.h"
|
||||||
#include "typeselectorpopup.h"
|
#include "typeselectorpopup.h"
|
||||||
@@ -198,6 +200,127 @@ private slots:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Isolate first-show cost with different window flags ──
|
||||||
|
|
||||||
|
void benchmarkFirstShow() {
|
||||||
|
auto ms = [](qint64 ns) { return QString::number(ns / 1000000.0, 'f', 2); };
|
||||||
|
|
||||||
|
struct FlagTest {
|
||||||
|
const char* name;
|
||||||
|
Qt::WindowFlags flags;
|
||||||
|
};
|
||||||
|
FlagTest tests[] = {
|
||||||
|
{"Qt::Popup|Frameless", Qt::Popup | Qt::FramelessWindowHint},
|
||||||
|
{"Qt::Tool|Frameless", Qt::Tool | Qt::FramelessWindowHint},
|
||||||
|
{"Qt::ToolTip", Qt::ToolTip},
|
||||||
|
{"Qt::Window|Frameless", Qt::Window | Qt::FramelessWindowHint},
|
||||||
|
{"Qt::Popup|Frameless (2nd)", Qt::Popup | Qt::FramelessWindowHint},
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const auto& test : tests) {
|
||||||
|
auto* f = new QFrame(nullptr, test.flags);
|
||||||
|
f->resize(300, 400);
|
||||||
|
|
||||||
|
QElapsedTimer t; t.start();
|
||||||
|
f->show();
|
||||||
|
qint64 t1 = t.nsecsElapsed(); t.restart();
|
||||||
|
QApplication::processEvents();
|
||||||
|
qint64 t2 = t.nsecsElapsed();
|
||||||
|
f->hide();
|
||||||
|
QApplication::processEvents();
|
||||||
|
|
||||||
|
t.restart();
|
||||||
|
f->show();
|
||||||
|
qint64 t3 = t.nsecsElapsed(); t.restart();
|
||||||
|
QApplication::processEvents();
|
||||||
|
qint64 t4 = t.nsecsElapsed();
|
||||||
|
f->hide();
|
||||||
|
QApplication::processEvents();
|
||||||
|
|
||||||
|
qDebug() << "";
|
||||||
|
qDebug().noquote() << QString("=== %1 ===").arg(test.name);
|
||||||
|
qDebug().noquote() << QString(" 1st: show=%1ms events=%2ms | 2nd: show=%3ms events=%4ms")
|
||||||
|
.arg(ms(t1)).arg(ms(t2)).arg(ms(t3)).arg(ms(t4));
|
||||||
|
delete f;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TypeSelectorPopup: cold vs after warmUp
|
||||||
|
{
|
||||||
|
auto* popup = new TypeSelectorPopup();
|
||||||
|
TypeEntry dummy;
|
||||||
|
dummy.entryKind = TypeEntry::Primitive;
|
||||||
|
dummy.primitiveKind = NodeKind::Hex8;
|
||||||
|
dummy.displayName = "test";
|
||||||
|
popup->setTypes({dummy});
|
||||||
|
|
||||||
|
QElapsedTimer t; t.start();
|
||||||
|
popup->show();
|
||||||
|
qint64 t1 = t.nsecsElapsed(); t.restart();
|
||||||
|
QApplication::processEvents();
|
||||||
|
qint64 t2 = t.nsecsElapsed();
|
||||||
|
popup->hide();
|
||||||
|
QApplication::processEvents();
|
||||||
|
|
||||||
|
t.restart();
|
||||||
|
popup->show();
|
||||||
|
qint64 t3 = t.nsecsElapsed(); t.restart();
|
||||||
|
QApplication::processEvents();
|
||||||
|
qint64 t4 = t.nsecsElapsed();
|
||||||
|
popup->hide();
|
||||||
|
QApplication::processEvents();
|
||||||
|
|
||||||
|
qDebug() << "";
|
||||||
|
qDebug().noquote() << QString("=== TypeSelectorPopup (cold, Qt::Popup) ===");
|
||||||
|
qDebug().noquote() << QString(" 1st: show=%1ms events=%2ms | 2nd: show=%3ms events=%4ms")
|
||||||
|
.arg(ms(t1)).arg(ms(t2)).arg(ms(t3)).arg(ms(t4));
|
||||||
|
delete popup;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean order test: dummy popup with children FIRST, then TypeSelectorPopup
|
||||||
|
qDebug() << "";
|
||||||
|
qDebug() << "=== CLEAN: dummy popup first, then TypeSelectorPopup ===";
|
||||||
|
{
|
||||||
|
auto* dummy = new QFrame(nullptr, Qt::Popup | Qt::FramelessWindowHint);
|
||||||
|
dummy->resize(300, 400);
|
||||||
|
auto* dLay = new QVBoxLayout(dummy);
|
||||||
|
dLay->addWidget(new QLabel("dummy"));
|
||||||
|
dLay->addWidget(new QLineEdit);
|
||||||
|
auto* dModel = new QStringListModel(dummy);
|
||||||
|
QStringList dItems; for (int i = 0; i < 10; i++) dItems << "x";
|
||||||
|
dModel->setStringList(dItems);
|
||||||
|
auto* dLv = new QListView; dLv->setModel(dModel);
|
||||||
|
dLay->addWidget(dLv);
|
||||||
|
|
||||||
|
QElapsedTimer t; t.start();
|
||||||
|
dummy->show();
|
||||||
|
qint64 t1 = t.nsecsElapsed(); t.restart();
|
||||||
|
QApplication::processEvents();
|
||||||
|
qint64 t2 = t.nsecsElapsed();
|
||||||
|
dummy->hide();
|
||||||
|
QApplication::processEvents();
|
||||||
|
qDebug().noquote() << QString(" Dummy popup: show=%1ms events=%2ms").arg(ms(t1)).arg(ms(t2));
|
||||||
|
delete dummy;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
auto* popup = new TypeSelectorPopup();
|
||||||
|
TypeEntry e;
|
||||||
|
e.entryKind = TypeEntry::Primitive;
|
||||||
|
e.primitiveKind = NodeKind::Hex8;
|
||||||
|
e.displayName = "test";
|
||||||
|
popup->setTypes({e});
|
||||||
|
popup->resize(300, 400);
|
||||||
|
QElapsedTimer t; t.start();
|
||||||
|
popup->show();
|
||||||
|
qint64 t1 = t.nsecsElapsed(); t.restart();
|
||||||
|
QApplication::processEvents();
|
||||||
|
qint64 t2 = t.nsecsElapsed();
|
||||||
|
popup->hide();
|
||||||
|
QApplication::processEvents();
|
||||||
|
qDebug().noquote() << QString(" TypeSelectorPopup (after dummy): show=%1ms events=%2ms").arg(ms(t1)).arg(ms(t2));
|
||||||
|
delete popup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ── Popup data model ──
|
// ── Popup data model ──
|
||||||
|
|
||||||
void testPopupListsRootStructs() {
|
void testPopupListsRootStructs() {
|
||||||
|
|||||||
@@ -57,8 +57,8 @@ static void buildValidationTree(NodeTree& tree) {
|
|||||||
field(46, NodeKind::Hex32, "field_h32");
|
field(46, NodeKind::Hex32, "field_h32");
|
||||||
field(50, NodeKind::Hex64, "field_h64");
|
field(50, NodeKind::Hex64, "field_h64");
|
||||||
field(58, NodeKind::Pointer64, "field_ptr");
|
field(58, NodeKind::Pointer64, "field_ptr");
|
||||||
field(66, NodeKind::Padding, "pad0");
|
field(66, NodeKind::Hex32, "pad0");
|
||||||
tree.nodes.last().arrayLen = 6;
|
field(70, NodeKind::Hex16, "pad1");
|
||||||
fieldArr(72, NodeKind::UInt32, 4, "field_arr");
|
fieldArr(72, NodeKind::UInt32, 4, "field_arr");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -725,9 +725,9 @@ private slots:
|
|||||||
QCOMPARE(m_doc->undoStack.count(), 0);
|
QCOMPARE(m_doc->undoStack.count(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── changeNodeKind size transitions: shrink inserts padding ──
|
// ── changeNodeKind size transitions: shrink inserts hex nodes ──
|
||||||
|
|
||||||
void testChangeKindShrinkInsertsPadding() {
|
void testChangeKindShrinkInsertsHexNodes() {
|
||||||
int idx = findNode(m_doc->tree, "field_u32");
|
int idx = findNode(m_doc->tree, "field_u32");
|
||||||
QVERIFY(idx >= 0);
|
QVERIFY(idx >= 0);
|
||||||
QCOMPARE(m_doc->tree.nodes[idx].kind, NodeKind::UInt32); // 4 bytes
|
QCOMPARE(m_doc->tree.nodes[idx].kind, NodeKind::UInt32); // 4 bytes
|
||||||
@@ -737,7 +737,7 @@ private slots:
|
|||||||
QApplication::processEvents();
|
QApplication::processEvents();
|
||||||
|
|
||||||
QCOMPARE(m_doc->tree.nodes[idx].kind, NodeKind::UInt8);
|
QCOMPARE(m_doc->tree.nodes[idx].kind, NodeKind::UInt8);
|
||||||
// Should have inserted padding nodes (Hex16 + Hex8 = 3 bytes, or similar)
|
// Should have inserted hex nodes (Hex16 + Hex8 = 3 bytes, or similar)
|
||||||
QVERIFY(m_doc->tree.nodes.size() > origCount);
|
QVERIFY(m_doc->tree.nodes.size() > origCount);
|
||||||
|
|
||||||
// Undo restores everything
|
// Undo restores everything
|
||||||
@@ -985,37 +985,6 @@ private slots:
|
|||||||
QVERIFY(!m_editor->isEditing());
|
QVERIFY(!m_editor->isEditing());
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Editor: padding value edit blocked, name/type still work ──
|
|
||||||
|
|
||||||
void testPaddingEditRestrictions() {
|
|
||||||
m_ctrl->refresh();
|
|
||||||
QApplication::processEvents();
|
|
||||||
|
|
||||||
ComposeResult result = m_doc->compose();
|
|
||||||
m_editor->applyDocument(result);
|
|
||||||
QApplication::processEvents();
|
|
||||||
|
|
||||||
// Find padding line
|
|
||||||
int padLine = -1;
|
|
||||||
for (int i = 0; i < result.meta.size(); i++) {
|
|
||||||
if (result.meta[i].nodeKind == NodeKind::Padding &&
|
|
||||||
result.meta[i].lineKind == LineKind::Field) {
|
|
||||||
padLine = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
QVERIFY(padLine >= 0);
|
|
||||||
|
|
||||||
// Value edit rejected
|
|
||||||
QVERIFY(!m_editor->beginInlineEdit(EditTarget::Value, padLine));
|
|
||||||
|
|
||||||
// Type edit accepted
|
|
||||||
bool ok = m_editor->beginInlineEdit(EditTarget::Type, padLine);
|
|
||||||
QVERIFY(ok);
|
|
||||||
m_editor->cancelInlineEdit();
|
|
||||||
QApplication::processEvents();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Editor: struct header rejects value edit ──
|
// ── Editor: struct header rejects value edit ──
|
||||||
|
|
||||||
void testStructHeaderRejectsValueEdit() {
|
void testStructHeaderRejectsValueEdit() {
|
||||||
|
|||||||
@@ -325,7 +325,7 @@ private slots:
|
|||||||
// Verify it's not all zeros (the old failure mode)
|
// Verify it's not all zeros (the old failure mode)
|
||||||
bool allZero = true;
|
bool allZero = true;
|
||||||
for (int i = 0; i < data.size(); ++i) {
|
for (int i = 0; i < data.size(); ++i) {
|
||||||
if (data[i] != 0) { allZero = false; break; }
|
if (data[i] != '\0') { allZero = false; break; }
|
||||||
}
|
}
|
||||||
QVERIFY2(!allZero, "Data is all zeros — background thread read failed");
|
QVERIFY2(!allZero, "Data is all zeros — background thread read failed");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,9 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#else
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/select.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user