camelot.camelot.view.controls.filter

Package camelot :: Package camelot :: Package view :: Package controls :: Module filter |
[hide private]
[frames] | no frames]

# Source Code for Module camelot.camelot.view.controls.filter

     1  #  ============================================================================
     2  #
     3  #  Copyright (C) 2007-2008 Conceptive Engineering bvba. All rights reserved.
     4  #  www.conceptive.be / project-camelot@conceptive.be
     5  #
     6  #  This file is part of the Camelot Library.
     7  #
     8  #  This file may be used under the terms of the GNU General Public
     9  #  License version 2.0 as published by the Free Software Foundation
    10  #  and appearing in the file LICENSE.GPL included in the packaging of
    11  #  this file.  Please review the following information to ensure GNU
    12  #  General Public Licensing requirements will be met:
    13  #  http://www.trolltech.com/products/qt/opensource.html
    14  #
    15  #  If you are unsure which license is appropriate for your use, please
    16  #  review the following information:
    17  #  http://www.trolltech.com/products/qt/licensing.html or contact
    18  #  project-camelot@conceptive.be.
    19  #
    20  #  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
    21  #  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
    22  #
    23  #  For use of this library in commercial applications, please contact
    24  #  project-camelot@conceptive.be
    25  #
    26  #  ============================================================================
    27
    28  """Controls to filter data"""
    29
    30  import logging
    31  logger = logging.getLogger('camelot.view.controls.filter')
    32
    33  from PyQt4 import QtGui
    34  from PyQt4 import QtCore
    35
    36  _ = lambda x:x
    37
    38
    39 -class FilterList(QtGui.QScrollArea):
    40    """A list with filters that can be applied on a query in the tableview"""
    41
    42 -  def __init__(self, items, parent):
    43      """@param item list of tubles (name, choices) for constructing the
    44      different filterboxes
    45      """
    46      QtGui.QScrollArea.__init__(self, parent)
    47      self.widget = QtGui.QWidget()
    48      layout = QtGui.QVBoxLayout()
    49      self.filters = []
    50      layout.addWidget(QtGui.QLabel(_('Filter'), self))
    51
    52      for filter,(name,options) in items:
    53        widget = filter.render(self, name, options)
    54        layout.addWidget(widget)
    55        self.filters.append(widget)
    56        self.connect(widget,
    57                     QtCore.SIGNAL('filter_changed'),
    58                     self.emit_filters_changed)
    59
    60      layout.addStretch()
    61      self.widget.setLayout(layout)
    62      self.setWidget(self.widget)
    63      self.setMaximumWidth(self.widget.width() + 10)
    64      if len(self.filters) == 0:
    65        self.setMaximumWidth(0)
    66
    67 -  def decorate_query(self, query):
    68      for filter in self.filters:
    69        query = filter.decorate_query(query)
    70      return query
    71
    72 -  def emit_filters_changed(self):
    73      logger.debug('filters changed')
    74      self.emit(QtCore.SIGNAL('filters_changed'))
    75
    76 -  def __del__(self):
    77      logger.debug('delete filter list')
    78