Class: Cosmos::TabbedPlotsDataObjectEditor

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

Overview

Dialog which allows the user to edit the data object

Instance Method Summary collapse

Methods inherited from Qt::Dialog

#exec

Constructor Details

#initialize(parent, title, data_object_types, data_object = nil) ⇒ TabbedPlotsDataObjectEditor

Returns a new instance of TabbedPlotsDataObjectEditor.



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

def initialize(parent, title, data_object_types, data_object = nil)
  # Call base class constructor
  super(parent)
  setWindowTitle(title)

  layout = Qt::VBoxLayout.new

  unless data_object
    # Create combobox to select data object type
    @combobox = Qt::ComboBox.new(self)
    data_object_types.each {|data_object_type| @combobox.addItem(data_object_type.to_s.upcase)}
    @combobox.setMaxVisibleItems(data_object_types.length)
    @combobox.connect(SIGNAL('currentIndexChanged(int)')) { handle_data_object_type_change(data_object) }
    combo_layout = Qt::FormLayout.new()
    combo_layout.addRow('Data Object 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 + " : #{data_object.data_object_type}")
  end

  # Create editor class for specific data object type
  # Defaults to data_object_types[0] if a data object was not given
  if data_object
    data_object_type = data_object.class.to_s[0..-11].downcase
    data_object_type = data_object_type.split('::')[-1] # Remove Cosmos:: if present
  else
    data_object_type = data_object_types[0].to_s.downcase
  end
  @editor_layout = Qt::VBoxLayout.new
  layout.addLayout(@editor_layout)
  @editor = Cosmos.require_class(data_object_type + '_data_object_editor.rb').new(self)
  @editor.set_data_object(data_object)
  @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)

  setLayout(layout)
end

Instance Method Details

#executeObject

Executes the dialog box



83
84
85
86
87
88
89
90
91
# File 'lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_data_object_editor.rb', line 83

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