From: Pino Toscano Date: Fri, 16 Feb 2007 16:12:55 +0000 (+0000) Subject: API work on KPlotAxis: X-Git-Tag: v3.80.3~56 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=7af6efa248bd0448a902bed8a69584261d3577dd;p=libqmvoc.git API work on KPlotAxis: - 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 --- diff --git a/kdeeduplot/kplotaxis.cpp b/kdeeduplot/kplotaxis.cpp index fdaf83d..5f547b1 100644 --- a/kdeeduplot/kplotaxis.cpp +++ b/kdeeduplot/kplotaxis.cpp @@ -20,19 +20,92 @@ #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 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= x0 && xmaj <= x0 + length ) { - m_MajorTickMarks.append( xmaj ); + d->m_MajorTickMarks.append( xmaj ); } for ( int j=1; j= 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& KPlotAxis::majorTickMarks() const +{ + return d->m_MajorTickMarks; +} + +QList& KPlotAxis::minorTickMarks() const +{ + return d->m_MinorTickMarks; +} + diff --git a/kdeeduplot/kplotaxis.h b/kdeeduplot/kplotaxis.h index 1efbfe5..adedc35 100644 --- a/kdeeduplot/kplotaxis.h +++ b/kdeeduplot/kplotaxis.h @@ -34,51 +34,47 @@ 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& majorTickMarks() { return m_MajorTickMarks; } - inline QList& minorTickMarks() { return m_MinorTickMarks; } + QList& majorTickMarks() const; + + QList& 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 m_MajorTickMarks, m_MinorTickMarks; + class Private; + Private * const d; + Q_DISABLE_COPY( KPlotAxis ) }; #endif // KPLOTAXIS_H