00001 #include "qsecontroller.h"
00002
00003 #include <QTableWidget>
00004 #include <QTableWidgetItem>
00005
00006 #include <QPushButton>
00007 #include <QStatusBar>
00008 #include <QProgressBar>
00009 #include <QSlider>
00010 #include <QLabel>
00011 #include <QLineEdit>
00012 #include <QCheckBox>
00013 #include <QMenu>
00014 #include <QCursor>
00015 #include <QFileDialog>
00016 #include <QSettings>
00017 #include <QDesktopServices>
00018
00019 #include <qwt_plot.h>
00020 #include <qwt_plot_item.h>
00021 #include <qwt_plot_curve.h>
00022 #include <qwt_plot_zoomer.h>
00023
00024 #include "qsescan.h"
00025 #include "qsefilereader.h"
00026 #include "qsedataset.h"
00027 #include "qsedatasetmodel.h"
00028 #include "qseinputfile.h"
00029 #include "qseprocessormain.h"
00030 #include "qsegraphcontroller.h"
00031 #include "qsedataflow.h"
00032 #include "qsedatadeglitcherui.h"
00033 #include "qsenormalizer.h"
00034 #include "qsenormalizerui.h"
00035 #include "qseedgealignerui.h"
00036 #include "qsescanaveragerui.h"
00037
00038 QseController::QseController
00039 (QseProcessorMain *w, QObject *parent)
00040 : QObject(parent),
00041 m_DataFlow(0),
00042 m_MainWindow(w),
00043 m_CurrentScan(0),
00044 m_InputDataUI(NULL),
00045 m_DeglitcherUI(NULL),
00046 m_NormalizerUI(NULL),
00047 m_EdgeAlignerUI(NULL),
00048 m_ScanAveragerUI(NULL),
00049 m_NormalizedController(NULL),
00050 m_AveragedController(NULL),
00051 m_Progress(NULL)
00052 {
00053 m_DataFlow = new QseDataFlow();
00054 int tab = 0;
00055
00056 m_InputDataUI = new QseGraphController(m_DataFlow->m_InputData, NULL);
00057 m_MainWindow -> m_TabWidget -> insertTab(tab++, m_InputDataUI, "Input Data");
00058
00059
00060
00061
00062 m_NormalizerUI = new QseNormalizerUI(m_DataFlow->m_Normalizer, NULL);
00063 m_MainWindow -> m_TabWidget -> insertTab(tab++, m_NormalizerUI, "Normalization");
00064
00065 m_NormalizedController =
00066 new QseGraphController(m_DataFlow->m_NormalizedData, NULL);
00067 m_MainWindow -> m_TabWidget ->
00068 insertTab(tab++, m_NormalizedController, "Normalized Data");
00069
00070
00071
00072
00073 m_ScanAveragerUI = new QseScanAveragerUI(m_DataFlow->m_ScanAverager, NULL);
00074 m_MainWindow -> m_TabWidget -> insertTab(tab++, m_ScanAveragerUI, "Averaging");
00075
00076 m_AveragedController =
00077 new QseGraphController(m_DataFlow->m_AveragedData, NULL);
00078 m_MainWindow -> m_TabWidget ->
00079 insertTab(tab++, m_AveragedController, "Averaged Data");
00080
00081 m_MainWindow -> m_TabWidget -> setCurrentIndex(0);
00082
00083 m_NormalizedController -> addContextMenuAction(m_MainWindow->actionAverageSelectedScans);
00084
00085 setupActions();
00086
00087 connect(m_MainWindow -> actionRunNormalizer, SIGNAL(triggered()),
00088 this, SLOT(runNormalizer(void)));
00089
00090 connect(m_DataFlow->m_InputData, SIGNAL(message(const QString&)),
00091 this, SLOT(message(const QString&)));
00092
00093 connect(m_DataFlow->m_Normalizer, SIGNAL(message(const QString&)),
00094 this, SLOT(message(const QString&)));
00095
00096 connect(m_DataFlow->m_InputData, SIGNAL(madeProgress(int)), this, SLOT(setProgress(int)));
00097
00098 m_NormalizedController->setTitle("Normalized Scans");
00099
00100 m_AveragedController->setTitle("Averaged Data");
00101
00102 m_Progress = new QProgressBar(NULL);
00103 m_Progress -> setMinimumWidth(150);
00104 m_Progress -> setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
00105
00106 m_MainWindow -> statusBar() -> addPermanentWidget(m_Progress);
00107
00108 QStringList args = QApplication::arguments();
00109 int nargs = args.size();
00110
00111 for (int i=1; i<nargs; i++) {
00112 appendDataFile(args.at(i));
00113 }
00114 }
00115
00116 QseController::~QseController()
00117 {
00118 delete m_NormalizedController;
00119 delete m_AveragedController;
00120 }
00121
00122 void QseController::setupActions()
00123 {
00124 connect(m_MainWindow->actionOpenDataFile, SIGNAL(triggered()),
00125 this, SLOT(openDataFile()));
00126 connect(m_MainWindow->actionAppendDataFile, SIGNAL(triggered()),
00127 this, SLOT(appendDataFile()));
00128 connect(m_MainWindow->actionOpenControlFile, SIGNAL(triggered()),
00129 this, SLOT(openControlFile()));
00130 connect(m_MainWindow->actionSaveSplitDataFiles, SIGNAL(triggered()),
00131 this, SLOT(saveSplitDataFile()));
00132 connect(m_MainWindow->actionSaveNormalizedFiles, SIGNAL(triggered()),
00133 this, SLOT(saveNormalizedFile()));
00134 connect(m_MainWindow->actionSaveAveragedFiles, SIGNAL(triggered()),
00135 this, SLOT(saveAveragedFile()));
00136 connect(m_MainWindow->actionSaveControlFile, SIGNAL(triggered()),
00137 this, SLOT(saveControlFile()));
00138 connect(m_MainWindow->actionExit, SIGNAL(triggered()),
00139 this, SLOT(exitApplication()));
00140
00141 connect(m_MainWindow->actionPrintNormalizedGraph, SIGNAL(triggered()),
00142 m_NormalizedController, SLOT(printGraph()));
00143 connect(m_MainWindow->actionPrintAveragedGraph, SIGNAL(triggered()),
00144 m_AveragedController, SLOT(printGraph()));
00145
00146 connect(m_MainWindow->actionQSEHomePage, SIGNAL(triggered()),
00147 this, SLOT(openQSEHomePage()));
00148
00149 connect(m_MainWindow->actionExit, SIGNAL(triggered()),
00150 qApp, SLOT(quit()));
00151
00152 connect(m_MainWindow->actionAverageSelectedScans, SIGNAL(triggered()),
00153 this, SLOT(averageSelectedScans()));
00154 }
00155
00156 void QseController::message(const QString& message)
00157 {
00158 m_MainWindow->statusBar()->showMessage(message, 5000);
00159 m_MainWindow->outputMessageView->append(message);
00160 }
00161
00162 void QseController::setProgress(int level)
00163 {
00164 if (level > 100) {
00165 m_Progress -> reset();
00166 } else {
00167 m_Progress -> setValue(level);
00168 }
00169 }
00170
00171 void QseController::openCompleted()
00172 {
00173 m_MainWindow -> loadedFile -> setText(m_DataFlow->m_InputData -> filePath());
00174
00175 QString fname = m_DataFlow->m_InputData -> fileName();
00176 QStringList hdr = m_DataFlow->m_InputData -> header();
00177
00178 m_DataFlow->m_NormalizedData -> setFileName(fname+"_norm");
00179 m_DataFlow->m_NormalizedData -> setHeader(hdr);
00180
00181 m_DataFlow->m_AveragedData -> setFileName(fname+"_avg");
00182 m_DataFlow->m_AveragedData -> setHeader(hdr);
00183 }
00184
00185
00189 QseScan* QseController::scan(int n)
00190 {
00191 return m_DataFlow->m_InputData->scan(n);
00192 }
00193
00197 QseScan* QseController::currentScan()
00198 {
00199 return m_DataFlow->m_InputData->scan(m_CurrentScan);
00200 }
00201
00202 void QseController::runNormalizer()
00203 {
00204 m_DataFlow->m_Normalizer->exec();
00205
00206 emit normalizedScansChanged();
00207 }
00208
00209 void QseController::openDataFile()
00210 {
00211 QString filename = QFileDialog::getOpenFileName(m_MainWindow, tr("Open Data File"), ".", "");
00212
00213 if (filename != "") {
00214 readDataFile(filename);
00215 }
00216 }
00217
00218 void QseController::readDataFile(const QString &name)
00219 {
00220
00221
00222 m_DataFlow -> m_InputReader -> openFile(name);
00223
00224 openCompleted();
00225
00226 message(tr("New Data File loaded %1").arg(name));
00227 }
00228
00229 void QseController::appendDataFile()
00230 {
00231 QString filename = QFileDialog::getOpenFileName(m_MainWindow, tr("Append Data File"), ".", "");
00232
00233 if (filename != "") {
00234 appendDataFile(filename);
00235 }
00236 }
00237
00238 void QseController::appendDataFile(const QString &name)
00239 {
00240 m_DataFlow -> m_InputReader -> appendFile(name);
00241
00242 openCompleted();
00243
00244 message(tr("New Data File appended %1").arg(name));
00245 }
00246
00247 void QseController::openControlFile()
00248 {
00249 QString filename = QFileDialog::getOpenFileName(m_MainWindow, tr("Open Control File"), ".", "");
00250
00251 if (filename != "") {
00252 readControlFile(filename);
00253 }
00254 }
00255
00256 void QseController::readControlFile(const QString &name)
00257 {
00258 QSettings settings(name, QSettings::IniFormat);
00259
00260 readSettings(&settings);
00261 }
00262
00263 void QseController::saveSplitDataFile()
00264 {
00265
00266 }
00267
00268 void QseController::saveNormalizedFile()
00269 {
00270 m_NormalizedController -> saveSelectedScans();
00271 }
00272
00273 void QseController::saveAveragedFile()
00274 {
00275 m_AveragedController -> saveSelectedScans();
00276 }
00277
00278 void QseController::saveControlFile()
00279 {
00280 QString filename = QFileDialog::getSaveFileName(m_MainWindow, tr("Save Control File"), ".", "");
00281
00282 if (filename != "") {
00283 writeControlFile(filename);
00284 }
00285 }
00286
00287 void QseController::writeControlFile(const QString &name)
00288 {
00289 QSettings settings(name, QSettings::IniFormat);
00290
00291 writeSettings(&settings);
00292 }
00293
00294 void QseController::exitApplication()
00295 {
00296 }
00297
00298 void QseController::readSettings(QSettings *settings)
00299 {
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381 }
00382
00383 void QseController::writeSettings(QSettings *settings)
00384 {
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457 }
00458
00459 void QseController::averageSelectedScans()
00460 {
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491 }
00492
00493 void QseController::openQSEHomePage()
00494 {
00495 QDesktopServices::openUrl(QUrl("http://www.bessrc.aps.anl.gov/software/qse"));
00496 }