summaryrefslogtreecommitdiff
path: root/src/stamps/StampsModel.cpp
blob: f76d4f1f24473ecbffc25a1b6b2d6f2ef92e6858 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
 * StampsModel.cpp
 *
 *  Created on: Mar 29, 2012
 *      Author: Simon
 */

#include "StampsModel.h"
#include "StampsView.h"
#include "client/Client.h"
#include "StampsModelException.h"

StampsModel::StampsModel():
	stamp(NULL)
{
	// TODO Auto-generated constructor stub
	stampIDs = Client::Ref().GetStamps();
}


std::vector<Save *> StampsModel::GetStampsList()
{
	return stampsList;
}

void StampsModel::AddObserver(StampsView * observer)
{
	observers.push_back(observer);
	observer->NotifyStampsListChanged(this);
}

void StampsModel::notifyStampsListChanged()
{
	for(int i = 0; i < observers.size(); i++)
	{
		observers[i]->NotifyStampsListChanged(this);
	}
}

void StampsModel::notifyPageChanged()
{
	for(int i = 0; i < observers.size(); i++)
	{
		observers[i]->NotifyPageChanged(this);
	}
}

Save * StampsModel::GetStamp()
{
	return stamp;
}

void StampsModel::SetStamp(Save * newStamp)
{
	if(stamp)
		delete stamp;
	stamp = new Save(*newStamp);
}

void StampsModel::UpdateStampsList(int pageNumber)
{
	std::vector<Save*> tempStampsList = stampsList;
	stampsList.clear();
	/*notifyStampsListChanged();
	for(int i = 0; i < tempStampsList.size(); i++)
	{
		delete tempStampsList[i];
	}*/

	int stampsEnd = pageNumber*20;

	for(int i = stampsEnd-20; i<stampIDs.size() && i<stampsEnd; i++)
	{
		Save * tempSave = Client::Ref().GetStamp(stampIDs[i]);
		stampsList.push_back(tempSave);
	}
	notifyStampsListChanged();
}

StampsModel::~StampsModel() {
	if(stamp)
		delete stamp;
}