Пример #1
0
    def createEditor(self, parent, option, index):
        if index.column() == 0:
            combobox = QComboBox(parent)
            combobox.setEditable(False)
            props = []
            sindex = self.table.table.model().mapToSource(index)

            #we list the properties that are compatible with the subject type
            #the subject type depends on the direction of the relation: current resource
            #is subject or is object of the relation?

            currentRelation = index.model().sourceModel().relations[
                sindex.row()]
            direct = currentRelation[2]
            if direct:
                subject = self.table.resource
            else:
                subject = currentRelation[1]

            for property in datamanager.resourceTypesProperties(
                    subject, True, False):
                item = property.label(
                    "en") + " [" + datamanager.ontologyAbbreviationForUri(
                        property.uri(), False) + "]"
                props.append((property, item))

            self.sortedProps = sorted(props, key=lambda tuple: tuple[1])

            for tuple in self.sortedProps:
                combobox.addItem(tuple[1],
                                 QVariant(str(tuple[0].uri().toString())))

            return combobox
        else:
            return QItemDelegate.createEditor(self, parent, option, index)
Пример #2
0
    def createEditor(self, parent, option, index):
        if index.column() == 0:
            combobox = QComboBox(parent)
            combobox.setEditable(False)
            props = []
            sindex = self.table.table.model().mapToSource(index)
            
            #we list the properties that are compatible with the subject type
            #the subject type depends on the direction of the relation: current resource 
            #is subject or is object of the relation?
            
            currentRelation = index.model().sourceModel().relations[sindex.row()]
            direct = currentRelation[2]
            if direct:
                subject =  self.table.resource
            else:
                subject =  currentRelation[1]

            for property in datamanager.resourceTypesProperties(subject, True, False):
                item = property.label("en") +" ["+datamanager.ontologyAbbreviationForUri(property.uri(), False)+"]"
                props.append((property, item))
                 
            self.sortedProps = sorted(props, key=lambda tuple: tuple[1])            
            
            
            for tuple in self.sortedProps: 
                combobox.addItem(tuple[1], QVariant(str(tuple[0].uri().toString())))
            
            
            return combobox
        else:
            return QItemDelegate.createEditor(self, parent, option,index)
Пример #3
0
    def setupUi(self, dialog):
        dialog.setObjectName("dialog")
        vbox = QVBoxLayout(dialog)
#        self.gridlayout.setMargin(9)
#        self.gridlayout.setSpacing(6)
#        self.gridlayout.setObjectName("gridlayout")
        
        #if this is a new relation dialog
        if self.resource is not None:
            propertyWidget = QWidget(dialog)
            hbox = QHBoxLayout(propertyWidget)
            hbox.setContentsMargins(0, 0, 0, 0)
            label = QLabel(propertyWidget)
            label.setText(i18n("&Relation type:"))
            hbox.addWidget(label)
            self.properties = QComboBox()
            label.setBuddy(self.properties)
            props = []

            for property in datamanager.resourceTypesProperties(self.resource, True, False):
                ontology = datamanager.ontologyAbbreviationForUri(property.uri())
                item = property.label("en") + " [" + ontology + "]"
                props.append((property, item))
                     
            sortedProps = sorted(props, key=lambda tuple: tuple[1])
            index = 0
            isRelatedIndex = 0
            for tuple in sortedProps: 
                self.properties.addItem(tuple[1], QVariant(str(tuple[0].uri().toString())))
                if tuple[0].uri() == Soprano.Vocabulary.NAO.isRelated():
                    isRelatedIndex = index 
                index = index + 1
            hbox.addWidget(self.properties)
            self.properties.setCurrentIndex(isRelatedIndex)
            self.properties.activated.connect(self.onPropertyChanged)
            vbox.addWidget(propertyWidget)
        
        filter = QWidget(dialog)
        hbox = QHBoxLayout(filter)
        label = QLabel(filter)
        label.setText(self.objectNameLabel)
        hbox.addWidget(label)
        self.input = QLineEdit(filter)
        self.input.setObjectName("input")
        label.setBuddy(self.input)
        hbox.addWidget(self.input)
        
        label = QLabel(filter)
        label.setText(i18n("&Type:"))
        hbox.addWidget(label)
        
        
        self.typeFilterButton = QToolButton()
        self.typeFilterButton.setText(i18n("All"))
        self.typeFilterButton.setToolButtonStyle(Qt.ToolButtonTextOnly)
        self.typeFilterButton.setToolTip(i18n("Filter by type"))
        self.typeFilterButton.setIcon(KIcon("nepomuk"))
        self.typeFilterButton.setPopupMode(QToolButton.InstantPopup)
        self.typeFilterMenu = QMenu(self)
        self.typeFilterMenu.setTitle(i18n("Filter by type"))
        self.typeFilterMenu.setIcon(KIcon("nepomuk"))
        label.setBuddy(self.typeFilterButton)
        
        self.typeFilterMenu.addAction(self.mainWindow.createAction(i18n("&All"), self.onTypeFilterChanged, None, "nepomuk", None, Soprano.Vocabulary.RDFS.Resource()))
            
        for type in self.mainWindow.placesData:
            self.typeFilterMenu.addAction(self.mainWindow.createAction(type[1], self.onTypeFilterChanged, None, type[3], None, type[0]))
                
        self.typeFilterButton.setMenu(self.typeFilterMenu)
        hbox.addWidget(self.typeFilterButton)
        hbox.setContentsMargins(0, 0, 0, 0)
        
        vbox.addWidget(filter)
        
        self.matchingItems = ResourcesTable(mainWindow=dialog.mainWindow, dialog=self)
            
        label = QLabel(dialog)
        label.setText(i18n("Matching items:"))
        
        vbox.addWidget(label)
        vbox.addWidget(self.matchingItems)

        self.buttonBox = QDialogButtonBox(dialog)
        self.buttonBox.setOrientation(Qt.Horizontal)
        self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.NoButton | QDialogButtonBox.Ok)
        self.buttonBox.setObjectName("buttonBox")
        vbox.addWidget(self.buttonBox)

        dialog.setWindowTitle(i18n(self.title))

        self.buttonBox.accepted.connect(dialog.accept)
        self.buttonBox.rejected.connect(dialog.reject)
        
        QMetaObject.connectSlotsByName(dialog)
