kdganttdatetimegrid.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** Copyright (C) 2001-2011 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 KDCHART_EXPORT DateTimeScaleFormatter
00034     {
00035         KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC( DateTimeScaleFormatter )
00036     public:
00037         enum Range {
00038             Second,
00039             Minute,
00040             Hour,
00041             Day,
00042             Week,
00043             Month,
00044             Year
00045         };
00046 
00047         DateTimeScaleFormatter( Range range, const QString& formatString, 
00048                                 Qt::Alignment alignment = Qt::AlignCenter );
00049         DateTimeScaleFormatter( Range range, const QString& formatString, 
00050                                 const QString& templ, Qt::Alignment alignment = Qt::AlignCenter );
00051         DateTimeScaleFormatter( const DateTimeScaleFormatter& other );
00052         virtual ~DateTimeScaleFormatter();
00053 
00054         DateTimeScaleFormatter& operator=( const DateTimeScaleFormatter& other );
00055 
00056         QString format() const;
00057         Range range() const;
00058         Qt::Alignment alignment() const;
00059 
00060         virtual QDateTime nextRangeBegin( const QDateTime& datetime ) const;
00061         virtual QDateTime currentRangeBegin( const QDateTime& datetime ) const;
00062 
00063         QString format( const QDateTime& datetime ) const;
00064         virtual QString text( const QDateTime& datetime ) const;
00065     };
00066 
00067     class KDCHART_EXPORT DateTimeGrid : public AbstractGrid
00068     {
00069         Q_OBJECT
00070         KDGANTT_DECLARE_PRIVATE_DERIVED( DateTimeGrid )
00071     public:
00072         enum Scale {
00073             ScaleAuto, 
00074             ScaleHour,
00075             ScaleDay,
00076             ScaleWeek,
00077             ScaleMonth,
00078             ScaleUserDefined
00079         };
00080         
00081         DateTimeGrid();
00082         virtual ~DateTimeGrid();
00083 
00084         QDateTime startDateTime() const;
00085         void setStartDateTime( const QDateTime& dt );
00086 
00087         qreal dayWidth() const;
00088         void setDayWidth( qreal );
00089 
00090         qreal mapFromDateTime( const QDateTime& dt) const;
00091         QDateTime mapToDateTime( qreal x ) const;
00092 
00093         void setWeekStart( Qt::DayOfWeek );
00094         Qt::DayOfWeek weekStart() const;
00095 
00096         void setFreeDays( const QSet<Qt::DayOfWeek>& fd );
00097         QSet<Qt::DayOfWeek> freeDays() const;
00098 
00099         void setFreeDaysBrush(const QBrush brush);
00100         QBrush freeDaysBrush() const;
00101 
00102         void setScale( Scale s );
00103         Scale scale() const;
00104 
00105         void setUserDefinedLowerScale( DateTimeScaleFormatter* lower );
00106         void setUserDefinedUpperScale( DateTimeScaleFormatter* upper );
00107         DateTimeScaleFormatter* userDefinedLowerScale() const;
00108         DateTimeScaleFormatter* userDefinedUpperScale() const;
00109 
00110         bool rowSeparators() const;
00111         void setRowSeparators( bool enable );
00112 
00113         void setNoInformationBrush( const QBrush& brush );
00114         QBrush noInformationBrush() const;
00115 
00116         /*reimp*/ Span mapToChart( const QModelIndex& idx ) const;
00117         /*reimp*/ bool mapFromChart( const Span& span, const QModelIndex& idx,
00118                                      const QList<Constraint>& constraints=QList<Constraint>() ) const;
00119         /*reimp*/ qreal mapToChart( const QVariant& value ) const;
00120         /*reimp*/ QVariant mapFromChart( qreal x ) const;
00121         /*reimp*/ void paintGrid( QPainter* painter, 
00122                                   const QRectF& sceneRect, const QRectF& exposedRect,
00123                                   AbstractRowController* rowController = 0,
00124                                   QWidget* widget=0 );
00125         /*reimp*/ void paintHeader( QPainter* painter, 
00126                                     const QRectF& headerRect, const QRectF& exposedRect,
00127                                     qreal offset, QWidget* widget=0 );
00128 
00129     protected:
00130         virtual void paintHourScaleHeader( QPainter* painter, 
00131                            const QRectF& headerRect, const QRectF& exposedRect,
00132                            qreal offset, QWidget* widget=0 );
00133         virtual void paintDayScaleHeader( QPainter* painter, 
00134                           const QRectF& headerRect, const QRectF& exposedRect,
00135                           qreal offset, QWidget* widget=0 );
00136         virtual void paintWeekScaleHeader( QPainter* painter,
00137                                            const QRectF& headerRect, const QRectF& exposedRect,
00138                                            qreal offset, QWidget* widget=0 );
00139         virtual void paintMonthScaleHeader( QPainter* painter,
00140                                             const QRectF& headerRect, const QRectF& exposedRect,
00141                                             qreal offset, QWidget* widget=0 );
00142 
00143         virtual void paintUserDefinedHeader( QPainter* painter, 
00144                                      const QRectF& headerRect, const QRectF& exposedRect, 
00145                                      qreal offset, const DateTimeScaleFormatter* formatter, 
00146                                      QWidget* widget = 0 );
00147 
00148         virtual void drawDayBackground(QPainter* painter, const QRectF& rect, const QDate& date);
00149         virtual void drawDayForeground(QPainter* painter, const QRectF& rect, const QDate& date);
00150         
00151         QRectF computeRect(const QDateTime& from, const QDateTime& to, const QRectF& rect) const;
00152         QPair<QDateTime, QDateTime> dateTimeRange(const QRectF& rect) const;
00153 
00154         /* reimp */ void drawBackground(QPainter* paint, const QRectF& rect);
00155         /* reimp */ void drawForeground(QPainter* paint, const QRectF& rect);
00156     };
00157 }
00158 
00159 #ifndef QT_NO_DEBUG_STREAM
00160 QDebug KDCHART_EXPORT operator<<( QDebug dbg, KDGantt::DateTimeScaleFormatter::Range );
00161 #endif
00162 
00163 #endif /* KDGANTTDATETIMEGRID_H */
00164 
 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/