-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdatachart.h
344 lines (294 loc) · 10.2 KB
/
datachart.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
#include <qwidget.h>
#include <q3mainwindow.h>
#include <qcheckbox.h>
#include <qpainter.h>
#include <qpixmap.h>
#include <qstring.h>
#include <qcolor.h>
#include <qdialog.h>
#include <q3popupmenu.h>
#include <qprinter.h>
#include <q3canvas.h>
#include <qlabel.h>
#include <qlayout.h>
#include <q3listview.h>
#include <q3buttongroup.h>
#include <qradiobutton.h>
#include <qspinbox.h>
#include <qlineedit.h>
#include <q3tabdialog.h>
#include <q3textedit.h>
//Added by qt3to4:
#include <QMouseEvent>
#include <QPaintEvent>
#ifndef DATACHART_H
#define DATACHART_H
enum CHARTTYPE { POINTCHART, LINECHART, BARCHART, PIECHART, PIECHART2 };
enum VALUETYPE { ONEDIM, TWODIM };
class dc_dataset{
public:
int id;
QString *desc;
double *data_x;
double *data_y;
char **idx;
int data_length;
int linesize;
QColor data_color;
QColor* pie_data_color;
double scale_rate;
double offset_x;
double offset_y;
bool visi;
bool showpoints;
// struct dc_dataset * next;
};
class dc_settings{
public:
int id;
QString *desc;
bool visi;
int linesize;
QColor color;
double scale_rate;
double offset_x;
double offset_y;
bool showpoints;
};
class dc_settings_general{
public:
QString title;
QColor title_color;
double minx, maxx, miny, maxy;
};
class xyGraph : public QWidget {
Q_OBJECT
public:
/**********************************************************************************/
/******* the following methods are written to be invoked by an application ******/
/**********************************************************************************/
//xyGraph construction fuction
xyGraph();
//reloaded xyGraph construction function for display a pointchart( 2D data, like(x,y) )
//minx: min x coordinate value
//maxx: max x coordinate value
//miny, maxy: min(max) y coordinate value
//title: title to be shown at the top of the graph
//charttypename: POINTCHART, BARCHART, PIECHART
xyGraph( double minx, double maxx, double miny, double maxy,
QString title = " ", CHARTTYPE charttypename = POINTCHART, QWidget * parent1 = 0 );
//reloaded xyGraph construction function for display a barchart( 1D data )
//maxy: max y(vertical) coordinate value
xyGraph( double maxy,
QString title = " ", CHARTTYPE charttypename = BARCHART, QWidget * parent1 = 0 );
//reloaded xyGraph construction function for display a none-coordinate graph, such as PIECHART.
//when it is used to display a coorinate graph, u have to use fuction setCoord() to sepecify the coordinate after the construction fuction
xyGraph( QString title, CHARTTYPE charttypename, QWidget * parent1 = 0 );
//destruction function
~xyGraph();
//add a data set: (x0,y0),(x1,y1),(x2,y2)... in the graph
//datasetx: pointer to the x value list: x[0],x[1],x[2]...x[num_data-1]
//datasety: pointer to the y value list: y[0],y[1],y[2]...y[num_data-1]
//num_data: number of the point( a point is in a format like (x[i],y[i]) )
//lineSize: size of the line joins each two points( point(x[i],y[i]) and point(x[i+1],y[i+1]) )
// the default value is 0, which means do not join any points with lines
//Color: the color used to display this data set in the graph
void addXY( double * datasetx, double * datasety, int num_data, int lineSize = 0, QColor Color = Qt::white );
//reloaded function for adding a 1D data set: y0,y1,y2.....
//index: a pointer to an array of string which contains the comments of y[i]
// thus, each element in the data set is like ( index[i], y[i] )
//datasety: pointer to the value list: y[0],y[1],y[2]...y[num_data-1]
void addXY( char ** index, double * datasety, int num_data, QColor Color = Qt::white );
//reloaded function used to adding a 1D data set without a comment for each element
void addXY( double * datasety, int num_data, QColor Color = Qt::white );
//remove a data set
//dataset: index of the data set in all data sets
void removeXY( int dataset );
//set coordinate value
//return true if succeed, otherwise false
bool setCoord( double minx, double maxx, double miny, double maxy );
//set graph title
//color: the color which the title displayed in
void setTitle( QString title, QColor color );
//reloaded function for setting the title of a PIECHART2 chart
void setTitle( QString title1, QString title2, QColor color );
//set whether to show the grid or not
//flag: true for show and false for not
void setShowgrid( bool flag );
//set size of a point in a POINTCHART
void setPointSize( int size );
//repaint the graph
//u can invoke this function whenever u find the need to refresh it
void repaintChart( );
//set coordinate description
void setCoordDesc( QString desc_x = "X", QString desc_y = "Y" );
//set type of reference on the right of the graph, 0 for normal and 1 for display prop-model
void setReference( int reference_type );
//set the color of data i in every datasets to datacolor in a PIECHART or PIECHART2
//before callling this function, the program use default color for each data automatically
void setPieDataColor( QColor* datacolor );
//the following 2 functions are not available yet
void setExpXY( int expx, int expy );
void setDataStep( double dstepx, double dstepy );
/**********************************************************************************/
private slots:
void PointChart();
void LineChart();
void BarChart();
void PieChart();
void About();
void ExportBmp();
void ExportJpg();
void Export( QString );
void Print();
void Settings();
void setPieSet( int );
void onSelectionChanged( Q3ListViewItem* );
void onBtnColorClicked( );
void onBtnTitleColorClicked( );
void onLinesizeChanged( int );
void applySettings( );
void addFromFile( );
void removeDataset( );
void viewData( );
void View_saveData( );
void zoomIn();
void zoomOut();
void scroll();
void restore();
void close();
private:
void init();
void initMenu( CHARTTYPE );
void paintEvent( QPaintEvent* );
void drawCoordinate( );
void drawChartIndex( );
// void drawIntCoord( );
void drawLine( int );
void drawTitle( QString );
void drawGrid( );
void drawPoints( int );
void drawPointsValue( int, int );
// void drawzoomGraph();
void drawLineChart( int );
void drawBarChart( int );
void drawOnePie( int, int, int );
void drawPieChart( int );
void drawBarValue( int );
void zoomGraph();
void mousePressEvent( QMouseEvent* );
void mouseReleaseEvent( QMouseEvent* );
void mouseMoveEvent( QMouseEvent* );
void loadSettings( int );
void saveSettings( int );
void repaintPageDataset( int );
void disableWidgets( );
void enableWidgets( );
void checkBarPieData( double*, int );
bool IsMouseeventInregion();
bool IsPointInregion( int, int );
void resetPainter( );
int modifiedX( int );
int modifiedY( int );
double calStep( double, double, int );
void dc_FloatToStr( double, char*, int );
double nearestValue( double, double, int );
QColor chooseColor( int );
QColor chooseColorMore( int );
double getRateXFrame();
double getRateYFrame();
int getMaxStrLen( char**, int );
void drawDelta( int, int );
void setDouble( QString &, double );
//public class members, also called "properties"
public:
int max_x, max_y; //max pixel number of the coordinate
int size_x, size_y; //max size of this dialog
int title_height; //title height
int menu_height; //menu height
int lmargin, rmargin, tmargin, bmargin, tmargin_all; //margin between edges of the widget and the coordniate
//private class members
private:
double dminx, dminy, dmaxx, dmaxy;
double dminx_old, dminy_old, dmaxx_old, dmaxy_old;
double dminx_ori, dminy_ori, dmaxx_ori, dmaxy_ori;
QString title, title1, title2;
int title_type;
int pie_color_type;
QColor title_color;
int pointsize;
QString desc_x, desc_y;
double zoomrate;
QPixmap *pixmap;
dc_settings_general* settings_general;
dc_dataset** setlist;
dc_settings** settings_setlist;
int num_data_set;
double ratex;
double ratey;
QPrinter *printer;
int xmousepress, ymousepress;
int xmouserelease, ymouserelease;
int xmousecurrent, ymousecurrent;
int regionstartx, regionstarty;
int scrollstartx, scrollstarty, scrollendx, scrollendy;
bool scrollbegin;
int scrollx_old, scrolly_old;
int reference_type;
double regionw, regionh;
double valuestartx, valueendx, valuestarty, valueendy;
bool mousepressed;
QMenuBar *menubar;
Q3PopupMenu *file;
Q3PopupMenu *view;
Q3PopupMenu *options;
Q3PopupMenu *help;
int gid, pid, lid, pointcid, linecid, barcid, piecid, scrollid;
int pie_set_num;
QPainter *painter;
QRect *regionrect;
CHARTTYPE charttype;
VALUETYPE valuetype;
bool showgrid;
bool viewscroll;
bool intCoord;
bool cursor_inregion;
int exp_x, exp_y;
double grid_size_x, grid_size_y;
double num_grid_x, num_grid_y;
double dstepx, dstepy;
int dexpx, dexpy;
QString datatext;
QRadioButton* Btn_Grids_Yes;
QRadioButton* Btn_Grids_No;
QRadioButton* Btn_Coord_Yes;
QRadioButton* Btn_Coord_No;
QLineEdit* LE_minX;
QLineEdit* LE_maxX;
QLineEdit* LE_minY;
QLineEdit* LE_maxY;
QLineEdit* LE_Title;
Q3TabDialog* Dlg_Settings;
QWidget* Page_General;
QWidget* Page_Dataset;
Q3ListView* LV_Dataset;
Q3ListViewItem* olditem;
QLineEdit* LE_Desc;
QPushButton* Btn_Add;
QPushButton* Btn_Remove;
QPushButton* Btn_Data;
QRadioButton* Btn_Visi_Yes;
QRadioButton* Btn_Visi_No;
QPushButton* Btn_Color;
QPushButton* Btn_Title_Color;
QSpinBox* SBox_Linesize;
QCheckBox* CB_showPoints;
QSpinBox* SBox_Scale;
QLineEdit* LE_Trans_X;
QLineEdit* LE_Trans_Y;
QCheckBox* CB_Grid;
QCheckBox* CB_Coord;
QCheckBox* CB_Index;
Q3TextEdit* textEditer;
};
#endif