CFEL - ASG Software Suite  2.5.0
CASS
data_viewer.cpp
Go to the documentation of this file.
1 // Copyright (C) 2014 Lutz Foucar
2 
3 /**
4  * @file data_viewer.cpp contains the base class for all data viewers
5  *
6  * @author Lutz Foucar
7  */
8 
9 #include <QtCore/QSettings>
10 
11 #if QT_VERSION >= 0x050000
12 #include <QtPrintSupport/QPrintDialog>
13 #include <QtPrintSupport/QPrinter>
14 #else
15 #include <QtGui/QPrintDialog>
16 #include <QtGui/QPrinter>
17 #endif
18 #include <QtGui/QCloseEvent>
19 
20 #include <qwt_plot_renderer.h>
21 #include <qwt_plot.h>
22 
23 #include "data_viewer.h"
24 
25 using namespace jocassview;
26 
28  : QMainWindow(parent),
29  _plot(0)
30 {
31  setWindowTitle(title);
32  setAttribute(Qt::WA_DeleteOnClose);
33 }
34 
36 {
37 
38 }
39 
40 void DataViewer::print()const
41 {
42  QPrinter printer( QPrinter::HighResolution );
43  printer.setDocName(windowTitle());
44  printer.setCreator(windowTitle());
45  printer.setOrientation( QPrinter::Landscape );
46 
47  QPrintDialog dialog(&printer);
48  if ( dialog.exec() == QDialog::Accepted)
49  {
50  QwtPlotRenderer renderer;
51  if ( printer.colorMode() == QPrinter::GrayScale )
52  {
53  renderer.setDiscardFlag( QwtPlotRenderer::DiscardBackground );
54  renderer.setDiscardFlag( QwtPlotRenderer::DiscardCanvasBackground );
55  renderer.setDiscardFlag( QwtPlotRenderer::DiscardCanvasFrame );
56  renderer.setLayoutFlag( QwtPlotRenderer::FrameWithScales );
57  }
58  renderer.renderTo( _plot, printer );
59  }
60 }
61 
63 {
64 
65 }
66 
68 {
69  emit viewerClosed(this);
70  event->accept();
71 }
72 
74 {
75  QMainWindow::moveEvent(event);
76  QSettings settings;
77  settings.beginGroup(windowTitle());
78  settings.setValue("WindowPosition",frameGeometry().topLeft());
79  settings.endGroup();
80 }
81 
83 {
84  QSettings settings;
85  settings.beginGroup(windowTitle());
86  settings.setValue("WindowSize",event->size());
87  settings.endGroup();
88 }
virtual void print() const
print the plot
Definition: data_viewer.cpp:40
void viewerClosed(DataViewer *viewer)
signal emitted when viewer is about to be destroyed
contains the base class for all data viewers
QwtPlot * _plot
the plot inside which the data will be displayed
Definition: data_viewer.h:115
virtual ~DataViewer()
destructor
Definition: data_viewer.cpp:35
void resizeEvent(QResizeEvent *event)
receive resize events to store the current size to the settings
Definition: data_viewer.cpp:82
void closeEvent(QCloseEvent *event)
react when a close event is send to this viewer
Definition: data_viewer.cpp:67
setValue(const QString &key, const QVariant &value)
setCreator(const QString &creator)
setDocName(const QString &name)
DataViewer(QString title, QWidget *parent)
constructor
Definition: data_viewer.cpp:27
setOrientation(Orientation orientation)
virtual void dataChanged()
use this to tell that the data has changed
Definition: data_viewer.cpp:62
void moveEvent(QMoveEvent *event)
receive move events to store the current position to the settings
Definition: data_viewer.cpp:73
beginGroup(const QString &prefix)