00001 #include "qsegraphcontroller.h"
00002
00003 #include <QListWidget>
00004 #include <QTableWidget>
00005 #include <QPrinter>
00006 #include <QPrintDialog>
00007 #include <QMenu>
00008 #include <QMap>
00009 #include <QThread>
00010
00011 #include <qwt_plot.h>
00012 #include <qwt_plot_zoomer.h>
00013 #include <qwt_plot_panner.h>
00014 #include <qwt_plot_magnifier.h>
00015 #include <qwt_plot_curve.h>
00016 #include <qwt_plot_layout.h>
00017 #include <qwt_legend.h>
00018
00019 #include "qsedataset.h"
00020 #include "qsedataexport.h"
00021 #include "qsedatareference.h"
00022 #include "qsegraphscansmodel.h"
00023 #include "qsegraphcolumnsmodel.h"
00024
00025 QseGraphController::QseGraphController(QseDataSet *f, QWidget *parent)
00026 : QWidget(parent),
00027 m_DataSet(f),
00028 m_ScansModel(NULL),
00029 m_ScansSelection(NULL),
00030 m_ColumnsModel(NULL),
00031 m_ColumnsSelection(NULL),
00032 m_Zoomer(NULL),
00033 m_Zoomer2(NULL),
00034 m_Panner(NULL),
00035 m_Magnifier(NULL),
00036 m_Legend(NULL),
00037 m_LegendShown(true),
00038 m_ScanPenStep(1),
00039 m_ScanSymbolStep(0),
00040 m_CurvePenStep(0),
00041 m_CurveSymbolStep(1)
00042 {
00043 m_Pens[0].setColor(Qt::black);
00044 m_Pens[1].setColor(Qt::red);
00045 m_Pens[2].setColor(Qt::green);
00046 m_Pens[3].setColor(Qt::blue);
00047 m_Pens[4].setColor(Qt::cyan);
00048 m_Pens[5].setColor(Qt::magenta);
00049 m_Pens[6].setColor(Qt::darkYellow);
00050 m_Pens[7].setColor(Qt::darkRed);
00051 m_Pens[8].setColor(Qt::darkGreen);
00052 m_Pens[9].setColor(Qt::darkBlue);
00053 m_Pens[10].setColor(Qt::darkCyan);
00054 m_Pens[11].setColor(Qt::darkMagenta);
00055
00056 m_Symbols[0] = QwtSymbol(QwtSymbol::Ellipse, QBrush(), m_Pens[0], QSize(3,3));
00057 m_Symbols[1] = QwtSymbol(QwtSymbol::Ellipse, QBrush(), m_Pens[1], QSize(5,5));
00058 m_Symbols[2] = QwtSymbol(QwtSymbol::Rect, QBrush(), m_Pens[2], QSize(5,5));
00059 m_Symbols[3] = QwtSymbol(QwtSymbol::Diamond, QBrush(), m_Pens[3], QSize(5,5));
00060 m_Symbols[4] = QwtSymbol(QwtSymbol::Triangle, QBrush(), m_Pens[4], QSize(5,5));
00061 m_Symbols[5] = QwtSymbol(QwtSymbol::DTriangle, QBrush(), m_Pens[5], QSize(5,5));
00062 m_Symbols[6] = QwtSymbol(QwtSymbol::UTriangle, QBrush(), m_Pens[6], QSize(5,5));
00063 m_Symbols[7] = QwtSymbol(QwtSymbol::LTriangle, QBrush(), m_Pens[7], QSize(5,5));
00064 m_Symbols[8] = QwtSymbol(QwtSymbol::RTriangle, QBrush(), m_Pens[8], QSize(5,5));
00065 m_Symbols[9] = QwtSymbol(QwtSymbol::Cross, QBrush(), m_Pens[9], QSize(5,5));
00066 m_Symbols[10] = QwtSymbol(QwtSymbol::XCross, QBrush(), m_Pens[10], QSize(5,5));
00067 m_Symbols[11] = QwtSymbol(QwtSymbol::Star1, QBrush(), m_Pens[11], QSize(5,5));
00068
00069 setupUi(this);
00070
00071 m_Graph->setCanvasBackground(QColor(Qt::white));
00072
00073 m_Zoomer = new QwtPlotZoomer(QwtPlot::xBottom, QwtPlot::yLeft, m_Graph->canvas());
00074 m_Zoomer -> setSelectionFlags(QwtPicker::DragSelection | QwtPicker::CornerToCorner);
00075
00076 m_Zoomer2 = new QwtPlotZoomer(QwtPlot::xTop, QwtPlot::yRight, m_Graph->canvas());
00077 m_Zoomer2 -> setSelectionFlags(QwtPicker::DragSelection | QwtPicker::CornerToCorner);
00078
00079 m_Magnifier = new QwtPlotMagnifier(m_Graph->canvas());
00080 m_Magnifier -> setMouseFactor(1.0);
00081
00082 enableAxes(true, false);
00083
00084
00085
00086
00087 m_Zoomer -> setMousePattern(QwtEventPattern::MouseSelect2,
00088 Qt::LeftButton, Qt::ControlModifier | Qt::ShiftModifier);
00089 m_Zoomer2 -> setMousePattern(QwtEventPattern::MouseSelect2,
00090 Qt::LeftButton, Qt::ControlModifier | Qt::ShiftModifier);
00091
00092 m_Zoomer -> setMousePattern(QwtEventPattern::MouseSelect3,
00093 Qt::LeftButton, Qt::ControlModifier);
00094 m_Zoomer2 -> setMousePattern(QwtEventPattern::MouseSelect3,
00095 Qt::LeftButton, Qt::ControlModifier);
00096
00097 m_Panner = new QwtPlotPanner(m_Graph->canvas());
00098 m_Panner -> setMouseButton(Qt::MidButton);
00099 m_Panner -> setEnabled(true);
00100
00101 m_Legend = new QwtLegend;
00102 m_Legend -> setFrameStyle(QFrame::Box|QFrame::Sunken);
00103 m_Legend -> setItemMode(QwtLegend::CheckableItem);
00104
00105 m_Graph -> insertLegend(m_Legend, QwtPlot::BottomLegend);
00106
00107 connect(m_Graph, SIGNAL(legendChecked(QwtPlotItem*,bool)),
00108 this, SLOT(legendChecked(QwtPlotItem*,bool)));
00109
00110 m_Graph -> canvas() -> setContextMenuPolicy(Qt::CustomContextMenu);
00111 connect(m_Graph -> canvas(), SIGNAL(customContextMenuRequested(const QPoint &)),
00112 this, SLOT(graphContextMenu(const QPoint&)));
00113
00114 m_ScansView -> setContextMenuPolicy(Qt::CustomContextMenu);
00115 connect(m_ScansView, SIGNAL(customContextMenuRequested(const QPoint &)),
00116 this, SLOT(scansListContextMenu(const QPoint &)));
00117
00118 m_ColumnsView -> setContextMenuPolicy(Qt::CustomContextMenu);
00119 connect(m_ColumnsView, SIGNAL(customContextMenuRequested(const QPoint &)),
00120 this, SLOT(columnsTableContextMenu(const QPoint &)));
00121
00122 m_ScansModel = new QseGraphScansModel(m_DataSet, m_ScansView, this);
00123 m_ColumnsModel = new QseGraphColumnsModel(this, m_ColumnsView, this);
00124
00125 m_ScansView -> setModel(m_ScansModel);
00126 m_ColumnsView -> setModel(m_ColumnsModel);
00127
00128 m_ScansSelection = m_ScansView->selectionModel();
00129 m_ColumnsSelection = m_ColumnsView->selectionModel();
00130
00131 connect(m_DataSet, SIGNAL(dataCleared()), this, SLOT(dataCleared()));
00132 connect(m_DataSet, SIGNAL(dataChanged()), this, SLOT(dataChanged()));
00133 connect(m_DataSet, SIGNAL(operationCompleted()), this, SLOT(operationCompleted()));
00134
00135
00136 connect(m_ColumnsView, SIGNAL(clicked(const QModelIndex&)),
00137 this, SLOT(columnsCellClicked(const QModelIndex&)));
00138
00139 connect(m_ScansSelection,
00140 SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
00141 this,
00142 SLOT(scansSelectionChanged(const QItemSelection&, const QItemSelection&)));
00143
00144 connect(m_PrintButton, SIGNAL(clicked()), this, SLOT(printGraph()));
00145 connect(m_ZoomAllButton, SIGNAL(clicked()), this, SLOT(zoomGraphAll()));
00146 connect(m_ZoomInButton, SIGNAL(clicked()), this, SLOT(zoomGraphIn()));
00147 connect(m_ZoomOutButton, SIGNAL(clicked()), this, SLOT(zoomGraphOut()));
00148 }
00149
00150 QseGraphController::~QseGraphController()
00151 {
00152 }
00153
00154 QseDataSet* QseGraphController::dataSet() const
00155 {
00156 return m_DataSet;
00157 }
00158
00159 int QseGraphController::selectedColumnCount() const
00160 {
00161 return m_SelectedScanColumns.count();
00162 }
00163
00164 QString QseGraphController::selectedColumn(int i) const
00165 {
00166 return m_SelectedScanColumns[i];
00167 }
00168
00169 void QseGraphController::setTitle(const QString &title)
00170 {
00171 m_Graph -> setTitle(title);
00172 }
00173
00174 void QseGraphController::addContextMenuAction(QAction *action)
00175 {
00176 m_Actions.append(action);
00177 }
00178
00179 void QseGraphController::scanAdded(int s)
00180 {
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 }
00224
00225 void QseGraphController::operationCompleted()
00226 {
00227
00228
00229 m_ScansView->resizeRowsToContents();
00230 m_ScansView->resizeColumnsToContents();
00231
00232 updateGraph();
00233 }
00234
00235 void QseGraphController::dataCleared()
00236 {
00237
00238
00239
00240 m_SelectedScanColumns.clear();
00241 m_SelectedScanColumnCounts.clear();
00242
00243 m_ColumnsModel -> columnsChanged();
00244
00245 }
00246
00247 void QseGraphController::dataChanged()
00248 {
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263 }
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307 bool QseGraphController::scanSelected(int i)
00308 {
00309 return m_ScansSelection -> isRowSelected(i, QModelIndex());
00310
00311 }
00312
00313 bool QseGraphController::selectedPlotX(int i) const
00314 {
00315 QString colname = selectedColumn(i);
00316
00317 return m_PlotXColumns.contains(colname);
00318 }
00319
00320 bool QseGraphController::selectedPlotY(int i) const
00321 {
00322 QString colname = selectedColumn(i);
00323
00324 return m_PlotYColumns.contains(colname);
00325 }
00326
00327 bool QseGraphController::selectedPlotY2(int i) const
00328 {
00329 QString colname = selectedColumn(i);
00330
00331 return m_PlotY2Columns.contains(colname);
00332 }
00333
00334 bool QseGraphController::selectedPlotNorm(int i) const
00335 {
00336 QString colname = selectedColumn(i);
00337
00338 return m_PlotNormColumns.contains(colname);
00339 }
00340
00341 void QseGraphController::scansSelectionChanged
00342 (const QItemSelection & selected, const QItemSelection & deselected)
00343 {
00344
00345
00346 m_SelectedScanColumns.clear();
00347 m_SelectedScanColumnCounts.clear();
00348
00349 int n = scanCount();
00350
00351 for (int i = 0; i<n; i++) {
00352 if (scanSelected(i)) {
00353 QseScan* s = m_DataSet -> scan(i);
00354
00355 if (s) {
00356 int nc = s->columnCount();
00357
00358 for (int i=0; i<nc; i++) {
00359 QseColumn* col = s->column(i);
00360 if (col) {
00361 QString colname = col->name();
00362 if (!m_SelectedScanColumnCounts.contains(colname)) {
00363 m_SelectedScanColumns.append(colname);
00364 }
00365 m_SelectedScanColumnCounts[colname] += 1;
00366 }
00367 }
00368 }
00369 }
00370 }
00371
00372 m_ColumnsModel -> columnsChanged();
00373 m_ColumnsView->resizeRowsToContents();
00374 m_ColumnsView->resizeColumnsToContents();
00375
00376 updateGraph();
00377 }
00378
00379 void QseGraphController::toggleGraphSelection
00380 (int n, QSet<QString>& set)
00381 {
00382 QString colname = selectedColumn(n);
00383
00384 if (set.contains(colname)) {
00385 set.remove(colname);
00386 } else {
00387 set.insert(colname);
00388 }
00389 }
00390
00391 void QseGraphController::columnsSelectionChanged
00392 (const QItemSelection & selected, const QItemSelection & deselected)
00393 {
00394
00395
00396 QItemSelectionRange r;
00397
00398 foreach(r, selected) {
00399 int tp=r.top(), bt=r.bottom();
00400 int lf=r.left(), rt=r.right();
00401 for (int i=tp; i<=bt; i++) {
00402 for (int j=lf; j<=rt; j++) {
00403 printf("QseGraphController::columnsSelectionChanged::selected(%d,%d)\n",i,j);
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419 }
00420 }
00421
00422 m_ColumnsModel -> emitDataChanged(r.topLeft(), r.bottomRight());
00423 }
00424
00425 foreach(r, deselected) {
00426 int tp=r.top(), bt=r.bottom();
00427 int lf=r.left(), rt=r.right();
00428 for (int i=tp; i<=bt; i++) {
00429 for (int j=lf; j<=rt; j++) {
00430 printf("QseGraphController::columnsSelectionChanged::deselected(%d,%d)\n",i,j);
00431 }
00432 }
00433
00434 m_ColumnsModel -> emitDataChanged(r.topLeft(), r.bottomRight());
00435 }
00436
00437
00438 updateGraph();
00439 }
00440
00441 void QseGraphController::columnsCellClicked(const QModelIndex& index)
00442 {
00443
00444
00445 int i = index.row(), j = index.column();
00446
00447 switch (j) {
00448 case 1:
00449 m_PlotXColumns.clear();
00450 toggleGraphSelection(i, m_PlotXColumns);
00451 m_ColumnsModel -> emitDataChanged(m_ColumnsModel->index(0,1),
00452 m_ColumnsModel->index(m_ColumnsModel->rowCount(),1));
00453 break;
00454 case 2:
00455 toggleGraphSelection(i, m_PlotYColumns);
00456 break;
00457 case 3:
00458 toggleGraphSelection(i, m_PlotY2Columns);
00459 break;
00460 case 4:
00461 toggleGraphSelection(i, m_PlotNormColumns);
00462 break;
00463 }
00464
00465 m_ColumnsModel -> emitDataChanged(index, index);
00466
00467 updateGraph();
00468 }
00469
00470 void QseGraphController::updateGraph()
00471 {
00472
00473
00474 m_Graph -> clear();
00475
00476 int s;
00477 int nscans = 0;
00478 int nscanstotal = m_DataSet -> scanCount();
00479
00480 for (s=0; s<nscanstotal; s++) {
00481 if (scanSelected(s)) {
00482 nscans++;
00483 }
00484 }
00485
00486 int pnnum = 0;
00487 int smnum = -1;
00488
00489 int ncurves = 0;
00490 int npscans = 0;
00491 int ncrvscn = 0;
00492
00493 QSet<QString> xnames, ynames, y2names;
00494
00495 if (nscans > 1) {
00496 m_Graph -> setTitle(QString("%1 Scans").arg(nscans));
00497 }
00498
00499 int hasy1 = false;
00500 int hasy2 = false;
00501
00502 for (s=0; s<nscanstotal; s++) {
00503 if (scanSelected(s)) {
00504
00505
00506 ncrvscn = 0;
00507
00508 if (m_ScanPenStep) {
00509 pnnum = (pnnum + m_ScanPenStep + NPENS) % NPENS;
00510 } else {
00511 pnnum = 0;
00512 }
00513
00514 if (m_ScanSymbolStep) {
00515 smnum = (smnum + m_ScanSymbolStep + NSYMBOLS) % NSYMBOLS;
00516 } else {
00517 smnum = 0;
00518 }
00519
00520 QseScan *scan = m_DataSet -> scan(s);
00521
00522 if (scan) {
00523 if (nscans == 1) {
00524 m_Graph->setTitle(scan->scanCommand());
00525 }
00526 int nc = scan->columnCount();
00527 QseColumn *xc = NULL;
00528 int nxc = -1;
00529
00530 for (int c = 0; c<nc; c++) {
00531 QseColumn *col = scan->column(c);
00532 if (col) {
00533 QString colname = col->name();
00534
00535 if (m_PlotXColumns.contains(colname)) {
00536 xc = col;
00537 nxc = c;
00538 break;
00539 }
00540 }
00541 }
00542
00543 if (nc && (xc == NULL)) {
00544 xc = scan->column(0);
00545 nxc = 0;
00546 }
00547
00548 if (xc) {
00549
00550 int nnc = 0;
00551
00552 for (int c = 0; c<nc; c++) {
00553 QseColumn *yc = scan->column(c);
00554 if (yc) {
00555 QString colname = yc->name();
00556
00557 if (m_PlotYColumns.contains(colname)) {
00558 QString name;
00559 nnc += 1;
00560 ncurves += 1;
00561
00562 if (nnc == 1) {
00563 xnames.insert(xc->name());
00564 }
00565 ynames.insert(colname);
00566
00567 if (ncurves <= MAX_CURVES) {
00568 if (ncrvscn == 0) {
00569 npscans += 1;
00570 }
00571 ncrvscn += 1;
00572
00573 if (nscans == 1) {
00574 name = colname;
00575 } else {
00576 name = QString("S%1:%2").arg(scan->scanNumber()).arg(colname);
00577 }
00578
00579 QwtPlotCurve *pc = new QwtPlotCurve(name);
00580
00581 pc->setData(QseDataReference(m_DataSet, s, nxc, c));
00582 pc->setPen(m_Pens[pnnum]);
00583 QwtSymbol ps = m_Symbols[smnum];
00584 ps.setPen(m_Pens[pnnum]);
00585 ps.setBrush(QBrush(m_Pens[pnnum].color()));
00586 pc->setSymbol(ps);
00587 pnnum = (pnnum + m_CurvePenStep + NPENS) % NPENS;
00588 smnum = (smnum + m_CurveSymbolStep + NSYMBOLS) % NSYMBOLS;
00589 pc->setItemAttribute(QwtPlotItem::Legend, m_LegendShown);
00590 pc->attach(m_Graph);
00591 hasy1 = true;
00592 }
00593 }
00594 }
00595 }
00596
00597 for (int c = 0; c<nc; c++) {
00598 QseColumn *yc = scan->column(c);
00599 if (yc) {
00600 QString colname = yc->name();
00601
00602 if (m_PlotY2Columns.contains(colname)) {
00603 QString name;
00604 nnc += 1;
00605 ncurves += 1;
00606
00607 if (nnc == 1) {
00608 xnames.insert(xc->name());
00609 }
00610 y2names.insert(colname);
00611
00612 if (ncurves <= MAX_CURVES) {
00613 if (ncrvscn == 0) {
00614 npscans += 1;
00615 }
00616 ncrvscn += 1;
00617
00618 if (nscans == 1) {
00619 name = colname;
00620 } else {
00621 name = QString("S%1:%2").arg(scan->scanNumber()).arg(colname);
00622 }
00623
00624 QwtPlotCurve *pc = new QwtPlotCurve(name);
00625
00626 pc->setData(QseDataReference(m_DataSet, s, nxc, c));
00627 pc->setYAxis(QwtPlot::yRight);
00628 pc->setPen(m_Pens[pnnum]);
00629 QwtSymbol ps = m_Symbols[smnum];
00630 ps.setPen(m_Pens[pnnum]);
00631 ps.setBrush(QBrush(m_Pens[pnnum].color()));
00632 pc->setSymbol(ps);
00633 pnnum = (pnnum + m_CurvePenStep + NPENS) % NPENS;
00634 smnum = (smnum + m_CurveSymbolStep + NSYMBOLS) % NSYMBOLS;
00635 pc->setItemAttribute(QwtPlotItem::Legend, m_LegendShown);
00636 pc->attach(m_Graph);
00637 hasy2 = true;
00638 }
00639 }
00640 }
00641 }
00642 }
00643 }
00644 }
00645 }
00646
00647 if (ncurves > MAX_CURVES) {
00648 m_Graph -> setTitle(QString("%1 of %2 curves from %3 scans").
00649 arg(MAX_CURVES).arg(ncurves).arg(npscans));
00650 } else if (npscans > 1) {
00651 m_Graph -> setTitle(QString("%1 curves from %2 scans").arg(ncurves).arg(npscans));
00652 }
00653
00654 setAxisTitle(QwtPlot::xBottom, xnames);
00655 setAxisTitle(QwtPlot::yLeft, ynames);
00656 setAxisTitle(QwtPlot::yRight, y2names);
00657
00658 enableAxes(hasy1, hasy2);
00659
00660 m_Graph -> replot();
00661
00662 if (m_Zoomer -> zoomRectIndex() == 0) {
00663 m_Zoomer -> setZoomBase();
00664 }
00665
00666 if (m_Zoomer2 -> zoomRectIndex() == 0) {
00667 m_Zoomer2 -> setZoomBase();
00668 }
00669
00670
00671 }
00672
00673 void QseGraphController::setAxisTitle(int axisId, const QSet<QString>& names)
00674 {
00675 QString title, name;
00676 int n = names.count();
00677 int nt;
00678
00679 if (n == 0) {
00680 m_Graph -> setAxisTitle(axisId, "");
00681 } else {
00682 if (n > 4) {
00683 nt = 4;
00684 } else {
00685 nt = n;
00686 }
00687
00688 QSet<QString>::const_iterator it = names.constBegin();
00689 title = *it;
00690
00691 for (int i = 1; i<nt; i++) {
00692 it++;
00693 title += ", " + *it;
00694 }
00695
00696 if (n > nt) {
00697 title += "...";
00698 }
00699
00700 m_Graph -> setAxisTitle(axisId, title);
00701 }
00702 }
00703
00704 void QseGraphController::enableAxes(bool y1, bool y2)
00705 {
00706 m_Graph -> enableAxis(QwtPlot::yLeft, y1 | !y2);
00707 m_Graph -> enableAxis(QwtPlot::yRight, y2);
00708
00709 if (y1 | !y2) {
00710 m_Zoomer -> setTrackerMode(QwtPicker::AlwaysOn);
00711 m_Zoomer -> setRubberBand(QwtPicker::RectRubberBand);
00712 m_Zoomer2 -> setTrackerMode(QwtPicker::AlwaysOff);
00713 m_Zoomer2 -> setRubberBand(QwtPicker::NoRubberBand);
00714 } else {
00715 m_Zoomer2 -> setTrackerMode(QwtPicker::AlwaysOn);
00716 m_Zoomer2 -> setRubberBand(QwtPicker::RectRubberBand);
00717 m_Zoomer -> setTrackerMode(QwtPicker::AlwaysOff);
00718 m_Zoomer -> setRubberBand(QwtPicker::NoRubberBand);
00719 }
00720 }
00721
00722 void QseGraphController::setAutoScale()
00723 {
00724 m_Graph -> setAxisAutoScale(QwtPlot::xBottom);
00725 m_Graph -> setAxisAutoScale(QwtPlot::yLeft);
00726 m_Graph -> setAxisAutoScale(QwtPlot::yRight);
00727 m_Graph -> replot();
00728
00729 m_Zoomer -> setZoomBase();
00730 m_Zoomer2 -> setZoomBase();
00731 }
00732
00733 void QseGraphController::showLegend()
00734 {
00735 m_LegendShown = true;
00736
00737 QwtPlotItem *item;
00738 const QwtPlotItemList &items = m_Graph->itemList();
00739
00740 foreach (item, items) {
00741 item->setItemAttribute(QwtPlotItem::Legend, true);
00742 }
00743
00744 m_Graph -> updateLayout();
00745 }
00746
00747 void QseGraphController::hideLegend()
00748 {
00749 m_LegendShown = false;
00750
00751 QwtPlotItem *item;
00752 const QwtPlotItemList &items = m_Graph->itemList();
00753
00754 foreach (item, items) {
00755 item->setItemAttribute(QwtPlotItem::Legend, false);
00756 }
00757
00758 m_Graph -> updateLayout();
00759 }
00760
00761 void QseGraphController::printGraph()
00762 {
00763 QPrinter printer;
00764
00765 printer.setCreator("Spec EXAFS Processor");
00766
00767
00768 QPrintDialog dialog(&printer);
00769
00770 if (dialog.exec()) {
00771 QwtPlotPrintFilter filter;
00772
00773
00774
00775
00776
00777 m_Graph -> print(printer, filter);
00778 }
00779 }
00780
00781 void QseGraphController::legendChecked(QwtPlotItem *it, bool checked)
00782 {
00783 if (it) {
00784 QwtPlotCurve *pc = dynamic_cast<QwtPlotCurve*>(it);
00785
00786 if (pc) {
00787 QPen p = pc->pen();
00788 if (checked) {
00789 p.setWidth(3);
00790 } else {
00791 p.setWidth(0);
00792 }
00793
00794 if (m_Graph) {
00795 pc->setPen(p);
00796 m_Graph->replot();
00797 }
00798 }
00799 }
00800 }
00801
00802 void QseGraphController::columnsTableContextMenu(const QPoint & pos)
00803 {
00804 QMenu menu(NULL, NULL);
00805
00806 QAction* selectCells = menu.addAction(QString("Select..."));
00807 QAction* deselectCells = menu.addAction(QString("Deselect..."));
00808
00809 menu.setMouseTracking(TRUE);
00810
00811 QAction* id = menu.exec(QCursor::pos() + QPoint( -40, -10), selectCells);
00812
00813 }
00814
00815 void QseGraphController::scansListContextMenu(const QPoint & pos)
00816 {
00817 QMenu menu(NULL, NULL);
00818
00819 QAction* selectCells = menu.addAction(QString("Select..."));
00820 QAction* deselectCells = menu.addAction(QString("Deselect..."));
00821
00822 menu.setMouseTracking(TRUE);
00823
00824 QAction* id = menu.exec(QCursor::pos() + QPoint( -40, -10), selectCells);
00825 }
00826
00827 void QseGraphController::graphContextMenu(const QPoint &pos)
00828 {
00829 QMenu menu(NULL, NULL);
00830 QAction *action;
00831
00832 foreach (action, m_Actions) {
00833 menu.addAction(action);
00834 }
00835
00836 QAction* autoscaleItem = menu.addAction(QString("Autoscale Graph"));
00837 QAction* printItem = menu.addAction(QString("Print Graph..."));
00838
00839 QAction* showLegendItem = NULL;
00840 QAction* hideLegendItem = NULL;
00841
00842 if (m_LegendShown) {
00843 hideLegendItem = menu.addAction(QString("Hide Legend"));
00844 } else {
00845 showLegendItem = menu.addAction(QString("Display Legend"));
00846 }
00847
00848 QAction* saveItem = NULL;
00849 QAction* removeItem = NULL;
00850
00851 if (m_ScansView) {
00852 saveItem = menu.addAction(QString("Save selected scans"));
00853 removeItem = menu.addAction(QString("Remove selected scans"));
00854 }
00855
00856 menu.setMouseTracking(TRUE);
00857
00858 QAction* id = menu.exec(QCursor::pos() + QPoint( -40, -10), saveItem);
00859
00860 if (id == autoscaleItem) {
00861 setAutoScale();
00862 } else if (id == printItem) {
00863 printGraph();
00864 } else if (id == showLegendItem) {
00865 showLegend();
00866 } else if (id == hideLegendItem) {
00867 hideLegend();
00868 } else if (m_ScansView && (id == saveItem)) {
00869 saveSelectedScans();
00870 } else if (m_ScansView && (id == removeItem)) {
00871 removeSelectedScans();
00872 }
00873 }
00874
00875 int QseGraphController::scanCount()
00876 {
00877 return m_DataSet -> scanCount();
00878 }
00879
00880 QList<int> QseGraphController::selectedScans()
00881 {
00882 QList<int> res;
00883 int nscans = scanCount();
00884
00885 for (int i=0; i<nscans; i++) {
00886 if (scanSelected(i)) {
00887 res.append(i);
00888 }
00889 }
00890
00891 return res;
00892 }
00893
00894 void QseGraphController::saveSelectedScans()
00895 {
00896 QseDataExport::exportSelectedData("export/data", m_DataSet, selectedScans());
00897 }
00898
00899 void QseGraphController::removeSelectedScans()
00900 {
00901 }
00902
00903 void QseGraphController::zoomGraphAll()
00904 {
00905 setAutoScale();
00906 }
00907
00908 void QseGraphController::zoomGraphOut()
00909 {
00910 m_Zoomer -> zoom(-1);
00911 m_Zoomer2 -> zoom(-1);
00912 }
00913
00914 void QseGraphController::zoomGraphIn()
00915 {
00916 m_Zoomer -> zoom(1);
00917 m_Zoomer2 -> zoom(1);
00918 }