source: src/gui/tabcontainer.cpp @ 8896336

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

some performance optimizations

  • favourities reloaded only if they have really changed
  • otherwise only event in the question is updated
  • Property mode set to 100644
File size: 3.6 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,bool)), SIGNAL(eventHasChanged(int,bool)));
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    // day navigator is hidden by default
35    dayNavigator->hide();
36}
37
38void TabContainer::updateTreeView(const QDate &aDate)
39{
40    dayNavigator->show();
41    loadEvents( aDate, Conference::activeConference() );
42    treeView->reset();
43}
44
45void TabContainer::itemClicked(const QModelIndex &aIndex)
46{
47    // have to handle only events, not time-groups
48    if(!aIndex.parent().isValid()) // time-group
49        return;
50
51    EventDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this);
52    connect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool)));
53    dialog.exec();
54    disconnect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool)));
55}
56
57void TabContainer::displayMap(const QModelIndex &aIndex)
58{
59    Event *event = static_cast<Event*>(aIndex.internalPointer());
60
61    // room names are stored in lower-case format
62    // room names are stored without dots in the name, eg. "aw.1124.png" -> "aw1124.png"
63    QString mapPath = QString(":/maps/rooms/%1.png").arg(event->room().toLower().remove("."));
64    if(!QFile::exists(mapPath))
65        mapPath = QString(":/maps/rooms/not-available.png");
66
67    QString roomName;
68    if(mapPath.contains("not-available", Qt::CaseInsensitive))
69        roomName = QString("Map is not available: %1").arg(event->room());
70    else
71        roomName = event->room();
72
73    QPixmap map(mapPath);
74    MapWindow window(map,roomName,this);
75    window.exec();
76}
77
78void TabContainer::displayConflicts(const QModelIndex &aIndex)
79{
80    ConflictsDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this);
81    connect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool)));
82    dialog.exec();
83    disconnect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool)));
84}
85
86void TabContainer::updateTreeViewModel(int aEventId, bool aReloadModel)
87{
88    if(aReloadModel)
89    {
90        // requires special handling
91        // eg. in case of favourities - some favourities may have changed
92        // and so we need to reload them
93        int confId = Conference::activeConference();
94        QDate startDate = Conference::getById(confId).start();
95        QDate endDate = Conference::getById(confId).end();
96        dayNavigator->setDates(startDate, endDate);
97        updateTreeView( Conference::getById(confId).start() );
98    }
99    else
100    {
101        // just update event in the question
102        static_cast<EventModel*>(treeView->model())->updateModel(aEventId);
103    }
104}
105
106void TabContainer::setDates(const QDate &aStart, const QDate &aEnd)
107{
108    dayNavigator->setDates(aStart, aEnd);
109}
110
Note: See TracBrowser for help on using the repository browser.