diff --git a/modules/editor/grapheditor/editor/graph/abstractnodegraph.cpp b/modules/editor/grapheditor/editor/graph/abstractnodegraph.cpp index 19e2868d4..0f1041884 100644 --- a/modules/editor/grapheditor/editor/graph/abstractnodegraph.cpp +++ b/modules/editor/grapheditor/editor/graph/abstractnodegraph.cpp @@ -26,6 +26,10 @@ AbstractNodeGraph::AbstractNodeGraph() : m_version(0) { } +GraphNode *AbstractNodeGraph::nodeCreate(const TString &path, int &index) { + return nullptr; +} + void AbstractNodeGraph::nodeDelete(GraphNode *node) { auto it = m_nodes.begin(); while(it != m_nodes.end()) { @@ -212,7 +216,7 @@ void AbstractNodeGraph::load(const TString &path) { blockSignals(false); - emit graphUpdated(); + emitSignal(_SIGNAL(graphUpdated())); if(version != m_version) { save(path); @@ -220,7 +224,7 @@ void AbstractNodeGraph::load(const TString &path) { } } - emit graphLoaded(); + emitSignal(_SIGNAL(graphLoaded())); } void AbstractNodeGraph::save(const TString &path) { @@ -334,5 +338,5 @@ const AbstractNodeGraph::LinkList &AbstractNodeGraph::links() const { } void AbstractNodeGraph::reportMessage(GraphNode *node, const TString &text) { - emit messageReported(AbstractNodeGraph::node(node), text); + } diff --git a/modules/editor/grapheditor/editor/graph/abstractnodegraph.h b/modules/editor/grapheditor/editor/graph/abstractnodegraph.h index 62b221917..ee2f9e3b1 100644 --- a/modules/editor/grapheditor/editor/graph/abstractnodegraph.h +++ b/modules/editor/grapheditor/editor/graph/abstractnodegraph.h @@ -11,8 +11,13 @@ class Texture; -class NODEGRAPH_EXPORT AbstractNodeGraph : public QObject { - Q_OBJECT +class NODEGRAPH_EXPORT AbstractNodeGraph : public Object { + A_OBJECT(AbstractNodeGraph, Object, Editor) + + A_METHODS( + A_SIGNAL(AbstractNodeGraph::graphUpdated), + A_SIGNAL(AbstractNodeGraph::graphLoaded) + ) public: struct Link { @@ -32,9 +37,7 @@ class NODEGRAPH_EXPORT AbstractNodeGraph : public QObject { public: AbstractNodeGraph(); - AbstractNodeGraph(const AbstractNodeGraph &) { assert(false && "DONT EVER USE THIS"); } - - virtual GraphNode *nodeCreate(const TString &path, int &index) = 0; + virtual GraphNode *nodeCreate(const TString &path, int &index); virtual void nodeDelete(GraphNode *node); virtual Link *linkCreate(GraphNode *sender, NodePort *oport, GraphNode *receiver, NodePort *iport); @@ -70,10 +73,6 @@ class NODEGRAPH_EXPORT AbstractNodeGraph : public QObject { void graphUpdated(); void graphLoaded(); - void messageReported(int node, const TString &text); - - void menuVisible(bool visible); - protected: virtual void loadGraph(const pugi::xml_node &parent); diff --git a/modules/editor/grapheditor/editor/graph/actions/changenodeproperty.cpp b/modules/editor/grapheditor/editor/graph/actions/changenodeproperty.cpp index 2b54fbb1d..1579ea3f7 100644 --- a/modules/editor/grapheditor/editor/graph/actions/changenodeproperty.cpp +++ b/modules/editor/grapheditor/editor/graph/actions/changenodeproperty.cpp @@ -33,5 +33,5 @@ void ChangeNodeProperty::redo() { auto g = m_controller->graph(); - g->graphUpdated(); + g->emitSignal(_SIGNAL(graphUpdated())); } diff --git a/modules/editor/grapheditor/editor/graph/actions/createlink.cpp b/modules/editor/grapheditor/editor/graph/actions/createlink.cpp index d9a34d7aa..d1f596965 100644 --- a/modules/editor/grapheditor/editor/graph/actions/createlink.cpp +++ b/modules/editor/grapheditor/editor/graph/actions/createlink.cpp @@ -17,7 +17,8 @@ void CreateLink::undo() { AbstractNodeGraph::Link *link = g->link(m_index); if(link) { g->linkDelete(link); - emit g->graphUpdated(); + + g->emitSignal(_SIGNAL(graphUpdated())); } } @@ -32,6 +33,7 @@ void CreateLink::redo() { AbstractNodeGraph::Link *link = g->linkCreate(snd, op, rcv, ip); m_index = g->link(link); - emit g->graphUpdated(); + + g->emitSignal(_SIGNAL(graphUpdated())); } } diff --git a/modules/editor/grapheditor/editor/graph/actions/createnode.cpp b/modules/editor/grapheditor/editor/graph/actions/createnode.cpp index 7fdb0d0e1..cd2cc142c 100644 --- a/modules/editor/grapheditor/editor/graph/actions/createnode.cpp +++ b/modules/editor/grapheditor/editor/graph/actions/createnode.cpp @@ -17,7 +17,8 @@ void CreateNode::undo() { auto g = m_controller->graph(); g->nodeDelete(g->node(m_node)); m_controller->selectNodes(m_list); - emit g->graphUpdated(); + + g->emitSignal(_SIGNAL(graphUpdated())); } void CreateNode::redo() { @@ -64,5 +65,6 @@ void CreateNode::redo() { } m_controller->selectNodes({m_node}); - emit g->graphUpdated(); + + g->emitSignal(_SIGNAL(graphUpdated())); } diff --git a/modules/editor/grapheditor/editor/graph/actions/deletelinksbyport.cpp b/modules/editor/grapheditor/editor/graph/actions/deletelinksbyport.cpp index 21b17adac..bd3a3a215 100644 --- a/modules/editor/grapheditor/editor/graph/actions/deletelinksbyport.cpp +++ b/modules/editor/grapheditor/editor/graph/actions/deletelinksbyport.cpp @@ -23,7 +23,7 @@ void DeleteLinksByPort::undo() { g->linkCreate(snd, op, rcv, ip); } } - emit g->graphUpdated(); + g->emitSignal(_SIGNAL(graphUpdated())); } void DeleteLinksByPort::redo() { @@ -52,6 +52,6 @@ void DeleteLinksByPort::redo() { } g->linkDelete(item); } - emit g->graphUpdated(); + g->emitSignal(_SIGNAL(graphUpdated())); } } diff --git a/modules/editor/grapheditor/editor/graph/actions/deletenodes.cpp b/modules/editor/grapheditor/editor/graph/actions/deletenodes.cpp index b90223762..8fb9c30e4 100644 --- a/modules/editor/grapheditor/editor/graph/actions/deletenodes.cpp +++ b/modules/editor/grapheditor/editor/graph/actions/deletenodes.cpp @@ -36,5 +36,5 @@ void DeleteNodes::redo() { g->nodeDelete(it); } - emit g->graphUpdated(); + g->emitSignal(_SIGNAL(graphUpdated())); } diff --git a/modules/editor/grapheditor/editor/graph/actions/pastenodes.cpp b/modules/editor/grapheditor/editor/graph/actions/pastenodes.cpp index 995e3197d..77e293c79 100644 --- a/modules/editor/grapheditor/editor/graph/actions/pastenodes.cpp +++ b/modules/editor/grapheditor/editor/graph/actions/pastenodes.cpp @@ -18,7 +18,8 @@ void PasteNodes::undo() { g->nodeDelete(g->node(it)); } m_controller->selectNodes(m_lastSelect); - emit g->graphUpdated(); + + g->emitSignal(_SIGNAL(graphUpdated())); } void PasteNodes::redo() { @@ -60,5 +61,6 @@ void PasteNodes::redo() { } m_controller->selectNodes(m_list); - emit g->graphUpdated(); + + g->emitSignal(_SIGNAL(graphUpdated())); } diff --git a/modules/editor/grapheditor/editor/graph/graphview.cpp b/modules/editor/grapheditor/editor/graph/graphview.cpp index 9779251dd..827422fc4 100644 --- a/modules/editor/grapheditor/editor/graph/graphview.cpp +++ b/modules/editor/grapheditor/editor/graph/graphview.cpp @@ -37,16 +37,18 @@ namespace { const char *gFrame("Frame"); }; -class ObjectObserver : public Object { - A_OBJECT(ObjectObserver, Object, Editor) +class GraphViewProxy : public Object { + A_OBJECT(GraphViewProxy, Object, Proxy) A_METHODS( - A_SLOT(ObjectObserver::onPortPressed), - A_SLOT(ObjectObserver::onPortReleased) + A_SLOT(GraphViewProxy::onPortPressed), + A_SLOT(GraphViewProxy::onPortReleased), + A_SLOT(GraphViewProxy::onGraphUpdated), + A_SLOT(GraphViewProxy::onGraphLoaded) ) public: - ObjectObserver() : + GraphViewProxy() : m_view(nullptr) { } @@ -75,6 +77,18 @@ class ObjectObserver : public Object { } } + void onGraphUpdated() { + if(m_view) { + m_view->onGraphUpdated(); + } + } + + void onGraphLoaded() { + if(m_view) { + m_view->onGraphLoaded(); + } + } + private: GraphView *m_view; @@ -85,7 +99,7 @@ GraphView::GraphView(QWidget *parent) : m_scene(nullptr), m_view(nullptr), m_createMenu(new QMenu(this)), - m_objectObserver(new ObjectObserver), + m_proxy(new GraphViewProxy), m_linksRender(nullptr), m_rubberBand(nullptr), m_updateLinks(false) { @@ -104,7 +118,7 @@ GraphView::GraphView(QWidget *parent) : firtCall = false; } - m_objectObserver->setView(this); + m_proxy->setView(this); connect(static_cast(m_controller), &GraphController::copied, this, &GraphView::copied); @@ -138,9 +152,8 @@ AbstractNodeGraph *GraphView::graph() const { void GraphView::setGraph(AbstractNodeGraph *graph) { static_cast(m_controller)->setGraph(graph); - connect(graph, &AbstractNodeGraph::graphUpdated, this, &GraphView::onGraphUpdated); - connect(graph, &AbstractNodeGraph::graphLoaded, this, &GraphView::onGraphLoaded); - connect(graph, &AbstractNodeGraph::menuVisible, this, &GraphView::onInProgressFlag); + Object::connect(graph, _SIGNAL(graphUpdated()), m_proxy, _SLOT(onGraphUpdated())); + Object::connect(graph, _SIGNAL(graphLoaded()), m_proxy, _SLOT(onGraphLoaded())); StringList nodeList = graph->nodeList(); @@ -298,8 +311,8 @@ void GraphView::onGraphUpdated() { if(actor->parent() == nullptr) { actor->setParent(m_view); - Object::connect(widget, _SIGNAL(portPressed(int)), m_objectObserver, _SLOT(onPortPressed(int))); - Object::connect(widget, _SIGNAL(portReleased(int)), m_objectObserver, _SLOT(onPortReleased(int))); + Object::connect(widget, _SIGNAL(portPressed(int)), m_proxy, _SLOT(onPortPressed(int))); + Object::connect(widget, _SIGNAL(portReleased(int)), m_proxy, _SLOT(onPortReleased(int))); } RectTransform *rect = widget->rectTransform(); diff --git a/modules/editor/grapheditor/editor/graph/graphview.h b/modules/editor/grapheditor/editor/graph/graphview.h index be3f9dc4f..2edf33ba3 100644 --- a/modules/editor/grapheditor/editor/graph/graphview.h +++ b/modules/editor/grapheditor/editor/graph/graphview.h @@ -7,7 +7,7 @@ class QMenu; -class ObjectObserver; +class GraphViewProxy; class NodeWidget; class LinksRender; class Frame; @@ -54,13 +54,13 @@ class NODEGRAPH_EXPORT GraphView : public Viewport { public slots: void onObjectsChanged(const Object::ObjectList &objects, QString property, const Variant &value); -private slots: - void onComponentSelected(); - void onGraphUpdated(); void onGraphLoaded(); +private slots: + void onComponentSelected(); + void onDraw() override; private: @@ -73,7 +73,7 @@ private slots: QMenu *m_createMenu; - ObjectObserver *m_objectObserver; + GraphViewProxy *m_proxy; LinksRender *m_linksRender; diff --git a/modules/editor/motiontools/converter/animationcontrollergraph.h b/modules/editor/motiontools/converter/animationcontrollergraph.h index 88f1b4aec..2ce561f75 100644 --- a/modules/editor/motiontools/converter/animationcontrollergraph.h +++ b/modules/editor/motiontools/converter/animationcontrollergraph.h @@ -4,8 +4,6 @@ #include class AnimationControllerGraph : public AbstractNodeGraph { - Q_OBJECT - public: AnimationControllerGraph(); diff --git a/modules/editor/motiontools/editor/animationedit.cpp b/modules/editor/motiontools/editor/animationedit.cpp index 25d9e8eaa..f4fac1d48 100644 --- a/modules/editor/motiontools/editor/animationedit.cpp +++ b/modules/editor/motiontools/editor/animationedit.cpp @@ -10,16 +10,40 @@ #include "../converter/animationbuilder.h" +class AnimationProxy : public Object { + A_OBJECT(AnimationProxy, Object, Proxy) + + A_METHODS( + A_SLOT(AnimationProxy::onGraphUpdated) + ) +public: + void setEditor(AnimationEdit *editor) { + m_editor = editor; + } + + void onGraphUpdated() { + m_editor->updated(); + } + +private: + AnimationEdit *m_editor = nullptr; + +}; + AnimationEdit::AnimationEdit() : ui(new Ui::AnimationEdit), m_graph(new AnimationControllerGraph), m_assetConverter(new AnimationControllerBuilder), m_stateMachine(nullptr), - m_lastCommand(nullptr) { + m_lastCommand(nullptr), + m_proxy(new AnimationProxy) { ui->setupUi(this); - connect(m_graph, &AnimationControllerGraph::graphUpdated, this, &AnimationEdit::updated); + m_proxy->setEditor(this); + + Object::connect(m_graph, _SIGNAL(graphUpdated), m_proxy, _SLOT(onGraphUpdated())); + connect(ui->schemeWidget, &GraphView::objectsSelected, this, &AnimationEdit::objectsSelected); ui->schemeWidget->init(); @@ -32,7 +56,7 @@ AnimationEdit::~AnimationEdit() { } bool AnimationEdit::isModified() const { - return (UndoManager::instance()->lastCommand(m_graph) != m_lastCommand); + return (UndoManager::instance()->lastCommand(this) != m_lastCommand); } QStringList AnimationEdit::suffixes() const { @@ -75,7 +99,7 @@ void AnimationEdit::loadAsset(AssetConverterSettings *settings) { m_graph->load(settings->source().toStdString()); - m_lastCommand = UndoManager::instance()->lastCommand(m_graph); + m_lastCommand = UndoManager::instance()->lastCommand(this); } } @@ -83,7 +107,7 @@ void AnimationEdit::saveAsset(const QString &path) { if(!path.isEmpty() || !m_settings.first()->source().isEmpty()) { m_graph->save(path.isEmpty() ? m_settings.first()->source().toStdString() : path.toStdString()); - m_lastCommand = UndoManager::instance()->lastCommand(m_graph); + m_lastCommand = UndoManager::instance()->lastCommand(this); } } diff --git a/modules/editor/motiontools/editor/animationedit.h b/modules/editor/motiontools/editor/animationedit.h index 892546910..e0538cd1b 100644 --- a/modules/editor/motiontools/editor/animationedit.h +++ b/modules/editor/motiontools/editor/animationedit.h @@ -11,6 +11,8 @@ class AssetConverter; class UndoCommand; +class AnimationProxy; + namespace Ui { class AnimationEdit; } @@ -54,6 +56,8 @@ private slots: const UndoCommand *m_lastCommand; + AnimationProxy *m_proxy; + }; #endif // ANIMATIONEDIT_H diff --git a/modules/editor/particletools/converter/effectbuilder.cpp b/modules/editor/particletools/converter/effectbuilder.cpp index 372dfe2bf..8ee27cc62 100644 --- a/modules/editor/particletools/converter/effectbuilder.cpp +++ b/modules/editor/particletools/converter/effectbuilder.cpp @@ -64,7 +64,7 @@ void EffectBuilderSettings::setThumbnailWarmup(float value) { } EffectBuilder::EffectBuilder() { - connect(&m_graph, &EffectGraph::effectUpdated, this, &EffectBuilder::effectUpdated); + } int EffectBuilder::version() { diff --git a/modules/editor/particletools/converter/effectbuilder.h b/modules/editor/particletools/converter/effectbuilder.h index 521e1aa17..38f8e07db 100644 --- a/modules/editor/particletools/converter/effectbuilder.h +++ b/modules/editor/particletools/converter/effectbuilder.h @@ -46,9 +46,6 @@ class EffectBuilder : public AssetConverter { void convertOld(const QString &path); -signals: - void effectUpdated(); - private: EffectGraph m_graph; diff --git a/modules/editor/particletools/converter/effectgraph.h b/modules/editor/particletools/converter/effectgraph.h index 055c82083..f0e52bc18 100644 --- a/modules/editor/particletools/converter/effectgraph.h +++ b/modules/editor/particletools/converter/effectgraph.h @@ -1,14 +1,17 @@ #ifndef SHADERGRAPH_H #define SHADERGRAPH_H -#include #include class EffectRootNode; -class QMenu; class EffectGraph : public AbstractNodeGraph { - Q_OBJECT + A_OBJECT(EffectGraph, AbstractNodeGraph, Editor) + + A_METHODS( + A_SIGNAL(EffectGraph::moduleChanged), + A_SIGNAL(EffectGraph::effectUpdated) + ) public: EffectGraph(); @@ -27,7 +30,6 @@ class EffectGraph : public AbstractNodeGraph { signals: void moduleChanged(); - void effectUpdated(); public slots: diff --git a/modules/editor/particletools/converter/effectmodule.cpp b/modules/editor/particletools/converter/effectmodule.cpp index c1acc6609..9607496f9 100644 --- a/modules/editor/particletools/converter/effectmodule.cpp +++ b/modules/editor/particletools/converter/effectmodule.cpp @@ -71,7 +71,8 @@ void EffectModule::setEnabled(bool enabled) { m_enabled = enabled; EffectGraph *graph = static_cast(m_effect->graph()); - graph->effectUpdated(); + + graph->emitSignal(_SIGNAL(effectUpdated())); } void EffectModule::setProperty(const char *name, const Variant &value) { @@ -104,7 +105,7 @@ void EffectModule::setProperty(const char *name, const Variant &value) { } EffectGraph *graph = static_cast(m_effect->graph()); - graph->effectUpdated(); + graph->emitSignal(_SIGNAL(effectUpdated())); } } } @@ -446,7 +447,8 @@ void EffectModule::setRoot(EffectRootNode *effect) { m_blockUpdate = false; EffectGraph *graph = static_cast(m_effect->graph()); - graph->moduleChanged(); + + graph->emitSignal(_SIGNAL(moduleChanged())); } EffectModule::ParameterData *EffectModule::parameter(const TString &name) { diff --git a/modules/editor/particletools/editor/actions/createmodule.cpp b/modules/editor/particletools/editor/actions/createmodule.cpp index 397b00d96..4b6b19146 100644 --- a/modules/editor/particletools/editor/actions/createmodule.cpp +++ b/modules/editor/particletools/editor/actions/createmodule.cpp @@ -3,8 +3,10 @@ #include "effectrootnode.h" #include "effectmodule.h" -CreateModule::CreateModule(const std::string &module, EffectGraph *graph, const QString &name, QUndoCommand *group) : - UndoCommand(name, graph, group), +#include "../particleedit.h" + +CreateModule::CreateModule(const std::string &module, EffectGraph *graph, ParticleEdit *editor, const QString &name, QUndoCommand *group) : + UndoCommand(name, editor, group), m_moduleName(module), m_graph(graph), m_object(0) { @@ -17,7 +19,7 @@ void CreateModule::undo() { EffectRootNode *root = static_cast(m_graph->defaultNode()); root->removeModule(module); - m_graph->moduleChanged(); + m_graph->emitSignal(_SIGNAL(moduleChanged())); } } @@ -27,6 +29,6 @@ void CreateModule::redo() { if(module) { m_object = module->uuid(); - m_graph->moduleChanged(); + m_graph->emitSignal(_SIGNAL(moduleChanged())); } } diff --git a/modules/editor/particletools/editor/actions/createmodule.h b/modules/editor/particletools/editor/actions/createmodule.h index cdfbb649e..ba084efd5 100644 --- a/modules/editor/particletools/editor/actions/createmodule.h +++ b/modules/editor/particletools/editor/actions/createmodule.h @@ -3,9 +3,11 @@ #include "effectgraph.h" +class ParticleEdit; + class CreateModule : public UndoCommand { public: - CreateModule(const std::string &module, EffectGraph *graph, const QString &name, QUndoCommand *group = nullptr); + CreateModule(const std::string &module, EffectGraph *graph, ParticleEdit *editor, const QString &name, QUndoCommand *group = nullptr); void undo() override; void redo() override; diff --git a/modules/editor/particletools/editor/actions/deletemodule.cpp b/modules/editor/particletools/editor/actions/deletemodule.cpp index 60ce951af..47c862021 100644 --- a/modules/editor/particletools/editor/actions/deletemodule.cpp +++ b/modules/editor/particletools/editor/actions/deletemodule.cpp @@ -3,8 +3,10 @@ #include "effectmodule.h" #include "effectrootnode.h" -DeleteModule::DeleteModule(EffectModule *module, EffectGraph *graph, const QString &name, QUndoCommand *group) : - UndoCommand(name, graph, group), +#include "../particleedit.h" + +DeleteModule::DeleteModule(EffectModule *module, EffectGraph *graph, ParticleEdit *editor, const QString &name, QUndoCommand *group) : + UndoCommand(name, editor, group), m_graph(graph), m_object(module->uuid()), m_root(0), @@ -19,7 +21,7 @@ void DeleteModule::undo() { if(module) { module->fromXml(m_document.first_child()); - m_graph->moduleChanged(); + m_graph->emitSignal(_SIGNAL(moduleChanged())); } } } @@ -40,6 +42,6 @@ void DeleteModule::redo() { root->removeModule(module); - m_graph->moduleChanged(); + m_graph->emitSignal(_SIGNAL(moduleChanged())); } } diff --git a/modules/editor/particletools/editor/actions/deletemodule.h b/modules/editor/particletools/editor/actions/deletemodule.h index c5dd550bc..bac7b199b 100644 --- a/modules/editor/particletools/editor/actions/deletemodule.h +++ b/modules/editor/particletools/editor/actions/deletemodule.h @@ -6,10 +6,11 @@ #include class EffectModule; +class ParticleEdit; class DeleteModule : public UndoCommand { public: - DeleteModule(EffectModule *module, EffectGraph *graph, const QString &name, QUndoCommand *group = nullptr); + DeleteModule(EffectModule *module, EffectGraph *graph, ParticleEdit *editor, const QString &name, QUndoCommand *group = nullptr); void undo() override; void redo() override; diff --git a/modules/editor/particletools/editor/particleedit.cpp b/modules/editor/particletools/editor/particleedit.cpp index 0c950cd8d..096c7053b 100644 --- a/modules/editor/particletools/editor/particleedit.cpp +++ b/modules/editor/particletools/editor/particleedit.cpp @@ -28,6 +28,37 @@ namespace { Q_DECLARE_METATYPE(Object *) +class ParticleProxy : public Object { + A_OBJECT(ParticleProxy, Object, Proxy) + + A_METHODS( + A_SLOT(ParticleProxy::onUpdateTemplate), + A_SLOT(ParticleProxy::onGrapUpdated), + A_SLOT(ParticleProxy::onModuleChanged) + ) + +public: + void setEditor(ParticleEdit *editor) { + m_editor = editor; + } + + void onUpdateTemplate() { + m_editor->onUpdateTemplate(); + } + + void onGrapUpdated() { + m_editor->updated(); + } + + void onModuleChanged() { + m_editor->onModuleChanged(); + } + +protected: + ParticleEdit *m_editor = nullptr; + +}; + ParticleEdit::ParticleEdit() : ui(new Ui::ParticleEdit), m_builder(new EffectBuilder), @@ -35,10 +66,13 @@ ParticleEdit::ParticleEdit() : m_effect(nullptr), m_render(nullptr), m_lastCommand(nullptr), - m_moduleButton(nullptr) { + m_moduleButton(nullptr), + m_proxy(new ParticleProxy) { ui->setupUi(this); + m_proxy->setEditor(this); + m_controller->blockMovement(true); m_controller->setFree(false); @@ -52,17 +86,18 @@ ParticleEdit::ParticleEdit() : m_effect = Engine::composeActor("EffectRender", "ParticleEffect", scene); m_render = m_effect->getComponent(); - connect(ui->graph, &GraphView::objectsSelected, this, &ParticleEdit::objectsSelected); - connect(m_builder, &EffectBuilder::effectUpdated, this, &ParticleEdit::onUpdateTemplate); - EffectGraph *graph = &m_builder->graph(); + Object::connect(graph, _SIGNAL(effectUpdated()), m_proxy, _SLOT(onUpdateTemplate())); + + connect(ui->graph, &GraphView::objectsSelected, this, &ParticleEdit::objectsSelected); + ui->graph->setWorld(Engine::objectCreate("World")); ui->graph->setGraph(graph); ui->graph->init(); - connect(graph, &EffectGraph::moduleChanged, ui->graph, &GraphView::reselect); - connect(graph, &EffectGraph::graphUpdated, this, &ParticleEdit::updated); + Object::connect(graph, _SIGNAL(moduleChanged()), m_proxy, _SLOT(onModuleChanged())); + Object::connect(graph, _SIGNAL(graphUpdated()), m_proxy, _SLOT(onGrapUpdated())); startTimer(16); @@ -99,7 +134,7 @@ void ParticleEdit::writeSettings() { } bool ParticleEdit::isModified() const { - return (UndoManager::instance()->lastCommand(&m_builder->graph()) != m_lastCommand); + return (UndoManager::instance()->lastCommand(this) != m_lastCommand); } QStringList ParticleEdit::suffixes() const { @@ -133,7 +168,7 @@ bool ParticleEdit::isPasteActionAvailable() const { void ParticleEdit::onAddModule(QAction *action) { QString name = tr("Create %1").arg(action->text()); EffectGraph *graph = &m_builder->graph(); - UndoManager::instance()->push(new CreateModule(action->text().toStdString(), graph, name)); + UndoManager::instance()->push(new CreateModule(action->text().toStdString(), graph, this, name)); } void ParticleEdit::onObjectsChanged(const Object::ObjectList &objects, QString property, const Variant &value) { @@ -213,7 +248,7 @@ void ParticleEdit::loadAsset(AssetConverterSettings *settings) { EffectGraph &graph = m_builder->graph(); graph.load(settings->source().toStdString()); - m_lastCommand = UndoManager::instance()->lastCommand(&m_builder->graph()); + m_lastCommand = UndoManager::instance()->lastCommand(this); onUpdateTemplate(); } @@ -223,7 +258,7 @@ void ParticleEdit::saveAsset(const QString &path) { if(!path.isEmpty() || !m_settings.first()->source().isEmpty()) { m_builder->graph().save(path.isEmpty() ? m_settings.first()->source().toStdString() : path.toStdString()); - m_lastCommand = UndoManager::instance()->lastCommand(&m_builder->graph()); + m_lastCommand = UndoManager::instance()->lastCommand(this); } } @@ -237,13 +272,17 @@ void ParticleEdit::onUpdateTemplate() { } } +void ParticleEdit::onModuleChanged() { + ui->graph->reselect(); +} + void ParticleEdit::onDeleteModule() { EffectModule *module = static_cast(sender()->property(gFunction).value()); QString name = tr("Delete %1").arg(module->name().data()); EffectGraph *graph = &m_builder->graph(); - UndoManager::instance()->push(new DeleteModule(module, graph, name)); + UndoManager::instance()->push(new DeleteModule(module, graph, this, name)); } void ParticleEdit::changeEvent(QEvent *event) { diff --git a/modules/editor/particletools/editor/particleedit.h b/modules/editor/particletools/editor/particleedit.h index 2c11acd12..b2e7b8837 100644 --- a/modules/editor/particletools/editor/particleedit.h +++ b/modules/editor/particletools/editor/particleedit.h @@ -16,6 +16,8 @@ class UndoCommand; class QToolButton; +class ParticleProxy; + namespace Ui { class ParticleEdit; } @@ -27,13 +29,14 @@ class ParticleEdit : public AssetEditor { ParticleEdit(); ~ParticleEdit(); + void onUpdateTemplate(); + void onModuleChanged(); + private slots: void onCutAction() override; void onCopyAction() override; void onPasteAction() override; - void onUpdateTemplate(); - void onDeleteModule(); void onActivated() override; @@ -76,6 +79,8 @@ private slots: QToolButton *m_moduleButton; + ParticleProxy *m_proxy; + }; #endif // PARTICLEEDIT_H diff --git a/modules/editor/pipelinetools/converter/pipelinetaskgraph.h b/modules/editor/pipelinetools/converter/pipelinetaskgraph.h index 4d6176029..e5f5d1fa2 100644 --- a/modules/editor/pipelinetools/converter/pipelinetaskgraph.h +++ b/modules/editor/pipelinetools/converter/pipelinetaskgraph.h @@ -71,8 +71,6 @@ class PipelineNode : public GraphNode { }; class PipelineTaskGraph : public AbstractNodeGraph { - Q_OBJECT - public: PipelineTaskGraph(); @@ -95,6 +93,7 @@ class PipelineTaskGraph : public AbstractNodeGraph { VariantList m_taskLinks; PipelineRootNode *m_rootNode; + }; #endif // PIPELINETASKGRAPH_H diff --git a/modules/editor/pipelinetools/editor/pipelineedit.cpp b/modules/editor/pipelinetools/editor/pipelineedit.cpp index 205aba48c..98b63f145 100644 --- a/modules/editor/pipelinetools/editor/pipelineedit.cpp +++ b/modules/editor/pipelinetools/editor/pipelineedit.cpp @@ -32,15 +32,37 @@ namespace { const char *gDirectLight("DirectLight"); }; +class PipelineProxy : public Object { + A_OBJECT(PipelineProxy, Object, Proxy) + + A_METHODS( + A_SLOT(PipelineProxy::onGraphUpdated) + ) +public: + void setEditor(PipelineEdit *editor) { + m_editor = editor; + } + + void onGraphUpdated() { + m_editor->onGraphUpdated(); + } + +private: + PipelineEdit *m_editor = nullptr;; +}; + PipelineEdit::PipelineEdit() : ui(new Ui::PipelineEdit), m_graph(new PipelineTaskGraph), m_builder(new PipelineConverter()), m_controller(new CameraController), - m_lastCommand(nullptr) { + m_lastCommand(nullptr), + m_proxy(new PipelineProxy()) { ui->setupUi(this); + m_proxy->setEditor(this); + ui->preview->setController(m_controller); ui->preview->setWorld(Engine::objectCreate("World")); ui->preview->init(); // must be called after all options set @@ -49,8 +71,8 @@ PipelineEdit::PipelineEdit() : ui->preview->hide(); - connect(m_graph, &PipelineTaskGraph::graphUpdated, this, &PipelineEdit::onGraphUpdated); - connect(m_graph, &PipelineTaskGraph::graphUpdated, this, &PipelineEdit::updated); + Object::connect(m_graph, _SIGNAL(graphUpdated()), m_proxy, _SLOT(onGraphUpdated())); + connect(ui->schemeWidget, &GraphView::objectsSelected, this, &PipelineEdit::objectsSelected); ui->schemeWidget->setWorld(Engine::objectCreate("World")); @@ -80,7 +102,7 @@ void PipelineEdit::writeSettings() { } bool PipelineEdit::isModified() const { - return (UndoManager::instance()->lastCommand(m_graph) != m_lastCommand); + return (UndoManager::instance()->lastCommand(this) != m_lastCommand); } QStringList PipelineEdit::suffixes() const { @@ -117,7 +139,7 @@ void PipelineEdit::loadAsset(AssetConverterSettings *settings) { m_graph->load(m_settings.first()->source().toStdString()); - m_lastCommand = UndoManager::instance()->lastCommand(m_graph); + m_lastCommand = UndoManager::instance()->lastCommand(this); } } @@ -125,7 +147,7 @@ void PipelineEdit::saveAsset(const QString &path) { if(!path.isEmpty() || !m_settings.first()->source().isEmpty()) { m_graph->save(path.isEmpty() ? m_settings.first()->source().toStdString() : path.toStdString()); - m_lastCommand = UndoManager::instance()->lastCommand(m_graph); + m_lastCommand = UndoManager::instance()->lastCommand(this); } } @@ -134,6 +156,8 @@ void PipelineEdit::onGraphUpdated() { // Need to attach it m_graph->data(); } + + emit updated(); } void PipelineEdit::onObjectsChanged(const std::list &objects, QString property, const Variant &value) { diff --git a/modules/editor/pipelinetools/editor/pipelineedit.h b/modules/editor/pipelinetools/editor/pipelineedit.h index 56c4c7325..f5dac9478 100644 --- a/modules/editor/pipelinetools/editor/pipelineedit.h +++ b/modules/editor/pipelinetools/editor/pipelineedit.h @@ -8,6 +8,7 @@ class PipelineTaskGraph; class CameraController; class UndoCommand; +class PipelineProxy; namespace Ui { class PipelineEdit; @@ -20,6 +21,8 @@ class PipelineEdit : public AssetEditor { PipelineEdit(); ~PipelineEdit(); + void onGraphUpdated(); + private slots: void onCutAction() override; void onCopyAction() override; @@ -27,8 +30,6 @@ private slots: void onActivated() override; - void onGraphUpdated(); - void onObjectsChanged(const std::list &objects, QString property, const Variant &value) override; private: @@ -55,6 +56,8 @@ private slots: CameraController *m_controller; + PipelineProxy *m_proxy; + const UndoCommand *m_lastCommand; }; diff --git a/modules/editor/shadertools/converter/shadergraph.cpp b/modules/editor/shadertools/converter/shadergraph.cpp index 3672266f0..4cf8c4db9 100644 --- a/modules/editor/shadertools/converter/shadergraph.cpp +++ b/modules/editor/shadertools/converter/shadergraph.cpp @@ -261,10 +261,10 @@ void ShaderGraph::scanForCustomFunctions() { pugi::xml_node function = doc.document_element(); - TString name = function.attribute("name").as_string(); + const char *name = function.attribute("name").as_string(); - m_nodeTypes.push_back(name.toStdString()); - m_exposedFunctions[QFileInfo(name.data()).baseName().toStdString()] = path.toStdString(); + m_nodeTypes.push_back(name); + m_exposedFunctions[QFileInfo(name).baseName().toStdString()] = path.toStdString(); } } } @@ -676,7 +676,7 @@ void ShaderGraph::onNodeUpdated() { if(node) { markDirty(node); } - emit graphUpdated(); + emitSignal(_SIGNAL(graphUpdated())); } void ShaderGraph::setPreviewVisible(GraphNode *node, bool visible) { diff --git a/modules/editor/shadertools/converter/shadergraph.h b/modules/editor/shadertools/converter/shadergraph.h index e5bc8691f..50774d6fa 100644 --- a/modules/editor/shadertools/converter/shadergraph.h +++ b/modules/editor/shadertools/converter/shadergraph.h @@ -18,8 +18,6 @@ enum OldBlendType { }; class ShaderGraph : public AbstractNodeGraph { - Q_OBJECT - enum Stage { Fragment, Vertex @@ -48,7 +46,6 @@ class ShaderGraph : public AbstractNodeGraph { void updatePreviews(CommandBuffer &buffer); -private slots: void onNodeUpdated(); private: diff --git a/modules/editor/shadertools/editor/materialedit.cpp b/modules/editor/shadertools/editor/materialedit.cpp index 566bb1531..8d8e975ae 100644 --- a/modules/editor/shadertools/editor/materialedit.cpp +++ b/modules/editor/shadertools/editor/materialedit.cpp @@ -48,6 +48,26 @@ class PreviewRender : public PipelineTask { }; +class MaterialProxy : public Object { + A_OBJECT(MaterialProxy, Object, Proxy) + + A_METHODS( + A_SLOT(MaterialProxy::onGraphUpdated) + ) +public: + void setEditor(MaterialEdit *editor) { + m_editor = editor; + } + + void onGraphUpdated() { + m_editor->onGraphUpdated(); + } + +private: + MaterialEdit *m_editor = nullptr; + +}; + MaterialEdit::MaterialEdit() : ui(new Ui::MaterialEdit), m_mesh(nullptr), @@ -56,9 +76,13 @@ MaterialEdit::MaterialEdit() : m_graph(new ShaderGraph), m_builder(new ShaderBuilder), m_controller(new CameraController), - m_lastCommand(nullptr) { + m_lastCommand(nullptr), + m_proxy(new MaterialProxy) { ui->setupUi(this); + + m_proxy->setEditor(this); + m_controller->blockMovement(true); m_controller->setFree(false); @@ -81,8 +105,8 @@ MaterialEdit::MaterialEdit() : m_material = Engine::objectCreate(); - connect(m_graph, &ShaderGraph::graphUpdated, this, &MaterialEdit::onGraphUpdated); - connect(m_graph, &ShaderGraph::graphUpdated, this, &MaterialEdit::updated); + Object::connect(m_graph, _SIGNAL(graphUpdated()), m_proxy, _SLOT(onGraphUpdated())); + connect(ui->schemeWidget, &GraphView::objectsSelected, this, &MaterialEdit::objectsSelected); connect(ui->schemeWidget, &GraphView::objectsSelected, this, &MaterialEdit::copyPasteChanged); connect(ui->schemeWidget, &GraphView::copied, this, &MaterialEdit::copyPasteChanged); @@ -118,7 +142,7 @@ void MaterialEdit::writeSettings() { } bool MaterialEdit::isModified() const { - return (UndoManager::instance()->lastCommand(m_graph) != m_lastCommand); + return (UndoManager::instance()->lastCommand(this) != m_lastCommand); } QStringList MaterialEdit::suffixes() const { @@ -166,7 +190,7 @@ void MaterialEdit::loadAsset(AssetConverterSettings *settings) { mesh->setMaterial(m_material); } - m_lastCommand = UndoManager::instance()->lastCommand(m_graph); + m_lastCommand = UndoManager::instance()->lastCommand(this); } } @@ -174,7 +198,7 @@ void MaterialEdit::saveAsset(const QString &path) { if(!path.isEmpty() || !m_settings.first()->source().isEmpty()) { m_graph->save(path.isEmpty() ? m_settings.first()->source().toStdString() : path.toStdString()); - m_lastCommand = UndoManager::instance()->lastCommand(m_graph); + m_lastCommand = UndoManager::instance()->lastCommand(this); } } @@ -192,6 +216,8 @@ void MaterialEdit::onGraphUpdated() { m_material->initInstance(instance); } } + + emit updated(); } void MaterialEdit::changeMesh(Mesh *mesh) { diff --git a/modules/editor/shadertools/editor/materialedit.h b/modules/editor/shadertools/editor/materialedit.h index f67653574..41248055a 100644 --- a/modules/editor/shadertools/editor/materialedit.h +++ b/modules/editor/shadertools/editor/materialedit.h @@ -13,6 +13,8 @@ class CameraController; class UndoCommand; +class MaterialProxy; + namespace Ui { class MaterialEdit; } @@ -24,6 +26,8 @@ class MaterialEdit : public AssetEditor { MaterialEdit(); ~MaterialEdit(); + void onGraphUpdated(); + private slots: void onCutAction() override; void onCopyAction() override; @@ -33,8 +37,6 @@ private slots: void onObjectsChanged(const std::list &objects, QString property, const Variant &value) override; - void onGraphUpdated(); - void on_actionPlane_triggered(); void on_actionCube_triggered(); void on_actionSphere_triggered(); @@ -59,6 +61,8 @@ private slots: QStringList suffixes() const override; private: + ShaderCodeDialog m_codeDlg; + Ui::MaterialEdit *ui; Actor *m_mesh; @@ -73,7 +77,7 @@ private slots: const UndoCommand *m_lastCommand; - ShaderCodeDialog m_codeDlg; + MaterialProxy *m_proxy; };