当前位置: 首页>>代码示例>>C++>>正文


C++ QSqlRelationalTableModel类代码示例

本文整理汇总了C++中QSqlRelationalTableModel的典型用法代码示例。如果您正苦于以下问题:C++ QSqlRelationalTableModel类的具体用法?C++ QSqlRelationalTableModel怎么用?C++ QSqlRelationalTableModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了QSqlRelationalTableModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

void ui_module_articulos::on_pushButton_eliminar_2_clicked()
{
   QModelIndexList  list = ui->tableView_articulos->selectionModel()->selectedRows();
    int filas = list.size();
   if(filas==0)
   {
       QMessageBox::information(this,"Error","Por favor, seleccione una fila para eliminar");
   }
   else
   {
       int rpta = QMessageBox::question(this,"Confirmación","Esta seguro de eliminar "+QString::number(filas)+" articulos?","Aceptar","Cancelar");

       if(rpta==0)
       {
           bool ok = true;
           for(int i=0;i<filas;i++)
           {
               QSqlRelationalTableModel * model = (QSqlRelationalTableModel*)ui->tableView_articulos->model();
               QSqlRecord record = model->record(list.at(i).row());

               object_e_articulo obj;
               obj.mf_load(record.value(COD).toString());

               obj.mf_set_habilitado(C_NO_HABILITADO);

               //Si ocurre un error
              if (!obj.mf_update())
              {
                ok = false;
              }
           }


           if(!ok)
           {
               //Mostramos mensaje de error
               QMessageBox::information(this,"Error",C_ERROR_ELIMINAR_ARTICULO)        ;


           }
           else
           {
               //No ocurre ningun error
              update_table_articulos();
           }



       }

   }

}
开发者ID:Darklink159,项目名称:Juanes,代码行数:53,代码来源:ui_module_articulos.cpp

示例2: QSqlRelationalTableModel

QSqlRelationalTableModel* EkonTables::createRelationalTableModel(QWidget *parentWidget, QString tableName, QStringList columnNames, QList<QPair<int, QSqlRelation> > relations)
{
    QSqlRelationalTableModel *tableModel = new QSqlRelationalTableModel(parentWidget, DbService::getInstance()->getCurrentDatabase());
    tableModel->setTable(tableName);

    for (auto relation : relations)
        tableModel->setRelation(relation.first, relation.second);

    configureTableModel(tableModel, columnNames);

    return tableModel;
}
开发者ID:pavelalexeenko,项目名称:Ekon,代码行数:12,代码来源:ekon_tables.cpp

示例3: QSqlRelationalTableModel

void ui_module_articulos::update_table_articulos()
{
    //Limipiamos el model anterior
    QAbstractItemModel * anteriorModel = ui->tableView_articulos->model();
    if(anteriorModel)
            delete anteriorModel;

    //Creamos el nuevo model
    QSqlRelationalTableModel * model = new QSqlRelationalTableModel();
    model->setTable(v_articuloProveedor);


  /* model->setRelation(GRUPO,QSqlRelation(e_grupo,pk_grupo,descripcion));
   model->setRelation(MARCA,QSqlRelation(e_marca,pk_marca,descripcion));
    model->setRelation(MEDIDA,QSqlRelation(e_medida,pk_medida,descripcion));
    model->setJoinMode(QSqlRelationalTableModel::LeftJoin);
    model->setFilter("habilitado=1");*/


    for(int i=0;i<num_header;i++)
    {
        model->setHeaderData(i,Qt::Horizontal,tableHeaders[i]);
    }

    if(model->select())
    {

            ui->tableView_articulos->setModel(model);
            ui->busqueda->setTableModel(model);


    }
    else
    {
        qDebug()<<model->query().lastError();
        qDebug()<<model->query().lastQuery();
        QMessageBox::information(this,"Error","Ocurrio un error al cargar la información");
    }

    //Ocultamos columnas
    ui->tableView_articulos->setColumnHidden(GRUPO,true);
    ui->tableView_articulos->setColumnHidden(HABILITADO,true);
    ui->tableView_articulos->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
    //qDebug()<<model->query().lastQuery()<<endl;
}
开发者ID:Darklink159,项目名称:Juanes,代码行数:45,代码来源:ui_module_articulos.cpp

