activities tab implemented
authorkorrco <korrco@localhost>
Thu, 21 Jan 2010 12:54:58 +0000 (12:54 +0000)
committerkorrco <korrco@localhost>
Thu, 21 Jan 2010 12:54:58 +0000 (12:54 +0000)
src/gui/mainwindow.cpp
src/mvc/eventmodel.cpp
src/orm/ormrecord.h
src/sql/schedulexmlparser.cpp
src/sql/sql.pro
src/sql/sqlengine.cpp

index defed3c..eff03fc 100644 (file)
@@ -162,10 +162,10 @@ void MainWindow::importSchedule()
         QDate aStartDate = Conference::getById(confId).start();
         QDate aEndDate = Conference::getById(confId).end();
         dayNavigator->setDates(aStartDate, aEndDate);
+        //update activity map
+        Track::updateTrackMap();
         trackDayNavigator->setDates(aStartDate, aEndDate);
     }
-    //update track map
-    Track::updateTrackMap();
 }
 
 void MainWindow::showParsingProgress(int aStatus)
@@ -207,11 +207,10 @@ void MainWindow::updateTab(const int aIndex)
             favouriteDayNavigator->show();
         }
         break;
-    case 2: //index 2 of tabWidget: trackTab
+    case 2: //index 2 of tabWidget: activitiesTab
         {
-            static_cast<EventModel*>(trackTreeView->model())->loadEventsByTrack(Conference::getById(confId).start(), confId);
-            trackTreeView->reset();
-            trackDayNavigator->show();
+            //TODO korinpa: nastavit navigator, alebo dat datum navigatora pre ine case
+            updateTracksView(activityDayNavigator->getCurrentDate());
         }
         break;
     default:
index abd688f..3015565 100644 (file)
@@ -2,6 +2,8 @@
 #include <conference.h>
 #include <track.h>
 
+const QString EventModel::COMMA_SEPARATOR = ", ";
+
 EventModel::EventModel()
 {
     mEvents.clear();
@@ -165,7 +167,7 @@ void EventModel::loadEvents(const QDate &aDate, int aConferenceId)
     if(Conference::getAll().count())
     {
         qDebug() << "Loading Conference Data: [" << Conference::getById(aConferenceId).title() << "] " << aDate;
-        mEvents = Event::getByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, "start");
+        mEvents = Event::getByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, Event::START);
     }
     createTimeGroups();
 }
index a4923d7..2328549 100644 (file)
@@ -120,13 +120,13 @@ T OrmRecord<T>::loadOne(QSqlQuery query)
     {
         if (!query.exec())
         {
-            throw new OrmSqlException(query.lastError().text());
+            throw OrmSqlException(query.lastError().text());
         }
     }
 
     if (!query.next())
     {
-        throw new OrmNoObjectException();
+        throw OrmNoObjectException();
     }
 
     return hydrate(query.record());
