void MainWindow::displayEvents(QDate debut, QDate fin) { this->current_debut = debut; this->current_fin = fin; QColor color(130,130,255); agenda_widget->clearContents(); if (this->em) { qDebug()<<"Mise à jour des events de la vue de la fenêtre principale"; vector<Evenement*> v = em->getFromPeriod(debut,fin); Evenement* ev; for (vector<Evenement*>::const_iterator it = v.begin(); it != v.end(); ++it) { color.setRgb(((color.red()+rand())%150)+106,((color.green()+rand())%150)+106,((color.blue()+rand())%150)+106); // que des couleurs claires ev = *it; int start_colonne = debut.daysTo(ev->getDateDebut()); int end_colonne = debut.daysTo(ev->getDateFin()); int start_ligne = ev->getHeureDebut().hour(); int end_ligne = ev->getHeureFin().hour()-1; int i = start_colonne>=0?start_colonne:0; int i_end = end_colonne<=6?end_colonne:agenda_widget->columnCount()-1; int j = start_colonne>=0?start_ligne:0; int j_end = end_colonne<=6?end_ligne:agenda_widget->rowCount()-1; int k = j; for (i;i<=i_end;i++) { for (k; k<agenda_widget->rowCount()&&(i!=i_end||k<=j_end); k++) { //qDebug()<<"i:"<<i<<"\t k:"<<k; QTableWidgetItem* item; if ((item = agenda_widget->item(k,i)) == nullptr) { agenda_widget->setItem(k,i, new QTableWidgetItem(ev->getTitre())); agenda_widget->item(k,i)->setBackgroundColor(color); //agenda_widget->item(k,i)->setFlags(agenda_widget->item(k,i)->flags() ^ Qt::ItemIsEditable); } else { item->setText(item->text()+" ; "+ev->getTitre()); QColor tmp = item->backgroundColor(); tmp.setRgb((tmp.red()+color.red())/2,(tmp.green()+color.green())/2,(tmp.blue()+color.blue())/2); item->setBackgroundColor(tmp); } } k = 0; } } } }
void MainWindow::exportXML(Projet* p) { vector<Evenement*> events; if (p) { qDebug()<<"Export depuis un projet"; events = em->getFromProjet(p); } else events = em->getFromPeriod(this->current_debut,this->current_fin); QString filename = QFileDialog::getSaveFileName(this,"Exporter la semaine en XML",QDir::homePath(), "XML files (*.xml)"); if (filename != "") { QFile newfile(filename); if (!newfile.open(QIODevice::WriteOnly | QIODevice::Text)) { showError("Project Calendar", "Impossible d'ouvrir le fichier de destination"); return; } QXmlStreamWriter stream(&newfile); stream.setAutoFormatting(true); stream.writeStartDocument(); stream.writeStartElement("evenements"); for (vector<Evenement*>::const_iterator it = events.begin(); it != events.end(); ++it){ Evenement* ev = *it; stream.writeStartElement("evenement"); stream.writeAttribute("id", (QString::number(ev->getId()))); stream.writeTextElement("titre",ev->getTitre()); stream.writeTextElement("description",ev->getDescription()); stream.writeTextElement("lieu",ev->getLieu()); stream.writeStartElement("debut"); stream.writeTextElement("jour",ev->getDateDebut().toString("yyyy-MM-dd")); stream.writeTextElement("heure",ev->getHeureDebut().toString("hh:mm")); stream.writeEndElement(); stream.writeStartElement("fin"); stream.writeTextElement("jour",ev->getDateFin().toString("yyyy-MM-dd")); stream.writeTextElement("heure",ev->getHeureFin().toString("hh:mm")); stream.writeEndElement(); stream.writeEndElement(); } stream.writeEndElement(); stream.writeEndDocument(); newfile.close(); QMessageBox::information(this, "Project Calendar", "Exporté !"); } else showError("Project Calendar", "Opération annulée"); }
bool operator ==(const Evenement& e1, const Evenement& e2){ return(e1.getDate()==e2.getDate() && e1.getEcheance()==e2.getEcheance() && e1.getId()==e2.getId() && e1.getTitre()==e2.getTitre()); }