]> Git trees. - libqmvoc.git/commitdiff
- remove all the QT3_SUPPORT and compile without it
authorPino Toscano <pino@kde.org>
Tue, 27 Dec 2005 17:51:30 +0000 (17:51 +0000)
committerPino Toscano <pino@kde.org>
Tue, 27 Dec 2005 17:51:30 +0000 (17:51 +0000)
- unvirtualize the methods of KPlotAxis, as imho it is not meant to be subclassed
- unvirtualize some KPlotWidget methods that doesn't need to be overloaded on subclassing
- moved some methods from inline to the relative cpp
- delete the KPlotObjects when emptying the list

svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=491821

kdeeduplot/Makefile.am
kdeeduplot/kplotaxis.h
kdeeduplot/kplotwidget.cpp
kdeeduplot/kplotwidget.h

index 639ea788d374255101cd4cdddfb0e92dedadefbf..0a25a742b460bcd8604efb2f780ec21527b7ea0b 100644 (file)
@@ -1,5 +1,6 @@
 INCLUDES= $(all_includes)
 SUBDIRS = . 
+KDE_CXXFLAGS = -UQT3_SUPPORT
 
 lib_LTLIBRARIES = libkdeeduplot.la
 
index e5cce98ea23d26e6ff541150a69335b0b76e408c..83c2a7b994a8e2ddab9a68a79b478a0e1065c427 100644 (file)
@@ -45,61 +45,61 @@ public:
        /**
         * Destructor.
         */
-       virtual ~KPlotAxis() {}
+       ~KPlotAxis() {}
 
        /**
         * Returns whether the axis is visible or not.
         */
-       virtual bool isVisible() const { return m_visible; }
+       bool isVisible() const { return m_visible; }
 
        /**
         * Sets the "visible" property of the axis.
         */
-       virtual void setVisible(bool visible) { m_visible = visible; }
+       void setVisible(bool visible) { m_visible = visible; }
 
        /**
         * Shows the axis (axis will be shown at next update of plot widget).
         */
-       virtual void show() { m_visible = true; }
+       void show() { m_visible = true; }
 
        /**
         * Hides the axis (axis will be hidden at next update of plot widget).
         */
-       virtual void hide() { m_visible = false; }
+       void hide() { m_visible = false; }
 
        /**
         * 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.
         */
-       virtual void setLabel( const QString& label ) { m_label = label; }
+       void setLabel( const QString& label ) { m_label = label; }
 
        /**
         * Returns the axis label.
         */
-       virtual QString label() const { return m_label; }
+       QString label() const { return m_label; }
 
        /**
         * Set the number format for the tick labels, see QString::arg() for
         * description of arguments.
          */
