本文整理汇总了C++中QSqlTableModel::setEditStrategy方法的典型用法代码示例。如果您正苦于以下问题:C++ QSqlTableModel::setEditStrategy方法的具体用法?C++ QSqlTableModel::setEditStrategy怎么用?C++ QSqlTableModel::setEditStrategy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSqlTableModel
的用法示例。
在下文中一共展示了QSqlTableModel::setEditStrategy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: afficherTable
void FenPrincipale::afficherTable()
{
// database = FenPrincipale::newdatabase;
// createConnection();
//QMessageBox::information(0,QObject::tr("debug"),
// "debug "+database);
QSqlTableModel *model = new QSqlTableModel ();
model->setTable( "stationStationnee" );
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->setSort(0,Qt::AscendingOrder);
model->select();
QSqlTableModel *model1 = new QSqlTableModel ();
model1->setTable("mesures");
model1->setEditStrategy(QSqlTableModel::OnManualSubmit);
model1->setSort(0,Qt::AscendingOrder);
model1->select();
tabless->setModel( model );
tabless->show();
// tabless->setColumnHidden(0,true);
tabless->setColumnHidden(5,true);
tabless->setColumnHidden(6,true);
tabless->setColumnHidden(7,true);
tabless->resizeColumnToContents(1);
tablemesures->setModel( model1 );
// tablemesures->setColumnHidden(0,true);
tablemesures->setColumnHidden(19,true);
tablemesures->resizeColumnsToContents();
QSqlQuery query;
QModelIndex index;
// query.exec("select id from mesures where classe = 30");
// int id=0;
// while (query.next()) {
// id = query.value(0).toInt();
// }
// if (index.row() == id)
// {
// tablemesures->setBackgroundRole(QPalette::Text);
// }tmpAreteList->count()
tablemesures->show();
// QString date = "";
// QFileInfo file(database);
// QDateTime lastModified = file.lastModified();
// date = lastModified.toString();
// bool valid = QFile::copy (database, database+"."+date);
}
示例2: deleteRow
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);
}
示例3: getVenueModel
QSqlTableModel* MainWindow::getVenueModel()
{
ui->tableView_ven->setModel(NULL);
QSqlTableModel *model = new QSqlTableModel;
model->setTable("venues");
model->setEditStrategy(QSqlTableModel::OnFieldChange);
model->select();
model->setHeaderData(0, Qt::Horizontal, "ID");
model->setHeaderData(1, Qt::Horizontal, "Name");
return model;
}
示例4: onDatabaseItemActivated
void DataViewer::onDatabaseItemActivated(const DatabaseItem &item)
{
if ((DatabaseItem::Table != item.m_type) &&
(DatabaseItem::View != item.m_type))
{
return;
}
d_ptr->database = item.m_database;
// for table tableShema
QSqlRecord record = item.m_database.record(item.m_value);
d_ptr->m_shemaModel->removeRows(0, d_ptr->m_shemaModel->rowCount());
d_ptr->m_shemaModel->insertRows(0, record.count());
for (int i = 0; i < record.count(); ++i)
{
QSqlField field = record.field(i);
d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 0), field.name());
d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 1),
field.type() == QVariant::Invalid ? "???" : QString(QVariant::typeToName(field.type())));
d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 2),
(field.length() < 0) ? QVariant("???") : field.length());
d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 3),
(field.precision() < 0) ? QVariant("???") : field.precision());
d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 4),
field.requiredStatus() == QSqlField::Unknown ? "???" : QVariant(bool(field.requiredStatus())));
d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 5), field.isAutoValue());
d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 6), field.defaultValue());
}
d_ptr->m_tableShema->setModel(d_ptr->m_shemaModel.data());
d_ptr->m_tableShema->setEditTriggers(QAbstractItemView::NoEditTriggers);
d_ptr->m_tableShema->resizeColumnsToContents();
d_ptr->m_tab->setTabText(::Scheme, tr(::c_schemeTable).arg(item.m_value));
// for table tableData
QSqlTableModel *modelData = new QSqlTableModel(0, item.m_database);
modelData->setEditStrategy(QSqlTableModel::OnRowChange);
modelData->setTable(item.m_value);
modelData->select();
d_ptr->m_tableData->setModel(modelData);
d_ptr->m_tableData->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed);
d_ptr->m_tableData->resizeColumnsToContents();
d_ptr->m_tab->setTabText(::Data, tr(::c_dataTable).arg(item.m_value));
d_ptr->m_sqlDataModel.reset(modelData);
}
示例5: on_pbAggiungiPermesso_clicked
void FormGestioneFerie::on_pbAggiungiPermesso_clicked()
{
for(QDate a=ui->dePermessiDal->date(); a.operator <=( ui->dePermessiAl->date());a= a.addDays(1) )
{
qDebug() << "Permesso per "+ui->cbMatricola->currentText()+" per il giorno "+a.toString("dd/MM/yyyy");
QSqlQuery query;
query.prepare("INSERT INTO assenze (ID, matricola, causa, data)" "VALUES (?, ?, ?, ?)");
// query.addBindValue( ui->cbMatricola->currentText()+"_"+ui->dePermessiDal->date().toString("dd/MM/yyyy"));
query.addBindValue( ui->cbMatricola->currentText()+"_"+a.toString("dd/MM/yyyy"));
query.addBindValue( ui->cbMatricola->currentText());
query.addBindValue( ui->cbTipoPermesso->currentText());
// query.addBindValue( ui->dePermessiDal->date().toString("dd/MM/yyyy"));
query.addBindValue( a.toString("dd/MM/yyyy"));
if(query.exec())
{
QMessageBox msgBox;
msgBox.setText("Inserzione nel database.");
msgBox.setInformativeText(QString("Permesso per il giorno %1 inserito correttamente.").arg(a.toString("dd/MM/yyyy")));
msgBox.setStandardButtons(QMessageBox::Ok );
msgBox.setIcon(QMessageBox::Information);
msgBox.exec();
}
else
{
QMessageBox msgBox;
msgBox.setText("Inserzione nel database.");
msgBox.setInformativeText(QString("Permesso per il giorno %1 NON inserito nel database. Probabilmente è gia stato inserito un permesso per lo stesso giorno.").arg(a.toString("dd/MM/yyyy")));
msgBox.setStandardButtons(QMessageBox::Ok );
msgBox.setIcon(QMessageBox::Critical);
msgBox.exec();
}
QSqlTableModel *model = new QSqlTableModel(this, this->db);
model->setTable("assenze");
model->setEditStrategy(QSqlTableModel::OnFieldChange);
model->select();
model->setFilter(QString("Matricola=\"%1\"").arg(ui->cbMatricola->currentText()));
model->sort(2,Qt::AscendingOrder);
model->setHeaderData(1, Qt::Horizontal, tr("MATRICOLA"));
model->setHeaderData(2, Qt::Horizontal, tr("DATA"));
model->setHeaderData(3, Qt::Horizontal, tr("CAUSA"));
ui->tvPermessi->setModel(model);
ui->tvPermessi->hideColumn(0);
ui->tvPermessi->resizeColumnsToContents();
ui->tvPermessi->resizeRowsToContents();
ui->tvPermessi->selectRow(0);
}
}
示例6: printNeighbor
void Control::printNeighbor()
{
QString whichID = ui->comboBox_5->currentText();
QSqlTableModel* model = new QSqlTableModel(this);
model->setTable("Distance");
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->setFilter("CellID1="+whichID+" and distance<=2 order by distance asc");
model->setHeaderData(1,Qt::Horizontal,tr("邻居"));
model->setHeaderData(2,Qt::Horizontal,tr("距离(千米)"));
model->select();
ui->tableView->setModel(model);
ui->tableView->show();
ui->tableView->setColumnHidden(model->fieldIndex("CellID1"),true);
}
示例7: showTable
void Browser::showTable(const QString &t)
{
QSqlTableModel *model = new QSqlTableModel(table, connectionWidget->currentDatabase());
model->setEditStrategy(QSqlTableModel::OnRowChange);
model->setTable(t);
model->select();
if (model->lastError().type() != QSqlError::NoError)
emit statusMessage(model->lastError().text());
table->setModel(model);
table->setEditTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
connect(table->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
this, SLOT(currentChanged()));
updateActions();
}
示例8: updateUI
void ListPc::updateUI(){
QSqlTableModel *model = new QSqlTableModel(this, QSqlDatabase::database());
model->setTable("pc");
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->select();
model->setHeaderData(0, Qt::Horizontal, tr("ID"));
model->setHeaderData(1, Qt::Horizontal, tr("Processzor"));
model->setHeaderData(2, Qt::Horizontal, tr("Memórie"));
model->setHeaderData(3, Qt::Horizontal, tr("Merevlemez"));
model->setHeaderData(4, Qt::Horizontal, tr("Operációs rendszer"));
model->setHeaderData(5, Qt::Horizontal, tr("Megjegyzés"));
ui->tableView_listpc->setModel(model);
ui->tableView_listpc->hideColumn(0);
ui->tableView_listpc->resizeColumnsToContents();
}
示例9: initBorrowTableView
void AdminDialog::initBorrowTableView()
{
QSqlTableModel *model = new QSqlTableModel(this,Tool::getInstance()->getDb());
model->setTable("borrow");
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->select(); //选取整个表的所有行
model->setFilter("isreturn=0");
model->removeColumn(model->columnCount()-1);
model->removeColumn(model->columnCount()-1);
model->setHeaderData(0,Qt::Horizontal,"借阅编号");
model->setHeaderData(1,Qt::Horizontal,"图书编号");
model->setHeaderData(2,Qt::Horizontal,"读者编号");
model->setHeaderData(3,Qt::Horizontal,"剩余续借次数");
model->setHeaderData(4,Qt::Horizontal,"借阅时间");
model->setHeaderData(5,Qt::Horizontal,"应还时间");
ui->tv3->setModel(model);
ui->tv3->setEditTriggers(QAbstractItemView::NoEditTriggers);
}
示例10: viewTable
void MainWindow::viewTable()
{
QString table;
//table = "SELECT * FROM '";
table.append(ui->viewEdit->text());
//table.append("'");
//dbQuery.exec(table);
QSqlTableModel * tmodel = new QSqlTableModel;
tmodel->setTable(table);
tmodel->select();
tmodel->setEditStrategy(QSqlTableModel::OnManualSubmit);
tview = new QTableView;
tview->setModel(tmodel);
tview->show();
}
示例11: initBookTableView
void AdminDialog::initBookTableView()
{
QSqlTableModel *model = new QSqlTableModel(this,Tool::getInstance()->getDb());
model->setTable("book");
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->select(); //选取整个表的所有行
model->setHeaderData(0,Qt::Horizontal,"图书编号");
model->setHeaderData(1,Qt::Horizontal,"书名");
model->setHeaderData(2,Qt::Horizontal,"作者");
model->setHeaderData(3,Qt::Horizontal,"出版社");
model->setHeaderData(4,Qt::Horizontal,"出版日期");
model->setHeaderData(5,Qt::Horizontal,"价格");
model->setHeaderData(6,Qt::Horizontal,"类型");
model->setHeaderData(7,Qt::Horizontal,"总数量");
model->setHeaderData(8,Qt::Horizontal,"在馆数");
ui->tv1->setModel(model);
ui->tv1->setEditTriggers(QAbstractItemView::NoEditTriggers);
}
示例12: findCellInfo
void Control::findCellInfo()
{
if(!checkDurationValid())
{
QMessageBox::warning(this,"警告","请选择正确的时间段",QMessageBox::Yes);
return;
}
if(ui->lineEdit->text().isEmpty())
{
QMessageBox::warning(this,"警告","请输入拥塞门限(0到1的小数)",QMessageBox::Yes);
return;
}
double rate= ui->lineEdit->text().toDouble();
QSqlQuery query;
query.exec("exec countCongs");
QDateTime start = ui->startDateTimeEdit->dateTime();
QDateTime end = ui->endDateTimeEdit->dateTime();
int year1 = start.date().year() % 10 * 10000;
int month1 = start.date().month() * 100;
int day1 = start.date().day();
int hour1 = start.time().hour();
int year2 = end.date().year() % 10 * 10000;
int month2 = end.date().month() * 100;
int day2 = end.date().day();
int hour2 = end.time().hour();
query.exec(QString("exec finder2 %1,%2,%3,%4,%5").arg(rate).arg(year1 + month1 + day1).arg(hour1)
.arg(year2 + month2 + day2).arg(hour2));//finder2只列rate超过门限的部分数据
QSqlTableModel* model = new QSqlTableModel(this);
model->setTable("H_result");
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->setFilter("H_rate>"+QString::number(rate) +" order by CellID,bdate,btime");
model->setHeaderData(0,Qt::Horizontal,tr("日期"));
model->setHeaderData(1,Qt::Horizontal,tr("小时"));
model->setHeaderData(2,Qt::Horizontal,tr("小区ID"));
model->setHeaderData(3,Qt::Horizontal,tr("小时级话务量"));
model->setHeaderData(4,Qt::Horizontal,tr("小时级拥塞率"));
model->setHeaderData(5,Qt::Horizontal,tr("小时级半速率话务量比例"));
model->select();
ui->tableView_2->setModel(model);
ui->tableView_2->show();
}
示例13: query
FormGestioneFerie::FormGestioneFerie(QSqlDatabase db, QWidget *parent) :
QWidget(parent),
ui(new Ui::FormGestioneFerie)
{
ui->setupUi(this);
QDate oggi;
ui->dePermessiDal->setDate(oggi.currentDate());
ui->dePermessiAl->setDate(oggi.currentDate());
this->db= db;
QSqlQuery query(QString("SELECT Matricola,cognome FROM anagrafica"));
while (query.next())
{
ui->cbMatricola->addItem( query.value(0).toString() );
ui->cbCognome->addItem( query.value(1).toString() );
ui->lNome->setText( query.value(2).toString() );
}
QSqlQuery query1(QString("SELECT nome FROM anagrafica where Matricola=\"%1\"").arg(ui->cbMatricola->currentText()));
query1.next();
ui->lNome->setText( query1.value(0).toString() );
QSqlTableModel *model = new QSqlTableModel(this, this->db);
model->setTable("assenze");
model->setEditStrategy(QSqlTableModel::OnFieldChange);
model->select();
model->setFilter(QString("Matricola=\"%1\"").arg(ui->cbMatricola->currentText()));
model->sort(2,Qt::AscendingOrder);
model->setHeaderData(1, Qt::Horizontal, tr("MATRICOLA"));
model->setHeaderData(2, Qt::Horizontal, tr("DATA"));
model->setHeaderData(3, Qt::Horizontal, tr("CAUSA"));
ui->tvPermessi->setModel(model);
ui->tvPermessi->hideColumn(0);
ui->tvPermessi->resizeColumnsToContents();
ui->tvPermessi->resizeRowsToContents();
ui->tvPermessi->selectRow(0);
}
示例14: QWidget
TableView::TableView()
: QWidget()
{
if (! this->createConnection()) {
QString msg = "** Create Database Error";
throw msg;
}
setWindowTitle(tr("Table View Model"));
setMinimumSize(300, 350);
//
QSqlTableModel *model = new QSqlTableModel(this, m_db);
QStringList tempX = m_db.tables();
model->setTable(tempX.at(0));
QSqlError error = model->lastError();
if ( error.isValid() ) {
ksMsg( this, "Table View - SQL Error", error.text() );
}
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->setSort(2, Qt::AscendingOrder);
model->select();
model->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("First name"));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("Last name"));
//
QTableView *view = new QTableView;
view->setModel(model);
view->resizeColumnsToContents();
QHeaderView *temp = view->horizontalHeader();
temp->setStretchLastSection(true);
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addWidget(view);
setLayout(mainLayout);
}
示例15: insertRow
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);
}