示例4: form_edit_articulos

void ui_module_articulos::on_pushButton_editar_2_clicked()
{

    QModelIndexList  list = ui->tableView_articulos->selectionModel()->selectedRows();
    int filas = list.size();


    if(filas>1)
    {
        QMessageBox::information(this,"Error","Solo se puede editar una fila a la vez");
    }
    else
    {
        if(filas==0)
        {
            QMessageBox::information(this,"Error","Por favor, seleccione una fila para editar");
        }
        else
        {
            object_e_articulo  articulo;

            QSqlRelationalTableModel * model = (QSqlRelationalTableModel*)ui->tableView_articulos->model();
            QSqlRecord record = model->record(list.at(0).row());



            articulo.mf_set_pk_articulo(record.value(COD).toString());
            articulo.mf_set_descripcion(record.value(DESCRIPCION).toString());
            articulo.mf_set_fk_marca(record.value(MARCA).toString());
            articulo.mf_set_fk_grupo(record.value(GRUPO).toString());
            articulo.mf_set_fk_medida(record.value(MEDIDA).toString());
            articulo.mf_set_precio_lista(record.value(PRECIO).toString());
            articulo.mf_set_stock(record.value(STOCK).toString());


            ui_edit_articulo  form_edit_articulos(&articulo) ;
            form_edit_articulos.exec();


            //Actualizamos la tabla de articulos
            update_table_articulos();
        }
    }

}
开发者ID:Darklink159,项目名称:Juanes,代码行数:45,代码来源:ui_module_articulos.cpp

示例5: rootModelIndex

void MainWindow::addOrEditTreeItem(DialogMode mode, TreeItem treeItem, const QModelIndex &index)
{
    const int eventsTableRow = rootModelIndex(index).row();
    int eventsTableColumn = -1;
    int itemTableNameColumn = -1;
    QSqlRelationalTableModel *tableModel = 0;
    SqlRelationalTableDialog *tableDialog = 0;

    switch (treeItem) {
    case CharacterItem:
        eventsTableColumn = 2;
        itemTableNameColumn = 1;
        tableModel = database->characters();
        tableDialog = new CharacterDialog(tableModel, this);
        break;

    case ConversationItem:
        eventsTableColumn = 3;
        itemTableNameColumn = 3;
        tableModel = database->conversations();
        tableDialog = new ConversationDialog(tableModel, this);
        break;
    }

    QModelIndex eventsIndex =
        database->events()->index(eventsTableRow, eventsTableColumn);
    const QString &conversation = eventsIndex.data().toString();

    QModelIndex firstItem =
        tableModel->index(0, itemTableNameColumn);
    QModelIndexList itemIndexes =
        tableModel->match(firstItem, Qt::DisplayRole, conversation);

    //Q_ASSERT(!itemIndexes.isEmpty());
    //if (itemIndexes.isEmpty())
    //    return;

    QModelIndex itemIndex;
    if (!itemIndexes.isEmpty())
        itemIndex = itemIndexes.first();

    editViewItem(itemIndex, tableDialog, mode);
}
开发者ID:MikeMcQuaid,项目名称:Fabula,代码行数:43,代码来源:MainWindow.cpp

示例6: 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);
}
开发者ID:BarsukAlexey,项目名称:xelarogi,代码行数:40,代码来源:handbookdialog.cpp

示例7: 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);
    }
}
开发者ID:VictorCarlquist,项目名称:GSMESAP,代码行数:34,代码来源:mysqlrelationaldelegate.cpp

示例8: QWidget

