diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 50502f6e28..782c4fb011 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -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")) { diff --git a/apps/launcher/model/datafilesmodel.cpp b/apps/launcher/model/datafilesmodel.cpp index 0aa29a337a..d4674b9539 100644 --- a/apps/launcher/model/datafilesmodel.cpp +++ b/apps/launcher/model/datafilesmodel.cpp @@ -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 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(); + } + - 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 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::ConstIterator it; - QHash::ConstIterator itEnd = mCheckStates.constEnd(); - for (it = mCheckStates.constBegin(); it != itEnd; ++it) { - if (it.value() == Qt::Checked) { - list << it.key(); - } + QList::ConstIterator it; + QList::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;