qt: add AssignableManager class

This commit is contained in:
jussi 2019-10-22 22:33:40 +03:00
parent f8d0dbb7b8
commit 07a05e004d
3 changed files with 55 additions and 3 deletions

View File

@ -0,0 +1,36 @@
#include "AssignableManager.h"
AssignableManager::AssignableManager() {
// Open all assignable modules
uint16_t mod_count;
tc_module_t **assignableModules = tc_module_find_all_from_category(TC_CATEGORY_ASSIGNABLE, &mod_count);
// Try to initialize every module
for (uint16_t i = 0; i < mod_count; i++) {
if (assignableModules[i]->init_callback != NULL) {
if (assignableModules[i]->init_callback() != TC_SUCCESS) {
// Couldn't initialize, close module
tc_module_close(assignableModules[i]);
}
// Add module to the list
m_assignableModules.append(assignableModules[i]);
}
}
// Obtain root node from each module
for (tc_module_t *module : m_assignableModules) {
tc_assignable_node_t *root = static_cast<tc_assignable_node_t*>(module->category_data_callback());
if (root == NULL) {
m_assignableModules.remove(m_assignableModules.indexOf(module));
}
m_assignableRootNodes.append(root);
}
delete assignableModules;
}
AssignableManager::~AssignableManager() {
// Close all modules
for (tc_module_t *module : m_assignableModules) {
tc_module_close(module);
}
}

View File

@ -0,0 +1,17 @@
#include <tc_assignable.h>
#include <tc_module.h>
#include <QVector>
// Initializes, holds and closes the list of assignable modules
class AssignableManager {
public:
AssignableManager();
~AssignableManager();
// Return a list of root assignable nodes
QList <tc_assignable_node_t*> rootNodes();
private:
QVector <tc_module_t*> m_assignableModules;
QVector <tc_assignable_node_t*> m_assignableRootNodes;
};

View File

@ -4,7 +4,6 @@ qt5_dep = dependency('qt5',
moc_files = qt5.preprocess(moc_headers : [ 'MainWindow.h',
'widgets/AssignableWidget.h',
'widgets/AssignableEditor.h',
'widgets/IntRangeEditor.h',
'widgets/EnumEditor.h',
'data/AssignableEditorDelegate.h'],
@ -13,11 +12,11 @@ moc_files = qt5.preprocess(moc_headers : [ 'MainWindow.h',
sources = ['main.cpp',
'MainWindow.cpp',
'widgets/AssignableWidget.cpp',
'widgets/AssignableEditor.cpp',
'widgets/IntRangeEditor.cpp',
'widgets/EnumEditor.cpp',
'data/AssignableData.cpp',
'data/AssignableEditorDelegate.cpp']
'data/AssignableEditorDelegate.cpp',
'data/AssignableManager.cpp']
local_qt_incdirs = ['widgets', 'data']