ICF 3.1.1.10
Technical documentation of ICF Libraries
CViewBase.h
Go to the documentation of this file.
1/********************************************************************************
2** This file is part of the ICF Framework. Copyright (C) Witold Gantzke & Kirill Lepskiy
3** ICF Framework may be used under the terms of the LGPL License v. 2.1 by the Free Software Foundation.
4********************************************************************************/
5
6#ifndef iview_CViewBase_included
7#define iview_CViewBase_included
8
9
10// ICF includes
11#include <i2d/CRectangle.h>
12
13#include <iview/IDraggable.h>
16#include <iview/CViewLayer.h>
18
19
20class QPainter;
21
22
23namespace iview
24{
25
26
27class IViewEventObserver;
28class ISelectableLayer;
29class IInteractiveShape;
30
31
33 virtual public IShapeView,
34 virtual public IDraggable,
35 protected IMouseActionObserver
36{
37public:
48
50 virtual ~CViewBase();
51
55 virtual void SetZoom(ZoomMode zoom);
56
60 virtual void SetEditMode(int mode);
61
65 virtual void UpdateAllShapes(const istd::IChangeable::ChangeSet& changeSet);
66
70 virtual void SetScreenPosition(const i2d::CVector2d& client, istd::CIndex2d screen);
71
76 virtual const i2d::CRectangle& GetFitArea() const;
77
82 virtual void SetFitArea(const i2d::CRectangle& area);
83
87 virtual void SetViewDraggable(bool state = true);
88
92 virtual void SetMultiselectable(bool state = true);
93
97 virtual void SetDraggable(bool state = true);
98
103
108
112 virtual void InsertDefaultLayers();
113
117 int GetBackgroundLayerIndex() const;
118
122 int GetInactiveLayerIndex() const;
123
127 int GetActiveLayerIndex() const;
128
134
136
137 // reimplemented (iview::IShapeView)
138 virtual void Update();
139 virtual bool IsViewDraggable() const;
140 virtual bool IsMultiselectable() const;
141 virtual int InsertLayer(IViewLayer* layerPtr, int index = -1, int layerType = IViewLayer::LT_NONE);
142 virtual int GetLayerIndex(const IViewLayer& layer) const;
143 virtual int GetLayerIndex(int layerType) const;
144 virtual void RemoveLayer(int index);
145 virtual int GetLayersCount() const;
146 virtual IViewLayer& GetLayer(int index) const;
147 virtual bool ConnectShape(IShape* shapePtr);
149 virtual void OnLayerShapeFocused(IInteractiveShape* shapePtr, ISelectableLayer* layerPtr);
150 virtual void OnLayerShapeDefocused(IInteractiveShape* shapePtr, ISelectableLayer* layerPtr);
151 virtual void OnLayerInvalidated(const IViewLayer& layer, const i2d::CRect& prevArea, const i2d::CRect& newArea);
152
153 // reimplemented (iview::ISelectable)
154 virtual int GetSelectedShapesCount() const;
155 virtual void InsertSelectedShapes(SelectedShapes& result) const;
156 virtual void DeselectAllShapes();
157 virtual int GetKeysState() const;
158 virtual int GetEditMode() const;
159 virtual void OnShapeFocused(IInteractiveShape* /*shapePtr*/) {}
160 virtual void OnShapeDefocused(IInteractiveShape* /*shapePtr*/) {}
161
162 // reimplemented (iview::ITouchable)
163 virtual TouchState IsTouched(istd::CIndex2d position) const;
164 virtual QString GetShapeDescriptionAt(istd::CIndex2d position) const;
165
166 // reimplemented (iview::IShapeView)
167 virtual void SetTransform(const i2d::CAffine2d& transform);
168 virtual void UpdateMousePointer();
169
170 // reimplemented (iview::IMouseActionObserver)
171 virtual bool OnMouseButton(istd::CIndex2d position, Qt::MouseButton buttonType, bool downFlag);
172 virtual bool OnMouseMove(istd::CIndex2d position);
173
174 // reimplemented (iview::IDisplay)
175 virtual IDisplay* GetParentDisplayPtr() const;
176 virtual const iview::CScreenTransform& GetTransform() const;
177 virtual i2d::CRect GetBoundingBox() const;
178 virtual const IColorSchema& GetColorSchema() const;
179 virtual void OnAreaInvalidated(const i2d::CRect& prevArea, const i2d::CRect& newArea);
180
181 // reimplemented (iview::IShapeObserver)
182 virtual void OnChangeShape(IShape* shapePtr);
183 virtual bool DisconnectShape(IShape* shapePtr);
184 virtual void OnShapeSelected(IInteractiveShape& shape, bool state = true);
185
186 // reimplemented (iview::IDraggable)
187 virtual bool IsDraggable() const;
188 virtual void BeginDrag(const istd::CIndex2d& reference);
189 virtual void SetDragPosition(const istd::CIndex2d& position);
190 virtual void EndDrag();
191
192 // abstract methods
193 virtual const IColorSchema& GetDefaultColorSchema() const = 0;
194
195protected:
196 typedef QVector<IViewLayer*> Layers;
197
204 virtual void DrawLayers(QPainter& drawContext, int firstLayer, int lastLayer);
205
210 void SetLastBackgroundLayerIndex(int index);
211
217 virtual bool CanBeMoved() const;
218
223
228 virtual void InvalidateBackground();
229
233 virtual void InvalidateBoundingBox();
239
248 virtual void OnBoundingBoxChanged();
249
251
255 virtual void InvalidateMouseShape();
256
260 virtual void CalcMouseShape() const;
261
265 virtual bool IsBackgroundBufferValid() const;
266
270 virtual void SetBackgroundBufferValid(bool state = true);
271
276 virtual int CalcShapeLayerIndex(const IShape& shape) const;
277
281 const i2d::CRect& GetInvalidatedBox() const;
282
287 void InvalidateBox(const i2d::CRect& rect);
288
292 void ResetInvalidatedBox();
293
297 void SetKeysState(int state);
298
299 const Layers& GetLayers() const;
300 Layers& GetLayers();
301
302 // abstract methods
303
308 virtual void SetMousePointer(MousePointerMode mode) = 0;
311 virtual void UpdateRectArea(const i2d::CRect& rect) = 0;
312
313private:
314 enum ViewMode
315 {
316 VM_NONE,
317 VM_DRAG,
318 VM_MOVE
319 };
320
321 bool m_isBackgroundBufferValid;
322
323 iview::CScreenTransform m_transform;
324
325 ViewMode m_viewMode;
326 int m_editMode;
327 i2d::CVector2d m_moveReference;
328
329 bool m_isMultiselectable;
330 bool m_isViewDraggable;
331 bool m_isDraggable;
332
333 QVector<iview::IViewEventObserver*> m_viewListeners;
334
335 ISelectableLayer* m_focusedLayerPtr;
336 int m_backgroundLayerIndex;
337 int m_activeLayerIndex;
338 int m_inactiveLayerIndex;
339
340 i2d::CRect m_invalidatedBox;
341 i2d::CRectangle m_fitArea;
342
343 Layers m_layers;
344
345 int m_lastBackgroundLayerIndex;
346
347 // default layers
348 iview::CViewLayer m_backgroundLayer;
349 iview::CViewLayer m_inactiveLayer;
350 iview::CInteractiveViewLayer m_activeLayer;
351
352 // help objects
353 bool m_isLastMouseButtonDown;
354 mutable int m_keysState;
355 mutable istd::CIndex2d m_lastMousePosition;
356 mutable bool m_isSelectEventActive;
357
358 i2d::CRect m_boundingBox;
359 bool m_isBoundingBoxValid;
360
361 mutable IInteractiveShape* m_mouseShapePtr;
362 mutable bool m_isMouseShapeValid;
363
364 mutable bool m_blockBBoxEvent;
365};
366
367
368// inline methods
369
371{
372 return m_fitArea;
373}
374
375
377{
378 m_fitArea = area;
379}
380
381
382inline void CViewBase::SetViewDraggable(bool state)
383{
384 m_isViewDraggable = state;
385}
386
387
388inline void CViewBase::SetMultiselectable(bool state)
389{
390 m_isMultiselectable = state;
391}
392
393
394inline void CViewBase::SetDraggable(bool state)
395{
396 m_isDraggable = state;
397}
398
399
401{
402 if (!m_isMouseShapeValid){
404 m_isMouseShapeValid = true;
405 }
406
407 return m_mouseShapePtr;
408}
409
410
411// reimplemented (iview::IShapeView)
412
413inline bool CViewBase::IsViewDraggable() const
414{
415 return m_isViewDraggable;
416}
417
418
420{
421 return m_isMultiselectable;
422}
423
424
426{
427 return int(m_layers.size());
428}
429
430
431inline IViewLayer& CViewBase::GetLayer(int index) const
432{
433 if (GetLayersCount() <= 0){
434 CViewBase* view = const_cast<CViewBase*> (this);
435 view->InsertDefaultLayers();
436 }
437
438 Q_ASSERT((index >= 0) && (index < int(m_layers.size())));
439
440 IViewLayer* layerPtr = m_layers[index];
441 Q_ASSERT(layerPtr != nullptr);
442
443 return *layerPtr;
444}
445
446
447// reimplemented (iview::IDisplay)
448
450{
451 return nullptr;
452}
453
454
456{
457 return m_transform;
458}
459
460
462{
463 const_cast<CViewBase*>(this)->EnsureBoundingBoxValid();
464
465 return m_boundingBox;
466}
467
468
470{
471 return GetDefaultColorSchema();
472}
473
474
475// reimplemented (iview::ISelectable)
476
477inline int CViewBase::GetKeysState() const
478{
479 return m_keysState;
480}
481
482
483// reimplemented (iview::IDraggable)
484
485inline bool CViewBase::IsDraggable() const
486{
487 return m_isDraggable;
488}
489
490
491// protected methods
492
494{
495 return m_lastBackgroundLayerIndex;
496}
497
498
500{
501 m_lastBackgroundLayerIndex = index;
502}
503
504
506{
507 return m_backgroundLayerIndex;
508}
509
510
512{
513 return m_inactiveLayerIndex;
514}
515
516
518{
519 return m_activeLayerIndex;
520}
521
522
524{
525 return m_isBackgroundBufferValid;
526}
527
528
530{
531 if (state != m_isBackgroundBufferValid){
532 if (!state){
533 m_invalidatedBox = GetClientRect();
534 }
535 m_isBackgroundBufferValid = state;
536 }
537}
538
539
541{
542 return m_invalidatedBox;
543}
544
545
546inline void CViewBase::InvalidateBox(const i2d::CRect& rect)
547{
548 m_invalidatedBox.Union(rect);
549}
550
551
553{
554 m_invalidatedBox.Reset();
555}
556
557
558inline void CViewBase::SetKeysState(int state)
559{
560 m_keysState = state;
561}
562
563
565{
566 return m_layers;
567}
568
569
571{
572 return m_layers;
573}
574
575
576} // namespace iview
577
578
579#endif // !iview_CViewBase_included
580
581
This class defines an affine 2D-transformation.
Definition CAffine2d.h:22
Simple rectangle with integer bounds.
Definition CRect.h:26
void Union(const CRect &rect)
Calculate union of this and second rectangle and stores result in this object.
Definition CRect.h:499
void Reset()
Set all members to 0.
Definition CRect.h:492
Definition of rectangle area orthogonal to axis of coordination system.
Definition CRectangle.h:31
Definition of position or mathematical vector on 2D plane.
Definition CVector2d.h:29
Index implementation for addressing elements in 2D-space.
Definition CIndex2d.h:25
Set of change flags (its IDs).
Definition IChangeable.h:38
virtual void SetEditMode(int mode)
Set edit mode.
virtual void OnAreaInvalidated(const i2d::CRect &prevArea, const i2d::CRect &newArea)
Invalidate display area.
virtual QString GetShapeDescriptionAt(istd::CIndex2d position) const
Get description to shape at specified position.
virtual int GetSelectedShapesCount() const
Get count of selected shapes.
virtual MousePointerMode CalcMousePointer(istd::CIndex2d position) const
virtual const IColorSchema & GetDefaultColorSchema() const =0
void InvalidateBox(const i2d::CRect &rect)
Invalidate rectangle screen area.
Definition CViewBase.h:546
virtual IViewLayer & GetLayer(int index) const
Get layer with the given index.
Definition CViewBase.h:431
virtual void InvalidateBoundingBox()
Invalidate bounding box.
virtual bool OnMouseButton(istd::CIndex2d position, Qt::MouseButton buttonType, bool downFlag)
It is called, when mouse button is pushed down or up on this object.
virtual void SetMousePointer(MousePointerMode mode)=0
Set mouse pointer.
virtual int GetLayersCount() const
Get count of layer in this view.
Definition CViewBase.h:425
virtual void OnShapeSelected(IInteractiveShape &shape, bool state=true)
It is called after change shape selection state.
virtual void OnLayerShapeFocused(IInteractiveShape *shapePtr, ISelectableLayer *layerPtr)
Called when shape in layer get focus.
IInteractiveShape * GetMouseShapePtr() const
Get shape under mouse pointer.
Definition CViewBase.h:400
virtual TouchState IsTouched(istd::CIndex2d position) const
Check, if any shape is touched.
virtual bool IsBackgroundBufferValid() const
Check if background buffer is valid.
Definition CViewBase.h:523
virtual IDisplay * GetParentDisplayPtr() const
Get parent object of this display.
Definition CViewBase.h:449
virtual i2d::CRect CalcBoundingBox() const
Calculate bounding box of all shapes.
virtual bool CanBeMoved() const
This method is internal used to check, if drag mode is allowed.
virtual int GetKeysState() const
Get state of system keys.
Definition CViewBase.h:477
virtual ~CViewBase()
virtual void SetBackgroundBufferValid(bool state=true)
Set validate flag of background buffer.
Definition CViewBase.h:529
virtual void SetScreenPosition(const i2d::CVector2d &client, istd::CIndex2d screen)
It sets position to become transformation of client point to specified screen position.
virtual void SetDragPosition(const istd::CIndex2d &position)
Set new drag position.
virtual ISelectableLayer * GetFocusedLayerPtr() const
Get focused layer.
virtual void OnChangeShape(IShape *shapePtr)
Invalidate a shape.
virtual void BeginDrag(const istd::CIndex2d &reference)
Called before dragging is begin.
virtual int InsertLayer(IViewLayer *layerPtr, int index=-1, int layerType=IViewLayer::LT_NONE)
Insert layer to view.
virtual void RemoveViewEventObserver(iview::IViewEventObserver *listenerPtr)
Removes handler to catch view events.
const i2d::CRect & GetInvalidatedBox() const
Get bounding box of all invalidated rectangles.
Definition CViewBase.h:540
virtual void UpdateMousePointer()
Update mouse pointer.
virtual void DeselectAllShapes()
Set all shapes to be deselected.
int GetBackgroundLayerIndex() const
Get index of default background layer.
Definition CViewBase.h:505
void DisconnectAllShapes()
Disconnect all shapes from this view.
virtual i2d::CRect GetBoundingBox() const
Get bounding box of all object in this display.
Definition CViewBase.h:461
virtual bool IsMultiselectable() const
Check, if it is possible to select more than one shape.
Definition CViewBase.h:419
virtual void OnBoundingBoxChanged()
Called when bounding box has been changed.
virtual bool IsViewDraggable() const
Check if is draggable mode.
Definition CViewBase.h:413
virtual void OnShapeFocused(IInteractiveShape *)
Called when shape get focus.
Definition CViewBase.h:159
virtual void SetTransform(const i2d::CAffine2d &transform)
Set a screen transformation.
int GetActiveLayerIndex() const
Get index of default active layer.
Definition CViewBase.h:517
virtual int CalcShapeLayerIndex(const IShape &shape) const
Calculate optimal layer index for some shape.
virtual void SetViewDraggable(bool state=true)
Turn on/off possibility to move whole view transform.
Definition CViewBase.h:382
virtual bool DisconnectShape(IShape *shapePtr)
Disconnect shape object from view.
virtual void InvalidateBackground()
Invalidate whole background buffer.
virtual int GetLayerIndex(const IViewLayer &layer) const
Get index of layer.
virtual void UpdateAllShapes(const istd::IChangeable::ChangeSet &changeSet)
Inform all shapes about changes.
virtual void CalcMouseShape() const
Calc shape under mouse pointer.
virtual void OnShapeDefocused(IInteractiveShape *)
Called when shape loose focus.
Definition CViewBase.h:160
virtual void InvalidateMouseShape()
Invalidate stored shape under mouse pointer.
virtual int GetEditMode() const
Get actual edit mode.
virtual const i2d::CRectangle & GetFitArea() const
Get area will be used to automatic fit the zoom to view size.
Definition CViewBase.h:370
int GetLastBackgroundLayerIndex()
Get last background layer index.
Definition CViewBase.h:493
virtual void InsertDefaultLayers()
Insert default layers, when there is no one user layer.
const Layers & GetLayers() const
Definition CViewBase.h:564
virtual const iview::CScreenTransform & GetTransform() const
Return a screen transformation.
Definition CViewBase.h:455
virtual void InsertSelectedShapes(SelectedShapes &result) const
Get set of selected shapes.
virtual const IColorSchema & GetColorSchema() const
Get color schema.
Definition CViewBase.h:469
virtual void SetZoom(ZoomMode zoom)
Set zoom.
void SetLastBackgroundLayerIndex(int index)
Definition CViewBase.h:499
IInteractiveShape * GetFirstActiveShape() const
QVector< IViewLayer * > Layers
Definition CViewBase.h:196
virtual bool OnMouseMove(istd::CIndex2d position)
It is called, when mouse is moved.
virtual void OnLayerShapeDefocused(IInteractiveShape *shapePtr, ISelectableLayer *layerPtr)
Called when shape in layer loose focus.
virtual void UpdateRectArea(const i2d::CRect &rect)=0
Start updating specified rectangle area.
virtual void SetFitArea(const i2d::CRectangle &area)
Set area will be used to fit in some zoom modes.
Definition CViewBase.h:376
virtual void OnLayerInvalidated(const IViewLayer &layer, const i2d::CRect &prevArea, const i2d::CRect &newArea)
Inform that layer was invalidated.
virtual int GetLayerIndex(int layerType) const
Get index of layer by type.
virtual void RemoveLayer(int index)
Remove layer from view.
virtual bool ConnectShape(IShape *shapePtr)
Connect shape object to view.
void ResetInvalidatedBox()
Reset invalidated box.
Definition CViewBase.h:552
int GetInactiveLayerIndex() const
Get index of default inactive layer.
Definition CViewBase.h:511
virtual bool IsDraggable() const
Check if drag is enabled.
Definition CViewBase.h:485
virtual void Update()
Updates all invalidates shapes.
virtual void SetDraggable(bool state=true)
Turn on/off possibility to move more selected shapes, when one is moved.
Definition CViewBase.h:394
virtual void EndDrag()
Called after dragging.
virtual void SetMultiselectable(bool state=true)
Turn on/off possibility to select more shapes using control keys.
Definition CViewBase.h:388
bool EnsureBoundingBoxValid()
Calculate bounding box if it was invalid.
void SetKeysState(int state)
Set state of keys.
Definition CViewBase.h:558
virtual void AddViewEventObserver(iview::IViewEventObserver *listenerPtr)
Adds handler to catch view events.
virtual void DrawLayers(QPainter &drawContext, int firstLayer, int lastLayer)
Draw Background layer.
Standard implementation of view layer.
Definition CViewLayer.h:27
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:23
Common interface for all display console shapes which can interacts with user.
Common interface for all shapes which are mouse events receiver.
MousePointerMode
Defines possible states of mouse pointer.
Definition ISelectable.h:35
QSet< IInteractiveShape * > SelectedShapes
Definition ISelectable.h:29
Common interface for all display console shapes.
Definition IShape.h:37
Common interface for a general shape view implementations.
Definition IShapeView.h:32
TouchState
Enumeration for possible shape touch states.
Definition ITouchable.h:30
Interface for external view event observer.
Interface for a logical layer in the console view.
Definition IViewLayer.h:32
@ LT_NONE
Layer type is not set.
Definition IViewLayer.h:39
In this library is defined 2D view concept and standard visualisation objects.

© Witold Gantzke and Kirill Lepskiy