Used slightly different approach. This tab is fully build in source code using subclasses to adjust behaviour of widgets for reuse in the other tabs. Uses custom proxy model for filtering triggers for correct table and supporting out of the box sorting by QTableView. SqlCodePreview: QPlainTextEditor which sql highlighter and in readonly mode but allows copy.
27 lines
836 B
C++
27 lines
836 B
C++
#include "SqlCodePreview.h"
|
|
#include "UserConfiguration.h"
|
|
#include "SqlSyntaxHighlighter.h"
|
|
|
|
SqlCodePreview::SqlCodePreview(QWidget *parent)
|
|
: QPlainTextEdit(parent)
|
|
{
|
|
auto&& config = UserConfiguration::instance();
|
|
setFont(config->codeFont());
|
|
setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
|
|
m_highlighter = new SqlSyntaxHighlighter(document());
|
|
}
|
|
|
|
|
|
void SqlCodePreview::setCatalog(std::shared_ptr<const PgDatabaseCatalog> catalog)
|
|
{
|
|
connect(catalog.get(), &PgDatabaseCatalog::refreshed, this, &SqlCodePreview::catalogRefresh);
|
|
catalogRefresh(catalog.get(), PgDatabaseCatalog::All);
|
|
}
|
|
|
|
|
|
void SqlCodePreview::catalogRefresh(const PgDatabaseCatalog *catalog, PgDatabaseCatalog::RefreshFlags flags)
|
|
{
|
|
if (flags & PgDatabaseCatalog::Types) {
|
|
m_highlighter->setTypes(*catalog->types());
|
|
}
|
|
}
|