1 #include "tabcontainer.h"
7 #include <appsettings.h>
9 #include <conference.h>
12 #include <eventmodel.h>
15 #include "eventdialog.h"
16 #include "mapwindow.h"
18 TabContainer::TabContainer(QWidget *aParent)
20 , mType(EContainerTypeNone)
24 searchAgainButton->hide();
26 treeView->setHeaderHidden(true);
27 treeView->setRootIsDecorated(false);
28 treeView->setIndentation(0);
29 treeView->setAnimated(true);
30 treeView->setModel(new EventModel());
31 treeView->setItemDelegate(new Delegate(treeView));
33 connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateTreeView(const QDate &)));
35 connect(treeView, SIGNAL(eventHasChanged(int)), SIGNAL(eventHasChanged(int)));
36 connect(treeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
37 connect(treeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
38 connect(treeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
40 if(!Conference::getAll().count()) // no conference(s) in the DB
42 dayNavigator->hide(); // hide DayNavigatorWidget
46 QDate aStartDate = Conference::getById(AppSettings::confId()).start();
47 QDate aEndDate = Conference::getById(AppSettings::confId()).end();
48 dayNavigator->setDates(aStartDate, aEndDate);
52 void TabContainer::setType(TabContainer::Type aType)
55 if(aType == EContainerTypeNow)
57 QTimer *timer = new QTimer( this );
58 connect( timer, SIGNAL(timeout()), SLOT(timerUpdateTreeView()) );
59 timer->start( 30000); // 30 seconds timer
63 void TabContainer::updateTreeView(const QDate &aDate)
67 case EContainerTypeDay:
69 static_cast<EventModel*>(treeView->model())->loadEvents(aDate,AppSettings::confId());
72 case EContainerTypeFavs:
74 static_cast<EventModel*>(treeView->model())->loadFavEvents(aDate,AppSettings::confId());
77 case EContainerTypeTracks:
79 static_cast<EventModel*>(treeView->model())->loadEventsByTrack(aDate, AppSettings::confId());
82 case EContainerTypeRooms:
84 static_cast<EventModel*>(treeView->model())->loadEventsByRoom(aDate, AppSettings::confId());
87 case EContainerTypeNow:
89 static_cast<EventModel*>(treeView->model())->loadNowEvents(AppSettings::confId());
90 treeView->setAllExpanded(true);
93 case EContainerTypeNone:
96 qDebug() << "Container type not specified";
100 dayNavigator->show();
103 void TabContainer::itemClicked(const QModelIndex &aIndex)
105 // have to handle only events, not time-groups
106 if(!aIndex.parent().isValid()) // time-group
109 EventDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this);
113 void TabContainer::displayMap(const QModelIndex &aIndex)
115 Event *event = static_cast<Event*>(aIndex.internalPointer());
117 // room names are stored in lower-case format
118 // room names are stored without dots in the name, eg. "aw.1124.png" -> "aw1124.png"
119 QString mapPath = QString(":/maps/rooms/%1.png").arg(event->room().toLower().remove("."));
120 if(!QFile::exists(mapPath))
121 mapPath = QString(":/maps/rooms/not-available.png");
124 if(mapPath.contains("not-available", Qt::CaseInsensitive))
125 roomName = QString("Map is not available: %1").arg(event->room());
127 roomName = event->room();
129 QPixmap map(mapPath);
130 MapWindow window(map,roomName,this);
134 void TabContainer::displayWarning(const QModelIndex &aIndex)
138 QMessageBox::warning(
140 tr("Time Conflict Warning"),
141 tr("This event happens at the same time than another one of your favourites.") );
144 void TabContainer::updateTreeViewModel(int aEventId)
148 case EContainerTypeFavs:
150 // requires special handling
151 // we need to reload favourites, because some favourite could be deleted
152 //static_cast<EventModel*>(favTreeView->model())->updateModel(aEventId);
153 QDate aStartDate = Conference::getById(AppSettings::confId()).start();
154 QDate aEndDate = Conference::getById(AppSettings::confId()).end();
155 dayNavigator->setDates(aStartDate, aEndDate);
156 updateTreeView( Conference::getById(AppSettings::confId()).start() );
159 case EContainerTypeDay:
160 case EContainerTypeNone:
163 static_cast<EventModel*>(treeView->model())->updateModel(aEventId);
168 void TabContainer::setDates(const QDate &aStart, const QDate &aEnd)
170 dayNavigator->setDates(aStart, aEnd);
173 void TabContainer::timerUpdateTreeView()
175 if(mType == EContainerTypeNow)
177 updateTreeView(QDate());