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