Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 128 lines (116 sloc) 3.715 kB
418ce8a @gnuvince initial commit
authored
1 /*
2 * station.cpp
3 * Copyright (C) 2011 Nicolas Martin, Université de Montréal
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "station.h"
20
21 /**
22 Il faut absolument intialiser les champs
23 statiques de cette maniere ... Sinon on risque
24 de creer un bug lorsque on herite de cette classe
25 et redefinit le champs headers parce qu'il se peut
26 que ce champs ne soit pas encore initialise
27 C'est le construct-on-first-use idiom :
28 http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.8
29 */
30 QStringList& Station::headers() {
31 static QStringList _headers = QStringList()
32 << trUtf8("id") <<
e64a8e4 @gnuvince Selecting a position on the map affects the selection of the station …
authored
33 trUtf8("Station") <<
418ce8a @gnuvince initial commit
authored
34 trUtf8("description") <<
35 trUtf8("coffret") <<
36 trUtf8("position") <<
37 trUtf8("photo") <<
bf29915 @gnuvince added data
authored
38 trUtf8("carte") <<
ba35c54 @gnuvince Added interrogation icon to get station information
authored
39 trUtf8("Distance") <<
40 trUtf8("Information");
418ce8a @gnuvince initial commit
authored
41 return _headers;
42 }
43
44 Station::Station(uint id, QString nom, QString description,QString coffret, GeoPosition position, QPixmap photo, QPixmap carte, QObject *parent) :
45 QObject(parent),
46 id(id), nom(nom), description(description), coffret(coffret), position(position),
47 photo(photo), carte(carte)
48 {
49 }
50
51 QVariant Station::field(uint column, int role) const
52 {
53 switch (role) {
54 case Qt::DisplayRole:
55 case Qt::EditRole:
56 switch (column)
57 {
58 case COL_ID: return id;
59 case COL_NOM: return nom;
60 case COL_DESCR: return description;
61 case COL_COFF: return coffret;
62 case COL_POS: return qVariantFromValue<GeoPosition>(position);
63 default:
64 break;
65 }
66 break;
67 case Qt::DecorationRole:
68 switch (column)
69 {
70 case COL_PHOTO: return photo;
71 case COL_CARTE: return carte;
72 default: break;
73 }
74 break;
75 case Qt::SizeHintRole:
76 switch (column)
77 {
78 case COL_PHOTO: return QSize(150,150);
79 case COL_CARTE: return QSize(150,150);
80 default: break;
81 }
82 break;
83 }
84 return QVariant();
85 }
86
87 /*
88 bool Station::changeField(uint column, QVariant value)
89 {
90 Q_UNUSED(column)
91 Q_UNUSED(value)
92 return false;
93 }
94 */
95
96 uint Station::headerCount()
97 {
98 return headers().count();
99 }
100
101 QVariant Station::header(uint column)
102 {
103 if (column >= uint(headers().count()))
104 return QVariant();
105
106 return headers()[column];
107 }
108
109 //pas accessible pour personne d'autre que les sérialisateurs
110 Station::Station(const Station &s) :
111 QObject(s.parent()),
112 id(s.id), nom(s.nom), description(s.description), coffret(s.coffret), position(s.position), photo(s.photo),
113 carte(s.carte)
114 {
115 }
116
117 QDataStream& operator<<(QDataStream &ds, const Station &station)
118 {
119 ds << station.id << station.nom << station.description << station.coffret << station.position << station.photo << station.carte;
120 return ds;
121 }
122
123 QDataStream& operator>>(QDataStream &ds, Station &station)
124 {
125 ds >> station.id >> station.nom >> station.description >> station.coffret >> station.position >> station.photo >> station.carte;
126 return ds;
127 }
Something went wrong with that request. Please try again.