From 3a88f26f808f9cb1a16124be77968f9af1648c8e Mon Sep 17 00:00:00 2001 From: Adam Washington Date: Mon, 13 Jan 2025 17:28:42 +0000 Subject: [PATCH 01/15] Add diagnostic depth of concept issues --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4737c3af60..6bf5574494 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -178,7 +178,7 @@ if(UNIX) set(gui_target_name dissolve-gui) set(qmlgui_target_name dissolve-gui-qml) endif(PARALLEL) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -fconcepts-diagnostics-depth=2") endif(UNIX) # -- OSX From 2622bcec79ac8d439ee18fe26fbb0de442857911 Mon Sep 17 00:00:00 2001 From: Adam Washington Date: Mon, 13 Jan 2025 17:30:04 +0000 Subject: [PATCH 02/15] Start addings a Graphable concept --- .../models/nodeGraph/exampleGraphModel.cpp | 2 +- src/gui/models/nodeGraph/exampleGraphModel.h | 2 ++ .../models/nodeGraph/generatorGraphModel.h | 18 ---------------- src/gui/models/nodeGraph/graphModel.h | 2 +- src/gui/models/nodeGraph/graphNodeContext.h | 11 ++++++++++ src/gui/models/nodeGraph/graphNodeModel.h | 4 ++-- src/gui/models/nodeGraph/instances/all.h | 21 ++++++++++++++++++- .../nodeGraph/instances/configuration.cpp | 2 +- .../nodeGraph/instances/configuration.h | 4 +++- .../models/nodeGraph/instances/generator.cpp | 2 +- .../models/nodeGraph/instances/generator.h | 4 +++- .../instances/generatorGraphNode.cpp | 2 +- .../nodeGraph/instances/generatorGraphNode.h | 5 ++--- .../nodeGraph/instances/generatorNode.cpp | 2 +- .../nodeGraph/instances/generatorNode.h | 8 ++++++- src/gui/models/nodeGraph/nodeWrapper.h | 18 +++++++--------- tests/CMakeLists.txt | 2 +- 17 files changed, 65 insertions(+), 44 deletions(-) create mode 100644 src/gui/models/nodeGraph/graphNodeContext.h diff --git a/src/gui/models/nodeGraph/exampleGraphModel.cpp b/src/gui/models/nodeGraph/exampleGraphModel.cpp index 63077c8a6f..e2fca4b4fd 100644 --- a/src/gui/models/nodeGraph/exampleGraphModel.cpp +++ b/src/gui/models/nodeGraph/exampleGraphModel.cpp @@ -63,7 +63,7 @@ template <> std::string nodeTypeIcon(const nodeValue &value) } // The title of the node -template <> std::string nodeName(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 &value, const std::string name) { value.name = name; } diff --git a/src/gui/models/nodeGraph/exampleGraphModel.h b/src/gui/models/nodeGraph/exampleGraphModel.h index 035336b879..67df158d47 100644 --- a/src/gui/models/nodeGraph/exampleGraphModel.h +++ b/src/gui/models/nodeGraph/exampleGraphModel.h @@ -29,5 +29,7 @@ class nodeValue std::variant value; }; +std::string nodeName(const nodeValue &value); + // The graph model for the example typedef GraphModel ExampleGraphModel; diff --git a/src/gui/models/nodeGraph/generatorGraphModel.h b/src/gui/models/nodeGraph/generatorGraphModel.h index a862aac132..c2bd06b8ce 100644 --- a/src/gui/models/nodeGraph/generatorGraphModel.h +++ b/src/gui/models/nodeGraph/generatorGraphModel.h @@ -10,24 +10,6 @@ #include "gui/models/nodeGraph/instances/all.h" #include "nodeWrapper.h" -// The variant of all of the types that we will examine -using GeneratorGraphInnerType = std::variant; - -// A class to contain the inner type, since we need a constructor that -// take a QVariant -class GeneratorGraphNode -{ - public: - GeneratorGraphNode(QVariant var = {}); - GeneratorGraphInnerType value; -}; - -// All of these types may require access to CoreData -template <> struct GraphNodeContext -{ - using type = CoreData *; -}; - // A graph node model for looking at the generators on a configuration class GeneratorGraphModel : public GraphModel { diff --git a/src/gui/models/nodeGraph/graphModel.h b/src/gui/models/nodeGraph/graphModel.h index b08854939c..83eead9d5c 100644 --- a/src/gui/models/nodeGraph/graphModel.h +++ b/src/gui/models/nodeGraph/graphModel.h @@ -37,7 +37,7 @@ **/ // This is the base class for any node graph type -template class GraphModel : public GraphModelBase +template class GraphModel : public GraphModelBase { public: GraphModel() : nodes_(this) {} diff --git a/src/gui/models/nodeGraph/graphNodeContext.h b/src/gui/models/nodeGraph/graphNodeContext.h new file mode 100644 index 0000000000..1de9705343 --- /dev/null +++ b/src/gui/models/nodeGraph/graphNodeContext.h @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// Copyright (c) 2024 Team Dissolve and contributors + +#pragma once + +// A template that we can specialise to associate a a context type +// with a type. +template struct GraphNodeContext +{ + using type = GraphNodeContext; +}; diff --git a/src/gui/models/nodeGraph/graphNodeModel.h b/src/gui/models/nodeGraph/graphNodeModel.h index bde80a506e..90cfedbe04 100644 --- a/src/gui/models/nodeGraph/graphNodeModel.h +++ b/src/gui/models/nodeGraph/graphNodeModel.h @@ -8,7 +8,7 @@ #include #include -template class GraphModel; +template class GraphModel; // A base to add a static terms or properties to GraphNodeModel class GraphNodeModelBase : public QAbstractListModel @@ -22,7 +22,7 @@ class GraphNodeModelBase : public QAbstractListModel // The model for accessing the node data (which is *held* in the // GraphModel class) -template class GraphNodeModel : public GraphNodeModelBase +template class GraphNodeModel : public GraphNodeModelBase { friend GraphModel; diff --git a/src/gui/models/nodeGraph/instances/all.h b/src/gui/models/nodeGraph/instances/all.h index 1277a1c206..d17a4c50af 100644 --- a/src/gui/models/nodeGraph/instances/all.h +++ b/src/gui/models/nodeGraph/instances/all.h @@ -3,8 +3,27 @@ #pragma once +#include #include "configuration.h" #include "generator.h" #include "generatorNode.h" -// This file exists to easily include all of the templated methods for all of the types for the Node Graph +// The variant of all of the types that we will examine +using GeneratorGraphInnerType = std::variant; + +// A class to contain the inner type, since we need a constructor that +// take a QVariant +class GeneratorGraphNode +{ + public: + GeneratorGraphNode(QVariant var = {}); + GeneratorGraphInnerType value; +}; + +// All of these types may require access to CoreData +template <> struct GraphNodeContext +{ + using type = CoreData *; +}; + +std::string nodeName(GeneratorGraphNode &value); diff --git a/src/gui/models/nodeGraph/instances/configuration.cpp b/src/gui/models/nodeGraph/instances/configuration.cpp index 67c1f471a7..7c6a4f876b 100644 --- a/src/gui/models/nodeGraph/instances/configuration.cpp +++ b/src/gui/models/nodeGraph/instances/configuration.cpp @@ -13,7 +13,7 @@ template <> std::string nodeTypeIcon(Configuration *const &valu } // The title of the node -template <> std::string nodeName(Configuration *const &value) +std::string nodeName(Configuration *const &value) { if (!value) diff --git a/src/gui/models/nodeGraph/instances/configuration.h b/src/gui/models/nodeGraph/instances/configuration.h index 070c52e0cf..343717cfdf 100644 --- a/src/gui/models/nodeGraph/instances/configuration.h +++ b/src/gui/models/nodeGraph/instances/configuration.h @@ -4,7 +4,7 @@ #pragma once #include "classes/configuration.h" -#include "gui/models/nodeGraph/nodeWrapper.h" +#include "gui/models/nodeGraph/graphNodeContext.h" // Configurations need access to the CoreData to access all of their // children. @@ -12,3 +12,5 @@ template <> struct GraphNodeContext { using type = CoreData *; }; + +std::string nodeName(Configuration *const &value); diff --git a/src/gui/models/nodeGraph/instances/generator.cpp b/src/gui/models/nodeGraph/instances/generator.cpp index 59305802e2..8420e926bc 100644 --- a/src/gui/models/nodeGraph/instances/generator.cpp +++ b/src/gui/models/nodeGraph/instances/generator.cpp @@ -10,7 +10,7 @@ template <> std::string nodeTypeName(Generator *const &value) { ret template <> std::string nodeTypeIcon(Generator *const &value) { return "qrc:/Dissolve/icons/generator.svg"; } // The title of the node -template <> std::string nodeName(Generator *const &value) { return "Generator"; } +std::string nodeName(Generator *const &value) { return "Generator"; } // Get a specific piece of information from a node by index template <> QVariant nodeData(Generator *const &value, int role) diff --git a/src/gui/models/nodeGraph/instances/generator.h b/src/gui/models/nodeGraph/instances/generator.h index fa29de2365..2890c14771 100644 --- a/src/gui/models/nodeGraph/instances/generator.h +++ b/src/gui/models/nodeGraph/instances/generator.h @@ -4,7 +4,7 @@ #pragma once #include "generator/generator.h" -#include "gui/models/nodeGraph/nodeWrapper.h" +#include "gui/models/nodeGraph/graphNodeContext.h" // Generators need access to the CoreData to access all of their // children. @@ -12,3 +12,5 @@ template <> struct GraphNodeContext { using type = CoreData *; }; + +std::string nodeName(Generator *const &value); diff --git a/src/gui/models/nodeGraph/instances/generatorGraphNode.cpp b/src/gui/models/nodeGraph/instances/generatorGraphNode.cpp index f7b230319d..9dc01eabb5 100644 --- a/src/gui/models/nodeGraph/instances/generatorGraphNode.cpp +++ b/src/gui/models/nodeGraph/instances/generatorGraphNode.cpp @@ -59,7 +59,7 @@ template <> std::string nodeTypeIcon(const GeneratorGraphNod } // The title of the node -template <> std::string nodeName(const GeneratorGraphNode &value) +std::string nodeName(GeneratorGraphNode &value) { return std::visit([](auto *arg) { return nodeName(arg); }, value.value); } diff --git a/src/gui/models/nodeGraph/instances/generatorGraphNode.h b/src/gui/models/nodeGraph/instances/generatorGraphNode.h index c6f0068ab0..e73f838530 100644 --- a/src/gui/models/nodeGraph/instances/generatorGraphNode.h +++ b/src/gui/models/nodeGraph/instances/generatorGraphNode.h @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-or-later // Copyright (c) 2024 Team Dissolve and contributors -#include "gui/models/nodeGraph/generatorGraphModel.h" -#include "gui/models/nodeGraph/nodeWrapper.h" - #pragma once + +#include "gui/models/nodeGraph/generatorGraphModel.h" diff --git a/src/gui/models/nodeGraph/instances/generatorNode.cpp b/src/gui/models/nodeGraph/instances/generatorNode.cpp index 784b702ae9..a665e7a96f 100644 --- a/src/gui/models/nodeGraph/instances/generatorNode.cpp +++ b/src/gui/models/nodeGraph/instances/generatorNode.cpp @@ -16,7 +16,7 @@ template <> std::string nodeTypeIcon(GeneratorNode *const &valu } // The title of the node -template <> std::string nodeName(GeneratorNode *const &value) +std::string nodeName(GeneratorNode *const &value) { std::string result = {value->name().begin(), value->name().end()}; return result; diff --git a/src/gui/models/nodeGraph/instances/generatorNode.h b/src/gui/models/nodeGraph/instances/generatorNode.h index 59482a855b..7bef77e9db 100644 --- a/src/gui/models/nodeGraph/instances/generatorNode.h +++ b/src/gui/models/nodeGraph/instances/generatorNode.h @@ -3,7 +3,11 @@ #pragma once -#include "gui/models/nodeGraph/generatorGraphModel.h" +#include "gui/models/nodeGraph/graphNodeContext.h" +#include "classes/coreData.h" + +class GeneratorNode; + // GeneratorNodes need access to the CoreData to access all of their // children. @@ -11,3 +15,5 @@ template <> struct GraphNodeContext { using type = CoreData *; }; + +std::string nodeName(GeneratorNode *const &value); diff --git a/src/gui/models/nodeGraph/nodeWrapper.h b/src/gui/models/nodeGraph/nodeWrapper.h index 0f047b152d..da03b70438 100644 --- a/src/gui/models/nodeGraph/nodeWrapper.h +++ b/src/gui/models/nodeGraph/nodeWrapper.h @@ -4,7 +4,9 @@ #pragma once #include +#include #include +#include "gui/models/nodeGraph/instances/all.h" /** This file contains a series of templates that need to be overloaded @@ -25,13 +27,6 @@ suddenly become a dependency of the command line code. **/ -// A template that we can specialise to associate a a context type -// with a type. -template struct GraphNodeContext -{ - using type = GraphNodeContext; -}; - // Append the roles for the type onto the QHash template QHash &nodeRoleNames(QHash &base); // The name of the type (for delegate dispatch) @@ -40,8 +35,6 @@ template std::string nodeTypeName(const T &value); template std::string nodeTypeIcon(const T &value); // Delete the node template bool nodeDelete(T &value, typename GraphNodeContext::type &context); -// The title of the node -template std::string nodeName(const T &value); // Change the title of the node template void setNodeName(T &value, const std::string); // The value of the node @@ -53,8 +46,13 @@ template bool nodeConnectable(const T &source, int sourceIndex, con // Unlink an indexed position on the source to an indexed position on the destination template bool nodeDisconnect(T &source, int sourceIndex, T &destination, int destinationIndex); +template +concept Graphable = requires(T a) { + { nodeName(a) } -> std::same_as; +}; + // A wrapper with supplemental information for a node -template class NodeWrapper +template class NodeWrapper { public: NodeWrapper(QVariant value) : value_(value) {} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 502c99a99f..1d9663601d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -47,7 +47,7 @@ function(dissolve_add_test) target_include_directories(${TEST_NAME} PRIVATE ${Qt6Widgets_INCLUDE_DIRS}) target_link_libraries( ${TEST_NAME} - PUBLIC keywordWidgets models widgets render delegates + PUBLIC keywordWidgets models widgets render delegates nodeGraphModel PRIVATE Qt6::Core Qt6::Widgets ) endif(DISSOLVE_UNIT_TEST_GUI) From 8f630b319e0341fea612c84d3134edfa7c06aa72 Mon Sep 17 00:00:00 2001 From: Adam Washington Date: Tue, 14 Jan 2025 14:12:02 +0000 Subject: [PATCH 03/15] Move more into Concepts --- src/gui/models/nodeGraph/exampleGraphModel.cpp | 4 ++-- src/gui/models/nodeGraph/exampleGraphModel.h | 2 ++ src/gui/models/nodeGraph/instances/all.h | 4 +++- src/gui/models/nodeGraph/instances/configuration.cpp | 4 ++-- src/gui/models/nodeGraph/instances/configuration.h | 2 ++ src/gui/models/nodeGraph/instances/generator.cpp | 4 ++-- src/gui/models/nodeGraph/instances/generator.h | 2 ++ src/gui/models/nodeGraph/instances/generatorGraphNode.cpp | 8 ++++---- src/gui/models/nodeGraph/instances/generatorNode.cpp | 4 ++-- src/gui/models/nodeGraph/instances/generatorNode.h | 2 ++ src/gui/models/nodeGraph/nodeWrapper.h | 4 ++-- 11 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/gui/models/nodeGraph/exampleGraphModel.cpp b/src/gui/models/nodeGraph/exampleGraphModel.cpp index e2fca4b4fd..f1d8c1c559 100644 --- a/src/gui/models/nodeGraph/exampleGraphModel.cpp +++ b/src/gui/models/nodeGraph/exampleGraphModel.cpp @@ -27,7 +27,7 @@ template <> QVariant nodeGetValue(const nodeValue value) }; // The name of the type (for delegate dispatch) -template <> std::string nodeTypeName(const nodeValue &value) +std::string nodeTypeName(const nodeValue &value) { return std::visit( [](auto arg) -> std::string @@ -45,7 +45,7 @@ template <> std::string nodeTypeName(const nodeValue &value) } // The path to the icon for the node -template <> std::string nodeTypeIcon(const nodeValue &value) +std::string nodeTypeIcon(const nodeValue &value) { return std::visit( [](auto arg) -> std::string diff --git a/src/gui/models/nodeGraph/exampleGraphModel.h b/src/gui/models/nodeGraph/exampleGraphModel.h index 67df158d47..cce8b310cc 100644 --- a/src/gui/models/nodeGraph/exampleGraphModel.h +++ b/src/gui/models/nodeGraph/exampleGraphModel.h @@ -30,6 +30,8 @@ class nodeValue }; std::string nodeName(const nodeValue &value); +std::string nodeTypeName(const nodeValue &value); +std::string nodeTypeIcon(const nodeValue &value); // The graph model for the example typedef GraphModel ExampleGraphModel; diff --git a/src/gui/models/nodeGraph/instances/all.h b/src/gui/models/nodeGraph/instances/all.h index d17a4c50af..b09f6fe277 100644 --- a/src/gui/models/nodeGraph/instances/all.h +++ b/src/gui/models/nodeGraph/instances/all.h @@ -26,4 +26,6 @@ template <> struct GraphNodeContext using type = CoreData *; }; -std::string nodeName(GeneratorGraphNode &value); +std::string nodeName(const GeneratorGraphNode &value); +std::string nodeTypeName(const GeneratorGraphNode &value); +std::string nodeTypeIcon(const GeneratorGraphNode &value); diff --git a/src/gui/models/nodeGraph/instances/configuration.cpp b/src/gui/models/nodeGraph/instances/configuration.cpp index 7c6a4f876b..7eac870410 100644 --- a/src/gui/models/nodeGraph/instances/configuration.cpp +++ b/src/gui/models/nodeGraph/instances/configuration.cpp @@ -4,10 +4,10 @@ #include "gui/models/nodeGraph/nodeWrapper.h" // The name of the type (for delegate dispatch) -template <> std::string nodeTypeName(Configuration *const &value) { return "Configuration"; } +std::string nodeTypeName(Configuration *const &value) { return "Configuration"; } // The path to the icon for the node -template <> std::string nodeTypeIcon(Configuration *const &value) +std::string nodeTypeIcon(Configuration *const &value) { return "qrc:/Dissolve/icons/configuration.svg"; } diff --git a/src/gui/models/nodeGraph/instances/configuration.h b/src/gui/models/nodeGraph/instances/configuration.h index 343717cfdf..286c943ba9 100644 --- a/src/gui/models/nodeGraph/instances/configuration.h +++ b/src/gui/models/nodeGraph/instances/configuration.h @@ -14,3 +14,5 @@ template <> struct GraphNodeContext }; std::string nodeName(Configuration *const &value); +std::string nodeTypeName(Configuration *const &value); +std::string nodeTypeIcon(Configuration *const &value); diff --git a/src/gui/models/nodeGraph/instances/generator.cpp b/src/gui/models/nodeGraph/instances/generator.cpp index 8420e926bc..3b14f9e3da 100644 --- a/src/gui/models/nodeGraph/instances/generator.cpp +++ b/src/gui/models/nodeGraph/instances/generator.cpp @@ -4,10 +4,10 @@ #include "gui/models/nodeGraph/nodeWrapper.h" // The name of the type (for delegate dispatch) -template <> std::string nodeTypeName(Generator *const &value) { return "Generator"; } +std::string nodeTypeName(Generator *const &value) { return "Generator"; } // The path to the icon for the node -template <> std::string nodeTypeIcon(Generator *const &value) { return "qrc:/Dissolve/icons/generator.svg"; } +std::string nodeTypeIcon(Generator *const &value) { return "qrc:/Dissolve/icons/generator.svg"; } // The title of the node std::string nodeName(Generator *const &value) { return "Generator"; } diff --git a/src/gui/models/nodeGraph/instances/generator.h b/src/gui/models/nodeGraph/instances/generator.h index 2890c14771..e80d9a6822 100644 --- a/src/gui/models/nodeGraph/instances/generator.h +++ b/src/gui/models/nodeGraph/instances/generator.h @@ -14,3 +14,5 @@ template <> struct GraphNodeContext }; std::string nodeName(Generator *const &value); +std::string nodeTypeName(Generator *const &value); +std::string nodeTypeIcon(Generator *const &value); diff --git a/src/gui/models/nodeGraph/instances/generatorGraphNode.cpp b/src/gui/models/nodeGraph/instances/generatorGraphNode.cpp index 9dc01eabb5..b08b6b7e59 100644 --- a/src/gui/models/nodeGraph/instances/generatorGraphNode.cpp +++ b/src/gui/models/nodeGraph/instances/generatorGraphNode.cpp @@ -3,7 +3,7 @@ #include "gui/models/nodeGraph/generatorGraphModel.h" // The value of the node -template <> QVariant nodeGetValue(const GeneratorGraphNode value) +QVariant nodeGetValue(const GeneratorGraphNode value) { return std::visit( [](auto *arg) -> QVariant @@ -16,7 +16,7 @@ template <> QVariant nodeGetValue(const GeneratorGraphNode v } // The name of the type (for delegate dispatch) -template <> std::string nodeTypeName(const GeneratorGraphNode &value) +std::string nodeTypeName(const GeneratorGraphNode &value) { return std::visit( [](auto *arg) -> std::string @@ -53,13 +53,13 @@ bool nodeDisconnect(GeneratorGraphNode &source, int sourceIn } // The path to the icon for the node -template <> std::string nodeTypeIcon(const GeneratorGraphNode &value) +std::string nodeTypeIcon(const GeneratorGraphNode &value) { return std::visit([](auto *arg) { return nodeTypeIcon(arg); }, value.value); } // The title of the node -std::string nodeName(GeneratorGraphNode &value) +std::string nodeName(const GeneratorGraphNode &value) { return std::visit([](auto *arg) { return nodeName(arg); }, value.value); } diff --git a/src/gui/models/nodeGraph/instances/generatorNode.cpp b/src/gui/models/nodeGraph/instances/generatorNode.cpp index a665e7a96f..b3c28dee23 100644 --- a/src/gui/models/nodeGraph/instances/generatorNode.cpp +++ b/src/gui/models/nodeGraph/instances/generatorNode.cpp @@ -6,10 +6,10 @@ #include "keywords/nodeValue.h" // The name of the type (for delegate dispatch) -template <> std::string nodeTypeName(GeneratorNode *const &value) { return "GeneratorNode"; } +std::string nodeTypeName(GeneratorNode *const &value) { return "GeneratorNode"; } // The path to the icon for the node -template <> std::string nodeTypeIcon(GeneratorNode *const &value) +std::string nodeTypeIcon(GeneratorNode *const &value) { auto name = GeneratorNode::nodeTypes().keyword(value->type()); return "qrc:/Dissolve/icons/nodes/" + name + ".svg"; diff --git a/src/gui/models/nodeGraph/instances/generatorNode.h b/src/gui/models/nodeGraph/instances/generatorNode.h index 7bef77e9db..8f9f6e8a9a 100644 --- a/src/gui/models/nodeGraph/instances/generatorNode.h +++ b/src/gui/models/nodeGraph/instances/generatorNode.h @@ -17,3 +17,5 @@ template <> struct GraphNodeContext }; std::string nodeName(GeneratorNode *const &value); +std::string nodeTypeName(GeneratorNode *const &value); +std::string nodeTypeIcon(GeneratorNode *const &value); diff --git a/src/gui/models/nodeGraph/nodeWrapper.h b/src/gui/models/nodeGraph/nodeWrapper.h index da03b70438..a8f0029295 100644 --- a/src/gui/models/nodeGraph/nodeWrapper.h +++ b/src/gui/models/nodeGraph/nodeWrapper.h @@ -29,8 +29,6 @@ // Append the roles for the type onto the QHash template QHash &nodeRoleNames(QHash &base); -// The name of the type (for delegate dispatch) -template std::string nodeTypeName(const T &value); // The path to the icon for the node template std::string nodeTypeIcon(const T &value); // Delete the node @@ -49,6 +47,8 @@ template bool nodeDisconnect(T &source, int sourceIndex, T &destina template concept Graphable = requires(T a) { { nodeName(a) } -> std::same_as; + { nodeTypeName(a) } -> std::same_as; + { nodeTypeIcon(a) } -> std::same_as; }; // A wrapper with supplemental information for a node From 6444df3e9bf87e4d565adcf0fcb6302df822d333 Mon Sep 17 00:00:00 2001 From: Adam Washington Date: Tue, 14 Jan 2025 14:33:03 +0000 Subject: [PATCH 04/15] setNodeName and nodeGetValue in concept --- src/gui/models/nodeGraph/exampleGraphModel.cpp | 6 +++--- src/gui/models/nodeGraph/exampleGraphModel.h | 2 ++ src/gui/models/nodeGraph/instances/all.h | 2 ++ src/gui/models/nodeGraph/instances/generatorGraphNode.cpp | 2 +- src/gui/models/nodeGraph/nodeWrapper.h | 8 +++----- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/gui/models/nodeGraph/exampleGraphModel.cpp b/src/gui/models/nodeGraph/exampleGraphModel.cpp index f1d8c1c559..8f81bdba1e 100644 --- a/src/gui/models/nodeGraph/exampleGraphModel.cpp +++ b/src/gui/models/nodeGraph/exampleGraphModel.cpp @@ -7,7 +7,7 @@ #include // The value of the node -template <> QVariant nodeGetValue(const nodeValue value) +QVariant nodeGetValue(const nodeValue &value) { return std::visit( [](auto arg) -> QVariant @@ -19,7 +19,7 @@ template <> QVariant nodeGetValue(const nodeValue value) else { if (arg) - return nodeGetValue(*arg); + return nodeGetValue(*arg); return {}; } }, @@ -66,7 +66,7 @@ std::string nodeTypeIcon(const nodeValue &value) std::string nodeName(const nodeValue &value) { return value.name; } // Change the title of the node -template <> void setNodeName(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 &source, int sourceIndex, nodeValue &destionation, int destinationIndex) diff --git a/src/gui/models/nodeGraph/exampleGraphModel.h b/src/gui/models/nodeGraph/exampleGraphModel.h index cce8b310cc..3cf84c662a 100644 --- a/src/gui/models/nodeGraph/exampleGraphModel.h +++ b/src/gui/models/nodeGraph/exampleGraphModel.h @@ -32,6 +32,8 @@ class nodeValue 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); // The graph model for the example typedef GraphModel ExampleGraphModel; diff --git a/src/gui/models/nodeGraph/instances/all.h b/src/gui/models/nodeGraph/instances/all.h index b09f6fe277..421b9c54f6 100644 --- a/src/gui/models/nodeGraph/instances/all.h +++ b/src/gui/models/nodeGraph/instances/all.h @@ -29,3 +29,5 @@ template <> struct GraphNodeContext std::string nodeName(const GeneratorGraphNode &value); std::string nodeTypeName(const GeneratorGraphNode &value); std::string nodeTypeIcon(const GeneratorGraphNode &value); +void setNodeName(GeneratorGraphNode &value, std::string); +QVariant nodeGetValue(const GeneratorGraphNode &value); diff --git a/src/gui/models/nodeGraph/instances/generatorGraphNode.cpp b/src/gui/models/nodeGraph/instances/generatorGraphNode.cpp index b08b6b7e59..661ee3fbe9 100644 --- a/src/gui/models/nodeGraph/instances/generatorGraphNode.cpp +++ b/src/gui/models/nodeGraph/instances/generatorGraphNode.cpp @@ -65,7 +65,7 @@ std::string nodeName(const GeneratorGraphNode &value) } // Change the title of the node -template <> void setNodeName(GeneratorGraphNode &value, const std::string name) {} +void setNodeName(GeneratorGraphNode &value, const std::string name) {} // Set a specific piece of information from a node by index template <> bool nodeSetData(GeneratorGraphNode &item, const QVariant &value, int role) diff --git a/src/gui/models/nodeGraph/nodeWrapper.h b/src/gui/models/nodeGraph/nodeWrapper.h index a8f0029295..9199eada0a 100644 --- a/src/gui/models/nodeGraph/nodeWrapper.h +++ b/src/gui/models/nodeGraph/nodeWrapper.h @@ -33,10 +33,6 @@ template QHash &nodeRoleNames(QHash std::string nodeTypeIcon(const T &value); // Delete the node template bool nodeDelete(T &value, typename GraphNodeContext::type &context); -// Change the title of the node -template void setNodeName(T &value, const std::string); -// The value of the node -template QVariant nodeGetValue(const T value); // Link an indexed position on the source to an indexed position on the destination template bool nodeConnect(T &source, int sourceIndex, T &destination, int destinationIndex); // Confirm that a connection is possible (e.g. types match and index isn't already connected) @@ -45,10 +41,12 @@ template bool nodeConnectable(const T &source, int sourceIndex, con template bool nodeDisconnect(T &source, int sourceIndex, T &destination, int destinationIndex); template -concept Graphable = requires(T a) { +concept Graphable = requires(T a, const std::string name) { { nodeName(a) } -> std::same_as; { nodeTypeName(a) } -> std::same_as; { nodeTypeIcon(a) } -> std::same_as; + { setNodeName(a, name) }; + { nodeGetValue(a) } -> std::same_as; }; // A wrapper with supplemental information for a node From 8d63de3c7234edf02f5dc363f04e4a1da6db8c49 Mon Sep 17 00:00:00 2001 From: Adam Washington Date: Tue, 14 Jan 2025 14:53:37 +0000 Subject: [PATCH 05/15] Add connections to node concept Intriguingly, the connection types are only rarely needed. It may be worth making this a separate concept --- .../models/nodeGraph/exampleGraphModel.cpp | 8 ++-- src/gui/models/nodeGraph/exampleGraphModel.h | 3 ++ src/gui/models/nodeGraph/instances/all.h | 3 ++ .../nodeGraph/instances/configuration.h | 4 ++ .../instances/generatorGraphNode.cpp | 13 ++---- src/gui/models/nodeGraph/nodeWrapper.h | 41 ++++++++++++------- 6 files changed, 44 insertions(+), 28 deletions(-) diff --git a/src/gui/models/nodeGraph/exampleGraphModel.cpp b/src/gui/models/nodeGraph/exampleGraphModel.cpp index 8f81bdba1e..bd068f912a 100644 --- a/src/gui/models/nodeGraph/exampleGraphModel.cpp +++ b/src/gui/models/nodeGraph/exampleGraphModel.cpp @@ -69,21 +69,21 @@ std::string nodeName(const nodeValue &value) { return value.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 &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(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(source.value) && std::holds_alternative(destination.value); } // Unlink an indexed position on the source to an indexed position on the destination -template <> bool nodeDisconnect(nodeValue &source, int sourceIndex, nodeValue &destination, int destinationIndex) +bool nodeDisconnect(nodeValue &source, int sourceIndex, nodeValue &destination, int destinationIndex) { destination.value = nullptr; return true; diff --git a/src/gui/models/nodeGraph/exampleGraphModel.h b/src/gui/models/nodeGraph/exampleGraphModel.h index 3cf84c662a..aa25bb8ba6 100644 --- a/src/gui/models/nodeGraph/exampleGraphModel.h +++ b/src/gui/models/nodeGraph/exampleGraphModel.h @@ -34,6 +34,9 @@ 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); // The graph model for the example typedef GraphModel ExampleGraphModel; diff --git a/src/gui/models/nodeGraph/instances/all.h b/src/gui/models/nodeGraph/instances/all.h index 421b9c54f6..020cac3370 100644 --- a/src/gui/models/nodeGraph/instances/all.h +++ b/src/gui/models/nodeGraph/instances/all.h @@ -31,3 +31,6 @@ std::string nodeTypeName(const GeneratorGraphNode &value); std::string nodeTypeIcon(const GeneratorGraphNode &value); void setNodeName(GeneratorGraphNode &value, std::string); QVariant nodeGetValue(const GeneratorGraphNode &value); +bool nodeConnect(GeneratorGraphNode &source, int sourceIndex, GeneratorGraphNode &destionation, int destinationIndex); +bool nodeConnectable(const GeneratorGraphNode &source, int sourceIndex, const GeneratorGraphNode &destination, int destinationIndex); +bool nodeDisconnect(GeneratorGraphNode &source, int sourceIndex, GeneratorGraphNode &destination, int destinationIndex); diff --git a/src/gui/models/nodeGraph/instances/configuration.h b/src/gui/models/nodeGraph/instances/configuration.h index 286c943ba9..1e1cf482e6 100644 --- a/src/gui/models/nodeGraph/instances/configuration.h +++ b/src/gui/models/nodeGraph/instances/configuration.h @@ -16,3 +16,7 @@ template <> struct GraphNodeContext std::string nodeName(Configuration *const &value); std::string nodeTypeName(Configuration *const &value); std::string nodeTypeIcon(Configuration *const &value); + +bool nodeConnect(Configuration *&source, int sourceIndex, Configuration *&destionation, int destinationIndex); +bool nodeConnectable(const Configuration *&source, int sourceIndex, const Configuration *&destination, int destinationIndex); +bool nodeDisconnect(Configuration *&source, int sourceIndex, Configuration *&destination, int destinationIndex); diff --git a/src/gui/models/nodeGraph/instances/generatorGraphNode.cpp b/src/gui/models/nodeGraph/instances/generatorGraphNode.cpp index 661ee3fbe9..539acb443e 100644 --- a/src/gui/models/nodeGraph/instances/generatorGraphNode.cpp +++ b/src/gui/models/nodeGraph/instances/generatorGraphNode.cpp @@ -29,25 +29,20 @@ std::string nodeTypeName(const GeneratorGraphNode &value) } // Link an indexed position on the source to an indexed position on the destination -template <> -bool nodeConnect(GeneratorGraphNode &source, int sourceIndex, GeneratorGraphNode &destination, - int destinationIndex) +bool nodeConnect(GeneratorGraphNode &source, int sourceIndex, GeneratorGraphNode &destination, int destinationIndex) { return false; } // Confirm that a connection is possible (e.g. types match and index isn't already connected) -template <> -bool nodeConnectable(const GeneratorGraphNode &source, int sourceIndex, - const GeneratorGraphNode &destination, int destinationIndex) +bool nodeConnectable(const GeneratorGraphNode &source, int sourceIndex, const GeneratorGraphNode &destination, + int destinationIndex) { return false; } // Unlink an indexed position on the source to an indexed position on the destination -template <> -bool nodeDisconnect(GeneratorGraphNode &source, int sourceIndex, GeneratorGraphNode &destination, - int destinationIndex) +bool nodeDisconnect(GeneratorGraphNode &source, int sourceIndex, GeneratorGraphNode &destination, int destinationIndex) { return true; } diff --git a/src/gui/models/nodeGraph/nodeWrapper.h b/src/gui/models/nodeGraph/nodeWrapper.h index 9199eada0a..02ebec75e1 100644 --- a/src/gui/models/nodeGraph/nodeWrapper.h +++ b/src/gui/models/nodeGraph/nodeWrapper.h @@ -3,10 +3,10 @@ #pragma once +#include "gui/models/nodeGraph/instances/all.h" #include #include #include -#include "gui/models/nodeGraph/instances/all.h" /** This file contains a series of templates that need to be overloaded @@ -29,24 +29,35 @@ // Append the roles for the type onto the QHash template QHash &nodeRoleNames(QHash &base); -// The path to the icon for the node -template std::string nodeTypeIcon(const T &value); // Delete the node template bool nodeDelete(T &value, typename GraphNodeContext::type &context); -// Link an indexed position on the source to an indexed position on the destination -template bool nodeConnect(T &source, int sourceIndex, T &destination, int destinationIndex); -// Confirm that a connection is possible (e.g. types match and index isn't already connected) -template bool nodeConnectable(const T &source, int sourceIndex, const T &destination, int destinationIndex); -// Unlink an indexed position on the source to an indexed position on the destination -template bool nodeDisconnect(T &source, int sourceIndex, T &destination, int destinationIndex); template -concept Graphable = requires(T a, const std::string name) { - { nodeName(a) } -> std::same_as; - { nodeTypeName(a) } -> std::same_as; - { nodeTypeIcon(a) } -> std::same_as; - { setNodeName(a, name) }; - { nodeGetValue(a) } -> std::same_as; +concept Graphable = requires(T a, const std::string name, T b, int sourceIndex, int destinationIndex) { + { + nodeName(a) + } -> std::same_as; + { + nodeTypeName(a) + } -> std::same_as; + { + nodeTypeIcon(a) + } -> std::same_as; + { + setNodeName(a, name) + }; + { + nodeGetValue(a) + } -> std::same_as; + { + nodeConnect(a, sourceIndex, b, destinationIndex) + } -> std::same_as; + { + nodeConnectable(a, sourceIndex, b, destinationIndex) + } -> std::same_as; + { + nodeDisconnect(a, sourceIndex, b, destinationIndex) + } -> std::same_as; }; // A wrapper with supplemental information for a node From d5d5a1f1441f343bf5e91cde68b88a57d0c0dfb9 Mon Sep 17 00:00:00 2001 From: Adam Washington Date: Tue, 14 Jan 2025 15:56:30 +0000 Subject: [PATCH 06/15] Put node role names in concept --- src/gui/models/nodeGraph/exampleGraphModel.cpp | 2 +- src/gui/models/nodeGraph/exampleGraphModel.h | 1 + src/gui/models/nodeGraph/graphNodeContext.h | 4 ++++ src/gui/models/nodeGraph/graphNodeModel.h | 3 ++- src/gui/models/nodeGraph/instances/all.h | 1 + src/gui/models/nodeGraph/instances/generatorGraphNode.cpp | 2 +- src/gui/models/nodeGraph/nodeWrapper.h | 8 +++++--- 7 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/gui/models/nodeGraph/exampleGraphModel.cpp b/src/gui/models/nodeGraph/exampleGraphModel.cpp index bd068f912a..173ed53b1e 100644 --- a/src/gui/models/nodeGraph/exampleGraphModel.cpp +++ b/src/gui/models/nodeGraph/exampleGraphModel.cpp @@ -90,7 +90,7 @@ bool nodeDisconnect(nodeValue &source, int sourceIndex, nodeValue &destination, } // Append the roles for the type onto the QHash -template <> QHash &nodeRoleNames(QHash &roles) +QHash &nodeRoleNames(Proxy proxy, QHash &roles) { const auto base = Qt::UserRole + GraphNodeModelBase::ownedRoles; roles[base] = "value"; diff --git a/src/gui/models/nodeGraph/exampleGraphModel.h b/src/gui/models/nodeGraph/exampleGraphModel.h index aa25bb8ba6..eb3e51262f 100644 --- a/src/gui/models/nodeGraph/exampleGraphModel.h +++ b/src/gui/models/nodeGraph/exampleGraphModel.h @@ -37,6 +37,7 @@ 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 &nodeRoleNames(Proxy proxy, QHash &roles); // The graph model for the example typedef GraphModel ExampleGraphModel; diff --git a/src/gui/models/nodeGraph/graphNodeContext.h b/src/gui/models/nodeGraph/graphNodeContext.h index 1de9705343..12cebda58a 100644 --- a/src/gui/models/nodeGraph/graphNodeContext.h +++ b/src/gui/models/nodeGraph/graphNodeContext.h @@ -9,3 +9,7 @@ template struct GraphNodeContext { using type = GraphNodeContext; }; + +template struct Proxy +{ +}; diff --git a/src/gui/models/nodeGraph/graphNodeModel.h b/src/gui/models/nodeGraph/graphNodeModel.h index 90cfedbe04..1c4710c250 100644 --- a/src/gui/models/nodeGraph/graphNodeModel.h +++ b/src/gui/models/nodeGraph/graphNodeModel.h @@ -43,13 +43,14 @@ template class GraphNodeModel : public GraphNodeModelBase // Labels for QML roles (required by QAbstractListModel) QHash roleNames() const override { + Proxy proxy; QHash roles; roles[Qt::UserRole] = "name"; roles[Qt::UserRole + 1] = "posX"; roles[Qt::UserRole + 2] = "posY"; roles[Qt::UserRole + 3] = "type"; roles[Qt::UserRole + 4] = "icon"; - return nodeRoleNames(roles); + return nodeRoleNames(proxy, roles); } // Data accessor (required by QAbstractListModel) diff --git a/src/gui/models/nodeGraph/instances/all.h b/src/gui/models/nodeGraph/instances/all.h index 020cac3370..37dc536e06 100644 --- a/src/gui/models/nodeGraph/instances/all.h +++ b/src/gui/models/nodeGraph/instances/all.h @@ -34,3 +34,4 @@ QVariant nodeGetValue(const GeneratorGraphNode &value); bool nodeConnect(GeneratorGraphNode &source, int sourceIndex, GeneratorGraphNode &destionation, int destinationIndex); bool nodeConnectable(const GeneratorGraphNode &source, int sourceIndex, const GeneratorGraphNode &destination, int destinationIndex); bool nodeDisconnect(GeneratorGraphNode &source, int sourceIndex, GeneratorGraphNode &destination, int destinationIndex); +QHash &nodeRoleNames(Proxy proxy, QHash &roles); diff --git a/src/gui/models/nodeGraph/instances/generatorGraphNode.cpp b/src/gui/models/nodeGraph/instances/generatorGraphNode.cpp index 539acb443e..135cb4c9c2 100644 --- a/src/gui/models/nodeGraph/instances/generatorGraphNode.cpp +++ b/src/gui/models/nodeGraph/instances/generatorGraphNode.cpp @@ -77,7 +77,7 @@ template <> QVariant nodeData(const GeneratorGraphNode &item, int role) } // Append the roles for the type onto the QHash -template <> QHash &nodeRoleNames(QHash &roles) +QHash &nodeRoleNames(Proxy proxy, QHash &roles) { auto base = Qt::UserRole + GraphNodeModelBase::ownedRoles; using names = GeneratorGraphModel::PropertyIndex; diff --git a/src/gui/models/nodeGraph/nodeWrapper.h b/src/gui/models/nodeGraph/nodeWrapper.h index 02ebec75e1..a4ca11cc6b 100644 --- a/src/gui/models/nodeGraph/nodeWrapper.h +++ b/src/gui/models/nodeGraph/nodeWrapper.h @@ -27,13 +27,15 @@ suddenly become a dependency of the command line code. **/ -// Append the roles for the type onto the QHash -template QHash &nodeRoleNames(QHash &base); // Delete the node template bool nodeDelete(T &value, typename GraphNodeContext::type &context); template -concept Graphable = requires(T a, const std::string name, T b, int sourceIndex, int destinationIndex) { +concept Graphable = requires(T a, const std::string name, T b, int sourceIndex, int destinationIndex, Proxy proxy, + QHash &baseHash) { + { + nodeRoleNames(proxy, baseHash) + } -> std::same_as &>; { nodeName(a) } -> std::same_as; From 8b5d40d88e855b5692e384153e960b302359c25c Mon Sep 17 00:00:00 2001 From: Adam Washington Date: Thu, 16 Jan 2025 15:15:19 +0000 Subject: [PATCH 07/15] Move `nodeDelete` into concept --- .../models/nodeGraph/exampleGraphModel.cpp | 2 +- src/gui/models/nodeGraph/exampleGraphModel.h | 3 ++- .../models/nodeGraph/generatorGraphModel.h | 2 +- src/gui/models/nodeGraph/graphModel.h | 12 ++++++----- src/gui/models/nodeGraph/graphNodeModel.h | 20 +++++++++++-------- src/gui/models/nodeGraph/instances/all.h | 1 + .../nodeGraph/instances/configuration.cpp | 8 ++++---- .../nodeGraph/instances/configuration.h | 13 ++++++------ .../models/nodeGraph/instances/generator.cpp | 2 +- .../models/nodeGraph/instances/generator.h | 1 + .../instances/generatorGraphNode.cpp | 3 +-- .../nodeGraph/instances/generatorNode.cpp | 2 +- .../nodeGraph/instances/generatorNode.h | 2 ++ src/gui/models/nodeGraph/nodeWrapper.h | 15 +++++++++----- 14 files changed, 51 insertions(+), 35 deletions(-) diff --git a/src/gui/models/nodeGraph/exampleGraphModel.cpp b/src/gui/models/nodeGraph/exampleGraphModel.cpp index 173ed53b1e..590666d35e 100644 --- a/src/gui/models/nodeGraph/exampleGraphModel.cpp +++ b/src/gui/models/nodeGraph/exampleGraphModel.cpp @@ -113,7 +113,7 @@ template <> QVariant nodeData(const nodeValue &item, int role) template <> bool nodeSetData(nodeValue &item, const QVariant &value, int role) { return false; } // Delete the node -template <> bool nodeDelete(nodeValue &value, GraphNodeContext::type &context) { return true; } +bool nodeDelete(nodeValue &value, Proxy &context) { return true; } // Create node from variant nodeValue::nodeValue(QVariant var) diff --git a/src/gui/models/nodeGraph/exampleGraphModel.h b/src/gui/models/nodeGraph/exampleGraphModel.h index eb3e51262f..f9dacc5971 100644 --- a/src/gui/models/nodeGraph/exampleGraphModel.h +++ b/src/gui/models/nodeGraph/exampleGraphModel.h @@ -38,6 +38,7 @@ bool nodeConnect(nodeValue &source, int sourceIndex, nodeValue &destionation, in bool nodeConnectable(const nodeValue &source, int sourceIndex, const nodeValue &destination, int destinationIndex); bool nodeDisconnect(nodeValue &source, int sourceIndex, nodeValue &destination, int destinationIndex); QHash &nodeRoleNames(Proxy proxy, QHash &roles); +bool nodeDelete(nodeValue &value, Proxy &context); // The graph model for the example -typedef GraphModel ExampleGraphModel; +typedef GraphModel> ExampleGraphModel; diff --git a/src/gui/models/nodeGraph/generatorGraphModel.h b/src/gui/models/nodeGraph/generatorGraphModel.h index c2bd06b8ce..53a0d5ab91 100644 --- a/src/gui/models/nodeGraph/generatorGraphModel.h +++ b/src/gui/models/nodeGraph/generatorGraphModel.h @@ -11,7 +11,7 @@ #include "nodeWrapper.h" // A graph node model for looking at the generators on a configuration -class GeneratorGraphModel : public GraphModel +class GeneratorGraphModel : public GraphModel { Q_OBJECT // The Dissolve Model that contains the Dissolve object instance we diff --git a/src/gui/models/nodeGraph/graphModel.h b/src/gui/models/nodeGraph/graphModel.h index 83eead9d5c..3b6ae21566 100644 --- a/src/gui/models/nodeGraph/graphModel.h +++ b/src/gui/models/nodeGraph/graphModel.h @@ -37,15 +37,17 @@ **/ // This is the base class for any node graph type -template class GraphModel : public GraphModelBase +template + requires Graphable +class GraphModel : public GraphModelBase { public: GraphModel() : nodes_(this) {} protected: - typename GraphNodeContext::type context_; + Context context_; // The nodes in the model - std::vector> items_; + std::vector> items_; // Get index of name int indexByName(std::string name) override { @@ -55,7 +57,7 @@ template class GraphModel : public GraphModelBase public: // Access the acutal nodes in the model - std::vector> &items() { return items_; } + std::vector> &items() { return items_; } // Access the GraphNodeModel QAbstractListModel *nodes() override { return &nodes_; } @@ -120,5 +122,5 @@ template class GraphModel : public GraphModelBase protected: // The abstract data model for the nodes - GraphNodeModel nodes_; + GraphNodeModel nodes_; }; diff --git a/src/gui/models/nodeGraph/graphNodeModel.h b/src/gui/models/nodeGraph/graphNodeModel.h index 1c4710c250..341a5b0489 100644 --- a/src/gui/models/nodeGraph/graphNodeModel.h +++ b/src/gui/models/nodeGraph/graphNodeModel.h @@ -8,7 +8,9 @@ #include #include -template class GraphModel; +template + requires Graphable +class GraphModel; // A base to add a static terms or properties to GraphNodeModel class GraphNodeModelBase : public QAbstractListModel @@ -22,20 +24,22 @@ class GraphNodeModelBase : public QAbstractListModel // The model for accessing the node data (which is *held* in the // GraphModel class) -template class GraphNodeModel : public GraphNodeModelBase +template + requires Graphable +class GraphNodeModel : public GraphNodeModelBase { - friend GraphModel; + friend GraphModel; public: - GraphNodeModel(GraphModel *parent = nullptr) : parent_(parent) {} - GraphNodeModel(const GraphNodeModel &other) : parent_(other.parent_) {} + GraphNodeModel(GraphModel *parent = nullptr) : parent_(parent) {} + GraphNodeModel(const GraphNodeModel &other) : parent_(other.parent_) {} - GraphNodeModel &operator=(const GraphNodeModel &other) + GraphNodeModel &operator=(const GraphNodeModel &other) { parent_ = other.parent_; return *this; } - bool operator!=(const GraphNodeModel &other) { return &parent_ != &other.parent_; } + bool operator!=(const GraphNodeModel &other) { return &parent_ != &other.parent_; } // Number of nodes (required by QAbstractListModel) int rowCount(const QModelIndex &parent = QModelIndex()) const override { return parent_->items().size(); } @@ -102,5 +106,5 @@ template class GraphNodeModel : public GraphNodeModelBase private: // The GraphModel that this is part of (which will hold the actual vector of nodes - GraphModel *parent_; + GraphModel *parent_; }; diff --git a/src/gui/models/nodeGraph/instances/all.h b/src/gui/models/nodeGraph/instances/all.h index 37dc536e06..f2965ddc3e 100644 --- a/src/gui/models/nodeGraph/instances/all.h +++ b/src/gui/models/nodeGraph/instances/all.h @@ -35,3 +35,4 @@ bool nodeConnect(GeneratorGraphNode &source, int sourceIndex, GeneratorGraphNode bool nodeConnectable(const GeneratorGraphNode &source, int sourceIndex, const GeneratorGraphNode &destination, int destinationIndex); bool nodeDisconnect(GeneratorGraphNode &source, int sourceIndex, GeneratorGraphNode &destination, int destinationIndex); QHash &nodeRoleNames(Proxy proxy, QHash &roles); +bool nodeDelete(GeneratorGraphNode &item, CoreData *coreData); diff --git a/src/gui/models/nodeGraph/instances/configuration.cpp b/src/gui/models/nodeGraph/instances/configuration.cpp index 7eac870410..157b5cca7d 100644 --- a/src/gui/models/nodeGraph/instances/configuration.cpp +++ b/src/gui/models/nodeGraph/instances/configuration.cpp @@ -4,16 +4,16 @@ #include "gui/models/nodeGraph/nodeWrapper.h" // The name of the type (for delegate dispatch) -std::string nodeTypeName(Configuration *const &value) { return "Configuration"; } +std::string nodeTypeName(const Configuration *value) { return "Configuration"; } // The path to the icon for the node -std::string nodeTypeIcon(Configuration *const &value) +std::string nodeTypeIcon(const Configuration *value) { return "qrc:/Dissolve/icons/configuration.svg"; } // The title of the node -std::string nodeName(Configuration *const &value) +std::string nodeName(const Configuration *value) { if (!value) @@ -56,7 +56,7 @@ template <> bool nodeSetData(Configuration *&item, const QVariant &value, int ro } // Delete the node -template <> bool nodeDelete(Configuration *&item, typename GraphNodeContext::type &coreData) +bool nodeDelete(Configuration *item, CoreData *coreData) { coreData->removeConfiguration(item); return true; diff --git a/src/gui/models/nodeGraph/instances/configuration.h b/src/gui/models/nodeGraph/instances/configuration.h index 1e1cf482e6..80a0bf05ad 100644 --- a/src/gui/models/nodeGraph/instances/configuration.h +++ b/src/gui/models/nodeGraph/instances/configuration.h @@ -13,10 +13,11 @@ template <> struct GraphNodeContext using type = CoreData *; }; -std::string nodeName(Configuration *const &value); -std::string nodeTypeName(Configuration *const &value); -std::string nodeTypeIcon(Configuration *const &value); +std::string nodeName(const Configuration *value); +std::string nodeTypeName(const Configuration *value); +std::string nodeTypeIcon(const Configuration *value); -bool nodeConnect(Configuration *&source, int sourceIndex, Configuration *&destionation, int destinationIndex); -bool nodeConnectable(const Configuration *&source, int sourceIndex, const Configuration *&destination, int destinationIndex); -bool nodeDisconnect(Configuration *&source, int sourceIndex, Configuration *&destination, int destinationIndex); +bool nodeConnect(Configuration *source, int sourceIndex, Configuration *destination, int destinationIndex); +bool nodeConnectable(const Configuration *source, int sourceIndex, const Configuration *destination, int destinationIndex); +bool nodeDisconnect(Configuration *source, int sourceIndex, Configuration *destination, int destinationIndex); +bool nodeDelete(Configuration *item, CoreData *coreData); diff --git a/src/gui/models/nodeGraph/instances/generator.cpp b/src/gui/models/nodeGraph/instances/generator.cpp index 3b14f9e3da..fcb237a159 100644 --- a/src/gui/models/nodeGraph/instances/generator.cpp +++ b/src/gui/models/nodeGraph/instances/generator.cpp @@ -33,4 +33,4 @@ template <> QVariant nodeData(Generator *const &value, int role) template <> bool nodeSetData(Generator *&item, const QVariant &value, int role) { return false; } // Delete the node -template <> bool nodeDelete(Generator *&item, typename GraphNodeContext::type &coreData) { return false; } +bool nodeDelete(Generator *item, CoreData *coreData) { return false; } diff --git a/src/gui/models/nodeGraph/instances/generator.h b/src/gui/models/nodeGraph/instances/generator.h index e80d9a6822..3a43b8172d 100644 --- a/src/gui/models/nodeGraph/instances/generator.h +++ b/src/gui/models/nodeGraph/instances/generator.h @@ -16,3 +16,4 @@ template <> struct GraphNodeContext std::string nodeName(Generator *const &value); std::string nodeTypeName(Generator *const &value); std::string nodeTypeIcon(Generator *const &value); +bool nodeDelete(Generator *item, CoreData *coreData); diff --git a/src/gui/models/nodeGraph/instances/generatorGraphNode.cpp b/src/gui/models/nodeGraph/instances/generatorGraphNode.cpp index 135cb4c9c2..e90ea222b4 100644 --- a/src/gui/models/nodeGraph/instances/generatorGraphNode.cpp +++ b/src/gui/models/nodeGraph/instances/generatorGraphNode.cpp @@ -89,8 +89,7 @@ QHash &nodeRoleNames(Proxy proxy, QHash -bool nodeDelete(GeneratorGraphNode &item, typename GraphNodeContext::type &coreData) +bool nodeDelete(GeneratorGraphNode &item, CoreData *coreData) { return std::visit([&](auto *arg) -> bool { return nodeDelete(arg, coreData); }, item.value); } diff --git a/src/gui/models/nodeGraph/instances/generatorNode.cpp b/src/gui/models/nodeGraph/instances/generatorNode.cpp index b3c28dee23..61a02d2fbf 100644 --- a/src/gui/models/nodeGraph/instances/generatorNode.cpp +++ b/src/gui/models/nodeGraph/instances/generatorNode.cpp @@ -53,7 +53,7 @@ template <> QVariant nodeData(GeneratorNode *const &value, int role) template <> bool nodeSetData(GeneratorNode *&item, const QVariant &value, int role) { return false; } // Delete the node -template <> bool nodeDelete(GeneratorNode *&item, typename GraphNodeContext::type &coreData) +bool nodeDelete(GeneratorNode *item, CoreData *coreData) { for (auto &conf : coreData->configurations()) { diff --git a/src/gui/models/nodeGraph/instances/generatorNode.h b/src/gui/models/nodeGraph/instances/generatorNode.h index 8f9f6e8a9a..b445f1d5a1 100644 --- a/src/gui/models/nodeGraph/instances/generatorNode.h +++ b/src/gui/models/nodeGraph/instances/generatorNode.h @@ -19,3 +19,5 @@ template <> struct GraphNodeContext std::string nodeName(GeneratorNode *const &value); std::string nodeTypeName(GeneratorNode *const &value); std::string nodeTypeIcon(GeneratorNode *const &value); + +bool nodeDelete(GeneratorNode *item, CoreData *coreData); diff --git a/src/gui/models/nodeGraph/nodeWrapper.h b/src/gui/models/nodeGraph/nodeWrapper.h index a4ca11cc6b..591d251e1e 100644 --- a/src/gui/models/nodeGraph/nodeWrapper.h +++ b/src/gui/models/nodeGraph/nodeWrapper.h @@ -28,11 +28,14 @@ **/ // Delete the node -template bool nodeDelete(T &value, typename GraphNodeContext::type &context); +// template bool nodeDelete(T &value, typename GraphNodeContext::type &context); -template -concept Graphable = requires(T a, const std::string name, T b, int sourceIndex, int destinationIndex, Proxy proxy, - QHash &baseHash) { +template +concept Graphable = requires(T a, Context context, const std::string name, T b, int sourceIndex, int destinationIndex, + Proxy proxy, QHash &baseHash) { + { + nodeDelete(a, context) + } -> std::same_as; { nodeRoleNames(proxy, baseHash) } -> std::same_as &>; @@ -63,7 +66,9 @@ concept Graphable = requires(T a, const std::string name, T b, int sourceIndex, }; // A wrapper with supplemental information for a node -template class NodeWrapper +template + requires Graphable +class NodeWrapper { public: NodeWrapper(QVariant value) : value_(value) {} From a61ef7df56f1e590538ab9f2fa135bf45858b26e Mon Sep 17 00:00:00 2001 From: Adam Washington Date: Thu, 16 Jan 2025 16:01:53 +0000 Subject: [PATCH 08/15] Move nodeData and nodeSetData into concept --- src/gui/models/nodeGraph/exampleGraphModel.cpp | 4 ++-- src/gui/models/nodeGraph/exampleGraphModel.h | 2 ++ src/gui/models/nodeGraph/instances/all.h | 2 ++ .../models/nodeGraph/instances/configuration.cpp | 4 ++-- src/gui/models/nodeGraph/instances/configuration.h | 2 ++ src/gui/models/nodeGraph/instances/generator.cpp | 4 ++-- src/gui/models/nodeGraph/instances/generator.h | 2 ++ .../nodeGraph/instances/generatorGraphNode.cpp | 4 ++-- .../models/nodeGraph/instances/generatorNode.cpp | 4 ++-- src/gui/models/nodeGraph/instances/generatorNode.h | 4 +++- src/gui/models/nodeGraph/nodeWrapper.h | 14 +++++++------- 11 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/gui/models/nodeGraph/exampleGraphModel.cpp b/src/gui/models/nodeGraph/exampleGraphModel.cpp index 590666d35e..df522a5dcc 100644 --- a/src/gui/models/nodeGraph/exampleGraphModel.cpp +++ b/src/gui/models/nodeGraph/exampleGraphModel.cpp @@ -98,7 +98,7 @@ QHash &nodeRoleNames(Proxy proxy, QHash QVariant nodeData(const nodeValue &item, int role) +QVariant nodeData(const nodeValue &item, int role) { switch (role) { @@ -110,7 +110,7 @@ template <> QVariant nodeData(const nodeValue &item, int role) } // Set a specific piece of information from a node by index -template <> bool nodeSetData(nodeValue &item, const QVariant &value, int role) { return false; } +bool nodeSetData(nodeValue &item, const QVariant &value, int role) { return false; } // Delete the node bool nodeDelete(nodeValue &value, Proxy &context) { return true; } diff --git a/src/gui/models/nodeGraph/exampleGraphModel.h b/src/gui/models/nodeGraph/exampleGraphModel.h index f9dacc5971..1cf1b3be41 100644 --- a/src/gui/models/nodeGraph/exampleGraphModel.h +++ b/src/gui/models/nodeGraph/exampleGraphModel.h @@ -39,6 +39,8 @@ bool nodeConnectable(const nodeValue &source, int sourceIndex, const nodeValue & bool nodeDisconnect(nodeValue &source, int sourceIndex, nodeValue &destination, int destinationIndex); QHash &nodeRoleNames(Proxy proxy, QHash &roles); bool nodeDelete(nodeValue &value, Proxy &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> ExampleGraphModel; diff --git a/src/gui/models/nodeGraph/instances/all.h b/src/gui/models/nodeGraph/instances/all.h index f2965ddc3e..773e5dcbbd 100644 --- a/src/gui/models/nodeGraph/instances/all.h +++ b/src/gui/models/nodeGraph/instances/all.h @@ -36,3 +36,5 @@ bool nodeConnectable(const GeneratorGraphNode &source, int sourceIndex, const Ge bool nodeDisconnect(GeneratorGraphNode &source, int sourceIndex, GeneratorGraphNode &destination, int destinationIndex); QHash &nodeRoleNames(Proxy proxy, QHash &roles); bool nodeDelete(GeneratorGraphNode &item, CoreData *coreData); +QVariant nodeData(const GeneratorGraphNode &item, int role); +bool nodeSetData(GeneratorGraphNode &item, const QVariant &value, int role); diff --git a/src/gui/models/nodeGraph/instances/configuration.cpp b/src/gui/models/nodeGraph/instances/configuration.cpp index 157b5cca7d..e55d1ba47a 100644 --- a/src/gui/models/nodeGraph/instances/configuration.cpp +++ b/src/gui/models/nodeGraph/instances/configuration.cpp @@ -23,7 +23,7 @@ std::string nodeName(const Configuration *value) } // Get a specific piece of information from a node by index -template <> QVariant nodeData(Configuration *const &value, int role) +QVariant nodeData(const Configuration *value, int role) { using names = GeneratorGraphModel::PropertyIndex; if (!value) @@ -42,7 +42,7 @@ template <> QVariant nodeData(Configuration *const &value, int role) } // Set a specific piece of information from a node by index -template <> bool nodeSetData(Configuration *&item, const QVariant &value, int role) +bool nodeSetData(Configuration *item, const QVariant &value, int role) { using names = GeneratorGraphModel::PropertyIndex; switch (role) diff --git a/src/gui/models/nodeGraph/instances/configuration.h b/src/gui/models/nodeGraph/instances/configuration.h index 80a0bf05ad..0bc7bd4cd8 100644 --- a/src/gui/models/nodeGraph/instances/configuration.h +++ b/src/gui/models/nodeGraph/instances/configuration.h @@ -21,3 +21,5 @@ bool nodeConnect(Configuration *source, int sourceIndex, Configuration *destinat bool nodeConnectable(const Configuration *source, int sourceIndex, const Configuration *destination, int destinationIndex); bool nodeDisconnect(Configuration *source, int sourceIndex, Configuration *destination, int destinationIndex); bool nodeDelete(Configuration *item, CoreData *coreData); +QVariant nodeData(const Configuration *value, int role); +bool nodeSetData(Configuration *item, const QVariant &value, int role); diff --git a/src/gui/models/nodeGraph/instances/generator.cpp b/src/gui/models/nodeGraph/instances/generator.cpp index fcb237a159..268fb998af 100644 --- a/src/gui/models/nodeGraph/instances/generator.cpp +++ b/src/gui/models/nodeGraph/instances/generator.cpp @@ -13,7 +13,7 @@ std::string nodeTypeIcon(Generator *const &value) { return "qrc:/Dissolve/icons/ std::string nodeName(Generator *const &value) { return "Generator"; } // Get a specific piece of information from a node by index -template <> QVariant nodeData(Generator *const &value, int role) +QVariant nodeData(const Generator *value, int role) { using names = GeneratorGraphModel::PropertyIndex; if (!value) @@ -30,7 +30,7 @@ template <> QVariant nodeData(Generator *const &value, int role) } // Set a specific piece of information from a node by index -template <> bool nodeSetData(Generator *&item, const QVariant &value, int role) { return false; } +bool nodeSetData(Generator *item, const QVariant &value, int role) { return false; } // Delete the node bool nodeDelete(Generator *item, CoreData *coreData) { return false; } diff --git a/src/gui/models/nodeGraph/instances/generator.h b/src/gui/models/nodeGraph/instances/generator.h index 3a43b8172d..050445657f 100644 --- a/src/gui/models/nodeGraph/instances/generator.h +++ b/src/gui/models/nodeGraph/instances/generator.h @@ -17,3 +17,5 @@ std::string nodeName(Generator *const &value); std::string nodeTypeName(Generator *const &value); std::string nodeTypeIcon(Generator *const &value); bool nodeDelete(Generator *item, CoreData *coreData); +QVariant nodeData(const Generator *value, int role); +bool nodeSetData(Generator *item, const QVariant &value, int role); diff --git a/src/gui/models/nodeGraph/instances/generatorGraphNode.cpp b/src/gui/models/nodeGraph/instances/generatorGraphNode.cpp index e90ea222b4..4c8232d1c4 100644 --- a/src/gui/models/nodeGraph/instances/generatorGraphNode.cpp +++ b/src/gui/models/nodeGraph/instances/generatorGraphNode.cpp @@ -63,14 +63,14 @@ std::string nodeName(const GeneratorGraphNode &value) void setNodeName(GeneratorGraphNode &value, const std::string name) {} // Set a specific piece of information from a node by index -template <> bool nodeSetData(GeneratorGraphNode &item, const QVariant &value, int role) +bool nodeSetData(GeneratorGraphNode &item, const QVariant &value, int role) { using names = GeneratorGraphModel::PropertyIndex; return std::visit([&value, role](auto *arg) { return nodeSetData(arg, value, role); }, item.value); } // Get a specific piece of information from a node by index -template <> QVariant nodeData(const GeneratorGraphNode &item, int role) +QVariant nodeData(const GeneratorGraphNode &item, int role) { using names = GeneratorGraphModel::PropertyIndex; return std::visit([role](auto *arg) -> QVariant { return nodeData(arg, role); }, item.value); diff --git a/src/gui/models/nodeGraph/instances/generatorNode.cpp b/src/gui/models/nodeGraph/instances/generatorNode.cpp index 61a02d2fbf..6d27b26c74 100644 --- a/src/gui/models/nodeGraph/instances/generatorNode.cpp +++ b/src/gui/models/nodeGraph/instances/generatorNode.cpp @@ -23,7 +23,7 @@ std::string nodeName(GeneratorNode *const &value) } // Get a specific piece of information from a node by index -template <> QVariant nodeData(GeneratorNode *const &value, int role) +QVariant nodeData(const GeneratorNode *value, int role) { using names = GeneratorGraphModel::PropertyIndex; if (!value) @@ -50,7 +50,7 @@ template <> QVariant nodeData(GeneratorNode *const &value, int role) } // Set a specific piece of information from a node by index -template <> bool nodeSetData(GeneratorNode *&item, const QVariant &value, int role) { return false; } +bool nodeSetData(GeneratorNode *item, const QVariant &value, int role) { return false; } // Delete the node bool nodeDelete(GeneratorNode *item, CoreData *coreData) diff --git a/src/gui/models/nodeGraph/instances/generatorNode.h b/src/gui/models/nodeGraph/instances/generatorNode.h index b445f1d5a1..be2d4a1f23 100644 --- a/src/gui/models/nodeGraph/instances/generatorNode.h +++ b/src/gui/models/nodeGraph/instances/generatorNode.h @@ -3,6 +3,7 @@ #pragma once +#include #include "gui/models/nodeGraph/graphNodeContext.h" #include "classes/coreData.h" @@ -19,5 +20,6 @@ template <> struct GraphNodeContext std::string nodeName(GeneratorNode *const &value); std::string nodeTypeName(GeneratorNode *const &value); std::string nodeTypeIcon(GeneratorNode *const &value); - bool nodeDelete(GeneratorNode *item, CoreData *coreData); +QVariant nodeData(const GeneratorNode *value, int role); +bool nodeSetData(GeneratorNode *item, const QVariant &value, int role); diff --git a/src/gui/models/nodeGraph/nodeWrapper.h b/src/gui/models/nodeGraph/nodeWrapper.h index 591d251e1e..b6ac176386 100644 --- a/src/gui/models/nodeGraph/nodeWrapper.h +++ b/src/gui/models/nodeGraph/nodeWrapper.h @@ -32,7 +32,7 @@ template concept Graphable = requires(T a, Context context, const std::string name, T b, int sourceIndex, int destinationIndex, - Proxy proxy, QHash &baseHash) { + Proxy proxy, QHash &baseHash, int role, QVariant value) { { nodeDelete(a, context) } -> std::same_as; @@ -63,6 +63,12 @@ concept Graphable = requires(T a, Context context, const std::string name, T b, { nodeDisconnect(a, sourceIndex, b, destinationIndex) } -> std::same_as; + { + nodeData(a, role) + } -> std::convertible_to; + { + nodeSetData(a, value, role) + } -> std::convertible_to; }; // A wrapper with supplemental information for a node @@ -86,9 +92,3 @@ class NodeWrapper // The actual value of the node T value_; }; - -// Get a specific piece of information from a node by index -template QVariant nodeData(const T &, int role); - -// Set a specific piece of information from a node by index -template bool nodeSetData(T &, const QVariant &value, int role); From 1e80790bc88e46139cf6db22e52f1f8bafcfc1bf Mon Sep 17 00:00:00 2001 From: Adam Washington Date: Thu, 16 Jan 2025 16:07:35 +0000 Subject: [PATCH 09/15] Get rid of GraphNodeContext The context is now bound to the concept --- src/gui/models/nodeGraph/graphNodeContext.h | 7 ------- src/gui/models/nodeGraph/instances/all.h | 6 ------ src/gui/models/nodeGraph/instances/configuration.h | 7 ------- src/gui/models/nodeGraph/instances/generator.cpp | 2 +- src/gui/models/nodeGraph/instances/generator.h | 9 +-------- src/gui/models/nodeGraph/instances/generatorNode.h | 8 -------- 6 files changed, 2 insertions(+), 37 deletions(-) diff --git a/src/gui/models/nodeGraph/graphNodeContext.h b/src/gui/models/nodeGraph/graphNodeContext.h index 12cebda58a..90eea508ba 100644 --- a/src/gui/models/nodeGraph/graphNodeContext.h +++ b/src/gui/models/nodeGraph/graphNodeContext.h @@ -3,13 +3,6 @@ #pragma once -// A template that we can specialise to associate a a context type -// with a type. -template struct GraphNodeContext -{ - using type = GraphNodeContext; -}; - template struct Proxy { }; diff --git a/src/gui/models/nodeGraph/instances/all.h b/src/gui/models/nodeGraph/instances/all.h index 773e5dcbbd..ff8ae0027f 100644 --- a/src/gui/models/nodeGraph/instances/all.h +++ b/src/gui/models/nodeGraph/instances/all.h @@ -20,12 +20,6 @@ class GeneratorGraphNode GeneratorGraphInnerType value; }; -// All of these types may require access to CoreData -template <> struct GraphNodeContext -{ - using type = CoreData *; -}; - std::string nodeName(const GeneratorGraphNode &value); std::string nodeTypeName(const GeneratorGraphNode &value); std::string nodeTypeIcon(const GeneratorGraphNode &value); diff --git a/src/gui/models/nodeGraph/instances/configuration.h b/src/gui/models/nodeGraph/instances/configuration.h index 0bc7bd4cd8..8c05a8a4ed 100644 --- a/src/gui/models/nodeGraph/instances/configuration.h +++ b/src/gui/models/nodeGraph/instances/configuration.h @@ -6,13 +6,6 @@ #include "classes/configuration.h" #include "gui/models/nodeGraph/graphNodeContext.h" -// Configurations need access to the CoreData to access all of their -// children. -template <> struct GraphNodeContext -{ - using type = CoreData *; -}; - std::string nodeName(const Configuration *value); std::string nodeTypeName(const Configuration *value); std::string nodeTypeIcon(const Configuration *value); diff --git a/src/gui/models/nodeGraph/instances/generator.cpp b/src/gui/models/nodeGraph/instances/generator.cpp index 268fb998af..cb84f6e436 100644 --- a/src/gui/models/nodeGraph/instances/generator.cpp +++ b/src/gui/models/nodeGraph/instances/generator.cpp @@ -13,7 +13,7 @@ std::string nodeTypeIcon(Generator *const &value) { return "qrc:/Dissolve/icons/ std::string nodeName(Generator *const &value) { return "Generator"; } // Get a specific piece of information from a node by index -QVariant nodeData(const Generator *value, int role) +QVariant nodeData(Generator *value, int role) { using names = GeneratorGraphModel::PropertyIndex; if (!value) diff --git a/src/gui/models/nodeGraph/instances/generator.h b/src/gui/models/nodeGraph/instances/generator.h index 050445657f..7ded6a882b 100644 --- a/src/gui/models/nodeGraph/instances/generator.h +++ b/src/gui/models/nodeGraph/instances/generator.h @@ -6,16 +6,9 @@ #include "generator/generator.h" #include "gui/models/nodeGraph/graphNodeContext.h" -// Generators need access to the CoreData to access all of their -// children. -template <> struct GraphNodeContext -{ - using type = CoreData *; -}; - std::string nodeName(Generator *const &value); std::string nodeTypeName(Generator *const &value); std::string nodeTypeIcon(Generator *const &value); bool nodeDelete(Generator *item, CoreData *coreData); -QVariant nodeData(const Generator *value, int role); +QVariant nodeData(Generator *value, int role); bool nodeSetData(Generator *item, const QVariant &value, int role); diff --git a/src/gui/models/nodeGraph/instances/generatorNode.h b/src/gui/models/nodeGraph/instances/generatorNode.h index be2d4a1f23..947438d576 100644 --- a/src/gui/models/nodeGraph/instances/generatorNode.h +++ b/src/gui/models/nodeGraph/instances/generatorNode.h @@ -9,14 +9,6 @@ class GeneratorNode; - -// GeneratorNodes need access to the CoreData to access all of their -// children. -template <> struct GraphNodeContext -{ - using type = CoreData *; -}; - std::string nodeName(GeneratorNode *const &value); std::string nodeTypeName(GeneratorNode *const &value); std::string nodeTypeIcon(GeneratorNode *const &value); From 3187dc1ed3dce1e6b724728d97fb383ef0248c1c Mon Sep 17 00:00:00 2001 From: Adam Washington Date: Thu, 16 Jan 2025 16:26:57 +0000 Subject: [PATCH 10/15] More focus on phantom types --- .../models/nodeGraph/exampleGraphModel.cpp | 4 +- src/gui/models/nodeGraph/exampleGraphModel.h | 6 +-- src/gui/models/nodeGraph/graphNodeContext.h | 8 --- src/gui/models/nodeGraph/graphNodeModel.h | 2 +- src/gui/models/nodeGraph/instances/all.h | 2 +- .../nodeGraph/instances/configuration.h | 2 +- .../models/nodeGraph/instances/generator.h | 2 +- .../instances/generatorGraphNode.cpp | 2 +- .../nodeGraph/instances/generatorNode.h | 2 +- src/gui/models/nodeGraph/nodeWrapper.h | 2 +- src/gui/models/nodeGraph/phantom.h | 51 +++++++++++++++++++ 11 files changed, 63 insertions(+), 20 deletions(-) delete mode 100644 src/gui/models/nodeGraph/graphNodeContext.h create mode 100644 src/gui/models/nodeGraph/phantom.h diff --git a/src/gui/models/nodeGraph/exampleGraphModel.cpp b/src/gui/models/nodeGraph/exampleGraphModel.cpp index df522a5dcc..aa7a8cdc3d 100644 --- a/src/gui/models/nodeGraph/exampleGraphModel.cpp +++ b/src/gui/models/nodeGraph/exampleGraphModel.cpp @@ -90,7 +90,7 @@ bool nodeDisconnect(nodeValue &source, int sourceIndex, nodeValue &destination, } // Append the roles for the type onto the QHash -QHash &nodeRoleNames(Proxy proxy, QHash &roles) +QHash &nodeRoleNames(Phantom proxy, QHash &roles) { const auto base = Qt::UserRole + GraphNodeModelBase::ownedRoles; roles[base] = "value"; @@ -113,7 +113,7 @@ QVariant nodeData(const nodeValue &item, int role) bool nodeSetData(nodeValue &item, const QVariant &value, int role) { return false; } // Delete the node -bool nodeDelete(nodeValue &value, Proxy &context) { return true; } +bool nodeDelete(nodeValue &value, Phantom &context) { return true; } // Create node from variant nodeValue::nodeValue(QVariant var) diff --git a/src/gui/models/nodeGraph/exampleGraphModel.h b/src/gui/models/nodeGraph/exampleGraphModel.h index 1cf1b3be41..f8421e3937 100644 --- a/src/gui/models/nodeGraph/exampleGraphModel.h +++ b/src/gui/models/nodeGraph/exampleGraphModel.h @@ -37,10 +37,10 @@ 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 &nodeRoleNames(Proxy proxy, QHash &roles); -bool nodeDelete(nodeValue &value, Proxy &context); +QHash &nodeRoleNames(Phantom proxy, QHash &roles); +bool nodeDelete(nodeValue &value, Phantom &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> ExampleGraphModel; +typedef GraphModel> ExampleGraphModel; diff --git a/src/gui/models/nodeGraph/graphNodeContext.h b/src/gui/models/nodeGraph/graphNodeContext.h deleted file mode 100644 index 90eea508ba..0000000000 --- a/src/gui/models/nodeGraph/graphNodeContext.h +++ /dev/null @@ -1,8 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-or-later -// Copyright (c) 2024 Team Dissolve and contributors - -#pragma once - -template struct Proxy -{ -}; diff --git a/src/gui/models/nodeGraph/graphNodeModel.h b/src/gui/models/nodeGraph/graphNodeModel.h index 341a5b0489..cc8ef55ec9 100644 --- a/src/gui/models/nodeGraph/graphNodeModel.h +++ b/src/gui/models/nodeGraph/graphNodeModel.h @@ -47,7 +47,7 @@ class GraphNodeModel : public GraphNodeModelBase // Labels for QML roles (required by QAbstractListModel) QHash roleNames() const override { - Proxy proxy; + Phantom proxy; QHash roles; roles[Qt::UserRole] = "name"; roles[Qt::UserRole + 1] = "posX"; diff --git a/src/gui/models/nodeGraph/instances/all.h b/src/gui/models/nodeGraph/instances/all.h index ff8ae0027f..a0abf0379d 100644 --- a/src/gui/models/nodeGraph/instances/all.h +++ b/src/gui/models/nodeGraph/instances/all.h @@ -28,7 +28,7 @@ QVariant nodeGetValue(const GeneratorGraphNode &value); bool nodeConnect(GeneratorGraphNode &source, int sourceIndex, GeneratorGraphNode &destionation, int destinationIndex); bool nodeConnectable(const GeneratorGraphNode &source, int sourceIndex, const GeneratorGraphNode &destination, int destinationIndex); bool nodeDisconnect(GeneratorGraphNode &source, int sourceIndex, GeneratorGraphNode &destination, int destinationIndex); -QHash &nodeRoleNames(Proxy proxy, QHash &roles); +QHash &nodeRoleNames(Phantom proxy, QHash &roles); bool nodeDelete(GeneratorGraphNode &item, CoreData *coreData); QVariant nodeData(const GeneratorGraphNode &item, int role); bool nodeSetData(GeneratorGraphNode &item, const QVariant &value, int role); diff --git a/src/gui/models/nodeGraph/instances/configuration.h b/src/gui/models/nodeGraph/instances/configuration.h index 8c05a8a4ed..d0ab6ac390 100644 --- a/src/gui/models/nodeGraph/instances/configuration.h +++ b/src/gui/models/nodeGraph/instances/configuration.h @@ -4,7 +4,7 @@ #pragma once #include "classes/configuration.h" -#include "gui/models/nodeGraph/graphNodeContext.h" +#include "gui/models/nodeGraph/phantom.h" std::string nodeName(const Configuration *value); std::string nodeTypeName(const Configuration *value); diff --git a/src/gui/models/nodeGraph/instances/generator.h b/src/gui/models/nodeGraph/instances/generator.h index 7ded6a882b..6a4f6f8593 100644 --- a/src/gui/models/nodeGraph/instances/generator.h +++ b/src/gui/models/nodeGraph/instances/generator.h @@ -4,7 +4,7 @@ #pragma once #include "generator/generator.h" -#include "gui/models/nodeGraph/graphNodeContext.h" +#include "gui/models/nodeGraph/phantom.h" std::string nodeName(Generator *const &value); std::string nodeTypeName(Generator *const &value); diff --git a/src/gui/models/nodeGraph/instances/generatorGraphNode.cpp b/src/gui/models/nodeGraph/instances/generatorGraphNode.cpp index 4c8232d1c4..04f5cc72aa 100644 --- a/src/gui/models/nodeGraph/instances/generatorGraphNode.cpp +++ b/src/gui/models/nodeGraph/instances/generatorGraphNode.cpp @@ -77,7 +77,7 @@ QVariant nodeData(const GeneratorGraphNode &item, int role) } // Append the roles for the type onto the QHash -QHash &nodeRoleNames(Proxy proxy, QHash &roles) +QHash &nodeRoleNames(Phantom proxy, QHash &roles) { auto base = Qt::UserRole + GraphNodeModelBase::ownedRoles; using names = GeneratorGraphModel::PropertyIndex; diff --git a/src/gui/models/nodeGraph/instances/generatorNode.h b/src/gui/models/nodeGraph/instances/generatorNode.h index 947438d576..8672a7fe72 100644 --- a/src/gui/models/nodeGraph/instances/generatorNode.h +++ b/src/gui/models/nodeGraph/instances/generatorNode.h @@ -4,7 +4,7 @@ #pragma once #include -#include "gui/models/nodeGraph/graphNodeContext.h" +#include "gui/models/nodeGraph/phantom.h" #include "classes/coreData.h" class GeneratorNode; diff --git a/src/gui/models/nodeGraph/nodeWrapper.h b/src/gui/models/nodeGraph/nodeWrapper.h index b6ac176386..807efc59c7 100644 --- a/src/gui/models/nodeGraph/nodeWrapper.h +++ b/src/gui/models/nodeGraph/nodeWrapper.h @@ -32,7 +32,7 @@ template concept Graphable = requires(T a, Context context, const std::string name, T b, int sourceIndex, int destinationIndex, - Proxy proxy, QHash &baseHash, int role, QVariant value) { + Phantom proxy, QHash &baseHash, int role, QVariant value) { { nodeDelete(a, context) } -> std::same_as; diff --git a/src/gui/models/nodeGraph/phantom.h b/src/gui/models/nodeGraph/phantom.h new file mode 100644 index 0000000000..22f41972a3 --- /dev/null +++ b/src/gui/models/nodeGraph/phantom.h @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// Copyright (c) 2024 Team Dissolve and contributors + +#pragma once + +/* + + The Phantom type is a compile time marker of zero size that allows + the passing of type info to a function. For example, you could have + the `getBits` function with overloads. + + >>> + int getBits(Phantom phantom) { return 8; } + int getBits(Phantom phantom) { return 64; } + <<< + + Now, there's two other ways that this could have been written + + >>> + int getBits(char phantom) { return 8; } + int getBits(double phantom) { return 64; } + <<< + + While this works well for our trivial example, imagine that we had a + type with an expensive constructor. If the information is purely + related to the type, there's no need to instantiate a copy of it to + determine what we already know. + + The other solution would be to use a function template + + >>> + template int getBits(); + template <> int getBits { return 8; } + template <> int getBits { return 64; } + <<< + + This works up until the moment that we have a type for which + `getBits` is undefined. We would not implement the template + overload for that type, but attempts to call that function would + return an odd linker error. After all, we *have* provided a + function header that declares that `getBits` is defined for *all* + types T. + + Using Phantom types, we can still get the overloads at compile time, + but we're only producing headers for explicitly the types that we + want to support. + + */ +template struct Phantom +{ +}; From b99c70432394bce28716af86e7dd97d6a78662d2 Mon Sep 17 00:00:00 2001 From: Adam Washington Date: Thu, 16 Jan 2025 17:01:59 +0000 Subject: [PATCH 11/15] Fixups --- src/gui/models/nodeGraph/graphNodeModel.h | 4 ++-- src/gui/models/nodeGraph/nodeWrapper.h | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/gui/models/nodeGraph/graphNodeModel.h b/src/gui/models/nodeGraph/graphNodeModel.h index cc8ef55ec9..44ae62ac18 100644 --- a/src/gui/models/nodeGraph/graphNodeModel.h +++ b/src/gui/models/nodeGraph/graphNodeModel.h @@ -47,14 +47,14 @@ class GraphNodeModel : public GraphNodeModelBase // Labels for QML roles (required by QAbstractListModel) QHash roleNames() const override { - Phantom proxy; + Phantom phantom; QHash roles; roles[Qt::UserRole] = "name"; roles[Qt::UserRole + 1] = "posX"; roles[Qt::UserRole + 2] = "posY"; roles[Qt::UserRole + 3] = "type"; roles[Qt::UserRole + 4] = "icon"; - return nodeRoleNames(proxy, roles); + return nodeRoleNames(phantom, roles); } // Data accessor (required by QAbstractListModel) diff --git a/src/gui/models/nodeGraph/nodeWrapper.h b/src/gui/models/nodeGraph/nodeWrapper.h index 807efc59c7..8be36e6413 100644 --- a/src/gui/models/nodeGraph/nodeWrapper.h +++ b/src/gui/models/nodeGraph/nodeWrapper.h @@ -9,10 +9,12 @@ #include /** - This file contains a series of templates that need to be overloaded - to allow a type to be displayed as a node. This is essentially a - C++ Concept, but without all the compiler checks and niceties that - we will get with C++20. + This file contains a C++20 concept which defines whether a type can + be shown as a graph. Any type T which contains implementations for + all of the functions listed below can be displayed in a graph. A + second template parameter Context was also necessary to implement + deletion as most nodes would need to know *where* they were being + deleted from. A concept was chosen over class methods because: @@ -25,10 +27,13 @@ part of the class even in the command line version. As some of the methods require Qt types (e.g. QHash, QVariant), then Qt would suddenly become a dependency of the command line code. - **/ -// Delete the node -// template bool nodeDelete(T &value, typename GraphNodeContext::type &context); + This code is a direct conversion of the template code that came + before. Truth be told, the connection functions should likely be + split out into a separate Concept (allowing us to check for + connection correctness as compile time), but that is outside of the + scope of this PR. + **/ template concept Graphable = requires(T a, Context context, const std::string name, T b, int sourceIndex, int destinationIndex, From 01ceb86d4e0ef9df251591fa23a1c237d2b220e0 Mon Sep 17 00:00:00 2001 From: Adam Washington Date: Thu, 16 Jan 2025 17:11:03 +0000 Subject: [PATCH 12/15] Formatting fix --- src/gui/models/nodeGraph/generatorGraphModel.h | 2 +- src/gui/models/nodeGraph/instances/all.h | 5 +++-- src/gui/models/nodeGraph/instances/configuration.cpp | 5 +---- src/gui/models/nodeGraph/instances/generatorNode.h | 4 ++-- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/gui/models/nodeGraph/generatorGraphModel.h b/src/gui/models/nodeGraph/generatorGraphModel.h index 53a0d5ab91..a727ffd826 100644 --- a/src/gui/models/nodeGraph/generatorGraphModel.h +++ b/src/gui/models/nodeGraph/generatorGraphModel.h @@ -11,7 +11,7 @@ #include "nodeWrapper.h" // A graph node model for looking at the generators on a configuration -class GeneratorGraphModel : public GraphModel +class GeneratorGraphModel : public GraphModel { Q_OBJECT // The Dissolve Model that contains the Dissolve object instance we diff --git a/src/gui/models/nodeGraph/instances/all.h b/src/gui/models/nodeGraph/instances/all.h index a0abf0379d..2f51f4ad50 100644 --- a/src/gui/models/nodeGraph/instances/all.h +++ b/src/gui/models/nodeGraph/instances/all.h @@ -3,10 +3,10 @@ #pragma once -#include #include "configuration.h" #include "generator.h" #include "generatorNode.h" +#include // The variant of all of the types that we will examine using GeneratorGraphInnerType = std::variant; @@ -26,7 +26,8 @@ std::string nodeTypeIcon(const GeneratorGraphNode &value); void setNodeName(GeneratorGraphNode &value, std::string); QVariant nodeGetValue(const GeneratorGraphNode &value); bool nodeConnect(GeneratorGraphNode &source, int sourceIndex, GeneratorGraphNode &destionation, int destinationIndex); -bool nodeConnectable(const GeneratorGraphNode &source, int sourceIndex, const GeneratorGraphNode &destination, int destinationIndex); +bool nodeConnectable(const GeneratorGraphNode &source, int sourceIndex, const GeneratorGraphNode &destination, + int destinationIndex); bool nodeDisconnect(GeneratorGraphNode &source, int sourceIndex, GeneratorGraphNode &destination, int destinationIndex); QHash &nodeRoleNames(Phantom proxy, QHash &roles); bool nodeDelete(GeneratorGraphNode &item, CoreData *coreData); diff --git a/src/gui/models/nodeGraph/instances/configuration.cpp b/src/gui/models/nodeGraph/instances/configuration.cpp index e55d1ba47a..e1c9ddb76a 100644 --- a/src/gui/models/nodeGraph/instances/configuration.cpp +++ b/src/gui/models/nodeGraph/instances/configuration.cpp @@ -7,10 +7,7 @@ std::string nodeTypeName(const Configuration *value) { return "Configuration"; } // The path to the icon for the node -std::string nodeTypeIcon(const Configuration *value) -{ - return "qrc:/Dissolve/icons/configuration.svg"; -} +std::string nodeTypeIcon(const Configuration *value) { return "qrc:/Dissolve/icons/configuration.svg"; } // The title of the node std::string nodeName(const Configuration *value) diff --git a/src/gui/models/nodeGraph/instances/generatorNode.h b/src/gui/models/nodeGraph/instances/generatorNode.h index 8672a7fe72..e64e3835cf 100644 --- a/src/gui/models/nodeGraph/instances/generatorNode.h +++ b/src/gui/models/nodeGraph/instances/generatorNode.h @@ -3,9 +3,9 @@ #pragma once -#include -#include "gui/models/nodeGraph/phantom.h" #include "classes/coreData.h" +#include "gui/models/nodeGraph/phantom.h" +#include class GeneratorNode; From 126ff72de48e80f3480d2b1b2c906066200fef37 Mon Sep 17 00:00:00 2001 From: Adam Washington Date: Thu, 16 Jan 2025 17:21:11 +0000 Subject: [PATCH 13/15] Remove debugging flag --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6bf5574494..4737c3af60 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -178,7 +178,7 @@ if(UNIX) set(gui_target_name dissolve-gui) set(qmlgui_target_name dissolve-gui-qml) endif(PARALLEL) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -fconcepts-diagnostics-depth=2") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") endif(UNIX) # -- OSX From 76b4d5671d0355270246c4ba182d48d294199194 Mon Sep 17 00:00:00 2001 From: Adam Washington Date: Thu, 16 Jan 2025 17:35:10 +0000 Subject: [PATCH 14/15] Reformat qml Again I guess --- src/gui-qml/qml/DissolveMain.qml | 119 ++++++++++++-------- src/gui/qml/nodeGraph/ExampleDelegate.qml | 5 + src/gui/qml/nodeGraph/GeneratorDelegate.qml | 7 ++ src/gui/qml/nodeGraph/GraphView.qml | 7 +- src/gui/qml/nodeGraph/NodeBox.qml | 11 +- 5 files changed, 95 insertions(+), 54 deletions(-) diff --git a/src/gui-qml/qml/DissolveMain.qml b/src/gui-qml/qml/DissolveMain.qml index f3ec88c35b..29f213413c 100644 --- a/src/gui-qml/qml/DissolveMain.qml +++ b/src/gui-qml/qml/DissolveMain.qml @@ -11,6 +11,7 @@ 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 @@ -18,8 +19,51 @@ ApplicationWindow { 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 @@ -48,20 +92,24 @@ 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 @@ -69,6 +117,7 @@ ApplicationWindow { } ScatterModel { id: plotLine + color: "red" scale: dissolveWindow.scale thickness: 0.1 @@ -90,6 +139,7 @@ ApplicationWindow { axis: Axis { id: xAxis + direction: true maximum: 2.0 minimum: -2.0 @@ -102,6 +152,7 @@ ApplicationWindow { axis: Axis { id: yAxis + direction: false maximum: 2.0 minimum: -2.0 @@ -111,9 +162,16 @@ ApplicationWindow { } View3D { id: graphView + anchors.fill: parent importScene: standAloneScene + camera: OrthographicCamera { + id: cameraOrthographicLeft + + z: 600 + } + MouseArea { anchors.fill: parent @@ -122,32 +180,31 @@ 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 @@ -155,6 +212,7 @@ ApplicationWindow { FileDialog { id: openDialog + onAccepted: { dissolve.file = selectedFile; } @@ -172,6 +230,7 @@ ApplicationWindow { } SpinBox { id: nodeValue + from: 0 } Button { @@ -197,6 +256,7 @@ ApplicationWindow { } SpinBox { id: conSrc + from: 0 to: graphModel.nodeCount - 1 } @@ -205,11 +265,13 @@ ApplicationWindow { } SpinBox { id: conDest + from: 0 to: graphModel.nodeCount - 1 } Button { id: connectButton + text: "Connect" onClicked: { @@ -223,6 +285,7 @@ ApplicationWindow { } Button { id: disconnectButton + text: "Disconnect" onClicked: { @@ -238,6 +301,7 @@ ApplicationWindow { } GraphView { id: graph + anchors.bottom: parent.bottom anchors.left: parent.left anchors.right: parent.right @@ -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() - } - } - } } diff --git a/src/gui/qml/nodeGraph/ExampleDelegate.qml b/src/gui/qml/nodeGraph/ExampleDelegate.qml index 344c4b7790..987832b803 100644 --- a/src/gui/qml/nodeGraph/ExampleDelegate.qml +++ b/src/gui/qml/nodeGraph/ExampleDelegate.qml @@ -26,6 +26,7 @@ Item { Text { id: root + anchors.fill: parent height: contentHeight text: value @@ -52,6 +53,7 @@ Item { Text { id: root + anchors.fill: parent color: value != null ? "black" : "red" height: contentHeight @@ -76,16 +78,19 @@ Item { ColumnLayout { id: root + anchors.fill: parent Text { id: xnode + height: contentHeight text: "X: " + px width: contentWidth } Text { id: ynode + height: contentHeight text: "Y: " + py width: contentWidth diff --git a/src/gui/qml/nodeGraph/GeneratorDelegate.qml b/src/gui/qml/nodeGraph/GeneratorDelegate.qml index 991bdea126..2a6a6097a8 100644 --- a/src/gui/qml/nodeGraph/GeneratorDelegate.qml +++ b/src/gui/qml/nodeGraph/GeneratorDelegate.qml @@ -33,6 +33,7 @@ Item { } TextField { id: root + text: temperature } Text { @@ -67,6 +68,7 @@ Item { Text { id: root + text: name } Text { @@ -98,6 +100,7 @@ Item { Text { id: root + text: "name" } } @@ -122,6 +125,7 @@ Item { Text { id: root + anchors.fill: parent color: value != null ? "black" : "red" height: contentHeight @@ -146,16 +150,19 @@ Item { ColumnLayout { id: root + anchors.fill: parent Text { id: xnode + height: contentHeight text: "X: " + px width: contentWidth } Text { id: ynode + height: contentHeight text: "Y: " + py width: contentWidth diff --git a/src/gui/qml/nodeGraph/GraphView.qml b/src/gui/qml/nodeGraph/GraphView.qml index 995cb65e60..af7d754bea 100644 --- a/src/gui/qml/nodeGraph/GraphView.qml +++ b/src/gui/qml/nodeGraph/GraphView.qml @@ -6,12 +6,13 @@ import Qt.labs.qmlmodels Pane { id: graphRoot + property double curveOffset: 125 property variant delegate property variant edgeModel + property var nameLookup: ({}) property variant nodeModel property variant rootModel - property var nameLookup: ({}) // Edge connections Repeater { @@ -44,9 +45,11 @@ Pane { // Actual nodes Repeater { id: nodeRepeater + delegate: graphRoot.delegate model: nodeModel - onItemAdded: function(index, item) { + + onItemAdded: function (index, item) { nameLookup[item.nodeType] = index; } } diff --git a/src/gui/qml/nodeGraph/NodeBox.qml b/src/gui/qml/nodeGraph/NodeBox.qml index 362e252872..660705d4f1 100644 --- a/src/gui/qml/nodeGraph/NodeBox.qml +++ b/src/gui/qml/nodeGraph/NodeBox.qml @@ -5,6 +5,7 @@ import Qt.labs.qmlmodels GroupBox { id: root + property double basey: header.height property string image property string nodeType @@ -15,6 +16,7 @@ GroupBox { label: RowLayout { id: header + Image { clip: true fillMode: Image.PreserveAspectFit @@ -24,24 +26,25 @@ GroupBox { } TextField { id: titleLabel + font.pointSize: 14 text: root.nodeType } Button { - onClicked: root.deleted() - contentItem: Image { fillMode: Image.PreserveAspectFit source: "qrc:/Dissolve/icons/cross.svg" sourceSize.height: titleLabel.height sourceSize.width: titleLabel.height } + + onClicked: root.deleted() } DragHandler { target: null - xAxis.onActiveValueChanged: delta => posX += delta; - yAxis.onActiveValueChanged: delta => posY += delta; + xAxis.onActiveValueChanged: delta => posX += delta + yAxis.onActiveValueChanged: delta => posY += delta } } } From c3c22be6ddce44560e493f7e49fd6381bb6c94d6 Mon Sep 17 00:00:00 2001 From: Adam Washington Date: Thu, 16 Jan 2025 17:50:34 +0000 Subject: [PATCH 15/15] Fix copyright dates Again. It seems like something weird is going on here --- src/gui/models/nodeGraph/exampleGraphModel.cpp | 2 +- src/gui/models/nodeGraph/exampleGraphModel.h | 2 +- src/gui/models/nodeGraph/generatorGraphModel.cpp | 2 +- src/gui/models/nodeGraph/generatorGraphModel.h | 2 +- src/gui/models/nodeGraph/graphEdgeModel.cpp | 2 +- src/gui/models/nodeGraph/graphEdgeModel.h | 2 +- src/gui/models/nodeGraph/graphModel.h | 2 +- src/gui/models/nodeGraph/graphModelBase.cpp | 2 +- src/gui/models/nodeGraph/graphModelBase.h | 2 +- src/gui/models/nodeGraph/graphNodeModel.h | 2 +- src/gui/models/nodeGraph/instances/all.h | 2 +- src/gui/models/nodeGraph/instances/configuration.h | 2 +- src/gui/models/nodeGraph/instances/generator.h | 2 +- src/gui/models/nodeGraph/instances/generatorGraphNode.h | 2 +- src/gui/models/nodeGraph/instances/generatorNode.h | 2 +- src/gui/models/nodeGraph/nodeWrapper.h | 2 +- src/gui/models/nodeGraph/phantom.h | 2 +- tests/gui/graphModel.cpp | 2 +- 18 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/gui/models/nodeGraph/exampleGraphModel.cpp b/src/gui/models/nodeGraph/exampleGraphModel.cpp index aa7a8cdc3d..0ff086aec4 100644 --- a/src/gui/models/nodeGraph/exampleGraphModel.cpp +++ b/src/gui/models/nodeGraph/exampleGraphModel.cpp @@ -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 #include "exampleGraphModel.h" #include "nodeWrapper.h" diff --git a/src/gui/models/nodeGraph/exampleGraphModel.h b/src/gui/models/nodeGraph/exampleGraphModel.h index f8421e3937..17df4de7f4 100644 --- a/src/gui/models/nodeGraph/exampleGraphModel.h +++ b/src/gui/models/nodeGraph/exampleGraphModel.h @@ -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 diff --git a/src/gui/models/nodeGraph/generatorGraphModel.cpp b/src/gui/models/nodeGraph/generatorGraphModel.cpp index 726ab203b4..9303569a29 100644 --- a/src/gui/models/nodeGraph/generatorGraphModel.cpp +++ b/src/gui/models/nodeGraph/generatorGraphModel.cpp @@ -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 #include "generatorGraphModel.h" #include "expression/variable.h" diff --git a/src/gui/models/nodeGraph/generatorGraphModel.h b/src/gui/models/nodeGraph/generatorGraphModel.h index a727ffd826..19c78704af 100644 --- a/src/gui/models/nodeGraph/generatorGraphModel.h +++ b/src/gui/models/nodeGraph/generatorGraphModel.h @@ -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 diff --git a/src/gui/models/nodeGraph/graphEdgeModel.cpp b/src/gui/models/nodeGraph/graphEdgeModel.cpp index e44a633216..99ea38ba0a 100644 --- a/src/gui/models/nodeGraph/graphEdgeModel.cpp +++ b/src/gui/models/nodeGraph/graphEdgeModel.cpp @@ -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 #include "gui/models/nodeGraph/graphEdgeModel.h" diff --git a/src/gui/models/nodeGraph/graphEdgeModel.h b/src/gui/models/nodeGraph/graphEdgeModel.h index aa96c7e51f..ecb24cce7e 100644 --- a/src/gui/models/nodeGraph/graphEdgeModel.h +++ b/src/gui/models/nodeGraph/graphEdgeModel.h @@ -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 diff --git a/src/gui/models/nodeGraph/graphModel.h b/src/gui/models/nodeGraph/graphModel.h index 3b6ae21566..247edbd424 100644 --- a/src/gui/models/nodeGraph/graphModel.h +++ b/src/gui/models/nodeGraph/graphModel.h @@ -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 diff --git a/src/gui/models/nodeGraph/graphModelBase.cpp b/src/gui/models/nodeGraph/graphModelBase.cpp index 6bd9b3074f..853d9f728c 100644 --- a/src/gui/models/nodeGraph/graphModelBase.cpp +++ b/src/gui/models/nodeGraph/graphModelBase.cpp @@ -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 #include "graphEdgeModel.h" #include "graphModel.h" diff --git a/src/gui/models/nodeGraph/graphModelBase.h b/src/gui/models/nodeGraph/graphModelBase.h index aa0fcd11d8..43e0a36f84 100644 --- a/src/gui/models/nodeGraph/graphModelBase.h +++ b/src/gui/models/nodeGraph/graphModelBase.h @@ -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 diff --git a/src/gui/models/nodeGraph/graphNodeModel.h b/src/gui/models/nodeGraph/graphNodeModel.h index 44ae62ac18..476f59fa2c 100644 --- a/src/gui/models/nodeGraph/graphNodeModel.h +++ b/src/gui/models/nodeGraph/graphNodeModel.h @@ -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 diff --git a/src/gui/models/nodeGraph/instances/all.h b/src/gui/models/nodeGraph/instances/all.h index 2f51f4ad50..9ba25e0e39 100644 --- a/src/gui/models/nodeGraph/instances/all.h +++ b/src/gui/models/nodeGraph/instances/all.h @@ -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 diff --git a/src/gui/models/nodeGraph/instances/configuration.h b/src/gui/models/nodeGraph/instances/configuration.h index d0ab6ac390..e686c01991 100644 --- a/src/gui/models/nodeGraph/instances/configuration.h +++ b/src/gui/models/nodeGraph/instances/configuration.h @@ -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 diff --git a/src/gui/models/nodeGraph/instances/generator.h b/src/gui/models/nodeGraph/instances/generator.h index 6a4f6f8593..85ab1f95da 100644 --- a/src/gui/models/nodeGraph/instances/generator.h +++ b/src/gui/models/nodeGraph/instances/generator.h @@ -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 diff --git a/src/gui/models/nodeGraph/instances/generatorGraphNode.h b/src/gui/models/nodeGraph/instances/generatorGraphNode.h index e73f838530..a0a1bfb551 100644 --- a/src/gui/models/nodeGraph/instances/generatorGraphNode.h +++ b/src/gui/models/nodeGraph/instances/generatorGraphNode.h @@ -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 diff --git a/src/gui/models/nodeGraph/instances/generatorNode.h b/src/gui/models/nodeGraph/instances/generatorNode.h index e64e3835cf..7254a3c5aa 100644 --- a/src/gui/models/nodeGraph/instances/generatorNode.h +++ b/src/gui/models/nodeGraph/instances/generatorNode.h @@ -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 diff --git a/src/gui/models/nodeGraph/nodeWrapper.h b/src/gui/models/nodeGraph/nodeWrapper.h index 8be36e6413..a4aa90138b 100644 --- a/src/gui/models/nodeGraph/nodeWrapper.h +++ b/src/gui/models/nodeGraph/nodeWrapper.h @@ -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 diff --git a/src/gui/models/nodeGraph/phantom.h b/src/gui/models/nodeGraph/phantom.h index 22f41972a3..1f46bb7ecb 100644 --- a/src/gui/models/nodeGraph/phantom.h +++ b/src/gui/models/nodeGraph/phantom.h @@ -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 diff --git a/tests/gui/graphModel.cpp b/tests/gui/graphModel.cpp index 003eaa9c32..d6e869ad6f 100644 --- a/tests/gui/graphModel.cpp +++ b/tests/gui/graphModel.cpp @@ -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 #include "gui/models/dissolveModel.h" #include "gui/models/nodeGraph/exampleGraphModel.h"