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  \param readall A boolean that holds weather the entire raster will be read (if the scatter is based on a raster)
67 
68  \note It will traverse the data set, using the moveNext() method
69  \note It will not take the ownership of the "dataset" pointer.
70  \note It will not take the ownership of the "dataType" pointer.
71  \note The caller will take the ownership of the returned scatter pointer.
72 
73  \return a new Scatter
74  */
75  TEQTWIDGETSEXPORT Scatter* createScatter(te::da::DataSet* dataset, te::da::DataSetType* dataType, int propX, int propY, int stat, bool readall = true);
76 
77  /*!
78  \brief Scatter Creator
79 
80  \param dataset The dataset that will be used to populate the scatter's data
81  \param dataType The dataType that will be used to recover the objectIds associated with the given dataset.
82  \param propX The id of the property that contains the data of the x axis.
83  \param propY The id of the property that contains the data of the y axis.
84 
85  \note It will traverse the data set, using the moveNext() method
86  \note It will not take the ownership of the "dataset" pointer.
87  \note It will not take the ownership of the "dataType" pointer.
88  \note The caller will take the ownership of the returned ChartDisplayWidget pointer.
89 
90  */
91  TEQTWIDGETSEXPORT ChartDisplayWidget* createScatterDisplay(te::da::DataSet* dataset, te::da::DataSetType* dataType, int propX, int propY, int stat = -1);
92 
93  /*!
94  \brief Histogram Creator
95 
96  \param dataset The dataset that will be used to populate the histogram's data
97  \param dataType The dataType that will be used to recover the objectIds associated with the given dataset.
98  \param propId The id of the property that contains the data
99  \param slices The desired number of intervals
100  \param stat The selected satistical function
101  \param readall A boolean that holds weather the entire raster will be read (if the histogram is based on a raster)
102 
103  \note It will traverse the data set, using the moveNext() method
104  \note It will not take the ownership of the "dataset" pointer.
105  \note It will not take the ownership of the "dataType" pointer.
106  \note The caller will take the ownership of the returned histogram pointer.
107 
108  \return a new Histogram
109  */
110  TEQTWIDGETSEXPORT Histogram* createHistogram(te::da::DataSet* dataset, te::da::DataSetType* dataType, int propId, int slices, int stat, bool readall = true);
111  /*!
112  \brief Histogram Creator
113 
114  \param dataset The dataset that will be used to populate the histogram's data
115  \param dataType The dataType that will be used to recover the objectIds associated with the given dataset.
116  \param propId The id of the property that contains the data
117  \param stat The selected satistical function
118 
119  \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
120  \note It will traverse the data set, using the moveNext() method
121  \note It will not take the ownership of the "dataset" pointer.
122  \note It will not take the ownership of the "dataType" pointer.
123  \note The caller will take the ownership of the returned histogram pointer.
124 
125  \return a new Histogram
126  */
127  TEQTWIDGETSEXPORT Histogram* createHistogram(te::da::DataSet* dataset, te::da::DataSetType* dataType, int propId, int stat);
128 
129  /*!
130  \brief Histogram Creator
131 
132  \param dataset The dataset that will be used to populate the histogram's data
133  \param dataType The dataType that will be used to recover the objectIds associated with the given dataset.
134  \param propId The id of the property that contains the data
135  \param slices The desired number of intervals, the default is 10 and this parameter is not used when the preperty is a string
136  \param stat The selected satistical function, defaults to -1 (i.e. none)
137 
138  \note It will traverse the data set, using the moveNext() method
139  \note It will not take the ownership of the "dataset" pointer.
140  \note It will not take the ownership of the "dataType" pointer.
141  \note The caller will take the ownership of the returned ChartDisplayWidget pointer.
142 
143  \return A pointer to a new ChartDisplayWidget that contains the generated chart
144 
145  */
146  TEQTWIDGETSEXPORT ChartDisplayWidget* createHistogramDisplay(te::da::DataSet* dataset, te::da::DataSetType* dataType, int propId, int slices = 10, int stat = -1);
147 
148  /*!
149  \brief Histogram Creator
150 
151  \param dataset The dataset that will be used to populate the histogram's data
152  \param dataType The dataType that will be used to recover the objectIds associated with the given dataset.
153  \param propId The id of the property that contains the data
154  \param histogram THe histogram that will be displayed by the returned widget
155 
156  \note It will traverse the data set, using the moveNext() method
157  \note It will not take the ownership of the "dataset" pointer.
158  \note It will not take the ownership of the "dataType" pointer.
159  \note It will take ownership of the given histogram pointer and pass it along to the returned ChartDisplay.
160  \note The caller will take the ownership of the returned ChartDisplayWidget pointer.
161 
162  \return A pointer to a new ChartDisplayWidget that contains the generated chart
163  */
164  TEQTWIDGETSEXPORT ChartDisplayWidget* createHistogramDisplay(te::da::DataSet* dataset, te::da::DataSetType* dataType, int propId, std::string summary, Histogram* histogram);
165 
166  /*!
167  \brief Function that exports a chart's data to a .csv file
168 
169  \param plotItem The chart from which the data will be exported
170  \param style The style containing information about the chart axes
171  \param filepath The path of the file that will be created
172 
173  \note It will traverse the data set, using the moveNext() method
174  \note It will not take the ownership of the "plotItem" pointer.
175  \note It will not take the ownership of the "style" pointer.
176  \note It may throw an exception if the data can't be exported
177  */
178  TEQTWIDGETSEXPORT void exportChart(QwtPlotItem* plotItem, te::qt::widgets::ChartStyle* style, std::string filepath);
179 
180  /*!
181  \function Terralib2Qwt
182 
183  This function returns a default QwtText.
184 
185  \param title A text.
186 
187  \return A QwtText
188 
189  \note The caller will take the ownership of the returned pointer.
190  */
191  TEQTWIDGETSEXPORT QwtText* Terralib2Qwt(const std::string& title);
192 
193 
194  /*!
195  \function Terralib2Qwt
196 
197  This function translates TerraLib text styles into a QwtText.
198 
199  \param text A text
200  \param color The text's color
201  \param font The text's font
202  \param backFill The text's background fill
203  \param backStroke The text's background stroke
204 
205  \return A QwtText
206 
207  \note The caller will take the ownership of the returned pointer.
208  \note It will not take the ownership of given "font", "backFill" and "backStroke"" pointers.
209  */
210  TEQTWIDGETSEXPORT QwtText* Terralib2Qwt(const std::string& text, te::color::RGBAColor* color,
211  te::se::Font* font, te::se::Fill* backFill,
212  te::se::Stroke* backStroke);
213 
214  /*!
215  \function Terralib2Qwt
216 
217  This function translates a terralib's Graphic object into a QWTSymbol object.
218 
219  \param graphic The graphic that will be used to generate the symbol.
220 
221  \return A QwtSymbol
222 
223  \note The caller will take the ownership of the returned pointer.
224  \note It will not take the ownership of the Graphic pointer.
225  */
226  TEQTWIDGETSEXPORT QwtSymbol* Terralib2Qwt(te::se::Graphic* graphic);
227 
228  /*!
229  \function createNormalDistribution
230 
231  This function translates a terralib's Graphic object into a QWTSymbol object.
232 
233  \param dataset The dataset that will be used calculate the normal distribution.
234  \param propId The id of the property that contains the data.
235 
236  \note The caller will take the ownership of the returned pointer.
237  \note It will not take the ownership of the "dataset" pointer.
238 
239  \return A pointer to a new ChartDisplayWidget that contains the generated chart
240  */
241  TEQTWIDGETSEXPORT ChartDisplayWidget* createNormalDistribution(te::da::DataSet* dataset, int propId);
242 
243  } // end namespace widgets
244  } // end namespace qt
245 } // end namespace te
246 
247 #endif // __TERRALIB_QT_WIDGETS_INTERNAL_CHARTUTILS_H
248 
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
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
TEQTWIDGETSEXPORT Histogram * createHistogram(te::da::DataSet *dataset, te::da::DataSetType *dataType, int propId, int slices, int stat, bool readall=true)
Histogram Creator.
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.