Skip to content

Commit

Permalink
app: initial changes to port to Qt 6
Browse files Browse the repository at this point in the history
Signed-off-by: Bartłomiej Burdukiewicz <[email protected]>
  • Loading branch information
dev-0x7C6 committed Jan 16, 2024
1 parent 93f2a8d commit 6a0fa21
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 32 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.26)

project(fdt-viewer VERSION 0.8.1 LANGUAGES CXX)

Expand All @@ -8,11 +8,11 @@ set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(Qt5 COMPONENTS Widgets)
if (Qt5_FOUND)
find_package(Qt6 COMPONENTS Widgets Core)
if (Qt6_FOUND)
add_subdirectory("src")

if (UNIX)
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ add_executable(fdt-viewer
../resources.qrc
)

target_link_libraries(fdt-viewer PRIVATE Qt5::Widgets qhexview-lib)
target_link_libraries(fdt-viewer PRIVATE Qt6::Widgets Qt6::Core QHexView)
install(TARGETS fdt-viewer RUNTIME DESTINATION bin)
25 changes: 11 additions & 14 deletions src/endian-conversions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,19 @@
#include <bit>
#include <cstring>

constexpr u32 u32_be(const char *data) noexcept {
if constexpr (std::endian::native == std::endian::big)
return *reinterpret_cast<const u32 *>(data);

if constexpr (std::endian::native == std::endian::little)
return __builtin_bswap32(*reinterpret_cast<const u32 *>(data));

return 0;
template <std::integral T>
constexpr T byteswap(T value) noexcept {
static_assert(std::has_unique_object_representations_v<T>,
"T may not have padding bits");
auto value_representation = std::bit_cast<std::array<std::byte, sizeof(T)>>(value);
std::ranges::reverse(value_representation);
return std::bit_cast<T>(value_representation);
}

constexpr u32 u32_be(const u32 data) noexcept {
if constexpr (std::endian::native == std::endian::big)
return data;

template <std::integral T>
T convert(const T data) noexcept {
if constexpr (std::endian::native == std::endian::little)
return __builtin_bswap32(data);
return byteswap(data);

return data;
}
Expand All @@ -31,6 +28,6 @@ constexpr type read_data_32be(input_data *input) noexcept {
std::memcpy(reinterpret_cast<void *>(&container), reinterpret_cast<const void *>(input), sizeof(type));
auto *data = reinterpret_cast<u32 *>(&container);
for (auto i = 0; i < (sizeof(type) / sizeof(u32)); ++i)
data[i] = u32_be(data[i]);
data[i] = convert<u32>(data[i]);
return container;
}
2 changes: 1 addition & 1 deletion src/fdt/fdt-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void fdt_parser::parse(const fdt::header header, iface_fdt_generator &generator)
return iter += size;
};

const auto token = static_cast<fdt::token>(u32_be(iter));
const auto token = static_cast<fdt::token>(convert(*reinterpret_cast<const u32 *>(iter)));
seek_and_align(sizeof(token));

if (fdt::token::begin_node == token) {
Expand Down
12 changes: 6 additions & 6 deletions src/fdt/fdt-view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ string present(const fdt_property &property) {
return result_str({data});

if (property_type::number == info.type)
return result(string::number(u32_be(data.data())));
return result(string::number(convert(*reinterpret_cast<const u32 *>(data.data()))));
}

const static regexp cells_regexp("^#.*-cells$");
const static regexp names_regexp("^.*-names");
const static QRegularExpression cells_regexp("^#.*-cells$");
const static QRegularExpression names_regexp("^.*-names");

if (cells_regexp.exactMatch(name))
return result(string::number(u32_be(data.data())));
if (cells_regexp.match(name).hasMatch())
return result(string::number(convert(*reinterpret_cast<const u32 *>(data.data()))));

if (names_regexp.exactMatch(name)) {
if (names_regexp.match(name).hasMatch()) {
auto lines = data.split(0);
lines.removeLast();

Expand Down
5 changes: 2 additions & 3 deletions src/main-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
#include <menu-manager.hpp>
#include <viewer-settings.hpp>

#include <document/buffer/qmemorybuffer.h>
#include <document/qhexdocument.h>
#include <qhexview.h>
#include "submodules/qhexview/model/buffer/qmemorybuffer.h"
#include "submodules/qhexview/qhexview.h"

using namespace Window;

Expand Down
2 changes: 1 addition & 1 deletion src/submodules/qhexview
Submodule qhexview updated 55 files
+47 −26 CMakeLists.txt
+33 −24 QHexView.pri
+49 −43 README.md
+343 −0 dialogs/hexfinddialog.cpp
+52 −0 dialogs/hexfinddialog.h
+0 −107 document/buffer/qfilebuffer.cpp
+0 −99 document/buffer/qmemoryrefbuffer.cpp
+0 −26 document/buffer/qmemoryrefbuffer.h
+0 −3 document/commands/hexcommand.cpp
+0 −10 document/commands/insertcommand.cpp
+0 −14 document/commands/insertcommand.h
+0 −15 document/commands/removecommand.cpp
+0 −14 document/commands/removecommand.h
+0 −15 document/commands/replacecommand.cpp
+0 −17 document/commands/replacecommand.h
+0 −135 document/qhexcursor.cpp
+0 −71 document/qhexcursor.h
+0 −213 document/qhexdocument.cpp
+0 −128 document/qhexdocument.h
+0 −160 document/qhexmetadata.cpp
+0 −77 document/qhexmetadata.h
+0 −449 document/qhexrenderer.cpp
+0 −79 document/qhexrenderer.h
+130 −0 model/buffer/qdevicebuffer.cpp
+8 −12 model/buffer/qdevicebuffer.h
+2 −3 model/buffer/qhexbuffer.cpp
+1 −5 model/buffer/qhexbuffer.h
+49 −0 model/buffer/qmappedfilebuffer.cpp
+22 −0 model/buffer/qmappedfilebuffer.h
+3 −2 model/buffer/qmemorybuffer.cpp
+2 −5 model/buffer/qmemorybuffer.h
+28 −0 model/buffer/qmemoryrefbuffer.cpp
+13 −0 model/buffer/qmemoryrefbuffer.h
+3 −0 model/commands/hexcommand.cpp
+5 −5 model/commands/hexcommand.h
+16 −0 model/commands/insertcommand.cpp
+11 −0 model/commands/insertcommand.h
+20 −0 model/commands/removecommand.cpp
+11 −0 model/commands/removecommand.h
+20 −0 model/commands/replacecommand.cpp
+14 −0 model/commands/replacecommand.h
+129 −0 model/qhexcursor.cpp
+69 −0 model/qhexcursor.h
+68 −0 model/qhexdelegate.cpp
+25 −0 model/qhexdelegate.h
+103 −0 model/qhexdocument.cpp
+91 −0 model/qhexdocument.h
+149 −0 model/qhexmetadata.cpp
+64 −0 model/qhexmetadata.h
+55 −0 model/qhexoptions.h
+331 −0 model/qhexutils.cpp
+49 −0 model/qhexutils.h
+1,022 −401 qhexview.cpp
+147 −42 qhexview.h
+ screenshots/QHexView.png
4 changes: 2 additions & 2 deletions src/types.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#include <cstdint>
#include <QStringList>
#include <QRegularExpression>

using i16 = std::int16_t;
using i32 = std::int32_t;
Expand All @@ -21,7 +23,6 @@ class QFile;
class QFileInfo;
class QRegExp;
class QString;
class QStringList;
class QTreeWidget;
class QTreeWidgetItem;
class QWidget;
Expand All @@ -33,7 +34,6 @@ using byte_array = QByteArray;
using dir_iterator = QDirIterator;
using file = QFile;
using file_info = QFileInfo;
using regexp = QRegExp;
using string = QString;
using string_list = QStringList;
using tree_widget = QTreeWidget;
Expand Down

0 comments on commit 6a0fa21

Please sign in to comment.