forked from giowck/symphytum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstandardmodel.h
executable file
·90 lines (68 loc) · 2.83 KB
/
standardmodel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
* \class StandardModel
* \brief This model is the standard model used for the storage
* of content data. It uses the default SQLite database
* of Symphytum as storage service.
* \author Giorgio Wicklein - GIOWISYS Software
* \date 07/06/2012
*/
#ifndef STANDARDMODEL_H
#define STANDARDMODEL_H
//-----------------------------------------------------------------------------
// Headers
//-----------------------------------------------------------------------------
#include <QtSql/QSqlTableModel>
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class MetadataEngine;
//-----------------------------------------------------------------------------
// StandardModel
//-----------------------------------------------------------------------------
class StandardModel : public QSqlTableModel
{
Q_OBJECT
public:
explicit StandardModel(MetadataEngine *meta, QObject *parent = nullptr);
~StandardModel();
/**
* Reimplemented headerData because the column names are queried from metadata
* and not directly from database column names
*/
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
/**
* Reimplemented sort to emit layoutChanged() signal so FormView
* and any other attached view reloads its data after sort operation
*/
void sort(int column, Qt::SortOrder order);
/** Add a new empty record to the model */
void addRecord();
/** Duplicate the specified row */
void duplicateRecord(int row);
/** Reimplemented to notify views that rows have been deleted (after deletion) */
bool removeRows(int row, int count, const QModelIndex &parent);
/**
* This method has been introduced as a workaround for the default
* rowCount() method, which returns 256 when using SQLite because
* SQLite driver doesn't support size() on queries. So this method
* returns the real row count by calling fetchMore() when needed
*/
int realRowCount();
/** Reimplement to avoid edits on read only session */
bool setData(const QModelIndex &index, const QVariant &value, int role);
signals:
/** Emitted after a model sort operation */
void modelSortedSignal(int column);
/**
* This signal is used to inform attached views that rows have been deleted.
* This is emitted _after_ row deletion operations and not before like
* other methods exposed by QSqlTableModel
* @param startRow - the first row that has been deleted
* @param count - the deleted rows count beginning with startRow
*/
void rowsDeleted(int startRow, int count);
private:
MetadataEngine *m_metadataEngine;
};
#endif // STANDARDMODEL_H