Skip to content

Commit

Permalink
[processing] Use c++ recent algorithm log, remove python log
Browse files Browse the repository at this point in the history
Indirectly fixes #19218
  • Loading branch information
nyalldawson committed Jul 4, 2018
1 parent d232cde commit 6c014b4
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
QgsProject,
QgsMessageLog,
QgsProcessingOutputLayerDefinition)
from qgis.gui import QgsEncodingFileDialog
from qgis.gui import QgsEncodingFileDialog, QgsGui
from qgis.utils import OverrideCursor

from processing.core.ProcessingConfig import ProcessingConfig
Expand Down Expand Up @@ -240,6 +240,7 @@ def accept(self):

context = dataobjects.createContext()
ProcessingLog.addToLog(self.alg.asPythonCommand(parameters, context))
QgsGui.instance().processingRecentAlgorithmLog().push(self.alg.id())

self.executed, results = execute(self.alg, parameters, context, self.feedback)
self.setPercentage(0)
Expand Down
5 changes: 0 additions & 5 deletions python/plugins/processing/core/ProcessingConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class ProcessingConfig:
USE_FILENAME_AS_LAYER_NAME = 'USE_FILENAME_AS_LAYER_NAME'
KEEP_DIALOG_OPEN = 'KEEP_DIALOG_OPEN'
SHOW_DEBUG_IN_DIALOG = 'SHOW_DEBUG_IN_DIALOG'
RECENT_ALGORITHMS = 'RECENT_ALGORITHMS'
PRE_EXECUTION_SCRIPT = 'PRE_EXECUTION_SCRIPT'
POST_EXECUTION_SCRIPT = 'POST_EXECUTION_SCRIPT'
SHOW_CRS_DEF = 'SHOW_CRS_DEF'
Expand Down Expand Up @@ -136,10 +135,6 @@ def initialize():
ProcessingConfig.POST_EXECUTION_SCRIPT,
ProcessingConfig.tr('Post-execution script'), '',
valuetype=Setting.FILE))
ProcessingConfig.addSetting(Setting(
ProcessingConfig.tr('General'),
ProcessingConfig.RECENT_ALGORITHMS,
ProcessingConfig.tr('Recent algorithms'), '', hidden=True))
ProcessingConfig.addSetting(Setting(
ProcessingConfig.tr('General'),
ProcessingConfig.MODELS_SCRIPTS_REPO,
Expand Down
19 changes: 0 additions & 19 deletions python/plugins/processing/core/ProcessingLog.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
class ProcessingLog:

DATE_FORMAT = "%Y-%m-%d %H:%M:%S"
recentAlgs = []

@staticmethod
def logFilename():
Expand All @@ -63,14 +62,6 @@ def addToLog(msg):
with codecs.open(ProcessingLog.logFilename(), 'a',
encoding='utf-8') as logfile:
logfile.write(line)
algname = msg[len('processing.run("'):]
algname = algname[:algname.index('"')]
if algname not in ProcessingLog.recentAlgs:
ProcessingLog.recentAlgs.append(algname)
recentAlgsString = ';'.join(ProcessingLog.recentAlgs[-6:])
ProcessingConfig.setSettingValue(
ProcessingConfig.RECENT_ALGORITHMS,
recentAlgsString)
except:
pass

Expand All @@ -95,16 +86,6 @@ def getLogEntries():

return entries

@staticmethod
def getRecentAlgorithms():
recentAlgsSetting = ProcessingConfig.getSetting(
ProcessingConfig.RECENT_ALGORITHMS)
try:
ProcessingLog.recentAlgs = recentAlgsSetting.split(';')
except:
pass
return ProcessingLog.recentAlgs

@staticmethod
def clearLog():
os.unlink(ProcessingLog.logFilename())
Expand Down
4 changes: 3 additions & 1 deletion python/plugins/processing/gui/AlgorithmDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
QgsProcessingParameterFeatureSink,
QgsProcessingParameterRasterDestination,
QgsProcessingAlgorithm)
from qgis.gui import (QgsMessageBar,
from qgis.gui import (QgsGui,
QgsMessageBar,
QgsProcessingAlgorithmDialogBase)
from qgis.utils import iface

Expand Down Expand Up @@ -188,6 +189,7 @@ def accept(self):
command = self.algorithm().asPythonCommand(parameters, context)
if command:
ProcessingLog.addToLog(command)
QgsGui.instance().processingRecentAlgorithmLog().push(self.algorithm().id())
self.cancelButton().setEnabled(self.algorithm().flags() & QgsProcessingAlgorithm.FlagCanCancel)

def on_complete(ok, results):
Expand Down
17 changes: 7 additions & 10 deletions python/plugins/processing/gui/ProcessingToolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
from qgis.utils import iface
from qgis.core import (QgsApplication,
QgsProcessingAlgorithm)
from qgis.gui import QgsDockWidget
from qgis.gui import (QgsGui,
QgsDockWidget)

from processing.gui.Postprocessing import handleAlgorithmResults
from processing.core.ProcessingLog import ProcessingLog
Expand Down Expand Up @@ -107,6 +108,7 @@ def openSettings(url):

QgsApplication.processingRegistry().providerRemoved.connect(self.removeProvider)
QgsApplication.processingRegistry().providerAdded.connect(self.addProvider)
QgsGui.instance().processingRecentAlgorithmLog().changed.connect(self.addRecentAlgorithms)
settingsWatcher.settingsChanged.connect(self.fillTree)

def showDisabled(self):
Expand Down Expand Up @@ -349,11 +351,6 @@ def executeAlgorithm(self):
except:
pass
canvas.setMapTool(prevMapTool)
if dlg.wasExecuted():
showRecent = ProcessingConfig.getSetting(
ProcessingConfig.SHOW_RECENT_ALGORITHMS)
if showRecent:
self.addRecentAlgorithms(True)
else:
feedback = MessageBarProgress()
context = dataobjects.createContext(feedback)
Expand All @@ -366,11 +363,11 @@ def fillTree(self):
self.fillTreeUsingProviders()
self.addRecentAlgorithms(False)

def addRecentAlgorithms(self, updating):
def addRecentAlgorithms(self, updating=True):
showRecent = ProcessingConfig.getSetting(
ProcessingConfig.SHOW_RECENT_ALGORITHMS)
if showRecent:
recent = ProcessingLog.getRecentAlgorithms()
recent = QgsGui.instance().processingRecentAlgorithmLog().recentAlgorithmIds()
if len(recent) != 0:
found = False
if updating:
Expand All @@ -382,8 +379,8 @@ def addRecentAlgorithms(self, updating):

recentItem = QTreeWidgetItem()
recentItem.setText(0, self.tr('Recently used'))
for algname in recent:
alg = QgsApplication.processingRegistry().createAlgorithmById(algname)
for algorithm_id in recent:
alg = QgsApplication.processingRegistry().createAlgorithmById(algorithm_id)
if alg is not None:
algItem = TreeAlgorithmItem(alg)
recentItem.addChild(algItem)
Expand Down

0 comments on commit 6c014b4

Please sign in to comment.