本文整理汇总了C++中QSqlTableModel::index方法的典型用法代码示例。如果您正苦于以下问题:C++ QSqlTableModel::index方法的具体用法?C++ QSqlTableModel::index怎么用?C++ QSqlTableModel::index使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSqlTableModel
的用法示例。
在下文中一共展示了QSqlTableModel::index方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setModelData
void mySqlRelationalDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
if (!index.isValid())
return;
QSqlRelationalTableModel *sqlModel = qobject_cast<QSqlRelationalTableModel *>(model);
QSortFilterProxyModel* proxyModel = NULL;
if (!sqlModel )
{
proxyModel = qobject_cast<QSortFilterProxyModel *>(model);
if (proxyModel)
sqlModel = qobject_cast<QSqlRelationalTableModel *>(proxyModel->sourceModel());
}
QSqlTableModel *childModel = sqlModel ? sqlModel->relationModel(index.column()) : 0;
QComboBox *combo = qobject_cast<QComboBox *>(editor);
if (!sqlModel || !childModel || !combo) {
QItemDelegate::setModelData(editor, model, index);
return;
}
int currentItem = combo->currentIndex();
int childColIndex = childModel->fieldIndex(sqlModel->relation(index.column()).displayColumn());
int childEditIndex = childModel->fieldIndex(sqlModel->relation(index.column()).indexColumn());
if (proxyModel) {
proxyModel->setData(index, childModel->data(childModel->index(currentItem, childColIndex), Qt::DisplayRole), Qt::DisplayRole);
proxyModel->setData(index, childModel->data(childModel->index(currentItem, childEditIndex), Qt::EditRole), Qt::EditRole);
} else {
sqlModel->setData(index, childModel->data(childModel->index(currentItem, childColIndex), Qt::DisplayRole), Qt::DisplayRole);
sqlModel->setData(index, childModel->data(childModel->index(currentItem, childEditIndex), Qt::EditRole), Qt::EditRole);
}
}
示例2: importData
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;
}
}
示例3: SubmitButton
void Liveinfo::SubmitButton()
{
// bool a,b,c;
if(NameEdit->text().isEmpty() || ContactEdit->text().isEmpty() || IDEdit->text().isEmpty() ||
DaysEdit->text().isEmpty() || DespoitEdit->text().isEmpty())
{
QMessageBox::critical(0,QObject::tr("Error!"),QObject::tr("Please Fill them all!"),QMessageBox::Cancel);
}
else
{
QString Ename = NameEdit->text();
QString Econtact = ContactEdit->text();
QString EID = IDEdit->text();
QString Edays = DaysEdit->text();
QString Edeposit = DespoitEdit->text();
QDate cudate = QDate::currentDate();
cudate = cudate.addDays(Edays.toInt());
Eetime = cudate.toString("yyyy-MM-dd");
QSqlTableModel *insertGuest = new QSqlTableModel; //修改Guest中的记录
insertGuest->setTable("Guest");
insertGuest->select(); // 只要指定Row=0即可插入新行
int row = 0;
insertGuest->insertRows(row,1);
insertGuest->setData(insertGuest->index(row, 0), QVariant(Ename));
insertGuest->setData(insertGuest->index(row, 1), QVariant(EID));
insertGuest->setData(insertGuest->index(row, 2), QVariant(Econtact));
insertGuest->setData(insertGuest->index(row, 3), QVariant(RoomNum));
// a = insertGuest->submit();
insertGuest->submit();
QSqlTableModel *insertRecord = new QSqlTableModel; //修改Record中的记录
insertRecord->setTable("Record");
insertRecord->select();
insertRecord->insertRows(row,1);
insertRecord->setData(insertRecord->index(row,0),QVariant(Ename));
insertRecord->setData(insertRecord->index(row,1),QVariant(RoomNum));
insertRecord->setData(insertRecord->index(row,2),QVariant(Edays));
insertRecord->setData(insertRecord->index(row,3),QVariant(Edeposit));
insertRecord->setData(insertRecord->index(row,4),QVariant(Estime));
insertRecord->setData(insertRecord->index(row,5),QVariant(Eetime));
// b = insertRecord->submit();
insertRecord->submit();
UpdateRoom(RoomNum,1); //修改已入住的房间
// if(a && b && c)
// {
QMessageBox msgBox;
msgBox.setText("Succeed to live in! Welcome");
msgBox.exec();
// }
QDialog::accept();
}
}
示例4: setData
void simplePerson::setData(QString idx, QString tableName)
{
QSqlTableModel model;
model.setTable(tableName);
model.setFilter(QString("id = %1").arg(idx));
model.select();
id = model.data(model.index(0,0)).toString();
surname = model.data(model.index(0,1)).toString();
name = model.data(model.index(0,2)).toString();
patronimic = model.data(model.index(0,3)).toString();;
}
示例5: qDebug
void ChengjiaoQianyueDialog::on_pushButton_3_clicked(){
qDebug() << "add";
QSqlTableModel * model = this->dbcon->qianyue;
int row = this->tableViewqianyue->currentIndex().row();
model->setData(model->index(row, 0), this->comboBoxFang->currentText());
model->setData(model->index(row, 1), this->comboBoxKe->currentText());
model->setData(model->index(row, 2), this->comboBoxRen->currentText());
model->setData(model->index(row, 3), this->spinBoxYongjin->text().toInt());
model->setData(model->index(row, 4), this->comboBoxFen->currentText());
model->setData(model->index(row, 5), this->spinBoxBianhao->text().toInt());
model->submitAll();
}
示例6: addClicked
void QgsBookmarks::addClicked()
{
QSqlTableModel *model = qobject_cast<QSqlTableModel *>( lstBookmarks->model() );
Q_ASSERT( model );
QgsMapCanvas *canvas = QgisApp::instance()->mapCanvas();
Q_ASSERT( canvas );
QSqlQuery query( "INSERT INTO tbl_bookmarks(bookmark_id,name,project_name,xmin,ymin,xmax,ymax,projection_srid)"
" VALUES (NULL,:name,:project_name,:xmin,:xmax,:ymin,:ymax,:projection_srid)",
model->database() );
QString projStr( "" );
if ( QgsProject::instance() )
{
if ( !QgsProject::instance()->title().isEmpty() )
{
projStr = QgsProject::instance()->title();
}
else if ( !QgsProject::instance()->fileName().isEmpty() )
{
QFileInfo fi( QgsProject::instance()->fileName() );
projStr = fi.exists() ? fi.fileName() : "";
}
}
query.bindValue( ":name", tr( "New bookmark" ) );
query.bindValue( ":project_name", projStr );
query.bindValue( ":xmin", canvas->extent().xMinimum() );
query.bindValue( ":ymin", canvas->extent().yMinimum() );
query.bindValue( ":xmax", canvas->extent().xMaximum() );
query.bindValue( ":ymax", canvas->extent().yMaximum() );
query.bindValue( ":projection_srid", QVariant::fromValue( canvas->mapSettings().destinationCrs().srsid() ) );
if ( query.exec() )
{
model->setSort( 0, Qt::AscendingOrder );
model->select();
lstBookmarks->scrollToBottom();
lstBookmarks->setCurrentIndex( model->index( model->rowCount() - 1, 1 ) );
lstBookmarks->edit( model->index( model->rowCount() - 1, 1 ) );
}
else
{
QMessageBox::warning( this, tr( "Error" ), tr( "Unable to create the bookmark.\nDriver:%1\nDatabase:%2" )
.arg( query.lastError().driverText() )
.arg( query.lastError().databaseText() ) );
}
}
示例7: indexOfArtist
QModelIndex MainWindow::indexOfArtist(const QString &artist)
{
QSqlTableModel *artistModel = model->relationModel(2);
for (int i = 0; i < artistModel->rowCount(); i++) {
QSqlRecord record = artistModel->record(i);
if (record.value("artist") == artist)
return artistModel->index(i, 1);
}
return QModelIndex();
}
示例8: appendDataAfterCurrent
void MainWindow::appendDataAfterCurrent() {
if(ui->articleList->currentIndex().isValid()) {
int res = insertDlg->exec();
if(res == QDialog::Accepted) {
QSqlTableModel* mdl = mysqlDataModel->getMapTableModel();
int newRowIndex = ui->articleList->currentIndex().row() + 1;
if(!mysqlDataModel->articleExists(insertDlg->getArticleName().toUpper().toStdString())) {
mdl->insertRows(newRowIndex, 1);
mdl->setData(mdl->index(newRowIndex, 1), insertDlg->getArticleName().toUpper());
mdl->setData(mdl->index(newRowIndex, 2), insertDlg->getArticleDescription());
mdl->setData(mdl->index(newRowIndex, 3), QString::fromStdString(TriangleNumber::getBindedStrID(insertDlg->getVote())));
mdl->submitAll();
mdl->select();
}
}
}
}
示例9: saveUnits
void Database::saveUnits(QString userName, QList<Unit> units)
{
QSqlTableModel model;
model.setTable("user");
model.select();
QString saveName;
for (int i=0; i<model.rowCount(); ++i)
{
QSqlRecord record = model.record(i);
if (record.value("name").toString()==userName)
{
saveName=record.value("id").toString();
break;
}
}
saveName.prepend("save");
model.setTable(saveName);
int row=0, line=0;
model.select();
model.removeRows(row, model.rowCount());
model.submitAll();
while(line<units.size())
{
model.insertRows(row,1);
model.setData(model.index(row,0), line+1);
model.setData(model.index(row,1), units[line].imageFileName);
model.setData(model.index(row,2), units[line].faceLeft);
model.setData(model.index(row,3), units[line].vLocation);
model.setData(model.index(row,4), units[line].hLocation);
model.setData(model.index(row,5), units[line].hitPoints);
model.setData(model.index(row,6), units[line].totalHitPoints);
model.setData(model.index(row,7), units[line].actionTime);
model.setData(model.index(row,8), units[line].actionRate);
model.setData(model.index(row,9), units[line].movementRange);
model.setData(model.index(row,10), units[line].attackRange);
model.setData(model.index(row,11), units[line].attackPower);
model.setData(model.index(row,12), units[line].status);
model.setData(model.index(row,13), units[line].maskFileName);
model.setData(model.index(row,14), units[line].team);
model.setData(model.index(row,15), units[line].unitWorth);
model.submitAll();
line++;
}
}
示例10: QSqlQueryModel_snippets
void QSqlQueryModel_snippets()
{
{
//! [16]
QSqlQueryModel *model = new QSqlQueryModel;
model->setQuery("SELECT name, salary FROM employee");
model->setHeaderData(0, Qt::Horizontal, tr("Name"));
model->setHeaderData(1, Qt::Horizontal, tr("Salary"));
//! [17]
QTableView *view = new QTableView;
//! [17] //! [18]
view->setModel(model);
//! [18] //! [19]
view->show();
//! [16] //! [19] //! [20]
view->setEditTriggers(QAbstractItemView::NoEditTriggers);
//! [20]
}
//! [21]
QSqlTableModel model;
model.setTable("employee");
model.select();
int salary = model.record(4).value("salary").toInt();
//! [21]
Q_UNUSED(salary);
{
//! [22]
int salary = model.data(model.index(4, 2)).toInt();
//! [22]
Q_UNUSED(salary);
}
for (int row = 0; row < model.rowCount(); ++row) {
for (int col = 0; col < model.columnCount(); ++col) {
qDebug() << model.data(model.index(row, col));
}
}
}
示例11: areaUpdateCombo
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);
}
示例12: getrowoffacturation
int FacturationIO::getrowoffacturation(QSqlTableModel & modelfacturation,const QString & factureid)
{
int row = 0;
for ( int i = 0; i < modelfacturation.rowCount(); ++i)
{
if (modelfacturation.data(modelfacturation.index(i,ID_FACTURE),Qt::DisplayRole).toString() == factureid)
{
row = i;
}
}
return row;
}
示例13: setModelData
void MySqlRelationDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
if (!index.isValid())
return;
QSqlRelationalTableModel *sqlModel = qobject_cast<QSqlRelationalTableModel *>(model);
QSqlTableModel *childModel = sqlModel ? sqlModel->relationModel(index.column()) : 0;
QComboBox *combo = qobject_cast<QComboBox *>(editor);
if (!sqlModel || !childModel || !combo) {
if (HandbookDialog::m_record.fieldName(index.column()).contains("IS_", Qt::CaseSensitive))
{
QCheckBox * checkBox = qobject_cast<QCheckBox *>(editor);
sqlModel->setData(index, checkBox->isChecked(), Qt::DisplayRole);
sqlModel->setData(index, checkBox->isChecked(), Qt::EditRole);
return;
}
else if (HandbookDialog::m_record.fieldName(index.column()).contains("DATE_", Qt::CaseSensitive))
{
QDateEdit * dateEdit = qobject_cast<QDateEdit *>(editor);
sqlModel->setData(index, dateEdit->date().toString("yyyy-MM-dd"), Qt::DisplayRole);
sqlModel->setData(index, dateEdit->date().toString("yyyy-MM-dd"), Qt::EditRole);
return;
}
else
{
QItemDelegate::setModelData(editor, model, index);
return;
}
}
int currentItem = combo->currentIndex();
int childColIndex = childModel->fieldIndex(sqlModel->relation(index.column()).displayColumn());
int childEditIndex = childModel->fieldIndex(sqlModel->relation(index.column()).indexColumn());
sqlModel->setData(index,
childModel->data(childModel->index(currentItem, childColIndex), Qt::DisplayRole),
Qt::DisplayRole);
sqlModel->setData(index,
childModel->data(childModel->index(currentItem, childEditIndex), Qt::EditRole),
Qt::EditRole);
}
示例14: insertRow
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);
}
示例15: on_currencyComboBox_currentIndexChanged
void MainWindow::on_currencyComboBox_currentIndexChanged(int index)
{
int row = ui->assetsTable->currentIndex().row();
QVariant current_value = model->data(model->index(row, currency_column_index), Qt::DisplayRole);
QSqlTableModel *childModel = model->relationModel(currency_column_index);
int childColIndex = childModel->fieldIndex("code");
QVariant new_value = childModel->data(childModel->index(index, childColIndex), Qt::DisplayRole);
if(current_value != new_value) {
mapper->submit();
}
}