TaskCheckBox::TaskCheckBox(SideBarTask* sidebar, int row, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::taskWidget), sidebar(sidebar)
{
    this->row = row;
    ui->setupUi(this);
    setStyleSheet(TaskCheckBox::defaultCSS);
    removeTaskBtn = new QPushButton("X");
    checkbox = new QCheckBox();
    taskName = new QLabel;
    termDate = new TermDate;
    priority = new Priority;

    ui->taskLayout->addWidget(checkbox,1);
    ui->taskLayout->addWidget(priority, 0, Qt::AlignLeft);
    ui->taskLayout->addWidget(taskName,10);
    ui->taskLayout->addWidget(new QLabel(""));
    ui->taskLayout->addWidget(termDate, 0, Qt::AlignLeft);
    ui->taskLayout->addWidget(removeTaskBtn, 0, Qt::AlignLeft);

    QSqlRelationalTableModel* model = Task::getInstance()->getModel();
    mapper = new QDataWidgetMapper(this);
    mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
    mapper->setModel(model);

    mapper->addMapping(taskName, model->fieldIndex("name"), "text");
    mapper->addMapping(termDate, model->fieldIndex("termDate"));
    mapper->addMapping(checkbox, model->fieldIndex("isFinished"));
    mapper->addMapping(priority, model->fieldIndex("priority"));


//    priority->setText(QString::number(row)); // DEBUG
    mapper->setCurrentIndex(row);

    connect(checkbox, SIGNAL(stateChanged(int)), mapper, SLOT(submit()));
    connect(this,SIGNAL(editTask(int)), sidebar, SLOT(loadTask(int)));
    connect(removeTaskBtn, SIGNAL(clicked()), this, SLOT(onRemoveTaskClicked()));
}
开发者ID:paulnta,项目名称:ProAgenda,代码行数:38,代码来源:taskcheckbox.cpp

示例9: QDialog

SQLOpenProjectDialog::SQLOpenProjectDialog(const QString & host, unsigned int port, const QString & dbname, const QString & user, const QString & password,QWidget *parent) :
    QDialog(parent),
    ui(new Ui::SQLOpenProjectDialog)
{
    ui->setupUi(this);
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    m_Host=host;
    m_Port=port;
    m_DBName=dbname;
    m_User=user;
    m_Password=password;

    db.setHostName(m_Host);
    db.setPort(m_Port);
    db.setDatabaseName(m_DBName);
    db.setUserName(m_User);
    db.setPassword(m_Password);

    bool ok=db.open();


    std::cout << db.lastError().databaseText().toStdString() << std::endl;


    if(ok){
    	QSqlRelationalTableModel *model = new QSqlRelationalTableModel(this,db);
    	model->setTable("Project");
    	model->setEditStrategy(QSqlTableModel::OnRowChange);
    	model->select();
    	ui->existingProjectsTableView->setModel(model);
    }else{

    }

    m_Accepted=false;
    m_Project=0;
}
开发者ID:BioinformaticsArchive,项目名称:TTT,代码行数:37,代码来源:tttsqlopenprojectdialog.cpp

示例10: QWidget

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    resize(400,300);
    if(connect())
    {
        QTableView *view = new QTableView(this);
        QSqlRelationalTableModel *model = new QSqlRelationalTableModel;//要先有数据才能创建model,也就是先连接数据库局
        view->setGeometry(0,0,400,300);

        view->setModel(model);
        model->setTable("student");
        model->setSort(0,Qt::AscendingOrder);
//        model->setHeaderData(0,Qt::Horizontal,"Name");//from 0
//        model->setHeaderData(1,Qt::Horizontal,"Age");
//        model->setHeaderData(2,Qt::Horizontal,"likes");
        model->setRelation(3,QSqlRelation("city","id","name"));
        model->select();


//        view->setModel(model);

        view->setSelectionMode(QAbstractItemView::SingleSelection);//设置选择模式
        view->setSelectionBehavior(QAbstractItemView::SelectRows);//选择行
//        view->resizeColumnsToContents();//tiaozhengziti
        view->setEditTriggers(QAbstractItemView::DoubleClicked);//不可编辑?

        QHeaderView *header =  view->horizontalHeader();
        header->setStretchLastSection(true);
        view->setItemDelegate(new QSqlRelationalDelegate(view));
//        QHeaderView *head = view->verticalHeader();
//        head->setStretchLastSection(true);
//        view->show();
//        this?->show();
    }
}
开发者ID:youngjeff,项目名称:qt,代码行数:36,代码来源:widget.cpp

