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
17using 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
30DiagramObserver::~DiagramObserver()
31{
32}
33
34const AbstractDiagram* DiagramObserver::diagram() const
35{
36 return m_diagram;
37}
38
39AbstractDiagram* DiagramObserver::diagram()
40{
41 return m_diagram;
42}
43
44
45void 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
86void 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;
94}
95
96void DiagramObserver::slotAboutToBeDestroyed()
97{
99}
100
101void DiagramObserver::slotModelsChanged()
102{
103 init();
104 slotDataChanged();
105 slotAttributesChanged();
106}
107
108void DiagramObserver::slotHeaderDataChanged(Qt::Orientation,int,int)
109{
110 //qDebug() << "DiagramObserver::slotHeaderDataChanged()";
111 Q_EMIT diagramDataChanged( m_diagram );
112}
113
114void DiagramObserver::slotDataChanged(QModelIndex,QModelIndex)
115{
116 slotDataChanged();
117}
118
119void DiagramObserver::slotDataChanged()
120{
121 //qDebug() << "DiagramObserver::slotDataChanged()";
122 Q_EMIT diagramDataChanged( m_diagram );
123}
124
125void DiagramObserver::slotDataHidden()
126{
127 //qDebug() << "DiagramObserver::slotDataHidden()";
128 Q_EMIT diagramDataHidden( m_diagram );
129}
130
131void DiagramObserver::slotAttributesChanged(QModelIndex,QModelIndex)
132{
133 slotAttributesChanged();
134}
135
136void DiagramObserver::slotAttributesChanged()
137{
138 //qDebug() << "DiagramObserver::slotAttributesChanged()";
139 Q_EMIT diagramAttributesChanged( m_diagram );
140}
141
AbstractDiagram defines the interface for diagram classes.
virtual AttributesModel * attributesModel() const
Returns the AttributesModel, that is used by this diagram.
DiagramObserver(AbstractDiagram *diagram, QObject *parent=nullptr)
Constructs a new observer observing the given diagram.
void diagramDestroyed(KChart::AbstractDiagram *diagram)
This signal is emitted immediately before the diagram is being destroyed.
void diagramDataChanged(KChart::AbstractDiagram *diagram)
This signal is emitted whenever the data of the diagram changes.
void diagramDataHidden(KChart::AbstractDiagram *diagram)
This signal is emitted whenever any of the data of the diagram was set (un)hidden.
void diagramAboutToBeDestroyed(KChart::AbstractDiagram *diagram)
Emitted when a diagram is being destroyed, but before its data is invalidated.
void diagramAttributesChanged(KChart::AbstractDiagram *diagram)
This signal is emitted whenever the attributes of the diagram change.
QAbstractItemModel * model() const const
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void destroyed(QObject *obj)
bool disconnect(const QMetaObject::Connection &connection)
Orientation
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.