source: src/gui/mainwindow.cpp @ 7f84a70

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

Favourites dayNavigator

  • Property mode set to 100644
File size: 7.5 KB
RevLine 
[e5bc908]1#include "mainwindow.h"
2
[d0d0a66]3#include <QTreeView>
[9bbb44e]4#include <QDirModel>
[d0d0a66]5
[72f6fe4]6#include <sqlengine.h>
7#include <schedulexmlparser.h>
8
[d0d0a66]9#include <eventmodel.h>
[66327a0]10#include <delegate.h>
[d0d0a66]11
[969a840]12#include <conference.h>
13
[c2d66b2]14#include <QDialog>
15#include "ui_about.h"
[707cd31]16#include "eventdialog.h"
[969a840]17#include "daynavigatorwidget.h"
[59c6cfe]18#include "mapwindow.h"
[72f6fe4]19
[e5bc908]20MainWindow::MainWindow(QWidget *parent)
21    : QMainWindow(parent)
22{
[9bbb44e]23    setupUi(this);
[72f6fe4]24
[c2d66b2]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
[72f6fe4]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
[969a840]39    connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateDayView(const QDate &)));
[f6300c7]40    connect(activityDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateActivitiesDayView(const QDate &)));
[7f84a70]41    connect(favouriteDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateFavouritesDayView(const QDate &)));
[5842349]42
[6f39595]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));
[fbc1646]58
59    //ACTIVITIES View
[707cd31]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
[59c6cfe]67    // event double clicked
[707cd31]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 &)));
[59c6cfe]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
[fbc1646]76
[6f39595]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    }
[969a840]84
85    if(!Conference::getAll().count()) // no conference(s) in the DB
[fbc1646]86    {
[969a840]87        dayNavigator->hide(); // hide DayNavigatorWidget
[fbc1646]88        activityDayNavigator->hide();
89    }
[969a840]90    else
91    {
92        int confId = 1;
[fbc1646]93        QDate aStartDate = Conference::getById(confId).start();
94        QDate aEndDate = Conference::getById(confId).end();
95        dayNavigator->setDates(aStartDate, aEndDate);
96        activityDayNavigator->setDates(aStartDate, aEndDate);
[7f84a70]97        favouriteDayNavigator->setDates(aStartDate, aEndDate);
[969a840]98    }
[c5324ca]99
100    connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateTab(int)));
101
[e5bc908]102}
[66327a0]103
[72f6fe4]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{
[2fc2878]120    QFile file(":/schedule.en.xml");
[72f6fe4]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);
[969a840]129
130    if(Conference::getAll().count())
131    {
132        int confId = 1;
133        // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
[a35aa83]134        QDate aStartDate = Conference::getById(confId).start();
135        QDate aEndDate = Conference::getById(confId).end();
136        dayNavigator->setDates(aStartDate, aEndDate);
137        activityDayNavigator->setDates(aStartDate, aEndDate);
[969a840]138    }
[72f6fe4]139}
140
141void MainWindow::showParsingProgress(int aStatus)
142{
143    QString msg = QString("Parsing completed: %1\%").arg(aStatus);
144    statusBar()->showMessage(msg,1000);
145}
146
[c2d66b2]147void MainWindow::aboutApp()
148{
149    QDialog dialog(this);
150    Ui::AboutDialog ui;
151    ui.setupUi(&dialog);
152    dialog.exec();
153}
154
[ec67a0b]155void MainWindow::updateDayView(const QDate &aDate)
[969a840]156{
157    int confId = 1;
[ec67a0b]158    static_cast<EventModel*>(dayTreeView->model())->loadEvents(aDate,confId);
[6f39595]159    dayTreeView->reset();
[969a840]160    dayNavigator->show();
161}
162
[ec67a0b]163void MainWindow::updateTab(const int aIndex)
[5842349]164{
165    int confId = 1;
[ec67a0b]166    switch(aIndex)
[c5324ca]167    {
[ec67a0b]168    case 0://index 0 of tabWidget: dayViewTab
169        {
170            static_cast<EventModel*>(dayTreeView->model())->loadEvents(Conference::getById(confId).start(),confId);
171            dayTreeView->reset();
[7f84a70]172            dayNavigator->show();
[ec67a0b]173        }
174        break;
175    case 1: //index 1 of tabWidget: favouritesTab
176        {
[7f84a70]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();
[ec67a0b]187        }
188        break;
189    default:
190        {
[7f84a70]191
[ec67a0b]192        }
193    };
194
[d23aa6a]195
[7f84a70]196}
[f6300c7]197
198void MainWindow::updateActivitiesDayView(const QDate &aDate)
199{
200    int confId = 1;
[707cd31]201    static_cast<EventModel*>(actTreeView->model())->loadEventsByActivities(aDate,confId);
202    actTreeView->reset();
[f6300c7]203    activityDayNavigator->show();
204}
[707cd31]205
[7f84a70]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
[707cd31]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
[59c6cfe]224void MainWindow::displayMap(const QModelIndex &aIndex)
225{
[f9db452]226    Event *event = static_cast<Event*>(aIndex.internalPointer());
[9afc0ee]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("."));
[b1fc17a]231    if(!QFile::exists(mapPath))
232        mapPath = QString(":/maps/rooms/not-available.png");
[9afc0ee]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
[f9db452]240    QPixmap map(mapPath);
[9afc0ee]241    MapWindow window(map,roomName,this);
[59c6cfe]242    window.exec();
243}
244
Note: See TracBrowser for help on using the repository browser.