source: src/gui/tabcontainer.cpp @ a61c5f5

qt5
Last change on this file since a61c5f5 was 04acaf9, checked in by kirilma <kirilma@…>, 12 years ago

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

  • Property mode set to 100644
File size: 4.7 KB
Line 
1/*
2 * Copyright (C) 2010 Ixonos Plc.
3 *
4 * This file is part of fosdem-schedule.
5 *
6 * fosdem-schedule is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * fosdem-schedule is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * fosdem-schedule.  If not, see <http://www.gnu.org/licenses/>.
18 */
19#include "tabcontainer.h"
20
21#include <QFile>
22#include <QMessageBox>
23#include <QTimer>
24
25#include <treeview.h>
26#include <delegate.h>
27
28#include "eventdialog.h"
29#include "mapwindow.h"
30
31#include "conflictsdialog.h"
32
33TabContainer::TabContainer(QWidget *aParent)
34    : QWidget(aParent)
35{
36    setupUi(this);
37
38    treeView->setHeaderHidden(true);
39    treeView->setRootIsDecorated(false);
40    treeView->setIndentation(0);
41    treeView->setAnimated(true);
42    treeView->setModel(new EventModel());
43    treeView->setItemDelegate(new Delegate(treeView));
44
45    connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateTreeView(const QDate &)));
46
47    connect(treeView, SIGNAL(eventHasChanged(int,bool)), SIGNAL(eventHasChanged(int,bool)));
48    connect(treeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
49    connect(treeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
50    connect(treeView, SIGNAL(requestForConflicts(const QModelIndex &)), SLOT(displayConflicts(const QModelIndex &)));
51
52    // day navigator is hidden by default
53    dayNavigator->hide();
54}
55
56void TabContainer::updateTreeView(const QDate &aDate)
57{
58    int active_id = Conference::activeConference();
59    dayNavigator->show();
60    if (active_id > 0) {
61        loadEvents(aDate, active_id);
62    } else {
63        static_cast<EventModel*>(treeView->model())->clearModel();
64    }
65}
66
67void TabContainer::itemClicked(const QModelIndex &aIndex)
68{
69    // have to handle only events, not time-groups
70    if(!aIndex.parent().isValid()) // time-group
71        return;
72
73    EventDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this);
74#ifdef N810
75    dialog.setFixedWidth(static_cast<QWidget*>(parent())->width());
76#endif
77    connect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool)));
78    dialog.exec();
79    disconnect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool)));
80}
81
82void TabContainer::displayMap(const QModelIndex &aIndex)
83{
84    Event *event = static_cast<Event*>(aIndex.internalPointer());
85
86    // room names are stored in lower-case format
87    // room names are stored without dots in the name, eg. "aw.1124.png" -> "aw1124.png"
88    QString mapPath = QString(":/maps/rooms/%1.png").arg(event->room().toLower().remove("."));
89    if(!QFile::exists(mapPath))
90        mapPath = QString(":/maps/rooms/not-available.png");
91
92    QString roomName;
93    if(mapPath.contains("not-available", Qt::CaseInsensitive))
94        roomName = QString("Map is not available: %1").arg(event->room());
95    else
96        roomName = event->room();
97
98    QPixmap map(mapPath);
99    MapWindow window(map,roomName,this);
100    window.exec();
101}
102
103void TabContainer::displayConflicts(const QModelIndex &aIndex)
104{
105    ConflictsDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this);
106#ifdef N810
107    dialog.setFixedWidth(static_cast<QWidget*>(parent())->width());
108#endif
109    connect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool)));
110    dialog.exec();
111    disconnect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool)));
112}
113
114void TabContainer::updateTreeViewModel(int aEventId, bool aReloadModel)
115{
116    if(aReloadModel)
117    {
118        // requires special handling
119        // eg. in case of favourities - some favourities may have changed
120        // and so we need to reload them
121        int confId = Conference::activeConference();
122        QDate startDate = Conference::getById(confId).start();
123        QDate endDate = Conference::getById(confId).end();
124        dayNavigator->setDates(startDate, endDate);
125        updateTreeView( Conference::getById(confId).start() );
126    }
127    else
128    {
129        // just update event in the question
130        static_cast<EventModel*>(treeView->model())->updateModel(aEventId);
131    }
132}
133
134void TabContainer::setDates(const QDate &aStart, const QDate &aEnd)
135{
136    dayNavigator->setDates(aStart, aEnd);
137}
138
139void TabContainer::clearModel()
140{
141    static_cast<EventModel*>(treeView->model())->clearModel();
142}
143
Note: See TracBrowser for help on using the repository browser.