void Browser::deleteRow() { QSqlTableModel *model = qobject_cast<QSqlTableModel *>(table->model()); if (!model) return; QModelIndexList currentSelection = table->selectionModel()->selectedIndexes(); for (int i = 0; i < currentSelection.count(); ++i) { if (currentSelection.at(i).column() != 0) continue; model->removeRow(currentSelection.at(i).row()); } updateActions(); }
void MainWindow::decreaseAlbumCount(QModelIndex artistIndex) { int row = artistIndex.row(); QModelIndex albumCountIndex = artistIndex.sibling(row, 2); int albumCount = albumCountIndex.data().toInt(); QSqlTableModel *artists = model->relationModel(2); if (albumCount == 1) { artists->removeRow(row); showImageLabel(); } else { artists->setData(albumCountIndex, QVariant(albumCount - 1)); } }
void Form::on_pushButton_2_clicked() { QSqlTableModel *model = qobject_cast<QSqlTableModel *>(ui->treeView->model()); if (!model) return; QModelIndexList currentSelection = ui->treeView->selectionModel()->selectedIndexes(); for (int i = 0; i < currentSelection.count(); ++i) { if (currentSelection.at(i).column() != 0) continue; model->removeRow(currentSelection.at(i).row()); } }
void FenPrincipale::deleteRow() { QSqlTableModel *model = qobject_cast<QSqlTableModel *>(tablemesures->model()); if (!model) return; model->setEditStrategy(QSqlTableModel::OnManualSubmit); QModelIndexList currentSelection = tablemesures->selectionModel()->selectedIndexes(); for (int i = 0; i < currentSelection.count(); ++i) { if (currentSelection.at(i).column() != 0) continue; model->removeRow(currentSelection.at(i).row()); } model->submitAll(); model->setEditStrategy(QSqlTableModel ::OnManualSubmit); }
void FenPrincipale::deleteRowss() { QSqlTableModel *model = qobject_cast<QSqlTableModel *>(tabless->model()); if (!model) return; QModelIndexList currentSelection = tabless->selectionModel()->selectedIndexes(); for (int i = 0; i < currentSelection.count(); ++i) { if (currentSelection.at(i).column() != 0) continue; model->removeRow(currentSelection.at(i).row()); //tabless->edit(); deleteRow(); } }
//插入一条记录 void Widget::CStudentDialog::insertRecord() { bool ok; QString name = m_pNameEdit->text(); QString Sex = m_pSexEdit->text(); double age = m_pAgeEdit->text().toDouble( &ok ); if( !ok ){ QMessageBox::warning( this , "错误" , "请重新填写年龄" ); return; } QString number = m_pNumberEdit->text(); QString post = m_pPostEdit->text(); QSqlTableModel table; table.setTable( "person" ); table.select(); QSqlRecord record; record = table.record(); record.setValue( "name" , name ); record.setValue( "gender" , Sex ); record.setValue( "age" , age ); ok = table.insertRecord( -1, record ); if( !ok ){ AddStudentError } table.submitAll(); table.setTable( "person" ); table.setFilter( tr("name = '%0'").arg( name ) ); qDebug() << table.select(); int id = table.record(0).value( Enum::PersonSection::Person_id ).toInt( &ok ); if( !ok ){ table.removeRow( 0 ); table.submitAll(); AddStudentError }
void loginFrame::deleteUserInfo() { QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName("Registry.db"); if(!db.open()) return; QSqlTableModel *model = new QSqlTableModel(); model->setTable("userlist"); model->select(); //删除相应行 model->removeRow(ui->comboBox->currentIndex()); model->submitAll(); //修正combobox的显示 RegistyShowID.removeAt(ui->comboBox->currentIndex()); ui->comboBox->removeItem(ui->comboBox->currentIndex()); ui->comboBox->setCurrentIndex(0); for(int i=0;i<model->rowCount();i++) { ui->comboBox->setIconSize(QSize(20,20)); ui->comboBox->setItemIcon(i,QIcon(":/images/head.png")); ui->comboBox->setItemText(i,RegistyShowID.at(i).id); } }
void TableEditor::removeSelectedRows() { int currentTab = tabWidget->currentIndex(); QTableView *tv = agentsTable; QSqlTableModel *stm = agentsModel; QString table = "agents"; int idColumn = 0; if (currentTab == 1) { tv = determinationsTable; stm = determinationsModel; table = "determinations"; } else if (currentTab == 2) { tv = imagesTable; stm = imagesModel; table = "images"; idColumn = 20; } else if (currentTab == 3) { tv = taxaTable; stm = taxaModel; table = "taxa"; idColumn = 1; } else if (currentTab == 4) { tv = organismsTable; stm = organismsModel; table = "organisms"; } else if (currentTab == 5) { tv = sensuTable; stm = sensuModel; table = "sensu"; } QItemSelectionModel *selected = tv->selectionModel(); QModelIndexList rowList = selected->selectedIndexes(); for (int i = rowList.count()-1; i >= 0; i--) { stm->removeRow(rowList.at(i).row(), rowList.at(i).parent()); QString identifier; if (table == "determinations") { QString orgID = stm->data(stm->index(rowList.at(i).row(),0),Qt::DisplayRole).toString(); QString date = stm->data(stm->index(rowList.at(i).row(),2),Qt::DisplayRole).toString(); QString tsnID = stm->data(stm->index(rowList.at(i).row(),4),Qt::DisplayRole).toString(); QString source = stm->data(stm->index(rowList.at(i).row(),5),Qt::DisplayRole).toString(); reversions.append("INSERT OR REPLACE INTO determinations SELECT * FROM pub_determinations " "WHERE dsw_identified = '" + orgID + "' AND " "dwc_dateIdentified = '" + date + "' AND " "tsnID = '" + tsnID + "' AND " "nameAccordingToID = '" + source + "' LIMIT 1"); } else { identifier = stm->data(stm->index(rowList.at(i).row(),idColumn),Qt::DisplayRole).toString(); reversions.append("INSERT OR REPLACE INTO " + table + " SELECT * FROM pub_" + table + " WHERE dcterms_identifier = '" + identifier + "' LIMIT 1"); } } }