sagi ha manyak

This commit is contained in:
Liran BN 2014-10-15 12:26:30 +03:00
parent 85e2ea645f
commit 68030355c8
3 changed files with 61 additions and 63 deletions

View file

@ -5,6 +5,8 @@ gradegraph::gradegraph(QWidget *parent) : QDialog(parent), ui(new Ui::gradegraph
ui->setupUi(this); ui->setupUi(this);
this->setModal(true); //makes it on top of application this->setModal(true); //makes it on top of application
this->gp = NULL; this->gp = NULL;
tableWidget = new QCustomPlot(this);
ui->verticalLayoutTable->addWidget(tableWidget);
} }
@ -13,13 +15,14 @@ void gradegraph::showGraph(GradePage *gpPTR)
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
this->gp = gpPTR; this->gp = gpPTR;
if (ui->graphwidget->graphCount() > 0) if (tableWidget->graphCount() > 0)
clearGraph(); clearGraph();
setVisualization(); setVisualization();
setGraphsData(); setGraphsData();
ui->graphwidget->replot();
tableWidget->replot();
this->show(); this->show();
} }
@ -42,8 +45,8 @@ void gradegraph::setGraphsData()
indicatorX[i] = i; indicatorX[i] = i;
if (i%4==1) //years if (i%4==1) //years
{ {
QCPItemText *textLabel = new QCPItemText(ui->graphwidget); QCPItemText *textLabel = new QCPItemText(tableWidget);
ui->graphwidget->addItem(textLabel); tableWidget->addItem(textLabel);
double lastAvg = gp->getAvg(minYearInList+yearCount); double lastAvg = gp->getAvg(minYearInList+yearCount);
@ -72,8 +75,8 @@ void gradegraph::setGraphsData()
{ {
if (i+4 < xRangeForYear) //semesters if (i+4 < xRangeForYear) //semesters
{ {
QCPItemText *textLabel = new QCPItemText(ui->graphwidget); QCPItemText *textLabel = new QCPItemText(tableWidget);
ui->graphwidget->addItem(textLabel); tableWidget->addItem(textLabel);
//qDebug() << "year: " << minYearInList+yearCount << "sem " << (i-1)%4; //qDebug() << "year: " << minYearInList+yearCount << "sem " << (i-1)%4;
double avg = gp->getAvg(minYearInList+yearCount,(i-1)%4); double avg = gp->getAvg(minYearInList+yearCount,(i-1)%4);
@ -105,9 +108,9 @@ void gradegraph::setGraphsData()
} }
} }
//yearly //yearly
ui->graphwidget->graph(0)->setData(indicatorX,yearlyAvg); tableWidget->graph(0)->setData(indicatorX,yearlyAvg);
//yearly //yearly
ui->graphwidget->graph(1)->setData(indicatorX,SemesterialAvg); tableWidget->graph(1)->setData(indicatorX,SemesterialAvg);
} }
/** /**
@ -115,21 +118,21 @@ void gradegraph::setGraphsData()
*/ */
void gradegraph::setVisualization() void gradegraph::setVisualization()
{ {
ui->graphwidget->setBackground(QBrush(Qt::white)); tableWidget->setBackground(QBrush(Qt::white));
ui->graphwidget->axisRect()->setupFullAxesBox(true); //make the graph looks like a box tableWidget->axisRect()->setupFullAxesBox(true); //make the graph looks like a box
ui->graphwidget->addGraph(); //yearly and semesterial graphs tableWidget->addGraph(); //yearly and semesterial graphs
ui->graphwidget->addGraph(); tableWidget->addGraph();
ui->graphwidget->graph(0)->setName(tr("Yearly Average")); tableWidget->graph(0)->setName(tr("Yearly Average"));
ui->graphwidget->graph(0)->setPen(QPen(Qt::GlobalColor::blue)); tableWidget->graph(0)->setPen(QPen(Qt::GlobalColor::blue));
ui->graphwidget->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, Qt::blue, Qt::blue, 7)); tableWidget->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, Qt::blue, Qt::blue, 7));
ui->graphwidget->graph(0)->setLineStyle(QCPGraph::lsImpulse ); tableWidget->graph(0)->setLineStyle(QCPGraph::lsImpulse );
ui->graphwidget->graph(1)->setName(tr("Semesterial Average")); tableWidget->graph(1)->setName(tr("Semesterial Average"));
ui->graphwidget->graph(1)->setLineStyle(QCPGraph::lsStepLeft); tableWidget->graph(1)->setLineStyle(QCPGraph::lsStepLeft);
ui->graphwidget->graph(1)->setPen(QPen( QColor(Qt::GlobalColor::red))); tableWidget->graph(1)->setPen(QPen( QColor(Qt::GlobalColor::red)));
ui->graphwidget->graph(1)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, Qt::red, Qt::red, 7)); tableWidget->graph(1)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, Qt::red, Qt::red, 7));
int minYearInList = gp->getMinYearInList()-1; int minYearInList = gp->getMinYearInList()-1;
int maxYearInList = gp->getMaxYearInList()+1; int maxYearInList = gp->getMaxYearInList()+1;
@ -163,33 +166,33 @@ void gradegraph::setVisualization()
} }
} }
ui->graphwidget->yAxis->setLabel(tr("AVG Grade")); tableWidget->yAxis->setLabel(tr("AVG Grade"));
ui->graphwidget->yAxis->setTickLabelFont(QFont(QFont().family(), 8)); tableWidget->yAxis->setTickLabelFont(QFont(QFont().family(), 8));
ui->graphwidget->yAxis->setRange(MIN_GRADE,MAX_GRADE); tableWidget->yAxis->setRange(MIN_GRADE,MAX_GRADE);
ui->graphwidget->yAxis->setTickStep(2); tableWidget->yAxis->setTickStep(2);
ui->graphwidget->yAxis->setAutoSubTicks(false); tableWidget->yAxis->setAutoSubTicks(false);
ui->graphwidget->yAxis->setAutoTickStep(false); tableWidget->yAxis->setAutoTickStep(false);
ui->graphwidget->yAxis->setSubTickCount(5); tableWidget->yAxis->setSubTickCount(5);
ui->graphwidget->xAxis->setLabel(tr("Years")); tableWidget->xAxis->setLabel(tr("Years"));
ui->graphwidget->xAxis->setAutoTickLabels(false); tableWidget->xAxis->setAutoTickLabels(false);
ui->graphwidget->xAxis->setTickLabelFont(QFont(QFont().family(), 7)); tableWidget->xAxis->setTickLabelFont(QFont(QFont().family(), 7));
ui->graphwidget->xAxis->setAutoTickStep(false); tableWidget->xAxis->setAutoTickStep(false);
ui->graphwidget->xAxis->setTickStep(1); tableWidget->xAxis->setTickStep(1);
ui->graphwidget->xAxis->setAutoSubTicks(false); tableWidget->xAxis->setAutoSubTicks(false);
ui->graphwidget->xAxis->setSubTickCount(0); tableWidget->xAxis->setSubTickCount(0);
ui->graphwidget->xAxis->setTickVectorLabels(xStrings); tableWidget->xAxis->setTickVectorLabels(xStrings);
ui->graphwidget->xAxis->setRange(1,xRangeForYear); tableWidget->xAxis->setRange(1,xRangeForYear);
ui->graphwidget->legend->setVisible(true); //show graph name on top right tableWidget->legend->setVisible(true); //show graph name on top right
} }
void gradegraph::clearGraph() void gradegraph::clearGraph()
{ {
int itemDeleted,graphs,plots; int itemDeleted,graphs,plots;
itemDeleted = ui->graphwidget->clearItems(); itemDeleted = tableWidget->clearItems();
graphs = ui->graphwidget->clearGraphs(); graphs = tableWidget->clearGraphs();
plots = ui->graphwidget->clearPlottables(); plots = tableWidget->clearPlottables();
qDebug() << Q_FUNC_INFO << "items:" << itemDeleted << "graphs" << graphs << "plots:" << plots; qDebug() << Q_FUNC_INFO << "items:" << itemDeleted << "graphs" << graphs << "plots:" << plots;
} }
void gradegraph::on_pushButton_clicked() void gradegraph::on_pushButton_clicked()

View file

@ -2,6 +2,7 @@
#define GRADEGRAPH_H #define GRADEGRAPH_H
#include "../gradePage.h" #include "../gradePage.h"
#include "qcustomplot.h"
#include <QDialog> #include <QDialog>
namespace Ui { namespace Ui {
@ -27,6 +28,7 @@ private:
GradePage *gp; GradePage *gp;
QCustomPlot *tableWidget;
void setVisualization(); void setVisualization();
void setGraphsData(); void setGraphsData();
void clearGraph(); void clearGraph();

View file

@ -17,8 +17,8 @@
<iconset resource="../../../../resources/connectionstatus.qrc"> <iconset resource="../../../../resources/connectionstatus.qrc">
<normaloff>:/icons/icon.ico</normaloff>:/icons/icon.ico</iconset> <normaloff>:/icons/icon.ico</normaloff>:/icons/icon.ico</iconset>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QGridLayout" name="gridLayout">
<item> <item row="0" column="0">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum"> <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
@ -37,29 +37,30 @@
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="1" column="0">
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayoutMain">
<item> <item>
<widget class="QCustomPlot" name="graphwidget" native="true"> <layout class="QVBoxLayout" name="verticalLayoutTable"/>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="verticalLayout"/>
</widget>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayoutButtomPanel">
<property name="spacing">
<number>0</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<item> <item>
<spacer name="horizontalSpacer"> <spacer name="horizontalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>88</width> <width>90</width>
<height>20</height> <height>20</height>
</size> </size>
</property> </property>
@ -78,14 +79,6 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<customwidgets>
<customwidget>
<class>QCustomPlot</class>
<extends>QWidget</extends>
<header>qcustomplot.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources> <resources>
<include location="../../../../resources/connectionstatus.qrc"/> <include location="../../../../resources/connectionstatus.qrc"/>
</resources> </resources>