File indexing completed on 2024-05-19 05:42:21
0001 // ct_lvtqtc_lakosrelation.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_LVTGRPS_LAKOSRELATION 0021 #define INCLUDED_CT_LVTGRPS_LAKOSRELATION 0022 0023 #include <lvtqtc_export.h> 0024 0025 #include <QGraphicsLineItem> 0026 0027 #include <memory> 0028 0029 #include <QBrush> 0030 #include <QPen> 0031 #include <QPointF> 0032 0033 #include <ct_lvtqtc_edgecollection.h> 0034 #include <ct_lvtqtc_util.h> 0035 0036 #include <ct_lvtshr_graphenums.h> 0037 0038 class QUndoCommand; 0039 0040 namespace Codethink::lvtqtc { 0041 0042 struct Vertex; 0043 class LakosEntity; 0044 0045 /*! \class LakosRelation lakos_relation.cpp lakos_relation.h 0046 * \brief Represents and draws a Lakos Relation 0047 * 0048 * %LakosRelation draws a Lakos Relation 0049 */ 0050 class LVTQTC_EXPORT LakosRelation : public QObject, public QGraphicsItem { 0051 Q_OBJECT 0052 public: 0053 LakosRelation(LakosEntity *source, LakosEntity *target); 0054 ~LakosRelation() override; 0055 0056 void setColor(QColor const& newColor); 0057 void setStyle(Qt::PenStyle const& newStyle); 0058 0059 /*! \brief The type of a particular instance of sub class LakosRelation 0060 */ 0061 [[nodiscard]] virtual lvtshr::LakosRelationType relationType() const = 0; 0062 0063 /*! \brief Returns a string of the sub class of LakosRelation 0064 */ 0065 [[nodiscard]] virtual std::string relationTypeAsString() const = 0; 0066 0067 [[nodiscard]] QRectF boundingRect() const override; 0068 0069 enum { Type = QtcUtil::LAKOSRELATION_TYPE }; 0070 // for qgraphicsitem_cast magic 0071 0072 [[nodiscard]] inline int type() const override 0073 // for qgraphicsitem_cast magic 0074 { 0075 return Type; 0076 } 0077 0078 virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; 0079 0080 [[nodiscard]] QLineF line() const; 0081 void setLine(const QLineF& line); 0082 void setLine(qreal x1, qreal y1, qreal x2, qreal y2); 0083 0084 [[nodiscard]] QLineF adjustedLine() const; 0085 0086 static QGraphicsPathItem *defaultArrow(); 0087 static QGraphicsPathItem *defaultTail(); 0088 static QGraphicsPathItem *diamondArrow(); 0089 0090 [[nodiscard]] LakosEntity *from() const; 0091 [[nodiscard]] LakosEntity *to() const; 0092 0093 void toggleRelationFlags(EdgeCollection::RelationFlags flags, bool toggle); 0094 0095 void setShouldBeHidden(bool hidden); 0096 // controls the visibility, has higher precedence than isHidden. 0097 // this is used to block some data from being displayed. 0098 0099 bool shouldBeHidden() const; 0100 0101 virtual void populateMenu(QMenu& menu, QMenu *debugMenu); 0102 0103 std::pair<QPainterPath, QPainterPath> calculateIntersection(QGraphicsItem *lhs, QGraphicsItem *rhs); 0104 0105 [[nodiscard]] QPainterPath shape() const override; 0106 0107 void updateTooltip(); 0108 [[nodiscard]] std::string legendText() const; 0109 // Returns a string which summarises what this thing is 0110 0111 // Debug methods 0112 static void toggleBoundingRect(); 0113 static void toggleShape(); 0114 static void toggleTextualInformation(); 0115 static void toggleIntersectionPaths(); 0116 static void toggleOriginalLine(); 0117 static bool showBoundingRect(); 0118 static bool showShape(); 0119 static bool showTextualInformation(); 0120 static bool showIntersectionPaths(); 0121 static bool showOriginalLine(); 0122 0123 // fist the static methods above, then call this for each LakosRelation. 0124 void updateDebugInformation(); 0125 0126 Q_SIGNAL void undoCommandCreated(QUndoCommand *command); 0127 // A new undo command is created for his edge. 0128 0129 Q_SIGNAL void requestRemoval(); 0130 0131 protected: 0132 void setDashed(bool dashed); 0133 0134 void setThickness(qreal thickness); 0135 // set the thickness of the line. defaults to 0.5, a hair-thin line. 0136 0137 void setHead(QGraphicsPathItem *head); 0138 // This assumes that the item is pointed upwards 0139 // and that the origin point is at the mid-right 0140 0141 void setTail(QGraphicsPathItem *tail); 0142 // this assumes that the item is pointed upwards 0143 // and that the origin point is at the mid-right 0144 0145 virtual QColor hoverColor() const; 0146 0147 private: 0148 QColor overrideColor() const; 0149 0150 struct Private; 0151 std::unique_ptr<Private> d; 0152 }; 0153 0154 } // end namespace Codethink::lvtqtc 0155 0156 #endif