def fetchResults(self, string, context, feedback): # collect results in main thread, since this method is inexpensive and # accessing the processing registry/current layer is not thread safe if iface.activeLayer() is None or iface.activeLayer().type() != QgsMapLayer.VectorLayer or not iface.activeLayer().selectedFeatureCount(): return for a in QgsApplication.processingRegistry().algorithms(): if not a.flags() & QgsProcessingAlgorithm.FlagSupportsInPlaceEdits: continue if not a.supportInPlaceEdit(iface.activeLayer()): continue if QgsLocatorFilter.stringMatches(a.displayName(), string) or [t for t in a.tags() if QgsLocatorFilter.stringMatches(t, string)] or \ (context.usingPrefix and not string): result = QgsLocatorResult() result.filter = self result.displayString = a.displayName() result.icon = a.icon() result.userData = a.id() if string and QgsLocatorFilter.stringMatches(a.displayName(), string): result.score = float(len(string)) / len(a.displayName()) else: result.score = 0 self.resultFetched.emit(result)
def fetchResults(self, string, context, feedback): # collect results in main thread, since this method is inexpensive and # accessing the processing registry is not thread safe for a in QgsApplication.processingRegistry().algorithms(): if a.flags() & QgsProcessingAlgorithm.FlagHideFromToolbox: continue if QgsLocatorFilter.stringMatches(a.displayName(), string) or [t for t in a.tags() if QgsLocatorFilter.stringMatches(t, string)]: result = QgsLocatorResult() result.filter = self result.displayString = a.displayName() result.icon = a.icon() result.userData = a.id() if string and QgsLocatorFilter.stringMatches(a.displayName(), string): result.score = float(len(string)) / len(a.displayName()) else: result.score = 0 self.resultFetched.emit(result)
def fetchResults(self, string, context, feedback): for a in QgsApplication.processingRegistry().algorithms(): if feedback.isCanceled(): return if a.flags() & QgsProcessingAlgorithm.FlagHideFromToolbox: continue if QgsLocatorFilter.stringMatches(a.displayName(), string) or [t for t in a.tags() if QgsLocatorFilter.stringMatches(t, string)]: result = QgsLocatorResult() result.filter = self result.displayString = a.displayName() result.icon = a.icon() result.userData = a.id() if string and QgsLocatorFilter.stringMatches(a.displayName(), string): result.score = float(len(string)) / len(a.displayName()) else: result.score = 0 self.resultFetched.emit(result)
def fetchResults(self, string, context, feedback): # collect results in main thread, since this method is inexpensive and # accessing the processing registry is not thread safe for a in QgsApplication.processingRegistry().algorithms(): if a.flags() & QgsProcessingAlgorithm.FlagHideFromToolbox: continue if QgsLocatorFilter.stringMatches(a.displayName(), string) or [t for t in a.tags() if QgsLocatorFilter.stringMatches(t, string)] or \ (context.usingPrefix and not string): result = QgsLocatorResult() result.filter = self result.displayString = a.displayName() result.icon = a.icon() result.userData = a.id() if string and QgsLocatorFilter.stringMatches(a.displayName(), string): result.score = float(len(string)) / len(a.displayName()) else: result.score = 0 self.resultFetched.emit(result)
def fetchResults( self, query, context, feedback ): matching_layers = self.data.get_matching_layers( query ) for layer in matching_layers: result = QgsLocatorResult() result.filter = self result.displayString = layer['title'] result.userData = layer['actionindex'] result.score = 0 self.resultFetched.emit(result)
def fetchResults(self, string, context, feedback): # collect results in main thread, since this method is inexpensive and # accessing the processing registry/current layer is not thread safe if iface.activeLayer() is None or iface.activeLayer().type() != QgsMapLayerType.VectorLayer: return for a in QgsApplication.processingRegistry().algorithms(): if not a.flags() & QgsProcessingAlgorithm.FlagSupportsInPlaceEdits: continue if not a.supportInPlaceEdit(iface.activeLayer()): continue result = QgsLocatorResult() result.filter = self result.displayString = a.displayName() result.icon = a.icon() result.userData = a.id() result.score = 0 if (context.usingPrefix and not string): self.resultFetched.emit(result) if not string: return string = string.lower() tagScore = 0 tags = [*a.tags(), a.provider().name()] if a.group(): tags.append(a.group()) for t in tags: if string in t.lower(): tagScore = 1 break result.score = QgsStringUtils.fuzzyScore(result.displayString, string) * 0.5 + tagScore * 0.5 if result.score > 0: self.resultFetched.emit(result)
def fetchResults(self, string, context, feedback): for a in QgsApplication.processingRegistry().algorithms(): if feedback.isCanceled(): return if a.flags() & QgsProcessingAlgorithm.FlagHideFromToolbox: continue if QgsLocatorFilter.stringMatches(a.displayName(), string) or [ t for t in a.tags() if QgsLocatorFilter.stringMatches(t, string) ]: result = QgsLocatorResult() result.filter = self result.displayString = a.displayName() result.icon = a.icon() result.userData = a.id() if string and QgsLocatorFilter.stringMatches( a.displayName(), string): result.score = float(len(string)) / len(a.displayName()) else: result.score = 0 self.resultFetched.emit(result)
def fetchResults(self, string, context, feedback): # collect results in main thread, since this method is inexpensive and # accessing the processing registry is not thread safe for a in QgsApplication.processingRegistry().algorithms(): if a.flags() & QgsProcessingAlgorithm.FlagHideFromToolbox: continue if not ProcessingConfig.getSetting(ProcessingConfig.SHOW_ALGORITHMS_KNOWN_ISSUES) and \ a.flags() & QgsProcessingAlgorithm.FlagKnownIssues: continue result = QgsLocatorResult() result.filter = self result.displayString = a.displayName() result.icon = a.icon() result.userData = a.id() result.score = 0 if (context.usingPrefix and not string): self.resultFetched.emit(result) if not string: return string = string.lower() tagScore = 0 tags = [*a.tags(), a.provider().name()] if a.group(): tags.append(a.group()) for t in tags: if string in t.lower(): tagScore = 1 break result.score = QgsStringUtils.fuzzyScore( result.displayString, string) * 0.5 + tagScore * 0.5 if result.score > 0: self.resultFetched.emit(result)
def data_product_qgsresult(self, data: dict, sub_layer: bool, score: float, stacktype) -> QgsLocatorResult: result = QgsLocatorResult() result.filter = self result.displayString = '{prefix}{title}'.format( prefix=' ↳ ' if sub_layer else '', title=data['display']) if stacktype == 'background': result.group = 'Karten (Hintergrundkarten)' else: result.group = 'Karten (Vordergrundkarten)' result.userData = DataProductResult( type=data['type'], dataproduct_id=data['dataproduct_id'], display=data['display'], dset_info=data['dset_info'], stacktype=stacktype, sublayers=data.get('sublayers', None)) data_product = 'dataproduct' data_type = data['type'] result.icon, result.description = dataproduct2icon_description( data_product, data_type) result.score = score return result
def handle_response(self, response, search_text: str): try: if response.status_code != 200: if not isinstance(response.exception, RequestsExceptionUserAbort): self.info("Error in main response with status code: " "{} from {}".format(response.status_code, response.url)) return data = json.loads(response.content.decode('utf-8')) # Since results are ordered by score (0 to 1) # we use an ordering score to keep the same order than the one from the remote service score = 1 # sub-filtering # dbg_info(data['result_counts']) if len(data['result_counts']) > 1: for _filter in data['result_counts']: result = QgsLocatorResult() result.filter = self result.group = 'Suche verfeinern' result.displayString = _filter['filterword'] if _filter['count']: result.displayString += ' ({})'.format( _filter['count']) self.dbg_info(_filter) result.icon, _ = dataproduct2icon_description( _filter['dataproduct_id'], 'datasetview') result.userData = FilterResult(_filter['filterword'], search_text) result.score = score self.resultFetched.emit(result) score -= 0.001 for res in data['results']: # dbg_info(res) result = QgsLocatorResult() result.filter = self if 'feature' in res.keys(): f = res['feature'] # dbg_info("feature: {}".format(f)) result.displayString = f['display'] result.group = 'Orte' result.userData = FeatureResult( dataproduct_id=f['dataproduct_id'], id_field_name=f['id_field_name'], id_field_type=f['id_field_type'], feature_id=f['feature_id']) data_product = f['dataproduct_id'] data_type = None result.icon, result.description = dataproduct2icon_description( data_product, data_type) result.score = score self.resultFetched.emit(result) score -= 0.001 elif 'dataproduct' in res.keys(): dp = res['dataproduct'] # self.dbg_info("data_product: {}".format(dp)) result = self.data_product_qgsresult( dp, False, score, dp['stacktype']) self.resultFetched.emit(result) score -= 0.001 # also give sublayers for layer in dp.get('sublayers', []): always_show_sublayers = True if always_show_sublayers or search_text.lower( ) in layer['display'].lower(): result = self.data_product_qgsresult( layer, True, score, dp['stacktype']) self.resultFetched.emit(result) score -= 0.001 else: continue self.result_found = True except Exception as e: self.info(str(e), Qgis.Critical) exc_type, exc_obj, exc_traceback = sys.exc_info() filename = os.path.split( exc_traceback.tb_frame.f_code.co_filename)[1] self.info( '{} {} {}'.format(exc_type, filename, exc_traceback.tb_lineno), Qgis.Critical) self.info( traceback.print_exception(exc_type, exc_obj, exc_traceback), Qgis.Critical)