summaryrefslogtreecommitdiff
path: root/src/location/places/provider/qplacesuppliersrepository.cpp
blob: 768023d46bd54020abc26986fd44ba2f5aeb5323 (plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "qplacesuppliersrepository.h"

#include "../qplacesupplier.h"

using namespace QT_PLACES_NAMESPACE;

QPlaceSuppliersRepository *QPlaceSuppliersRepository::instance()
{
    static QPlaceSuppliersRepository instance;
    return &instance;
}

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

QPlaceSuppliersRepository::~QPlaceSuppliersRepository()
{
    suppliers.clear();
}

QPlaceSupplier QPlaceSuppliersRepository::addSupplier(const QPlaceSupplier &src)
{
    QPlaceSupplier res;
    QPlaceSupplier tmp;

    foreach (tmp, suppliers) {
        if ((!src.supplierId().isEmpty() && src.supplierId() == tmp.supplierId())
                || (!src.name().isEmpty() && src.name() == tmp.name())) {
            copyMissingData(src, tmp);
            res = tmp;
            break;
        }
    }
    if (res.supplierId().isEmpty() && res.name().isEmpty()) {
        res = src;
        suppliers.append(res);
    }
    return res;
}

void QPlaceSuppliersRepository::copyMissingData(const QPlaceSupplier &src,
                                                QPlaceSupplier &target)
{
    if (target.name().isEmpty() && !src.name().isEmpty()) {
        target.setName(src.name());
    }
    if (target.supplierId().isEmpty() && !src.supplierId().isEmpty()) {
        target.setSupplierId(src.supplierId());
    }
    if (target.URL().isEmpty() && !src.URL().isEmpty()) {
        target.setURL(src.URL());
    }
    if (target.supplierIconURL().isEmpty() && !src.supplierIconURL().isEmpty()) {
        target.setSupplierIconURL(src.supplierIconURL());
    }
}