graph view, parent pointer to table

This commit is contained in:
Liran BN 2014-10-12 16:48:42 +03:00
parent bec16503b7
commit 7980382db7
6 changed files with 593 additions and 528 deletions

View file

@ -5,46 +5,46 @@
*/ */
coursesTableManager::coursesTableManager(QTableWidget *ptr, user *usrPtr) coursesTableManager::coursesTableManager(QTableWidget *ptr, user *usrPtr)
{ {
this->gp = NULL; this->gp = NULL;
this->us = usrPtr; this->us = usrPtr;
this->courseTBL = ptr; this->courseTBL = ptr;
/* /*
* Initilizing Table * Initilizing Table
*/ */
courseTBL->setRowCount(0); courseTBL->setRowCount(0);
courseTBL->setColumnCount(COURSE_FIELDS); courseTBL->setColumnCount(COURSE_FIELDS);
QStringList mz; QStringList mz;
mz << QObject::tr("Number") << QObject::tr("Year") << QObject::tr("Semester") << QObject::tr("Serial") << QObject::tr("Name") << QObject::tr("Type") << QObject::tr("Points") << QObject::tr("Hours") << QObject::tr("Grade") << QObject::tr("Additions"); mz << QObject::tr("Number") << QObject::tr("Year") << QObject::tr("Semester") << QObject::tr("Serial") << QObject::tr("Name") << QObject::tr("Type") << QObject::tr("Points") << QObject::tr("Hours") << QObject::tr("Grade") << QObject::tr("Additions");
courseTBL->setHorizontalHeaderLabels(mz); courseTBL->setHorizontalHeaderLabels(mz);
courseTBL->verticalHeader()->setVisible(false); courseTBL->verticalHeader()->setVisible(false);
courseTBL->setSelectionMode(QAbstractItemView::SingleSelection); courseTBL->setSelectionMode(QAbstractItemView::SingleSelection);
courseTBL->setShowGrid(true); courseTBL->setShowGrid(true);
courseTBL->setStyleSheet("QTableView {selection-background-color: red;}"); courseTBL->setStyleSheet("QTableView {selection-background-color: red;}");
graph = new gradegraph(NULL); graph = new gradegraph(ptr);
} }
coursesTableManager::~coursesTableManager() coursesTableManager::~coursesTableManager()
{ {
courseTBL = NULL; courseTBL = NULL;
delete gp; delete gp;
gp = NULL; gp = NULL;
} }
/** /**
* @brief coursesTableManager::insertJceCoursesIntoTable phrasing the course list to rows in table * @brief coursesTableManager::insertJceCoursesIntoTable phrasing the course list to rows in table
*/ */
void coursesTableManager::insertJceCoursesIntoTable() void coursesTableManager::insertJceCoursesIntoTable()
{ {
for (gradeCourse *c: gp->getCourses()) for (gradeCourse *c: gp->getCourses())
{ {
if (us->getInfluenceCourseOnly()) if (us->getInfluenceCourseOnly())
{ {
if (isCourseInfluence(c)) if (isCourseInfluence(c))
addRow(c);
}
else
addRow(c); addRow(c);
}
else
addRow(c);
} }
} }
/** /**
@ -53,9 +53,9 @@ void coursesTableManager::insertJceCoursesIntoTable()
*/ */
void coursesTableManager::setCoursesList(QString &html) void coursesTableManager::setCoursesList(QString &html)
{ {
if (gp != NULL) if (gp != NULL)
gp->~GradePage(); gp->~GradePage();
gp = new GradePage(html); gp = new GradePage(html);
} }
/** /**
* @brief coursesTableManager::changes when user changes the table manually it updates it * @brief coursesTableManager::changes when user changes the table manually it updates it
@ -67,81 +67,81 @@ void coursesTableManager::setCoursesList(QString &html)
bool coursesTableManager::changes(QString change, int row, int col) bool coursesTableManager::changes(QString change, int row, int col)
{ {
bool isNumFlag = true; bool isNumFlag = true;
if (courseTBL->item(row,gradeCourse::CourseScheme::SERIAL) == NULL) if (courseTBL->item(row,gradeCourse::CourseScheme::SERIAL) == NULL)
return true; return true;
int serialCourse = courseTBL->item(row,gradeCourse::CourseScheme::SERIAL)->text().toInt(); int serialCourse = courseTBL->item(row,gradeCourse::CourseScheme::SERIAL)->text().toInt();
for (gradeCourse *c: gp->getCourses()) for (gradeCourse *c: gp->getCourses())
{ {
if (c->getSerialNum() == serialCourse) if (c->getSerialNum() == serialCourse)
{ {
switch (col) switch (col)
{ {
case (gradeCourse::CourseScheme::COURSE_NUMBER_IN_LIST): case (gradeCourse::CourseScheme::COURSE_NUMBER_IN_LIST):
c->setCourseNumInList(change.toInt()); c->setCourseNumInList(change.toInt());
break; break;
case (gradeCourse::CourseScheme::YEAR): case (gradeCourse::CourseScheme::YEAR):
c->setYear(change.toInt()); c->setYear(change.toInt());
break; break;
case (gradeCourse::CourseScheme::SEMESTER): case (gradeCourse::CourseScheme::SEMESTER):
c->setSemester(change.toInt()); c->setSemester(change.toInt());
break; break;
case (gradeCourse::CourseScheme::NAME): case (gradeCourse::CourseScheme::NAME):
c->setName(change); c->setName(change);
break; break;
case (gradeCourse::CourseScheme::TYPE): case (gradeCourse::CourseScheme::TYPE):
c->setType(change); c->setType(change);
break; break;
case (gradeCourse::CourseScheme::POINTS): case (gradeCourse::CourseScheme::POINTS):
{ {
change.toDouble(&isNumFlag); change.toDouble(&isNumFlag);
if (!isNumFlag) if (!isNumFlag)
{ {
courseTBL->item(row,col)->setText(QString::number(c->getPoints())); courseTBL->item(row,col)->setText(QString::number(c->getPoints()));
} }
else else
c->setPoints(change.toDouble()); c->setPoints(change.toDouble());
break; break;
} }
case (gradeCourse::CourseScheme::HOURS): case (gradeCourse::CourseScheme::HOURS):
{ {
change.toDouble(&isNumFlag); change.toDouble(&isNumFlag);
if (!isNumFlag) if (!isNumFlag)
{ {
courseTBL->item(row,col)->setText(QString::number(c->getHours())); courseTBL->item(row,col)->setText(QString::number(c->getHours()));
} }
else else
c->setHours(change.toDouble()); c->setHours(change.toDouble());
break; break;
} }
case (gradeCourse::CourseScheme::GRADE): case (gradeCourse::CourseScheme::GRADE):
{ {
change.toDouble(&isNumFlag); change.toDouble(&isNumFlag);
if (!isNumFlag) if (!isNumFlag)
{ {
courseTBL->item(row,col)->setText(QString::number(c->getGrade())); courseTBL->item(row,col)->setText(QString::number(c->getGrade()));
} }
else else
{ {
if ((change.toDouble() >= 0) && (change.toDouble() <= 100)) if ((change.toDouble() >= 0) && (change.toDouble() <= 100))
c->setGrade(change.toDouble()); c->setGrade(change.toDouble());
else else
courseTBL->item(row,col)->setText(QString::number(c->getGrade())); courseTBL->item(row,col)->setText(QString::number(c->getGrade()));
} }
break; break;
} }
case (gradeCourse::CourseScheme::ADDITION): case (gradeCourse::CourseScheme::ADDITION):
c->setAdditions(change); c->setAdditions(change);
break; break;
} }
break; break;
} }
} }
return isNumFlag; return isNumFlag;
} }
/** /**
@ -150,183 +150,190 @@ bool coursesTableManager::changes(QString change, int row, int col)
*/ */
void coursesTableManager::addRow(const gradeCourse *courseToAdd) void coursesTableManager::addRow(const gradeCourse *courseToAdd)
{ {
int i=1,j=1; int i=1,j=1;
j = 0; j = 0;
QTableWidgetItem *number,*year,*semester,*serial,*name,*type,*points,*hours,*grade,*addition; QTableWidgetItem *number,*year,*semester,*serial,*name,*type,*points,*hours,*grade,*addition;
const gradeCourse * c; const gradeCourse * c;
if (courseToAdd != NULL) if (courseToAdd != NULL)
{ {
c = courseToAdd; c = courseToAdd;
if (!isCourseAlreadyInserted(c->getSerialNum())) if (!isCourseAlreadyInserted(c->getSerialNum()))
{ {
courseTBL->setRowCount(courseTBL->rowCount() + 1); courseTBL->setRowCount(courseTBL->rowCount() + 1);
i = courseTBL->rowCount()-1; i = courseTBL->rowCount()-1;
number = new QTableWidgetItem(); number = new QTableWidgetItem();
number->setData(Qt::EditRole, c->getCourseNumInList()); number->setData(Qt::EditRole, c->getCourseNumInList());
number->setFlags(number->flags() & ~Qt::ItemIsEditable); number->setFlags(number->flags() & ~Qt::ItemIsEditable);
year = new QTableWidgetItem(); year = new QTableWidgetItem();
year->setData(Qt::EditRole,c->getYear()); year->setData(Qt::EditRole,c->getYear());
year->setFlags(year->flags() & ~Qt::ItemIsEditable); year->setFlags(year->flags() & ~Qt::ItemIsEditable);
semester = new QTableWidgetItem(); semester = new QTableWidgetItem();
semester->setData(Qt::EditRole,c->getSemester()); semester->setData(Qt::EditRole,c->getSemester());
semester->setFlags(semester->flags() & ~Qt::ItemIsEditable); semester->setFlags(semester->flags() & ~Qt::ItemIsEditable);
serial = new QTableWidgetItem(); serial = new QTableWidgetItem();
serial->setData(Qt::EditRole,c->getSerialNum()); serial->setData(Qt::EditRole,c->getSerialNum());
serial->setFlags(serial->flags() & ~Qt::ItemIsEditable); serial->setFlags(serial->flags() & ~Qt::ItemIsEditable);
name = new QTableWidgetItem(); name = new QTableWidgetItem();
name->setData(Qt::EditRole,c->getName()); name->setData(Qt::EditRole,c->getName());
name->setFlags(name->flags() & ~Qt::ItemIsEditable); name->setFlags(name->flags() & ~Qt::ItemIsEditable);
type = new QTableWidgetItem(); type = new QTableWidgetItem();
type->setData(Qt::EditRole, c->getType()); type->setData(Qt::EditRole, c->getType());
type->setFlags(type->flags() & ~Qt::ItemIsEditable); type->setFlags(type->flags() & ~Qt::ItemIsEditable);
points = new QTableWidgetItem(); points = new QTableWidgetItem();
points->setData(Qt::EditRole, c->getPoints()); points->setData(Qt::EditRole, c->getPoints());
points->setFlags(points->flags() & ~Qt::ItemIsEditable); points->setFlags(points->flags() & ~Qt::ItemIsEditable);
hours = new QTableWidgetItem(); hours = new QTableWidgetItem();
hours->setData(Qt::EditRole, c->getHours()); hours->setData(Qt::EditRole, c->getHours());
hours->setFlags(hours->flags() & ~Qt::ItemIsEditable); hours->setFlags(hours->flags() & ~Qt::ItemIsEditable);
grade = new QTableWidgetItem(); grade = new QTableWidgetItem();
grade->setData(Qt::EditRole,c->getGrade()); // grade->setData(Qt::EditRole,c->getGrade()); //BUG good for sorting, the problem is when you edit -> the cell indicator disappear
grade->setText(QString::number(c->getGrade()));
addition = new QTableWidgetItem(); addition = new QTableWidgetItem();
addition->setData(Qt::EditRole,c->getAddidtions()); addition->setData(Qt::EditRole,c->getAddidtions());
courseTBL->setItem(i,j++,number); courseTBL->setItem(i,j++,number);
courseTBL->setItem(i,j++,year); courseTBL->setItem(i,j++,year);
courseTBL->setItem(i,j++,semester); courseTBL->setItem(i,j++,semester);
courseTBL->setItem(i,j++,serial); courseTBL->setItem(i,j++,serial);
courseTBL->setItem(i,j++,name); courseTBL->setItem(i,j++,name);
courseTBL->setItem(i,j++,type); courseTBL->setItem(i,j++,type);
courseTBL->setItem(i,j++,points); courseTBL->setItem(i,j++,points);
courseTBL->setItem(i,j++,hours); courseTBL->setItem(i,j++,hours);
courseTBL->setItem(i,j,grade); courseTBL->setItem(i,j,grade);
if(c->getGrade() < 55 && c->getGrade() != 0)
//FIXME : make it a function, add it when cell has changed
if(c->getGrade() < 55 && c->getGrade() != 0)
{ {
courseTBL->item(i, j)->setBackground(Qt::darkRed); courseTBL->item(i, j)->setBackground(Qt::darkRed);
courseTBL->item(i,j)->setTextColor(Qt::white); courseTBL->item(i,j)->setTextColor(Qt::white);
} }
else if(55 <= c->getGrade() && c->getGrade() < 70 ) else if(55 <= c->getGrade() && c->getGrade() < 70 )
{ {
courseTBL->item(i, j)->setBackground(Qt::darkYellow); courseTBL->item(i, j)->setBackground(Qt::darkYellow);
courseTBL->item(i,j)->setTextColor(Qt::white); courseTBL->item(i,j)->setTextColor(Qt::white);
} }
// else if(70 < c->getGrade() && c->getGrade() <= 80 ) // else if(70 < c->getGrade() && c->getGrade() <= 80 )
// courseTBL->item(i, j)->setBackground(Qt::darkGreen); //They Look Bad!! // courseTBL->item(i, j)->setBackground(Qt::darkGreen); //They Look Bad!!
// else if(c->getGrade() > 80) // else if(c->getGrade() > 80)
// courseTBL->item(i, j)->setBackground(Qt::green); // courseTBL->item(i, j)->setBackground(Qt::green);
j++; j++;
courseTBL->setItem(i,j,addition); courseTBL->setItem(i,j,addition);
} }
} }
else else
{ {
qCritical() << Q_FUNC_INFO << " no course to load!"; qCritical() << Q_FUNC_INFO << " no course to load!";
} }
courseTBL->resizeColumnsToContents(); courseTBL->resizeColumnsToContents();
courseTBL->resizeRowsToContents(); courseTBL->resizeRowsToContents();
} }
double coursesTableManager::getAvg() double coursesTableManager::getAvg()
{ {
if (this->gp != NULL) if (this->gp != NULL)
return gp->getAvg(); return gp->getAvg();
return 0; return 0;
} }
void coursesTableManager::showGraph() void coursesTableManager::showGraph()
{ {
if (gp != NULL) qDebug() << Q_FUNC_INFO;
if (gp != NULL)
{ {
qDebug() << Q_FUNC_INFO << " Graph Dialog Opened. gp != NULL"; this->graph->showGraph(gp);
this->graph->showGraph(gp); }
else
{
qWarning() << Q_FUNC_INFO << "open with null grade page";
} }
} }
void coursesTableManager::influnceCourseChanged(bool ignoreCourseStatus) void coursesTableManager::influnceCourseChanged(bool ignoreCourseStatus)
{ {
if (ignoreCourseStatus) if (ignoreCourseStatus)
{ {
int i = 0; int i = 0;
while (i < courseTBL->rowCount()) while (i < courseTBL->rowCount())
{ {
if (courseTBL->item(i,gradeCourse::CourseScheme::POINTS)->text().compare("0") == 0) if (courseTBL->item(i,gradeCourse::CourseScheme::POINTS)->text().compare("0") == 0)
courseTBL->removeRow(i--); courseTBL->removeRow(i--);
i++; i++;
} }
} }
else else
{ {
if (this->gp != NULL) if (this->gp != NULL)
for (gradeCourse *c: gp->getCourses()) for (gradeCourse *c: gp->getCourses())
{ {
if (!(isCourseAlreadyInserted(c->getSerialNum()))) if (!(isCourseAlreadyInserted(c->getSerialNum())))
if (c->getPoints() == 0) if (c->getPoints() == 0)
addRow(c); addRow(c);
} }
} }
} }
void coursesTableManager::clearTable() void coursesTableManager::clearTable()
{ {
if (courseTBL->rowCount() == 0) if (courseTBL->rowCount() == 0)
return; return;
int i = 0; //starting point int i = 0; //starting point
while (courseTBL->rowCount() > i) while (courseTBL->rowCount() > i)
{ {
gp->removeCourse(courseTBL->item(i,gradeCourse::CourseScheme::SERIAL)->text()); gp->removeCourse(courseTBL->item(i,gradeCourse::CourseScheme::SERIAL)->text());
courseTBL->removeRow(i); courseTBL->removeRow(i);
} }
gp = NULL; gp = NULL;
courseTBL->repaint(); courseTBL->repaint();
} }
gradeCourse *coursesTableManager::getCourseByRow(int row) gradeCourse *coursesTableManager::getCourseByRow(int row)
{ {
QString courseSerial = courseTBL->item(row,gradeCourse::CourseScheme::SERIAL)->text(); QString courseSerial = courseTBL->item(row,gradeCourse::CourseScheme::SERIAL)->text();
for (gradeCourse *c: gp->getCourses()) for (gradeCourse *c: gp->getCourses())
{ {
if (c->getSerialNum() == courseSerial.toDouble()) if (c->getSerialNum() == courseSerial.toDouble())
return c; return c;
} }
return NULL; return NULL;
} }
bool coursesTableManager::isCourseAlreadyInserted(double courseID) bool coursesTableManager::isCourseAlreadyInserted(double courseID)
{ {
int i; int i;
for (i = courseTBL->rowCount(); i >= 0; --i) for (i = courseTBL->rowCount(); i >= 0; --i)
{ {
if (courseTBL->item(i,gradeCourse::CourseScheme::SERIAL) != NULL) if (courseTBL->item(i,gradeCourse::CourseScheme::SERIAL) != NULL)
{ {
QString courseSerial = courseTBL->item(i,gradeCourse::CourseScheme::SERIAL)->text(); QString courseSerial = courseTBL->item(i,gradeCourse::CourseScheme::SERIAL)->text();
if (QString::number(courseID) == courseSerial) if (QString::number(courseID) == courseSerial)
return true; return true;
} }
} }
return false; return false;
} }
bool coursesTableManager::isCourseInfluence(const gradeCourse *courseToCheck) bool coursesTableManager::isCourseInfluence(const gradeCourse *courseToCheck)
{ {
if (courseToCheck->getPoints() > 0) if (courseToCheck->getPoints() > 0)
return true; return true;
return false; return false;
} }

