Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

GenericTreeViewPage_wdgt.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2006 by Graeme Foster                                   *
00003  *   email    foster.graeme@gmail.com                                      *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Swdgtte 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 #include "GenericTreeViewPage_wdgt.h"
00021 #include "control_panel.h"
00022 
00023 GenericTreeViewPageWidget::GenericTreeViewPageWidget(ControlPanel * window
00024                                   ,QWidget * widgetParent
00025                                   ,QBoxLayout * layoutParent
00026                                   ,dbListManager * pDataLists)
00027 : RootPageWidget(window, widgetParent, layoutParent, pDataLists)
00028 {
00029         wdgt.setupUi(this);
00030         createActions();
00031         rootSubtype = QString();
00032 }
00033 
00034 void GenericTreeViewPageWidget::createActions()
00035 {
00036         connect (wdgt.treeView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(itemClicked(const QModelIndex &)));
00037         connect (wdgt.treeView, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(btnModClicked()));
00038 
00039         connect (wdgt.btnAdd, SIGNAL(clicked(bool)), this, SLOT(btnAddClicked()));
00040         connect (wdgt.btnNew, SIGNAL(clicked(bool)), this, SLOT(btnNewClicked()));
00041         connect (wdgt.btnMod, SIGNAL(clicked(bool)), this, SLOT(btnModClicked()));
00042         connect (wdgt.btnDel, SIGNAL(clicked(bool)), this, SLOT(btnDelClicked()));
00043 }
00044 
00045 void GenericTreeViewPageWidget::initTabBtns(RootItem * obj)
00046 {
00047         if (obj == 0)
00048         {
00049                 wdgt.btnAdd->setText(tr("Add Institute"));
00050                 wdgt.btnMod->hide();
00051                 wdgt.btnDel->hide();
00052                 wdgt.btnNew->hide();
00053         }
00054         else
00055         {
00056                 QString type, subtype;
00057                 switch (obj->rtti())
00058                 {
00059                         case RootItem::INST_ITEM:
00060                                 type = "Institute";
00061                                 subtype = rootSubtype;
00062                                 break;
00063                         case RootItem::PROG_ITEM:
00064                                 type = "Programme";
00065                                 subtype = "Module";
00066                                 break;
00067                         case RootItem::MODULE_ITEM:
00068                                 type = "Module";
00069                                 subtype = "";
00070                                 break;
00071                         case RootItem::FACULTY_ITEM:
00072                                 type = "Faculty";
00073                                 subtype = "Department";
00074                                 break;
00075                         case RootItem::DEPT_ITEM:
00076                                 type = "Department";
00077                                 subtype = "Staff";
00078                                 break;
00079                         case RootItem::STAFF_ITEM:
00080                                 type = "Staff";
00081                                 subtype = "";
00082                                 break;
00083                         case RootItem::ROOM_ITEM:
00084                                 type = "Room";
00085                                 subtype = "";
00086                                 break;
00087                         default:
00088                                 type = "Institute";
00089                                 subtype = rootSubtype;
00090                 }
00091                 wdgt.btnAdd->setText(tr("Add ") + type);
00092                 wdgt.btnMod->setText(tr("Modify ") + type);
00093                 wdgt.btnDel->setText(tr("Delete ") + type);
00094                 wdgt.btnNew->setText(tr("Add ") + subtype);
00095                 wdgt.btnMod->show();
00096                 wdgt.btnDel->show();
00097                 if (subtype == "")
00098                         wdgt.btnNew->hide();
00099                 else
00100                         wdgt.btnNew->show();
00101         }
00102 }
00103 
00104 bool GenericTreeViewPageWidget::eventFilter(QObject * target, QEvent * event)
00105 {
00106         if (event->type() == QEvent::KeyRelease)
00107         {
00108                 int key = ((QKeyEvent*)event)->key();
00109                 if ((key == Qt::Key_Up) || (key == Qt::Key_Down))
00110                 {
00111                         treeViewClicked(((QTreeView*)target)->currentIndex());
00112                 }
00113         }
00114         return  QWidget::eventFilter(target, event);
00115 }
00116 
00117 void GenericTreeViewPageWidget::treeViewClicked(const QModelIndex & index)
00118 {
00119         QString data;
00120         int row = index.row();
00121         
00122         if (row > -1)
00123         {
00124                 selectedItem = getSelectedItem();
00125                 data = selectedItem->getDescription();
00126         }
00127         else
00128         {
00129                 selectedItem =0;
00130         }
00131         initTabBtns(selectedItem);
00132         mainWindow->statusBar()->showMessage(data);
00133 }
00134 
00135 void GenericTreeViewPageWidget::itemClicked(const QModelIndex & index)
00136 {
00137         treeViewClicked(index);
00138 }

Generated on Thu Apr 6 16:27:17 2006 for time-table by  doxygen 1.4.4