File indexing completed on 2024-05-12 16:33:33

0001 /* This file is part of the KDE project
0002 
0003    Copyright 2010 Johannes Simon <johannes.simon@gmail.com>
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 #include "kochart_global.h"
0022 
0023 namespace KoChart {
0024 
0025 bool isPolar(ChartType type)
0026 {
0027     switch (type)
0028     {
0029     case CircleChartType:
0030     case RingChartType:
0031     case RadarChartType:
0032     case FilledRadarChartType:
0033         return true;
0034     default:
0035         return false;
0036     }
0037     return false;
0038 }
0039 
0040 bool isCartesian(ChartType type)
0041 {
0042     return !isPolar(type);
0043 }
0044 
0045 ChartSubtype defaultChartSubtype(ChartType type)
0046 {
0047     switch (type) {
0048         case BarChartType:
0049         case LineChartType:
0050         case AreaChartType:
0051             return NormalChartSubtype;
0052         case CircleChartType:
0053         case RingChartType:
0054             return NoChartSubtype;
0055         case RadarChartType:
0056         case FilledRadarChartType:
0057             return NormalChartSubtype;
0058         case ScatterChartType:
0059             return NoChartSubtype;
0060         case SurfaceChartType:
0061             return NoChartSubtype;
0062         case BubbleChartType:
0063             return NoChartSubtype;
0064         case StockChartType:
0065             return HighLowCloseChartSubtype;
0066         default:
0067             break;
0068     }
0069     return NoChartSubtype;
0070 }
0071 
0072 int numDimensions(ChartType type, ChartSubtype subtype)
0073 {
0074     int dimensions = 1;
0075 
0076     switch (type) {
0077     case BarChartType:
0078     case LineChartType:
0079     case AreaChartType:
0080     case CircleChartType:
0081     case RingChartType:
0082     case RadarChartType:
0083     case FilledRadarChartType:
0084         dimensions = 1;
0085         break;
0086     case ScatterChartType:
0087     case SurfaceChartType:
0088         dimensions = 2;
0089         break;
0090     case BubbleChartType:
0091         dimensions = 3;
0092         break;
0093     case StockChartType:
0094         dimensions = 1;
0095         break;
0096     case GanttChartType:
0097         // FIXME: Figure out correct number of dimensions
0098         dimensions = 1;
0099         break;
0100     case LastChartType:
0101         dimensions = 1;
0102     }
0103 
0104     return dimensions;
0105 }
0106 
0107 QMap<QPair<qint64, qint64>, QLatin1String> chartTypeIconMap;
0108 
0109 void insertIcon(ChartType type, ChartSubtype subtype, const QLatin1String &name)
0110 {
0111     chartTypeIconMap[QPair<qint64, qint64>((qint64)(type), (qint64)(subtype))] = name;
0112 }
0113 
0114 void initchartTypeIconMap()
0115 {
0116     // Bar charts
0117     insertIcon(BarChartType, NoChartSubtype, QLatin1String("office-chart-bar"));
0118     insertIcon(BarChartType, NormalChartSubtype, QLatin1String("office-chart-bar"));
0119     insertIcon(BarChartType, StackedChartSubtype, QLatin1String("office-chart-bar-stacked"));
0120     insertIcon(BarChartType, PercentChartSubtype, QLatin1String("office-chart-bar-percentage"));
0121 
0122     // Line charts
0123     insertIcon(LineChartType, NoChartSubtype, QLatin1String("office-chart-line"));
0124     insertIcon(LineChartType, NormalChartSubtype, QLatin1String("office-chart-line"));
0125     insertIcon(LineChartType, StackedChartSubtype, QLatin1String("office-chart-line-stacked"));
0126     insertIcon(LineChartType, PercentChartSubtype, QLatin1String("office-chart-line-percentage"));
0127 
0128     // Area charts
0129     insertIcon(AreaChartType, NoChartSubtype, QLatin1String("office-chart-area"));
0130     insertIcon(AreaChartType, NormalChartSubtype, QLatin1String("office-chart-area"));
0131     insertIcon(AreaChartType, StackedChartSubtype, QLatin1String("office-chart-area-stacked"));
0132     insertIcon(AreaChartType, PercentChartSubtype, QLatin1String("office-chart-area-percentage"));
0133 
0134     // Circular charts: pie and ring
0135     insertIcon(CircleChartType, NoChartSubtype, QLatin1String("office-chart-pie"));
0136     insertIcon(CircleChartType, NormalChartSubtype, QLatin1String("office-chart-pie"));
0137 
0138     insertIcon(RingChartType, NoChartSubtype, QLatin1String("office-chart-ring"));
0139     insertIcon(RingChartType, NormalChartSubtype, QLatin1String("office-chart-ring"));
0140 
0141     // Polar charts: radar
0142     insertIcon(RadarChartType, NoChartSubtype, QLatin1String("office-chart-polar"));
0143     insertIcon(RadarChartType, NormalChartSubtype, QLatin1String("office-chart-polar"));
0144     insertIcon(RadarChartType, StackedChartSubtype, QLatin1String("office-chart-polar-stacked"));
0145     insertIcon(RadarChartType, PercentChartSubtype, QLatin1String("office-chart-polar"));
0146 
0147     insertIcon(FilledRadarChartType, NoChartSubtype, QLatin1String("office-chart-polar-filled"));
0148     insertIcon(FilledRadarChartType, NormalChartSubtype, QLatin1String("office-chart-polar-filled"));
0149     insertIcon(FilledRadarChartType, StackedChartSubtype, QLatin1String("office-chart-polar-filled"));
0150     insertIcon(FilledRadarChartType, PercentChartSubtype, QLatin1String("office-chart-polar-filled"));
0151 
0152     // X/Y charts: scatter and bubble
0153     insertIcon(ScatterChartType, NoChartSubtype, QLatin1String("office-chart-scatter"));
0154     insertIcon(ScatterChartType, NormalChartSubtype, QLatin1String("office-chart-scatter"));
0155 
0156     insertIcon(BubbleChartType, NoChartSubtype, QLatin1String("skg-chart-bubble"));
0157     insertIcon(BubbleChartType, NormalChartSubtype, QLatin1String("skg-chart-bubble"));
0158 
0159     // Stock Charts
0160     insertIcon(StockChartType, NoChartSubtype, QLatin1String("office-chart-stock-candlestick"));
0161     insertIcon(StockChartType, HighLowCloseChartSubtype, QLatin1String("office-chart-stock-hlc"));
0162     insertIcon(StockChartType, OpenHighLowCloseChartSubtype, QLatin1String("office-chart-stock-ohlc"));
0163     insertIcon(StockChartType, CandlestickChartSubtype, QLatin1String("office-chart-stock-candlestick"));
0164 
0165     // TODO surface/gantt
0166 }
0167 
0168 QLatin1String chartTypeIconName(ChartType type, ChartSubtype subtype)
0169 {
0170     QPair<qint64, qint64> entry((qint64)(type), (qint64)(subtype));
0171     if (chartTypeIconMap.isEmpty()) {
0172         initchartTypeIconMap();
0173     }
0174     return chartTypeIconMap.value(entry);
0175 }
0176 
0177 } // namespace KoChart
0178 
0179 QDebug operator<<(QDebug dbg, KoChart::Position p)
0180 {
0181     switch (p) {
0182     case KoChart::StartPosition: dbg << "(StartPosition)"; break;
0183     case KoChart::TopPosition: dbg << "(TopPosition)"; break;
0184     case KoChart::EndPosition: dbg << "(EndPosition)"; break;
0185     case KoChart::BottomPosition: dbg << "(BottomPosition)"; break;
0186     case KoChart::TopStartPosition: dbg << "(BottomPosition)"; break;
0187     case KoChart::TopEndPosition: dbg << "(TopEndPosition)"; break;
0188     case KoChart::BottomStartPosition: dbg << "(BottomStartPosition)"; break;
0189     case KoChart::BottomEndPosition: dbg << "(BottomEndPosition)"; break;
0190     case KoChart::CenterPosition: dbg << "(CenterPosition)"; break;
0191     case KoChart::FloatingPosition: dbg << "(FloatingPosition)"; break;
0192     default: break;
0193         Q_ASSERT(false); // Unknown position
0194     }
0195     return dbg;
0196 }
0197 
0198 QDebug operator<<(QDebug dbg, KoChart::ChartType ct)
0199 {
0200     switch (ct) {
0201         case KoChart::BarChartType: dbg << "(BarChartType)"; break;
0202         case KoChart::LineChartType: dbg << "(LineChartType)"; break;
0203         case KoChart::AreaChartType: dbg << "(AreaChartType)"; break;
0204         case KoChart::CircleChartType: dbg << "(CircleChartType)"; break;
0205         case KoChart::RingChartType: dbg << "(RingChartType)"; break;
0206         case KoChart::RadarChartType: dbg << "(RadarChartType)"; break;
0207         case KoChart::FilledRadarChartType: dbg << "(FilledRadarChartType)"; break;
0208         case KoChart::ScatterChartType: dbg << "(ScatterChartType)"; break;
0209         case KoChart::SurfaceChartType: dbg << "(SurfaceChartType)"; break;
0210         case KoChart::BubbleChartType: dbg << "(BubbleChartType)"; break;
0211         case KoChart::StockChartType: dbg << "(StockChartType)"; break;
0212         case KoChart::GanttChartType: dbg << "(StockChartType)"; break;
0213         case KoChart::LastChartType: dbg << "(LastChartType)"; break;
0214     }
0215     return dbg;
0216 }
0217 
0218 QDebug operator<<(QDebug dbg, KoChart::ChartSubtype st)
0219 {
0220     switch (st) {
0221         case KoChart::NoChartSubtype: dbg << "(NoChartSubtype)"; break;
0222         case KoChart::NormalChartSubtype: dbg << "(NormalChartSubtype)"; break;
0223         case KoChart::StackedChartSubtype: dbg << "(StackedChartSubtype)"; break;
0224         case KoChart::PercentChartSubtype: dbg << "(PercentChartSubtype)"; break;
0225         case KoChart::HighLowCloseChartSubtype: dbg << "(HighLowCloseChartSubtype)"; break;
0226         case KoChart::OpenHighLowCloseChartSubtype: dbg << "(OpenHighLowCloseChartSubtype)"; break;
0227         case KoChart::CandlestickChartSubtype: dbg << "(CandlestickChartSubtype)"; break;
0228     }
0229     return dbg;
0230 }