address+="//";
address+="Data";
address+="//";
address+="SystemData";
address+=".db3";
if (!QFile::exists(address
)) {
}
db.setDatabaseName(address);
db.open();
welldatamodel->setTable("wells");
welldatamodel->setSort(0,Qt::AscendingOrder);
//set header name
welldatamodel->setHeaderData(0,Qt::Horizontal,tr("Name"));
welldatamodel->setHeaderData(1,Qt::Horizontal,tr("Group"));
welldatamodel->setHeaderData(2,Qt::Horizontal,tr("X"));
welldatamodel->setHeaderData(3,Qt::Horizontal,tr("Y"));
welldatamodel->setHeaderData(4,Qt::Horizontal,tr("Type"));
welldatamodel->setHeaderData(5,Qt::Horizontal,tr("Production"));
welldatamodel->setHeaderData(6,Qt::Horizontal,tr("Depth"));
welldatamodel->setHeaderData(7,Qt::Horizontal,tr("BeginDepth"));
welldatamodel->setHeaderData(8,Qt::Horizontal,tr("EndDepth"));
welldatamodel->setHeaderData(9,Qt::Horizontal,tr("Altitude"));
welldatamodel->select();
welldatamodel->removeColumn(0);
wellTableView->setModel(welldatamodel);
// wellTableView->resizeColumnsToContents();
// wellTableView->horizontalHeader()->setStretchLastSection(true);
welldatamapper->setModel(welldatamodel);
welldatamapper->addMapping(wellNameEdit,0);
welldatamapper->addMapping(wellGroupEdit,1);
welldatamapper->addMapping(wellXPositionEdit,2);
welldatamapper->addMapping(wellYPositionEdit,3);
welldatamapper->addMapping(wellProductionEdit,5);
/*welldatamapper->addMapping(wellDepthEdit,6);*/
welldatamapper->addMapping(wellBeginDepthEdit,7);
welldatamapper->addMapping(wellEndDepthEdit,8);
welldatamapper->addMapping(wellAltitudeEdit,9);
//create connect of the buttons
connect(firstAction,SIGNAL(triggered()),welldatamapper,SLOT(toFirst()));
connect(lastAction,SIGNAL(triggered()),welldatamapper,SLOT(toLast()));
connect(previousAction,SIGNAL(triggered()),welldatamapper,SLOT(toLast()));
connect(nextAction,SIGNAL(triggered()),welldatamapper,SLOT(toNext()));
//connect(addAction,SIGNAL(triggered()),welldatamapper,SLOT())
QString address=projectAddress;
address+="//";
address+="Data";
address+="//";
address+="SystemData";
address+=".db3";
if (!QFile::exists(address))
{
QMessageBox::information(this,tr("Information"),tr("There is something wrong with the wells databases"),QMessageBox::Ok,QMessageBox::Ok);
}
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(address);
db.open();
welldatamodel = new QSqlRelationalTableModel;
welldatamodel->setTable("wells");
welldatamodel->setEditStrategy(QSqlTableModel::OnManualSubmit);
welldatamodel->setSort(0,Qt::AscendingOrder);
//set header name
welldatamodel->setHeaderData(0,Qt::Horizontal,tr("Name"));
welldatamodel->setHeaderData(1,Qt::Horizontal,tr("Group"));
welldatamodel->setHeaderData(2,Qt::Horizontal,tr("X"));
welldatamodel->setHeaderData(3,Qt::Horizontal,tr("Y"));
welldatamodel->setHeaderData(4,Qt::Horizontal,tr("Type"));
welldatamodel->setHeaderData(5,Qt::Horizontal,tr("Production"));
welldatamodel->setHeaderData(6,Qt::Horizontal,tr("Depth"));
welldatamodel->setHeaderData(7,Qt::Horizontal,tr("BeginDepth"));
welldatamodel->setHeaderData(8,Qt::Horizontal,tr("EndDepth"));
welldatamodel->setHeaderData(9,Qt::Horizontal,tr("Altitude"));
welldatamodel->select();
welldatamodel->removeColumn(0);
wellTableView->setModel(welldatamodel);
wellTableView->setSelectionBehavior(QAbstractItemView::SelectRows);
// wellTableView->resizeColumnsToContents();
// wellTableView->horizontalHeader()->setStretchLastSection(true);
welldatamapper->setSubmitPolicy(QDataWidgetMapper::AutoSubmit);
welldatamapper->setModel(welldatamodel);
welldatamapper->setItemDelegate(new QSqlRelationalDelegate(this));
welldatamapper->addMapping(wellNameEdit,0);
welldatamapper->addMapping(wellGroupEdit,1);
welldatamapper->addMapping(wellXPositionEdit,2);
welldatamapper->addMapping(wellYPositionEdit,3);
welldatamapper->addMapping(wellProductionEdit,5);
/*welldatamapper->addMapping(wellDepthEdit,6);*/
welldatamapper->addMapping(wellBeginDepthEdit,7);
welldatamapper->addMapping(wellEndDepthEdit,8);
welldatamapper->addMapping(wellAltitudeEdit,9);
//create connect of the buttons
connect(firstAction,SIGNAL(triggered()),welldatamapper,SLOT(toFirst()));
connect(lastAction,SIGNAL(triggered()),welldatamapper,SLOT(toLast()));
connect(previousAction,SIGNAL(triggered()),welldatamapper,SLOT(toLast()));
connect(nextAction,SIGNAL(triggered()),welldatamapper,SLOT(toNext()));
//connect(addAction,SIGNAL(triggered()),welldatamapper,SLOT())
To copy to clipboard, switch view to plain text mode
Bookmarks