feat: add support for sorting play times

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
Sefa Eyeoglu 2022-10-01 22:27:18 +02:00
parent 24060291c8
commit b0dc7927fb
No known key found for this signature in database
GPG Key ID: C10411294912A422
5 changed files with 26 additions and 12 deletions

View File

@ -252,7 +252,7 @@ void BaseInstance::setRunning(bool running)
emit runningStatusChanged(running); emit runningStatusChanged(running);
} }
int64_t BaseInstance::totalTimePlayed() const quint64 BaseInstance::totalTimePlayed() const
{ {
qint64 current = m_settings->get("totalTimePlayed").toLongLong(); qint64 current = m_settings->get("totalTimePlayed").toLongLong();
if(m_isRunning) if(m_isRunning)
@ -263,7 +263,7 @@ int64_t BaseInstance::totalTimePlayed() const
return current; return current;
} }
int64_t BaseInstance::lastTimePlayed() const quint64 BaseInstance::lastTimePlayed() const
{ {
if(m_isRunning) if(m_isRunning)
{ {
@ -306,12 +306,12 @@ bool BaseInstance::reloadSettings()
return m_settings->reload(); return m_settings->reload();
} }
qint64 BaseInstance::lastLaunch() const quint64 BaseInstance::lastLaunch() const
{ {
return m_settings->get("lastLaunchTime").value<qint64>(); return m_settings->get("lastLaunchTime").value<quint64>();
} }
void BaseInstance::setLastLaunch(qint64 val) void BaseInstance::setLastLaunch(quint64 val)
{ {
//FIXME: if no change, do not set. setting involves saving a file. //FIXME: if no change, do not set. setting involves saving a file.
m_settings->set("lastLaunchTime", val); m_settings->set("lastLaunchTime", val);

View File

@ -106,8 +106,8 @@ public:
void setRunning(bool running); void setRunning(bool running);
bool isRunning() const; bool isRunning() const;
int64_t totalTimePlayed() const; quint64 totalTimePlayed() const;
int64_t lastTimePlayed() const; quint64 lastTimePlayed() const;
void resetTimePlayed(); void resetTimePlayed();
/// get the type of this instance /// get the type of this instance
@ -165,9 +165,9 @@ public:
* Gets the time that the instance was last launched. * Gets the time that the instance was last launched.
* Stored in milliseconds since epoch. * Stored in milliseconds since epoch.
*/ */
qint64 lastLaunch() const; quint64 lastLaunch() const;
/// Sets the last launched time to 'val' milliseconds since epoch /// Sets the last launched time to 'val' milliseconds since epoch
void setLastLaunch(qint64 val = QDateTime::currentMSecsSinceEpoch()); void setLastLaunch(quint64 val = QDateTime::currentMSecsSinceEpoch());
/*! /*!
* \brief Gets this instance's settings object. * \brief Gets this instance's settings object.

View File

@ -199,6 +199,18 @@ QVariant InstanceList::data(const QModelIndex& index, int role) const {
return tr("%1 Instance").arg(inst->name()); return tr("%1 Instance").arg(inst->name());
break; break;
} }
case SortRole: {
switch (index.column()) {
case PlayTimeColumn:
return QVariant(inst->totalTimePlayed());
case LastPlayedColumn:
return QVariant(inst->lastLaunch());
default:
return data(index, Qt::DisplayRole);
}
break;
}
} }
return QVariant(); return QVariant();
} }

View File

@ -86,9 +86,10 @@ public:
enum AdditionalRoles enum AdditionalRoles
{ {
GroupRole = Qt::UserRole, SortRole = Qt::UserRole + 1,
InstancePointerRole = 0x34B1CB48, ///< Return pointer to real instance GroupRole,
InstanceIDRole = 0x34B1CB49 ///< Return id if the instance InstancePointerRole, ///< Return pointer to real instance
InstanceIDRole ///< Return id if the instance
}; };
/*! /*!
* \brief Error codes returned by functions in the InstanceList class. * \brief Error codes returned by functions in the InstanceList class.

View File

@ -25,6 +25,7 @@ InstanceProxyModel::InstanceProxyModel(QObject* parent) : QSortFilterProxyModel(
m_naturalSort.setCaseSensitivity(Qt::CaseSensitivity::CaseInsensitive); m_naturalSort.setCaseSensitivity(Qt::CaseSensitivity::CaseInsensitive);
// FIXME: use loaded translation as source of locale instead, hook this up to translation changes // FIXME: use loaded translation as source of locale instead, hook this up to translation changes
m_naturalSort.setLocale(QLocale::system()); m_naturalSort.setLocale(QLocale::system());
setSortRole(InstanceList::SortRole);
} }
QVariant InstanceProxyModel::data(const QModelIndex& index, int role) const QVariant InstanceProxyModel::data(const QModelIndex& index, int role) const