Changeset 72f6fe4


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
Location:
src
Files:
6 added
8 edited

Legend:

Unmodified
Added
Removed
  • src/app/app.pro

    r66327a0 r72f6fe4  
    22TARGET = fosdem
    33DESTDIR = ../bin
    4 QT += sql
     4QT += sql xml
    55
    66# module dependencies
    7 LIBS += -L$$DESTDIR -lgui -lmodel
     7LIBS += -L$$DESTDIR -lgui -lmodel -lsql
    88INCLUDEPATH += ../gui
    99DEPENDPATH += . ../gui
    10 TARGETDEPS += $$DESTDIR/libmodel.a $$DESTDIR/libgui.a
     10TARGETDEPS += $$DESTDIR/libmodel.a $$DESTDIR/libgui.a $$DESTDIR/libsql.a
    1111
    1212SOURCES += main.cpp
  • src/fosdem.pro

    r66327a0 r72f6fe4  
    11TEMPLATE = subdirs
    2 SUBDIRS  = orm model gui app test
     2SUBDIRS  = orm model sql gui app test
    33CONFIG += ordered
    44
  • src/gui/gui.pro

    r66327a0 r72f6fe4  
    33DESTDIR = ../bin
    44CONFIG += static
    5 QT += sql
     5QT += sql xml
    66
    77# module dependencies
    8 LIBS += -L$$DESTDIR -lmodel -orm
    9 INCLUDEPATH += ../orm ../model
    10 DEPENDPATH += . ../orm ../model
    11 TARGETDEPS += $$DESTDIR/liborm.a $$DESTDIR/libmodel.a
     8LIBS += -L$$DESTDIR -lmodel -lorm -lsql
     9INCLUDEPATH += ../orm ../model ../sql
     10DEPENDPATH += . ../orm ../model ../sql
     11TARGETDEPS += $$DESTDIR/liborm.a $$DESTDIR/libmodel.a $$DESTDIR/libsql.a
    1212
    1313
  • 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
  • src/gui/mainwindow.h

    r66327a0 r72f6fe4  
    66#include <ui_mainwindow.h>
    77
     8class SqlEngine;
     9class ScheduleXmlParser;
     10
    811class MainWindow : public QMainWindow, private Ui::MainWindow
    912{
    1013    Q_OBJECT
    11 
    1214public:
    1315    MainWindow(QWidget *parent = 0);
     16    ~MainWindow();
     17private slots:
     18    void importSchedule();
     19    void showParsingProgress(int aStatus);
     20private:
     21    SqlEngine *mSqlEngine;
     22    ScheduleXmlParser *mXmlParser;
    1423};
    1524
  • src/gui/mainwindow.ui

    r66327a0 r72f6fe4  
    5656     <y>0</y>
    5757     <width>856</width>
    58      <height>22</height>
     58     <height>26</height>
    5959    </rect>
    6060   </property>
     61   <widget class="QMenu" name="menuFile" >
     62    <property name="title" >
     63     <string>File</string>
     64    </property>
     65    <addaction name="actionImportSchedule" />
     66   </widget>
     67   <addaction name="menuFile" />
    6168  </widget>
    6269  <widget class="QStatusBar" name="statusbar" />
     70  <action name="actionImportSchedule" >
     71   <property name="text" >
     72    <string>Import Schedule</string>
     73   </property>
     74  </action>
    6375 </widget>
    6476 <customwidgets>
  • src/model/eventmodel.cpp

    r66327a0 r72f6fe4  
    22
    33EventModel::EventModel() :
    4         mEvents(Event::getByDate(QDate(2009, 2, 7), 1))
     4    mEvents(Event::getByDate(QDate(2009, 2, 7), 1))
    55{
    66    createTimeGroups();
     
    117117    return 0;
    118118}
     119
     120void EventModel::reload()
     121{
     122    mEvents.clear();
     123    mEvents=Event::getByDate(QDate(2009, 2, 7), 1);
     124    createTimeGroups();
     125}
     126
  • src/model/eventmodel.h

    r66327a0 r72f6fe4  
    1515    int columnCount ( const QModelIndex & parent = QModelIndex() ) const;
    1616    int rowCount ( const QModelIndex & parent = QModelIndex() ) const;
     17    void reload(); // reloads Events from the DB
    1718
    1819private:
Note: See TracChangeset for help on using the changeset viewer.