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