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