QGIS API Documentation 3.41.0-Master (3440c17df1d)
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,
45 tr( "Clear History" ),
46 tr( "Are you sure you want to clear the Processing history?" ),
47 QMessageBox::Yes | QMessageBox::No,
48 QMessageBox::No
49 ) == QMessageBox::Yes )
50 {
52 }
53}
54
56{
57 QgsHelp::openHelp( QStringLiteral( "processing/history.html" ) );
58}
59
61{
62 QString fileName = QFileDialog::getSaveFileName( this,
63 tr( "Save File" ),
64 QDir::homePath(),
65 tr( "Log files (*.log *.LOG)" ) );
66 // return dialog focus on Mac
67 activateWindow();
68 raise();
69
70 if ( fileName.isEmpty() )
71 return;
72
73 fileName = QgsFileUtils::ensureFileNameHasExtension( fileName, { QStringLiteral( "log" ) } );
74
75 const QList< QgsHistoryEntry > entries = QgsGui::historyProviderRegistry()->queryEntries( QDateTime(), QDateTime(), QStringLiteral( "processing" ) );
76
77 const QString logSeparator = QStringLiteral( "|~|" );
78 QFile logFile( fileName );
79 if ( logFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
80 {
81 QTextStream logOut( &logFile );
82 for ( const QgsHistoryEntry &entry : entries )
83 {
84 logOut << QStringLiteral( "ALGORITHM%1%2%3%4\n" ).arg( logSeparator,
85 entry.timestamp.toString( "yyyy-MM-dd HH:mm:ss" ),
86 logSeparator,
87 entry.entry.value( QStringLiteral( "python_command" ) ).toString() );
88 }
89 }
90}
91
92
93//
94// QgsProcessingHistoryDialog
95//
96
98 : QDialog( parent )
99{
100 setObjectName( QStringLiteral( "QgsProcessingHistoryDialog" ) );
102
103 setWindowTitle( tr( "Processing History" ) );
104
105 QVBoxLayout *vl = new QVBoxLayout();
106 mWidget = new QgsProcessingHistoryWidget();
107 vl->addWidget( mWidget, 1 );
108
109 mButtonBox = new QDialogButtonBox( QDialogButtonBox::Close | QDialogButtonBox::Help );
110
111 QPushButton *clearButton = new QPushButton( tr( "Clear" ) );
112 clearButton->setToolTip( tr( "Clear history" ) );
113 mButtonBox->addButton( clearButton, QDialogButtonBox::ActionRole );
114
115 QPushButton *saveButton = new QPushButton( tr( "Save As…" ) );
116 saveButton->setToolTip( tr( "Save history" ) );
117 mButtonBox->addButton( saveButton, QDialogButtonBox::ActionRole );
118
119 connect( clearButton, &QPushButton::clicked, mWidget, &QgsProcessingHistoryWidget::clearHistory );
120 connect( saveButton, &QPushButton::clicked, mWidget, &QgsProcessingHistoryWidget::saveLog );
121 connect( mButtonBox->button( QDialogButtonBox::Help ), &QPushButton::clicked, mWidget, &QgsProcessingHistoryWidget::openHelp );
122 connect( mButtonBox->button( QDialogButtonBox::Close ), &QPushButton::clicked, mWidget, [ = ]() { close(); } );
123
124 vl->addWidget( mButtonBox );
125
126 setLayout( vl );
127}
@ 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:78
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:209
static QgsHistoryProviderRegistry * historyProviderRegistry()
Returns the global history provider registry, used for tracking history providers.
Definition qgsgui.cpp:199
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.