-       virtual void setLabelFormat(int fieldWidth, char fmt = 'g', int prec=-1) {
+       void setLabelFormat(int fieldWidth, char fmt = 'g', int prec=-1) {
                m_labelFieldWidth = fieldWidth; m_labelFmt = fmt; m_labelPrec = prec; }
 
        /**
         * Returns the field width of the tick labels.
         */
-       virtual int labelFieldWidth() const { return m_labelFieldWidth; }
+       int labelFieldWidth() const { return m_labelFieldWidth; }
 
        /**
         * Returns the number format of the tick labels.
         */
-       virtual char labelFmt() const { return m_labelFmt; }
+       char labelFmt() const { return m_labelFmt; }
 
        /**
         * short Returns the number precision of the tick labels.
         */
-       virtual int labelPrec() const { return m_labelPrec; }
+       int labelPrec() const { return m_labelPrec; }
 
 private:
        bool            m_visible;                      ///< Property "visible" defines if Axis is drawn or not.
index cdb11d707a0e393ca0370456cffad767882879c0..ba9ff5e8c761cc32d3884b1a24e10f1598383b5f 100644 (file)
 #include <kdebug.h>
 #include <qevent.h>
 #include <qpainter.h>
+#include <qpalette.h>
 #include <qpixmap.h>
 #include <qpolygon.h>
+#include <QtAlgorithms>
 
 #include "kplotwidget.h"
 #include "kplotwidget.moc"
@@ -33,11 +35,11 @@ KPlotWidget::KPlotWidget( double x1, double x2, double y1, double y2, QWidget *p
    nmajX(0), nminX(0), nmajY(0), nminY(0),
    ShowTickMarks( true ), ShowTickLabels( true ), ShowGrid( false )
 {
-       setBackgroundMode( Qt::NoBackground );
+       setAttribute( Qt::WA_NoBackground, true );
 
        //set DataRect
        setLimits( x1, x2, y1, y2 );
-       setDefaultPadding();
+       setDefaultPaddings();
 
        //Set PixRect (starts at (0,0) because we will translate by leftPadding(), topPadding() )
        PixRect = QRect( 0, 0, width() - leftPadding() - rightPadding(),
@@ -46,14 +48,15 @@ KPlotWidget::KPlotWidget( double x1, double x2, double y1, double y2, QWidget *p
        buffer = new QPixmap();
 
        //default colors:
-       setBGColor( Qt::black );
-       setFGColor( Qt::white );
+       setBackgroundColor( Qt::black );
+       setForegroundColor( Qt::white );
        setGridColor( Qt::gray );
 }
 
 KPlotWidget::~KPlotWidget()
 {
        delete (buffer);
+       qDeleteAll( ObjectList );
        ObjectList.clear();
 }
 
@@ -134,26 +137,52 @@ void KPlotWidget::updateTickmarks() {
        } //end for iaxis
 }
 
+void KPlotWidget::clearObjectList() {
+       qDeleteAll( ObjectList );
+       ObjectList.clear();
+       update();
+}
+
+KPlotObject *KPlotWidget::object( int i ) {
+       if ( i < 0 || i >= ObjectList.size() ) {
+               kdWarning() << "KPlotWidget::object(): index " << i << " out of range!" << endl;
+               return 0;
+       }
+       return ObjectList.at(i);
+}
+
+void KPlotWidget::setBackgroundColor( const QColor &bg ) {
+       cBackground = bg;
+       QPalette palette;
+       palette.setColor( backgroundRole(), bg );
+       setPalette( palette );
+}
+
 void KPlotWidget::resizeEvent( QResizeEvent* /* e */ ) {
        int newWidth = width() - leftPadding() - rightPadding();
        int newHeight = height() - topPadding() - bottomPadding();
        PixRect = QRect( 0, 0, newWidth, newHeight );
 
-       buffer->resize( width(), height() );
+       QPixmap *tmp = new QPixmap( size() );
+       delete buffer;
+       buffer = tmp;
+       tmp = 0;
 }
 
 void KPlotWidget::paintEvent( QPaintEvent* /* e */ ) {
        QPainter p;
 
        p.begin( buffer );
-       p.fillRect( 0, 0, width(), height(), bgColor() );
+       p.fillRect( 0, 0, width(), height(), backgroundColor() );
        p.translate( leftPadding(), topPadding() );
 
        drawObjects( &p );
        drawBox( &p );
 
        p.end();
-       bitBlt( this, 0, 0, buffer );
+       p.begin( this );
+       p.drawPixmap( 0, 0, *buffer );
+       p.end();
 }
 
 void KPlotWidget::drawObjects( QPainter *p ) {
@@ -210,9 +239,8 @@ void KPlotWidget::drawObjects( QPainter *p ) {
 
                                        QPolygon a( po->count() );
 
-                                       unsigned int i=0;
                                        for ( QList<QPointF*>::ConstIterator dpit = po->points()->begin(); dpit != po->points()->constEnd(); ++dpit )
-                                               a.setPoint( i++, mapToPoint( **dpit ) );
+                                               a << mapToPoint( **dpit );
 
                                        p->drawPolygon( a );
                                        break;
@@ -230,8 +258,8 @@ double KPlotWidget::dmod( double a, double b ) { return ( b * ( ( a / b ) - int(
 
 void KPlotWidget::drawBox( QPainter *p ) {
        //First, fill in padding region with bgColor() to mask out-of-bounds plot data
-       p->setPen( bgColor() );
-       p->setBrush( bgColor() );
+       p->setPen( backgroundColor() );
+       p->setBrush( backgroundColor() );
 
        //left padding ( don't forget: we have translated by XPADDING, YPADDING )
        p->drawRect( -leftPadding(), -topPadding(), leftPadding(), height() );
@@ -264,7 +292,7 @@ void KPlotWidget::drawBox( QPainter *p ) {
                }
        }
 
-       p->setPen( fgColor() );
+       p->setPen( foregroundColor() );
        p->setBrush( Qt::NoBrush );
 
        if (BottomAxis.isVisible() || LeftAxis.isVisible())  p->drawRect( PixRect ); //box outline
index 87bf0894c059fbc646aaedfee0f615f518bdd4ab..da1ffb4b39fa8690d2a9687567fdebfbec3ddca2 100644 (file)
@@ -34,11 +34,15 @@ class KPlotObject;
 /**
  * @class KPlotWidget
  *
- * @short Genric data plotting widget.
+ * @short Generic data plotting widget.
  *
  * Widget for drawing plots. Includes adjustable axes (KPlotAxis) with
  * tickmarks and labels and a list of KPlotObjects to be drawn.
  *
+ * @note KPlotWidget will take care of the objects added to it, so when
+ * clearing the objects list (eg with clearObjectList()) any previous reference
+ * to a KPlotObject already added to a KPlotWidget will be invalid
+ *
  * @author Jason Harris
  *
  * @version 1.1
@@ -114,60 +118,60 @@ public:
        virtual void addObject( KPlotObject *o ) { ObjectList.append( o ); }
 
        /**
-        * Remove all items from the list of KPlotObjects
+        * Remove and delete all items from the list of KPlotObjects
         */
-       virtual void clearObjectList() { ObjectList.clear(); update(); }
+       void clearObjectList();
 
        /**
         * Replace an item in the KPlotObject list.
         * @param i the index of th item to be replaced
         * @param o pointer to the replacement KPlotObject
         */
-       virtual void replaceObject( int i, KPlotObject *o ) { ObjectList.replace( i, o ); }
+       void replaceObject( int i, KPlotObject *o ) { ObjectList.replace( i, o ); }
 
        /**
         * @return the number of KPlotObjects in the list
         */
-       virtual int objectCount() const { return ObjectList.count(); }
+       int objectCount() const { return ObjectList.count(); }
 
        /**
         * @return a pointer to a specific KPlotObject in the list
         * @param i the index of the desired KPlotObject
         */
-       virtual KPlotObject *object( int i ) { return ObjectList.at(i); }
+       KPlotObject *object( int i );
 
        /**
         * @return the background color
         */
-       virtual QColor bgColor() const { return cBackground; }
+       QColor backgroundColor() const { return cBackground; }
 
        /**
         * @return the foreground color
         */
-       virtual QColor fgColor() const { return cForeground; }
+       QColor foregroundColor() const { return cForeground; }
 
        /**
         * @return the grid color
         */
-       virtual QColor gridColor() const { return cGrid; }
+       QColor gridColor() const { return cGrid; }
 
        /**
         * Set the background color
         * @param bg the new background color
         */
-       virtual void setBGColor( const QColor &bg ) { cBackground = bg; setBackgroundColor( bg ); }
+       void setBackgroundColor( const QColor &bg );
 
        /**
         * Set the foreground color
         * @param fg the new foreground color
         */
-       virtual void setFGColor( const QColor &fg ) { cForeground = fg; }
+       void setForegroundColor( const QColor &fg ) { cForeground = fg; }
 
        /**
         * Set the grid color
         * @param gc the new grid color
         */
-       virtual void setGridColor( const QColor &gc ) { cGrid = gc; }
+       void setGridColor( const QColor &gc ) { cGrid = gc; }
 
        /**
         * Toggle whether plot axes are drawn.
@@ -257,7 +261,7 @@ public:
        /**
         * Revert all four padding values to be automatically determined.
         */
-       virtual void setDefaultPadding() { LeftPadding = -1; RightPadding = -1; TopPadding = -1; BottomPadding = -1; }
+       void setDefaultPaddings() { LeftPadding = -1; RightPadding = -1; TopPadding = -1; BottomPadding = -1; }
 
        QPoint mapToPoint( const QPointF& p ) {
                int px = PixRect.left() + int( PixRect.width()*( p.x() -  DataRect.x() )/DataRect.width() );
@@ -316,9 +320,13 @@ protected:
        //The number of major and minor tickmarks to be plotted in X and Y
        int nmajX, nminX, nmajY, nminY;
 
-       //Limits of the plot area in pixel units
+       /**
+        * Limits of the plot area in pixel units
+        */
        QRect PixRect;
-       //Limits of the plot area in data units
+       /**
+        * Limits of the plot area in data units
+        */
        QRectF DataRect;
        /**
         * List of KPlotObjects