]> Git trees. - libqmvoc.git/commitdiff
Some changes to kdeeduplot:
authorPino Toscano <pino@kde.org>
Thu, 29 Dec 2005 23:32:45 +0000 (23:32 +0000)
committerPino Toscano <pino@kde.org>
Thu, 29 Dec 2005 23:32:45 +0000 (23:32 +0000)
- 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
kdeeduplot/kplotobject.cpp
kdeeduplot/kplotobject.h
kdeeduplot/kplotwidget.cpp
kdeeduplot/kplotwidget.h

index 83c2a7b994a8e2ddab9a68a79b478a0e1065c427..41e173c2d56b5345e8652b7f6380fab99b3e6fe3 100644 (file)
@@ -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; }
 
index e29c4efa512684e0fa69ca9daeb9f7c6e75dd715..e197103d6a26768d5bc9949ecc821a88203ca67a 100644 (file)
@@ -17,6 +17,8 @@
 
 #include "kplotobject.h"
 
+#include <QtAlgorithms>
+
 #include <kdebug.h>
 
 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();
+}
+
index cba3102d3ab787671299549b7d8b12fa6747e7b5..09f7ffc926626defa1a6e4f186718d795c305264 100644 (file)
@@ -20,7 +20,6 @@
 
 #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
@@ -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<QPointF*> *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<QPointF*> pList;
index ba9ff5e8c761cc32d3884b1a24e10f1598383b5f..592850ab2367a48e4225b40c35360b3075ed159b 100644 (file)
@@ -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<x1) { XA1=x2; XA2=x1; }
@@ -137,6 +142,12 @@ void KPlotWidget::updateTickmarks() {
        } //end for iaxis
 }
 
+void KPlotWidget::addObject( KPlotObject *o ) {
+       // skip null pointers
+       if ( !o ) return;
+       ObjectList.append( o );
+}
+
 void KPlotWidget::clearObjectList() {
        qDeleteAll( ObjectList );
        ObjectList.clear();
@@ -144,7 +155,7 @@ void KPlotWidget::clearObjectList() {
 }
 
 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;
        }
index da1ffb4b39fa8690d2a9687567fdebfbec3ddca2..c68d942f13a5a5cd73f7cadcbaac9b6374bfe81e 100644 (file)
@@ -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.