@@ -140,7 +140,7 @@ QList<T> OrmRecord<T>::load(QSqlQuery query)
         if (!query.exec())
         {
             qDebug() << "Error: " << query.lastError().driverText() << "; Type: " << query.lastError().type();
-            throw new OrmSqlException(query.lastError().text());
+            throw OrmSqlException(query.lastError().text());
         }
         else
         {
index 1c5ebec..6b7308f 100644 (file)
@@ -80,54 +80,49 @@ void ScheduleXmlParser::parseData(const QByteArray &aData, SqlEngine *aDBEngine)
                         aDBEngine->addRoomToDB(room);\r
 \r
                         // process event's nodes\r
-                        QHash<QString,QString> event;\r
-                        event["id"] = eventElement.attribute("id");\r
-                        event["conference_id"] = QString::number(conferenceID,10);\r
+                        QHash<QString,QString> event;
+                        event["id"] = eventElement.attribute("id");;
+                        event["conference_id"] = QString::number(conferenceID, 10);
                         event["start"] = eventElement.firstChildElement("start").text(); // time eg. 10:00\r
-                        event["date"] = dayElement.attribute("date"); // date eg. 2009-02-07\r
-                        event["duration"] = eventElement.firstChildElement("duration").text(); // time eg. 00:30\r
-                        event["room_name"] = eventElement.firstChildElement("room").text(); // string eg. "Janson"\r
-                        event["tag"] = eventElement.firstChildElement("tag").text(); // string eg. "welcome"\r
-                        event["title"] = eventElement.firstChildElement("title").text(); // string eg. "Welcome"\r
-                        event["subtitle"] = eventElement.firstChildElement("subtitle").text(); // string\r
+                        event["date"] = dayElement.attribute("date"); // date eg. 2009-02-07
+                        event["duration"] = eventElement.firstChildElement("duration").text(); // time eg. 00:30
+                        event["room_name"] = eventElement.firstChildElement("room").text(); // string eg. "Janson"
+                        event["tag"] = eventElement.firstChildElement("tag").text(); // string eg. "welcome"
+                        event["title"] = eventElement.firstChildElement("title").text(); // string eg. "Welcome"
+                        event["subtitle"] = eventElement.firstChildElement("subtitle").text(); // string
                         event["track"] = eventElement.firstChildElement("track").text(); // string eg. "Keynotes"\r
-                        event["type"] = eventElement.firstChildElement("type").text(); // string eg. "Podium"\r
-                        event["language"] = eventElement.firstChildElement("language").text(); // language eg. "English"\r
-                        event["abstract"] = eventElement.firstChildElement("abstract").text(); // string\r
-                        event["description"] = eventElement.firstChildElement("description").text(); // string\r
-                        aDBEngine->addEventToDB(event);\r
-\r
-                        // process persons' nodes\r
-                        QList<QString> persons;\r
-                        QDomElement personsElement = eventElement.firstChildElement("persons");\r
-                        QDomNodeList personList = personsElement.elementsByTagName("person");\r
-                        for (int i=0; i<personList.count(); i++)\r
-                        {\r
-                            QHash<QString,QString> person;\r
-                            person["id"] = personList.at(i).toElement().attribute("id");\r
-                            person["name"] = personList.at(i).toElement().text();\r
-                            person["event_id"] = eventElement.attribute("id");\r
-                            person["conference_id"] = QString::number(conferenceID,10);\r
-                            //qDebug() << "adding Person: " << person["name"];\r
-                            aDBEngine->addPersonToDB(person);\r
-                        }\r
-\r
-                        // process links' nodes\r
-                        QDomElement linksElement = eventElement.firstChildElement("links");\r
-                        QDomNodeList linkList = linksElement.elementsByTagName("link");\r
-                        for (int i=0; i<linkList.count(); i++)\r
-                        {\r
-                            QHash<QString,QString> link;\r
-                            link["name"] = linkList.at(i).toElement().text();\r
-                            link["url"] = linkList.at(i).toElement().attribute("href");\r
-                            link["event_id"] = eventElement.attribute("id");\r
-                            link["conference_id"] = QString::number(conferenceID,10);\r
-                            aDBEngine->addLinkToDB(link);\r
-                        }\r
-\r
-                        // emit signal to inform the user about the current status (how many events are parsed so far - expressed in %)\r
-                        int status=currentEvent*100/totalEventsCount;\r
-                        emit progressStatus(status);\r
+                        event["type"] = eventElement.firstChildElement("type").text(); // string eg. "Podium"
+                        event["language"] = eventElement.firstChildElement("language").text(); // language eg. "English"
+                        event["abstract"] = eventElement.firstChildElement("abstract").text(); // string
+                        event["description"] = eventElement.firstChildElement("description").text(); // string
+                        aDBEngine->addEventToDB(event);
+                        // process persons' nodes
+                        QList<QString> persons;
+                        QDomElement personsElement = eventElement.firstChildElement("persons");
+                        QDomNodeList personList = personsElement.elementsByTagName("person");
+                        for(int i = 0;i < personList.count();i++){
+                            QHash<QString,QString> person;
+                            person["id"] = personList.at(i).toElement().attribute("id");
+                            person["name"] = personList.at(i).toElement().text();
+                            person["event_id"] = eventElement.attribute("id");
+                            person["conference_id"] = QString::number(conferenceID, 10);
+                            //qDebug() << "adding Person: " << person["name"];
+                            aDBEngine->addPersonToDB(person);
+                        }
+                        // process links' nodes
+                        QDomElement linksElement = eventElement.firstChildElement("links");
+                        QDomNodeList linkList = linksElement.elementsByTagName("link");
+                        for(int i = 0;i < linkList.count();i++){
+                            QHash<QString,QString> link;
+                            link["name"] = linkList.at(i).toElement().text();
+                            link["url"] = linkList.at(i).toElement().attribute("href");
+                            link["event_id"] = eventElement.attribute("id");
+                            link["conference_id"] = QString::number(conferenceID, 10);
+                            aDBEngine->addLinkToDB(link);
+                        }
+                        // emit signal to inform the user about the current status (how many events are parsed so far - expressed in %)
+                        int status = currentEvent * 100 / totalEventsCount;
+                        progressStatus(status);\r
                     } // parsing event elements\r
                 }\r
             } // parsing room elements\r
