mirror of
https://github.com/Lurkki14/tuxclocker.git
synced 2025-02-25 18:55:24 -06:00
save parametrization data in DeviceModel
This commit is contained in:
parent
0293e8606f
commit
7d74a17e8c
@ -3,9 +3,13 @@
|
||||
#include "DeviceModel.hpp"
|
||||
#include <DoubleRangeEditor.hpp>
|
||||
#include <EnumEditor.hpp>
|
||||
#include <FunctionEditor.hpp>
|
||||
#include <IntRangeEditor.hpp>
|
||||
#include <patterns.hpp>
|
||||
#include <QDebug>
|
||||
#include <QEvent>
|
||||
#include <QMenu>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
|
||||
using namespace TuxClocker::Device;
|
||||
@ -13,7 +17,11 @@ using namespace mpark::patterns;
|
||||
|
||||
Q_DECLARE_METATYPE(AssignableItemData)
|
||||
|
||||
DeviceModelDelegate::DeviceModelDelegate(QObject *parent) : QStyledItemDelegate(parent) {}
|
||||
DeviceModelDelegate::DeviceModelDelegate(QObject *parent) : QStyledItemDelegate(parent) {
|
||||
m_parametrize = new QAction{"Parametrize...", this};
|
||||
|
||||
m_menu.addAction(m_parametrize);
|
||||
}
|
||||
|
||||
void DeviceModelDelegate::commitAndClose() {
|
||||
// It's also retarded to get the editor this way when we could just use it in the lambda
|
||||
@ -84,6 +92,54 @@ void DeviceModelDelegate::updateEditorGeometry(
|
||||
editor->setGeometry(option.rect);
|
||||
}
|
||||
|
||||
bool DeviceModelDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
|
||||
const QStyleOptionViewItem &item, const QModelIndex &index) {
|
||||
// Context menu handling
|
||||
if (event->type() == QEvent::MouseButtonRelease) {
|
||||
auto mouse = dynamic_cast<QMouseEvent *>(event);
|
||||
|
||||
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,
|
||||
index.data(DeviceModel::NodeNameRole).toString());
|
||||
auto conn = connect(
|
||||
m_parametrize, &QAction::triggered, [=](auto) { editor->show(); });
|
||||
m_menu.exec(mouse->globalPos());
|
||||
|
||||
// TODO: not handled in AssignableProxy
|
||||
connect(editor, &FunctionEditor::connectionDataChanged, [=](auto data) {
|
||||
setAssignableData(model, index, "(Parametrized)", data);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return QStyledItemDelegate::editorEvent(event, model, item, index);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void DeviceModelDelegate::setAssignableData(
|
||||
QAbstractItemModel *model, const QModelIndex &index, QString text, T data) {
|
||||
auto assData = index.data(DeviceModel::AssignableRole).value<AssignableItemData>();
|
||||
QVariant assV;
|
||||
assV.setValue(data);
|
||||
assData.setValue(assV);
|
||||
|
||||
QVariant v;
|
||||
v.setValue(assData);
|
||||
|
||||
model->setData(index, text, Qt::DisplayRole);
|
||||
model->setData(index, v, DeviceModel::AssignableRole);
|
||||
}
|
||||
|
||||
QColor alphaBlend(QColor top, QColor background) {
|
||||
auto alpha = top.alphaF();
|
||||
auto factor = 1 - alpha;
|
||||
|
@ -1,7 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <QMenu>
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
class AssignableItemData;
|
||||
|
||||
// TODO: align checkbox to the right
|
||||
class DeviceModelDelegate : public QStyledItemDelegate {
|
||||
public:
|
||||
@ -13,9 +16,16 @@ public:
|
||||
void setEditorData(QWidget *editor, const QModelIndex &index) const;
|
||||
void setModelData(
|
||||
QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
|
||||
bool editorEvent(QEvent *, QAbstractItemModel *, const QStyleOptionViewItem &,
|
||||
const QModelIndex &) override;
|
||||
protected:
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const override;
|
||||
private:
|
||||
void commitAndClose();
|
||||
template <typename T>
|
||||
void setAssignableData(QAbstractItemModel *, const QModelIndex &, QString text, T data);
|
||||
|
||||
QAction *m_parametrize;
|
||||
QMenu m_menu;
|
||||
};
|
||||
|
@ -51,8 +51,9 @@ DeviceBrowser::DeviceBrowser(DeviceModel &model, QWidget *parent)
|
||||
[=](auto ri) {
|
||||
auto f_editor = new FunctionEditor{m_deviceModel, ri, *proxy, name};
|
||||
f_editor->show();
|
||||
f_editor->assignableConnectionChanged.connect(
|
||||
[=](auto conn) { proxy->startConnection(conn); });
|
||||
|
||||
// f_editor->assignableConnectionChanged.connect(
|
||||
//[=](auto conn) { proxy->startConnection(conn); });
|
||||
},
|
||||
pattern(_) = [] {});
|
||||
|
||||
|
@ -17,9 +17,9 @@ DeviceTreeView::DeviceTreeView(QWidget *parent) : QTreeView(parent) {
|
||||
header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
setSortingEnabled(true);
|
||||
setEditTriggers(SelectedClicked | EditKeyPressed);
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
setContextMenuPolicy(Qt::DefaultContextMenu);
|
||||
connect(this, &QTreeView::customContextMenuRequested, [this](QPoint point) {
|
||||
auto index = indexAt(point);
|
||||
/*auto index = indexAt(point);
|
||||
auto data = index.data(DeviceModel::AssignableRole);
|
||||
auto proxyData = index.data(DeviceModel::AssignableProxyRole);
|
||||
QMenu menu;
|
||||
@ -30,21 +30,7 @@ DeviceTreeView::DeviceTreeView(QWidget *parent) : QTreeView(parent) {
|
||||
menu.addActions({&editConn, enableConn});
|
||||
if (data.canConvert<AssignableItemData>() &&
|
||||
proxyData.canConvert<AssignableProxy *>()) {
|
||||
functionEditorRequested(index);
|
||||
/*auto a_data = data.value<AssignableItemData>();
|
||||
auto proxy = proxyData.value<AssignableProxy*>();
|
||||
match(a_data.assignableInfo()) (
|
||||
pattern(as<RangeInfo>(arg)) = [this, &menu, proxy, &editConn](auto
|
||||
ri) {
|
||||
//functionEditorRequested(*proxy, ri);
|
||||
connect(&editConn, &QAction::triggered, [this, proxy, ri] {
|
||||
functionEditorRequested(*proxy, ri);
|
||||
});
|
||||
menu.exec(QCursor::pos());
|
||||
},
|
||||
pattern(_) = []{}
|
||||
);*/
|
||||
}
|
||||
}*/
|
||||
});
|
||||
m_delegate = new DeviceModelDelegate(this);
|
||||
|
||||
|
@ -32,6 +32,7 @@
|
||||
// Delet this
|
||||
namespace p = mpark::patterns;
|
||||
|
||||
Q_DECLARE_METATYPE(DynamicReadableConnectionData)
|
||||
Q_DECLARE_METATYPE(DynamicReadableProxy *)
|
||||
|
||||
// TODO: make constructor of the type data Editor a = Maybe (Range a)
|
||||
|
Loading…
Reference in New Issue
Block a user