]> Git trees. - libqmvoc.git/commitdiff
API work on KPlotAxis:
authorPino Toscano <pino@kde.org>
Fri, 16 Feb 2007 16:12:55 +0000 (16:12 +0000)
committerPino Toscano <pino@kde.org>
Fri, 16 Feb 2007 16:12:55 +0000 (16:12 +0000)
- hide all the private stuff into the Private class
- disable the copy of the class
- merge the two constructors in one, explicit
- remove the 'inline' declarations

svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=634205

kdeeduplot/kplotaxis.cpp
kdeeduplot/kplotaxis.h

index fdaf83d0ee3f27eff08230de574e6bd6a46700b0..5f547b1762db70583f4a798523448e7f8b984d44 100644 (file)
 
 #include "kplotaxis.h"
 
-KPlotAxis::KPlotAxis() : m_visible(true), m_showTickLabels(false), m_label(QString()),
-       m_labelFieldWidth(0), m_labelFmt('g'), m_labelPrec(-1)
+class KPlotAxis::Private
 {
+    public:
+        Private( KPlotAxis *qq )
+            : q( qq ), m_visible( true ), m_showTickLabels( false ),
+              m_labelFieldWidth( 0 ), m_labelFmt( 'g' ), m_labelPrec( -1 )
+        {
+        }
+
+        KPlotAxis *q;
+
+        bool m_visible; // Property "visible" defines if Axis is drawn or not.
+        bool m_showTickLabels;
+        QString m_label; // The label of the axis.
+        int m_labelFieldWidth; // Field width for number labels, see QString::arg()
+        char m_labelFmt; // Number format for number labels, see QString::arg()
+        int m_labelPrec; // Number precision for number labels, see QString::arg()
+        QList<double> m_MajorTickMarks, m_MinorTickMarks;
+};
+
+KPlotAxis::KPlotAxis( const QString &label )
+    : d( new Private( this ) )
+{
+    d->m_label = label;
+}
+
+KPlotAxis::~KPlotAxis()
+{
+    delete d;
+}
+
+bool KPlotAxis::isVisible() const
+{
+    return d->m_visible;
+}
+
+void KPlotAxis::setVisible( bool visible )
+{
+    d->m_visible = visible;
+}
+
+bool KPlotAxis::showTickLabels() const
+{
+    return d->m_showTickLabels;
+}
+
+void KPlotAxis::setShowTickLabels( bool b )
+{
+    d->m_showTickLabels = b;
+}
+
+void KPlotAxis::setLabel( const QString& label )
+{
+    d->m_label = label;
 }
 
