You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

101 lines
3.0 KiB

  1. #include "episodes.h"
  2. #include "ui_episodes.h"
  3. episodes::episodes(CrunchyrollAPI* _api,QVector<meta_episode_t> _allEpisodes,
  4. QVector<meta_episode_t> currentEpisodes,QWidget *parent) :
  5. QDialog(parent),
  6. ui(new Ui::episodes)
  7. {
  8. ui->setupUi(this);
  9. api = _api;
  10. allEpisodes = _allEpisodes;
  11. for(auto e:allEpisodes){
  12. ui->e_table->insertRow(ui->e_table->rowCount());
  13. collection_t c = e.collection;
  14. for(int i = 0; i < 7;i++){
  15. QTableWidgetItem* item = new QTableWidgetItem();
  16. switch (i) {
  17. case 0:
  18. item->setText(c.name);
  19. break;
  20. case 1:
  21. item->setText("Season " + c.season);
  22. break;
  23. case 2:
  24. item->setText("E"+QString::number(e.number));
  25. break;
  26. case 3:
  27. item->setText(e.name);
  28. break;
  29. case 4:
  30. item->setText(e.free_available ? "true" : "false");
  31. break;
  32. case 5:
  33. item->setText(e.available ? "true" : "false");
  34. break;
  35. case 6:
  36. item->setText(e.media_id);
  37. break;
  38. }
  39. ui->e_table->setItem(ui->e_table->rowCount()-1,i,item);
  40. }
  41. }
  42. QVector<int> rows;
  43. for(auto cur:currentEpisodes){
  44. for(int i = 0; i < ui->e_table->rowCount(); i++){
  45. if(ui->e_table->item(i,6)->text()==cur.media_id){
  46. for (int j = 0; j < 7; j++) {
  47. ui->e_table->selectionModel()->select(
  48. ui->e_table->model()->index(i,j),
  49. QItemSelectionModel::SelectionFlag::Select);
  50. }
  51. break;
  52. }
  53. }
  54. }
  55. ui->e_table->setFocus();
  56. ui->e_table->horizontalHeader()->resizeSection(0,200);
  57. ui->e_table->horizontalHeader()->resizeSection(1,75);
  58. ui->e_table->horizontalHeader()->resizeSection(2,50);
  59. ui->e_table->horizontalHeader()->resizeSection(3,200);
  60. ui->e_table->horizontalHeader()->resizeSection(4,50);
  61. ui->e_table->horizontalHeader()->resizeSection(5,65);
  62. ui->e_table->horizontalHeader()->resizeSection(6,0);
  63. connect(ui->e_table,SIGNAL(itemSelectionChanged()),this,SLOT(selected()));
  64. }
  65. episodes::~episodes()
  66. {
  67. delete ui;
  68. }
  69. QVector<meta_episode_t> episodes::getSelectedEpisodes(){
  70. return selection;
  71. }
  72. void episodes::selected(){
  73. QVector<int> rows;
  74. auto selectedItems = ui->e_table->selectedItems();
  75. for(auto item:selectedItems){
  76. if(!rows.contains(item->row()))
  77. rows.append(item->row());
  78. }
  79. QVector<meta_episode_t> sel;
  80. for(int row:rows){
  81. QString id = ui->e_table->item(row,6)->text();
  82. //Find episode by media id
  83. for(auto ae:allEpisodes){
  84. if(ae.media_id==id){
  85. sel.push_back(ae);
  86. break;
  87. }
  88. }
  89. }
  90. selection = sel;
  91. }