@@ -303,7 +303,7 @@ bool ModFolderModel::installMod(const QString &filename)
303
303
return false ;
304
304
}
305
305
306
- bool ModFolderModel::enableMods (const QModelIndexList& indexes, bool enable)
306
+ bool ModFolderModel::setModStatus (const QModelIndexList& indexes, ModStatusAction enable)
307
307
{
308
308
if (interaction_disabled) {
309
309
return false ;
@@ -314,27 +314,14 @@ bool ModFolderModel::enableMods(const QModelIndexList& indexes, bool enable)
314
314
315
315
for (auto index: indexes)
316
316
{
317
- Mod &m = mods[index.row ()];
318
- m.enable (enable);
319
- emit dataChanged (index, index);
317
+ if (index.column () != 0 ) {
318
+ continue ;
319
+ }
320
+ setModStatus (index.row (), enable);
320
321
}
321
322
return true ;
322
323
}
323
324
324
- void ModFolderModel::toggleEnabled (const QModelIndex& index)
325
- {
326
- if (interaction_disabled) {
327
- return ;
328
- }
329
- if (!index.isValid ()) {
330
- return ;
331
- }
332
-
333
- Mod &m = mods[index.row ()];
334
- m.enable (!m.enabled ());
335
- emit dataChanged (index, index);
336
- }
337
-
338
325
bool ModFolderModel::deleteMods (const QModelIndexList& indexes)
339
326
{
340
327
if (interaction_disabled) {
@@ -418,16 +405,52 @@ bool ModFolderModel::setData(const QModelIndex &index, const QVariant &value, in
418
405
419
406
if (role == Qt::CheckStateRole)
420
407
{
421
- auto &mod = mods[index.row ()];
422
- if (mod.enable (!mod.enabled ()))
423
- {
424
- emit dataChanged (index, index);
425
- return true ;
426
- }
408
+ return setModStatus (index.row (), Toggle);
427
409
}
428
410
return false ;
429
411
}
430
412
413
+ bool ModFolderModel::setModStatus (int row, ModFolderModel::ModStatusAction action)
414
+ {
415
+ if (row < 0 || row >= mods.size ()) {
416
+ return false ;
417
+ }
418
+
419
+ auto &mod = mods[row];
420
+ bool desiredStatus;
421
+ switch (action) {
422
+ case Enable:
423
+ desiredStatus = true ;
424
+ break ;
425
+ case Disable:
426
+ desiredStatus = false ;
427
+ break ;
428
+ case Toggle:
429
+ default :
430
+ desiredStatus = !mod.enabled ();
431
+ break ;
432
+ }
433
+
434
+ if (desiredStatus == mod.enabled ()) {
435
+ return true ;
436
+ }
437
+
438
+ // preserve the row, but change its ID
439
+ auto oldId = mod.mmc_id ();
440
+ if (!mod.enable (!mod.enabled ())) {
441
+ return false ;
442
+ }
443
+ auto newId = mod.mmc_id ();
444
+ if (modsIndex.contains (newId)) {
445
+ // NOTE: this could handle a corner case, where we are overwriting a file, because the same 'mod' exists both enabled and disabled
446
+ // But is it necessary?
447
+ }
448
+ modsIndex.remove (oldId);
449
+ modsIndex[newId] = row;
450
+ emit dataChanged (index (row, 0 ), index (row, columnCount (QModelIndex ()) - 1 ));
451
+ return true ;
452
+ }
453
+
431
454
QVariant ModFolderModel::headerData (int section, Qt::Orientation orientation, int role) const
432
455
{
433
456
switch (role)
0 commit comments