feat: update model from geometry
This commit is contained in:
@@ -81,7 +81,7 @@ void enzo::nt::NetworkManager::setDisplayOp(OpId opId)
|
||||
|
||||
enzo::nt::GeometryOperator& displayOp = getGeoOperator(opId);
|
||||
updateDisplay(displayOp.getOutputGeo(0));
|
||||
displayNodeChanged();
|
||||
displayNodeChanged(opId);
|
||||
}
|
||||
|
||||
void enzo::nt::NetworkManager::cookOp(enzo::nt::OpId opId)
|
||||
|
||||
@@ -24,7 +24,7 @@ public:
|
||||
GeometryOperator& getGeoOperator(nt::OpId opId);
|
||||
void setDisplayOp(OpId opId);
|
||||
|
||||
boost::signals2::signal<void ()> displayNodeChanged;
|
||||
boost::signals2::signal<void (nt::OpId)> displayNodeChanged;
|
||||
|
||||
#ifdef UNIT_TEST
|
||||
void _reset();
|
||||
|
||||
@@ -1,22 +1,52 @@
|
||||
#include "Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetModel.h"
|
||||
#include "Engine/Network/NetworkManager.h"
|
||||
#include "Engine/Operator/Geometry.h"
|
||||
#include "Engine/Types.h"
|
||||
#include <icecream.hpp>
|
||||
|
||||
|
||||
GeometrySpreadsheetModel::GeometrySpreadsheetModel(const QStringList &strings, QObject *parent)
|
||||
: QAbstractListModel(parent), stringList(strings)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GeometrySpreadsheetModel::selectionChanged(enzo::nt::OpId opId)
|
||||
{
|
||||
beginResetModel();
|
||||
enzo::nt::NetworkManager& nm = enzo::nt::nm();
|
||||
opId_ = opId;
|
||||
IC();
|
||||
geometry_ = nm.getGeoOperator(opId).getOutputGeo(0);
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
int GeometrySpreadsheetModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
return stringList.count();
|
||||
return geometry_.getNumPoints();
|
||||
}
|
||||
|
||||
QVariant GeometrySpreadsheetModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
if (index.row() >= stringList.size())
|
||||
if (index.row() >= geometry_.getNumPoints())
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
if (role == Qt::DisplayRole)
|
||||
return stringList.at(index.row());
|
||||
{
|
||||
std::cout << geometry_.getPointPos(index.row()).x() << "\n";
|
||||
return geometry_.getPointPos(index.row()).x();
|
||||
}
|
||||
else
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
QVariant GeometrySpreadsheetModel::headerData(int section, Qt::Orientation orientation,
|
||||
|
||||
@@ -1,19 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include "Engine/Types.h"
|
||||
#include "Engine/Operator/Geometry.h"
|
||||
|
||||
class GeometrySpreadsheetModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GeometrySpreadsheetModel(const QStringList &strings, QObject *parent = nullptr)
|
||||
: QAbstractListModel(parent), stringList(strings) {}
|
||||
GeometrySpreadsheetModel(const QStringList &strings, QObject *parent = nullptr);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const override;
|
||||
|
||||
void selectionChanged(enzo::nt::OpId opId);
|
||||
|
||||
|
||||
private:
|
||||
QStringList stringList;
|
||||
enzo::nt::OpId opId_;
|
||||
enzo::geo::Geometry geometry_;
|
||||
|
||||
};
|
||||
|
||||
@@ -14,28 +14,34 @@ GeometrySpreadsheetPanel::GeometrySpreadsheetPanel(QWidget *parent, Qt::WindowFl
|
||||
mainLayout_ = new QVBoxLayout();
|
||||
|
||||
|
||||
auto *t = new QTreeView(parent);
|
||||
t->setRootIsDecorated(false);
|
||||
t->setAlternatingRowColors(true);
|
||||
t->setStyleSheet(R"(
|
||||
view_ = new QTreeView(parent);
|
||||
view_->setRootIsDecorated(false);
|
||||
view_->setAlternatingRowColors(true);
|
||||
view_->setStyleSheet(R"(
|
||||
QTreeView {
|
||||
background-color: #282828;
|
||||
alternate-background-color: #242424;
|
||||
paint-alternating-row-colors-for-empty-area: 1;
|
||||
}
|
||||
)");
|
||||
t->setFrameStyle(QFrame::NoFrame);
|
||||
view_->setFrameStyle(QFrame::NoFrame);
|
||||
|
||||
auto model = new GeometrySpreadsheetModel({"hello", "world"});
|
||||
t->setModel(model);
|
||||
model_ = new GeometrySpreadsheetModel({"hello", "world"});
|
||||
view_->setModel(model_);
|
||||
|
||||
|
||||
mainLayout_->addWidget(new GeometrySpreadsheetMenuBar());
|
||||
mainLayout_->addWidget(t);
|
||||
mainLayout_->addWidget(view_);
|
||||
|
||||
setLayout(mainLayout_);
|
||||
}
|
||||
|
||||
void GeometrySpreadsheetPanel::selectionChanged(enzo::nt::OpId opId)
|
||||
{
|
||||
model_->selectionChanged(opId);
|
||||
view_->update();
|
||||
}
|
||||
|
||||
void GeometrySpreadsheetPanel::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
QPainterPath path;
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
#include <QWidget>
|
||||
#include <QVBoxLayout>
|
||||
#include <qtreeview.h>
|
||||
#include "Engine/Types.h"
|
||||
#include "Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetModel.h"
|
||||
|
||||
class GeometrySpreadsheetPanel
|
||||
: public QWidget
|
||||
@@ -9,10 +12,12 @@ class GeometrySpreadsheetPanel
|
||||
public:
|
||||
GeometrySpreadsheetPanel(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
|
||||
public Q_SLOTS:
|
||||
void selectionChanged();
|
||||
void selectionChanged(enzo::nt::OpId opId);
|
||||
private:
|
||||
QVBoxLayout* mainLayout_;
|
||||
QWidget* bgWidget_;
|
||||
GeometrySpreadsheetModel* model_;
|
||||
QTreeView* view_;
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <qsplitter.h>
|
||||
#include <QTimer>
|
||||
#include <Gui/UtilWidgets/Splitter.h>
|
||||
#include <icecream.hpp>
|
||||
|
||||
EnzoUI::EnzoUI()
|
||||
{
|
||||
@@ -61,6 +62,7 @@ EnzoUI::EnzoUI()
|
||||
|
||||
// connect signals
|
||||
connect(&enzo::nt::nm(), &enzo::nt::NetworkManager::updateDisplay, viewport, &Viewport::geometryChanged);
|
||||
enzo::nt::nm().displayNodeChanged.connect([parametersPanel](){parametersPanel->selectionChanged();});
|
||||
enzo::nt::nm().displayNodeChanged.connect([parametersPanel](enzo::nt::OpId opId){parametersPanel->selectionChanged(opId);});
|
||||
enzo::nt::nm().displayNodeChanged.connect([geometrySpreadsheetPanel](enzo::nt::OpId opId){geometrySpreadsheetPanel->selectionChanged(opId);});
|
||||
// connect(&enzo::nt::nm(), &enzo::nt::NetworkManager::updateDisplay, parametersPanel, &ParametersPanel::selectionChanged);
|
||||
}
|
||||
|
||||
@@ -36,13 +36,11 @@ ParametersPanel::ParametersPanel(QWidget *parent, Qt::WindowFlags f)
|
||||
setLayout(mainLayout_);
|
||||
}
|
||||
|
||||
void ParametersPanel::selectionChanged()
|
||||
void ParametersPanel::selectionChanged(enzo::nt::OpId opId)
|
||||
{
|
||||
using namespace enzo;
|
||||
enzo::nt::NetworkManager& nm = enzo::nt::nm();
|
||||
std::optional<enzo::nt::OpId> displayOpId = nm.getDisplayOp();
|
||||
|
||||
if(!displayOpId.has_value()) return;
|
||||
const enzo::nt::OpId displayOpId = opId;
|
||||
|
||||
// clear layout safely
|
||||
QLayoutItem *child;
|
||||
@@ -51,7 +49,7 @@ void ParametersPanel::selectionChanged()
|
||||
delete child;
|
||||
}
|
||||
|
||||
enzo::nt::GeometryOperator& displayOp = nm.getGeoOperator(displayOpId.value());
|
||||
enzo::nt::GeometryOperator& displayOp = nm.getGeoOperator(displayOpId);
|
||||
auto parameters = displayOp.getParameters();
|
||||
|
||||
std::vector<enzo::ui::AbstractFormParm*> parameterWidgets;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <QWidget>
|
||||
#include <QVBoxLayout>
|
||||
#include "Engine/Types.h"
|
||||
|
||||
class ParametersPanel
|
||||
: public QWidget
|
||||
@@ -9,7 +10,7 @@ class ParametersPanel
|
||||
public:
|
||||
ParametersPanel(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
|
||||
public Q_SLOTS:
|
||||
void selectionChanged();
|
||||
void selectionChanged(enzo::nt::OpId opId);
|
||||
private:
|
||||
QVBoxLayout* mainLayout_;
|
||||
QVBoxLayout* parametersLayout_;
|
||||
|
||||
Reference in New Issue
Block a user