summaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/guiSQLiteStudio/windows/tablewindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'SQLiteStudio3/guiSQLiteStudio/windows/tablewindow.cpp')
-rw-r--r--SQLiteStudio3/guiSQLiteStudio/windows/tablewindow.cpp80
1 files changed, 61 insertions, 19 deletions
diff --git a/SQLiteStudio3/guiSQLiteStudio/windows/tablewindow.cpp b/SQLiteStudio3/guiSQLiteStudio/windows/tablewindow.cpp
index c9356d8..86f48bf 100644
--- a/SQLiteStudio3/guiSQLiteStudio/windows/tablewindow.cpp
+++ b/SQLiteStudio3/guiSQLiteStudio/windows/tablewindow.cpp
@@ -2,21 +2,16 @@
#include "ui_tablewindow.h"
#include "services/dbmanager.h"
#include "services/notifymanager.h"
-#include "sqlitestudio.h"
#include "common/unused.h"
#include "schemaresolver.h"
#include "iconmanager.h"
-#include "common/intvalidator.h"
-#include "common/extlineedit.h"
#include "datagrid/sqltablemodel.h"
-#include "common/extaction.h"
#include "mainwindow.h"
#include "tablestructuremodel.h"
#include "tableconstraintsmodel.h"
#include "dialogs/columndialog.h"
#include "dialogs/constraintdialog.h"
#include "mdiarea.h"
-#include "sqlitesyntaxhighlighter.h"
#include "dialogs/newconstraintdialog.h"
#include "db/chainexecutor.h"
#include "common/widgetcover.h"
@@ -37,7 +32,6 @@
#include "themetuner.h"
#include "dialogs/importdialog.h"
#include "dialogs/populatedialog.h"
-#include "datagrid/sqlqueryitem.h"
#include "common/dbcombobox.h"
#include <QMenu>
#include <QToolButton>
@@ -217,10 +211,10 @@ void TableWindow::createActions()
void TableWindow::createStructureActions()
{
- createAction(REFRESH_STRUCTURE, ICONS.RELOAD, tr("Refresh structure", "table window"), this, SLOT(refreshStructure()), ui->structureToolBar);
+ createAction(REFRESH_STRUCTURE, ICONS.RELOAD, tr("Refresh structure", "table window"), this, SLOT(refreshStructure()), ui->structureToolBar, ui->structureView);
ui->structureToolBar->addSeparator();
- createAction(COMMIT_STRUCTURE, ICONS.COMMIT, tr("Commit structure changes", "table window"), this, SLOT(commitStructure()), ui->structureToolBar);
- createAction(ROLLBACK_STRUCTURE, ICONS.ROLLBACK, tr("Rollback structure changes", "table window"), this, SLOT(rollbackStructure()), ui->structureToolBar);
+ createAction(COMMIT_STRUCTURE, ICONS.COMMIT, tr("Commit structure changes", "table window"), this, SLOT(commitStructure()), ui->structureToolBar, ui->structureView);
+ createAction(ROLLBACK_STRUCTURE, ICONS.ROLLBACK, tr("Rollback structure changes", "table window"), this, SLOT(rollbackStructure()), ui->structureToolBar, ui->structureView);
createAction(ADD_COLUMN, ICONS.TABLE_COLUMN_ADD, tr("Add column", "table window"), this, SLOT(addColumn()), ui->structureToolBar, ui->structureView);
createAction(EDIT_COLUMN, ICONS.TABLE_COLUMN_EDIT, tr("Edit column", "table window"), this, SLOT(editColumn()), ui->structureToolBar, ui->structureView);
createAction(DEL_COLUMN, ICONS.TABLE_COLUMN_DELETE, tr("Delete column", "table window"), this, SLOT(delColumn()), ui->structureToolBar, ui->structureView);
@@ -348,10 +342,10 @@ void TableWindow::executeStructureChanges()
MessageListDialog dialog(tr("Following problems will take place while modifying the table.\n"
"Would you like to proceed?", "table window"));
dialog.setWindowTitle(tr("Table modification", "table window"));
- for (const QString& error : tableModifier->getErrors())
+ for (QString& error : tableModifier->getErrors())
dialog.addError(error);
- for (const QString& warn : tableModifier->getWarnings())
+ for (QString& warn : tableModifier->getWarnings())
dialog.addWarning(warn);
if (dialog.exec() != QDialog::Accepted)
@@ -458,8 +452,9 @@ void TableWindow::setupDefShortcuts()
{
// Widget context
setShortcutContext({
+ COMMIT_STRUCTURE,
+ ROLLBACK_STRUCTURE,
REFRESH_STRUCTURE,
- REFRESH_INDEXES,
REFRESH_TRIGGERS,
ADD_COLUMN,
EDIT_COLUMN,
@@ -567,6 +562,7 @@ void TableWindow::initDbAndTable()
ui->constraintsView->setModel(constraintTabModel);
connect(ui->withoutRowIdCheck, SIGNAL(clicked()), this, SLOT(withOutRowIdChanged()));
+ connect(ui->strictTableCheck, SIGNAL(clicked()), this, SLOT(strictChanged()));
parseDdl();
updateIndexes();
@@ -614,7 +610,8 @@ void TableWindow::parseDdl()
structureModel->setCreateTable(createTable.data());
structureConstraintsModel->setCreateTable(createTable.data());
constraintTabModel->setCreateTable(createTable.data());
- ui->withoutRowIdCheck->setChecked(!createTable->withOutRowId.isNull());
+ ui->withoutRowIdCheck->setChecked(createTable->withOutRowId);
+ ui->strictTableCheck->setChecked(createTable->strict);
ui->tableConstraintsView->resizeColumnsToContents();
ui->structureView->resizeColumnsToContents();
ui->constraintsView->resizeColumnsToContents();
@@ -645,7 +642,7 @@ void TableWindow::changeEvent(QEvent *e)
QVariant TableWindow::saveSession()
{
- if (!db || DBLIST->isTemporary(db))
+ if (!db || DBLIST->isTemporary(db) || !existingTable)
return QVariant();
QHash<QString,QVariant> sessionValue;
@@ -681,7 +678,7 @@ bool TableWindow::restoreSession(const QVariant& sessionValue)
SchemaResolver resolver(db);
if (!resolver.getTables(database).contains(table, Qt::CaseInsensitive))
{
- notifyWarn(tr("Could not restore window '%1'', because the table %2 doesn't exist in the database %3.").arg(value["title"].toString(), table, db->getName()));
+ notifyWarn(tr("Could not restore window '%1', because the table %2 doesn't exist in the database %3.").arg(value["title"].toString(), table, db->getName()));
return false;
}
@@ -759,6 +756,7 @@ void TableWindow::checkIfTableDeleted(const QString& database, const QString& ob
if (object.compare(table, Qt::CaseInsensitive) == 0)
{
dbClosedFinalCleanup();
+ MDIAREA->enforceCurrentTaskSelectionAfterWindowClose();
getMdiWindow()->close();
}
}
@@ -832,6 +830,8 @@ void TableWindow::changesSuccessfullyCommitted()
updateNewTableState();
updateWindowTitle();
+ emit sessionValueChanged();
+
NotifyManager* notifyManager = NotifyManager::getInstance();
if (oldTable.compare(table, Qt::CaseInsensitive) == 0 || oldTable.isEmpty())
{
@@ -883,6 +883,8 @@ void TableWindow::rollbackStructure()
structureConstraintsModel->setCreateTable(createTable.data());
constraintTabModel->setCreateTable(createTable.data());
ui->tableNameEdit->setText(createTable->table);
+ ui->withoutRowIdCheck->setChecked(createTable->withOutRowId);
+ ui->strictTableCheck->setChecked(createTable->strict);
updateStructureCommitState();
updateStructureToolbarState();
@@ -1040,6 +1042,26 @@ bool TableWindow::validate(bool skipWarning)
}
}
+ if (ui->strictTableCheck->isChecked())
+ {
+ QStringList nonStrictColumns;
+ for (SqliteCreateTable::Column* column : createTable->columns)
+ {
+ if (DataType::isStrict(column->type->name))
+ continue;
+
+ nonStrictColumns << column->name;
+ }
+
+ if (!nonStrictColumns.isEmpty())
+ {
+ notifyError(tr("Following columns have non-strict data type: %1."
+ " Either disable strict mode of the table, or fix column data types. Valid strict data types are: %2")
+ .arg(nonStrictColumns.join(", "), DataType::getStrictValueNames().join(", ")));
+ return false;
+ }
+ }
+
return true;
}
@@ -1049,7 +1071,8 @@ bool TableWindow::isModified() const
(structureConstraintsModel && structureConstraintsModel->isModified()) ||
(originalCreateTable &&
(originalCreateTable->table != ui->tableNameEdit->text() ||
- originalCreateTable->withOutRowId != createTable->withOutRowId)
+ originalCreateTable->withOutRowId != createTable->withOutRowId ||
+ originalCreateTable->strict != createTable->strict)
) ||
!existingTable;
}
@@ -1355,7 +1378,26 @@ void TableWindow::withOutRowIdChanged()
if (!createTable)
return;
- createTable->withOutRowId = ui->withoutRowIdCheck->isChecked() ? QStringLiteral("ROWID") : QString();
+ createTable->withOutRowId = ui->withoutRowIdCheck->isChecked();
+ updateDdlTab();
+ emit modifyStatusChanged();
+}
+
+void TableWindow::strictChanged()
+{
+ if (!createTable)
+ return;
+
+ createTable->strict = ui->strictTableCheck->isChecked();
+ if (createTable->strict)
+ {
+ for (SqliteCreateTable::Column* column : createTable->columns)
+ {
+ column->type->precision = QVariant();
+ column->type->scale = QVariant();
+ }
+ }
+
updateDdlTab();
emit modifyStatusChanged();
}
@@ -1401,7 +1443,7 @@ void TableWindow::delIndex()
return;
DbObjectDialogs dialogs(db, this);
- dialogs.dropObject(index);
+ dialogs.dropObject(DbObjectDialogs::Type::INDEX, index);
updateIndexes();
}
@@ -1448,7 +1490,7 @@ void TableWindow::delTrigger()
return;
DbObjectDialogs dialogs(db, this);
- dialogs.dropObject(trigger);
+ dialogs.dropObject(DbObjectDialogs::Type::TRIGGER, trigger);
updateTriggers();
}