Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

KDChartAbstractCoordinatePlane.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002  ** Copyright (C) 2006 Klarälvdalens Datakonsult AB.  All rights reserved.
00003  **
00004  ** This file is part of the KD Chart library.
00005  **
00006  ** This file may be distributed and/or modified under the terms of the
00007  ** GNU General Public License version 2 as published by the Free Software
00008  ** Foundation and appearing in the file LICENSE.GPL included in the
00009  ** packaging of this file.
00010  **
00011  ** Licensees holding valid commercial KD Chart licenses may use this file in
00012  ** accordance with the KD Chart Commercial License Agreement provided with
00013  ** the Software.
00014  **
00015  ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00016  ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00017  **
00018  ** See http://www.kdab.net/kdchart for
00019  **   information about KDChart Commercial License Agreements.
00020  **
00021  ** Contact info@kdab.net if any conditions of this
00022  ** licensing are not clear to you.
00023  **
00024  **********************************************************************/
00025 
00026 
00027 #include <QGridLayout>
00028 
00029 #include "KDChartChart.h"
00030 #include "KDChartAbstractCoordinatePlane.h"
00031 #include "KDChartAbstractCoordinatePlane_p.h"
00032 #include "KDChartGridAttributes.h"
00033 
00034 #include <KDABLibFakes>
00035 
00036 
00037 using namespace KDChart;
00038 
00039 #define d d_func()
00040 
00041 AbstractCoordinatePlane::Private::Private()
00042     : AbstractArea::Private()
00043     , parent( 0 )
00044     , grid( 0 )
00045     , referenceCoordinatePlane( 0 )
00046 {
00047     // this bloc left empty intentionally
00048 }
00049 
00050 
00051 AbstractCoordinatePlane::AbstractCoordinatePlane ( KDChart::Chart* parent )
00052     : AbstractArea ( new Private() )
00053 {
00054     d->parent = parent;
00055     d->init();
00056 }
00057 
00058 AbstractCoordinatePlane::~AbstractCoordinatePlane()
00059 {
00060     emit destroyedCoordinatePlane( this );
00061 }
00062 
00063 void AbstractCoordinatePlane::init()
00064 {
00065     d->initialize();  // virtual method to init the correct grid: cartesian, polar, ...
00066 }
00067 
00068 void AbstractCoordinatePlane::addDiagram ( AbstractDiagram* diagram )
00069 {
00070     // diagrams are invisible and paint through their paint() method
00071     diagram->hide();
00072 
00073     d->diagrams.append( diagram );
00074     diagram->setParent( d->parent );
00075     diagram->setCoordinatePlane( this );
00076     layoutDiagrams();
00077     layoutPlanes(); // there might be new axes, etc
00078     update();
00079 }
00080 
00081 /*virtual*/
00082 void AbstractCoordinatePlane::replaceDiagram ( AbstractDiagram* diagram, AbstractDiagram* oldDiagram_ )
00083 {
00084     if( diagram && oldDiagram_ != diagram ){
00085         AbstractDiagram* oldDiagram = oldDiagram_;
00086         if( d->diagrams.count() ){
00087             if( ! oldDiagram )
00088                 oldDiagram = d->diagrams.first();
00089             takeDiagram( oldDiagram );
00090         }
00091         delete oldDiagram;
00092         addDiagram( diagram );
00093         layoutDiagrams();
00094         layoutPlanes(); // there might be new axes, etc
00095         update();
00096     }
00097 }
00098 
00099 /*virtual*/
00100 void AbstractCoordinatePlane::takeDiagram ( AbstractDiagram* diagram )
00101 {
00102     const int idx = d->diagrams.indexOf( diagram );
00103     if( idx != -1 ){
00104         d->diagrams.removeAt( idx );
00105         diagram->setParent( 0 );
00106         diagram->setCoordinatePlane( 0 );
00107         layoutDiagrams();
00108         update();
00109     }
00110 }
00111 
00112 
00113 AbstractDiagram* AbstractCoordinatePlane::diagram()
00114 {
00115     if ( d->diagrams.isEmpty() )
00116     {
00117         return 0;
00118     } else {
00119         return d->diagrams.first();
00120     }
00121 }
00122 
00123 AbstractDiagramList AbstractCoordinatePlane::diagrams()
00124 {
00125     return d->diagrams;
00126 }
00127 
00128 ConstAbstractDiagramList AbstractCoordinatePlane::diagrams() const
00129 {
00130     ConstAbstractDiagramList list;
00131 #ifndef QT_NO_STL
00132     qCopy( d->diagrams.begin(), d->diagrams.end(), std::back_inserter( list ) );
00133 #else
00134     Q_FOREACH( AbstractDiagram * a, d->diagrams )
00135         list.push_back( a );
00136 #endif
00137     return list;
00138 }
00139 
00140 QSize KDChart::AbstractCoordinatePlane::minimumSizeHint() const
00141 {
00142     return QSize( 200, 200 );
00143 }
00144 
00145 
00146 QSizePolicy KDChart::AbstractCoordinatePlane::sizePolicy() const
00147 {
00148     return QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding );
00149 }
00150 
00151 void KDChart::AbstractCoordinatePlane::setGlobalGridAttributes( const GridAttributes& a )
00152 {
00153     d->gridAttributes = a;
00154     update();
00155 }
00156 
00157 GridAttributes KDChart::AbstractCoordinatePlane::globalGridAttributes() const
00158 {
00159     return d->gridAttributes;
00160 }
00161 
00162 KDChart::DataDimensionsList KDChart::AbstractCoordinatePlane::gridDimensionsList()
00163 {
00164     //KDChart::DataDimensionsList l( d->grid->updateData( this ) );
00165     //qDebug() << "AbstractCoordinatePlane::gridDimensionsList() Y-range:" << l.last().end - l.last().start << "   step width:" << l.last().stepWidth;
00166     //qDebug() << "AbstractCoordinatePlane::gridDimensionsList() X-range:" << l.first().end - l.first().start << "   step width:" << l.first().stepWidth;
00167     return d->grid->updateData( this );
00168 }
00169 
00170 void KDChart::AbstractCoordinatePlane::setGridNeedsRecalculate()
00171 {
00172     d->grid->setNeedRecalculate();
00173 }
00174 
00175 void KDChart::AbstractCoordinatePlane::setReferenceCoordinatePlane( AbstractCoordinatePlane * plane )
00176 {
00177     d->referenceCoordinatePlane = plane;
00178 }
00179 
00180 AbstractCoordinatePlane * KDChart::AbstractCoordinatePlane::referenceCoordinatePlane( ) const
00181 {
00182     return d->referenceCoordinatePlane;
00183 }
00184 
00185 void KDChart::AbstractCoordinatePlane::setParent( KDChart::Chart* parent )
00186 {
00187     d->parent = parent;
00188 }
00189 
00190 const KDChart::Chart* KDChart::AbstractCoordinatePlane::parent() const
00191 {
00192     return d->parent;
00193 }
00194 
00195 KDChart::Chart* KDChart::AbstractCoordinatePlane::parent()
00196 {
00197     return d->parent;
00198 }
00199 
00200 /* pure virtual in QLayoutItem */
00201 bool KDChart::AbstractCoordinatePlane::isEmpty() const
00202 {
00203     return false; // never empty!
00204     // coordinate planes with no associated diagrams
00205     // are showing a default grid of ()1..10, 1..10) stepWidth 1
00206 }
00207 /* pure virtual in QLayoutItem */
00208 Qt::Orientations KDChart::AbstractCoordinatePlane::expandingDirections() const
00209 {
00210     return Qt::Vertical | Qt::Horizontal;
00211 }
00212 /* pure virtual in QLayoutItem */
00213 QSize KDChart::AbstractCoordinatePlane::maximumSize() const
00214 {
00215     // No maximum size set. Especially not parent()->size(), we are not layouting
00216     // to the parent widget's size when using Chart::paint()!
00217     return QSize(QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX);
00218 }
00219 /* pure virtual in QLayoutItem */
00220 QSize KDChart::AbstractCoordinatePlane::minimumSize() const
00221 {
00222     return QSize(60, 60); // this default can be overwritten by derived classes
00223 }
00224 /* pure virtual in QLayoutItem */
00225 QSize KDChart::AbstractCoordinatePlane::sizeHint() const
00226 {
00227     // we return our maxiumu (which is the full size of the Chart)
00228     // even if we know the plane will be smaller
00229     return maximumSize();
00230 }
00231 /* pure virtual in QLayoutItem */
00232 void KDChart::AbstractCoordinatePlane::setGeometry( const QRect& r )
00233 {
00234 //    qDebug() << "KDChart::AbstractCoordinatePlane::setGeometry(" << r << ") called";
00235     if( d->geometry != r ){
00236         d->geometry = r;
00237         // Note: We do *not* call update() here
00238         //       because it would invoke KDChart::update() recursively.
00239     }
00240 }
00241 /* pure virtual in QLayoutItem */
00242 QRect KDChart::AbstractCoordinatePlane::geometry() const
00243 {
00244     return d->geometry;
00245 }
00246 
00247 void KDChart::AbstractCoordinatePlane::update()
00248 {
00249     //qDebug("KDChart::AbstractCoordinatePlane::update() called");
00250     emit needUpdate();
00251 }
00252 
00253 void KDChart::AbstractCoordinatePlane::relayout()
00254 {
00255     //qDebug("KDChart::AbstractCoordinatePlane::relayout() called");
00256     emit needRelayout();
00257 }
00258 
00259 void KDChart::AbstractCoordinatePlane::layoutPlanes()
00260 {
00261     //qDebug("KDChart::AbstractCoordinatePlane::relayout() called");
00262     emit needLayoutPlanes();
00263 }
00264 
00265 
00266 void KDChart::AbstractCoordinatePlane::mousePressEvent( QMouseEvent* event )
00267 {
00268     KDAB_FOREACH( AbstractDiagram * a, d->diagrams )
00269     {
00270         a->mousePressEvent( event );
00271     }
00272 }
00273 
00274 
00275 const bool KDChart::AbstractCoordinatePlane::isVisiblePoint( const QPointF& point ) const
00276 {
00277     return d->isVisiblePoint( this, point );
00278 }
00279 
00280 
00281 #undef d

Generated on Thu May 10 11:06:24 2007 for KD Chart 2 by doxygen 1.3.6