void MainWindow::on_FlowpathcopyPB_clicked()
{
//******************************************************************
//* This functions takes the currently selected flowpath, *
//* prompts for a new name, and makes a copy of the data sets... *
//******************************************************************
QModelIndex old_index
= ui
->FlowpathTV
->currentIndex
();
QSqlRecord old_record
= flowpathmodel
->record
(old_index.
row ());
int old_fp_id = old_record.value ("flowpath_id").toInt();
if (old_index.isValid ())
{
on_FlowpathnewPB_clicked ();
//*****************************************************
//* Here we have the ID from the copied flowpath *
//* and the new ID of the new flowpath...Use *
//* these to cycle thru the associated data sets... *
//*****************************************************
QModelIndex new_index
= ui
->FlowpathTV
->currentIndex
();
QSqlRecord new_record
= flowpathmodel
->record
(new_index.
row ());
int new_fp_id = new_record.value ("flowpath_id").toInt ();
//*******************************************************
//* Reset the index to the original flowdata model... *
//*******************************************************
ui->FlowdatanewPB->setEnabled (true);
ui->FlowdatarevertPB->setEnabled (true);
ui->FlowdatasavePB->setEnabled (true);
flowdatamodel->setFilter(
QString("flowdata_flowpath_id = %1").
arg(old_fp_id
));
int num_rows_old = flowdatamodel->rowCount ();
int row = num_rows_old;
for (int i = 0; i < num_rows_old; i++)
{
//**************************************************
//* Get the records from the set to copy from... *
//**************************************************
old_index = flowdatamodel->index (i, 0);
old_record = flowdatamodel->record (old_index.row ());
flowdatamodel->insertRow(row);
flowdatamodel->setData (flowdatamodel->index (row, 0),
old_record.value("flowdata_od").toReal ());
flowdatamodel->setData (flowdatamodel->index (row, 1),
old_record.value("flowdata_id").toReal ());
flowdatamodel->setData (flowdatamodel->index (row, 2),
old_record.value("flowdate_yield").toReal ());
flowdatamodel->setData (flowdatamodel->index (row, 3),
old_record.value("flowdate_emod").toReal ());
flowdatamodel->setData (flowdatamodel->index (row, 4),
old_record.value("flowdate_val_gap").toReal ());
flowdatamodel->setData (flowdatamodel->index (row, 5),
old_record.value("flowdata_val_offset").toReal ());
flowdatamodel->setData (flowdatamodel->index (row, 6),
old_record.value("flowdate_string").toString ());
flowdatamodel->setData (flowdatamodel->index (row, 7),
old_record.value("flowdata_seq_no").toInt ());
flowdatamodel->setData (flowdatamodel->index (row, 8), user);
flowdatamodel->setData (flowdatamodel->index (row, 9),
flowdatamodel->setData (flowdatamodel-> index (row, 10), new_fp_id);
new_index = flowdatamodel->index (row, 0);
ui->FlowdataTV->setCurrentIndex (new_index);
ui->FlowdataTV->edit (new_index);
ui->FlowdataTV->resizeColumnsToContents ();
ui->FlowdataTV->setColumnHidden (7, true);
ui->FlowdataTV->setColumnHidden (10, true);
ui->FlowdataTV->horizontalHeader ()->setVisible (true);
++row;
}
new_index = ui->FlowpathTV->currentIndex ();
refresh_FlowdataView ();
}
}
void MainWindow::on_FlowpathcopyPB_clicked()
{
//******************************************************************
//* This functions takes the currently selected flowpath, *
//* prompts for a new name, and makes a copy of the data sets... *
//******************************************************************
QModelIndex old_index = ui->FlowpathTV->currentIndex ();
QSqlRecord old_record = flowpathmodel->record (old_index.row ());
int old_fp_id = old_record.value ("flowpath_id").toInt();
if (old_index.isValid ())
{
on_FlowpathnewPB_clicked ();
//*****************************************************
//* Here we have the ID from the copied flowpath *
//* and the new ID of the new flowpath...Use *
//* these to cycle thru the associated data sets... *
//*****************************************************
QModelIndex new_index = ui->FlowpathTV->currentIndex ();
QSqlRecord new_record = flowpathmodel->record (new_index.row ());
int new_fp_id = new_record.value ("flowpath_id").toInt ();
//*******************************************************
//* Reset the index to the original flowdata model... *
//*******************************************************
ui->FlowdatanewPB->setEnabled (true);
ui->FlowdatarevertPB->setEnabled (true);
ui->FlowdatasavePB->setEnabled (true);
flowdatamodel->setFilter(
QString("flowdata_flowpath_id = %1").arg(old_fp_id));
int num_rows_old = flowdatamodel->rowCount ();
int row = num_rows_old;
for (int i = 0; i < num_rows_old; i++)
{
//**************************************************
//* Get the records from the set to copy from... *
//**************************************************
old_index = flowdatamodel->index (i, 0);
old_record = flowdatamodel->record (old_index.row ());
flowdatamodel->insertRow(row);
flowdatamodel->setData (flowdatamodel->index (row, 0),
old_record.value("flowdata_od").toReal ());
flowdatamodel->setData (flowdatamodel->index (row, 1),
old_record.value("flowdata_id").toReal ());
flowdatamodel->setData (flowdatamodel->index (row, 2),
old_record.value("flowdate_yield").toReal ());
flowdatamodel->setData (flowdatamodel->index (row, 3),
old_record.value("flowdate_emod").toReal ());
flowdatamodel->setData (flowdatamodel->index (row, 4),
old_record.value("flowdate_val_gap").toReal ());
flowdatamodel->setData (flowdatamodel->index (row, 5),
old_record.value("flowdata_val_offset").toReal ());
flowdatamodel->setData (flowdatamodel->index (row, 6),
old_record.value("flowdate_string").toString ());
flowdatamodel->setData (flowdatamodel->index (row, 7),
old_record.value("flowdata_seq_no").toInt ());
flowdatamodel->setData (flowdatamodel->index (row, 8), user);
flowdatamodel->setData (flowdatamodel->index (row, 9),
QDateTime::currentDateTime ());
flowdatamodel->setData (flowdatamodel-> index (row, 10), new_fp_id);
new_index = flowdatamodel->index (row, 0);
ui->FlowdataTV->setCurrentIndex (new_index);
ui->FlowdataTV->edit (new_index);
ui->FlowdataTV->resizeColumnsToContents ();
ui->FlowdataTV->setColumnHidden (7, true);
ui->FlowdataTV->setColumnHidden (10, true);
ui->FlowdataTV->horizontalHeader ()->setVisible (true);
++row;
}
new_index = ui->FlowpathTV->currentIndex ();
refresh_FlowdataView ();
}
}
To copy to clipboard, switch view to plain text mode
void MainWindow::refresh_FlowdataView()
{
//**********************************************************
//* This function is called to display the flowdata data *
//* set that are related to a particular flowpath... *
//**********************************************************
if (index.isValid ())
{
QSqlRecord record
= flowpathmodel
->record
(index.
row ());
int fp_id = record.value ("flowpath_id").toInt();
//*****************************************************
//* Now we want to find out if this is new data *
//* or not as we can't allow editing of old data... *
//*****************************************************
if (sqldb.numflowdatasetsDB (fp_id) > 0)
{
ui->FlowdatanewPB->setEnabled (false);
ui->FlowdatarevertPB->setEnabled (false);
ui->FlowdatasavePB->setEnabled (false);
}
else
{
ui->FlowdatanewPB->setEnabled (true);
ui->FlowdatarevertPB->setEnabled (true);
ui->FlowdatasavePB->setEnabled (true);
}
flowdatamodel
->setFilter
(QString("flowdata_flowpath_id = %1").
arg(fp_id
));
}
else
{
flowdatamodel->setFilter ("flowdata_flowpath_id = -1");
}
flowdatamodel->select ();
ui->FlowdataTV->horizontalHeader ()->setVisible (
flowdatamodel->rowCount () > 0);
}
void MainWindow::refresh_FlowdataView()
{
//**********************************************************
//* This function is called to display the flowdata data *
//* set that are related to a particular flowpath... *
//**********************************************************
QModelIndex index = ui->FlowpathTV->currentIndex ();
if (index.isValid ())
{
QSqlRecord record = flowpathmodel->record (index.row ());
int fp_id = record.value ("flowpath_id").toInt();
//*****************************************************
//* Now we want to find out if this is new data *
//* or not as we can't allow editing of old data... *
//*****************************************************
if (sqldb.numflowdatasetsDB (fp_id) > 0)
{
ui->FlowdatanewPB->setEnabled (false);
ui->FlowdatarevertPB->setEnabled (false);
ui->FlowdatasavePB->setEnabled (false);
}
else
{
ui->FlowdatanewPB->setEnabled (true);
ui->FlowdatarevertPB->setEnabled (true);
ui->FlowdatasavePB->setEnabled (true);
}
flowdatamodel->setFilter(QString("flowdata_flowpath_id = %1").arg(fp_id));
}
else
{
flowdatamodel->setFilter ("flowdata_flowpath_id = -1");
}
flowdatamodel->select ();
ui->FlowdataTV->horizontalHeader ()->setVisible (
flowdatamodel->rowCount () > 0);
}
To copy to clipboard, switch view to plain text mode
Bookmarks