Changeset 1187
- Timestamp:
- 03/13/10 13:49:04 (5 months ago)
- Location:
- trunk/camelot/view
- Files:
-
- 1 added
- 4 modified
-
controls/delegates/comboboxdelegate.py (modified) (1 diff)
-
controls/filter_operator.py (added)
-
controls/tableview.py (modified) (6 diffs)
-
field_attributes.py (modified) (13 diffs)
-
filters.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/camelot/view/controls/delegates/comboboxdelegate.py
r1179 r1187 41 41 editor = editors.ChoicesEditor 42 42 43 def __init__(self, parent , choices, editable=True, **kwargs):43 def __init__(self, parent=None, choices=[], editable=True, **kwargs): 44 44 CustomDelegate.__init__(self, parent, editable=editable, **kwargs) 45 45 self.choices = choices -
trunk/camelot/view/controls/tableview.py
r1186 r1187 37 37 38 38 from camelot.view.proxy.queryproxy import QueryTableProxy 39 from camelot.view.controls.filterlist import filter_changed_signal 39 40 from camelot.view.controls.view import AbstractView 40 41 from camelot.view.controls.user_translatable_label import UserTranslatableLabel … … 113 114 def __init__( self, parent, admin ): 114 115 QtGui.QWidget.__init__( self, parent ) 116 self._admin = admin 115 117 layout = QtGui.QVBoxLayout() 116 118 widget_layout = QtGui.QHBoxLayout() … … 136 138 137 139 def _fill_expanded_search_options(self, columns): 140 from camelot.view.controls.filter_operator import FilterOperator 138 141 layout = QtGui.QHBoxLayout() 139 142 for field, attributes in columns: 140 143 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 ) 142 146 layout.addWidget( widget ) 147 layout.addStretch() 143 148 self._expanded_search.setLayout( layout ) 144 149 150 def _filter_changed(self): 151 self.emit(QtCore.SIGNAL('filters_changed')) 145 152 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 146 160 def expand_search_options(self): 147 161 if self._expanded_search.isHidden(): … … 245 259 shortcut = QtGui.QShortcut(QtGui.QKeySequence(QtGui.QKeySequence.Find), self) 246 260 self.connect( shortcut, QtCore.SIGNAL( 'activated()' ), self.activate_search ) 261 self.connect( self.header, QtCore.SIGNAL('filters_changed'), self.rebuildQuery ) 247 262 # give the table widget focus to prevent the header and its search control to 248 263 # receive default focus, as this would prevent the displaying of 'Search...' in the … … 416 431 workspace.addSubWindow( form ) 417 432 form.show() 418 419 420 421 # @gui_function422 # def set_filters_and_actions( self, filters_and_actions ):423 # """sets filters for the tableview"""424 # filters, actions = filters_and_actions425 # from filterlist import FilterList426 # from actionsbox import ActionsBox427 # 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 = None432 # if self.actions:433 # self.actions.deleteLater()434 # self.actions = None435 # 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 )443 433 444 434 def toHtml( self ): … … 538 528 def rebuild_query(): 539 529 query = self.admin.entity.query 530 query = self.header.decorate_query(query) 540 531 if self.filters: 541 532 query = self.filters.decorate_query( query ) -
trunk/camelot/view/field_attributes.py
r1186 r1187 46 46 ) 47 47 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) 49 50 50 51 _sqlalchemy_to_python_type_ = { … … 149 150 'widget': 'str', 150 151 'from_string': string_from_string, 152 'operators' : _text_operators, 151 153 }, 152 154 … … 159 161 'widget': 'str', 160 162 'from_string': string_from_string, 163 'operators' : _text_operators, 161 164 }, 162 165 … … 169 172 'widget': 'str', 170 173 'from_string': string_from_string, 174 'operators' : _text_operators, 171 175 }, 172 176 … … 178 182 'storage': f.storage, 179 183 'preview_width': 100, 180 'preview_height': 100 184 'preview_height': 100, 185 'operators' : _text_operators, 181 186 }, 182 187 … … 186 191 'delegate': delegates.CodeDelegate, 187 192 'nullable': True, 188 'parts': f.parts 193 'parts': f.parts, 194 'operators' : _text_operators, 189 195 }, 190 196 … … 195 201 'parts': f.parts, 196 202 'delegate': delegates.CodeDelegate, 197 'widget': 'code' 203 'widget': 'code', 204 'operators' : _text_operators, 198 205 }, 199 206 … … 202 209 'editable': True, 203 210 'nullable': True, 204 'delegate': delegates.VirtualAddressDelegate 211 'delegate': delegates.VirtualAddressDelegate, 212 'operators' : _text_operators, 205 213 }, 206 214 … … 211 219 'delegate': delegates.RichTextDelegate, 212 220 'from_string': string_from_string, 221 'operators' : _text_operators, 213 222 }, 214 223 … … 218 227 'editable': True, 219 228 'nullable': True, 220 'widget': 'color' 229 'widget': 'color', 230 'operators' : _text_operators, 221 231 }, 222 232 … … 227 237 'python_type': int, 228 238 'widget': 'star', 229 'from_string': int_from_string 239 'from_string': int_from_string, 240 'operators' : _numerical_operators, 230 241 }, 231 242 … … 238 249 'nullable': False, 239 250 'widget': 'combobox', 251 'operators' : _numerical_operators, 240 252 }, 241 253 … … 254 266 'editable': True, 255 267 'delegate': delegates.FileDelegate, 256 'storage': f.storage 268 'storage': f.storage, 269 'operators' : _text_operators, 257 270 }, 258 271 } -
trunk/camelot/view/filters.py
r1184 r1187 204 204 205 205 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) 257 209 258 210 def get_name_and_options(self, admin):
