Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
zmoth committed Jan 10, 2023
1 parent 55200a1 commit 7701e37
Show file tree
Hide file tree
Showing 11 changed files with 361 additions and 499 deletions.
22 changes: 10 additions & 12 deletions examples/plugin_text/PluginDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@

#include "TextModel.hpp"

Plugin* Plugin::_this_plugin = nullptr;
Plugin *Plugin::_this_plugin = nullptr;

Plugin::
Plugin()
{ _this_plugin = this; }
Plugin::Plugin()
{
_this_plugin = this;
}

Plugin::
~Plugin()
Plugin::~Plugin()
{
// TODO: Unregister all models here
// TODO: Unregister all models here
}

void
Plugin::
registerDataModels(std::shared_ptr<QtNodes::NodeDelegateModelRegistry> & reg)
void Plugin::registerDataModels(std::shared_ptr<QtNodes::NodeDelegateModelRegistry> &reg)
{
assert(reg);
assert(reg);

reg->registerModel<TextModel>();
reg->registerModel<TextModel>();
}
23 changes: 9 additions & 14 deletions examples/plugin_text/PluginDefinition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,20 @@

#define PLUGIN_NAME "pluginText"

class DLL_EXPORT Plugin
: public QObject
, public QtNodes::PluginInterface
class DLL_EXPORT Plugin : public QObject, public QtNodes::PluginInterface
{
Q_OBJECT
Q_INTERFACES(QtNodes::PluginInterface)
Q_PLUGIN_METADATA(IID PLUGIN_NAME)
Q_OBJECT
Q_INTERFACES(QtNodes::PluginInterface)
Q_PLUGIN_METADATA(IID PLUGIN_NAME)

public:
Plugin();
~Plugin();
Plugin();
~Plugin();

QString
name() const override
{ return PLUGIN_NAME; };
QString name() const override { return PLUGIN_NAME; };

void
registerDataModels(std::shared_ptr<QtNodes::NodeDelegateModelRegistry> & reg) override;
void registerDataModels(std::shared_ptr<QtNodes::NodeDelegateModelRegistry> &reg) override;

private:
static Plugin* _this_plugin;
static Plugin *_this_plugin;
};
17 changes: 7 additions & 10 deletions examples/plugin_text/TextData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,16 @@ using QtNodes::NodeDataType;
class TextData : public NodeData
{
public:
TextData() {}

TextData() {}
TextData(QString const &text)
: _text(text)
{}

TextData(QString const &text)
: _text(text)
{}
NodeDataType type() const override { return NodeDataType{"text", "Text"}; }

NodeDataType type() const override
{ return NodeDataType {"text", "Text"}; }

QString text() const { return _text; }
QString text() const { return _text; }

private:

QString _text;
QString _text;
};
93 changes: 33 additions & 60 deletions examples/plugin_text/TextModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,95 +2,68 @@

#include <QtWidgets/QTextEdit>

TextModel::
TextModel()
TextModel::TextModel()
{
//
//
}


unsigned int
TextModel::
nPorts(PortType portType) const
unsigned int TextModel::nPorts(PortType portType) const
{
unsigned int result = 1;
unsigned int result = 1;

switch (portType)
{
switch (portType) {
case PortType::In:
result = 1;
break;
result = 1;
break;

case PortType::Out:
result = 1;
result = 1;

default:
break;
}
break;
}

return result;
return result;
}


void
TextModel::
onTextEdited()
void TextModel::onTextEdited()
{
Q_EMIT dataUpdated(0);
Q_EMIT dataUpdated(0);
}


NodeDataType
TextModel::
dataType(PortType, PortIndex) const
NodeDataType TextModel::dataType(PortType, PortIndex) const
{
return TextData().type();
return TextData().type();
}


std::shared_ptr<NodeData>
TextModel::
outData(PortIndex const portIndex)
std::shared_ptr<NodeData> TextModel::outData(PortIndex const portIndex)
{
Q_UNUSED(portIndex);
return std::make_shared<TextData>(_textEdit->toPlainText());
Q_UNUSED(portIndex);
return std::make_shared<TextData>(_textEdit->toPlainText());
}


QWidget *
TextModel::
embeddedWidget()
QWidget *TextModel::embeddedWidget()
{
if (!_textEdit)
{
_textEdit = new QTextEdit();

connect(_textEdit, &QTextEdit::textChanged,
this, &TextModel::onTextEdited);
if (!_textEdit) {
_textEdit = new QTextEdit();

}
connect(_textEdit, &QTextEdit::textChanged, this, &TextModel::onTextEdited);
}

return _textEdit;
return _textEdit;
}


void
TextModel::
setInData(std::shared_ptr<NodeData> data, PortIndex const)
void TextModel::setInData(std::shared_ptr<NodeData> data, PortIndex const)
{
auto textData = std::dynamic_pointer_cast<TextData>(data);
auto textData = std::dynamic_pointer_cast<TextData>(data);

QString inputText;
QString inputText;

if (textData)
{
inputText = textData->text();
}
else
{
inputText = "";
}
if (textData) {
inputText = textData->text();
} else {
inputText = "";
}

_textEdit->setText(inputText);
_textEdit->setText(inputText);
}

46 changes: 16 additions & 30 deletions examples/plugin_text/TextModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,62 +8,48 @@

#include <iostream>

using QtNodes::PortType;
using QtNodes::PortIndex;
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
Q_OBJECT

public:
TextModel();
TextModel();

public:
QString
caption() const override
{ return QString("Text"); }
QString caption() const override { return QString("Text"); }

bool
captionVisible() const override { return true; }
bool captionVisible() const override { return true; }

static QString
Name()
{ return QString("TextModel"); }
static QString Name() { return QString("TextModel"); }

QString
name() const override
{ return TextModel::Name(); }
QString name() const override { return TextModel::Name(); }

public:
unsigned int
nPorts(PortType portType) const override;
unsigned int nPorts(PortType portType) const override;

NodeDataType
dataType(PortType portType, PortIndex portIndex) const override;
NodeDataType dataType(PortType portType, PortIndex portIndex) const override;

std::shared_ptr<NodeData>
outData(PortIndex const portIndex) override;
std::shared_ptr<NodeData> outData(PortIndex const portIndex) override;

void
setInData(std::shared_ptr<NodeData>, PortIndex const) override;
void setInData(std::shared_ptr<NodeData>, PortIndex const) override;

QWidget *
embeddedWidget() override;
QWidget *embeddedWidget() override;

bool
resizable() const override { return true; }
bool resizable() const override { return true; }

private Q_SLOTS:

void
onTextEdited();
void onTextEdited();

private:
QTextEdit * _textEdit = nullptr;
QTextEdit *_textEdit = nullptr;
};
Loading

0 comments on commit 7701e37

Please sign in to comment.