9
9
#include < QStandardPaths>
10
10
#include < QUuid>
11
11
#include " enginesmodel.h"
12
- #include " extension .h"
12
+ #include " plugin .h"
13
13
#include " searchengine.h"
14
14
15
15
namespace {
16
-
17
16
enum class Section { Name, Trigger, URL} ;
18
17
const int sectionCount = 3 ;
19
-
20
18
std::map<QString,QIcon> iconCache;
21
-
22
19
}
23
20
24
21
25
- /* * ***************************************************************************/
26
- Websearch::EnginesModel::EnginesModel (Extension *extension, QObject *parent)
27
- : QAbstractTableModel(parent), extension_(extension) {
22
+ EnginesModel::EnginesModel (Plugin *extension, QObject *parent)
23
+ : QAbstractTableModel(parent), extension_(extension)
24
+ {
25
+
28
26
}
29
27
30
28
31
- /* * ************************************************************************** */
32
- int Websearch::EnginesModel::rowCount ( const QModelIndex &) const {
29
+ int EnginesModel::rowCount ( const QModelIndex &) const
30
+ {
33
31
return static_cast <int >(extension_->engines ().size ());
34
32
}
35
33
36
34
37
-
38
- /* * ***************************************************************************/
39
- int Websearch::EnginesModel::columnCount (const QModelIndex &) const {
35
+ int EnginesModel::columnCount (const QModelIndex &) const
36
+ {
40
37
return sectionCount;
41
38
}
42
39
43
40
44
-
45
- /* * ***************************************************************************/
46
- QVariant Websearch::EnginesModel::headerData (int section, Qt::Orientation orientation, int role) const {
41
+ QVariant EnginesModel::headerData (int section, Qt::Orientation orientation, int role) const
42
+ {
47
43
// No sanity check necessary since
48
44
if ( section < 0 || sectionCount <= section )
49
45
return QVariant ();
@@ -81,9 +77,8 @@ QVariant Websearch::EnginesModel::headerData(int section, Qt::Orientation orient
81
77
}
82
78
83
79
84
-
85
- /* * ***************************************************************************/
86
- QVariant Websearch::EnginesModel::data (const QModelIndex &index, int role) const {
80
+ QVariant EnginesModel::data (const QModelIndex &index, int role) const
81
+ {
87
82
if ( !index .isValid () ||
88
83
index .row () >= static_cast <int >(extension_->engines ().size ()) ||
89
84
index .column () >= sectionCount )
@@ -119,9 +114,8 @@ QVariant Websearch::EnginesModel::data(const QModelIndex &index, int role) const
119
114
}
120
115
121
116
122
-
123
- /* * ***************************************************************************/
124
- bool Websearch::EnginesModel::setData (const QModelIndex &index, const QVariant &value, int role) {
117
+ bool EnginesModel::setData (const QModelIndex &index, const QVariant &value, int role)
118
+ {
125
119
if ( !index .isValid () ||
126
120
index .row () >= static_cast <int >(extension_->engines ().size ()) ||
127
121
index .column () >= sectionCount)
@@ -168,14 +162,14 @@ bool Websearch::EnginesModel::setData(const QModelIndex &index, const QVariant &
168
162
169
163
// Create extension dir if necessary
170
164
QDir configDir = QDir (QStandardPaths::writableLocation (QStandardPaths::AppConfigLocation));
171
- if ( !configDir.exists (extension_->Core ::Plugin ::id ()) ) {
172
- if ( !configDir.mkdir (extension_->Core ::Plugin ::id ()) ) {
165
+ if ( !configDir.exists (extension_->Core ::PluginInstance ::id ()) ) {
166
+ if ( !configDir.mkdir (extension_->Core ::PluginInstance ::id ()) ) {
173
167
qWarning () << " Could not create extension data dir." ;
174
168
return false ;
175
169
}
176
170
}
177
171
178
- configDir.cd (extension_->Core ::Plugin ::id ());
172
+ configDir.cd (extension_->Core ::PluginInstance ::id ());
179
173
180
174
// Build the new random path
181
175
QString newFilePath = configDir.filePath (QString (" %1.%2" )
@@ -206,19 +200,17 @@ bool Websearch::EnginesModel::setData(const QModelIndex &index, const QVariant &
206
200
}
207
201
208
202
209
-
210
- /* * ***************************************************************************/
211
- Qt::ItemFlags Websearch::EnginesModel::flags (const QModelIndex &index) const {
203
+ Qt::ItemFlags EnginesModel::flags (const QModelIndex &index) const
204
+ {
212
205
if (index .isValid ())
213
206
return QAbstractTableModel::flags (index ) | Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled;
214
207
else
215
208
return QAbstractTableModel::flags (index ) | Qt::ItemIsDropEnabled;
216
209
}
217
210
218
211
219
-
220
- /* * ***************************************************************************/
221
- bool Websearch::EnginesModel::insertRows (int position, int rows, const QModelIndex &) {
212
+ bool EnginesModel::insertRows (int position, int rows, const QModelIndex &)
213
+ {
222
214
if ( position < 0 || rows < 1 ||
223
215
static_cast <int >(extension_->engines ().size ()) < position)
224
216
return false ;
@@ -235,9 +227,8 @@ bool Websearch::EnginesModel::insertRows(int position, int rows, const QModelInd
235
227
}
236
228
237
229
238
-
239
- /* * ***************************************************************************/
240
- bool Websearch::EnginesModel::removeRows (int position, int rows, const QModelIndex &) {
230
+ bool EnginesModel::removeRows (int position, int rows, const QModelIndex &)
231
+ {
241
232
if ( position < 0 || rows < 1 ||
242
233
static_cast <int >(extension_->engines ().size ()) < position + rows)
243
234
return false ;
@@ -252,10 +243,9 @@ bool Websearch::EnginesModel::removeRows(int position, int rows, const QModelInd
252
243
}
253
244
254
245
255
-
256
- /* * ***************************************************************************/
257
- bool Websearch::EnginesModel::moveRows (const QModelIndex &srcParent, int srcRow, int cnt,
258
- const QModelIndex &dstParent, int dstRow) {
246
+ bool EnginesModel::moveRows (const QModelIndex &srcParent, int srcRow, int cnt,
247
+ const QModelIndex &dstParent, int dstRow)
248
+ {
259
249
if ( srcRow < 0 || cnt < 1 || dstRow < 0 ||
260
250
static_cast <int >(extension_->engines ().size ()) < srcRow + cnt - 1 ||
261
251
static_cast <int >(extension_->engines ().size ()) < dstRow ||
@@ -279,29 +269,23 @@ bool Websearch::EnginesModel::moveRows(const QModelIndex &srcParent, int srcRow,
279
269
}
280
270
281
271
282
-
283
- /* * ***************************************************************************/
284
- void Websearch::EnginesModel::restoreDefaults () {
272
+ void EnginesModel::restoreDefaults ()
273
+ {
285
274
beginResetModel ();
286
275
extension_->restoreDefaultEngines ();
287
276
endResetModel ();
288
277
}
289
278
290
279
291
-
292
- /* * ***************************************************************************/
293
- Qt::DropActions Websearch::EnginesModel::supportedDropActions () const {
280
+ Qt::DropActions EnginesModel::supportedDropActions () const
281
+ {
294
282
return Qt::MoveAction;
295
283
}
296
284
297
285
298
-
299
- /* * ***************************************************************************/
300
- bool Websearch::EnginesModel::dropMimeData (const QMimeData *data,
301
- Qt::DropAction /* action*/ ,
302
- int dstRow,
303
- int /* column*/ ,
304
- const QModelIndex &/* parent*/ ) {
286
+ bool EnginesModel::dropMimeData (const QMimeData *data, Qt::DropAction /* action*/ ,
287
+ int dstRow, int /* column*/ , const QModelIndex &/* parent*/ )
288
+ {
305
289
QByteArray encoded = data->data (" application/x-qabstractitemmodeldatalist" );
306
290
QDataStream stream (&encoded, QIODevice::ReadOnly);
307
291
int srcRow = 0 ;
0 commit comments