KD Chart 2  [rev.2.7]
kdganttgraphicsitem.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2020 Klaralvdalens Datakonsult AB. All rights reserved.
3 **
4 ** This file is part of the KD Chart library.
5 **
6 ** Licensees holding valid commercial KD Chart licenses may use this file in
7 ** accordance with the KD Chart Commercial License Agreement provided with
8 ** the Software.
9 **
10 **
11 ** This file may be distributed and/or modified under the terms of the
12 ** GNU General Public License version 2 and version 3 as published by the
13 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included.
14 **
15 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 **
18 ** Contact info@kdab.com if any conditions of this licensing are not
19 ** clear to you.
20 **
21 **********************************************************************/
22 
23 #ifndef KDGANTTGRAPHICSITEM_H
24 #define KDGANTTGRAPHICSITEM_H
25 
26 #include "kdganttglobal.h"
28 
29 #include <QGraphicsItem>
30 #include <QDateTime>
31 #include <QPersistentModelIndex>
32 
33 QT_BEGIN_NAMESPACE
34 class QGraphicsLineItem;
35 QT_END_NAMESPACE
36 
37 namespace KDGantt {
38  class GraphicsScene;
39  class ConstraintGraphicsItem;
40 
41  /* Can we fit every kind of item into one gfxitem class? */
42  class GraphicsItem : public QGraphicsItem {
43  public:
44  enum { Type = UserType + 42 };
45 
46  explicit GraphicsItem( QGraphicsItem* parent = 0, GraphicsScene* scene = 0 );
47  explicit GraphicsItem( const QModelIndex& idx, QGraphicsItem* parent = 0, GraphicsScene* scene = 0 );
48  ~GraphicsItem() override;
49 
50  /*reimp*/int type() const override;
51  /*reimp (non-virtual)*/ GraphicsScene* scene() const;
52 
53  void updateItem( const Span& rowgeometry, const QPersistentModelIndex& idx );
54 
55  //virtual ItemType itemType() const = 0;
56 
57  //qreal dateTimeToSceneX( const QDateTime& dt ) const;
58  //QDateTime sceneXtoDateTime( qreal x ) const;
59 
60  QRectF rect() const { return m_rect; }
61  void setRect( const QRectF& r );
62  void setBoundingRect( const QRectF& r );
63 
64  virtual QString ganttToolTip() const;
65 
66  const QPersistentModelIndex& index() const { return m_index; }
67  void setIndex( const QPersistentModelIndex& idx );
68 
69  bool isEditable() const;
70  bool isUpdating() const { return m_isupdating; }
71 
76  QList<ConstraintGraphicsItem*> startConstraints() const { return m_startConstraints; }
77  QList<ConstraintGraphicsItem*> endConstraints() const { return m_endConstraints; }
78 
79  /*reimp*/ QRectF boundingRect() const override;
80  /*reimp*/ void paint( QPainter* painter, const QStyleOptionGraphicsItem* option,
81  QWidget* widget = 0 ) override;
82 
83  /*reimp*/ QVariant itemChange( GraphicsItemChange, const QVariant& value ) override;
84  protected:
85  /*reimp*/ void focusInEvent( QFocusEvent* event ) override;
86  /*reimp*/ void hoverMoveEvent( QGraphicsSceneHoverEvent* ) override;
87  /*reimp*/ void hoverLeaveEvent( QGraphicsSceneHoverEvent* ) override;
88  /*reimp*/ void mousePressEvent( QGraphicsSceneMouseEvent* ) override;
89  /*reimp*/ void mouseReleaseEvent( QGraphicsSceneMouseEvent* ) override;
90  /*reimp*/ void mouseDoubleClickEvent( QGraphicsSceneMouseEvent* ) override;
91  /*reimp*/ void mouseMoveEvent( QGraphicsSceneMouseEvent* ) override;
92 
93  private:
94  void init();
95 
96  QPointF startConnector( int relationType ) const;
97  QPointF endConnector( int relationType ) const;
98  void updateConstraintItems();
99  StyleOptionGanttItem getStyleOption() const;
100  void updateModel();
101  void updateItemFromMouse( const QPointF& scenepos );
102  void constraintsChanged();
103 
104  QRectF m_rect;
105  QRectF m_boundingrect;
106  QPersistentModelIndex m_index;
107  bool m_isupdating;
108  int m_istate;
109  QPointF m_presspos;
110  QPointF m_pressscenepos;
111  QGraphicsLineItem* m_dragline;
112  GraphicsItem* m_dragtarget; //TODO: not used. remove it
113  QList<ConstraintGraphicsItem*> m_startConstraints;
114  QList<ConstraintGraphicsItem*> m_endConstraints;
115  };
116 }
117 
118 #endif /* KDGANTTGRAPHICSITEM_H */
void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override
void setRect(const QRectF &r)
virtual QString ganttToolTip() const
void mousePressEvent(QGraphicsSceneMouseEvent *) override
GraphicsItem(QGraphicsItem *parent=0, GraphicsScene *scene=0)
void updateItem(const Span &rowgeometry, const QPersistentModelIndex &idx)
QRectF boundingRect() const override
void addStartConstraint(ConstraintGraphicsItem *)
const QPersistentModelIndex & index() const
QVariant itemChange(GraphicsItemChange, const QVariant &value) override
void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override
A class representing a start point and a length.
void hoverMoveEvent(QGraphicsSceneHoverEvent *) override
void focusInEvent(QFocusEvent *event) override
void setBoundingRect(const QRectF &r)
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) override
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0) override
QStyleOption subclass for gantt items.
void removeStartConstraint(ConstraintGraphicsItem *)
int type() const override
QList< ConstraintGraphicsItem * > endConstraints() const
void addEndConstraint(ConstraintGraphicsItem *)
void setIndex(const QPersistentModelIndex &idx)
GraphicsScene * scene() const
Class only listed here to document inheritance of some KDChart classes.
QList< ConstraintGraphicsItem * > startConstraints() const
void removeEndConstraint(ConstraintGraphicsItem *)
void mouseMoveEvent(QGraphicsSceneMouseEvent *) override

Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/

https://www.kdab.com/development-resources/qt-tools/kd-chart/