Skip to content

Commit

Permalink
Add context menu entries
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 26, 2023
1 parent 4c1c6be commit 4541af6
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions src/gui/qgsdbqueryhistoryprovider.cpp
Expand Up @@ -19,12 +19,16 @@
#include "qgshistoryentry.h"
#include "qgsprovidermetadata.h"
#include "qgsproviderregistry.h"
#include "qgsapplication.h"

#include <QIcon>

class QgsDatabaseQueryValueNode;
#include <QAction>
#include <QMenu>
#include <QMimeData>
#include <QClipboard>

///@cond PRIVATE

class DatabaseQueryHistoryNode : public QgsHistoryEntryGroup
{
public:
Expand All @@ -39,9 +43,6 @@ class DatabaseQueryHistoryNode : public QgsHistoryEntryGroup
protected:

QgsHistoryEntry mEntry;
QgsDatabaseQueryValueNode *mConnectionNode = nullptr;
QgsDatabaseQueryValueNode *mRowsNode = nullptr;
QgsDatabaseQueryValueNode *mTimeNode = nullptr;
QgsDatabaseQueryHistoryProvider *mProvider = nullptr;

};
Expand Down Expand Up @@ -162,6 +163,30 @@ class DatabaseQueryRootNode : public DatabaseQueryHistoryNode
mEntry.entry.value( QStringLiteral( "query" ) ).toString() );
}

void populateContextMenu( QMenu *menu, const QgsHistoryWidgetContext & ) override
{
QAction *executeAction = new QAction(
QObject::tr( "Execute SQL Command…" ), menu );
QObject::connect( executeAction, &QAction::triggered, menu, [ = ]
{
mProvider->emitOpenSqlDialog( mEntry.entry.value( QStringLiteral( "connection" ) ).toString(),
mEntry.entry.value( QStringLiteral( "provider" ) ).toString(),
mEntry.entry.value( QStringLiteral( "query" ) ).toString() );
} );
menu->addAction( executeAction );

QAction *copyAction = new QAction(
QObject::tr( "Copy SQL Command" ), menu );
copyAction->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mActionEditCopy.svg" ) ) );
QObject::connect( copyAction, &QAction::triggered, menu, [ = ]
{
QMimeData *m = new QMimeData();
m->setText( mEntry.entry.value( QStringLiteral( "query" ) ).toString() );
QApplication::clipboard()->setMimeData( m );
} );
menu->addAction( copyAction );
}

private:

QString mProviderKey;
Expand Down

0 comments on commit 4541af6

Please sign in to comment.