[processing] add "Save as" functionality to History dialog (fix #10086)

This commit is contained in:
Alexander Bruy 2014-09-14 15:53:12 +03:00
parent e3f630adb1
commit 986bd1c41a
2 changed files with 25 additions and 0 deletions

View File

@ -134,6 +134,14 @@ class ProcessingLog:
os.unlink(ProcessingLog.logFilename())
ProcessingLog.startLogging()
@staticmethod
def saveLog(fileName):
entries = ProcessingLog.getLogEntries()
with codecs.open(fileName, 'w', encoding='utf-8') as f:
for k, v in entries.iteritems():
for entry in v:
f.write('%s|%s|%s\n' % (k, entry.date, entry.text))
class LogEntry:

View File

@ -51,9 +51,14 @@ class HistoryDialog(QDialog, Ui_DlgHistory):
self.clearButton.setToolTip(self.tr('Clear history and log'))
self.buttonBox.addButton(self.clearButton, QDialogButtonBox.ActionRole)
self.saveButton = QPushButton(self.tr('Save As...'))
self.saveButton.setToolTip(self.tr('Save history and log'))
self.buttonBox.addButton(self.saveButton, QDialogButtonBox.ActionRole)
self.tree.doubleClicked.connect(self.executeAlgorithm)
self.tree.currentItemChanged.connect(self.changeText)
self.clearButton.clicked.connect(self.clearLog)
self.saveButton.clicked.connect(self.saveLog)
self.tree.setContextMenuPolicy(Qt.CustomContextMenu)
self.tree.customContextMenuRequested.connect(self.showPopupMenu)
@ -70,6 +75,18 @@ class HistoryDialog(QDialog, Ui_DlgHistory):
ProcessingLog.clearLog()
self.fillTree()
def saveLog(self):
fileName = QFileDialog.getSaveFileName(self,
self.tr('Save file'), '.', 'Log files (*.log *.LOG)')
if fileName == '':
return
if not fileName.lower().endswith('.log'):
fileName += '.log'
ProcessingLog.saveLog(fileName)
def fillTree(self):
self.tree.clear()
elements = ProcessingLog.getLogEntries()