From 8d5385f99e224801682aaae564ff4f5dc1d639cf Mon Sep 17 00:00:00 2001 From: liranbg Date: Fri, 10 Oct 2014 21:33:08 +0300 Subject: [PATCH] gradepage documentation, using qlist --- main/CourseTab/coursestablemanager.cpp | 8 +- src/jceData/Calendar/Exams/calendarExam.cpp | 12 +- src/jceData/Calendar/Exams/calendarExam.h | 13 +- .../Calendar/Exams/calendarExamCourse.h | 11 + src/jceData/Calendar/Exams/examDialog.cpp | 13 +- src/jceData/Calendar/Exams/examDialog.h | 10 + .../Calendar/coursesSchedule/calendarDialog.h | 15 +- src/jceData/Grades/gradeCourse.h | 3 - src/jceData/Grades/gradePage.cpp | 267 ++++++++++-------- src/jceData/Grades/gradePage.h | 7 +- 10 files changed, 202 insertions(+), 157 deletions(-) diff --git a/main/CourseTab/coursestablemanager.cpp b/main/CourseTab/coursestablemanager.cpp index 30646e7..da0d613 100644 --- a/main/CourseTab/coursestablemanager.cpp +++ b/main/CourseTab/coursestablemanager.cpp @@ -33,7 +33,7 @@ coursesTableManager::~coursesTableManager() */ void coursesTableManager::insertJceCoursesIntoTable() { - for (gradeCourse *c: *gp->getCourses()) + for (gradeCourse *c: gp->getCourses()) { if (us->getInfluenceCourseOnly()) { @@ -69,7 +69,7 @@ bool coursesTableManager::changes(QString change, int row, int col) return true; int serialCourse = courseTBL->item(row,gradeCourse::CourseScheme::SERIAL)->text().toInt(); - for (gradeCourse *c: *gp->getCourses()) + for (gradeCourse *c: gp->getCourses()) { if (c->getSerialNum() == serialCourse) { @@ -267,7 +267,7 @@ void coursesTableManager::influnceCourseChanged(bool ignoreCourseStatus) else { if (this->gp != NULL) - for (gradeCourse *c: *gp->getCourses()) + for (gradeCourse *c: gp->getCourses()) { if (!(isCourseAlreadyInserted(c->getSerialNum()))) if (c->getPoints() == 0) @@ -295,7 +295,7 @@ void coursesTableManager::clearTable() gradeCourse *coursesTableManager::getCourseByRow(int row) { QString courseSerial = courseTBL->item(row,gradeCourse::CourseScheme::SERIAL)->text(); - for (gradeCourse *c: *gp->getCourses()) + for (gradeCourse *c: gp->getCourses()) { if (c->getSerialNum() == courseSerial.toDouble()) return c; diff --git a/src/jceData/Calendar/Exams/calendarExam.cpp b/src/jceData/Calendar/Exams/calendarExam.cpp index 70141b1..31444b5 100644 --- a/src/jceData/Calendar/Exams/calendarExam.cpp +++ b/src/jceData/Calendar/Exams/calendarExam.cpp @@ -2,7 +2,6 @@ calendarExam::calendarExam() { - exams = NULL; htmlDataHolderParsed = ""; } @@ -13,10 +12,7 @@ calendarExam::calendarExam() void calendarExam::setPage(QString html) { examsCounter = 0; - if (exams == NULL) - exams = new QList(); - else - exams->clear(); + exams.clear(); this->htmlDataHolderParsed = getString(html); examListInit(htmlDataHolderParsed); } @@ -38,15 +34,15 @@ void calendarExam::examListInit(QString &linesTokinzedString) { calendarExamCourse *cTemp = lineToCourse(tempToken); if (cTemp != NULL) - this->exams->push_back(cTemp); + this->exams.push_back(cTemp); } } } /** * @brief calendarExam::lineToCourse getting line of exam with data and make it an object containing data (date, time, course name and etc) - * @param line - * @return + * @param line - parsed line with tabs between each relevant data + * @return object of examcourse with its data */ calendarExamCourse *calendarExam::lineToCourse(QString line) { diff --git a/src/jceData/Calendar/Exams/calendarExam.h b/src/jceData/Calendar/Exams/calendarExam.h index 20f5a3f..b538da4 100644 --- a/src/jceData/Calendar/Exams/calendarExam.h +++ b/src/jceData/Calendar/Exams/calendarExam.h @@ -8,14 +8,21 @@ #include #include - +/** + * @brief The calendarExam class + * + * This class generating html string to a list of examcourses + * Each item in a list is a course with its information (hour, day, name, serial and etc) + * + * Made By liran ben gida, LiranBG@gmail.com On 08/10/2014 + */ class calendarExam : public Page { public: calendarExam(); void setPage(QString html); - QList* getExams() { return exams; } + QList getExams() { return exams; } int getExamsCounter() const; @@ -26,7 +33,7 @@ private: calendarExamCourse * lineToCourse(QString line); QString htmlDataHolderParsed; - QList *exams; + QList exams; int examsCounter; //not including madei b }; diff --git a/src/jceData/Calendar/Exams/calendarExamCourse.h b/src/jceData/Calendar/Exams/calendarExamCourse.h index 4127074..12a37b8 100644 --- a/src/jceData/Calendar/Exams/calendarExamCourse.h +++ b/src/jceData/Calendar/Exams/calendarExamCourse.h @@ -13,6 +13,17 @@ #define HOUR_DEFAULT_STRING "00:00" #define SECOND_DATE_DEFAULT_STRING "nullSECOND_DATE" +/** + * @brief The calendarExamCourse class + * + * This class holds each exam course + * the course scheme can be found below, inside the enum ExamScheme + * + * The class's constructor gets the data and manipulate it into an object + * with its relevant information. + * + * Made By liran ben gida, LiranBG@gmail.com On 08/10/2014 + */ class calendarExamCourse : public Course { diff --git a/src/jceData/Calendar/Exams/examDialog.cpp b/src/jceData/Calendar/Exams/examDialog.cpp index a51a264..4c0ae8d 100644 --- a/src/jceData/Calendar/Exams/examDialog.cpp +++ b/src/jceData/Calendar/Exams/examDialog.cpp @@ -1,6 +1,10 @@ #include "examDialog.h" #include "ui_examDialog.h" - +/** + * @brief examDialog::examDialog + * @param parent + * @param calSchedPtr - list of courses with information about each exam + */ examDialog::examDialog(QWidget *parent, calendarExam *calSchedPtr) : QDialog(parent), ui(new Ui::examDialog) { @@ -20,6 +24,11 @@ examDialog::examDialog(QWidget *parent, calendarExam *calSchedPtr) : QDialog(par this->setModal(true); } +/** + * @brief examDialog::initializingDataIntoTable + * + * Inserting each object of exam into the table + */ void examDialog::initializingDataIntoTable() { ui->tableWidget->setRowCount(exams->getExamsCounter()); @@ -31,7 +40,7 @@ void examDialog::initializingDataIntoTable() QTimeEdit *firstHourbegin; QDateEdit *secondDate; QTimeEdit *secondHourbegin; - for (calendarExamCourse * tempExam: *exams->getExams()) + for (calendarExamCourse * tempExam: exams->getExams()) { j=0; lecturer = new QTableWidgetItem(); diff --git a/src/jceData/Calendar/Exams/examDialog.h b/src/jceData/Calendar/Exams/examDialog.h index 43d4341..24aef6b 100644 --- a/src/jceData/Calendar/Exams/examDialog.h +++ b/src/jceData/Calendar/Exams/examDialog.h @@ -10,6 +10,16 @@ namespace Ui { class examDialog; } +/** + * @brief The examDialog class + * + * This class preseting a Dialog with dates, information and time of exams + * + * This dialog main goal is to let the user an option to edit and see the containing data of his exam schedule. + * The user will be able to export the exam schedule into .CSV file through CalendarTab + * + * Made By liran ben gida, LiranBG@gmail.com On 08/10/2014 + */ class examDialog : public QDialog { Q_OBJECT diff --git a/src/jceData/Calendar/coursesSchedule/calendarDialog.h b/src/jceData/Calendar/coursesSchedule/calendarDialog.h index 52ca03f..1adbe5a 100644 --- a/src/jceData/Calendar/coursesSchedule/calendarDialog.h +++ b/src/jceData/Calendar/coursesSchedule/calendarDialog.h @@ -1,10 +1,12 @@ /** * JCE Manager (C) * - * This QDialog widget will hold the dates of a Semester, Start and End. + * This QDialog widget hold the dates of a Semester, Start and End. * * this dialog will help the csv_exporter class to export a CSV file that will contain * all the courses within that period of time. + * + * Made By Sagi Dayan, sagidayan@gmail.com On 22/09/2014 */ #ifndef CALENDARDIALOG_H @@ -18,17 +20,6 @@ namespace Ui { class CalendarDialog; } -/** - * @brief The CalendarDialog class - * - * This class preseting a Dialog with selection of dates - * The user has to choose between a starting point of semester to the end. - * - * This dialog main goal is to let the user an option to export his CSV - * containing data of his schedule. - * - * Made By Sagi Dayan, sagidayan@gmail.com On 22/09/2014 - */ class CalendarDialog : public QDialog { Q_OBJECT diff --git a/src/jceData/Grades/gradeCourse.h b/src/jceData/Grades/gradeCourse.h index bcdeff6..12d329b 100644 --- a/src/jceData/Grades/gradeCourse.h +++ b/src/jceData/Grades/gradeCourse.h @@ -8,9 +8,6 @@ * LiranBG@gmail.com */ #include "../course.h" -#include -#include -#include #define COURSE_FIELDS 10 #define NO_GRADE_YET 101; diff --git a/src/jceData/Grades/gradePage.cpp b/src/jceData/Grades/gradePage.cpp index 456d19f..f63be27 100644 --- a/src/jceData/Grades/gradePage.cpp +++ b/src/jceData/Grades/gradePage.cpp @@ -5,165 +5,185 @@ static int minYear = 9999; GradePage::GradePage(QString html) : Page() { - courses = new std::list(); - tempHtml = getString(html); - coursesListInit(tempHtml); - + tempHtml = getString(html); + coursesListInit(tempHtml); } GradePage::~GradePage() { - for(Course* c : *courses) - delete c; - delete courses; + for (Course* c : courses) + delete c; } +/** + * @brief GradePage::removeCourse + * @param courseSerialID - course ID to remove + */ void GradePage::removeCourse(QString courseSerialID) { - for(gradeCourse* c : *courses) + for(gradeCourse* c : courses) { - if (c->getSerialNum() == courseSerialID.toInt()) + if (c->getSerialNum() == courseSerialID.toInt()) { - courses->remove(c); - delete c; - return; + courses.removeAll(c); + delete c; + return; } } } + +/** + * @brief GradePage::coursesListInit + * using lineToCourse function, its making a list of gradeCourse object from a given string of information + * @param linesTokinzedString list of courses, tokenized by lines. containing data of each course + */ void GradePage::coursesListInit(QString &linesTokinzedString) { - std::list stringHolder; - QString temp; - gradeCourse* cTemp = NULL; - char* tok; - char* textToTok = strdup(linesTokinzedString.toStdString().c_str()); - tok = strtok(textToTok,"\n"); - while (tok != NULL) //putting every line in a string holder before parsing it + QString tempToken; + + QStringList holder = linesTokinzedString.split("\n"); + QStringList::iterator iterator; + for (iterator = holder.begin(); iterator != holder.end(); ++iterator) { - temp = tok; - stringHolder.push_back(temp); - tok = strtok(NULL, "\n"); - } - for (QString temp: stringHolder) - { - cTemp = lineToCourse(temp); - if (cTemp != NULL) - courses->push_back(cTemp); + tempToken = (*iterator); + if ((!tempToken.isEmpty()) && (tempToken.length() > 1)) + { + gradeCourse *cTemp = lineToCourse(tempToken); + if (cTemp != NULL) + this->courses.push_back(cTemp); + } } } + +/** + * @brief GradePage::lineToCourse + * making an object of gradepage with the given information from string + * @param line - lines tokenized by tabs containing each course information (year, serial, name, points and etc..) + * @return + */ gradeCourse* GradePage::lineToCourse(QString line) { - gradeCourse *tempC = NULL; - QString templinearray[COURSE_FIELDS];//[serial,name,type,points,hours,grade,additions] - int serial,year,semester,courseNumInList; - double points,hours,grade; - QString name,type, additions; - QString tempS = ""; - int i = 0; - char* tok; - char* cLine = strdup(line.toStdString().c_str()); - tok = strtok(cLine, "\t"); - while(tok != NULL) + gradeCourse *tempC = NULL; + QString templinearray[COURSE_FIELDS];//[year,semester,numInList,serial,name,type,points,hours,grade,additions] + int serial,year,semester,courseNumInList; + double points,hours,grade; + QString name,type, additions; + + QString tempToken; + int i = 0; + QStringList holder = line.split("\t"); + QStringList::iterator iterator; + for (iterator = holder.begin(); iterator != holder.end(); ++iterator) { - tempS = tok; - if (i == gradeCourse::CourseScheme::SERIAL) //we need to extract the serial manually + tempToken = (*iterator); + tempToken = tempToken.trimmed(); + //we are checking it because in GPA, serial and course name are mixed + if (i == gradeCourse::CourseScheme::SERIAL) { - tempS = ""; - char *tokTemp; - tokTemp = tok; - while (!(isdigit((int)*tokTemp))) //getting to serial number starting pointer - tokTemp++; + QString tempDataOfSerialCourseName; - while (isdigit((int)*tokTemp)) //serial number + //getting serial + QStringList secHolder = tempToken.split(" "); + QStringList::iterator secIterator = secHolder.begin(); + tempDataOfSerialCourseName = *secIterator; + templinearray[i] = tempDataOfSerialCourseName.trimmed(); + //getting course name; + ++secIterator; + tempDataOfSerialCourseName.clear(); + while (secIterator != secHolder.end()) { - tempS += QString(*tokTemp); - tokTemp++; + tempDataOfSerialCourseName.append(*secIterator + " "); + secIterator++; } - templinearray[i] = tempS.trimmed(); - templinearray[i+1] = QString(tokTemp).trimmed(); - i +=2; //skipping on serial and course name + templinearray[++i] = tempDataOfSerialCourseName.trimmed(); } - else + else { - templinearray[i] = tempS.trimmed(); - i++; + templinearray[i] = tempToken; } - if (i == COURSE_FIELDS) - break; - tok=strtok(NULL, "\t"); + i++; + if (i >= COURSE_FIELDS) + break; } - if (templinearray[0] == "") //empty parsing + + if (templinearray[0] == "") //empty parsing { - qCritical() << Q_FUNC_INFO << "empty parsing"; - return NULL; + qCritical() << Q_FUNC_INFO << "empty parsing"; + return NULL; } - year = templinearray[gradeCourse::CourseScheme::YEAR].toInt(); - semester = templinearray[gradeCourse::CourseScheme::SEMESTER].toInt(); - courseNumInList = templinearray[gradeCourse::CourseScheme::COURSE_NUMBER_IN_LIST].toInt(); - serial = templinearray[gradeCourse::CourseScheme::SERIAL].toInt(); + year = templinearray[gradeCourse::CourseScheme::YEAR].toInt(); + semester = templinearray[gradeCourse::CourseScheme::SEMESTER].toInt(); + courseNumInList = templinearray[gradeCourse::CourseScheme::COURSE_NUMBER_IN_LIST].toInt(); + serial = templinearray[gradeCourse::CourseScheme::SERIAL].toInt(); - name = templinearray[gradeCourse::CourseScheme::NAME]; - type = templinearray[gradeCourse::CourseScheme::TYPE]; + name = templinearray[gradeCourse::CourseScheme::NAME]; + type = templinearray[gradeCourse::CourseScheme::TYPE]; - points = templinearray[gradeCourse::CourseScheme::POINTS].toDouble(); - hours = templinearray[gradeCourse::CourseScheme::HOURS].toDouble(); + points = templinearray[gradeCourse::CourseScheme::POINTS].toDouble(); + hours = templinearray[gradeCourse::CourseScheme::HOURS].toDouble(); - if (isGradedYet(templinearray[gradeCourse::CourseScheme::GRADE])) - grade = templinearray[gradeCourse::CourseScheme::GRADE].toDouble(); - else - grade = NO_GRADE_YET; + if (isGradedYet(templinearray[gradeCourse::CourseScheme::GRADE])) + grade = templinearray[gradeCourse::CourseScheme::GRADE].toDouble(); + else + grade = NO_GRADE_YET; - additions = templinearray[gradeCourse::CourseScheme::ADDITION]; + additions = templinearray[gradeCourse::CourseScheme::ADDITION]; - if (year >= maxYear) - maxYear = year; + if (year >= maxYear) + maxYear = year; - if (year <= minYear) - minYear = year; + if (year <= minYear) + minYear = year; - tempC = new gradeCourse(year,semester,courseNumInList,serial,name,type,points,hours,grade,additions); - return tempC; + tempC = new gradeCourse(year,semester,courseNumInList,serial,name,type,points,hours,grade,additions); + return tempC; } -//checking if one of the chars inside grade is not a number +/** + * @brief GradePage::isGradedYet checking if one of the chars inside grade is not a number + * @param grade + * @return if has bee graded or not + */ bool GradePage::isGradedYet(QString grade) { - if (strlen(grade.toStdString().c_str()) <= 1) - return false; - - for (char c: grade.toStdString()) - { - if (c == '\0') - break; - if (((!isdigit((int)c)) && (!isspace((int)c)))) //48 = 0, 57 = 9 + if (strlen(grade.toStdString().c_str()) <= 1) return false; + for (char c: grade.toStdString()) + { + if (c == '\0') + break; + if (((!isdigit((int)c)) && (!isspace((int)c)))) //48 = 0, 57 = 9 + return false; + } - return true; + return true; } + /** * @brief GradePage::getAvg getting avg * @return - gpa avg of all courses */ double GradePage::getAvg() { - double avg = 0; - double points = 0; - for (gradeCourse* c : *courses) + double avg = 0; + double points = 0; + for (gradeCourse* c : courses) { - if ((c->getGrade() != 0)) + if ((c->getGrade() != 0)) { - avg += c->getGrade() * c->getPoints(); - points += c->getPoints(); + avg += c->getGrade() * c->getPoints(); + points += c->getPoints(); } } - avg /= points; - return avg; + avg /= points; + return avg; } + /** * @brief GradePage::getAvg getting avg of given year * @param year - year (yyyy) @@ -171,56 +191,59 @@ double GradePage::getAvg() */ double GradePage::getAvg(int year) { - double avg = 0; - double points = 0; - for (gradeCourse* c : *courses) + double avg = 0; + double points = 0; + for (gradeCourse* c : courses) { - if ((c->getGrade() != 0) && (c->getYear() == year)) + if ((c->getGrade() != 0) && (c->getYear() == year)) { - avg += c->getGrade() * c->getPoints(); - points += c->getPoints(); + avg += c->getGrade() * c->getPoints(); + points += c->getPoints(); } } - if (points != 0) - avg /= points; - else - avg=0; - return avg; + if (points != 0) + avg /= points; + else + avg=0; + return avg; } + /** * @brief GradePage::getAvg * @param year - year (yyyy) * @param semester - semeser (1-3) * @return -gpa avg of given year in given semester */ + double GradePage::getAvg(int year, int semester) { - double avg = 0; - double points = 0; - for (gradeCourse* c : *courses) + double avg = 0; + double points = 0; + for (gradeCourse* c : courses) { - if ((c->getGrade() != 0) && (c->getYear() == year) && (c->getSemester() == semester)) + if ((c->getGrade() != 0) && (c->getYear() == year) && (c->getSemester() == semester)) { - avg += c->getGrade() * c->getPoints(); - points += c->getPoints(); + avg += c->getGrade() * c->getPoints(); + points += c->getPoints(); } } - if (points != 0) - avg /= points; - else - avg=0; - return avg; + if (points != 0) + avg /= points; + else + avg=0; + return avg; } + /** * @brief GradePage::getMinYearInList * @return the minimal year inside courses list */ int GradePage::getMinYearInList() { - return minYear; + return minYear; } int GradePage::getMaxYearInList() { - return maxYear; + return maxYear; } diff --git a/src/jceData/Grades/gradePage.h b/src/jceData/Grades/gradePage.h index 677c0e5..c94c428 100644 --- a/src/jceData/Grades/gradePage.h +++ b/src/jceData/Grades/gradePage.h @@ -11,7 +11,7 @@ #include "../page.h" #include "../Grades/gradeCourse.h" -#include +#include class GradePage : public Page { @@ -21,6 +21,7 @@ public: ~GradePage(); void removeCourse(QString courseSerialID); + double getAvg(); double getAvg(int year); double getAvg(int year, int semester); @@ -29,7 +30,7 @@ public: int getMaxYearInList(); - std::list* getCourses() { return courses; } + QList getCourses() { return courses; } private: @@ -38,7 +39,7 @@ private: bool isGradedYet(QString grade); - std::list* courses; + QList courses; QString tempHtml;