~KPlotAxis() {}
/**
- * Returns whether the axis is visible or not.
+ * @return whether the axis is visible or not
*/
bool isVisible() const { return m_visible; }
void setLabel( const QString& label ) { m_label = label; }
/**
- * Returns the axis label.
+ * @return the axis label
*/
QString label() const { return m_label; }
m_labelFieldWidth = fieldWidth; m_labelFmt = fmt; m_labelPrec = prec; }
/**
- * Returns the field width of the tick labels.
+ * @return the field width of the tick labels
*/
int labelFieldWidth() const { return m_labelFieldWidth; }
/**
- * Returns the number format of the tick labels.
+ * @return the number format of the tick labels
*/
char labelFmt() const { return m_labelFmt; }
/**
- * short Returns the number precision of the tick labels.
+ * @return the number precision of the tick labels
*/
int labelPrec() const { return m_labelPrec; }
#include "kplotobject.h"
+#include <QtAlgorithms>
+
#include <kdebug.h>
KPlotObject::KPlotObject() {
KPlotObject::~KPlotObject()
{
+ qDeleteAll( pList );
+ pList.clear();
+}
+
+QPointF* KPlotObject::point( int index ) {
+ if ( index < 0 || index >= pList.count() ) {
+ kdWarning() << "KPlotObject::object(): index " << index << " out of range!" << endl;
+ return 0;
+ }
+ return pList.at(index);
+}
+
+void KPlotObject::addPoint( QPointF *p ) {
+ // skip null pointers
+ if ( !p ) return;
+ pList.append( p );
}
void KPlotObject::removePoint( int index ) {
if ( ( index < 0 ) || ( index >= pList.count() ) ) {
- kdWarning() << "Ignoring attempt to remove non-existent plot object" << endl;
+ kdWarning() << "KPlotObject::removePoint(): index " << index << " out of range!" << endl;
return;
}
pList.removeAt( index );
}
+void KPlotObject::clearPoints() {
+ qDeleteAll( pList );
+ pList.clear();
+}
+
#include <QColor>
#include <QPointF>
-#include <QRectF>
#include <QString>
#include <kdemacros.h>
* @class KPlotObject
* @short Encapsulates an object to be plotted in a KPlotWidget.
*
- * Each KPlotObject consists of a list of QPoints, an object type, a color, a size,
- * and a name. An additional integer (param) specifies something further
- * about the object's appearance, depending on its type. There is a draw function
- * for plotting the object on a KPlotWidget's QPainter.
+ * Each KPlotObject consists of a list of QPointF's, an object type, a color,
+ * a size, and a name. An additional integer (param) specifies something
+ * further about the object's appearance, depending on its type.
+ *
+ * @note KPlotObject will take care of the points added to it, so when clearing
+ * the points list (eg with clearPoints()) any previous reference to a QPointF
+ * already added to a KPlotObject will be invalid.
*
* @author Jason Harris
* @version 1.0
void setParam( unsigned int p ) { Parameter = p; }
/**
- * @return a pointer to the QPointF at position i
- * @param i the index of the desired point.
+ * @return a pointer to the QPointF at position index
+ * @param index the index of the desired point
*/
- QPointF* point( unsigned int i ) { return pList.at(i); }
+ QPointF* point( int index );
+ /**
+ * @return a pointer to the list of points of the current KPlotObject
+ */
QList<QPointF*> *points() { return &pList; }
/**
* @overload
* @param p pointer to the QPointF to add.
*/
- void addPoint( QPointF *p ) { pList.append( p ); }
+ void addPoint( QPointF *p );
/**
* Remove the QPointF at position index from the list of points
/**
* @return the number of QPoints currently in the list
*/
- unsigned int count() const { return pList.count(); }
+ int count() const { return pList.count(); }
/**
* Clear the Object's points list
*/
- void clearPoints() { pList.clear(); }
+ void clearPoints();
private:
QList<QPointF*> pList;
ObjectList.clear();
}
+QSize KPlotWidget::minimumSizeHint() const
+{
+ return QSize( 150, 150 );
+}
+
void KPlotWidget::setLimits( double x1, double x2, double y1, double y2 ) {
double XA1, XA2, YA1, YA2;
if (x2<x1) { XA1=x2; XA2=x1; }
} //end for iaxis
}
+void KPlotWidget::addObject( KPlotObject *o ) {
+ // skip null pointers
+ if ( !o ) return;
+ ObjectList.append( o );
+}
+
void KPlotWidget::clearObjectList() {
qDeleteAll( ObjectList );
ObjectList.clear();
}
KPlotObject *KPlotWidget::object( int i ) {
- if ( i < 0 || i >= ObjectList.size() ) {
+ if ( i < 0 || i >= ObjectList.count() ) {
kdWarning() << "KPlotWidget::object(): index " << i << " out of range!" << endl;
return 0;
}
class KDE_EXPORT KPlotWidget : public QFrame {
Q_OBJECT
+ Q_PROPERTY(int leftPadding READ leftPadding WRITE setLeftPadding)
+ Q_PROPERTY(int rightPadding READ rightPadding WRITE setRightPadding)
+ Q_PROPERTY(int topPadding READ topPadding WRITE setTopPadding)
+ Q_PROPERTY(int bottomPadding READ bottomPadding WRITE setBottomPadding)
+ Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
+ Q_PROPERTY(QColor foregroundColor READ foregroundColor WRITE setForegroundColor)
+ Q_PROPERTY(QColor gridColor READ gridColor WRITE setGridColor)
public:
/**
* @short Constructor. Sets the primary x and y limits in data units.
*/
virtual ~KPlotWidget();
+ virtual QSize minimumSizeHint() const;
+
/**
* @short Determine the placement of major and minor tickmarks,
* Based on the current Limit settings
* Add an item to the list of KPlotObjects to be plotted.
* @param o pointer to the KPlotObject to be added
*/
- virtual void addObject( KPlotObject *o ) { ObjectList.append( o ); }
+ void addObject( KPlotObject *o );
/**
* Remove and delete all items from the list of KPlotObjects
* Sets the X-axis label.
* Set the label to an empty string to omit the axis label.
*
- * This function is deprecated, set the label property in the BottomAxis directly.
+ * @deprecated set the label property in the BottomAxis directly
* @param xlabel a short string describing the data plotted on the x-axis.
*/
- virtual void setXAxisLabel( const QString& xlabel ) { BottomAxis.setLabel(xlabel); }
+ KDE_DEPRECATED void setXAxisLabel( const QString& xlabel ) { BottomAxis.setLabel(xlabel); }
/**
* Sets the Y-axis label
* Set the label to an empty string to omit the axis label.
*
- * This function is deprecated, set the label property in the LeftAxis directly.
+ * @deprecated set the label property in the LeftAxis directly
* @param ylabel a short string describing the data plotted on the y-axis.
*/
- virtual void setYAxisLabel( const QString& ylabel ) { LeftAxis.setLabel(ylabel); }
+ KDE_DEPRECATED void setYAxisLabel( const QString& ylabel ) { LeftAxis.setLabel(ylabel); }
/**
* @returns the number of pixels to the left of the plot area.