source: src/gui/mainwindow.cpp @ b6cd05c

qt5
Last change on this file since b6cd05c was d23aa6a, checked in by fortefr <fortefr@…>, 13 years ago

Favourites fix

  • Property mode set to 100644
File size: 4.2 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 "daynavigatorwidget.h"
17
18MainWindow::MainWindow(QWidget *parent)
19    : QMainWindow(parent)
20{
21    setupUi(this);
22
23    // connect Menu actions
24    connect(actionImportSchedule, SIGNAL(triggered()), SLOT(importSchedule()));
25    connect(actionAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
26    connect(actionAboutApplication, SIGNAL(triggered()), SLOT(aboutApp()));
27
28    // create "SQLITE" DB instance/connection
29    // opens DB connection (needed for EventModel)
30    mSqlEngine = new SqlEngine(this);
31    mSqlEngine->initialize();
32
33    mXmlParser = new ScheduleXmlParser(this);
34    connect(mXmlParser, SIGNAL(progressStatus(int)), this, SLOT(showParsingProgress(int)));
35    statusBar()->showMessage(tr("Ready"));
36
37    connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateDayView(const QDate &)));
38
39
40    // DAY EVENTS View
41    dayTreeView->setHeaderHidden(true);
42    dayTreeView->setRootIsDecorated(false);
43    dayTreeView->setIndentation(0);
44    dayTreeView->setAnimated(true);
45    dayTreeView->setModel(new EventModel());
46    dayTreeView->setItemDelegate(new Delegate(dayTreeView));
47
48    // FAVOURITIES View
49    favTreeView->setHeaderHidden(true);
50    favTreeView->setRootIsDecorated(false);
51    favTreeView->setIndentation(0);
52    favTreeView->setAnimated(true);
53    favTreeView->setModel(new EventModel());
54    favTreeView->setItemDelegate(new Delegate(favTreeView));
55    // TESTING: load some 'fav' data
56    if(Conference::getAll().count()) // no conference(s) in the DB
57    {
58        int confId = 1;
59        static_cast<EventModel*>(favTreeView->model())->loadFavEvents(Conference::getById(confId).start(),confId);
60        favTreeView->reset();
61    }
62
63    if(!Conference::getAll().count()) // no conference(s) in the DB
64        dayNavigator->hide(); // hide DayNavigatorWidget
65    else
66    {
67        int confId = 1;
68        dayNavigator->setDates(Conference::getById(confId).start(),Conference::getById(confId).end());
69    }
70
71    connect(static_cast<EventModel*>(dayTreeView->model()), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), SLOT(updateFavView()));
72    connect(static_cast<EventModel*>(favTreeView->model()), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), SLOT(updateFavViewComplete()));
73}
74
75MainWindow::~MainWindow()
76{
77    if(mSqlEngine)
78    {
79        delete mSqlEngine;
80        mSqlEngine = NULL;
81    }
82    if(mXmlParser)
83    {
84        delete mXmlParser;
85        mXmlParser = NULL;
86    }
87}
88
89void MainWindow::importSchedule()
90{
91    QFile file("../schedule.en.xml");
92    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
93    {
94        QString currPath = QDir::currentPath();
95        qDebug() << "current path: " << currPath;
96        qDebug() << "can't open " << file.fileName();
97        return;
98    }
99
100    QByteArray data = file.readAll();
101    mXmlParser->parseData(data,mSqlEngine);
102
103    if(Conference::getAll().count())
104    {
105        int confId = 1;
106        // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
107        dayNavigator->setDates(Conference::getById(confId).start(),Conference::getById(confId).end());
108    }
109}
110
111void MainWindow::showParsingProgress(int aStatus)
112{
113    QString msg = QString("Parsing completed: %1\%").arg(aStatus);
114    statusBar()->showMessage(msg,1000);
115}
116
117void MainWindow::aboutApp()
118{
119    QDialog dialog(this);
120    Ui::AboutDialog ui;
121    ui.setupUi(&dialog);
122    dialog.exec();
123}
124
125void MainWindow::updateDayView(const QDate &aDate)
126{
127    int confId = 1;
128    static_cast<EventModel*>(dayTreeView->model())->loadEvents(aDate,confId);
129    dayTreeView->reset();
130    dayNavigator->show();
131}
132
133void MainWindow::updateFavView()
134{
135    int confId = 1;
136    static_cast<EventModel*>(favTreeView->model())->loadFavEvents(Conference::getById(confId).start(),confId);
137    favTreeView->reset(); //Necessary reset:
138                        //  if favourite event unselected as favourite is the only one in its time, and reset is not produced, crashed
139}
140
141void MainWindow::updateFavViewComplete()
142{
143    int confId = 1;
144    updateFavView();
145    updateDayView(Conference::getById(confId).start());
146}
Note: See TracBrowser for help on using the repository browser.