2020-07-21 17:50:01 +03:00
|
|
|
#include "DeviceBrowser.hpp"
|
|
|
|
|
#include "AssignableItemData.hpp"
|
|
|
|
|
#include "qnamespace.h"
|
|
|
|
|
|
|
|
|
|
#include <patterns.hpp>
|
|
|
|
|
#include <QVariant>
|
|
|
|
|
|
|
|
|
|
using namespace mpark::patterns;
|
|
|
|
|
using namespace TuxClocker::Device;
|
|
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(AssignableItemData)
|
2023-07-26 16:33:11 +03:00
|
|
|
Q_DECLARE_METATYPE(AssignableProxy *)
|
2020-07-21 17:50:01 +03:00
|
|
|
|
2023-07-26 16:33:11 +03:00
|
|
|
DeviceBrowser::DeviceBrowser(DeviceModel &model, QWidget *parent)
|
|
|
|
|
: QWidget(parent), m_deviceModel(model) {
|
2020-07-21 17:50:01 +03:00
|
|
|
m_layout = new QGridLayout(this);
|
|
|
|
|
m_proxyModel = new DeviceProxyModel(model, this);
|
|
|
|
|
m_treeView = new DeviceTreeView;
|
|
|
|
|
m_treeView->setModel(m_proxyModel);
|
2023-07-24 13:18:46 +03:00
|
|
|
|
|
|
|
|
// Expand all nodes
|
|
|
|
|
// TODO: remember collapsed nodes
|
|
|
|
|
m_treeView->expandAll();
|
|
|
|
|
|
2020-07-21 17:50:01 +03:00
|
|
|
m_flagLabel = new QLabel("Showing:");
|
|
|
|
|
m_apply = new QPushButton("Apply changes");
|
|
|
|
|
m_apply->setEnabled(true);
|
2023-07-26 16:33:11 +03:00
|
|
|
|
2020-07-21 17:50:01 +03:00
|
|
|
m_flagEditor = new FlagEditor(
|
2023-07-26 16:33:11 +03:00
|
|
|
QVector({std::tuple(QString("Assignables"), DeviceModel::assignableIcon(),
|
|
|
|
|
DeviceModel::Assignable),
|
|
|
|
|
std::tuple(QString("Dynamic Values"), DeviceModel::dynamicReadableIcon(),
|
|
|
|
|
DeviceModel::DynamicReadable),
|
|
|
|
|
std::tuple(QString("Static Values"), DeviceModel::staticReadableIcon(),
|
|
|
|
|
DeviceModel::StaticReadable)}),
|
|
|
|
|
this);
|
|
|
|
|
|
|
|
|
|
connect(m_apply, &QPushButton::pressed, &m_deviceModel, &DeviceModel::applyChanges);
|
|
|
|
|
|
2020-07-21 17:50:01 +03:00
|
|
|
m_treeView->functionEditorRequested.connect([this](QModelIndex &index) {
|
|
|
|
|
auto a_data = index.data(DeviceModel::AssignableRole);
|
|
|
|
|
if (!a_data.isValid())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
auto a_info = a_data.value<AssignableItemData>();
|
2023-07-26 16:33:11 +03:00
|
|
|
auto proxy =
|
|
|
|
|
index.data(DeviceModel::AssignableProxyRole).value<AssignableProxy *>();
|
2020-07-21 17:50:01 +03:00
|
|
|
auto name = index.data(DeviceModel::NodeNameRole).toString();
|
2023-07-26 16:33:11 +03:00
|
|
|
match(a_info.assignableInfo())(
|
|
|
|
|
pattern(as<RangeInfo>(arg)) =
|
|
|
|
|
[=](auto ri) {
|
|
|
|
|
auto f_editor = new FunctionEditor{m_deviceModel, ri, *proxy, name};
|
2020-07-21 17:50:01 +03:00
|
|
|
f_editor->show();
|
2023-07-26 16:33:11 +03:00
|
|
|
f_editor->assignableConnectionChanged.connect(
|
|
|
|
|
[=](auto conn) { proxy->startConnection(conn); });
|
2020-07-21 17:50:01 +03:00
|
|
|
},
|
2023-07-26 16:33:11 +03:00
|
|
|
pattern(_) = [] {});
|
2020-07-21 17:50:01 +03:00
|
|
|
|
|
|
|
|
/*auto f_editor = new FunctionEditor(m_deviceModel, rangeInfo, proxy);
|
|
|
|
|
f_editor->show();
|
|
|
|
|
|
|
|
|
|
f_editor->assignableConnectionChanged.connect(
|
|
|
|
|
[&proxy] (auto assignableConnection) {
|
|
|
|
|
proxy.startConnection(assignableConnection);
|
|
|
|
|
});*/
|
|
|
|
|
});
|
2023-07-26 16:33:11 +03:00
|
|
|
|
2020-07-21 17:50:01 +03:00
|
|
|
m_flagEditor->setFlags(DeviceModel::AllInterfaces);
|
2023-07-26 16:33:11 +03:00
|
|
|
|
|
|
|
|
m_flagEditor->flagsChanged.connect([=](auto flags) { m_proxyModel->setFlags(flags); });
|
|
|
|
|
|
2020-07-21 17:50:01 +03:00
|
|
|
m_layout->addWidget(m_flagLabel, 0, 0);
|
|
|
|
|
m_layout->addWidget(m_flagEditor, 0, 1);
|
|
|
|
|
m_layout->addWidget(m_treeView, 1, 0, 1, 2);
|
|
|
|
|
m_layout->addWidget(m_apply, 2, 0, 1, 2);
|
2023-07-26 16:33:11 +03:00
|
|
|
|
2020-07-21 17:50:01 +03:00
|
|
|
setLayout(m_layout);
|
|
|
|
|
}
|