18#include "moc_qgsdbqueryhistoryprovider.cpp" 
   40      , mProvider( provider )
 
   49class DatabaseQueryValueNode : 
public DatabaseQueryHistoryNode
 
   53      : DatabaseQueryHistoryNode( entry, provider )
 
   57    QVariant data( 
int role = Qt::DisplayRole )
 const override 
   79class DatabaseQueryRootNode : 
public DatabaseQueryHistoryNode
 
   83      : DatabaseQueryHistoryNode( entry, provider )
 
   87      mProviderKey = mEntry.entry.value( QStringLiteral( 
"provider" ) ).toString();
 
   90    QVariant data( 
int role = Qt::DisplayRole )
 const override 
   96          return mEntry.entry.value( QStringLiteral( 
"query" ) );
 
   98        case Qt::DecorationRole:
 
  100          if ( !mProviderIcon.isNull() )
 
  101            return mProviderIcon;
 
  105            mProviderIcon = md->icon();
 
  107          return mProviderIcon;
 
  118      if ( !mConnectionNode )
 
  120        mConnectionNode = 
new DatabaseQueryValueNode( mEntry, mProvider, QObject::tr( 
"Connection: %1" ).arg( entry.
entry.value( QStringLiteral( 
"connection" ) ).toString() ) );
 
  121        addChild( mConnectionNode );
 
  123      if ( entry.
entry.contains( QStringLiteral( 
"rows" ) ) )
 
  127          mRowsNode = 
new DatabaseQueryValueNode( mEntry, mProvider, QObject::tr( 
"Row count: %1" ).arg( entry.
entry.value( QStringLiteral( 
"rows" ) ).toString() ) );
 
  128          addChild( mRowsNode );
 
  131      if ( entry.
entry.contains( QStringLiteral( 
"time" ) ) )
 
  135          mTimeNode = 
new DatabaseQueryValueNode( mEntry, mProvider, QObject::tr( 
"Execution time: %1 ms" ).arg( entry.
entry.value( QStringLiteral( 
"time" ) ).toString() ) );
 
  136          addChild( mTimeNode );
 
  144      editor->
setText( mEntry.entry.value( QStringLiteral( 
"query" ) ).toString() );
 
  145      editor->setReadOnly( 
true );
 
  146      editor->setCaretLineVisible( 
false );
 
  149      editor->setEdgeMode( QsciScintilla::EdgeNone );
 
  150      editor->setWrapMode( QsciScintilla::WrapMode::WrapWord );
 
  158        queryHistoryWidget->emitSqlTriggered( mEntry.entry.value( QStringLiteral( 
"connection" ) ).toString(), mEntry.entry.value( QStringLiteral( 
"provider" ) ).toString(), mEntry.entry.value( QStringLiteral( 
"query" ) ).toString() );
 
  167        QAction *loadAction = 
new QAction(
 
  168          QObject::tr( 
"Load SQL Command…" ), menu
 
  170        QObject::connect( loadAction, &QAction::triggered, menu, [
this, queryHistoryWidget] {
 
  171          queryHistoryWidget->emitSqlTriggered( mEntry.entry.value( QStringLiteral( 
"connection" ) ).toString(), mEntry.entry.value( QStringLiteral( 
"provider" ) ).toString(), mEntry.entry.value( QStringLiteral( 
"query" ) ).toString() );
 
  173        menu->addAction( loadAction );
 
  176      QAction *copyAction = 
new QAction(
 
  177        QObject::tr( 
"Copy SQL Command" ), menu
 
  180      QObject::connect( copyAction, &QAction::triggered, menu, [
this] {
 
  181        QMimeData *m = 
new QMimeData();
 
  182        m->setText( mEntry.entry.value( QStringLiteral( 
"query" ) ).toString() );
 
  183        QApplication::clipboard()->setMimeData( m );
 
  185      menu->addAction( copyAction );
 
  189    QString mProviderKey;
 
  190    mutable QIcon mProviderIcon;
 
  191    DatabaseQueryValueNode *mConnectionNode = 
nullptr;
 
  192    DatabaseQueryValueNode *mRowsNode = 
nullptr;
 
  193    DatabaseQueryValueNode *mTimeNode = 
nullptr;
 
  205  return QStringLiteral( 
"dbquery" );
 
 
  210  return new DatabaseQueryRootNode( entry, 
this );
 
 
  215  if ( DatabaseQueryRootNode *dbNode = 
dynamic_cast<DatabaseQueryRootNode *
>( node ) )
 
  217    dbNode->setEntry( entry );
 
 
  226  : 
QgsHistoryWidget( QStringLiteral( 
"dbquery" ), backends, registry, context, parent )
 
 
QFlags< HistoryProviderBackend > HistoryProviderBackends
 
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
 
A SQL editor based on QScintilla2.
 
void setText(const QString &text) override
 
void setFoldingVisible(bool folding)
Set whether the folding controls are visible in the editor.
 
void setLineNumbersVisible(bool visible)
Sets whether line numbers should be visible in the editor.
 
History provider for operations database queries.
 
void updateNodeForEntry(QgsHistoryEntryNode *node, const QgsHistoryEntry &entry, const QgsHistoryWidgetContext &context) override
Updates an existing history node for the given entry.
 
QgsDatabaseQueryHistoryProvider()
 
QString id() const override
Returns the provider's unique id, which is used to associate existing history entries with the provid...
 
QgsHistoryEntryNode * createNodeForEntry(const QgsHistoryEntry &entry, const QgsHistoryWidgetContext &context) override
Creates a new history node for the given entry.
 
Custom QgsHistoryWidget for use with the database query provider.
 
QgsDatabaseQueryHistoryWidget(Qgis::HistoryProviderBackends backends=Qgis::HistoryProviderBackend::LocalProfile, QgsHistoryProviderRegistry *registry=nullptr, const QgsHistoryWidgetContext &context=QgsHistoryWidgetContext(), QWidget *parent=nullptr)
Constructor for QgsDatabaseQueryHistoryWidget, with the specified parent widget.
 
void sqlTriggered(const QString &connectionUri, const QString &provider, const QString &sql)
Emitted when the user has triggered a previously executed SQL statement in the widget.
 
void emitSqlTriggered(const QString &connectionUri, const QString &provider, const QString &sql)
Causes the widget to emit the sqlTriggered() signal.
 
Base class for history entry "group" nodes, which contain children of their own.
 
Base class for nodes representing a QgsHistoryEntry.
 
Encapsulates a history entry.
 
QVariantMap entry
Entry details.
 
A registry for objects which track user history (i.e.
 
Contains settings which reflect the context in which a history widget is shown, e....
 
QgsHistoryWidget * historyWidget() const
Returns the parent history widget.
 
A widget showing entries from a QgsHistoryProviderRegistry.
 
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.