root/src/franchise.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "franchise.h"
#include "utils.h"
#include <QDebug>

Franchise::Franchise(QObject *parent) :
    QObject(parent)
{
}

bool Franchise::hasRelationTo(const TvShow *show) const {
    foreach (const TvShow* s, tvShows) {
        if (s == show || s->hasRelationTo(show)) {
            return true;
        }
    }
    return false;
}

void Franchise::addTvShow(const TvShow* show) {
    if (tvShows.contains(show)) {
        return;
    }
    tvShows.push_back(show);
}

void Franchise::generateName() {
    if (tvShows.length() == 1) {
        this->name = tvShows.front()->name();
        emit nameGenerated();
        return;
    }

    QStringList titles;
    foreach(const TvShow* show, tvShows) {
        titles << show->name();
    }

    this->name = Utils::commonSliceInStrings(titles);
    emit nameGenerated();
}