void MainWindow::importData() { int exam_id; QString dataFileName = QFileDialog::getOpenFileName(this,tr("Import Data From a CSV File"),QDir::homePath(),tr("CSV File (*.csv)")); if(dataFileName.isEmpty()) return; QFile dataFile(dataFileName); if(!dataFile.open(QIODevice::ReadOnly)) { QMessageBox::critical(this,tr("Open File Failed"),tr("Cannot open selected file"));; return; } QSqlTableModel* student = m_scoreView->studentListModel(); QSqlTableModel* exam = m_scoreView->examListModel(); QSqlRelationalTableModel* score = m_scoreView->scoreListModel(); QFileInfo tmp(dataFileName); QString exam_name = tmp.baseName(); exam->setFilter(QString("name = \'%1\'").arg(exam_name)); if(exam->rowCount() == 1) { QSqlRecord rq = exam->record(0); exam_id = rq.value("id").toInt(); } else { exam->insertRow(0); exam->setData(exam->index(0,Global::Exam_Name),exam_name); exam->submitAll(); exam->setFilter(QString("name = \'%1\'").arg(exam_name)); QSqlRecord rq = exam->record(0); exam_id = rq.value("id").toInt(); } QHash<QString,int> studentMap; for(int row = 0;row < student->rowCount();++row) studentMap.insert(student->data(student->index(row,1)).toString(),student->data(student->index(row,0)).toInt()); QTextStream in(&dataFile); QString record = in.readLine(); QStringList candidate_seps; candidate_seps << ";" << "," << "\t" << " "; QString real_sep; bool is_legal = false; QStringList cols; foreach(real_sep, candidate_seps) { cols = record.split(real_sep); if(cols.size() == 11) { is_legal = true; break; } }
void SupplierManageWindow::areaUpdateCombo(bool select) { QSqlTableModel *ptrModel = m_model->relationModel(SupplierManageWindow::idArea); if(select) ptrModel->select(); ptrModel->insertRow(0); ptrModel->setData(ptrModel->index(0, ptrModel->fieldIndex("name")), trUtf8("-- Seleccione Rubro --"), Qt::EditRole); cb_area->setModel(ptrModel); cb_area->setModelColumn(ptrModel->fieldIndex("name")); cb_area->setCurrentIndex(0); }
void Browser::insertRow() { QSqlTableModel *model = qobject_cast<QSqlTableModel *>(table->model()); if (!model) return; QModelIndex insertIndex = table->currentIndex(); int row = insertIndex.row() == -1 ? 0 : insertIndex.row(); model->insertRow(row); insertIndex = model->index(row, 0); table->setCurrentIndex(insertIndex); table->edit(insertIndex); }
void FenPrincipale::insertRow() { QSqlTableModel *model = qobject_cast<QSqlTableModel *>(tablemesures->model()); if (!model) return; model->setEditStrategy(QSqlTableModel::OnManualSubmit); QModelIndex insertIndex = tablemesures->currentIndex(); int row = insertIndex.row() == -1 ? 0 : insertIndex.row(); model->insertRow(row); insertIndex = model->index(row, 0); tablemesures->setCurrentIndex(insertIndex); tablemesures->edit(insertIndex); }