Ejemplo n.º 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)
Ejemplo n.º 2
0
 def itemAt(self, index):
     resource = self.resources[index.row()]
     column = index.column()
     if column == 0:
         return datamanager.ontologyAbbreviationForUri(resource.resourceUri())
     elif column == 1:
         return resource.genericLabel()
Ejemplo n.º 3
0
    def data(self, index, role):
        if not index.isValid():
            return None
        if role == Qt.DecorationRole:
            item = index.internalPointer()
            type = item.nodeData
            if self.mainWindow and index.column() == 0:
                return self.mainWindow.typeQIcon(type.uri())
            else:
                return None
        
        elif role == Qt.DisplayRole:
            item = index.internalPointer()
            #print item.nodeData.label("")
            if index.column() == 0:
                #return item.nodeData.name()
#                if item.label:
#                    return item.label
#                else:
#                    return item.nodeData.name()
                return item.nodeData.genericLabel()
            elif index.column() == 1:
                return datamanager.ontologyAbbreviationForUri(item.nodeData.resourceUri())
                
            elif index.column() == 2:
                desc = item.nodeData.genericDescription()
                desc = desc.replace("\n", "")
                return desc

        else:
            return None
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
 def itemAt(self, index):
     resource = self.resources[index.row()]
     column = index.column()
     if column == 0:
         return datamanager.ontologyAbbreviationForUri(
             resource.resourceUri())
     elif column == 1:
         return resource.genericLabel()
Ejemplo n.º 6
0
 def getProperties(self, ontologyAbbrev):
     properties = self.resource.properties()
     foundProperties = []
     for propertyUri in properties:
         abbrev = datamanager.ontologyAbbreviationForUri(propertyUri)
         if abbrev == ontologyAbbrev:
             property = Nepomuk.Types.Property(propertyUri)
             foundProperties.append(property)
     
     return foundProperties
Ejemplo n.º 7
0
    def getProperties(self, ontologyAbbrev):
        properties = self.resource.properties()
        foundProperties = []
        for propertyUri in properties:
            abbrev = datamanager.ontologyAbbreviationForUri(propertyUri)
            if abbrev == ontologyAbbrev:
                property = Nepomuk.Types.Property(propertyUri)
                foundProperties.append(property)

        return foundProperties
Ejemplo n.º 8
0
 def getTypeName(self, ontologyAbbrev):
     """Finds the first type of this resource that belongs to the ontology having the given abbreviation,
         and returns its name."""
     
     typesUris = self.resource.types()
     for typeUri in typesUris:
         abbrev = datamanager.ontologyAbbreviationForUri(typeUri)
         if abbrev == ontologyAbbrev:
             type = Nepomuk.Types.Class(typeUri)
             typeName = unicode(type.name())
             return typeName
     
     return None
Ejemplo n.º 9
0
    def getTypeName(self, ontologyAbbrev):
        """Finds the first type of this resource that belongs to the ontology having the given abbreviation,
            and returns its name."""

        typesUris = self.resource.types()
        for typeUri in typesUris:
            abbrev = datamanager.ontologyAbbreviationForUri(typeUri)
            if abbrev == ontologyAbbrev:
                type = Nepomuk.Types.Class(typeUri)
                typeName = unicode(type.name())
                return typeName

        return None
Ejemplo n.º 10
0
 def nodeToString(self, node):
     if node.isResource():
         value = node.uri()
         valueQstr = value.toString()
         label = unicode(valueQstr)
         if label.find("#") > 0:
             label = label[label.find("#") + 1:]
         ontologyLabel = datamanager.ontologyAbbreviationForUri(QUrl(valueQstr), False)
         if ontologyLabel != label:
             return label+" ["+ontologyLabel+"]"
         return label
     elif node.isLiteral():
         value = unicode(node.literal().toString())
         if len(value) > 100:
             value = value[0:100] +"..."
         return value
Ejemplo n.º 11
0
 def itemAt(self, index):
     column = index.column()
     if column == 0:
         parentClass = self.data[index.row()][0]
         return parentClass.label("en")
     elif column == 1:
         property = self.data[index.row()][1]
         uri = property.uri()
         ontologyLabel = datamanager.ontologyAbbreviationForUri(uri)
         return property.label("en") + " [" + ontologyLabel + "]"
     elif column == 2:
         property = self.data[index.row()][1]
         range = property.range()
         if range.isValid():
             return range.label("en")
         else:
             dataType = str(property.literalRangeType().dataTypeUri().toString())
             index = dataType.find("#")
             if index > 0 and len(dataType) > index:
                 dataType = dataType[index + 1:]
             return dataType
Ejemplo n.º 12
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)
Ejemplo n.º 13
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)
Ejemplo n.º 14
0
    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