#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
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 );
}
}
}
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;
+}
+
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
* 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.
*/
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