source: src/gui/tabcontainer.cpp @ d49254d

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

'conflict' dialog now contains list of events in conflict with given eventId

  • Property mode set to 100644
File size: 3.3 KB
Line 
1#include "tabcontainer.h"
2
3#include <QFile>
4#include <QMessageBox>
5#include <QTimer>
6
7#include <treeview.h>
8#include <delegate.h>
9
10#include "eventdialog.h"
11#include "mapwindow.h"
12
13#include "conflictsdialog.h"
14
15TabContainer::TabContainer(QWidget *aParent)
16    : QWidget(aParent)
17{
18    setupUi(this);
19
20    treeView->setHeaderHidden(true);
21    treeView->setRootIsDecorated(false);
22    treeView->setIndentation(0);
23    treeView->setAnimated(true);
24    treeView->setModel(new EventModel());
25    treeView->setItemDelegate(new Delegate(treeView));
26
27    connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateTreeView(const QDate &)));
28
29    connect(treeView, SIGNAL(eventHasChanged(int)), SIGNAL(eventHasChanged(int)));
30    connect(treeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
31    connect(treeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
32    connect(treeView, SIGNAL(requestForConflicts(const QModelIndex &)), SLOT(displayConflicts(const QModelIndex &)));
33
34    if(!Conference::getAll().count()) // no conference(s) in the DB
35    {
36        dayNavigator->hide();
37    }
38    else
39    {
40        QDate aStartDate = Conference::getById(Conference::activeConference()).start();
41        QDate aEndDate = Conference::getById(Conference::activeConference()).end();
42        dayNavigator->setDates(aStartDate, aEndDate);
43    }
44}
45
46void TabContainer::updateTreeView(const QDate &aDate)
47{
48    dayNavigator->show();
49    loadEvents( aDate, Conference::activeConference() );
50    treeView->reset();
51}
52
53void TabContainer::itemClicked(const QModelIndex &aIndex)
54{
55    // have to handle only events, not time-groups
56    if(!aIndex.parent().isValid()) // time-group
57        return;
58
59    EventDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this);
60    connect(&dialog, SIGNAL(eventHasChanged(int)), this, SIGNAL(eventHasChanged(int)));
61    dialog.exec();
62    disconnect(&dialog, SIGNAL(eventHasChanged(int)), this, SIGNAL(eventHasChanged(int)));
63}
64
65void TabContainer::displayMap(const QModelIndex &aIndex)
66{
67    Event *event = static_cast<Event*>(aIndex.internalPointer());
68
69    // room names are stored in lower-case format
70    // room names are stored without dots in the name, eg. "aw.1124.png" -> "aw1124.png"
71    QString mapPath = QString(":/maps/rooms/%1.png").arg(event->room().toLower().remove("."));
72    if(!QFile::exists(mapPath))
73        mapPath = QString(":/maps/rooms/not-available.png");
74
75    QString roomName;
76    if(mapPath.contains("not-available", Qt::CaseInsensitive))
77        roomName = QString("Map is not available: %1").arg(event->room());
78    else
79        roomName = event->room();
80
81    QPixmap map(mapPath);
82    MapWindow window(map,roomName,this);
83    window.exec();
84}
85
86void TabContainer::displayConflicts(const QModelIndex &aIndex)
87{
88    ConflictsDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this);
89    connect(&dialog, SIGNAL(eventHasChanged(int)), this, SIGNAL(eventHasChanged(int)));
90    dialog.exec();
91    disconnect(&dialog, SIGNAL(eventHasChanged(int)), this, SIGNAL(eventHasChanged(int)));
92}
93
94void TabContainer::updateTreeViewModel(int aEventId)
95{
96    static_cast<EventModel*>(treeView->model())->updateModel(aEventId);
97}
98
99void TabContainer::setDates(const QDate &aStart, const QDate &aEnd)
100{
101    dayNavigator->setDates(aStart, aEnd);
102}
103
Note: See TracBrowser for help on using the repository browser.