QgisAlgorithm.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. """
  2. ***************************************************************************
  3. QgisAlgorithm.py
  4. ----------------
  5. Date : May 2017
  6. Copyright : (C) 2017 by Nyall Dawson
  7. Email : nyall dot dawson at gmail dot com
  8. ***************************************************************************
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. ***************************************************************************
  16. """
  17. __author__ = 'Nyall Dawson'
  18. __date__ = 'May2017'
  19. __copyright__ = '(C) 2017, Nyall Dawson'
  20. from qgis.core import QgsProcessingAlgorithm, QgsProcessingFeatureBasedAlgorithm
  21. from qgis.PyQt.QtCore import QCoreApplication
  22. from processing.algs.help import shortHelp
  23. class QgisAlgorithm(QgsProcessingAlgorithm):
  24. def __init__(self):
  25. super().__init__()
  26. def shortHelpString(self):
  27. return shortHelp.get(self.id(), None)
  28. def tr(self, string, context=''):
  29. if context == '':
  30. context = self.__class__.__name__
  31. return QCoreApplication.translate(context, string)
  32. def trAlgorithm(self, string, context=''):
  33. if context == '':
  34. context = self.__class__.__name__
  35. return string, QCoreApplication.translate(context, string)
  36. def createInstance(self):
  37. return type(self)()
  38. class QgisFeatureBasedAlgorithm(QgsProcessingFeatureBasedAlgorithm):
  39. def __init__(self):
  40. super().__init__()
  41. def shortHelpString(self):
  42. return shortHelp.get(self.id(), None)
  43. def tr(self, string, context=''):
  44. if context == '':
  45. context = self.__class__.__name__
  46. return QCoreApplication.translate(context, string)
  47. def trAlgorithm(self, string, context=''):
  48. if context == '':
  49. context = self.__class__.__name__
  50. return string, QCoreApplication.translate(context, string)
  51. def createInstance(self):
  52. return type(self)()