def indexAt(self, point):
        """
        Overriden base method that returns the model index under the specified point in
        the viewport

        :param point:   The QPoint to find the model index for
        :returns:       The model index for the item under the point or an invalid
                        QModelIndex() if there isn't one.
        """
        if not self.model():
            return QtCore.QModelIndex()

        # convert viewport relative point to global point:
        point = point + QtCore.QPoint(self.horizontalOffset(),
                                      self.verticalOffset())

        num_rows = len(self._item_info)
        if num_rows != self.model().rowCount():
            # just in case!
            return QtCore.QModelIndex()

        y_offset = self._border.height()
        for row, item_info in enumerate(self._item_info):

            # get point in local space:
            local_point = point + QtCore.QPoint(0, -y_offset)

            if local_point.y() < item_info.rect.y():
                # point definitely isn't on an item as we'd have found it by now!
                break

            # ok, we'll need an index for this row:
            index = self.model().index(row, 0)

            # check if the point is within this item:
            if item_info.rect.contains(local_point):
                return index

            # update y-offset:
            y_offset += item_info.rect.height()

            if not item_info.collapsed:
                # now check children:
                local_point = point + QtCore.QPoint(0, -y_offset)
                for child_row, (_, _,
                                child_rect) in enumerate(item_info.child_info):
                    if child_rect.contains(local_point):
                        # found a hit on a child item
                        return self.model().index(child_row, 0, index)

                # update y-offset
                y_offset += item_info.child_area_rect.height(
                ) + self._group_spacing
            else:
                y_offset += self._item_spacing.height()

        # no match so return invalid model index
        return QtCore.QModelIndex()
    def rowCount(self, parent=QtCore.QModelIndex()):
        """
        Override the base method.

        Returns the number of rows in the model.
        """

        return len(self._data)
    def build(self):
        """
        Return the filters based on the model data.
        """

        # Clear the existing filters definitions before rebuilding it.
        self.clear()

        # Recursively go through each model item to extract the data to built the filters.
        self._build_from_root(QtCore.QModelIndex())
 def async_refresh(self):
     QtGui.QApplication.processEvents()
     try:
         self.dataChanged.emit(QtCore.QModelIndex(), QtCore.QModelIndex())
     except Exception as e:
         logger.error(e)
 def addRow(self, name, duration):
     self.list.append(timelogEvent(name, date.today(), duration))
     self.dataChanged.emit(QtCore.QModelIndex(), QtCore.QModelIndex())
 def rowCount(self, parent=QtCore.QModelIndex()):
     return len(self.list)