-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCountryModel.cpp
45 lines (36 loc) · 1.02 KB
/
CountryModel.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
41
42
43
44
45
#include "CountryModel.h"
#include <QIcon>
CountryModel::CountryModel(QObject* parent) :
QAbstractListModel(parent),
countries()
{
countries
<< new Country("France", "Paris", ":/flags/fr.png")
<< new Country("Great Britain", "London", ":/flags/gb.png")
<< new Country("Japan", "Tokyo", ":/flags/jp.png")
<< new Country("United States of America", "Washington, D.C", ":/flags/us.png");
}
CountryModel::~CountryModel()
{
qDeleteAll(countries);
}
int CountryModel::rowCount(const QModelIndex& parent) const
{
Q_UNUSED(parent)
return countries.size();
}
QVariant CountryModel::data(const QModelIndex& index, int role) const
{
const Country& country = *countries.at(index.row());
switch (role) {
case Qt::DisplayRole:
return country.name;
case Qt::DecorationRole:
return QIcon(country.flagIcon);
case CountryRoles::CapitalRole:
return country.capital;
default:
return QVariant();
break;
}
}