KDChartDiagramObserver.cpp

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