00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "ModuleEnrolPage_wdgt.h"
00021
00022 #include "control_panel.h"
00023
00024 ModuleEnrolPageWidget::ModuleEnrolPageWidget(ControlPanel * mainWindow
00025 ,QWidget * widgetParent
00026 ,QBoxLayout * layoutParent
00027 ,dbListManager * dataLists)
00028 : QWidget(widgetParent)
00029 {
00030 wdgt.setupUi(this);
00031 pMainWindow = mainWindow;
00032 pDataLists = dataLists;
00033
00034 wdgt.cbxInst->init(dataLists);
00035 vboxLayout = new QVBoxLayout();
00036 vboxLayout->setSpacing(0);
00037 vboxLayout->setMargin(0);
00038 vboxLayout->addWidget(this);
00039 layoutParent->addLayout(vboxLayout);
00040
00041 createActions();
00042 }
00043
00044 void ModuleEnrolPageWidget::createActions()
00045 {
00046 connect (wdgt.cbxInst, SIGNAL(currentIndexChanged(QString)), this, SLOT(cbxInstSelected(QString)));
00047 connect (wdgt.trvModules, SIGNAL(clicked(const QModelIndex &)), this, SLOT(itemSelectedEnrol(const QModelIndex &)));
00048
00049 connect (wdgt.edtClassSize, SIGNAL(textEdited(const QString &)), this, SLOT(classSizeUpdate(const QString &)));
00050 connect (wdgt.edtGroups, SIGNAL(textEdited(const QString &)), this, SLOT(classGroupsUpdate(const QString &)));
00051 connect (wdgt.edtLabHours, SIGNAL(textEdited(const QString &)), this, SLOT(labHoursUpdate(const QString &)));
00052 connect (wdgt.edtLabGroups, SIGNAL(textEdited(const QString &)), this, SLOT(labGroupsUpdate(const QString &)));
00053 }
00054
00055 void ModuleEnrolPageWidget::cbxInstSelected(QString name)
00056 {
00057 Institute * instObj = pDataLists->getInstFromName(name);
00058 inittrvModules(instObj);
00059 }
00060
00061 void ModuleEnrolPageWidget::inittrvModules(Institute * instObj)
00062 {
00063 if (instObj == 0)
00064 wdgt.trvModules->setModel(0);
00065 else
00066 {
00067 MLEnrolModel * model = new MLEnrolModel(pDataLists, instObj);
00068 pDataLists->registerModel(model
00069 ,dbListManager::regMLAlloc
00070 );
00071 wdgt.trvModules->setModel(model);
00072 wdgt.trvModules->resizeColumnToContents(0);
00073 wdgt.trvModules->resizeColumnToContents(1);
00074 wdgt.trvModules->resizeColumnToContents(2);
00075 wdgt.trvModules->resizeColumnToContents(3);
00076 wdgt.trvModules->resizeColumnToContents(4);
00077 wdgt.trvModules->resizeColumnToContents(5);
00078 wdgt.trvModules->resizeColumnToContents(6);
00079 wdgt.trvModules->setRootIsDecorated(true);
00080 }
00081 }
00082
00083 void ModuleEnrolPageWidget::itemSelectedEnrol(const QModelIndex & index)
00084 {
00085 int row = index.row();
00086 QString desc;
00087
00088 if (row > -1)
00089 {
00090 SelectedEnrol = static_cast<RootItem*>(index.internalPointer());
00091 if (SelectedEnrol->rtti() == RootItem::PROG_ITEM)
00092 {
00093 ProgItem * progItem = dynamic_cast<ProgItem*>(SelectedEnrol);
00094 desc = progItem->getProgAbbrev() + ": Semester " + progItem->getSemDesc();
00095 pMainWindow->statusBar()->showMessage(desc + tr(" selected."));
00096 wdgt.lblModule->setText(desc);
00097 }
00098 else if (SelectedEnrol->rtti() == RootItem::ML_ALLOC_ITEM)
00099 {
00100 MLAllocItem * enrolItem = dynamic_cast<MLAllocItem*>(SelectedEnrol);
00101 desc = enrolItem->getModuleDesc() + ": Class Size " + enrolItem->getClassSizeDesc();
00102 pMainWindow->statusBar()->showMessage(desc + tr(" selected."));
00103 wdgt.edtClassSize->setText(enrolItem->getClassSizeDesc());
00104 wdgt.edtGroups->setText(enrolItem->getGroupsDesc());
00105 wdgt.edtLabHours->setText(enrolItem->getLabHoursDesc());
00106 wdgt.edtLabGroups->setText(enrolItem->getLabGroupsDesc());
00107 wdgt.lblModule->setText(desc);
00108 }
00109 wdgt.trvModules->resizeColumnToContents(0);
00110 }
00111 else
00112 SelectedEnrol = 0;
00113 }
00114
00115 void ModuleEnrolPageWidget::classSizeUpdate(const QString & class_size)
00116 {
00117 int classSize = class_size.toInt();
00118 enrolTabUpdates(&MLAllocItem::updateClassSize,classSize, "Class Size");
00119 }
00120
00121 void ModuleEnrolPageWidget::classGroupsUpdate(const QString & class_groups)
00122 {
00123 int groups = class_groups.toInt();
00124 enrolTabUpdates(&MLAllocItem::updateGroups,groups, "Class Groups");
00125 }
00126
00127 void ModuleEnrolPageWidget::labHoursUpdate(const QString & lab_hours)
00128 {
00129 int labHours = lab_hours.toInt();
00130 enrolTabUpdates(&MLAllocItem::updateLabHours,labHours, "Lab Hours");
00131 }
00132
00133 void ModuleEnrolPageWidget::labGroupsUpdate(const QString & lab_groups)
00134 {
00135 int labGroups = lab_groups.toInt();
00136 enrolTabUpdates(&MLAllocItem::updateLabGroups,labGroups, "Lab Groups");
00137 }
00138
00139 void ModuleEnrolPageWidget::enrolTabUpdates(void (MLAllocItem::*updateFn)(int),int value, QString msg)
00140 {
00141 QString desc;
00142 if (SelectedEnrol == 0) return;
00143 if (SelectedEnrol->rtti() == RootItem::PROG_ITEM)
00144 {
00145 ProgItem * progItem = dynamic_cast<ProgItem*>(SelectedEnrol);
00146 int i;
00147 for (i=0; i<progItem->childCount(); i++)
00148 {
00149 MLAllocItem * enrolItem = dynamic_cast<MLAllocItem*>(progItem->child(i));
00150 ((enrolItem)->*(updateFn))(value);
00151 }
00152 desc = QString::number(i) + ": Modules updated.";
00153 pMainWindow->statusBar()->showMessage(desc);
00154 }
00155 else if (SelectedEnrol->rtti() == RootItem::ML_ALLOC_ITEM)
00156 {
00157 MLAllocItem * enrolItem = dynamic_cast<MLAllocItem*>(SelectedEnrol);
00158 ((enrolItem)->*(updateFn))(value);
00159 desc = enrolItem->getModuleDesc() + ": " + msg + " " + QString::number(value);
00160 pMainWindow->statusBar()->showMessage(desc + tr(" updated."));
00161 wdgt.lblModule->setText(desc);
00162 }
00163 wdgt.trvModules->update();
00164 }
00165
00166 void ModuleEnrolPageWidget::classSizeClicked()
00167 {
00168 classSizeUpdate(wdgt.edtClassSize->text());
00169 focusNextChild ();
00170 }
00171
00172 void ModuleEnrolPageWidget::classGroupsClicked()
00173 {
00174 classGroupsUpdate(wdgt.edtGroups->text());
00175 focusNextChild ();
00176 }
00177
00178 void ModuleEnrolPageWidget::labHoursClicked()
00179 {
00180 labHoursUpdate(wdgt.edtLabHours->text());
00181 focusNextChild ();
00182 }
00183
00184 void ModuleEnrolPageWidget::labGroupsClicked()
00185 {
00186 labGroupsUpdate(wdgt.edtLabGroups->text());
00187 wdgt.trvModules->setFocus();
00188 }