mirror of
https://github.com/Lurkki14/tuxclocker.git
synced 2025-02-25 18:55:24 -06:00
change FunctionEditor to take mutating parameters
This commit is contained in:
parent
6e985fda59
commit
c04c1b5c41
@ -21,6 +21,13 @@ DeviceModelDelegate::DeviceModelDelegate(QObject *parent) : QStyledItemDelegate(
|
|||||||
m_parametrize = new QAction{"Parametrize...", this};
|
m_parametrize = new QAction{"Parametrize...", this};
|
||||||
|
|
||||||
m_menu.addAction(m_parametrize);
|
m_menu.addAction(m_parametrize);
|
||||||
|
m_functionEditor = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceModelDelegate::~DeviceModelDelegate() {
|
||||||
|
// Need to delete manually since this isn't a widget
|
||||||
|
if (m_functionEditor)
|
||||||
|
delete m_functionEditor;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceModelDelegate::commitAndClose() {
|
void DeviceModelDelegate::commitAndClose() {
|
||||||
@ -95,25 +102,30 @@ bool DeviceModelDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
|
|||||||
|
|
||||||
auto data = index.data(DeviceModel::AssignableRole);
|
auto data = index.data(DeviceModel::AssignableRole);
|
||||||
auto assInfo = data.value<AssignableItemData>();
|
auto assInfo = data.value<AssignableItemData>();
|
||||||
auto proxyV = index.data(DeviceModel::AssignableProxyRole);
|
|
||||||
auto proxy = proxyV.value<AssignableProxy *>();
|
|
||||||
// TODO: need a different check for future 'Reset assignable' action
|
// TODO: need a different check for future 'Reset assignable' action
|
||||||
if (mouse->button() == Qt::RightButton && data.canConvert<AssignableItemData>() &&
|
if (mouse->button() == Qt::RightButton && data.canConvert<AssignableItemData>() &&
|
||||||
proxyV.canConvert<AssignableProxy *>() &&
|
|
||||||
std::holds_alternative<RangeInfo>(assInfo.assignableInfo())) {
|
std::holds_alternative<RangeInfo>(assInfo.assignableInfo())) {
|
||||||
// FIXME: this obviously will keep creating and showing new windows :D
|
// Initialize FunctionEditor with model once
|
||||||
// change FunctionEditor to allow mutating params to stop malloc spam?
|
if (!m_functionEditor) {
|
||||||
auto editor = new FunctionEditor(*static_cast<DeviceModel *>(model),
|
// This cast should be valid since we can fetch AssignableData
|
||||||
std::get<RangeInfo>(assInfo.assignableInfo()), *proxy,
|
auto devModel = static_cast<DeviceModel *>(model);
|
||||||
|
m_functionEditor = new FunctionEditor{*devModel};
|
||||||
|
}
|
||||||
|
m_functionEditor->setRangeInfo(
|
||||||
|
std::get<RangeInfo>(assInfo.assignableInfo()));
|
||||||
|
m_functionEditor->setAssignableName(
|
||||||
index.data(DeviceModel::NodeNameRole).toString());
|
index.data(DeviceModel::NodeNameRole).toString());
|
||||||
auto conn = connect(
|
|
||||||
m_parametrize, &QAction::triggered, [=](auto) { editor->show(); });
|
// TODO: show in main window as a page
|
||||||
|
connect(m_parametrize, &QAction::triggered,
|
||||||
|
[=](auto) { m_functionEditor->show(); });
|
||||||
m_menu.exec(mouse->globalPos());
|
m_menu.exec(mouse->globalPos());
|
||||||
|
|
||||||
// TODO: not handled in AssignableProxy
|
// TODO: not handled in AssignableProxy
|
||||||
connect(editor, &FunctionEditor::connectionDataChanged, [=](auto data) {
|
connect(m_functionEditor, &FunctionEditor::connectionDataChanged,
|
||||||
setAssignableData(model, index, "(Parametrized)", data);
|
[=](auto data) {
|
||||||
});
|
setAssignableData(model, index, "(Parametrized)", data);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,11 +4,13 @@
|
|||||||
#include <QStyledItemDelegate>
|
#include <QStyledItemDelegate>
|
||||||
|
|
||||||
class AssignableItemData;
|
class AssignableItemData;
|
||||||
|
class FunctionEditor;
|
||||||
|
|
||||||
// TODO: align checkbox to the right
|
// TODO: align checkbox to the right
|
||||||
class DeviceModelDelegate : public QStyledItemDelegate {
|
class DeviceModelDelegate : public QStyledItemDelegate {
|
||||||
public:
|
public:
|
||||||
DeviceModelDelegate(QObject *parent = nullptr);
|
DeviceModelDelegate(QObject *parent = nullptr);
|
||||||
|
~DeviceModelDelegate();
|
||||||
QWidget *createEditor(
|
QWidget *createEditor(
|
||||||
QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||||
void updateEditorGeometry(
|
void updateEditorGeometry(
|
||||||
@ -27,6 +29,7 @@ private:
|
|||||||
static void setAssignableData(
|
static void setAssignableData(
|
||||||
QAbstractItemModel *, const QModelIndex &, QString text, T data);
|
QAbstractItemModel *, const QModelIndex &, QString text, T data);
|
||||||
|
|
||||||
|
FunctionEditor *m_functionEditor;
|
||||||
QAction *m_parametrize;
|
QAction *m_parametrize;
|
||||||
QMenu m_menu;
|
QMenu m_menu;
|
||||||
};
|
};
|
||||||
|
@ -37,35 +37,6 @@ DeviceBrowser::DeviceBrowser(DeviceModel &model, QWidget *parent)
|
|||||||
|
|
||||||
connect(m_apply, &QPushButton::pressed, &m_deviceModel, &DeviceModel::applyChanges);
|
connect(m_apply, &QPushButton::pressed, &m_deviceModel, &DeviceModel::applyChanges);
|
||||||
|
|
||||||
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>();
|
|
||||||
auto proxy =
|
|
||||||
index.data(DeviceModel::AssignableProxyRole).value<AssignableProxy *>();
|
|
||||||
auto name = index.data(DeviceModel::NodeNameRole).toString();
|
|
||||||
match(a_info.assignableInfo())(
|
|
||||||
pattern(as<RangeInfo>(arg)) =
|
|
||||||
[=](auto ri) {
|
|
||||||
auto f_editor = new FunctionEditor{m_deviceModel, ri, *proxy, name};
|
|
||||||
f_editor->show();
|
|
||||||
|
|
||||||
// f_editor->assignableConnectionChanged.connect(
|
|
||||||
//[=](auto conn) { proxy->startConnection(conn); });
|
|
||||||
},
|
|
||||||
pattern(_) = [] {});
|
|
||||||
|
|
||||||
/*auto f_editor = new FunctionEditor(m_deviceModel, rangeInfo, proxy);
|
|
||||||
f_editor->show();
|
|
||||||
|
|
||||||
f_editor->assignableConnectionChanged.connect(
|
|
||||||
[&proxy] (auto assignableConnection) {
|
|
||||||
proxy.startConnection(assignableConnection);
|
|
||||||
});*/
|
|
||||||
});
|
|
||||||
|
|
||||||
m_flagEditor->setFlags(DeviceModel::AllInterfaces);
|
m_flagEditor->setFlags(DeviceModel::AllInterfaces);
|
||||||
|
|
||||||
m_flagEditor->flagsChanged.connect([=](auto flags) { m_proxyModel->setFlags(flags); });
|
m_flagEditor->flagsChanged.connect([=](auto flags) { m_proxyModel->setFlags(flags); });
|
||||||
|
@ -38,14 +38,11 @@ Q_DECLARE_METATYPE(DynamicReadableProxy *)
|
|||||||
// TODO: make constructor of the type data Editor a = Maybe (Range a)
|
// TODO: make constructor of the type data Editor a = Maybe (Range a)
|
||||||
class FunctionEditor : public QWidget {
|
class FunctionEditor : public QWidget {
|
||||||
public:
|
public:
|
||||||
FunctionEditor(DeviceModel &model, TuxClocker::Device::RangeInfo rangeInfo,
|
FunctionEditor(DeviceModel &model, QWidget *parent = nullptr)
|
||||||
AssignableProxy &proxy, QString nodeName, QWidget *parent = nullptr)
|
: QWidget(parent), m_model(model), m_proxyModel(model) {
|
||||||
: QWidget(parent), m_assignableProxy(proxy), m_model(model), m_proxyModel(model),
|
|
||||||
m_rangeInfo(rangeInfo) {
|
|
||||||
m_proxyModel.setDisableFiltered(true);
|
m_proxyModel.setDisableFiltered(true);
|
||||||
m_proxyModel.setFlags(DeviceModel::DynamicReadable);
|
m_proxyModel.setFlags(DeviceModel::DynamicReadable);
|
||||||
m_proxyModel.setShowIcons(false);
|
m_proxyModel.setShowIcons(false);
|
||||||
// m_proxyModel.setShowValueColumn(false);
|
|
||||||
|
|
||||||
m_layout = new QGridLayout(this);
|
m_layout = new QGridLayout(this);
|
||||||
m_dependableReadableComboBox = new NodeSelector;
|
m_dependableReadableComboBox = new NodeSelector;
|
||||||
@ -58,16 +55,11 @@ public:
|
|||||||
// Try not to cut off node names
|
// Try not to cut off node names
|
||||||
treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||||
|
|
||||||
m_dependableLabel = new QLabel(QString("Connecting %1 with:").arg(nodeName));
|
m_dependableLabel = new QLabel;
|
||||||
m_layout->addWidget(m_dependableLabel, 0, 0, 1, 2);
|
m_layout->addWidget(m_dependableLabel, 0, 0, 1, 2);
|
||||||
m_layout->addWidget(m_dependableReadableComboBox, 1, 0, 1, 2);
|
m_layout->addWidget(m_dependableReadableComboBox, 1, 0, 1, 2);
|
||||||
m_dragView = new DragChartView;
|
m_dragView = new DragChartView;
|
||||||
|
|
||||||
p::match(rangeInfo)(
|
|
||||||
p::pattern(p::as<TuxClocker::Device::Range<double>>(p::arg)) =
|
|
||||||
[this](auto dr) { m_dragView->setRange(0, 100, dr.min, dr.max); },
|
|
||||||
p::pattern(p::as<TuxClocker::Device::Range<int>>(p::arg)) =
|
|
||||||
[this](auto ir) { m_dragView->setRange(0, 100, ir.min, ir.max); });
|
|
||||||
// m_dragView->setRange(0, 100, 0, 100);
|
// m_dragView->setRange(0, 100, 0, 100);
|
||||||
m_layout->addWidget(m_dragView, 2, 0, 1, 2);
|
m_layout->addWidget(m_dragView, 2, 0, 1, 2);
|
||||||
m_applyButton = new QPushButton("Apply");
|
m_applyButton = new QPushButton("Apply");
|
||||||
@ -92,8 +84,6 @@ public:
|
|||||||
this->close();
|
this->close();
|
||||||
});
|
});
|
||||||
|
|
||||||
m_dragView->yAxis().setTitleText(nodeName);
|
|
||||||
|
|
||||||
m_dependableReadableComboBox->indexChanged.connect([this](auto &index) {
|
m_dependableReadableComboBox->indexChanged.connect([this](auto &index) {
|
||||||
m_latestNodeIndex = index;
|
m_latestNodeIndex = index;
|
||||||
m_applyButton->setEnabled(true);
|
m_applyButton->setEnabled(true);
|
||||||
@ -103,6 +93,19 @@ public:
|
|||||||
|
|
||||||
setLayout(m_layout);
|
setLayout(m_layout);
|
||||||
}
|
}
|
||||||
|
// Somehow existing points disappear somewhere in these two?
|
||||||
|
void setRangeInfo(TuxClocker::Device::RangeInfo rangeInfo) {
|
||||||
|
p::match(rangeInfo)(
|
||||||
|
p::pattern(p::as<TuxClocker::Device::Range<double>>(p::arg)) =
|
||||||
|
[this](auto dr) { m_dragView->setRange(0, 100, dr.min, dr.max); },
|
||||||
|
p::pattern(p::as<TuxClocker::Device::Range<int>>(p::arg)) =
|
||||||
|
[this](auto ir) { m_dragView->setRange(0, 100, ir.min, ir.max); });
|
||||||
|
}
|
||||||
|
void setAssignableName(QString name) {
|
||||||
|
m_dependableLabel->setText(QString{"Connecting %1 with:"}.arg(name));
|
||||||
|
m_dragView->yAxis().setTitleText(name);
|
||||||
|
}
|
||||||
|
|
||||||
boost::signals2::signal<void(std::shared_ptr<AssignableConnection>)>
|
boost::signals2::signal<void(std::shared_ptr<AssignableConnection>)>
|
||||||
assignableConnectionChanged;
|
assignableConnectionChanged;
|
||||||
signals:
|
signals:
|
||||||
@ -110,16 +113,13 @@ signals:
|
|||||||
private:
|
private:
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
AssignableProxy &m_assignableProxy;
|
|
||||||
DeviceModel &m_model;
|
DeviceModel &m_model;
|
||||||
DeviceProxyModel m_proxyModel;
|
DeviceProxyModel m_proxyModel;
|
||||||
DragChartView *m_dragView;
|
DragChartView *m_dragView;
|
||||||
// NodeSelector *m_nodeSelector;
|
|
||||||
QComboBox *m_functionComboBox;
|
QComboBox *m_functionComboBox;
|
||||||
NodeSelector *m_dependableReadableComboBox;
|
NodeSelector *m_dependableReadableComboBox;
|
||||||
QGridLayout *m_layout;
|
QGridLayout *m_layout;
|
||||||
QLabel *m_dependableLabel;
|
QLabel *m_dependableLabel;
|
||||||
QModelIndex m_latestNodeIndex;
|
QModelIndex m_latestNodeIndex;
|
||||||
QPushButton *m_applyButton, *m_cancelButton;
|
QPushButton *m_applyButton, *m_cancelButton;
|
||||||
TuxClocker::Device::RangeInfo m_rangeInfo;
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user