1 | #include "mainwindow.h" |
---|
2 | |
---|
3 | #include <QTreeView> |
---|
4 | #include <QDirModel> |
---|
5 | |
---|
6 | #include <sqlengine.h> |
---|
7 | #include <schedulexmlparser.h> |
---|
8 | |
---|
9 | #include <eventmodel.h> |
---|
10 | #include <delegate.h> |
---|
11 | |
---|
12 | #include <conference.h> |
---|
13 | |
---|
14 | #include <QDialog> |
---|
15 | #include "ui_about.h" |
---|
16 | #include "eventdialog.h" |
---|
17 | #include "daynavigatorwidget.h" |
---|
18 | |
---|
19 | MainWindow::MainWindow(QWidget *parent) |
---|
20 | : QMainWindow(parent) |
---|
21 | { |
---|
22 | setupUi(this); |
---|
23 | |
---|
24 | // connect Menu actions |
---|
25 | connect(actionImportSchedule, SIGNAL(triggered()), SLOT(importSchedule())); |
---|
26 | connect(actionAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt())); |
---|
27 | connect(actionAboutApplication, SIGNAL(triggered()), SLOT(aboutApp())); |
---|
28 | |
---|
29 | // create "SQLITE" DB instance/connection |
---|
30 | // opens DB connection (needed for EventModel) |
---|
31 | mSqlEngine = new SqlEngine(this); |
---|
32 | mSqlEngine->initialize(); |
---|
33 | |
---|
34 | mXmlParser = new ScheduleXmlParser(this); |
---|
35 | connect(mXmlParser, SIGNAL(progressStatus(int)), this, SLOT(showParsingProgress(int))); |
---|
36 | statusBar()->showMessage(tr("Ready")); |
---|
37 | |
---|
38 | connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateDayView(const QDate &))); |
---|
39 | connect(activityDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateActivitiesDayView(const QDate &))); |
---|
40 | //connect(tabWidget, SIGNAL(currentChanged(int)), SLOT(updateView(int))); |
---|
41 | |
---|
42 | // DAY EVENTS View |
---|
43 | dayTreeView->setHeaderHidden(true); |
---|
44 | dayTreeView->setRootIsDecorated(false); |
---|
45 | dayTreeView->setIndentation(0); |
---|
46 | dayTreeView->setAnimated(true); |
---|
47 | dayTreeView->setModel(new EventModel()); |
---|
48 | dayTreeView->setItemDelegate(new Delegate(dayTreeView)); |
---|
49 | |
---|
50 | // FAVOURITIES View |
---|
51 | favTreeView->setHeaderHidden(true); |
---|
52 | favTreeView->setRootIsDecorated(false); |
---|
53 | favTreeView->setIndentation(0); |
---|
54 | favTreeView->setAnimated(true); |
---|
55 | favTreeView->setModel(new EventModel()); |
---|
56 | favTreeView->setItemDelegate(new Delegate(favTreeView)); |
---|
57 | |
---|
58 | //ACTIVITIES View |
---|
59 | actTreeView->setHeaderHidden(true); |
---|
60 | actTreeView->setRootIsDecorated(false); |
---|
61 | actTreeView->setIndentation(0); |
---|
62 | actTreeView->setAnimated(true); |
---|
63 | actTreeView->setModel(new EventModel()); |
---|
64 | actTreeView->setItemDelegate(new Delegate(actTreeView)); |
---|
65 | |
---|
66 | connect(dayTreeView, SIGNAL(doubleClicked(const QModelIndex &)), SLOT(itemDoubleClicked(const QModelIndex &))); |
---|
67 | connect(favTreeView, SIGNAL(doubleClicked(const QModelIndex &)), SLOT(itemDoubleClicked(const QModelIndex &))); |
---|
68 | connect(actTreeView, SIGNAL(doubleClicked(const QModelIndex &)), SLOT(itemDoubleClicked(const QModelIndex &))); |
---|
69 | |
---|
70 | // TESTING: load some 'fav' data |
---|
71 | if(Conference::getAll().count()) // no conference(s) in the DB |
---|
72 | { |
---|
73 | int confId = 1; |
---|
74 | static_cast<EventModel*>(favTreeView->model())->loadFavEvents(Conference::getById(confId).start(),confId); |
---|
75 | favTreeView->reset(); |
---|
76 | } |
---|
77 | |
---|
78 | if(!Conference::getAll().count()) // no conference(s) in the DB |
---|
79 | { |
---|
80 | dayNavigator->hide(); // hide DayNavigatorWidget |
---|
81 | activityDayNavigator->hide(); |
---|
82 | } |
---|
83 | else |
---|
84 | { |
---|
85 | int confId = 1; |
---|
86 | QDate aStartDate = Conference::getById(confId).start(); |
---|
87 | QDate aEndDate = Conference::getById(confId).end(); |
---|
88 | dayNavigator->setDates(aStartDate, aEndDate); |
---|
89 | activityDayNavigator->setDates(aStartDate, aEndDate); |
---|
90 | } |
---|
91 | connect(static_cast<EventModel*>(dayTreeView->model()), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), SLOT(updateFavView())); |
---|
92 | connect(static_cast<EventModel*>(favTreeView->model()), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), SLOT(updateFavView())); |
---|
93 | /* connect(static_cast<EventModel*>(favTreeView->model()), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), SLOT(updateFavViewComplete()));*/ |
---|
94 | } |
---|
95 | |
---|
96 | MainWindow::~MainWindow() |
---|
97 | { |
---|
98 | if(mSqlEngine) |
---|
99 | { |
---|
100 | delete mSqlEngine; |
---|
101 | mSqlEngine = NULL; |
---|
102 | } |
---|
103 | if(mXmlParser) |
---|
104 | { |
---|
105 | delete mXmlParser; |
---|
106 | mXmlParser = NULL; |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | void MainWindow::importSchedule() |
---|
111 | { |
---|
112 | QFile file("../schedule.en.xml"); |
---|
113 | if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) |
---|
114 | { |
---|
115 | QString currPath = QDir::currentPath(); |
---|
116 | qDebug() << "current path: " << currPath; |
---|
117 | qDebug() << "can't open " << file.fileName(); |
---|
118 | return; |
---|
119 | } |
---|
120 | |
---|
121 | QByteArray data = file.readAll(); |
---|
122 | mXmlParser->parseData(data,mSqlEngine); |
---|
123 | |
---|
124 | if(Conference::getAll().count()) |
---|
125 | { |
---|
126 | int confId = 1; |
---|
127 | // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates |
---|
128 | QDate aStartDate = Conference::getById(confId).start(); |
---|
129 | QDate aEndDate = Conference::getById(confId).end(); |
---|
130 | dayNavigator->setDates(aStartDate, aEndDate); |
---|
131 | activityDayNavigator->setDates(aStartDate, aEndDate); |
---|
132 | } |
---|
133 | } |
---|
134 | |
---|
135 | void MainWindow::showParsingProgress(int aStatus) |
---|
136 | { |
---|
137 | QString msg = QString("Parsing completed: %1\%").arg(aStatus); |
---|
138 | statusBar()->showMessage(msg,1000); |
---|
139 | } |
---|
140 | |
---|
141 | void MainWindow::aboutApp() |
---|
142 | { |
---|
143 | QDialog dialog(this); |
---|
144 | Ui::AboutDialog ui; |
---|
145 | ui.setupUi(&dialog); |
---|
146 | dialog.exec(); |
---|
147 | } |
---|
148 | |
---|
149 | void MainWindow::updateDayView(const QDate &aDate) |
---|
150 | { |
---|
151 | int confId = 1; |
---|
152 | static_cast<EventModel*>(dayTreeView->model())->loadEvents(aDate,confId); |
---|
153 | dayTreeView->reset(); |
---|
154 | dayNavigator->show(); |
---|
155 | } |
---|
156 | |
---|
157 | void MainWindow::updateFavView() |
---|
158 | { |
---|
159 | int confId = 1; |
---|
160 | static_cast<EventModel*>(favTreeView->model())->loadFavEvents(Conference::getById(confId).start(),confId); |
---|
161 | favTreeView->reset(); //Necessary reset: |
---|
162 | // if favourite event unselected as favourite is the only one in its time, and reset is not produced, crashed |
---|
163 | |
---|
164 | dayNavigator->show(); |
---|
165 | } |
---|
166 | |
---|
167 | /* |
---|
168 | void MainWindow::updateFavViewComplete() |
---|
169 | { |
---|
170 | int confId = 1; |
---|
171 | updateFavView(); |
---|
172 | updateDayView(Conference::getById(confId).start()); |
---|
173 | } |
---|
174 | */ |
---|
175 | |
---|
176 | void MainWindow::updateActivitiesDayView(const QDate &aDate) |
---|
177 | { |
---|
178 | int confId = 1; |
---|
179 | static_cast<EventModel*>(actTreeView->model())->loadEventsByActivities(aDate,confId); |
---|
180 | actTreeView->reset(); |
---|
181 | activityDayNavigator->show(); |
---|
182 | } |
---|
183 | |
---|
184 | void MainWindow::itemDoubleClicked(const QModelIndex &aIndex) |
---|
185 | { |
---|
186 | // have to handle only events, not time-groups |
---|
187 | if(!aIndex.parent().isValid()) // time-group |
---|
188 | return; |
---|
189 | |
---|
190 | EventDialog dialog(aIndex,this); |
---|
191 | dialog.exec(); |
---|
192 | } |
---|
193 | |
---|