Skip to content

Commit

Permalink
qt: moved data id enums to fdt::qt_wrappers
Browse files Browse the repository at this point in the history
Signed-off-by: Bartłomiej Burdukiewicz <bartlomiej.burdukiewicz@gmail.com>
  • Loading branch information
dev-0x7C6 committed Jul 4, 2024
1 parent 5f95062 commit 839e055
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
12 changes: 6 additions & 6 deletions src/fdt/fdt-generator-qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ tree_generator::tree_generator(tree_info &reference, QTreeWidget *target, QStrin

m_root->setText(0, name);
m_root->setIcon(0, QIcon::fromTheme("folder-open"));
m_root->setData(0, QT_ROLE_FILEPATH, id);
m_root->setData(0, QT_ROLE_NODETYPE, QVariant::fromValue(NodeType::Node));
m_root->setData(0, ROLE_FILEPATH, id);
m_root->setData(0, ROLE_NODETYPE, QVariant::fromValue(NodeType::Node));
m_root->setExpanded(true);
m_root->setSelected(true);
}
Expand All @@ -38,7 +38,7 @@ void tree_generator::begin_node(std::string_view vname) noexcept {
if (root->child(i)->text(0) == name) {
auto ret = root->child(i);
ret->setIcon(0, QIcon::fromTheme("folder-new"));
ret->setData(0, QT_ROLE_NODETYPE, QVariant::fromValue(NodeType::Node));
ret->setData(0, ROLE_NODETYPE, QVariant::fromValue(NodeType::Node));
return root->child(i);
}

Expand All @@ -48,7 +48,7 @@ void tree_generator::begin_node(std::string_view vname) noexcept {
if (child->text(0).isEmpty()) {
child->setText(0, name);
child->setIcon(0, QIcon::fromTheme("folder-open"));
child->setData(0, QT_ROLE_NODETYPE, QVariant::fromValue(NodeType::Node));
child->setData(0, ROLE_NODETYPE, QVariant::fromValue(NodeType::Node));
}

m_tree_stack.emplace(child);
Expand All @@ -68,6 +68,6 @@ void tree_generator::insert_property(const fdt::parser::token_types::property &p

item->setText(0, QString::fromUtf8(prop.name.data(), prop.name.size()));
item->setIcon(0, QIcon::fromTheme("flag-green"));
item->setData(0, QT_ROLE_NODETYPE, QVariant::fromValue(NodeType::Property));
item->setData(0, QT_ROLE_PROPERTY, QVariant::fromValue(std::move(property)));
item->setData(0, ROLE_NODETYPE, QVariant::fromValue(NodeType::Property));
item->setData(0, ROLE_PROPERTY, QVariant::fromValue(std::move(property)));
}
9 changes: 5 additions & 4 deletions src/fdt/fdt-generator-qt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@

Q_DECLARE_METATYPE(fdt::qt_wrappers::property)

constexpr auto QT_ROLE_PROPERTY = Qt::UserRole;
constexpr auto QT_ROLE_FILEPATH = Qt::UserRole + 1;
constexpr auto QT_ROLE_NODETYPE = Qt::UserRole + 2;

enum class NodeType {
Node,
Property
Expand All @@ -38,6 +34,11 @@ using tree_map = hash_map<QString, tree_info>;

namespace fdt::qt_wrappers {

constexpr auto ROLE_PROPERTY = Qt::UserRole;
constexpr auto ROLE_FILEPATH = Qt::UserRole + 1;
constexpr auto ROLE_NODETYPE = Qt::UserRole + 2;
constexpr auto ROLE_DATA_HOLDER = Qt::UserRole + 3;

struct tree_generator {
tree_generator(tree_info &reference, QTreeWidget *target, QString &&name, QString &&id);

Expand Down
8 changes: 4 additions & 4 deletions src/fdt/fdt-view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ bool fdt::fdt_content_filter(QTreeWidgetItem *node, const std::function<bool(con

for (auto i = 0; i < node->childCount(); ++i) {
const auto child = node->child(i);
switch (child->data(0, QT_ROLE_NODETYPE).value<NodeType>()) {
switch (child->data(0, fdt::qt_wrappers::ROLE_NODETYPE).value<NodeType>()) {
case NodeType::Node:
nodes.append(child);
break;
Expand All @@ -156,7 +156,7 @@ bool fdt::fdt_content_filter(QTreeWidgetItem *node, const std::function<bool(con
if (isFound)
break;

const auto property = item->data(0, QT_ROLE_PROPERTY).value<fdt::qt_wrappers::property>();
const auto property = item->data(0, fdt::qt_wrappers::ROLE_PROPERTY).value<fdt::qt_wrappers::property>();
isFound |= match(property.name) || match(present(property));
}

Expand All @@ -178,7 +178,7 @@ bool fdt::fdt_view_dts(QTreeWidgetItem *item, QString &ret, int depth) {

for (auto i = 0; i < item->childCount(); ++i) {
const auto child = item->child(i);
switch (child->data(0, QT_ROLE_NODETYPE).value<NodeType>()) {
switch (child->data(0, fdt::qt_wrappers::ROLE_NODETYPE).value<NodeType>()) {
case NodeType::Node:
nodes.append(child);
break;
Expand All @@ -194,7 +194,7 @@ bool fdt::fdt_view_dts(QTreeWidgetItem *item, QString &ret, int depth) {
ret += depth_str + item->data(0, Qt::DisplayRole).toString() + " {\n";

for (auto item : properties) {
const auto property = item->data(0, QT_ROLE_PROPERTY).value<fdt::qt_wrappers::property>();
const auto property = item->data(0, fdt::qt_wrappers::ROLE_PROPERTY).value<fdt::qt_wrappers::property>();
ret += depth_str + " " + present(property) + "\n";
}

Expand Down
11 changes: 5 additions & 6 deletions src/main-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "fdt/fdt-parser-tokens.hpp"
#include "fdt/fdt-property-types.hpp"
#include "qabstractitemview.h"
#include "qelapsedtimer.h"
#include "ui_main-window.h"

#include <QAction>
Expand Down Expand Up @@ -160,7 +159,7 @@ void MainWindow::update_fdt_path(QTreeWidgetItem *item) {

m_fdt = root;

m_ui->statusbar->showMessage("file://" + root->data(0, QT_ROLE_FILEPATH).toString());
m_ui->statusbar->showMessage("file://" + root->data(0, fdt::qt_wrappers::ROLE_FILEPATH).toString());
m_ui->path->setText("fdt://" + path);
}

Expand All @@ -181,11 +180,11 @@ void MainWindow::update_view() {

const auto item = m_ui->treeWidget->selectedItems().first();

const auto type = item->data(0, QT_ROLE_NODETYPE).value<NodeType>();
const auto type = item->data(0, fdt::qt_wrappers::ROLE_NODETYPE).value<NodeType>();
m_ui->preview->setCurrentWidget(NodeType::Node == type ? m_ui->text_view_page : m_ui->property_view_page);

if (NodeType::Property == type) {
const auto property = item->data(0, QT_ROLE_PROPERTY).value<fdt::qt_wrappers::property>();
const auto property = item->data(0, fdt::qt_wrappers::ROLE_PROPERTY).value<fdt::qt_wrappers::property>();
m_hexview->setDocument(QHexDocument::fromMemory<QMemoryBuffer>(property.data));
}

Expand All @@ -203,10 +202,10 @@ void MainWindow::property_export() {
return;

const auto item = m_ui->treeWidget->selectedItems().first();
const auto type = item->data(0, QT_ROLE_NODETYPE).value<NodeType>();
const auto type = item->data(0, fdt::qt_wrappers::ROLE_NODETYPE).value<NodeType>();

if (NodeType::Property == type) {
const auto property = item->data(0, QT_ROLE_PROPERTY).value<fdt::qt_wrappers::property>();
const auto property = item->data(0, fdt::qt_wrappers::ROLE_PROPERTY).value<fdt::qt_wrappers::property>();

m_hexview->setDocument(QHexDocument::fromMemory<QMemoryBuffer>(property.data));
fdt::export_property_file_dialog(this, property.data, property.name);
Expand Down

0 comments on commit 839e055

Please sign in to comment.