-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoffermodel.cpp
56 lines (42 loc) · 1.29 KB
/
offermodel.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
46
47
48
49
50
51
52
53
54
55
56
#include "offermodel.h"
OfferModel::OfferModel(Controller* manag, QObject* parent) :
QAbstractListModel(parent), manag(manag)
{
QObject::connect(manag, SIGNAL(itemUpdated(int)), this, SLOT(on_itemUpdated(int)));
}
OfferModel::~OfferModel(){
}
int OfferModel::rowCount(const QModelIndex &parent) const{
return manag->getOffers().size();
}
QVariant OfferModel::data(const QModelIndex &index, int role) const{
if (!index.isValid()){
return QVariant();
}
if (index.row()>manag->getOffers().size()){
return QVariant();
}
if (role == Qt::DisplayRole){
using namespace std;
Offer of = manag->getOffers()[index.row()];
QString text = QString::fromStdString(of.getDest());
text.append(" ");
text.append(QString::fromStdString(of.getType));
stringstream ss;
ss << of.getPrice();
text.append(ss.str().c_str());
return QVariant(text);
}
return QVariant();
}
bool OfferModel::removeRows(int position, int rows, const QModelIndex & parent){
beginRemoveRows(QModelIndex(), position, position + rows - 1);
manag->removeOffer(manag->getOffers()[position].getId());
endRemoveRows();
return true;
}
void OfferModel::on_itemUpdated(int position){
QModelIndex lineLeft = createIndex(position, 0);
QModelIndex lineRight = createIndex(position, 0);
emit dataChanged(lineLeft, lineRight);
}