xwavengraph.h
1 /***************************************************************************
2  Copyright (C) 2002-2015 Kentaro Kitagawa
3  kitagawa@phys.s.u-tokyo.ac.jp
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  You should have received a copy of the GNU Library General
11  Public License and a list of authors along with this program;
12  see the files COPYING and AUTHORS.
13 ***************************************************************************/
14 //---------------------------------------------------------------------------
15 
16 #ifndef xwavengraphH
17 #define xwavengraphH
18 //---------------------------------------------------------------------------
19 
20 #include "xnodeconnector.h"
21 #include <vector>
22 #include "graph.h"
23 #include <fstream>
24 
25 class XQGraph;
26 class QLineEdit;
27 class QAbstractButton;
28 class QPushButton;
29 class XAxis;
30 class XXYPlot;
31 class Ui_FrmGraphNURL;
33 
34 //! Graph widget with internal data sets. The data can be saved as a text file.
35 //! \sa XQGraph, XGraph
36 
37 class DECLSPEC_KAME XWaveNGraph: public XNode {
38 public:
39  XWaveNGraph(const char *name, bool runtime, FrmGraphNURL *item);
40  XWaveNGraph(const char *name, bool runtime, XQGraph *graphwidget,
41  QLineEdit *ed, QAbstractButton *btn, QPushButton *btndump);
42  virtual ~XWaveNGraph();
43 
44  const shared_ptr<XGraph> &graph() const { return m_graph;}
45  const shared_ptr<XStringNode> &filename() const { return m_filename;}
46 
47  const shared_ptr<XTouchableNode> &dump() const { return m_dump;}
48  void drawGraph(Transaction &tr);
49 
50  struct DECLSPEC_KAME Payload : public XNode::Payload {
51  void clearPoints();
52  void clearPlots();
53  void insertPlot(const XString &label, int colx = 0, int coly1 = 1,
54  int coly2 = -1, int colweight = -1, int colz = -1);
55 
56  void setLabel(unsigned int col, const char *label);
57  const std::vector<XString> &labels() const {return m_labels;}
58  void setRowCount(unsigned int rowcnt);
59  void setColCount(unsigned int colcnt, const char **labels);
60  unsigned int rowCount() const {
61  return m_colcnt ? m_cols.size() / m_colcnt : 0;}
62  unsigned int colCount() const {return m_colcnt;}
63  unsigned int numPlots() const { return m_plots.size();}
64 
65  const double *cols(unsigned int n) const;
66  double *cols(unsigned int n);
67  const double *weight() const;
68  //! \param plotnum start with zero.
69  int colX(unsigned int plotnum) const { return m_plots[plotnum].colx;}
70  //! \param plotnum start with zero.
71  int colY1(unsigned int plotnum) const { return m_plots[plotnum].coly1;}
72  //! \param plotnum start with zero.
73  int colY2(unsigned int plotnum) const { return m_plots[plotnum].coly2;}
74  //! \param plotnum start with zero.
75  int colWeight(unsigned int plotnum) const { return m_plots[plotnum].colweight;}
76  //! \param plotnum start with zero.
77  int colZ(unsigned int plotnum) const { return m_plots[plotnum].colz;}
78  //! \param plotnum start with zero.
79  const shared_ptr<XXYPlot> &plot(unsigned int plotnum) const { return m_plots[plotnum].xyplot;}
80  const shared_ptr<XAxis> &axisx() const { return m_axisx;}
81  const shared_ptr<XAxis> &axisy() const { return m_axisy;}
82  const shared_ptr<XAxis> &axisy2() const { return m_axisy2;}
83  const shared_ptr<XAxis> &axisz() const { return m_axisz;}
84  const shared_ptr<XAxis> &axisw() const { return m_axisw;}
85 
86  const Talker<bool> &onIconChanged() const { return m_tlkOnIconChanged;}
87  Talker<bool> &onIconChanged() { return m_tlkOnIconChanged;}
88  private:
89 // friend class XWaveNGraph;
90  struct Plot {
91  shared_ptr<XXYPlot> xyplot;
92  int colx, coly1, coly2, colweight, colz;
93  };
94  unsigned int m_colcnt;
95  std::vector<XString> m_labels;
96  std::vector<double> m_cols;
97  int m_colw;
98  std::vector<Plot> m_plots;
99  shared_ptr<XAxis> m_axisx, m_axisy, m_axisy2, m_axisw, m_axisz;
100 
101  Talker<bool> m_tlkOnIconChanged;
102  };
103 private:
104  void init();
105 
106  QPushButton * const m_btnDump;
107 
108  const shared_ptr<XGraph> m_graph;
109 
110  const shared_ptr<XTouchableNode> m_dump;
111  const shared_ptr<XStringNode> m_filename;
112 
113  shared_ptr<XListener> m_lsnOnDumpTouched, m_lsnOnFilenameChanged,
114  m_lsnOnIconChanged;
115 
116  void onDumpTouched(const Snapshot &shot, XTouchableNode *);
117  void onFilenameChanged(const Snapshot &shot, XValueNodeBase *);
118  void onIconChanged(const Snapshot &shot, bool );
119 
120  xqcon_ptr m_conFilename, m_conDump;
121 
122  std::fstream m_stream;
123  XMutex m_filemutex;
124 };
125 
126 #endif

Generated for KAME4 by  doxygen 1.8.3