Ignore:
Timestamp:
04/15/10 14:50:23 (12 years ago)
Author:
kirilma <kirilma@…>
Branches:
master, qt5
Children:
2eda137
Parents:
d97bcab
Message:

fix deletion of last conference

implement for cleaning all views in the tabs
clean the models when no active conference found
fix cleaning model and signalling views

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/gui/mainwindow.cpp

    rd97bcab r04acaf9  
    5151    setupUi(this);
    5252
     53    saved_title = windowTitle();
     54
    5355#ifdef N810
    5456    tabWidget->setTabText(1,"Favs");
     
    99101        setWindowTitle(Conference::getById(confId).title());
    100102
    101         if(confCount==1) // don't have to show 'selectConference' widget, if there is only one conference in the DB
    102             selectConferenceWidget->hide();
    103         else
     103        QList<Conference> confs = Conference::getAll();
     104        QListIterator<Conference> i(confs);
     105        while(i.hasNext())
    104106        {
    105             // have to fill comboBox with available conferences
    106             QList<Conference> confs = Conference::getAll();
    107             QListIterator<Conference> i(confs);
    108             while(i.hasNext())
    109             {
    110                 Conference conf = i.next();
    111                 selectConference->addItem(conf.title(),conf.id());
    112             }
    113             int idx = selectConference->findText(Conference::getById(Conference::activeConference()).title());
    114             selectConference->setCurrentIndex(idx);
     107            Conference conf = i.next();
     108            selectConference->addItem(conf.title(),conf.id());
    115109        }
     110        int idx = selectConference->findText(Conference::getById(Conference::activeConference()).title());
     111        selectConference->setCurrentIndex(idx);
    116112        connect(selectConference, SIGNAL(currentIndexChanged(int)), SLOT(conferenceChanged(int)));
     113        conferenceChanged(idx);
    117114    }
    118115    else
     
    155152        selectConference->setCurrentIndex(idx);
    156153
    157         if(confCount>1)
    158             selectConferenceWidget->show();
     154        selectConferenceWidget->show();
    159155
    160156        conferenceChanged(idx);
     
    169165        // should not happen
    170166        qWarning() << __PRETTY_FUNCTION__ << "removed non-existent item:" << title;
     167        // this happens when you remove the only conference (the list is not ptoperly inited in this case)
     168        // now make sure that conferencet
     169        if (selectConference->count() > 0) {
     170            selectConference->setCurrentIndex(0);
     171            conferenceChanged(0);
     172        } else {
     173            conferenceChanged(-1);
     174        }
    171175    } else {
    172176        // will it signal "changed"?
     
    238242}
    239243
     244void MainWindow::unsetConference()
     245{
     246    dayTabContainer->clearModel();
     247    tracksTabContainer->clearModel();
     248    roomsTabContainer->clearModel();
     249    favsTabContainer->clearModel();
     250    searchTabContainer->clearModel();
     251    searchTabContainer->searchAgainClicked();
     252    nowTabContainer->clearModel();
     253
     254    conferenceHeader->hide();
     255    setWindowTitle(saved_title);
     256}
     257
    240258void MainWindow::conferenceChanged(int aIndex)
    241259{
    242     Conference::getById(Conference::activeConference()).update("active",0);
    243     Conference::getById(selectConference->itemData(aIndex).toInt()).update("active",1);
     260    if (aIndex < 0) {
     261        // no conferences left? reset all views
     262        unsetConference();
     263        return;
     264    }
     265
     266    try {
     267        Conference::getById(Conference::activeConference()).update("active",0);
     268        Conference::getById(selectConference->itemData(aIndex).toInt()).update("active",1);
     269    } catch (OrmException& e) {
     270        // cannon set an active conference
     271        unsetConference();
     272        return;
     273    }
    244274
    245275    initTabs();
Note: See TracChangeset for help on using the changeset viewer.