summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2016-08-05 00:10:33 +0200
committerPetr Mrázek <peterix@gmail.com>2016-08-05 00:10:33 +0200
commitcf0694a0cb9041c14cc0e06b9495590baacead73 (patch)
tree45613eaa4dd18165dedef4eed0bb86f9ab863f4c /api
parentb76d4573cdaa41a3493596571dbba452ab7a5b2e (diff)
downloadMultiMC-cf0694a0cb9041c14cc0e06b9495590baacead73.tar
MultiMC-cf0694a0cb9041c14cc0e06b9495590baacead73.tar.gz
MultiMC-cf0694a0cb9041c14cc0e06b9495590baacead73.tar.lz
MultiMC-cf0694a0cb9041c14cc0e06b9495590baacead73.tar.xz
MultiMC-cf0694a0cb9041c14cc0e06b9495590baacead73.zip
NOISSUE allow user to sort mod list by clicking on column headers
Diffstat (limited to 'api')
-rw-r--r--api/logic/minecraft/ModList.cpp32
-rw-r--r--api/logic/minecraft/ModList.h10
2 files changed, 9 insertions, 33 deletions
diff --git a/api/logic/minecraft/ModList.cpp b/api/logic/minecraft/ModList.cpp
index d1ad75ab..20963729 100644
--- a/api/logic/minecraft/ModList.cpp
+++ b/api/logic/minecraft/ModList.cpp
@@ -29,14 +29,16 @@ ModList::ModList(const QString &dir) : QAbstractListModel(), m_dir(dir)
QDir::NoSymLinks);
m_dir.setSorting(QDir::Name | QDir::IgnoreCase | QDir::LocaleAware);
m_watcher = new QFileSystemWatcher(this);
- is_watching = false;
- connect(m_watcher, SIGNAL(directoryChanged(QString)), this,
- SLOT(directoryChanged(QString)));
+ connect(m_watcher, SIGNAL(directoryChanged(QString)), this, SLOT(directoryChanged(QString)));
}
void ModList::startWatching()
{
+ if(is_watching)
+ return;
+
update();
+
is_watching = m_watcher->addPath(m_dir.absolutePath());
if (is_watching)
{
@@ -50,6 +52,9 @@ void ModList::startWatching()
void ModList::stopWatching()
{
+ if(!is_watching)
+ return;
+
is_watching = !m_watcher->removePath(m_dir.absolutePath());
if (!is_watching)
{
@@ -61,19 +66,6 @@ void ModList::stopWatching()
}
}
-void ModList::internalSort(QList<Mod> &what)
-{
- auto predicate = [](const Mod &left, const Mod &right)
- {
- if (left.name() == right.name())
- {
- return left.mmc_id().localeAwareCompare(right.mmc_id()) < 0;
- }
- return left.name().localeAwareCompare(right.name()) < 0;
- };
- std::sort(what.begin(), what.end(), predicate);
-}
-
bool ModList::update()
{
if (!isValid())
@@ -93,7 +85,6 @@ bool ModList::update()
{
newMods.append(Mod(entry));
}
- internalSort(newMods);
orderedMods.append(newMods);
orderOrStateChanged = true;
}
@@ -363,13 +354,6 @@ bool ModList::dropMimeData(const QMimeData* data, Qt::DropAction action, int, in
added = true;
}
}
- if(added)
- {
- // re-sort the list
- beginResetModel();
- internalSort(mods);
- endResetModel();
- }
if (was_watching)
{
startWatching();
diff --git a/api/logic/minecraft/ModList.h b/api/logic/minecraft/ModList.h
index e7267389..1b91764b 100644
--- a/api/logic/minecraft/ModList.h
+++ b/api/logic/minecraft/ModList.h
@@ -104,13 +104,6 @@ public:
return mods;
}
-private:
- void internalSort(QList<Mod> & what);
- struct OrderItem
- {
- QString id;
- bool enabled = false;
- };
private
slots:
void directoryChanged(QString path);
@@ -120,8 +113,7 @@ signals:
protected:
QFileSystemWatcher *m_watcher;
- bool is_watching;
+ bool is_watching = false;
QDir m_dir;
- QString m_list_id;
QList<Mod> mods;
};