Skip to content
Permalink
Browse files

[processing] Regroup executed algorithms under meaningful groups in t…

…he history dialog
  • Loading branch information
nirvn committed Apr 4, 2021
1 parent ca7c033 commit 026b8416ae27c84aa9c248f09caf419df2414362
Showing with 35 additions and 8 deletions.
  1. +35 −8 python/plugins/processing/gui/HistoryDialog.py
@@ -24,11 +24,12 @@
import os
import warnings
import re
from datetime import datetime

from qgis.core import QgsApplication
from qgis.gui import QgsGui, QgsHelp
from qgis.PyQt import uic
from qgis.PyQt.QtCore import Qt, QCoreApplication
from qgis.PyQt.QtCore import Qt, QCoreApplication, QDate
from qgis.PyQt.QtWidgets import QAction, QPushButton, QDialogButtonBox, QStyle, QMessageBox, QFileDialog, QMenu, QTreeWidgetItem
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.Qsci import QsciScintilla
@@ -84,6 +85,8 @@ def __init__(self):
self.tree.setContextMenuPolicy(Qt.CustomContextMenu)
self.tree.customContextMenuRequested.connect(self.showPopupMenu)

self.contextDateStrings = {}

self.fillTree()

def clearLog(self):
@@ -112,15 +115,38 @@ def saveLog(self):
def openHelp(self):
QgsHelp.openHelp("processing/history.html")

def contextDateString(self, date):
if date in self.contextDateStrings:
return self.contextDateStrings[date]

if date == datetime.today().strftime('%Y-%m-%d'):
self.contextDateStrings[date] = self.tr('Today')
else:
interval_days = (datetime.today() - datetime.strptime(date, '%Y-%m-%d')).days
if interval_days == 1:
self.contextDateStrings[date] = self.tr('Yesterday')
elif interval_days < 8:
self.contextDateStrings[date] = self.tr('Last 7 days')
else:
self.contextDateStrings[date] = QDate.fromString(date, 'yyyy-MM-dd').toString('MMMM yyyy')
return self.contextDateString(date)

def fillTree(self):
self.tree.clear()
entries = ProcessingLog.getLogEntries()
names = {}
icons = {}
groupItem = QTreeWidgetItem()
groupItem.setText(0, 'ALGORITHM')
groupItem.setIcon(0, self.groupIcon)
group_items = []
current_group_item = -1
current_date = ''
for entry in entries:
date = self.contextDateString(entry.date[0:10])
if date != current_date:
current_date = date
current_group_item += 1
group_items.append(QTreeWidgetItem())
group_items[current_group_item].setText(0, date)
group_items[current_group_item].setIcon(0, self.groupIcon)
icon = self.keyIcon
name = ''
match = re.search('processing.run\\("(.*?)"', entry.text)
@@ -138,9 +164,10 @@ def fillTree(self):
icon = icons[algorithm_id]
item = TreeLogEntryItem(entry, True, name)
item.setIcon(0, icon)
groupItem.insertChild(0, item)
self.tree.addTopLevelItem(groupItem)
groupItem.setExpanded(True)
group_items[current_group_item].insertChild(0, item)

self.tree.addTopLevelItems(reversed(group_items))
self.tree.topLevelItem(0).setExpanded(True)

def executeAlgorithm(self):
item = self.tree.currentItem()
@@ -184,4 +211,4 @@ def __init__(self, entry, isAlg, algName):
QTreeWidgetItem.__init__(self)
self.entry = entry
self.isAlg = isAlg
self.setText(0, '[' + entry.date + '] ' + algName + ' - ' + entry.text.split(LOG_SEPARATOR)[0])
self.setText(0, '[' + entry.date[:-3] + '] ' + algName + ' - ' + entry.text.split(LOG_SEPARATOR)[0])

0 comments on commit 026b841

Please sign in to comment.