ACF $AcfVersion:0$
TViewExtenderCompBase.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// ACF includes
9#include <iview/IShapeView.h>
10#include <iview/CShapeBase.h>
12#include <iqt2d/IViewProvider.h>
13#include <iqt2d/IViewExtender.h>
14
15
16namespace iqt2d
17{
18
19
20template <class Base>
21class TViewExtenderCompBase: public Base, virtual public IViewExtender
22{
23public:
24 typedef Base BaseClass;
25
26 I_BEGIN_BASE_COMPONENT(TViewExtenderCompBase);
27 I_REGISTER_INTERFACE(IViewExtender);
28 I_ASSIGN(m_slaveExtenderCompPtr, "SlaveSceneExtender", "Scene extender will be used to provide background shapes", false, "SlaveSceneExtender");
29 I_ASSIGN(m_sceneExtenderModeAttrPtr, "ViewExtenderMode", "Control how the view extender works:\n\t0 - combine slave with current shapes\n\t1 - use slave by direct calls only\n\t2 - use slave always and current shapes indirect only\n\t3 - use slave by direct calls only and current shapes indirect only", true, 0);
30 I_ASSIGN_MULTI_0(m_idFiltersAttrPtr, "SceneIdFilters", "Optional scene ID filters allowing to ignore some scene providers", false);
31 I_END_COMPONENT;
32
34
35 // reimplemented (iqt2d::IViewExtender)
36 virtual void AddItemsToScene(IViewProvider* providerPtr, int flags) override;
37 virtual void RemoveItemsFromScene(IViewProvider* providerPtr) override;
38
39protected:
47
49 typedef QMap<IViewProvider*, Shapes> ShapesMap;
50
51 bool IsViewIdSupported(int viewId) const;
52 const ShapesMap& GetShapesMap() const;
53
57 void UpdateAllViews();
58
59 // abstract methods
64 virtual void CreateShapes(int viewId, Shapes& result) = 0;
65
66private:
67 ShapesMap m_shapesMap;
68 bool m_isSlaveShown;
69
70 I_REF(IViewExtender, m_slaveExtenderCompPtr);
71 I_ATTR(int, m_sceneExtenderModeAttrPtr);
72 I_MULTIATTR(int, m_idFiltersAttrPtr);
73};
74
75
76// public methods
77
78template <class Base>
80: m_isSlaveShown(false)
81{
82}
83
84
85// reimplemented (iqt2d::IViewExtender)
86
87template <class Base>
89{
90 Q_ASSERT(providerPtr != NULL);
91
92 int viewId = providerPtr->GetViewId();
93 iview::IShapeView* viewPtr = providerPtr->GetView();
94
95 bool showOwnShapes = true;
96 bool showSlaveShapes = true;
97
98 switch (*m_sceneExtenderModeAttrPtr){
99 case EM_SLAVE_DIRECT_ONLY:
100 showSlaveShapes = ((flags & SF_DIRECT) != 0);
101 break;
102
103 case EM_OWN_SHAPES_INDIRECT:
104 showOwnShapes = ((flags & SF_DIRECT) == 0);
105 break;
106
107 case EM_SLAVE_DIRECT_ONLY_OWN_SHAPES_INDIRECT:
108 showOwnShapes = ((flags & SF_DIRECT) == 0);
109 showSlaveShapes = ((flags & SF_DIRECT) != 0);
110 break;
111
112 default:
113 break;
114 };
115
116
117 if ( showOwnShapes &&
118 (viewPtr != NULL) &&
119 IsViewIdSupported(viewId) &&
120 (m_shapesMap.find(providerPtr) == m_shapesMap.end())){
121 Shapes& shapes = m_shapesMap[providerPtr];
122
123 bool isBackground = ((flags & SF_BACKGROUND) != 0);
124 CreateShapes(viewId, shapes);
125
126 int shapesCount = shapes.GetCount();
127 for (int i = 0; i < shapesCount; ++i){
128 iview::IShape* shapePtr = shapes.GetAt(i);
129 if (shapePtr != NULL){
130 // If the shape should be placed in the scene background
131 // and is not already a background shape, move it to inactive layer:
132 if (isBackground && (shapePtr->GetLayerType() != iview::IViewLayer::LT_BACKGROUND)){
133 iview::CShapeBase* shapeImplPtr = dynamic_cast<iview::CShapeBase*>(shapePtr);
134 if (shapeImplPtr != NULL){
136 }
137 }
138
139 viewPtr->ConnectShape(shapePtr);
140 }
141 }
142 }
143
144 if (showSlaveShapes && m_slaveExtenderCompPtr.IsValid()){
145 m_slaveExtenderCompPtr->AddItemsToScene(providerPtr, (flags | SF_BACKGROUND) & ~SF_DIRECT);
146
147 m_isSlaveShown = true;
148 }
149 else{
150 m_isSlaveShown = false;
151 }
152}
153
154
155template <class Base>
157{
158 Q_ASSERT(providerPtr != NULL);
159
160 if (m_isSlaveShown){
161 Q_ASSERT(m_slaveExtenderCompPtr.IsValid());
162
163 m_slaveExtenderCompPtr->RemoveItemsFromScene(providerPtr);
164 }
165
166 ShapesMap::iterator iter = m_shapesMap.find(providerPtr);
167 if (iter != m_shapesMap.end()){
168 iview::IShapeView* viewPtr = providerPtr->GetView();
169
170 if (viewPtr != NULL){
171 Shapes& shapes = iter.value();
172
173 int shapesCount = shapes.GetCount();
174 for (int i = 0; i < shapesCount; ++i){
175 iview::IShape* shapePtr = shapes.GetAt(i);
176 if (shapePtr != NULL){
177 viewPtr->DisconnectShape(shapePtr);
178 }
179 }
180 }
181
182 m_shapesMap.erase(iter);
183 }
184}
185
186
187// protected methods
188
189template <class Base>
191{
192 if (m_idFiltersAttrPtr.IsValid()){
193 int filtersCount = m_idFiltersAttrPtr.GetCount();
194 for (int i = 0; i < filtersCount; ++i){
195 int filterId = m_idFiltersAttrPtr[i];
196 if (viewId == filterId){
197 return true;
198 }
199 }
200
201 return false;
202 }
203
204 return true;
205}
206
207
208template <class Base>
210{
211 return m_shapesMap;
212}
213
214
215template <class Base>
217{
218 for (ShapesMap::iterator index = m_shapesMap.begin(); index != m_shapesMap.end(); ++index){
219 IViewProvider* viewProvderPtr = index.key();
220 Q_ASSERT(viewProvderPtr != NULL);
221
222 iview::IShapeView* viewPtr = viewProvderPtr->GetView();
223 Q_ASSERT(viewPtr != NULL);
224
225 viewPtr->Update();
226 }
227}
228
229
230} // namespace iqt2d
231
232
233
234
Interface for GUI objects presenting its results using extern view objects.
Interface for GUI objects managing view.
virtual iview::IShapeView * GetView() const =0
Called when items should be removed from specified view.
virtual int GetViewId() const =0
Get ID indentifing this view.
virtual void RemoveItemsFromScene(IViewProvider *providerPtr) override
Called when items should be removed from specified scene.
bool IsViewIdSupported(int viewId) const
void UpdateAllViews()
It calls Update for all used views.
istd::TPointerVector< iview::IShape > Shapes
virtual void CreateShapes(int viewId, Shapes &result)=0
Create shapes for the view.
QMap< IViewProvider *, Shapes > ShapesMap
virtual void AddItemsToScene(IViewProvider *providerPtr, int flags) override
Called when items should be added to specified scene.
const ShapesMap & GetShapesMap() const
Implementation of a pointer container, which controls the live cycle of the pointer object.
Pointer * GetAt(int index) const
Get pointer at specified index.
int GetCount() const
Get number of stored elements.
virtual bool AssignToLayer(int layerType)
Assign this shape to same layer.
Common interface for all display console shapes.
Definition IShape.h:32
virtual int GetLayerType() const =0
Get layer type of this shape object.
virtual bool DisconnectShape(IShape *shapePtr)=0
Disconnect shape object from view.
Common interface for a general shape view implementations.
Definition IShapeView.h:30
virtual bool ConnectShape(IShape *shapePtr)=0
Connect shape object to view.
virtual void Update()=0
Updates all invalidates shapes.
@ LT_BACKGROUND
Background layer.
Definition IViewLayer.h:39
@ LT_INACTIVE
Layer with inactive shapes.
Definition IViewLayer.h:44
#define NULL
Definition istd.h:74
This package contains Qt based implementations for 2D graphic objects.