lib/reports/TableReport.rb in taskjuggler-0.0.8 vs lib/reports/TableReport.rb in taskjuggler-0.0.9

- old
+ new

@@ -1,11 +1,12 @@ #!/usr/bin/env ruby -w # encoding: UTF-8 # # = TableReport.rb -- The TaskJuggler III Project Management Software # -# Copyright (c) 2006, 2007, 2008, 2009, 2010 by Chris Schlaeger <cs@kde.org> +# Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011 +# by Chris Schlaeger <chris@linux.com> # # This program is free software; you can redistribute it and/or modify # it under the terms of version 2 of the GNU General Public License as # published by the Free Software Foundation. # @@ -206,10 +207,11 @@ @start = date if @start.nil? || date < @start date = task['end', scenarioIdx] || @project['end'] @end = date if @end.nil? || date > @end end end + # We want to add at least 5% on both ends. margin = 0 minWidth = @end - @start + 1 columns.each do |column| case column.id @@ -308,10 +310,11 @@ # We just set the pre-defined or user-defined column title in the first # row of the header. The 2nd row is not visible. column = ReportTableColumn.new(@table, columnDef, columnDef.title) column.cell1.rows = 2 column.cell2.hidden = true + column.cell1.width = columnDef.width if columnDef.width end end # Generate a ReportTableLine for each of the tasks in _taskList_. In case # _resourceList_ is not nil, it also generates the nested resource lines for @@ -596,10 +599,14 @@ # Generate a ReportTableCell filled the value of an attribute of the # property that line is for. It returns true if the cell exists, false for a # hidden cell. def genStandardCell(query, line, columnDef) + query = query.dup + query.listType = columnDef.listType + query.listMode = columnDef.listMode + # Find out, what type of PropertyTreeNode we are dealing with. property = line.property if property.is_a?(Task) propertyList = @project.tasks elsif property.is_a?(Resource) @@ -625,28 +632,11 @@ cell.text = cdText elsif query.process cell.text = (rti = query.to_rti) ? rti : query.to_s end - # Replace the font color setting if the user has requested a custom - # color. - fontColor = columnDef.fontColor.getPattern(query) - cell.fontColor = fontColor if fontColor - - # Replace the cell background color if the user has requested a custom - # color. - cellColor = columnDef.cellColor.getPattern(query) - cell.cellColor = cellColor if cellColor - - # Replace the default cell alignment if the user has requested a custom - # alignment. - hAlign = columnDef.hAlign.getPattern(query) - cell.alignment = hAlign if hAlign - - # If the user has requested a custom tooltip, add it to the cell. - cell.tooltip = columnDef.tooltip.getPattern(query) || nil - + setCustomCellAttributes(cell, columnDef, query) checkCellText(cell) true end @@ -655,10 +645,14 @@ # for a hidden cell. _query_ is the Query to get the cell value. _line_ # is the ReportTableLine of the cell. _columnDef_ is the # TableColumnDefinition of the column. _property_ is the PropertyTreeNode # that is reported in this cell. def genCalculatedCell(query, line, columnDef, property) + query = query.dup + query.listType = columnDef.listType + query.listMode = columnDef.listMode + # Create a new cell cell = newCell(query, line) unless setScenarioSettings(cell, query.scenarioIdx, scenarioSpecific?(columnDef.id)) @@ -711,29 +705,11 @@ # Replace the cell text if the user has requested a custom cell text. cdText = columnDef.cellText.getPattern(query) cell.text = cdText if cdText - # Replace the cell background color if the user has requested a custom - # color. - cellColor = columnDef.cellColor.getPattern(query) - cell.cellColor = cellColor if cellColor - - # Replace the font color setting if the user has requested a custom - # color. - fontColor = columnDef.fontColor.getPattern(query) - cell.fontColor = fontColor if fontColor - - # Replace the default cell alignment if the user has requested a custom - # alignment. - hAlign = columnDef.hAlign.getPattern(query) - cell.alignment = hAlign if hAlign - - # Register the custom tooltip if the user has requested one. - cdTooltip = columnDef.tooltip.getPattern(query) - cell.tooltip = cdTooltip if cdTooltip - + setCustomCellAttributes(cell, columnDef, query) checkCellText(cell) true end @@ -787,10 +763,13 @@ cell.text = query.to_s if query.to_num != 0.0 else raise "Unknown column content #{column.content}" end + cdText = columnDef.cellText.getPattern(query) + cell.text = cdText if cdText + # Determine cell category (mostly the background color) if cellIv.overlaps?(taskIv) # The cell is either a container or leaf task cell.category = task.container? ? 'calconttask' : 'caltask' # If the user has requested a custom tooltip, add it to each task cell. @@ -884,10 +863,13 @@ end else raise "Unknown column content #{column.content}" end + cdText = columnDef.cellText.getPattern(query) + cell.text = cdText if cdText + # Set the tooltip for the cell. We might delete it again. cell.tooltip = columnDef.tooltip.getPattern(query) || nil cell.showTooltipHint = false # Determine cell category (mostly the background color) @@ -959,9 +941,31 @@ end # Set column width cell.width = columnDef.width if columnDef.width end + + def setCustomCellAttributes(cell, columnDef, query) + # Replace the cell background color if the user has requested a custom + # color. + cellColor = columnDef.cellColor.getPattern(query) + cell.cellColor = cellColor if cellColor + + # Replace the font color setting if the user has requested a custom + # color. + fontColor = columnDef.fontColor.getPattern(query) + cell.fontColor = fontColor if fontColor + + # Replace the default cell alignment if the user has requested a custom + # alignment. + hAlign = columnDef.hAlign.getPattern(query) + cell.alignment = hAlign if hAlign + + # Register the custom tooltip if the user has requested one. + cdTooltip = columnDef.tooltip.getPattern(query) + cell.tooltip = cdTooltip if cdTooltip + end + def setScenarioSettings(cell, scenarioIdx, scenarioSpecific) # Check if we are dealing with multiple scenarios. if a('scenarios').length > 1 # Check if the attribute is not scenario specific