From 04acaf943745237b9afdf4f83dde2457b3120933 Mon Sep 17 00:00:00 2001 From: kirilma Date: Thu, 15 Apr 2010 12:50:23 +0000 Subject: [PATCH] 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 --- src/gui/mainwindow.cpp | 64 +++++++++++++++++++++++++++++----------- src/gui/mainwindow.h | 3 ++ src/gui/tabcontainer.cpp | 13 ++++++-- src/gui/tabcontainer.h | 1 + src/mvc/eventmodel.cpp | 19 +++++------- src/mvc/eventmodel.h | 2 +- 6 files changed, 71 insertions(+), 31 deletions(-) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index b2d33d7..80321c3 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -50,6 +50,8 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent) { setupUi(this); + saved_title = windowTitle(); + #ifdef N810 tabWidget->setTabText(1,"Favs"); //tabWidget->setTabText(2,"Day"); @@ -98,22 +100,17 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent) fillAndShowConferenceHeader(); setWindowTitle(Conference::getById(confId).title()); - if(confCount==1) // don't have to show 'selectConference' widget, if there is only one conference in the DB - selectConferenceWidget->hide(); - else + QList confs = Conference::getAll(); + QListIterator i(confs); + while(i.hasNext()) { - // have to fill comboBox with available conferences - QList confs = Conference::getAll(); - QListIterator i(confs); - while(i.hasNext()) - { - Conference conf = i.next(); - selectConference->addItem(conf.title(),conf.id()); - } - int idx = selectConference->findText(Conference::getById(Conference::activeConference()).title()); - selectConference->setCurrentIndex(idx); + Conference conf = i.next(); + selectConference->addItem(conf.title(),conf.id()); } + int idx = selectConference->findText(Conference::getById(Conference::activeConference()).title()); + selectConference->setCurrentIndex(idx); connect(selectConference, SIGNAL(currentIndexChanged(int)), SLOT(conferenceChanged(int))); + conferenceChanged(idx); } else { @@ -154,8 +151,7 @@ void MainWindow::scheduleImported(int aConfId) int idx = selectConference->findText(conf.title()); selectConference->setCurrentIndex(idx); - if(confCount>1) - selectConferenceWidget->show(); + selectConferenceWidget->show(); conferenceChanged(idx); } @@ -168,6 +164,14 @@ void MainWindow::scheduleDeleted(const QString& title) if (idx == -1) { // should not happen qWarning() << __PRETTY_FUNCTION__ << "removed non-existent item:" << title; + // this happens when you remove the only conference (the list is not ptoperly inited in this case) + // now make sure that conferencet + if (selectConference->count() > 0) { + selectConference->setCurrentIndex(0); + conferenceChanged(0); + } else { + conferenceChanged(-1); + } } else { // will it signal "changed"? selectConference->removeItem(idx); @@ -237,10 +241,36 @@ void MainWindow::initTabs() nowTabContainer->updateTreeView(QDate::currentDate()); } +void MainWindow::unsetConference() +{ + dayTabContainer->clearModel(); + tracksTabContainer->clearModel(); + roomsTabContainer->clearModel(); + favsTabContainer->clearModel(); + searchTabContainer->clearModel(); + searchTabContainer->searchAgainClicked(); + nowTabContainer->clearModel(); + + conferenceHeader->hide(); + setWindowTitle(saved_title); +} + void MainWindow::conferenceChanged(int aIndex) { - Conference::getById(Conference::activeConference()).update("active",0); - Conference::getById(selectConference->itemData(aIndex).toInt()).update("active",1); + if (aIndex < 0) { + // no conferences left? reset all views + unsetConference(); + return; + } + + try { + Conference::getById(Conference::activeConference()).update("active",0); + Conference::getById(selectConference->itemData(aIndex).toInt()).update("active",1); + } catch (OrmException& e) { + // cannon set an active conference + unsetConference(); + return; + } initTabs(); fillAndShowConferenceHeader(); diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 7740b85..c069636 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -42,6 +42,9 @@ private slots: private: void fillAndShowConferenceHeader(); void initTabs(); + void unsetConference(); + + QString saved_title; }; #endif /* MAINWINDOW_H */ diff --git a/src/gui/tabcontainer.cpp b/src/gui/tabcontainer.cpp index 04c1bd9..01900d8 100644 --- a/src/gui/tabcontainer.cpp +++ b/src/gui/tabcontainer.cpp @@ -55,9 +55,13 @@ TabContainer::TabContainer(QWidget *aParent) void TabContainer::updateTreeView(const QDate &aDate) { + int active_id = Conference::activeConference(); dayNavigator->show(); - loadEvents( aDate, Conference::activeConference() ); - treeView->reset(); + if (active_id > 0) { + loadEvents(aDate, active_id); + } else { + static_cast(treeView->model())->clearModel(); + } } void TabContainer::itemClicked(const QModelIndex &aIndex) @@ -132,3 +136,8 @@ void TabContainer::setDates(const QDate &aStart, const QDate &aEnd) dayNavigator->setDates(aStart, aEnd); } +void TabContainer::clearModel() +{ + static_cast(treeView->model())->clearModel(); +} + diff --git a/src/gui/tabcontainer.h b/src/gui/tabcontainer.h index e292c06..c4a4b88 100644 --- a/src/gui/tabcontainer.h +++ b/src/gui/tabcontainer.h @@ -35,6 +35,7 @@ public: TabContainer(QWidget *aParent = NULL); virtual ~TabContainer() {} + void clearModel(); protected: virtual void loadEvents( const QDate &aDate, const int aConferenceId ) { diff --git a/src/mvc/eventmodel.cpp b/src/mvc/eventmodel.cpp index a9cca04..c57702a 100644 --- a/src/mvc/eventmodel.cpp +++ b/src/mvc/eventmodel.cpp @@ -24,9 +24,7 @@ const QString EventModel::COMMA_SEPARATOR = ", "; EventModel::EventModel() -{ - mEvents.clear(); -} +{ } void EventModel::createTimeGroups() { @@ -62,6 +60,8 @@ void EventModel::createTimeGroups() } mGroups.last().mChildCount = mEvents.count() - mGroups.last().mFirstEventIndex; + + reset(); } void EventModel::createTrackGroups() { @@ -199,15 +199,12 @@ int EventModel::rowCount (const QModelIndex & parent) const void EventModel::clearModel() { - for(int i = 0;i < mGroups.count();i++){ - QModelIndex idx = index(i, 0); - Group group = mGroups[i]; - beginRemoveRows(idx, 0, group.mChildCount - 1); - /*bool ok =*/ removeRows(0, group.mChildCount, idx); - endRemoveRows(); - //qDebug() << "removing " << group.mChildCount << " events from group:" << i << idx.data() << ":" << ok; - } + qDebug() << __PRETTY_FUNCTION__ << this << mEvents.count(); + mGroups.clear(); mEvents.clear(); + mParents.clear(); + + reset(); } void EventModel::loadEvents(const QDate &aDate, int aConferenceId) diff --git a/src/mvc/eventmodel.h b/src/mvc/eventmodel.h index 9e90ec4..5a21f36 100644 --- a/src/mvc/eventmodel.h +++ b/src/mvc/eventmodel.h @@ -41,6 +41,7 @@ public: void loadNowEvents(int aConferenceId); // loads Now events from the DB void loadEventsByRoom(const QDate &aDate, int aConferenceId); void loadConflictEvents(int aEventId, int aConferenceId); // loads events in conflict + void clearModel(); private: struct Group @@ -62,7 +63,6 @@ private: void createTimeGroups(); void createTrackGroups(); void createTrackGroupsNew(); - void clearModel(); void createRoomGroups(); public slots: -- 2.39.5