00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "ModuleAllocPage_wdgt.h"
00021
00022 #include "control_panel.h"
00023
00024 ModuleAllocPageWidget::ModuleAllocPageWidget(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
00035 wdgt.rztOddSem->setTwin(wdgt.rztEvenSem);
00036 wdgt.rztEvenSem->setTwin(wdgt.rztOddSem);
00037 wdgt.rztDeptStaff->setTwin(wdgt.rztInstStaff);
00038 wdgt.rztDeptStaff->setGrowDirection(gf_AutoResizeTreeView::gf_GD_HEIGHT);
00039 wdgt.rztInstStaff->setTwin(wdgt.rztDeptStaff);
00040 wdgt.rztInstStaff->setGrowDirection(gf_AutoResizeTreeView::gf_GD_HEIGHT);
00041
00042 wdgt.cbxInst->init(pDataLists);
00043 wdgt.cbxProg->init(pDataLists);
00044 wdgt.cbxDept->init(pDataLists);
00045
00046 vboxLayout = new QVBoxLayout();
00047 vboxLayout->setSpacing(0);
00048 vboxLayout->setMargin(0);
00049 vboxLayout->addWidget(this);
00050 layoutParent->addLayout(vboxLayout);
00051
00052 createActions();
00053 }
00054
00055 void ModuleAllocPageWidget::createActions()
00056 {
00057 connect (wdgt.cbxInst, SIGNAL(currentIndexChanged(QString)), this, SLOT(cbxInstSelected(QString)));
00058 connect (wdgt.cbxProg, SIGNAL(currentIndexChanged(QString)), this, SLOT(cbxProgSelected(QString)));
00059 connect (wdgt.cbxDept, SIGNAL(currentIndexChanged(QString)), this, SLOT(cbxDeptSelected(QString)));
00060
00061 connect (wdgt.btnAddAlloc, SIGNAL(clicked(bool)), this, SLOT(btnAddAllocation()));
00062 connect (wdgt.btnDelAlloc, SIGNAL(clicked(bool)), this, SLOT(btnDelAllocation()));
00063
00064 connect (wdgt.rztOddSem, SIGNAL(clicked(const QModelIndex &)), this, SLOT(itemModuleSelected(const QModelIndex &)));
00065 connect (wdgt.rztEvenSem, SIGNAL(clicked(const QModelIndex &)), this, SLOT(itemModuleSelected(const QModelIndex &)));
00066 connect (wdgt.rztDeptStaff, SIGNAL(clicked(const QModelIndex &)), this, SLOT(itemLecturerSelected(const QModelIndex &)));
00067 connect (wdgt.rztInstStaff, SIGNAL(clicked(const QModelIndex &)), this, SLOT(itemLecturerSelected(const QModelIndex &)));
00068 connect (wdgt.trvAllocation, SIGNAL(clicked(const QModelIndex &)), this, SLOT(itemAllocSelected(const QModelIndex &)));
00069
00070 }
00071
00072 void ModuleAllocPageWidget::cbxInstSelected(QString name)
00073 {
00074 Institute * instObj = pDataLists->getInstFromName(name);
00075 wdgt.cbxProg->init(pDataLists,name);
00076 wdgt.cbxDept->init(pDataLists,name);
00077 initrztInstStaff(instObj);
00078 initrzlModOdd(0);
00079 initrzlModEven(0);
00080 inittrvAlloc(0);
00081 }
00082
00083 void ModuleAllocPageWidget::cbxProgSelected(QString name)
00084 {
00085 QString instName = wdgt.cbxInst->currentText();
00086 Institute * instObj = pDataLists->getInstFromName(instName);
00087 Programme * progObj = pDataLists->getProgFromName(instObj, name);
00088 initrzlModOdd(progObj);
00089 initrzlModEven(progObj);
00090 inittrvAlloc(progObj);
00091
00092 }
00093
00094 void ModuleAllocPageWidget::cbxDeptSelected(QString name)
00095 {
00096 QString instName = wdgt.cbxInst->currentText();
00097 Institute * instObj = pDataLists->getInstFromName(instName);
00098 Department * deptObj = pDataLists->getDeptFromName(instObj, name);
00099 initrztDeptStaff(deptObj);
00100 }
00101
00102 void ModuleAllocPageWidget::initrzlModOdd(Programme * progObj)
00103 {
00104
00105 if (progObj == 0)
00106 wdgt.rztOddSem->setModel(0);
00107 else
00108 {
00109 ModuleModel * model = new ModuleModel(pDataLists, progObj, false, 0);
00110
00111 pDataLists->registerModel(model
00112 ,dbListManager::regModule
00113 );
00114 wdgt.rztOddSem->setModel(model);
00115 wdgt.rztOddSem->resizeColumnToContents(0);
00116 wdgt.rztOddSem->resizeColumnToContents(1);
00117 wdgt.rztOddSem->resizeColumnToContents(2);
00118 wdgt.rztOddSem->setRootIsDecorated(false);
00119 }
00120 }
00121 void ModuleAllocPageWidget::initrzlModEven(Programme * progObj)
00122 {
00123 if (progObj == 0)
00124 wdgt.rztEvenSem->setModel(0);
00125 else
00126 {
00127 ModuleModel * model = new ModuleModel(pDataLists, progObj, true, 0);
00128 pDataLists->registerModel(model
00129 ,dbListManager::regModule
00130 );
00131 wdgt.rztEvenSem->setModel(model);
00132 wdgt.rztEvenSem->resizeColumnToContents(0);
00133 wdgt.rztEvenSem->resizeColumnToContents(1);
00134 wdgt.rztEvenSem->resizeColumnToContents(2);
00135 wdgt.rztEvenSem->setRootIsDecorated(false);
00136 }
00137 }
00138
00139 void ModuleAllocPageWidget::inittrvAlloc(Programme * progObj)
00140 {
00141 if (progObj == 0)
00142 wdgt.trvAllocation->setModel(0);
00143 else
00144 {
00145 MLAllocModel * model = new MLAllocModel(pDataLists, progObj);
00146 pDataLists->registerModel(model
00147 ,dbListManager::regMLAlloc
00148 );
00149 wdgt.trvAllocation->setModel(model);
00150 wdgt.trvAllocation->resizeColumnToContents(0);
00151 wdgt.trvAllocation->setRootIsDecorated(false);
00152
00153 for (int i=0; i<model->getModuleCount(); i++)
00154 {
00155 hideModuleRow(model->getModuleAt(i));
00156 }
00157 }
00158 }
00159
00160 void ModuleAllocPageWidget::initrztDeptStaff(Department * deptObj)
00161 {
00162
00163 if (deptObj == 0)
00164 wdgt.rztDeptStaff->setModel(0);
00165 else
00166 {
00167 DeptItem * rootItem = new DeptItem(deptObj);
00168 StaffModel * model = new StaffModel(pDataLists, DataClass::DEPARTMENT_CLASS, rootItem, 0);
00169 pDataLists->registerModel(model
00170 ,dbListManager::regStaff
00171 );
00172 wdgt.rztDeptStaff->setModel(model);
00173 wdgt.rztDeptStaff->resizeColumnToContents(0);
00174 wdgt.rztDeptStaff->resizeColumnToContents(1);
00175 wdgt.rztDeptStaff->setRootIsDecorated(false);
00176 }
00177 }
00178
00179 void ModuleAllocPageWidget::initrztInstStaff(Institute * instObj)
00180 {
00181 if (instObj == 0)
00182 wdgt.rztInstStaff->setModel(0);
00183 else
00184 {
00185 InstItem * rootItem = new InstItem(instObj);
00186 StaffModel * model = new StaffModel(pDataLists, DataClass::DEPARTMENT_CLASS, rootItem, 0);
00187 pDataLists->registerModel(model
00188 ,dbListManager::regStaff
00189 );
00190 wdgt.rztInstStaff->setModel(model);
00191 wdgt.rztInstStaff->resizeColumnToContents(0);
00192 wdgt.rztInstStaff->resizeColumnToContents(1);
00193 wdgt.rztInstStaff->setRootIsDecorated(false);
00194 }
00195 }
00196
00197 void ModuleAllocPageWidget::hideModuleRow(Module * mod)
00198 {
00199 QTreeView * selectedModuleWidget;
00200 if (mod->isEvenSem())
00201 selectedModuleWidget = wdgt.rztEvenSem;
00202 else
00203 selectedModuleWidget = wdgt.rztOddSem;
00204 selectedModuleWidget->clearSelection();
00205 int selectedModuleRow = getModuleRow(mod, dynamic_cast<ModuleModel*>(selectedModuleWidget->model()));
00206 selectedModuleWidget->setRowHidden(selectedModuleRow, QModelIndex(), true);
00207 }
00208
00209 void ModuleAllocPageWidget::showModuleRow(Module * mod)
00210 {
00211 QTreeView * selectedModuleWidget;
00212 if (mod->isEvenSem())
00213 selectedModuleWidget = wdgt.rztEvenSem;
00214 else
00215 selectedModuleWidget = wdgt.rztOddSem;
00216 int selectedModuleRow = getModuleRow(mod, dynamic_cast<ModuleModel*>(selectedModuleWidget->model()));
00217 selectedModuleWidget->setRowHidden(selectedModuleRow, QModelIndex(), false);
00218 }
00219
00220 void ModuleAllocPageWidget::itemModuleSelected(const QModelIndex & index)
00221 {
00222 int row = index.row();
00223 if (row > -1)
00224 {
00225 selectedModule = dynamic_cast<ModuleItem*>(static_cast<RootItem*>(index.internalPointer()));
00226 pMainWindow->statusBar()->showMessage(selectedModule->getDescription() + tr(" selected."));
00227 }
00228 else
00229 selectedModule = 0;
00230 }
00231
00232
00233 void ModuleAllocPageWidget::itemLecturerSelected(const QModelIndex & index)
00234 {
00235 int row = index.row();
00236 if (row > -1)
00237 {
00238 selectedStaff = dynamic_cast<StaffItem*>(static_cast<RootItem*>(index.internalPointer()));
00239 pMainWindow->statusBar()->showMessage(selectedStaff->getDescription() + tr(" selected."));
00240 }
00241 else
00242 selectedStaff = 0;
00243 }
00244
00245 void ModuleAllocPageWidget::itemAllocSelected(const QModelIndex & index)
00246 {
00247 int row = index.row();
00248
00249 if (row > -1)
00250 {
00251 SelectedAllocation = dynamic_cast<MLAllocItem*>(static_cast<RootItem*>(index.internalPointer()));
00252 pMainWindow->statusBar()->showMessage(SelectedAllocation->getDescription() + tr(" selected."));
00253 }
00254 else
00255 SelectedAllocation = 0;
00256 }
00257
00258 void ModuleAllocPageWidget::btnAddAllocation()
00259 {
00260 if (selectedModule == 0 || selectedStaff == 0)
00261 return;
00262
00263 ModLecAlloc * mlAllocObj = new ModLecAlloc(DataClass::NOT_ON_DB
00264 ,selectedModule->getItemData()
00265 ,selectedStaff->getItemData()
00266 ,selectedModule->getModuWeeklyPeriods()
00267 );
00268 MLAllocItem * mlAllocItem = new MLAllocItem(mlAllocObj);
00269 QModelIndex index = QModelIndex();
00270 pDataLists->insert(mlAllocItem, pDataLists->MLAllocList(),index,mlAllocItem->getItemData()->dcCompareCI);
00271 hideModuleRow(selectedModule->getItemData());
00272 pMainWindow->statusBar()->showMessage(selectedModule->getDescription()
00273 +tr(" allocated to ")
00274 +selectedStaff->getDescription());
00275 selectedModule = 0;
00276 }
00277
00278 void ModuleAllocPageWidget::btnDelAllocation()
00279 {
00280 QString msg;
00281 if (SelectedAllocation == 0)
00282 return;
00283 msg = SelectedAllocation->getDescription() + tr(" has been unallocated.");
00284 pDataLists->remove(SelectedAllocation, pDataLists->MLAllocList());
00285 wdgt.trvAllocation->clearSelection();
00286 pMainWindow->statusBar()->showMessage(msg);
00287 showModuleRow(SelectedAllocation->getItemData()->getModule());
00288 SelectedAllocation = 0;
00289 }