This commit is contained in:
Liran BN 2014-08-31 12:35:43 +03:00
parent 95ccaa39d0
commit 65ce3d40ea
4 changed files with 0 additions and 469 deletions

View file

@ -1,251 +0,0 @@
#include "coursestablemanager.h"
coursesTableManager::coursesTableManager(QTableWidget *ptr, user *usrPtr)
{
this->gp = NULL;
this->us = usrPtr;
this->courseTBL = ptr;
/*
* Initilizing Table
*/
courseTBL->setRowCount(0);
courseTBL->setColumnCount(COURSE_FIELDS);
QStringList mz;
mz << QObject::tr("Code") << QObject::tr("Name") << QObject::tr("Type") << QObject::tr("Points") << QObject::tr("Hours") << QObject::tr("Grade") << QObject::tr("Additions");
courseTBL->setHorizontalHeaderLabels(mz);
courseTBL->verticalHeader()->setVisible(true);
courseTBL->setSelectionMode(QAbstractItemView::SingleSelection);
courseTBL->setShowGrid(true);
courseTBL->setStyleSheet("QTableView {selection-background-color: red;}");
}
coursesTableManager::~coursesTableManager()
{
courseTBL = NULL;
delete gp;
gp = NULL;
}
/**
* @brief coursesTableManager::insertJceCoursesIntoTable phrasing the course list to rows in table
*/
void coursesTableManager::insertJceCoursesIntoTable()
{
for (Course *c: *gp->getCourses())
{
if (us->getInfluenceCourseOnly())
{
if (isCourseInfluence(c))
addRow(c);
}
else
addRow(c);
}
}
/**
* @brief coursesTableManager::setCoursesList creating courses list with given html page
* @param html
*/
void coursesTableManager::setCoursesList(std::string &html)
{
gp = new GradePage(html);
}
/**
* @brief coursesTableManager::changes when user changes the table manually
* @param change string change
* @param row row index
* @param col col index
* @return if change has been done
*/
bool coursesTableManager::changes(QString change, int row, int col)
{
bool isNumFlag = true; //a flag to check if number
int serialCourse = courseTBL->item(row,Course::CourseScheme::SERIAL)->text().toInt();
for (Course *c: *gp->getCourses())
{
if (c->getSerialNum() == serialCourse)
{
switch (col)
{
case (Course::CourseScheme::NAME):
c->setName(change.toStdString());
break;
case (Course::CourseScheme::TYPE):
c->setType(change.toStdString());
break;
case (Course::CourseScheme::POINTS):
{
change.toDouble(&isNumFlag);
if (!isNumFlag)
{
courseTBL->item(row,col)->setText(QString::number(c->getPoints()));
}
else
c->setPoints(change.toDouble());
break;
}
case (Course::CourseScheme::HOURS):
{
change.toDouble(&isNumFlag);
if (!isNumFlag)
{
courseTBL->item(row,col)->setText(QString::number(c->getHours()));
}
else
c->setHours(change.toDouble());
break;
}
case (Course::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());
else
courseTBL->item(row,col)->setText(QString::number(c->getGrade()));
}
break;
}
case (Course::CourseScheme::ADDITION):
c->setAdditions(change.toStdString());
break;
}
break;
}
}
return isNumFlag;
}
/**
* @brief coursesTableManager::addRow adds row with given information
* @param courseToAdd if exists, add its information to table
*/
void coursesTableManager::addRow(const Course *courseToAdd)
{
int i,j;
i = courseTBL->rowCount();
j = 0;
QTableWidgetItem *serial,*name,*type,*points,*hours,*grade,*addition;
const Course * c;
if (courseToAdd != NULL)
{
c = courseToAdd;
if (!isCourseAlreadyInserted(c->getSerialNum()))
{
courseTBL->setRowCount(courseTBL->rowCount()+1);
serial = new QTableWidgetItem(QString::number(c->getSerialNum()));
serial->setFlags(serial->flags() & ~Qt::ItemIsEditable);
points = new QTableWidgetItem(QString::number(c->getPoints()));
points->setFlags(serial->flags() & ~Qt::ItemIsEditable);
hours = new QTableWidgetItem(QString::number(c->getHours()));
hours->setFlags(serial->flags() & ~Qt::ItemIsEditable);
grade = new QTableWidgetItem(QString::number(c->getGrade()));
name = new QTableWidgetItem(QString::fromStdString(c->getName()));
name->setFlags(serial->flags() & ~Qt::ItemIsEditable);
type = new QTableWidgetItem(QString::fromStdString(c->getType()));
type->setFlags(serial->flags() & ~Qt::ItemIsEditable);
addition = new QTableWidgetItem(QString::fromStdString(c->getAddidtions()));
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);
courseTBL->setItem(i,j,addition);
}
}
else
{
}
courseTBL->resizeColumnsToContents();
}
double coursesTableManager::getAvg()
{
if (this->gp != NULL)
return gp->getAvg();
return 0;
}
void coursesTableManager::influnceCourseChanged(bool ignoreCourseStatus)
{
if (ignoreCourseStatus)
{
int i = 0;
while (i < courseTBL->rowCount())
{
if (courseTBL->item(i,Course::CourseScheme::POINTS)->text().compare("0") == 0)
courseTBL->removeRow(i--);
i++;
}
}
else
{
for (Course *c: *gp->getCourses())
{
if (!(isCourseAlreadyInserted(c->getSerialNum())))
if (c->getPoints() == 0)
addRow(c);
}
}
}
void coursesTableManager::clearTable()
{
if (courseTBL->rowCount() == 0)
return;
int i = 0; //starting point
while (courseTBL->rowCount() > i)
{
gp->removeCourse(courseTBL->item(i,Course::CourseScheme::SERIAL)->text().toStdString());
courseTBL->removeRow(i);
}
gp = NULL;
courseTBL->repaint();
}
Course *coursesTableManager::getCourseByRow(int row)
{
QString courseSerial = courseTBL->item(row,Course::CourseScheme::SERIAL)->text();
for (Course *c: *gp->getCourses())
{
if (c->getSerialNum() == courseSerial.toDouble())
return c;
}
return NULL;
}
bool coursesTableManager::isCourseAlreadyInserted(double courseID)
{
int i=0;
for (i = 0; i < courseTBL->rowCount(); ++i)
{
QString courseSerial = courseTBL->item(i,Course::CourseScheme::SERIAL)->text();
if (QString::number(courseID) == courseSerial)
return true;
}
return false;
}
bool coursesTableManager::isCourseInfluence(const Course *courseToCheck)
{
if (courseToCheck->getPoints() > 0)
return true;
return false;
}

