Exemplo n.º 1
0
 def scope(parent, subcolumn):
     try:
         foreignClass = subcolumn.mappedClass
     except AttributeError: pass
     else:
         group = defaultColumnGroups.get(foreignClass.__name__)
         if group:
             submenu = menu.addMenu(_('Display {0} as...').format(parent.baseName or parent.name))
             buildColumnMenu(self.model().g, submenu, group, _(u'{0} Column'),
                     lambda columnGroup: lambda: model.replaceQueryColumn(columnIndex,
                         column.replaceSubcolumn(subcolumn, columnGroup.getColumn(self.model(), mappedClass=subcolumn.mappedClass))))
Exemplo n.º 2
0
        def showMenu():
            menu = QtGui.QMenu()

            group = defaultColumnGroups.get(self.model.queryModel.tableName)
            if group:
                buildColumnMenu(self.model.g, menu, group, _(u'Sort by {0} Column'),
                        lambda columnGroup: lambda: self.model.append(
                            columnGroup.getColumn(model=self.model.queryModel).getSortClause()))

            action = menu.addAction(_('Clear sort'))
            action.setIcon(QtGui.QIcon(resource_filename('qdex', 'icons/cross.png')))
            action.triggered.connect(lambda: self.model.clear())

            menu.exec_(QtGui.QCursor.pos())
Exemplo n.º 3
0
 def showHeaderContextMenu(self, pos):
     """Show a context menu when the header is right-clicked"""
     _ = self.g.translator
     model = self.model()
     menu = QtGui.QMenu()
     columnIndex = self.columnAt(pos.x())
     try:
         column = model.columns[columnIndex]
     except IndexError:
         pass
     else:
         if columnIndex != 0:
             name = column.headerData(Qt.DisplayRole, self.model())
             action = menu.addAction(_(u'Remove column {0}').format(name))
             remove = lambda: model.removeColumn(columnIndex)
             action.triggered.connect(remove)
             menu.addSeparator()
             for parent, subcolumn in column.getSubcolumns(column):
                 def scope(parent, subcolumn):
                     try:
                         foreignClass = subcolumn.mappedClass
                     except AttributeError: pass
                     else:
                         group = defaultColumnGroups.get(foreignClass.__name__)
                         if group:
                             submenu = menu.addMenu(_('Display {0} as...').format(parent.baseName or parent.name))
                             buildColumnMenu(self.model().g, submenu, group, _(u'{0} Column'),
                                     lambda columnGroup: lambda: model.replaceQueryColumn(columnIndex,
                                         column.replaceSubcolumn(subcolumn, columnGroup.getColumn(self.model(), mappedClass=subcolumn.mappedClass))))
                 scope(parent, subcolumn)
     # XXX: Move the table's column groups to the model
     group = defaultColumnGroups.get(model.tableName)
     if group:
         menu.addSeparator()
         def insertColumn(columnGroup):
             """Insert the column from the given columnGroup"""
             model.insertQueryColumn(
                     columnIndex + 1,
                     columnGroup.getColumn(model=model),
                 )
             if columnIndex == self.model().columnCount() - 2:
                 # We added a column after the last (stretchable) one.
                 # Let's be helpful and stretch the ex-last column to some
                 # reasonable size.
                 self.autoResizeColumn(columnIndex)
         buildColumnMenu(self.g, menu, group, _(u'Add {0} Column'),
                 lambda columnGroup: lambda: insertColumn(columnGroup))
     menu.exec_(self.header().mapToGlobal(pos))
Exemplo n.º 4
0
 def scope(parent, subcolumn):
     try:
         foreignClass = subcolumn.mappedClass
     except AttributeError:
         pass
     else:
         group = defaultColumnGroups.get(
             foreignClass.__name__)
         if group:
             submenu = menu.addMenu(
                 _('Display {0} as...').format(
                     parent.baseName or parent.name))
             buildColumnMenu(
                 self.model().g, submenu, group,
                 _(u'{0} Column'), lambda columnGroup:
                 lambda: model.replaceQueryColumn(
                     columnIndex,
                     column.replaceSubcolumn(
                         subcolumn,
                         columnGroup.
                         getColumn(self.model(),
                                   mappedClass=subcolumn.
                                   mappedClass))))
Exemplo n.º 5
0
    def showHeaderContextMenu(self, pos):
        """Show a context menu when the header is right-clicked"""
        _ = self.g.translator
        model = self.model()
        menu = QtGui.QMenu()
        columnIndex = self.columnAt(pos.x())
        try:
            column = model.columns[columnIndex]
        except IndexError:
            pass
        else:
            if columnIndex != 0:
                name = column.headerData(Qt.DisplayRole, self.model())
                action = menu.addAction(_(u'Remove column {0}').format(name))
                remove = lambda: model.removeColumn(columnIndex)
                action.triggered.connect(remove)
                menu.addSeparator()
                for parent, subcolumn in column.getSubcolumns(column):

                    def scope(parent, subcolumn):
                        try:
                            foreignClass = subcolumn.mappedClass
                        except AttributeError:
                            pass
                        else:
                            group = defaultColumnGroups.get(
                                foreignClass.__name__)
                            if group:
                                submenu = menu.addMenu(
                                    _('Display {0} as...').format(
                                        parent.baseName or parent.name))
                                buildColumnMenu(
                                    self.model().g, submenu, group,
                                    _(u'{0} Column'), lambda columnGroup:
                                    lambda: model.replaceQueryColumn(
                                        columnIndex,
                                        column.replaceSubcolumn(
                                            subcolumn,
                                            columnGroup.
                                            getColumn(self.model(),
                                                      mappedClass=subcolumn.
                                                      mappedClass))))

                    scope(parent, subcolumn)
        # XXX: Move the table's column groups to the model
        group = defaultColumnGroups.get(model.tableName)
        if group:
            menu.addSeparator()

            def insertColumn(columnGroup):
                """Insert the column from the given columnGroup"""
                model.insertQueryColumn(
                    columnIndex + 1,
                    columnGroup.getColumn(model=model),
                )
                if columnIndex == self.model().columnCount() - 2:
                    # We added a column after the last (stretchable) one.
                    # Let's be helpful and stretch the ex-last column to some
                    # reasonable size.
                    self.autoResizeColumn(columnIndex)

            buildColumnMenu(
                self.g, menu, group, _(u'Add {0} Column'),
                lambda columnGroup: lambda: insertColumn(columnGroup))
        menu.exec_(self.header().mapToGlobal(pos))