Modified sorting, should not crash anymore

actorid
pvdk 12 years ago
parent 64c348c39e
commit 60aea3653f

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

Loading…
Cancel
Save