source: src/gui/mainwindow.cpp @ 0c658c1

qt5
Last change on this file since 0c658c1 was 7f84a70, checked in by fortefr <fortefr@…>, 12 years ago

Favourites dayNavigator

  • Property mode set to 100644
File size: 7.5 KB
Line 
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#include "mapwindow.h"
19
20MainWindow::MainWindow(QWidget *parent)
21    : QMainWindow(parent)
22{
23    setupUi(this);
24
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()));
29
30    // create "SQLITE" DB instance/connection
31    // opens DB connection (needed for EventModel)
32    mSqlEngine = new SqlEngine(this);
33    mSqlEngine->initialize();
34
35    mXmlParser = new ScheduleXmlParser(this);
36    connect(mXmlParser, SIGNAL(progressStatus(int)), this, SLOT(showParsingProgress(int)));
37    statusBar()->showMessage(tr("Ready"));
38
39    connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateDayView(const QDate &)));
40    connect(activityDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateActivitiesDayView(const QDate &)));
41    connect(favouriteDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateFavouritesDayView(const QDate &)));
42
43    // DAY EVENTS View
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));
50
51    // FAVOURITIES View
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));
58
59    //ACTIVITIES View
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));
66
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 &)));
75
76
77    // TESTING: load some 'fav' data
78    if(Conference::getAll().count()) // no conference(s) in the DB
79    {
80        int confId = 1;
81        static_cast<EventModel*>(favTreeView->model())->loadFavEvents(Conference::getById(confId).start(),confId);
82        favTreeView->reset();
83    }
84
85    if(!Conference::getAll().count()) // no conference(s) in the DB
86    {
87        dayNavigator->hide(); // hide DayNavigatorWidget
88        activityDayNavigator->hide();
89    }
90    else
91    {
92        int confId = 1;
93        QDate aStartDate = Conference::getById(confId).start();
94        QDate aEndDate = Conference::getById(confId).end();
95        dayNavigator->setDates(aStartDate, aEndDate);
96        activityDayNavigator->setDates(aStartDate, aEndDate);
97        favouriteDayNavigator->setDates(aStartDate, aEndDate);
98    }
99
100    connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateTab(int)));
101
102}
103
104MainWindow::~MainWindow()
105{
106    if(mSqlEngine)
107    {
108        delete mSqlEngine;
109        mSqlEngine = NULL;
110    }
111    if(mXmlParser)
112    {
113        delete mXmlParser;
114        mXmlParser = NULL;
115    }
116}
117
118void MainWindow::importSchedule()
119{
120    QFile file(":/schedule.en.xml");
121    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
122    {
123        qDebug() << "can't open " << file.fileName();
124        return;
125    }
126
127    QByteArray data = file.readAll();
128    mXmlParser->parseData(data,mSqlEngine);
129
130    if(Conference::getAll().count())
131    {
132        int confId = 1;
133        // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
134        QDate aStartDate = Conference::getById(confId).start();
135        QDate aEndDate = Conference::getById(confId).end();
136        dayNavigator->setDates(aStartDate, aEndDate);
137        activityDayNavigator->setDates(aStartDate, aEndDate);
138    }
139}
140
141void MainWindow::showParsingProgress(int aStatus)
142{
143    QString msg = QString("Parsing completed: %1\%").arg(aStatus);
144    statusBar()->showMessage(msg,1000);
145}
146
147void MainWindow::aboutApp()
148{
149    QDialog dialog(this);
150    Ui::AboutDialog ui;
151    ui.setupUi(&dialog);
152    dialog.exec();
153}
154
155void MainWindow::updateDayView(const QDate &aDate)
156{
157    int confId = 1;
158    static_cast<EventModel*>(dayTreeView->model())->loadEvents(aDate,confId);
159    dayTreeView->reset();
160    dayNavigator->show();
161}
162
163void MainWindow::updateTab(const int aIndex)
164{
165    int confId = 1;
166    switch(aIndex)
167    {
168    case 0://index 0 of tabWidget: dayViewTab
169        {
170            static_cast<EventModel*>(dayTreeView->model())->loadEvents(Conference::getById(confId).start(),confId);
171            dayTreeView->reset();
172            dayNavigator->show();
173        }
174        break;
175    case 1: //index 1 of tabWidget: favouritesTab
176        {
177            static_cast<EventModel*>(favTreeView->model())->loadFavEvents(Conference::getById(confId).start(),confId);
178            favTreeView->reset();
179            favouriteDayNavigator->show();
180        }
181        break;
182    case 2: //index 2 of tabWidget: activitiesTab
183        {
184            static_cast<EventModel*>(actTreeView->model())->loadEventsByActivities(Conference::getById(confId).start(),confId);
185            actTreeView->reset();
186            activityDayNavigator->show();
187        }
188        break;
189    default:
190        {
191
192        }
193    };
194
195
196}
197
198void MainWindow::updateActivitiesDayView(const QDate &aDate)
199{
200    int confId = 1;
201    static_cast<EventModel*>(actTreeView->model())->loadEventsByActivities(aDate,confId);
202    actTreeView->reset();
203    activityDayNavigator->show();
204}
205
206void MainWindow::updateFavouritesDayView(const QDate &aDate)
207{
208    int confId = 1;
209    static_cast<EventModel*>(favTreeView->model())->loadFavEvents(aDate,confId);
210    favTreeView->reset();
211    favouriteDayNavigator->show();
212}
213
214void MainWindow::itemDoubleClicked(const QModelIndex &aIndex)
215{
216    // have to handle only events, not time-groups
217    if(!aIndex.parent().isValid()) // time-group
218        return;
219
220    EventDialog dialog(aIndex,this);
221    dialog.exec();
222}
223
224void MainWindow::displayMap(const QModelIndex &aIndex)
225{
226    Event *event = static_cast<Event*>(aIndex.internalPointer());
227
228    // room names are stored in lower-case format
229    // room names are stored without dots in the name, eg. "aw.1124.png" -> "aw1124.png"
230    QString mapPath = QString(":/maps/rooms/%1.png").arg(event->room().toLower().remove("."));
231    if(!QFile::exists(mapPath))
232        mapPath = QString(":/maps/rooms/not-available.png");
233
234    QString roomName;
235    if(mapPath.contains("not-available", Qt::CaseInsensitive))
236        roomName = QString("Map is not available: %1").arg(event->room());
237    else
238        roomName = event->room();
239
240    QPixmap map(mapPath);
241    MapWindow window(map,roomName,this);
242    window.exec();
243}
244
Note: See TracBrowser for help on using the repository browser.