1 /*************************************************************************** 2 File : PieCurve.h 3 Project : QtiPlot 4 -------------------------------------------------------------------- 5 Copyright : (C) 2004 - 2010 by Ion Vasilief 6 Email (use @ for *) : ion_vasilief*yahoo.fr 7 Description : Pie plot class 8 9 ***************************************************************************/ 10 11 /*************************************************************************** 12 * * 13 * This program is free software; you can redistribute it and/or modify * 14 * it under the terms of the GNU General Public License as published by * 15 * the Free Software Foundation; either version 2 of the License, or * 16 * (at your option) any later version. * 17 * * 18 * This program is distributed in the hope that it will be useful, * 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 21 * GNU General Public License for more details. * 22 * * 23 * You should have received a copy of the GNU General Public License * 24 * along with this program; if not, write to the Free Software * 25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 26 * Boston, MA 02110-1301 USA * 27 * * 28 ***************************************************************************/ 29 #include <qwt_plot.h> 30 #include "PlotCurve.h" 31 #include "LegendWidget.h" 32 33 class PieLabel; 34 35 //! Pie plot class 36 class PieCurve: public DataCurve 37 { 38 public: 39 PieCurve(Table *t, const QString& name, int startRow, int endRow); 40 void clone(PieCurve* c); 41 viewAngle()42 double viewAngle(){return d_view_angle;}; setViewAngle(double a)43 void setViewAngle(double a){d_view_angle = a;}; 44 thickness()45 double thickness(){return d_thickness;}; setThickness(double t)46 void setThickness(double t){d_thickness = t;}; 47 horizontalOffset()48 double horizontalOffset(){return d_horizontal_offset;}; setHorizontalOffset(double d)49 void setHorizontalOffset(double d){d_horizontal_offset = d;}; 50 counterClockwise()51 bool counterClockwise(){return d_counter_clockwise;}; setCounterClockwise(bool on)52 void setCounterClockwise(bool on){d_counter_clockwise = on;}; 53 startAzimuth()54 double startAzimuth(){return d_start_azimuth;}; setStartAzimuth(double angle)55 void setStartAzimuth(double angle){d_start_azimuth = angle;}; 56 labelsEdgeDistance()57 double labelsEdgeDistance(){return d_edge_dist;}; setLabelsEdgeDistance(double d)58 void setLabelsEdgeDistance(double d){d_edge_dist = d;}; 59 labelsAutoFormat()60 bool labelsAutoFormat(){return d_auto_labeling;}; setLabelsAutoFormat(bool on)61 void setLabelsAutoFormat(bool on){d_auto_labeling = on;}; 62 labelsValuesFormat()63 bool labelsValuesFormat(){return d_values;}; setLabelValuesFormat(bool on)64 void setLabelValuesFormat(bool on){d_values = on;}; 65 labelsPercentagesFormat()66 bool labelsPercentagesFormat(){return d_percentages;}; setLabelPercentagesFormat(bool on)67 void setLabelPercentagesFormat(bool on){d_percentages = on;}; 68 labelCategories()69 bool labelCategories(){return d_categories;}; setLabelCategories(bool on)70 void setLabelCategories(bool on){d_categories = on;}; 71 fixedLabelsPosition()72 bool fixedLabelsPosition(){return d_fixed_labels_pos;}; setFixedLabelsPosition(bool on)73 void setFixedLabelsPosition(bool on){d_fixed_labels_pos = on;}; 74 75 QColor color(int i) const; 76 radius()77 int radius(){return d_pie_ray;}; setRadius(int size)78 void setRadius(int size){d_pie_ray = size;}; 79 pattern()80 Qt::BrushStyle pattern(){return QwtPlotCurve::brush().style();}; 81 void setBrushStyle(const Qt::BrushStyle& style); 82 setFirstColor(int index)83 void setFirstColor(int index){d_first_color = index;}; firstColor()84 int firstColor(){return d_first_color;}; 85 86 void loadData(); 87 void initLabels(); 88 void clearLabels(); 89 90 PieLabel* addLabel(PieLabel *l, bool clone = false); 91 labelsList()92 QList <PieLabel *> labelsList(){return d_texts_list;}; 93 94 private: 95 void draw(QPainter *painter,const QwtScaleMap &xMap, 96 const QwtScaleMap &yMap, int from, int to) const; 97 void drawSlices(QPainter *painter, const QwtScaleMap &xMap, 98 const QwtScaleMap &yMap, int from, int to) const; 99 void drawDisk(QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap) const; 100 101 int d_pie_ray; 102 int d_first_color; 103 double d_start_azimuth; 104 double d_view_angle; 105 double d_thickness; 106 double d_horizontal_offset; 107 double d_edge_dist; 108 bool d_counter_clockwise; 109 bool d_auto_labeling; 110 bool d_values; 111 bool d_percentages; 112 bool d_categories; 113 bool d_fixed_labels_pos; 114 QList <PieLabel *> d_texts_list; 115 //! Stores table row indices to be displayed in PieLabels if d_categories is true. 116 QVarLengthArray<int> d_table_rows; 117 }; 118 119 class PieLabel: public LegendWidget 120 { 121 Q_OBJECT 122 123 public: 124 PieLabel(Graph *, PieCurve *pie = 0); 125 126 QString customText(); setCustomText(const QString & s)127 void setCustomText(const QString& s){d_custom_text = s;}; 128 setPieCurve(PieCurve * pie)129 void setPieCurve(PieCurve *pie){d_pie_curve = pie;}; 130 131 QString saveToString(); 132 static void restore(Graph *g, const QStringList& lst); 133 134 private: 135 void closeEvent(QCloseEvent* e); 136 137 PieCurve *d_pie_curve; 138 QString d_custom_text; 139 }; 140