QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsprocessinghistorywidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsprocessinghistorywidget.cpp
3 ------------------------
4 Date : April 2023
5 Copyright : (C) 2023 Nyall Dawson
6 Email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17
18#include "qgsfileutils.h"
19#include "qgsgui.h"
20#include "qgshelp.h"
21#include "qgshistoryentry.h"
23#include "qgshistorywidget.h"
24
25#include <QDialogButtonBox>
26#include <QFileDialog>
27#include <QMessageBox>
28#include <QPushButton>
29#include <QTextStream>
30#include <QVBoxLayout>
31
32#include "moc_qgsprocessinghistorywidget.cpp"
33
35 : QgsPanelWidget( parent )
36{
37 mHistoryWidget = new QgsHistoryWidget( QStringLiteral( "processing" ) );
38 QVBoxLayout *vl = new QVBoxLayout();
39 vl->setContentsMargins( 0, 0, 0, 0 );
40 vl->addWidget( mHistoryWidget );
41 setLayout( vl );
42}
43
45{
46 if ( QMessageBox::question( this, tr( "Clear History" ), tr( "Are you sure you want to clear the Processing history?" ), QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) == QMessageBox::Yes )
47 {
49 }
50}
51
53{
54 QgsHelp::openHelp( QStringLiteral( "processing/history.html" ) );
55}
56
58{
59 QString fileName = QFileDialog::getSaveFileName( this, tr( "Save File" ), QDir::homePath(), tr( "Log files (*.log *.LOG)" ) );
60 // return dialog focus on Mac
61 activateWindow();
62 raise();
63
64 if ( fileName.isEmpty() )
65 return;
66
67 fileName = QgsFileUtils::ensureFileNameHasExtension( fileName, { QStringLiteral( "log" ) } );
68
69 const QList<QgsHistoryEntry> entries = QgsGui::historyProviderRegistry()->queryEntries( QDateTime(), QDateTime(), QStringLiteral( "processing" ) );
70
71 const QString logSeparator = QStringLiteral( "|~|" );
72 QFile logFile( fileName );
73 if ( logFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
74 {
75 QTextStream logOut( &logFile );
76 for ( const QgsHistoryEntry &entry : entries )
77 {
78 logOut << QStringLiteral( "ALGORITHM%1%2%3%4\n" ).arg( logSeparator, entry.timestamp.toString( "yyyy-MM-dd HH:mm:ss" ), logSeparator, entry.entry.value( QStringLiteral( "python_command" ) ).toString() );
79 }
80 }
81}
82
83
84//
85// QgsProcessingHistoryDialog
86//
87
89 : QDialog( parent )
90{
91 setObjectName( QStringLiteral( "QgsProcessingHistoryDialog" ) );
93
94 setWindowTitle( tr( "Processing History" ) );
95
96 QVBoxLayout *vl = new QVBoxLayout();
97 mWidget = new QgsProcessingHistoryWidget();
98 vl->addWidget( mWidget, 1 );
99
100 mButtonBox = new QDialogButtonBox( QDialogButtonBox::Close | QDialogButtonBox::Help );
101
102 QPushButton *clearButton = new QPushButton( tr( "Clear" ) );
103 clearButton->setToolTip( tr( "Clear history" ) );
104 mButtonBox->addButton( clearButton, QDialogButtonBox::ActionRole );
105
106 QPushButton *saveButton = new QPushButton( tr( "Save As…" ) );
107 saveButton->setToolTip( tr( "Save history" ) );
108 mButtonBox->addButton( saveButton, QDialogButtonBox::ActionRole );
109
110 connect( clearButton, &QPushButton::clicked, mWidget, &QgsProcessingHistoryWidget::clearHistory );
111 connect( saveButton, &QPushButton::clicked, mWidget, &QgsProcessingHistoryWidget::saveLog );
112 connect( mButtonBox->button( QDialogButtonBox::Help ), &QPushButton::clicked, mWidget, &QgsProcessingHistoryWidget::openHelp );
113 connect( mButtonBox->button( QDialogButtonBox::Close ), &QPushButton::clicked, mWidget, [this]() { close(); } );
114
115 vl->addWidget( mButtonBox );
116
117 setLayout( vl );
118}
@ LocalProfile
Local profile.
Definition qgis.h:3504
static QString ensureFileNameHasExtension(const QString &fileName, const QStringList &extensions)
Ensures that a fileName ends with an extension from the provided list of extensions.
static QgsGui * instance()
Returns a pointer to the singleton instance.
Definition qgsgui.cpp:90
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
Definition qgsgui.cpp:221
static QgsHistoryProviderRegistry * historyProviderRegistry()
Returns the global history provider registry, used for tracking history providers.
Definition qgsgui.cpp:211
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition qgshelp.cpp:38
Encapsulates a history entry.
bool clearHistory(Qgis::HistoryProviderBackend backend, const QString &providerId=QString())
Clears the history for the specified backend.
QList< QgsHistoryEntry > queryEntries(const QDateTime &start=QDateTime(), const QDateTime &end=QDateTime(), const QString &providerId=QString(), Qgis::HistoryProviderBackends backends=Qgis::HistoryProviderBackend::LocalProfile) const
Queries history entries which occurred between the specified start and end times.
A widget showing entries from a QgsHistoryProviderRegistry.
QgsPanelWidget(QWidget *parent=nullptr)
Base class for any widget that can be shown as an inline panel.
QgsProcessingHistoryDialog(QWidget *parent=nullptr)
Constructor for QgsProcessingHistoryDialog.
A widget for showing Processing algorithm execution history.
void saveLog()
Interactively allows users to save the history log.
QgsProcessingHistoryWidget(QWidget *parent=nullptr)
Constructor for QgsProcessingHistoryWidget, with the specified parent widget.
void clearHistory()
Clears the Processing history (after user confirmation).
void openHelp()
Opens helps for the widget.