void WellDataManage
::loadWellData(QString projectAddress
) {
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 Comobox model
wellTypeComoBox->setModel(welldatamodel);
wellTypeComoBox->setModelColumn(welldatamodel->fieldIndex("welltype"));
//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->resizeRowsToContents();
// wellTableView->enabledChange(false);
// wellTableView->resizeColumnsToContents();
// wellTableView->horizontalHeader()->setStretchLastSection(true);
welldatamapper->setModel(welldatamodel);
//welldatamapper->setSubmitPolicy(QDataWidgetMapper::AutoSubmit);
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(wellTypeComoBox,6);
welldatamapper->addMapping(wellBeginDepthEdit,7);
welldatamapper->addMapping(wellEndDepthEdit,8);
welldatamapper->addMapping(wellAltitudeEdit,9);
//create connect of the buttons
welldatamapper->toFirst();//åˆå§‹åŒ–时选择选择第一行
connect(firstAction,SIGNAL(triggered()),welldatamapper,SLOT(toFirst()));
connect(lastAction,SIGNAL(triggered()),welldatamapper,SLOT(toLast()));
connect(previousAction,SIGNAL(triggered()),welldatamapper,SLOT(toPrevious()));
connect(nextAction,SIGNAL(triggered()),welldatamapper,SLOT(toNext()));
connect(newAction,SIGNAL(triggered()),this,SLOT(addWellRecord()));
connect(deleteAction,SIGNAL(triggered()),this,SLOT(deleteWellRecord()));
connect(updateAction,SIGNAL(triggered()),this,SLOT(updateWellRecord()));
connect(welldatamapper,SIGNAL(currentIndexChanged(int)),wellTableView,SLOT(selectRow (int)));
}
void WellDataManage::addWellRecord()
{
int row=welldatamapper->currentIndex();
welldatamapper->submit();
welldatamodel->insertRow(row);
welldatamapper->setCurrentIndex(row);
wellNameEdit->clear();
wellGroupEdit->clear();
wellXPositionEdit->clear();
wellYPositionEdit->clear();
wellBeginDepthEdit->clear();
wellEndDepthEdit->clear();
wellProductionEdit->clear();
wellTypeComoBox->clear();
wellNameEdit->setFocus();
}
void WellDataManage::deleteWellRecord()
{
int row=welldatamapper->currentIndex();
welldatamodel->removeRow(row);
welldatamapper->submit();
welldatamodel->submit();
//welldatamapper->setCurrentIndex(QMIN(row,welldatamodel->rowCount()-1));
}
void WellDataManage::updateWellRecord()
{
welldatamapper->submit();
//welldatamodel->submitAll();
}
void WellDataManage::loadWellData(QString projectAddress)
{
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 Comobox model
wellTypeComoBox->setModel(welldatamodel);
wellTypeComoBox->setModelColumn(welldatamodel->fieldIndex("welltype"));
//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->resizeRowsToContents();
// wellTableView->enabledChange(false);
// wellTableView->resizeColumnsToContents();
// wellTableView->horizontalHeader()->setStretchLastSection(true);
welldatamapper->setModel(welldatamodel);
//welldatamapper->setSubmitPolicy(QDataWidgetMapper::AutoSubmit);
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(wellTypeComoBox,6);
welldatamapper->addMapping(wellBeginDepthEdit,7);
welldatamapper->addMapping(wellEndDepthEdit,8);
welldatamapper->addMapping(wellAltitudeEdit,9);
//create connect of the buttons
welldatamapper->toFirst();//åˆå§‹åŒ–时选择选择第一行
connect(firstAction,SIGNAL(triggered()),welldatamapper,SLOT(toFirst()));
connect(lastAction,SIGNAL(triggered()),welldatamapper,SLOT(toLast()));
connect(previousAction,SIGNAL(triggered()),welldatamapper,SLOT(toPrevious()));
connect(nextAction,SIGNAL(triggered()),welldatamapper,SLOT(toNext()));
connect(newAction,SIGNAL(triggered()),this,SLOT(addWellRecord()));
connect(deleteAction,SIGNAL(triggered()),this,SLOT(deleteWellRecord()));
connect(updateAction,SIGNAL(triggered()),this,SLOT(updateWellRecord()));
connect(wellTableView->selectionModel(),SIGNAL(currentRowChanged(QModelIndex, QModelIndex)),welldatamapper,SLOT(setCurrentModelIndex(QModelIndex) ));
connect(welldatamapper,SIGNAL(currentIndexChanged(int)),wellTableView,SLOT(selectRow (int)));
}
void WellDataManage::addWellRecord()
{
int row=welldatamapper->currentIndex();
welldatamapper->submit();
welldatamodel->insertRow(row);
welldatamapper->setCurrentIndex(row);
wellNameEdit->clear();
wellGroupEdit->clear();
wellXPositionEdit->clear();
wellYPositionEdit->clear();
wellBeginDepthEdit->clear();
wellEndDepthEdit->clear();
wellProductionEdit->clear();
wellTypeComoBox->clear();
wellNameEdit->setFocus();
}
void WellDataManage::deleteWellRecord()
{
int row=welldatamapper->currentIndex();
welldatamodel->removeRow(row);
welldatamapper->submit();
welldatamodel->submit();
//welldatamapper->setCurrentIndex(QMIN(row,welldatamodel->rowCount()-1));
}
void WellDataManage::updateWellRecord()
{
welldatamapper->submit();
//welldatamodel->submitAll();
}
To copy to clipboard, switch view to plain text mode
Bookmarks