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

KDChartDiagramObserver.cpp

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*-
00002    KDChart - a multi-platform charting engine
00003    */
00004 
00005 /****************************************************************************
00006  ** Copyright (C) 2001-2006 Klarävdalens Datakonsult AB.  All rights reserved.
00007  **
00008  ** This file is part of the KD Chart library.
00009  **
00010  ** This file may be distributed and/or modified under the terms of the
00011  ** GNU General Public License version 2 as published by the Free Software
00012  ** Foundation and appearing in the file LICENSE.GPL included in the
00013  ** packaging of this file.
00014  **
00015  ** Licensees holding valid commercial KD Chart licenses may use this file in
00016  ** accordance with the KD Chart Commercial License Agreement provided with
00017  ** the Software.
00018  **
00019  ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020  ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021  **
00022  ** See http://www.kdab.net/kdchart for
00023  **   information about KD Chart Commercial License Agreements.
00024  **
00025  ** Contact info@kdab.net if any conditions of this
00026  ** licensing are not clear to you.
00027  **
00028  **********************************************************************/
00029 
00030 #include <KDChartAbstractDiagram.h>
00031 #include <KDChartDiagramObserver.h>
00032 #include <KDChartAttributesModel.h>
00033 
00034 #include <KDABLibFakes>
00035 
00036 #include <QDebug>
00037 
00038 using namespace KDChart;
00039 
00040 DiagramObserver::DiagramObserver( AbstractDiagram * diagram, QObject* parent )
00041     : QObject( parent ), m_diagram( diagram )
00042 {
00043     if ( m_diagram ) {
00044         connect( m_diagram, SIGNAL(destroyed(QObject*)), SLOT(slotDestroyed(QObject*)));
00045         connect( m_diagram, SIGNAL(modelsChanged()), SLOT(slotModelsChanged()));
00046     }
00047     init();
00048 }
00049 
00050 DiagramObserver::~DiagramObserver()
00051 {
00052 }
00053 
00054 const AbstractDiagram* DiagramObserver::diagram() const
00055 {
00056     return m_diagram;
00057 }
00058 
00059 AbstractDiagram* DiagramObserver::diagram()
00060 {
00061     return m_diagram;
00062 }
00063 
00064 
00065 void DiagramObserver::init()
00066 {
00067     if ( !m_diagram )
00068         return;
00069 
00070     if ( m_model )
00071         disconnect(m_model);
00072 
00073     if ( m_attributesmodel )
00074         disconnect(m_attributesmodel);
00075 
00076     connect( m_diagram, SIGNAL(dataHidden()), SLOT(slotDataHidden()) );
00077 
00078     if( m_diagram->model() ){
00079         connect( m_diagram->model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)),
00080                  SLOT(slotDataChanged(QModelIndex,QModelIndex)));
00081         connect( m_diagram->model(), SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
00082                  SLOT(slotHeaderDataChanged(Qt::Orientation,int,int)));
00083     }
00084 
00085     if( m_diagram->attributesModel() )
00086         connect( m_diagram->attributesModel(), SIGNAL(attributesChanged(QModelIndex,QModelIndex)),
00087                  SLOT(slotAttributesChanged(QModelIndex,QModelIndex)));
00088     m_model = m_diagram->model();
00089     m_attributesmodel = m_diagram->attributesModel();
00090 }
00091 
00092 
00093 void DiagramObserver::slotDestroyed(QObject*)
00094 {
00095     //qDebug() << this << "emits signal\n"
00096     //        "    emit diagramDestroyed(" <<  m_diagram << ")";
00097     AbstractDiagram* diag = m_diagram;
00098     disconnect( m_diagram, 0, this, 0);
00099     m_diagram = 0;
00100     emit diagramDestroyed( diag );
00101 }
00102 
00103 void DiagramObserver::slotModelsChanged()
00104 {
00105     init();
00106     slotDataChanged();
00107     slotAttributesChanged();
00108 }
00109 
00110 void DiagramObserver::slotHeaderDataChanged(Qt::Orientation,int,int)
00111 {
00112     //qDebug() << "DiagramObserver::slotHeaderDataChanged()";
00113     emit diagramDataChanged( m_diagram );
00114 }
00115 
00116 void DiagramObserver::slotDataChanged(QModelIndex,QModelIndex)
00117 {
00118     slotDataChanged();
00119 }
00120 
00121 void DiagramObserver::slotDataChanged()
00122 {
00123     //qDebug() << "DiagramObserver::slotDataChanged()";
00124     emit diagramDataChanged( m_diagram );
00125 }
00126 
00127 void DiagramObserver::slotDataHidden()
00128 {
00129     //qDebug() << "DiagramObserver::slotDataHidden()";
00130     emit diagramDataHidden( m_diagram );
00131 }
00132 
00133 void DiagramObserver::slotAttributesChanged(QModelIndex,QModelIndex)
00134 {
00135     slotAttributesChanged();
00136 }
00137 
00138 void DiagramObserver::slotAttributesChanged()
00139 {
00140     //qDebug() << "DiagramObserver::slotAttributesChanged()";
00141     emit diagramAttributesChanged( m_diagram );
00142 }
00143 

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