barchart.h

Go to the documentation of this file.
00001 // OSB library ************************************************ -*- C++ -*-
00006 /*
00007   AUTHOR(S): Stephan Broennimann (vb)
00008 
00009   RCS information
00010    $Name: OSB_060808 $
00011    $Revision: 1.5 $
00012 
00013   License
00014    OSB rating and billing library for communication networks
00015    Copyright (C) 2004, 2005, 2006  OSB systems
00016 
00017    This file may be distributed and/or modify under the terms of the
00018    GNU General Public License (GPL) as published by the Free Software
00019    Foundation which is provided in the file LICENSE.GPL included in the
00020    packaging of this file.
00021 
00022    The file is distributed in the hope that it will be useful, but WITHOUT
00023    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00024    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00025    for more details.
00026 
00027    Holders of a OSB Commercial License may use this file under the terms
00028    and conditions of this commercial license.
00029  */
00030 #ifndef _BARCHART_H_
00031 #define _BARCHART_H_
00032 
00033 // ************************************************************************
00034 // included header files
00035 // + standard includes
00036 #include <vector>
00037 
00038 // + libraries
00039 #include <qframe.h>
00040 
00041 // + local headers
00042 
00043 // + class declarations
00044 class QGridLayout;
00045 class QLabel;
00046 
00047 // ************************************************************************
00048 // namespace extensions
00049 namespace OSB_GUI {
00050 
00051 // ************************************************************************
00052 // forward declarations
00053 
00054 // ************************************************************************
00055 // type definitions
00056 
00057 // ************************************************************************
00058 // class definitions
00062     class BarChartInfo : public QObject {
00063         Q_OBJECT                        // for vim ->;
00064     public:
00066         typedef std::map<double, std::string> Ticks;
00067     protected:
00069         explicit BarChartInfo(
00070             double minX = 0.0,
00071             double maxX = 0.0
00072         );
00073 
00074     public:
00076         virtual ~BarChartInfo();
00077 
00078     private:
00080         BarChartInfo(const BarChartInfo& rhs);
00082         BarChartInfo& operator=(const BarChartInfo& rhs);
00083 
00084     public:
00086         virtual double scaleX(double x) = 0;
00087 
00089         double min() const
00090         {
00091             return min_;
00092         }
00093 
00095         double max() const
00096         {
00097             return max_;
00098         }
00099 
00101         const Ticks& ticks() const
00102         {
00103             return ticks_;
00104         }
00105 
00107 
00108 
00109         int minLabelWidth() const
00110         {
00111             return minLabelWidth_;
00112         }
00114         int minBarWidth() const
00115         {
00116             return minBarWidth_;
00117         }
00119         int leftOff() const
00120         {
00121             return leftOff_;
00122         }
00124         int rightOff() const
00125         {
00126             return rightOff_;
00127         }
00129 
00131 
00132 
00137         virtual void resetGeometry();
00144         void setMinLabelWidth(int minWidth);
00146         void setMinBarWidth(int minWidth);
00151         void setLeftOff(int leftOff);
00156         void setRightOff(int rightOff);
00158 
00159     signals:
00161         void minLabelWidth(int minWidth);
00162 
00163     protected:
00165         double min_;
00167         double max_;
00169         Ticks ticks_;
00170 
00172 
00173 
00174         int minLabelWidth_;
00176         int minBarWidth_;
00178         int leftOff_;
00180         int rightOff_;
00182     };                                  // class BarChartInfo
00183 
00187     class BarChart : public QFrame {
00188         Q_OBJECT                        // for vim ->;
00189     public:
00190         // defined and documented below
00191         struct Range {
00193             explicit Range(
00194                 double low   = 0,
00195                 double high  = 0,
00196                 QColor color = QColor()
00197             );
00198 
00199         public:
00201             double low_;
00203             double high_;
00205             QColor color_;
00206         };                              // struct Range
00207 
00209         typedef std::vector<Range> Ranges;
00210     private:
00211         // defined and documented below
00212         class Bar;
00213         // defined and documented below
00214         class Ruler;
00215 
00216     public:
00220         explicit BarChart(
00221                   BarChartInfo& info,
00222                   QWidget*      parent,
00223             const char*         name    = 0,
00224                   WFlags        flags   = 0
00225         );
00226 
00228         virtual ~BarChart() = 0;
00229 
00230     public:
00238         std::pair<QLabel*, QWidget*> add(
00239             const std::string& label,
00240             const Ranges&      ranges
00241         );
00242 
00243     public slots:
00252         void setMinLabelWidth(int minWidth);
00253 
00254     signals:
00260         void minLabelWidth(int minWidth);
00261 
00262     protected:
00264         QLabel* header_;
00265     private:
00267         BarChartInfo& info_;
00269         Ruler* ruler_;
00271         QGridLayout* layout_;
00272     };                                  // class BarChart
00273 
00277     class BarChart::Bar : public QWidget {
00278     public:
00282         Bar(
00283                   BarChartInfo& info,
00284                   QWidget*      parent,
00285             const char*         name    = 0,
00286                   WFlags        flags   = 0
00287         );
00288 
00289     public:
00291         void show(const Ranges& ranges);
00292 
00293     private:
00295         void paintEvent(QPaintEvent* e);
00296 
00297     private:
00299         BarChartInfo& info_;
00301         Ranges ranges_;
00302     };                                  // class BarChart::Bar
00303 
00307     class BarChart::Ruler : public QWidget {
00308     public:
00312         Ruler(
00313                   BarChartInfo& info,
00314                   QWidget*      parent,
00315             const char*         name    = 0,
00316                   WFlags        flags   = 0
00317         );
00318     public:
00320         QSize sizeHint () const;
00321     private:
00323         void paintEvent(QPaintEvent* e);
00325         void calcSize();
00327         void fontChange(const QFont&);
00328     private:
00330         BarChartInfo& info_;
00332         int height_;
00333     };                                  // class BarChart::Ruler
00334 }                                       // namespace OSB_GUI
00335 
00336 // ************************************************************************
00337 // inline definitions
00338 namespace OSB_GUI {
00339 }                                       // namespace OSB_GUI
00340 #endif                                  // #ifndef _BARCHART_H_

Generated on Sat Sep 2 14:17:36 2006 for OSB Library by  doxygen 1.4.7