4 #include <QTableWidget>
6 #include <QPrintDialog>
12 #include <qwt_plot_zoomer.h>
13 #include <qwt_plot_panner.h>
14 #include <qwt_plot_magnifier.h>
15 #include <qwt_plot_curve.h>
16 #include <qwt_plot_layout.h>
17 #include <qwt_legend.h>
18 #include <qwt_picker_machine.h>
19 #include <qwt_plot_renderer.h>
33 m_ScansSelection(NULL),
35 m_ColumnsSelection(NULL),
47 m_Pens[0].setColor(Qt::black);
48 m_Pens[1].setColor(Qt::red);
49 m_Pens[2].setColor(Qt::green);
50 m_Pens[3].setColor(Qt::blue);
51 m_Pens[4].setColor(Qt::cyan);
52 m_Pens[5].setColor(Qt::magenta);
53 m_Pens[6].setColor(Qt::darkYellow);
54 m_Pens[7].setColor(Qt::darkRed);
55 m_Pens[8].setColor(Qt::darkGreen);
56 m_Pens[9].setColor(Qt::darkBlue);
57 m_Pens[10].setColor(Qt::darkCyan);
58 m_Pens[11].setColor(Qt::darkMagenta);
62 m_Graph->setCanvasBackground(QColor(Qt::white));
64 m_Zoomer =
new QwtPlotZoomer(QwtPlot::xBottom, QwtPlot::yLeft, m_Graph->canvas());
65 m_Zoomer -> setStateMachine(
new QwtPickerDragRectMachine());
66 m_Zoomer2 =
new QwtPlotZoomer(QwtPlot::xTop, QwtPlot::yRight, m_Graph->canvas());
67 m_Zoomer2 -> setStateMachine(
new QwtPickerDragRectMachine());
69 m_Magnifier =
new QwtPlotMagnifier(m_Graph->canvas());
77 m_Zoomer -> setMousePattern(QwtEventPattern::MouseSelect2,
78 Qt::LeftButton, Qt::ControlModifier | Qt::ShiftModifier);
79 m_Zoomer2 -> setMousePattern(QwtEventPattern::MouseSelect2,
80 Qt::LeftButton, Qt::ControlModifier | Qt::ShiftModifier);
82 m_Zoomer -> setMousePattern(QwtEventPattern::MouseSelect3,
83 Qt::LeftButton, Qt::ControlModifier);
84 m_Zoomer2 -> setMousePattern(QwtEventPattern::MouseSelect3,
85 Qt::LeftButton, Qt::ControlModifier);
87 m_Panner =
new QwtPlotPanner(m_Graph->canvas());
88 m_Panner -> setMouseButton(Qt::MidButton);
92 m_Legend -> setFrameStyle(QFrame::Box|QFrame::Sunken);
93 m_Legend -> setDefaultItemMode(QwtLegendData::Checkable);
95 m_Graph -> insertLegend(
m_Legend, QwtPlot::BottomLegend);
97 connect(
m_Legend, SIGNAL(checked(
const QVariant&,
bool,
int)),
this, SLOT(
legendChecked(
const QVariant&,
bool,
int)));
99 m_Graph -> canvas() -> setContextMenuPolicy(Qt::CustomContextMenu);
100 connect(m_Graph -> canvas(), SIGNAL(customContextMenuRequested(
const QPoint &)),
103 m_ScansView -> setContextMenuPolicy(Qt::CustomContextMenu);
104 connect(m_ScansView, SIGNAL(customContextMenuRequested(
const QPoint &)),
107 m_ColumnsView -> setContextMenuPolicy(Qt::CustomContextMenu);
108 connect(m_ColumnsView, SIGNAL(customContextMenuRequested(
const QPoint &)),
125 connect(m_ColumnsView, SIGNAL(clicked(
const QModelIndex&)),
129 SIGNAL(selectionChanged(
const QItemSelection&,
const QItemSelection&)),
133 connect(m_PrintButton, SIGNAL(clicked()),
this, SLOT(
printGraph()));
134 connect(m_ZoomAllButton, SIGNAL(clicked()),
this, SLOT(
zoomGraphAll()));
135 connect(m_ZoomInButton, SIGNAL(clicked()),
this, SLOT(
zoomGraphIn()));
136 connect(m_ZoomOutButton, SIGNAL(clicked()),
this, SLOT(
zoomGraphOut()));
139 m_ScansView->resizeColumnsToContents();
140 m_ScansView->resizeRowsToContents();
142 m_ColumnsView->resizeColumnsToContents();
143 m_ColumnsView->resizeRowsToContents();
235 (
const QItemSelection & selected,
const QItemSelection & deselected)
239 m_SelectedScanColumns.clear();
240 m_SelectedScanColumnCounts.clear();
244 for (
int i = 0; i<n; i++) {
245 if (scanSelected(i)) {
246 QseScan* s = m_DataSet -> scan(i);
251 for (
int i=0; i<nc; i++) {
254 QString colname = col->
name();
255 if (!m_SelectedScanColumnCounts.contains(colname)) {
256 m_SelectedScanColumns.append(colname);
258 m_SelectedScanColumnCounts[colname] += 1;
265 m_ColumnsModel -> columnsChanged();
273 (
int n, QSet<QString>& set)
275 QString colname = selectedColumn(n);
277 if (set.contains(colname)) {
285 (
const QItemSelection & selected,
const QItemSelection & deselected)
289 QItemSelectionRange r;
291 foreach(r, selected) {
292 int tp=r.top(), bt=r.bottom();
293 int lf=r.left(), rt=r.right();
294 for (
int i=tp; i<=bt; i++) {
295 for (
int j=lf; j<=rt; j++) {
296 printf(
"QseGraphController::columnsSelectionChanged::selected(%d,%d)\n",i,j);
315 m_ColumnsModel -> emitDataChanged(r.topLeft(), r.bottomRight());
318 foreach(r, deselected) {
319 int tp=r.top(), bt=r.bottom();
320 int lf=r.left(), rt=r.right();
321 for (
int i=tp; i<=bt; i++) {
322 for (
int j=lf; j<=rt; j++) {
323 printf(
"QseGraphController::columnsSelectionChanged::deselected(%d,%d)\n",i,j);
327 m_ColumnsModel -> emitDataChanged(r.topLeft(), r.bottomRight());
338 int i = index.row(), j = index.column();
367 m_Graph -> detachItems(QwtPlotItem::Rtti_PlotCurve);
368 m_Graph -> detachItems(QwtPlotItem::Rtti_PlotMarker);
374 for (s=0; s<nscanstotal; s++) {
387 QSet<QString> xnames, ynames, y2names;
390 m_Graph ->
setTitle(QString(
"%1 Scans").arg(nscans));
396 for (s=0; s<nscanstotal; s++) {
424 for (
int c = 0; c<nc; c++) {
427 QString colname = col->
name();
437 if (nc && (xc == NULL)) {
446 for (
int c = 0; c<nc; c++) {
449 QString colname = yc->
name();
457 xnames.insert(xc->
name());
459 ynames.insert(colname);
470 name = QString(
"S%1:%2").arg(scan->
scanNumber()).arg(colname);
473 QwtPlotCurve *pc =
new QwtPlotCurve(name);
476 pc->setPen(
m_Pens[pnnum]);
478 ps->setPen(
m_Pens[pnnum]);
479 ps->setBrush(QBrush(
m_Pens[pnnum].color()));
491 for (
int c = 0; c<nc; c++) {
494 QString colname = yc->
name();
502 xnames.insert(xc->
name());
504 y2names.insert(colname);
515 name = QString(
"S%1:%2").arg(scan->
scanNumber()).arg(colname);
518 QwtPlotCurve *pc =
new QwtPlotCurve(name);
521 pc->setYAxis(QwtPlot::yRight);
522 pc->setPen(
m_Pens[pnnum]);
524 ps->setPen(
m_Pens[pnnum]);
525 ps->setBrush(QBrush(
m_Pens[pnnum].color()));
542 m_Graph ->
setTitle(QString(
"%1 of %2 curves from %3 scans").
544 }
else if (npscans > 1) {
545 m_Graph ->
setTitle(QString(
"%1 curves from %2 scans").arg(ncurves).arg(npscans));
556 if (
m_Zoomer -> zoomRectIndex() == 0) {
570 int n = names.count();
582 QSet<QString>::const_iterator it = names.constBegin();
585 for (
int i = 1; i<nt; i++) {
600 m_Graph -> enableAxis(QwtPlot::yLeft, y1 | !y2);
601 m_Graph -> enableAxis(QwtPlot::yRight, y2);
604 m_Zoomer -> setTrackerMode(QwtPicker::AlwaysOn);
605 m_Zoomer -> setRubberBand(QwtPicker::RectRubberBand);
606 m_Zoomer2 -> setTrackerMode(QwtPicker::AlwaysOff);
607 m_Zoomer2 -> setRubberBand(QwtPicker::NoRubberBand);
609 m_Zoomer2 -> setTrackerMode(QwtPicker::AlwaysOn);
610 m_Zoomer2 -> setRubberBand(QwtPicker::RectRubberBand);
611 m_Zoomer -> setTrackerMode(QwtPicker::AlwaysOff);
612 m_Zoomer -> setRubberBand(QwtPicker::NoRubberBand);
618 m_Graph -> setAxisAutoScale(QwtPlot::xBottom);
619 m_Graph -> setAxisAutoScale(QwtPlot::yLeft);
620 m_Graph -> setAxisAutoScale(QwtPlot::yRight);
632 const QwtPlotItemList &items = m_Graph->itemList();
634 foreach (item, items) {
635 item->setItemAttribute(QwtPlotItem::Legend,
true);
638 m_Graph -> updateLayout();
646 const QwtPlotItemList &items = m_Graph->itemList();
648 foreach (item, items) {
649 item->setItemAttribute(QwtPlotItem::Legend,
false);
652 m_Graph -> updateLayout();
657 QPrinter printer (QPrinter::HighResolution);
659 printer.setCreator(
"Spec EXAFS Processor");
662 QPrintDialog dialog(&printer);
665 QwtPlotRenderer filter;
671 filter.renderTo(m_Graph, printer);
679 QwtPlotItem *item = m_Graph->infoToItem(v);
682 QwtPlotCurve *pc =
dynamic_cast<QwtPlotCurve*
>(item);
702 QMenu menu(NULL, NULL);
704 QAction* selectCells = menu.addAction(QString(
"Select..."));
705 QAction* deselectCells = menu.addAction(QString(
"Deselect..."));
707 menu.setMouseTracking(
true);
709 QAction*
id = menu.exec(QCursor::pos() + QPoint( -40, -10), selectCells);
715 QMenu menu(NULL, NULL);
717 QAction* selectCells = menu.addAction(QString(
"Select..."));
718 QAction* deselectCells = menu.addAction(QString(
"Deselect..."));
720 menu.setMouseTracking(
true);
722 QAction*
id = menu.exec(QCursor::pos() + QPoint( -40, -10), selectCells);
727 QMenu menu(NULL, NULL);
731 menu.addAction(action);
734 QAction* autoscaleItem = menu.addAction(QString(
"Autoscale Graph"));
735 QAction* printItem = menu.addAction(QString(
"Print Graph..."));
737 QAction* showLegendItem = NULL;
738 QAction* hideLegendItem = NULL;
741 hideLegendItem = menu.addAction(QString(
"Hide Legend"));
743 showLegendItem = menu.addAction(QString(
"Display Legend"));
746 QAction* saveItem = NULL;
747 QAction* removeItem = NULL;
750 saveItem = menu.addAction(QString(
"Save selected scans"));
751 removeItem = menu.addAction(QString(
"Remove selected scans"));
754 menu.setMouseTracking(
true);
756 QAction*
id = menu.exec(QCursor::pos() + QPoint( -40, -10), saveItem);
758 if (
id == autoscaleItem) {
760 }
else if (
id == printItem) {
762 }
else if (
id == showLegendItem) {
764 }
else if (
id == hideLegendItem) {
766 }
else if (m_ScansView && (
id == saveItem)) {
768 }
else if (m_ScansView && (
id == removeItem)) {
783 for (
int i=0; i<nscans; i++) {
822 QwtSymbol *res = NULL;
827 res =
new QwtSymbol(QwtSymbol::Ellipse, QBrush(),
m_Pens[0], QSize(3,3));
831 res =
new QwtSymbol(QwtSymbol::Ellipse, QBrush(),
m_Pens[1], QSize(5,5));
835 res =
new QwtSymbol(QwtSymbol::Rect, QBrush(),
m_Pens[2], QSize(5,5));
839 res =
new QwtSymbol(QwtSymbol::Diamond, QBrush(),
m_Pens[3], QSize(5,5));
843 res =
new QwtSymbol(QwtSymbol::Triangle, QBrush(),
m_Pens[4], QSize(5,5));
847 res =
new QwtSymbol(QwtSymbol::DTriangle, QBrush(),
m_Pens[5], QSize(5,5));
851 res =
new QwtSymbol(QwtSymbol::UTriangle, QBrush(),
m_Pens[6], QSize(5,5));
855 res =
new QwtSymbol(QwtSymbol::LTriangle, QBrush(),
m_Pens[7], QSize(5,5));
859 res =
new QwtSymbol(QwtSymbol::RTriangle, QBrush(),
m_Pens[8], QSize(5,5));
863 res =
new QwtSymbol(QwtSymbol::Cross, QBrush(),
m_Pens[9], QSize(5,5));
867 res =
new QwtSymbol(QwtSymbol::XCross, QBrush(),
m_Pens[10], QSize(5,5));
871 res =
new QwtSymbol(QwtSymbol::Star1, QBrush(),
m_Pens[11], QSize(5,5));
QString selectedColumn(int i) const
QSet< QString > m_PlotYColumns
QwtSymbol * newSymbol(int n)
QHash< QString, int > m_SelectedScanColumnCounts
void setAxisTitle(int axisId, const QSet< QString > &names)
void scansSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
bool selectedPlotY(int i) const
QseGraphController(QseDataSet *ds, QWidget *parent=0)
QItemSelectionModel * m_ColumnsSelection
void toggleGraphSelection(int n, QSet< QString > &set)
bool selectedPlotX(int i) const
QseGraphScansModel * m_ScansModel
static const int MAX_CURVES
void graphContextMenu(const QPoint &pos)
QSet< QString > m_PlotXColumns
QString scanCommand() const
QList< int > selectedScans()
void columnsSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
static void exportSelectedData(const QString &id, QseDataSet *data, QList< int > selections)
void enableAxes(bool y1, bool y2)
QwtPlotZoomer * m_Zoomer2
void columnsCellClicked(const QModelIndex &index)
void removeSelectedScans()
static const int NSYMBOLS
QList< QString > m_SelectedScanColumns
QList< QAction * > m_Actions
int rowCount(const QModelIndex &parent=QModelIndex()) const
void setTitle(const QString &title)
void addContextMenuAction(QAction *action)
void scansListContextMenu(const QPoint &pos)
QseColumn * column(int n) const
void columnsTableContextMenu(const QPoint &pos)
void operationCompleted()
QwtPlotMagnifier * m_Magnifier
QSet< QString > m_PlotNormColumns
void legendChecked(const QVariant &v, bool checked, int n)
QseGraphColumnsModel * m_ColumnsModel
QSet< QString > m_PlotY2Columns
int selectedColumnCount() const
bool selectedPlotY2(int i) const
bool selectedPlotNorm(int i) const
QItemSelectionModel * m_ScansSelection
QseDataSet * dataSet() const