ACF $AcfVersion:0$
CViewBase.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
6#include <i2d/CRectangle.h>
7
8#include <iview/IDraggable.h>
11#include <iview/CViewLayer.h>
13#include <istd/TSmartPtr.h>
14
15
16class QPainter;
17
18
19namespace iview
20{
21
22
23class IViewEventObserver;
24class ISelectableLayer;
25class IInteractiveShape;
26
27
29 virtual public IShapeView,
30 virtual public IDraggable,
31 protected IMouseActionObserver
32{
33public:
44
46 virtual ~CViewBase();
47
48
50
54 void CenterTo(const iview::IShape& shape);
55
59 int GetBackgroundLayerIndex() const;
60
64 int GetInactiveLayerIndex() const;
65
69 int GetActiveLayerIndex() const;
70
71 // reimplemented (iview::IShapeView)
72 virtual void AddViewEventObserver(iview::IViewEventObserver* listenerPtr) override;
73 virtual void RemoveViewEventObserver(iview::IViewEventObserver* listenerPtr) override;
74 virtual void SetZoom(ZoomMode zoom);
75 virtual void SetEditMode(int mode) override;
76 virtual void SetDisplayMode(int mode) override;
77 virtual void Update() override;
78 virtual void UpdateAllShapes(const istd::IChangeable::ChangeSet& changeSet);
79 virtual void SetScreenPosition(const i2d::CVector2d& client, istd::CIndex2d screen);
80 virtual const i2d::CRectangle& GetFitArea() const;
81 virtual void SetFitArea(const i2d::CRectangle& area) override;
82 virtual void SetViewDraggable(bool state = true);
83 virtual void SetMultiselectable(bool state = true);
84 virtual void SetDraggable(bool state = true);
85 virtual void InsertDefaultLayers();
86 virtual bool IsViewDraggable() const override;
87 virtual bool IsMultiselectable() const override;
88 virtual int InsertLayer(IViewLayer* layerPtr, int index = -1, int layerType = IViewLayer::LT_NONE) override;
89 virtual int GetLayerIndex(const IViewLayer& layer) const override;
90 virtual int GetLayerIndex(int layerType) const override;
91 virtual void RemoveLayer(int index) override;
92 virtual int GetLayersCount() const override;
93 virtual IViewLayer& GetLayer(int index) const override;
94 virtual bool ConnectShape(IShape* shapePtr) override;
95 virtual ISelectableLayer* GetFocusedLayerPtr() const override;
96 virtual void OnLayerShapeFocused(IInteractiveShape* shapePtr, ISelectableLayer* layerPtr) override;
97 virtual void OnLayerShapeDefocused(IInteractiveShape* shapePtr, ISelectableLayer* layerPtr) override;
98 virtual void OnLayerInvalidated(const IViewLayer& layer, const i2d::CRect& prevArea, const i2d::CRect& newArea) override;
99
100 // reimplemented (iview::ISelectable)
101 virtual int GetSelectedShapesCount() const override;
102 virtual void InsertSelectedShapes(SelectedShapes& result) const override;
103 virtual void DeselectAllShapes() override;
104 virtual int GetKeysState() const override;
105 virtual int GetEditMode() const override;
106 virtual int GetDisplayMode() const override;
107 virtual void OnShapeFocused(IInteractiveShape* /*shapePtr*/) override {}
108 virtual void OnShapeDefocused(IInteractiveShape* /*shapePtr*/) override {}
109
110 // reimplemented (iview::ITouchable)
111 virtual TouchState IsTouched(istd::CIndex2d position) const override;
112 virtual QString GetShapeDescriptionAt(istd::CIndex2d position) const override;
113 virtual QString GetToolTipAt(istd::CIndex2d) const override;
114
115 // reimplemented (iview::IShapeView)
116 virtual void SetTransform(const i2d::CAffine2d& transform) override;
117 virtual void UpdateMousePointer() override;
118
119 // reimplemented (iview::IMouseActionObserver)
120 virtual bool OnMouseButton(istd::CIndex2d position, Qt::MouseButton buttonType, bool downFlag) override;
121 virtual bool OnMouseMove(istd::CIndex2d position) override;
122
123 // reimplemented (iview::IDisplay)
124 virtual IDisplay* GetParentDisplayPtr() const override;
125 virtual const iview::CScreenTransform& GetTransform() const override;
126 virtual i2d::CRect GetBoundingBox() const override;
127 virtual const IColorSchema& GetColorSchema() const override;
128 virtual void OnAreaInvalidated(const i2d::CRect& prevArea, const i2d::CRect& newArea) override;
129
130 // reimplemented (iview::IShapeObserver)
131 virtual void OnChangeShape(IShape* shapePtr) override;
132 virtual bool DisconnectShape(IShape* shapePtr) override;
133 virtual void OnShapeSelected(IInteractiveShape& shape, bool state = true) override;
134
135 // reimplemented (iview::IDraggable)
136 virtual bool IsDraggable() const override;
137 virtual void BeginDrag(const istd::CIndex2d& reference) override;
138 virtual void SetDragPosition(const istd::CIndex2d& position) override;
139 virtual void EndDrag() override;
140
141 // abstract methods
142 virtual const IColorSchema& GetDefaultColorSchema() const = 0;
143
144protected:
145 typedef QVector<IViewLayer*> Layers;
146
153 virtual void DrawLayers(QPainter& drawContext, int firstLayer, int lastLayer);
154
158 int GetLastBackgroundLayerIndex() const;
159 void SetLastBackgroundLayerIndex(int index);
160
166 virtual bool CanBeMoved() const;
167
172
177 virtual void InvalidateBackground();
178
182 virtual void InvalidateBoundingBox();
183
189
195
199 virtual void OnBoundingBoxChanged();
200
205
209 virtual bool IsBackgroundBufferValid() const;
210
214 virtual void SetBackgroundBufferValid(bool state = true);
215
219 const i2d::CRect& GetInvalidatedBox() const;
220
225 void InvalidateBox(const i2d::CRect& rect);
226
230 void ResetInvalidatedBox();
231
235 void SetKeysState(int state);
236
237 const Layers& GetLayers() const;
238 Layers& GetLayers();
239
240 // abstract methods
241
246 virtual void SetMousePointer(MousePointerMode mode) = 0;
247
251 virtual void UpdateRectArea(const i2d::CRect& rect) = 0;
252
253protected:
260
262
264
269
273
274 QVector<iview::IViewEventObserver*> m_viewListeners;
275
280
283
285
287
288 // default layers
292
294
295 // help objects
297 mutable int m_keysState;
300
303
304 mutable bool m_blockBBoxEvent;
305};
306
307
308// inline methods
309
314
315
317{
318 m_transformPtr = screenTransformPtr;
319}
320
321
322// reimplemented (iview::IShapeView)
323
325{
326 return m_fitArea;
327}
328
329
331{
332 m_fitArea = area;
333}
334
335
336inline void CViewBase::SetViewDraggable(bool state)
337{
338 m_isViewDraggable = state;
339}
340
341
342inline void CViewBase::SetMultiselectable(bool state)
343{
344 m_isMultiselectable = state;
345}
346
347
348inline void CViewBase::SetDraggable(bool state)
349{
350 m_isDraggable = state;
351}
352
353
354inline bool CViewBase::IsViewDraggable() const
355{
356 return m_isViewDraggable;
357}
358
359
361{
362 return m_isMultiselectable;
363}
364
365
367{
368 return int(m_layers.size());
369}
370
371
372inline IViewLayer& CViewBase::GetLayer(int index) const
373{
374 if (GetLayersCount() <= 0){
375 CViewBase* view = const_cast<CViewBase*> (this);
376 view->InsertDefaultLayers();
377 }
378
379 Q_ASSERT((index >= 0) && (index < int(m_layers.size())));
380
381 IViewLayer* layerPtr = m_layers[index];
382 Q_ASSERT(layerPtr != NULL);
383
384 return *layerPtr;
385}
386
387
388// reimplemented (iview::IDisplay)
389
391{
392 return NULL;
393}
394
395
397{
398 return *m_transformPtr.GetPtr();
399}
400
401
403{
404 const_cast<CViewBase*>(this)->EnsureBoundingBoxValid();
405
406 return m_boundingBox;
407}
408
409
411{
412 return GetDefaultColorSchema();
413}
414
415
416// reimplemented (iview::ISelectable)
417
418inline int CViewBase::GetKeysState() const
419{
420 return m_keysState;
421}
422
423
424// reimplemented (iview::IDraggable)
425
426inline bool CViewBase::IsDraggable() const
427{
428 return m_isDraggable;
429}
430
431
432// protected methods
433
438
439
441{
443}
444
445
447{
449}
450
451
453{
455}
456
457
459{
460 return m_activeLayerIndex;
461}
462
463
465{
467}
468
469
471{
472 if (state != m_isBackgroundBufferValid){
473 if (!state){
475 }
477 }
478}
479
480
482{
483 return m_invalidatedBox;
484}
485
486
487inline void CViewBase::InvalidateBox(const i2d::CRect& rect)
488{
490}
491
492
497
498
499inline void CViewBase::SetKeysState(int state)
500{
501 m_keysState = state;
502}
503
504
506{
507 return m_layers;
508}
509
510
512{
513 return m_layers;
514}
515
516
517} // namespace iview
518
519
520
521
This class defines an affine 2D-transformation.
Definition CAffine2d.h:18
Simple rectangle with integer bounds.
Definition CRect.h:22
void Union(const CRect &rect)
Calculate union of this and second rectangle and stores result in this object.
Definition CRect.h:495
void Reset()
Set all members to 0.
Definition CRect.h:488
Definition of rectangle area orthogonal to axis of coordination system.
Definition CRectangle.h:27
Definition of position or mathematical vector on 2D plane.
Definition CVector2d.h:29
Index implementation for addressing elements in 2D-space.
Definition CIndex2d.h:21
Set of change flags (its IDs).
Definition IChangeable.h:36
const Type * GetPtr() const
Get access to pointed object.
Definition TTransPtr.h:80
virtual int GetLayersCount() const override
Get count of layer in this view.
Definition CViewBase.h:366
i2d::CRect m_boundingBox
Definition CViewBase.h:301
virtual int GetLayerIndex(int layerType) const override
Get index of layer by type.
virtual bool ConnectShape(IShape *shapePtr) override
Connect shape object to view.
virtual bool IsViewDraggable() const override
Check if is draggable mode.
Definition CViewBase.h:354
int m_backgroundLayerIndex
Definition CViewBase.h:277
virtual MousePointerMode CalcMousePointer(istd::CIndex2d position) const
Calc mouse pointer for the given position.
virtual const IColorSchema & GetDefaultColorSchema() const =0
void InvalidateBox(const i2d::CRect &rect)
Invalidate rectangle screen area.
Definition CViewBase.h:487
virtual QString GetShapeDescriptionAt(istd::CIndex2d position) const override
Get description to shape at specified position.
virtual void SetEditMode(int mode) override
Changes the edit mode.
virtual void InvalidateBoundingBox()
Invalidate bounding box.
virtual void SetMousePointer(MousePointerMode mode)=0
Set mouse pointer.
virtual int GetKeysState() const override
Get state of system keys.
Definition CViewBase.h:418
virtual TouchState IsTouched(istd::CIndex2d position) const override
Check, if any shape is touched.
i2d::CVector2d m_moveReference
Definition CViewBase.h:268
virtual void EndDrag() override
Called after dragging.
bool m_isBoundingBoxValid
Definition CViewBase.h:302
virtual void DeselectAllShapes() override
Set all shapes to be deselected.
virtual IViewLayer & GetLayer(int index) const override
Get layer with the given index.
Definition CViewBase.h:372
void SetExternalScreenTransform(const istd::TSmartPtr< iview::CScreenTransform > &screenTransformPtr)
Definition CViewBase.h:316
virtual bool IsBackgroundBufferValid() const
Check if background buffer is valid.
Definition CViewBase.h:464
virtual bool OnMouseMove(istd::CIndex2d position) override
It is called, when mouse is moved.
virtual i2d::CRect CalcBoundingBox() const
Calculate bounding box of all shapes.
virtual i2d::CRect GetBoundingBox() const override
Get bounding box of all object in this display.
Definition CViewBase.h:402
int m_lastBackgroundLayerIndex
Definition CViewBase.h:284
virtual bool CanBeMoved() const
This method is internal used to check, if drag mode is allowed.
virtual void OnLayerInvalidated(const IViewLayer &layer, const i2d::CRect &prevArea, const i2d::CRect &newArea) override
Inform that layer was invalidated.
virtual ~CViewBase()
virtual void SetBackgroundBufferValid(bool state=true)
Set validate flag of background buffer.
Definition CViewBase.h:470
virtual void SetScreenPosition(const i2d::CVector2d &client, istd::CIndex2d screen)
ViewMode m_viewMode
Definition CViewBase.h:265
iview::CInteractiveViewLayer m_activeLayer
Definition CViewBase.h:291
virtual void OnShapeFocused(IInteractiveShape *) override
Called when shape get focus.
Definition CViewBase.h:107
virtual IDisplay * GetParentDisplayPtr() const override
Get parent object of this display.
Definition CViewBase.h:390
virtual const IColorSchema & GetColorSchema() const override
Get color schema.
Definition CViewBase.h:410
const i2d::CRect & GetInvalidatedBox() const
Get bounding box of all invalidated rectangles.
Definition CViewBase.h:481
bool m_isLastMouseButtonDown
Definition CViewBase.h:296
int GetBackgroundLayerIndex() const
Get index of default background layer.
Definition CViewBase.h:446
void DisconnectAllShapes()
Disconnect all shapes from this view.
virtual void OnAreaInvalidated(const i2d::CRect &prevArea, const i2d::CRect &newArea) override
Invalidate display area.
virtual bool IsDraggable() const override
Check if drag is enabled.
Definition CViewBase.h:426
virtual bool OnMouseButton(istd::CIndex2d position, Qt::MouseButton buttonType, bool downFlag) override
It is called, when mouse button is pushed down or up on this object.
iview::IMouseActionObserver * m_mouseActionObserverPtr
Definition CViewBase.h:286
int GetLastBackgroundLayerIndex() const
Get last background layer index.
Definition CViewBase.h:434
virtual int InsertLayer(IViewLayer *layerPtr, int index=-1, int layerType=IViewLayer::LT_NONE) override
Insert layer to view.
virtual void OnLayerShapeDefocused(IInteractiveShape *shapePtr, ISelectableLayer *layerPtr) override
Called when shape in layer loose focus.
iview::CViewLayer m_backgroundLayer
Definition CViewBase.h:289
virtual void SetDragPosition(const istd::CIndex2d &position) override
Set new drag position.
virtual void OnBoundingBoxChanged()
Called when bounding box has been changed.
virtual ISelectableLayer * GetFocusedLayerPtr() const override
Get focused layer.
Definition CViewBase.h:310
int GetActiveLayerIndex() const
Get index of default active layer.
Definition CViewBase.h:458
virtual int GetDisplayMode() const override
Get actual display mode.
virtual void SetViewDraggable(bool state=true)
Definition CViewBase.h:336
virtual void SetTransform(const i2d::CAffine2d &transform) override
Set a screen transformation.
virtual bool IsMultiselectable() const override
Check, if it is possible to select more than one shape.
Definition CViewBase.h:360
virtual void SetDisplayMode(int mode) override
Changes the display mode.
virtual void InvalidateBackground()
Invalidate whole background buffer.
void CenterTo(const iview::IShape &shape)
Zooms the view to the given shape.
bool m_isBackgroundBufferValid
Definition CViewBase.h:261
virtual void AddViewEventObserver(iview::IViewEventObserver *listenerPtr) override
Add/remove external event observers.
virtual void SetFitArea(const i2d::CRectangle &area) override
Set area used for fitting of the view contents.
Definition CViewBase.h:330
virtual void Update() override
Updates all invalidates shapes.
virtual int GetSelectedShapesCount() const override
Get count of selected shapes.
virtual bool DisconnectShape(IShape *shapePtr) override
Disconnect shape object from view.
bool m_isSelectEventActive
Definition CViewBase.h:299
ISelectableLayer * m_focusedLayerPtr
Definition CViewBase.h:276
virtual void UpdateAllShapes(const istd::IChangeable::ChangeSet &changeSet)
virtual int GetEditMode() const override
Get actual edit mode.
virtual void UpdateMousePointer() override
Update mouse pointer.
virtual void BeginDrag(const istd::CIndex2d &reference) override
Called before dragging is begin.
virtual int GetLayerIndex(const IViewLayer &layer) const override
Get index of layer.
virtual void OnShapeDefocused(IInteractiveShape *) override
Called when shape loose focus.
Definition CViewBase.h:108
virtual const i2d::CRectangle & GetFitArea() const
Definition CViewBase.h:324
i2d::CRectangle m_fitArea
Definition CViewBase.h:282
virtual void InsertDefaultLayers()
const Layers & GetLayers() const
Definition CViewBase.h:505
virtual QString GetToolTipAt(istd::CIndex2d) const override
Get tooltip at specified position.
virtual void SetZoom(ZoomMode zoom)
void SetLastBackgroundLayerIndex(int index)
Definition CViewBase.h:440
virtual void UpdateRectArea(const i2d::CRect &rect)=0
Start updating specified rectangle area.
void ResetInvalidatedBox()
Reset invalidated box.
Definition CViewBase.h:493
istd::CIndex2d m_lastMousePosition
Definition CViewBase.h:298
virtual void InsertSelectedShapes(SelectedShapes &result) const override
Get set of selected shapes.
virtual void OnShapeSelected(IInteractiveShape &shape, bool state=true) override
It is called after change shape selection state.
QVector< iview::IViewEventObserver * > m_viewListeners
Definition CViewBase.h:274
virtual void OnChangeShape(IShape *shapePtr) override
Invalidate a shape.
istd::TSmartPtr< iview::CScreenTransform > m_transformPtr
Definition CViewBase.h:263
int GetInactiveLayerIndex() const
Get index of default inactive layer.
Definition CViewBase.h:452
iview::CViewLayer m_inactiveLayer
Definition CViewBase.h:290
virtual const iview::CScreenTransform & GetTransform() const override
Return a screen transformation.
Definition CViewBase.h:396
bool m_isMultiselectable
Definition CViewBase.h:270
virtual void SetDraggable(bool state=true)
Definition CViewBase.h:348
virtual void OnLayerShapeFocused(IInteractiveShape *shapePtr, ISelectableLayer *layerPtr) override
Called when shape in layer get focus.
i2d::CRect m_invalidatedBox
Definition CViewBase.h:281
virtual void RemoveViewEventObserver(iview::IViewEventObserver *listenerPtr) override
virtual void SetMultiselectable(bool state=true)
Definition CViewBase.h:342
virtual void RemoveLayer(int index) override
Remove layer from view.
bool EnsureBoundingBoxValid()
Calculate bounding box if it was invalid.
void SetKeysState(int state)
Set state of keys.
Definition CViewBase.h:499
QVector< IViewLayer * > Layers
Definition CViewBase.h:145
virtual void DrawLayers(QPainter &drawContext, int firstLayer, int lastLayer)
Draw Background layer.
Standard implementation of view layer.
Definition CViewLayer.h:22
Defines set of standard pens, brushes and simple management of unions.
virtual i2d::CRect GetClientRect() const =0
Get bounding box of client area.
Common interface for all, you can drag.
Definition IDraggable.h:18
Common interface for all display console shapes which can interacts with user.
Common interface for all shapes which are mouse events receiver.
QSet< IInteractiveShape * > SelectedShapes
Definition ISelectable.h:23
MousePointerMode
Defines possible states of mouse pointer.
Definition ISelectable.h:29
Common interface for all display console shapes.
Definition IShape.h:32
Common interface for a general shape view implementations.
Definition IShapeView.h:30
TouchState
Enumeration for possible shape touch states.
Definition ITouchable.h:25
Interface for external view event observer.
Interface for a logical layer in the console view.
Definition IViewLayer.h:27
@ LT_NONE
Layer type is not set.
Definition IViewLayer.h:34
#define NULL
Definition istd.h:74
In this library is defined 2D view concept and standard visualisation objects.