Class: Syskit::GUI::IDE::Picker

Inherits:
Qt::Dialog
  • Object
show all
Defined in:
lib/syskit/gui/ide.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, items) ⇒ Picker

Returns a new instance of Picker



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/syskit/gui/ide.rb', line 119

def initialize(parent, items)
    super(parent)

    model = Qt::StringListModel.new(self)
    model.string_list = items.sort
    @filter = Qt::SortFilterProxyModel.new(self)
    @filter.dynamic_sort_filter = true
    @filter.source_model = model

    @filter_text = Qt::LineEdit.new(self)
    @filter_text.connect(SIGNAL('textChanged(QString)')) do |text|
        @filter.filterRegExp = Qt::RegExp.new(text)
    end
    @list = Qt::ListView.new(self)
    @list.edit_triggers = Qt::AbstractItemView::NoEditTriggers
    @list.model = @filter
    @list.connect(SIGNAL('doubleClicked(const QModelIndex&)')) do |index|
        accept
    end
    @list.current_index = @filter.index(0, 0)

    resize(500, 500)

    layout = Qt::VBoxLayout.new(self)
    layout.add_widget(@filter_text)
    layout.add_widget(@list)

    buttons = Qt::DialogButtonBox.new(
        Qt::DialogButtonBox::Ok | Qt::DialogButtonBox::Cancel)
    connect(buttons, SIGNAL('accepted()'), self, SLOT('accept()'))
    connect(buttons, SIGNAL('rejected()'), self, SLOT('reject()'))
    layout.add_widget(buttons)
end

Class Method Details

.select(parent, items) ⇒ Object



153
154
155
156
157
158
159
160
# File 'lib/syskit/gui/ide.rb', line 153

def self.select(parent, items)
    if items.empty?
        Qt::MessageBox.information(parent, "Nothing to pick",
            "There is nothing to pick from")
        return
    end
    new(parent, items).select
end

Instance Method Details

#selectObject



162
163
164
165
166
167
168
# File 'lib/syskit/gui/ide.rb', line 162

def select
    result = exec
    if result == Qt::Dialog::Accepted
        @filter.data(@list.current_index).
            to_string
    end
end