16 setWindowTitle (
"UltraScan Model Editor" );
18 setAttribute ( Qt::WA_DeleteOnClose );
19 setWindowModality( Qt::WindowModal );
29 QGridLayout*
main =
new QGridLayout(
this );
30 main->setContentsMargins( 2, 2, 2, 2 );
31 main->setSpacing ( 2 );
34 QPushButton* pb_investigator =
us_pushbutton( tr(
"Select Investigator" ) );
37 pb_investigator->setEnabled(
false );
43 QLabel* lb_mlfilt =
us_label( tr(
"List Filter:" ) );
47 QPushButton* pb_models =
us_pushbutton( tr(
"List Available Models" ) );
48 QPushButton* pb_new =
us_pushbutton( tr(
"Create New Model" ) );
50 QLabel* lb_description =
us_label( tr(
"Model Description:" ) );
56 QPushButton* pb_components =
us_pushbutton( tr(
"Manage Components" ) );
57 QPushButton* pb_associations =
us_pushbutton( tr(
"Manage Associations" ) );
59 QLabel* lb_wavelength =
us_label( tr(
"Wavelength:" ) );
62 QLabel* lb_optics =
us_label( tr(
"Optical System:" ) );
69 QLabel* lb_guid =
us_label( tr(
"Global Identifier:" ) );
74 lb_guid->setVisible(
false );
85 QBoxLayout* buttonbox =
new QHBoxLayout;
89 buttonbox->addWidget( pb_help );
90 buttonbox->addWidget( pb_close );
91 buttonbox->addWidget( pb_accept );
94 main->addWidget( pb_investigator, row, 0, 1, 1 );
97 main->addWidget( lb_mlfilt, row, 0, 1, 1 );
98 main->addWidget(
le_mlfilt, row, 1, 1, 2 );
99 main->addWidget(
le_nlines, row++, 3, 1, 1 );
100 main->addWidget( pb_models, row, 0, 1, 2 );
101 main->addWidget( pb_new, row++, 2, 1, 2 );
102 main->addWidget( lb_description, row, 0, 1, 1 );
104 main->addWidget(
lw_models, row, 0, 5, 4 ); row += 5;
105 main->addWidget( pb_components, row, 0, 1, 2 );
106 main->addWidget( pb_associations, row++, 2, 1, 2 );
107 main->addWidget( lb_wavelength, row, 0, 1, 1 );
109 main->addWidget( lb_optics, row, 2, 1, 1 );
110 main->addWidget(
cb_optics, row++, 3, 1, 1 );
111 main->addWidget( lb_guid, row, 0, 1, 1 );
112 main->addWidget(
le_guid, row++, 1, 1, 3 );
113 main->addWidget(
pb_save, row, 0, 1, 2 );
114 main->addWidget(
pb_delete, row++, 2, 1, 2 );
115 main->addLayout( buttonbox, row++, 0, 1, 4 );
117 connect( pb_investigator, SIGNAL( clicked() ),
121 connect(
le_mlfilt, SIGNAL( editingFinished() ),
123 connect( pb_models, SIGNAL( clicked() ),
125 connect( pb_new, SIGNAL( clicked() ),
129 connect( pb_components, SIGNAL( clicked() ),
131 connect( pb_associations, SIGNAL( clicked() ),
133 connect(
pb_save, SIGNAL( clicked() ),
137 connect( pb_help, SIGNAL( clicked() ),
139 connect( pb_close, SIGNAL( clicked() ),
141 connect( pb_accept, SIGNAL( clicked() ),
143 connect(
lw_models, SIGNAL( itemClicked ( QListWidgetItem* ) ),
198 for (
int ii = 0; ii <
lw_models->count(); ii++ )
200 if (
lw_models->item( ii )->type() - QListWidgetItem::UserType == last )
213 bool listdesc = !mfilt.isEmpty();
214 qDebug() <<
"ShMDsc: mfilt listdesc" << mfilt << listdesc;
215 QRegExp mpart = QRegExp(
".*" + mfilt +
".*", Qt::CaseInsensitive );
216 QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
223 if ( listdesc && !desc.contains( mpart ) )
229 new QListWidgetItem( desc,
lw_models, ii + QListWidgetItem::UserType );
233 QApplication::restoreOverrideCursor();
240 int response = QMessageBox::question(
this,
241 tr(
"Model Changed" ),
242 tr(
"The model has changed. Do you want to ignore the changes?" ),
243 QMessageBox::Cancel, QMessageBox::Yes );
245 if ( response == QMessageBox::Cancel )
return false;
257 if ( desc.isEmpty() )
return;
259 if ( desc !=
"New Model" )
265 if ( desc ==
lw_models->item( row )->text() )
return;
268 int index =
lw_models->item( row )->type() - QListWidgetItem::UserType;
277 if (
lw_models->item( ii )->type() - QListWidgetItem::UserType == index )
287 qDebug() <<
"SelMdl: IN";
290 qDebug() <<
"SelMdl: ignore_changes FALSE";
292 item -> listWidget()->setCurrentRow(
recent_row );
300 int index = item->listWidget()-> currentRow();
301 QString mdesc = item->text();
303 qDebug() <<
"SelMdl: index modlx" << index << modlx <<
"mdesc" << mdesc;
334 if ( filename.isEmpty() )
340 if ( mdesc !=
"New Model" )
364 if ( row < 0 )
return;
366 QString mdesc =
lw_models->item( row )->text();
389 q <<
"delete_model" << md.
DB_id;
392 QMessageBox::information(
this,
393 tr(
"Model Deleted" ),
394 tr(
"The model has been deleted from the database." ) );
422 QMessageBox::warning(
this,
424 tr(
"There is no default database set." ) );
439 QMessageBox::warning(
this,
440 tr(
"Connection Problem" ),
441 tr(
"Could not connect to database\n" ) + error );
448 QMessageBox::information(
this,
449 tr(
"Database Error" ),
450 tr(
"The following error was returned:\n" ) + db.
lastError() );
472 qDebug() <<
"MngCmp: index" << index;
476 QMessageBox::information(
this,
477 tr(
"Model not selected" ),
478 tr(
"Please select a model first.\n"
479 "If necessary, create a new model." ) );
489 connect( dialog, SIGNAL( done (
void ) ), SLOT(
update_sim (
void ) ) );
490 connect( dialog, SIGNAL( use_db(
bool ) ), SLOT(
source_changed(
bool ) ) );
506 QMessageBox::information(
this,
507 tr(
"Model not selected" ),
508 tr(
"Please select a model first.\n"
509 "If necessary, create a new model." ) );
515 QMessageBox::information(
this,
516 tr(
"Model Incomplete" ),
517 tr(
"There must be at least two analytes in the selected\n"
518 "model to specify associations." ) );
525 connect( dialog, SIGNAL( done() ), SLOT(
update_assoc() ) );
542 int response = QMessageBox::question(
this,
543 tr(
"Model Changed" ),
544 tr(
"The model may have changed and not been saved.\n"
545 "Do you want to accept the possibly unsaved model?" ),
546 QMessageBox::Cancel, QMessageBox::Yes );
548 if ( response == QMessageBox::Cancel )
return;
569 if (
le_guid->text().size() != 36 )
579 qDebug() <<
"MdlSv: fn" << fn;
581 if ( ! file.open( QIODevice::WriteOnly | QIODevice::Text) )
583 qDebug() <<
"Cannot open file for writing: " << fn;
589 QString save_type =
newFile ?
"saved" :
"updated";
591 QMessageBox::information(
this,
593 tr(
"The model has been %1 in the disk." ).arg( save_type ) );
610 QMessageBox::information(
this,
611 tr(
"Model Written" ),
612 tr(
"The model has been %1 in the database." ).arg(
model.
message ) );
619 QMessageBox::information(
this,
620 tr(
"Database Error" ),
621 tr(
"The model could not be saved:\n" ) +
model.
message );
633 QMessageBox::information(
this,
635 tr(
"The model has no components." ) );
642 QMessageBox::information(
this,
643 tr(
"Model Name Error" ),
644 tr(
"The model does not have an acceptable name.\n"
645 "Enter a non-blank, non-\"New Model\" name in the\n"
646 "Model Description field. You may then save the model." ) );
655 for (
int ii = 0; ii < mds.size(); ii++ )
657 if ( mdesc == mds[ ii ].description )
666 qDebug() <<
"SrcChg: db" << db;
676 qApp->processEvents();
682 qDebug() <<
"FltChg: mfilt" <<
le_mlfilt->text();
689 qDebug() <<
"UpdDDb: db" << db;
694 qApp->processEvents();
700 qDebug() <<
"LsMdl: IN";
706 qDebug() <<
"LsMdl: path" << path;
711 QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
716 QStringList filter(
"M*.xml" );
717 QStringList f_names = f.entryList( filter, QDir::Files, QDir::Name );
719 QXmlStreamAttributes a;
721 for (
int ii = 0; ii < f_names.size(); ii++ )
723 QFile m_file( path +
"/" + f_names[ ii ] );
725 if ( ! m_file.open( QIODevice::ReadOnly | QIODevice::Text) )
728 QXmlStreamReader xml( &m_file );
730 while ( ! xml.atEnd() )
734 if ( xml.isStartElement() )
736 if ( xml.name() ==
"model" )
739 a = xml.attributes();
740 md.
description = a.value(
"description" ).toString();
741 md.
modelGUID = a.value(
"modelGUID" ).toString();
742 md.
editGUID = a.value(
"editGUID" ).toString();
743 md.
filename = path +
"/" + f_names[ ii ];
759 QMessageBox::information(
this,
760 tr(
"Investigator not set" ),
761 tr(
"Please select an investigator first." ) );
775 q <<
"get_model_desc" << QString::number(
investigator );
783 md.
DB_id = db.value( 0 ).toString();
786 md.
editGUID = db.value( 5 ).toString();
792 QApplication::restoreOverrideCursor();
793 QApplication::restoreOverrideCursor();
796 qApp->processEvents();
799 qDebug() <<
"LsMdl: old h,w" << olhgt << olwid;
805 qDebug() <<
"LsMdl: nmodls" << nmodls <<
"nlines" << nlines;
806 le_nlines->setText( nlines == 1 ? tr(
"1 list item" )
807 : tr(
"%1 list items" ).arg( nlines ) );
808 qApp->processEvents();
811 lw_models->addItem(
"No models found." );
815 nlines = qMin( nlines, 13 );
816 nlines = qMin( nlines, 5 );
818 QFontMetrics fm =
lw_models->fontMetrics();
819 int height = nlines * fm.lineSpacing();
820 int width = fm.maxWidth() * 20;
822 height = qMax( height, olhgt );
823 width = qMax( width, olwid );
825 height = this->height() + height - olhgt;
826 width = this->width() + width - olwid;
828 resize( width, height );
830 qDebug() <<
"LsMdl: END";