KD Chart 2  [rev.2.7]
KDChartDiagramObserver.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2020 Klaralvdalens Datakonsult AB. All rights reserved.
3 **
4 ** This file is part of the KD Chart library.
5 **
6 ** Licensees holding valid commercial KD Chart licenses may use this file in
7 ** accordance with the KD Chart Commercial License Agreement provided with
8 ** the Software.
9 **
10 **
11 ** This file may be distributed and/or modified under the terms of the
12 ** GNU General Public License version 2 and version 3 as published by the
13 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included.
14 **
15 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 **
18 ** Contact info@kdab.com if any conditions of this licensing are not
19 ** clear to you.
20 **
21 **********************************************************************/
22 
23 #include <KDChartDiagramObserver.h>
24 #include <KDChartAbstractDiagram.h>
25 #include <KDChartAttributesModel.h>
26 
27 #include <KDABLibFakes>
28 
29 #include <QDebug>
30 
31 using namespace KDChart;
32 
34  : QObject( parent ), m_diagram( diagram )
35 {
36  if ( m_diagram ) {
37  connect( m_diagram, SIGNAL(destroyed(QObject*)), SLOT(slotDestroyed(QObject*)));
38  connect( m_diagram, SIGNAL(aboutToBeDestroyed()), SLOT(slotAboutToBeDestroyed()));
39  connect( m_diagram, SIGNAL(modelsChanged()), SLOT(slotModelsChanged()));
40  }
41  init();
42 }
43 
45 {
46 }
47 
49 {
50  return m_diagram;
51 }
52 
54 {
55  return m_diagram;
56 }
57 
58 
59 void DiagramObserver::init()
60 {
61  if ( !m_diagram )
62  return;
63 
64  if ( m_model )
65  disconnect(m_model);
66 
67  if ( m_attributesmodel )
68  disconnect(m_attributesmodel);
69 
70  const bool con = connect( m_diagram, SIGNAL( viewportCoordinateSystemChanged() ), this, SLOT( slotDataChanged() ) );
71  Q_ASSERT( con );
72  Q_UNUSED( con )
73  connect( m_diagram, SIGNAL(dataHidden()), SLOT(slotDataHidden()) );
74 
75  if ( m_diagram->model() ) {
76  connect( m_diagram->model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)),
77  SLOT(slotDataChanged(QModelIndex,QModelIndex)));
78  connect( m_diagram->model(), SIGNAL(rowsInserted(QModelIndex,int,int)),
79  SLOT(slotDataChanged()));
80  connect( m_diagram->model(), SIGNAL(columnsInserted(QModelIndex,int,int)),
81  SLOT(slotDataChanged()));
82  connect( m_diagram->model(), SIGNAL(rowsRemoved(QModelIndex,int,int)),
83  SLOT(slotDataChanged()));
84  connect( m_diagram->model(), SIGNAL(columnsRemoved(QModelIndex,int,int)),
85  SLOT(slotDataChanged()));
86  connect( m_diagram->model(), SIGNAL(modelReset()),
87  SLOT(slotDataChanged()));
88  connect( m_diagram->model(), SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
89  SLOT(slotHeaderDataChanged(Qt::Orientation,int,int)));
90  }
91 
92  if ( m_diagram->attributesModel() )
93  connect( m_diagram->attributesModel(), SIGNAL(attributesChanged(QModelIndex,QModelIndex)),
94  SLOT(slotAttributesChanged(QModelIndex,QModelIndex)));
95  m_model = m_diagram->model();
96  m_attributesmodel = m_diagram->attributesModel();
97 }
98 
99 
100 void DiagramObserver::slotDestroyed(QObject*)
101 {
102  //qDebug() << this << "emits signal\n"
103  // " emit diagramDestroyed(" << m_diagram << ")";
104  AbstractDiagram* diag = m_diagram;
105  disconnect( m_diagram, 0, this, 0);
106  m_diagram = 0;
107  emit diagramDestroyed( diag );
108 }
109 
110 void DiagramObserver::slotAboutToBeDestroyed()
111 {
112  emit diagramAboutToBeDestroyed( m_diagram );
113 }
114 
115 void DiagramObserver::slotModelsChanged()
116 {
117  init();
118  slotDataChanged();
119  slotAttributesChanged();
120 }
121 
122 void DiagramObserver::slotHeaderDataChanged(Qt::Orientation,int,int)
123 {
124  //qDebug() << "DiagramObserver::slotHeaderDataChanged()";
125  emit diagramDataChanged( m_diagram );
126 }
127 
128 void DiagramObserver::slotDataChanged(QModelIndex,QModelIndex)
129 {
130  slotDataChanged();
131 }
132 
133 void DiagramObserver::slotDataChanged()
134 {
135  //qDebug() << "DiagramObserver::slotDataChanged()";
136  emit diagramDataChanged( m_diagram );
137 }
138 
139 void DiagramObserver::slotDataHidden()
140 {
141  //qDebug() << "DiagramObserver::slotDataHidden()";
142  emit diagramDataHidden( m_diagram );
143 }
144 
145 void DiagramObserver::slotAttributesChanged(QModelIndex,QModelIndex)
146 {
147  slotAttributesChanged();
148 }
149 
150 void DiagramObserver::slotAttributesChanged()
151 {
152  //qDebug() << "DiagramObserver::slotAttributesChanged()";
153  emit diagramAttributesChanged( m_diagram );
154 }
155 
void diagramAttributesChanged(AbstractDiagram *diagram)
This signal is emitted whenever the attributes of the diagram change.
DiagramObserver(AbstractDiagram *diagram, QObject *parent=0)
Constructs a new observer observing the given diagram.
void diagramDestroyed(AbstractDiagram *diagram)
This signal is emitted immediately before the diagram is being destroyed.
virtual AttributesModel * attributesModel() const
Returns the AttributesModel, that is used by this diagram.
AbstractDiagram defines the interface for diagram classes.
void diagramDataHidden(AbstractDiagram *diagram)
This signal is emitted whenever any of the data of the diagram was set (un)hidden.
Class only listed here to document inheritance of some KDChart classes.
const AbstractDiagram * diagram() const
void diagramDataChanged(AbstractDiagram *diagram)
This signal is emitted whenever the data of the diagram changes.
void diagramAboutToBeDestroyed(AbstractDiagram *diagram)
Emitted when a diagram is being destroyed, but before its data is invalidated.

Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/

https://www.kdab.com/development-resources/qt-tools/kd-chart/