comparison src/anime.cpp @ 3:190ded9438c0

Fix many warnings
author Paper <mrpapersonic@gmail.com>
date Sat, 12 Aug 2023 11:57:25 -0400
parents 23d0d9319a00
children 1d82f6e04d7d
comparison
equal deleted inserted replaced
2:23d0d9319a00 3:190ded9438c0
116 return anime_list.cend(); 116 return anime_list.cend();
117 } 117 }
118 118
119 AnimeList::AnimeList() {} 119 AnimeList::AnimeList() {}
120 AnimeList::AnimeList(const AnimeList& l) { 120 AnimeList::AnimeList(const AnimeList& l) {
121 for (int i = 0; i < l.Size(); i++) { 121 for (unsigned long long i = 0; i < l.Size(); i++) {
122 anime_list.push_back(Anime(l[i])); 122 anime_list.push_back(Anime(l[i]));
123 } 123 }
124 name = l.name; 124 name = l.name;
125 } 125 }
126 126
136 bool AnimeList::AnimeInList(int id) { 136 bool AnimeList::AnimeInList(int id) {
137 return anime_id_to_anime.contains(id); 137 return anime_id_to_anime.contains(id);
138 } 138 }
139 139
140 int AnimeList::GetAnimeIndex(Anime& anime) const { 140 int AnimeList::GetAnimeIndex(Anime& anime) const {
141 for (int i = 0; i < Size(); i++) { 141 for (unsigned long long i = 0; i < Size(); i++) {
142 if (&anime_list.at(i) == &anime) { // lazy 142 if (&anime_list.at(i) == &anime) { // lazy
143 return i; 143 return i;
144 } 144 }
145 } 145 }
146 return -1; 146 return -1;
164 return; 164 return;
165 } 165 }
166 166
167 int AnimeListWidgetModel::rowCount(const QModelIndex& parent) const { 167 int AnimeListWidgetModel::rowCount(const QModelIndex& parent) const {
168 return list.Size(); 168 return list.Size();
169 (void)(parent);
169 } 170 }
170 171
171 int AnimeListWidgetModel::columnCount(const QModelIndex& parent) const { 172 int AnimeListWidgetModel::columnCount(const QModelIndex& parent) const {
172 return NB_COLUMNS; 173 return NB_COLUMNS;
174 (void)(parent);
173 } 175 }
174 176
175 QVariant AnimeListWidgetModel::headerData(const int section, const Qt::Orientation orientation, const int role) const { 177 QVariant AnimeListWidgetModel::headerData(const int section, const Qt::Orientation orientation, const int role) const {
176 if (role == Qt::DisplayRole) { 178 if (role == Qt::DisplayRole) {
177 switch (section) { 179 switch (section) {
334 QMenu *menu = new QMenu(this); 336 QMenu *menu = new QMenu(this);
335 menu->setAttribute(Qt::WA_DeleteOnClose); 337 menu->setAttribute(Qt::WA_DeleteOnClose);
336 menu->setTitle(tr("Column visibility")); 338 menu->setTitle(tr("Column visibility"));
337 menu->setToolTipsVisible(true); 339 menu->setToolTipsVisible(true);
338 340
339 for (int i = 0; i < AnimeListWidgetModel::NB_COLUMNS; i++) 341 for (int i = 0; i < AnimeListWidgetModel::NB_COLUMNS; i++) {
340 {
341 if (i == AnimeListWidgetModel::AL_TITLE) 342 if (i == AnimeListWidgetModel::AL_TITLE)
342 continue; 343 continue;
343 const auto column_name = model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString(); 344 const auto column_name = model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString();
344 QAction *action = menu->addAction(column_name, this, [this, i](const bool checked) { 345 QAction *action = menu->addAction(column_name, this, [this, i](const bool checked) {
345 if (!checked && (VisibleColumnsCount() <= 1)) 346 if (!checked && (VisibleColumnsCount() <= 1))
355 action->setCheckable(true); 356 action->setCheckable(true);
356 action->setChecked(!isColumnHidden(i)); 357 action->setChecked(!isColumnHidden(i));
357 } 358 }
358 359
359 menu->addSeparator(); 360 menu->addSeparator();
360 QAction *resetAction = menu->addAction(tr("Reset to defaults"), this, [this]() 361 QAction *resetAction = menu->addAction(tr("Reset to defaults"), this, [this]() {
361 {
362 for (int i = 0, count = header()->count(); i < count; ++i) 362 for (int i = 0, count = header()->count(); i < count; ++i)
363 { 363 {
364 SetColumnDefaults(); 364 SetColumnDefaults();
365 } 365 }
366 // SaveSettings(); 366 // SaveSettings();
367 }); 367 });
368
369 menu->popup(QCursor::pos()); 368 menu->popup(QCursor::pos());
369 (void)(resetAction);
370 } 370 }
371 371
372 void AnimeListWidget::DisplayListMenu() { 372 void AnimeListWidget::DisplayListMenu() {
373 /* throw out any other garbage */ 373 /* throw out any other garbage */
374 const QModelIndexList selected_items = selectionModel()->selectedRows(); 374 const QModelIndexList selected_items = selectionModel()->selectedRows();
375 if (selected_items.size() != 1 || !selected_items.first().isValid()) 375 if (selected_items.size() != 1 || !selected_items.first().isValid()) {
376 return; 376 return;
377 }
377 378
378 const QModelIndex index = model->index(selected_items.first().row()); 379 const QModelIndex index = model->index(selected_items.first().row());
379 Anime* anime = model->GetAnimeFromIndex(index); 380 Anime* anime = model->GetAnimeFromIndex(index);
380 if (!anime) 381 if (!anime) {
381 return; 382 return;
383 }
382 384
383 } 385 }
384 386
385 void AnimeListWidget::ItemDoubleClicked() { 387 void AnimeListWidget::ItemDoubleClicked() {
386 /* throw out any other garbage */ 388 /* throw out any other garbage */
387 const QModelIndexList selected_items = selectionModel()->selectedRows(); 389 const QModelIndexList selected_items = selectionModel()->selectedRows();
388 if (selected_items.size() != 1 || !selected_items.first().isValid()) 390 if (selected_items.size() != 1 || !selected_items.first().isValid()) {
389 return; 391 return;
392 }
390 393
391 /* TODO: after we implement our sort model, we have to use mapToSource here... */ 394 /* TODO: after we implement our sort model, we have to use mapToSource here... */
392 const QModelIndex index = model->index(selected_items.first().row()); 395 const QModelIndex index = model->index(selected_items.first().row());
393 Anime* anime = model->GetAnimeFromIndex(index); 396 Anime* anime = model->GetAnimeFromIndex(index);
394 if (!anime) 397 if (!anime) {
395 return; 398 return;
399 }
396 400
397 InformationDialog* dialog = new InformationDialog(*anime, model, this); 401 InformationDialog* dialog = new InformationDialog(*anime, model, this);
398 402
399 dialog->show(); 403 dialog->show();
400 dialog->raise(); 404 dialog->raise();
412 setSortingEnabled(true); 416 setSortingEnabled(true);
413 setSelectionMode(QAbstractItemView::ExtendedSelection); 417 setSelectionMode(QAbstractItemView::ExtendedSelection);
414 setItemsExpandable(false); 418 setItemsExpandable(false);
415 setRootIsDecorated(false); 419 setRootIsDecorated(false);
416 setContextMenuPolicy(Qt::CustomContextMenu); 420 setContextMenuPolicy(Qt::CustomContextMenu);
417 connect(this, &QAbstractItemView::doubleClicked, this, &ItemDoubleClicked); 421 connect(this, &QAbstractItemView::doubleClicked, this, &AnimeListWidget::ItemDoubleClicked);
418 connect(this, &QWidget::customContextMenuRequested, this, &DisplayListMenu); 422 connect(this, &QWidget::customContextMenuRequested, this, &AnimeListWidget::DisplayListMenu);
419 423
420 /* Enter & return keys */ 424 /* Enter & return keys */
421 connect(new QShortcut(Qt::Key_Return, this, nullptr, nullptr, Qt::WidgetShortcut), 425 connect(new QShortcut(Qt::Key_Return, this, nullptr, nullptr, Qt::WidgetShortcut),
422 &QShortcut::activated, this, &ItemDoubleClicked); 426 &QShortcut::activated, this, &AnimeListWidget::ItemDoubleClicked);
423 427
424 connect(new QShortcut(Qt::Key_Enter, this, nullptr, nullptr, Qt::WidgetShortcut), 428 connect(new QShortcut(Qt::Key_Enter, this, nullptr, nullptr, Qt::WidgetShortcut),
425 &QShortcut::activated, this, &ItemDoubleClicked); 429 &QShortcut::activated, this, &AnimeListWidget::ItemDoubleClicked);
426 430
427 header()->setStretchLastSection(false); 431 header()->setStretchLastSection(false);
428 header()->setContextMenuPolicy(Qt::CustomContextMenu); 432 header()->setContextMenuPolicy(Qt::CustomContextMenu);
429 connect(header(), &QWidget::customContextMenuRequested, this, &DisplayColumnHeaderMenu); 433 connect(header(), &QWidget::customContextMenuRequested, this, &AnimeListWidget::DisplayColumnHeaderMenu);
430 // if(!session.config.anime_list.columns) { 434 // if(!session.config.anime_list.columns) {
431 SetColumnDefaults(); 435 SetColumnDefaults();
432 // } 436 // }
433 } 437 }
434 438
448 session.config.anilist.user_id = anilist.GetUserId(session.config.anilist.username); 452 session.config.anilist.user_id = anilist.GetUserId(session.config.anilist.username);
449 FreeAnimeList(); 453 FreeAnimeList();
450 anilist.UpdateAnimeList(&anime_lists, session.config.anilist.user_id); 454 anilist.UpdateAnimeList(&anime_lists, session.config.anilist.user_id);
451 break; 455 break;
452 } 456 }
457 default:
458 break;
453 } 459 }
454 } 460 }
455 461
456 void AnimeListPage::FreeAnimeList() { 462 void AnimeListPage::FreeAnimeList() {
457 if (anime_lists.size() > 0) { 463 if (anime_lists.size() > 0) {