index eebde17..e293aa3 100644 (file)
@@ -6,6 +6,8 @@ CONFIG += static
 QT += sql xml
 
 # module dependencies
+LIBS += -L$$DESTDIR -lmvc -lorm
+INCLUDEPATH += ../mvc ../orm
 DEPENDPATH += .
 
 HEADERS += sqlengine.h \
index c9a0e21..a9b482f 100644 (file)
@@ -7,6 +7,7 @@
 
 #include <QDir>
 #include "sqlengine.h"
+#include <track.h>
 
 #include <QDebug>
 
@@ -88,27 +89,21 @@ void SqlEngine::addEventToDB(QHash<QString,QString> &aEvent)
 
     if (db.isValid() && db.isOpen())
     {
-        // track has to be handled as the first, since it is necessary to get
-        // track ID from the TRACK table, or to create new TRACK record
-        // and get the ID from newly created record
-        QString queryExist = QString("SELECT id FROM track WHERE name='%1'").arg(aEvent["track"]);
-        QSqlQuery resultExist(queryExist,db);
-        // now we have to check whether TRACK record with 'name' exists or not,
-        // - if it doesn't exist yet, then we have to add that record to 'TRACK' table
-        // - if it exists, then we need to get its 'id'
-        int actId = -1;
-        if(resultExist.next()) // TRACK record with 'name' already exists: we need to get its 'id'
+        //insert event track to table
+        QString name = aEvent["track"];
+        Track track;
+        int trackId;
+        try
         {
-            actId = resultExist.value(0).toInt();
+            track = Track::retrieveByName(name);
+            trackId = track.id();
+            /*qDebug() << QString("DEBUG: Track %1 in DB").arg(name);*/
         }
-        else // TRACK record doesn't exist yet, need to create it
-        {
-            QString values = QString("'%1'").arg(aEvent["track"]);
-            QString query = QString("INSERT INTO track (name) VALUES (%1)").arg(values);
-            QSqlQuery result (query, db);
-            actId = result.lastInsertId().toInt(); // 'id' is assigned automatically
+        catch (OrmNoObjectException &e) {
+            track.setName(name);
+            trackId = track.insert();
+            /*qDebug() << QString("DEBUG: Track %1 added to DB").arg(name);*/
         }
-
         // The items of the Event are divided into the two tables EVENT and VIRTUAL_EVENT
         // VIRTUAL_EVENT is for Full-Text-Serach Support
         QDateTime startDateTime = QDateTime(QDate::fromString(aEvent["date"],DATE_FORMAT),QTime::fromString(aEvent["start"],TIME_FORMAT));
@@ -117,7 +112,7 @@ void SqlEngine::addEventToDB(QHash<QString,QString> &aEvent)
                          .arg(aEvent["id"]) \
                          .arg(QString::number(startDateTime.toTime_t())) \
                          .arg(-QTime::fromString(aEvent["duration"],TIME_FORMAT).secsTo(QTime(0,0))) \
-                         .arg(QString::number(actId)) \
+                         .arg(trackId) \
                          .arg(aEvent["type"]) \
                          .arg(aEvent["language"]) \
                          .arg("0") \
@@ -235,7 +230,7 @@ bool SqlEngine::createTables(QSqlDatabase &aDatabase)
 
         query.exec("CREATE TABLE TRACK ( \
             id INTEGER  PRIMARY KEY AUTOINCREMENT  NOT NULL , \
-            name VARCHAR NOT NULL )");
+            name VARCHAR UNIQUE NOT NULL )");
 
         query.exec("CREATE TABLE ROOM ( \
             id INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL , \