From 4693fa6dfc3d959f0bd7decd5facae07a261784a Mon Sep 17 00:00:00 2001 From: pavelpa Date: Wed, 20 Jan 2010 21:02:30 +0000 Subject: [PATCH] changed 'Activity' -> 'Track' --- src/gui/mainwindow.cpp | 54 +++++----- src/gui/mainwindow.h | 4 +- src/gui/mainwindow.ui | 172 ++++++++++++++++---------------- src/mvc/activity.cpp | 44 -------- src/mvc/delegate.cpp | 6 +- src/mvc/event.cpp | 6 +- src/mvc/event.h | 10 +- src/mvc/eventmodel.cpp | 30 +++--- src/mvc/eventmodel.h | 4 +- src/mvc/mvc.pro | 8 +- src/mvc/track.cpp | 44 ++++++++ src/mvc/{activity.h => track.h} | 19 ++-- src/sql/sqlengine.cpp | 27 +++-- src/test/mvc/eventtest.cpp | 12 +-- 14 files changed, 216 insertions(+), 224 deletions(-) delete mode 100644 src/mvc/activity.cpp create mode 100644 src/mvc/track.cpp rename src/mvc/{activity.h => track.h} (62%) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 1c1becf..00ae49b 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include @@ -39,12 +39,12 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent) connect(mXmlParser, SIGNAL(progressStatus(int)), this, SLOT(showParsingProgress(int))); statusBar()->showMessage(tr("Ready")); - //update activity map - Activity::updateActivityMap(); + //update track map + Track::updateTrackMap(); connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateDayView(const QDate &))); - connect(activityDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateActivitiesDayView(const QDate &))); - connect(favouriteDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateFavouritesDayView(const QDate &))); + connect(trackDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateTracksView(const QDate &))); + connect(favouriteDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateFavouritesView(const QDate &))); // DAY EVENTS View dayTreeView->setHeaderHidden(true); @@ -63,12 +63,12 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent) favTreeView->setItemDelegate(new Delegate(favTreeView)); //ACTIVITIES View - actTreeView->setHeaderHidden(true); - actTreeView->setRootIsDecorated(false); - actTreeView->setIndentation(0); - actTreeView->setAnimated(true); - actTreeView->setModel(new EventModel()); - actTreeView->setItemDelegate(new Delegate(actTreeView)); + trackTreeView->setHeaderHidden(true); + trackTreeView->setRootIsDecorated(false); + trackTreeView->setIndentation(0); + trackTreeView->setAnimated(true); + trackTreeView->setModel(new EventModel()); + trackTreeView->setItemDelegate(new Delegate(trackTreeView)); // DAY EVENTS View searchTreeView->setHeaderHidden(true); @@ -82,12 +82,12 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent) // event clicked connect(dayTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &))); connect(favTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &))); - connect(actTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &))); + connect(trackTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &))); connect(searchTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &))); // request for map to be displayed connect(dayTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &))); connect(favTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &))); - connect(actTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &))); + connect(trackTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &))); connect(searchTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &))); // event search button clicked connect(searchButton, SIGNAL(clicked()), SLOT(searchClicked())); @@ -102,14 +102,14 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent) if(!Conference::getAll().count()) // no conference(s) in the DB { dayNavigator->hide(); // hide DayNavigatorWidget - activityDayNavigator->hide(); + trackDayNavigator->hide(); } else { QDate aStartDate = Conference::getById(confId).start(); QDate aEndDate = Conference::getById(confId).end(); dayNavigator->setDates(aStartDate, aEndDate); - activityDayNavigator->setDates(aStartDate, aEndDate); + trackDayNavigator->setDates(aStartDate, aEndDate); favouriteDayNavigator->setDates(aStartDate, aEndDate); } @@ -161,10 +161,10 @@ void MainWindow::importSchedule() QDate aStartDate = Conference::getById(confId).start(); QDate aEndDate = Conference::getById(confId).end(); dayNavigator->setDates(aStartDate, aEndDate); - activityDayNavigator->setDates(aStartDate, aEndDate); + trackDayNavigator->setDates(aStartDate, aEndDate); } - //update activity map - Activity::updateActivityMap(); + //update track map + Track::updateTrackMap(); } void MainWindow::showParsingProgress(int aStatus) @@ -206,11 +206,11 @@ void MainWindow::updateTab(const int aIndex) favouriteDayNavigator->show(); } break; - case 2: //index 2 of tabWidget: activitiesTab + case 2: //index 2 of tabWidget: trackTab { - static_cast(actTreeView->model())->loadEventsByActivities(Conference::getById(confId).start(), confId); - actTreeView->reset(); - activityDayNavigator->show(); + static_cast(trackTreeView->model())->loadEventsByTrack(Conference::getById(confId).start(), confId); + trackTreeView->reset(); + trackDayNavigator->show(); } break; default: @@ -220,14 +220,14 @@ void MainWindow::updateTab(const int aIndex) }; } -void MainWindow::updateActivitiesDayView(const QDate &aDate) +void MainWindow::updateTracksView(const QDate &aDate) { - static_cast(actTreeView->model())->loadEventsByActivities(aDate, confId); - actTreeView->reset(); - activityDayNavigator->show(); + static_cast(trackTreeView->model())->loadEventsByTrack(aDate, confId); + trackTreeView->reset(); + trackDayNavigator->show(); } -void MainWindow::updateFavouritesDayView(const QDate &aDate) +void MainWindow::updateFavouritesView(const QDate &aDate) { static_cast(favTreeView->model())->loadFavEvents(aDate,confId); favTreeView->reset(); diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index c55b121..25fa6c8 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -22,8 +22,8 @@ private slots: void aboutApp(); void updateDayView(const QDate &aDate); void updateTab(const int n); - void updateActivitiesDayView(const QDate &aDate); - void updateFavouritesDayView(const QDate &aDate); + void updateTracksView(const QDate &aDate); + void updateFavouritesView(const QDate &aDate); void itemClicked(const QModelIndex &aIndex); void displayMap(const QModelIndex &aIndex); void searchClicked(); diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index c2df896..57d3afa 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -5,8 +5,8 @@ 0 0 - 531 - 373 + 609 + 431 @@ -68,16 +68,16 @@ - Activities + Tracks - + - + 16777215 @@ -90,89 +90,89 @@ - - + + Search - - - - - QFormLayout::AllNonFixedFieldsGrow - - - - - Title - - - - - - - - - true - - - type a keyword to search - - - - - - - Search - - - false - - - false - - - true - - - false - - - - - - - - - Abstract - - - - - - - - - - 16777215 - 16777215 - - - - - - - - - 16777215 - 16777215 - - - - - + + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + Title + + + + + + + + + true + + + type a keyword to search + + + + + + + Search + + + false + + + false + + + true + + + false + + + + + + + + + Abstract + + + + + + + + + + 16777215 + 16777215 + + + + + + + + + 16777215 + 16777215 + + + + + - - + + Map @@ -185,7 +185,7 @@ 0 0 - 531 + 609 22 diff --git a/src/mvc/activity.cpp b/src/mvc/activity.cpp deleted file mode 100644 index 2ff2d6b..0000000 --- a/src/mvc/activity.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * activity.cpp - * - * Created on: Dec 27, 2009 - * Author: Pavol Korinek - */ - -#include "activity.h" - -QString const Activity::sTableName = QString("activity"); -int const Activity::sTableColCount = 2; - -QSqlRecord const Activity::sColumns = Activity::toRecord(QList() - << QSqlField("id", QVariant::Int) - << QSqlField("name", QVariant::String)); - -QMap Activity::mIdToActivity; - -QList Activity::getAll() -{ - QSqlQuery query; - query.prepare(selectQuery()); - return load(query); -} - -void Activity::updateActivityMap() -{ - mIdToActivity.clear(); - QList activityList = Activity::getAll(); - Activity activity; - for (int id = 0; id < activityList.count(); ++id) { - activity = activityList.at(id); - mIdToActivity.insert(activity.id(), activity); - } -} - -QString Activity::getActivityName(int id) -{ - QString name = mIdToActivity.value(id).name(); - if (name == "") { - qDebug() << QString("Error: undefined activity name for id %1").arg(id); - } - return name; -} diff --git a/src/mvc/delegate.cpp b/src/mvc/delegate.cpp index 59d6489..54808b8 100644 --- a/src/mvc/delegate.cpp +++ b/src/mvc/delegate.cpp @@ -1,6 +1,6 @@ #include "delegate.h" #include "eventmodel.h" -#include +#include #include #include @@ -62,7 +62,7 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons fontBigB.setBold(true); QFontMetrics fmBigB(fontBigB); - int spacer = (fmSmall.boundingRect("999").width() < SPACER) ? SPACER : fmSmall.boundingRect("999").width(); + //int spacer = (fmSmall.boundingRect("999").width() < SPACER) ? SPACER : fmSmall.boundingRect("999").width(); if(isLast(index)) { @@ -164,7 +164,7 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons painter->drawText(titlePointF,"Presenter(s): " + event->persons().join(" and ")); // track titlePointF.setY(titlePointF.y()+fmSmall.height()-fmSmall.descent()); - painter->drawText(titlePointF,"Activity(s): " + Activity::getActivityName(event->activityId())); + painter->drawText(titlePointF,"Track: " + Track::getTrackName(event->trackId())); } else // doesn't have parent - time-groups' elements (top items) { diff --git a/src/mvc/event.cpp b/src/mvc/event.cpp index 18b6e33..022a8ac 100644 --- a/src/mvc/event.cpp +++ b/src/mvc/event.cpp @@ -7,10 +7,6 @@ QString const Event::sTable1Name = QString("event"); QString const Event::sTable2Name = QString("virtual_event"); int const Event::sTable1ColCount = 9; // see 'toRecord()' for more details int const Event::sTable2ColCount = 5; // see 'toRecord()' for more details -const QString Event::XID_ACTIVITY = "xid_activity"; -const QString Event::START = "start"; - - QSqlRecord const Event::sColumns = Event::toRecord(QList() /* 'columns from Table 1 */ @@ -18,7 +14,7 @@ QSqlRecord const Event::sColumns = Event::toRecord(QList() << QSqlField("xid_conference", QVariant::Int) << QSqlField("start", QVariant::DateTime) << QSqlField("duration", QVariant::Int) - << QSqlField("xid_activity", QVariant::Int) + << QSqlField("xid_track", QVariant::Int) << QSqlField("type", QVariant::String) << QSqlField("language", QVariant::String) << QSqlField("favourite", QVariant::Bool) diff --git a/src/mvc/event.h b/src/mvc/event.h index 8c99f4f..2b392dc 100644 --- a/src/mvc/event.h +++ b/src/mvc/event.h @@ -23,8 +23,6 @@ public: static const QString sTable2Name; static const int sTable1ColCount; static const int sTable2ColCount; - static const QString XID_ACTIVITY; - static const QString START; public: static Event getById(int id, int conferenceId); static QList getByDate(const QDate & date, int conferenceId, QString orderBy); @@ -33,9 +31,9 @@ public: // Table 1 int id() const { return value("id").toInt(); } int conferenceId() const { return value("xid_conference").toInt(); } - QDateTime start() const { return value(START).toDateTime(); } + QDateTime start() const { return value("start").toDateTime(); } int duration() const { return value("duration").toInt(); } - int activityId() const { return value(XID_ACTIVITY).toInt(); } + int trackId() const { return value("xid_track").toInt(); } QString type() const { return value("type").toString(); } QString language() const { return value("language").toString(); } bool isFavourite() const { return value("favourite").toBool(); } @@ -54,9 +52,9 @@ public: // Table 1 void setId(int id) { setValue("id", id); } void setConferenceId(int conferenceId) { setValue("xid_conference", conferenceId); } - void setStart(const QDateTime & start) { setValue(START, start); } + void setStart(const QDateTime & start) { setValue("start", start); } void setDuration(int duration) { setValue("duration", duration); } - void setActivityId(int activityId) { setValue(XID_ACTIVITY, activityId); } + void setTrackId(int trackId) { setValue("xid_track", trackId); } void setType(const QString & type) { setValue("type", type); } void setLanguage(const QString & language) { setValue("language", language); } void setFavourite(bool favourite) { setValue("favourite", (int)((favourite))); } diff --git a/src/mvc/eventmodel.cpp b/src/mvc/eventmodel.cpp index 498677c..c877f02 100644 --- a/src/mvc/eventmodel.cpp +++ b/src/mvc/eventmodel.cpp @@ -1,8 +1,6 @@ #include "eventmodel.h" #include -#include - -const QString EventModel::COMMA_SEPARATOR = ", "; +#include EventModel::EventModel() { @@ -45,26 +43,26 @@ void EventModel::createTimeGroups() mGroups.last().mChildCount = mEvents.count() - mGroups.last().mFirstEventIndex; } -void EventModel::createActivityGroups() { +void EventModel::createTrackGroups() { mGroups.clear(); mParents.clear(); if (mEvents.empty()) { return; } - int activityId = mEvents.first().activityId(); + int trackId = mEvents.first().trackId(); - mGroups << EventModel::Group(Activity::getActivityName(activityId), 0); - int nextActivityId = activityId; + mGroups << EventModel::Group(Track::getTrackName(trackId), 0); + int nextTrackId = trackId; for (int i=0; i() + << QSqlField("id", QVariant::Int) + << QSqlField("name", QVariant::String)); + +QMap Track::mIdToTrack; + +QList Track::getAll() +{ + QSqlQuery query; + query.prepare(selectQuery()); + return load(query); +} + +void Track::updateTrackMap() +{ + mIdToTrack.clear(); + QList trackList = Track::getAll(); + Track track; + for (int id = 0; id < trackList.count(); ++id) { + track = trackList.at(id); + mIdToTrack.insert(track.id(), track); + } +} + +QString Track::getTrackName(int id) +{ + QString name = mIdToTrack.value(id).name(); + if (name == "") { + qDebug() << QString("Error: undefined track name for id %1").arg(id); + } + return name; +} diff --git a/src/mvc/activity.h b/src/mvc/track.h similarity index 62% rename from src/mvc/activity.h rename to src/mvc/track.h index 7a300ec..194fe9c 100644 --- a/src/mvc/activity.h +++ b/src/mvc/track.h @@ -1,32 +1,33 @@ /* - * activity.h + * track.h * * Created on: Dec 27, 2009 * Author: Pavol Korinek */ -#ifndef ACTIVITY_H_ -#define ACTIVITY_H_ +#ifndef TRACK_H +#define TRACK_H #include -class Activity : public OrmRecord +class Track : public OrmRecord { public: static const QSqlRecord sColumns; static QString const sTableName; static const int sTableColCount; public: - static QMap mIdToActivity; + static QMap mIdToTrack; public: - static QList getAll(); + static QList getAll(); int id() const { return value("id").toInt(); } void setId(int id) { setValue("id", id); } QString name() const { return value("name").toString(); } void setName(const QString & type) { setValue("name", type); } public: - static void updateActivityMap(); - static QString getActivityName(int id); + static void updateTrackMap(); + static QString getTrackName(int id); }; -#endif /* ACTIVITY_H_ */ +#endif /* TRACK_H */ + diff --git a/src/sql/sqlengine.cpp b/src/sql/sqlengine.cpp index d0efe13..d74792b 100644 --- a/src/sql/sqlengine.cpp +++ b/src/sql/sqlengine.cpp @@ -86,24 +86,23 @@ void SqlEngine::addEventToDB(QHash &aEvent) if (db.isValid() && db.isOpen()) { - // track/activity has to be handled as the first, since it is necessary to get - // track ID from the ACTIVITY table, or to create new ACTIVITY record + // 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 activity WHERE name='%1'").arg(aEvent["track"]); + QString queryExist = QString("SELECT id FROM track WHERE name='%1'").arg(aEvent["track"]); QSqlQuery resultExist(queryExist,db); - // now we have to check whether ACTIVITY record with 'name' exists or not, - // - if it doesn't exist yet, then we have to add that record to 'ACTIVITY' table - // and assign autoincremented 'id' to aActivity - // - if it exists, then we need to get its 'id' and assign it to aRoom + // 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()) // ACTIVITY record with 'name' already exists: we need to get its 'id' + if(resultExist.next()) // TRACK record with 'name' already exists: we need to get its 'id' { actId = resultExist.value(0).toInt(); } - else // ACTIVITY record doesn't exist yet, need to create it + else // TRACK record doesn't exist yet, need to create it { QString values = QString("'%1'").arg(aEvent["track"]); - QString query = QString("INSERT INTO activity (name) VALUES (%1)").arg(values); + QString query = QString("INSERT INTO track (name) VALUES (%1)").arg(values); QSqlQuery result (query, db); actId = result.lastInsertId().toInt(); // 'id' is assigned automatically } @@ -122,7 +121,7 @@ void SqlEngine::addEventToDB(QHash &aEvent) .arg("0") \ .arg("0"); - QString query = QString("INSERT INTO EVENT (xid_conference, id, start, duration, xid_activity, type, language, favourite, alarm) VALUES (%1)").arg(values); + QString query = QString("INSERT INTO EVENT (xid_conference, id, start, duration, xid_track, type, language, favourite, alarm) VALUES (%1)").arg(values); QSqlQuery result (query, db); //LOG_AUTOTEST(query); @@ -232,7 +231,7 @@ bool SqlEngine::createTables(QSqlDatabase &aDatabase) day_change INTEGER, \ timeslot_duration INTEGER)"); - query.exec("CREATE TABLE ACTIVITY ( \ + query.exec("CREATE TABLE TRACK ( \ id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , \ name VARCHAR NOT NULL )"); @@ -250,14 +249,14 @@ bool SqlEngine::createTables(QSqlDatabase &aDatabase) id INTEGER NOT NULL , \ start INTEGER NOT NULL , \ duration INTEGER NOT NULL , \ - xid_activity INTEGER NOT NULL REFERENCES ACTIVITY(id), \ + xid_track INTEGER NOT NULL REFERENCES TRACK(id), \ type VARCHAR, \ language VARCHAR, \ favourite INTEGER DEFAULT 0, \ alarm INTEGER DEFAULT 0, \ PRIMARY KEY (xid_conference,id), \ FOREIGN KEY(xid_conference) REFERENCES CONFERENCE(id) \ - FOREIGN KEY(xid_activity) REFERENCES ACTIVITY(id))"); + FOREIGN KEY(xid_track) REFERENCES TRACK(id))"); #ifdef MAEMO // TBD: MAEMO Virtual tables compatibility (waiting for Marek). diff --git a/src/test/mvc/eventtest.cpp b/src/test/mvc/eventtest.cpp index 232421a..59b0eb3 100644 --- a/src/test/mvc/eventtest.cpp +++ b/src/test/mvc/eventtest.cpp @@ -21,7 +21,7 @@ void EventTest::getById() QCOMPARE(event.id(), 500); QCOMPARE(event.start(), QDateTime(QDate(2009, 2, 7), QTime(11, 30, 0), Qt::UTC)); - QCOMPARE(event.activityId(), 123); + QCOMPARE(event.trackId(), 123); // !!! TODO: typeId and languageId QCOMPARE(event.type(), QString("Podium")); @@ -42,7 +42,7 @@ void EventTest::storingValues() event.setConferenceId(20); event.setStart(QDateTime::fromString("Sat Feb 7 11:30:00 2009")); event.setDuration(30); - event.setActivityId(40); + event.setTrackId(40); event.setType(QString("type")); event.setLanguage(QString("language")); @@ -50,7 +50,7 @@ void EventTest::storingValues() QCOMPARE(event.conferenceId(), 20); QCOMPARE(event.start(), QDateTime::fromString("Sat Feb 7 11:30:00 2009")); QCOMPARE(event.duration(), 30); - QCOMPARE(event.activityId(), 40); + QCOMPARE(event.trackId(), 40); QCOMPARE(event.type(), QString("type")); QCOMPARE(event.language(), QString("language")); } @@ -70,12 +70,12 @@ void EventTest::hydrate() void EventTest::columnsForSelect() { - QCOMPARE(Event::columnsForSelect(), QString("id,xid_conference,start,duration,xid_activity,type,language")); + QCOMPARE(Event::columnsForSelect(), QString("id,xid_conference,start,duration,xid_track,type,language")); QCOMPARE(Event::columnsForSelect("t0"), - QString("t0.id,t0.xid_conference,t0.start,t0.duration,t0.xid_activity,t0.type,t0.language")); + QString("t0.id,t0.xid_conference,t0.start,t0.duration,t0.xid_track,t0.type,t0.language")); } void EventTest::selectQuery() { - QCOMPARE(Event::selectQuery(), QString("SELECT id,xid_conference,start,duration,xid_activity,type,language FROM event ")); + QCOMPARE(Event::selectQuery(), QString("SELECT id,xid_conference,start,duration,xid_track,type,language FROM event ")); } -- 2.39.5