Skip to content

Commit

Permalink
Add selection functionality to nodes
Browse files Browse the repository at this point in the history
The NodeController class is expanded to include the selected property and its accompanying functions. The AppController class is also modified to manage adding Nodes, such that every time a node is selected, it checks if any other node is selected and deselects them. The
  • Loading branch information
xorza committed Jun 8, 2024
1 parent f312f68 commit 0130a11
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 40 deletions.
88 changes: 56 additions & 32 deletions ScenariumEditor.QML/qml/AppController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,56 @@
#include <QQuickWindow>

void AppController::loadSample() {
auto node = new NodeController(this);
node->setName("Node 1");
{
auto node = new NodeController(this);
node->setName("Node 1");

auto input = new ArgumentController(node);
input->setName("Input 1");
node->addInput(input);
auto input = new ArgumentController(node);
input->setName("Input 1");
node->addInput(input);

input = new ArgumentController(node);
input->setName("Input 2");
node->addInput(input);
input = new ArgumentController(node);
input->setName("Input 2");
node->addInput(input);

auto output = new ArgumentController(node);
output->setName("Output 2");
node->addOutput(output);

m_nodes.append(node);
auto output = new ArgumentController(node);
output->setName("Output 2");
node->addOutput(output);

addNode(node);
}

node = new NodeController(this);
node->setName("Node 2");
{
auto node = new NodeController(this);
node->setName("Node 2");

input = new ArgumentController(node);
input->setName("Input 1");
node->addInput(input);
auto input = new ArgumentController(node);
input->setName("Input 1");
node->addInput(input);

output = new ArgumentController(node);
output->setName("value 2");
node->addOutput(output);
auto output = new ArgumentController(node);
output->setName("value 2");
node->addOutput(output);

output = new ArgumentController(node);
output->setName("asfahgd 2");
node->addOutput(output);
output = new ArgumentController(node);
output->setName("asfahgd 2");
node->addOutput(output);

auto event = new ArgumentController(node);
event->setName("event 2");
node->addEvent(event);
auto event = new ArgumentController(node);
event->setName("event 2");
node->addEvent(event);

m_nodes.append(node);
addNode(node);
}

auto connection = new ConnectionController(this);
connection->setSource(m_nodes[0], 0);
connection->setTarget(m_nodes[1], 0);
m_connections.append(connection);
{
auto connection = new ConnectionController(this);
connection->setSource(m_nodes[0], 0);
connection->setTarget(m_nodes[1], 0);
m_connections.append(connection);
}

m_nodes[1]->setSelected(true);

emit nodesChanged();
emit connectionsChanged();
Expand All @@ -62,3 +68,21 @@ void AppController::loadSample() {
node->updateViewPos();
}
}

void AppController::addNode(NodeController *node) {
m_nodes.append(node);

connect(node, &NodeController::selectedChanged, this, [this, node]() {
if (!node->selected()) {
return;
}

if (this->m_selectedNode != nullptr) {
if (this->m_selectedNode != node)
this->m_selectedNode->setSelected(false);
}
this->m_selectedNode = node;
});

emit nodesChanged();
}
4 changes: 3 additions & 1 deletion ScenariumEditor.QML/qml/AppController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Q_OBJECT
return m_connections;
}

void addNode(NodeController *node);

void loadSample();

signals:
Expand All @@ -41,5 +43,5 @@ public slots:
private:
QList<NodeController *> m_nodes{};
QList<ConnectionController *> m_connections{};

NodeController *m_selectedNode{};
};
14 changes: 8 additions & 6 deletions ScenariumEditor.QML/qml/Node.qml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.cssodessa.NodeController
Rectangle {
property NodeController nodeController


signal viewPosChanged()

id: root
Expand All @@ -33,7 +34,7 @@ Rectangle {
spacing: 5

Rectangle {
color: "#242424"
color: nodeController.selected ? "orange" : "#242424"
height: 28
Layout.fillWidth: true
topRightRadius: 2
Expand Down Expand Up @@ -65,7 +66,7 @@ Rectangle {
}

Text {
color: "lightgray"
color: nodeController.selected ? "black" : "lightgray"
anchors {
verticalCenter: parent.verticalCenter
horizontalCenter: parent.horizontalCenter
Expand All @@ -85,15 +86,17 @@ Rectangle {
viewPosChanged()
}
}
onClicked: {
if (!nodeController.selected)
nodeController.selected = true
}
}
}

GridLayout {
width: gridLayout.width
columns: 3



ColumnLayout {
id: inputsColumn
Layout.alignment: Qt.AlignTop
Expand Down Expand Up @@ -146,7 +149,6 @@ Rectangle {

Item {
Layout.fillWidth: true

}

ColumnLayout {
Expand Down Expand Up @@ -247,7 +249,7 @@ Rectangle {
}

GridLayout {
id : gridLayout
id: gridLayout
columns: 2

ToggleButton {
Expand Down
10 changes: 10 additions & 0 deletions ScenariumEditor.QML/qml/NodeController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ void ArgumentController::setItem(QQuickItem *item) {
emit itemChanged();
}

void NodeController::setSelected(bool selected) {
if (m_selected == selected) {
return;
}

m_selected = selected;
emit selectedChanged();
}

void NodeController::setName(const QString &name) {
if (m_name == name) {
return;
Expand Down Expand Up @@ -98,3 +107,4 @@ void NodeController::setTriggerItem(QQuickItem *triggerItem) {
m_triggerItem = triggerItem;
emit triggerItemChanged();
}

16 changes: 15 additions & 1 deletion ScenariumEditor.QML/qml/NodeController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Q_OBJECT

void setItem(QQuickItem *item);


signals:

void nameChanged();
Expand Down Expand Up @@ -64,6 +65,9 @@ Q_OBJECT
Q_PROPERTY(QQuickItem *item READ item WRITE setItem NOTIFY itemChanged)
Q_PROPERTY(QQuickItem *triggerItem READ triggerItem WRITE setTriggerItem NOTIFY triggerItemChanged)

Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectedChanged)


public:
explicit NodeController(QObject *parent = nullptr) : QObject(parent) {}

Expand Down Expand Up @@ -127,6 +131,13 @@ Q_OBJECT
}


[[nodiscard]] bool selected() const {
return m_selected;
}

void setSelected(bool selected);


void updateViewPos();

signals:
Expand All @@ -147,6 +158,9 @@ Q_OBJECT

void eventsChanged();

void selectedChanged();


private:
QString m_name{};
QList<ArgumentController *> m_inputs{};
Expand All @@ -156,5 +170,5 @@ Q_OBJECT
QPointF m_triggerViewPos{};
QQuickItem *m_triggerItem{};
QList<ArgumentController *> m_events{};

bool m_selected = false;
};

0 comments on commit 0130a11

Please sign in to comment.