File indexing completed on 2024-05-12 16:33:31
0001 /* This file is part of the KDE project 0002 0003 Copyright 2018 Dag Andersen <danders@get2net.dk> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License as published by the Free Software Foundation; either 0008 version 2 of the License, or (at your option) any later version. 0009 0010 This library is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this library; see the file COPYING.LIB. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 * Boston, MA 02110-1301, USA. 0019 */ 0020 0021 0022 #ifndef KOCHART_CONFIGWIDGETBASE 0023 #define KOCHART_CONFIGWIDGETBASE 0024 0025 0026 #include <KoShapeConfigWidgetBase.h> 0027 0028 #include "ChartShape.h" 0029 #include "ConfigSubWidgetBase.h" 0030 0031 #include <QWidget> 0032 0033 #include "ChartDebug.h" 0034 0035 namespace KoChart 0036 { 0037 0038 class ConfigWidgetBase : public KoShapeConfigWidgetBase 0039 { 0040 public: 0041 ConfigWidgetBase() {} 0042 ~ConfigWidgetBase() {} 0043 0044 /// Calling open() with @p shape will call deactivate() 0045 /// reimplemented from KoShapeConfigWidgetBase 0046 void open(KoShape *shape) override { 0047 if (!shape) { 0048 deactivate(); 0049 return; 0050 } 0051 chart = dynamic_cast<ChartShape*>(shape); 0052 if (!chart) { 0053 chart = dynamic_cast<ChartShape*>(shape->parent()); 0054 if (!chart) { 0055 deactivate(); 0056 return; 0057 } 0058 } 0059 if (chart) { 0060 connect(chart, &ChartShape::chartTypeChanged, this, &ConfigWidgetBase::removeSubDialogs); 0061 } 0062 } 0063 virtual void deactivate() { 0064 for (ConfigSubWidgetBase *w : findChildren<ConfigSubWidgetBase*>()) { 0065 w->deactivate(); 0066 } 0067 if (chart) { 0068 deleteSubDialogs(); 0069 disconnect(chart, &ChartShape::chartTypeChanged, this, &ConfigWidgetBase::removeSubDialogs); 0070 } 0071 chart = 0; 0072 } 0073 0074 /// reimplemented from KoShapeConfigWidgetBase 0075 void save() override { Q_ASSERT(false); } 0076 0077 /// Reimplement to update the ui 0078 virtual void updateData() {} 0079 0080 /// Reimplement if you open any dialogs 0081 /// This is called from close() 0082 virtual void deleteSubDialogs(ChartType type = LastChartType) {Q_UNUSED(type)} 0083 0084 void blockSignals(bool block) { 0085 blockSignals(this, block); 0086 } 0087 void blockSignals(QWidget *w, bool block) { 0088 QList<QWidget*> lst = w->findChildren<QWidget*>(); 0089 for (int i = 0; i < lst.count(); ++i) { 0090 lst.at(i)->blockSignals(block); 0091 } 0092 } 0093 0094 public: 0095 ChartShape *chart; 0096 0097 private Q_SLOTS: 0098 void removeSubDialogs(ChartType type, ChartType prev = LastChartType) { 0099 if (type != prev) { 0100 deleteSubDialogs(); 0101 } 0102 } 0103 }; 0104 0105 } // namespace KoChart 0106 0107 0108 #endif // KOCHART_CONFIGWIDGETBASE