implemented 'tab container' widget, which groups daynavigator with treeview
authorpavelpa <pavelpa@localhost>
Tue, 26 Jan 2010 19:17:47 +0000 (19:17 +0000)
committerpavelpa <pavelpa@localhost>
Tue, 26 Jan 2010 19:17:47 +0000 (19:17 +0000)
  - moved functionality from mainwindow to tabcontainer
  - TODO: 'search' tab not done yet

src/app/app.pro
src/app/main.cpp
src/gui/gui.pro
src/gui/mainwindow.cpp
src/gui/mainwindow.h
src/gui/mainwindow.ui
src/gui/tabcontainer.cpp [new file with mode: 0644]
src/gui/tabcontainer.h [new file with mode: 0644]
src/gui/tabcontainer.ui [new file with mode: 0644]
src/sql/sqlengine.h

index 6b1ea4c..67f6bab 100644 (file)
@@ -6,7 +6,7 @@ QT += sql xml
 
 # module dependencies
 LIBS += -L$$DESTDIR -lgui -lmvc -lsql
-INCLUDEPATH += ../gui
+INCLUDEPATH += ../gui ../sql
 DEPENDPATH += . ../gui
 TARGETDEPS += $$DESTDIR/libmvc.a $$DESTDIR/libgui.a $$DESTDIR/libsql.a
 maemo {
index 6711834..43728cb 100644 (file)
@@ -5,6 +5,8 @@
 #include <alarmdialog.h>
 #endif /* MAEMO */
 
+#include <sqlengine.h>
+
 int main(int argc, char *argv[])
 {
     Q_INIT_RESOURCE(icons);
@@ -13,6 +15,8 @@ int main(int argc, char *argv[])
     QApplication a(argc, argv);
     QApplication::setWindowIcon(QIcon(":/icons/fosdem.png"));
 
+    SqlEngine::initialize(); // creates DB connection
+
     QWidget *window;
 #ifdef MAEMO
     // if the app is run with two cmd-line arguments
index 50def41..82a215e 100644 (file)
@@ -28,6 +28,7 @@ FORMS += mainwindow.ui \
          importschedulewidget.ui \
          about.ui \
          eventdialog.ui \
+         tabcontainer.ui \
          mapwindow.ui
 
 HEADERS += mainwindow.h \
@@ -35,6 +36,7 @@ HEADERS += mainwindow.h \
            importschedulewidget.h \
            eventdialog.h \
            tabwidget.h \
+           tabcontainer.h \
            mapwindow.h
 
 SOURCES += mainwindow.cpp \
@@ -42,6 +44,7 @@ SOURCES += mainwindow.cpp \
            importschedulewidget.cpp \
            eventdialog.cpp \
            tabwidget.cpp \
+           tabcontainer.cpp \
            mapwindow.cpp
 
 maemo {
index d7d3fec..3a260f4 100644 (file)
@@ -2,7 +2,7 @@
 #include <appsettings.h>
 
 #include <QTreeView>
-#include <QDirModel>
+#include <QFile>
 
 #include <sqlengine.h>
 
 
 #include <QDialog>
 #include <QMessageBox>
-#include <QTimer>
 #include "ui_about.h"
-#include "eventdialog.h"
+#include <eventdialog.h>
 #include "daynavigatorwidget.h"
 #include "importschedulewidget.h"
 #include "mapwindow.h"
 
+#include <tabcontainer.h>
+
 MainWindow::MainWindow(int aEventId, QWidget *aParent)
     : QMainWindow(aParent)
 {
@@ -29,7 +30,7 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent)
     // create "SQLITE" DB instance/connection
     // opens DB connection (needed for EventModel)
     mSqlEngine = new SqlEngine(this);
-    mSqlEngine->initialize();
+    //mSqlEngine->initialize();
     importScheduleWidget->setSqlEngine(mSqlEngine);
 
     // Sanity check for existence of any Conference in the DB
@@ -48,37 +49,15 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent)
         setWindowTitle(confs[0].title());
     }
 
+    dayTabContainer->setType(TabContainer::EContainerTypeDay);
+    favsTabContainer->setType(TabContainer::EContainerTypeFavs);
+    tracksTabContainer->setType(TabContainer::EContainerTypeTracks);
+    nowTabContainer->setType(TabContainer::EContainerTypeNow);
+    roomsTabContainer->setType(TabContainer::EContainerTypeRooms);
+
     connect(importScheduleWidget, SIGNAL(scheduleImported(int)), SLOT(scheduleImported(int)));
 
-    connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateDayView(const QDate &)));
-    connect(trackDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateTracksView(const QDate &)));
-    connect(favouriteDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateFavouritesView(const QDate &)));
     connect(searchDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateSearchView(const QDate &)));
