presentation/GraphLinesItem.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include "GraphGeometry.h" | ||
| 4 | #include "GraphPaintCache.h" | ||
| 5 | #include "QuickContactGraph.h" | ||
| 6 | |||
| 7 | #include <QColor> | ||
| 8 | #include <QPointer> | ||
| 9 | #include <QQuickItem> | ||
| 10 | #include <QTimer> | ||
| 11 | #include <QVariantList> | ||
| 12 | #include <QVariantMap> | ||
| 13 | |||
| 14 | |||
| 15 | // Sprint 105 S105.4.2 (D-6): the relationship graph's lines in the scene | ||
| 16 | // graph instead of a Canvas. The lines are kept in world coordinates | ||
| 17 | // (QuickContactGraph::drawnEdges) and turned into screen-space triangles | ||
| 18 | // whenever the view transform changes — widths, dashes, arrowheads and the | ||
| 19 | // couples' rings keep their pixel size while zooming, and a zoom never | ||
| 20 | // waits for a repaint. What the old ContactGraphEdges.qml drew, in the same | ||
| 21 | // order: the lines at rest (boosted ones last), the couples' rings, the | ||
| 22 | // bundles' trunks; the names and the rings' and years' places are left out | ||
| 23 | // of the lines with a soft edge (GraphGeometry::Cutouts). The base instance | ||
| 24 | // draws every line, the overlay (`overlay`) only `indices` (what the pointer | ||
| 25 | // emphasises) and the relationship being dragged. The look (alpha, boost, | ||
| 26 | // colour per edge) comes from QML (ContactGraphLook), once per change of | ||
| 27 | // what is emphasised — not per frame. | ||
| 28 | class GraphLinesItem : public QQuickItem { | ||
| 29 | Q_OBJECT | ||
| 30 | Q_PROPERTY(QObject *graph READ graph WRITE setGraph NOTIFY changed) | ||
| 31 | Q_PROPERTY(bool overlay MEMBER m_overlay NOTIFY changed) | ||
| 32 | // Per edge of graph.edges. | ||
| 33 | Q_PROPERTY(QVariantList alphas READ alphas WRITE setAlphas NOTIFY changed) | ||
| 34 | Q_PROPERTY(QVariantList boosts READ boosts WRITE setBoosts NOTIFY changed) | ||
| 35 | Q_PROPERTY(QVariantList colours READ colours WRITE setColours NOTIFY changed) | ||
| 36 | // The overlay's edges, in drawing order. | ||
| 37 | Q_PROPERTY(QVariantList indices READ indices WRITE setIndices NOTIFY changed) | ||
| 38 | // Per node: the avatar's radius in px (arrowheads and rings stop short of it). | ||
| 39 | Q_PROPERTY(QVariantList radii READ radii WRITE setRadii NOTIFY changed) | ||
| 40 | // Name boxes: [ax, ay, dx, dy, w, h, …] — anchored at the world point | ||
| 41 | // (ax, ay), offset (dx, dy) and sized (w, h) in px (labels keep their size). | ||
| 42 | Q_PROPERTY(QVariantList cutouts READ cutouts WRITE setCutouts NOTIFY changed) | ||
| 43 | // Boxes fixed on the screen: [x, y, w, h, …]. | ||
| 44 | Q_PROPERTY(QVariantList screenCutouts READ screenCutouts WRITE setScreenCutouts NOTIFY changed) | ||
| 45 | Q_PROPERTY(bool arrows MEMBER m_arrows NOTIFY changed) | ||
| 46 | // The couples' sign, px wide (20; 11 with the dots far out in Everyone). | ||
| 47 | Q_PROPERTY(double ringSize MEMBER m_ringSize NOTIFY changed) | ||
| 48 | // The wedding years are shown (their place is kept clear). | ||
| 49 | Q_PROPERTY(bool years MEMBER m_years NOTIFY changed) | ||
| 50 | Q_PROPERTY(QColor trunkColour MEMBER m_trunkColour NOTIFY changed) | ||
| 51 | Q_PROPERTY(QColor dragColour MEMBER m_dragColour NOTIFY changed) | ||
| 52 | // The relationship being dragged: {from: node index, x, y (canvas)}; {} when none. | ||
| 53 | Q_PROPERTY(QVariantMap linkDrag READ linkDrag WRITE setLinkDrag NOTIFY changed) | ||
| 54 | // Tests and the benchmark: vertices and build time of the last frame. | ||
| 55 | Q_PROPERTY(int vertexCount READ vertexCount NOTIFY built) | ||
| 56 | Q_PROPERTY(double buildMs READ buildMs NOTIFY built) | ||
| 57 | // Tests: no picture is due any more — the last frame was built for the | ||
| 58 | // resting view (no GraphPaintCache refresh pending, no content change). | ||
| 59 | Q_PROPERTY(bool settled READ settled NOTIFY built) | ||
| 60 | |||
| 61 | public: | ||
| 62 | explicit GraphLinesItem(QQuickItem *parent = nullptr); | ||
| 63 | static void registerTypes(); | ||
| 64 | |||
| 65 | QObject *graph() const; | ||
| 66 | void setGraph(QObject *graph); | ||
| 67 | ✗ | QVariantList alphas() const { return m_alphasIn; } | |
| 68 | void setAlphas(const QVariantList &values); | ||
| 69 | ✗ | QVariantList boosts() const { return m_boostsIn; } | |
| 70 | void setBoosts(const QVariantList &values); | ||
| 71 | ✗ | QVariantList colours() const { return m_coloursIn; } | |
| 72 | void setColours(const QVariantList &values); | ||
| 73 | ✗ | QVariantList indices() const { return m_indicesIn; } | |
| 74 | void setIndices(const QVariantList &values); | ||
| 75 | ✗ | QVariantList radii() const { return m_radiiIn; } | |
| 76 | void setRadii(const QVariantList &values); | ||
| 77 | ✗ | QVariantList cutouts() const { return m_cutoutsIn; } | |
| 78 | void setCutouts(const QVariantList &values); | ||
| 79 | ✗ | QVariantList screenCutouts() const { return m_screenCutoutsIn; } | |
| 80 | void setScreenCutouts(const QVariantList &values); | ||
| 81 | ✗ | QVariantMap linkDrag() const { return m_linkDrag; } | |
| 82 | void setLinkDrag(const QVariantMap &value); | ||
| 83 | ✗ | int vertexCount() const { return m_vertexCount; } | |
| 84 | ✗ | double buildMs() const { return m_buildMs; } | |
| 85 |
2/4✓ Branch 2 → 3 taken 4 times.
✗ Branch 2 → 5 not taken.
✓ Branch 3 → 4 taken 4 times.
✗ Branch 3 → 5 not taken.
|
4 | bool settled() const { return !m_refreshPending && !m_contentChanged; } |
| 86 | |||
| 87 | // The dash pattern of a line style (px on, px off, …): the legend's samples | ||
| 88 | // and the lines use the one table. | ||
| 89 | static QList<double> dashOf(const QString &style); | ||
| 90 | |||
| 91 | signals: | ||
| 92 | void changed(); | ||
| 93 | void built(); | ||
| 94 | |||
| 95 | protected: | ||
| 96 | QSGNode *updatePaintNode(QSGNode *old, UpdatePaintNodeData *) override; | ||
| 97 | void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; | ||
| 98 | |||
| 99 | private: | ||
| 100 | void build(GraphGeometry::Sink *mesh); | ||
| 101 | void paintEdge(GraphGeometry::Sink *mesh, int index, const GraphGeometry::Cutouts &cuts, QList<int> *pairs); | ||
| 102 | double alphaOf(int index) const; | ||
| 103 | double radiusOf(int node) const; | ||
| 104 | QList<QPointF> screenPath(const QuickContactGraph::DrawnEdge &edge) const; | ||
| 105 | 5472 | QPointF toScreen(QPointF world) const { return world * m_k + m_t; } | |
| 106 | |||
| 107 | QPointer<QuickContactGraph> m_graph; | ||
| 108 | bool m_overlay = false; | ||
| 109 | bool m_arrows = true; | ||
| 110 | bool m_years = true; | ||
| 111 | double m_ringSize = 20; | ||
| 112 | QColor m_trunkColour = Qt::gray; | ||
| 113 | QColor m_dragColour = Qt::blue; | ||
| 114 | QVariantList m_alphasIn, m_boostsIn, m_coloursIn, m_indicesIn, m_radiiIn, m_cutoutsIn, m_screenCutoutsIn; | ||
| 115 | QList<double> m_alphas, m_boosts, m_radii, m_cutouts, m_screenCutouts; | ||
| 116 | QList<QColor> m_colours; | ||
| 117 | QList<int> m_indices; | ||
| 118 | QVariantMap m_linkDrag; | ||
| 119 | // The view while building. | ||
| 120 | double m_k = 1; | ||
| 121 | QPointF m_t; | ||
| 122 | int m_vertexCount = 0; | ||
| 123 | double m_buildMs = 0; | ||
| 124 | GraphPaintCache m_cache; | ||
| 125 | bool m_contentChanged = true; | ||
| 126 | bool m_refreshPending = false; // the last frame asked for a refresh (GraphPaintCache) | ||
| 127 | QTimer m_refresh; | ||
| 128 | }; | ||
| 129 |