File indexing completed on 2024-05-12 16:33:32
0001 /* This file is part of the KDE project 0002 0003 Copyright 2007-2008 Johannes Simon <johannes.simon@gmail.com> 0004 Copyright (C) 2010 Carlos Licea <carlos@kdab.com> 0005 Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 0006 Contact: Suresh Chande suresh.chande@nokia.com 0007 0008 This library is free software; you can redistribute it and/or 0009 modify it under the terms of the GNU Library General Public 0010 License as published by the Free Software Foundation; either 0011 version 2 of the License, or (at your option) any later version. 0012 0013 This library is distributed in the hope that it will be useful, 0014 but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0016 Library General Public License for more details. 0017 0018 You should have received a copy of the GNU Library General Public License 0019 along with this library; see the file COPYING.LIB. If not, write to 0020 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0021 * Boston, MA 02110-1301, USA. 0022 */ 0023 0024 0025 #ifndef KCHART_DATASET_H 0026 #define KCHART_DATASET_H 0027 0028 0029 // Qt 0030 #include <QPen> 0031 #include <QDebug> 0032 0033 // KoChart 0034 #include "ChartShape.h" 0035 #include "CellRegion.h" 0036 0037 namespace KChart { 0038 class DataValueAttributes; 0039 class PieAttributes; 0040 class MarkerAttributes; 0041 } 0042 0043 class KoShapeLoadingContext; 0044 0045 namespace KoChart { 0046 0047 class KChartModel; 0048 0049 /** 0050 * @brief The DataSet class stores properties of a single data series. 0051 * 0052 * A global chart type can be overridden by setting a specific type 0053 * on a data series. 0054 * 0055 * To change properties of a single data point inside a data series, 0056 * use section's like for example \a brush(int section) where the 0057 * section refers to the data-point number. 0058 */ 0059 0060 class DataSet 0061 { 0062 public: 0063 explicit DataSet(int dataSetNr); 0064 ~DataSet(); 0065 0066 // Getter methods 0067 QString title() const; 0068 ChartType chartType() const; 0069 ChartSubtype chartSubType() const; 0070 Axis *attachedAxis() const; 0071 0072 /** 0073 * Describes ODF attribute chart:data-label-number from ยง15.32.3 0074 */ 0075 class ValueLabelType { 0076 public: 0077 /// Show value as number. 0078 bool number; 0079 bool numberIsLoaded; 0080 /// Show value as percentage. 0081 bool percentage; 0082 bool percentageIsLoaded; 0083 /// Show category. 0084 bool category; 0085 bool categoryIsLoaded; 0086 /// Show legend key. 0087 /// TODO: not supported by KChart 0088 bool symbol; 0089 bool symbolIsLoaded; 0090 /// Constructor. 0091 explicit ValueLabelType(bool number = false, 0092 bool percentage = false, 0093 bool category = false, 0094 bool symbol = true) // to keep old behaviour where symbols were displayed by default 0095 : number(number) 0096 , numberIsLoaded(false) 0097 , percentage(percentage) 0098 , percentageIsLoaded(false) 0099 , category(category) 0100 , categoryIsLoaded(false) 0101 , symbol(symbol) 0102 , symbolIsLoaded(false) 0103 {} 0104 0105 /// Returns true if no label will be displayed. 0106 bool noLabel() const { return !number && !percentage && !category && !symbol; } 0107 }; 0108 0109 /** 0110 * Sets the value label type. \see ValueLabelType 0111 * 0112 * \param section The data point to set this type for. -1 will set 0113 * a series-wide value 0114 */ 0115 void setValueLabelType(const ValueLabelType &type, int section = -1); 0116 0117 /** 0118 * \return the value label type. 0119 * \see ValueLabelType 0120 * 0121 * \param section The data point to return the type for. -1 will return 0122 * the series-wide value 0123 */ 0124 ValueLabelType valueLabelType(int section = -1) const; 0125 0126 /** 0127 * Sets the marker attributes of the series 0128 * 0129 * \param section The data point to set this type for. -1 will set 0130 * a series-wide value 0131 */ 0132 void setMarkerAttributes(const KChart::MarkerAttributes& attribs, int section = -1); 0133 0134 /** 0135 * \return the MarkerAttributes. 0136 * \see ValueLabelType 0137 * 0138 * \param section The data point to return the MarkerAttributes for. -1 will return 0139 * the series-wide value 0140 */ 0141 KChart::MarkerAttributes getMarkerAttributes(int section = -1) const; 0142 0143 // Graphics properties for the visualization of this dataset. 0144 QPen pen() const; 0145 QBrush brush() const; 0146 QIcon markerIcon(OdfMarkerStyle markerStyle); 0147 KChart::PieAttributes pieAttributes() const; 0148 QPen pen(int section) const; 0149 QBrush brush(int section) const; 0150 KChart::PieAttributes pieAttributes(int section) const; 0151 KChart::DataValueAttributes dataValueAttributes(int section = -1) const; 0152 int number() const; 0153 0154 bool showMeanValue() const; 0155 QPen meanValuePen() const; 0156 0157 bool showLowerErrorIndicator() const; 0158 bool showUpperErrorIndicator() const; 0159 QPen errorIndicatorPen() const; 0160 ErrorCategory errorCategory() const; 0161 qreal errorPercentage() const; 0162 qreal errorMargin() const; 0163 qreal lowerErrorLimit() const; 0164 qreal upperErrorLimit() const; 0165 /// returns the marker symbol type to use 0166 OdfSymbolType odfSymbolType() const; 0167 /// Set symbol type to @p type and marker style to @p style 0168 void setOdfSymbolType(OdfSymbolType type); 0169 OdfMarkerStyle markerStyle() const; 0170 void setMarkerStyle(OdfMarkerStyle style); 0171 0172 // Setter methods 0173 void setChartType(ChartType type); 0174 void setChartSubType(ChartSubtype type); 0175 void setAttachedAxis(Axis *axis); 0176 0177 void setPen(const QPen &pen); 0178 void setBrush(const QBrush &brush); 0179 void setPen(int section, const QPen &pen); 0180 void setBrush(int section, const QBrush &brush); 0181 0182 void setPieExplodeFactor(int factor); 0183 void setPieExplodeFactor(int section, int factor); 0184 0185 void setShowMeanValue(bool b); 0186 void setMeanValuePen(const QPen &pen); 0187 0188 void setShowLowerErrorIndicator(bool b); 0189 void setShowUpperErrorIndicator(bool b); 0190 void setShowErrorIndicators(bool lower, bool upper); 0191 void setErrorIndicatorPen(const QPen &pen); 0192 void setErrorCategory(ErrorCategory category); 0193 void setErrorPercentage(qreal percentage); 0194 void setErrorMargin(qreal margin); 0195 void setLowerErrorLimit(qreal limit); 0196 void setUpperErrorLimit(qreal limit); 0197 0198 /** 0199 * Returns the x-data. 0200 * 0201 * \param index the unique index that identifies the cell. 0202 * \param role either Qt::DisplayRole if the content displayed 0203 * in the cell (aka the displayText()) should be returned or 0204 * Qt::EditRole if the actual data of the cell (which can be 0205 * different from what is displayed) should be returned. 0206 * \return the x-data value. 0207 */ 0208 QVariant xData(int index, int role = Qt::EditRole) const; 0209 0210 /** 0211 * Returns the y-data aka value-data. 0212 * 0213 * \param index the unique index that identifies the cell. 0214 * \param role either Qt::DisplayRole if the content displayed 0215 * in the cell (aka the displayText()) should be returned or 0216 * Qt::EditRole if the actual data of the cell (which can be 0217 * different from what is displayed) should be returned. 0218 * \return the y-data value. 0219 */ 0220 QVariant yData(int index, int role = Qt::EditRole) const; 0221 0222 /** 0223 * Used for bubble width in bubble charts. May also be referred to as 0224 * 'z data' in some cases. 0225 */ 0226 QVariant customData(int index, int role = Qt::EditRole) const; 0227 0228 QVariant categoryData(int index, int role = Qt::EditRole) const; 0229 0230 QVariant labelData() const; 0231 QString defaultLabelData() const; 0232 0233 CellRegion xDataRegion() const; 0234 CellRegion yDataRegion() const; 0235 CellRegion customDataRegion() const; 0236 CellRegion categoryDataRegion() const; 0237 CellRegion labelDataRegion() const; 0238 // TODO: Region for custom colors 0239 0240 void setXDataRegion(const CellRegion ®ion); 0241 void setYDataRegion(const CellRegion ®ion); 0242 void setCustomDataRegion(const CellRegion ®ion); 0243 void setCategoryDataRegion(const CellRegion ®ion); 0244 void setLabelDataRegion(const CellRegion ®ion); 0245 0246 int size() const; 0247 int dimension() const; 0248 0249 // Called by the proxy model 0250 void yDataChanged(const QRect ®ion) const; 0251 void xDataChanged(const QRect ®ion) const; 0252 void customDataChanged(const QRect ®ion) const; 0253 void labelDataChanged(const QRect ®ion) const; 0254 void categoryDataChanged(const QRect ®ion) const; 0255 0256 void setKdChartModel(KChartModel *model); 0257 KChartModel *kdChartModel() const; 0258 0259 bool loadOdf(const KoXmlElement &n, KoShapeLoadingContext &context); 0260 bool loadSeriesIntoDataset(const KoXmlElement &n, KoShapeLoadingContext &context); 0261 /** 0262 * Saves a series to ODF. Creates a new chart:series element. 0263 */ 0264 void saveOdf(KoShapeSavingContext &context) const; 0265 0266 QString axisName() const; 0267 0268 private: 0269 class Private; 0270 Private *const d; 0271 }; 0272 0273 } // Namespace KoChart 0274 0275 QDebug operator<<(QDebug dbg, const KoChart::DataSet* ds); 0276 QDebug operator<<(QDebug dbg, const KoChart::DataSet::ValueLabelType &v); 0277 0278 #endif // KCHART_DATASET_H 0279