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)); }
void SessionAnalysisWidget::keyPressEvent(QKeyEvent *k) { if (k->key() == Qt::Key_Escape) close(); if (k->key() == Qt::Key_C && k->modifiers() == Qt::ControlModifier) { QTableWidget *table = ui.lapTimeTableWidget; if (EventData::getInstance().getEventType() == LTPackets::PRACTICE_EVENT) table = ui.lapTimeTableWidgetFP; if (EventData::getInstance().getEventType() == LTPackets::QUALI_EVENT) { switch (ui.qualiTabWidget->currentIndex()) { case 0: table = ui.lapTimeTableWidgetQuali; break; case 1: table = ui.lapTimeTableWidgetQ1; break; case 2: table = ui.lapTimeTableWidgetQ2; break; case 3: table = ui.lapTimeTableWidgetQ3; break; } } QItemSelectionModel * selection = table->selectionModel(); QModelIndexList indexes = selection->selectedIndexes(); if(indexes.size() < 1) return; // QModelIndex::operator < sorts first by row, then by column. // this is what we need qSort(indexes.begin(), indexes.end()); // You need a pair of indexes to find the row changes QModelIndex previous = indexes.first(); indexes.removeFirst(); QString selected_text; QModelIndex current; Q_FOREACH(current, indexes) { QVariant data = table->model()->data(previous); QString text = data.toString(); selected_text.append(text); if (current.row() != previous.row()) { selected_text.append(QLatin1Char('\n')); } else { selected_text.append(QLatin1Char('\t')); } previous = current; }
void AccountsPage::done(int retval) { QTableWidget *tableW = ui->tableWidget; if(!tableW->selectionModel()) return; // Figure out which address was selected, and return it QModelIndexList indexes = tableW->selectionModel()->selectedRows(2); foreach (QModelIndex index, indexes) { QVariant address = tableW->model()->data(index); returnValue = address.toString(); }
void WindingWizardWidget::export_table_to_clipboard(){ QTableWidget * table = ui->tw_winding; QItemSelectionModel * selection = table->selectionModel(); QModelIndexList indexes = selection->selectedIndexes(); if(indexes.size() < 1) return; // QModelIndex::operator < sorts first by row, then by column. // this is what we need std::sort(indexes.begin(), indexes.end()); // You need a pair of indexes to find the row changes QModelIndex previous = indexes.first(); indexes.removeFirst(); QString selected_text; QModelIndex current; Q_FOREACH(current, indexes) { QVariant data = table->model()->data(previous); QString text = data.toString(); // At this point `text` contains the text in one cell selected_text.append(text); // If you are at the start of the row the row number of the previous index // isn't the same. Text is followed by a row separator, which is a newline. if (current.row() != previous.row()) { selected_text.append(QLatin1Char('\n')); } // Otherwise it's the same row, so append a column separator, which is a tab. else { selected_text.append(QLatin1Char('\t')); } previous = current; }
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); }