UltraScan III
us_mwl_run.cpp
Go to the documentation of this file.
1 
3 #include "us_mwl_run.h"
4 #include "us_settings.h"
5 #include "us_gui_settings.h"
6 #include "us_util.h"
7 
8 // Primary constructor to establish the dialog
9 US_MwlRun::US_MwlRun( QString& runID, bool isRawMwl )
10 : US_WidgetsDialog( 0, 0 ), runID( runID ), isRawMwl( isRawMwl )
11 {
12  if ( isRawMwl )
13  {
14  setWindowTitle( tr( "Available Raw MWL Directories with .mwrs Files" ) );
15  }
16  else
17  {
18  setWindowTitle( tr( "Available US3 Directories with MWL .auc Files" ) );
19  }
20 
21  setPalette( US_GuiSettings::frameColor() );
22 
23  runID = "";
24  QVBoxLayout* main = new QVBoxLayout( this );
25  main->setSpacing ( 2 );
26  main->setContentsMargins( 2, 2, 2, 2 );
27 
28  // Search
29  QHBoxLayout* search = new QHBoxLayout;
30  QLabel* lb_search = us_label( tr( "Search" ) );
31  le_search = us_lineedit( "" );
32  search ->addWidget( lb_search );
33  search ->addWidget( le_search );
34  connect( le_search, SIGNAL( textChanged( const QString& ) ),
35  this, SLOT ( limit_data ( const QString& ) ) );
36 
37  // Load the runInfo structure with current data
38  load_files();
39 
40  // Tree
41  tw = new QTableWidget( runInfo.size(), 3, this );
42  populate_list();
43 
44  // Button Row
45  QHBoxLayout* buttons = new QHBoxLayout;
46 
47  QPushButton* pb_cancel = us_pushbutton( tr( "Cancel" ) );
48  connect( pb_cancel, SIGNAL( clicked() ), SLOT( reject() ) );
49  buttons->addWidget( pb_cancel );
50 
51  QPushButton* pb_accept = us_pushbutton( tr( "Select" ) );
52  connect( pb_accept, SIGNAL( clicked() ), SLOT( select() ) );
53  buttons->addWidget( pb_accept );
54 
55  main->addLayout( search );
56  main->addWidget( tw );
57  main->addLayout( buttons );
58 qDebug() << "gDBr: size" << size();
59 // resize( 120, 120 );
60  resize( 480, 360 );
61 qDebug() << "gDBr: size" << size();
62 }
63 
64 // Function to load the runInfo structure with all runID's on local disk
66 {
67  QStringList efilt;
68 
69  if ( isRawMwl )
70  {
72  efilt << "*.mwrs";
73  }
74  else
75  {
77  efilt << "*.auc";
78  }
79  QStringList rdirs = QDir( resdir ).entryList(
80  QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name );
81 qDebug() << "LdDk: rdirs count" << rdirs.count() << "resdir" << resdir;
82 qDebug() << "LdDk: RawMwl" << isRawMwl << "efilt" << efilt << "rdirscount"
83  << rdirs.count();
84  resdir = resdir + "/";
85  QStringList runids;
86 
87  // Get the list of all Run IDs with data in their work directories
88  for ( int ii = 0; ii < rdirs.count(); ii++ )
89  {
90  QString runID = rdirs[ ii ];
91  QString wdir = resdir + runID;
92  QStringList efiles = QDir( wdir ).entryList( efilt, QDir::Files,
93  QDir::Name );
94 
95  int nfiles = efiles.count();
96 qDebug() << "LdDk: ii" << ii << "run" << rdirs[ii] << "count" << nfiles;
97  if ( nfiles < 2 ) // Definitely not MWL
98  continue;
99 
100  if ( ! isRawMwl )
101  { // For US3 openAUC, count wavelengths
102  QStringList wavelns;
103 
104  for ( int jj = 0; jj < nfiles; jj++ )
105  {
106  QString waveln = QString( efiles[ jj ] ).section( ".", -2, -2 );
107  if ( ! wavelns.contains( waveln ) )
108  wavelns << waveln;
109  if ( wavelns.count() > 2 ) break;
110  }
111 qDebug() << "LdDk: ii" << ii << "run" << rdirs[ii] << "nwaveln"
112  << wavelns.count();
113 
114  if ( wavelns.count() < 2 ) // Unique wavelengths count says non MWL
115  continue;
116  }
117 
118  QString rfn = wdir + "/" + efiles[ 0 ];
119  QString date = US_Util::toUTCDatetimeText(
120  QFileInfo( rfn ).lastModified().toUTC()
121  .toString( Qt::ISODate ), true )
122  .section( " ", 0, 0 ).simplified();
123 
124 //qDebug() << "LdDk: ii" << ii << " rfn" << rfn;
125  RunInfo rr;
126  rr.runID = runID;
127  rr.date = date;
128  rr.nfiles = nfiles;
129 //qDebug() << "LdDk: ii" << ii << " runID date count"
130 // << rr.runID << rr.date << rr.nfiles;
131 
132  runInfo << rr;
133  }
134 
135  if ( runInfo.size() < 1 )
136  {
137  QMessageBox::information( this,
138  tr( "Error" ),
139  tr( "There are no US3 runs on the local Disk to load.\n" ) );
140  }
141 
142  return;
143 }
144 
145 // Function to pass information back when select button is pressed
146 void US_MwlRun::select( void )
147 {
148  int ndx = tw ->currentRow();
149 
150  if ( ndx < 0 )
151  {
152  QMessageBox::information( this, tr( "No Run Selected" ),
153  tr( "You have not selected a run to load."
154  " To cancel loading, click on the \"Cancel\" button."
155  " Otherwise, make a selection in the list before"
156  " clicking on the \"Select\" button" ) );
157  return;
158  }
159 
160  runID = resdir + tw ->item( ndx, 0 )->text();
161 qDebug() << "MwlRun: accept : runID" << runID;
162  accept();
163 }
164 
165 // Function to populate the data tree
167 {
168  QFont tw_font( US_Widgets::fixedFont().family(),
170  QFontMetrics* fm = new QFontMetrics( tw_font );
171  int rowht = fm->height() + 2;
172  tw->setFont ( tw_font );
173  tw->setPalette( US_GuiSettings::editColor() );
174  tw->setRowCount( runInfo.count() );
175 
176  QStringList headers;
177  headers << tr( "Run" )
178  << tr( "Date" )
179  << tr( "Count of " ) + ( isRawMwl ? ".mwrs" : ".auc" );
180 
181  tw->setHorizontalHeaderLabels( headers );
182  tw->verticalHeader()->hide();
183  tw->setShowGrid( false );
184  tw->setSelectionBehavior( QAbstractItemView::SelectRows );
185  tw->setMinimumWidth ( 100 );
186  tw->setMinimumHeight( 100 );
187  tw->setColumnWidth( 0, 250 );
188  tw->setColumnWidth( 1, 150 );
189  tw->setColumnWidth( 2, 50 );
190  tw->setSortingEnabled( false );
191  tw->clearContents();
192 
193  // Now load the table, marking each as not-editable
194  for ( int ii = 0; ii < runInfo.size(); ii++ )
195  {
196  QTableWidgetItem* item;
197  RunInfo rr = runInfo[ ii ];
198 
199  item = new QTableWidgetItem( rr.runID );
200  item->setFlags( item->flags() ^ Qt::ItemIsEditable );
201  tw ->setItem( ii, 0, item );
202 
203  item = new QTableWidgetItem( rr.date );
204  item->setFlags( item->flags() ^ Qt::ItemIsEditable );
205  tw ->setItem( ii, 1, item );
206 
207  item = new QTableWidgetItem( QString().sprintf( "%6d", rr.nfiles ) );
208  item->setFlags( item->flags() ^ Qt::ItemIsEditable );
209  tw ->setItem( ii, 2, item );
210 //qDebug() << "setItems ii" << ii << "ID date runID label"
211 // << rr.ID << rr.date << rr.runID << rr.label;
212 
213  tw ->setRowHeight( ii, rowht );
214  }
215 
216  tw->setSortingEnabled( true );
217  tw->sortByColumn( 1, Qt::DescendingOrder );
218  tw->resizeColumnsToContents();
219  tw->adjustSize();
220  tw->resize( size().width() - 4, tw->size().height() );
221  qApp->processEvents();
222 }
223 
224 // Function to limit table data shown based on search criteria
225 void US_MwlRun::limit_data( const QString& sfilt )
226 {
227 qDebug() << "LimData: sfilt" << sfilt;
228  bool have_search = ! sfilt.isEmpty();
229  QFont tw_font( US_Widgets::fixedFont().family(),
231  QFontMetrics* fm = new QFontMetrics( tw_font );
232  int rowht = fm->height() + 2;
233  tw->clearContents();
234  tw->setSortingEnabled( false );
235 
236  for ( int ii = 0; ii < runInfo.size(); ii++ )
237  {
238  QTableWidgetItem* item;
239  RunInfo rr = runInfo[ ii ];
240 
241  // Skip the item if search text exists and the runID does not contain it
242  if ( have_search &&
243  ! rr.runID.contains( sfilt, Qt::CaseInsensitive ) )
244  continue;
245 
246  item = new QTableWidgetItem( rr.runID );
247  item->setFlags( item->flags() ^ Qt::ItemIsEditable );
248  tw ->setItem( ii, 0, item );
249 
250  item = new QTableWidgetItem( rr.date );
251  item->setFlags( item->flags() ^ Qt::ItemIsEditable );
252  tw ->setItem( ii, 1, item );
253 
254  item = new QTableWidgetItem( QString().sprintf( "%5d", rr.nfiles ) );
255  item->setFlags( item->flags() ^ Qt::ItemIsEditable );
256  tw ->setItem( ii, 2, item );
257 //qDebug() << "setItems ii" << ii << "ID date runID label"
258 // << rr.ID << rr.date << rr.runID << rr.label;
259 
260  tw ->setRowHeight( ii, rowht );
261  }
262 
263  tw->setSortingEnabled( true );
264  tw->sortByColumn( 1, Qt::DescendingOrder );
265  tw->resizeColumnsToContents();
266  tw->adjustSize();
267 // tw->update();
268 // update();
269  tw->resize( size().width() - 4, tw->size().height() );
270  qApp->processEvents();
271 }
272