-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathFileTypesModel.h
170 lines (145 loc) · 5.4 KB
/
FileTypesModel.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
//-----------------------------------------------------------------------------
// File: FileTypesModel.h
//-----------------------------------------------------------------------------
// Project: Kactus 2
// Author: Joni-Matti Maatta
// Date: 20.02.2013
//
// Description:
// Model for file types data.
//-----------------------------------------------------------------------------
#ifndef FILETYPESMODEL_H
#define FILETYPESMODEL_H
#include <QAbstractTableModel>
#include <QMap>
#include <QList>
#include <QString>
#include <QSettings>
#include <QSharedPointer>
//-----------------------------------------------------------------------------
//! Data model for the address editor.
//-----------------------------------------------------------------------------
class FileTypesModel : public QAbstractTableModel
{
Q_OBJECT
public:
/*!
* Constructor which loads the model from settings.
*
* @param [in] settings The settings store.
* @param [in] parent The owner of this model.
*
*/
FileTypesModel(QSettings& settings, QObject* parent);
/*!
* The destructor.
*/
virtual ~FileTypesModel() = default;
// Disable copying.
FileTypesModel(FileTypesModel const& rhs) = delete;
FileTypesModel& operator=(FileTypesModel const& rhs) = delete;
/*!
* Saves the model to settings.
*
* @param [in,out] settings The settings store.
*/
void apply(QSettings& settings);
/*!
* Returns the number of rows to be displayed.
*
* @param [in] parent Identifies the parent. Must always be a invalid index.
*/
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
/*!
* Returns the number of columns to display.
*
* @param [in] parent Identifies the parent. Must always be a invalid index.
*/
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
/*!
* Returns that data for specified index in given data role.
*
* Qt::UserRole returns QStringList containing the file types that are already defined.
*
* @param [in] index Identifies the object that's data is wanted.
* @param [in] role Identifies the type of data being requested.
*
* @return QVariant containing the requested data.
*/
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
/*!
* Returns the data for given header in given data role.
*
* @param [in] section Identifies the header section.
* @param [in] orientation Only Qt::Horizontal is supported.
* @param [in] role Identifies the type of the data being requested.
*
* @return QVariant contains the requested data.
*/
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
/*!
* Sets the data for specified index.
*
* @param [in] index Identifies the object that's data is to be saved.
* @param [in] value Contains the data to be saved.
* @param [in] role Identifies the type of the data to be saved.
*
* @return True if data was saved successfully.
*/
virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole );
/*!
* Retrieves info on what operations are possible for specified item.
*
* @param [in] index Identifies the item that's operations are requested.
*
* @return Item flags containing info on which operations are available for the given index.
*/
virtual Qt::ItemFlags flags(const QModelIndex& index) const;
public slots:
/*!
* Adds a new empty row to the model.
*/
void onAddRow();
/*!
* Removes a row from the model.
*
* @param [in] row Specifies the row to remove.
*/
void onRemoveRow(int row);
/*!
* Called when a new item should be added to given index.
*
* @param [in] index The position where new item should be added at.
*/
void onAddItem(const QModelIndex& index);
/*!
* An item should be removed from the model.
*
* @param [in] index Identifies the item that should be removed.
*/
void onRemoveItem(const QModelIndex& index);
private:
//-----------------------------------------------------------------------------
//! FileTypeEntry structure.
//-----------------------------------------------------------------------------
struct FileTypeEntry
{
QString name; //!< The file type name.
bool editInKactus; //!< True, if edited in Kactus rather than some other application.
QString extensions; //!< The extensions for this file type.
QString executable; //!< The executable to run this file type.
/*!
* Default constructor.
*/
FileTypeEntry() : name(), editInKactus(false), extensions(), executable()
{
}
};
//-----------------------------------------------------------------------------
// Data.
//-----------------------------------------------------------------------------
//! The file type entries.
QList<FileTypeEntry> entries_;
};
//-----------------------------------------------------------------------------
#endif // FILETYPESMODEL_H