|
10 | 10 | QgsProcessing,
|
11 | 11 | QgsProcessingAlgorithm,
|
12 | 12 | QgsProcessingException,
|
| 13 | + # QgsFeatureRequest, |
13 | 14 | QgsProcessingParameterBoolean,
|
14 | 15 | QgsProcessingParameterExpression,
|
15 | 16 | QgsProcessingParameterFeatureSource,
|
@@ -106,13 +107,41 @@ def checkParameterValues(self, parameters, context) -> Tuple[bool, str]:
|
106 | 107 | msg = tr("You must have at least one layer with the configuration.")
|
107 | 108 | return False, msg
|
108 | 109 |
|
109 |
| - source = self.parameterAsSource(parameters, self.INPUT, context) |
110 |
| - field = self.parameterAsString(parameters, self.FIELD, context) |
111 |
| - unique_values = source.uniqueValues(source.fields().indexFromName(field)) |
112 |
| - if len(unique_values) != source.featureCount(): |
113 |
| - msg = tr("You field '{}' does not have unique values within the given layer.") |
| 110 | + if context.project().isDirty(): |
| 111 | + msg = tr("You must save your project first.") |
114 | 112 | return False, msg
|
115 | 113 |
|
| 114 | + # source = self.parameterAsSource(parameters, self.INPUT, context) |
| 115 | + # field = self.parameterAsString(parameters, self.FIELD, context) |
| 116 | + # index = source.fields().indexFromName(field) |
| 117 | + # unique_values = source.uniqueValues(index) |
| 118 | + # if len(unique_values) != source.featureCount(): |
| 119 | + # |
| 120 | + # request = QgsFeatureRequest() |
| 121 | + # request.setSubsetOfAttributes([field], source.fields()) |
| 122 | + # request.addOrderBy(field) |
| 123 | + # request.setFlags(QgsFeatureRequest.NoGeometry) |
| 124 | + # count = {} |
| 125 | + # for f in source.getFeatures(request): |
| 126 | + # if f[field] not in count.keys(): |
| 127 | + # count[f[field]] = 0 |
| 128 | + # count[f[field]] += 1 |
| 129 | + # debug = '' |
| 130 | + # for k, v in count.items(): |
| 131 | + # debug += f'{k} → {v}, ' |
| 132 | + # |
| 133 | + # # count = {k: v for k, v in count.items() if v >= 2} |
| 134 | + # msg = tr( |
| 135 | + # "You field '{}' does not have unique values within the given layer : " |
| 136 | + # "{} uniques values versus {} features : {}" |
| 137 | + # ).format( |
| 138 | + # field, |
| 139 | + # len(unique_values), |
| 140 | + # source.featureCount(), |
| 141 | + # debug |
| 142 | + # ) |
| 143 | + # return False, msg |
| 144 | + |
116 | 145 | return super().checkParameterValues(parameters, context)
|
117 | 146 |
|
118 | 147 | def processAlgorithm(self, parameters, context, feedback):
|
|
0 commit comments