View file

@ -1,43 +0,0 @@
#ifndef COURSESTABLEMANAGER_H
#define COURSESTABLEMANAGER_H
#include <QApplication>
#include <QDesktopWidget>
#include <QtCore/QCoreApplication>
#include <QHeaderView>
#include <QMessageBox>
#include <QTableWidget>
#include <QString>
#include <QMessageBox>
#include <list>
#include "src/grades/GradePage.h"
#include "src/user.h"
class coursesTableManager
{
public:
coursesTableManager(QTableWidget *, user *usrPtr);
~coursesTableManager();
void insertJceCoursesIntoTable();
void setCoursesList(std::string &htmlPage);
bool changes(QString change, int row, int col);
void addRow(const Course * courseToAdd = 0);
double getAvg();
void influnceCourseChanged(bool status);
void clearTable();
private:
QTableWidget *courseTBL;
GradePage *gp;
user *us;
Course * getCourseByRow(int row);
bool isCourseAlreadyInserted(double courseID);
bool isCourseInfluence(const Course *courseToCheck);
};
#endif // COURSESTABLEMANAGER_H

View file

@ -1,133 +0,0 @@
#include "loginhandler.h"
loginHandler::loginHandler(user *ptr): logggedInFlag(false)
{
this->jceLog = new jceLogin(ptr);
}
void loginHandler::setPointers(QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr)
{
this->statusLabelPtr = statusLabelPtr;
this->pswdEditPtr = pswdEditPtr;
this->usrnmEditPtr = usrnmEditPtr;
}
bool loginHandler::makeConnection()
{
if (this->jceLog == NULL)
return false;
try
{
jceLog->makeConnection();
}
catch (jceLogin::jceStatus &a)
{
int status = (int)a;
switch (status)
{
case jceLogin::JCE_YOU_ARE_IN:
{
logggedInFlag = true;
return logggedInFlag;
break;
}
case jceLogin::ERROR_ON_VALIDATION:
{
popMessage("Please Check Your Username & Password",false);
usrnmEditPtr->setDisabled(false);
pswdEditPtr->setDisabled(false);
pswdEditPtr->selectAll();
pswdEditPtr->setFocus();
return false;
}
case jceLogin::ERROR_ON_VALIDATION_USER_BLOCKED:
{
popMessage("You have been blocked by JCE, please try in a couple of minutes.");
jceLog->closeAll();
return false;
}
case jceLogin::ERROR_ON_OPEN_SOCKET:
{
popMessage("Please Check Your Internet Connection.");
jceLog->closeAll();
return false;
}
case jceLogin::JCE_NOT_CONNECTED:
{
jceLog->reConnect();
/*
* Fix: need to add promte window to ask user whenever he wants to reconnect or not
*/
break;
}
case jceLogin::ERROR_ON_GETTING_INFO:
{
popMessage("Recieve Request Time Out.");
jceLog->closeAll();
return false;
break;
}
case jceLogin::ERROR_ON_SEND_REQUEST:
{
popMessage("Send Request Time Out.");
jceLog->closeAll();
return false;
break;
}
}
}
return false;
}
bool loginHandler::isLoggedInFlag()
{
return this->logggedInFlag;
}
void loginHandler::setLoginFlag(bool flag)
{
this->logggedInFlag = flag;
}
QString loginHandler::getCurrentPageContect()
{
QTextEdit phrase;
if (isLoggedInFlag())
phrase.setText(QString::fromStdString(jceLog->getPage()));
else
throw jceLogin::ERROR_ON_GETTING_INFO;
return phrase.toPlainText();
}
void loginHandler::makeDisconnectionRequest()
{
jceLog->closeAll();
this->logggedInFlag = false;
}
int loginHandler::makeGradeRequest()
{
if (isLoggedInFlag())
return jceLog->getGrades();
else
return jceLogin::JCE_NOT_CONNECTED;
}
void loginHandler::popMessage(QString message,bool addInfo)
{
if (addInfo)
message.append("\nIf this message appear without reason, please contact me at liranbg@gmail.com");
QMessageBox msgBox;
msgBox.setWindowTitle("Error");
msgBox.setText(message);
msgBox.exec();
msgBox.setFocus();
}

View file

@ -1,42 +0,0 @@
#ifndef LOGINHANDLER_H
#define LOGINHANDLER_H
#include <QString>
#include <QLabel>
#include <QLineEdit>
#include <QTextEdit>
#include <QMessageBox>
#include <QPixmap>
#include "src/jce/jcelogin.h"
#include "./src/data/savedata.h"
class loginHandler
{
public:
loginHandler(user *ptr);
void setPointers(QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr);
bool makeConnection();
bool isLoggedInFlag();
void setLoginFlag(bool flag);
QString getCurrentPageContect();
int makeGradeRequest();
void makeDisconnectionRequest();
private:
void popMessage(QString message, bool addInfo = true);
bool logggedInFlag;
jceLogin *jceLog;
QLabel *statusLabelPtr;
QLineEdit *pswdEditPtr;
QLineEdit *usrnmEditPtr;
};
#endif // LOGINHANDLER_H