diff options
Diffstat (limited to 'SQLiteStudio3/guiSQLiteStudio/windows/viewwindow.cpp')
| -rw-r--r-- | SQLiteStudio3/guiSQLiteStudio/windows/viewwindow.cpp | 83 |
1 files changed, 69 insertions, 14 deletions
diff --git a/SQLiteStudio3/guiSQLiteStudio/windows/viewwindow.cpp b/SQLiteStudio3/guiSQLiteStudio/windows/viewwindow.cpp index 2181934..44025e5 100644 --- a/SQLiteStudio3/guiSQLiteStudio/windows/viewwindow.cpp +++ b/SQLiteStudio3/guiSQLiteStudio/windows/viewwindow.cpp @@ -6,7 +6,6 @@ #include "services/dbmanager.h" #include "mainwindow.h" #include "mdiarea.h" -#include "sqlitesyntaxhighlighter.h" #include "datagrid/sqlquerymodel.h" #include "common/utils_sql.h" #include "viewmodifier.h" @@ -180,10 +179,13 @@ void ViewWindow::setupDefShortcuts() { // Widget context setShortcutContext({ + COMMIT_QUERY, + ROLLBACK_QUERY, REFRESH_TRIGGERS, ADD_TRIGGER, EDIT_TRIGGER, DEL_TRIGGER, + EXECUTE_QUERY }, Qt::WidgetWithChildrenShortcut); @@ -223,6 +225,7 @@ void ViewWindow::init() ui->queryEdit->setVirtualSqlExpression("CREATE VIEW name AS %1"); ui->queryEdit->setDb(db); + ui->queryEdit->setOpenSaveActionsEnabled(false); connect(dataModel, SIGNAL(executionSuccessful()), this, SLOT(executionSuccessful())); connect(dataModel, SIGNAL(executionFailed(QString)), this, SLOT(executionFailed(QString))); @@ -233,11 +236,12 @@ void ViewWindow::init() connect(ui->triggersList, SIGNAL(itemSelectionChanged()), this, SLOT(updateTriggersState())); connect(ui->triggersList, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(triggerViewDoubleClicked(QModelIndex))); connect(ui->outputColumnsTable, SIGNAL(currentRowChanged(int)), this, SLOT(updateColumnButtons())); - connect(ui->outputColumnsTable->model(), SIGNAL(rowsMoved(const QModelIndex&, int, int, const QModelIndex&, int)), this, SLOT(updateColumnButtons())); - connect(ui->outputColumnsTable->model(), SIGNAL(rowsMoved(const QModelIndex&, int, int, const QModelIndex&, int)), this, SLOT(updateQueryToolbarStatus())); + connect(ui->outputColumnsTable->model(), SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), this, SLOT(updateColumnButtons())); + connect(ui->outputColumnsTable->model(), SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), this, SLOT(updateQueryToolbarStatus())); connect(ui->outputColumnsTable, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(updateQueryToolbarStatus())); - connect(CFG_UI.General.DataTabAsFirstInViews, SIGNAL(changed(const QVariant&)), this, SLOT(updateTabsOrder())); + connect(CFG_UI.General.DataTabAsFirstInViews, SIGNAL(changed(QVariant)), this, SLOT(updateTabsOrder())); connect(CFG_UI.Fonts.DataView, SIGNAL(changed(QVariant)), this, SLOT(updateFont())); + connect(NotifyManager::getInstance(), SIGNAL(objectModified(Db*,QString,QString)), this, SLOT(handleObjectModified(Db*,QString,QString))); structureExecutor = new ChainExecutor(this); connect(structureExecutor, SIGNAL(success(SqlQueryPtr)), this, SLOT(changesSuccessfullyCommitted())); @@ -296,7 +300,7 @@ void ViewWindow::initView() { dataModel->setDb(db); dataModel->setQuery(originalCreateView->select->detokenize()); - dataModel->setView(view); + dataModel->setDatabaseAndView(database, view); ui->dbCombo->setDisabled(true); } ui->queryEdit->setDb(db); @@ -313,6 +317,8 @@ void ViewWindow::initView() refreshTriggers(); + // Disconnect first in case this method is (re)executed upon dependant table changes. + disconnect(db, SIGNAL(dbObjectDeleted(QString,QString,DbObjectType)), this, SLOT(checkIfViewDeleted(QString,QString,DbObjectType))); connect(db, SIGNAL(dbObjectDeleted(QString,QString,DbObjectType)), this, SLOT(checkIfViewDeleted(QString,QString,DbObjectType))); } @@ -325,10 +331,10 @@ void ViewWindow::setupCoverWidget() void ViewWindow::createQueryTabActions() { - createAction(REFRESH_QUERY, ICONS.RELOAD, tr("Refresh the view", "view window"), this, SLOT(refreshView()), ui->queryToolbar); + createAction(REFRESH_QUERY, ICONS.RELOAD, tr("Refresh the view", "view window"), this, SLOT(refreshView()), ui->queryToolbar, ui->queryEdit); ui->queryToolbar->addSeparator(); - createAction(COMMIT_QUERY, ICONS.COMMIT, tr("Commit the view changes", "view window"), this, SLOT(commitView()), ui->queryToolbar); - createAction(ROLLBACK_QUERY, ICONS.ROLLBACK, tr("Rollback the view changes", "view window"), this, SLOT(rollbackView()), ui->queryToolbar); + createAction(COMMIT_QUERY, ICONS.COMMIT, tr("Commit the view changes", "view window"), this, SLOT(commitView()), ui->queryToolbar, ui->queryEdit); + createAction(ROLLBACK_QUERY, ICONS.ROLLBACK, tr("Rollback the view changes", "view window"), this, SLOT(rollbackView()), ui->queryToolbar, ui->queryEdit); ui->queryToolbar->addSeparator(); ui->queryToolbar->addAction(ui->queryEdit->getAction(SqlEditor::FORMAT_SQL)); @@ -344,6 +350,7 @@ void ViewWindow::createQueryTabActions() createAction(DEL_COLUMN, ICONS.TABLE_COLUMN_DELETE, tr("Delete column", "view window"), this, SLOT(delColumn()), ui->queryToolbar); createAction(MOVE_COLUMN_UP, ICONS.MOVE_UP, tr("Move column up", "view window"), this, SLOT(moveColumnUp()), ui->queryToolbar); createAction(MOVE_COLUMN_DOWN, ICONS.MOVE_DOWN, tr("Move column down", "view window"), this, SLOT(moveColumnDown()), ui->queryToolbar); + createAction(EXECUTE_QUERY, QString(), this, SLOT(executeQuery()), this); } void ViewWindow::createTriggersTabActions() @@ -431,8 +438,23 @@ void ViewWindow::refreshView() updateTriggersState(); } -void ViewWindow::commitView(bool skipWarnings) +void ViewWindow::executeQuery() +{ + if (isModified()) + { + if (!actionMap[COMMIT_QUERY]->isEnabled()) + return; + + commitView(false, true); + return; + } + + switchToDataAndReload(); +} + +void ViewWindow::commitView(bool skipWarnings, bool loadDataAfterNextCommit) { + this->loadDataAfterNextCommit = loadDataAfterNextCommit; if (!isModified()) { qWarning() << "Called ViewWindow::commitView(), but isModified() returned false."; @@ -535,6 +557,12 @@ int ViewWindow::getDdlTabIdx() const return ui->tabWidget->indexOf(ui->ddlTab); } +void ViewWindow::switchToDataAndReload() +{ + ui->tabWidget->setCurrentWidget(ui->dataTab); + // Query execution will happen automatically upon changing tab to data tab. +} + void ViewWindow::addTrigger() { DbObjectDialogs dialogs(db, this); @@ -560,7 +588,7 @@ void ViewWindow::deleteTrigger() return; DbObjectDialogs dialogs(db, this); - dialogs.dropObject(trigger); + dialogs.dropObject(DbObjectDialogs::Type::TRIGGER, trigger); refreshTriggers(); } @@ -573,7 +601,7 @@ void ViewWindow::executionSuccessful() void ViewWindow::executionFailed(const QString& errorMessage) { modifyingThisView = false; - notifyError(tr("Could not load data for view %1. Error details: %2").arg(view).arg(errorMessage)); + notifyError(tr("Could not load data for view %1. Error details: %2").arg(view, errorMessage)); } void ViewWindow::tabChanged(int tabIdx) @@ -615,7 +643,8 @@ void ViewWindow::updateQueryToolbarStatus() { bool modified = isModified(); bool queryOk = ui->queryEdit->isSyntaxChecked() && !ui->queryEdit->haveErrors(); - actionMap[COMMIT_QUERY]->setEnabled(modified && queryOk); + bool dbOk = ui->dbCombo->currentIndex() > -1; + actionMap[COMMIT_QUERY]->setEnabled(modified && queryOk && dbOk); actionMap[ROLLBACK_QUERY]->setEnabled(modified && existingView); actionMap[REFRESH_QUERY]->setEnabled(existingView); } @@ -635,6 +664,8 @@ void ViewWindow::changesSuccessfullyCommitted() QString oldView = view; view = createView->view; + emit sessionValueChanged(); + if (!existingView) notifyInfo(tr("View '%1' was committed successfully.").arg(view)); else if (oldView.compare(view, Qt::CaseInsensitive) == 0) @@ -649,6 +680,12 @@ void ViewWindow::changesSuccessfullyCommitted() updateAfterInit(); DBTREE->refreshSchema(db); + + if (loadDataAfterNextCommit) + { + loadDataAfterNextCommit = false; + switchToDataAndReload(); + } } void ViewWindow::changesFailedToCommit(int errorCode, const QString& errorText) @@ -720,6 +757,7 @@ void ViewWindow::checkIfViewDeleted(const QString& database, const QString& obje if (object.compare(view, Qt::CaseInsensitive) == 0) { dbClosedFinalCleanup(); + MDIAREA->enforceCurrentTaskSelectionAfterWindowClose(); getMdiWindow()->close(); } } @@ -1075,11 +1113,28 @@ void ViewWindow::updateFont() void ViewWindow::dbChanged() { - disconnect(db, SIGNAL(dbObjectDeleted(QString,QString,DbObjectType)), this, SLOT(checkIfViewDeleted(QString,QString,DbObjectType))); + if (db) + disconnect(db, SIGNAL(dbObjectDeleted(QString,QString,DbObjectType)), this, SLOT(checkIfViewDeleted(QString,QString,DbObjectType))); db = ui->dbCombo->currentDb(); dataModel->setDb(db); ui->queryEdit->setDb(db); - connect(db, SIGNAL(dbObjectDeleted(QString,QString,DbObjectType)), this, SLOT(checkIfViewDeleted(QString,QString,DbObjectType))); + if (db) + connect(db, SIGNAL(dbObjectDeleted(QString,QString,DbObjectType)), this, SLOT(checkIfViewDeleted(QString,QString,DbObjectType))); +} + +void ViewWindow::handleObjectModified(Db* db, const QString& database, const QString& object) +{ + UNUSED(db); + UNUSED(database); + if (object.compare(view, Qt::CaseInsensitive) != 0) + return; + +// TODO uncomment below when dbnames are supported +// if (this->database != database) +// return; + + view = object; + refreshView(); } |
