source: src/gui/mainwindow.cpp @ 969a840

qt5
Last change on this file since 969a840 was 969a840, checked in by pavelpa <pavelpa@…>, 13 years ago

implemented day navigator widget

  • to switch between conference days
  • Property mode set to 100644
File size: 2.8 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    treeView->setHeaderHidden(true);
40    treeView->setRootIsDecorated(false);
41    treeView->setIndentation(0);
42    treeView->setAnimated(true);
43    treeView->setModel(new EventModel());
44    treeView->setItemDelegate(new Delegate(treeView));
45
46    if(!Conference::getAll().count()) // no conference(s) in the DB
47        dayNavigator->hide(); // hide DayNavigatorWidget
48    else
49    {
50        int confId = 1;
51        dayNavigator->setDates(Conference::getById(confId).start(),Conference::getById(confId).end());
52    }
53}
54
55MainWindow::~MainWindow()
56{
57    if(mSqlEngine)
58    {
59        delete mSqlEngine;
60        mSqlEngine = NULL;
61    }
62    if(mXmlParser)
63    {
64        delete mXmlParser;
65        mXmlParser = NULL;
66    }
67}
68
69void MainWindow::importSchedule()
70{
71    QFile file("../schedule.en.xml");
72    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
73    {
74        qDebug() << "can't open " << file.fileName();
75        return;
76    }
77
78    QByteArray data = file.readAll();
79    mXmlParser->parseData(data,mSqlEngine);
80
81    if(Conference::getAll().count())
82    {
83        int confId = 1;
84        // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
85        dayNavigator->setDates(Conference::getById(confId).start(),Conference::getById(confId).end());
86    }
87}
88
89void MainWindow::showParsingProgress(int aStatus)
90{
91    QString msg = QString("Parsing completed: %1\%").arg(aStatus);
92    statusBar()->showMessage(msg,1000);
93}
94
95void MainWindow::aboutApp()
96{
97    QDialog dialog(this);
98    Ui::AboutDialog ui;
99    ui.setupUi(&dialog);
100    dialog.exec();
101}
102
103void MainWindow::updateDayView(const QDate &aDate)
104{
105    int confId = 1;
106    static_cast<EventModel*>(treeView->model())->loadEvents(aDate,confId);
107    treeView->reset();
108    dayNavigator->show();
109}
110
Note: See TracBrowser for help on using the repository browser.