QGIS API Documentation 3.41.0-Master (af5edcb665c)
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#include "moc_qgsprocessinghistorywidget.cpp"
18#include "qgshistorywidget.h"
19#include "qgsgui.h"
21#include "qgshelp.h"
22#include "qgsfileutils.h"
23#include "qgshistoryentry.h"
24
25#include <QVBoxLayout>
26#include <QMessageBox>
27#include <QFileDialog>
28#include <QTextStream>
29#include <QDialogButtonBox>
30#include <QPushButton>
31
33 : QgsPanelWidget( parent )
34{
35 mHistoryWidget = new QgsHistoryWidget( QStringLiteral( "processing" ) );
36 QVBoxLayout *vl = new QVBoxLayout();
37 vl->setContentsMargins( 0, 0, 0, 0 );
38 vl->addWidget( mHistoryWidget );
39 setLayout( vl );
40}
41
43{
44 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 )
45 {
47 }
48}
49
51{
52 QgsHelp::openHelp( QStringLiteral( "processing/history.html" ) );
53}
54
56{
57 QString fileName = QFileDialog::getSaveFileName( this, tr( "Save File" ), QDir::homePath(), tr( "Log files (*.log *.LOG)" ) );
58 // return dialog focus on Mac
59 activateWindow();
60 raise();
61
62 if ( fileName.isEmpty() )
63 return;
64
65 fileName = QgsFileUtils::ensureFileNameHasExtension( fileName, { QStringLiteral( "log" ) } );
66
67 const QList<QgsHistoryEntry> entries = QgsGui::historyProviderRegistry()->queryEntries( QDateTime(), QDateTime(), QStringLiteral( "processing" ) );
68
69 const QString logSeparator = QStringLiteral( "|~|" );
70 QFile logFile( fileName );
71 if ( logFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
72 {
73 QTextStream logOut( &logFile );
74 for ( const QgsHistoryEntry &entry : entries )
75 {
76 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() );
77 }
78 }
79}
80
81
82//
83// QgsProcessingHistoryDialog
84//
85
87 : QDialog( parent )
88{
89 setObjectName( QStringLiteral( "QgsProcessingHistoryDialog" ) );
91
92 setWindowTitle( tr( "Processing History" ) );
93
94 QVBoxLayout *vl = new QVBoxLayout();
95 mWidget = new QgsProcessingHistoryWidget();
96 vl->addWidget( mWidget, 1 );
97
98 mButtonBox = new QDialogButtonBox( QDialogButtonBox::Close | QDialogButtonBox::Help );
99
100 QPushButton *clearButton = new QPushButton( tr( "Clear" ) );
101 clearButton->setToolTip( tr( "Clear history" ) );
102 mButtonBox->addButton( clearButton, QDialogButtonBox::ActionRole );
103
104 QPushButton *saveButton = new QPushButton( tr( "Save As…" ) );
105 saveButton->setToolTip( tr( "Save history" ) );
106 mButtonBox->addButton( saveButton, QDialogButtonBox::ActionRole );
107
108 connect( clearButton, &QPushButton::clicked, mWidget, &QgsProcessingHistoryWidget::clearHistory );
109 connect( saveButton, &QPushButton::clicked, mWidget, &QgsProcessingHistoryWidget::saveLog );
110 connect( mButtonBox->button( QDialogButtonBox::Help ), &QPushButton::clicked, mWidget, &QgsProcessingHistoryWidget::openHelp );
111 connect( mButtonBox->button( QDialogButtonBox::Close ), &QPushButton::clicked, mWidget, [=]() { close(); } );
112
113 vl->addWidget( mButtonBox );
114
115 setLayout( vl );
116}
@ LocalProfile
Local profile.
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:79
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:210
static QgsHistoryProviderRegistry * historyProviderRegistry()
Returns the global history provider registry, used for tracking history providers.
Definition qgsgui.cpp:200
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition qgshelp.cpp:39
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.
Base class for any widget that can be shown as a 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.