Ignore:
Timestamp:
01/18/10 16:25:57 (12 years ago)
Author:
korrco <korrco@…>
Branches:
master, qt5
Children:
28d9e28
Parents:
b6cd05c
Message:

activities tab implemented - not finished yet

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mvc/eventmodel.cpp

    rb6cd05c rf6300c7  
    4343}
    4444
     45void EventModel::createActivityGroups() {
     46    mGroups.clear();
     47    mParents.clear();
     48    if (mEvents.empty())
     49    {
     50        return;
     51    }
     52    int activityId = mEvents.first().activityId();
     53    //TODO korinpa: get activity name
     54    mGroups << EventModel::Group(QString("activity %1").arg(activityId), 0);
     55    int nextActivityId = activityId;
     56
     57    for (int i=0; i<mEvents.count(); i++)
     58    {
     59        activityId = mEvents.at(i).activityId();
     60        if (nextActivityId != activityId)
     61        {
     62            mGroups.last().mChildCount = i - mGroups.last().mFirstEventIndex;
     63            mGroups << EventModel::Group(QString("activity %1").arg(activityId), 0);
     64            int nextActivityId = activityId;
     65        }
     66        // add parent-child relation
     67        mParents[mEvents.at(i).id()] = mGroups.count() - 1;
     68    }
     69    mGroups.last().mChildCount = mEvents.count() - mGroups.last().mFirstEventIndex;
     70}
     71
    4572QVariant EventModel::data(const QModelIndex& index, int role) const
    4673{
     
    118145}
    119146
    120 void EventModel::loadEvents(const QDate &aDate, int aConferenceId)
    121 {
    122     for(int i=0; i<mGroups.count(); i++)
    123     {
    124         QModelIndex idx = index(i,0);
     147void EventModel::clearModel()
     148{
     149/*
     150    for(int i = 0;i < mGroups.count();i++){
     151        QModelIndex idx = index(i, 0);
    125152        Group group = mGroups[i];
    126         beginRemoveRows(idx,0,group.mChildCount-1);
    127         removeRows(0,group.mChildCount,idx);
     153        beginRemoveRows(idx, 0, group.mChildCount - 1);
     154        bool ok = removeRows(0, group.mChildCount, idx);
    128155        endRemoveRows();
    129156        //qDebug() << "removing " << group.mChildCount << " events from group:" << i << idx.data() << ":" << ok;
    130157    }
    131 
     158*/
     159    mGroups.clear();
    132160    mEvents.clear();
    133 
     161}
     162
     163void EventModel::loadEvents(const QDate &aDate, int aConferenceId)
     164{
     165    clearModel();
    134166    // check for existence of the conference in the DB
    135167    if(Conference::getAll().count())
     
    143175void EventModel::loadFavEvents(const QDate &aDate, int aConferenceId)
    144176{
    145     for(int i=0; i<mGroups.count(); i++)
    146     {
    147         QModelIndex idx = index(i,0);
    148         Group group = mGroups[i];
    149         beginRemoveRows(idx,0,group.mChildCount-1);
    150         removeRows(0,group.mChildCount,idx);
    151         endRemoveRows();
    152         //qDebug() << "removing " << group.mChildCount << " events from group:" << i << idx.data() << ":" << ok;
    153     }
    154 
    155     mEvents.clear();
    156 
     177    clearModel();
    157178    // check for existence of the conference in the DB
    158179    if(Conference::getAll().count())
     
    164185}
    165186
     187void EventModel::loadEventsByActivities(const QDate &aDate, int aConferenceId)
     188{
     189    clearModel();
     190    if(Conference::getAll().count())
     191        {
     192            qDebug() << "Loading Conference Data (by Activities): [" << Conference::getById(aConferenceId).title() << "] " << aDate;
     193            mEvents = Event::getByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId);
     194        }
     195    createActivityGroups();
     196}
     197
    166198void EventModel::emitDataChangedSignal(const QModelIndex &aTopLeft, const QModelIndex &aBottomRight)
    167199{
Note: See TracChangeset for help on using the changeset viewer.