File indexing completed on 2024-05-12 16:33:34
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 // Own 0022 #include "PieConfigWidget.h" 0023 #include "ui_PieConfigWidget.h" 0024 0025 // Qt 0026 #include <QAction> 0027 #include <QMenu> 0028 #include <QLatin1String> 0029 0030 // KF5 0031 #include <klocalizedstring.h> 0032 #include <kmessagebox.h> 0033 #include <kfontchooser.h> 0034 0035 // Calligra 0036 #include <interfaces/KoChartModel.h> 0037 #include <KoIcon.h> 0038 0039 // KChart 0040 #include <KChartChart> 0041 #include <KChartPosition> 0042 #include <KChartCartesianAxis> 0043 #include <KChartGridAttributes> 0044 #include <KChartPieAttributes> 0045 #include <KChartAbstractCartesianDiagram> 0046 #include <KChartLegend> 0047 #include <KChartDataValueAttributes> 0048 #include <KChartMeasure> 0049 0050 // KoChart 0051 #include "ChartProxyModel.h" 0052 #include "PlotArea.h" 0053 #include "DataSet.h" 0054 #include "ChartDebug.h" 0055 0056 using namespace KoChart; 0057 0058 0059 PieConfigWidget::PieConfigWidget(QWidget *parent) 0060 : ConfigSubWidgetBase(parent) 0061 { 0062 init(); 0063 } 0064 0065 PieConfigWidget::PieConfigWidget(QList<ChartType> types, QWidget *parent) 0066 : ConfigSubWidgetBase(types, parent) 0067 { 0068 init(); 0069 } 0070 0071 PieConfigWidget::~PieConfigWidget() 0072 { 0073 } 0074 0075 void PieConfigWidget::init() 0076 { 0077 setObjectName("PieConfigWidget"); 0078 m_ui.setupUi(this); 0079 0080 connect(m_ui.dataPoints, SIGNAL(currentIndexChanged(int)), this, SLOT(dataPointSelectionChanged(int))); 0081 connect(m_ui.dataPointBrush, SIGNAL(changed(QColor)), this, SLOT(brushChanged(QColor))); 0082 connect(m_ui.dataPointPen, SIGNAL(changed(QColor)), this, SLOT(penChanged(QColor))); 0083 connect(m_ui.explodeFactor, SIGNAL(valueChanged(int)), this, SLOT(explodeFactorChanged(int))); 0084 connect(m_ui.dataPointShowCategory, SIGNAL(toggled(bool)), this, SLOT(showCategoryChanged(bool))); 0085 connect(m_ui.dataPointShowNumber, SIGNAL(toggled(bool)), this, SLOT(showNumberChanged(bool))); 0086 connect(m_ui.dataPointShowPercent, SIGNAL(toggled(bool)), this, SLOT(showPercentChanged(bool))); 0087 } 0088 void PieConfigWidget::open(ChartShape* shape) 0089 { 0090 ConfigSubWidgetBase::open(shape); 0091 } 0092 0093 void PieConfigWidget::updateData(ChartType type, ChartSubtype subtype) 0094 { 0095 Q_UNUSED(subtype); 0096 0097 if (!chart || !chartTypes.contains(type)) { 0098 return; 0099 } 0100 m_dataSet = chart->plotArea()->dataSets().value(0); 0101 if (!m_dataSet) { 0102 return; 0103 } 0104 int index = m_ui.dataPoints->currentIndex(); 0105 blockSignals(true); 0106 m_ui.dataPoints->clear(); 0107 if (m_dataSet->size() == 0) { 0108 return; 0109 } 0110 for (int i = 0; i < m_dataSet->size(); ++i) { 0111 QString title = m_dataSet->categoryData(i).toString(); 0112 if (title.isEmpty()) { 0113 title = i18n("Data Point %1", i + 1); 0114 } 0115 m_ui.dataPoints->addItem(title); 0116 } 0117 blockSignals(false); 0118 0119 dataPointSelectionChanged(index < 0 ? 0 : index); 0120 } 0121 0122 void PieConfigWidget::dataPointSelectionChanged(int index) 0123 { 0124 // Check for valid index 0125 qInfo()<<Q_FUNC_INFO<<index; 0126 if (index < 0) { 0127 return; 0128 } 0129 blockSignals(true); 0130 0131 m_ui.explodeFactor->setValue((int)(m_dataSet->pieAttributes(index).explodeFactor()*100)); 0132 0133 m_ui.dataPointBrush->setColor(m_dataSet->brush(index).color()); 0134 0135 m_ui.dataPointPen->setColor(m_dataSet->pen(index).color()); 0136 0137 m_ui.dataPointShowCategory->setChecked(m_dataSet->valueLabelType(index).category); 0138 0139 m_ui.dataPointShowNumber->setChecked(m_dataSet->valueLabelType(index).number); 0140 0141 m_ui.dataPointShowPercent->setChecked(m_dataSet->valueLabelType(index).percentage); 0142 0143 m_ui.dataPoints->setCurrentIndex(index); 0144 0145 blockSignals(false); 0146 0147 } 0148 0149 void PieConfigWidget::brushChanged(const QColor& color) 0150 { 0151 int index = m_ui.dataPoints->currentIndex(); 0152 if (index < 0) { 0153 return; 0154 } 0155 emit brushChanged(m_dataSet, color, index); 0156 } 0157 0158 void PieConfigWidget::penChanged(const QColor& color) 0159 { 0160 int index = m_ui.dataPoints->currentIndex(); 0161 if (index < 0) { 0162 return; 0163 } 0164 emit penChanged(m_dataSet, color, index); 0165 } 0166 0167 void PieConfigWidget::explodeFactorChanged(int percent) 0168 { 0169 int index = m_ui.dataPoints->currentIndex(); 0170 if (index < 0) { 0171 return; 0172 } 0173 emit explodeFactorChanged(m_dataSet, index, percent); 0174 } 0175 0176 void PieConfigWidget::showCategoryChanged(bool b) 0177 { 0178 int index = m_ui.dataPoints->currentIndex(); 0179 if (index < 0) { 0180 return; 0181 } 0182 emit showCategoryChanged(m_dataSet, b, index); 0183 } 0184 0185 void PieConfigWidget::showNumberChanged(bool b) 0186 { 0187 int index = m_ui.dataPoints->currentIndex(); 0188 if (index < 0) { 0189 return; 0190 } 0191 emit showNumberChanged(m_dataSet, b, index); 0192 } 0193 0194 void PieConfigWidget::showPercentChanged(bool b) 0195 { 0196 int index = m_ui.dataPoints->currentIndex(); 0197 if (index < 0) { 0198 return; 0199 } 0200 emit showPercentChanged(m_dataSet, b, index); 0201 }