-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fdt: moved qt generator to separate files.
Signed-off-by: Bartłomiej Burdukiewicz <bartlomiej.burdukiewicz@gmail.com>
- Loading branch information
Showing
7 changed files
with
135 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include "fdt-generator-qt.hpp" | ||
|
||
qt_tree_fdt_generator::qt_tree_fdt_generator(tree_info &reference, tree_widget *target, string &&name, string &&id) { | ||
m_root = [&]() { | ||
if (reference.root) | ||
return reference.root; | ||
|
||
auto ret = new tree_widget_item(target); | ||
reference.root = ret; | ||
return ret; | ||
}(); | ||
|
||
m_root->setText(0, name); | ||
m_root->setData(0, QT_ROLE_FILEPATH, id); | ||
m_root->setIcon(0, QIcon::fromTheme("folder-open")); | ||
m_root->setData(0, QT_ROLE_NODETYPE, QVariant::fromValue(NodeType::Node)); | ||
m_root->setExpanded(true); | ||
m_root->setSelected(true); | ||
} | ||
|
||
void qt_tree_fdt_generator::begin_node(const QString &name) noexcept { | ||
auto child = [&]() { | ||
if (m_tree_stack.empty()) | ||
return m_root; | ||
|
||
tree_widget_item *item = nullptr; | ||
tree_widget_item *root = m_tree_stack.top(); | ||
|
||
for (auto i = 0; i < root->childCount(); ++i) | ||
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)); | ||
return root->child(i); | ||
} | ||
|
||
return new tree_widget_item(root); | ||
}(); | ||
|
||
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)); | ||
} | ||
|
||
m_tree_stack.emplace(child); | ||
} | ||
|
||
void qt_tree_fdt_generator::end_node() noexcept { | ||
m_tree_stack.pop(); | ||
} | ||
|
||
void qt_tree_fdt_generator::insert_property(const fdt_property &property) noexcept { | ||
auto item = new tree_widget_item(m_tree_stack.top()); | ||
|
||
item->setText(0, property.name); | ||
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(property)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#pragma once | ||
|
||
#include <fdt/fdt-generator.hpp> | ||
#include <fdt/fdt-header.hpp> | ||
#include <fdt/fdt-property-types.hpp> | ||
#include <types.hpp> | ||
|
||
#include <QMetaType> | ||
#include <QTreeWidgetItem> | ||
#include <QHash> | ||
#include <stack> | ||
|
||
Q_DECLARE_METATYPE(fdt_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 | ||
}; | ||
|
||
Q_DECLARE_METATYPE(NodeType) | ||
|
||
template <typename... types> | ||
using hash_map = QHash<types...>; | ||
|
||
using node_map = hash_map<string, tree_widget_item *>; | ||
|
||
struct tree_info { | ||
string id; | ||
tree_widget_item *root{nullptr}; | ||
node_map nodes; | ||
}; | ||
|
||
using tree_map = hash_map<string, tree_info>; | ||
|
||
struct qt_tree_fdt_generator : public iface_fdt_generator { | ||
qt_tree_fdt_generator(tree_info &reference, tree_widget *target, string &&name, string &&id); | ||
|
||
void begin_node(const QString &name) noexcept final; | ||
void end_node() noexcept final; | ||
void insert_property(const fdt_property &property) noexcept final; | ||
|
||
private: | ||
tree_widget_item *m_root{nullptr}; | ||
std::stack<tree_widget_item *> m_tree_stack; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#pragma once | ||
|
||
#include <QByteArray> | ||
#include <QString> | ||
|
||
struct fdt_property { | ||
QString name; | ||
QByteArray data; | ||
|
||
auto clear() noexcept { | ||
name.clear(); | ||
data.clear(); | ||
} | ||
}; | ||
|
||
struct iface_fdt_generator { | ||
virtual void begin_node(const QString &name) noexcept = 0; | ||
virtual void end_node() noexcept = 0; | ||
virtual void insert_property(const fdt_property &property) noexcept = 0; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters