-
Notifications
You must be signed in to change notification settings - Fork 823
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
754 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
file(GLOB_RECURSE CPPS ./*.cpp) | ||
file(GLOB_RECURSE HPPS ./*.hpp) | ||
|
||
foreach(OUTPUT_TYPES ${CMAKE_CONFIGURATION_TYPES}) | ||
string(TOUPPER ${OUTPUT_TYPES} OUTPUT_CONFIG) | ||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUT_CONFIG} ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUT_CONFIG}}/plugins) | ||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUT_CONFIG} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUT_CONFIG}}/plugins) | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUT_CONFIG} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUT_CONFIG}}/plugins) | ||
# message(STATUS "CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUT_CONFIG} : ${CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUT_CONFIG}}") | ||
endforeach(OUTPUT_TYPES CMAKE_CONFIGURATION_TYPES) | ||
|
||
add_library(plugin_text SHARED ${CPPS} ${HPPS}) | ||
|
||
target_link_libraries(plugin_text QtNodes) | ||
|
||
target_compile_definitions(plugin_text PUBLIC NODE_EDITOR_SHARED) | ||
|
||
set_target_properties(plugin_text PROPERTIES SUFFIX ".node") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include "PluginDefinition.hpp" | ||
|
||
#include "TextModel.hpp" | ||
|
||
Plugin *Plugin::_this_plugin = nullptr; | ||
|
||
Plugin::Plugin() | ||
{ | ||
_this_plugin = this; | ||
} | ||
|
||
Plugin::~Plugin() | ||
{ | ||
// TODO: Unregister all models here | ||
} | ||
|
||
void Plugin::registerDataModels(std::shared_ptr<QtNodes::NodeDelegateModelRegistry> ®) | ||
{ | ||
assert(reg); | ||
|
||
reg->registerModel<TextModel>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#pragma once | ||
|
||
#include <QObject> | ||
#include <QtNodes/NodeDelegateModelRegistry> | ||
#include <QtNodes/PluginInterface> | ||
|
||
// This needs to be the same as the name of your project file ${PROJECT_NAME} | ||
#ifdef plugin_text_EXPORTS | ||
#define DLL_EXPORT Q_DECL_EXPORT | ||
#else | ||
#define DLL_EXPORT Q_DECL_IMPORT | ||
#endif | ||
|
||
#define PLUGIN_NAME "Text" | ||
|
||
class DLL_EXPORT Plugin | ||
: public QObject | ||
, public QtNodes::PluginInterface | ||
{ | ||
Q_OBJECT | ||
Q_INTERFACES(QtNodes::PluginInterface) | ||
Q_PLUGIN_METADATA(IID PLUGIN_NAME) | ||
|
||
public: | ||
Plugin(); | ||
~Plugin(); | ||
|
||
QString name() const override { return PLUGIN_NAME; }; | ||
|
||
void registerDataModels(std::shared_ptr<QtNodes::NodeDelegateModelRegistry> ®) override; | ||
|
||
private: | ||
static Plugin *_this_plugin; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
|
||
#include <QtNodes/NodeData> | ||
|
||
using QtNodes::NodeData; | ||
using QtNodes::NodeDataType; | ||
|
||
/// The class can potentially incapsulate any user data which | ||
/// need to be transferred within the Node Editor graph | ||
class TextData : public NodeData | ||
{ | ||
public: | ||
TextData() {} | ||
|
||
TextData(QString const &text) | ||
: _text(text) | ||
{} | ||
|
||
NodeDataType type() const override { return NodeDataType{"text", "Text"}; } | ||
|
||
QString text() const { return _text; } | ||
|
||
private: | ||
QString _text; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include "TextModel.hpp" | ||
|
||
#include <QtWidgets/QTextEdit> | ||
|
||
TextModel::TextModel() | ||
{ | ||
// | ||
} | ||
|
||
unsigned int TextModel::nPorts(PortType portType) const | ||
{ | ||
unsigned int result = 1; | ||
|
||
switch (portType) { | ||
case PortType::In: | ||
result = 1; | ||
break; | ||
|
||
case PortType::Out: | ||
result = 1; | ||
|
||
default: | ||
break; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
void TextModel::onTextEdited() | ||
{ | ||
Q_EMIT dataUpdated(0); | ||
} | ||
|
||
NodeDataType TextModel::dataType(PortType, PortIndex) const | ||
{ | ||
return TextData().type(); | ||
} | ||
|
||
std::shared_ptr<NodeData> TextModel::outData(PortIndex const portIndex) | ||
{ | ||
Q_UNUSED(portIndex); | ||
return std::make_shared<TextData>(_textEdit->toPlainText()); | ||
} | ||
|
||
QWidget *TextModel::embeddedWidget() | ||
{ | ||
if (!_textEdit) { | ||
_textEdit = new QTextEdit(); | ||
|
||
connect(_textEdit, &QTextEdit::textChanged, this, &TextModel::onTextEdited); | ||
} | ||
|
||
return _textEdit; | ||
} | ||
|
||
void TextModel::setInData(std::shared_ptr<NodeData> data, PortIndex const) | ||
{ | ||
auto textData = std::dynamic_pointer_cast<TextData>(data); | ||
|
||
QString inputText; | ||
|
||
if (textData) { | ||
inputText = textData->text(); | ||
} else { | ||
inputText = ""; | ||
} | ||
|
||
_textEdit->setText(inputText); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#pragma once | ||
|
||
#include <QtCore/QObject> | ||
|
||
#include "TextData.hpp" | ||
|
||
#include <QtNodes/NodeDelegateModel> | ||
|
||
#include <iostream> | ||
|
||
using QtNodes::NodeData; | ||
using QtNodes::NodeDelegateModel; | ||
using QtNodes::PortIndex; | ||
using QtNodes::PortType; | ||
|
||
class QTextEdit; | ||
|
||
/// The model dictates the number of inputs and outputs for the Node. | ||
/// In this example it has no logic. | ||
class TextModel : public NodeDelegateModel | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
TextModel(); | ||
|
||
public: | ||
QString caption() const override { return QString("Text"); } | ||
|
||
bool captionVisible() const override { return true; } | ||
|
||
static QString Name() { return QString("Text"); } | ||
|
||
QString name() const override { return TextModel::Name(); } | ||
|
||
public: | ||
unsigned int nPorts(PortType portType) const override; | ||
|
||
NodeDataType dataType(PortType portType, PortIndex portIndex) const override; | ||
|
||
std::shared_ptr<NodeData> outData(PortIndex const portIndex) override; | ||
|
||
void setInData(std::shared_ptr<NodeData>, PortIndex const) override; | ||
|
||
QWidget *embeddedWidget() override; | ||
|
||
bool resizable() const override { return true; } | ||
|
||
private Q_SLOTS: | ||
|
||
void onTextEdited(); | ||
|
||
private: | ||
QTextEdit *_textEdit = nullptr; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
file(GLOB_RECURSE CPPS ./*.cpp) | ||
file(GLOB_RECURSE HPPS ./*.hpp) | ||
|
||
add_executable(plugins_load ${CPPS} ${HPPS}) | ||
|
||
target_link_libraries(plugins_load QtNodes) |
Oops, something went wrong.