⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subjectsform.cpp

📁 基于遗传算法的排课软件源码 根据需要安排合理的课程时间等
💻 CPP
字号:
////// C++ Implementation: $MODULE$//// Description:////// Author: Lalescu Liviu <liviu@lalescu.ro>, (C) 2003//// Copyright: See COPYING file that comes with this distribution////#include "genetictimetable_defs.h"#include "genetictimetable.h"#include "fet.h"#include "subjectsform.h"#include "fetmainform.h"#include "studentsset.h"#include "teacher.h"#include "subject.h"#include <qlistbox.h>#include <qinputdialog.h>#include <qtextedit.h>SubjectsForm::SubjectsForm() : SubjectsForm_template(){	subjectsListBox->clear();	for(Subject* sbj=gt.rules.subjectsList.first(); sbj; sbj=gt.rules.subjectsList.next())		subjectsListBox->insertItem(sbj->name);			if(subjectsListBox->count()>0){		subjectsListBox->setCurrentItem(0);		this->subjectChanged(0);	}}SubjectsForm::~SubjectsForm(){}void SubjectsForm::addSubject(){	bool ok = FALSE;	Subject* sbj=new Subject();	sbj->name = QInputDialog::getText( QObject::tr("User input"), QObject::tr("Please enter subject's name") ,                    QLineEdit::Normal, QString::null, &ok, this );	if ( ok && !((sbj->name).isEmpty()) ){		// user entered something and pressed OK		if(!gt.rules.addSubject(sbj)){			QMessageBox::information( this, QObject::tr("Subject insertion dialog"),				QObject::tr("Could not insert item. Must be a duplicate"));			delete sbj;		}		else{			subjectsListBox->insertItem(sbj->name);			subjectsListBox->setCurrentItem(subjectsListBox->count()-1);			this->subjectChanged(subjectsListBox->count()-1);		}	}	else		delete sbj;// user entered nothing or pressed Cancel}void SubjectsForm::removeSubject(){	int i=subjectsListBox->currentItem();	if(subjectsListBox->currentItem()<0){		QMessageBox::information(this, QObject::tr("FET information"), QObject::tr("Invalid selected subject"));		return;	}	QString text=subjectsListBox->currentText();	int subject_ID=gt.rules.searchSubject(text);	if(subject_ID<0){		QMessageBox::information(this, QObject::tr("FET information"), QObject::tr("Invalid selected subject"));		return;	}	if(QMessageBox::warning( this, QObject::tr("FET"),		QObject::tr("Are you sure you want to delete this subject and all related activities and constraints?\n"),		QObject::tr("Yes"), QObject::tr("No"), 0, 0, 1 ) == 1)		return;	int tmp=gt.rules.removeSubject(text);	if(tmp){		subjectsListBox->removeItem(subjectsListBox->currentItem());		if((uint)(i)>=subjectsListBox->count())			i=subjectsListBox->count()-1;		subjectsListBox->setCurrentItem(i);		this->subjectChanged(i);	}}void SubjectsForm::renameSubject(){	int i=subjectsListBox->currentItem();	if(subjectsListBox->currentItem()<0){		QMessageBox::information(this, QObject::tr("FET information"), QObject::tr("Invalid selected subject"));		return;	}		QString initialSubjectName=subjectsListBox->currentText();	int subject_ID=gt.rules.searchSubject(initialSubjectName);	if(subject_ID<0){		QMessageBox::information(this, QObject::tr("FET information"), QObject::tr("Invalid selected subject"));		return;	}	bool ok = FALSE;	QString finalSubjectName;	finalSubjectName = QInputDialog::getText( QObject::tr("User input"), QObject::tr("Please enter new subject's name") ,                    QLineEdit::Normal, initialSubjectName, &ok, this );	if ( ok && !(finalSubjectName.isEmpty()) ){		// user entered something and pressed OK		if(gt.rules.searchSubject(finalSubjectName)>=0){			QMessageBox::information( this, QObject::tr("Subject insertion dialog"),				QObject::tr("Could not modify item. New name must be a duplicate"));		}		else{			gt.rules.modifySubject(initialSubjectName, finalSubjectName);			subjectsListBox->changeItem(finalSubjectName, i);		}	}}void SubjectsForm::sortSubjects(){	gt.rules.sortSubjectsAlphabetically();	subjectsListBox->clear();	for(Subject* sbj=gt.rules.subjectsList.first(); sbj; sbj=gt.rules.subjectsList.next())		subjectsListBox->insertItem(sbj->name);	}void SubjectsForm::subjectChanged(int index){	if(index<0){		currentSubjectTextEdit->setText(QObject::tr("Invalid subject"));		return;	}		Subject* sb=gt.rules.subjectsList.at(index);	assert(sb);	QString s=sb->getDetailedDescriptionWithConstraints(gt.rules);	currentSubjectTextEdit->setText(s);}void SubjectsForm::activateSubject(){	if(subjectsListBox->currentItem()<0){		QMessageBox::information(this, QObject::tr("FET information"), QObject::tr("Invalid selected subject"));		return;	}		QString subjectName=subjectsListBox->currentText();		int count=gt.rules.activateSubject(subjectName);	QMessageBox::information(this, QObject::tr("FET information"), QObject::tr("Activated a number of %1 activities").arg(count));}void SubjectsForm::deactivateSubject(){	if(subjectsListBox->currentItem()<0){		QMessageBox::information(this, QObject::tr("FET information"), QObject::tr("Invalid selected subject"));		return;	}		QString subjectName=subjectsListBox->currentText();		int count=gt.rules.deactivateSubject(subjectName);	QMessageBox::information(this, QObject::tr("FET information"), QObject::tr("De-activated a number of %1 activities").arg(count));}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -