1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
#ifndef VIEWWINDOW_H
#define VIEWWINDOW_H
#include "mdichild.h"
#include "common/extactioncontainer.h"
#include "db/db.h"
#include "parser/ast/sqlitecreateview.h"
#include "guiSQLiteStudio_global.h"
#include <QWidget>
namespace Ui {
class ViewWindow;
}
class SqliteSyntaxHighlighter;
class WidgetCover;
class QPushButton;
class QProgressBar;
class ChainExecutor;
class ViewModifier;
class SqlViewModel;
CFG_KEY_LIST(ViewWindow, QObject::tr("A view window"),
CFG_KEY_ENTRY(COMMIT_QUERY, QKeySequence::Save, QObject::tr("Commit the view's query"))
CFG_KEY_ENTRY(ROLLBACK_QUERY, QKeySequence::Cancel, QObject::tr("Rollback pending changes in the view's query"))
CFG_KEY_ENTRY(REFRESH_TRIGGERS, Qt::Key_F5, QObject::tr("Refresh view trigger list"))
CFG_KEY_ENTRY(EXECUTE_QUERY, Qt::Key_F9, QObject::tr("Execute the view's query"))
CFG_KEY_ENTRY(ADD_TRIGGER, Qt::Key_Insert, QObject::tr("Add new trigger"))
CFG_KEY_ENTRY(EDIT_TRIGGER, Qt::Key_Return, QObject::tr("Edit selected trigger"))
CFG_KEY_ENTRY(DEL_TRIGGER, Qt::Key_Delete, QObject::tr("Delete selected trigger"))
CFG_KEY_ENTRY(NEXT_TAB, Qt::ALT + Qt::Key_Right, QObject::tr("Go to next tab"))
CFG_KEY_ENTRY(PREV_TAB, Qt::ALT + Qt::Key_Left, QObject::tr("Go to previous tab"))
)
class GUI_API_EXPORT ViewWindow : public MdiChild
{
Q_OBJECT
public:
enum Action
{
// Structure tab
REFRESH_QUERY,
COMMIT_QUERY,
ROLLBACK_QUERY,
ADD_COLUMN,
EDIT_COLUMN,
DEL_COLUMN,
MOVE_COLUMN_UP,
MOVE_COLUMN_DOWN,
GENERATE_OUTPUT_COLUMNS,
// Triggers tab
REFRESH_TRIGGERS,
ADD_TRIGGER,
EDIT_TRIGGER,
DEL_TRIGGER,
// All tabs
NEXT_TAB,
PREV_TAB,
EXECUTE_QUERY
};
Q_ENUM(Action)
enum ToolBar
{
TOOLBAR_QUERY,
TOOLBAR_TRIGGERS
};
explicit ViewWindow(QWidget *parent = 0);
ViewWindow(Db* db, QWidget *parent = 0);
ViewWindow(const ViewWindow& win);
ViewWindow(QWidget *parent, Db* db, const QString& database, const QString& view);
~ViewWindow();
Db* getDb() const;
QString getDatabase() const;
QString getView() const;
void setSelect(const QString& selectSql);
bool isUncommitted() const;
QString getQuitUncommittedConfirmMessage() const;
Db* getAssociatedDb() const;
bool isWindowClosingBlocked() const;
static void staticInit();
static void insertAction(ExtActionPrototype* action, ToolBar toolbar = TOOLBAR_QUERY);
static void insertActionBefore(ExtActionPrototype* action, Action beforeAction, ToolBar toolbar = TOOLBAR_QUERY);
static void insertActionAfter(ExtActionPrototype* action, Action afterAction, ToolBar toolbar = TOOLBAR_QUERY);
static void removeAction(ExtActionPrototype* action, ToolBar toolbar = TOOLBAR_QUERY);
protected:
void changeEvent(QEvent *e);
QVariant saveSession();
bool restoreSession(const QVariant& sessionValue);
Icon* getIconNameForMdiWindow();
QString getTitleForMdiWindow();
void createActions();
void setupDefShortcuts();
bool restoreSessionNextTime();
QToolBar* getToolBar(int toolbar) const;
private:
void init();
void updateAfterInit();
void createDbCombo();
void newView();
void initView();
void setupCoverWidget();
void createQueryTabActions();
void createTriggersTabActions();
void parseDdl();
void updateDdlTab();
bool isModified() const;
bool validate(bool skipWarnings = false);
void executeStructureChanges();
QString getCurrentTrigger() const;
void applyInitialTab();
QString getCurrentDdl() const;
QStringList indexedColumnsToNamesOnly(const QList<SqliteIndexedColumn*>& columns) const;
QStringList collectColumnNames() const;
void columnsFromViewToList();
int getDataTabIdx() const;
int getQueryTabIdx() const;
int getDdlTabIdx() const;
void switchToDataAndReload();
Db* db = nullptr;
QString database;
QString view;
bool existingView = true;
bool dataLoaded = false;
int newViewWindowNum = 1;
bool modified = false;
SqliteCreateViewPtr originalCreateView;
SqliteCreateViewPtr createView;
SqlViewModel* dataModel = nullptr;
QString originalQuery;
WidgetCover* widgetCover = nullptr;
ChainExecutor* structureExecutor = nullptr;
ViewModifier* viewModifier = nullptr;
Ui::ViewWindow *ui = nullptr;
bool modifyingThisView = false;
QAction* outputColumnsCheck = nullptr;
QAction* outputColumnsSeparator = nullptr;
bool tabsMoving = false;
bool loadDataAfterNextCommit = false;
private slots:
void refreshView();
void executeQuery();
void commitView(bool skipWarnings = false, bool loadDataAfterNextCommit = false);
void rollbackView();
void addTrigger();
void editTrigger();
void deleteTrigger();
void executionSuccessful();
void executionFailed(const QString& errorMessage);
void tabChanged(int tabIdx);
void updateQueryToolbarStatus();
void changesSuccessfullyCommitted();
void changesFailedToCommit(int errorCode, const QString& errorText);
void updateTriggersState();
void nextTab();
void prevTab();
void dbClosedFinalCleanup();
void checkIfViewDeleted(const QString& database, const QString& object, DbObjectType type);
void updateOutputColumnsVisibility();
void addColumn();
void editColumn();
void delColumn();
void moveColumnUp();
void moveColumnDown();
void updateColumnButtons();
void generateOutputColumns();
void updateTabsOrder();
void triggerViewDoubleClicked(const QModelIndex& idx);
void updateFont();
void dbChanged();
void handleObjectModified(Db* db, const QString& database, const QString& object);
public slots:
void refreshTriggers();
};
#endif // VIEWWINDOW_H
|