-    connect(roomDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateRoomView(const QDate &)));
-
-    // DAY EVENTS View
-    dayTreeView->setHeaderHidden(true);
-    dayTreeView->setRootIsDecorated(false);
-    dayTreeView->setIndentation(0);
-    dayTreeView->setAnimated(true);
-    dayTreeView->setModel(new EventModel());
-    dayTreeView->setItemDelegate(new Delegate(dayTreeView));
-
-    // FAVOURITIES View
-    favTreeView->setHeaderHidden(true);
-    favTreeView->setRootIsDecorated(false);
-    favTreeView->setIndentation(0);
-    favTreeView->setAnimated(true);
-    favTreeView->setModel(new EventModel());
-    favTreeView->setItemDelegate(new Delegate(favTreeView));
-
-    // TRACKS View
-    trackTreeView->setHeaderHidden(true);
-    trackTreeView->setRootIsDecorated(false);
-    trackTreeView->setIndentation(0);
-    trackTreeView->setAnimated(true);
-    trackTreeView->setModel(new EventModel());
-    trackTreeView->setItemDelegate(new Delegate(trackTreeView));
 
     // SEARCH EVENTS View
        searchTreeView->setHeaderHidden(true);
@@ -88,80 +67,37 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent)
        searchTreeView->setModel(new EventModel());
        searchTreeView->setItemDelegate(new Delegate(searchTreeView));
 
-    // NOW View
-       nowTreeView->setHeaderHidden(true);
-       nowTreeView->setRootIsDecorated(false);
-       nowTreeView->setIndentation(0);
-       nowTreeView->setAnimated(true);
-       nowTreeView->setModel(new EventModel());
-       nowTreeView->setItemDelegate(new Delegate(nowTreeView));
-
-       // NOW View refresh timer
-    QTimer *timer = new QTimer( this );
-    connect( timer, SIGNAL(timeout()), SLOT(timerUpdateNowView()) );
-    timer->start( 30000); // 30 seconds timer
-
-    // ROOMS View
-    roomTreeView->setHeaderHidden(true);
-    roomTreeView->setRootIsDecorated(false);
-    roomTreeView->setIndentation(0);
-    roomTreeView->setAnimated(true);
-    roomTreeView->setModel(new EventModel());
-    roomTreeView->setItemDelegate(new Delegate(roomTreeView));
-
     // event details have changed
