Utils.h
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18 */
19 
20 /*!
21  \file terralib/qt/widgets/charts/Utils.h
22 
23  \brief This file contains a set of utility chart functions
24 */
25 
26 #ifndef __TERRALIB_QT_WIDGETS_INTERNAL_CHARTUTILS_H
27 #define __TERRALIB_QT_WIDGETS_INTERNAL_CHARTUTILS_H
28 
29 //TerraLib
30 #include "../Config.h"
31 
32 //QWT
33 #include <qwt_symbol.h>
34 #include <qwt_text.h>
35 #include <qwt_plot_curve.h>
36 
37 //STL
38 #include <vector>
39 
40 namespace te
41 {
42  // Forward declarations
43  namespace color { class RGBAColor; }
44  namespace se { class Font; class Fill; class Stroke; class Mark; class Graphic;}
45  namespace da { class DataSet; class DataSetType; class ObjectId; }
46  namespace dt { class DateTime; }
47 
48  namespace qt
49  {
50 
51  namespace widgets
52  {
53 
54  class Scatter;
55  class Histogram;
56  class ChartDisplayWidget;
57  class ChartStyle;
58 
59  /*!
60  \brief Scatter Creator
61 
62  \param dataset The dataset that will be used to populate the scatter's data
63  \param dataType The dataType that will be used to recover the objectIds associated with the given dataset.
64  \param propX The id of the property that contains the data of the x axis.
65  \param propY The id of the property that contains the data of the y axis.
66 
67  \note It will traverse the data set, using the moveNext() method
68  \note It will not take the ownership of the "dataset" pointer.
69  \note It will not take the ownership of the "dataType" pointer.
70  \note The caller will take the ownership of the returned scatter pointer.
71 
72  \return a new Scatter
73  */
74  TEQTWIDGETSEXPORT Scatter* createScatter(te::da::DataSet* dataset, te::da::DataSetType* dataType, int propX, int propY, int stat, bool readall = true);
75 
76  /*!
77  \brief Scatter Creator
78 
79  \param dataset The dataset that will be used to populate the scatter's data
80  \param dataType The dataType that will be used to recover the objectIds associated with the given dataset.
81  \param propX The id of the property that contains the data of the x axis.
82  \param propY The id of the property that contains the data of the y axis.
83 
84  \note It will traverse the data set, using the moveNext() method
85  \note It will not take the ownership of the "dataset" pointer.
86  \note It will not take the ownership of the "dataType" pointer.
87  \note The caller will take the ownership of the returned ChartDisplayWidget pointer.
88 
89  */
90  TEQTWIDGETSEXPORT ChartDisplayWidget* createScatterDisplay(te::da::DataSet* dataset, te::da::DataSetType* dataType, int propX, int propY, int stat = -1);
91 
92  /*!
93  \brief Histogram Creator
94 
95  \param dataset The dataset that will be used to populate the histogram's data
96  \param dataType The dataType that will be used to recover the objectIds associated with the given dataset.
97  \param propId The id of the property that contains the data
98  \param slices The desired number of intervals
99  \param stat The selected satistical function
100 
101  \note It will traverse the data set, using the moveNext() method
102  \note It will not take the ownership of the "dataset" pointer.
103  \note It will not take the ownership of the "dataType" pointer.
104  \note The caller will take the ownership of the returned histogram pointer.
105 
106  \return a new Histogram
107  */
108  TEQTWIDGETSEXPORT Histogram* createHistogram(te::da::DataSet* dataset, te::da::DataSetType* dataType, int propId, int slices, int stat);
109 
110  /*!
111  \brief Histogram Creator
112 
113  \param dataset The dataset that will be used to populate the histogram's data
114  \param dataType The dataType that will be used to recover the objectIds associated with the given dataset.
115  \param propId The id of the property that contains the data
116  \param stat The selected satistical function
117 
118  \note This version is used to create a histogram based on a set of labels (Strings), therefore there is no user-defined number of intervals, each unique label is an interval
119  \note It will traverse the data set, using the moveNext() method
120  \note It will not take the ownership of the "dataset" pointer.
121  \note It will not take the ownership of the "dataType" pointer.
122  \note The caller will take the ownership of the returned histogram pointer.
123 
124  \return a new Histogram
125  */
126  TEQTWIDGETSEXPORT Histogram* createHistogram(te::da::DataSet* dataset, te::da::DataSetType* dataType, int propId, int stat);
127 
128  /*!
129  \brief Histogram Creator
130 
131  \param dataset The dataset that will be used to populate the histogram's data
132  \param dataType The dataType that will be used to recover the objectIds associated with the given dataset.
133  \param propId The id of the property that contains the data
134  \param slices The desired number of intervals, the default is 10 and this parameter is not used when the preperty is a string
135  \param stat The selected satistical function, defaults to -1 (i.e. none)
136 
137  \note It will traverse the data set, using the moveNext() method
138  \note It will not take the ownership of the "dataset" pointer.
139  \note It will not take the ownership of the "dataType" pointer.
140  \note The caller will take the ownership of the returned ChartDisplayWidget pointer.
141 
142  \return A pointer to a new ChartDisplayWidget that contains the generated chart
143 
144  */
145  TEQTWIDGETSEXPORT ChartDisplayWidget* createHistogramDisplay(te::da::DataSet* dataset, te::da::DataSetType* dataType, int propId, int slices = 10, int stat = -1);
146 
147  /*!
148  \brief Histogram Creator
149 
150  \param dataset The dataset that will be used to populate the histogram's data
151  \param dataType The dataType that will be used to recover the objectIds associated with the given dataset.
152  \param propId The id of the property that contains the data
153  \param histogram THe histogram that will be displayed by the returned widget
154 
155  \note It will traverse the data set, using the moveNext() method
156  \note It will not take the ownership of the "dataset" pointer.
157  \note It will not take the ownership of the "dataType" pointer.
158  \note It will take ownership of the given histogram pointer and pass it along to the returned ChartDisplay.
159  \note The caller will take the ownership of the returned ChartDisplayWidget pointer.
160 
161  \return A pointer to a new ChartDisplayWidget that contains the generated chart
162  */
163  TEQTWIDGETSEXPORT ChartDisplayWidget* createHistogramDisplay(te::da::DataSet* dataset, te::da::DataSetType* dataType, int propId, std::string summary, Histogram* histogram);
164 
165  /*!
166  \brief Function that exports a chart's data to a .csv file
167 
168  \param plotItem The chart from which the data will be exported
169  \param style The style containing information about the chart axes
170  \param filepath The path of the file that will be created
171 
172  \note It will traverse the data set, using the moveNext() method
173  \note It will not take the ownership of the "plotItem" pointer.
174  \note It will not take the ownership of the "style" pointer.
175  \note It may throw an exception if the data can't be exported
176  */
177  TEQTWIDGETSEXPORT void exportChart(QwtPlotItem* plotItem, te::qt::widgets::ChartStyle* style, std::string filepath);
178 
179  /*!
180  \function Terralib2Qwt
181 
182  This function returns a default QwtText.
183 
184  \param title A text.
185 
186  \return A QwtText
187 
188  \note The caller will take the ownership of the returned pointer.
189  */
190  TEQTWIDGETSEXPORT QwtText* Terralib2Qwt(const std::string& title);
191 
192 
193  /*!
194  \function Terralib2Qwt
195 
196  This function translates TerraLib text styles into a QwtText.
197 
198  \param text A text
199  \param color The text's color
200  \param font The text's font
201  \param backFill The text's background fill
202  \param backStroke The text's background stroke
203 
204  \return A QwtText
205 
206  \note The caller will take the ownership of the returned pointer.
207  \note It will not take the ownership of given "font", "backFill" and "backStroke"" pointers.
208  */
209  TEQTWIDGETSEXPORT QwtText* Terralib2Qwt(const std::string& text, te::color::RGBAColor* color,
210  te::se::Font* font, te::se::Fill* backFill,
211  te::se::Stroke* backStroke);
212 
213  /*!
214  \function Terralib2Qwt
215 
216  This function translates a terralib's Graphic object into a QWTSymbol object.
217 
218  \param graphic The graphic that will be used to generate the symbol.
219 
220  \return A QwtSymbol
221 
222  \note The caller will take the ownership of the returned pointer.
223  \note It will not take the ownership of the Graphic pointer.
224  */
225  TEQTWIDGETSEXPORT QwtSymbol* Terralib2Qwt(te::se::Graphic* graphic);
226 
227  /*!
228  \function createNormalDistribution
229 
230  This function translates a terralib's Graphic object into a QWTSymbol object.
231 
232  \param dataset The dataset that will be used calculate the normal distribution.
233  \param propId The id of the property that contains the data.
234 
235  \note The caller will take the ownership of the returned pointer.
236  \note It will not take the ownership of the "dataset" pointer.
237 
238  \return A pointer to a new ChartDisplayWidget that contains the generated chart
239  */
240  TEQTWIDGETSEXPORT ChartDisplayWidget* createNormalDistribution(te::da::DataSet* dataset, int propId);
241 
242  } // end namespace widgets
243  } // end namespace qt
244 } // end namespace te
245 
246 #endif // __TERRALIB_QT_WIDGETS_INTERNAL_CHARTUTILS_H
247 
A class that models the description of a dataset.
Definition: DataSetType.h:72
A Graphic is a graphic symbol with an inherent shape, color(s), and possibly size.
Definition: Graphic.h:66
TEQTWIDGETSEXPORT ChartDisplayWidget * createNormalDistribution(te::da::DataSet *dataset, int propId)
TEQTWIDGETSEXPORT Scatter * createScatter(te::da::DataSet *dataset, te::da::DataSetType *dataType, int propX, int propY, int stat, bool readall=true)
Scatter Creator.
TEQTWIDGETSEXPORT QwtText * Terralib2Qwt(const std::string &title)
URI C++ Library.
A Font specifies the text font to use in a text symbolizer.
Definition: Font.h:63
TEQTWIDGETSEXPORT void exportChart(QwtPlotItem *plotItem, te::qt::widgets::ChartStyle *style, std::string filepath)
Function that exports a chart's data to a .csv file.
A Fill specifies the pattern for filling an area geometry.
Definition: Fill.h:59
TEQTWIDGETSEXPORT Histogram * createHistogram(te::da::DataSet *dataset, te::da::DataSetType *dataType, int propId, int slices, int stat)
Histogram Creator.
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:112
A Stroke specifies the appearance of a linear geometry.
Definition: Stroke.h:67
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
#define TEQTWIDGETSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:63
TEQTWIDGETSEXPORT ChartDisplayWidget * createHistogramDisplay(te::da::DataSet *dataset, te::da::DataSetType *dataType, int propId, int slices=10, int stat=-1)
Histogram Creator.
TEQTWIDGETSEXPORT ChartDisplayWidget * createScatterDisplay(te::da::DataSet *dataset, te::da::DataSetType *dataType, int propX, int propY, int stat=-1)
Scatter Creator.