Пример #4
0
    def setupUi(self, dialog):
        dialog.setObjectName("dialog")
        vbox = QVBoxLayout(dialog)
        #        self.gridlayout.setMargin(9)
        #        self.gridlayout.setSpacing(6)
        #        self.gridlayout.setObjectName("gridlayout")

        #if this is a new relation dialog
        if self.resource is not None:
            propertyWidget = QWidget(dialog)
            hbox = QHBoxLayout(propertyWidget)
            hbox.setContentsMargins(0, 0, 0, 0)
            label = QLabel(propertyWidget)
            label.setText(i18n("&Relation type:"))
            hbox.addWidget(label)
            self.properties = QComboBox()
            label.setBuddy(self.properties)
            props = []

            for property in datamanager.resourceTypesProperties(
                    self.resource, True, False):
                ontology = datamanager.ontologyAbbreviationForUri(
                    property.uri())
                item = property.label("en") + " [" + ontology + "]"
                props.append((property, item))

            sortedProps = sorted(props, key=lambda tuple: tuple[1])
            index = 0
            isRelatedIndex = 0
            for tuple in sortedProps:
                self.properties.addItem(
                    tuple[1], QVariant(str(tuple[0].uri().toString())))
                if tuple[0].uri() == Soprano.Vocabulary.NAO.isRelated():
                    isRelatedIndex = index
                index = index + 1
            hbox.addWidget(self.properties)
            self.properties.setCurrentIndex(isRelatedIndex)
            self.properties.activated.connect(self.onPropertyChanged)
            vbox.addWidget(propertyWidget)

        filter = QWidget(dialog)
        hbox = QHBoxLayout(filter)
        label = QLabel(filter)
        label.setText(self.objectNameLabel)
        hbox.addWidget(label)
        self.input = QLineEdit(filter)
        self.input.setObjectName("input")
        label.setBuddy(self.input)
        hbox.addWidget(self.input)

        label = QLabel(filter)
        label.setText(i18n("&Type:"))
        hbox.addWidget(label)

        self.typeFilterButton = QToolButton()
        self.typeFilterButton.setText(i18n("All"))
        self.typeFilterButton.setToolButtonStyle(Qt.ToolButtonTextOnly)
        self.typeFilterButton.setToolTip(i18n("Filter by type"))
        self.typeFilterButton.setIcon(KIcon("nepomuk"))
        self.typeFilterButton.setPopupMode(QToolButton.InstantPopup)
        self.typeFilterMenu = QMenu(self)
        self.typeFilterMenu.setTitle(i18n("Filter by type"))
        self.typeFilterMenu.setIcon(KIcon("nepomuk"))
        label.setBuddy(self.typeFilterButton)

        self.typeFilterMenu.addAction(
            self.mainWindow.createAction(i18n("&All"),
                                         self.onTypeFilterChanged, None,
                                         "nepomuk", None,
                                         Soprano.Vocabulary.RDFS.Resource()))

        for type in self.mainWindow.placesData:
            self.typeFilterMenu.addAction(
                self.mainWindow.createAction(type[1], self.onTypeFilterChanged,
                                             None, type[3], None, type[0]))

        self.typeFilterButton.setMenu(self.typeFilterMenu)
        hbox.addWidget(self.typeFilterButton)
        hbox.setContentsMargins(0, 0, 0, 0)

        vbox.addWidget(filter)

        self.matchingItems = ResourcesTable(mainWindow=dialog.mainWindow,
                                            dialog=self)

        label = QLabel(dialog)
        label.setText(i18n("Matching items:"))

        vbox.addWidget(label)
        vbox.addWidget(self.matchingItems)

        self.buttonBox = QDialogButtonBox(dialog)
        self.buttonBox.setOrientation(Qt.Horizontal)
        self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel
                                          | QDialogButtonBox.NoButton
                                          | QDialogButtonBox.Ok)
        self.buttonBox.setObjectName("buttonBox")
        vbox.addWidget(self.buttonBox)

        dialog.setWindowTitle(i18n(self.title))

        self.buttonBox.accepted.connect(dialog.accept)
        self.buttonBox.rejected.connect(dialog.reject)

        QMetaObject.connectSlotsByName(dialog)
    def createEditor(self, parent, option, index):
        if index.column() == 0:
            combobox = QComboBox(parent)
            combobox.setEditable(False)
            props = []
            
            #we list the properties that are compatible with the subject type
            #the subject type depends on the direction of the relation: current resource 
            #is subject or is object of the relation?
            

            for property in datamanager.resourceTypesProperties(self.table.resource, False, True):
                item = property.label("en") + " [" + datamanager.ontologyAbbreviationForUri(property.uri(), True) + "]"
                props.append((property, item))
                 
            self.sortedProps = sorted(props, key=lambda tuple: tuple[1])            
            
            
            for tuple in self.sortedProps: 
                combobox.addItem(tuple[1], QVariant(str(tuple[0].uri().toString())))
            
            return combobox
        elif index.column() == 1:
            #edition of a property value
            #identify the range of the property
            sindex = self.table.table.model().mapToSource(index)
            propertyUrl = index.model().sourceModel().data[sindex.row()][0]
            
            #TODO: see why property.range() won't return the expected range URI.
            #Until then,  we use a the property as a resource
            #property = Nepomuk.Types.Property(QUrl(propertyStr))
            
            propertyResource = Nepomuk.Resource(propertyUrl)
            range = str(propertyResource.property(Soprano.Vocabulary.RDFS.range()).toString())
            
            #"boolean", "integer", "dateTime", "date", "duration", "float",  "int", "nonNegativeInteger", "string"]:
            #"http://www.w3.org/2000/01/rdf-schema#Literal"

            if range in ("http://www.w3.org/2001/XMLSchema#duration", "http://www.w3.org/2001/XMLSchema#integer", "http://www.w3.org/2001/XMLSchema#int", "http://www.w3.org/2001/XMLSchema#nonNegativeInteger"):
                spinbox = QSpinBox(parent)
                spinbox.setRange(0, 100000000)
                spinbox.setSingleStep(1)
                spinbox.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding)
                spinbox.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
                return spinbox
            
            elif range in ("http://www.w3.org/2001/XMLSchema#float"):
                dspinbox = QDoubleSpinBox(parent)
                dspinbox.setRange(0, 100000000)
                return dspinbox
            
            elif range == "http://www.w3.org/2001/XMLSchema#date":
                dateEdit = QDateEdit(parent)
                return dateEdit
            
            elif range == "http://www.w3.org/2001/XMLSchema#dateTime":
                dateEdit = QDateTimeEdit(parent)
                return dateEdit
            else:
                editor = QLineEdit(parent)
                editor.returnPressed.connect(self.commitAndCloseEditor)
                return editor
            
                
                 
            
        else:
            return None