source: src/gui/tabcontainer.cpp @ ce59092

qt5
Last change on this file since ce59092 was ce59092, checked in by pavelpa <pavelpa@…>, 12 years ago

Event 'details' dialog now contains also 'favourite' and 'alarm'
buttons, so the user can set/unset the property directly from the dialog

  • Property mode set to 100644
File size: 7.8 KB
Line 
1#include "tabcontainer.h"
2
3#include <QFile>
4#include <QMessageBox>
5#include <QTimer>
6
7#include <sqlengine.h>
8#include <appsettings.h>
9
10#include <conference.h>
11
12#include <treeview.h>
13#include <eventmodel.h>
14#include <delegate.h>
15
16#include "eventdialog.h"
17#include "mapwindow.h"
18
19TabContainer::TabContainer(QWidget *aParent)
20    : QWidget(aParent)
21    , mType(EContainerTypeNone)
22{
23    setupUi(this);
24
25    searchAgainButton->hide();
26    searchHead->hide();
27
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));
34
35    connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateTreeView(const QDate &)));
36
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 &)));
41
42    connect(searchButton, SIGNAL(clicked()), SLOT(searchClicked()));
43    connect(searchAgainButton, SIGNAL(clicked()), SLOT(searchAgainClicked()));
44
45    if(!Conference::getAll().count()) // no conference(s) in the DB
46    {
47        dayNavigator->hide(); // hide DayNavigatorWidget
48    }
49    else
50    {
51        QDate aStartDate = Conference::getById(AppSettings::confId()).start();
52        QDate aEndDate = Conference::getById(AppSettings::confId()).end();
53        dayNavigator->setDates(aStartDate, aEndDate);
54    }
55}
56
57void TabContainer::setType(TabContainer::Type aType)
58{
59    mType = aType;
60
61    if(aType == EContainerTypeNow)
62    {
63        QTimer *timer = new QTimer( this );
64        connect( timer, SIGNAL(timeout()), SLOT(timerUpdateTreeView()) );
65        timer->start( 30000); // 30 seconds timer
66    }
67    if(aType == EContainerTypeSearch)
68    {
69        searchHead->show();
70    }
71}
72
73void TabContainer::updateTreeView(const QDate &aDate)
74{
75    switch(mType)
76    {
77        case EContainerTypeDay:
78            {
79                static_cast<EventModel*>(treeView->model())->loadEvents(aDate,AppSettings::confId());
80            }
81            break;
82        case EContainerTypeFavs:
83            {
84                static_cast<EventModel*>(treeView->model())->loadFavEvents(aDate,AppSettings::confId());
85            }
86            break;
87        case EContainerTypeTracks:
88            {
89                static_cast<EventModel*>(treeView->model())->loadEventsByTrack(aDate, AppSettings::confId());
90            }
91            break;
92        case EContainerTypeRooms:
93            {
94                static_cast<EventModel*>(treeView->model())->loadEventsByRoom(aDate, AppSettings::confId());
95            }
96            break;
97        case EContainerTypeNow:
98            {
99                static_cast<EventModel*>(treeView->model())->loadNowEvents(AppSettings::confId());
100                treeView->setAllExpanded(true);
101            }
102            break;
103        case EContainerTypeSearch:
104            {
105                treeView->reset();
106                int eventsCount = static_cast<EventModel*>(treeView->model())->loadSearchResultEvents(aDate,AppSettings::confId());
107                if( eventsCount ||
108                        dayNavigator->getCurrentDate() != Conference::getById(AppSettings::confId()).start() ){
109                    searchAgainButton->show();
110                    dayNavigator->show();
111                    treeView->show();
112                    searchHead->hide();
113                }
114                else{
115                    treeView->hide();
116                    searchAgainButton->hide();
117                    dayNavigator->hide();
118                    searchHead->show();
119                }
120            }
121            break;
122        case EContainerTypeNone:
123        default:
124            {
125                qDebug() << "Container type not specified";
126            }
127    }
128    treeView->reset();
129    dayNavigator->show();
130}
131
132void TabContainer::itemClicked(const QModelIndex &aIndex)
133{
134    // have to handle only events, not time-groups
135    if(!aIndex.parent().isValid()) // time-group
136        return;
137
138    EventDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this);
139    connect(&dialog, SIGNAL(eventHasChanged(int)), this, SIGNAL(eventHasChanged(int)));
140    dialog.exec();
141    disconnect(&dialog, SIGNAL(eventHasChanged(int)), this, SIGNAL(eventHasChanged(int)));
142}
143
144void TabContainer::displayMap(const QModelIndex &aIndex)
145{
146    Event *event = static_cast<Event*>(aIndex.internalPointer());
147
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");
153
154    QString roomName;
155    if(mapPath.contains("not-available", Qt::CaseInsensitive))
156        roomName = QString("Map is not available: %1").arg(event->room());
157    else
158        roomName = event->room();
159
160    QPixmap map(mapPath);
161    MapWindow window(map,roomName,this);
162    window.exec();
163}
164
165void TabContainer::displayWarning(const QModelIndex &aIndex)
166{
167    Q_UNUSED(aIndex);
168
169    QMessageBox::warning(
170        this,
171        tr("Time Conflict Warning"),
172        tr("This event happens at the same time than another one of your favourites.") );
173}
174
175void TabContainer::updateTreeViewModel(int aEventId)
176{
177    switch(mType)
178    {
179        case EContainerTypeFavs:
180            {
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() );
188            }
189            break;
190        case EContainerTypeDay:
191        case EContainerTypeNone:
192        default:
193            {
194                static_cast<EventModel*>(treeView->model())->updateModel(aEventId);
195            }
196    }
197}
198
199void TabContainer::setDates(const QDate &aStart, const QDate &aEnd)
200{
201    dayNavigator->setDates(aStart, aEnd);
202}
203
204void TabContainer::timerUpdateTreeView()
205{
206    if(mType == EContainerTypeNow)
207    {
208        updateTreeView(QDate());
209    }
210}
211
212void TabContainer::searchClicked()
213{
214    if(mType == EContainerTypeSearch)
215    {
216        QHash<QString,QString> columns;
217
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";
228
229        QString keyword = searchEdit->text().replace( QString("%"), QString("\\%") );
230        qDebug() << "\nKeyword to search: " << keyword;
231        SqlEngine::searchEvent( AppSettings::confId(), columns, keyword );
232
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() );
237    }
238}
239
240void TabContainer::searchAgainClicked()
241{
242    if(mType == EContainerTypeSearch)
243    {
244        searchHead->show();
245        searchAgainButton->hide();
246        dayNavigator->hide();
247        treeView->hide();
248    }
249}
250
Note: See TracBrowser for help on using the repository browser.