From 24060291c859453cf8e51dea4e7ae756fa0a7b6f Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Sat, 1 Oct 2022 22:16:07 +0200 Subject: [PATCH] refactor: improve code readability Signed-off-by: Sefa Eyeoglu --- launcher/InstanceList.cpp | 72 ++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/launcher/InstanceList.cpp b/launcher/InstanceList.cpp index 8dcb9dec5..94d1e3e5c 100644 --- a/launcher/InstanceList.cpp +++ b/launcher/InstanceList.cpp @@ -153,44 +153,52 @@ QVariant InstanceList::data(const QModelIndex& index, int role) const { } const InstancePtr inst = m_instances[index.row()]; - switch (static_cast(index.column())) { - case IconColumn: - if (role == Qt::DecorationRole) { + switch (role) { + case Qt::DecorationRole: { + if (index.column() == IconColumn) return inst->iconKey(); + break; + } + + case Qt::DisplayRole: { + switch (index.column()) { + case NameColumn: + return inst->name(); + case GameVersionColumn: + return inst->getMainVersion(); + case PlayTimeColumn: + return Time::prettifyDuration(inst->totalTimePlayed()); + case LastPlayedColumn: + return QDateTime::fromMSecsSinceEpoch(inst->lastLaunch()); } break; - case NameColumn: - if (role == Qt::DisplayRole || role == Qt::EditRole) - return inst->name(); - if (role == Qt::AccessibleTextRole) + } + + case Qt::ToolTipRole: { + switch (index.column()) { + case NameColumn: + return inst->instanceRoot(); + case GameVersionColumn: + return inst->getMainVersion(); + case PlayTimeColumn: + return tr("Total played for %1").arg(Time::prettifyDuration(inst->totalTimePlayed())); + case LastPlayedColumn: + return tr("Last played for %1").arg(Time::prettifyDuration(inst->lastTimePlayed())); + } + break; + } + + case Qt::EditRole: { + if (index.column() == NameColumn) + return data(index, Qt::DisplayRole); + break; + } + + case Qt::AccessibleTextRole: { + if (index.column() == NameColumn) return tr("%1 Instance").arg(inst->name()); - if (role == Qt::ToolTipRole) - return inst->instanceRoot(); - break; - case GameVersionColumn: { - if (role == Qt::DisplayRole) - return inst->getMainVersion(); break; } - case PlayTimeColumn: { - QString foo = Time::prettifyDuration(inst->totalTimePlayed()); - if (role == Qt::DisplayRole) - return foo; - if (role == Qt::ToolTipRole) - return tr("Total played for %1").arg(foo); - break; - } - case LastPlayedColumn: { - QString foo = Time::prettifyDuration(inst->lastTimePlayed()); - QDateTime bar = QDateTime::fromMSecsSinceEpoch(inst->lastLaunch()); - if (role == Qt::DisplayRole) - return bar; - if (role == Qt::ToolTipRole) - return tr("Last played for %1").arg(foo); - break; - } - default: - break; } return QVariant(); }