File: plotwindow.cpp

package info (click to toggle)
aoflagger 3.4.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,688 kB
  • sloc: cpp: 83,116; python: 10,187; sh: 260; makefile: 178
file content (114 lines) | stat: -rw-r--r-- 3,822 bytes parent folder | download
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
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "plotwindow.h"

#include "../plot/plotmanager.h"
#include "../plot/plotpropertieswindow.h"

PlotWindow::PlotWindow(PlotManager& plotManager)
    : _plotManager(plotManager),
      _clearButton("_Clear"),
      _editButton("_Edit"),
      _plotPropertiesWindow(nullptr) {
  Gtk::ToolButton();
  plotManager.OnUpdate() = std::bind(&PlotWindow::handleUpdate, this);

  _hBox.pack_start(_plotWidget, Gtk::PACK_EXPAND_WIDGET);

  _plotListStore = Gtk::ListStore::create(_plotListColumns);
  _plotListView.set_model(_plotListStore);
  _plotListView.append_column("Plot title", _plotListColumns._name);
  _plotListView.get_selection()->signal_changed().connect(
      sigc::mem_fun(*this, &PlotWindow::onSelectedPlotChange));

  _clearButton.set_tooltip_text("Clear the list of plots");
  _clearButton.set_icon_name("edit-clear");
  _clearButton.signal_clicked().connect(
      sigc::mem_fun(*this, &PlotWindow::onClearPlotsPressed));
  _toolbar.append(_clearButton);
  _editButton.set_tooltip_text("Edit the properties of the selected plot");
  _editButton.set_icon_name("document-properties");
  _editButton.signal_clicked().connect(
      sigc::mem_fun(*this, &PlotWindow::onEditPlottingPropertiesPressed));
  _toolbar.append(_editButton);
  _toolbar.set_icon_size(Gtk::ICON_SIZE_SMALL_TOOLBAR);
  _toolbar.set_toolbar_style(Gtk::TOOLBAR_ICONS);
  _sideBox.pack_start(_toolbar, Gtk::PACK_SHRINK);
  _sideBox.pack_start(_plotListView);

  _hBox.pack_end(_sideBox, false, false, 3);

  add(_hBox);
  _hBox.show_all();
}

PlotWindow::~PlotWindow() { delete _plotPropertiesWindow; }

void PlotWindow::handleUpdate() {
  updatePlotList();

  const std::vector<std::unique_ptr<XYPlot>>& plots = _plotManager.Items();
  if (!plots.empty()) {
    XYPlot& lastPlot = **plots.rbegin();
    const size_t index = plots.size() - 1;
    _plotWidget.SetPlot(lastPlot);
    for (Gtk::TreeNodeChildren::iterator i = _plotListStore->children().begin();
         i != _plotListStore->children().end(); ++i) {
      if ((*i)[_plotListColumns._index] == index) {
        _plotListView.get_selection()->select(i);
        break;
      }
    }
  } else {
    _plotWidget.Clear();
    delete _plotPropertiesWindow;
    _plotPropertiesWindow = nullptr;
  }
  show();
  raise();
}

void PlotWindow::updatePlotList() {
  const std::vector<std::unique_ptr<XYPlot>>& plots = _plotManager.Items();

  _plotListView.get_selection()->unselect_all();
  _plotListStore->clear();
  for (size_t index = 0; index != plots.size(); ++index) {
    const XYPlot& plot = *plots[index];
    const Gtk::TreeModel::Row row = *_plotListStore->append();
    row[_plotListColumns._index] = index;
    row[_plotListColumns._name] = plot.GetTitle();
  }
  onSelectedPlotChange();
}

void PlotWindow::onSelectedPlotChange() {
  const Gtk::TreeModel::iterator iter =
      _plotListView.get_selection()->get_selected();
  if (iter)  // If anything is selected
  {
    const Gtk::TreeModel::Row row = *iter;
    const size_t index = row[_plotListColumns._index];
    XYPlot& plot = *_plotManager.Items()[index];
    _plotWidget.SetPlot(plot);
  }
}

void PlotWindow::onClearPlotsPressed() {
  _plotListView.get_selection()->unselect_all();
  _plotManager.Clear();
}

void PlotWindow::onEditPlottingPropertiesPressed() {
  delete _plotPropertiesWindow;
  const Gtk::TreeModel::iterator iter =
      _plotListView.get_selection()->get_selected();
  if (iter) {
    XYPlot& plot = *_plotManager.Items()[(*iter)[_plotListColumns._index]];
    _plotPropertiesWindow = new PlotPropertiesWindow(plot, "Plot properties");
    _plotPropertiesWindow->OnChangesApplied =
        std::bind(&PlotWindow::onPlotPropertiesChanged, this);
    _plotPropertiesWindow->show();
    _plotPropertiesWindow->raise();
  }
}

void PlotWindow::onPlotPropertiesChanged() { _plotWidget.Update(); }