View file

@ -1,416 +1,417 @@
#include "mainscreen.h" #include "mainscreen.h"
#include "ui_mainscreen.h" #include "ui_mainscreen.h"
//TODO: busy flag to aboid overload request //TODO: busy flag to avoid overload request
MainScreen::MainScreen(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainScreen) MainScreen::MainScreen(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainScreen)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->labelMadeBy->setOpenExternalLinks(true); ui->labelMadeBy->setOpenExternalLinks(true);
//Login Tab //Login Tab
iconPix.load(":/icons/iconX.png"); iconPix.load(":/icons/iconX.png");
ui->pswdLineEdit->setEchoMode((QLineEdit::Password)); ui->pswdLineEdit->setEchoMode((QLineEdit::Password));
ui->labelUsrInputStatus->setVisible(false); ui->labelUsrInputStatus->setVisible(false);
ui->labelPswInputStatus->setVisible(false); ui->labelPswInputStatus->setVisible(false);
ui->labelUsrInputStatus->setPixmap(iconPix); ui->labelUsrInputStatus->setPixmap(iconPix);
ui->labelPswInputStatus->setPixmap(iconPix); ui->labelPswInputStatus->setPixmap(iconPix);
//StatusBar & progressbar //StatusBar & progressbar
ui->progressBar->setFixedHeight(STATUS_ICON_HEIGH); ui->progressBar->setFixedHeight(STATUS_ICON_HEIGH);
ui->statusBar->setStyleSheet("QStatusBar::item { border: 0px solid black };"); ui->statusBar->setStyleSheet("QStatusBar::item { border: 0px solid black };");
ui->statusBar->setFixedHeight(STATUS_ICON_HEIGH+5); ui->statusBar->setFixedHeight(STATUS_ICON_HEIGH+5);
ui->statusBar->showMessage(tr("Ready")); ui->statusBar->showMessage(tr("Ready"));
//GPA Tab //GPA Tab
ui->avgLCD->setPalette(QPalette(QPalette::WindowText,Qt::blue)); ui->avgLCD->setPalette(QPalette(QPalette::WindowText,Qt::blue));
//Pointer allocating //Pointer allocating
qDebug() << Q_FUNC_INFO << "Allocating pointers"; qDebug() << Q_FUNC_INFO << "Allocating pointers";
this->userLoginSetting = new user("",""); this->userLoginSetting = new user("","");
this->courseTableMgr = new coursesTableManager(ui->coursesTable,userLoginSetting); this->courseTableMgr = new coursesTableManager(ui->coursesTable,userLoginSetting);
this->loginHandel = new loginHandler(userLoginSetting,ui->statusBar,ui->loginButton,ui->progressBar); this->loginHandel = new loginHandler(userLoginSetting,ui->statusBar,ui->loginButton,ui->progressBar);
this->calendar = new CalendarManager(this,ui->calendarGridLayoutMain); this->calendar = new CalendarManager(this,ui->calendarGridLayoutMain);
this->data = new SaveData(); this->data = new SaveData();
//check login File //check login File
if (data->isSaved()) if (data->isSaved())
{ {
qDebug() << Q_FUNC_INFO << "Loading data from file"; qDebug() << Q_FUNC_INFO << "Loading data from file";
ui->usrnmLineEdit->setText(data->getUsername()); ui->usrnmLineEdit->setText(data->getUsername());
ui->pswdLineEdit->setText(data->getPassword()); ui->pswdLineEdit->setText(data->getPassword());
ui->keepLogin->setChecked(true); ui->keepLogin->setChecked(true);
} }
//language //language
qDebug() << Q_FUNC_INFO << "Checking locale"; qDebug() << Q_FUNC_INFO << "Checking locale";
checkLocale(); checkLocale();
ui->statusBar->repaint(); ui->statusBar->repaint();
qDebug() << Q_FUNC_INFO << "Ready."; qDebug() << Q_FUNC_INFO << "Ready.";
//set the progress bar to be invisible (It will show only if value !=0 or !=100) //set the progress bar to be invisible (It will show only if value !=0 or !=100)
ui->progressBar->setVisible(false); ui->progressBar->setVisible(false);
} }
MainScreen::~MainScreen() MainScreen::~MainScreen()
{ {
delete calendar; delete calendar;
delete courseTableMgr; delete courseTableMgr;
delete userLoginSetting; delete userLoginSetting;
delete loginHandel; delete loginHandel;
delete data; delete data;
delete ui; delete ui;
} }
//EVENTS ON LOGIN TAB //EVENTS ON LOGIN TAB
void MainScreen::on_loginButton_clicked() void MainScreen::on_loginButton_clicked()
{ {
ui->progressBar->setValue(0); ui->progressBar->setValue(0);
qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName();
if ((ui->usrnmLineEdit->text().isEmpty()) || (ui->pswdLineEdit->text().isEmpty())) if ((ui->usrnmLineEdit->text().isEmpty()) || (ui->pswdLineEdit->text().isEmpty()))
{ {
if (ui->usrnmLineEdit->text().isEmpty()) if (ui->usrnmLineEdit->text().isEmpty())
{ {
ui->labelUsrInputStatus->setVisible(true); ui->labelUsrInputStatus->setVisible(true);
qDebug() << Q_FUNC_INFO << "username input is empty"; qDebug() << Q_FUNC_INFO << "username input is empty";
} }
else else
ui->labelUsrInputStatus->setVisible(false);
if (ui->pswdLineEdit->text().isEmpty())
{
ui->labelPswInputStatus->setVisible(true);
qDebug() << Q_FUNC_INFO << "password input is empty";
}
else
ui->labelPswInputStatus->setVisible(false);
return;
}
else
{
ui->labelUsrInputStatus->setVisible(false); ui->labelUsrInputStatus->setVisible(false);
ui->labelPswInputStatus->setVisible(false); if (ui->pswdLineEdit->text().isEmpty())
}
qDebug() << Q_FUNC_INFO << "login session start";
QApplication::setOverrideCursor(Qt::WaitCursor);
if (this->loginHandel->login(ui->usrnmLineEdit->text(),ui->pswdLineEdit->text()) == true)
{
ui->progressBar->setValue(100);
qDebug() << Q_FUNC_INFO << "login session end with true";
ui->pswdLineEdit->setDisabled(true);
ui->usrnmLineEdit->setDisabled(true);
if (ui->keepLogin->isChecked())
{ {
qDebug() << Q_FUNC_INFO << "saving data"; ui->labelPswInputStatus->setVisible(true);
data->setUsername(ui->usrnmLineEdit->text()); qDebug() << Q_FUNC_INFO << "password input is empty";
data->setPassword(ui->pswdLineEdit->text()); }
else
ui->labelPswInputStatus->setVisible(false);
return;
}
else
{
ui->labelUsrInputStatus->setVisible(false);
ui->labelPswInputStatus->setVisible(false);
}
qDebug() << Q_FUNC_INFO << "login session start";
QApplication::setOverrideCursor(Qt::WaitCursor);
if (this->loginHandel->login(ui->usrnmLineEdit->text(),ui->pswdLineEdit->text()) == true)
{
ui->progressBar->setValue(100);
qDebug() << Q_FUNC_INFO << "login session end with true";
ui->pswdLineEdit->setDisabled(true);
ui->usrnmLineEdit->setDisabled(true);
if (ui->keepLogin->isChecked())
{
qDebug() << Q_FUNC_INFO << "saving data";
data->setUsername(ui->usrnmLineEdit->text());
data->setPassword(ui->pswdLineEdit->text());
} }
} }
else else
{ {
qDebug() << Q_FUNC_INFO << "login session end with false"; qDebug() << Q_FUNC_INFO << "login session end with false";
ui->pswdLineEdit->setDisabled(false); ui->pswdLineEdit->setDisabled(false);
ui->usrnmLineEdit->setDisabled(false); ui->usrnmLineEdit->setDisabled(false);
} }
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
} }
void MainScreen::on_keepLogin_clicked() void MainScreen::on_keepLogin_clicked()
{ {
qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName();
if (ui->keepLogin->isChecked()) if (ui->keepLogin->isChecked())
{ {
qDebug() << Q_FUNC_INFO << "saving data"; qDebug() << Q_FUNC_INFO << "saving data";
data->setUsername(ui->usrnmLineEdit->text()); data->setUsername(ui->usrnmLineEdit->text());
data->setPassword(ui->pswdLineEdit->text()); data->setPassword(ui->pswdLineEdit->text());
} }
else else
data->reset(); data->reset();
} }
void MainScreen::on_usrnmLineEdit_editingFinished() void MainScreen::on_usrnmLineEdit_editingFinished()
{ {
qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName();
ui->usrnmLineEdit->setText(ui->usrnmLineEdit->text().toLower()); ui->usrnmLineEdit->setText(ui->usrnmLineEdit->text().toLower());
} }
//EVENTS ON GPA TAB //EVENTS ON GPA TAB
void MainScreen::on_ratesButton_clicked() void MainScreen::on_ratesButton_clicked()
{ {
ui->progressBar->setValue(0);
qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); ui->progressBar->setValue(0);
if (!checkIfValidDates()) qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName();
if (!checkIfValidDates())
{ {
qWarning() << Q_FUNC_INFO << "Invalid dates! return"; qWarning() << Q_FUNC_INFO << "Invalid dates! return";
QMessageBox::critical(this,tr("Error"),tr("Invalid Dates.\nMake Sure everything is correct and try again")); QMessageBox::critical(this,tr("Error"),tr("Invalid Dates.\nMake Sure everything is correct and try again"));
return; return;
} }
QString pageString; QString pageString;
int status = 0; int status = 0;
QApplication::setOverrideCursor(Qt::WaitCursor); QApplication::setOverrideCursor(Qt::WaitCursor);
if (loginHandel->isLoggedInFlag()) if (loginHandel->isLoggedInFlag())
{ {
ui->statusBar->showMessage(tr("Getting grades...")); ui->statusBar->showMessage(tr("Getting grades..."));
if ((status = loginHandel->makeGradeRequest(ui->spinBoxCoursesFromYear->value(), if ((status = loginHandel->makeGradeRequest(ui->spinBoxCoursesFromYear->value(),
ui->spinBoxCoursesToYear->value(),ui->spinBoxCoursesFromSemester->value(), ui->spinBoxCoursesToYear->value(),ui->spinBoxCoursesFromSemester->value(),
ui->spinBoxCoursesToSemester->value())) == jceLogin::JCE_PAGE_PASSED) ui->spinBoxCoursesToSemester->value())) == jceLogin::JCE_PAGE_PASSED)
{ {
qDebug() << Q_FUNC_INFO << "grade page is ready"; qDebug() << Q_FUNC_INFO << "grade page is ready";
ui->statusBar->showMessage(tr("Done. Inserting data into table..."),1000); ui->statusBar->showMessage(tr("Done. Inserting data into table..."),1000);
pageString = loginHandel->getCurrentPageContect(); pageString = loginHandel->getCurrentPageContect();
courseTableMgr->setCoursesList(pageString); courseTableMgr->setCoursesList(pageString);
courseTableMgr->insertJceCoursesIntoTable(); courseTableMgr->insertJceCoursesIntoTable();
ui->progressBar->setValue(100); ui->progressBar->setValue(100);
ui->statusBar->showMessage(tr("Done")); ui->statusBar->showMessage(tr("Done"));
} }
else if (status == jceLogin::JCE_NOT_CONNECTED) else if (status == jceLogin::JCE_NOT_CONNECTED)
{ {
qWarning() << Q_FUNC_INFO << "not connected"; qWarning() << Q_FUNC_INFO << "not connected";
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
QMessageBox::critical(this,tr("Error"),tr("Not Connected")); QMessageBox::critical(this,tr("Error"),tr("Not Connected"));
} }
else else
{ {
qCritical() << Q_FUNC_INFO << "grade get ended with" << status; qCritical() << Q_FUNC_INFO << "grade get ended with" << status;
} }
} }
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
} }
bool MainScreen::checkIfValidDates() bool MainScreen::checkIfValidDates()
{ {
bool flag = false; bool flag = false;
if (ui->spinBoxCoursesFromYear->value() < ui->spinBoxCoursesToYear->value()) if (ui->spinBoxCoursesFromYear->value() < ui->spinBoxCoursesToYear->value())
{ {
//doesnt matter what is the semester, its valid! //doesnt matter what is the semester, its valid!
flag = true;
}
else if ((ui->spinBoxCoursesFromYear->value() == ui->spinBoxCoursesToYear->value()))
{
//semester from must be equal or less than to semester
if (ui->spinBoxCoursesFromSemester->value() <= ui->spinBoxCoursesToSemester->value())
flag = true; flag = true;
} }
else if ((ui->spinBoxCoursesFromYear->value() == ui->spinBoxCoursesToYear->value())) return flag;
{
//semester from must be equal or less than to semester
if (ui->spinBoxCoursesFromSemester->value() <= ui->spinBoxCoursesToSemester->value())
flag = true;
}
return flag;
} }
void MainScreen::on_checkBoxCoursesInfluence_toggled(bool checked) void MainScreen::on_checkBoxCoursesInfluence_toggled(bool checked)
{ {
qDebug() << Q_FUNC_INFO << "only main courses toggeled" << checked; qDebug() << Q_FUNC_INFO << "only main courses toggeled" << checked;
this->userLoginSetting->setInfluenceCourseOnly(checked); this->userLoginSetting->setInfluenceCourseOnly(checked);
this->courseTableMgr->influnceCourseChanged(checked); this->courseTableMgr->influnceCourseChanged(checked);
} }
void MainScreen::on_spinBoxCoursesFromYear_valueChanged(int arg1) void MainScreen::on_spinBoxCoursesFromYear_valueChanged(int arg1)
{ {
ui->spinBoxCoursesFromYear->setValue(arg1); ui->spinBoxCoursesFromYear->setValue(arg1);
} }
void MainScreen::on_spinBoxCoursesToYear_valueChanged(int arg1) void MainScreen::on_spinBoxCoursesToYear_valueChanged(int arg1)
{ {
ui->spinBoxCoursesToYear->setValue(arg1); ui->spinBoxCoursesToYear->setValue(arg1);
} }
void MainScreen::on_spinBoxCoursesFromSemester_valueChanged(int arg1) void MainScreen::on_spinBoxCoursesFromSemester_valueChanged(int arg1)
{ {
ui->spinBoxCoursesFromSemester->setValue(arg1%4); ui->spinBoxCoursesFromSemester->setValue(arg1%4);
} }
void MainScreen::on_spinBoxCoursesToSemester_valueChanged(int arg1) void MainScreen::on_spinBoxCoursesToSemester_valueChanged(int arg1)
{ {
ui->spinBoxCoursesToSemester->setValue(arg1%4); ui->spinBoxCoursesToSemester->setValue(arg1%4);
} }
void MainScreen::on_coursesTable_itemChanged(QTableWidgetItem *item) void MainScreen::on_coursesTable_itemChanged(QTableWidgetItem *item)
{ {
if (this->courseTableMgr->changes(item->text(),item->row(),item->column())) if (this->courseTableMgr->changes(item->text(),item->row(),item->column()))
ui->avgLCD->display(courseTableMgr->getAvg()); ui->avgLCD->display(courseTableMgr->getAvg());
else else
{ {
qWarning() << Q_FUNC_INFO << "missmatch data"; qWarning() << Q_FUNC_INFO << "missmatch data";
QMessageBox::critical(this,tr("Error"),tr("Missmatching data")); QMessageBox::critical(this,tr("Error"),tr("Missmatching data"));
} }
} }
void MainScreen::on_clearTableButton_clicked() void MainScreen::on_clearTableButton_clicked()
{ {
qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName();
courseTableMgr->clearTable(); courseTableMgr->clearTable();
ui->avgLCD->display(courseTableMgr->getAvg()); ui->avgLCD->display(courseTableMgr->getAvg());
} }
void MainScreen::on_graphButton_clicked() void MainScreen::on_graphButton_clicked()
{ {
qDebug() << "Show Graph button clicked"; qDebug() << Q_FUNC_INFO;
courseTableMgr->showGraph(); courseTableMgr->showGraph();
} }
//EVENTS ON CALENDAR TAB //EVENTS ON CALENDAR TAB
void MainScreen::on_examsBtn_clicked() void MainScreen::on_examsBtn_clicked()
{ {
calendar->showExamDialog(); calendar->showExamDialog();
} }
void MainScreen::on_getCalendarBtn_clicked() void MainScreen::on_getCalendarBtn_clicked()
{ {
ui->progressBar->setValue(0); ui->progressBar->setValue(0);
qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName();
int status = 0; int status = 0;
QString page; QString page;
QApplication::setOverrideCursor(Qt::WaitCursor); QApplication::setOverrideCursor(Qt::WaitCursor);
if (loginHandel->isLoggedInFlag()) if (loginHandel->isLoggedInFlag())
{ {
ui->statusBar->showMessage(tr("Getting schedule...")); ui->statusBar->showMessage(tr("Getting schedule..."));
if ((status = loginHandel->makeCalendarRequest(ui->spinBoxYear->value(),ui->spinBoxSemester->value())) == jceLogin::JCE_PAGE_PASSED) if ((status = loginHandel->makeCalendarRequest(ui->spinBoxYear->value(),ui->spinBoxSemester->value())) == jceLogin::JCE_PAGE_PASSED)
{ {
calendar->resetTable(); calendar->resetTable();
ui->statusBar->showMessage(tr("Done. Inserting schdule into table..."),1000); ui->statusBar->showMessage(tr("Done. Inserting schdule into table..."),1000);
page = loginHandel->getCurrentPageContect(); page = loginHandel->getCurrentPageContect();
calendar->setCalendar(page); calendar->setCalendar(page);
qDebug() << Q_FUNC_INFO << "calendar is loaded"; qDebug() << Q_FUNC_INFO << "calendar is loaded";
//auto getting exam //auto getting exam
if (loginHandel->isLoggedInFlag()) if (loginHandel->isLoggedInFlag())
{ {
ui->statusBar->showMessage(tr("Getting exams...")); ui->statusBar->showMessage(tr("Getting exams..."));
if ((status = loginHandel->makeExamsScheduleRequest(ui->spinBoxYear->value(),ui->spinBoxSemester->value())) == jceLogin::JCE_PAGE_PASSED) if ((status = loginHandel->makeExamsScheduleRequest(ui->spinBoxYear->value(),ui->spinBoxSemester->value())) == jceLogin::JCE_PAGE_PASSED)
{ {
ui->statusBar->showMessage(tr("Done."),1000); ui->statusBar->showMessage(tr("Done."),1000);
page = loginHandel->getCurrentPageContect(); page = loginHandel->getCurrentPageContect();
calendar->setExamsSchedule(page); calendar->setExamsSchedule(page);
qDebug() << Q_FUNC_INFO << "exams schedule is loaded"; qDebug() << Q_FUNC_INFO << "exams schedule is loaded";
} }
else if (status == jceLogin::JCE_NOT_CONNECTED) else if (status == jceLogin::JCE_NOT_CONNECTED)
{ {
qWarning() << Q_FUNC_INFO << "not connected"; qWarning() << Q_FUNC_INFO << "not connected";
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
QMessageBox::critical(this,tr("Error"),tr("Not Connected")); QMessageBox::critical(this,tr("Error"),tr("Not Connected"));
} }
else else
qCritical() << Q_FUNC_INFO << "exams request get ended with" << status; qCritical() << Q_FUNC_INFO << "exams request get ended with" << status;
ui->progressBar->setValue(100); ui->progressBar->setValue(100);
ui->statusBar->showMessage(tr("Done")); ui->statusBar->showMessage(tr("Done"));
} }
else if (status == jceLogin::JCE_NOT_CONNECTED) else if (status == jceLogin::JCE_NOT_CONNECTED)
{ {
qWarning() << Q_FUNC_INFO << "not connected"; qWarning() << Q_FUNC_INFO << "not connected";
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
QMessageBox::critical(this,tr("Error"),tr("Not Connected")); QMessageBox::critical(this,tr("Error"),tr("Not Connected"));
} }
else else
qCritical() << Q_FUNC_INFO << "calendar get ended with" << status; qCritical() << Q_FUNC_INFO << "calendar get ended with" << status;
} }
} }
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
} }
void MainScreen::on_exportToCVSBtn_clicked() void MainScreen::on_exportToCVSBtn_clicked()
{ {
qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName();
if (loginHandel->isLoggedInFlag()) if (loginHandel->isLoggedInFlag())
{ {
this->calendar->exportCalendarCSV(); this->calendar->exportCalendarCSV();
} }
} }
//EVENTS ON MENU BAR //EVENTS ON MENU BAR
void MainScreen::on_actionCredits_triggered() void MainScreen::on_actionCredits_triggered()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
QMessageBox::about(this, "About", QMessageBox::about(this, "About",
"<a href='http://liranbg.github.io/JceManager/'>Jce Manager</a> v1.0.0<br><br>" "<a href='http://liranbg.github.io/JceManager/'>Jce Manager</a> v1.0.0<br><br>"
+tr("License:")+ +tr("License:")+
"<br>GNU LESSER GENERAL PUBLIC LICENSE V2.1<br>" "<br>GNU LESSER GENERAL PUBLIC LICENSE V2.1<br>"
+"<br>"+ +"<br>"+
"<a href='https://github.com/liranbg/JceManager'>JceManager Repository</a>"+ "<a href='https://github.com/liranbg/JceManager'>JceManager Repository</a>"+
"<br><br>" "<br><br>"
+tr("Powered By: ")+ +tr("Powered By: ")+
"<a href='https://github.com/liranbg/jceConnection'> Jce Connection</a><br><br>" "<a href='https://github.com/liranbg/jceConnection'> Jce Connection</a><br><br>"
+tr("Developed By")+ +tr("Developed By")+
":<ul>"+ ":<ul>"+
"<li><a href='mailto:liranbg@gmail.com'>"+tr("Liran")+"</a></li>"+ "<li><a href='mailto:liranbg@gmail.com'>"+tr("Liran")+"</a></li>"+
"<li><a href='mailto:sagidayan@gmail.com'>"+tr("Sagi")+"</a></li></ul>" "<li><a href='mailto:sagidayan@gmail.com'>"+tr("Sagi")+"</a></li></ul>"
); );
} }
void MainScreen::on_actionExit_triggered() void MainScreen::on_actionExit_triggered()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
exit(0); exit(0);
} }
void MainScreen::on_actionHow_To_triggered() void MainScreen::on_actionHow_To_triggered()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
QMessageBox::information(this,"How To", QMessageBox::information(this,"How To",
"<b>" "<b>"
+tr("Help Guide")+ +tr("Help Guide")+
"</b><ul>" "</b><ul>"
+tr("<br><li>Login: <ul><li>Type your username and password and click Login.</li><li>Once you are connected, you will see a green ball in the right buttom panel.</li></ul></li>") +tr("<br><li>Login: <ul><li>Type your username and password and click Login.</li><li>Once you are connected, you will see a green ball in the right buttom panel.</li></ul></li>")
+tr("<br><li>Getting GPA sheet<ul><li>Click on GPA Tab</li><li> Select your dates and click on Add</li></ul></li>") +tr("<br><li>Getting GPA sheet<ul><li>Click on GPA Tab</li><li> Select your dates and click on Add</li></ul></li>")
+tr("<br><li>Average Changing<ul><li>Change one of your grade and see the average in the buttom panel changing.</li></ul></li>") +tr("<br><li>Average Changing<ul><li>Change one of your grade and see the average in the buttom panel changing.</li></ul></li>")
+tr("<br><li>Getting Calendar<ul><li>Click on Calendar Tab</li><li> Select your dates and click on Get Calendar</li></ul></li>") +tr("<br><li>Getting Calendar<ul><li>Click on Calendar Tab</li><li> Select your dates and click on Get Calendar</li></ul></li>")
+tr("<br><li>For exporting your calendar to a .CSV file:<ul><li>Do previous step and continue to next step</li><li> Click on Export to CSV</li><li>Select your dates and click OK</li><li>Once you're Done, go on your calendar and import your csv file</li></li>")+ +tr("<br><li>For exporting your calendar to a .CSV file:<ul><li>Do previous step and continue to next step</li><li> Click on Export to CSV</li><li>Select your dates and click OK</li><li>Once you're Done, go on your calendar and import your csv file</li></li>")+
"<br><br>" "<br><br>"
+tr("<b>For more information, please visit us at: <a href='http://liranbg.github.io/JceManager/'>Jce Manager site</a></b>")); +tr("<b>For more information, please visit us at: <a href='http://liranbg.github.io/JceManager/'>Jce Manager site</a></b>"));
} }
void MainScreen::on_actionHebrew_triggered() void MainScreen::on_actionHebrew_triggered()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
if (ui->actionEnglish->isChecked() || ui->actionOS_Default->isChecked()) if (ui->actionEnglish->isChecked() || ui->actionOS_Default->isChecked())
{ {
ui->actionEnglish->setChecked(false); ui->actionEnglish->setChecked(false);
ui->actionOS_Default->setChecked(false); ui->actionOS_Default->setChecked(false);
qDebug() << Q_FUNC_INFO << "Changed Language to hebrew"; qDebug() << Q_FUNC_INFO << "Changed Language to hebrew";
data->setLocal("he"); data->setLocal("he");
QMessageBox::information(this,tr("Settings"),tr("Your settings will take effect next time you start the program"),QMessageBox::Ok); QMessageBox::information(this,tr("Settings"),tr("Your settings will take effect next time you start the program"),QMessageBox::Ok);
} }
else else
ui->actionHebrew->setChecked(true); ui->actionHebrew->setChecked(true);
} }
void MainScreen::on_actionEnglish_triggered() void MainScreen::on_actionEnglish_triggered()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
if (ui->actionHebrew->isChecked() || ui->actionOS_Default->isChecked()) if (ui->actionHebrew->isChecked() || ui->actionOS_Default->isChecked())
{ {
ui->actionHebrew->setChecked(false); ui->actionHebrew->setChecked(false);
ui->actionOS_Default->setChecked(false); ui->actionOS_Default->setChecked(false);
qDebug() << Q_FUNC_INFO << "Changed Language to English"; qDebug() << Q_FUNC_INFO << "Changed Language to English";
data->setLocal("en"); data->setLocal("en");
QMessageBox::information(this,"Settings",tr("Your settings will take effect next time you start the program"),QMessageBox::Ok); QMessageBox::information(this,"Settings",tr("Your settings will take effect next time you start the program"),QMessageBox::Ok);
} }
else else
ui->actionEnglish->setChecked(true); ui->actionEnglish->setChecked(true);
} }
void MainScreen::on_actionOS_Default_triggered() void MainScreen::on_actionOS_Default_triggered()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
if (ui->actionHebrew->isChecked() || ui->actionEnglish->isChecked()) if (ui->actionHebrew->isChecked() || ui->actionEnglish->isChecked())
{ {
ui->actionHebrew->setChecked(false); ui->actionHebrew->setChecked(false);
ui->actionEnglish->setChecked(false); ui->actionEnglish->setChecked(false);
qDebug() << Q_FUNC_INFO << "Changed Language to OS Default"; qDebug() << Q_FUNC_INFO << "Changed Language to OS Default";
data->setLocal("default"); data->setLocal("default");
QMessageBox::information(this,tr("Settings"),tr("Your settings will take effect next time you start the program"),QMessageBox::Ok); QMessageBox::information(this,tr("Settings"),tr("Your settings will take effect next time you start the program"),QMessageBox::Ok);
} }
else else
ui->actionOS_Default->setChecked(true); ui->actionOS_Default->setChecked(true);
} }
void MainScreen::checkLocale() void MainScreen::checkLocale()
{ {
if(data->getLocal() == "en") if(data->getLocal() == "en")
{ {
ui->actionHebrew->setChecked(false); ui->actionHebrew->setChecked(false);
ui->actionOS_Default->setChecked(false); ui->actionOS_Default->setChecked(false);
ui->actionEnglish->setChecked(true); ui->actionEnglish->setChecked(true);
}else if(data->getLocal() == "he"){ }else if(data->getLocal() == "he"){
ui->actionHebrew->setChecked(true); ui->actionHebrew->setChecked(true);
ui->actionOS_Default->setChecked(false); ui->actionOS_Default->setChecked(false);
ui->actionEnglish->setChecked(false); ui->actionEnglish->setChecked(false);
}else{ }else{
ui->actionHebrew->setChecked(false); ui->actionHebrew->setChecked(false);
ui->actionOS_Default->setChecked(true); ui->actionOS_Default->setChecked(true);
ui->actionEnglish->setChecked(false); ui->actionEnglish->setChecked(false);
} }
} }
void MainScreen::on_labelMadeBy_linkActivated(const QString &link) void MainScreen::on_labelMadeBy_linkActivated(const QString &link)
{ {
qDebug() << Q_FUNC_INFO << "link: " << link; qDebug() << Q_FUNC_INFO << "link: " << link;
} }
@ -421,10 +422,10 @@ void MainScreen::on_labelMadeBy_linkActivated(const QString &link)
*/ */
void MainScreen::on_progressBar_valueChanged(int value) void MainScreen::on_progressBar_valueChanged(int value)
{ {
if(value == 0 || value == 100) if(value == 0 || value == 100)
ui->progressBar->setVisible(false); ui->progressBar->setVisible(false);
else else
ui->progressBar->setVisible(true); ui->progressBar->setVisible(true);
} }

