Example #1
0
Programmation& Agenda::ajouterProg(Evenement* e, const QDateTime& d, const Horaire& h){
    if (trouverProgrammation(e)) throw AgendaException("erreur, tache deja existante dans le projet");
    if (e->getDate()<d && d<e->getEcheance()){
        if(e->getStatus()==false){
            //on vérifie qu'une tache precédente n'est pas programmée avant la tache qu'on programme
            if (e->withPrecedence()){ //Si l'événement a des precedences
                for(precedences_iterator it = e->begin_precedences() ; it != e->end_precedences() ; ++it){
                    if((*it)->getStatus()){//Si la précédence est programmée
                        //On vérifie la cohérence des dates
                        Programmation* prog = trouverProgrammation(*it);
                        if(prog->getDate() > d)
                            throw AgendaException("Impossible de programmer une tache avant de ses tâches précédentes");
                        else if (prog->getDate() == d && h < prog->getHoraire())
                            throw AgendaException("Impossible de programmer une tache avant de ses tâches précédentes");
                    }
                }
            }
            //L'événement n'est pas encore programmé et la date choisie est cohérente avec ses taches précédentes.
            //On peut créer la programmation
            Programmation* newt=new Programmation(d,h,e);
            e->setEstProg(true);
            addItem(newt);
            return *newt;
        }else throw AgendaException("l'evenement est déjà programmé");
    }else throw AgendaException("erreur les dates ne concordent pas");
};
Example #2
0
void Tache::ajouterPrecedence(Tache *pred)throw(AgendaException)
{
    int id = pred->getId();
    if(!this->estPredecence(id))
       if(!pred->estPredecence(this->id))
           precedence.push_back(pred);
       else throw AgendaException("Impossible d'avoir des précédences mutuelles");
    else throw AgendaException("Précédence déjà existante");

}
Example #3
0
ProgActivite::ProgActivite(const int id, const QDate& d, const QTime& dur, const QTime &h, Activite* p)throw(AgendaException)
    :Programmation(id,d,dur,h),programme(p)
{
   if(p->getDate() != d)
       throw AgendaException("L'activite ne peut pas être programmée avec ces dates !");
   if(p->getDuree() != dur)
       throw AgendaException("L'activite ne peut pas être programmée avec ces durées !");
   if(d < QDate::currentDate())
       throw AgendaException("Une programmation ne peut pas commencer dans le passé !");
   if(d == QDate::currentDate() && h < QTime::currentTime())
       throw AgendaException("Une programmation ne peut pas commencer dans le passé !");
   setType(PROGACTIVITE);
}
Example #4
0
void Projet::ajouterTache(Tache *t)throw(AgendaException)
{
    //On vérifie qu'on ajoute une tache non présente dans le projet
    int id = t->getId();
    qDebug() << "id de la tache a ajouter" << id;
    QList<Tache*>::iterator it = taches.begin();
    bool ok=true;
    while(it!=taches.end() && ok)
    {
        qDebug() << "id testé " << (*it)->getId();
        ok = id!=(*it)->getId();
        ++it;
    }
    if(ok) ok = t->getDateDispo() >= this->dateDispo && t->getEcheance() <= this->dateEcheance;
    else throw AgendaException("La tâche est déjà dans le projet");
    if(ok) taches.push_back(t);
    else throw AgendaException("La tâche a des dates incompatibles avec le projet");
}
Example #5
0
void Agenda::supprimerProg(Evenement* e)
{
    vector<Programmation*>::iterator it = trouverProgrammationIterator(e);
    if(it != progs.end()) {
        progs.erase(it);
        e->setEstProg(false);
        return;
    }
    throw AgendaException("Prog inexistante");

}
Example #6
0
void Projet::setDateEcheance(QDate &d)throw(AgendaException)
{
    QList<Tache*>::iterator it = taches.begin();
    bool ok=true;
    while(it !=taches.end() && ok)
    {
        ok = d <= (*it)->getEcheance();
        ++it;
    }
    if(!ok)throw AgendaException("Impossible: des taches terminent plus tôt que la nouvelle date");
    dateEcheance = d;
}
Example #7
0
void Projet::setDateDispo(QDate &d)throw(AgendaException)
{
    QList<Tache*>::iterator it = taches.begin();
    bool ok=true;
    while(it!=taches.end() && ok)
    {
        ok = d >=(*it)->getDateDispo();
        ++it;
    }
    if(!ok)throw AgendaException("Impossible: des taches commencent plus tard que la nouvelle date");
    dateDispo = d;
}
Tache* AjouteurTachePreemptive::construire(QMap<QString, QVariant> &params)const throw(AgendaException)
{
    int id;
    QString titre;
    QDate dispo;
    QDate deadline;
    QTime duree;
    //On vérifie que les paramètres passés correspondent bien à une tache composite
    if(verifTypes(params.keys()))
    {
        //On récup les param de la tâche
        id = params["id"].toInt();
        titre = params["titre"].toString();
        dispo = params["dispo"].toDate();
        deadline = params["deadline"].toDate();
        duree = params["dur"].toTime();
    }
    else throw AgendaException("Paramètre passés invalides");
    return new TachePreemptive(id,titre,dispo,deadline,duree);
}
Example #9
0
Programmation::Programmation(const int id, const QDate &d, const QTime &dur, const QTime &h):id(id),date(d),duree(dur),horaire(h)
{
   ProgManager::Iterator it = ProgManager::getInstance()->getIterator();
   int jour = d.day();
   /*int debut = h.hour();
   int fin = debut + dur.hour();*/
   QTime debut=h;
   QTime fin;
   fin.setHMS(h.hour()+dur.hour(),h.minute()+dur.minute(),h.second()+dur.second());
   /*bool commencePendant=false;
   bool terminePendant=false;*/
   bool horaireinvalide=false;
   bool memeJour=false;
   while(it.courant() != ProgManager::getInstance()->end())
   {
       Programmation *p = it.valeur();
       /*int pH = p->getHoraire().hour();
       int pFin = pH + p->getDuree().hour();*/
       int pJour = it.valeur()->getDate().day();
     /*  commencePendant = (debut >= pH && debut <= pFin); //On autorise qu'un evenement se finisse à une heure h et qu'un autre commence tout de suite après
       terminePendant = (fin >= pH && fin <= pFin);*/
       QTime pDeb=p->getHoraire();
       QTime pFin;
       pFin.setHMS(p->getHoraire().hour()+p->getDuree().hour(),p->getHoraire().minute()+p->getDuree().minute(),p->getHoraire().second()+p->getDuree().second());
       /*commencePendant= (debut>=pDeb && debut<pFin);
       terminePendant= (fin>pDeb && fin<=pFin);*/
       horaireinvalide=(debut<=pDeb && fin>=pFin)
               || (debut<=pDeb && (fin<=pFin && fin>pDeb))
               || ((debut>=pDeb && debut<pFin) && fin>=pFin)
               || ((debut>=pDeb && debut<pFin) && (fin>=pDeb && fin<=pFin));
       memeJour = jour == pJour;
       if( memeJour && horaireinvalide)
               throw AgendaException("Une programmation occupe déjà une partie de cette plage horaire");
       it.next();
   }
}
Example #10
0
void ProgActivite::setDuree(const QTime &d)throw(AgendaException)
{
    if(d > this->programme->getDuree())
        throw AgendaException("Impossible d'avoir une programmation plus longue que la durée de l'activite");
}
Example #11
0
void ProgActivite::setDate(const QDate &d)throw(AgendaException)
{
    if(d > this->programme->getDate())
        throw AgendaException("Impossible de programmer une activite à une autre date que celle voulue");
    date=d;
}
Example #12
0
void ExportXML::save(const QString& f){
    //file=f;
    ProjetManager& PM = ProjetManager::getInstance();
    Agenda& A = Agenda::getInstance();
    QFile newfile(f);
    if (!newfile.open(QIODevice::WriteOnly | QIODevice::Text))
        throw AgendaException(QString("erreur sauvegarde tâches : ouverture fichier xml"));
    QXmlStreamWriter stream(&newfile);
    stream.setAutoFormatting(true);
    stream.writeStartDocument();
    stream.writeStartElement("projectcalendar");
    //Liste des projets dans la balise <projets>
    stream.writeStartElement("projets");
    for(ProjetManager::projets_iterator it1 = PM.begin_projets() ; it1 != PM.end_projets() ; ++it1){
        //chaque projet est dans une balise <projet>
        stream.writeStartElement("projet");
        stream.writeTextElement("identificateur",(*it1)->getId());
        stream.writeTextElement("titre",(*it1)->getTitre());
        stream.writeTextElement("description",(*it1)->getDesc());
        stream.writeTextElement("disponibilite",(*it1)->getDispo().toString(Qt::ISODate));
        stream.writeTextElement("echeance",(*it1)->getEcheance().toString(Qt::ISODate));
        //Liste des taches du projet et de leurs programmations dans une balise <taches>
        stream.writeStartElement("taches");
        for(Projet::taches_iterator it2 = (*it1)->begin_taches() ; it2 != (*it1)->end_taches() ; ++it2){
            //Chaque tache dans une balise <tache>
            stream.writeStartElement("tache");
            //Met l'attribut preemptive à true si tache préemptable, false sinon
            if (typeid(**it2) == typeid(TachePreemptable))
                stream.writeAttribute("preemptive", "true");
            else
                stream.writeAttribute("preemptive", "false");
            //Met l'attribut composite à true si tache composite, false sinon
            if (typeid(**it2) == typeid(TacheComposite))
                stream.writeAttribute("composite", "true");
            else
                stream.writeAttribute("composite", "false");
            //Met l'attribut unitaire à true si tache unitaire, false sinon
            if (typeid(**it2) == typeid(TacheUnitaire))
                stream.writeAttribute("unitaire", "true");
            else
                stream.writeAttribute("unitaire", "false");

            stream.writeTextElement("identificateur",(*it2)->getId());
            stream.writeTextElement("titre",(*it2)->getTitre());
            stream.writeTextElement("disponibilite",(*it2)->getDate().toString(Qt::ISODate));
            stream.writeTextElement("echeance",(*it2)->getEcheance().toString(Qt::ISODate));
            //Durée uniquement si tache unitaire
            if ((typeid(**it2) ==  typeid(TacheUnitaire)) || (typeid(**it2) == typeid(TachePreemptable))){
                QString str;
                str.setNum((*it2)->getDuree().getDureeEnMinutes());
                stream.writeTextElement("duree",str);
            }

            //Programmation si la tâche est programmée
            if ((*it2)->getStatus()){ // La Tache est programmée nous écrivons ici sa programmation
                Programmation* prog = A.trouverProgrammation(*it2);
                if (prog){
                    stream.writeStartElement("programmation");
                    stream.writeTextElement("date",prog->getDate().toString(Qt::ISODate));
                    stream.writeTextElement("heure", prog->getHoraire().toString());
                    stream.writeEndElement(); // Fin <programmation>
                }
            }

            stream.writeEndElement();// Fin <tache>
        }
        stream.writeEndElement(); // Fin <taches>
        stream.writeEndElement(); // Fin <projet>
    }
    stream.writeEndElement(); // Fin <projets>

    //Liste des précédences de Taches dans la balise <precedences>
    stream.writeStartElement("precedences");
    for(ProjetManager::projets_iterator it1 = PM.begin_projets() ; it1 != PM.end_projets() ; ++it1){ //Itération sur les projets
        for(Projet::taches_iterator it2 = (*it1)->begin_taches() ; it2 != (*it1)->end_taches() ; ++it2){ //Itération sur les taches du projet
            if ((*it2)->withPrecedence()){ //La tache a des contraintes de precedence
                stream.writeStartElement("precedence");
                stream.writeAttribute("id_projet", (*it1)->getId());
                stream.writeAttribute("id_tache", (*it2)->getId());
                for(precedences_iterator it3 = (*it2)->begin_precedences() ; it3 != (*it2)->end_precedences() ; ++it3) //Pour chaque tache, itération sur les taches précédentes
                    stream.writeTextElement("id_precedence", (*it3)->getId());
                stream.writeEndElement(); // Fin <precedence>
            }
        }
    }
    stream.writeEndElement(); // Fin <precedences>

    //Liste des composants pour les taches compositees
    stream.writeStartElement("composites");
    for(ProjetManager::projets_iterator it1 = PM.begin_projets() ; it1 != PM.end_projets() ; ++it1){ //Itération sur les projets
        for(Projet::taches_iterator it2 = (*it1)->begin_taches() ; it2 != (*it1)->end_taches() ; ++it2){ //Itération sur les taches du projet
            if (typeid(**it2) == typeid(TacheComposite)){
                soustaches_iterator it3 = (*it2)->begin_soustaches();
                if (it3 != (*it2)->end_soustaches()) { //on teste si la tache a des taches composants
                    stream.writeStartElement("composite");
                    stream.writeAttribute("id_projet", (*it1)->getId());
                    stream.writeAttribute("id_tache", (*it2)->getId());
                    for(it3 = (*it2)->begin_soustaches() ; it3 != (*it2)->end_soustaches() ; ++it3) //Pour chaque tache, itération sur les sous taches
                        stream.writeTextElement("id_composant", (*it3)->getId());
                    stream.writeEndElement(); // Fin <composite>
                }
            }
        }
    }
    stream.writeEndElement(); // Fin <composites>

    //Liste des activités et de leurs programmations
    stream.writeStartElement("activites");
    ActiviteManager& AM = ActiviteManager::getInstance();
    for(ActiviteManager::activites_iterator it1 = AM.begin_activites() ; it1 != AM.end_activites() ; ++it1){
        stream.writeStartElement("activite");
        //Met l'attribut reunion à true si c'est une reunion, false sinon
        if (typeid(**it1) == typeid(Reunion))
            stream.writeAttribute("reunion", "true");
        else
            stream.writeAttribute("reunion", "false");
        //Met l'attribut rdv à true si c'est un rdv, false sinon
        if (typeid(**it1) == typeid(Rdv))
            stream.writeAttribute("rdv", "true");
        else
            stream.writeAttribute("rdv", "false");
        stream.writeTextElement("identificateur",(*it1)->getId());
        stream.writeTextElement("titre",(*it1)->getTitre());
        stream.writeTextElement("disponibilite",(*it1)->getDate().toString(Qt::ISODate));
        stream.writeTextElement("echeance",(*it1)->getEcheance().toString(Qt::ISODate));
        QString str;
        str.setNum((*it1)->getDuree().getDureeEnMinutes());
        stream.writeTextElement("duree",str);
        stream.writeTextElement("lieu",(*it1)->getLieu());
        if (typeid(**it1) == typeid(Reunion)){ // C'est un réunion, on ajoute la liste des participants
            stream.writeStartElement("participants");
            //for(int i = 0 ; i < (*it1)->getNbParticipants() ; i++){
            for(participants_iterator it2 = (*it1)->begin_participants() ; it2 != (*it1)->end_participants() ; ++it2){
                stream.writeTextElement("participant",*it2);
            }
            stream.writeEndElement();// Fin <participants
        }
        if (typeid(**it1) == typeid(Rdv)){ //C'est un rdv, on ajoute l'interlocuteur du rdv
            stream.writeTextElement("interlocuteur", (*it1)->getInterlocuteur());
        }
        //Programmation si l'activité est programmée
        if ((*it1)->getStatus()){ // L'a Tache 'activité est programmée nous écrivons ici sa programmation
            Programmation* prog = A.trouverProgrammation(*it1);
            if (prog){
                stream.writeStartElement("programmation");
                stream.writeTextElement("date",prog->getDate().toString(Qt::ISODate));
                stream.writeTextElement("heure", prog->getHoraire().toString());
                stream.writeEndElement(); // Fin <programmation>
            }
        }
        stream.writeEndElement(); // Fin <activite>
    }
    stream.writeEndElement(); // Fin <activites>
    stream.writeEndElement(); // Fin <projectcalendar>
    stream.writeEndDocument();
    newfile.close();
}
Example #13
0
Projet::Projet(int id, QString &t, QDate &dispo, QDate &echeance):id(id),titre(t),dateDispo(dispo),dateEcheance(echeance)
{
    if(dispo > echeance)throw AgendaException("Un projet doit se finir après avoir commencé !");
}