1 #include "tabcontainer.h"
8 #include <appsettings.h>
10 #include <conference.h>
13 #include <eventmodel.h>
16 #include "eventdialog.h"
17 #include "mapwindow.h"
19 TabContainer::TabContainer(QWidget *aParent)
21 , mType(EContainerTypeNone)
25 searchAgainButton->hide();
28 treeView->setHeaderHidden(true);
29 treeView->setRootIsDecorated(false);
30 treeView->setIndentation(0);
31 treeView->setAnimated(true);
32 treeView->setModel(new EventModel());
33 treeView->setItemDelegate(new Delegate(treeView));
35 connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateTreeView(const QDate &)));
37 connect(treeView, SIGNAL(eventHasChanged(int)), SIGNAL(eventHasChanged(int)));
38 connect(treeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
39 connect(treeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
40 connect(treeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
42 connect(searchButton, SIGNAL(clicked()), SLOT(searchClicked()));
43 connect(searchAgainButton, SIGNAL(clicked()), SLOT(searchAgainClicked()));
45 if(!Conference::getAll().count()) // no conference(s) in the DB
47 dayNavigator->hide(); // hide DayNavigatorWidget
51 QDate aStartDate = Conference::getById(AppSettings::confId()).start();
52 QDate aEndDate = Conference::getById(AppSettings::confId()).end();
53 dayNavigator->setDates(aStartDate, aEndDate);
57 void TabContainer::setType(TabContainer::Type aType)
61 if(aType == EContainerTypeNow)
63 QTimer *timer = new QTimer( this );
64 connect( timer, SIGNAL(timeout()), SLOT(timerUpdateTreeView()) );
65 timer->start( 30000); // 30 seconds timer
67 if(aType == EContainerTypeSearch)
73 void TabContainer::updateTreeView(const QDate &aDate)
77 case EContainerTypeDay:
79 static_cast<EventModel*>(treeView->model())->loadEvents(aDate,AppSettings::confId());
82 case EContainerTypeFavs:
84 static_cast<EventModel*>(treeView->model())->loadFavEvents(aDate,AppSettings::confId());
87 case EContainerTypeTracks:
89 static_cast<EventModel*>(treeView->model())->loadEventsByTrack(aDate, AppSettings::confId());
92 case EContainerTypeRooms:
94 static_cast<EventModel*>(treeView->model())->loadEventsByRoom(aDate, AppSettings::confId());
97 case EContainerTypeNow:
99 static_cast<EventModel*>(treeView->model())->loadNowEvents(AppSettings::confId());
100 treeView->setAllExpanded(true);
103 case EContainerTypeSearch:
106 int eventsCount = static_cast<EventModel*>(treeView->model())->loadSearchResultEvents(aDate,AppSettings::confId());
108 dayNavigator->getCurrentDate() != Conference::getById(AppSettings::confId()).start() ){
109 searchAgainButton->show();
110 dayNavigator->show();
116 searchAgainButton->hide();
117 dayNavigator->hide();
122 case EContainerTypeNone:
125 qDebug() << "Container type not specified";
129 dayNavigator->show();
132 void TabContainer::itemClicked(const QModelIndex &aIndex)
134 // have to handle only events, not time-groups
135 if(!aIndex.parent().isValid()) // time-group
138 EventDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this);
139 connect(&dialog, SIGNAL(eventHasChanged(int)), this, SIGNAL(eventHasChanged(int)));
141 disconnect(&dialog, SIGNAL(eventHasChanged(int)), this, SIGNAL(eventHasChanged(int)));
144 void TabContainer::displayMap(const QModelIndex &aIndex)
146 Event *event = static_cast<Event*>(aIndex.internalPointer());
148 // room names are stored in lower-case format
149 // room names are stored without dots in the name, eg. "aw.1124.png" -> "aw1124.png"
150 QString mapPath = QString(":/maps/rooms/%1.png").arg(event->room().toLower().remove("."));
151 if(!QFile::exists(mapPath))
152 mapPath = QString(":/maps/rooms/not-available.png");
155 if(mapPath.contains("not-available", Qt::CaseInsensitive))
156 roomName = QString("Map is not available: %1").arg(event->room());
158 roomName = event->room();
160 QPixmap map(mapPath);
161 MapWindow window(map,roomName,this);
165 void TabContainer::displayWarning(const QModelIndex &aIndex)
169 QMessageBox::warning(
171 tr("Time Conflict Warning"),
172 tr("This event happens at the same time than another one of your favourites.") );
175 void TabContainer::updateTreeViewModel(int aEventId)
179 case EContainerTypeFavs:
181 // requires special handling
182 // we need to reload favourites, because some favourite could be deleted
183 //static_cast<EventModel*>(favTreeView->model())->updateModel(aEventId);
184 QDate aStartDate = Conference::getById(AppSettings::confId()).start();
185 QDate aEndDate = Conference::getById(AppSettings::confId()).end();
186 dayNavigator->setDates(aStartDate, aEndDate);
187 updateTreeView( Conference::getById(AppSettings::confId()).start() );
190 case EContainerTypeDay:
191 case EContainerTypeNone:
194 static_cast<EventModel*>(treeView->model())->updateModel(aEventId);
199 void TabContainer::setDates(const QDate &aStart, const QDate &aEnd)
201 dayNavigator->setDates(aStart, aEnd);
204 void TabContainer::timerUpdateTreeView()
206 if(mType == EContainerTypeNow)
208 updateTreeView(QDate());
212 void TabContainer::searchClicked()
214 if(mType == EContainerTypeSearch)
216 QHash<QString,QString> columns;
218 if( searchTitle->isChecked() )
219 columns.insertMulti("EVENT", "title");
220 if( searchAbstract->isChecked() )
221 columns.insertMulti("EVENT", "abstract");
222 if( searchTag->isChecked() )
223 columns.insertMulti("EVENT", "tag");
224 if( searchSpeaker->isChecked() )
225 columns["PERSON"] = "name";
226 if( searchRoom->isChecked() )
227 columns["ROOM"] = "name";
229 QString keyword = searchEdit->text().replace( QString("%"), QString("\\%") );
230 qDebug() << "\nKeyword to search: " << keyword;
231 SqlEngine::searchEvent( AppSettings::confId(), columns, keyword );
233 QDate startDate = Conference::getById(AppSettings::confId()).start();
234 QDate endDate = Conference::getById(AppSettings::confId()).end();
235 dayNavigator->setDates(startDate, endDate);
236 updateTreeView( Conference::getById(AppSettings::confId()).start() );
240 void TabContainer::searchAgainClicked()
242 if(mType == EContainerTypeSearch)
245 searchAgainButton->hide();
246 dayNavigator->hide();