View file

@ -503,7 +503,7 @@ font-size: 15px;
<number>0</number> <number>0</number>
</property> </property>
<property name="spacing"> <property name="spacing">
<number>-1</number> <number>6</number>
</property> </property>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QPushButton" name="clearTableButton"> <widget class="QPushButton" name="clearTableButton">
@ -809,6 +809,9 @@ font-size: 15px;
<property name="sortingEnabled"> <property name="sortingEnabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -950,7 +953,7 @@ background: qlineargradient(x1: 0, y1: 0.5, x2: 1, y2: 0.5, stop: 0 green, stop:
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1133</width> <width>1133</width>
<height>22</height> <height>21</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuA_about"> <widget class="QMenu" name="menuA_about">

View file

@ -4,81 +4,113 @@
* TODO: make graph understandable * TODO: make graph understandable
* BUG: graph bug when theres small range of years * BUG: graph bug when theres small range of years
*/ */
gradegraph::gradegraph(QWidget *parent) : gradegraph::gradegraph(QWidget *parent) : QDialog(parent), ui(new Ui::gradegraph)
QDialog(parent),
ui(new Ui::gradegraph)
{ {
ui->setupUi(this); ui->setupUi(this);
this->gp = NULL; this->setModal(true); //makes it on top of application
this->gp = NULL;
} }
void gradegraph::showGraph(GradePage *gpPTR) void gradegraph::showGraph(GradePage *gpPTR)
{ {
this->gp = gpPTR; qDebug() << Q_FUNC_INFO;
setVisualization(); this->gp = gpPTR;
setGraphsData();
this->show();
this->setModal(true); //makes it on top of application
clearGraph();
setVisualization();
setGraphsData();
ui->graphwidget->replot();
this->show();
} }
gradegraph::~gradegraph() gradegraph::~gradegraph()
{ {
delete ui; delete ui;
} }
void gradegraph::setGraphsData() void gradegraph::setGraphsData()
{ {
int minYearInList = gp->getMinYearInList(); int minYearInList = gp->getMinYearInList();
int maxYearInList = gp->getMaxYearInList()+1; int maxYearInList = gp->getMaxYearInList()+1;
int xRangeForYear = (maxYearInList - minYearInList+2)*3; int xRangeForYear = (maxYearInList - minYearInList+2)*3;
QVector<double> SemesterialAvg(xRangeForYear),yearlyAvg(xRangeForYear),sem(xRangeForYear); QVector<double> SemesterialAvg(xRangeForYear),yearlyAvg(xRangeForYear),indicatorX(xRangeForYear);
for (int yearCount=0,i=1; i<xRangeForYear; ++i) //filling data for (int yearCount=0,i=1; i<xRangeForYear; ++i) //filling data
{ {
double lastAvg = 0;
sem[i] = i;
if (i%4==1) //years
{
lastAvg = gp->getAvg(minYearInList+yearCount);
yearlyAvg[i] = lastAvg;
// add the text label at the top: indicatorX[i] = i;
QCPItemText *textLabel = new QCPItemText(ui->graphwidget); if (i%4==1) //years
ui->graphwidget->addItem(textLabel); {
textLabel->position->setCoords(i, lastAvg+1.5); // place position at center/top of axis rect QCPItemText *textLabel = new QCPItemText(ui->graphwidget);
textLabel->setText(QString::number(lastAvg,'g',4)); ui->graphwidget->addItem(textLabel);
textLabel->setFont(QFont(font().family(), 8)); // make font a bit larger
textLabel->setPen(QPen(Qt::black)); // show black border around text double lastAvg = gp->getAvg(minYearInList+yearCount);
yearCount++;
if (lastAvg > 0)
{
// add the text label at the top:
if (lastAvg <= MIN_GRADE) //will be below the graph
{
textLabel->position->setCoords(i, MIN_GRADE+5); // place position at center/top of axis rect
textLabel->setText(QString::number(lastAvg,'g',4) + "<= Min Grade (" + QString::number(MIN_GRADE) + ")");
}
else
{
textLabel->position->setCoords(i, lastAvg+1.5); // place position at center/top of axis rect
textLabel->setText(QString::number(lastAvg,'g',4));
}
}
textLabel->setFont(QFont(font().family(), 8)); // make font a bit larger
textLabel->setPen(QPen(Qt::black)); // show black border around text
yearlyAvg[i] = lastAvg;
yearCount++;
} }
else else
{ {
if (i+4 < xRangeForYear) //semesters if (i+4 < xRangeForYear) //semesters
{ {
double avg = gp->getAvg(minYearInList+yearCount,(i-1)%4); QCPItemText *textLabel = new QCPItemText(ui->graphwidget);
SemesterialAvg[i+4] = avg; ui->graphwidget->addItem(textLabel);
// add the text label at the top:
QCPItemText *textLabel = new QCPItemText(ui->graphwidget); //qDebug() << "year: " << minYearInList+yearCount << "sem " << (i-1)%4;
ui->graphwidget->addItem(textLabel); double avg = gp->getAvg(minYearInList+yearCount,(i-1)%4);
textLabel->position->setCoords(i+4, avg+0.5); // place position at center/top of axis rect //qDebug() << "avg: " << avg;
textLabel->setText(QString::number(avg,'g',4));
textLabel->setFont(QFont(font().family(), 8)); // make font a bit larger
textLabel->setPen(QPen(Qt::black)); // show black border around text
if (avg > 0)
{
// add the text label at the top:
if (avg <= MIN_GRADE) //will be below the graph
{
textLabel->position->setCoords(i+4, MIN_GRADE+1.5); // place position at center/top of axis rect
textLabel->setText(QString::number(avg,'g',4) + "<= Min Grade (" + QString::number(MIN_GRADE) + ")");
}
else
{
textLabel->position->setCoords(i+4, avg+1.5); // place position at center/top of axis rect
textLabel->setText(QString::number(avg,'g',4));
}
textLabel->setFont(QFont(font().family(), 8)); // make font a bit larger
textLabel->setPen(QPen(Qt::black)); // show black border around text
SemesterialAvg[i+4] = avg;
}
} }
yearlyAvg[i] = 0; yearlyAvg[i] = 0;
} }
} }
//yearly //yearly
ui->graphwidget->graph(0)->setData(sem,yearlyAvg); ui->graphwidget->graph(0)->setData(indicatorX,yearlyAvg);
//yearly //yearly
ui->graphwidget->graph(1)->setData(sem,SemesterialAvg); ui->graphwidget->graph(1)->setData(indicatorX,SemesterialAvg);
} }
/** /**
@ -86,75 +118,86 @@ void gradegraph::setGraphsData()
*/ */
void gradegraph::setVisualization() void gradegraph::setVisualization()
{ {
ui->graphwidget->axisRect()->setupFullAxesBox(true); //make the graph looks like a box ui->graphwidget->setBackground(QBrush(Qt::white));
ui->graphwidget->axisRect()->setupFullAxesBox(true); //make the graph looks like a box
ui->graphwidget->addGraph(); //yearly and semesterial graphs ui->graphwidget->addGraph(); //yearly and semesterial graphs
ui->graphwidget->addGraph(); ui->graphwidget->addGraph();
ui->graphwidget->graph(0)->setName(tr("Yearly Average")); ui->graphwidget->graph(0)->setName(tr("Yearly Average"));
ui->graphwidget->graph(0)->setLineStyle(QCPGraph::lsLine); ui->graphwidget->graph(0)->setPen(QPen(Qt::GlobalColor::blue));
ui->graphwidget->graph(0)->setPen(QPen(Qt::GlobalColor::blue)); ui->graphwidget->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, Qt::blue, Qt::blue, 7));
ui->graphwidget->graph(0)->setLineStyle(QCPGraph::lsImpulse );
ui->graphwidget->graph(1)->setName(tr("Semesterial Average")); ui->graphwidget->graph(1)->setName(tr("Semesterial Average"));
ui->graphwidget->graph(1)->setLineStyle(QCPGraph::lsLine); ui->graphwidget->graph(1)->setLineStyle(QCPGraph::lsStepLeft);
ui->graphwidget->graph(1)->setPen(QPen( QColor(Qt::GlobalColor::red))); ui->graphwidget->graph(1)->setPen(QPen( QColor(Qt::GlobalColor::red)));
ui->graphwidget->graph(1)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, Qt::red, Qt::red, 7));
int minYearInList = gp->getMinYearInList();
int maxYearInList = gp->getMaxYearInList()+1;
int xRangeForYear = (maxYearInList - minYearInList+2)*3;
QVector<QString> xStrings(0); int minYearInList = gp->getMinYearInList();
for (int year=minYearInList,i = 0; i < xRangeForYear-1; ++i) int maxYearInList = gp->getMaxYearInList()+1;
int xRangeForYear = (maxYearInList - minYearInList+2)*3;
QVector<QString> xStrings(0);
for (int year=minYearInList,i = 0; i < xRangeForYear-1; ++i)
{ {
//set year x axe label to be yyyy A B C yyyy+1 A B C yyyy+2.... //set year x axe label to be yyyy A B C yyyy+1 A B C yyyy+2....
int semesterChar = i%4; int semesterChar = i%4;
QString tempString; QString tempString;
switch (semesterChar) switch (semesterChar)
{ {
case 1: case 1:
tempString = tr("A"); tempString = tr("A");
xStrings << tempString; xStrings << tempString;
break; break;
case 2: case 2:
tempString = tr("B"); tempString = tr("B");
xStrings << tempString; xStrings << tempString;
break; break;
case 3: case 3:
tempString = tr("C"); tempString = tr("C");
xStrings << tempString; xStrings << tempString;
break; break;
case 0: case 0:
tempString = QString::number(year); tempString = QString::number(year);
xStrings << tempString; xStrings << tempString;
year++; year++;
break; break;
} }
} }
ui->graphwidget->yAxis->setLabel(tr("AVG Grade")); ui->graphwidget->yAxis->setLabel(tr("AVG Grade"));
ui->graphwidget->yAxis->setTickLabelFont(QFont(QFont().family(), 8)); ui->graphwidget->yAxis->setTickLabelFont(QFont(QFont().family(), 8));
ui->graphwidget->yAxis->setRange(50,100); ui->graphwidget->yAxis->setRange(MIN_GRADE,MAX_GRADE);
ui->graphwidget->yAxis->setTickStep(2); ui->graphwidget->yAxis->setTickStep(2);
ui->graphwidget->yAxis->setAutoSubTicks(false); ui->graphwidget->yAxis->setAutoSubTicks(false);
ui->graphwidget->yAxis->setAutoTickStep(false); ui->graphwidget->yAxis->setAutoTickStep(false);
ui->graphwidget->yAxis->setSubTickCount(5); ui->graphwidget->yAxis->setSubTickCount(5);
ui->graphwidget->xAxis->setLabel(tr("Years")); ui->graphwidget->xAxis->setLabel(tr("Years"));
ui->graphwidget->xAxis->setAutoTickLabels(false); ui->graphwidget->xAxis->setAutoTickLabels(false);
ui->graphwidget->xAxis->setTickLabelFont(QFont(QFont().family(), 7)); ui->graphwidget->xAxis->setTickLabelFont(QFont(QFont().family(), 7));
ui->graphwidget->xAxis->setAutoTickStep(false); ui->graphwidget->xAxis->setAutoTickStep(false);
ui->graphwidget->xAxis->setTickStep(1); ui->graphwidget->xAxis->setTickStep(1);
ui->graphwidget->xAxis->setAutoSubTicks(false); ui->graphwidget->xAxis->setAutoSubTicks(false);
ui->graphwidget->xAxis->setSubTickCount(1); ui->graphwidget->xAxis->setSubTickCount(0);
ui->graphwidget->xAxis->setTickVectorLabels(xStrings); ui->graphwidget->xAxis->setTickVectorLabels(xStrings);
ui->graphwidget->xAxis->setRange(1,xRangeForYear); ui->graphwidget->xAxis->setRange(1,xRangeForYear);
ui->graphwidget->legend->setVisible(true); //show graph name on top right ui->graphwidget->legend->setVisible(true); //show graph name on top right
}
void gradegraph::clearGraph()
{
int itemDeleted,graphs,plots;
itemDeleted = ui->graphwidget->clearItems();
graphs = ui->graphwidget->clearGraphs();
plots = ui->graphwidget->clearPlottables();
qDebug() << Q_FUNC_INFO << "items:" << itemDeleted << "graphs" << graphs << "plots:" << plots;
} }
void gradegraph::on_pushButton_clicked() void gradegraph::on_pushButton_clicked()
{ {
qDebug() << Q_FUNC_INFO << " Closed Graph Dialog"; qDebug() << Q_FUNC_INFO << " Closed Graph Dialog";
this->done(0); this->done(0);
} }

