Пример #1
1
void mainWindow::editGame()
{
    if(ui->tableGames->currentIndex().isValid())
    {
        QString console = ui->tableGames->model()->data(ui->tableGames->model()->index(ui->tableGames->currentIndex().row(), 0)).toString();
        QString title = ui->tableGames->model()->data(ui->tableGames->model()->index(ui->tableGames->currentIndex().row(), 1)).toString();
        QString annee = ui->tableGames->model()->data(ui->tableGames->model()->index(ui->tableGames->currentIndex().row(), 2)).toString();
        QString devs = ui->tableGames->model()->data(ui->tableGames->model()->index(ui->tableGames->currentIndex().row(), 3)).toString();

        QSqlTableModel* m = new QSqlTableModel();
        m->setTable("Consoles");
        m->removeColumn(0);
        m->select();

        QStringList list;

        for(int i = 0; i < m->rowCount(); i++)
        {
            list.append(m->record(i).value(0).toString());
        }
        list.removeDuplicates();

        editDialog* d = new editDialog(list, this, console, title, annee, devs);

        if(d->exec() == QDialog::Accepted)
        {
            QSqlQuery q;

            QString query = "UPDATE Games "
                    "SET console='" + d->console() + "', "
                    "titre='" + d->titre() + "', "
                    "annee='" + d->annee() + "', "
                    "devs='" + d->devs() + "' "
                    "WHERE console='" + console +"' AND titre='" + title + "' AND annee='"+ annee +
                    "' AND devs='" + devs + "';";

            q.exec(query);

            m_model->select();
        }
    }
}
Пример #2
0
void mainWindow::setupComboBox()
{
    QSqlTableModel* m = new QSqlTableModel();
    m->setTable("Consoles");
    m->removeColumn(0);
    m->select();

    QStringList list;

    for(int i = 0; i < m->rowCount(); i++)
    {
        list.append(m->record(i).value(0).toString());
    }
    list.removeDuplicates();
    list.sort();
    ui->comboConsole->clear();
    ui->comboConsole->addItems(list);
}
Пример #3
0
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);
}
Пример #4
0
void QSqlTableModel_snippets()
{
//! [24]
    QSqlTableModel *model = new QSqlTableModel;
    model->setTable("employee");
    model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    model->select();
    model->removeColumn(0); // don't show the ID
    model->setHeaderData(0, Qt::Horizontal, tr("Name"));
    model->setHeaderData(1, Qt::Horizontal, tr("Salary"));

    QTableView *view = new QTableView;
    view->setModel(model);
    view->show();
//! [24]

    {
//! [25]
    QSqlTableModel model;
    model.setTable("employee");
    QString name = model.record(4).value("name").toString();
//! [25]
    }
}
Пример #5
0
void MainWindow::createBars() {
    createActions();

    qpbMain = new QProgressBar;
        qpbMain->setMaximumSize( 150, 15 );
        qpbMain->setTextVisible( 0 );

    setStatusBar(qsbMain = new QStatusBar);
        qsbMain->showMessage( tr( "Ready" ));
        qsbMain->addPermanentWidget( qpbMain );

    setMenuBar( qmbMain = new QMenuBar );
        qmbMain->addMenu( qmFile = new QMenu( tr( "&File" )));
            qmFile->addSeparator();
            qmFile->addAction( qaPrintDialog );
            qmFile->addSeparator();
            qmFile->addAction( qaExit );
        qmbMain->addMenu( qmEdit = new QMenu( tr( "&Edit" )));
            qmEdit->addActions( qagNavigation->actions ());
            qmEdit->addAction( qaSearch );
            qmEdit->addMenu (qmSubEdit = new QMenu( tr( "Languages" )));
                qmSubEdit->addActions (qagLanguages->actions ());
        qmbMain->addMenu( qmView = new QMenu( tr( "&View" )));
            qmView->addActions ( qagZoom->actions ());
        qmbMain->addMenu( qmHelp = new QMenu( tr( "&Help" )));
            qmHelp->addAction( qaAboutQt );
            qmHelp->addSeparator();
            qmHelp->addAction( qaAbout );

    qtbDeleteSearch = new QToolButton(this);
        qtbDeleteSearch->setDefaultAction( qaClearSearch );
        qtbDeleteSearch->setToolTip( "Clear" );
        qtbDeleteSearch->setFocusPolicy( Qt::NoFocus );

    qleSearch = new QLineEdit;
        connect( qleSearch, SIGNAL( returnPressed ()), this, SLOT( lineSearch ()));
        connect( qleSearch, SIGNAL( returnPressed ()), this, SLOT( setSearchWord ()));

#if ( QT_VERSION >= 0x040700 )
        qleSearch->setPlaceholderText( tr( "Search" ));
#endif

    QSqlTableModel qstm;
        qstm.setTable("searchWords"); // table name
        qstm.removeColumn(0); // remove the id column
        qstm.removeColumn(2); // remove the numberofused column
        qstm.select();

    QCompleter::CompletionMode mode = QCompleter::InlineCompletion; // a new completer mode
    QCompleter *qcSearchWordHelp = new QCompleter(&qstm);
	qcSearchWordHelp->setCompletionMode(mode); // set the mode 
    qleSearch->setCompleter(qcSearchWordHelp);

    qtbMain = new QToolBar( "Toolbar" );
	qtbMain->setFloatable( false );
	qtbMain->setMovable( false );
        qtbMain->addAction( qaHome );
        qtbMain->addSeparator();
        qtbMain->addActions( qagNavigation->actions ());
	qtbMain->addSeparator();
	qtbMain->addWidget( qtbDeleteSearch );
        qtbMain->addWidget( qleSearch );
        addToolBar( qtbMain );
}