Files are now sorted by modified timestamp, fixes Bug #415

pull/37/head
Pieter van der Kloet 12 years ago
parent 2b25178aef
commit 1c06a06f91

@ -424,6 +424,7 @@ bool DataFilesPage::setupDataFiles()
if (!showDataFilesWarning())
return false;
}
// Add the paths to the respective models
for (Files::PathContainer::iterator it = mDataDirs.begin(); it != mDataDirs.end(); ++it) {
QString path = QString::fromStdString(it->string());
@ -440,8 +441,10 @@ bool DataFilesPage::setupDataFiles()
mPluginsModel->addPlugins(path);
}
// mMastersModel->sort(0);
// mPluginsModel->sort(0);
mMastersModel->sort(0);
mPluginsModel->sort(0);
// mMastersTable->sortByColumn(3, Qt::AscendingOrder);
// mPluginsTable->sortByColumn(3, Qt::AscendingOrder);
readConfig();
@ -734,8 +737,8 @@ void DataFilesPage::setCheckState(QModelIndex index)
QModelIndex sourceIndex = mPluginsProxyModel->mapToSource(index);
(mPluginsModel->checkState(sourceIndex) == Qt::Checked)
? mPluginsModel->setCheckState(index, Qt::Unchecked)
: mPluginsModel->setCheckState(index, Qt::Checked);
? mPluginsModel->setCheckState(sourceIndex, Qt::Unchecked)
: mPluginsModel->setCheckState(sourceIndex, Qt::Checked);
}
if (object->objectName() == QLatin1String("MastersTable")) {

@ -96,15 +96,11 @@ QVariant DataFilesModel::data(const QModelIndex &index, int role) const
case Qt::TextAlignmentRole: {
switch (column) {
case 0:
return Qt::AlignLeft + Qt::AlignVCenter;
case 1:
return Qt::AlignLeft + Qt::AlignVCenter;
case 2:
return Qt::AlignRight + Qt::AlignVCenter;
case 3:
return Qt::AlignRight + Qt::AlignVCenter;
case 4:
return Qt::AlignRight + Qt::AlignVCenter;
case 5:
return Qt::AlignRight + Qt::AlignVCenter;
default:
@ -218,20 +214,34 @@ void DataFilesModel::sort(int column, Qt::SortOrder order)
// TODO: Make this more efficient
emit layoutAboutToBeChanged();
// A reference list we can sort
QStringList all = uncheckedItems();
//all.append(uncheckedItems());
// Sort the list of items naturally
qSort(all.begin(), all.end(), naturalSortLessThanCI);
QMap<QString, QString> timestamps;
QList<EsmFile *>::ConstIterator it;
QList<EsmFile *>::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();
}
for (int i = 0; i < all.size(); ++i) {
const QString currentItem = all.at(i);
QModelIndex index = indexFromItem(findItem(currentItem));
// Now sort the actual list of files by timestamp
i = 0;
QMapIterator<QString, QString> ti(timestamps);
while (ti.hasNext()) {
ti.next();
i++;
// Move the actual item from the old position to the new
if (index.isValid())
QModelIndex index = indexFromItem(findItem(ti.value()));
if (index.isValid()) {
mFiles.swap(index.row(), i);
}
}
emit layoutChanged();
@ -381,13 +391,20 @@ EsmFile* DataFilesModel::item(int row)
QStringList DataFilesModel::checkedItems()
{
QStringList list;
QHash<QString, Qt::CheckState>::ConstIterator it;
QHash<QString, Qt::CheckState>::ConstIterator itEnd = mCheckStates.constEnd();
for (it = mCheckStates.constBegin(); it != itEnd; ++it) {
if (it.value() == Qt::Checked) {
list << it.key();
}
QList<EsmFile *>::ConstIterator it;
QList<EsmFile *>::ConstIterator itEnd = mFiles.constEnd();
int i = 0;
for (it = mFiles.constBegin(); it != itEnd; ++it) {
EsmFile *file = item(i);
++i;
QString name = file->fileName();
// Only add the items that are in the checked list and available
if (mCheckStates[name] == Qt::Checked && mAvailableFiles.contains(name))
list << name;
}
return list;

Loading…
Cancel
Save