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-2007 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 <KDChartDiagramObserver.h>
00031 #include <KDChartAbstractDiagram.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(modelReset()),
00082                  SLOT(slotDataChanged()));
00083         connect( m_diagram->model(), SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
00084                  SLOT(slotHeaderDataChanged(Qt::Orientation,int,int)));
00085     }
00086 
00087     if( m_diagram->attributesModel() )
00088         connect( m_diagram->attributesModel(), SIGNAL(attributesChanged(QModelIndex,QModelIndex)),
00089                  SLOT(slotAttributesChanged(QModelIndex,QModelIndex)));
00090     m_model = m_diagram->model();
00091     m_attributesmodel = m_diagram->attributesModel();
00092 }
00093 
00094 
00095 void DiagramObserver::slotDestroyed(QObject*)
00096 {
00097     //qDebug() << this << "emits signal\n"
00098     //        "    emit diagramDestroyed(" <<  m_diagram << ")";
00099     AbstractDiagram* diag = m_diagram;
00100     disconnect( m_diagram, 0, this, 0);
00101     m_diagram = 0;
00102     emit diagramDestroyed( diag );
00103 }
00104 
00105 void DiagramObserver::slotModelsChanged()
00106 {
00107     init();
00108     slotDataChanged();
00109     slotAttributesChanged();
00110 }
00111 
00112 void DiagramObserver::slotHeaderDataChanged(Qt::Orientation,int,int)
00113 {
00114     //qDebug() << "DiagramObserver::slotHeaderDataChanged()";
00115     emit diagramDataChanged( m_diagram );
00116 }
00117 
00118 void DiagramObserver::slotDataChanged(QModelIndex,QModelIndex)
00119 {
00120     slotDataChanged();
00121 }
00122 
00123 void DiagramObserver::slotDataChanged()
00124 {
00125     //qDebug() << "DiagramObserver::slotDataChanged()";
00126     emit diagramDataChanged( m_diagram );
00127 }
00128 
00129 void DiagramObserver::slotDataHidden()
00130 {
00131     //qDebug() << "DiagramObserver::slotDataHidden()";
00132     emit diagramDataHidden( m_diagram );
00133 }
00134 
00135 void DiagramObserver::slotAttributesChanged(QModelIndex,QModelIndex)
00136 {
00137     slotAttributesChanged();
00138 }
00139 
00140 void DiagramObserver::slotAttributesChanged()
00141 {
00142     //qDebug() << "DiagramObserver::slotAttributesChanged()";
00143     emit diagramAttributesChanged( m_diagram );
00144 }
00145 

Generated on Thu Mar 4 23:19:11 2010 for KD Chart 2 by  doxygen 1.5.4