mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 08:23:53 +00:00
Files are now sorted by modified timestamp, fixes Bug #415
This commit is contained in:
parent
2b25178aef
commit
1c06a06f91
2 changed files with 44 additions and 24 deletions
|
@ -424,6 +424,7 @@ bool DataFilesPage::setupDataFiles()
|
||||||
if (!showDataFilesWarning())
|
if (!showDataFilesWarning())
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the paths to the respective models
|
// Add the paths to the respective models
|
||||||
for (Files::PathContainer::iterator it = mDataDirs.begin(); it != mDataDirs.end(); ++it) {
|
for (Files::PathContainer::iterator it = mDataDirs.begin(); it != mDataDirs.end(); ++it) {
|
||||||
QString path = QString::fromStdString(it->string());
|
QString path = QString::fromStdString(it->string());
|
||||||
|
@ -440,8 +441,10 @@ bool DataFilesPage::setupDataFiles()
|
||||||
mPluginsModel->addPlugins(path);
|
mPluginsModel->addPlugins(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// mMastersModel->sort(0);
|
mMastersModel->sort(0);
|
||||||
// mPluginsModel->sort(0);
|
mPluginsModel->sort(0);
|
||||||
|
// mMastersTable->sortByColumn(3, Qt::AscendingOrder);
|
||||||
|
// mPluginsTable->sortByColumn(3, Qt::AscendingOrder);
|
||||||
|
|
||||||
|
|
||||||
readConfig();
|
readConfig();
|
||||||
|
@ -734,8 +737,8 @@ void DataFilesPage::setCheckState(QModelIndex index)
|
||||||
QModelIndex sourceIndex = mPluginsProxyModel->mapToSource(index);
|
QModelIndex sourceIndex = mPluginsProxyModel->mapToSource(index);
|
||||||
|
|
||||||
(mPluginsModel->checkState(sourceIndex) == Qt::Checked)
|
(mPluginsModel->checkState(sourceIndex) == Qt::Checked)
|
||||||
? mPluginsModel->setCheckState(index, Qt::Unchecked)
|
? mPluginsModel->setCheckState(sourceIndex, Qt::Unchecked)
|
||||||
: mPluginsModel->setCheckState(index, Qt::Checked);
|
: mPluginsModel->setCheckState(sourceIndex, Qt::Checked);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (object->objectName() == QLatin1String("MastersTable")) {
|
if (object->objectName() == QLatin1String("MastersTable")) {
|
||||||
|
|
|
@ -96,15 +96,11 @@ QVariant DataFilesModel::data(const QModelIndex &index, int role) const
|
||||||
case Qt::TextAlignmentRole: {
|
case Qt::TextAlignmentRole: {
|
||||||
switch (column) {
|
switch (column) {
|
||||||
case 0:
|
case 0:
|
||||||
return Qt::AlignLeft + Qt::AlignVCenter;
|
|
||||||
case 1:
|
case 1:
|
||||||
return Qt::AlignLeft + Qt::AlignVCenter;
|
return Qt::AlignLeft + Qt::AlignVCenter;
|
||||||
case 2:
|
case 2:
|
||||||
return Qt::AlignRight + Qt::AlignVCenter;
|
|
||||||
case 3:
|
case 3:
|
||||||
return Qt::AlignRight + Qt::AlignVCenter;
|
|
||||||
case 4:
|
case 4:
|
||||||
return Qt::AlignRight + Qt::AlignVCenter;
|
|
||||||
case 5:
|
case 5:
|
||||||
return Qt::AlignRight + Qt::AlignVCenter;
|
return Qt::AlignRight + Qt::AlignVCenter;
|
||||||
default:
|
default:
|
||||||
|
@ -218,20 +214,34 @@ void DataFilesModel::sort(int column, Qt::SortOrder order)
|
||||||
// TODO: Make this more efficient
|
// TODO: Make this more efficient
|
||||||
emit layoutAboutToBeChanged();
|
emit layoutAboutToBeChanged();
|
||||||
|
|
||||||
// A reference list we can sort
|
|
||||||
QStringList all = uncheckedItems();
|
|
||||||
//all.append(uncheckedItems());
|
|
||||||
|
|
||||||
// Sort the list of items naturally
|
QMap<QString, QString> timestamps;
|
||||||
qSort(all.begin(), all.end(), naturalSortLessThanCI);
|
|
||||||
|
|
||||||
for (int i = 0; i < all.size(); ++i) {
|
QList<EsmFile *>::ConstIterator it;
|
||||||
const QString currentItem = all.at(i);
|
QList<EsmFile *>::ConstIterator itEnd = mFiles.constEnd();
|
||||||
QModelIndex index = indexFromItem(findItem(currentItem));
|
|
||||||
|
|
||||||
// Move the actual item from the old position to the new
|
// Make a list of files sorted by timestamp
|
||||||
if (index.isValid())
|
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);
|
||||||
|
while (ti.hasNext()) {
|
||||||
|
ti.next();
|
||||||
|
i++;
|
||||||
|
|
||||||
|
QModelIndex index = indexFromItem(findItem(ti.value()));
|
||||||
|
|
||||||
|
if (index.isValid()) {
|
||||||
mFiles.swap(index.row(), i);
|
mFiles.swap(index.row(), i);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
emit layoutChanged();
|
emit layoutChanged();
|
||||||
|
@ -381,13 +391,20 @@ EsmFile* DataFilesModel::item(int row)
|
||||||
QStringList DataFilesModel::checkedItems()
|
QStringList DataFilesModel::checkedItems()
|
||||||
{
|
{
|
||||||
QStringList list;
|
QStringList list;
|
||||||
QHash<QString, Qt::CheckState>::ConstIterator it;
|
|
||||||
QHash<QString, Qt::CheckState>::ConstIterator itEnd = mCheckStates.constEnd();
|
|
||||||
|
|
||||||
for (it = mCheckStates.constBegin(); it != itEnd; ++it) {
|
QList<EsmFile *>::ConstIterator it;
|
||||||
if (it.value() == Qt::Checked) {
|
QList<EsmFile *>::ConstIterator itEnd = mFiles.constEnd();
|
||||||
list << it.key();
|
|
||||||
}
|
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;
|
return list;
|
||||||
|
|
Loading…
Reference in a new issue