diff src/gui/pages/anime_list.cpp @ 47:d8eb763e6661

information.cpp: add widgets to the list tab, and add an "optional date" widget like taiga has so users can specify whether to set the date or not
author Paper <mrpapersonic@gmail.com>
date Mon, 25 Sep 2023 00:43:38 -0400
parents d0adc4aedfc8
children 75c804f713b2
line wrap: on
line diff
--- a/src/gui/pages/anime_list.cpp	Sat Sep 23 01:02:15 2023 -0400
+++ b/src/gui/pages/anime_list.cpp	Mon Sep 25 00:43:38 2023 -0400
@@ -11,9 +11,9 @@
 #include "gui/pages/anime_list.h"
 #include "core/anime.h"
 #include "core/anime_db.h"
+#include "core/array.h"
 #include "core/session.h"
 #include "core/time.h"
-#include "core/array.h"
 #include "gui/dialog/information.h"
 #include "gui/translate/anime.h"
 #include "services/anilist.h"
@@ -99,33 +99,33 @@
 QVariant AnimeListWidgetModel::headerData(const int section, const Qt::Orientation orientation, const int role) const {
 	if (role == Qt::DisplayRole) {
 		switch (section) {
-			   case AL_TITLE: return tr("Anime title");
-			   case AL_PROGRESS: return tr("Progress");
-			   case AL_EPISODES: return tr("Episodes");
-			   case AL_TYPE: return tr("Type");
-			   case AL_SCORE: return tr("Score");
-			   case AL_SEASON: return tr("Season");
-			   case AL_STARTED: return tr("Date started");
-			   case AL_COMPLETED: return tr("Date completed");
-			   case AL_NOTES: return tr("Notes");
-			   case AL_AVG_SCORE: return tr("Average score");
-			   case AL_UPDATED: return tr("Last updated");
-			   default: return {};
+			case AL_TITLE: return tr("Anime title");
+			case AL_PROGRESS: return tr("Progress");
+			case AL_EPISODES: return tr("Episodes");
+			case AL_TYPE: return tr("Type");
+			case AL_SCORE: return tr("Score");
+			case AL_SEASON: return tr("Season");
+			case AL_STARTED: return tr("Date started");
+			case AL_COMPLETED: return tr("Date completed");
+			case AL_NOTES: return tr("Notes");
+			case AL_AVG_SCORE: return tr("Average score");
+			case AL_UPDATED: return tr("Last updated");
+			default: return {};
 		}
 	} else if (role == Qt::TextAlignmentRole) {
 		switch (section) {
-			   case AL_TITLE:
-			   case AL_NOTES: return QVariant(Qt::AlignLeft | Qt::AlignVCenter);
-			   case AL_PROGRESS:
-			   case AL_EPISODES:
-			   case AL_TYPE:
-			   case AL_SCORE:
-			   case AL_AVG_SCORE: return QVariant(Qt::AlignCenter | Qt::AlignVCenter);
-			   case AL_SEASON:
-			   case AL_STARTED:
-			   case AL_COMPLETED:
-			   case AL_UPDATED: return QVariant(Qt::AlignRight | Qt::AlignVCenter);
-			   default: return QAbstractListModel::headerData(section, orientation, role);
+			case AL_TITLE:
+			case AL_NOTES: return QVariant(Qt::AlignLeft | Qt::AlignVCenter);
+			case AL_PROGRESS:
+			case AL_EPISODES:
+			case AL_TYPE:
+			case AL_SCORE:
+			case AL_AVG_SCORE: return QVariant(Qt::AlignCenter | Qt::AlignVCenter);
+			case AL_SEASON:
+			case AL_STARTED:
+			case AL_COMPLETED:
+			case AL_UPDATED: return QVariant(Qt::AlignRight | Qt::AlignVCenter);
+			default: return QAbstractListModel::headerData(section, orientation, role);
 		}
 	}
 	return QAbstractListModel::headerData(section, orientation, role);
@@ -136,56 +136,56 @@
 		return QVariant();
 	switch (role) {
 		case Qt::DisplayRole:
-			   switch (index.column()) {
-				   case AL_TITLE: return QString::fromUtf8(list[index.row()].GetUserPreferredTitle().c_str());
-				   case AL_PROGRESS:
-					   return QString::number(list[index.row()].GetUserProgress()) + "/" +
-					          QString::number(list[index.row()].GetEpisodes());
-				   case AL_EPISODES: return list[index.row()].GetEpisodes();
-				   case AL_SCORE: return list[index.row()].GetUserScore();
-				   case AL_TYPE: return QString::fromStdString(Translate::ToString(list[index.row()].GetFormat()));
-				   case AL_SEASON:
-					   return QString::fromStdString(Translate::ToString(list[index.row()].GetSeason())) + " " +
-					          QString::number(list[index.row()].GetAirDate().GetYear());
-				   case AL_AVG_SCORE: return QString::number(list[index.row()].GetAudienceScore()) + "%";
-				   case AL_STARTED: return list[index.row()].GetUserDateStarted().GetAsQDate();
-				   case AL_COMPLETED: return list[index.row()].GetUserDateCompleted().GetAsQDate();
-				   case AL_UPDATED: {
-					   if (list[index.row()].GetUserTimeUpdated() == 0)
-						   return QString("-");
-					   Time::Duration duration(Time::GetSystemTime() - list[index.row()].GetUserTimeUpdated());
-					   return QString::fromUtf8(duration.AsRelativeString().c_str());
-				   }
-				   case AL_NOTES: return QString::fromUtf8(list[index.row()].GetUserNotes().c_str());
-				   default: return "";
-			   }
-			   break;
+			switch (index.column()) {
+				case AL_TITLE: return QString::fromUtf8(list[index.row()].GetUserPreferredTitle().c_str());
+				case AL_PROGRESS:
+					return QString::number(list[index.row()].GetUserProgress()) + "/" +
+					       QString::number(list[index.row()].GetEpisodes());
+				case AL_EPISODES: return list[index.row()].GetEpisodes();
+				case AL_SCORE: return list[index.row()].GetUserScore();
+				case AL_TYPE: return QString::fromStdString(Translate::ToString(list[index.row()].GetFormat()));
+				case AL_SEASON:
+					return QString::fromStdString(Translate::ToString(list[index.row()].GetSeason())) + " " +
+					       QString::number(list[index.row()].GetAirDate().GetYear());
+				case AL_AVG_SCORE: return QString::number(list[index.row()].GetAudienceScore()) + "%";
+				case AL_STARTED: return list[index.row()].GetUserDateStarted().GetAsQDate();
+				case AL_COMPLETED: return list[index.row()].GetUserDateCompleted().GetAsQDate();
+				case AL_UPDATED: {
+					if (list[index.row()].GetUserTimeUpdated() == 0)
+						return QString("-");
+					Time::Duration duration(Time::GetSystemTime() - list[index.row()].GetUserTimeUpdated());
+					return QString::fromUtf8(duration.AsRelativeString().c_str());
+				}
+				case AL_NOTES: return QString::fromUtf8(list[index.row()].GetUserNotes().c_str());
+				default: return "";
+			}
+			break;
 		case Qt::UserRole:
-			   switch (index.column()) {
-				   case AL_PROGRESS: return list[index.row()].GetUserProgress();
-				   case AL_TYPE: return static_cast<int>(list[index.row()].GetFormat());
-				   case AL_SEASON: return list[index.row()].GetAirDate().GetAsQDate();
-				   case AL_AVG_SCORE: return list[index.row()].GetAudienceScore();
-				   case AL_UPDATED: return QVariant::fromValue(list[index.row()].GetUserTimeUpdated());
-				   default: return data(index, Qt::DisplayRole);
-			   }
-			   break;
+			switch (index.column()) {
+				case AL_PROGRESS: return list[index.row()].GetUserProgress();
+				case AL_TYPE: return static_cast<int>(list[index.row()].GetFormat());
+				case AL_SEASON: return list[index.row()].GetAirDate().GetAsQDate();
+				case AL_AVG_SCORE: return list[index.row()].GetAudienceScore();
+				case AL_UPDATED: return QVariant::fromValue(list[index.row()].GetUserTimeUpdated());
+				default: return data(index, Qt::DisplayRole);
+			}
+			break;
 		case Qt::TextAlignmentRole:
-			   switch (index.column()) {
-				   case AL_TITLE:
-				   case AL_NOTES: return QVariant(Qt::AlignLeft | Qt::AlignVCenter);
-				   case AL_PROGRESS:
-				   case AL_EPISODES:
-				   case AL_TYPE:
-				   case AL_SCORE:
-				   case AL_AVG_SCORE: return QVariant(Qt::AlignCenter | Qt::AlignVCenter);
-				   case AL_SEASON:
-				   case AL_STARTED:
-				   case AL_COMPLETED:
-				   case AL_UPDATED: return QVariant(Qt::AlignRight | Qt::AlignVCenter);
-				   default: break;
-			   }
-			   break;
+			switch (index.column()) {
+				case AL_TITLE:
+				case AL_NOTES: return QVariant(Qt::AlignLeft | Qt::AlignVCenter);
+				case AL_PROGRESS:
+				case AL_EPISODES:
+				case AL_TYPE:
+				case AL_SCORE:
+				case AL_AVG_SCORE: return QVariant(Qt::AlignCenter | Qt::AlignVCenter);
+				case AL_SEASON:
+				case AL_STARTED:
+				case AL_COMPLETED:
+				case AL_UPDATED: return QVariant(Qt::AlignRight | Qt::AlignVCenter);
+				default: break;
+			}
+			break;
 	}
 	return QVariant();
 }
