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_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() {
|
||||
@ -95,25 +102,30 @@ bool DeviceModelDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
|
||||
|
||||
auto data = index.data(DeviceModel::AssignableRole);
|
||||
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
|
||||
if (mouse->button() == Qt::RightButton && data.canConvert<AssignableItemData>() &&
|
||||
proxyV.canConvert<AssignableProxy *>() &&
|
||||
std::holds_alternative<RangeInfo>(assInfo.assignableInfo())) {
|
||||
// FIXME: this obviously will keep creating and showing new windows :D
|
||||
// change FunctionEditor to allow mutating params to stop malloc spam?
|
||||
auto editor = new FunctionEditor(*static_cast<DeviceModel *>(model),
|
||||
std::get<RangeInfo>(assInfo.assignableInfo()), *proxy,
|
||||
// Initialize FunctionEditor with model once
|
||||
if (!m_functionEditor) {
|
||||
// This cast should be valid since we can fetch AssignableData
|
||||
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());
|
||||
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());
|
||||
|
||||
// TODO: not handled in AssignableProxy
|
||||
connect(editor, &FunctionEditor::connectionDataChanged, [=](auto data) {
|
||||
setAssignableData(model, index, "(Parametrized)", data);
|
||||
});
|
||||
connect(m_functionEditor, &FunctionEditor::connectionDataChanged,
|
||||
[=](auto data) {
|
||||
setAssignableData(model, index, "(Parametrized)", data);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,11 +4,13 @@
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
class AssignableItemData;
|
||||
class FunctionEditor;
|
||||
|
||||
// TODO: align checkbox to the right
|
||||
class DeviceModelDelegate : public QStyledItemDelegate {
|
||||
public:
|
||||
DeviceModelDelegate(QObject *parent = nullptr);
|
||||
~DeviceModelDelegate();
|
||||
QWidget *createEditor(
|
||||
QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
void updateEditorGeometry(
|
||||
@ -27,6 +29,7 @@ private:
|
||||
static void setAssignableData(
|
||||
QAbstractItemModel *, const QModelIndex &, QString text, T data);
|
||||
|
||||
FunctionEditor *m_functionEditor;
|
||||
QAction *m_parametrize;
|
||||
QMenu m_menu;
|
||||
};
|
||||
|
@ -37,35 +37,6 @@ DeviceBrowser::DeviceBrowser(DeviceModel &model, QWidget *parent)
|
||||
|
||||
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->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)
|
||||
class FunctionEditor : public QWidget {
|
||||
public:
|
||||
FunctionEditor(DeviceModel &model, TuxClocker::Device::RangeInfo rangeInfo,
|
||||
AssignableProxy &proxy, QString nodeName, QWidget *parent = nullptr)
|
||||
: QWidget(parent), m_assignableProxy(proxy), m_model(model), m_proxyModel(model),
|
||||
m_rangeInfo(rangeInfo) {
|
||||
FunctionEditor(DeviceModel &model, QWidget *parent = nullptr)
|
||||
: QWidget(parent), m_model(model), m_proxyModel(model) {
|
||||
m_proxyModel.setDisableFiltered(true);
|
||||
m_proxyModel.setFlags(DeviceModel::DynamicReadable);
|
||||
m_proxyModel.setShowIcons(false);
|
||||
// m_proxyModel.setShowValueColumn(false);
|
||||
|
||||
m_layout = new QGridLayout(this);
|
||||
m_dependableReadableComboBox = new NodeSelector;
|
||||
@ -58,16 +55,11 @@ public:
|
||||
// Try not to cut off node names
|
||||
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_dependableReadableComboBox, 1, 0, 1, 2);
|
||||
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_layout->addWidget(m_dragView, 2, 0, 1, 2);
|
||||
m_applyButton = new QPushButton("Apply");
|
||||
@ -92,8 +84,6 @@ public:
|
||||
this->close();
|
||||
});
|
||||
|
||||
m_dragView->yAxis().setTitleText(nodeName);
|
||||
|
||||
m_dependableReadableComboBox->indexChanged.connect([this](auto &index) {
|
||||
m_latestNodeIndex = index;
|
||||
m_applyButton->setEnabled(true);
|
||||
@ -103,6 +93,19 @@ public:
|
||||
|
||||
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>)>
|
||||
assignableConnectionChanged;
|
||||
signals:
|
||||
@ -110,16 +113,13 @@ signals:
|
||||
private:
|
||||
Q_OBJECT
|
||||
|
||||
AssignableProxy &m_assignableProxy;
|
||||
DeviceModel &m_model;
|
||||
DeviceProxyModel m_proxyModel;
|
||||
DragChartView *m_dragView;
|
||||
// NodeSelector *m_nodeSelector;
|
||||
QComboBox *m_functionComboBox;
|
||||
NodeSelector *m_dependableReadableComboBox;
|
||||
QGridLayout *m_layout;
|
||||
QLabel *m_dependableLabel;
|
||||
QModelIndex m_latestNodeIndex;
|
||||
QPushButton *m_applyButton, *m_cancelButton;
|
||||
TuxClocker::Device::RangeInfo m_rangeInfo;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user