KD Chart 2  [rev.2.7]
kdganttdatetimegrid.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 KDGANTTDATETIMEGRID_H
24 #define KDGANTTDATETIMEGRID_H
25 
26 #include "kdganttabstractgrid.h"
27 
28 #include <QDateTime>
29 #include <QSet>
30 
31 namespace KDGantt {
32 
33  class DateTimeScaleFormatter;
34 
35  class KDGANTT_EXPORT DateTimeGrid : public AbstractGrid
36  {
37  Q_OBJECT
39  public:
40  enum Scale {
46  ScaleUserDefined
47  };
48 
49  DateTimeGrid();
50  ~DateTimeGrid() override;
51 
52  QDateTime startDateTime() const;
53  void setStartDateTime( const QDateTime& dt );
54 
55  qreal dayWidth() const;
56  void setDayWidth( qreal );
57 
58  qreal mapFromDateTime( const QDateTime& dt) const;
59  QDateTime mapToDateTime( qreal x ) const;
60 
61  void setWeekStart( Qt::DayOfWeek );
62  Qt::DayOfWeek weekStart() const;
63 
64  void setFreeDays( const QSet<Qt::DayOfWeek>& fd );
65  QSet<Qt::DayOfWeek> freeDays() const;
66 
67  void setFreeDaysBrush(const QBrush brush);
68  QBrush freeDaysBrush() const;
69 
70  void setScale( Scale s );
71  Scale scale() const;
72 
73  void setUserDefinedLowerScale( DateTimeScaleFormatter* lower );
74  void setUserDefinedUpperScale( DateTimeScaleFormatter* upper );
75  DateTimeScaleFormatter* userDefinedLowerScale() const;
76  DateTimeScaleFormatter* userDefinedUpperScale() const;
77 
78  bool rowSeparators() const;
79  void setRowSeparators( bool enable );
80 
81  void setNoInformationBrush( const QBrush& brush );
82  QBrush noInformationBrush() const;
83 
84  /*reimp*/ Span mapToChart( const QModelIndex& idx ) const override;
85  /*reimp*/ bool mapFromChart( const Span& span, const QModelIndex& idx,
86  const QList<Constraint>& constraints=QList<Constraint>() ) const override;
87  /*reimp*/ qreal mapToChart( const QVariant& value ) const override;
88  /*reimp*/ QVariant mapFromChart( qreal x ) const override;
89  /*reimp*/ void paintGrid( QPainter* painter,
90  const QRectF& sceneRect, const QRectF& exposedRect,
91  AbstractRowController* rowController = 0,
92  QWidget* widget=0 ) override;
93  /*reimp*/ void paintHeader( QPainter* painter,
94  const QRectF& headerRect, const QRectF& exposedRect,
95  qreal offset, QWidget* widget=0 ) override;
96 
97  protected:
98  virtual void paintHourScaleHeader( QPainter* painter,
99  const QRectF& headerRect, const QRectF& exposedRect,
100  qreal offset, QWidget* widget=0 );
101  virtual void paintDayScaleHeader( QPainter* painter,
102  const QRectF& headerRect, const QRectF& exposedRect,
103  qreal offset, QWidget* widget=0 );
104  virtual void paintWeekScaleHeader( QPainter* painter,
105  const QRectF& headerRect, const QRectF& exposedRect,
106  qreal offset, QWidget* widget=0 );
107  virtual void paintMonthScaleHeader( QPainter* painter,
108  const QRectF& headerRect, const QRectF& exposedRect,
109  qreal offset, QWidget* widget=0 );
110 
111  virtual void paintUserDefinedHeader( QPainter* painter,
112  const QRectF& headerRect, const QRectF& exposedRect,
113  qreal offset, const DateTimeScaleFormatter* formatter,
114  QWidget* widget = 0 );
115 
116  virtual void drawDayBackground(QPainter* painter, const QRectF& rect, const QDate& date);
117  virtual void drawDayForeground(QPainter* painter, const QRectF& rect, const QDate& date);
118 
119  QRectF computeRect(const QDateTime& from, const QDateTime& to, const QRectF& rect) const;
120  QPair<QDateTime, QDateTime> dateTimeRange(const QRectF& rect) const;
121 
122  /* reimp */ void drawBackground(QPainter* paint, const QRectF& rect) override;
123  /* reimp */ void drawForeground(QPainter* paint, const QRectF& rect) override;
124  };
125 
126  class KDGANTT_EXPORT DateTimeScaleFormatter
127  {
129  public:
130  enum Range {
137  Year
138  };
139 
140  DateTimeScaleFormatter( Range range, const QString& formatString,
141  Qt::Alignment alignment = Qt::AlignCenter );
142  DateTimeScaleFormatter( Range range, const QString& formatString,
143  const QString& templ, Qt::Alignment alignment = Qt::AlignCenter );
145  virtual ~DateTimeScaleFormatter();
146 
147  DateTimeScaleFormatter& operator=( const DateTimeScaleFormatter& other );
148 
149  QString format() const;
150  Range range() const;
151  Qt::Alignment alignment() const;
152 
153  virtual QDateTime nextRangeBegin( const QDateTime& datetime ) const;
154  virtual QDateTime currentRangeBegin( const QDateTime& datetime ) const;
155 
156  QString format( const QDateTime& datetime ) const;
157  virtual QString text( const QDateTime& datetime ) const;
158  };
159 }
160 
161 
162 
163 #ifndef QT_NO_DEBUG_STREAM
164 QDebug KDGANTT_EXPORT operator<<( QDebug dbg, KDGantt::DateTimeScaleFormatter::Range );
165 #endif
166 
167 #endif /* KDGANTTDATETIMEGRID_H */
168 
#define KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC(X)
QDebug KDGANTT_EXPORT operator<<(QDebug dbg, KDGantt::DateTimeScaleFormatter::Range)
Abstract baseclass for grids. A grid is used to convert between QModelIndex&#39;es and gantt chart values...
A class representing a start point and a length.
#define KDGANTT_DECLARE_PRIVATE_DERIVED(X)
Definition: kdganttglobal.h:69
Class only listed here to document inheritance of some KDChart classes.
Abstract baseclass for row controllers. A row controller is used by the GraphicsView to nagivate the ...

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/