示例11: QSqlRelationalTableModel

void BadgeWindow::timer()
{
    DialogTimer dialogTimer;

    bool saveRequest;
    QString taskName;
    QTime elapsedTime;

    saveRequest = dialogTimer.getTaskInfo(taskName, elapsedTime);

    if (saveRequest) {
        DialogTask dialog;
        QSqlRelationalTableModel *taskModel;

        taskModel = new QSqlRelationalTableModel();

        taskModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
        taskModel->setTable("task");
        qDebug() << "Day" << QDate::currentDate().toString("yyyy-MM-dd") << endl;
        taskModel->setFilter("day='" + QDate::currentDate().toString("yyyy-MM-dd") + "'");
        //taskModel.setEditStrategy(QSqlTableModel::OnFieldChange);
        taskModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
        taskModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Date"));
        taskModel->setHeaderData(2, Qt::Horizontal, QObject::tr("Elapsed"));
        //taskModel->setHeaderData(3, Qt::Horizontal, QObject::tr("Attivita'"));
        taskModel->setRelation(3, QSqlRelation("attivita", "id", "attivita"));

        taskModel->select();

        // TODO: if current date don't exist create it


        dialog.openTask("Task", "Elapsed", taskModel, QDate::currentDate(), "task", elapsedTime, taskName);

        delete taskModel;
    }
}
开发者ID:BackupTheBerlios,项目名称:qbadgetask,代码行数:37,代码来源:badgewindow.cpp

示例12: main

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;

    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    if(!createConnection(db))
        return 1;
/*
    QSqlQueryModel * mode = new QSqlQueryModel;
    mode->setQuery("select prod_id, vend_name, prod_name, prod_price from products, vendors where products.vend_id = vendors.vend_id", db);
    mode->setHeaderData(0, Qt::Horizontal, "prod_id");
    mode->setHeaderData(1, Qt::Horizontal, "vend_name");
    mode->setHeaderData(2, Qt::Horizontal, "prod_name");
    mode->setHeaderData(3, Qt::Horizontal, "prod_price");
*/

    QSqlRelationalTableModel * mode =
            new QSqlRelationalTableModel;
    mode->setTable("products");
    QSqlRelation relation("vendors",
                          "vend_id",
                          "vend_name");

    mode->setRelation(1, relation);
    mode->select();
    mode->setHeaderData(0, Qt::Horizontal, "prod_id");
    mode->setHeaderData(1, Qt::Horizontal, "vend_name");
    mode->setHeaderData(2, Qt::Horizontal, "prod_name");
    mode->setHeaderData(3, Qt::Horizontal, "prod_price");

    QTableView * tableview = new QTableView(&w);
    tableview->verticalHeader()->hide();
    tableview->setModel(mode);

    w.setCentralWidget(tableview);
    w.resize(600, 400);
    w.show();
    
    return a.exec();
}
开发者ID:hemiao3000,项目名称:code,代码行数:41,代码来源:main.cpp

示例13: QSqlQueryModel

void CarsEdit::FillTable()
{
    QString str_oper = "SELECT hm_cars.id, hm_cars.name, hm_cars.speed, hm_fuel.name, hm_fuel.id FROM hm_cars INNER JOIN hm_fuel ON hm_cars.fuel_id = hm_fuel.id;";
    QSqlQueryModel * model_Oper = new QSqlQueryModel(0);
    model_Oper->setQuery(str_oper);
    model_Oper->setHeaderData(1, Qt::Horizontal, QObject::trUtf8("Название автомобиля"));
    model_Oper->setHeaderData(2, Qt::Horizontal, QObject::trUtf8("Максимальная скорость"));
    model_Oper->setHeaderData(3, Qt::Horizontal, QObject::trUtf8("Тип топлива"));
    ui->tableView->setModel(model_Oper);
    ui->tableView->hideColumn(0);
    ui->tableView->hideColumn(4);

    QSqlRelationalTableModel *comboModel = new QSqlRelationalTableModel(0);
    comboModel->setTable("hm_fuel");
    int comboIndex = comboModel->fieldIndex("id");
    comboModel->setRelation(comboIndex, QSqlRelation("hm_fuel", "id", "name"));
    comboModel->select();
    QSqlTableModel *comboRelModel = comboModel->relationModel(comboIndex);
    ui->comboBox->setModel(comboRelModel);
    ui->comboBox->setModelColumn(comboRelModel->fieldIndex("name"));
}
开发者ID:Berimor66,项目名称:humblemaps,代码行数:21,代码来源:carsedit.cpp

