Skip to content

Commit

Permalink
Port history dialog to c++
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 24, 2023
1 parent ea58fd7 commit 45d8918
Show file tree
Hide file tree
Showing 5 changed files with 297 additions and 0 deletions.
@@ -0,0 +1,80 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/processing/qgsprocessinghistorywidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsProcessingHistoryWidget : QgsPanelWidget
{
%Docstring(signature="appended")
A widget for showing Processing algorithm exection history.

.. versionadded:: 3.32
%End

%TypeHeaderCode
#include "qgsprocessinghistorywidget.h"
%End
public:

QgsProcessingHistoryWidget( QWidget *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsProcessingHistoryWidget, with the specified ``parent`` widget.
%End

public slots:

void clearHistory();
%Docstring
Clears the Processing history (after user confirmation).
%End

void openHelp();
%Docstring
Opens helps for the widget.
%End

void saveLog();
%Docstring
Interactively allows users to save the history log.
%End

};

class QgsProcessingHistoryDialog : QDialog
{
%Docstring(signature="appended")
A dialog for showing Processing algorithm exection history.

.. warning::

This is not part of stable API -- it is exposed to Python for internal use by Processing only!

.. versionadded:: 3.32
%End

%TypeHeaderCode
#include "qgsprocessinghistorywidget.h"
%End
public:

QgsProcessingHistoryDialog( QWidget *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsProcessingHistoryDialog.
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/processing/qgsprocessinghistorywidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
1 change: 1 addition & 0 deletions python/gui/gui_auto.sip
Expand Up @@ -405,6 +405,7 @@
%Include auto_generated/processing/qgsprocessinggui.sip
%Include auto_generated/processing/qgsprocessingguiregistry.sip
%Include auto_generated/processing/qgsprocessinghistoryprovider.sip
%Include auto_generated/processing/qgsprocessinghistorywidget.sip
%Include auto_generated/processing/qgsprocessingmaplayercombobox.sip
%Include auto_generated/processing/qgsprocessingmodelerparameterwidget.sip
%Include auto_generated/processing/qgsprocessingmultipleselectiondialog.sip
Expand Down
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -373,6 +373,7 @@ set(QGIS_GUI_SRCS
processing/qgsprocessingguiregistry.cpp
processing/qgsprocessinghelpeditorwidget.cpp
processing/qgsprocessinghistoryprovider.cpp
processing/qgsprocessinghistorywidget.cpp
processing/qgsprocessingmaplayercombobox.cpp
processing/qgsprocessingmatrixmodelerwidget.cpp
processing/qgsprocessingmatrixparameterdialog.cpp
Expand Down Expand Up @@ -1286,6 +1287,7 @@ set(QGIS_GUI_HDRS
processing/qgsprocessingguiregistry.h
processing/qgsprocessinghelpeditorwidget.h
processing/qgsprocessinghistoryprovider.h
processing/qgsprocessinghistorywidget.h
processing/qgsprocessingmaplayercombobox.h
processing/qgsprocessingmatrixmodelerwidget.h
processing/qgsprocessingmatrixparameterdialog.h
Expand Down
124 changes: 124 additions & 0 deletions src/gui/processing/qgsprocessinghistorywidget.cpp
@@ -0,0 +1,124 @@
/***************************************************************************
qgsprocessinghistorywidget.cpp
------------------------
Date : April 2023
Copyright : (C) 2023 Nyall Dawson
Email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsprocessinghistorywidget.h"
#include "qgshistorywidget.h"
#include "qgsgui.h"
#include "qgshistoryproviderregistry.h"
#include "qgshistoryprovider.h"
#include "qgshelp.h"
#include "qgsfileutils.h"
#include "qgshistoryentry.h"

#include <QVBoxLayout>
#include <QMessageBox>
#include <QFileDialog>
#include <QTextStream>
#include <QDialogButtonBox>
#include <QPushButton>

QgsProcessingHistoryWidget::QgsProcessingHistoryWidget( QWidget *parent )
: QgsPanelWidget( parent )
{
mHistoryWidget = new QgsHistoryWidget( QStringLiteral( "processing" ) );
QVBoxLayout *vl = new QVBoxLayout();
vl->setContentsMargins( 0, 0, 0, 0 );
vl->addWidget( mHistoryWidget );

}

void QgsProcessingHistoryWidget::clearHistory()
{
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 )
{
QgsGui::historyProviderRegistry()->clearHistory( Qgis::HistoryProviderBackend::LocalProfile, QStringLiteral( "providerId" ) );
}
}

void QgsProcessingHistoryWidget::openHelp()
{
QgsHelp::openHelp( QStringLiteral( "processing/history.html" ) );
}

void QgsProcessingHistoryWidget::saveLog()
{
QString fileName = QFileDialog::getSaveFileName( this,
tr( "Save File" ),
QDir::homePath(),
tr( "Log files (*.log *.LOG)" ) );

if ( fileName.isEmpty() )
return;

fileName = QgsFileUtils::ensureFileNameHasExtension( fileName, { QStringLiteral( "log" ) } );

const QList< QgsHistoryEntry > entries = QgsGui::historyProviderRegistry()->queryEntries( QDateTime(), QDateTime(), QStringLiteral( "processing" ) );

const QString logSeparator = QStringLiteral( "|~|" );
QFile logFile( fileName );
if ( logFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
{
QTextStream logOut( &logFile );
for ( const QgsHistoryEntry &entry : entries )
{
logOut << QStringLiteral( "ALGORITHM{}{}{}{}\n" ).arg( logSeparator,
entry.timestamp.toString( "YYYY-mm-dd HH:MM:SS" ),
logSeparator,
entry.entry.value( QStringLiteral( "python_command" ) ).toString() );
}
}
}


//
// QgsProcessingHistoryDialog
//

QgsProcessingHistoryDialog::QgsProcessingHistoryDialog( QWidget *parent )
: QDialog( parent )
{
QgsGui::instance()->enableAutoGeometryRestore( this );

QVBoxLayout *vl = new QVBoxLayout();
mWidget = new QgsProcessingHistoryWidget();
vl->addWidget( mWidget, 1 );

mButtonBox = new QDialogButtonBox();

QPushButton *clearButton = new QPushButton( tr( "Clear" ) );
clearButton->setToolTip( tr( "Clear history" ) );
mButtonBox->addButton( clearButton, QDialogButtonBox::ActionRole );

QPushButton *helpButton = new QPushButton( tr( "Help" ) );
helpButton->setToolTip( tr( "Show help" ) );
mButtonBox->addButton( helpButton, QDialogButtonBox::HelpRole );

QPushButton *saveButton = new QPushButton( tr( "Save As…" ) );
saveButton->setToolTip( tr( "Save history" ) );
mButtonBox->addButton( saveButton, QDialogButtonBox::ActionRole );

connect( clearButton, &QPushButton::clicked, mWidget, &QgsProcessingHistoryWidget::clearHistory );
connect( saveButton, &QPushButton::clicked, mWidget, &QgsProcessingHistoryWidget::saveLog );
connect( helpButton, &QPushButton::clicked, mWidget, &QgsProcessingHistoryWidget::openHelp );

vl->addWidget( mButtonBox );

setLayout( vl );
}
90 changes: 90 additions & 0 deletions src/gui/processing/qgsprocessinghistorywidget.h
@@ -0,0 +1,90 @@
/***************************************************************************
qgsprocessinghistorywidget.h
------------------------
Date : April 2023
Copyright : (C) 2023 Nyall Dawson
Email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSPROCESSINGHISTORYWIDGET_H
#define QGSPROCESSINGHISTORYWIDGET_H

#include "qgis.h"
#include "qgis_gui.h"
#include "qgspanelwidget.h"

#include <QDialog>

class QgsHistoryWidget;
class QDialogButtonBox;

/**
* \ingroup gui
* \brief A widget for showing Processing algorithm exection history.
* \since QGIS 3.32
*/
class GUI_EXPORT QgsProcessingHistoryWidget : public QgsPanelWidget
{
Q_OBJECT
public:

/**
* Constructor for QgsProcessingHistoryWidget, with the specified \a parent widget.
*/
QgsProcessingHistoryWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );

public slots:

/**
* Clears the Processing history (after user confirmation).
*/
void clearHistory();

/**
* Opens helps for the widget.
*/
void openHelp();

/**
* Interactively allows users to save the history log.
*/
void saveLog();

private:

QgsHistoryWidget *mHistoryWidget = nullptr;

};

/**
* \ingroup gui
* \brief A dialog for showing Processing algorithm exection history.
*
* \warning This is not part of stable API -- it is exposed to Python for internal use by Processing only!
*
* \since QGIS 3.32
*/
class GUI_EXPORT QgsProcessingHistoryDialog : public QDialog
{
Q_OBJECT
public:

/**
* Constructor for QgsProcessingHistoryDialog.
*/
QgsProcessingHistoryDialog( QWidget *parent SIP_TRANSFERTHIS = nullptr );

private:

QgsProcessingHistoryWidget *mWidget = nullptr;
QDialogButtonBox *mButtonBox = nullptr;
};

#endif // QGSPROCESSINGHISTORYWIDGET_H

0 comments on commit 45d8918

Please sign in to comment.