1 /* 2 * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved. 3 * 4 * This file is part of the KD Chart library. 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <https://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef __KCHARTDIAGRAMOBSERVER_H_ 21 #define __KCHARTDIAGRAMOBSERVER_H_ 22 23 #include "KChartGlobal.h" 24 25 #include <QObject> 26 #include <QPointer> 27 #include <QModelIndex> 28 29 QT_BEGIN_NAMESPACE 30 class QAbstractItemModel; 31 QT_END_NAMESPACE 32 33 namespace KChart { 34 35 class AbstractDiagram; 36 37 /** 38 * \brief A DiagramObserver watches the associated diagram for 39 * changes and deletion and emits corresponsing signals. 40 */ 41 class KCHART_EXPORT DiagramObserver : public QObject 42 { 43 Q_OBJECT 44 public: 45 /** 46 * Constructs a new observer observing the given diagram. 47 */ 48 explicit DiagramObserver( AbstractDiagram * diagram, QObject* parent = nullptr ); 49 ~DiagramObserver(); 50 51 const AbstractDiagram* diagram() const; 52 AbstractDiagram* diagram(); 53 54 Q_SIGNALS: 55 /** This signal is emitted immediately before the diagram is 56 * being destroyed. */ 57 void diagramDestroyed( AbstractDiagram* diagram ); 58 /** Emitted when a diagram is being destroyed, but before its data is invalidated **/ 59 void diagramAboutToBeDestroyed( AbstractDiagram* diagram ); 60 /** This signal is emitted whenever the data of the diagram changes. */ 61 void diagramDataChanged( AbstractDiagram* diagram ); 62 /** This signal is emitted whenever any of the data of the diagram was set (un)hidden. */ 63 void diagramDataHidden( AbstractDiagram* diagram ); 64 /** This signal is emitted whenever the attributes of the diagram change. */ 65 void diagramAttributesChanged( AbstractDiagram* diagram ); 66 67 private Q_SLOTS: 68 void slotDestroyed(QObject*); 69 void slotAboutToBeDestroyed(); 70 void slotHeaderDataChanged(Qt::Orientation,int,int); 71 void slotDataChanged(QModelIndex,QModelIndex); 72 void slotDataChanged(); 73 void slotDataHidden(); 74 void slotAttributesChanged(); 75 void slotAttributesChanged(QModelIndex,QModelIndex); 76 void slotModelsChanged(); 77 78 private: 79 void init(); 80 81 AbstractDiagram* m_diagram; 82 QPointer<QAbstractItemModel> m_model; 83 QPointer<QAbstractItemModel> m_attributesmodel; 84 }; 85 } 86 87 #endif // KChartDiagramObserver_H 88