Debian Codegraph @

src/Gui/DAGView/DAGModel.h

raw
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 /***************************************************************************
3 * Copyright (c) 2015 Thomas Anderson <blobfish[at]gmx.com> *
4 * *
5 * This file is part of the FreeCAD CAx development system. *
6 * *
7 * This library is free software; you can redistribute it and/or *
8 * modify it under the terms of the GNU Library General Public *
9 * License as published by the Free Software Foundation; either *
10 * version 2 of the License, or (at your option) any later version. *
11 * *
12 * This library is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU Library General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Library General Public *
18 * License along with this library; see the file COPYING.LIB. If not, *
19 * write to the Free Software Foundation, Inc., 59 Temple Place, *
20 * Suite 330, Boston, MA 02111-1307, USA *
21 * *
22 ***************************************************************************/
23
24 #ifndef DAGMODEL_H
25 #define DAGMODEL_H
26
27 #include <memory>
28 #include <vector>
29
30 #include <boost/signals2.hpp>
31
32 #include <QBrush>
33 #include <QGraphicsScene>
34 #include <QLineEdit>
35
36 #include "DAGModelGraph.h"
37 #include "DAGRectItem.h"
38
39
40 class QGraphicsSceneHoverEvent;
41 class QGraphicsProxyWidget;
42
43 namespace Gui
44 {
45 class Document;
46 class ViewProviderDocumentObject;
47 class SelectionChanges;
48
49 namespace DAG
50 {
51 class LineEdit: public QLineEdit
52 {
53 Q_OBJECT
54 public:
55 explicit LineEdit(QWidget* parentIn = nullptr);
56 Q_SIGNALS:
57 void acceptedSignal();
58 void rejectedSignal();
59
60 protected:
61 void keyPressEvent(QKeyEvent*) override;
62 };
63
64 class Model: public QGraphicsScene
65 {
66 Q_OBJECT
67 public:
68 Model(QObject* parentIn, const Gui::Document& documentIn);
69 ~Model() override;
70 void awake(); //!< hooked up to event dispatcher for update when idle.
71 void selectionChanged(const SelectionChanges& msg);
72
73 protected:
74 void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
75 void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
76 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) override;
77 void contextMenuEvent(QGraphicsSceneContextMenuEvent* event) override;
78
79 private Q_SLOTS:
80 void updateSlot();
81 void onRenameSlot();
82 void renameAcceptedSlot();
83 void renameRejectedSlot();
84 void editingStartSlot();
85 void editingFinishedSlot();
86
87 private:
88 Model() = default;
89 // documentObject slots.
90 using Connection = boost::signals2::connection;
91 Connection connectNewObject;
92 Connection connectDelObject;
93 Connection connectChgObject;
94 Connection connectRenObject;
95 Connection connectActObject;
96 Connection connectEdtObject;
97 Connection connectResObject;
98 Connection connectHltObject;
99 Connection connectExpObject;
100 void slotNewObject(const Gui::ViewProviderDocumentObject& VPDObjectIn);
101 void slotDeleteObject(const Gui::ViewProviderDocumentObject& VPDObjectIn);
102 void slotChangeObject(
103 const Gui::ViewProviderDocumentObject& VPDObjectIn,
104 const App::Property& propertyIn
105 );
106 void slotInEdit(const Gui::ViewProviderDocumentObject& VPDObjectIn);
107 void slotResetEdit(const Gui::ViewProviderDocumentObject& VPDObjectIn);
108 void slotChangeIcon(
109 const Gui::ViewProviderDocumentObject& VPDObjectIn,
110 std::shared_ptr<QGraphicsPixmapItem> icon
111 );
112
113 std::shared_ptr<GraphLinkContainer> graphLink;
114 std::shared_ptr<Graph> theGraph;
115 bool graphDirty;
116
117 void indexVerticesEdges();
118 void removeAllItems();
119 void addVertexItemsToScene(const Vertex& vertexIn);
120 void removeVertexItemsFromScene(const Vertex& vertexIn);
121 void updateStates();
122 std::size_t columnFromMask(const ColumnMask&);
123
124 RectItem* getRectFromPosition(const QPointF& position); //!< can be nullptr
125
126 //! @name View Constants for spacing
127 //@{
128 qreal fontHeight; //!< height of the current qApp default font.
129 qreal direction; //!< controls top to bottom or bottom to top direction.
130 qreal verticalSpacing; //!< pixels between top and bottom of text to background rectangle.
131 qreal rowHeight; //!< height of background rectangle.
132 qreal iconSize; //!< size of icon to match font.
133 qreal pointSize; //!< size of the connection point.
134 qreal pointSpacing; //!< spacing between pofloat columns.
135 qreal pointToIcon; //!< spacing from last column points to first icon.
136 qreal iconToIcon; //!< spacing between icons.
137 qreal iconToText; //!< spacing between last icon and text.
138 qreal rowPadding; //!< spaces added to rectangle background width ends.
139 std::vector<QBrush> backgroundBrushes; //!< brushes to paint background rectangles.
140 std::vector<QBrush> forgroundBrushes; //!< brushes to paint points, connectors, text.
141 void setupViewConstants();
142 //@}
143
144 RectItem* currentPrehighlight;
145
146 enum class SelectionMode
147 {
148 Single,
149 Multiple
150 };
151 SelectionMode selectionMode;
152 std::vector<Vertex> getAllSelected();
153 void visiblyIsolate(Vertex sourceIn); //!< hide any connected feature and turn on sourceIn.
154
155 QPointF lastPick;
156 bool lastPickValid = false;
157
158 QPixmap visiblePixmapEnabled;
159 QPixmap visiblePixmapDisabled;
160 QPixmap passPixmap;
161 QPixmap failPixmap;
162 QPixmap pendingPixmap;
163 Vertex lastAddedVertex = Graph::null_vertex(); //!< needed because python objects are not ready.
164
165 QAction* renameAction;
166 QAction* editingFinishedAction;
167 QGraphicsProxyWidget* proxy = nullptr;
168 void finishRename();
169 };
170 } // namespace DAG
171 } // namespace Gui
172
173 #endif // DAGMODEL_H