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

Module_dlg.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 - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 #include "Module_dlg.h"
00021 
00022 #include "control_panel.h"
00023 
00024 ModuleDlg::ModuleDlg(int btnAction
00025                                                   ,RootItem * module
00026                                                   ,RootItem * programme
00027                                                   ,QMainWindow *parent)
00028         : RootDlg(parent)
00029 {
00030         statusBar = parent->statusBar();
00031         parentItem = dynamic_cast<ProgItem *>(programme);
00032         dataItem = dynamic_cast<ModuleItem *>(module);
00033 
00034         createWidgets();
00035         createActions();
00036         initialise (btnAction);
00037 }
00038 
00039 
00040 void ModuleDlg::enableBtn()
00041 {
00042         QString name = getNameOnDB();
00043         QString abbrev = getAbbrevOnDB();
00044 
00045         NameAbbrevRootDlg::enableBtn(name
00046                                     ,getName()
00047                                     ,abbrev
00048                                     ,getAbbrev()
00049                                     ,getInstItem()->getID()
00050                                     ,getModuleItem()
00051                                     ,Module::uniqueName
00052                                     ,Module::uniqueNomenclature
00053                                     ,this
00054                                     );
00055 }
00056 
00057 
00058 
00059 void ModuleDlg::okPressed()
00060 {
00061         if (dataItem == 0)
00062         {
00063                 Module * moduleObj = new Module(Module::NOT_ON_DB
00064                                                                                                  ,getProgItem()->getProgramme()
00065                                                                                                  ,getName()
00066                                                                                                  ,getAbbrev()
00067                                                                                                  ,getDuration()
00068                                                                                                  ,getWeeklyPeriods()
00069                                                                                                  ,getSemester()
00070                                                                                                  );
00071                 dataItem = new ModuleItem(moduleObj,getProgItem());
00072         }
00073         else
00074         {
00075                 getModuleItem()->setModuName(getName());
00076                 getModuleItem()->setModuNomencatlure(getAbbrev());
00077                 getModuleItem()->setModuDuration(getDuration());
00078                 getModuleItem()->setModuWeeklyPeriods(getWeeklyPeriods());
00079         }
00080         accept();
00081 }
00082 
00083 /******************************************************************************
00084  * Private Methods
00085  ******************************************************************************/
00086 void ModuleDlg::createWidgets()
00087 {
00088         in_wdgt  = new NameWidget(60, tr("Institute:"), ui.frame, ui.vboxLayout2, this);
00089         in_wdgt->disableName();
00090         pn_wdgt  = new NameWidget(80, tr("Programme:"), ui.frame, ui.vboxLayout2, this);
00091         pn_wdgt->disableName();
00092         mna_wdgt = new NameAbbrevWidget(80, tr("Module Name:")
00093                                        ,12, tr("Abbreviation")
00094                                        ,ui.frame, ui.vboxLayout2, this);
00095         dno_wdgt = new NumberWidget(2,tr("Duration:"), ui.frame, ui.vboxLayout2, this);
00096         pno_wdgt = new NumberWidget(2,tr("Periods:"), ui.frame, ui.vboxLayout2, this);
00097         sno_wdgt = new NumberWidget(1,tr("Semester:"),ui.frame, ui.vboxLayout2,this);
00098 }
00099 
00100 void ModuleDlg::createActions()
00101 {
00102         QObject::connect(mna_wdgt->getNameWdgt(), SIGNAL(textEdited(const QString & )), this, SLOT(enableBtn()));
00103         QObject::connect(mna_wdgt->getAbbrevWdgt(), SIGNAL(textEdited(const QString & )), this, SLOT(enableBtn()));
00104         QObject::connect(dno_wdgt->getNumberWdgt(), SIGNAL(textEdited(const QString & )), this, SLOT(enableBtn()));
00105         QObject::connect(pno_wdgt->getNumberWdgt(), SIGNAL(textEdited(const QString & )), this, SLOT(enableBtn()));
00106         QObject::connect(ui.okButton, SIGNAL(clicked()), this, SLOT(okPressed()));
00107 }
00108 
00109 void ModuleDlg::initialise (int btnAction)
00110 {
00111         QString name = "";
00112         QString abbrev = "";
00113         int duration = 0;
00114         int periods = 0;
00115         
00116         if (getInstItem() != 0)
00117                 setInstName(getInstName());
00118         
00119         if (getProgItem() != 0)
00120                 setProgName(getProgName());
00121 
00122         if (getModuleItem() != 0)
00123         {
00124                 name = getModuleItem()->getModuName();
00125                 abbrev = getModuleItem()->getModuNomenclature();
00126                 duration = getModuleItem()->getModuDuration();
00127                 periods = getModuleItem()->getModuWeeklyPeriods();
00128         }
00129         
00130         setName(name);
00131         setAbbrev(abbrev);
00132         setDuration(duration);
00133         setWeeklyPeriods(periods);
00134         
00135         RootDlg::initialise(btnAction, tr("Module"), name);
00136         getStatusBar()->showMessage(windowTitle());
00137         if (btnAction == ControlPanel::BTN_DELETE)
00138         {
00139                 mna_wdgt->disableControls();
00140                 dno_wdgt->disableControls();
00141                 pno_wdgt->disableControls();
00142                 
00143                 ui.okButton->setEnabled(true);
00144         }
00145 }

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