-KPlotAxis::KPlotAxis(const QString& label) : m_visible(true), m_label(label), 
-       m_labelFieldWidth(0), m_labelFmt('g'), m_labelPrec(-1)
+QString KPlotAxis::label() const
 {
+    return d->m_label;
+}
+
+void KPlotAxis::setTickLabelFormat( char fmt, int fieldWidth, int prec )
+{
+    d->m_labelFieldWidth = fieldWidth;
+    d->m_labelFmt = fmt;
+    d->m_labelPrec = prec;
+}
+
+int KPlotAxis::tickLabelWidth() const
+{
+    return d->m_labelFieldWidth;
+}
+
+char KPlotAxis::tickLabelFmt() const
+{
+    return d->m_labelFmt;
+}
+
+int KPlotAxis::tickLabelPrec() const
+{
+    return d->m_labelPrec;
 }
 
 void KPlotAxis::setTickMarks( double x0, double length ) {
-       m_MajorTickMarks.clear();
-       m_MinorTickMarks.clear();
+       d->m_MajorTickMarks.clear();
+       d->m_MinorTickMarks.clear();
 
        //s is the power-of-ten factor of length:
        //length = t * s; s = 10^(pwr).  e.g., length=350.0 then t=3.5, s = 100.0; pwr = 2.0
@@ -84,13 +157,13 @@ void KPlotAxis::setTickMarks( double x0, double length ) {
        for ( int i=0; i<NumMajorTicks+1; i++ ) {
                double xmaj = Tick0 + i*TickDistance;
                if ( xmaj >= x0 && xmaj <= x0 + length ) {
-                       m_MajorTickMarks.append( xmaj );
+                       d->m_MajorTickMarks.append( xmaj );
                }
 
                for ( int j=1; j<NumMinorTicks; j++ ) {
                        double xmin = xmaj + TickDistance*j/NumMinorTicks;
                        if ( xmin >= x0 && xmin <= x0 + length ) 
-                               m_MinorTickMarks.append( xmin );
+                               d->m_MinorTickMarks.append( xmin );
                }
        }
 }
@@ -107,3 +180,14 @@ QString KPlotAxis::tickLabel( double val ) const {
 
        return QString( "%1" ).arg( val, tickLabelWidth(), tickLabelFmt(), tickLabelPrec() );
 }
+
+QList<double>& KPlotAxis::majorTickMarks() const
+{
+    return d->m_MajorTickMarks;
+}
+
+QList<double>& KPlotAxis::minorTickMarks() const
+{
+    return d->m_MinorTickMarks;
+}
+
index 1efbfe533a375a9004768d694a2d64a8977e58c2..adedc350949cd5a96041b6a2487b727202792288 100644 (file)
 class KDEEDUPLOT_EXPORT KPlotAxis {
 public:
 
-       /**
-        * Default constructor, creates a default axis.
-        */
-       KPlotAxis();
        /**
         * Constructor, constructs an axis with the label @p label.
         */
-       KPlotAxis(const QString& label);
+        explicit KPlotAxis( const QString& label = QString() );
 
        /**
         * Destructor.
         */
-       ~KPlotAxis() {}
+        ~KPlotAxis();
 
        /**
         * @return whether the axis is visible or not
         */
-       inline bool isVisible() const { return m_visible; }
+        bool isVisible() const;
 
        /**
         * Sets the "visible" property of the axis.
         */
-       inline void setVisible(bool visible) { m_visible = visible; }
+        void setVisible( bool visible );
 
        /**
         * @return whether tick labels will be drawn for this axis
         */
-       inline bool showTickLabels() const { return m_showTickLabels; }
+        bool showTickLabels() const;
 
        /**
         * Determine whether tick labels will be drawn for this axis.
         */
-       inline void setShowTickLabels( bool b ) { m_showTickLabels = b; }
+        void setShowTickLabels( bool b );
 
        /**
         * Sets the axis label.
         * Set the label to an empty string to omit the axis label.
         * @param label a string describing the data plotted on the axis.
         */
-       inline void setLabel( const QString& label ) { m_label = label; }
+        void setLabel( const QString& label );
 
        /**
         * @return the axis label
         */
-       inline QString label() const { return m_label; }
+        QString label() const;
 
        /**
         * @return the ticklabel string for the given value, rendered according
@@ -107,23 +103,22 @@ public:
         * render the value.
         * @param prec the number of characters following the decimal point.
         */
-       inline void setTickLabelFormat( char fmt = 'g', int fieldWidth = 0, int prec=-1) {
-               m_labelFieldWidth = fieldWidth; m_labelFmt = fmt; m_labelPrec = prec; }
+        void setTickLabelFormat( char fmt = 'g', int fieldWidth = 0, int prec = -1 );
 
        /**
         * @return the field width of the tick labels
         */
-       inline int tickLabelWidth() const { return m_labelFieldWidth; }
+        int tickLabelWidth() const;
 
        /**
         * @return the number format of the tick labels
         */
-       inline char tickLabelFmt() const { return m_labelFmt; }
+        char tickLabelFmt() const;
 
        /**
         * @return the number precision of the tick labels
         */
-       inline int tickLabelPrec() const { return m_labelPrec; }
+        int tickLabelPrec() const;
 
        /**
         * Determine the positions of major and minor tickmarks for this axis.
@@ -134,18 +129,15 @@ public:
         */
        void setTickMarks( double x0, double length );
 
-       inline QList<double>& majorTickMarks() { return m_MajorTickMarks; }
-       inline QList<double>& minorTickMarks() { return m_MinorTickMarks; }
+        QList<double>& majorTickMarks() const;
+
+        QList<double>& minorTickMarks() const;
 
 private:
-       bool            m_visible;                      ///< Property "visible" defines if Axis is drawn or not.
-       bool            m_showTickLabels;
-       QString         m_label;                        ///< The label of the axis.
-       int             m_labelFieldWidth;      ///< Field width for number labels, see QString::arg().
-       char            m_labelFmt;                     ///< Number format for number labels, see QString::arg().
-       int             m_labelPrec;            ///< Number precision for number labels, see QString::arg().
-       QList<double> m_MajorTickMarks, m_MinorTickMarks;
+        class Private;
+        Private * const d;
 
+        Q_DISABLE_COPY( KPlotAxis )
 };
 
 #endif // KPLOTAXIS_H