diff --git a/apps/launcher/model/datafilesmodel.cpp b/apps/launcher/model/datafilesmodel.cpp index 68f9336f2..70b9d0ca7 100644 --- a/apps/launcher/model/datafilesmodel.cpp +++ b/apps/launcher/model/datafilesmodel.cpp @@ -223,36 +223,34 @@ void DataFilesModel::sort(int column, Qt::SortOrder order) // TODO: Make this more efficient emit layoutAboutToBeChanged(); + QList sortedFiles; - QMap timestamps; + QMultiMap timestamps; - QList::ConstIterator it; - QList::ConstIterator itEnd = mFiles.constEnd(); - - // Make a list of files sorted by timestamp - int i = 0; - for (it = mFiles.constBegin(); it != itEnd; ++it) { - EsmFile *file = item(i); - ++i; - timestamps[file->modified().toString(Qt::ISODate)] = file->fileName(); - } + foreach (EsmFile *file, mFiles) + timestamps.insert(file->modified().toString(Qt::ISODate), file->fileName()); - - // Now sort the actual list of files by timestamp - i = 0; QMapIterator ti(timestamps); + while (ti.hasNext()) { ti.next(); - i++; QModelIndex index = indexFromItem(findItem(ti.value())); - if (index.isValid()) { - mFiles.swap(index.row(), i); - } + if (!index.isValid()) + continue; + EsmFile *file = item(index.row()); + + if (!file) + continue; + + sortedFiles.append(file); } + mFiles.clear(); + mFiles = sortedFiles; + emit layoutChanged(); } @@ -301,6 +299,7 @@ void DataFilesModel::addMasters(const QString &path) } catch(std::runtime_error &e) { // An error occurred while reading the .esp + qWarning() << "Error reading esp: " << e.what(); continue; } } @@ -361,6 +360,7 @@ void DataFilesModel::addPlugins(const QString &path) addFile(file); } catch(std::runtime_error &e) { // An error occurred while reading the .esp + qWarning() << "Error reading esp: " << e.what(); continue; }