KChart

KChartDiagramObserver.cpp
1 /*
2  * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
3  *
4  * This file is part of the KD Chart library.
5  *
6  * SPDX-License-Identifier: GPL-2.0-or-later
7  */
8 
9 #include <KChartDiagramObserver.h>
10 
11 #include <KChartAbstractDiagram.h>
12 #include <KChartAttributesModel.h>
13 #include "KChartMath_p.h"
14 
15 #include <QDebug>
16 
17 using namespace KChart;
18 
20  : QObject( parent ), m_diagram( diagram )
21 {
22  if ( m_diagram ) {
23  connect( m_diagram, SIGNAL(destroyed(QObject*)), SLOT(slotDestroyed(QObject*)));
24  connect( m_diagram, SIGNAL(aboutToBeDestroyed()), SLOT(slotAboutToBeDestroyed()));
25  connect( m_diagram, SIGNAL(modelsChanged()), SLOT(slotModelsChanged()));
26  }
27  init();
28 }
29 
30 DiagramObserver::~DiagramObserver()
31 {
32 }
33 
34 const AbstractDiagram* DiagramObserver::diagram() const
35 {
36  return m_diagram;
37 }
38 
39 AbstractDiagram* DiagramObserver::diagram()
40 {
41  return m_diagram;
42 }
43 
44 
45 void DiagramObserver::init()
46 {
47  if ( !m_diagram )
48  return;
49 
50  if ( m_model )
51  disconnect(m_model);
52 
53  if ( m_attributesmodel )
54  disconnect(m_attributesmodel);
55 
56  const bool con = connect( m_diagram, SIGNAL(viewportCoordinateSystemChanged()), this, SLOT(slotDataChanged()) );
57  Q_ASSERT( con );
58  Q_UNUSED( con )
59  connect( m_diagram, SIGNAL(dataHidden()), SLOT(slotDataHidden()) );
60 
61  if ( m_diagram->model() ) {
62  connect( m_diagram->model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)),
63  SLOT(slotDataChanged(QModelIndex,QModelIndex)));
64  connect( m_diagram->model(), SIGNAL(rowsInserted(QModelIndex,int,int)),
65  SLOT(slotDataChanged()));
66  connect( m_diagram->model(), SIGNAL(columnsInserted(QModelIndex,int,int)),
67  SLOT(slotDataChanged()));
68  connect( m_diagram->model(), SIGNAL(rowsRemoved(QModelIndex,int,int)),
69  SLOT(slotDataChanged()));
70  connect( m_diagram->model(), SIGNAL(columnsRemoved(QModelIndex,int,int)),
71  SLOT(slotDataChanged()));
72  connect( m_diagram->model(), SIGNAL(modelReset()),
73  SLOT(slotDataChanged()));
74  connect( m_diagram->model(), SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
75  SLOT(slotHeaderDataChanged(Qt::Orientation,int,int)));
76  }
77 
78  if ( m_diagram->attributesModel() )
79  connect( m_diagram->attributesModel(), SIGNAL(attributesChanged(QModelIndex,QModelIndex)),
80  SLOT(slotAttributesChanged(QModelIndex,QModelIndex)));
81  m_model = m_diagram->model();
82  m_attributesmodel = m_diagram->attributesModel();
83 }
84 
85 
86 void DiagramObserver::slotDestroyed(QObject*)
87 {
88  //qDebug() << this << "emits signal\n"
89  // " Q_EMIT diagramDestroyed(" << m_diagram << ")";
90  AbstractDiagram* diag = m_diagram;
91  disconnect( m_diagram, nullptr, this, nullptr);
92  m_diagram = nullptr;
93  Q_EMIT diagramDestroyed( diag );
94 }
95 
96 void DiagramObserver::slotAboutToBeDestroyed()
97 {
98  Q_EMIT diagramAboutToBeDestroyed( m_diagram );
99 }
100 
101 void DiagramObserver::slotModelsChanged()
102 {
103  init();
104  slotDataChanged();
105  slotAttributesChanged();
106 }
107 
108 void DiagramObserver::slotHeaderDataChanged(Qt::Orientation,int,int)
109 {
110  //qDebug() << "DiagramObserver::slotHeaderDataChanged()";
111  Q_EMIT diagramDataChanged( m_diagram );
112 }
113 
114 void DiagramObserver::slotDataChanged(QModelIndex,QModelIndex)
115 {
116  slotDataChanged();
117 }
118 
119 void DiagramObserver::slotDataChanged()
120 {
121  //qDebug() << "DiagramObserver::slotDataChanged()";
122  Q_EMIT diagramDataChanged( m_diagram );
123 }
124 
125 void DiagramObserver::slotDataHidden()
126 {
127  //qDebug() << "DiagramObserver::slotDataHidden()";
128  Q_EMIT diagramDataHidden( m_diagram );
129 }
130 
131 void DiagramObserver::slotAttributesChanged(QModelIndex,QModelIndex)
132 {
133  slotAttributesChanged();
134 }
135 
136 void DiagramObserver::slotAttributesChanged()
137 {
138  //qDebug() << "DiagramObserver::slotAttributesChanged()";
139  Q_EMIT diagramAttributesChanged( m_diagram );
140 }
141 
void diagramDestroyed(KChart::AbstractDiagram *diagram)
This signal is emitted immediately before the diagram is being destroyed.
AbstractDiagram defines the interface for diagram classes.
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
virtual AttributesModel * attributesModel() const
Returns the AttributesModel, that is used by this diagram.
Class only listed here to document inheritance of some KChart classes.
void diagramAttributesChanged(KChart::AbstractDiagram *diagram)
This signal is emitted whenever the attributes of the diagram change.
void diagramDataHidden(KChart::AbstractDiagram *diagram)
This signal is emitted whenever any of the data of the diagram was set (un)hidden.
DiagramObserver(AbstractDiagram *diagram, QObject *parent=nullptr)
Constructs a new observer observing the given diagram.
Orientation
QAbstractItemModel * model() const const
void diagramAboutToBeDestroyed(KChart::AbstractDiagram *diagram)
Emitted when a diagram is being destroyed, but before its data is invalidated.
Global namespace.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void diagramDataChanged(KChart::AbstractDiagram *diagram)
This signal is emitted whenever the data of the diagram changes.
void destroyed(QObject *obj)
Q_EMITQ_EMIT
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Sep 19 2021 22:37:21 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.