Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 71 additions & 48 deletions src/gui-qml/qml/DissolveMain.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,59 @@ import "../../Dissolve"

ApplicationWindow {
id: dissolveWindow

property vector3d scale: Qt.vector3d(Math.min(graphView.width / 2.5, graphView.height / 2.5), Math.min(graphView.width / 2.5, graphView.height / 2.5), 200)

height: 743
title: "Dissolve"
visible: true
width: 819

menuBar: MenuBar {
id: mainMenu

Menu {
title: "&File"

MenuItem {
text: "&New"
}
Action {
shortcut: "Ctrl+O"
text: "&Open..."

onTriggered: openDialog.open()
}
MenuItem {
text: "Open R&ecent"
}
MenuItem {
text: "Save"
}
MenuItem {
text: "Save As..."
}
MenuItem {
text: "Load Restart Point..."
}
MenuItem {
text: "Save Restart Point..."
}
MenuItem {
text: "Close"
}
Action {
shortcut: "Ctrl+Q"
text: "&Quit"

onTriggered: Qt.quit()
}
}
}

TabBar {
id: tabBar

width: parent.width

// DEFAULT TABS
Expand Down Expand Up @@ -48,27 +92,32 @@ ApplicationWindow {

Item {
id: messagesTab

Text {
text: "Messages"
}
}
Item {
id: forcefieldTab

Text {
text: "Forcefields"
}
}
Item {
id: examplePlotTab

Node {
id: standAloneScene

DirectionalLight {
ambientColor: Qt.rgba(0.5, 0.5, 0.5, 1.0)
brightness: 1.0
eulerRotation.x: -25
}
ScatterModel {
id: plotLine

color: "red"
scale: dissolveWindow.scale
thickness: 0.1
Expand All @@ -90,6 +139,7 @@ ApplicationWindow {

axis: Axis {
id: xAxis

direction: true
maximum: 2.0
minimum: -2.0
Expand All @@ -102,6 +152,7 @@ ApplicationWindow {

axis: Axis {
id: yAxis

direction: false
maximum: 2.0
minimum: -2.0
Expand All @@ -111,9 +162,16 @@ ApplicationWindow {
}
View3D {
id: graphView

anchors.fill: parent
importScene: standAloneScene

camera: OrthographicCamera {
id: cameraOrthographicLeft

z: 600
}

MouseArea {
anchors.fill: parent

Expand All @@ -122,39 +180,39 @@ ApplicationWindow {
yAxis.nudge(-0.01 * event.pixelDelta.y);
}
}

camera: OrthographicCamera {
id: cameraOrthographicLeft
z: 600
}
}
}
Item {
id: exampleGraphTab

ModuleGraphModel {
id: graphModel

world: dissolve
}
Connections {
target: dissolve.configurationsModel

function onModelReset() {
graphModel.handleReset();
}

target: dissolve.configurationsModel
}
GeneratorDelegate {
id: exampleDelegate

rootModel: graphModel
}
Pane {
id: toolBar

RowLayout {
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top

FileDialog {
id: openDialog

onAccepted: {
dissolve.file = selectedFile;
}
Expand All @@ -172,6 +230,7 @@ ApplicationWindow {
}
SpinBox {
id: nodeValue

from: 0
}
Button {
Expand All @@ -197,6 +256,7 @@ ApplicationWindow {
}
SpinBox {
id: conSrc

from: 0
to: graphModel.nodeCount - 1
}
Expand All @@ -205,11 +265,13 @@ ApplicationWindow {
}
SpinBox {
id: conDest

from: 0
to: graphModel.nodeCount - 1
}
Button {
id: connectButton

text: "Connect"

onClicked: {
Expand All @@ -223,6 +285,7 @@ ApplicationWindow {
}
Button {
id: disconnectButton

text: "Disconnect"

onClicked: {
Expand All @@ -238,6 +301,7 @@ ApplicationWindow {
}
GraphView {
id: graph

anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
Expand All @@ -249,45 +313,4 @@ ApplicationWindow {
}
}
}

menuBar: MenuBar {
id: mainMenu
Menu {
title: "&File"

MenuItem {
text: "&New"
}
Action {
shortcut: "Ctrl+O"
text: "&Open..."

onTriggered: openDialog.open()
}
MenuItem {
text: "Open R&ecent"
}
MenuItem {
text: "Save"
}
MenuItem {
text: "Save As..."
}
MenuItem {
text: "Load Restart Point..."
}
MenuItem {
text: "Save Restart Point..."
}
MenuItem {
text: "Close"
}
Action {
shortcut: "Ctrl+Q"
text: "&Quit"

onTriggered: Qt.quit()
}
}
}
}
30 changes: 15 additions & 15 deletions src/gui/models/nodeGraph/exampleGraphModel.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (c) 2024 Team Dissolve and contributors
// Copyright (c) 2025 Team Dissolve and contributors

#include "exampleGraphModel.h"
#include "nodeWrapper.h"
#include <type_traits>
#include <variant>

// The value of the node
template <> QVariant nodeGetValue<nodeValue>(const nodeValue value)
QVariant nodeGetValue(const nodeValue &value)
{
return std::visit(
[](auto arg) -> QVariant
Expand All @@ -19,15 +19,15 @@ template <> QVariant nodeGetValue<nodeValue>(const nodeValue value)
else
{
if (arg)
return nodeGetValue<nodeValue>(*arg);
return nodeGetValue(*arg);
return {};
}
},
value.value);
};

// The name of the type (for delegate dispatch)
template <> std::string nodeTypeName<nodeValue>(const nodeValue &value)
std::string nodeTypeName(const nodeValue &value)
{
return std::visit(
[](auto arg) -> std::string
Expand All @@ -45,7 +45,7 @@ template <> std::string nodeTypeName<nodeValue>(const nodeValue &value)
}

// The path to the icon for the node
template <> std::string nodeTypeIcon<nodeValue>(const nodeValue &value)
std::string nodeTypeIcon(const nodeValue &value)
{
return std::visit(
[](auto arg) -> std::string
Expand All @@ -63,42 +63,42 @@ template <> std::string nodeTypeIcon<nodeValue>(const nodeValue &value)
}

// The title of the node
template <> std::string nodeName<nodeValue>(const nodeValue &value) { return value.name; }
std::string nodeName(const nodeValue &value) { return value.name; }

// Change the title of the node
template <> void setNodeName<nodeValue>(nodeValue &value, const std::string name) { value.name = name; }
void setNodeName(nodeValue &value, const std::string name) { value.name = name; }

// Link an indexed position on the source to an indexed position on the destination
template <> bool nodeConnect<nodeValue>(nodeValue &source, int sourceIndex, nodeValue &destionation, int destinationIndex)
bool nodeConnect(nodeValue &source, int sourceIndex, nodeValue &destionation, int destinationIndex)
{
destionation.value = &source;
return true;
}

// Confirm that a connection is possible (e.g. types match and index isn't already connected)
template <>
bool nodeConnectable<nodeValue>(const nodeValue &source, int sourceIndex, const nodeValue &destination, int destinationIndex)

bool nodeConnectable(const nodeValue &source, int sourceIndex, const nodeValue &destination, int destinationIndex)
{
return std::holds_alternative<double>(source.value) && std::holds_alternative<nodeValue *>(destination.value);
}

// Unlink an indexed position on the source to an indexed position on the destination
template <> bool nodeDisconnect<nodeValue>(nodeValue &source, int sourceIndex, nodeValue &destination, int destinationIndex)
bool nodeDisconnect(nodeValue &source, int sourceIndex, nodeValue &destination, int destinationIndex)
{
destination.value = nullptr;
return true;
}

// Append the roles for the type onto the QHash
template <> QHash<int, QByteArray> &nodeRoleNames<nodeValue>(QHash<int, QByteArray> &roles)
QHash<int, QByteArray> &nodeRoleNames(Phantom<nodeValue> proxy, QHash<int, QByteArray> &roles)
{
const auto base = Qt::UserRole + GraphNodeModelBase::ownedRoles;
roles[base] = "value";
return roles;
}

// Get a specific piece of information from a node by index
template <> QVariant nodeData<nodeValue>(const nodeValue &item, int role)
QVariant nodeData(const nodeValue &item, int role)
{
switch (role)
{
Expand All @@ -110,10 +110,10 @@ template <> QVariant nodeData<nodeValue>(const nodeValue &item, int role)
}

// Set a specific piece of information from a node by index
template <> bool nodeSetData<nodeValue>(nodeValue &item, const QVariant &value, int role) { return false; }
bool nodeSetData(nodeValue &item, const QVariant &value, int role) { return false; }

// Delete the node
template <> bool nodeDelete<nodeValue>(nodeValue &value, GraphNodeContext<nodeValue>::type &context) { return true; }
bool nodeDelete(nodeValue &value, Phantom<nodeValue> &context) { return true; }

// Create node from variant
nodeValue::nodeValue(QVariant var)
Expand Down
17 changes: 15 additions & 2 deletions src/gui/models/nodeGraph/exampleGraphModel.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (c) 2024 Team Dissolve and contributors
// Copyright (c) 2025 Team Dissolve and contributors

#pragma once

Expand Down Expand Up @@ -29,5 +29,18 @@ class nodeValue
std::variant<double, nodeValue *> value;
};

std::string nodeName(const nodeValue &value);
std::string nodeTypeName(const nodeValue &value);
std::string nodeTypeIcon(const nodeValue &value);
void setNodeName(nodeValue &value, std::string);
QVariant nodeGetValue(const nodeValue &value);
bool nodeConnect(nodeValue &source, int sourceIndex, nodeValue &destionation, int destinationIndex);
bool nodeConnectable(const nodeValue &source, int sourceIndex, const nodeValue &destination, int destinationIndex);
bool nodeDisconnect(nodeValue &source, int sourceIndex, nodeValue &destination, int destinationIndex);
QHash<int, QByteArray> &nodeRoleNames(Phantom<nodeValue> proxy, QHash<int, QByteArray> &roles);
bool nodeDelete(nodeValue &value, Phantom<nodeValue> &context);
QVariant nodeData(const nodeValue &item, int role);
bool nodeSetData(nodeValue &item, const QVariant &value, int role);

// The graph model for the example
typedef GraphModel<nodeValue> ExampleGraphModel;
typedef GraphModel<nodeValue, Phantom<nodeValue>> ExampleGraphModel;
Loading
Loading