View file

@ -9,6 +9,9 @@ namespace Ui {
class gradegraph; class gradegraph;
} }
#define MIN_GRADE 50
#define MAX_GRADE 100
class gradegraph : public QDialog class gradegraph : public QDialog
{ {
Q_OBJECT Q_OBJECT
@ -27,6 +30,8 @@ private:
void setVisualization(); void setVisualization();
void setGraphsData(); void setGraphsData();
void clearGraph();
Ui::gradegraph *ui; Ui::gradegraph *ui;
}; };

View file

@ -11,7 +11,11 @@
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Dialog</string> <string>GPA Graph View</string>
</property>
<property name="windowIcon">
<iconset resource="../../../../resources/connectionstatus.qrc">
<normaloff>:/icons/icon.ico</normaloff>:/icons/icon.ico</iconset>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
<item> <item>
@ -29,7 +33,7 @@
</size> </size>
</property> </property>
<property name="text"> <property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:18pt; font-weight:600;&quot;&gt;Graph View&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:18pt; font-weight:600;&quot;&gt;GPA Graph View&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -82,6 +86,8 @@
<container>1</container> <container>1</container>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<resources/> <resources>
<include location="../../../../resources/connectionstatus.qrc"/>
</resources>
<connections/> <connections/>
</ui> </ui>