activityinitial::activityinitial(QWidget *parent) : QDialog(parent), ui(new Ui::activityinitial) { ui->setupUi(this); ui->myName->setText(getName()); ui->courseName->setText(getCourseName()); ui->activityName->setText(getActivityName()); QSqlQueryModel *model = new QSqlQueryModel(); QSqlQuery cts; qDebug() << actid; cts.prepare("select CoursesToStudent.studentName, ModifiedBy.userType " "from CoursesToStudent " "left join ModifiedBy " "on CoursesToStudent.studentID = ModifiedBy.studentID " "where ModifiedBy.activityID = ?"); cts.addBindValue(actid); cts.exec(); model->setQuery(cts); model->setHeaderData(0, Qt::Horizontal, tr("Student Name")); model->setHeaderData(1, Qt::Horizontal, tr("Modified By")); ui->studentList->setModel(model); }
void HModifyProd::getComponetsLot() { QSqlQuery q(db); // idlot=ui->tvLots->model()->index(ui->tvLots->currentIndex().row(),0).data(0).toInt(); QString sql="select operazioni.ID,operazioni.IDlotto,lotdef.lot,prodotti.ID,prodotti.descrizione,operazioni.quantita,unita_di_misura.ID,unita_di_misura.descrizione from operazioni,lotdef,prodotti,unita_di_misura where prodotti.ID=operazioni.IDprodotto and lotdef.ID=operazioni.IDlotto and unita_di_misura.ID=operazioni.um and operazioni.ID in (SELECT operazione from composizione_lot where ID_lotto=:lotid )order by operazioni.quantita desc"; QSqlQueryModel *qmod = new QSqlQueryModel(); q.prepare(sql); q.bindValue(":lotid",QVariant(idlot)); q.exec(); qmod->setQuery(q); // // qDebug()<<q.lastQuery(); ui->tvDetails->setModel(qmod); connect(ui->tvDetails->selectionModel(),SIGNAL(currentChanged(QModelIndex,QModelIndex)),this,SLOT(getLotRowData())); //// qDebug()<<q.lastError().text(); qmod->setHeaderData(4,Qt::Horizontal,QObject::tr("Ingrediente")); qmod->setHeaderData(5,Qt::Horizontal,QObject::tr("Quantità")); ui->tvDetails->setColumnHidden(0,true); ui->tvDetails->setColumnHidden(1,true); ui->tvDetails->setColumnHidden(3,true); ui->tvDetails->setColumnHidden(6,true); QString lbtxt; lbtxt=ui->tvLots->model()->index(ui->tvLots->currentIndex().row(),1).data(0).toString(); lbtxt.append(" - "); lbtxt.append(ui->tvLots->model()->index(ui->tvLots->currentIndex().row(),2).data(0).toString()); ui->lbProd->setText(lbtxt); // qDebug()<<QString::number(idlot); }
//! Populates the checked in and not checked in item tables. void wndInventoryCheck::refreshTables( void ) { QSqlQuery checkedQuery; checkedQuery.prepare( "SELECT iid,name FROM inventorycheck WHERE checked=1" ); _pDB->query( checkedQuery ); QSqlQueryModel *checkmodel = new QSqlQueryModel; checkmodel->setQuery(checkedQuery); // Set header values checkmodel->setHeaderData( 0, Qt::Horizontal, tr( "ID" ) ); checkmodel->setHeaderData( 1, Qt::Horizontal, tr( "Name" ) ); // Set options for the QTableView _pUI->tblCheckedIn->setModel( checkmodel ); _pUI->tblCheckedIn->verticalHeader()->hide(); _pUI->tblCheckedIn->horizontalHeader()->setResizeMode( 0, QHeaderView::Stretch ); _pUI->tblCheckedIn->horizontalHeader()->setResizeMode( 1, QHeaderView::Stretch ); QSqlQuery ncheckedQuery; ncheckedQuery.prepare( "SELECT iid,name FROM inventorycheck WHERE checked=0" ); _pDB->query( ncheckedQuery ); QSqlQueryModel *ncheckmodel = new QSqlQueryModel; ncheckmodel->setQuery( ncheckedQuery ); // Set header values ncheckmodel->setHeaderData( 0, Qt::Horizontal, tr( "ID" ) ); ncheckmodel->setHeaderData( 1, Qt::Horizontal, tr( "Name" ) ); // Set options for the QTableView _pUI->tblNotCheckedIn->setModel( ncheckmodel ); _pUI->tblNotCheckedIn->verticalHeader()->hide(); _pUI->tblNotCheckedIn->horizontalHeader()->setResizeMode( 0, QHeaderView::Stretch ); _pUI->tblNotCheckedIn->horizontalHeader()->setResizeMode( 1, QHeaderView::Stretch ); }
void MainWindow::on_btnLogin_clicked() { QSqlQueryModel *model = new QSqlQueryModel; model->setQuery("SELECT * FROM users"); model->setHeaderData(0, Qt::Horizontal, tr("Name")); model->setHeaderData(0, Qt::Horizontal, tr("Password")); model->setHeaderData(0, Qt::Horizontal, tr("Type")); QString username = ui->txtUserName->text(); QString password = ui->txtPassWord->text(); bool success = loginManager->Login(username, password); if (success) { MainMenu *menu = new MainMenu(0, loginManager); menu->show(); this->destroy(); //QTableView *view = new QTableView; //view->setWindowTitle("Users"); //view->resizeColumnsToContents(); //view->resizeRowsToContents(); //view->setModel(model); //view->show(); //view->resize(640, 480); } }
void Search::on_lineEdit_cursorPositionChanged(int arg1, int arg2) { QString name=ui->lineEdit->text(); if(name.isEmpty()) { QSqlQueryModel *model = new QSqlQueryModel; model->setQuery("SELECT firstname, lastname, class, roll_no,STATUS FROM student where firstname like '"+name+"%'"); model->setHeaderData(0, Qt::Horizontal, tr("Firstname")); model->setHeaderData(1, Qt::Horizontal, tr("Lastname")); model->setHeaderData(2,Qt::Horizontal,tr("Class")); model->setHeaderData(3,Qt::Horizontal,tr("Roll")); model->setHeaderData(4,Qt::Horizontal,tr("Status")); ui->tableView->setModel(model); } else { QSqlQueryModel *model = new QSqlQueryModel; model->setQuery("SELECT firstname, lastname, class, roll_no,STATUS FROM student where firstname like '"+name+"%'"); model->setHeaderData(0, Qt::Horizontal, tr("Firstname")); model->setHeaderData(1, Qt::Horizontal, tr("Lastname")); model->setHeaderData(2,Qt::Horizontal,tr("Class")); model->setHeaderData(3,Qt::Horizontal,tr("Roll")); model->setHeaderData(4,Qt::Horizontal,tr("Status")); ui->tableView->setModel(model); } }
void mantenimientoTitulo::on_btmBuscar_clicked() { if(m_ui->btmTitulo->isChecked()) { QSqlQueryModel *model = new QSqlQueryModel(m_ui->titulos); model->setQuery("SELECT tituloObra, isbn FROM titulo WHERE tituloObra LIKE '%"+m_ui->busqueda->text()+"%';", QSqlDatabase::database("sibcues")); if (model->lastError().isValid()) qDebug() << model->lastError(); model->setHeaderData(0, Qt::Horizontal, QObject::tr("Titulo Material Bibliografico")); model->setHeaderData(1, Qt::Horizontal, QObject::tr("ISBN")); m_ui->titulos->setModel(model); connect(m_ui->titulos->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), this, SLOT(on_titulos_activated(QModelIndex))); m_ui->labelTitulo->setText("Titulos: "+QString::number(model->rowCount())+" resultados."); } else { QSqlQueryModel *model = new QSqlQueryModel(m_ui->titulos); model->setQuery("SELECT titulo.tituloObra, titulo.isbn FROM obrade left join titulo on titulo.idTitulo=obrade.idTitulo left join autor on obrade.idAutor=autor.idAutor WHERE autor.nombreAutor LIKE '%"+m_ui->busqueda->text()+"%';", QSqlDatabase::database("sibcues")); if (model->lastError().isValid()) qDebug() << model->lastError(); model->setHeaderData(0, Qt::Horizontal, QObject::tr("Titulo Material Bibliografico")); model->setHeaderData(1, Qt::Horizontal, QObject::tr("ISBN")); m_ui->titulos->setModel(model); connect(m_ui->titulos->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), this, SLOT(on_titulos_activated(QModelIndex))); m_ui->labelTitulo->setText("Titulos: "+QString::number(model->rowCount())+" resultados."); } }
mantenimientoTitulo::mantenimientoTitulo(int idUnidad, QWidget *parent) : QDialog(parent), m_ui(new Ui::mantenimientoTitulo) { m_ui->setupUi(this); m_ui->btmTitulo->setChecked(true); Persistencia::Persistencia *servicioPersistencia=new Persistencia(idUnidad); QSqlQueryModel *model = new QSqlQueryModel(m_ui->titulos); model->setQuery("SELECT tituloObra, isbn FROM titulo;", QSqlDatabase::database("sibcues")); if (model->lastError().isValid()) qDebug() << model->lastError(); //model->setTable("titulo"); //model->select(); model->setHeaderData(0, Qt::Horizontal, QObject::tr("Titulo Material Bibliografico")); model->setHeaderData(1, Qt::Horizontal, QObject::tr("ISBN")); m_ui->titulos->setModel(model); m_ui->titulos->alternatingRowColors(); //m_ui->titulos->hideColumn(0); m_ui->titulos->horizontalHeader()->resizeSection(0, 350); m_ui->titulos->setSelectionMode(QAbstractItemView::SingleSelection); connect(m_ui->titulos->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), this, SLOT(on_titulos_activated(QModelIndex))); m_ui->labelTitulo->setText("Titulos: "+QString::number(model->rowCount())+" resultados."); }
//! Loads all items from inventory into the table view in the window. void wndInventoryControl::refreshMasterList( void ) { QSqlQuery selectInventory; // If the filter category is all, do not condition SELECT query if ( _pUI->cmbCategoryFilter->currentText() == "[All]" ) { selectInventory.prepare( "SELECT * FROM inventory" ); } else // Otherwise, append the filter text to a condition in the query { selectInventory.prepare( "SELECT * FROM inventory WHERE category=?" ); selectInventory.addBindValue( _pUI->cmbCategoryFilter->currentText() ); } if ( _pDB->query( selectInventory ) ) { // Create a SQL Query Model for the QTableView QSqlQueryModel *model = new QSqlQueryModel; model->setQuery( selectInventory ); // Set header values model->setHeaderData( 0, Qt::Horizontal, tr( "Barcode" ) ); model->setHeaderData( 1, Qt::Horizontal, tr( "Name" ) ); model->setHeaderData( 2, Qt::Horizontal, tr( "Description" ) ); model->setHeaderData( 3, Qt::Horizontal, tr( "Category" ) ); // Set options for the QTableView _pUI->tblInventory->setModel( model ); _pUI->tblInventory->verticalHeader()->hide(); _pUI->tblInventory->horizontalHeader()->setResizeMode( 1, QHeaderView::Stretch ); _pUI->tblInventory->horizontalHeader()->setResizeMode( 2, QHeaderView::Stretch ); _pUI->tblInventory->horizontalHeader()->setResizeMode( 3, QHeaderView::Stretch ); } }
QSqlQueryModel * Mainwindow::modelback(QWidget * centralwidget) { QSqlQueryModel * model = new QSqlQueryModel(centralwidget); model->setQuery("select Num,Price from Room where Num in(select Num from Room where Live = 0)"); model->setHeaderData(0, Qt::Horizontal, QObject::tr("RoomNum")); model->setHeaderData(1, Qt::Horizontal, QObject::tr("Price")); return model; }
QSqlQueryModel * DatabaseHandler::getStuk4Associations() { QSqlQueryModel * model = new QSqlQueryModel; model->setQuery("SELECT code, category, description FROM stuk4_codes " "where type='ASS' AND code!='0' ORDER BY cast(code as integer)"); model->setHeaderData(0, Qt::Horizontal, "Code"); model->setHeaderData(1, Qt::Horizontal, "Kategorie"); model->setHeaderData(2, Qt::Horizontal, "Beschreibung"); return model; }
//点击喜爱歌曲按钮 void MusicWindow::favoriteSongs_Show() { QString loginName = "1"; QString loginName2 = "2"; QFile file("C:/Qt/Qt5.4.1/projects/QT_MusicPlayer/fiiles/user.txt"); QSqlQueryModel *model = new QSqlQueryModel; if(!file.open(QFile::ReadOnly | QFile::Text)) //只读打开 { QMessageBox::critical(0, tr("Tips"), tr("Local user file can not OPEN!")); return; } QTextStream in(&file); loginName = in.readLine(); file.close(); QFile file_previous("C:/Qt/Qt5.4.1/projects/QT_MusicPlayer/fiiles/user_previous.txt"); QTextStream in_previous(&file_previous); if(!file_previous.open(QFile::ReadOnly | QFile::Text)) //只读打开 { QMessageBox::critical(0, tr("Tips"), tr("Local user file can not OPEN!")); return; } loginName2 = in_previous.readLine(); file_previous.close(); if((loginName == loginName2) & (! loginName.isEmpty())) { LoginName = loginName; } else { QMessageBox::information(0, tr("Tips"), tr("You can check your favorite songs after you have logined!")); return; } model->setQuery(QString("select * from user_%1").arg(LoginName)); model->setHeaderData(0, Qt::Horizontal, tr("The name of songs")); model->setHeaderData(1, Qt::Horizontal, tr("The number of mark")); ui->favoriteView->setModel(model); ui->favoriteView->horizontalHeader()->setDefaultAlignment(Qt::AlignCenter); //表头居中 ui->favoriteView->setColumnWidth(0, 355);//设置固定列宽 ui->favoriteView->setColumnWidth(1, 355); titlePalette = ui->favoriteButton->palette(); titlePalette.setColor(QPalette::ButtonText, Qt::red); ui->favoriteButton->setPalette(titlePalette); titlePalette.setColor(QPalette::ButtonText,Qt::white); ui->storeButton->setPalette(titlePalette); ui->browserButton->setPalette(titlePalette); ui->webView->hide(); ui->storeView->hide(); ui->favoriteView->show(); }
void frmColaborador::refreshColaborador(){ QSqlQueryModel *model = new QSqlQueryModel; model->setQuery("SELECT pk_colaborador, col_nome, col_email FROM db_colaborador", ColaboradorDatabase::getInstance()); model->setHeaderData(0,Qt::Horizontal, tr("ID")); model->setHeaderData(1,Qt::Horizontal, tr("Nome")); model->setHeaderData(2,Qt::Horizontal, tr("Email")); ui->tbColaborador->setModel(model); ui->tbColaborador->setAlternatingRowColors(true); ui->tbColaborador->show(); }
void BadgeWindow::search() { DialogSearch searchDialog; int total; QString message; QString hours; QString minutes; QDate begin; QDate end; bool ok; QString own; //total = searchDialog.totalHours(ok); if (searchDialog.range(begin, end, own)) { DialogStatistics statistics; int overTime; BadgeData data; QMap <QString, QTime> activities; QSqlQueryModel *model; QString query; model = new QSqlQueryModel(); ok = true; total = data.totalTime(begin, end, overTime, /*activities,*/ workingTime, days); query = "select attivita.attivita, (sum((strftime('%H',time) * 3600) + (strftime('%M',time) * 60)) / 3600), ((sum((strftime('%H',time) * 3600) + (strftime('%M',time) * 60)) % 3600) /60) from attivita join task on (attivita.id=task.how) where task.day >= '"+ begin.toString("yyyy-MM-dd") + "' AND task.day <= '" + end.toString("yyyy-MM-dd") + "'"; if (own.size() > 0) query += " AND task.own='" + own + "'"; query += " group by attivita.attivita"; model->setQuery(query); model->setHeaderData(0, Qt::Horizontal, tr("Task")); model->setHeaderData(1, Qt::Horizontal, tr("Hours")); model->setHeaderData(2, Qt::Horizontal, tr("Minutes")); statistics.showStatistics(begin, end, total, overTime, model); delete model; /* hours.setNum(total.hour()); minutes.setNum(total.minute()); message = "Total time is: " + hours + " hours and " + minutes + " minutes"; QMessageBox::information(this, tr("Badge"), tr(message.toLatin1()));*/ } }
void Search::on_pushButton_clicked() { QSqlQueryModel *model = new QSqlQueryModel; model->setQuery("SELECT firstname, lastname, class, roll_no,STATUS FROM student"); model->setHeaderData(0, Qt::Horizontal, tr("Firstname")); model->setHeaderData(1, Qt::Horizontal, tr("Lastname")); model->setHeaderData(2,Qt::Horizontal,tr("Class")); model->setHeaderData(3,Qt::Horizontal,tr("Roll")); model->setHeaderData(4,Qt::Horizontal,tr("Status")); ui->tableView->setModel(model); }
void frmClients::on_tableView_clicked(const QModelIndex &index) { ui->ClientTabs->setVisible(true); ui->FIOEdit->setDisabled(true); ui->Nom_Edit->setDisabled(true); ui->dateEdit->setDisabled(true); ui->InfoEdit->setDisabled(true); ui->Pol->setDisabled(true); ui->OtkudaEdit->setDisabled(true); QModelIndex ID = ui->tableView->model()->index(index.row(),3); IDClients = ID.data().toInt(); frm->UpdateClients(IDClients); QSqlQuery query; query.prepare("SELECT FIO, nom_tel, Date_R, info, pol FROM Clients WHERE Clients.ID = :ID"); query.bindValue(":ID",IDClients); query.exec(); while (query.next()){ ui->FIOEdit->setText(query.value(0).toString()); ui->Nom_Edit->setText(query.value(1).toString()); ui->dateEdit->setDateCalendar(QDate::fromString(query.value(2).toString(),"dd.MM.yyyy")); ui->InfoEdit->setText(query.value(3).toString()); ui->Pol->setCurrentIndex(query.value(4).toInt()); } query.prepare("SELECT " " Clients_history.DATE_USLUGI, " " USLUGI.NAME, " " SUM(Clients_history.SUMMA) AS SUMMA, " " Clients_history.NUMBER " "FROM CLIENTS_HISTORY INNER JOIN USLUGI ON CLIENTS_HISTORY.ID_USLUGA = USLUGI.ID " "WHERE Clients_history.ID_CLIENT = :ID " "GROUP BY" " Clients_history.DATE_USLUGI, " " USLUGI.NAME, " " Clients_history.NUMBER " "ORDER BY " " Clients_history.NUMBER"); query.bindValue(":ID",IDClients); query.exec(); qDebug() << query.lastError(); QSqlQueryModel *model = new QSqlQueryModel; model->setQuery(query); model->setHeaderData(0,Qt::Horizontal,QObject::tr("Дата")); model->setHeaderData(1,Qt::Horizontal,QObject::tr("Услуга")); model->setHeaderData(2,Qt::Horizontal,QObject::tr("Сумма")); model->setHeaderData(3,Qt::Horizontal,QObject::tr("Ном. док.")); ui->tClient_history->setModel(model); ui->tClient_history->horizontalHeader()->setResizeMode(QHeaderView::Stretch); }
void AdminDialog::on_pushButton_2_clicked() { QString date = QDate::currentDate().toString("yyyy-MM-dd"); QSqlQueryModel *model = new QSqlQueryModel; QString sql = "select boid,bid,rid,overbor,botime,retime from borrow where isreturn=0 and retime<'"+date+"';"; model->setQuery(sql); 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); }
QSqlQueryModel * DatabaseHandler::getImageObjects(census * obj) { QSqlQueryModel * model = new QSqlQueryModel; QString qstr = "SELECT rcns_id, tp, ux, uy, max(censor), count(*) FROM view_census WHERE cam='" + obj->camera + "' AND img='" + obj->image + "' AND session='" + obj->session + "' AND (censor>0 OR censor IS NULL) GROUP BY rcns_id, tp, ux, uy ORDER BY rcns_id"; qDebug() << qstr; model->setQuery(qstr); model->setHeaderData(0, Qt::Horizontal, "Objekt Id"); model->setHeaderData(1, Qt::Horizontal, "Typ"); model->setHeaderData(2, Qt::Horizontal, "UTM X"); model->setHeaderData(3, Qt::Horizontal, "UTM Y"); model->setHeaderData(4, Qt::Horizontal, "Highest censor"); model->setHeaderData(5, Qt::Horizontal, "Censor count"); return model; }
void MainWindow::populate() { //QSqlQuery query; if (!QSqlDatabase::database().isOpen()) qDebug() << "Can't populate. Db not open."; QSqlQueryModel *model = new QSqlQueryModel; QString sql = "SELECT volunteer_firstname, " " volunteer_lastname" " FROM volunteer;"; model->setQuery(sql, _db); model->setHeaderData(0, Qt::Horizontal, tr("First Name")); model->setHeaderData(1, Qt::Horizontal, tr("Last Name")); tableView->setModel(model); }
void menusViewDialog::getMenusList(){ QSqlDatabase::database(); QSqlQueryModel *getMenus = new QSqlQueryModel; getMenus->setQuery("SELECT " "m.menu_id, " "m.name, " "m.altname, " "m.price, " "c.name, " "g.group_name, " "m.category_id, " "m.menu_group_id, " "g.deleted, " "c.deleted, " "m.deleted " "FROM " "menus m " "left join categories c on c.category_id = m.category_id " "left join menu_groups g on g.menu_group_id = m.menu_group_id " "WHERE " "c.deleted = 'false' " "AND g.deleted = 'false' " "AND m.deleted = 'false' "); getMenus->setHeaderData(0,Qt::Horizontal,QObject::trUtf8("Menu ID")); getMenus->setHeaderData(1,Qt::Horizontal,QObject::trUtf8("Menu Name")); getMenus->setHeaderData(2,Qt::Horizontal,QObject::trUtf8("Alt Name")); getMenus->setHeaderData(3,Qt::Horizontal,QObject::trUtf8("Price")); getMenus->setHeaderData(4,Qt::Horizontal,QObject::trUtf8("Category Name")); getMenus->setHeaderData(5,Qt::Horizontal,QObject::trUtf8("Menu Group Name")); getMenus->setHeaderData(6,Qt::Horizontal,QObject::trUtf8("Category ID")); getMenus->setHeaderData(7,Qt::Horizontal,QObject::trUtf8("Menu Group ID")); getMenus->setHeaderData(8,Qt::Horizontal,QObject::trUtf8("Group Deleted")); getMenus->setHeaderData(9,Qt::Horizontal,QObject::trUtf8("Category Deleted")); getMenus->setHeaderData(10,Qt::Horizontal,QObject::trUtf8("Menu Deleted")); // if(getMenus->lastError().isValid()) qDebug() << getMenus->lastError(); ui->menusTableView->setModel(getMenus); ui->menusTableView->hideColumn(6); ui->menusTableView->hideColumn(7); ui->menusTableView->hideColumn(8); ui->menusTableView->hideColumn(9); ui->menusTableView->hideColumn(10); qDebug() << "Get Menu List"; }
DodajArtikal::DodajArtikal(QWidget *parent) : QDialog(parent), ui(new Ui::DodajArtikal) { ui->setupUi(this); QSqlQueryModel *model = new QSqlQueryModel(); QTreeView *view = ui->tvArtikli; model->setQuery("SELECT ''"); model->setHeaderData(0, Qt::Horizontal, "Naziv"); view->setModel(model); }
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)); } } }
ViewParsedReferences::ViewParsedReferences(QWidget *parent) : QDialog(parent), ui(new Ui::ViewParsedReferences) { ui->setupUi(this); QSqlQueryModel *model = new QSqlQueryModel; model->setQuery("SELECT id,name FROM reference"); model->setHeaderData(0,Qt::Horizontal,tr("ID")); model->setHeaderData(1,Qt::Horizontal,tr("Identifier")); ui->tableView->setModel(model); ui->tableView->resizeColumnsToContents(); QHeaderView* header = ui->tableView->horizontalHeader(); header->setStretchLastSection(true); ui->tableView->setHorizontalHeader(header); ui->tableView->resizeRowsToContents(); ui->tableView->setColumnHidden(0,true); }
bool DatabaseHandler::getSpeciesList(QString type, QComboBox * cmb_box) { qDebug() << "Populating species list for " << type; QString qstr = "SELECT name_de, name_lat, euring_id, length FROM taxa LEFT JOIN " "(SELECT id_code, to_char(avg(length), 'FM99.99') as length FROM census WHERE tp='%1' GROUP BY id_code) as lt ON taxa.euring_id = lt.id_code " "WHERE type='%1' ORDER BY seaflag DESC, name_de"; QSqlQueryModel * model = new QSqlQueryModel; model->setQuery(qstr.arg(type)); qDebug() << qstr.arg(type); model->setHeaderData(0, Qt::Horizontal, "Deutscher Name"); model->setHeaderData(1, Qt::Horizontal, "Wissenschaftlicher Name"); model->setHeaderData(2, Qt::Horizontal, "EURING Code"); model->setHeaderData(3, Qt::Horizontal, QString::fromUtf8("Länge")); cmb_box->setModel(model); QTableView * view = new QTableView; cmb_box->setView(view); view->verticalHeader()->hide(); view->hideColumn(2); view->resizeColumnsToContents(); view->setSelectionMode(QAbstractItemView::SingleSelection); view->setSelectionBehavior(QAbstractItemView::SelectRows); view->setMinimumWidth(view->horizontalHeader()->length()); return true; }
//点击音乐库按钮 void MusicWindow::store_Show() { QSqlQueryModel *model = new QSqlQueryModel; model->setQuery("select * from music_songs"); model->setHeaderData(0, Qt::Horizontal, tr("The name of songs")); model->setHeaderData(1, Qt::Horizontal, tr("The number of mark")); ui->storeView->setModel(model); ui->storeView->horizontalHeader()->setDefaultAlignment(Qt::AlignCenter); //表头居中 ui->storeView->setColumnWidth(0, 355);//设置固定列宽 ui->storeView->setColumnWidth(1, 355); titlePalette = ui->storeButton->palette(); titlePalette.setColor(QPalette::ButtonText, Qt::red); ui->storeButton->setPalette(titlePalette); titlePalette.setColor(QPalette::ButtonText,Qt::white); ui->browserButton->setPalette(titlePalette); ui->favoriteButton->setPalette(titlePalette); ui->webView->hide(); ui->favoriteView->hide(); ui->storeView->show(); }
void mantenimientoTitulo::on_titulos_activated(QModelIndex index) { QString tituloSelecc=index.data(0).toString(); QSqlQueryModel *model = new QSqlQueryModel(m_ui->listaAutores); model->setQuery("SELECT autor.nombreAutor FROM obrade left join titulo on titulo.idTitulo=obrade.idTitulo left join autor on obrade.idAutor=autor.idAutor WHERE titulo.tituloObra=\""+tituloSelecc+"\";", QSqlDatabase::database("sibcues")); if (model->lastError().isValid()) qDebug() << model->lastError(); //model->setTable("titulo"); //model->select(); model->setHeaderData(0, Qt::Horizontal, QObject::tr("Titulo Material Bibliografico")); //model->setEditStrategy(QSqlTableModel::OnRowChange); //m_ui->titulos->setEditTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed); m_ui->listaAutores->setModel(model); m_ui->titulos->alternatingRowColors(); }
void Search::sh() { QSqlQueryModel *model = new QSqlQueryModel; model->setQuery("SELECT app_id,firstname, lastname, class, roll_no,STATUS FROM student "); model->setHeaderData(0, Qt::Horizontal, tr("ID")); model->setHeaderData(1, Qt::Horizontal, tr("Firstname")); model->setHeaderData(2,Qt::Horizontal,tr("Lastname")); model->setHeaderData(3,Qt::Horizontal,tr("Class")); model->setHeaderData(4,Qt::Horizontal,tr("roll_no")); model->setHeaderData(5,Qt::Horizontal,tr("Status")); ui->tableView->setModel(model); }
void FrmAlbaranProveedor::llenar_tabla_entregas() { QSqlQueryModel *modelEntregas = new QSqlQueryModel(this); modelEntregas->setQuery("select id, fecha_entrega, concepto, importe from proveedor_a_cuenta where id_proveedor = "+ QString::number(prov.id),Configuracion_global->groupDB); ui->tabla_entregas->setModel(modelEntregas); ui->tabla_entregas->setColumnHidden(0,true); ui->tabla_entregas->setColumnWidth(1,120); ui->tabla_entregas->setItemDelegateForColumn(1,new DateDelegate ); ui->tabla_entregas->setColumnWidth(2,400); ui->tabla_entregas->setColumnWidth(3,120); ui->tabla_entregas->setItemDelegateForColumn(3, new MonetaryDelegate); QStringList cabecera; cabecera << tr("id") << tr("Fecha entrega") << tr("Concepto") << tr("Importe"); for(int pos = 0; pos < cabecera.size();pos++) { modelEntregas->setHeaderData(pos,Qt::Horizontal,cabecera.at(pos)); } }
void EditArticle::journalSetup(QString entry) { QSqlQueryModel *sqlmodel = new QSqlQueryModel; QString wcard = entry; QString queryString = QString("SELECT * FROM JOURNAL WHERE NAME LIKE '\%%1\%'").arg(wcard); sqlmodel->setQuery(queryString); sqlmodel->setHeaderData(1,Qt::Horizontal,tr("Journal")); ui->tableView_2->setModel(sqlmodel); ui->tableView_2->resizeColumnsToContents(); QHeaderView* header2 = ui->tableView_2->horizontalHeader(); header2->setStretchLastSection(true); ui->tableView_2->setHorizontalHeader(header2); ui->tableView_2->setColumnHidden(0,true); }
void residuesFilialForm::getResiduesListFilial(){ //TODO: Create settings from column width QSqlDatabase::database(); QSqlQueryModel *dataViewFilial = new QSqlQueryModel; QString queryPrepare ;//= new QString; queryPrepare = QString("%1 %2 %3").arg("SELECT d.id, " "m.name, " "d.counts, " "d.countsp, " "d.orders, " "d.lastupdates, " "d.timeleft " "FROM ((dish d " "LEFT JOIN menu m ON ((m.id = d.menu))) " "LEFT JOIN users u ON ((u.id = d.users))) " "WHERE (((d.deleted = false) AND (m.deleted = false)) AND (u.deleted = false))").arg("AND d.users=").arg("1"); dataViewFilial->setQuery(queryPrepare); dataViewFilial->setHeaderData(0,Qt::Horizontal, QObject::trUtf8("ID")); dataViewFilial->setHeaderData(1,Qt::Horizontal, QObject::trUtf8("Menu")); dataViewFilial->setHeaderData(2,Qt::Horizontal, QObject::trUtf8("Count")); dataViewFilial->setHeaderData(3,Qt::Horizontal, QObject::trUtf8("Emergency Count")); dataViewFilial->setHeaderData(4,Qt::Horizontal, QObject::trUtf8("Orders")); dataViewFilial->setHeaderData(5,Qt::Horizontal, QObject::trUtf8("Latest Update")); dataViewFilial->setHeaderData(6,Qt::Horizontal, QObject::trUtf8("Expiry Date")); // dataViewFilial->setFilter("users=1"); qDebug() << dataViewFilial->query().lastQuery(); ui->filialTableView->setModel(dataViewFilial); ui->filialTableView->hideColumn(0); ui->filialTableView->setColumnWidth(1,350); ui->filialTableView->setColumnWidth(2,100); ui->filialTableView->setColumnWidth(3,110); ui->filialTableView->setColumnWidth(5,100); ui->filialTableView->setColumnWidth(6,100); ui->filialTableView->verticalHeader()->hide(); }
QSqlQueryModel * DatabaseHandler::getCloseObjects(census * obj) { QSqlQueryModel * model = new QSqlQueryModel; QString qstr = "SELECT sync_id FROM sync_utm32 WHERE cam" + obj->camera + "_id='" + obj->image + "'"; QSqlQuery query(qstr); int sync_id; if (query.next()) sync_id = query.value(0).toInt(); else { qDebug() << qstr; return model; } query.clear(); QStringList sidList = QStringList() << QString::number(sync_id-1) << QString::number(sync_id) << QString::number(sync_id+1); qstr = "SELECT cam, img FROM image_properties WHERE sync_id IN (" +sidList.join(",")+ ")"; query.exec(qstr); QStringList condList; while(query.next()) { condList.append("(cam='" + query.value(0).toString() + "' AND img='" +query.value(1).toString()+ "')"); } /* * TODO: Add distance comparison */ qstr = "SELECT rcns_id, cam, img, ux, uy, tp, " "ST_Distance( (SELECT ST_SetSRID(ST_Point(ux,uy),32632) FROM raw_census " "where rcns_id=" + QString::number(obj->id) + ") " ", ST_SetSRID(ST_Point(ux,uy),32632) ) as dist FROM raw_census " "WHERE (" + condList.join(" OR ") + ") AND rcns_id!=" + QString::number(obj->id) + " AND session='" + obj->session + "' ORDER BY dist"; qDebug() << qstr; model->setQuery(qstr); model->setHeaderData(0, Qt::Horizontal, "Object Id"); model->setHeaderData(1, Qt::Horizontal, "Kamera"); model->setHeaderData(2, Qt::Horizontal, "Bildnummer"); model->setHeaderData(3, Qt::Horizontal, "UTM X"); model->setHeaderData(4, Qt::Horizontal, "UTM Y"); model->setHeaderData(5, Qt::Horizontal, "Vorsortierung"); model->setHeaderData(6, Qt::Horizontal, "Entfernung in m"); return model; }