Project reorganization

This commit is contained in:
eelke 2022-04-10 14:26:31 +02:00
parent d0439c2d70
commit 2ad5fa5e4e
18 changed files with 31 additions and 37 deletions

View file

@ -0,0 +1,28 @@
#include "SqlCodePreview.h"
#include "UserConfiguration.h"
#include "util/SqlSyntaxHighlighter.h"
SqlCodePreview::SqlCodePreview(QWidget *parent)
: QPlainTextEdit(parent)
{
auto&& config = UserConfiguration::instance();
setFont(config->codeFont());
setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
setWordWrapMode(QTextOption::NoWrap);
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());
}
}

View file

@ -0,0 +1,30 @@
#ifndef SQLCODEPREVIEW_H
#define SQLCODEPREVIEW_H
#include "catalog/PgDatabaseCatalog.h"
#include <QPlainTextEdit>
#include <memory>
class SqlSyntaxHighlighter;
class PgDatabaseCatalog;
class SqlCodePreview : public QPlainTextEdit {
Q_OBJECT
public:
SqlCodePreview(QWidget *parent = nullptr);
/** Sets the database catalog that the syntax highlighter is to use.
*/
void setCatalog(std::shared_ptr<const PgDatabaseCatalog> catalog);
SqlSyntaxHighlighter *highlighter() { return m_highlighter; }
private:
SqlSyntaxHighlighter *m_highlighter = nullptr;
std::shared_ptr<const PgDatabaseCatalog> m_catalog;
private slots:
void catalogRefresh(const PgDatabaseCatalog *catalog, PgDatabaseCatalog::RefreshFlags flags);
};
#endif // SQLCODEPREVIEW_H