Class: Ruber::ProjectFilesRuleChooser

Inherits:
Qt::Widget
  • Object
show all
Defined in:
lib/ruber/world/project_files_widget.rb

Overview

Widget which displays and allows to modify the rules which determine whether a file belongs to a project or not.

It contains a @Qt::TreeView@ where the rules are displayed and some buttons to add and remove rules. The tree view has two columns: the first displays the contents of the rules, while the second contains the rules’ type (whether they’re regexp rules or file rules).

See Also:

  • ProjectFilesList

Defined Under Namespace

Classes: RegexpRuleValidator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil) ⇒ ProjectFilesRuleChooser

Returns a new instance of ProjectFilesRuleChooser.

Parameters:

  • parent (Qt::Widget) (defaults to: nil)

    the parent widget



83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/ruber/world/project_files_widget.rb', line 83

def initialize parent = nil
  super 
  @project = nil
  @ui = Ui::ProjectFilesRuleChooser.new
  @ui.setupUi self
  model = Qt::StandardItemModel.new @ui.rules_widget
  @ui.rules_widget.model = model
  model.horizontal_header_labels = %w[Pattern Type]
  connect @ui.add_regexp_btn, SIGNAL('clicked()'), self, SLOT('add_regexp_rule()')
  connect @ui.add_path_btn, SIGNAL('clicked()'), self, SLOT('add_path_rule()')
  connect @ui.remove_rule_btn, SIGNAL('clicked()'), self, SLOT('remove_rule()')
  connect @ui.rules_widget.selection_model, SIGNAL('selectionChanged(QItemSelection, QItemSelection)'), self, SLOT('change_button_state()')
  @ui.remove_rule_btn.enabled = false
end

Instance Attribute Details

#project=(value) ⇒ Ruber::Project (writeonly)

Returns the project the widget displays rules for.

Returns:



49
50
51
# File 'lib/ruber/world/project_files_widget.rb', line 49

def project=(value)
  @project = value
end

Instance Method Details

#rulesArray<String,Regexp>

The rules chosen by the user

String entries correspond to file rules, while regexp entries correspond to regexp rules

Returns:

  • (Array<String,Regexp>)

    an array containing the rules the user has chosen.



114
115
116
117
118
119
120
# File 'lib/ruber/world/project_files_widget.rb', line 114

def rules
  @ui.rules_widget.model.enum_for(:each_row).map do |rule, type|
    if type.text == 'Path' then rule.text
    else Regexp.new rule.text
    end
  end
end

#rules=(list) ⇒ nil

Fills the tree view

Note: calling this method won’t trigger the #rules_edited signal

entries will be considered as file rules, while regexp entries will be considered regexp rules

Parameters:

  • list (Array<String,Regexp>)

    a list of the rules to insert in the view. String

Returns:

  • (nil)


132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/ruber/world/project_files_widget.rb', line 132

def rules= list
  model = @ui.rules_widget.model
  model.clear
  model.horizontal_header_labels = %w[Pattern Type]
  list.each do |rule|
    type = 'Path'
    if rule.is_a? Regexp
      type = 'Regexp'
      rule = rule.source
    end
    model.append_row [Qt::StandardItem.new(rule), Qt::StandardItem.new(type)]
  end
  nil
end

#sizeHintQt::Size

Override of @Qt::Widget#sizeHint@

Returns:

  • (Qt::Size)

    the optimal size to use (350x200)



103
104
105
# File 'lib/ruber/world/project_files_widget.rb', line 103

def sizeHint
  Qt::Size.new(350,200)
end