00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "Programme_dlg.h"
00021
00022 #include "control_panel.h"
00023
00024 DepartmentDlg::DepartmentDlg(int btnAction
00025 ,RootItem * dept
00026 ,RootItem * faculty
00027 ,QMainWindow *parent)
00028 : RootDlg(parent)
00029 {
00030 statusBar = parent->statusBar();
00031 dataItem = dynamic_cast<DeptItem *>(dept);
00032 parentItem = dynamic_cast<FacItem *>(faculty);
00033
00034 createWidgets();
00035 createActions();
00036 initialise (btnAction);
00037 }
00038
00039
00040 void DepartmentDlg::enableBtn()
00041 {
00042 QString name = getNameOnDB();
00043 QString abbrev = getAbbrevOnDB();
00044
00045 NameAbbrevRootDlg::enableBtn(name
00046 ,getName()
00047 ,abbrev
00048 ,getAbbrev()
00049 ,getFacItem()->getID()
00050 ,getDeptItem()
00051 ,Department::uniqueName
00052 ,Department::uniqueAbbrev
00053 ,this
00054 );
00055 }
00056
00057
00058
00059 void DepartmentDlg::okPressed()
00060 {
00061 if (getDeptItem() == 0)
00062 {
00063 Department * deptObj = new Department(Department::NOT_ON_DB,getName(), getAbbrev(), getFacItem()->getFaculty());
00064 dataItem = new DeptItem(deptObj,getFacItem());
00065 }
00066 else
00067 {
00068 getDeptItem()->setDeptName(getName());
00069 getDeptItem()->setDeptAbbrev(getAbbrev());
00070 }
00071 accept();
00072 }
00073
00074
00075
00076
00077
00078 void DepartmentDlg::createWidgets()
00079 {
00080 in_wdgt = new NameWidget(60, tr("Institute:"), ui.frame, ui.vboxLayout2, this);
00081 in_wdgt->disableName();
00082 fn_wdgt = new NameWidget(80, tr("Faculty:"), ui.frame, ui.vboxLayout2, this);
00083 fn_wdgt->disableName();
00084 dna_wdgt = new NameAbbrevWidget(80, tr("Dept. Name:")
00085 ,12, tr("Abbreviation")
00086 ,ui.frame, ui.vboxLayout2, this);
00087
00088 }
00089
00090 void DepartmentDlg::createActions()
00091 {
00092 QObject::connect(dna_wdgt->getNameWdgt(), SIGNAL(textEdited(const QString & )), this, SLOT(enableBtn()));
00093 QObject::connect(dna_wdgt->getAbbrevWdgt(), SIGNAL(textEdited(const QString & )), this, SLOT(enableBtn()));
00094 QObject::connect(ui.okButton, SIGNAL(clicked()), this, SLOT(okPressed()));
00095 }
00096
00097 void DepartmentDlg::initialise (int btnAction)
00098 {
00099 QString name = "";
00100 QString abbrev = "";
00101 if (getDeptItem() != 0)
00102 {
00103 name = getDeptItem()->getDeptName();
00104 abbrev = getDeptItem()->getDeptAbbrev();
00105 }
00106 if (getFacItem() != 0)
00107 {
00108 setInstName(getInstName());
00109 setFacName(getFacName());
00110 }
00111
00112 setName(name);
00113 setAbbrev(abbrev);
00114
00115 RootDlg::initialise(btnAction, tr("Department"), name);
00116 getStatusBar()->showMessage(windowTitle());
00117
00118 if (btnAction == ControlPanel::BTN_DELETE)
00119 {
00120 dna_wdgt->disableControls();
00121
00122 ui.okButton->setEnabled(true);
00123 }
00124 }
00125