18#include "moc_qgsdbqueryhistoryprovider.cpp"
39 , mProvider( provider )
48class DatabaseQueryValueNode :
public DatabaseQueryHistoryNode
52 : DatabaseQueryHistoryNode( entry, provider )
56 QVariant data(
int role = Qt::DisplayRole )
const override
78class DatabaseQueryRootNode :
public DatabaseQueryHistoryNode
82 : DatabaseQueryHistoryNode( entry, provider )
86 mProviderKey = mEntry.entry.value( QStringLiteral(
"provider" ) ).toString();
89 QVariant data(
int role = Qt::DisplayRole )
const override
95 return mEntry.entry.value( QStringLiteral(
"query" ) );
97 case Qt::DecorationRole:
99 if ( !mProviderIcon.isNull() )
100 return mProviderIcon;
104 mProviderIcon = md->icon();
106 return mProviderIcon;
117 if ( !mConnectionNode )
119 mConnectionNode =
new DatabaseQueryValueNode( mEntry, mProvider, QObject::tr(
"Connection: %1" ).arg( entry.
entry.value( QStringLiteral(
"connection" ) ).toString() ) );
120 addChild( mConnectionNode );
122 if ( entry.
entry.contains( QStringLiteral(
"rows" ) ) )
126 mRowsNode =
new DatabaseQueryValueNode( mEntry, mProvider, QObject::tr(
"Row count: %1" ).arg( entry.
entry.value( QStringLiteral(
"rows" ) ).toString() ) );
127 addChild( mRowsNode );
130 if ( entry.
entry.contains( QStringLiteral(
"time" ) ) )
134 mTimeNode =
new DatabaseQueryValueNode( mEntry, mProvider, QObject::tr(
"Execution time: %1 ms" ).arg( entry.
entry.value( QStringLiteral(
"time" ) ).toString() ) );
135 addChild( mTimeNode );
143 editor->setText( mEntry.entry.value( QStringLiteral(
"query" ) ).toString() );
144 editor->setReadOnly(
true );
145 editor->setCaretLineVisible(
false );
148 editor->setEdgeMode( QsciScintilla::EdgeNone );
149 editor->setWrapMode( QsciScintilla::WrapMode::WrapWord );
155 mProvider->emitOpenSqlDialog( mEntry.entry.value( QStringLiteral(
"connection" ) ).toString(), mEntry.entry.value( QStringLiteral(
"provider" ) ).toString(), mEntry.entry.value( QStringLiteral(
"query" ) ).toString() );
161 QAction *executeAction =
new QAction(
162 QObject::tr(
"Execute SQL Command…" ), menu
164 QObject::connect( executeAction, &QAction::triggered, menu, [=] {
165 mProvider->emitOpenSqlDialog( mEntry.entry.value( QStringLiteral(
"connection" ) ).toString(), mEntry.entry.value( QStringLiteral(
"provider" ) ).toString(), mEntry.entry.value( QStringLiteral(
"query" ) ).toString() );
167 menu->addAction( executeAction );
169 QAction *copyAction =
new QAction(
170 QObject::tr(
"Copy SQL Command" ), menu
173 QObject::connect( copyAction, &QAction::triggered, menu, [=] {
174 QMimeData *m =
new QMimeData();
175 m->setText( mEntry.entry.value( QStringLiteral(
"query" ) ).toString() );
176 QApplication::clipboard()->setMimeData( m );
178 menu->addAction( copyAction );
182 QString mProviderKey;
183 mutable QIcon mProviderIcon;
184 DatabaseQueryValueNode *mConnectionNode =
nullptr;
185 DatabaseQueryValueNode *mRowsNode =
nullptr;
186 DatabaseQueryValueNode *mTimeNode =
nullptr;
198 return QStringLiteral(
"dbquery" );
203 return new DatabaseQueryRootNode( entry,
this );
208 if ( DatabaseQueryRootNode *dbNode =
dynamic_cast<DatabaseQueryRootNode *
>( node ) )
210 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.