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