void DialogProgTache::verificationParties() { int min = 0; //on parcours toutes les parties for(int i = 0; i < vec_duree.size(); ++i) { //on faite la somme des durée pour vérifier que la somme == durée de la tache min += vec_duree.at(i).getHeure()*60; min += vec_duree.at(i).getMinute(); if(i < vec_duree.size() -1) { QDate d = vec_date.at(i); QDate dd = vec_date.at(i+1); QTime deb = vec_debut.at(i); QTime debdeb = vec_debut.at(i+1); //on vérifie l'ordre des parties if((d > dd) || (d==dd && deb > debdeb)) throw CalendarException("Ordre des parties incohérentes"); //date et horaire différents if(d==dd && deb == debdeb) throw CalendarException("Les parties ne peuvent pas avoir la même programmation"); QTime fin = deb.addSecs(vec_duree.at(i).getDureeEnMinutes()*60); //chevauchements if(d==dd && fin > debdeb) throw CalendarException("Les parties se chevauchent"); } //vérifie la cohérence avec disponibilité et échéance if(vec_date.at(i) < tache->getDispo() || vec_date.at(i) > tache->getEcheance()) throw CalendarException("Parties non conforme avec la disponibilité et échéance de la tache"); } Duree d(min); if(!(tache->getDuree() == d)) throw CalendarException("Somme des durées des parties non cohérentes"); }
void TacheManager::setDatesDisponibiliteEcheance(Tache& t, const QDate& disp, const QDate& e) { if (e<disp) throw CalendarException("erreur Tâche : date echéance < date disponibilité"); const list<Tache*> l = this->getTaches(); list<Tache*>::const_iterator it; for( it = l.begin() ; it != l.end() ; ++it ) { if( (*it)->estPredecesseur(t) ) { if( (*it)->getDateDisponibilite() > disp ) throw CalendarException( "Le successeur "+(*it)->getTitre()+" possede une date de dispo supérieure" ); if( (*it)->getDateEcheance() < e ) throw CalendarException( "Le successeur "+(*it)->getTitre()+" possede une date d'échéance inférieure" ); } TacheComposite* tc = dynamic_cast<TacheComposite*>(*it); if( tc && tc->estSousTache(t) ) { if( (*it)->getDateDisponibilite() > disp ) throw CalendarException( "La sur-tache "+tc->getTitre()+" possede une date de dispo supérieure" ); if( (*it)->getDateEcheance() < e ) throw CalendarException( "Le successeur "+tc->getTitre()+" possede une date d'échéance inférieure" ); } } t.setDatesDisponibiliteEcheance(disp, e); }
void Agenda::ajouterProgrammation(const Evenement & t, const QDate& d, const QTime& debut, const QTime & fin) { list<Programmation *>::iterator iterator = programmations.begin(); //-On fait avancer l'itérateur jusqu'au jour qui nous intéresse while ( iterator != programmations.end() && (*iterator)->getDate() != d ) { iterator++; } // on continue jusqu'à atteindre la programmation située juste après celle à insérer c'est à dire soit : // la fin de la liste, soit la programmation où ce n'est plus le bon jour, soit la programmation suivante dans le planning while ( iterator != programmations.end() && (*iterator)->getDate() == d && debut > (*iterator)->getFin() ) { if ( Agenda::chevauche(d, debut, fin, iterator)) { throw CalendarException("Erreur AjoutProgrammation : deux prog ne peuvent se chevaucher (le cheval c'est génial)"); } ++iterator; } // on vérifie les chevauchements if ( Agenda::chevauche(d, debut, fin, iterator)) { throw CalendarException("Erreur AjoutProgrammation : deux prog ne peuvent se chevaucher (le cheval c'est génial)"); } //insertion de la programmation programmations.insert(iterator, new Programmation(t, d, debut, fin) ); }
void TacheManager::ajouterSousTache(const QString& t, const QString& soust) { TacheComposite* t1= dynamic_cast<TacheComposite*>(trouverTache(t)); if (!t1) throw CalendarException(t+" n'existe pas ou n'est pas composite"); Tache* t2=trouverTache(soust); if (!t2) throw CalendarException("TacheManager, "+soust+" inexistant"); t1->ajouterSousTache(*t2); }
void TacheManager::ajouterPred(const QString& t, const QString& pred) { Tache* t1= trouverTache(t); if (!t1) throw CalendarException("TacheManager, "+t+" inexistant"); Tache* t2=trouverTache(pred); if (!t2) throw CalendarException("TacheManager, "+pred+" inexistant"); t1->ajouterPredecesseur(*t2); }
void TacheManager::setDebut(const QDate& d) { if(d > fin) throw CalendarException("La date de début dépasse la date de fin"); for (std::list<Tache*>::const_iterator it = taches.begin(); it != taches.end(); it++) { if( (*it)->getDateDisponibilite() < d ) throw CalendarException(getNom()+": la tâche "+(*it)->getTitre()+" possède une échéance inférieure"); } debut=d; }
void TacheManager::setFin(const QDate& f) { if(debut > f) throw CalendarException("La date de début dépasse la date de fin"); for (std::list<Tache*>::const_iterator it = taches.begin(); it != taches.end(); it++) { if( (*it)->getDateEcheance() > f ) throw CalendarException(getNom()+": la tâche "+(*it)->getTitre()+" possède une deadline supérieure"); } fin=f; }
Tache& TacheManager::ajouterTacheUnaire(const QString& t, const QString& desc, const QDate& dispo, const QDate& deadline, const Duree& dur, bool preempt){ if( dispo < debut ) throw CalendarException(t+" ne doit pas commencer avant le début du projet"); if( deadline > fin ) throw CalendarException(t+" ne doit pas terminer après la fin du projet"); if (trouverTache(t)) throw CalendarException("Une tâche portant le même nom existe déjà dans le projet"); Tache* newt=new TacheUnaire(this, t,desc,dispo,deadline,dur,preempt); addItem(newt); return *newt; }
void Projet::ajouterTache(Tache *t) { if(taches.find(t->getId()) != taches.end()) throw CalendarException("Identifiant déjà existant"); if(t->getDisponibilite()<disponibilite) throw CalendarException("Disponibilité inférieure à celle du projet"); if(t->getEcheance()>echeance) throw CalendarException("Date d'échéance supérieure à celle du projet"); taches[t->getId()] = t; notifier(); }
void Agenda::ajouterProgrammation(const TacheUnitaire & t, const QDate& d, const QTime& h){ vector <Programmation *> & listeProgrammation = trouverProgrammation(t); // si la programmation existe déjà, on ne peut pas la programmer à nouveau if (listeProgrammation.size() != 0 ) { throw CalendarException("erreur ajouterProgrammation, cette fonction ne peut être appelée que si la tâche n'a jamais été programmée"); } int minute_fin = h.minute() + t.getDuree().getMinute(); int heure_fin = h.hour() + t.getDuree().getHeure() + (minute_fin / 60) ; minute_fin = minute_fin % 60; if ( !QTime::isValid(heure_fin, minute_fin, 0) ) { throw CalendarException("erreur ajouterProgrammation : une programmation ne peut pas être à cheval sur deux jours"); } ajouterProgrammation(t, d, h, *(new QTime(heure_fin, minute_fin)) ); }
Projet *ProjetManager::getProjet(const QString &id) { Projet* p = trouverProjet(id); if (!p) throw CalendarException("erreur, ProjetManager, projet inexistant"); return p; }
void Rdv::ajouterPersonne(const QString &nom) { for(std::vector<QString>::iterator it = personnes.begin() ; it != personnes.end() ; it++) if(*it == nom) throw CalendarException("Cette personne est déjà enregistrée"); personnes.push_back(nom); }
void UniqueTask::setDuree(QTime duration) { if(!m_preemptable && QTime(0, 0, 0).secsTo(duration)>=PREEMPT_TASK_MAX_DURATION*3600) throw CalendarException("Une tache préemptable ne peux pas avoir une durée qui excède "+QString::number(PREEMPT_TASK_MAX_DURATION)+"h"); else m_duration=duration; }
void UniqueTask::setPreemptability(bool choice) { if(QTime(0, 0, 0).secsTo(m_duration)>=PREEMPT_TASK_MAX_DURATION*3600 && !choice) throw CalendarException("Une tache préemptable ne peux pas avoir une durée qui excède "+QString::number(PREEMPT_TASK_MAX_DURATION)+"h"); else m_preemptable=choice; }
Tache* ProjetManager::getTache(const QString &id) { //qDebug() << "getTache(" << id << ");" ; Tache* t = trouverTache(id); if (!t) throw CalendarException("erreur, ProjetManager, tache inexistante"); return t; }
TacheUnitaire::TacheUnitaire(QString _titre, QDateTime _disponibilite, QDateTime _echeance, QTime _duree, bool _preemptable): Tache(_titre,_disponibilite,_echeance),duree(_duree),preemptable(_preemptable) { if(_preemptable && _duree>QTime::fromString("12:00:00")) { throw CalendarException("La tache unitaire non preemptable ne peut exceder 12h"); } }
Scheduling::Scheduling(QDateTime date,QTime duration,QString title): m_date(date),m_duration(duration),m_title(title),m_task(NULL) { if(date < QDateTime::currentDateTime()) { throw CalendarException("La date de la programmation est déjà passée !"); } }
void DialogProgTache::verification() { //si il s'agit d'une programmation de parties de taches, les verifiactions ont déjà été faites if(!ui->parties->isChecked()) { if(tache->getDispo() > ui->date->date()) throw CalendarException("Tache pas encore disponible"); if(tache->getEcheance() < ui->date->date()) throw CalendarException("Echéance dépassée"); Agenda* ag = &Agenda::getInstance(); //boucles sur les precedences pour vérifier la cohérence std::vector<Precedence*> vec = PrecedenceManager::getInstance().findPrecedence(projet, tache); for(std::vector<Precedence*>::iterator ite = vec.begin(); ite != vec.end(); ++ite) { //boucle sur ttes les précédences dt la tache succ ou pred est celle que l'on programme if(tache->getTitre() == (*ite)->getSucc().getTitre() || tache->getTitre() == (*ite)->getPred().getTitre()) { for(Agenda::Iterator it = ag->begin(); it != ag->end(); ++it)//boucle sur ttes les taches déjà programmées { //verif que c'est bien une prog de tache if((*it).type() == 2) { //si la tache est la tache antérieure de la précédence if(tache->getTitre() == (*ite)->getSucc().getTitre()) { ProgrammationTacheUnitaire* ptu = dynamic_cast<ProgrammationTacheUnitaire*>(&(*it)); if(ptu->getDate() > ui->date->date() || (ptu->getDate() == ui->date->date() && ptu->getDebut() > ui->horaire->time())) { throw CalendarException("Incohérence avec les contraintes de Précédences"); } } //sinon la tache est la tache postérieure de la précédence else { ProgrammationTacheUnitaire* ptu = dynamic_cast<ProgrammationTacheUnitaire*>(&(*it)); if(ptu->getDate() < ui->date->date() || (ptu->getDate() == ui->date->date() && ptu->getDebut() < ui->horaire->time())) { throw CalendarException("Incohérence avec les contraintes de Précédences"); } } } } } } } }
UniqueTask::UniqueTask(QString title,QDateTime disponibility,QDateTime deadline,QTime duration,bool preemptable): Task(title,disponibility,deadline),m_duration(duration),m_preemptable(preemptable) { if(!preemptable && QTime(0, 0, 0).secsTo(duration)>=PREEMPT_TASK_MAX_DURATION*3600) { throw CalendarException("Une tache préemptable ne peux pas avoir une durée qui excède "+QString::number(PREEMPT_TASK_MAX_DURATION)+"h"); } }
void TacheManager::afficherTaches(){ for (QVector<Tache*>::Iterator it= taches.begin(); it != taches.end(); ++it){ try{ throw CalendarException((*it)->getId() +" -- "+(*it)->getTitre()); }catch (CalendarException e){ e.afficherInfo(); } } }
void TacheManager::ajouterTache(Tache* t){ try { if (isExistant(t)) throw CalendarException("Une tâche a déjà cet id"); else taches.push_back(t); } catch(CalendarException e){ e.afficherWarning(); } }
void Rdv::retirerPersonne(const QString &nom) { std::vector<QString>::iterator it; for(it = personnes.begin() ; it != personnes.end() ; it++) if(*it == nom){ personnes.erase(it); return ; } throw CalendarException("Erreur, Rdv, cette personne n'etait pas enregistree"); }
void Projet::load(const QString &f) { //qDebug()<<"debut load\n"; //this->~TacheManager(); QFile fin(f); // If we can't open it, let's show an error message. if (!fin.open(QIODevice::ReadOnly | QIODevice::Text)) { throw CalendarException("Erreur ouverture fichier tâches"); } // QXmlStreamReader takes any QIODevice. QXmlStreamReader xml(&fin); //qDebug()<<"debut fichier\n"; // We'll parse the XML until we reach end of it. while(!xml.atEnd() && !xml.hasError()) { // Read next element. QXmlStreamReader::TokenType token = xml.readNext(); // If token is just StartDocument, we'll go to next. if(token == QXmlStreamReader::StartDocument) continue; // If token is StartElement, we'll see if we can read it. if(token == QXmlStreamReader::StartElement) { // If it's named taches, we'll go to the next. if(xml.name() == "taches") continue; // If it's named tache, we'll dig the information from there. if(xml.name() == "tacheunitaire") { ajouterTache(TacheUnitaire::getFromXml(xml)); }else if(xml.name() == "tachecomposite") { ajouterTache(TacheComposite::getFromXml(xml)); } } } // Error handling. if(xml.hasError()) { throw CalendarException("Erreur lecteur fichier taches, parser xml"); } // Removes any device() or data from the reader * and resets its internal state to the initial state. xml.clear(); //qDebug()<<"fin load\n"; }
Projet *ProjetManager::ajouterProjet(const QString& identificateur, const QString& ti, const QDate &dispo, const QDate &deadline) { //Si le projet existe déjà if (ProjetManager::getInstance().isProjetExistant(identificateur)){ throw CalendarException("erreur ProjetManager : projet id déjà existant"); return 0; } Projet *p = new Projet(identificateur, ti, dispo, deadline); projets.push_back(p); return p; }
Scheduling::Scheduling(QDateTime date,QTime duration,UniqueTask *task): m_date(date),m_duration(duration) { if(date < QDateTime::currentDateTime()) { throw CalendarException("La date de la programmation est déjà passée !"); } m_task=task; m_title=m_task->getTitle(); // Il faudra voir si on réduit la durée de task ici ou si on le fait ailleurs, dans l'agenda }
void Agenda::supprimerProgrammation(const QDate & d, const QTime & h) { std::list<Programmation *>::iterator it ; for(it = programmations.begin(); it != programmations.end() ; ++it) if ( (*it)->getDate() == d && (*it)->getDebut() == h ) { delete (*it); programmations.erase(it); return ; } throw CalendarException("La programmation que vous voulez supprimer n'existe pas"); }
Tache *ProjetManager::ajouterTache(const QString & id_projet, const QString & id, const QString & titre, const QDate & dispo, const QDate & deadline, const Duree & dur, const bool & pre) { if (this->trouverTache(id)) { throw CalendarException("Erreur AjouterTache : l'id de la tache existe déjà"); } Projet * p = this->trouverProjet(id_projet); if ( p == 0 ) { throw CalendarException("Erreur AjouterTache : l'id_projet n'existe pas"); } Tache * t = 0; if(dur.getDureeEnMinutes() != 0 ) { // si une durée est fixée, la tâche est unitaire if (pre) { t = new TachePreemptable(id,titre,dispo,deadline,dur); } else { t= new TacheNonPreemptable(id, titre, dispo, deadline, dur); } } else { t = new TacheComposite(id,titre,dispo,deadline); } p->ajouterTache(*t); return t; }
void Agenda::ajouterProgrammation(const QString & nomDeLEventClassique, const QDate & d, const QTime & h, const Duree duree) { EvenementClassique & evt = *(new EvenementClassique(duree, nomDeLEventClassique) ); int minute_fin = h.minute() + duree.getMinute(); int heure_fin = h.hour() + duree.getHeure() + (minute_fin / 60) ; minute_fin = minute_fin % 60; if ( !QTime::isValid(heure_fin, minute_fin, 0) ) { throw CalendarException("erreur ajouterProgrammation : une programmation ne peut pas être à cheval sur deux jours"); } ajouterProgrammation(evt, d, h, *(new QTime(heure_fin, minute_fin)) ); }
void DeprogTache::EnregistrerDeprogTache(){ if(ProjetManager::getInstance().isTacheExistante(ui->comboBoxTache->currentText())){ TacheUnitaire* t = dynamic_cast<TacheUnitaire*>(ProjetManager::getInstance().trouverProjet(ui->comboBoxProjet->currentText())->trouverTache(ui->comboBoxTache->currentText())); try { if(ui->radioButtonTot->isChecked() || ui->radioButtonPart->isChecked()){ MessageValidation confirmation(QString("Attention"), QString("Si des tâches sont précédées par "+ui->comboBoxTache->currentText()+" elles seront déprogrammées en cascade.")); int sur = confirmation.exec(); if (sur == QMessageBox::Yes) { if (ui->radioButtonTot->isChecked()) { ProgrammationManager::getInstance().deprogrammationTotale(t); MessageValidation mv(QString("Succès"), QString("La Tâche "+ui->comboBoxTache->currentText()+" a été déprogrammée avec succès")); int rep = mv.exec(); if (rep == QMessageBox::No) close(); else { //Si l'utilisateur veut déprogrammer une nouvelle programmation remplirComboTache(ui->comboBoxProjet->currentText()); //On actualise les tâches disponibles à la programamtion ui->radioButtonTot->setChecked(false); } } else { QString prog=ui->listProgrammation->currentItem()->text(); QDateTime dt=QDateTime::fromString(prog,"dddd d MMMM yyyy H:m").toLocalTime(); /*if (dt<QDateTime::currentDateTime()) throw CalendarException("Impossible d'annuler une programmation dans le passé");*/ ProgrammationManager::getInstance().deprogrammationPartielle(t,dt); MessageValidation mv(QString("Succès"), QString("La programmation de la tâche "+ui->comboBoxTache->currentText()+" a été retirée avec succès")); int rep = mv.exec(); if (rep == QMessageBox::No) close(); else { //Si l'utilisateur veut déprogrammer une nouvelle programmation remplirComboTache(ui->comboBoxProjet->currentText()); //On actualise les tâches disponibles à la programamtion ui->radioButtonPart->setChecked(false); } } } } else throw CalendarException("Choississez le type de déprogrammation"); } catch(CalendarException e){ QMessageBox::warning(this, "Erreur", e.getInfo()); } } else QMessageBox::warning(this, "Programmation", "Veuillez séléctionner une tâche"); }
void Projet::save(const QString &f) { QFile newfile(f); if (!newfile.open(QIODevice::WriteOnly | QIODevice::Text)) throw CalendarException(QString("erreur sauvegarde tâches : ouverture fichier xml")); QXmlStreamWriter stream(&newfile); stream.setAutoFormatting(true); stream.writeStartDocument(); stream.writeStartElement("taches"); for(iterator it = begin() ; it!= end(); ++it) { (*it).toXml(stream); } stream.writeEndElement(); newfile.close(); }