Class: Cosmos::TabbedPlotsPlotEditor

Inherits:
Qt::Dialog show all
Defined in:
lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_plot_editor.rb

Overview

Dialog to edit the plot

Instance Method Summary collapse

Methods inherited from Qt::Dialog

#exec

Constructor Details

#initialize(parent, title, plot_types, plot = nil) ⇒ TabbedPlotsPlotEditor

Returns a new instance of TabbedPlotsPlotEditor.



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
# File 'lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_plot_editor.rb', line 21

def initialize(parent, title, plot_types, plot = nil)
  super(parent)
  setWindowTitle(title)

  @layout = Qt::VBoxLayout.new

  unless plot
    # Create combobox to select plot type
    @combobox = Qt::ComboBox.new(self)
    plot_types.each {|plot_type| @combobox.addItem(plot_type.to_s.upcase)}
    @combobox.setMaxVisibleItems(plot_types.length)
    @combobox.connect(SIGNAL('currentIndexChanged(int)')) { handle_plot_type_change() }
    @combo_layout = Qt::FormLayout.new()
    @combo_layout.addRow('Plot Type:', @combobox)
    @layout.addLayout(@combo_layout)

    # Separator before actual editing dialog
    @sep1 = Qt::Frame.new
    @sep1.setFrameStyle(Qt::Frame::HLine | Qt::Frame::Sunken)
    @layout.addWidget(@sep1)
  else
    setWindowTitle(title + " : #{plot.plot_type}")
  end

  # Create editor class for specific plot type
  # Defaults to plot_types[0] if a plot was not given
  if plot
    plot_type = plot.class.to_s[0..-5].downcase
    plot_type = plot_type.split('::')[-1] # Remove Cosmos:: if present
  else
    plot_type = plot_types[0].to_s.downcase
  end
  @editor_layout = Qt::VBoxLayout.new
  @layout.addLayout(@editor_layout)
  @editor = Cosmos.require_class(plot_type + '_plot_editor').new(self, plot)
  @editor_layout.addWidget(@editor)

  # Separator before buttons
  @sep2 = Qt::Frame.new
  @sep2.setFrameStyle(Qt::Frame::HLine | Qt::Frame::Sunken)
  @layout.addWidget(@sep2)
  @layout.addStretch

  # Create OK and Cancel buttons
  @ok_button = Qt::PushButton.new('Ok')
  @ok_button.setDefault(true)
  connect(@ok_button, SIGNAL('clicked()'), self, SLOT('accept()'))
  @cancel_button = Qt::PushButton.new('Cancel')
  connect(@cancel_button, SIGNAL('clicked()'), self, SLOT('reject()'))
  @button_layout = Qt::HBoxLayout.new()
  @button_layout.addWidget(@ok_button)
  @button_layout.addWidget(@cancel_button)
  @layout.addLayout(@button_layout)
  @ok_button.setDefault(true)

  setLayout(@layout)
end

Instance Method Details

#executeObject

Executes the plot editor dialog box



80
81
82
83
84
85
86
87
# File 'lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_plot_editor.rb', line 80

def execute
  return_value = nil
  result = exec()
  if result == Qt::Dialog::Accepted
    return_value = @editor.plot
  end
  return return_value
end