18#include "moc_qgsdbqueryhistoryprovider.cpp"
40 , mProvider( provider )
51class DatabaseQueryValueNode :
public DatabaseQueryHistoryNode
56 : DatabaseQueryHistoryNode( entry, provider )
60 QVariant data(
int role = Qt::DisplayRole )
const override
84class DatabaseQueryRootNode :
public DatabaseQueryHistoryNode
89 : DatabaseQueryHistoryNode( entry, provider )
93 mProviderKey = mEntry.entry.value( QStringLiteral(
"provider" ) ).toString();
96 QVariant data(
int role = Qt::DisplayRole )
const override
100 case Qt::DisplayRole:
101 case Qt::ToolTipRole:
102 return mEntry.entry.value( QStringLiteral(
"query" ) );
104 case Qt::DecorationRole:
106 if ( !mProviderIcon.isNull() )
107 return mProviderIcon;
111 mProviderIcon = md->icon();
113 return mProviderIcon;
124 if ( !mConnectionNode )
126 mConnectionNode =
new DatabaseQueryValueNode( mEntry, mProvider, QObject::tr(
"Connection: %1" ).arg( entry.
entry.value( QStringLiteral(
"connection" ) ).toString() ) );
127 addChild( mConnectionNode );
129 if ( entry.
entry.contains( QStringLiteral(
"rows" ) ) )
133 mRowsNode =
new DatabaseQueryValueNode( mEntry, mProvider, QObject::tr(
"Row count: %1" ).arg( entry.
entry.value( QStringLiteral(
"rows" ) ).toString() ) );
134 addChild( mRowsNode );
137 if ( entry.
entry.contains( QStringLiteral(
"time" ) ) )
141 mTimeNode =
new DatabaseQueryValueNode( mEntry, mProvider, QObject::tr(
"Execution time: %1 ms" ).arg( entry.
entry.value( QStringLiteral(
"time" ) ).toString() ) );
142 addChild( mTimeNode );
150 editor->setText( mEntry.entry.value( QStringLiteral(
"query" ) ).toString() );
151 editor->setReadOnly(
true );
152 editor->setCaretLineVisible(
false );
155 editor->setEdgeMode( QsciScintilla::EdgeNone );
156 editor->setWrapMode( QsciScintilla::WrapMode::WrapWord );
162 mProvider->emitOpenSqlDialog( mEntry.entry.value( QStringLiteral(
"connection" ) ).toString(),
163 mEntry.entry.value( QStringLiteral(
"provider" ) ).toString(),
164 mEntry.entry.value( QStringLiteral(
"query" ) ).toString() );
170 QAction *executeAction =
new QAction(
171 QObject::tr(
"Execute SQL Command…" ), menu );
172 QObject::connect( executeAction, &QAction::triggered, menu, [ = ]
174 mProvider->emitOpenSqlDialog( mEntry.entry.value( QStringLiteral(
"connection" ) ).toString(),
175 mEntry.entry.value( QStringLiteral(
"provider" ) ).toString(),
176 mEntry.entry.value( QStringLiteral(
"query" ) ).toString() );
178 menu->addAction( executeAction );
180 QAction *copyAction =
new QAction(
181 QObject::tr(
"Copy SQL Command" ), menu );
183 QObject::connect( copyAction, &QAction::triggered, menu, [ = ]
185 QMimeData *m =
new QMimeData();
186 m->setText( mEntry.entry.value( QStringLiteral(
"query" ) ).toString() );
187 QApplication::clipboard()->setMimeData( m );
189 menu->addAction( copyAction );
194 QString mProviderKey;
195 mutable QIcon mProviderIcon;
196 DatabaseQueryValueNode *mConnectionNode =
nullptr;
197 DatabaseQueryValueNode *mRowsNode =
nullptr;
198 DatabaseQueryValueNode *mTimeNode =
nullptr;
211 return QStringLiteral(
"dbquery" );
216 return new DatabaseQueryRootNode( entry,
this );
221 if ( DatabaseQueryRootNode *dbNode =
dynamic_cast< DatabaseQueryRootNode *
>( node ) )
223 dbNode->setEntry( entry );
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 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 emitOpenSqlDialog(const QString &connectionUri, const QString &provider, const QString &sql)
Causes the provider to emit the openSqlDialog() signal.
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...
void openSqlDialog(const QString &connectionUri, const QString &provider, const QString &sql)
Emitted when the provider wants to trigger a SQL execution dialog.
QgsHistoryEntryNode * createNodeForEntry(const QgsHistoryEntry &entry, const QgsHistoryWidgetContext &context) override
Creates a new history node for the given entry.
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.
Contains settings which reflect the context in which a history widget is shown, e....
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.