From d6c1e7e5d6894985b0a82f96a31cff668a7b89cb Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Mon, 13 Oct 2014 18:22:31 +0300 Subject: [PATCH] Added exams to the export - if user chooses to Tested on linux - works well! :wink: --- main/CalendarTab/CalendarManager.cpp | 2 +- main/mainscreen.h | 2 +- src/jceData/CSV/csv_exporter.cpp | 61 +++++++++++++++++-- src/jceData/CSV/csv_exporter.h | 3 +- .../coursesSchedule/calendarDialog.cpp | 4 ++ .../Calendar/coursesSchedule/calendarDialog.h | 1 + .../coursesSchedule/calendarDialog.ui | 4 +- 7 files changed, 66 insertions(+), 11 deletions(-) diff --git a/main/CalendarTab/CalendarManager.cpp b/main/CalendarTab/CalendarManager.cpp index 403143c..a763fc2 100644 --- a/main/CalendarTab/CalendarManager.cpp +++ b/main/CalendarTab/CalendarManager.cpp @@ -36,7 +36,7 @@ void CalendarManager::exportCalendarCSV() //calDialog.getStartDate(),calDialog.getEndDate() if (caliDialog->ok()) { - if (CSV_Exporter::exportCalendar(caliSchedPtr, caliDialog)) + if (CSV_Exporter::exportCalendar(caliSchedPtr, caliDialog, examSchePtr)) { msgBox.setIcon(QMessageBox::Information); msgBox.setText(QObject::tr("Exported Successfuly!")); diff --git a/main/mainscreen.h b/main/mainscreen.h index cc3b63e..b01f990 100644 --- a/main/mainscreen.h +++ b/main/mainscreen.h @@ -10,7 +10,7 @@ #include "./CourseTab/coursestablemanager.h" #include "./LoginTab/loginhandler.h" #include "./CalendarTab/CalendarManager.h" -#include "./jceWidgets/jceStatusBar.h" +#include "./jceWidgets/jcestatusbar.h" diff --git a/src/jceData/CSV/csv_exporter.cpp b/src/jceData/CSV/csv_exporter.cpp index 7f22f69..0eca597 100644 --- a/src/jceData/CSV/csv_exporter.cpp +++ b/src/jceData/CSV/csv_exporter.cpp @@ -3,7 +3,6 @@ /* * * Class doc can be found in csv_exporter.h - * TODO: add exam exportation */ CSV_Exporter::CSV_Exporter() { @@ -18,7 +17,7 @@ CSV_Exporter::CSV_Exporter() * @param cal - The Calendar dialog witch holdes the starting date and the eand date. * @return - True if *all* went well, false if something on the way went wrong. */ -bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *cal) +bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *cal, calendarExam *exams) { if ((cal == NULL) || (calSched == NULL)) //pointers checking! return false; @@ -97,6 +96,36 @@ bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *ca out.flush(); } + if(cal->isExams()) //Export Exams as well + { + qDebug() << "Exporting Exams!"; + for(calendarExamCourse* exam:exams->getExams()) + { + QTime startH = exam->getFirstHourbegin(); + QTime endH = startH.addSecs(60*60*3);//add 3 hours + QString type = "מבחן א"; + QString name = exam->getName(); + QDate date = exam->getFirstDate(); + QString line = makeLine(name, &date, startH.hour(), startH.minute(), endH.hour(), endH.minute(), "", "", type); + if(line != NULL) + out << line << char(0x0A); + else + qWarning() << Q_FUNC_INFO << "CSV : Got A NULL in Line! in function: " << Q_FUNC_INFO; + //=============== + // Second Date + //=============== + startH = exam->getSecondHourbegin(); + endH = startH.addSecs(60*60*3);//add 3 hours + date = exam->getSecondDate(); + type = "מבחן ב"; + line = makeLine(name, &date, startH.hour(), startH.minute(), endH.hour(), endH.minute(), "", "", type); + if(line != NULL) + out << line << char(0x0A); + else + qWarning() << Q_FUNC_INFO << "CSV : Got A NULL in Line! in function: " << Q_FUNC_INFO; + } + out.flush(); + } file.close(); qDebug() << Q_FUNC_INFO << "CSV : Exported Successfully"; @@ -115,6 +144,10 @@ QString CSV_Exporter::getFileFath() QObject::tr("CSV Files (*.csv);;All Files (*)")); if (fileName == "") return NULL; + + //IMPORTENT! ADD CSV EXTENTION + if(!fileName.contains(".csv") && !fileName.contains(".CSV")) + fileName.append(".csv"); return fileName; } @@ -149,20 +182,32 @@ QString CSV_Exporter::makeLine(QString name, QDate *date, int startH, int startM QString start; start.append(QString::number(startH)); - start.append(":00"); - // start.append(QString::number(startM)); + if(startM != 0) + { + start.append(":"); + start.append(QString::number(startM)); + } + else + start.append(":00"); start.append(":00"); QString end; end.append(QString::number(endH)); - end.append(":"); - end.append(QString::number(endM)); + if(endM != 0) + { + end.append(":"); + end.append(QString::number(endM)); + } + else + end.append(":00"); end.append(":00"); QString description = "\"מרצה "; if (lecturer == LECTURER_DEFAULT_STRING) description.append("טרם נקבע מרצה או מתרגל"); + else if(lecturer == "") + description = ""; else description.append(lecturer); @@ -176,6 +221,9 @@ QString CSV_Exporter::makeLine(QString name, QDate *date, int startH, int startM description.append(room); } + if(room == "") + description = "\"\Good Luck!\n"; + description.append("\n Created with JCE Manager.\""); //Create the Fucking Line @@ -237,3 +285,4 @@ void CSV_Exporter::changeDayNumberFromQtToNormal(int *QtDay) } return; //Done. } + diff --git a/src/jceData/CSV/csv_exporter.h b/src/jceData/CSV/csv_exporter.h index d83ddac..886448e 100644 --- a/src/jceData/CSV/csv_exporter.h +++ b/src/jceData/CSV/csv_exporter.h @@ -18,6 +18,7 @@ #include "../Calendar/coursesSchedule/calendarSchedule.h" #include "../Calendar/coursesSchedule/calendarDialog.h" +#include "../Calendar/Exams/calendarExam.h" #define CSV_CALENDAR_HEADER "Subject,Start Date,Start Time,End Date,End Time,Description,Location" @@ -26,7 +27,7 @@ class CSV_Exporter { public: CSV_Exporter(); - static bool exportCalendar(calendarSchedule* calSched, CalendarDialog *cal); + static bool exportCalendar(calendarSchedule* calSched, CalendarDialog *cal, calendarExam* exams); private: diff --git a/src/jceData/Calendar/coursesSchedule/calendarDialog.cpp b/src/jceData/Calendar/coursesSchedule/calendarDialog.cpp index cd9984f..0daa0fd 100644 --- a/src/jceData/Calendar/coursesSchedule/calendarDialog.cpp +++ b/src/jceData/Calendar/coursesSchedule/calendarDialog.cpp @@ -96,3 +96,7 @@ void CalendarDialog::changeLabeStatusIcon(bool goodOrBad) iconPixStatus.load(":/icons/iconX.png"); this->ui->labelIconStatus->setPixmap(iconPixStatus); } + +bool CalendarDialog::isExams(){ + return ui->isExam->isChecked(); +} diff --git a/src/jceData/Calendar/coursesSchedule/calendarDialog.h b/src/jceData/Calendar/coursesSchedule/calendarDialog.h index 1adbe5a..40c187e 100644 --- a/src/jceData/Calendar/coursesSchedule/calendarDialog.h +++ b/src/jceData/Calendar/coursesSchedule/calendarDialog.h @@ -30,6 +30,7 @@ public: QDate getStartDate(); QDate getEndDate(); bool ok(); + bool isExams(); private slots: void on_calStart_selectionChanged(); diff --git a/src/jceData/Calendar/coursesSchedule/calendarDialog.ui b/src/jceData/Calendar/coursesSchedule/calendarDialog.ui index cf08792..8ca5dda 100644 --- a/src/jceData/Calendar/coursesSchedule/calendarDialog.ui +++ b/src/jceData/Calendar/coursesSchedule/calendarDialog.ui @@ -6,7 +6,7 @@ 0 0 - 609 + 830 310 @@ -184,7 +184,7 @@ - + Include Exams