9 : QPushButton( text ), index( i )
15 setAutoDefault(
false );
27 setWindowTitle (
"UltraScan Model Associations" );
29 setAttribute ( Qt::WA_DeleteOnClose );
30 setWindowModality( Qt::WindowModal );
34 gray.setColor( QPalette::Base, QColor( 0xe0, 0xe0, 0xe0 ) );
36 QGridLayout*
main =
new QGridLayout(
this );
37 main->setContentsMargins( 2, 2, 2, 2 );
38 main->setSpacing ( 2 );
41 fm =
new QFontMetrics( font );
48 lw_analytes->setDragDropMode( QAbstractItemView::DragOnly );
62 tw =
new QTableWidget();
64 tw->setColumnCount( 7 );
65 tw->setRowCount ( 0 );
68 headers <<
"" <<
"Analyte 1" <<
"Analyte 2" <<
"<==>" <<
"Product"
69 <<
"K_dissociation\n(molar units)" <<
"K_off Rate\n(1/sec)";
70 int flwidth =
fm->width(
"8888.3456e+00" );
71 tw->setMinimumWidth( flwidth * 5 + 100 );
72 tw->setRowHeight( 0,
fm->height() + 4 );
73 tw->setColumnWidth( 0,
fm->width(
"D" ) + 6 );
74 tw->setColumnWidth( 1, flwidth );
75 tw->setColumnWidth( 2, flwidth );
76 tw->setColumnWidth( 3,
fm->width(
"<==>" ) - 2 );
77 tw->setColumnWidth( 4, flwidth );
78 tw->setColumnWidth( 5, flwidth );
79 tw->setColumnWidth( 6, flwidth );
83 tw->setHorizontalHeaderLabels( headers );
84 tw->setDragDropMode( QAbstractItemView::DropOnly );
85 tw->horizontalHeader()->setStretchLastSection(
true );
87 connect(
tw, SIGNAL( cellChanged(
int,
int ) ),
88 SLOT (
changed (
int,
int ) ) );
90 main->addWidget(
tw, row, 0, 5, 2 );
96 te_help->setPalette( pa );
97 te_help->setTextBackgroundColor( pa.color( QPalette::Window ) );
98 te_help->setTextColor( pa.color( QPalette::WindowText ) );
99 QFontMetrics
fm( te_help->font() );
100 te_help->setMaximumHeight(
fm.lineSpacing() * 13 / 2 );
101 te_help->setText( tr(
102 "* Drag a component from the upper list and drop it in an"
103 " Analyte or Product cell.\n"
104 "* Set the stoichiometry counter to the left of each component.\n"
105 "* Enter values for K_dissociation and K_off Rate in their text cells.\n"
106 "* Click on the \"D\" on the left side of any row to delete that row.\n"
107 "* Click the \"Accept\" button when all equations are as desired." ) );
108 main->addWidget( te_help, row, 0, 5, 2 );
112 QBoxLayout* buttonbox =
new QHBoxLayout;
115 connect( pb_help, SIGNAL( clicked() ), SLOT(
help()) );
116 buttonbox->addWidget( pb_help );
119 buttonbox->addWidget( pb_close );
120 connect( pb_close, SIGNAL( clicked() ), SLOT( close() ) );
123 buttonbox->addWidget( pb_accept );
124 connect( pb_accept, SIGNAL( clicked() ), SLOT(
complete()) );
126 main->addLayout( buttonbox, row++, 0, 1, 2 );
139 QString s = QString::number( as->
k_d,
'e', 4 );
140 tw->setItem( i, 5,
new QTableWidgetItem( s ) );
142 s = QString::number( as->
k_off,
'e', 4 );
143 tw->setItem( i, 6,
new QTableWidgetItem( s ) );
149 if ( as->
rcomps.size() > 2 )
160 int component = as->
rcomps[ index ];
161 QString s =
lw_analytes->item( component )->text();
163 s = s.left( 1 ) + QString::number( koligo );
164 tw->setItem( row, col,
new QTableWidgetItem( s ) );
166 qApp->processEvents();
169 QWidget* w =
tw->cellWidget( row, col );
170 QLayout* L = w->layout();
172 w = L->itemAt( 0 )->widget();
173 QwtCounter* c =
dynamic_cast< QwtCounter*
>( w );
175 c->setValue( fabs( (
double)as->
stoichs[ index ] ) );
182 QTableWidgetItem* item =
tw->item( row, col );
186 double value = item->text().toDouble();
187 item->setText( QString::number( value,
'e', 4 ) );
192 item->setText( QString() );
197 QWidget* w =
new QWidget;
198 QHBoxLayout* L =
new QHBoxLayout( w );
199 L->setContentsMargins( 0, 0, 0, 0 );
206 QString text = item->text().left( 1 );
207 QString sscr = item->text().mid( 1 );
209 if ( sscr.startsWith(
" " ) )
213 sscr = QString::number( colig );
217 QLabel* label =
us_label( text +
"<sub>" + sscr +
"</sub>" );
219 L->addWidget( label );
220 tw->setCellWidget( row, col, w );
223 connect(
tw, SIGNAL( cellChanged(
int,
int ) ),
224 SLOT (
changed (
int,
int ) ) );
226 if ( row ==
tw->rowCount() - 1 )
new_row();
231 int count =
tw->rowCount();
233 tw->setRowCount ( count + 1 );
234 tw->setRowHeight( count,
fm->height() + 4 );
237 pb->setMaximumWidth(
fm->width(
"D" ) + 6 );
238 connect( pb, SIGNAL( pushed(
int ) ), SLOT(
del(
int ) ) );
240 tw->setCellWidget( count, 0, pb );
246 if ( index ==
tw->rowCount() - 1 )
return;
247 tw->removeRow( index );
249 for (
int i = 0; i <
tw->rowCount(); i++ )
251 QWidget* w =
tw->cellWidget( i, 0 );
259 QVector< US_Model::Association > associations;
262 for (
int i = 0; i <
tw->rowCount() - 1; i++ )
274 QTableWidgetItem* item;
277 item =
tw->item( i, 5 );
278 if ( item != 0 ) association.
k_d = item->text().toDouble();
280 item =
tw->item( i, 6 );
281 if ( item != 0 ) association.
k_off = item->text().toDouble();
283 QWidget* w =
tw->cellWidget( i, 1 );
291 w = L->itemAt( 0 )->widget();
292 c =
dynamic_cast< QwtCounter*
>( w );
293 count = (int) c->value();
296 w = L->itemAt( 1 )->widget();
297 index =
dynamic_cast< QLabel*
>( w )->text().at( 0 ).cell() -
'A';
298 association.
rcomps << index;
302 moles_left += count * koligo;
306 w =
tw->cellWidget( i, 2 );
314 w = L->itemAt( 0 )->widget();
315 c =
dynamic_cast< QwtCounter*
>( w );
316 count = (int) c->value();
319 w = L->itemAt( 1 )->widget();
320 index =
dynamic_cast< QLabel*
>( w )->text().at( 0 ).cell() -
'A';
321 association.
rcomps << index;
325 moles_left += count * koligo;
329 w =
tw->cellWidget( i, 4 );
337 w = L->itemAt( 0 )->widget();
338 c =
dynamic_cast< QwtCounter*
>( w );
339 count = (int) c->value();
342 w = L->itemAt( 1 )->widget();
343 index =
dynamic_cast< QLabel*
>( w )->text().at( 0 ).cell() -
'A';
344 association.
rcomps << index;
348 moles_right += count * koligo;
352 if ( moles_right != moles_left )
354 QMessageBox::information(
this,
355 tr(
"Equations do not balance" ),
356 tr(
"Equation %1 does not balance" ).arg( i + 1 ) );
362 QMessageBox::information(
this,
363 tr(
"Combined Identical Reactants" ),
364 tr(
"In association %1, two identical reactants"
365 " have been combined into a single one, with"
366 " double the stoichiometry value." ).arg( i + 1 ) );
369 associations << association;
382 bool combined =
false;
386 int comp1 = as->
rcomps[ 0 ];
387 int comp2 = as->
rcomps[ 1 ];
391 combined = ( comp1 == comp2 && stoi1 == stoi2 );