mirror of
https://github.com/UltimMC/Launcher.git
synced 2025-10-03 16:51:30 +00:00
WIP some more perf work that was left over, I guess
This commit is contained in:
@@ -21,13 +21,10 @@ bool InstanceProxyModel::subSortLessThan(const QModelIndex &left, const QModelIn
|
||||
{
|
||||
BaseInstance *pdataLeft = static_cast<BaseInstance *>(left.internalPointer());
|
||||
BaseInstance *pdataRight = static_cast<BaseInstance *>(right.internalPointer());
|
||||
QString sortMode = MMC->settings()->get("InstSortMode").toString();
|
||||
if (sortMode == "LastLaunch")
|
||||
{
|
||||
switch(currentSortMode) {
|
||||
case SortMode::ByLastPlayed:
|
||||
return pdataLeft->lastLaunch() > pdataRight->lastLaunch();
|
||||
}
|
||||
else
|
||||
{
|
||||
case SortMode::ByName:
|
||||
return QString::localeAwareCompare(pdataLeft->name(), pdataRight->name()) < 0;
|
||||
}
|
||||
}
|
||||
|
@@ -7,10 +7,21 @@
|
||||
*/
|
||||
class InstanceProxyModel : public GroupedProxyModel
|
||||
{
|
||||
public:
|
||||
enum class SortMode {
|
||||
ByName,
|
||||
ByLastPlayed
|
||||
};
|
||||
public:
|
||||
explicit InstanceProxyModel(QObject *parent = 0);
|
||||
QVariant data(const QModelIndex & index, int role) const override;
|
||||
void setSortMode(SortMode mode) {
|
||||
currentSortMode = mode;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual bool subSortLessThan(const QModelIndex &left, const QModelIndex &right) const override;
|
||||
|
||||
private:
|
||||
SortMode currentSortMode = SortMode::ByName;
|
||||
};
|
||||
|
@@ -680,11 +680,22 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow
|
||||
proxymodel = new InstanceProxyModel(this);
|
||||
proxymodel->setSourceModel(MMC->instances().get());
|
||||
auto sortMode = MMC->settings()->getSetting("InstSortMode");
|
||||
connect(sortMode.get(), &Setting::SettingChanged, [](const Setting &setting, QVariant value){
|
||||
auto applySortMode = [this](QVariant value) {
|
||||
auto StrValue = value.toString();
|
||||
|
||||
});
|
||||
if (StrValue == "LastLaunch")
|
||||
{
|
||||
proxymodel->setSortMode(InstanceProxyModel::SortMode::ByLastPlayed);
|
||||
}
|
||||
else // Name
|
||||
{
|
||||
proxymodel->setSortMode(InstanceProxyModel::SortMode::ByName);
|
||||
}
|
||||
proxymodel->sort(0);
|
||||
};
|
||||
applySortMode(sortMode->get());
|
||||
connect(sortMode.get(), &Setting::SettingChanged, [applySortMode](const Setting &setting, QVariant value){
|
||||
applySortMode(value);
|
||||
});
|
||||
connect(proxymodel, &InstanceProxyModel::dataChanged, this, &MainWindow::instanceDataChanged);
|
||||
|
||||
view->setModel(proxymodel);
|
||||
|
Reference in New Issue
Block a user