aboutsummaryrefslogtreecommitdiffstats
path: root/Plugins/SqlFormatterSimple
diff options
context:
space:
mode:
Diffstat (limited to 'Plugins/SqlFormatterSimple')
-rw-r--r--Plugins/SqlFormatterSimple/SqlFormatterSimple.pro28
-rw-r--r--Plugins/SqlFormatterSimple/SqlFormatterSimple.ui51
-rw-r--r--Plugins/SqlFormatterSimple/sqlformattersimple.json7
-rw-r--r--Plugins/SqlFormatterSimple/sqlformattersimple.qrc5
-rw-r--r--Plugins/SqlFormatterSimple/sqlformattersimple_global.h12
-rw-r--r--Plugins/SqlFormatterSimple/sqlformattersimpleplugin.cpp50
-rw-r--r--Plugins/SqlFormatterSimple/sqlformattersimpleplugin.h38
7 files changed, 191 insertions, 0 deletions
diff --git a/Plugins/SqlFormatterSimple/SqlFormatterSimple.pro b/Plugins/SqlFormatterSimple/SqlFormatterSimple.pro
new file mode 100644
index 0000000..2c60801
--- /dev/null
+++ b/Plugins/SqlFormatterSimple/SqlFormatterSimple.pro
@@ -0,0 +1,28 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2013-12-02T16:14:12
+#
+#-------------------------------------------------
+
+include($$PWD/../../SQLiteStudio3/plugins.pri)
+
+QT -= gui
+
+TARGET = SqlFormatterSimple
+TEMPLATE = lib
+
+DEFINES += SQLFORMATTERSIMPLE_LIBRARY
+
+SOURCES += sqlformattersimpleplugin.cpp
+
+HEADERS += sqlformattersimpleplugin.h\
+ sqlformattersimple_global.h
+
+FORMS += \
+ SqlFormatterSimple.ui
+
+OTHER_FILES += \
+ sqlformattersimple.json
+
+RESOURCES += \
+ sqlformattersimple.qrc
diff --git a/Plugins/SqlFormatterSimple/SqlFormatterSimple.ui b/Plugins/SqlFormatterSimple/SqlFormatterSimple.ui
new file mode 100644
index 0000000..7e81ee0
--- /dev/null
+++ b/Plugins/SqlFormatterSimple/SqlFormatterSimple.ui
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>SqlFormatterSimplePlugin</class>
+ <widget class="QWidget" name="SqlFormatterSimplePlugin">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>354</width>
+ <height>290</height>
+ </rect>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QCheckBox" name="upperKeywordsCheck">
+ <property name="text">
+ <string>Upper case keywords</string>
+ </property>
+ <property name="cfg" stdset="0">
+ <string>SqlFormatterSimple.UpperCaseKeywords</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="tripLongSpacesCheck">
+ <property name="text">
+ <string>Reduce multiple whitespaces to single whitespace</string>
+ </property>
+ <property name="cfg" stdset="0">
+ <string>SqlFormatterSimple.TrimLongSpaces</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/Plugins/SqlFormatterSimple/sqlformattersimple.json b/Plugins/SqlFormatterSimple/sqlformattersimple.json
new file mode 100644
index 0000000..ff51f13
--- /dev/null
+++ b/Plugins/SqlFormatterSimple/sqlformattersimple.json
@@ -0,0 +1,7 @@
+{
+ "type": "CodeFormatterPlugin",
+ "title": "SQL Simple",
+ "description": "Basic formatter with very little options.",
+ "version": 10000,
+ "author": "SalSoft"
+}
diff --git a/Plugins/SqlFormatterSimple/sqlformattersimple.qrc b/Plugins/SqlFormatterSimple/sqlformattersimple.qrc
new file mode 100644
index 0000000..febfbd2
--- /dev/null
+++ b/Plugins/SqlFormatterSimple/sqlformattersimple.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/forms">
+ <file>SqlFormatterSimple.ui</file>
+ </qresource>
+</RCC>
diff --git a/Plugins/SqlFormatterSimple/sqlformattersimple_global.h b/Plugins/SqlFormatterSimple/sqlformattersimple_global.h
new file mode 100644
index 0000000..926a1b0
--- /dev/null
+++ b/Plugins/SqlFormatterSimple/sqlformattersimple_global.h
@@ -0,0 +1,12 @@
+#ifndef SQLFORMATTERSIMPLE_GLOBAL_H
+#define SQLFORMATTERSIMPLE_GLOBAL_H
+
+#include <QtCore/qglobal.h>
+
+#if defined(SQLFORMATTERSIMPLE_LIBRARY)
+# define SQLFORMATTERSIMPLESHARED_EXPORT Q_DECL_EXPORT
+#else
+# define SQLFORMATTERSIMPLESHARED_EXPORT Q_DECL_IMPORT
+#endif
+
+#endif // SQLFORMATTERSIMPLE_GLOBAL_H
diff --git a/Plugins/SqlFormatterSimple/sqlformattersimpleplugin.cpp b/Plugins/SqlFormatterSimple/sqlformattersimpleplugin.cpp
new file mode 100644
index 0000000..0cb60c5
--- /dev/null
+++ b/Plugins/SqlFormatterSimple/sqlformattersimpleplugin.cpp
@@ -0,0 +1,50 @@
+#include "sqlformattersimpleplugin.h"
+
+SqlFormatterSimplePlugin::SqlFormatterSimplePlugin()
+{
+}
+
+QString SqlFormatterSimplePlugin::format(SqliteQueryPtr query)
+{
+ TokenList tokens = query->tokens;
+ foreach (TokenPtr token, tokens)
+ {
+ if (token->type == Token::KEYWORD && cfg.SqlFormatterSimple.UpperCaseKeywords.get())
+ token->value = token->value.toUpper();
+
+ if (token->type == Token::SPACE && cfg.SqlFormatterSimple.TrimLongSpaces.get() &&
+ token->value.length() > 1)
+ token->value = " ";
+ }
+
+ return tokens.detokenize();
+}
+
+bool SqlFormatterSimplePlugin::init()
+{
+ Q_INIT_RESOURCE(sqlformattersimple);
+ return GenericPlugin::init();
+}
+
+void SqlFormatterSimplePlugin::deinit()
+{
+ Q_CLEANUP_RESOURCE(sqlformattersimple);
+}
+
+QString SqlFormatterSimplePlugin::getConfigUiForm() const
+{
+ return "SqlFormatterSimplePlugin";
+}
+
+CfgMain* SqlFormatterSimplePlugin::getMainUiConfig()
+{
+ return &cfg;
+}
+
+void SqlFormatterSimplePlugin::configDialogOpen()
+{
+}
+
+void SqlFormatterSimplePlugin::configDialogClosed()
+{
+}
diff --git a/Plugins/SqlFormatterSimple/sqlformattersimpleplugin.h b/Plugins/SqlFormatterSimple/sqlformattersimpleplugin.h
new file mode 100644
index 0000000..dde25c8
--- /dev/null
+++ b/Plugins/SqlFormatterSimple/sqlformattersimpleplugin.h
@@ -0,0 +1,38 @@
+#ifndef SQLFORMATTERSIMPLEPLUGIN_H
+#define SQLFORMATTERSIMPLEPLUGIN_H
+
+#include "sqlformattersimple_global.h"
+#include "plugins/sqlformatterplugin.h"
+#include "config_builder.h"
+#include "plugins/genericplugin.h"
+#include "plugins/uiconfiguredplugin.h"
+#include <QObject>
+
+CFG_CATEGORIES(SqlFormatterSimpleConfig,
+ CFG_CATEGORY(SqlFormatterSimple,
+ CFG_ENTRY(bool, UpperCaseKeywords, true)
+ CFG_ENTRY(bool, TrimLongSpaces, true)
+ )
+)
+
+class SQLFORMATTERSIMPLESHARED_EXPORT SqlFormatterSimplePlugin : public GenericPlugin, public SqlFormatterPlugin, public UiConfiguredPlugin
+{
+ Q_OBJECT
+ SQLITESTUDIO_PLUGIN("sqlformattersimple.json")
+
+ public:
+ SqlFormatterSimplePlugin();
+
+ QString format(SqliteQueryPtr query);
+ bool init();
+ void deinit();
+ QString getConfigUiForm() const;
+ CfgMain* getMainUiConfig();
+ void configDialogOpen();
+ void configDialogClosed();
+
+ private:
+ CFG_LOCAL_PERSISTABLE(SqlFormatterSimpleConfig, cfg)
+};
+
+#endif // SQLFORMATTERSIMPLEPLUGIN_H