KD Chart 2
[rev.2.5]
|
00001 /**************************************************************************** 00002 ** Copyright (C) 2001-2012 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.txt 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 const bool con = connect( m_diagram, SIGNAL( viewportCoordinateSystemChanged() ), this, SLOT( slotDataChanged() ) ); 00071 Q_ASSERT( con ); 00072 Q_UNUSED( con ) 00073 connect( m_diagram, SIGNAL(dataHidden()), SLOT(slotDataHidden()) ); 00074 00075 if( m_diagram->model() ){ 00076 connect( m_diagram->model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)), 00077 SLOT(slotDataChanged(QModelIndex,QModelIndex))); 00078 connect( m_diagram->model(), SIGNAL(rowsInserted(QModelIndex,int,int)), 00079 SLOT(slotDataChanged())); 00080 connect( m_diagram->model(), SIGNAL(columnsInserted(QModelIndex,int,int)), 00081 SLOT(slotDataChanged())); 00082 connect( m_diagram->model(), SIGNAL(rowsRemoved(QModelIndex,int,int)), 00083 SLOT(slotDataChanged())); 00084 connect( m_diagram->model(), SIGNAL(columnsRemoved(QModelIndex,int,int)), 00085 SLOT(slotDataChanged())); 00086 connect( m_diagram->model(), SIGNAL(modelReset()), 00087 SLOT(slotDataChanged())); 00088 connect( m_diagram->model(), SIGNAL(headerDataChanged(Qt::Orientation,int,int)), 00089 SLOT(slotHeaderDataChanged(Qt::Orientation,int,int))); 00090 } 00091 00092 if( m_diagram->attributesModel() ) 00093 connect( m_diagram->attributesModel(), SIGNAL(attributesChanged(QModelIndex,QModelIndex)), 00094 SLOT(slotAttributesChanged(QModelIndex,QModelIndex))); 00095 m_model = m_diagram->model(); 00096 m_attributesmodel = m_diagram->attributesModel(); 00097 } 00098 00099 00100 void DiagramObserver::slotDestroyed(QObject*) 00101 { 00102 //qDebug() << this << "emits signal\n" 00103 // " emit diagramDestroyed(" << m_diagram << ")"; 00104 AbstractDiagram* diag = m_diagram; 00105 disconnect( m_diagram, 0, this, 0); 00106 m_diagram = 0; 00107 emit diagramDestroyed( diag ); 00108 } 00109 00110 void DiagramObserver::slotAboutToBeDestroyed() 00111 { 00112 emit diagramAboutToBeDestroyed( m_diagram ); 00113 } 00114 00115 void DiagramObserver::slotModelsChanged() 00116 { 00117 init(); 00118 slotDataChanged(); 00119 slotAttributesChanged(); 00120 } 00121 00122 void DiagramObserver::slotHeaderDataChanged(Qt::Orientation,int,int) 00123 { 00124 //qDebug() << "DiagramObserver::slotHeaderDataChanged()"; 00125 emit diagramDataChanged( m_diagram ); 00126 } 00127 00128 void DiagramObserver::slotDataChanged(QModelIndex,QModelIndex) 00129 { 00130 slotDataChanged(); 00131 } 00132 00133 void DiagramObserver::slotDataChanged() 00134 { 00135 //qDebug() << "DiagramObserver::slotDataChanged()"; 00136 emit diagramDataChanged( m_diagram ); 00137 } 00138 00139 void DiagramObserver::slotDataHidden() 00140 { 00141 //qDebug() << "DiagramObserver::slotDataHidden()"; 00142 emit diagramDataHidden( m_diagram ); 00143 } 00144 00145 void DiagramObserver::slotAttributesChanged(QModelIndex,QModelIndex) 00146 { 00147 slotAttributesChanged(); 00148 } 00149 00150 void DiagramObserver::slotAttributesChanged() 00151 { 00152 //qDebug() << "DiagramObserver::slotAttributesChanged()"; 00153 emit diagramAttributesChanged( m_diagram ); 00154 } 00155