Ignore:
Timestamp:
01/12/10 21:32:08 (12 years ago)
Author:
pavelpa <pavelpa@…>
Branches:
master, qt5
Children:
f0ce4d0
Parents:
66327a0
Message:

implemented xml parser

  • parsing Schedule
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/gui/mainwindow.cpp

    r66327a0 r72f6fe4  
    44#include <QDirModel>
    55
     6#include <sqlengine.h>
     7#include <schedulexmlparser.h>
     8
    69#include <eventmodel.h>
    710#include <delegate.h>
     11
    812
    913MainWindow::MainWindow(QWidget *parent)
    1014    : QMainWindow(parent)
    1115{
    12     // open database connection
    13     QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    14     db.setDatabaseName("fosdem-test.sqlite");
    15     db.open();
     16    setupUi(this);
    1617
    17     setupUi(this);
    18     //TODO Palo: continue
     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
    1929    treeView->setHeaderHidden(true);
    2030    treeView->setRootIsDecorated(false);
     
    2535}
    2636
     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 TracChangeset for help on using the changeset viewer.