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)
{
this->gp = NULL;
this->us = usrPtr;
this->courseTBL = ptr;
this->gp = NULL;
this->us = usrPtr;
this->courseTBL = ptr;
/*
/*
* Initilizing Table
*/
courseTBL->setRowCount(0);
courseTBL->setColumnCount(COURSE_FIELDS);
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");
courseTBL->setHorizontalHeaderLabels(mz);
courseTBL->verticalHeader()->setVisible(false);
courseTBL->setSelectionMode(QAbstractItemView::SingleSelection);
courseTBL->setShowGrid(true);
courseTBL->setStyleSheet("QTableView {selection-background-color: red;}");
courseTBL->setRowCount(0);
courseTBL->setColumnCount(COURSE_FIELDS);
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");
courseTBL->setHorizontalHeaderLabels(mz);
courseTBL->verticalHeader()->setVisible(false);
courseTBL->setSelectionMode(QAbstractItemView::SingleSelection);
courseTBL->setShowGrid(true);
courseTBL->setStyleSheet("QTableView {selection-background-color: red;}");
graph = new gradegraph(NULL);
graph = new gradegraph(ptr);
}
coursesTableManager::~coursesTableManager()
{
courseTBL = NULL;
delete gp;
gp = NULL;
courseTBL = NULL;
delete gp;
gp = NULL;
}
/**
* @brief coursesTableManager::insertJceCoursesIntoTable phrasing the course list to rows in table
*/
void coursesTableManager::insertJceCoursesIntoTable()
{
for (gradeCourse *c: gp->getCourses())
for (gradeCourse *c: gp->getCourses())
{
if (us->getInfluenceCourseOnly())
if (us->getInfluenceCourseOnly())
{
if (isCourseInfluence(c))
addRow(c);
}
else
if (isCourseInfluence(c))
addRow(c);
}
else
addRow(c);
}
}
/**
@ -53,9 +53,9 @@ void coursesTableManager::insertJceCoursesIntoTable()
*/
void coursesTableManager::setCoursesList(QString &html)
{
if (gp != NULL)
gp->~GradePage();
gp = new GradePage(html);
if (gp != NULL)
gp->~GradePage();
gp = new GradePage(html);
}
/**
* @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 isNumFlag = true;
if (courseTBL->item(row,gradeCourse::CourseScheme::SERIAL) == NULL)
return true;
bool isNumFlag = true;
if (courseTBL->item(row,gradeCourse::CourseScheme::SERIAL) == NULL)
return true;
int serialCourse = courseTBL->item(row,gradeCourse::CourseScheme::SERIAL)->text().toInt();
for (gradeCourse *c: gp->getCourses())
int serialCourse = courseTBL->item(row,gradeCourse::CourseScheme::SERIAL)->text().toInt();
for (gradeCourse *c: gp->getCourses())
{
if (c->getSerialNum() == serialCourse)
if (c->getSerialNum() == serialCourse)
{
switch (col)
switch (col)
{
case (gradeCourse::CourseScheme::COURSE_NUMBER_IN_LIST):
c->setCourseNumInList(change.toInt());
break;
c->setCourseNumInList(change.toInt());
break;
case (gradeCourse::CourseScheme::YEAR):
c->setYear(change.toInt());
break;
c->setYear(change.toInt());
break;
case (gradeCourse::CourseScheme::SEMESTER):
c->setSemester(change.toInt());
break;
c->setSemester(change.toInt());
break;
case (gradeCourse::CourseScheme::NAME):
c->setName(change);
break;
c->setName(change);
break;
case (gradeCourse::CourseScheme::TYPE):
c->setType(change);
break;
c->setType(change);
break;
case (gradeCourse::CourseScheme::POINTS):
{
{
change.toDouble(&isNumFlag);
if (!isNumFlag)
{
{
courseTBL->item(row,col)->setText(QString::number(c->getPoints()));
}
}
else
c->setPoints(change.toDouble());
c->setPoints(change.toDouble());
break;
}
}
case (gradeCourse::CourseScheme::HOURS):
{
{
change.toDouble(&isNumFlag);
if (!isNumFlag)
{
{
courseTBL->item(row,col)->setText(QString::number(c->getHours()));
}
}
else
c->setHours(change.toDouble());
c->setHours(change.toDouble());
break;
}
}
case (gradeCourse::CourseScheme::GRADE):
{
{
change.toDouble(&isNumFlag);
if (!isNumFlag)
{
{
courseTBL->item(row,col)->setText(QString::number(c->getGrade()));
}
}
else
{
{
if ((change.toDouble() >= 0) && (change.toDouble() <= 100))
c->setGrade(change.toDouble());
c->setGrade(change.toDouble());
else
courseTBL->item(row,col)->setText(QString::number(c->getGrade()));
}
courseTBL->item(row,col)->setText(QString::number(c->getGrade()));
}
break;
}
}
case (gradeCourse::CourseScheme::ADDITION):
c->setAdditions(change);
break;
c->setAdditions(change);
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)
{
int i=1,j=1;
int i=1,j=1;
j = 0;
QTableWidgetItem *number,*year,*semester,*serial,*name,*type,*points,*hours,*grade,*addition;
const gradeCourse * c;
if (courseToAdd != NULL)
j = 0;
QTableWidgetItem *number,*year,*semester,*serial,*name,*type,*points,*hours,*grade,*addition;
const gradeCourse * c;
if (courseToAdd != NULL)
{
c = courseToAdd;
if (!isCourseAlreadyInserted(c->getSerialNum()))
c = courseToAdd;
if (!isCourseAlreadyInserted(c->getSerialNum()))
{
courseTBL->setRowCount(courseTBL->rowCount() + 1);
i = courseTBL->rowCount()-1;
courseTBL->setRowCount(courseTBL->rowCount() + 1);
i = courseTBL->rowCount()-1;
number = new QTableWidgetItem();
number->setData(Qt::EditRole, c->getCourseNumInList());
number->setFlags(number->flags() & ~Qt::ItemIsEditable);
number = new QTableWidgetItem();
number->setData(Qt::EditRole, c->getCourseNumInList());
number->setFlags(number->flags() & ~Qt::ItemIsEditable);
year = new QTableWidgetItem();
year->setData(Qt::EditRole,c->getYear());
year->setFlags(year->flags() & ~Qt::ItemIsEditable);
year = new QTableWidgetItem();
year->setData(Qt::EditRole,c->getYear());
year->setFlags(year->flags() & ~Qt::ItemIsEditable);
semester = new QTableWidgetItem();
semester->setData(Qt::EditRole,c->getSemester());
semester->setFlags(semester->flags() & ~Qt::ItemIsEditable);
semester = new QTableWidgetItem();
semester->setData(Qt::EditRole,c->getSemester());
semester->setFlags(semester->flags() & ~Qt::ItemIsEditable);
serial = new QTableWidgetItem();
serial->setData(Qt::EditRole,c->getSerialNum());
serial->setFlags(serial->flags() & ~Qt::ItemIsEditable);
serial = new QTableWidgetItem();
serial->setData(Qt::EditRole,c->getSerialNum());
serial->setFlags(serial->flags() & ~Qt::ItemIsEditable);
name = new QTableWidgetItem();
name->setData(Qt::EditRole,c->getName());
name->setFlags(name->flags() & ~Qt::ItemIsEditable);
name = new QTableWidgetItem();
name->setData(Qt::EditRole,c->getName());
name->setFlags(name->flags() & ~Qt::ItemIsEditable);
type = new QTableWidgetItem();
type->setData(Qt::EditRole, c->getType());
type->setFlags(type->flags() & ~Qt::ItemIsEditable);
type = new QTableWidgetItem();
type->setData(Qt::EditRole, c->getType());
type->setFlags(type->flags() & ~Qt::ItemIsEditable);
points = new QTableWidgetItem();
points->setData(Qt::EditRole, c->getPoints());
points->setFlags(points->flags() & ~Qt::ItemIsEditable);
points = new QTableWidgetItem();
points->setData(Qt::EditRole, c->getPoints());
points->setFlags(points->flags() & ~Qt::ItemIsEditable);
hours = new QTableWidgetItem();
hours->setData(Qt::EditRole, c->getHours());
hours->setFlags(hours->flags() & ~Qt::ItemIsEditable);
hours = new QTableWidgetItem();
hours->setData(Qt::EditRole, c->getHours());
hours->setFlags(hours->flags() & ~Qt::ItemIsEditable);
grade = new QTableWidgetItem();
grade->setData(Qt::EditRole,c->getGrade());
grade = new QTableWidgetItem();
// 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->setData(Qt::EditRole,c->getAddidtions());
addition = new QTableWidgetItem();
addition->setData(Qt::EditRole,c->getAddidtions());
courseTBL->setItem(i,j++,number);
courseTBL->setItem(i,j++,year);
courseTBL->setItem(i,j++,semester);
courseTBL->setItem(i,j++,serial);
courseTBL->setItem(i,j++,name);
courseTBL->setItem(i,j++,type);
courseTBL->setItem(i,j++,points);
courseTBL->setItem(i,j++,hours);
courseTBL->setItem(i,j,grade);
if(c->getGrade() < 55 && c->getGrade() != 0)
courseTBL->setItem(i,j++,number);
courseTBL->setItem(i,j++,year);
courseTBL->setItem(i,j++,semester);
courseTBL->setItem(i,j++,serial);
courseTBL->setItem(i,j++,name);
courseTBL->setItem(i,j++,type);
courseTBL->setItem(i,j++,points);
courseTBL->setItem(i,j++,hours);
courseTBL->setItem(i,j,grade);
//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)->setTextColor(Qt::white);
courseTBL->item(i, j)->setBackground(Qt::darkRed);
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)->setTextColor(Qt::white);
courseTBL->item(i, j)->setBackground(Qt::darkYellow);
courseTBL->item(i,j)->setTextColor(Qt::white);
}
// else if(70 < c->getGrade() && c->getGrade() <= 80 )
// courseTBL->item(i, j)->setBackground(Qt::darkGreen); //They Look Bad!!
// else if(c->getGrade() > 80)
// courseTBL->item(i, j)->setBackground(Qt::green);
// else if(70 < c->getGrade() && c->getGrade() <= 80 )
// courseTBL->item(i, j)->setBackground(Qt::darkGreen); //They Look Bad!!
// else if(c->getGrade() > 80)
// 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->resizeRowsToContents();
courseTBL->resizeColumnsToContents();
courseTBL->resizeRowsToContents();
}
double coursesTableManager::getAvg()
{
if (this->gp != NULL)
return gp->getAvg();
return 0;
if (this->gp != NULL)
return gp->getAvg();
return 0;
}
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)
{
if (ignoreCourseStatus)
if (ignoreCourseStatus)
{
int i = 0;
while (i < courseTBL->rowCount())
int i = 0;
while (i < courseTBL->rowCount())
{
if (courseTBL->item(i,gradeCourse::CourseScheme::POINTS)->text().compare("0") == 0)
courseTBL->removeRow(i--);
i++;
if (courseTBL->item(i,gradeCourse::CourseScheme::POINTS)->text().compare("0") == 0)
courseTBL->removeRow(i--);
i++;
}
}
else
else
{
if (this->gp != NULL)
for (gradeCourse *c: gp->getCourses())
{
if (!(isCourseAlreadyInserted(c->getSerialNum())))
if (c->getPoints() == 0)
addRow(c);
}
if (this->gp != NULL)
for (gradeCourse *c: gp->getCourses())
{
if (!(isCourseAlreadyInserted(c->getSerialNum())))
if (c->getPoints() == 0)
addRow(c);
}
}
}
void coursesTableManager::clearTable()
{
if (courseTBL->rowCount() == 0)
return;
if (courseTBL->rowCount() == 0)
return;
int i = 0; //starting point
while (courseTBL->rowCount() > i)
int i = 0; //starting point
while (courseTBL->rowCount() > i)
{
gp->removeCourse(courseTBL->item(i,gradeCourse::CourseScheme::SERIAL)->text());
courseTBL->removeRow(i);
gp->removeCourse(courseTBL->item(i,gradeCourse::CourseScheme::SERIAL)->text());
courseTBL->removeRow(i);
}
gp = NULL;
courseTBL->repaint();
gp = NULL;
courseTBL->repaint();
}
gradeCourse *coursesTableManager::getCourseByRow(int row)
{
QString courseSerial = courseTBL->item(row,gradeCourse::CourseScheme::SERIAL)->text();
for (gradeCourse *c: gp->getCourses())
QString courseSerial = courseTBL->item(row,gradeCourse::CourseScheme::SERIAL)->text();
for (gradeCourse *c: gp->getCourses())
{
if (c->getSerialNum() == courseSerial.toDouble())
return c;
if (c->getSerialNum() == courseSerial.toDouble())
return c;
}
return NULL;
return NULL;
}
bool coursesTableManager::isCourseAlreadyInserted(double courseID)
{
int i;
for (i = courseTBL->rowCount(); i >= 0; --i)
int 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();
if (QString::number(courseID) == courseSerial)
return true;
QString courseSerial = courseTBL->item(i,gradeCourse::CourseScheme::SERIAL)->text();
if (QString::number(courseID) == courseSerial)
return true;
}
}
return false;
return false;
}
bool coursesTableManager::isCourseInfluence(const gradeCourse *courseToCheck)
{
if (courseToCheck->getPoints() > 0)
return true;
return false;
if (courseToCheck->getPoints() > 0)
return true;
return false;
}

View file

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

View file

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

View file

@ -4,81 +4,113 @@
* TODO: make graph understandable
* BUG: graph bug when theres small range of years
*/
gradegraph::gradegraph(QWidget *parent) :
QDialog(parent),
ui(new Ui::gradegraph)
gradegraph::gradegraph(QWidget *parent) : QDialog(parent), ui(new Ui::gradegraph)
{
ui->setupUi(this);
this->gp = NULL;
ui->setupUi(this);
this->setModal(true); //makes it on top of application
this->gp = NULL;
}
void gradegraph::showGraph(GradePage *gpPTR)
{
this->gp = gpPTR;
setVisualization();
setGraphsData();
this->show();
this->setModal(true); //makes it on top of application
qDebug() << Q_FUNC_INFO;
this->gp = gpPTR;
clearGraph();
setVisualization();
setGraphsData();
ui->graphwidget->replot();
this->show();
}
gradegraph::~gradegraph()
{
delete ui;
delete ui;
}
void gradegraph::setGraphsData()
{
int minYearInList = gp->getMinYearInList();
int maxYearInList = gp->getMaxYearInList()+1;
int xRangeForYear = (maxYearInList - minYearInList+2)*3;
QVector<double> SemesterialAvg(xRangeForYear),yearlyAvg(xRangeForYear),sem(xRangeForYear);
int minYearInList = gp->getMinYearInList();
int maxYearInList = gp->getMaxYearInList()+1;
int xRangeForYear = (maxYearInList - minYearInList+2)*3;
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:
QCPItemText *textLabel = new QCPItemText(ui->graphwidget);
ui->graphwidget->addItem(textLabel);
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
yearCount++;
indicatorX[i] = i;
if (i%4==1) //years
{
QCPItemText *textLabel = new QCPItemText(ui->graphwidget);
ui->graphwidget->addItem(textLabel);
double lastAvg = gp->getAvg(minYearInList+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);
SemesterialAvg[i+4] = avg;
// add the text label at the top:
QCPItemText *textLabel = new QCPItemText(ui->graphwidget);
ui->graphwidget->addItem(textLabel);
QCPItemText *textLabel = new QCPItemText(ui->graphwidget);
ui->graphwidget->addItem(textLabel);
textLabel->position->setCoords(i+4, avg+0.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
//qDebug() << "year: " << minYearInList+yearCount << "sem " << (i-1)%4;
double avg = gp->getAvg(minYearInList+yearCount,(i-1)%4);
//qDebug() << "avg: " << avg;
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
ui->graphwidget->graph(0)->setData(sem,yearlyAvg);
//yearly
ui->graphwidget->graph(1)->setData(sem,SemesterialAvg);
//yearly
ui->graphwidget->graph(0)->setData(indicatorX,yearlyAvg);
//yearly
ui->graphwidget->graph(1)->setData(indicatorX,SemesterialAvg);
}
/**
@ -86,75 +118,86 @@ void gradegraph::setGraphsData()
*/
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();
ui->graphwidget->addGraph(); //yearly and semesterial graphs
ui->graphwidget->addGraph();
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)->setName(tr("Yearly Average"));
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)->setLineStyle(QCPGraph::lsLine);
ui->graphwidget->graph(1)->setPen(QPen( QColor(Qt::GlobalColor::red)));
ui->graphwidget->graph(1)->setName(tr("Semesterial Average"));
ui->graphwidget->graph(1)->setLineStyle(QCPGraph::lsStepLeft);
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);
for (int year=minYearInList,i = 0; i < xRangeForYear-1; ++i)
int minYearInList = gp->getMinYearInList();
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....
int semesterChar = i%4;
QString tempString;
switch (semesterChar)
//set year x axe label to be yyyy A B C yyyy+1 A B C yyyy+2....
int semesterChar = i%4;
QString tempString;
switch (semesterChar)
{
case 1:
tempString = tr("A");
xStrings << tempString;
break;
tempString = tr("A");
xStrings << tempString;
break;
case 2:
tempString = tr("B");
xStrings << tempString;
break;
tempString = tr("B");
xStrings << tempString;
break;
case 3:
tempString = tr("C");
xStrings << tempString;
break;
tempString = tr("C");
xStrings << tempString;
break;
case 0:
tempString = QString::number(year);
xStrings << tempString;
year++;
break;
tempString = QString::number(year);
xStrings << tempString;
year++;
break;
}
}
ui->graphwidget->yAxis->setLabel(tr("AVG Grade"));
ui->graphwidget->yAxis->setTickLabelFont(QFont(QFont().family(), 8));
ui->graphwidget->yAxis->setRange(50,100);
ui->graphwidget->yAxis->setTickStep(2);
ui->graphwidget->yAxis->setAutoSubTicks(false);
ui->graphwidget->yAxis->setAutoTickStep(false);
ui->graphwidget->yAxis->setSubTickCount(5);
ui->graphwidget->yAxis->setLabel(tr("AVG Grade"));
ui->graphwidget->yAxis->setTickLabelFont(QFont(QFont().family(), 8));
ui->graphwidget->yAxis->setRange(MIN_GRADE,MAX_GRADE);
ui->graphwidget->yAxis->setTickStep(2);
ui->graphwidget->yAxis->setAutoSubTicks(false);
ui->graphwidget->yAxis->setAutoTickStep(false);
ui->graphwidget->yAxis->setSubTickCount(5);
ui->graphwidget->xAxis->setLabel(tr("Years"));
ui->graphwidget->xAxis->setAutoTickLabels(false);
ui->graphwidget->xAxis->setTickLabelFont(QFont(QFont().family(), 7));
ui->graphwidget->xAxis->setAutoTickStep(false);
ui->graphwidget->xAxis->setTickStep(1);
ui->graphwidget->xAxis->setAutoSubTicks(false);
ui->graphwidget->xAxis->setSubTickCount(1);
ui->graphwidget->xAxis->setTickVectorLabels(xStrings);
ui->graphwidget->xAxis->setRange(1,xRangeForYear);
ui->graphwidget->xAxis->setLabel(tr("Years"));
ui->graphwidget->xAxis->setAutoTickLabels(false);
ui->graphwidget->xAxis->setTickLabelFont(QFont(QFont().family(), 7));
ui->graphwidget->xAxis->setAutoTickStep(false);
ui->graphwidget->xAxis->setTickStep(1);
ui->graphwidget->xAxis->setAutoSubTicks(false);
ui->graphwidget->xAxis->setSubTickCount(0);
ui->graphwidget->xAxis->setTickVectorLabels(xStrings);
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()
{
qDebug() << Q_FUNC_INFO << " Closed Graph Dialog";
this->done(0);
qDebug() << Q_FUNC_INFO << " Closed Graph Dialog";
this->done(0);
}

View file

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

View file

@ -11,7 +11,11 @@
</rect>
</property>
<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>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
@ -29,7 +33,7 @@
</size>
</property>
<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>
</widget>
</item>
@ -82,6 +86,8 @@
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<resources>
<include location="../../../../resources/connectionstatus.qrc"/>
</resources>
<connections/>
</ui>