-    connect(dayTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
-    connect(favTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
-    connect(trackTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
+    connect(dayTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
+    connect(favsTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
+    connect(favsTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
+    connect(roomsTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
+    connect(nowTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
+
     connect(searchTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
-    connect(nowTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
-    connect(roomTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
 
     // event clicked
-    connect(dayTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
-    connect(favTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
-    connect(trackTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
     connect(searchTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
-    connect(nowTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
-    connect(roomTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
-    // request for map to be displayed
-    connect(dayTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
-    connect(favTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
-    connect(trackTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
-    connect(searchTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
-    connect(nowTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
-    connect(roomTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
-    // request for warning to be displayed
-    connect(dayTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
-    connect(favTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
-    connect(trackTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
-    connect(searchTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
-    connect(nowTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
-    connect(roomTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
+
     // event search button clicked
     connect(searchButton, SIGNAL(clicked()), SLOT(searchClicked()));
     connect(searchAgainButton, SIGNAL(clicked()), SLOT(searchAgainClicked()));
+
     // event conference map button clicked
     connect(showMapButton, SIGNAL(clicked()), SLOT(conferenceMapClicked()));
     //
-    connect(tabWidget, SIGNAL(currentChanged(int)), SLOT(tabHasChanged(int)));
     connect(tabWidget, SIGNAL(infoIconClicked()), SLOT(aboutApp()));
 
-    if(!Conference::getAll().count()) // no conference(s) in the DB
-    {
-        dayNavigator->hide(); // hide DayNavigatorWidget
-        trackDayNavigator->hide();
-        roomDayNavigator->hide();
-    }
-    else
+    if(Conference::getAll().count()) // no conference(s) in the DB
     {
         QDate aStartDate = Conference::getById(AppSettings::confId()).start();
         QDate aEndDate = Conference::getById(AppSettings::confId()).end();
-        dayNavigator->setDates(aStartDate, aEndDate);
-        trackDayNavigator->setDates(aStartDate, aEndDate);
-        favouriteDayNavigator->setDates(aStartDate, aEndDate);
         searchDayNavigator->setDates(aStartDate, aEndDate);
-        roomDayNavigator->setDates(aStartDate, aEndDate);
+        //
+        dayTabContainer->setDates(aStartDate, aEndDate);
+        tracksTabContainer->setDates(aStartDate, aEndDate);
+        roomsTabContainer->setDates(aStartDate, aEndDate);
+        favsTabContainer->setDates(aStartDate, aEndDate);
         //
         conferenceTitle->setText(Conference::getById(AppSettings::confId()).title());
         conferenceSubtitle->setText(Conference::getById(AppSettings::confId()).subtitle());
@@ -214,11 +150,12 @@ void MainWindow::scheduleImported(int aConfId)
             AppSettings::setConfId(confs[0].id());
 
         // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
-        QDate aStartDate = Conference::getById(AppSettings::confId()).start();
-        QDate aEndDate = Conference::getById(AppSettings::confId()).end();
-        dayNavigator->setDates(aStartDate, aEndDate);
-        trackDayNavigator->setDates(aStartDate, aEndDate);
-        roomDayNavigator->setDates(aStartDate, aEndDate);
+        QDate startDate = Conference::getById(AppSettings::confId()).start();
+        QDate endDate = Conference::getById(AppSettings::confId()).end();
+        dayTabContainer->setDates(startDate, endDate);
+        tracksTabContainer->setDates(startDate, endDate);
+        roomsTabContainer->setDates(startDate, endDate);
+        favsTabContainer->setDates(startDate, endDate);
     }
 }
 
@@ -230,27 +167,6 @@ void MainWindow::aboutApp()
     dialog.exec();
 }
 
-void MainWindow::updateDayView(const QDate &aDate)
-{
-    static_cast<EventModel*>(dayTreeView->model())->loadEvents(aDate,AppSettings::confId());
-    dayTreeView->reset();
-    dayNavigator->show();
-}
-
-void MainWindow::updateTracksView(const QDate &aDate)
-{
-    static_cast<EventModel*>(trackTreeView->model())->loadEventsByTrack(aDate, AppSettings::confId());
-    trackTreeView->reset();
-    trackDayNavigator->show();
-}
-
-void MainWindow::updateFavouritesView(const QDate &aDate)
-{
-    static_cast<EventModel*>(favTreeView->model())->loadFavEvents(aDate,AppSettings::confId());
-    favTreeView->reset();
-    favouriteDayNavigator->show();
-}
-
 void MainWindow::updateSearchView(const QDate &aDate)
 {
     qDebug() << "MainWindow::updateSearchView(), aDate: " << aDate.toString() ;
@@ -270,52 +186,6 @@ void MainWindow::updateSearchView(const QDate &aDate)
     }
 }
 
-void MainWindow::updateNowView()
-{
-    EventModel *model = static_cast<EventModel*>(nowTreeView->model());
-    model->loadNowEvents(AppSettings::confId());
-    nowTreeView->reset();
-    nowTreeView->setAllExpanded(true);
-}
-
-void MainWindow::updateRoomView(const QDate &aDate)
-{
-    static_cast<EventModel*>(roomTreeView->model())->loadEventsByRoom(aDate, AppSettings::confId());
-    roomTreeView->reset();
-    roomDayNavigator->show();
-}
-
-void MainWindow::itemClicked(const QModelIndex &aIndex)
-{
-    // have to handle only events, not time-groups
-    if(!aIndex.parent().isValid()) // time-group
-        return;
-
-    EventDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this);
-    dialog.exec();
-}
-
-void MainWindow::displayMap(const QModelIndex &aIndex)
-{
-    Event *event = static_cast<Event*>(aIndex.internalPointer());
-
-    // room names are stored in lower-case format
-    // room names are stored without dots in the name, eg. "aw.1124.png" -> "aw1124.png"
-    QString mapPath = QString(":/maps/rooms/%1.png").arg(event->room().toLower().remove("."));
-    if(!QFile::exists(mapPath))
-        mapPath = QString(":/maps/rooms/not-available.png");
-
-    QString roomName;
-    if(mapPath.contains("not-available", Qt::CaseInsensitive))
-        roomName = QString("Map is not available: %1").arg(event->room());
-    else
-        roomName = event->room();
-
-    QPixmap map(mapPath);
-    MapWindow window(map,roomName,this);
-    window.exec();
-}
-
 void MainWindow::searchClicked()
 {
     QHash<QString,QString> columns;
@@ -347,12 +217,10 @@ void MainWindow::searchAgainClicked()
     //searchAgainButton->hide();
     searchVerticalWidget->hide();
     searchTreeView->hide();
-
 }
 
 void MainWindow::conferenceMapClicked()
 {
-
     QString mapPath = QString(":/maps/campus.png");
     if(!QFile::exists(mapPath))
         mapPath = QString(":/maps/rooms/not-available.png");
@@ -364,50 +232,14 @@ void MainWindow::conferenceMapClicked()
     window.exec();
 }
 
-void MainWindow::displayWarning(const QModelIndex &aIndex)
-{
-    Q_UNUSED(aIndex);
-
-    QMessageBox::warning(
-    this,
-    tr("Time Conflict Warning"),
-    tr("This event happens at the same time than another one of your favourites.") );
-}
-
 void MainWindow::eventHasChanged(int aEventId)
 {
-    static_cast<EventModel*>(dayTreeView->model())->updateModel(aEventId);
-
-    // we need to reload favourites, because some favourite could be deleted
-    //static_cast<EventModel*>(favTreeView->model())->updateModel(aEventId);
-    QDate aStartDate = Conference::getById(AppSettings::confId()).start();
-    QDate aEndDate = Conference::getById(AppSettings::confId()).end();
-    favouriteDayNavigator->setDates(aStartDate, aEndDate);
-    updateFavouritesView( Conference::getById(AppSettings::confId()).start() );
+    dayTabContainer->updateTreeViewModel(aEventId);
+    favsTabContainer->updateTreeViewModel(aEventId);
+    tracksTabContainer->updateTreeViewModel(aEventId);
+    nowTabContainer->updateTreeViewModel(aEventId);
+    roomsTabContainer->updateTreeViewModel(aEventId);
 
-    static_cast<EventModel*>(trackTreeView->model())->updateModel(aEventId);
     static_cast<EventModel*>(searchTreeView->model())->updateModel(aEventId);
-    static_cast<EventModel*>(nowTreeView->model())->updateModel(aEventId);
-    static_cast<EventModel*>(roomTreeView->model())->updateModel(aEventId);
 }
 
-void MainWindow::tabHasChanged(int aIndex)
-{
-    Q_UNUSED(aIndex);
-
-    // TODO: only if it changed to favourities tab
-    updateFavouritesView(favouriteDayNavigator->getCurrentDate());
-    // TODO: only if it changed to now tab
-    updateNowView();
-}
-
-void MainWindow::timerUpdateNowView()
-{
-       QWidget * pCurrentWidget = tabWidget->widget(tabWidget->currentIndex());
-
-       if( pCurrentWidget != NULL )
-       {
-               if( pCurrentWidget == tab )
-                   updateNowView();
-       }
-}
index 6986e15..0f425a3 100644 (file)
@@ -18,21 +18,11 @@ public:
 private slots:
     void scheduleImported(int aConfId);
     void aboutApp();
-    void updateDayView(const QDate &aDate);
-    void updateTracksView(const QDate &aDate);
-    void updateFavouritesView(const QDate &aDate);
     void updateSearchView(const QDate &aDate);
-    void updateNowView();
-    void updateRoomView(const QDate &aDate);
-    void itemClicked(const QModelIndex &aIndex);
-    void displayMap(const QModelIndex &aIndex);
-    void displayWarning(const QModelIndex &aIndex);
     void searchClicked();
        void searchAgainClicked();
     void conferenceMapClicked();
-    void tabHasChanged(int aIndex);
     void eventHasChanged(int aEventId);
-    void timerUpdateNowView();
 private:
     SqlEngine *mSqlEngine;
 };
index 2f2fa81..7f25a2f 100644 (file)
@@ -5,8 +5,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>935</width>
-    <height>514</height>
+    <width>903</width>
+    <height>498</height>
    </rect>
   </property>
   <property name="minimumSize" >
        </attribute>
        <layout class="QGridLayout" name="gridLayout_2" >
         <item row="0" column="0" >
-         <layout class="QVBoxLayout" name="verticalLayout" >
-          <item>
-           <layout class="QHBoxLayout" name="horizontalLayout_2" >
-            <item>
-             <widget class="DayNavigatorWidget" native="1" name="dayNavigator" >
-              <property name="sizePolicy" >
-               <sizepolicy vsizetype="Expanding" hsizetype="Minimum" >
-                <horstretch>0</horstretch>
-                <verstretch>0</verstretch>
-               </sizepolicy>
-              </property>
-             </widget>
-            </item>
-            <item>
-             <widget class="TreeView" name="dayTreeView" >
-              <property name="maximumSize" >
-               <size>
-                <width>16777215</width>
-                <height>16777215</height>
-               </size>
-              </property>
-             </widget>
-            </item>
-           </layout>
-          </item>
-         </layout>
+         <widget class="TabContainer" native="1" name="dayTabContainer" />
         </item>
        </layout>
       </widget>
         <string>Favourites</string>
        </attribute>
        <layout class="QGridLayout" name="gridLayout_3" >
-        <item row="1" column="0" >
-         <layout class="QHBoxLayout" name="horizontalLayout_4" >
-          <item>
-           <widget class="DayNavigatorWidget" native="1" name="favouriteDayNavigator" />
-          </item>
-          <item>
-           <widget class="TreeView" name="favTreeView" />
-          </item>
-         </layout>
+        <item row="0" column="0" >
+         <widget class="TabContainer" native="1" name="favsTabContainer" />
         </item>
        </layout>
       </widget>
        </attribute>
        <layout class="QGridLayout" name="gridLayout_4" >
         <item row="0" column="0" >
-         <layout class="QHBoxLayout" name="horizontalLayout_3" >
-          <item>
-           <widget class="DayNavigatorWidget" native="1" name="trackDayNavigator" />
-          </item>
-          <item>
-           <widget class="TreeView" name="trackTreeView" >
-            <property name="maximumSize" >
-             <size>
-              <width>16777215</width>
-              <height>16777215</height>
-             </size>
-            </property>
-           </widget>
-          </item>
-         </layout>
+         <widget class="TabContainer" native="1" name="tracksTabContainer" />
         </item>
        </layout>
       </widget>
        </attribute>
        <layout class="QGridLayout" name="gridLayout_8" >
         <item row="0" column="0" >
-         <layout class="QHBoxLayout" name="horizontalLayout_5" >
-          <property name="sizeConstraint" >
-           <enum>QLayout::SetDefaultConstraint</enum>
-          </property>
-          <item>
-           <widget class="DayNavigatorWidget" native="1" name="roomDayNavigator" />
-          </item>
-          <item>
-           <widget class="TreeView" name="roomTreeView" >
-            <property name="maximumSize" >
-             <size>
-              <width>16777215</width>
-              <height>16777215</height>
-             </size>
-            </property>
-           </widget>
-          </item>
-         </layout>
+         <widget class="TabContainer" native="1" name="roomsTabContainer" />
         </item>
        </layout>
       </widget>
         </item>
        </layout>
       </widget>
-      <widget class="QWidget" name="tab" >
+      <widget class="QWidget" name="nowTab" >
        <attribute name="title" >
         <string>Now</string>
        </attribute>
        <layout class="QGridLayout" name="gridLayout_7" >
         <item row="0" column="0" >
-         <widget class="TreeView" name="nowTreeView" />
+         <widget class="TabContainer" native="1" name="nowTabContainer" />
         </item>
        </layout>
       </widget>
    <header>importschedulewidget.h</header>
    <container>1</container>
   </customwidget>
+  <customwidget>
+   <class>TabContainer</class>
+   <extends>QWidget</extends>
+   <header>tabcontainer.h</header>
+   <container>1</container>
+  </customwidget>
  </customwidgets>
  <resources>
   <include location="../icons.qrc" />
diff --git a/src/gui/tabcontainer.cpp b/src/gui/tabcontainer.cpp
new file mode 100644 (file)
index 0000000..6035e84
--- /dev/null
@@ -0,0 +1,180 @@
+#include "tabcontainer.h"
+
+#include <QFile>
+#include <QMessageBox>
+#include <QTimer>
+
+#include <appsettings.h>
+
+#include <conference.h>
+
+#include <treeview.h>
+#include <eventmodel.h>
+#include <delegate.h>
+
+#include "eventdialog.h"
+#include "mapwindow.h"
+
+TabContainer::TabContainer(QWidget *aParent)
+    : QWidget(aParent)
+    , mType(EContainerTypeNone)
+{
+    setupUi(this);
+
+    searchAgainButton->hide();
+
+    treeView->setHeaderHidden(true);
+    treeView->setRootIsDecorated(false);
+    treeView->setIndentation(0);
+    treeView->setAnimated(true);
+    treeView->setModel(new EventModel());
+    treeView->setItemDelegate(new Delegate(treeView));
+
+    connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateTreeView(const QDate &)));
+
+    connect(treeView, SIGNAL(eventHasChanged(int)), SIGNAL(eventHasChanged(int)));
+    connect(treeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
+    connect(treeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
+    connect(treeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
+
+    if(!Conference::getAll().count()) // no conference(s) in the DB
+    {
+        dayNavigator->hide(); // hide DayNavigatorWidget
+    }
+    else
+    {
+        QDate aStartDate = Conference::getById(AppSettings::confId()).start();
+        QDate aEndDate = Conference::getById(AppSettings::confId()).end();
+        dayNavigator->setDates(aStartDate, aEndDate);
+    }
+}
+
+void TabContainer::setType(TabContainer::Type aType)
+{
+    mType = aType;
+    if(aType == EContainerTypeNow)
+    {
+        QTimer *timer = new QTimer( this );
+        connect( timer, SIGNAL(timeout()), SLOT(timerUpdateTreeView()) );
+        timer->start( 30000); // 30 seconds timer
+    }
+}
+
+void TabContainer::updateTreeView(const QDate &aDate)
+{
+    switch(mType)
+    {
+        case EContainerTypeDay:
+            {
+                static_cast<EventModel*>(treeView->model())->loadEvents(aDate,AppSettings::confId());
+            }
+            break;
+        case EContainerTypeFavs:
+            {
+                static_cast<EventModel*>(treeView->model())->loadFavEvents(aDate,AppSettings::confId());
+            }
+            break;
+        case EContainerTypeTracks:
+            {
+                static_cast<EventModel*>(treeView->model())->loadEventsByTrack(aDate, AppSettings::confId());
+            }
+            break;
+        case EContainerTypeRooms:
+            {
+                static_cast<EventModel*>(treeView->model())->loadEventsByRoom(aDate, AppSettings::confId());
+            }
+            break;
+        case EContainerTypeNow:
+            {
+                static_cast<EventModel*>(treeView->model())->loadNowEvents(AppSettings::confId());
+                treeView->setAllExpanded(true);
+            }
+            break;
+        case EContainerTypeNone:
+        default:
+            {
+                qDebug() << "Container type not specified";
+            }
+    }
+    treeView->reset();
+    dayNavigator->show();
+}
+
+void TabContainer::itemClicked(const QModelIndex &aIndex)
+{
+    // have to handle only events, not time-groups
+    if(!aIndex.parent().isValid()) // time-group
+        return;
+
+    EventDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this);
+    dialog.exec();
+}
+
+void TabContainer::displayMap(const QModelIndex &aIndex)
+{
+    Event *event = static_cast<Event*>(aIndex.internalPointer());
+
+    // room names are stored in lower-case format
+    // room names are stored without dots in the name, eg. "aw.1124.png" -> "aw1124.png"
+    QString mapPath = QString(":/maps/rooms/%1.png").arg(event->room().toLower().remove("."));
+    if(!QFile::exists(mapPath))
+        mapPath = QString(":/maps/rooms/not-available.png");
+
+    QString roomName;
+    if(mapPath.contains("not-available", Qt::CaseInsensitive))
+        roomName = QString("Map is not available: %1").arg(event->room());
+    else
+        roomName = event->room();
+
+    QPixmap map(mapPath);
+    MapWindow window(map,roomName,this);
+    window.exec();
+}
+
+void TabContainer::displayWarning(const QModelIndex &aIndex)
+{
+    Q_UNUSED(aIndex);
+
+    QMessageBox::warning(
+        this,
+        tr("Time Conflict Warning"),
+        tr("This event happens at the same time than another one of your favourites.") );
+}
+
+void TabContainer::updateTreeViewModel(int aEventId)
+{
+    switch(mType)
+    {
+        case EContainerTypeFavs:
+            {
+                // requires special handling
+                // we need to reload favourites, because some favourite could be deleted
+                //static_cast<EventModel*>(favTreeView->model())->updateModel(aEventId);
+                QDate aStartDate = Conference::getById(AppSettings::confId()).start();
+                QDate aEndDate = Conference::getById(AppSettings::confId()).end();
+                dayNavigator->setDates(aStartDate, aEndDate);
+                updateTreeView( Conference::getById(AppSettings::confId()).start() );
+            }
+            break;
+        case EContainerTypeDay:
+        case EContainerTypeNone:
+        default:
+            {
+                static_cast<EventModel*>(treeView->model())->updateModel(aEventId);
+            }
+    }
+}
+
+void TabContainer::setDates(const QDate &aStart, const QDate &aEnd)
+{
+    dayNavigator->setDates(aStart, aEnd);
+}
+
+void TabContainer::timerUpdateTreeView()
+{
+    if(mType == EContainerTypeNow)
+    {
+        updateTreeView(QDate());
+    }
+}
+
diff --git a/src/gui/tabcontainer.h b/src/gui/tabcontainer.h
new file mode 100644 (file)
index 0000000..527c58b
--- /dev/null
@@ -0,0 +1,48 @@
+#ifndef TABCONTAINER_H
+#define TABCONTAINER_H
+
+#include <QWidget>
+#include "ui_tabcontainer.h"
+
+class TabContainer : public QWidget, Ui::TabContainer
+{
+    Q_OBJECT
+public:
+
+    // type of the container
+    // specifies the type of the data that treeView holds
+    enum Type
+    {
+        EContainerTypeNone = 0,
+        EContainerTypeDay,
+        EContainerTypeFavs,
+        EContainerTypeTracks,
+        EContainerTypeRooms,
+        EContainerTypeSearch,
+        EContainerTypeNow
+    };
+
+    TabContainer(QWidget *aParent = NULL);
+    ~TabContainer() {}
+    void setType(TabContainer::Type aType);
+
+signals:
+    void eventHasChanged(int aEventId);
+
+public slots:
+    void updateTreeViewModel(int aEventId);
+    void setDates(const QDate &aStart, const QDate &aEnd);
+
+private slots:
+    void updateTreeView(const QDate &aDate);
+    void timerUpdateTreeView();
+    void itemClicked(const QModelIndex &aIndex);
+    void displayMap(const QModelIndex &aIndex);
+    void displayWarning(const QModelIndex &aIndex);
+
+private:
+    TabContainer::Type mType;
+};
+
+#endif /* TABCONTAINER_H */
+
diff --git a/src/gui/tabcontainer.ui b/src/gui/tabcontainer.ui
new file mode 100644 (file)
index 0000000..ff1966e
--- /dev/null
@@ -0,0 +1,80 @@
+<ui version="4.0" >
+ <class>TabContainer</class>
+ <widget class="QWidget" name="TabContainer" >
+  <property name="geometry" >
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>568</width>
+    <height>292</height>
+   </rect>
+  </property>
+  <property name="windowTitle" >
+   <string>Form</string>
+  </property>
+  <layout class="QGridLayout" name="gridLayout" >
+   <item row="0" column="0" >
+    <widget class="QToolButton" name="searchAgainButton" >
+     <property name="enabled" >
+      <bool>true</bool>
+     </property>
+     <property name="sizePolicy" >
+      <sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="toolTip" >
+      <string>Search again</string>
+     </property>
+     <property name="text" >
+      <string>S</string>
+     </property>
+     <property name="icon" >
+      <iconset resource="../icons.qrc" >
+       <normaloff>:/icons/search.png</normaloff>:/icons/search.png</iconset>
+     </property>
+     <property name="iconSize" >
+      <size>
+       <width>24</width>
+       <height>24</height>
+      </size>
+     </property>
+     <property name="toolButtonStyle" >
+      <enum>Qt::ToolButtonIconOnly</enum>
+     </property>
+    </widget>
+   </item>
+   <item rowspan="2" row="0" column="1" >
+    <widget class="TreeView" name="treeView" />
+   </item>
+   <item row="1" column="0" >
+    <widget class="DayNavigatorWidget" native="1" name="dayNavigator" >
+     <property name="sizePolicy" >
+      <sizepolicy vsizetype="Expanding" hsizetype="Minimum" >
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <customwidgets>
+  <customwidget>
+   <class>DayNavigatorWidget</class>
+   <extends>QWidget</extends>
+   <header>daynavigatorwidget.h</header>
+   <container>1</container>
+  </customwidget>
+  <customwidget>
+   <class>TreeView</class>
+   <extends>QTreeView</extends>
+   <header>../mvc/treeview.h</header>
+  </customwidget>
+ </customwidgets>
+ <resources>
+  <include location="../icons.qrc" />
+ </resources>
+ <connections/>
+</ui>
index 0ac9fa3..d52ceb3 100644 (file)
@@ -12,7 +12,7 @@ class SqlEngine : public QObject
     public:
         SqlEngine(QObject *aParent = NULL);
         ~SqlEngine();
-        void initialize();
+        static void initialize();
         void addConferenceToDB(QHash<QString,QString> &aConference);
         void addEventToDB(QHash<QString,QString> &aEvent);
         void addPersonToDB(QHash<QString,QString> &aPerson);
@@ -22,8 +22,8 @@ class SqlEngine : public QObject
         // search Events for ....
         int searchEvent(int conferenceId, const QHash<QString,QString> &columns, const QString &keyword);
     private:
-        QString login(const QString &aDatabaseType, const QString &aDatabaseName);
-        bool createTables(QSqlDatabase &aDatabase);
+        static QString login(const QString &aDatabaseType, const QString &aDatabaseName);
+        static bool createTables(QSqlDatabase &aDatabase);
         bool execQuery(QSqlDatabase &aDatabase, const QString &aQuery);
 };