show function editor in main window in stacked widget

This commit is contained in:
Jussi Kuokkanen 2023-09-04 19:09:20 +03:00
parent d59093fbc9
commit 67e43e0333
4 changed files with 29 additions and 9 deletions

View File

@ -1,11 +1,15 @@
#pragma once
class DeviceModel;
class QStackedWidget;
class QWidget;
// Data that (needs) to be accessed globally, eg. main stacked widget
namespace Globals {
// This is used to search nodes by their DBus path to avoid passing pointers through many levels
extern DeviceModel *g_deviceModel;
extern QStackedWidget *g_mainStack;
extern QWidget *g_deviceBrowser;
} // namespace Globals

View File

@ -10,6 +10,7 @@
#include <QDBusReply>
#include <QDebug>
#include <QSettings>
#include <QStackedWidget>
#include <QStandardItemModel>
#include <QStandardPaths>
#include <QString>
@ -27,6 +28,8 @@ Q_DECLARE_METATYPE(TCDBus::DeviceNode)
Q_DECLARE_METATYPE(TCDBus::FlatTreeNode<TCDBus::DeviceNode>)
DeviceModel *Globals::g_deviceModel;
QStackedWidget *Globals::g_mainStack;
QWidget *Globals::g_deviceBrowser;
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
qDBusRegisterMetaType<TCDBus::DeviceNode>();
@ -55,17 +58,17 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
auto root = flatTree.toTree(flatTree);
/*auto view = new QTreeView;
view->setItemDelegate(new DeviceModelDelegate);
view->setModel(model);
setCentralWidget(view);*/
auto model = new DeviceModel(root);
auto browser = new DeviceBrowser(*model);
setCentralWidget(browser);
auto stack = new QStackedWidget(this);
stack->addWidget(browser);
setCentralWidget(stack);
// TODO: make sure this is the only assignment
Globals::g_deviceBrowser = browser;
Globals::g_deviceModel = model;
Globals::g_mainStack = stack;
Utils::writeAssignableDefaults(*model);
}

View File

@ -4,6 +4,7 @@
#include <DoubleRangeEditor.hpp>
#include <EnumEditor.hpp>
#include <FunctionEditor.hpp>
#include <Globals.hpp>
#include <IntRangeEditor.hpp>
#include <patterns.hpp>
#include <QDebug>
@ -11,6 +12,7 @@
#include <QMenu>
#include <QMouseEvent>
#include <QPainter>
#include <QStackedWidget>
#include <QSettings>
#include <Utils.hpp>
@ -130,6 +132,8 @@ bool DeviceModelDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
// This cast should be valid since we can fetch AssignableData
auto devModel = static_cast<DeviceModel *>(model);
m_functionEditor = new FunctionEditor{*devModel};
Globals::g_mainStack->addWidget(m_functionEditor);
}
m_functionEditor->setRangeInfo(
std::get<RangeInfo>(assInfo.assignableInfo()));
@ -138,14 +142,20 @@ bool DeviceModelDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
m_menu.addAction(m_parametrize);
// TODO: show in main window as a page
connect(m_parametrize, &QAction::triggered,
[=](auto) { m_functionEditor->show(); });
connect(m_parametrize, &QAction::triggered, [=](auto) {
Globals::g_mainStack->setCurrentWidget(m_functionEditor);
});
connect(m_functionEditor, &FunctionEditor::cancelled, []() {
Globals::g_mainStack->setCurrentWidget(Globals::g_deviceBrowser);
});
// TODO: not handled in AssignableProxy
connect(m_functionEditor, &FunctionEditor::connectionDataChanged,
[=](auto data) {
setAssignableData(model, index, "(Parametrized)", data);
Globals::g_mainStack->setCurrentWidget(
Globals::g_deviceBrowser);
});
}
if (!m_menu.actions().empty())

View File

@ -79,6 +79,8 @@ public:
}
});
connect(m_cancelButton, &QPushButton::clicked, this, &FunctionEditor::cancelled);
connect(this, &FunctionEditor::canApplyChanged, m_applyButton,
&QPushButton::setEnabled);
@ -129,6 +131,7 @@ public:
boost::signals2::signal<void(std::shared_ptr<AssignableConnection>)>
assignableConnectionChanged;
signals:
void cancelled();
void connectionDataChanged(DynamicReadableConnectionData);
private:
Q_OBJECT