Changeset 1187

Show
Ignore:
Timestamp:
03/13/10 13:49:04 (5 months ago)
Author:
erikj
Message:

first functional expanded search

Location:
trunk/camelot/view
Files:
1 added
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/camelot/view/controls/delegates/comboboxdelegate.py

    r1179 r1187  
    4141    editor = editors.ChoicesEditor 
    4242 
    43     def __init__(self, parent, choices, editable=True, **kwargs): 
     43    def __init__(self, parent=None, choices=[], editable=True, **kwargs): 
    4444        CustomDelegate.__init__(self, parent, editable=editable, **kwargs) 
    4545        self.choices = choices 
  • trunk/camelot/view/controls/tableview.py

    r1186 r1187  
    3737 
    3838from camelot.view.proxy.queryproxy import QueryTableProxy 
     39from camelot.view.controls.filterlist import filter_changed_signal 
    3940from camelot.view.controls.view import AbstractView 
    4041from camelot.view.controls.user_translatable_label import UserTranslatableLabel 
     
    113114    def __init__( self, parent, admin ): 
    114115        QtGui.QWidget.__init__( self, parent ) 
     116        self._admin = admin 
    115117        layout = QtGui.QVBoxLayout() 
    116118        widget_layout = QtGui.QHBoxLayout() 
     
    136138     
    137139    def _fill_expanded_search_options(self, columns): 
     140        from camelot.view.controls.filter_operator import FilterOperator 
    138141        layout = QtGui.QHBoxLayout() 
    139142        for field, attributes in columns: 
    140143            if 'operators' in attributes: 
    141                 widget = QtGui.QLabel(field) 
     144                widget = FilterOperator( self._admin.entity, field, attributes, self) 
     145                self.connect( widget, filter_changed_signal,  self._filter_changed ) 
    142146                layout.addWidget( widget ) 
     147        layout.addStretch() 
    143148        self._expanded_search.setLayout( layout ) 
    144149         
     150    def _filter_changed(self): 
     151        self.emit(QtCore.SIGNAL('filters_changed')) 
    145152         
     153    def decorate_query(self, query): 
     154        """Apply expanded filters on the query""" 
     155        for i in range(self._expanded_search.layout().count()): 
     156            if self._expanded_search.layout().itemAt(i).widget(): 
     157                query = self._expanded_search.layout().itemAt(i).widget().decorate_query(query) 
     158        return query 
     159             
    146160    def expand_search_options(self): 
    147161        if self._expanded_search.isHidden(): 
     
    245259        shortcut = QtGui.QShortcut(QtGui.QKeySequence(QtGui.QKeySequence.Find), self) 
    246260        self.connect( shortcut, QtCore.SIGNAL( 'activated()' ), self.activate_search ) 
     261        self.connect( self.header, QtCore.SIGNAL('filters_changed'),  self.rebuildQuery ) 
    247262        # give the table widget focus to prevent the header and its search control to 
    248263        # receive default focus, as this would prevent the displaying of 'Search...' in the 
     
    416431        workspace.addSubWindow( form ) 
    417432        form.show() 
    418      
    419  
    420      
    421 #    @gui_function 
    422 #    def set_filters_and_actions( self, filters_and_actions ): 
    423 #        """sets filters for the tableview""" 
    424 #        filters, actions = filters_and_actions 
    425 #        from filterlist import FilterList 
    426 #        from actionsbox import ActionsBox 
    427 #        logger.debug( 'setting filters for tableview' ) 
    428 #        if self.filters: 
    429 #          self.disconnect( self.filters, SIGNAL( 'filters_changed' ), self.rebuildQuery ) 
    430 #          self.filters.deleteLater() 
    431 #          self.filters = None 
    432 #        if self.actions: 
    433 #          self.actions.deleteLater() 
    434 #          self.actions = None           
    435 #        if filters: 
    436 #          self.filters = FilterList( filters, parent=self ) 
    437 #          self.splitter.insertWidget( 2, self.filters ) 
    438 #          self.connect( self.filters, SIGNAL( 'filters_changed' ), self.rebuildQuery ) 
    439 #        if actions: 
    440 #          self.actions = ActionsBox( self, self._table_model.collection_getter, lambda:[] ) 
    441 #          self.actions.setActions( actions ) 
    442 #          self.splitter.insertWidget( 2, self.filters ) 
    443433 
    444434    def toHtml( self ): 
     
    538528        def rebuild_query(): 
    539529            query = self.admin.entity.query 
     530            query = self.header.decorate_query(query) 
    540531            if self.filters: 
    541532                query = self.filters.decorate_query( query ) 
  • trunk/camelot/view/field_attributes.py

    r1186 r1187  
    4646) 
    4747 
    48 _numerical_operators = (operator.eq, operator.lt, operator.le, operator.gt, operator.ge) 
     48_numerical_operators = (operator.eq, operator.ne, operator.lt, operator.le, operator.gt, operator.ge) 
     49_text_operators = (operator.eq, operator.ne) 
    4950 
    5051_sqlalchemy_to_python_type_ = { 
     
    149150        'widget': 'str', 
    150151        'from_string': string_from_string, 
     152        'operators' : _text_operators, 
    151153    }, 
    152154 
     
    159161        'widget': 'str', 
    160162        'from_string': string_from_string, 
     163        'operators' : _text_operators, 
    161164    }, 
    162165 
     
    169172        'widget': 'str', 
    170173        'from_string': string_from_string, 
     174        'operators' : _text_operators, 
    171175    }, 
    172176 
     
    178182        'storage': f.storage, 
    179183        'preview_width': 100, 
    180         'preview_height': 100 
     184        'preview_height': 100, 
     185        'operators' : _text_operators, 
    181186    }, 
    182187 
     
    186191        'delegate': delegates.CodeDelegate, 
    187192        'nullable': True, 
    188         'parts': f.parts 
     193        'parts': f.parts, 
     194        'operators' : _text_operators, 
    189195    }, 
    190196 
     
    195201        'parts': f.parts, 
    196202        'delegate': delegates.CodeDelegate, 
    197         'widget': 'code' 
     203        'widget': 'code', 
     204        'operators' : _text_operators, 
    198205    }, 
    199206 
     
    202209        'editable': True, 
    203210        'nullable': True, 
    204         'delegate': delegates.VirtualAddressDelegate 
     211        'delegate': delegates.VirtualAddressDelegate, 
     212        'operators' : _text_operators, 
    205213    }, 
    206214 
     
    211219        'delegate': delegates.RichTextDelegate, 
    212220        'from_string': string_from_string, 
     221        'operators' : _text_operators, 
    213222    }, 
    214223 
     
    218227        'editable': True, 
    219228        'nullable': True, 
    220         'widget': 'color' 
     229        'widget': 'color', 
     230        'operators' : _text_operators, 
    221231    }, 
    222232 
     
    227237        'python_type': int, 
    228238        'widget': 'star', 
    229         'from_string': int_from_string 
     239        'from_string': int_from_string, 
     240        'operators' : _numerical_operators, 
    230241    }, 
    231242 
     
    238249        'nullable': False, 
    239250        'widget': 'combobox', 
     251        'operators' : _numerical_operators, 
    240252    }, 
    241253     
     
    254266        'editable': True, 
    255267        'delegate': delegates.FileDelegate, 
    256         'storage': f.storage 
     268        'storage': f.storage, 
     269        'operators' : _text_operators, 
    257270    }, 
    258271} 
  • trunk/camelot/view/filters.py

    r1184 r1187  
    204204         
    205205    def render(self, parent, name, options): 
    206          
    207         from PyQt4 import QtCore, QtGui 
    208         from camelot.view.controls.filterlist import filter_changed_signal 
    209         from camelot.view.controls import editors 
    210                  
    211         class FilterWidget(QtGui.QGroupBox): 
    212              
    213             def __init__(self, name, parent): 
    214                 QtGui.QGroupBox.__init__(self, unicode(name), parent) 
    215                 self._entity, self._field_name, self._field_attributes = options 
    216                 self._field_attributes['editable'] = True 
    217                 layout = QtGui.QVBoxLayout() 
    218                 self._choices = [(0, ugettext('All')), (1, ugettext('None')), (2, ugettext('='))] 
    219                 combobox = QtGui.QComboBox(self) 
    220                 layout.addWidget(combobox) 
    221                 for i,name in self._choices: 
    222                     combobox.insertItem(i, unicode(name)) 
    223                 self.connect(combobox, QtCore.SIGNAL('currentIndexChanged(int)'), self.combobox_changed) 
    224                 delegate = self._field_attributes['delegate'](**self._field_attributes) 
    225                 option = QtGui.QStyleOptionViewItem() 
    226                 option.version = 5 
    227                 self._editor = delegate.createEditor( self, option, None ) 
    228                 # explicitely set a value, otherways the current value remains ValueLoading 
    229                 self._editor.set_value(None) 
    230                 self.connect(self._editor, editors.editingFinished, self.editor_editing_finished) 
    231                 layout.addWidget(self._editor) 
    232                 self.setLayout(layout) 
    233                 self._editor.setEnabled(False) 
    234                 self._index = 0 
    235                 self._value = None 
    236                  
    237             def combobox_changed(self, index): 
    238                 self._index = index 
    239                 if index==2: 
    240                     self._editor.setEnabled(True) 
    241                 else: 
    242                     self._editor.setEnabled(False) 
    243                 self.emit(filter_changed_signal) 
    244                  
    245             def editor_editing_finished(self): 
    246                 self._value = self._editor.get_value() 
    247                 self.emit(filter_changed_signal) 
    248              
    249             def decorate_query(self, query): 
    250                 if self._index==0: 
    251                     return query 
    252                 if self._index==1: 
    253                     return query.filter(getattr(self._entity, self._field_name)==None) 
    254                 return query.filter(getattr(self._entity, self._field_name)==self._value) 
    255                  
    256         return FilterWidget(name, parent)        
     206        from camelot.view.controls.filter_operator import FilterOperator 
     207        entity, field_name, field_attributes = options 
     208        return FilterOperator(entity, field_name, field_attributes, parent)        
    257209     
    258210    def get_name_and_options(self, admin):