-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeSeriesCtrl.cpp
More file actions
102 lines (89 loc) · 3.05 KB
/
TimeSeriesCtrl.cpp
File metadata and controls
102 lines (89 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* File: TimeSeriesCtrl.cpp
* Author: heshan
*
* Created on May 9, 2018, 3:13 PM
*/
#include "TimeSeriesCtrl.h"
#include <wx/filedlg.h>
#include <iostream>
TimeSeriesCtrl::TimeSeriesCtrl(wxWindow *parent,
wxWindowID id,
const wxLineChartData &data,
const wxPoint &pos,
const wxSize &size,
long style)
: wxChartCtrl(parent, id, pos, size, style),
m_lineChart(data, size)
{
CreateContextMenu();
}
TimeSeriesCtrl::TimeSeriesCtrl(wxWindow *parent,
wxWindowID id,
const wxLineChartData &data,
const wxLineChartOptions &options,
const wxPoint &pos,
const wxSize &size,
long style)
: wxChartCtrl(parent, id, pos, size, style),
m_lineChart(data, size)
{
CreateContextMenu();
}
wxLineChart& TimeSeriesCtrl::GetChart()
{
return m_lineChart;
}
void TimeSeriesCtrl::CreateContextMenu()
{
m_contextMenu.Append(wxID_SAVEAS, wxString("Save as"));
Bind(wxEVT_CONTEXT_MENU,
[this](wxContextMenuEvent& evt)
{
PopupMenu(&m_contextMenu, ScreenToClient(evt.GetPosition()));
}
);
m_contextMenu.Bind(wxEVT_MENU,
[this](wxCommandEvent &)
{
wxFileDialog saveFileDialog(this, _("Save file"), "", "",
"JPEG files (*.jpg;*.jpeg)|*.jpg;*.jpeg|PNG files (*.png)|*.png",
wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
if (saveFileDialog.ShowModal() == wxID_CANCEL)
return;
wxString filename = saveFileDialog.GetPath();
wxBitmapType type = wxBitmapType::wxBITMAP_TYPE_INVALID;
switch (saveFileDialog.GetFilterIndex())
{
case 0:
type = wxBitmapType::wxBITMAP_TYPE_JPEG;
if (wxImage::FindHandler(wxBitmapType::wxBITMAP_TYPE_JPEG) == 0)
{
wxImage::AddHandler(new wxJPEGHandler());
}
break;
case 1:
type = wxBitmapType::wxBITMAP_TYPE_PNG;
if (wxImage::FindHandler(wxBitmapType::wxBITMAP_TYPE_PNG) == 0)
{
wxImage::AddHandler(new wxPNGHandler());
}
break;
}
m_lineChart.Save(filename, type, GetSize());
},
wxID_SAVEAS
);
}
int TimeSeriesCtrl::updateChart(wxWindow *parent,
wxWindowID id,
const wxLineChartData &data,
const wxLineChartOptions &options,
const wxPoint &pos,
const wxSize &size,
long style)
{
std::cout<<"chart updated...!";
//CreateContextMenu();
return 0;
}