00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 modules = {}
00030 errors = {}
00031 
00032 import locale
00033 from Koo.Common import Common
00034 
00035 from ChartView import *
00036 from ChartGraphicsView import *
00037 
00038 import sys
00039 
00040 from Koo.View.AbstractParser import *
00041 
00042 from PyQt4.QtCore import *
00043 from PyQt4.QtGui import *
00044 
00045 
00046 class ChartParser( AbstractParser ):
00047 
00048         def create(self, viewId, parent, viewModel, node, fields):
00049                 self.viewModel = viewModel
00050                 self.parent = parent
00051 
00052                 attrs = Common.nodeAttributes(node)
00053 
00054 
00055                 
00056                 self.view = ChartView( parent )
00057                 self.view.id = viewId
00058                 self.view.title = attrs.get('string', _('Unknown') )
00059                 self.view.model = self.parent.currentRecord()
00060 
00061                 widget, onWriteFunction = self.parse( self.parent.currentRecord(), node, fields , self.view )
00062                 self.view.setWidget( widget )
00063                 self.view.setOnWriteFunction( onWriteFunction )
00064 
00065                 return self.view
00066 
00067         def parse(self, model, root_node, fields, container):
00068                 attrs = Common.nodeAttributes(root_node)
00069                 self.title = attrs.get('string', 'Unknown')
00070 
00071                 onWriteFunction = '' 
00072 
00073                 axis = []
00074                 groups = []
00075                 axis_data = {}
00076                 for node in root_node.childNodes:
00077                         if node.localName == 'field':
00078                                 node_attrs = Common.nodeAttributes(node)
00079                                 if node_attrs.get('group', False):
00080                                         groups.append(str(node_attrs['name']))
00081                                 else:
00082                                         axis.append(str(node_attrs['name']))
00083                                 axis_data[str(node_attrs['name'])] = node_attrs
00084 
00085                 
00086                 
00087                 
00088 
00089                 chart = ChartGraphicsView( container )
00090                 chart.setModel( self.parent.currentRecord() )
00091                 chart.setType( attrs.get('type', 'pie') )
00092                 chart.setAxis( axis )
00093                 chart.setGroups( groups )
00094                 chart.setFields( fields )
00095                 chart.setAxisData( axis_data )
00096                 if attrs.get('orientation', 'vertical') == 'vertical':
00097                         chart.setOrientation( Qt.Vertical )
00098                 else:
00099                         chart.setOrientation( Qt.Horizontal )
00100 
00101                 return chart, onWriteFunction
00102 
00103 
00104 
00105