DataSetTableView.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 DataSetTableView.h
22 
23  \brief A table view for a dataset.
24 */
25 
26 
27 #ifndef __TERRALIB_QT_WIDGETS_INTERNAL_DATASETTABLEVIEW_H
28 #define __TERRALIB_QT_WIDGETS_INTERNAL_DATASETTABLEVIEW_H
29 
30 // TerraLib
31 #include "../Config.h"
32 #include "../../../common/CharEncodingConv.h"
33 
34 // Qt
35 #include <QTableView>
36 
37 // Forward declaration
38 class TablePopupFilter;
39 
40 namespace te
41 {
42  // Forward declarations
43 
44  namespace da
45  {
46  class DataSet;
47  class DataSetType;
48  class ObjectIdSet;
49  class DataSourceCapabilities;
50  }
51 
52  namespace gm
53  {
54  class Envelope;
55  }
56 
57  namespace map
58  {
59  class AbstractLayer;
60  }
61 
62  namespace qt
63  {
64  namespace widgets
65  {
66  // Forward declaration
67  class DataSetTableModel;
68  class HighlightDelegate;
69  class ChartDisplayWidget;
70 
71  /*!
72  \class DataSetTableView
73 
74  \brief A customized table view for te::map::AbstractLayer objects. Uses a te::qt::widgets::DataSetModel as its model.
75 
76  \note We assume that the layer can return ALWAYS return a te::da::DataSet object with random access of it's values.
77 
78  \ingroup widgets
79  */
80  class TEQTWIDGETSEXPORT DataSetTableView : public QTableView
81  {
82  Q_OBJECT
83 
84  public:
85  /*!
86  \brief Constructor.
87 
88  \param parent Qt widget parent.
89  */
90  DataSetTableView(QWidget* parent=0);
91 
92  /*!
93  \brief Virtual destructor.
94  */
95  virtual ~DataSetTableView();
96 
97  /*!
98  \brief Sets the drag drop on the horizontal header.
99  When the drag drop is enabled, you lose the ability to swap columns
100 
101  \param b True: does the drag drop. False: do not drag drop.
102  */
103  void setDragDrop(bool b);
104 
105  /*!
106  \brief Gets the drag drop flag.
107 
108  \return True: is drag drop. False: not is drag drop.
109  */
110  bool getDragDrop();
111 
112  /*!
113  \brief Sets the drop on the horizontal header.
114 
115  \param b True: accept drop. False: do not accept drop.
116  */
117  void setAcceptDrop(bool b);
118 
119  /*!
120  \brief Gets accept drop flag.
121 
122  \return True: accept drop. False: not accept drop.
123  */
124  bool getAcceptDrop();
125 
126  /*!
127  \brief Sets the layer to be presented.
128 
129  \param layer Pointer to the layer to be presented.
130 
131  \param clearEditor True for reset editions, false to maintain it.
132  */
133  void setLayer(te::map::AbstractLayer* layer, const bool& clearEditor = true);
134 
135  /*!
136  \brief Updates the data set being visualized.
137 
138  Note that this DataSet MUST HAVE random access. The view DOES TAKE the ownership of the pointer.
139 
140  \param dset The new data set to be visualized.
141 
142  \param clearEditor True for reset editions, false to maintain it.
143  */
144  void setDataSet(te::da::DataSet* dset, te::common::CharEncoding enc, const bool& clearEditor = true);
145 
146  /*!
147  \brief Sets the schema of the data set. It is used to define the primary keys and create the ObjectIdSet.
148 
149  \param schema The DataSetType to extract keys.
150  */
151  virtual void setLayerSchema(const te::da::DataSetType* schema);
152 
153 
154  /*!
155  \brief Highlights the objects identified by \a oids
156 
157  \param oids The identifiers of rows to be highlighted.
158  */
159  void highlightOIds(const te::da::ObjectIdSet* oids);
160 
161  /*!
162  \brief Update the color to be used.
163 
164  \param color The new color;
165  */
166  void setHighlightColor(const QColor& color);
167 
168  /*!
169  \brief Returns \a true if there are unsaved editions e \a false if there is not.
170  */
171  bool hasEditions() const;
172 
173  public slots:
174 
175  /*!
176  \name Table slot methods.
177 
178  \brief Methods to handle user interaction with table.
179  */
180 
181  //@{
182 
183  /*!
184  \brief Creates a new histogram based on the data at position \a column
185 
186  \param column Column that provides the data for the histogram.
187  */
188  void createHistogram(const int& column);
189 
190  /*!
191  \brief Creates a new chart that displays the normal distribution based on the data at position \a column
192 
193  \param column Column that provides the data used to calculate the normal distribution.
194  */
195  void createNormalDistribution(const int& column);
196 
197  /*!
198  \brief Hides the column at position \a column
199 
200  \param column Column to be hidden.
201  */
202  void hideColumn(const int& column);
203 
204  /*!
205  \brief Shows the hidden column.
206 
207  \param column Column to be presented.
208  */
209  void showColumn(const int& column);
210 
211  /*!
212  \brief Rename a column of the table.
213  \param column Index of the column to be renamed.
214  */
215  void renameColumn(const int& column);
216 
217  /*!
218  \brief Changes teh type of a column in the table.
219  \param column Index of the column to be changed.
220  */
221  void retypeColumn(const int& column);
222 
223  /*!
224  \brief Shows the change column data dialog.
225  \param column Index of the column to be updated.
226  */
227  void changeColumnData(const int& column);
228 
229  /*!
230  \brief Shows all hidden columns.
231  */
232  void showAllColumns();
233 
234  /*!
235  \brief Shows columns in the original order.
236  */
237  void resetColumnsOrder();
238 
239  /*!
240  \brief Used to highlight the data when the mouse is clicked over a row in the table.
241 
242  \param row Row to be highlighted.
243 
244  \param add True to add to selection, false to new selection.
245  */
246  void highlightRow(const int& row, const bool& add);
247 
248  /*!
249  \brief Select all rows from \a initRow to \a finalRow.
250 
251  \param initRow the begin row.
252 
253  \param finalRow the final row.
254 
255  \note It does not matter if \a initRow is less than \a finalRow.
256  */
257  void highlightRows(const int& initRow, const int& finalRow);
258 
259  /*!
260  \brief Promotes the highlighted rows.
261 
262  The rows highlighted are presented in the begining of the table.
263 
264  \param If \a true, scrolls to the top of the table.
265  */
266  void promote(const bool& scroll=false);
267 
268  /*!
269  \brief Sort by the selected columns.
270 
271  \param asc True for ascendent order, false for descendent.
272  */
273  void sortByColumns(const bool& asc);
274 
275  //@}
276 
277  /*!
278  \brief Shows or hides the icon sinalizing the columns that identify each row.
279 
280  \param visible True for icon visible, false otherwise.
281  */
282  void setOIdsColumnsVisible(const bool& visible);
283 
284  /*!
285  \brief Add column to the table.
286  */
287  void addColumn();
288 
289  /*
290  \brief Removes a column from the table.
291 
292  \param column Position of the column to be removed.
293  */
294  void removeColumn(const int& column);
295 
296  /*!
297  \brief Enable / disable auto-scroll.
298 
299  \param enable True for enable auto-scroll, false for disable it.
300  */
301  void setAutoScrollEnabled(const bool& enable);
302 
303  /*!
304  \brief Enable / disable promotion.
305 
306  If enabled all selected rows will be moved to te top of the table.
307 
308  \param enable \a True to enable promotion, \a false to disable it
309  */
310  void setPromotionEnabled(const bool& enable);
311 
312  /*!
313  \brief Saves all editions to the dataset.
314  */
315  void saveEditions();
316 
317  signals:
318 
319  /*!
320  \brief Emmite when objects was selected.
321  */
322  void selectOIds(te::da::ObjectIdSet*, const bool&, te::gm::Envelope*);
323 
324  void deselectOIds(te::da::ObjectIdSet*);
325 
326  void createChartDisplay(te::qt::widgets::ChartDisplayWidget*);
327 
328  protected:
329 
330  void removeSelection(const int& initRow, const int& finalRow);
331 
332  DataSetTableModel* m_model; //!< The model to be used.
333  TablePopupFilter* m_popupFilter; //!< The menus popup filter.
334  HighlightDelegate* m_delegate; //!< Delegate used for rendering selected rows.
335  te::map::AbstractLayer* m_layer; //!< Pointer to the layer being presented.
336  bool m_autoScrollEnabled; //!< Auto scroll enabling.
337  bool m_doScroll; //!< Flag to force or not scrolling.
338  bool m_promotionEnabled; //!< Promotion enabled.
339  te::da::DataSet* m_dset; //!< Data set being used.
340  std::vector<std::string> m_orderby; //!< Order by columns.
341  bool m_orderAsc; //!< Flag that sinalizes if the it is sorted in ascending sorting.
342  bool m_resetOrder; //!< Flag that sinalizes if there's is no sort.
344  };
345  }
346  }
347 }
348 
349 #endif //__TERRALIB_QT_WIDGETS_INTERNAL_DATASETTABLEVIEW_H
An specialization of QItemDelegate to be used with te::map::AbstractTable objects.
te::common::CharEncoding m_encoding
CharEncoding
Supported charsets (character encoding).
This is the base class for layers.
Definition: AbstractLayer.h:76
bool m_doScroll
Flag to force or not scrolling.
A class that models the description of a dataset.
Definition: DataSetType.h:72
std::vector< std::string > m_orderby
Order by columns.
TEQTWIDGETSEXPORT ChartDisplayWidget * createNormalDistribution(te::da::DataSet *dataset, int propId)
bool m_autoScrollEnabled
Auto scroll enabling.
DataSetTableModel * m_model
The model to be used.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:55
URI C++ Library.
TablePopupFilter * m_popupFilter
The menus popup filter.
TEQTWIDGETSEXPORT Histogram * createHistogram(te::da::DataSet *dataset, te::da::DataSetType *dataType, int propId, int slices, int stat)
Histogram Creator.
HighlightDelegate * m_delegate
Delegate used for rendering selected rows.
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:112
A wdiget used to display a chart.
te::map::AbstractLayer * m_layer
Pointer to the layer being presented.
A customized table view for te::map::AbstractLayer objects. Uses a te::qt::widgets::DataSetModel as i...
#define TEQTWIDGETSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:63
te::da::DataSet * m_dset
Data set being used.
A table model representing a te::da::DataSet.
bool m_orderAsc
Flag that sinalizes if the it is sorted in ascending sorting.
bool m_promotionEnabled
Promotion enabled.
bool m_resetOrder
Flag that sinalizes if there's is no sort.