@@ -241,9 +241,6 @@ bool ContentSelectorModel::ContentModel::setData(const QModelIndex& index, const
241241 return false ;
242242
243243 EsmFile* file = item (index.row ());
244- QString fileName = file->fileName ();
245- bool success = false ;
246-
247244 switch (role)
248245 {
249246 case Qt::EditRole:
@@ -257,65 +254,23 @@ bool ContentSelectorModel::ContentModel::setData(const QModelIndex& index, const
257254 file->setFileProperty (EsmFile::FileProperty_GameFile, list.at (i));
258255
259256 emit dataChanged (index, index);
260-
261- success = true ;
257+ return true ;
262258 }
263- break ;
264-
265259 case Qt::UserRole + 1 :
266260 {
267- success = (flags (index) & Qt::ItemIsEnabled);
268-
269- if (success)
270- {
271- success = setCheckState (file, value.toBool ());
272- emit dataChanged (index, index);
273- }
261+ return isEnabled (index) && setCheckState (file, value.toBool ());
274262 }
275- break ;
276-
277263 case Qt::CheckStateRole:
278264 {
279265 int checkValue = value.toInt ();
280- bool setState = false ;
281- if (file->builtIn () || file->fromAnotherConfigFile ())
282- {
283- setState = false ;
284- success = false ;
285- }
286- else if (checkValue == Qt::Checked && !mCheckedFiles .contains (file))
287- {
288- setState = true ;
289- success = true ;
290- }
291- else if (checkValue == Qt::Checked && mCheckedFiles .contains (file))
292- setState = true ;
293- else if (checkValue == Qt::Unchecked)
294- setState = true ;
295-
296- if (setState)
297- {
298- setCheckState (file, success);
299- emit dataChanged (index, index);
300- }
301- else
302- return success;
303-
304- for (EsmFile* file2 : mFiles )
305- {
306- if (file2->gameFiles ().contains (fileName, Qt::CaseInsensitive))
307- {
308- QModelIndex idx = indexFromItem (file2);
309- emit dataChanged (idx, idx);
310- }
311- }
312-
313- success = true ;
266+ if (checkValue == Qt::Checked)
267+ return mCheckedFiles .contains (file) || setCheckState (file, true );
268+ if (checkValue == Qt::Unchecked)
269+ return !mCheckedFiles .contains (file) || setCheckState (file, false );
314270 }
315- break ;
316271 }
317272
318- return success ;
273+ return false ;
319274}
320275
321276bool ContentSelectorModel::ContentModel::insertRows (int position, int rows, const QModelIndex& parent)
@@ -709,6 +664,7 @@ void ContentSelectorModel::ContentModel::setContentList(const QStringList& fileL
709664 {
710665 // setCheckState already gracefully handles builtIn and fromAnotherConfigFile
711666 // as necessary, move plug-ins in visible list to match sequence of supplied filelist
667+ // FIXME: setCheckState also does tons of other things which we don't want to happen
712668 int filePosition = indexFromItem (file).row ();
713669 if (filePosition < previousPosition)
714670 {
@@ -802,38 +758,37 @@ bool ContentSelectorModel::ContentModel::setCheckState(const EsmFile* file, bool
802758 else
803759 mCheckedFiles .erase (file);
804760
805- emit dataChanged (indexFromItem (file), indexFromItem (file));
761+ QModelIndex fileIndex = indexFromItem (file);
762+ emit dataChanged (fileIndex, fileIndex);
806763
764+ // FIXME: this should not happen per-file.
765+ // Consider not hiding files if their game is disabled so that this is completely unnecessary.
807766 if (file->isGameFile ())
808767 refreshModel ();
809768
810- // if we're checking an item, ensure all "upstream" files (dependencies) are checked as well.
769+ // Check "upstream" files (dependencies) if the file is checked,
770+ // uncheck downstream files if the file is unchecked.
771+ // Update the data for downstream files unconditionally (load order warnings).
772+ // FIXME: downstream files of toggled upstream/downstream files should be updated, but that would be slow.
811773 if (checkState)
812774 {
813775 for (const QString& upstreamName : file->gameFiles ())
814776 {
815777 const EsmFile* upstreamFile = item (upstreamName);
816-
817- if (!upstreamFile)
778+ if (upstreamFile == nullptr || !mCheckedFiles .insert (upstreamFile).second )
818779 continue ;
819-
820- mCheckedFiles .insert (upstreamFile);
821-
822- emit dataChanged (indexFromItem (upstreamFile), indexFromItem (upstreamFile));
780+ QModelIndex upstreamIndex = indexFromItem (upstreamFile);
781+ emit dataChanged (upstreamIndex, upstreamIndex);
823782 }
824783 }
825- // otherwise, if we're unchecking an item (or the file is a game file) ensure all downstream files are unchecked.
826- else
784+ for (const EsmFile* otherFile : mFiles )
827785 {
828- for (const EsmFile* downstreamFile : mFiles )
829- {
830- if (downstreamFile->gameFiles ().contains (file->fileName (), Qt::CaseInsensitive))
831- {
832- mCheckedFiles .erase (downstreamFile);
833-
834- emit dataChanged (indexFromItem (downstreamFile), indexFromItem (downstreamFile));
835- }
836- }
786+ if (!otherFile->gameFiles ().contains (file->fileName (), Qt::CaseInsensitive))
787+ continue ;
788+ if (!checkState)
789+ mCheckedFiles .erase (otherFile);
790+ QModelIndex otherIndex = indexFromItem (otherFile);
791+ emit dataChanged (otherIndex, otherIndex);
837792 }
838793
839794 // Need to manually let Bloodmoon entry know if Tribunal is checked/unchecked
0 commit comments