| 1 |
require 'editissuedialog' |
| 2 |
|
| 3 |
require 'Qt4' |
| 4 |
|
| 5 |
class EditIssueDialog < Qt::Dialog |
| 6 |
|
| 7 |
attr_reader :arguments |
| 8 |
attr_reader :results |
| 9 |
|
| 10 |
slots :writeBackResults |
| 11 |
|
| 12 |
def initialize( title, arguments, parent = nil ) |
| 13 |
super( parent ) |
| 14 |
setWindowTitle( title ) |
| 15 |
|
| 16 |
@arguments = arguments |
| 17 |
@results = [] |
| 18 |
|
| 19 |
createUI |
| 20 |
end |
| 21 |
|
| 22 |
def createUI |
| 23 |
@argumentsLayout = Qt::GridLayout.new |
| 24 |
row = 0 |
| 25 |
@arguments.each do |argument| |
| 26 |
resultsEntry = { :id => argument[:id], :value => nil, :type => :unknown } |
| 27 |
|
| 28 |
label = Qt::Label.new( argument[:name] ) |
| 29 |
label.alignment = Qt::AlignLeft | Qt::AlignTop |
| 30 |
@argumentsLayout.addWidget( label, row, 0 ) |
| 31 |
|
| 32 |
widget = nil |
| 33 |
if argument[:type].equal?( :String ) then |
| 34 |
resultsEntry[:type] = :String |
| 35 |
widget = Qt::LineEdit.new( self ) |
| 36 |
widget.text = argument[:value] |
| 37 |
elsif argument[:type].equal?( :Text ) then |
| 38 |
resultsEntry[:type] = :Text |
| 39 |
widget = Qt::TextEdit.new( self ) |
| 40 |
widget.plainText = argument[:value] |
| 41 |
elsif argument[:type].equal?( :Select ) then |
| 42 |
resultsEntry[:type] = :Select |
| 43 |
widget = Qt::ComboBox.new( self ) |
| 44 |
argument[:value].keys.each do |key| |
| 45 |
widget.addItem( argument[:value][key], Qt::Variant::fromValue( key ) ) |
| 46 |
if key == argument[:default] then |
| 47 |
widget.currentIndex = widget.count - 1 |
| 48 |
end |
| 49 |
end |
| 50 |
end |
| 51 |
if not widget.nil? then |
| 52 |
resultsEntry[:widget] = widget |
| 53 |
@argumentsLayout.addWidget( widget, row, 1 ) |
| 54 |
end |
| 55 |
@results.push( resultsEntry ) |
| 56 |
|
| 57 |
row += 1 |
| 58 |
end |
| 59 |
|
| 60 |
@submitButton = Qt::PushButton.new( tr( "Submit" ), self ) |
| 61 |
connect( @submitButton, SIGNAL(:clicked), self, SLOT(:writeBackResults) ) |
| 62 |
|
| 63 |
@cancelButton = Qt::PushButton.new( tr( "Cancel" ), self ) |
| 64 |
connect( @cancelButton, SIGNAL(:clicked), self, SLOT(:reject) ) |
| 65 |
|
| 66 |
@buttonsLayout = Qt::HBoxLayout.new |
| 67 |
@buttonsLayout.addStretch |
| 68 |
@buttonsLayout.addWidget( @submitButton ) |
| 69 |
@buttonsLayout.addWidget( @cancelButton ) |
| 70 |
|
| 71 |
@mainLayout = Qt::VBoxLayout.new |
| 72 |
@mainLayout.addItem( @argumentsLayout ) |
| 73 |
@mainLayout.addItem( @buttonsLayout ) |
| 74 |
setLayout( @mainLayout ) |
| 75 |
end |
| 76 |
|
| 77 |
def writeBackResults |
| 78 |
@results.each do |result| |
| 79 |
if result[ :type ].equal?( :String ) then |
| 80 |
result[ :value ] = result[ :widget ].text |
| 81 |
elsif result[ :type ].equal?( :Text ) then |
| 82 |
result[ :value ] = result[ :widget ].toPlainText |
| 83 |
elsif result[ :type ].equal?( :Select ) then |
| 84 |
index = result[ :widget ].currentIndex |
| 85 |
result[ :value ] = result[ :widget ].itemData( index, Qt::UserRole ).toString |
| 86 |
end |
| 87 |
result[ :widget ] = nil |
| 88 |
end |
| 89 |
accept |
| 90 |
end |
| 91 |
|
| 92 |
end |