add graph. fixes more isses
This commit is contained in:
parent
63c5ec9cc7
commit
a87c5abb2c
|
@ -53,6 +53,8 @@ void coursesTableManager::insertJceCoursesIntoTable()
|
||||||
*/
|
*/
|
||||||
void coursesTableManager::setCoursesList(QString &html)
|
void coursesTableManager::setCoursesList(QString &html)
|
||||||
{
|
{
|
||||||
|
if (gp != NULL)
|
||||||
|
gp->~GradePage();
|
||||||
gp = new GradePage(html);
|
gp = new GradePage(html);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -229,7 +231,9 @@ double coursesTableManager::getAvg()
|
||||||
void coursesTableManager::showGraph()
|
void coursesTableManager::showGraph()
|
||||||
{
|
{
|
||||||
if (gp != NULL)
|
if (gp != NULL)
|
||||||
this->graph->show();
|
{
|
||||||
|
this->graph->showGraph(gp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -247,6 +251,7 @@ void coursesTableManager::influnceCourseChanged(bool ignoreCourseStatus)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (this->gp != NULL)
|
||||||
for (gradeCourse *c: *gp->getCourses())
|
for (gradeCourse *c: *gp->getCourses())
|
||||||
{
|
{
|
||||||
if (!(isCourseAlreadyInserted(c->getSerialNum())))
|
if (!(isCourseAlreadyInserted(c->getSerialNum())))
|
||||||
|
|
|
@ -172,6 +172,7 @@ void MainScreen::on_ratesButton_clicked()
|
||||||
}
|
}
|
||||||
QApplication::restoreOverrideCursor();
|
QApplication::restoreOverrideCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MainScreen::checkIfValidDates()
|
bool MainScreen::checkIfValidDates()
|
||||||
{
|
{
|
||||||
bool flag = false;
|
bool flag = false;
|
||||||
|
@ -188,29 +189,35 @@ bool MainScreen::checkIfValidDates()
|
||||||
}
|
}
|
||||||
return flag;
|
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()))
|
||||||
|
@ -221,17 +228,20 @@ void MainScreen::on_coursesTable_itemChanged(QTableWidgetItem *item)
|
||||||
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()
|
||||||
{
|
{
|
||||||
courseTableMgr->showGraph();
|
courseTableMgr->showGraph();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//EVENTS ON CALENDAR TAB
|
//EVENTS ON CALENDAR TAB
|
||||||
void MainScreen::on_getCalendarBtn_clicked()
|
void MainScreen::on_getCalendarBtn_clicked()
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
#include "gradePage.h"
|
#include "gradePage.h"
|
||||||
|
|
||||||
|
static int maxYear = 0;
|
||||||
|
static int minYear = 9999;
|
||||||
|
|
||||||
GradePage::GradePage(QString html) : Page()
|
GradePage::GradePage(QString html) : Page()
|
||||||
{
|
{
|
||||||
courses = new std::list<gradeCourse*>();
|
courses = new std::list<gradeCourse*>();
|
||||||
|
@ -115,6 +118,12 @@ gradeCourse* GradePage::lineToCourse(QString line)
|
||||||
|
|
||||||
additions = templinearray[gradeCourse::CourseScheme::ADDITION];
|
additions = templinearray[gradeCourse::CourseScheme::ADDITION];
|
||||||
|
|
||||||
|
if (year >= maxYear)
|
||||||
|
maxYear = year;
|
||||||
|
|
||||||
|
if (year <= minYear)
|
||||||
|
minYear = year;
|
||||||
|
|
||||||
tempC = new gradeCourse(year,semester,courseNumInList,serial,name,type,points,hours,grade,additions);
|
tempC = new gradeCourse(year,semester,courseNumInList,serial,name,type,points,hours,grade,additions);
|
||||||
return tempC;
|
return tempC;
|
||||||
}
|
}
|
||||||
|
@ -135,11 +144,15 @@ bool GradePage::isGradedYet(QString grade)
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @brief GradePage::getAvg getting avg
|
||||||
|
* @return - gpa avg of all courses
|
||||||
|
*/
|
||||||
double GradePage::getAvg()
|
double GradePage::getAvg()
|
||||||
{
|
{
|
||||||
double avg = 0;
|
double avg = 0;
|
||||||
double points = 0;
|
double points = 0;
|
||||||
for(gradeCourse* c : *courses)
|
for (gradeCourse* c : *courses)
|
||||||
{
|
{
|
||||||
if ((c->getGrade() != 0))
|
if ((c->getGrade() != 0))
|
||||||
{
|
{
|
||||||
|
@ -151,3 +164,63 @@ double GradePage::getAvg()
|
||||||
avg /= points;
|
avg /= points;
|
||||||
return avg;
|
return avg;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @brief GradePage::getAvg getting avg of given year
|
||||||
|
* @param year - year (yyyy)
|
||||||
|
* @return - gpa avg of given year
|
||||||
|
*/
|
||||||
|
double GradePage::getAvg(int year)
|
||||||
|
{
|
||||||
|
double avg = 0;
|
||||||
|
double points = 0;
|
||||||
|
for (gradeCourse* c : *courses)
|
||||||
|
{
|
||||||
|
if ((c->getGrade() != 0) && (c->getYear() == year))
|
||||||
|
{
|
||||||
|
avg += c->getGrade() * c->getPoints();
|
||||||
|
points += c->getPoints();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (points != 0)
|
||||||
|
avg /= points;
|
||||||
|
else
|
||||||
|
avg=0;
|
||||||
|
return avg;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @brief GradePage::getAvg
|
||||||
|
* @param year - year (yyyy)
|
||||||
|
* @param semester - semeser (1-3)
|
||||||
|
* @return -gpa avg of given year in given semester
|
||||||
|
*/
|
||||||
|
double GradePage::getAvg(int year, int semester)
|
||||||
|
{
|
||||||
|
double avg = 0;
|
||||||
|
double points = 0;
|
||||||
|
for (gradeCourse* c : *courses)
|
||||||
|
{
|
||||||
|
if ((c->getGrade() != 0) && (c->getYear() == year) && (c->getSemester() == semester))
|
||||||
|
{
|
||||||
|
avg += c->getGrade() * c->getPoints();
|
||||||
|
points += c->getPoints();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (points != 0)
|
||||||
|
avg /= points;
|
||||||
|
else
|
||||||
|
avg=0;
|
||||||
|
return avg;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @brief GradePage::getMinYearInList
|
||||||
|
* @return the minimal year inside courses list
|
||||||
|
*/
|
||||||
|
int GradePage::getMinYearInList()
|
||||||
|
{
|
||||||
|
return minYear;
|
||||||
|
}
|
||||||
|
|
||||||
|
int GradePage::getMaxYearInList()
|
||||||
|
{
|
||||||
|
return maxYear;
|
||||||
|
}
|
||||||
|
|
|
@ -22,6 +22,12 @@ public:
|
||||||
|
|
||||||
void removeCourse(QString courseSerialID);
|
void removeCourse(QString courseSerialID);
|
||||||
double getAvg();
|
double getAvg();
|
||||||
|
double getAvg(int year);
|
||||||
|
double getAvg(int year, int semester);
|
||||||
|
|
||||||
|
int getMinYearInList();
|
||||||
|
int getMaxYearInList();
|
||||||
|
|
||||||
|
|
||||||
std::list<gradeCourse*>* getCourses() { return courses; }
|
std::list<gradeCourse*>* getCourses() { return courses; }
|
||||||
|
|
||||||
|
@ -33,6 +39,7 @@ private:
|
||||||
bool isGradedYet(QString grade);
|
bool isGradedYet(QString grade);
|
||||||
|
|
||||||
std::list<gradeCourse*>* courses;
|
std::list<gradeCourse*>* courses;
|
||||||
|
|
||||||
QString tempHtml;
|
QString tempHtml;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,9 +7,143 @@ gradegraph::gradegraph(QWidget *parent, GradePage *gpPTR) :
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
this->gp = gpPTR;
|
this->gp = gpPTR;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void gradegraph::showGraph(GradePage *gpPTR)
|
||||||
|
{
|
||||||
|
this->gp = gpPTR;
|
||||||
|
setVisualization();
|
||||||
|
setGraphsData();
|
||||||
|
this->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
gradegraph::~gradegraph()
|
gradegraph::~gradegraph()
|
||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void gradegraph::setGraphsData()
|
||||||
|
{
|
||||||
|
int minYearInList = gp->getMinYearInList(); //2012
|
||||||
|
int maxYearInList = gp->getMaxYearInList()+1; //2016
|
||||||
|
int xRangeForYear = (maxYearInList - minYearInList+2)*3; //6*3=18
|
||||||
|
QVector<double> SemesterialAvg(xRangeForYear),yearlyAvg(xRangeForYear),sem(xRangeForYear);
|
||||||
|
|
||||||
|
for (int yearCount=0,i=1; i<xRangeForYear; ++i)
|
||||||
|
{
|
||||||
|
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++;
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
yearlyAvg[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//yearly
|
||||||
|
ui->graphwidget->graph(0)->setData(sem,yearlyAvg);
|
||||||
|
//yearly
|
||||||
|
ui->graphwidget->graph(1)->setData(sem,SemesterialAvg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief gradegraph::setvisualization set graph borders text, range and looking
|
||||||
|
*/
|
||||||
|
void gradegraph::setVisualization()
|
||||||
|
{
|
||||||
|
ui->graphwidget->axisRect()->setupFullAxesBox(true); //make the graph looks like a box
|
||||||
|
|
||||||
|
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(1)->setName(tr("Semesterial Average"));
|
||||||
|
ui->graphwidget->graph(1)->setLineStyle(QCPGraph::lsLine);
|
||||||
|
ui->graphwidget->graph(1)->setPen(QPen( QColor(Qt::GlobalColor::red)));
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
tempString = tr("A");
|
||||||
|
xStrings << tempString;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
tempString = tr("B");
|
||||||
|
xStrings << tempString;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
tempString = tr("C");
|
||||||
|
xStrings << tempString;
|
||||||
|
break;
|
||||||
|
case 0:
|
||||||
|
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->xAxis->setLabel(tr("Years"));
|
||||||
|
ui->graphwidget->xAxis->setAutoTickLabels(false);
|
||||||
|
ui->graphwidget->xAxis->setTickVectorLabels(xStrings);
|
||||||
|
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->setRange(1,xRangeForYear);
|
||||||
|
|
||||||
|
ui->graphwidget->legend->setVisible(true); //show graph name on top right
|
||||||
|
}
|
||||||
|
|
|
@ -15,11 +15,15 @@ class gradegraph : public QDialog
|
||||||
|
|
||||||
public:
|
public:
|
||||||
gradegraph(QWidget *parent = 0, GradePage *gpPTR = 0);
|
gradegraph(QWidget *parent = 0, GradePage *gpPTR = 0);
|
||||||
|
void showGraph(GradePage *gpPTR);
|
||||||
~gradegraph();
|
~gradegraph();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
GradePage *gp;
|
GradePage *gp;
|
||||||
|
|
||||||
|
void setVisualization();
|
||||||
|
void setGraphsData();
|
||||||
Ui::gradegraph *ui;
|
Ui::gradegraph *ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -6,14 +6,14 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>597</width>
|
<width>624</width>
|
||||||
<height>461</height>
|
<height>527</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Dialog</string>
|
<string>Dialog</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
@ -34,7 +34,16 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCustomPlot" name="graphwidget" native="true"/>
|
<widget class="QCustomPlot" name="graphwidget" native="true">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout"/>
|
||||||
|
<zorder></zorder>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
|
Loading…
Reference in a new issue