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