@@ -195,7 +195,7 @@
 	int i = 0;
 	for (const auto& a : Anime::db.items) {
 		if (a.second.IsInUserList() && a.first == id && a.second.GetUserStatus() == status) {
-			   emit dataChanged(index(i), index(i));
+			emit dataChanged(index(i), index(i));
 		}
 		i++;
 	}
@@ -212,8 +212,8 @@
 	else {
 		int count = 0;
 		for (const auto& a : Anime::db.items)
-			   if (a.second.IsInUserList() && a.second.GetUserStatus() == status)
-				   count++;
+			if (a.second.IsInUserList() && a.second.GetUserStatus() == status)
+				count++;
 		beginInsertRows(index(0), 0, count - 1);
 	}
 
@@ -221,7 +221,7 @@
 
 	for (const auto& a : Anime::db.items) {
 		if (a.second.IsInUserList() && a.second.GetUserStatus() == status) {
-			   list.push_back(a.second);
+			list.push_back(a.second);
 		}
 	}
 
@@ -236,7 +236,7 @@
 
 	for (int i = 0, end = tree_view->header()->count(); i < end; i++) {
 		if (!tree_view->isColumnHidden(i))
-			   count++;
+			count++;
 	}
 
 	return count;
@@ -265,7 +265,7 @@
 
 	for (int i = 0; i < AnimeListWidgetModel::NB_COLUMNS; i++) {
 		if (i == AnimeListWidgetModel::AL_TITLE)
-			   continue;
+			continue;
 		const auto column_name =
 		    sort_models[tab_bar->currentIndex()]->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString();
 		QAction* action = menu->addAction(column_name, this, [this, i](const bool checked) {