DataSetTableModel.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/table/DataSetTableModel.h
22 
23  \brief A model based on te::da::DataSet.
24 */
25 
26 #ifndef __TERRALIB_QT_WIDGETS_TABLE_INTERNAL_DATASETTABLEMODEL_H
27 #define __TERRALIB_QT_WIDGETS_TABLE_INTERNAL_DATASETTABLEMODEL_H
28 
29 // TerraLib
30 #include "../../../core/encoding/CharEncoding.h"
31 #include "../Config.h"
32 
33 // Qt
34 #include <QtCore/QAbstractTableModel>
35 
36 // STL
37 #include <memory>
38 #include <vector>
39 #include <set>
40 
41 class Editor;
42 
43 namespace te
44 {
45 
46  namespace da
47  {
48  class DataSet;
49  class ObjectId;
50  class ObjectIdSet;
51  class DataSetType;
52  }
53 
54  namespace qt
55  {
56  namespace widgets
57  {
58  // Forward declaration
59  class Promoter;
60 
61  /*!
62  \class DataSetTableModel
63 
64  \brief A table model representing a te::da::DataSet.
65 
66  \ingroup widgets
67  */
68  class TEQTWIDGETSEXPORT DataSetTableModel : public QAbstractTableModel
69  {
70  public:
71 
72  /*!
73  \brief Constructor.
74  */
75  DataSetTableModel(QObject* parent = 0);
76 
77  /*!
78  \brief Virtual destructor.
79  */
80  virtual ~DataSetTableModel();
81 
82  /*!
83  \brief Updates the data being used.
84 
85  \param dset The new data set to be used.
86 
87  \param clearEditor True for reset editions, false to maintain it.
88 
89  \note This method DOES TAKE the ownership of \a dset.
90  */
91  void setDataSet(te::da::DataSet* dset, const bool& clearEditor = true);
92 
93  /*!
94  \brief Sets the columns used as pkeys, for presentation purposes.
95 
96  \param pkeys Positions of the columns that form the primary key.
97  */
98  void setPkeysColumns(const std::vector<size_t>& pkeys);
99 
100  /*!
101  \brief Promotes the rows identified by \a oids.
102 
103  \parama oids The identifiers of the rows to be promoted.
104  */
105  void promote(const te::da::ObjectIdSet* oids);
106 
107  /*!
108  \brief Returns the pointer to the promoter being used.
109 
110  \return Pointer of the promoter being used.
111 
112  \note The caller of this method DOES NOT take the ownership of the pointer.
113  */
114  Promoter* getPromoter();
115 
116  /*!
117  \brief Shows an icon for indentify the columns that are used for identify objects.
118  */
119  void showOIdsVisible(const bool& visible);
120 
121  /*!
122  \brief Returns the ObjectIdSet begining with row \a initRow and ending in \a finalRow.
123 
124  \param initRow Initial row.
125 
126  \param endRow Final row.
127 
128  \note The caller WILL TAKE the ownership of the ObjectIdSet returned.
129  */
130  te::da::ObjectIdSet* getObjectIdSet (const int& initRow, const int& finalRow);
131 
132  /*!
133  \brief Enable or disable the dataset presentation.
134 
135  \param enabled True for show dataSet on table, false to hide it.
136  */
137  void setEnabled(const bool& enabled);
138 
139  /*!
140  \brief Sets if the model is editable or not.
141 
142  \param editable \a True if the model is editable, \a false otherwise.
143  */
144  void setEditable(const bool& editable);
145 
146  /*!
147  \brief Returns a memory dataset to be saved.
148 
149  \param type DataSetType to construct memory dataset.
150 
151  \param[out] ps Positions of the columns edited for each row.
152 
153  \return Memory dataset with editions.
154  */
155  std::auto_ptr<te::da::DataSet> getEditions(const te::da::DataSetType* type, std::vector< std::set<int> >& ps);
156 
157  /*!
158  \brief Returns true if there are unsaved editions.
159 
160  \return \a True if there are unsaved editions, \a false otherwise.
161  */
162  bool hasEditions() const;
163 
164  /*!
165  \brief Discard editions.
166  */
167  void discardEditions();
168 
169  /*!
170  \name QAbstractTableModel re-implementation methods.
171 
172  \brief Re-implementation of QAbstractTableModel methods.
173  */
174  //@{
175 
176  int rowCount(const QModelIndex & parent) const;
177 
178  int columnCount(const QModelIndex & parent) const;
179 
180  QVariant data(const QModelIndex & index, int role) const;
181 
182  QVariant headerData(int section, Qt::Orientation orientation, int role) const;
183 
184  Qt::ItemFlags flags(const QModelIndex & index) const;
185 
186  bool setData (const QModelIndex & index, const QVariant & value, int role = Qt::EditRole);
187 
188  bool insertColumns(int column, int count, const QModelIndex& parent = QModelIndex());
189 
190  bool removeColumns(int column, int count, const QModelIndex& parent = QModelIndex());
191  //@}
192 
193  protected:
194 
195  te::da::DataSet* m_dataset; //!< The dataset being used.
196 
197  mutable int m_currentRow; //!< An internal row pointer.
198 
199  std::vector<size_t> m_pkeysColumns; //!< Primary key columns.
200 
201  Promoter* m_promoter; //!< Promoter to be used.
202 
203  bool m_OIdsVisible; //!< Oids icon visibility.
204 
205  bool m_enabled; //!< Enabling flag.
206 
207  int m_rowCount; //!< Number of rows.
208 
209  bool m_isEditable; //!< Flag that indicates if the model is editable.
210 
211  std::auto_ptr<Editor> m_editor; //!< Pointer to editor.
212  };
213  }
214  }
215 }
216 
217 #endif //__TERRALIB_QT_WIDGETS_TABLE_INTERNAL_DATASETTABLEMODEL_H
std::auto_ptr< Editor > m_editor
Pointer to editor.
A class that models the description of a dataset.
Definition: DataSetType.h:72
std::vector< size_t > m_pkeysColumns
Primary key columns.
bool m_OIdsVisible
Oids icon visibility.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:55
bool m_isEditable
Flag that indicates if the model is editable.
URI C++ Library.
A class used for logical ordering of rows.
Definition: Promoter.h:69
Promoter * m_promoter
Promoter to be used.
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:112
te::da::DataSet * m_dataset
The dataset being used.
int m_currentRow
An internal row pointer.
#define TEQTWIDGETSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:63
A table model representing a te::da::DataSet.