source: src/gui/mainwindow.cpp @ 72f6fe4

qt5
Last change on this file since 72f6fe4 was 72f6fe4, checked in by pavelpa <pavelpa@…>, 12 years ago

implemented xml parser

  • parsing Schedule
  • Property mode set to 100644
File size: 1.6 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
13MainWindow::MainWindow(QWidget *parent)
14    : QMainWindow(parent)
15{
16    setupUi(this);
17
18    // create "SQLITE" DB instance/connection
19    // opens DB connection (needed for EventModel)
20    mSqlEngine = new SqlEngine(this);
21    mSqlEngine->initialize();
22
23    mXmlParser = new ScheduleXmlParser(this);
24    connect(mXmlParser, SIGNAL(progressStatus(int)), this, SLOT(showParsingProgress(int)));
25    statusBar()->showMessage(tr("Ready"));
26
27    connect(actionImportSchedule, SIGNAL(triggered()), SLOT(importSchedule()));
28
29    treeView->setHeaderHidden(true);
30    treeView->setRootIsDecorated(false);
31    treeView->setIndentation(0);
32    treeView->setAnimated(true);
33    treeView->setModel(new EventModel());
34    treeView->setItemDelegate(new Delegate(treeView));
35}
36
37MainWindow::~MainWindow()
38{
39    if(mSqlEngine)
40    {
41        delete mSqlEngine;
42        mSqlEngine = NULL;
43    }
44    if(mXmlParser)
45    {
46        delete mXmlParser;
47        mXmlParser = NULL;
48    }
49}
50
51void MainWindow::importSchedule()
52{
53    QFile file("../schedule.en.xml");
54    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
55    {
56        qDebug() << "can't open " << file.fileName();
57        return;
58    }
59
60    QByteArray data = file.readAll();
61    mXmlParser->parseData(data,mSqlEngine);
62    static_cast<EventModel*>(treeView->model())->reload();
63    treeView->reset();
64}
65
66void MainWindow::showParsingProgress(int aStatus)
67{
68    QString msg = QString("Parsing completed: %1\%").arg(aStatus);
69    statusBar()->showMessage(msg,1000);
70}
71
Note: See TracBrowser for help on using the repository browser.