Class: Cosmos::LinegraphDataObjectEditor
- Inherits:
-
DataObjectEditor
- Object
- Qt::Base
- Qt::Widget
- DataObjectEditor
- Cosmos::LinegraphDataObjectEditor
- Defined in:
- lib/cosmos/tools/tlm_grapher/data_object_editors/linegraph_data_object_editor.rb
Overview
Widget which creates an editor for a line graph data object
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from DataObjectEditor
Instance Method Summary collapse
-
#get_data_object ⇒ Object
Get the data object from the editor.
-
#handle_add_button ⇒ Object
Handle the Add Horizontal Line button being pressed.
-
#handle_delete_button ⇒ Object
Handle the delete horizontal line button being pressed.
-
#initialize(parent) ⇒ LinegraphDataObjectEditor
constructor
A new instance of LinegraphDataObjectEditor.
- #set_data_object(data_object) ⇒ Object
Constructor Details
#initialize(parent) ⇒ LinegraphDataObjectEditor
Returns a new instance of LinegraphDataObjectEditor.
24 25 26 |
# File 'lib/cosmos/tools/tlm_grapher/data_object_editors/linegraph_data_object_editor.rb', line 24 def initialize(parent) super(parent) end |
Instance Method Details
#get_data_object ⇒ Object
Get the data object from the editor
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/cosmos/tools/tlm_grapher/data_object_editors/linegraph_data_object_editor.rb', line 67 def get_data_object data_object = super() horizontal_lines = [] index = 0 @horizontal_lines.each do |list_item| horizontal_lines << [list_item.text.to_f, @horizontal_lines.getItemColor(index)] index += 1 end data_object.horizontal_lines = horizontal_lines data_object.y_offset = @y_offset.value data_object.y_axis = @y_axis.symbol data_object end |
#handle_add_button ⇒ Object
Handle the Add Horizontal Line button being pressed
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 |
# File 'lib/cosmos/tools/tlm_grapher/data_object_editors/linegraph_data_object_editor.rb', line 82 def dialog = Qt::Dialog.new(self) #'Add Horizontal Line' layout = Qt::VBoxLayout.new colors = LinegraphDataObject::COLOR_LIST.clone color = ComboboxChooser.new(dialog, 'Color:', colors, color_chooser: true) layout.addWidget(color) y_value = FloatChooser.new(dialog, 'Y Value:', 0.0) layout.addWidget(y_value) # Create OK and Cancel buttons = Qt::HBoxLayout.new = Qt::PushButton.new('OK') .connect(SIGNAL('clicked()')) { dialog.accept } .addWidget() = Qt::PushButton.new('Cancel') .connect(SIGNAL('clicked()')) { dialog.reject } .addWidget() layout.addLayout() dialog.setLayout(layout) result = dialog.exec if result != 0 # Horizontal Line Added @horizontal_lines.addItemColor(y_value.string, color.string) end dialog.dispose end |
#handle_delete_button ⇒ Object
Handle the delete horizontal line button being pressed
111 112 113 114 115 116 117 118 |
# File 'lib/cosmos/tools/tlm_grapher/data_object_editors/linegraph_data_object_editor.rb', line 111 def horizontal_line_indexes = selected_horizontal_lines() unless horizontal_line_indexes.empty? horizontal_line_indexes.reverse.each do |index| @horizontal_lines.takeItemColor(index) end end end |
#set_data_object(data_object) ⇒ Object
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 |
# File 'lib/cosmos/tools/tlm_grapher/data_object_editors/linegraph_data_object_editor.rb', line 28 def set_data_object(data_object) local_layout = Qt::VBoxLayout.new local_layout.setContentsMargins(0,0,0,0) # Float Chooser for y_offset @y_offset = FloatChooser.new(self, 'Y Offset:', 0) @y_offset.value = data_object.y_offset if data_object.y_offset local_layout.addWidget(@y_offset) # Chooser for Y Axis @y_axis = ComboboxChooser.new(self, 'Y Axis:', LinegraphDataObject::Y_AXIS_CHOICES.map {|x| x.to_s}) @y_axis.set_current(data_object.y_axis) if data_object.y_axis local_layout.addWidget(@y_axis) # Chooser for Horizontal Lines @button_layout = Qt::HBoxLayout.new @horizontal_label = Qt::Label.new('Horizontal Lines:') @button_layout.addWidget(@horizontal_label) @button_layout.addStretch() @add_button = Qt::PushButton.new('Add', self) @add_button.setAutoDefault(false) @add_button.connect(SIGNAL('clicked()')) { () } @button_layout.addWidget(@add_button) @delete_button = Qt::PushButton.new('Delete', self) @delete_button.setAutoDefault(false) @delete_button.connect(SIGNAL('clicked()')) { () } @button_layout.addWidget(@delete_button) local_layout.addLayout(@button_layout) @horizontal_lines = Qt::ColorListWidget.new(self) @horizontal_lines.setMinimumHeight(50) sync_gui_lines_with_data_object(data_object) local_layout.addWidget(@horizontal_lines) @layout.addLayout(local_layout) super(data_object) end |