26 setWindowTitle( tr(
"Buffer Management" ) );
28 setAttribute( Qt::WA_DeleteOnClose );
34 gray.setColor( QPalette::Base, QColor( 0xe0, 0xe0, 0xe0 ) );
38 QGridLayout*
main =
new QGridLayout(
this );
39 main->setSpacing ( 2 );
40 main->setContentsMargins ( 2, 2, 2, 2 );
43 if ( DB.isEmpty() ) DB <<
"Undefined";
44 QLabel* lb_DB =
us_banner( tr(
"Database: " ) + DB.at( 0 ) );
46 main->addWidget( lb_DB, row++, 0, 1, 3 );
48 QPushButton* pb_investigator =
us_pushbutton( tr(
"Select Investigator" ) );
50 main->addWidget( pb_investigator, row++, 0 );
53 pb_investigator->setEnabled(
false );
55 QBoxLayout* lo_search =
new QHBoxLayout;
58 QLabel* lb_search =
us_label( tr(
"Search:" ) );
59 lo_search->addWidget( lb_search );
63 connect(
le_search, SIGNAL( textChanged(
const QString& ) ),
64 SLOT (
search (
const QString& ) ) );
66 main->addLayout( lo_search, row++, 0 );
70 tr(
"Doubleclick on buffer data to select" ), -2 );
72 main->addWidget( lb_banner1, row++, 0 );
75 connect(
lw_buffer_db, SIGNAL( itemDoubleClicked( QListWidgetItem* ) ),
82 QHBoxLayout* desc =
new QHBoxLayout;
84 QLabel* lb_description =
us_label( tr(
"Buffer Description:" ) );
85 desc->addWidget( lb_description );
91 p.setColor( QPalette::Base, p.color( QPalette::WindowText ) );
92 p.setColor( QPalette::Button, p.color( QPalette::Window ) );
93 p.setColor( QPalette::Text, p.color( QPalette::Window ) );
95 shared->itemAt( 0 )->widget()->setPalette( p );
96 shared->itemAt( 1 )->widget()->setPalette( p );
98 desc->addLayout( shared );
100 main->addLayout( desc, row++, 0 );
102 QLabel* lb_guid =
us_label( tr(
"Global Identifier:" ) );
103 main->addWidget( lb_guid, row++, 0 );
105 QLabel* lb_buffer1 =
us_label( tr(
"Please select a Buffer Component:" ) );
107 main->addWidget( lb_buffer1, row++, 0 );
113 QLabel* lb_banner2 =
us_banner( tr(
"Click on item to select" ), -2 );
115 main->addWidget( lb_banner2, row++, 0 );
127 for (
int i = 0; i < keys.size(); i++ )
129 QString key = keys[ i ];
135 width =
max( fm.width( s ), width );
140 lw_ingredients->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
149 QPushButton* pb_synch =
us_pushbutton( tr(
"Synch components with DB" ) );
151 main->addWidget( pb_synch, row++, 0 );
155 QString bufcmp = etcdir +
"bufferComponents.xml";
156 QFileInfo fi( bufcmp );
157 pb_synch->setEnabled( ( !fi.exists() && QFileInfo( etcdir ).isWritable() )
158 || fi.isWritable() );
178 QLabel* lb_banner3 =
us_banner( tr(
"Database/Disk Functions" ), -2 );
180 main->addWidget( lb_banner3, row++, 1, 1, 2 );
182 QPushButton* pb_query =
us_pushbutton( tr(
"Query Descriptions" ) );
183 connect( pb_query, SIGNAL( clicked() ), SLOT(
query() ) );
184 main->addWidget( pb_query, row, 1 );
187 connect(
pb_save, SIGNAL( clicked() ), SLOT(
save() ) );
188 main->addWidget(
pb_save, row++, 2 );
196 main->addWidget(
pb_del, row++, 2 );
200 tr(
"Density (20" ) +
DEGC + tr(
", g/cm<sup>3</sup>):" ) );
201 main->addWidget( lb_density, row, 1 );
204 connect(
le_density, SIGNAL( textEdited(
const QString& ) ),
205 SLOT (
density (
const QString& ) ) );
208 QLabel* lb_viscosity =
209 us_label( tr(
"Viscosity (20" ) +
DEGC + tr(
", cp):" ) );
210 main->addWidget( lb_viscosity, row, 1 );
213 connect(
le_viscosity, SIGNAL( textEdited(
const QString& ) ),
217 QLabel* lb_ph =
us_label( tr(
"pH:" ) );
218 main->addWidget( lb_ph, row, 1 );
221 main->addWidget(
le_ph, row++, 2 );
223 QLabel* lb_compressibility =
us_label( tr(
"Compressibility:" ) );
224 main->addWidget( lb_compressibility, row, 1 );
232 tr(
"Manual unadjusted Density and Viscosity" ),
cb_manual );
233 main->addLayout( lo_manual, row++, 0, 1, 3 );
235 QLabel* lb_optics =
us_label( tr(
"Optics:" ) );
243 connect( pb_spectrum, SIGNAL( clicked() ), SLOT(
spectrum() ) );
245 main->addWidget( lb_optics, row, 0 );
247 main->addWidget( pb_spectrum, row++, 2 );
258 main->addWidget(
le_guid, row++, 1, 1, 2 );
262 lb_guid->setVisible(
false );
268 p.setColor( QPalette::WindowText, Qt::red );
270 lb_units->setAlignment( Qt::AlignCenter );
271 main->addWidget(
lb_units, row++, 1, 1, 2 );
279 QLabel* lb_buffer =
us_banner( tr(
"Doubleclick on item to remove" ), -2 );
281 main->addWidget( lb_buffer, row++, 1, 1, 2 );
284 connect(
lw_buffer, SIGNAL( itemDoubleClicked( QListWidgetItem* ) ),
286 main->addWidget(
lw_buffer, row, 1, 6, 2 );
290 QBoxLayout* buttons =
new QHBoxLayout;
293 connect( pb_reset, SIGNAL( clicked() ), SLOT(
reset() ) );
294 buttons->addWidget( pb_reset );
297 connect( pb_help, SIGNAL( clicked() ), SLOT(
help() ) );
298 buttons->addWidget( pb_help );
305 connect( pb_cancel, SIGNAL( clicked() ), SLOT( reject() ) );
306 buttons->addWidget( pb_cancel );
308 pb_accept->setText( tr(
"Accept" ) );
311 connect( pb_accept, SIGNAL( clicked() ), SLOT(
accept_buffer() ) );
312 buttons->addWidget( pb_accept );
314 main->addLayout( buttons, row, 0, 1, 3 );
325 QMessageBox::warning(
this,
327 tr(
"There is no default database set." ) );
352 lw_buffer ->addItem( tr(
"Manual Override" ) );
373 lw_buffer ->addItem( tr(
"Manual Override" ) );
436 qApp->processEvents();
448 for (
int i = 0; i < keys.size(); i++ )
450 QString key = keys[ i ];
464 SIGNAL( investigator_accepted(
int ) ),
476 ? QString::number( invID ) +
": "
490 if ( ! dir.exists( path ) )
492 if ( ! dir.mkpath( path ) )
494 QMessageBox::critical(
this,
495 tr(
"Bad Buffer Path" ),
496 tr(
"Could not create default directory for buffers\n" )
530 pb_save ->setEnabled( desc_set );
532 pb_del ->setEnabled(
false );
535 QStringList filter(
"B*.xml" );
536 QStringList f_names = f.entryList( filter, QDir::Files, QDir::Name );
538 for (
int i = 0; i < f_names.size(); i++ )
540 QFile b_file( path +
"/" + f_names[ i ] );
542 if ( ! b_file.open( QIODevice::ReadOnly | QIODevice::Text) )
continue;
544 QXmlStreamReader xml( &b_file );
546 while ( ! xml.atEnd() )
550 if ( xml.isStartElement() )
552 if ( xml.name() ==
"buffer" )
554 QXmlStreamAttributes a = xml.attributes();
556 GUIDs << a.value(
"guid" ).toString();
596 pb_save ->setEnabled( desc_set );
598 pb_del ->setEnabled(
false );
605 QStringList q(
"get_buffer_desc" );
634 QStringList sortdesc;
642 QRegExp(
".*" + text +
".*", Qt::CaseInsensitive ) ) &&
645 sortdesc <<
descriptions[ ii ] + sep + QString::number( ii );
652 for (
int jj = 0; jj < sortdesc.size(); jj++ )
654 int ii = sortdesc[ jj ].section( sep, 1, 1 ).toInt();
670 QMessageBox::warning(
this, tr(
"Connection Problem" ),
671 tr(
"Could not connect to database \n" ) + error );
676 QString spectrum_type =
cmb_optics->currentText();
678 QString s = tr(
"Extinction:" );
680 if ( spectrum_type == tr(
"Absorbance" ) )
682 else if ( spectrum_type == tr(
"Interference" ) )
687 dialog->setWindowTitle( tr(
"Manage %1 Values" ).arg( spectrum_type ) );
718 pb_del ->setEnabled (
true );
727 qDebug() <<
"read failed";
769 QString s = QString::number( conc,
'f', 1 );
771 lw_buffer->addItem( name +
" (" + s +
" " + unit +
")" );
780 :
le_ph->text().toDouble();
803 QMessageBox::information(
this,
805 tr(
"First select the buffer which you "
806 "want to delete." ) );
810 int response = QMessageBox::question(
this,
811 tr(
"Confirmation" ),
812 tr(
"Do you really want to delete this entry?\n"
813 "Clicking 'OK' will delete the selected buffer data." ),
814 QMessageBox::Ok, QMessageBox::Cancel );
816 if ( response != QMessageBox::Ok )
return;
830 QString bufGUID =
le_guid->text();
839 QMessageBox::warning(
this,
840 tr(
"Buffer Not Deleted" ),
841 tr(
"The buffer could not be deleted,\n"
842 "since it is in use in one or more solutions." ) );
865 QStringList q(
"get_bufferID" );
870 int status = db.lastErrno();
875 QString bufferID = db.value( 0 ).toString();
877 q[ 0 ] =
"delete_buffer";
879 status = db.statusQuery( q );
884 QMessageBox::warning(
this,
885 tr(
"Buffer Not Deleted" ),
886 tr(
"The buffer could not be deleted,\n"
887 "since it is in use in one or more solutions." ) );
893 QMessageBox::warning(
this,
895 tr(
"Delete failed.\n\n" ) + db.lastError() );
903 QMessageBox::information(
this,
905 tr(
"Please enter a description for\n"
906 "your buffer before saving it!" ) );
912 if (
le_guid->text().size() != 36 )
930 QMessageBox::information(
this,
931 tr(
"NO Save of Results" ),
932 tr(
"The buffer with an empty GUID and/or description\n"
933 "was not saved." ) );
943 QString s = ( newFile ) ? tr(
"saved" ) : tr(
"updated" );
945 QMessageBox::information(
this,
946 tr(
"Save results" ),
947 tr(
"Buffer " ) + s );
956 QMessageBox::information(
this,
958 tr(
"Please select an investigator first!" ) );
972 QString private_buffer = (
cb_shared->isChecked() ) ?
"0" :
"1";
978 QString msg = tr(
"( Return Code = %1 ) " ).arg( idBuf )
981 QMessageBox::information(
this,
983 tr(
"Error updating buffer in the database:\n" )
1009 QMessageBox::information(
this,
1011 tr(
"Please select an existing Buffer first!" ) );
1018 QMessageBox::information(
this,
1020 tr(
"Please select an investigator first!" ) );
1026 QMessageBox::information(
this,
1028 tr(
"Please enter a buffer description first!" ) );
1032 int response = QMessageBox::question(
this,
1033 tr(
"Confirmation" ),
1034 tr(
"Do you really want to update this entry in the database?\n" ),
1035 QMessageBox::Ok, QMessageBox::Cancel );
1037 if ( response == QMessageBox::Ok )
1049 QString private_buffer = (
cb_shared->isChecked() ) ?
"0" :
"1";
1054 QString msg = tr(
"( Return Code = %1 ) " ).arg( idBuf )
1057 QMessageBox::information(
this,
1059 tr(
"Error updating buffer in the database:\n" )
1064 QMessageBox::information(
this,
1066 tr(
"The database has been updated\n" ) );
1081 QMessageBox::information(
this,
1083 tr(
"First select a buffer component!\n" ) );
1088 if ( partial_concentration <= 0.0 )
return;
1093 bool newItem =
true;
1095 QString index = QString::number( item->type() );
1104 if ( std_bc.name == bc->
name )
1109 s.sprintf(
" (%.1f ", partial_concentration );
1111 lw_buffer->item( i )->setText( std_bc.name + s + std_bc.unit +
")" );
1124 s.sprintf(
" (%.1f ", partial_concentration );
1125 lw_buffer->addItem( std_bc.name + s + std_bc.unit +
")" );
1149 lb_units->setText( tr(
"Please enter with units in: " ) +
1172 QListWidgetItem* oldItem =
lw_buffer->takeItem( row );
1193 int response = QMessageBox::question(
this,
1194 tr(
"Buffer changed" ),
1195 tr(
"Changes have not been saved.\n\nContinue?" ),
1196 QMessageBox::Yes, QMessageBox::Cancel );
1198 if ( response != QMessageBox::Yes )
return;
1235 le_ph ->setText(
"7.0" );
1237 pb_save ->setEnabled(
false );
1239 pb_del ->setEnabled(
false );
1247 QString number = (
id > 0 ) ? QString::number(
id ) +
": " :
"";
1263 if ( bc->
unit ==
"mM" ) c1 /= 1000;
1265 double c2 = c1 * c1;
1266 double c3 = c2 * c1;
1267 double c4 = c3 * c1;
1295 if ( bc->
unit ==
"mM" ) c1 /= 1000;
1297 double c2 = c1 * c1;
1298 double c3 = c2 * c1;
1299 double c4 = c3 * c1;
1332 pb_save ->setEnabled( row < 0 );
1353 QStringList q(
"get_buffer_info" );
1363 int response = QMessageBox::question(
this,
1364 tr(
"Update Buffer?" ),
1365 tr(
"The buffer description is already used.\n"
1366 "Do you wish to replace that buffer?\n\n"
1367 "Click \"No\" to create a new buffer;\n"
1368 "Click \"Yes\" to update the existing buffer.\n" ),
1369 QMessageBox::Yes, QMessageBox::No );
1373 if ( response == QMessageBox::No )
1402 qApp->processEvents();
1408 bool in_use =
false;
1410 QStringList sfilt(
"S*.xml" );
1411 QStringList snames = QDir( soldir )
1412 .entryList( sfilt, QDir::Files, QDir::Name );
1414 for (
int ii = 0; ii < snames.size(); ii++ )
1416 QString sfname = soldir + snames.at( ii );
1417 QFile sfile( sfname );
1419 if ( ! sfile.open( QIODevice::ReadOnly | QIODevice::Text ) )
continue;
1421 QXmlStreamReader xml( &sfile );
1423 while ( ! xml.atEnd() )
1427 if ( xml.isStartElement() && xml.name() ==
"buffer" )
1429 QXmlStreamAttributes atts = xml.attributes();
1431 if ( atts.value(
"guid" ).toString() == bufferGUID )
1441 if ( in_use )
break;