class QDA::GUI::CodeReviewGrid < Wx::Grid # Data provider using a coderview to populate a grid class CodeReviewDataSource < Wx::GridTableBase include QDA::GUI attr_reader :cr, :highlight COUNT_METHODS = { 'Characters' => :num_of_chars, 'Passages' => :num_of_passages, 'Documents' => :num_of_docs } # +cr+ is the code review we're displaying # +highlighting+ should be a Wx::Colour if highlighting is desired def initialize(cr, highlight = false) super() @cr = cr @highlight = highlight @count_method = :num_of_passages end def get_number_cols @cr.cols.length end def get_number_rows @cr.rows.length end # Given a string, sets to that count method def count_method=(meth) @count_method = COUNT_METHODS[meth] || Kernel.raise("Unknown count method #{meth}") end # Gets the numeric value of the specified cell of the code review def cell_value(row, col) @cr.cell_value(row, col).send(@count_method) end # Implement interface, returns contents to be displayed in given # grid cell def get_value(row, col) cell_value(row, col).to_s end # Implement interface def get_attr(row, col, attr_kind) attr = Wx::GridCellAttr.new if @highlight attr.background_colour = Wx::WHITE.mix( @highlight, @cr.max, cell_value(row, col) ) end attr end def is_empty_cell(row, col) false end def get_row_label_value(row) obj = @cr.rows[row] obj.send( TYPE_LABELS[ obj.class ] ) end def get_col_label_value(col) obj = @cr.cols[col] obj.send( TYPE_LABELS[ obj.class ] ) end end attr_reader :highlight, :highlighting, :count_method # Core grid class def initialize(parent, code_review) super(parent, :style => Wx::SIMPLE_BORDER) @cr = code_review self.row_label_size = 160 self.enable_editing(false) @count_method = 'Passages' @highlighting = true @highlight = Wx::RED refresh end def highlight=(hl) @highlight = hl refresh end def highlighting=(hl) @highlighting = hl refresh end def count_method=(count_meth) @count_method = count_meth refresh end # repaints and recolours the content of the grid def refresh(*args) colr = self.highlighting ? self.highlight : false self.table = CodeReviewDataSource.new(@cr, colr) self.table.count_method = self.count_method Wx::BusyCursor.busy { super } end # def on_cell_dclicked(e) q = @cr.to_query(@client.app, e.get_row, e.get_col) if q q_id = @client.app.get_preference('NextQuery') || 1 @client.app.save_preference('NextQuery', q_id + 1) q.dbid = q_id @workarea.launch_window(QueryWindow, q) end end end