interface: display assignables in tree view

This commit is contained in:
jussi 2019-10-06 18:38:52 +03:00
parent 5297940e3d
commit 4639951c8a
6 changed files with 44 additions and 16 deletions

View File

@ -0,0 +1,14 @@
#pragma once
// Contains functions and definitions for dealing with files
#ifdef __cplusplus
extern "C" {
#endif
// Get filename list from a folder
char **tc_fs_folder_filenames();
#ifdef __cplusplus
}
#endif

View File

@ -103,6 +103,7 @@ tc_module_t *tc_module_find(enum tc_module_category category, const char *name)
}
tc_module_t **tc_module_find_all_from_category(enum tc_module_category category, uint16_t *count) {
// Get the file name list of the category modules
return NULL;

View File

@ -12,6 +12,8 @@ int main(int argc, char **argv) {
if (mod != NULL) {
printf("successful load for %s\n", mod->name);
mod->init_callback(argc, argv);
tc_module_close(mod);
}
return 0;

View File

@ -99,7 +99,6 @@ static int8_t generate_assignable_tree() {
// Got the name, append the item to the root item
tc_assignable_node_t *gpu_name_node = tc_assignable_node_new();
gpu_name_node->name = strdup(gpu_name);
printf("%s\n", gpu_name_node->name);
// Append to the root node
if (tc_assignable_node_add_child(root_node, gpu_name_node) != TC_SUCCESS) {
@ -140,4 +139,5 @@ void add_power_limit_item(tc_assignable_node_t *parent, nvmlDevice_t dev) {
};
power_node->value_category = TC_ASSIGNABLE_RANGE;
power_node->range_info = range;
power_node->name = "Power Limit";
}

View File

@ -10,9 +10,9 @@ AssignableWidget::AssignableWidget(QWidget *parent) : QWidget(parent) {
m_splitter = new QSplitter;
m_mainLayout->addWidget(m_splitter);
m_assignableTreeView = new QTreeView;
genAssignableTree(m_assignableTreeView);
m_splitter->addWidget(m_assignableTreeView);
m_assignableTreeWidget = new QTreeWidget;
genAssignableTree(m_assignableTreeWidget);
m_splitter->addWidget(m_assignableTreeWidget);
m_assignableEditor = new AssignableEditor;
m_splitter->addWidget(m_assignableEditor);
@ -23,7 +23,7 @@ AssignableWidget::AssignableWidget(QWidget *parent) : QWidget(parent) {
AssignableWidget::~AssignableWidget() {
}
void AssignableWidget::genAssignableTree(QTreeView* treeView) {
void AssignableWidget::genAssignableTree(QTreeWidget* treeWidget) {
tc_module_t *nv_mod = tc_module_find(TC_CATEGORY_ASSIGNABLE, "nvidia");
if (nv_mod != NULL) {
@ -36,31 +36,42 @@ void AssignableWidget::genAssignableTree(QTreeView* treeView) {
return;
}
QTreeWidgetItem *item = new QTreeWidgetItem;
tc_assignable_node_t *parent = (tc_assignable_node_t*) nv_mod->category_data_callback();
tc_assignable_node_t *root= (tc_assignable_node_t*) nv_mod->category_data_callback();
if (parent == NULL) {
if (root == NULL) {
return;
}
std::function<void(tc_assignable_node_t*)> traverse;
traverse = [=, &traverse](tc_assignable_node_t *node) {
std::function<void(tc_assignable_node_t*, QTreeWidgetItem*)> traverse;
traverse = [=, &traverse](tc_assignable_node_t *node, QTreeWidgetItem *item) {
if (node == NULL) {
return;
}
QTreeWidgetItem *newItem = new QTreeWidgetItem;
if (node->name != NULL) {
qDebug() << node->name;
newItem->setText(0, QString(node->name));
}
item->addChild(newItem);
if (node->children_count == 0) {
return;
}
for (uint32_t i = 0; i < node->children_count; i++) {
traverse(node->children_nodes[i]);
traverse(node->children_nodes[i], newItem);
}
};
qDebug() << "traversing nodes" << parent->children_count << parent << parent->children_nodes[0];
qDebug() << "traversing nodes";
traverse(parent);
QTreeWidgetItem *item = new QTreeWidgetItem;
item->setText(0, root->name);
m_assignableTreeWidget->addTopLevelItem(item);
traverse(root, item);
connect(m_assignableTreeWidget, &QTreeWidget::currentItemChanged, []() {qDebug("item changed");});
}

View File

@ -5,7 +5,7 @@
#include <QWidget>
#include <QSplitter>
#include <QLayout>
#include <QTreeView>
#include <QTreeWidget>
#include <QTreeWidgetItem>
class AssignableWidget : public QWidget {
@ -18,8 +18,8 @@ private:
QGridLayout *m_mainLayout;
// Splitter for editor and viewer
QSplitter *m_splitter;
QTreeView *m_assignableTreeView;
QTreeWidget *m_assignableTreeWidget;
AssignableEditor *m_assignableEditor;
void genAssignableTree(QTreeView *treeView);
void genAssignableTree(QTreeWidget *treeWidget);
};