2021-10-25 23:51:42 +02:00
|
|
|
/* Copyright 2013-2021 MultiMC Contributors
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-10-02 11:12:14 +02:00
|
|
|
#include "InstanceTableProxyModel.h"
|
2021-10-25 23:51:42 +02:00
|
|
|
|
|
|
|
#include <icons/IconList.h>
|
2022-10-01 19:38:40 +02:00
|
|
|
#include "Application.h"
|
|
|
|
#include "InstanceList.h"
|
2021-10-25 23:51:42 +02:00
|
|
|
|
2022-10-02 11:12:14 +02:00
|
|
|
InstanceTableProxyModel::InstanceTableProxyModel(QObject* parent) : QSortFilterProxyModel(parent)
|
2022-10-01 19:38:40 +02:00
|
|
|
{
|
2021-10-25 23:51:42 +02:00
|
|
|
m_naturalSort.setNumericMode(true);
|
|
|
|
m_naturalSort.setCaseSensitivity(Qt::CaseSensitivity::CaseInsensitive);
|
|
|
|
// FIXME: use loaded translation as source of locale instead, hook this up to translation changes
|
|
|
|
m_naturalSort.setLocale(QLocale::system());
|
|
|
|
}
|
|
|
|
|
2022-10-02 11:12:14 +02:00
|
|
|
QVariant InstanceTableProxyModel::data(const QModelIndex& index, int role) const
|
2021-10-25 23:51:42 +02:00
|
|
|
{
|
|
|
|
QVariant data = QSortFilterProxyModel::data(index, role);
|
2022-10-01 19:38:40 +02:00
|
|
|
if (role == Qt::DecorationRole) {
|
2022-09-30 23:37:00 +02:00
|
|
|
if (!data.toString().isEmpty())
|
2022-10-01 22:02:11 +02:00
|
|
|
return APPLICATION->icons()->getIcon(data.toString());
|
2021-10-25 23:51:42 +02:00
|
|
|
}
|
2022-10-01 18:22:36 +02:00
|
|
|
|
|
|
|
switch (index.column()) {
|
2022-10-01 22:07:38 +02:00
|
|
|
case InstanceList::LastPlayedColumn: {
|
2022-10-01 18:22:36 +02:00
|
|
|
if (role == Qt::DisplayRole) {
|
|
|
|
QDateTime foo = data.toDateTime();
|
|
|
|
if (foo.isNull() || !foo.isValid() || foo.toMSecsSinceEpoch() == 0)
|
|
|
|
return tr("Never");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-10-25 23:51:42 +02:00
|
|
|
return data;
|
2022-10-01 18:22:36 +02:00
|
|
|
}
|