File indexing completed on 2024-05-19 05:42:16
0001 // ct_lvtqtc_edgecollection.h -*-C++-*- 0002 0003 /* 0004 // Copyright 2023 Codethink Ltd <codethink@codethink.co.uk> 0005 // SPDX-License-Identifier: Apache-2.0 0006 // 0007 // Licensed under the Apache License, Version 2.0 (the "License"); 0008 // you may not use this file except in compliance with the License. 0009 // You may obtain a copy of the License at 0010 // 0011 // http://www.apache.org/licenses/LICENSE-2.0 0012 // 0013 // Unless required by applicable law or agreed to in writing, software 0014 // distributed under the License is distributed on an "AS IS" BASIS, 0015 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0016 // See the License for the specific language governing permissions and 0017 // limitations under the License. 0018 */ 0019 0020 #ifndef INCLUDED_CT_LVTQTC_EDGECOLLECTION 0021 #define INCLUDED_CT_LVTQTC_EDGECOLLECTION 0022 0023 #include <lvtqtc_export.h> 0024 0025 #include <memory> 0026 #include <vector> 0027 0028 #include <QPointF> 0029 0030 #include <ct_lvtshr_graphstorage.h> 0031 0032 namespace Codethink::lvtqtc { 0033 0034 struct Vertex; 0035 class LakosRelation; 0036 0037 /*! \struct Edge edge.cpp edge.h 0038 * \brief Represents an Edge in the LakosGraph 0039 * 0040 * %Edge contains one or more LakosRelation and the 0041 * center points of the source and target vertices 0042 * which are Lakos Entities. 0043 */ 0044 struct LVTQTC_EXPORT EdgeCollection { 0045 // This enum describes how the edge will be painted on screen 0046 enum RelationFlags { 0047 RelationFlagsNone = 0x0, 0048 RelationIsSelected = 0x1, /* the edge is selected */ 0049 RelationIsCyclic = 0x2, /* the edge belongs to a cycle */ 0050 RelationIsParentHovered = 0x4, /* the parent of this edge is hovered */ 0051 RelationIsHighlighted = 0x8, /* an algorithm is highlightning the relation */ 0052 }; 0053 0054 enum class PointFrom { SOURCE, PARENT }; 0055 enum class PointTo { TARGET, PARENT }; 0056 0057 EdgeCollection(); 0058 0059 ~EdgeCollection(); 0060 0061 LakosRelation *addRelation(LakosRelation *relation); 0062 // Adds a relation to the relations vector 0063 // 0064 // A relation is not adding of one of the same type and 0065 // direction already exists in the vector. 0066 // 0067 0068 void layoutRelations(); 0069 // Position the relations on the screen. 0070 0071 void setPointFrom(PointFrom entity); 0072 void setPointTo(PointTo entity); 0073 // Those to functions changes how the edge is displayed 0074 // if the edge belongs to a node inside of a package, making 0075 // it "toParent", means that the edge now will look like as if 0076 // it belongs to the pacakge, and not to the internal node. 0077 // those functions are important to the expand / shrink mechanism, 0078 // as we need to change where it's pointing to. 0079 0080 void setHighlighted(bool highlighted); 0081 // changes the color of the edges on the collection to a setHighlighted color. 0082 0083 void setVisible(bool v); 0084 0085 [[nodiscard]] std::vector<LakosRelation *> relations() const; 0086 // all the relations from this Collection 0087 0088 [[nodiscard]] LakosEntity *from() const; 0089 [[nodiscard]] LakosEntity *to() const; 0090 0091 void setFrom(LakosEntity *from); 0092 void setTo(LakosEntity *to); 0093 0094 void toggleRelationFlags(RelationFlags flags, bool toggle); 0095 0096 void removeEdge(LakosRelation *edge); 0097 0098 void setRedundant(bool redundant); 0099 [[nodiscard]] bool isRedundant() const; 0100 // a redundant edge is an edge that if removed, does not changes 0101 // the meaning of the graph. but it's still important to be able to 0102 // access them in runtime since we could potentially be trying to 0103 // look for redundancy and ways to remove those in code. 0104 0105 private: 0106 struct Private; 0107 std::unique_ptr<Private> d; 0108 0109 void layoutSingleEdge(LakosRelation *relation, double dx, double dy); 0110 // Applies the layout algorithm on the edge. 0111 }; 0112 0113 } // end namespace Codethink::lvtqtc 0114 0115 #endif