source: src/gui/mainwindow.cpp @ 96fe8fb

qt5
Last change on this file since 96fe8fb was 72cd3af, checked in by korrco <korrco@…>, 12 years ago

activities tab implemented

  • Property mode set to 100644
File size: 9.0 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 <track.h>
10#include <eventmodel.h>
11#include <delegate.h>
12
13#include <conference.h>
14
15#include <QDialog>
16#include "ui_about.h"
17#include "eventdialog.h"
18#include "daynavigatorwidget.h"
19#include "mapwindow.h"
20
21const int confId = 1;
22
23MainWindow::MainWindow(int aEventId, QWidget *aParent)
24    : QMainWindow(aParent)
25{
26    setupUi(this);
27
28    // connect Menu actions
29    connect(actionImportSchedule, SIGNAL(triggered()), SLOT(importSchedule()));
30    connect(actionAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
31    connect(actionAboutApplication, SIGNAL(triggered()), SLOT(aboutApp()));
32
33    // create "SQLITE" DB instance/connection
34    // opens DB connection (needed for EventModel)
35    mSqlEngine = new SqlEngine(this);
36    mSqlEngine->initialize();
37
38    mXmlParser = new ScheduleXmlParser(this);
39    connect(mXmlParser, SIGNAL(progressStatus(int)), this, SLOT(showParsingProgress(int)));
40    statusBar()->showMessage(tr("Ready"));
41
42    //update track map
43    Track::updateTrackMap();
44
45    connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateDayView(const QDate &)));
46    connect(trackDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateTracksView(const QDate &)));
47    connect(favouriteDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateFavouritesView(const QDate &)));
48
49    // DAY EVENTS View
50    dayTreeView->setHeaderHidden(true);
51    dayTreeView->setRootIsDecorated(false);
52    dayTreeView->setIndentation(0);
53    dayTreeView->setAnimated(true);
54    dayTreeView->setModel(new EventModel());
55    dayTreeView->setItemDelegate(new Delegate(dayTreeView));
56
57    // FAVOURITIES View
58    favTreeView->setHeaderHidden(true);
59    favTreeView->setRootIsDecorated(false);
60    favTreeView->setIndentation(0);
61    favTreeView->setAnimated(true);
62    favTreeView->setModel(new EventModel());
63    favTreeView->setItemDelegate(new Delegate(favTreeView));
64
65    //ACTIVITIES View
66    trackTreeView->setHeaderHidden(true);
67    trackTreeView->setRootIsDecorated(false);
68    trackTreeView->setIndentation(0);
69    trackTreeView->setAnimated(true);
70    trackTreeView->setModel(new EventModel());
71    trackTreeView->setItemDelegate(new Delegate(trackTreeView));
72
73    // SEARCH EVENTS View
74        searchTreeView->setHeaderHidden(true);
75        searchTreeView->setRootIsDecorated(false);
76        searchTreeView->setIndentation(0);
77        searchTreeView->setAnimated(true);
78        searchTreeView->setModel(new EventModel());
79        searchTreeView->setItemDelegate(new Delegate(searchTreeView));
80        searchTreeView->setVisible(false);
81        searchDayNavigator->setVisible(false);
82    // event clicked
83    connect(dayTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
84    connect(favTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
85    connect(trackTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
86    connect(searchTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
87    // request for map to be displayed
88    connect(dayTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
89    connect(favTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
90    connect(trackTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
91    connect(searchTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
92    // event search button clicked
93    connect(searchButton, SIGNAL(clicked()), SLOT(searchClicked()));
94
95    // TESTING: load some 'fav' data
96    if(Conference::getAll().count()) // no conference(s) in the DB
97    {
98        static_cast<EventModel*>(favTreeView->model())->loadFavEvents(Conference::getById(confId).start(),confId);
99        favTreeView->reset();
100    }
101
102    if(!Conference::getAll().count()) // no conference(s) in the DB
103    {
104        dayNavigator->hide(); // hide DayNavigatorWidget
105        trackDayNavigator->hide();
106    }
107    else
108    {
109        QDate aStartDate = Conference::getById(confId).start();
110        QDate aEndDate = Conference::getById(confId).end();
111        dayNavigator->setDates(aStartDate, aEndDate);
112        trackDayNavigator->setDates(aStartDate, aEndDate);
113        favouriteDayNavigator->setDates(aStartDate, aEndDate);
114        searchDayNavigator->setDates(aStartDate, aEndDate);
115    }
116
117    connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateTab(int)));
118
119    // open dialog for given Event ID
120    // this is used in case Alarm Dialog request application to start
121    if(aEventId)
122    {
123        try
124        {
125            EventDialog dialog(aEventId,this);
126            dialog.exec();
127        }
128        catch(OrmNoObjectException*) {} // just start application
129        catch(...) {} // just start application
130    }
131}
132
133MainWindow::~MainWindow()
134{
135    if(mSqlEngine)
136    {
137        delete mSqlEngine;
138        mSqlEngine = NULL;
139    }
140    if(mXmlParser)
141    {
142        delete mXmlParser;
143        mXmlParser = NULL;
144    }
145}
146
147void MainWindow::importSchedule()
148{
149    QFile file(":/schedule.en.xml");
150    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
151    {
152        qDebug() << "can't open " << file.fileName();
153        return;
154    }
155
156    QByteArray data = file.readAll();
157    mXmlParser->parseData(data,mSqlEngine);
158
159    if(Conference::getAll().count())
160    {
161        // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
162        QDate aStartDate = Conference::getById(confId).start();
163        QDate aEndDate = Conference::getById(confId).end();
164        dayNavigator->setDates(aStartDate, aEndDate);
165        //update activity map
166        Track::updateTrackMap();
167        trackDayNavigator->setDates(aStartDate, aEndDate);
168    }
169}
170
171void MainWindow::showParsingProgress(int aStatus)
172{
173    QString msg = QString("Parsing completed: %1\%").arg(aStatus);
174    statusBar()->showMessage(msg,1000);
175}
176
177void MainWindow::aboutApp()
178{
179    QDialog dialog(this);
180    Ui::AboutDialog ui;
181    ui.setupUi(&dialog);
182    dialog.exec();
183}
184
185void MainWindow::updateDayView(const QDate &aDate)
186{
187    static_cast<EventModel*>(dayTreeView->model())->loadEvents(aDate,confId);
188    dayTreeView->reset();
189    dayNavigator->show();
190}
191
192void MainWindow::updateTab(const int aIndex)
193{
194    switch(aIndex)
195    {
196    case 0://index 0 of tabWidget: dayViewTab
197        {
198            static_cast<EventModel*>(dayTreeView->model())->loadEvents(Conference::getById(confId).start(),confId);
199            dayTreeView->reset();
200            dayNavigator->show();
201        }
202        break;
203    case 1: //index 1 of tabWidget: favouritesTab
204        {
205            static_cast<EventModel*>(favTreeView->model())->loadFavEvents(Conference::getById(confId).start(),confId);
206            favTreeView->reset();
207            favouriteDayNavigator->show();
208        }
209        break;
210    case 2: //index 2 of tabWidget: activitiesTab
211        {
212            //TODO korinpa: nastavit navigator, alebo dat datum navigatora pre ine case
213            updateTracksView(activityDayNavigator->getCurrentDate());
214        }
215        break;
216    default:
217        {
218
219        }
220    };
221}
222
223void MainWindow::updateTracksView(const QDate &aDate)
224{
225    static_cast<EventModel*>(trackTreeView->model())->loadEventsByTrack(aDate, confId);
226    trackTreeView->reset();
227    trackDayNavigator->show();
228}
229
230void MainWindow::updateFavouritesView(const QDate &aDate)
231{
232    static_cast<EventModel*>(favTreeView->model())->loadFavEvents(aDate,confId);
233    favTreeView->reset();
234    favouriteDayNavigator->show();
235}
236
237void MainWindow::itemClicked(const QModelIndex &aIndex)
238{
239    // have to handle only events, not time-groups
240    if(!aIndex.parent().isValid()) // time-group
241        return;
242
243    EventDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this);
244    dialog.exec();
245}
246
247void MainWindow::displayMap(const QModelIndex &aIndex)
248{
249    Event *event = static_cast<Event*>(aIndex.internalPointer());
250
251    // room names are stored in lower-case format
252    // room names are stored without dots in the name, eg. "aw.1124.png" -> "aw1124.png"
253    QString mapPath = QString(":/maps/rooms/%1.png").arg(event->room().toLower().remove("."));
254    if(!QFile::exists(mapPath))
255        mapPath = QString(":/maps/rooms/not-available.png");
256
257    QString roomName;
258    if(mapPath.contains("not-available", Qt::CaseInsensitive))
259        roomName = QString("Map is not available: %1").arg(event->room());
260    else
261        roomName = event->room();
262
263    QPixmap map(mapPath);
264    MapWindow window(map,roomName,this);
265    window.exec();
266}
267
268void MainWindow::searchClicked()
269{
270    QList<QString> columns;
271
272    if( searchTitle->isChecked() )
273        columns.append( "title" );
274    if( searchAbstract->isChecked() )
275        columns.append( "abstract" );
276
277    searchTreeView->reset();
278    if( mSqlEngine->searchEvent( confId, columns, searchEdit->text() ) > 0 ){
279        static_cast<EventModel*>(searchTreeView->model())->loadSearchResultEvents(Conference::getById(confId).start(),confId);
280        searchDayNavigator->show();
281        searchTreeView->show();
282    }
283}
284
Note: See TracBrowser for help on using the repository browser.