From 983534ca4639c545434dc365a88f0063602e0b39 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Thu, 29 Dec 2005 23:32:45 +0000 Subject: [PATCH] Some changes to kdeeduplot: - delete'ing the points of a KPlotObject when clearing the list - some more checks in a pair of methods - really deprecate two functions already deprecated - apidox fixes - add Q_PROPERTYes for KPlotWidget svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=492443 --- kdeeduplot/kplotaxis.h | 10 +++++----- kdeeduplot/kplotobject.cpp | 25 ++++++++++++++++++++++++- kdeeduplot/kplotobject.h | 27 ++++++++++++++++----------- kdeeduplot/kplotwidget.cpp | 13 ++++++++++++- kdeeduplot/kplotwidget.h | 19 ++++++++++++++----- 5 files changed, 71 insertions(+), 23 deletions(-) diff --git a/kdeeduplot/kplotaxis.h b/kdeeduplot/kplotaxis.h index 83c2a7b..41e173c 100644 --- a/kdeeduplot/kplotaxis.h +++ b/kdeeduplot/kplotaxis.h @@ -48,7 +48,7 @@ public: ~KPlotAxis() {} /** - * Returns whether the axis is visible or not. + * @return whether the axis is visible or not */ bool isVisible() const { return m_visible; } @@ -75,7 +75,7 @@ public: void setLabel( const QString& label ) { m_label = label; } /** - * Returns the axis label. + * @return the axis label */ QString label() const { return m_label; } @@ -87,17 +87,17 @@ public: 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; } diff --git a/kdeeduplot/kplotobject.cpp b/kdeeduplot/kplotobject.cpp index e29c4ef..e197103 100644 --- a/kdeeduplot/kplotobject.cpp +++ b/kdeeduplot/kplotobject.cpp @@ -17,6 +17,8 @@ #include "kplotobject.h" +#include + #include KPlotObject::KPlotObject() { @@ -34,14 +36,35 @@ KPlotObject::KPlotObject( const QString &n, const QColor &c, PTYPE t, unsigned i 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(); +} + diff --git a/kdeeduplot/kplotobject.h b/kdeeduplot/kplotobject.h index cba3102..09f7ffc 100644 --- a/kdeeduplot/kplotobject.h +++ b/kdeeduplot/kplotobject.h @@ -20,7 +20,6 @@ #include #include -#include #include #include @@ -29,10 +28,13 @@ * @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 @@ -131,11 +133,14 @@ public: 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 *points() { return &pList; } /** @@ -149,7 +154,7 @@ public: * @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 @@ -160,12 +165,12 @@ public: /** * @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 pList; diff --git a/kdeeduplot/kplotwidget.cpp b/kdeeduplot/kplotwidget.cpp index ba9ff5e..592850a 100644 --- a/kdeeduplot/kplotwidget.cpp +++ b/kdeeduplot/kplotwidget.cpp @@ -60,6 +60,11 @@ KPlotWidget::~KPlotWidget() 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= ObjectList.size() ) { + if ( i < 0 || i >= ObjectList.count() ) { kdWarning() << "KPlotWidget::object(): index " << i << " out of range!" << endl; return 0; } diff --git a/kdeeduplot/kplotwidget.h b/kdeeduplot/kplotwidget.h index da1ffb4..c68d942 100644 --- a/kdeeduplot/kplotwidget.h +++ b/kdeeduplot/kplotwidget.h @@ -50,6 +50,13 @@ class KPlotObject; 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. @@ -66,6 +73,8 @@ public: */ virtual ~KPlotWidget(); + virtual QSize minimumSizeHint() const; + /** * @short Determine the placement of major and minor tickmarks, * Based on the current Limit settings @@ -115,7 +124,7 @@ public: * 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 @@ -199,18 +208,18 @@ public: * 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. -- 2.47.3