1 #include "mainwindow.h"
7 #include <schedulexmlparser.h>
9 #include <eventmodel.h>
12 #include <conference.h>
16 #include "eventdialog.h"
17 #include "daynavigatorwidget.h"
18 #include "mapwindow.h"
20 MainWindow::MainWindow(QWidget *parent)
25 // connect Menu actions
26 connect(actionImportSchedule, SIGNAL(triggered()), SLOT(importSchedule()));
27 connect(actionAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
28 connect(actionAboutApplication, SIGNAL(triggered()), SLOT(aboutApp()));
30 // create "SQLITE" DB instance/connection
31 // opens DB connection (needed for EventModel)
32 mSqlEngine = new SqlEngine(this);
33 mSqlEngine->initialize();
35 mXmlParser = new ScheduleXmlParser(this);
36 connect(mXmlParser, SIGNAL(progressStatus(int)), this, SLOT(showParsingProgress(int)));
37 statusBar()->showMessage(tr("Ready"));
39 connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateDayView(const QDate &)));
40 connect(activityDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateActivitiesDayView(const QDate &)));
41 //connect(tabWidget, SIGNAL(currentChanged(int)), SLOT(updateView(int)));
44 dayTreeView->setHeaderHidden(true);
45 dayTreeView->setRootIsDecorated(false);
46 dayTreeView->setIndentation(0);
47 dayTreeView->setAnimated(true);
48 dayTreeView->setModel(new EventModel());
49 dayTreeView->setItemDelegate(new Delegate(dayTreeView));
52 favTreeView->setHeaderHidden(true);
53 favTreeView->setRootIsDecorated(false);
54 favTreeView->setIndentation(0);
55 favTreeView->setAnimated(true);
56 favTreeView->setModel(new EventModel());
57 favTreeView->setItemDelegate(new Delegate(favTreeView));
60 actTreeView->setHeaderHidden(true);
61 actTreeView->setRootIsDecorated(false);
62 actTreeView->setIndentation(0);
63 actTreeView->setAnimated(true);
64 actTreeView->setModel(new EventModel());
65 actTreeView->setItemDelegate(new Delegate(actTreeView));
67 // event double clicked
68 connect(dayTreeView, SIGNAL(doubleClicked(const QModelIndex &)), SLOT(itemDoubleClicked(const QModelIndex &)));
69 connect(favTreeView, SIGNAL(doubleClicked(const QModelIndex &)), SLOT(itemDoubleClicked(const QModelIndex &)));
70 connect(actTreeView, SIGNAL(doubleClicked(const QModelIndex &)), SLOT(itemDoubleClicked(const QModelIndex &)));
71 // request for map to be displayed
72 connect(dayTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
73 connect(favTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
74 connect(actTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
77 // TESTING: load some 'fav' data
78 if(Conference::getAll().count()) // no conference(s) in the DB
81 static_cast<EventModel*>(favTreeView->model())->loadFavEvents(Conference::getById(confId).start(),confId);
85 if(!Conference::getAll().count()) // no conference(s) in the DB
87 dayNavigator->hide(); // hide DayNavigatorWidget
88 activityDayNavigator->hide();
93 QDate aStartDate = Conference::getById(confId).start();
94 QDate aEndDate = Conference::getById(confId).end();
95 dayNavigator->setDates(aStartDate, aEndDate);
96 activityDayNavigator->setDates(aStartDate, aEndDate);
98 connect(static_cast<EventModel*>(dayTreeView->model()), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), SLOT(updateFavView()));
99 connect(static_cast<EventModel*>(favTreeView->model()), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), SLOT(updateFavView()));
100 /* connect(static_cast<EventModel*>(favTreeView->model()), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), SLOT(updateFavViewComplete()));*/
103 MainWindow::~MainWindow()
117 void MainWindow::importSchedule()
119 QFile file("../schedule.en.xml");
120 if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
122 qDebug() << "can't open " << file.fileName();
126 QByteArray data = file.readAll();
127 mXmlParser->parseData(data,mSqlEngine);
129 if(Conference::getAll().count())
132 // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
133 QDate aStartDate = Conference::getById(confId).start();
134 QDate aEndDate = Conference::getById(confId).end();
135 dayNavigator->setDates(aStartDate, aEndDate);
136 activityDayNavigator->setDates(aStartDate, aEndDate);
140 void MainWindow::showParsingProgress(int aStatus)
142 QString msg = QString("Parsing completed: %1\%").arg(aStatus);
143 statusBar()->showMessage(msg,1000);
146 void MainWindow::aboutApp()
148 QDialog dialog(this);
154 void MainWindow::updateDayView(const QDate &aDate)
157 static_cast<EventModel*>(dayTreeView->model())->loadEvents(aDate,confId);
158 dayTreeView->reset();
159 dayNavigator->show();
162 void MainWindow::updateFavView()
165 static_cast<EventModel*>(favTreeView->model())->loadFavEvents(Conference::getById(confId).start(),confId);
166 favTreeView->reset(); //Necessary reset:
167 // if favourite event unselected as favourite is the only one in its time, and reset is not produced, crashed
169 dayNavigator->show();
173 void MainWindow::updateFavViewComplete()
177 updateDayView(Conference::getById(confId).start());
181 void MainWindow::updateActivitiesDayView(const QDate &aDate)
184 static_cast<EventModel*>(actTreeView->model())->loadEventsByActivities(aDate,confId);
185 actTreeView->reset();
186 activityDayNavigator->show();
189 void MainWindow::itemDoubleClicked(const QModelIndex &aIndex)
191 // have to handle only events, not time-groups
192 if(!aIndex.parent().isValid()) // time-group
195 EventDialog dialog(aIndex,this);
199 void MainWindow::displayMap(const QModelIndex &aIndex)
201 QPixmap map(":/maps/rooms/janson.png");
202 MapWindow window(map,this);