示例14: QMainWindow

/*
** public:
*/
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , m_timer(new QBasicTimer)
    , m_dataProvider(new DataProvider(this))
    , m_dialogSettings(0) // Guarded by QPointer
    , m_dialogAbout(0)    // Guarded by QPointer
{
    qDebug() << Q_FUNC_INFO;

/*
    m_dataModel = new QStandardItemModel(this);
    m_dataModel->setColumnCount(5);
*/
    setupUi(this);

/*
    QStringList labels;
    labels << tr("Show name") << tr("Episode name")
           << tr("Season #") << tr("Episode #") << tr("Date");
    m_dataModel->setHorizontalHeaderLabels(labels);
//    showsTableView->setModel(m_dataModel);
    showsTableView->setModel(DbInterface::instance().readEpisodes());
    showsTableView->verticalHeader()->hide();
    showsTableView->horizontalHeader()->setResizeMode(QHeaderView::Interactive);
    showsTableView->horizontalHeader()->setStretchLastSection(true);
    showsTableView->horizontalHeader()->setCascadingSectionResizes(true);
    showsTableView->horizontalHeader()->setHighlightSections(true);
    showsTableView->horizontalHeader()->setMovable(true);

    srand(QTime::currentTime().toString("hhmmsszzz").toUInt());

    // Fill with random stuff
    for (int i=0; i<30; ++i) {
        m_dataModel->setItem(i, 0, new QStandardItem(QString("show_%1").arg(i)));
        m_dataModel->setItem(i, 1, new QStandardItem(QString("episode_%1").arg(i)));
        m_dataModel->setItem(i, 2, new QStandardItem(QString("%1").arg(rand()%10+1)));
        m_dataModel->setItem(i, 3, new QStandardItem(QString("%1").arg(rand()%24+1)));
        QDate rndDate = QDate::currentDate().addDays(i);
        m_dataModel->setItem(i, 4, new QStandardItem(rndDate.toString("yyyy/MM/dd")));
    }
*/

    setWindowTitle(QString("nextShows - v%1").arg(NEXTSHOWS_VERSION));
    statusBar()->showMessage(tr("nextShows started"), 1000*3);


    // TEMPORARY CODE FOR TESTING ////////////////////////////////////////////
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", "NS_View");
    db.setDatabaseName("ns.db");
    db.open();
    QSqlRelationalTableModel *model = new QSqlRelationalTableModel(this, db);
    model->setTable("T_Episodes");
    model->setRelation(model->fieldIndex("shows_id"),
                       QSqlRelation("T_Shows", "idT_Shows", "ShowName"));
    model->setSort(model->fieldIndex("Date"), Qt::AscendingOrder);
    model->select();

    QStringList hideFields;
    hideFields << "idT_Episodes" << "ProdNumber" << "EpisodeCount"
               << "EpisodeUrl"   << "isSpecial";
    foreach (QString field, hideFields) {
        model->removeColumn(model->fieldIndex(field));
    }
开发者ID:gilcn,项目名称:nextshows,代码行数:66,代码来源:mainwindow.cpp

示例15: QSqlRelationalTableModel

QSqlRelationalTableModel * AddStoragePlace::getBoxModel(QString tableName) {
    QSqlRelationalTableModel *m = new QSqlRelationalTableModel();
    m->setTable(tableName);
    m->select();
    return m;
}
开发者ID:pavelrudenya,项目名称:OsnSredstv,代码行数:6,代码来源:addstorageplace.cpp


注:本文中的QSqlRelationalTableModel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。