QtiPlot
0.9.8.2
|
00001 /*************************************************************************** 00002 File : PieCurve.h 00003 Project : QtiPlot 00004 -------------------------------------------------------------------- 00005 Copyright : (C) 2004 - 2010 by Ion Vasilief 00006 Email (use @ for *) : ion_vasilief*yahoo.fr 00007 Description : Pie plot class 00008 00009 ***************************************************************************/ 00010 00011 /*************************************************************************** 00012 * * 00013 * This program is free software; you can redistribute it and/or modify * 00014 * it under the terms of the GNU General Public License as published by * 00015 * the Free Software Foundation; either version 2 of the License, or * 00016 * (at your option) any later version. * 00017 * * 00018 * This program is distributed in the hope that it will be useful, * 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00021 * GNU General Public License for more details. * 00022 * * 00023 * You should have received a copy of the GNU General Public License * 00024 * along with this program; if not, write to the Free Software * 00025 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 00026 * Boston, MA 02110-1301 USA * 00027 * * 00028 ***************************************************************************/ 00029 #include <qwt_plot.h> 00030 #include "PlotCurve.h" 00031 #include "LegendWidget.h" 00032 00033 class PieLabel; 00034 00036 class PieCurve: public DataCurve 00037 { 00038 public: 00039 PieCurve(Table *t, const QString& name, int startRow, int endRow); 00040 void clone(PieCurve* c); 00041 00042 double viewAngle(){return d_view_angle;}; 00043 void setViewAngle(double a){d_view_angle = a;}; 00044 00045 double thickness(){return d_thickness;}; 00046 void setThickness(double t){d_thickness = t;}; 00047 00048 double horizontalOffset(){return d_horizontal_offset;}; 00049 void setHorizontalOffset(double d){d_horizontal_offset = d;}; 00050 00051 bool counterClockwise(){return d_counter_clockwise;}; 00052 void setCounterClockwise(bool on){d_counter_clockwise = on;}; 00053 00054 double startAzimuth(){return d_start_azimuth;}; 00055 void setStartAzimuth(double angle){d_start_azimuth = angle;}; 00056 00057 double labelsEdgeDistance(){return d_edge_dist;}; 00058 void setLabelsEdgeDistance(double d){d_edge_dist = d;}; 00059 00060 bool labelsAutoFormat(){return d_auto_labeling;}; 00061 void setLabelsAutoFormat(bool on){d_auto_labeling = on;}; 00062 00063 bool labelsValuesFormat(){return d_values;}; 00064 void setLabelValuesFormat(bool on){d_values = on;}; 00065 00066 bool labelsPercentagesFormat(){return d_percentages;}; 00067 void setLabelPercentagesFormat(bool on){d_percentages = on;}; 00068 00069 bool labelCategories(){return d_categories;}; 00070 void setLabelCategories(bool on){d_categories = on;}; 00071 00072 bool fixedLabelsPosition(){return d_fixed_labels_pos;}; 00073 void setFixedLabelsPosition(bool on){d_fixed_labels_pos = on;}; 00074 00075 QColor color(int i) const; 00076 00077 int radius(){return d_pie_ray;}; 00078 void setRadius(int size){d_pie_ray = size;}; 00079 00080 Qt::BrushStyle pattern(){return QwtPlotCurve::brush().style();}; 00081 void setBrushStyle(const Qt::BrushStyle& style); 00082 00083 void setFirstColor(int index){d_first_color = index;}; 00084 int firstColor(){return d_first_color;}; 00085 00086 void loadData(); 00087 void initLabels(); 00088 void clearLabels(); 00089 00090 PieLabel* addLabel(PieLabel *l, bool clone = false); 00091 00092 QList <PieLabel *> labelsList(){return d_texts_list;}; 00093 00094 private: 00095 void draw(QPainter *painter,const QwtScaleMap &xMap, 00096 const QwtScaleMap &yMap, int from, int to) const; 00097 void drawSlices(QPainter *painter, const QwtScaleMap &xMap, 00098 const QwtScaleMap &yMap, int from, int to) const; 00099 void drawDisk(QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap) const; 00100 00101 int d_pie_ray; 00102 int d_first_color; 00103 double d_start_azimuth; 00104 double d_view_angle; 00105 double d_thickness; 00106 double d_horizontal_offset; 00107 double d_edge_dist; 00108 bool d_counter_clockwise; 00109 bool d_auto_labeling; 00110 bool d_values; 00111 bool d_percentages; 00112 bool d_categories; 00113 bool d_fixed_labels_pos; 00114 QList <PieLabel *> d_texts_list; 00116 QVarLengthArray<int> d_table_rows; 00117 }; 00118 00119 class PieLabel: public LegendWidget 00120 { 00121 Q_OBJECT 00122 00123 public: 00124 PieLabel(Graph *, PieCurve *pie = 0); 00125 00126 QString customText(); 00127 void setCustomText(const QString& s){d_custom_text = s;}; 00128 00129 void setPieCurve(PieCurve *pie){d_pie_curve = pie;}; 00130 00131 QString saveToString(); 00132 static void restore(Graph *g, const QStringList& lst); 00133 00134 private: 00135 void closeEvent(QCloseEvent* e); 00136 00137 PieCurve *d_pie_curve; 00138 QString d_custom_text; 00139 };