Пример #1
0
void PublicTalks::beforePublicTalkComboBoxShown(int rownumber)
{
    // themes combobox
    cPersonComboBox *c = static_cast<cPersonComboBox *>(maintable->cellWidget(rownumber,2));
    cPersonComboBox *speakerCombo = static_cast<cPersonComboBox *>(maintable->cellWidget(rownumber,3));

    QString currentThemeText = c->currentText();
    QTableWidget *table;
    cpersons cp;
    person *speaker = cp.getPerson(speakerCombo->currentText());
    if (speaker) {
        // the speaker selected --> will be shown speaker's themes
        table = this->getSpeakerPublicTalks(0,speaker->id, currentThemeText);
    } else {
        // no speaker selected  --> all themes will be shown
        table = this->getPublicTalksbyLang(currentThemeText);
    }

    //    schoolComboBox *sc = static_cast<schoolComboBox *>(ui->tableSchoolEdit->cellWidget(row,col));
    qDebug() << QString::number(table->rowCount());
    table->setSortingEnabled(true);
    table->sortByColumn(0,Qt::AscendingOrder);
    table->verticalHeader()->hide();
    table->setColumnWidth(0,40);
    table->setColumnWidth(1,200);
    table->setColumnWidth(2,80);
    table->setMinimumWidth(340);
    c->clear();
    c->setModel(table->model());
    c->setView(table);
    c->setModelColumn(1);

    c->setCurrentIndex(c->findText(currentThemeText,Qt::MatchExactly));
}
Пример #2
0
QTableWidget *PublicTalks::getPersons(int type)
{
    std::vector<sql_item> vt;
//    QString str = "SELECT yleisokokous.pvm, henkilot.nimi, henkilot.id, henkilot.etunimi "
//                  "FROM henkilot LEFT JOIN yleisokokous ON henkilot.id = yleisokokous.puheenjohtaja_id "
//                  "WHERE ohjelmatyypit & " + QString::number(type) + " GROUP BY henkilot.id";
    QString str = "SELECT yleisokokous.pvm, henkilot.nimi, henkilot.id, henkilot.etunimi "
                  "FROM henkilot LEFT JOIN yleisokokous ON henkilot.id = yleisokokous.";
    if(type == person::chairman) {
        str.append("puheenjohtaja_id");
    } else {
        str.append("vt_lukija_id");
    }
    str.append(" WHERE ohjelmatyypit & " + QString::number(type) + " GROUP BY henkilot.id");

    vt = sql.selectSql(str);

    QTableWidget *vttable = new QTableWidget();
    vttable->horizontalHeader()->show();
    vttable->verticalHeader()->setVisible(false);
    vttable->setColumnCount(3);
    vttable->setColumnHidden(0,true);
    vttable->setColumnWidth(1,150);
    vttable->setColumnWidth(2,100);
    vttable->setMinimumWidth(270);
    vttable->setSortingEnabled(true);

    vttable->setHorizontalHeaderItem(1,new QTableWidgetItem(QObject::tr("Name")));
    vttable->setHorizontalHeaderItem(2,new QTableWidgetItem(QObject::tr("Last")));

    vttable->setRowCount(vt.size()+1);
    vttable->setItem(0,0,new QTableWidgetItem(""));
    for(unsigned int i = 0; i < vt.size(); i++) {
        vttable->setItem(i+1,0,new QTableWidgetItem(vt[i].getValue("id")));
        vttable->setItem(i+1,1,new QTableWidgetItem(vt[i].getValue("nimi") + " " + vt[i].getValue("etunimi")));
        vttable->setItem(i+1,2,new QTableWidgetItem(vt[i].getValue("pvm")));
    }
    return vttable;
}
Пример #3
0
void PublicTalks::beforeSpeakerShown(QString name, cPersonComboBox *c)
{
    //cPersonComboBox *c = combo;

    // get speakers for comboBox
    //cPersonComboBox *combo = static_cast<cPersonComboBox *>(maintable->cellWidget(combo->property("currentrow").toInt(),3));
    cPersonComboBox *themeCombo = static_cast<cPersonComboBox *>(maintable->cellWidget(c->property("currentrow").toInt(),2));
    qDebug() << "currentRow1:" << c->currentText() << "rownumber:" << c->property("currentrow") << name;
    if (c) {
        qDebug() << "combo ok";
    } else {
        qDebug() << "combo false";
    }

    QTableWidget *table = new QTableWidget(0,4);
    table->setColumnHidden(0,true);
    table->setColumnWidth(3,0);
    std::vector<sql_item> speakers;
    if(themeCombo->currentText() == "") {
        // ei teemaa valittu
        speakers = sql.selectSql("SELECT henkilot.*,yleisokokous.pvm "
                                 "FROM henkilot "
                                 "LEFT JOIN yleisokokous ON henkilot.id = yleisokokous.puhuja_id "
                                 "WHERE henkilot.ohjelmatyypit & 512 GROUP BY henkilot.id ORDER BY nimi");
    } else {
        // teema valittu --> haetaan teeman sopivat puhujat
        speakers = sql.selectSql("SELECT henkilot.*,P_Esitelmat.aihe_id,yleisokokous.pvm "
                                 "FROM henkilot "
                                 "LEFT JOIN P_Esitelmat ON henkilot.id = P_Esitelmat.puhuja_id "
                                 "LEFT JOIN yleisokokous ON henkilot.id = yleisokokous.puhuja_id "
                                 " WHERE P_Esitelmat.aihe_id = '" +
                                 QString::number(getThemeId(themeCombo->currentText())) +
                                 "' AND henkilot.ohjelmatyypit & 512 GROUP BY henkilot.id ORDER BY nimi, etunimi");
    }
    table->setRowCount(speakers.size()+1);
    int currentRow = 0;
    for(unsigned int i = 0; i < speakers.size(); i++) {
        table->setItem(i+1,0,new QTableWidgetItem( speakers[i].getValue("id") ));
        table->setItem(i+1,1,new QTableWidgetItem( speakers[i].getValue("nimi") + ", " + speakers[i].getValue("etunimi")) );
        table->setItem(i+1,2,new QTableWidgetItem( speakers[i].getValue("pvm")) );
        table->setItem(i+1,3,new QTableWidgetItem( speakers[i].getValue("etunimi") + " " + speakers[i].getValue("nimi")) );

        if(c->currentText() == table->item(i+1,3)->text()) {
            QFont boldfont(table->item(i+1,1)->font().family(),
                           table->item(i+1,1)->font().pointSize(),
                           QFont::Bold);
            table->item(i+1,1)->setFont(boldfont);
            currentRow = i+1;
        }
    }
    table->verticalHeader()->hide();
    table->setColumnWidth(1,150);
    table->setColumnWidth(2,100);
    table->setMinimumWidth(280);

    c->clear();
    c->setModel(table->model());
    c->setView(table);
    c->setModelColumn(1);
    c->setCurrentIndex(currentRow);
    table->setSortingEnabled(true);
    table->sortByColumn(1,Qt::AscendingOrder);
}
Пример #4
0
void FenPrincipale::calcul_general() {
	QString html = "<table>\n\t<thead>\n\t\t<tr>\n\t\t\t";
	html += "<td>"+tr("Position")+"</td>";
	html += "<td>"+tr("Équipage")+"</td>";
	html += "<td>"+tr("Points")+"</td>";
	for (int j = 0; j < this->nbManches; ++j) {
		html += "<td>"+tr("M")+QString::number(j+1)+"</td>";
	}
	html += "\n\t\t</tr>\n\t</thead>\n\t<tboby>";
	QTableWidget *table = new QTableWidget();
	table->verticalHeader()->hide();
	table->setSelectionMode(QAbstractItemView::NoSelection);
	table->setColumnCount(3+this->nbManches);
	table->setRowCount(this->nbEquipages);
	table->setColumnWidth(0, 80);
	table->setColumnWidth(1, 200);
	table->setColumnWidth(2, 60);
	int size = 80 + 200 + 60;
	QList<QString> labels;
	labels << tr("Position") << tr("Équipage") << tr("Points");
	for (int j = 0; j < this->nbManches; ++j) {
		labels << tr("M")+QString::number(j+1);
		size += 50;
		table->setColumnWidth(3+j, 50);
	}
	table->setMinimumWidth(size + 20);
	table->setMaximumWidth(size + 20);
	table->setHorizontalHeaderLabels(labels);
	ui->resultatsLayout->insertWidget(0, table);
	for (int i = 0; i < this->nbEquipages; ++i) {
		QList<int> ids;
		Equipage e1;
		for (int k = 0; k < this->nbEquipages; ++k) {
			Equipage e2 = this->equipages[k];
			if (e2.points <= 0) {
				// cet équipage a déjà été affiché
				continue;
			}
			if (ids.isEmpty() || e2.points < e1.points) {
				ids.clear();
				ids.append(k);
				e1 = e2;
			}
			else if (e2.points == e1.points) {
				// égalité de points
				// pour départager les équipages, on confronte leurs meilleures
				// manches (sans celles retirées)
				for (int j = 0; j < e1.pointsTries.size(); ++j) {
					if (e2.pointsTries[j] < e1.pointsTries[j]) {
						ids.clear();
						ids.append(k);
						e1 = e2;
						break;
					}
					else if (e2.pointsTries[j] > e1.pointsTries[j]) {
						break;
					}
					else if (j == e1.pointsTries.size()-1) {
						// égalité des manches
						// pour départager les équipages, on confronte toutes
						// leur manches dans l'ordre en partant de la dernière
						for (int l = 0; l < e1.pointsOrdonnes.size(); ++l) {
							if (e2.pointsOrdonnes[l] < e1.pointsOrdonnes[l]) {
								ids.clear();
								ids.append(k);
								e1 = e2;
								break;
							}
							else if (e2.pointsOrdonnes[l] > e1.pointsOrdonnes[l]) {
								break;
							}
							else if (l == e1.pointsOrdonnes.size()-1) {
								// égalité parfaite
								ids.append(k);
							}
						}
					}
				}
			}
		}
		for (int k = 0; k < ids.size(); ++k) {
			Equipage e = this->equipages[ids[k]];
			// on ajoute le début de la table html
			// on rajoute les manches en parallèle à causes de celles retirées
			QString nomString = "<span class=\"equipage\">"+e.nom+"</span>";
			if (this->typeClmt == CLMT_TEMPS) {
				nomString += "<span class=\"bateau\">"
					+this->bateaux.value(e.rating.toUpper()).serie
					+" ("+QString::number(e.coef)+")</span>";
			}
			html += "\n\t\t<tr>\n\t\t\t<td>"+QString::number(i+1)+"</td>"
				+"<td>"+nomString+"</td>"
				+"<td>"+QString::number(e.points)+"</td>";
			// on ajout l'équipage
			QLabel *pos = new QLabel(QString::number(i+1));
			QWidget *nomWidget = new QWidget();
			QVBoxLayout *nomLayout = new QVBoxLayout();
			QLabel *nom = new QLabel(e.nom);
			nom->setProperty("label", "nom");
			nomLayout->addWidget(nom);
			if (this->typeClmt == CLMT_TEMPS) {
				QLabel *bateau = new QLabel();
				bateau->setText(this->bateaux.value(e.rating.toUpper()).serie
					+" ("+QString::number(e.coef)+")");
				bateau->setProperty("label", "bateau");
				nomLayout->addWidget(bateau);
				table->setRowHeight(i+k, 45);
			}
			nomLayout->setContentsMargins(0, 0, 0, 0);
			nomLayout->setSpacing(0);
			nomWidget->setLayout(nomLayout);
			QLabel *points = new QLabel(QString::number(e.points));
			table->setCellWidget(i+k, 0, pos);
			table->setCellWidget(i+k, 1, nomWidget);
			table->setCellWidget(i+k, 2, points);
			for (int j = 0; j < this->nbManches; ++j) {
				Manche m = e.manches[j];
				QLabel *la = new QLabel();
				if (m.tpsCompense < 0) {
					la->setText(this->get_abr(m.abr));
				}
				else {
					la->setText(QString::number(m.points));
				}
				for (int l = 0; l < e.pointsRetires.size(); ++l) {
					if (e.pointsRetires[l] == m.points) {
						la->setText("("+la->text()+")");
						e.pointsRetires.removeAt(l);
						break;
					}
				}
				html += "<td>"+la->text()+"</td>";
				table->setCellWidget(i+k, j+3, la);
			}
			html += "\n\t\t</tr>";
			this->equipages[ids[k]].points = 0;
		}
		i += ids.size()-1;
	}
	html += "\n\t</tbody>\n</table>";
	this->htmls.prepend(html);
	this->progression(95);
}
Пример #5
0
void FenPrincipale::calcul_manches() {
	for (int j = 0;  j < this->nbManches; ++j) {
			// on initialise la table html pour l'export
		QString html = "<table>\n\t<thead>\n\t\t<tr>\n\t\t\t";
		html += "<td>"+tr("Place")+"</td>";
		html += "<td>"+tr("Équipage")+"</td>";
		html += "<td>"+tr("Points")+"</td>";
		if (this->typeClmt == CLMT_TEMPS) {
			html += "<td>"+tr("Temps réel")+"</td><td>"+tr("Temps compensé")+"</td>";
		}
		html += "\n\t\t</tr>\n\t</thead>\n\t<tboby>";
			// on affiche la table qui va contenir les résultats de la manche
		QTableWidget *table = new QTableWidget();
		table->verticalHeader()->hide();
		table->setSelectionMode(QAbstractItemView::NoSelection);
		table->setProperty("table", "manches");
		QList<QString> labels;
		labels << tr("Place") << tr("Équipage") << tr("Points");
		if (this->typeClmt == CLMT_TEMPS) {
			table->setColumnCount(5);
			labels << tr("Temps réel") << tr("Temps compensé");
			table->setMaximumWidth(560 + 20);
			table->setMinimumWidth(560 + 20);
			table->setColumnWidth(3, 120);
			table->setColumnWidth(4, 120);
		}
		else {
			table->setColumnCount(3);
			table->setMaximumWidth(320 + 20);
			table->setMinimumWidth(320 + 20);
		}
		table->setColumnWidth(0, 60);
		table->setColumnWidth(1, 200);
		table->setColumnWidth(2, 60);
		table->setHorizontalHeaderLabels(labels);
		table->setRowCount(this->nbEquipages);
		ui->choisirResultat->insertItem(j+1,
			tr("Résultats de la manche %1").arg(QString::number(j+1)));
		int nbAffiches = 0; // pour savoir à quelle ligne on en est
			// on traite et affiche les équipages
		// on traite chaque manche pour attribuer les points aux équipages
		for (int i = 0; i < this->nbEquipages; ++i) {
			// on recherche tous les équipages non encore traités pour cette
			// manches qui ont un tpsCompense minimal
			int min = 0;
			QList<int> ids;
			for (int k = 0; k < this->nbEquipages; ++k) {
				Manche m = this->equipages[k].manches[j];
				if (m.tpsCompense < 0 || m.points > 0 ) {
					// cet équipage a déjà été traité ou n'a pas de place/temps
					// (DNF, DNS, OCS, ...)
					continue;
				}
				if (m.tpsCompense < min || min == 0) {
					min = m.tpsCompense;
					ids.clear();
					ids.append(k);
				}
				else if (m.tpsCompense == min) {
					ids.append(k);
				}
			}
			if (min == 0) {
				// on n'a pas trouvé d'équipage à traiter (se produit s'il y a
				// des équipages DNS, DNF, OCS, ...)
				break;
			}
			for (int l = 0; l < ids.size(); ++l) {
				double points = (ids.size()-1.0)/2.0+i+1.0;
				this->equipages[ids.at(l)].points += points;
				this->equipages[ids.at(l)].pointsOrdonnes.prepend(points);
				this->equipages[ids.at(l)].pointsTries.append(points);
				this->equipages[ids.at(l)].manches[j].points = points;
				// on affiche ces équipages
				Equipage e = this->equipages[ids.at(l)];
				Manche m = e.manches[j];
				QLabel *place = new QLabel(QString::number(i+1));
				table->setCellWidget(i+l, 0, place);
				QWidget *nomWidget = new QWidget();
				QVBoxLayout *nomLayout = new QVBoxLayout();
				QLabel *nom = new QLabel(e.nom);
				nom->setProperty("label", "nom");
				nomLayout->addWidget(nom);
				if (this->typeClmt == CLMT_TEMPS) {
					QLabel *bateau = new QLabel();
					bateau->setText(this->bateaux.value(e.rating.toUpper()).serie
						+" ("+QString::number(e.coef)+")");
					bateau->setProperty("label", "bateau");
					nomLayout->addWidget(bateau);
					table->setRowHeight(i+l, 45);
				}
				nomLayout->setContentsMargins(0, 0, 0, 0);
				nomLayout->setSpacing(0);
				nomWidget->setLayout(nomLayout);
				table->setCellWidget(i+l, 1, nomWidget);
				QLabel *pointsi = new QLabel(QString::number(m.points));
				table->setCellWidget(i+l, 2, pointsi);
				if (this->typeClmt == CLMT_TEMPS) {
					QLabel *tpsReel = new QLabel(this->formate_tps(m.tpsReel));
					table->setCellWidget(i+l, 3, tpsReel);
					QLabel *tpsCompense = new QLabel(this->formate_tps(qRound(m.tpsCompense)));
					table->setCellWidget(i+l, 4, tpsCompense);
				}
				// on ajoute l'équipage à la table html
				QString nomString = "<span class=\"equipage\">"+e.nom+"</span>";
				if (this->typeClmt == CLMT_TEMPS) {
					nomString += "<span class=\"bateau\">"
						+this->bateaux.value(e.rating.toUpper()).serie
						+" ("+QString::number(e.coef)+")</span>";
				}
				html += "\n\t\t<tr>\n\t\t\t<td>"+QString::number(i+1)+"</td>"
					+"<td>"+nomString+"</td>"
					+"<td>"+QString::number(m.points)+"</td>";
				if (this->typeClmt == CLMT_TEMPS) {
					html += "<td>"+this->formate_tps(m.tpsReel)+"</td>"
						+"<td>"+this->formate_tps(qRound(m.tpsCompense))+"</td>";
				}
				html += "\n\t\t</tr>";
				++nbAffiches;
			}
			i = i+ids.size()-1;
		}
		// on traite les équipages qui n'ont pas de place/temps
		for (int i = 0; i < this->nbEquipages; ++i) {
			if (this->equipages[i].manches[j].tpsCompense < 0) {
				double points = this->nbEquipages+1.0;
				this->equipages[i].points += points;
				this->equipages[i].pointsOrdonnes.prepend(points);
				this->equipages[i].pointsTries.append(points);
				this->equipages[i].manches[j].points = points;
				// on affiche ces équipages
				Equipage e = this->equipages[i];
				Manche m = e.manches[j];
				QString abr = this->get_abr(m.abr);
				QLabel *place = new QLabel(abr);
				table->setCellWidget(nbAffiches, 0, place);
				QWidget *nomWidget = new QWidget();
				QVBoxLayout *nomLayout = new QVBoxLayout();
				QLabel *nom = new QLabel(e.nom);
				nom->setProperty("label", "nom");
				nomLayout->addWidget(nom);
				if (this->typeClmt == CLMT_TEMPS) {
					QLabel *bateau = new QLabel();
					bateau->setText(this->bateaux.value(e.rating.toUpper()).serie
						+" ("+QString::number(e.coef)+")");
					bateau->setProperty("label", "bateau");
					nomLayout->addWidget(bateau);
					table->setRowHeight(nbAffiches, 45);
				}
				nomLayout->setContentsMargins(0, 0, 0, 0);
				nomLayout->setSpacing(0);
				nomWidget->setLayout(nomLayout);
				table->setCellWidget(nbAffiches, 1, nomWidget);
				QLabel *pointsi = new QLabel(QString::number(m.points));
				table->setCellWidget(nbAffiches, 2, pointsi);
				if (this->typeClmt == CLMT_TEMPS) {
					QLabel *tpsReel = new QLabel(abr);
					table->setCellWidget(nbAffiches, 3, tpsReel);
					QLabel *tpsCompense = new QLabel(abr);
					table->setCellWidget(nbAffiches, 4, tpsCompense);
				}
				// on ajoute l'équipage à la table html
				QString nomString = "<span class=\"equipage\">"+e.nom+"</span>";
				if (this->typeClmt == CLMT_TEMPS) {
					nomString += "<span class=\"bateau\">"
						+this->bateaux.value(e.rating.toUpper()).serie
						+" ("+QString::number(e.coef)+")</span>";
				}
				html += "\n\t\t<tr>\n\t\t\t<td>"+abr+"</td><td>"+nomString+"</td>"
					+"<td>"+QString::number(m.points)+"</td>";
				if (this->typeClmt == CLMT_TEMPS) {
					html += "<td>"+abr+"</td><td>"+abr+"</td>";
				}
				html += "\n\t\t</tr>";
				++nbAffiches;
			}
		}
		ui->resultatsLayout->addWidget(table);
		table->hide();
		html += "\n\t</tbody>\n</table>";
		this->htmls.append(html);
		this->progression(5+j*75/this->nbManches);
	}
	// on trie les liste pointsTries
	for (int i = 0; i < this->nbEquipages; ++i) {
		qSort(this->equipages[i].pointsTries);
	}
}