summaryrefslogtreecommitdiff
path: root/src/search/SearchModel.h
blob: 0ed7d86f83ecd841950af610ecbe8d5d247334ee (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
#ifndef SEARCHMODEL_H
#define SEARCHMODEL_H

#include <vector>
#include <string>
#include <math.h>
#include "Save.h"
#include "SearchView.h"

using namespace std;

class SearchView;
class SearchModel
{
private:
	string currentSort;
	string lastQuery;
	string lastError;
	vector<SearchView*> observers;
	vector<Save*> saveList;
	int currentPage;
	int resultCount;
	bool showOwn;
	void notifySaveListChanged();
	void notifyPageChanged();
	void notifySortChanged();
	void notifyShowOwnChanged();
public:
    SearchModel();
	void AddObserver(SearchView * observer);
	void UpdateSaveList(int pageNumber, std::string query);
	vector<Save*> GetSaveList();
	string GetLastError() { return lastError; }
	int GetPageCount() { return max(1, (int)(ceil(resultCount/16))); }
	int GetPageNum() { return currentPage; }
	std::string GetLastQuery() { return lastQuery; }
	void SetSort(string sort) { currentSort = sort; UpdateSaveList(1, lastQuery); notifySortChanged(); }
	string GetSort() { return currentSort; }
	void SetShowOwn(bool show) { showOwn = show; UpdateSaveList(1, lastQuery); notifyShowOwnChanged(); }
	bool GetShowOwn() { return showOwn; }
};

#endif // SEARCHMODEL_H