efa87751a2742db0b2c564520f7f1b0853727644
[movie-schedule] / itemmodelsortclient.cpp
1 // Copyright 2010 Jochen Becher
2 //
3 // This file is part of MovieSchedule.
4 //
5 // MovieSchedule 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 // MovieSchedule 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 MovieSchedule.  If not, see <http://www.gnu.org/licenses/>.
17
18 #include "itemmodelsortclient.h"
19
20 #include "itemmodelsortproxy.h"
21 #include "itemmodelsortcontroller.h"
22
23 #include <iostream>
24
25 ItemModelSortClient::ItemModelSortClient(ItemModelSortController *controller, QObject *parent)
26     : QObject(parent),
27     _proxy(new ItemModelSortProxy(controller)),
28     _model(0),
29     _task_id(0),
30     _intermediate(false)
31 {
32     connect(this, SIGNAL(Sort(QAbstractItemModel*)), _proxy, SLOT(Sort(QAbstractItemModel*)));
33     connect(_proxy, SIGNAL(SortFinished(QAbstractItemModel*)), this, SLOT(SortFinished(QAbstractItemModel*)));
34     _proxy->moveToThread(controller->thread());
35 }
36
37 void ItemModelSortClient::Sort(QAbstractItemModel *model, int task_id, bool intermediate)
38 {
39     _model = model;
40     _task_id = task_id;
41     _intermediate = intermediate;
42     //std::cout << "Start sorting model " << model << " with intermediate = " << intermediate << std::endl;
43     emit Sort(model);
44 }
45
46 void ItemModelSortClient::SortFinished(QAbstractItemModel *model)
47 {
48     //std::cout << "Finished sorting model " << model << " with intermediate = " << _intermediate << std::endl;
49     emit SortFinished(model, _task_id, _intermediate);
50     deleteLater();
51 }