Пример #1
0
Evenement1j* Evenement1j::getFromXml(QXmlStreamReader& xml)
{
    QDate date;
    QTime horaire;
    Duree duree;
    QString sujet;
    //construction de l'objet en lisant le xml
    while(!(xml.tokenType() == QXmlStreamReader::EndElement && xml.name() == "evenement1j")){
        if(xml.tokenType() == QXmlStreamReader::StartElement)
        {
            if(xml.name() == "date") {
                xml.readNext();
                date = QDate::fromString(xml.text().toString(),Qt::ISODate);
            }
            if(xml.name() == "horaire") {
                xml.readNext();
                horaire = QTime::fromString(xml.text().toString(),Qt::ISODate);
            }
            if(xml.name() == "sujet") {
                xml.readNext();
                sujet=xml.text().toString();
            }
            if(xml.name() == "duree") {
                xml.readNext();
                duree.setDuree(xml.text().toString().toUInt());
            }
        }
        xml.readNext();
    }
    Evenement1j *evt = new Evenement1j(date,horaire,duree,sujet);
    return evt;
}
Пример #2
0
Rdv* Rdv::getFromXml(QXmlStreamReader& xml)
{
    QDate date;
    QTime horaire;
    Duree duree;
    QString sujet;
    QString lieu;

    //construction de l'objet a partir des donnees xml
    while(!(xml.tokenType() == QXmlStreamReader::StartElement && xml.name() == "personnes")){
        if(xml.tokenType() == QXmlStreamReader::StartElement)
        {
            if(xml.name() == "date") {
                xml.readNext();
                date = QDate::fromString(xml.text().toString(),Qt::ISODate);
            }
            if(xml.name() == "horaire") {
                xml.readNext();
                horaire = QTime::fromString(xml.text().toString(),Qt::ISODate);
            }
            if(xml.name() == "sujet") {
                xml.readNext();
                sujet=xml.text().toString();
            }
            if(xml.name() == "lieu") {
                xml.readNext();
                lieu=xml.text().toString();
            }
            if(xml.name() == "duree") {
                xml.readNext();
                duree.setDuree(xml.text().toString().toUInt());
            }
        }
        xml.readNext();
    }
    //creation du rdv
    Rdv *evt = new Rdv(date,horaire,duree,sujet,lieu);
    xml.readNext();
    // ajout des participants au Rdv
    while(!(xml.tokenType() == QXmlStreamReader::EndElement && xml.name() == "personnes")){
        QString personne;
        if(xml.tokenType() == QXmlStreamReader::StartElement)
        {
            if(xml.name() == "personne") {
                xml.readNext();
                personne = xml.text().toString();
                evt->ajouterPersonne(personne);
            }
        }
        xml.readNext();
    }
    xml.readNext();

    return evt;
}
Пример #3
0
//au niveau des fichiers
void Manager::load(const QString& f){
    //qDebug()<<"debut load\n";
    this->~Manager();
    file = f;
    QFile fin(file);
    // If we can't open it, let's show an error message.
    if (!fin.open(QIODevice::ReadOnly | QIODevice::Text)) {
        throw TimeException("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() == "tache") {
                qDebug() << "new tache\n";
                QString titre;
                QDate disponibilite;
                QDate echeance;
                Duree duree;
                bool preemptive;

                QXmlStreamAttributes attributes = xml.attributes();
                /* Let's check that Task has attribute. */
                if (attributes.hasAttribute("preemptive")) {
                    QString val = attributes.value("preemptive").toString();
                    preemptive = (val == "true" ? true : false);
                }
                //qDebug()<<"preemptive="<<preemptive<<"\n";

                xml.readNext();
                //We're going to loop over the things because the order might change.
                //We'll continue the loop until we hit an EndElement named tache.


                while (!(xml.tokenType() == QXmlStreamReader::EndElement && xml.name() == "tache")) {
                    if (xml.tokenType() == QXmlStreamReader::StartElement) {
                        // We've found titre.
                        if (xml.name() == "titre") {
                            xml.readNext(); titre = xml.text().toString();
                            //qDebug()<<"titre="<<titre<<"\n";
                        }
                        // We've found disponibilite
                        if (xml.name() == "disponibilite") {
                            xml.readNext();
                            disponibilite = QDate::fromString(xml.text().toString(), Qt::ISODate);
                            //qDebug()<<"disp="<<disponibilite.toString()<<"\n";
                        }
                        // We've found echeance
                        if (xml.name() == "echeance") {
                            xml.readNext();
                            echeance = QDate::fromString(xml.text().toString(), Qt::ISODate);
                            //qDebug()<<"echeance="<<echeance.toString()<<"\n";
                        }
                        // We've found duree
                        if (xml.name() == "duree") {
                            xml.readNext();
                            duree.setDuree(xml.text().toString().toUInt());
                            //qDebug()<<"duree="<<duree.getDureeEnMinutes()<<"\n";
                        }
                    }
                    // ...and next...
                    xml.readNext();
                }
                //qDebug()<<"ajout tache "<<identificateur<<"\n";
                creerT(titre,disponibilite, echeance);

            }
        }
    }
    // Error handling.
    if (xml.hasError()) {
        throw TimeException("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";
}