graph view, parent pointer to table
This commit is contained in:
parent
bec16503b7
commit
7980382db7
6 changed files with 593 additions and 528 deletions
|
@ -22,7 +22,7 @@ coursesTableManager::coursesTableManager(QTableWidget *ptr, user *usrPtr)
|
|||
courseTBL->setShowGrid(true);
|
||||
courseTBL->setStyleSheet("QTableView {selection-background-color: red;}");
|
||||
|
||||
graph = new gradegraph(NULL);
|
||||
graph = new gradegraph(ptr);
|
||||
}
|
||||
|
||||
coursesTableManager::~coursesTableManager()
|
||||
|
@ -196,7 +196,8 @@ void coursesTableManager::addRow(const gradeCourse *courseToAdd)
|
|||
hours->setFlags(hours->flags() & ~Qt::ItemIsEditable);
|
||||
|
||||
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->setData(Qt::EditRole,c->getAddidtions());
|
||||
|
@ -210,6 +211,8 @@ void coursesTableManager::addRow(const gradeCourse *courseToAdd)
|
|||
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);
|
||||
|
@ -249,11 +252,15 @@ double coursesTableManager::getAvg()
|
|||
|
||||
void coursesTableManager::showGraph()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
if (gp != NULL)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << " Graph Dialog Opened. gp != NULL";
|
||||
this->graph->showGraph(gp);
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning() << Q_FUNC_INFO << "open with null grade page";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#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)
|
||||
{
|
||||
|
@ -136,6 +136,7 @@ void MainScreen::on_usrnmLineEdit_editingFinished()
|
|||
//EVENTS ON GPA TAB
|
||||
void MainScreen::on_ratesButton_clicked()
|
||||
{
|
||||
|
||||
ui->progressBar->setValue(0);
|
||||
qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName();
|
||||
if (!checkIfValidDates())
|
||||
|
@ -234,7 +235,7 @@ void MainScreen::on_clearTableButton_clicked()
|
|||
|
||||
void MainScreen::on_graphButton_clicked()
|
||||
{
|
||||
qDebug() << "Show Graph button clicked";
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
courseTableMgr->showGraph();
|
||||
}
|
||||
|
||||
|
|
|
@ -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">
|
||||
|
|
|
@ -4,23 +4,27 @@
|
|||
* 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->setModal(true); //makes it on top of application
|
||||
this->gp = NULL;
|
||||
|
||||
}
|
||||
|
||||
void gradegraph::showGraph(GradePage *gpPTR)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
this->gp = gpPTR;
|
||||
|
||||
clearGraph();
|
||||
|
||||
setVisualization();
|
||||
setGraphsData();
|
||||
this->show();
|
||||
this->setModal(true); //makes it on top of application
|
||||
|
||||
ui->graphwidget->replot();
|
||||
|
||||
this->show();
|
||||
}
|
||||
|
||||
gradegraph::~gradegraph()
|
||||
|
@ -33,24 +37,37 @@ 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);
|
||||
QVector<double> SemesterialAvg(xRangeForYear),yearlyAvg(xRangeForYear),indicatorX(xRangeForYear);
|
||||
|
||||
for (int yearCount=0,i=1; i<xRangeForYear; ++i) //filling data
|
||||
{
|
||||
double lastAvg = 0;
|
||||
sem[i] = i;
|
||||
|
||||
indicatorX[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);
|
||||
|
||||
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++;
|
||||
|
||||
}
|
||||
|
@ -58,17 +75,32 @@ void gradegraph::setGraphsData()
|
|||
{
|
||||
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
|
||||
|
||||
//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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -76,9 +108,9 @@ void gradegraph::setGraphsData()
|
|||
}
|
||||
}
|
||||
//yearly
|
||||
ui->graphwidget->graph(0)->setData(sem,yearlyAvg);
|
||||
ui->graphwidget->graph(0)->setData(indicatorX,yearlyAvg);
|
||||
//yearly
|
||||
ui->graphwidget->graph(1)->setData(sem,SemesterialAvg);
|
||||
ui->graphwidget->graph(1)->setData(indicatorX,SemesterialAvg);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -86,18 +118,22 @@ void gradegraph::setGraphsData()
|
|||
*/
|
||||
void gradegraph::setVisualization()
|
||||
{
|
||||
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->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)->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)->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;
|
||||
|
@ -133,7 +169,7 @@ void gradegraph::setVisualization()
|
|||
}
|
||||
ui->graphwidget->yAxis->setLabel(tr("AVG Grade"));
|
||||
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->setAutoSubTicks(false);
|
||||
ui->graphwidget->yAxis->setAutoTickStep(false);
|
||||
|
@ -146,13 +182,20 @@ void gradegraph::setVisualization()
|
|||
ui->graphwidget->xAxis->setAutoTickStep(false);
|
||||
ui->graphwidget->xAxis->setTickStep(1);
|
||||
ui->graphwidget->xAxis->setAutoSubTicks(false);
|
||||
ui->graphwidget->xAxis->setSubTickCount(1);
|
||||
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
|
||||
}
|
||||
|
||||
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";
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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><html><head/><body><p align="center"><span style=" font-size:18pt; font-weight:600;">Graph View</span></p></body></html></string>
|
||||
<string><html><head/><body><p align="center"><span style=" font-size:18pt; font-weight:600;">GPA Graph View</span></p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -82,6 +86,8 @@
|
|||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<resources>
|
||||
<include location="../../../../resources/connectionstatus.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
Loading…
Reference in a new issue