KD Chart 2 [rev.2.4]

kdganttdatetimegrid.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** Copyright (C) 2001-2012 Klaralvdalens Datakonsult AB.  All rights reserved.
00003 **
00004 ** This file is part of the KD Chart library.
00005 **
00006 ** Licensees holding valid commercial KD Chart licenses may use this file in
00007 ** accordance with the KD Chart Commercial License Agreement provided with
00008 ** the Software.
00009 **
00010 **
00011 ** This file may be distributed and/or modified under the terms of the
00012 ** GNU General Public License version 2 and version 3 as published by the
00013 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included.
00014 **
00015 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00016 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00017 **
00018 ** Contact info@kdab.com if any conditions of this licensing are not
00019 ** clear to you.
00020 **
00021 **********************************************************************/
00022 
00023 #ifndef KDGANTTDATETIMEGRID_H
00024 #define KDGANTTDATETIMEGRID_H
00025 
00026 #include "kdganttabstractgrid.h"
00027 
00028 #include <QDateTime>
00029 #include <QSet>
00030 
00031 namespace KDGantt {
00032 
00033     class DateTimeScaleFormatter;
00034 
00035     class KDGANTT_EXPORT DateTimeGrid : public AbstractGrid
00036     {
00037         Q_OBJECT
00038         KDGANTT_DECLARE_PRIVATE_DERIVED( DateTimeGrid )
00039     public:
00040         enum Scale {
00041             ScaleAuto, 
00042             ScaleHour,
00043             ScaleDay,
00044             ScaleWeek,
00045             ScaleMonth,
00046             ScaleUserDefined
00047         };
00048         
00049         DateTimeGrid();
00050         virtual ~DateTimeGrid();
00051 
00052         QDateTime startDateTime() const;
00053         void setStartDateTime( const QDateTime& dt );
00054 
00055         qreal dayWidth() const;
00056         void setDayWidth( qreal );
00057 
00058         qreal mapFromDateTime( const QDateTime& dt) const;
00059         QDateTime mapToDateTime( qreal x ) const;
00060 
00061         void setWeekStart( Qt::DayOfWeek );
00062         Qt::DayOfWeek weekStart() const;
00063 
00064         void setFreeDays( const QSet<Qt::DayOfWeek>& fd );
00065         QSet<Qt::DayOfWeek> freeDays() const;
00066 
00067         void setFreeDaysBrush(const QBrush brush);
00068         QBrush freeDaysBrush() const;
00069 
00070         void setScale( Scale s );
00071         Scale scale() const;
00072 
00073         void setUserDefinedLowerScale( DateTimeScaleFormatter* lower );
00074         void setUserDefinedUpperScale( DateTimeScaleFormatter* upper );
00075         DateTimeScaleFormatter* userDefinedLowerScale() const;
00076         DateTimeScaleFormatter* userDefinedUpperScale() const;
00077 
00078         bool rowSeparators() const;
00079         void setRowSeparators( bool enable );
00080 
00081         void setNoInformationBrush( const QBrush& brush );
00082         QBrush noInformationBrush() const;
00083 
00084         /*reimp*/ Span mapToChart( const QModelIndex& idx ) const;
00085         /*reimp*/ bool mapFromChart( const Span& span, const QModelIndex& idx,
00086                                      const QList<Constraint>& constraints=QList<Constraint>() ) const;
00087         /*reimp*/ qreal mapToChart( const QVariant& value ) const;
00088         /*reimp*/ QVariant mapFromChart( qreal x ) const;
00089         /*reimp*/ void paintGrid( QPainter* painter, 
00090                                   const QRectF& sceneRect, const QRectF& exposedRect,
00091                                   AbstractRowController* rowController = 0,
00092                                   QWidget* widget=0 );
00093         /*reimp*/ void paintHeader( QPainter* painter, 
00094                                     const QRectF& headerRect, const QRectF& exposedRect,
00095                                     qreal offset, QWidget* widget=0 );
00096 
00097     protected:
00098         virtual void paintHourScaleHeader( QPainter* painter, 
00099                            const QRectF& headerRect, const QRectF& exposedRect,
00100                            qreal offset, QWidget* widget=0 );
00101         virtual void paintDayScaleHeader( QPainter* painter, 
00102                           const QRectF& headerRect, const QRectF& exposedRect,
00103                           qreal offset, QWidget* widget=0 );
00104         virtual void paintWeekScaleHeader( QPainter* painter,
00105                                            const QRectF& headerRect, const QRectF& exposedRect,
00106                                            qreal offset, QWidget* widget=0 );
00107         virtual void paintMonthScaleHeader( QPainter* painter,
00108                                             const QRectF& headerRect, const QRectF& exposedRect,
00109                                             qreal offset, QWidget* widget=0 );
00110 
00111         virtual void paintUserDefinedHeader( QPainter* painter, 
00112                                      const QRectF& headerRect, const QRectF& exposedRect, 
00113                                      qreal offset, const DateTimeScaleFormatter* formatter, 
00114                                      QWidget* widget = 0 );
00115 
00116         virtual void drawDayBackground(QPainter* painter, const QRectF& rect, const QDate& date);
00117         virtual void drawDayForeground(QPainter* painter, const QRectF& rect, const QDate& date);
00118         
00119         QRectF computeRect(const QDateTime& from, const QDateTime& to, const QRectF& rect) const;
00120         QPair<QDateTime, QDateTime> dateTimeRange(const QRectF& rect) const;
00121 
00122         /* reimp */ void drawBackground(QPainter* paint, const QRectF& rect);
00123         /* reimp */ void drawForeground(QPainter* paint, const QRectF& rect);
00124     };
00125 
00126     class KDGANTT_EXPORT DateTimeScaleFormatter
00127     {
00128         KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC( DateTimeScaleFormatter )
00129     public:
00130         enum Range {
00131             Second,
00132             Minute,
00133             Hour,
00134             Day,
00135             Week,
00136             Month,
00137             Year
00138         };
00139 
00140         DateTimeScaleFormatter( Range range, const QString& formatString,
00141                                 Qt::Alignment alignment = Qt::AlignCenter );
00142         DateTimeScaleFormatter( Range range, const QString& formatString,
00143                                 const QString& templ, Qt::Alignment alignment = Qt::AlignCenter );
00144         DateTimeScaleFormatter( const DateTimeScaleFormatter& other );
00145         virtual ~DateTimeScaleFormatter();
00146 
00147         DateTimeScaleFormatter& operator=( const DateTimeScaleFormatter& other );
00148 
00149         QString format() const;
00150         Range range() const;
00151         Qt::Alignment alignment() const;
00152 
00153         virtual QDateTime nextRangeBegin( const QDateTime& datetime ) const;
00154         virtual QDateTime currentRangeBegin( const QDateTime& datetime ) const;
00155 
00156         QString format( const QDateTime& datetime ) const;
00157         virtual QString text( const QDateTime& datetime ) const;
00158     };
00159 }
00160 
00161 #ifndef QT_NO_DEBUG_STREAM
00162 QDebug KDGANTT_EXPORT operator<<( QDebug dbg, KDGantt::DateTimeScaleFormatter::Range );
00163 #endif
00164 
00165 #endif /* KDGANTTDATETIMEGRID_H */
00166 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines

Klarälvdalens Datakonsult AB (KDAB)
Qt-related services and products
http://www.kdab.com/
http://www.kdab.com/products/kd-chart/