コード例 #1
0
        def _createNewActivity(id=None, otherActivity=None):

            # Connect to the protocol signal
            self.connect(self.activityProtocol, SIGNAL("created( bool, int, QString )"), _createNewActivityFinished)

            # Create a new Uuid
            if id is not None:
                uid = QPlainUuid(id)
            else:
                uid = QPlainUuid(QUuid.createUuid())

            tagGroups = list(TagGroup() for i in range(len(groups)))

            # attrs is a dictionary: key = field index, value = QgsFeatureAttribute
            # show all attributes and their values
            self.log("Attribute list:")
            for (k, attr) in attrs.iteritems():
                if k is not identifierColumnIndex:
                    self.log("%s: %s" % (fieldIndexMap[k], attr.toString()))

                    # First search the correct taggroup to append
                    attributeName = provider.fields()[k].name()
                    currentTagGroup = 0
                    for g in groups:
                        if attributeName in g:
                            break
                        else:
                            currentTagGroup += 1

                    if attr is not None and attr.toString() != '':
                        tag = Tag(key=fieldIndexMap[k], value=attr.toString())
                        tagGroups[currentTagGroup].addTag(tag)
                        if tagGroups[currentTagGroup].mainTag() is None:
                            tagGroups[currentTagGroup].setMainTag(tag)

            a = Activity(id=uid)
            a.setGeometry(feature.geometry())
            for tg in tagGroups:
                if len(tg.tags) > 0:
                    a.addTagGroup(tg)

            wrapperObj = {}

            wrapperObj['activities'] = [a.createDiff(otherActivity)]

            self.activityProtocol.add(json.dumps(wrapperObj, sort_keys=True, indent=4 * ' '))