From a5b034d4a9c44f9bc1e83b01de82530f8fc63013 Mon Sep 17 00:00:00 2001 From: Unit 193 Date: Sat, 4 Apr 2015 14:41:04 -0400 Subject: Imported Upstream version 3.0.4 --- .../guiSQLiteStudio/dialogs/columndialog.ui | 6 + .../guiSQLiteStudio/dialogs/configdialog.cpp | 2 +- SQLiteStudio3/guiSQLiteStudio/dialogs/dbdialog.cpp | 173 ++++++++------ SQLiteStudio3/guiSQLiteStudio/dialogs/dbdialog.h | 9 +- SQLiteStudio3/guiSQLiteStudio/dialogs/dbdialog.ui | 255 ++++++++++----------- .../guiSQLiteStudio/dialogs/exportdialog.cpp | 17 +- .../guiSQLiteStudio/dialogs/exportdialog.h | 1 + .../guiSQLiteStudio/dialogs/importdialog.cpp | 13 +- .../guiSQLiteStudio/dialogs/importdialog.ui | 28 ++- .../guiSQLiteStudio/dialogs/triggerdialog.cpp | 31 ++- .../guiSQLiteStudio/dialogs/triggerdialog.h | 5 + 11 files changed, 310 insertions(+), 230 deletions(-) (limited to 'SQLiteStudio3/guiSQLiteStudio/dialogs') diff --git a/SQLiteStudio3/guiSQLiteStudio/dialogs/columndialog.ui b/SQLiteStudio3/guiSQLiteStudio/dialogs/columndialog.ui index 2133aca..1ac6cbb 100644 --- a/SQLiteStudio3/guiSQLiteStudio/dialogs/columndialog.ui +++ b/SQLiteStudio3/guiSQLiteStudio/dialogs/columndialog.ui @@ -31,6 +31,9 @@ 0 + + Scale + @@ -48,6 +51,9 @@ 0 + + Precision + diff --git a/SQLiteStudio3/guiSQLiteStudio/dialogs/configdialog.cpp b/SQLiteStudio3/guiSQLiteStudio/dialogs/configdialog.cpp index b22ee6e..1ff053f 100644 --- a/SQLiteStudio3/guiSQLiteStudio/dialogs/configdialog.cpp +++ b/SQLiteStudio3/guiSQLiteStudio/dialogs/configdialog.cpp @@ -1238,7 +1238,7 @@ void ConfigDialog::initPluginsPage() builtIn = PLUGINS->isBuiltIn(pluginName); title = PLUGINS->getTitle(pluginName); if (builtIn) - title += tr("%1 (built-in)", "plugins manager in configuration dialog").arg(title); + title = tr("%1 (built-in)", "plugins manager in configuration dialog").arg(title); item = new QTreeWidgetItem({title}); item->setCheckState(0, PLUGINS->isLoaded(pluginName) ? Qt::Checked : Qt::Unchecked); diff --git a/SQLiteStudio3/guiSQLiteStudio/dialogs/dbdialog.cpp b/SQLiteStudio3/guiSQLiteStudio/dialogs/dbdialog.cpp index a2a9c36..05d50af 100644 --- a/SQLiteStudio3/guiSQLiteStudio/dialogs/dbdialog.cpp +++ b/SQLiteStudio3/guiSQLiteStudio/dialogs/dbdialog.cpp @@ -15,6 +15,7 @@ #include #include #include +#include DbDialog::DbDialog(Mode mode, QWidget *parent) : QDialog(parent), @@ -54,26 +55,6 @@ QString DbDialog::getName() return ui->nameEdit->text(); } -Db* DbDialog::getDb() -{ - if (ui->typeCombo->currentIndex() < 0) - return nullptr; - - Db* testDb = nullptr; - QHash options = collectOptions(); - QString path = ui->fileEdit->text(); - foreach (DbPlugin* plugin, dbPlugins) - { - if (options.contains(DB_PLUGIN) && options[DB_PLUGIN].toString() != plugin->getName()) - continue; - - testDb = plugin->getInstance("", path, options); - if (testDb) - return testDb; - } - return testDb; -} - bool DbDialog::isPermanent() { return ui->permamentCheckBox->isChecked(); @@ -95,17 +76,18 @@ void DbDialog::showEvent(QShowEvent *e) { if (db) { + disableTypeAutodetection = true; int idx = ui->typeCombo->findText(db->getTypeLabel()); ui->typeCombo->setCurrentIndex(idx); - ui->typeCombo->setEnabled(false); // converting to other type is in separate dialog, it's different feature ui->generateCheckBox->setChecked(false); ui->fileEdit->setText(db->getPath()); ui->nameEdit->setText(db->getName()); + disableTypeAutodetection = false; } else if (ui->typeCombo->count() > 0) { - int idx = ui->typeCombo->findText("SQLite3"); // we should have SQLite3 plugin + int idx = ui->typeCombo->findText("SQLite 3", Qt::MatchFixedString); // we should have SQLite 3 plugin if (idx > -1) ui->typeCombo->setCurrentIndex(idx); else @@ -126,24 +108,30 @@ void DbDialog::init() { ui->setupUi(this); - ui->browseButton->setIcon(ICONS.DATABASE_FILE); - dbPlugins = PLUGINS->getLoadedPlugins(); - foreach (DbPlugin* dbPlugin, dbPlugins) - { - ui->typeCombo->addItem(dbPlugin->getLabel()); - } + ui->browseCreateButton->setIcon(ICONS.PLUS); - ui->browseButton->setVisible(true); + for (DbPlugin* dbPlugin : PLUGINS->getLoadedPlugins()) + dbPlugins[dbPlugin->getLabel()] = dbPlugin; + + QStringList typeLabels; + typeLabels += dbPlugins.keys(); + typeLabels.sort(Qt::CaseInsensitive); + ui->typeCombo->addItems(typeLabels); + + ui->browseCreateButton->setVisible(true); ui->testConnIcon->setVisible(false); connect(ui->fileEdit, SIGNAL(textChanged(QString)), this, SLOT(fileChanged(QString))); connect(ui->nameEdit, SIGNAL(textChanged(QString)), this, SLOT(nameModified(QString))); connect(ui->generateCheckBox, SIGNAL(toggled(bool)), this, SLOT(generateNameSwitched(bool))); - connect(ui->browseButton, SIGNAL(clicked()), this, SLOT(browseClicked())); + connect(ui->browseCreateButton, SIGNAL(clicked()), this, SLOT(browseClicked())); + connect(ui->browseOpenButton, SIGNAL(clicked()), this, SLOT(browseClicked())); connect(ui->testConnButton, SIGNAL(clicked()), this, SLOT(testConnectionClicked())); connect(ui->typeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(dbTypeChanged(int))); generateNameSwitched(true); + + layout()->setSizeConstraint(QLayout::SetFixedSize); } void DbDialog::updateOptions() @@ -153,10 +141,14 @@ void DbDialog::updateOptions() // Remove olds foreach (QWidget* w, optionWidgets) { - ui->gridLayout->removeWidget(w); + ui->optionsGrid->removeWidget(w); delete w; } - adjustSize(); + + customBrowseHandler = nullptr; + ui->pathGroup->setTitle(tr("File")); + ui->browseOpenButton->setToolTip(tr("Browse for existing database file on local computer")); + ui->browseCreateButton->setVisible(true); optionWidgets.clear(); optionKeyToWidget.clear(); @@ -166,31 +158,43 @@ void DbDialog::updateOptions() lastWidgetInTabOrder = ui->permamentCheckBox; // Retrieve new list - DbPlugin* plugin = nullptr; - if (dbPlugins.count() > 0) + if (ui->typeCombo->currentIndex() > -1) { - int idx = ui->typeCombo->currentIndex(); - if (idx > -1 ) + DbPlugin* plugin = dbPlugins[ui->typeCombo->currentText()]; + QList optList = plugin->getOptionsList(); + if (optList.size() > 0) { - plugin = dbPlugins[idx]; - QList optList = plugin->getOptionsList(); - if (optList.size() > 0) + // Add new options + int row = ADDITIONAL_ROWS_BEGIN_INDEX; + for (const DbPluginOption& opt : optList) { - // Add new options - int row = ADDITIONAL_ROWS_BEGIN_INDEX; - foreach (DbPluginOption opt, optList) - addOption(opt, row++); + addOption(opt, row); + row++; } } } - adjustSize(); + setUpdatesEnabled(true); } -void DbDialog::addOption(const DbPluginOption& option, int row) +void DbDialog::addOption(const DbPluginOption& option, int& row) { + if (option.type == DbPluginOption::CUSTOM_PATH_BROWSE) + { + // This option does not add any editor, but has it's own label for path edit. + row--; + ui->pathGroup->setTitle(option.label); + ui->browseCreateButton->setVisible(false); + if (!option.toolTip.isEmpty()) + ui->browseOpenButton->setToolTip(option.toolTip); + + customBrowseHandler = option.customBrowseHandler; + return; + } + QLabel* label = new QLabel(option.label, this); + label->setAlignment(Qt::AlignVCenter|Qt::AlignRight); QWidget* editor = nullptr; QWidget* editorHelper = nullptr; // TODO, based on plugins for Url handlers @@ -204,15 +208,15 @@ void DbDialog::addOption(const DbPluginOption& option, int row) optionKeyToWidget[option.key] = editor; optionKeyToType[option.key] = option.type; - ui->gridLayout->addWidget(label, row, 0); - ui->gridLayout->addWidget(editor, row, 1); + ui->optionsGrid->addWidget(label, row, 0); + ui->optionsGrid->addWidget(editor, row, 1); setTabOrder(lastWidgetInTabOrder, editor); lastWidgetInTabOrder = editor; if (editorHelper) { - ui->gridLayout->addWidget(editorHelper, row, 2); + ui->optionsGrid->addWidget(editorHelper, row, 2); optionWidgets << editorHelper; helperToKey[editorHelper] = option.key; @@ -307,6 +311,8 @@ QWidget *DbDialog::getEditor(const DbPluginOption& opt, QWidget*& editorHelper) connect(sb, SIGNAL(valueChanged(double)), this, SLOT(propertyChanged())); break; } + case DbPluginOption::CUSTOM_PATH_BROWSE: + return nullptr; // should not happen ever, asserted one stack level before default: // TODO plugin based handling of custom editors qWarning() << "Unhandled DbDialog option for creating editor."; @@ -344,6 +350,8 @@ QVariant DbDialog::getValueFrom(DbPluginOption::Type type, QWidget *editor) case DbPluginOption::CHOICE: value = dynamic_cast(editor)->currentText(); break; + case DbPluginOption::CUSTOM_PATH_BROWSE: + break; // should not happen ever default: // TODO plugin based handling of custom editors qWarning() << "Unhandled DbDialog option for value."; @@ -373,6 +381,8 @@ void DbDialog::setValueFor(DbPluginOption::Type type, QWidget *editor, const QVa case DbPluginOption::CHOICE: dynamic_cast(editor)->setCurrentText(value.toString()); break; + case DbPluginOption::CUSTOM_PATH_BROWSE: + break; // should not happen ever default: qWarning() << "Unhandled DbDialog option to set value."; // TODO plugin based handling of custom editors @@ -382,18 +392,19 @@ void DbDialog::setValueFor(DbPluginOption::Type type, QWidget *editor, const QVa void DbDialog::updateType() { + if (disableTypeAutodetection) + return; + QFileInfo file(ui->fileEdit->text()); if (!file.exists() || file.isDir()) - { - ui->typeCombo->setEnabled(true); return; - } - DbPlugin* validPlugin = nullptr; + QString currentPluginLabel = ui->typeCombo->currentText(); + QList validPlugins; QHash options; QString path = ui->fileEdit->text(); Db* probeDb = nullptr; - foreach (DbPlugin* plugin, dbPlugins) + for (DbPlugin* plugin : dbPlugins) { probeDb = plugin->getInstance("", path, options); if (probeDb) @@ -401,15 +412,15 @@ void DbDialog::updateType() delete probeDb; probeDb = nullptr; - validPlugin = plugin; - break; + if (plugin->getLabel() == currentPluginLabel) + return; // current plugin is among valid plugins, no need to change anything + + validPlugins << plugin; } } - if (validPlugin) - ui->typeCombo->setCurrentText(validPlugin->getLabel()); - - ui->typeCombo->setEnabled(!validPlugin); + if (validPlugins.size() > 0) + ui->typeCombo->setCurrentText(validPlugins.first()->getLabel()); } QHash DbDialog::collectOptions() @@ -424,7 +435,7 @@ QHash DbDialog::collectOptions() DbPlugin* plugin = nullptr; if (dbPlugins.count() > 0) { - plugin = dbPlugins[ui->typeCombo->currentIndex()]; + plugin = dbPlugins[ui->typeCombo->currentText()]; options[DB_PLUGIN] = plugin->getName(); } @@ -433,9 +444,32 @@ QHash DbDialog::collectOptions() bool DbDialog::testDatabase() { + if (ui->typeCombo->currentIndex() < 0) + return false; + QString path = ui->fileEdit->text(); - bool existed = QFile::exists(path); - bool res = getDb() != nullptr; + if (path.isEmpty()) + return false; + + QUrl url(path); + if (url.scheme().isEmpty()) + url.setScheme("file"); + + bool existed = false; + if (url.isLocalFile() && QFile::exists(path)) + existed = QFile::exists(path); + + QHash options = collectOptions(); + DbPlugin* plugin = dbPlugins[ui->typeCombo->currentText()]; + Db* testDb = plugin->getInstance("", path, options); + + bool res = false; + if (testDb) + { + res = true; + delete testDb; + } + if (!existed) { QFile file(path); @@ -522,10 +556,9 @@ void DbDialog::valueForNameGenerationChanged() if (!ui->generateCheckBox->isChecked()) return; - DbPlugin* plugin = nullptr; if (dbPlugins.count() > 0) { - plugin = dbPlugins[ui->typeCombo->currentIndex()]; + DbPlugin* plugin = dbPlugins[ui->typeCombo->currentText()]; QString generatedName = plugin->generateDbName(ui->fileEdit->text()); generatedName = generateUniqueName(generatedName, existingDatabaseNames); ui->nameEdit->setText(generatedName); @@ -549,7 +582,7 @@ void DbDialog::generateNameSwitched(bool checked) { if (checked) { - ui->nameEdit->setPlaceholderText(tr("The name will be auto-generated")); + ui->nameEdit->setPlaceholderText(tr("Auto-generated")); valueForNameGenerationChanged(); } else @@ -570,6 +603,14 @@ void DbDialog::fileChanged(const QString &arg1) void DbDialog::browseClicked() { + if (customBrowseHandler) + { + customBrowseHandler(ui->fileEdit->text()); + return; + } + + bool createMode = (sender() == ui->browseCreateButton); + QFileInfo fileInfo(ui->fileEdit->text()); QString dir; if (ui->fileEdit->text().isEmpty()) @@ -581,7 +622,7 @@ void DbDialog::browseClicked() else dir = getFileDialogInitPath(); - QString path = getDbPath(dir); + QString path = getDbPath(createMode, dir); if (path.isNull()) return; diff --git a/SQLiteStudio3/guiSQLiteStudio/dialogs/dbdialog.h b/SQLiteStudio3/guiSQLiteStudio/dialogs/dbdialog.h index b2c0d68..ce73b11 100644 --- a/SQLiteStudio3/guiSQLiteStudio/dialogs/dbdialog.h +++ b/SQLiteStudio3/guiSQLiteStudio/dialogs/dbdialog.h @@ -47,12 +47,11 @@ class GUI_API_EXPORT DbDialog : public QDialog private: void init(); void updateOptions(); - void addOption(const DbPluginOption& option, int row); + void addOption(const DbPluginOption& option, int& row); QWidget* getEditor(const DbPluginOption& opt, QWidget *&editorHelper); QVariant getValueFrom(DbPluginOption::Type type, QWidget* editor); void setValueFor(DbPluginOption::Type type, QWidget* editor, const QVariant& value); void updateType(); - Db* getDb(); bool testDatabase(); bool validate(); void updateState(); @@ -61,14 +60,16 @@ class GUI_API_EXPORT DbDialog : public QDialog Mode mode; QStringList existingDatabaseNames; Db* db = nullptr; - QList dbPlugins; + QHash dbPlugins; QList optionWidgets; QHash optionKeyToWidget; QHash optionKeyToType; QHash helperToKey; QWidget* lastWidgetInTabOrder = nullptr; + DbPluginOption::CustomBrowseHandler customBrowseHandler = nullptr; + bool disableTypeAutodetection = false; - static const constexpr int ADDITIONAL_ROWS_BEGIN_INDEX = 4; + static const constexpr int ADDITIONAL_ROWS_BEGIN_INDEX = 1; private slots: void typeChanged(int index); diff --git a/SQLiteStudio3/guiSQLiteStudio/dialogs/dbdialog.ui b/SQLiteStudio3/guiSQLiteStudio/dialogs/dbdialog.ui index fb53428..6f35079 100644 --- a/SQLiteStudio3/guiSQLiteStudio/dialogs/dbdialog.ui +++ b/SQLiteStudio3/guiSQLiteStudio/dialogs/dbdialog.ui @@ -7,7 +7,7 @@ 0 0 455 - 200 + 365 @@ -21,127 +21,124 @@ - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Database driver - - - - - - - - - true - - - - - - - Name - - - - - - - Type - - - - - - - - - - - - Browse for database file on local computer - - - - - - - - - - - - File - - - - - - - Generate name basing on file path - - - - - - true - - - - - - - Permanent - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - <p>Enable this if you want the database to be stored in configuration file and restored every time SQLiteStudio is started.</p> - - - - - - true - - - - - - + + + Database type + + + + + + Database driver + + + + + + + + + + File + + + + + + + + + Create new database file + + + + + + + :/icons/img/plus.png:/icons/img/plus.png + + + + + + + + + + + :/icons/img/open_sql_file.png:/icons/img/open_sql_file.png + + + + + + + + + + Name (on the list) + + + + + + true + + + + + + + Generate name basing on file path + + + Generate automatically + + + true + + + + + + + + + + Options + + + + + + <p>Enable this if you want the database to be stored in configuration file and restored every time SQLiteStudio is started.</p> + + + Permanent (keep it in configuration) + + + true + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 360 + 1 + + + @@ -161,7 +158,7 @@ - Test database connection + Test connection @@ -190,15 +187,9 @@ - - fileEdit - browseButton - nameEdit - generateCheckBox - typeCombo - permamentCheckBox - - + + + buttonBox diff --git a/SQLiteStudio3/guiSQLiteStudio/dialogs/exportdialog.cpp b/SQLiteStudio3/guiSQLiteStudio/dialogs/exportdialog.cpp index e495dd9..91b4087 100644 --- a/SQLiteStudio3/guiSQLiteStudio/dialogs/exportdialog.cpp +++ b/SQLiteStudio3/guiSQLiteStudio/dialogs/exportdialog.cpp @@ -124,6 +124,14 @@ void ExportDialog::setDatabaseMode(Db* db) this->db = db; } +void ExportDialog::setPreselectedDb(Db *db) +{ + if (!db->isOpen()) + return; + + this->db = db; +} + void ExportDialog::initModePage() { connect(ui->subjectDatabaseRadio, SIGNAL(clicked()), this, SLOT(updateExportMode())); @@ -146,10 +154,11 @@ void ExportDialog::initTablePage() dbListModel = new DbListModel(this); dbListModel->setCombo(ui->exportTableDbNameCombo); - dbListModel->setSortMode(DbListModel::SortMode::Alphabetical); + dbListModel->setSortMode(DbListModel::SortMode::AlphabeticalCaseInsensitive); tablesModel = new DbObjListModel(this); tablesModel->setType(DbObjListModel::ObjectType::TABLE); + tablesModel->setSortMode(DbObjListModel::SortMode::AlphabeticalCaseInsensitive); connect(this, SIGNAL(tablePageCompleteChanged()), ui->tablePage, SIGNAL(completeChanged())); } @@ -295,6 +304,9 @@ void ExportDialog::tablePageDisplayed() if (table.isNull()) // table mode selected by user, not forced by setTableMode(). { ui->exportTableDbNameCombo->setModel(dbListModel); + if (db) + ui->exportTableDbNameCombo->setCurrentText(db->getName()); + connect(ui->exportTableDbNameCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateDbTables())); ui->exportTableNameCombo->setModel(tablesModel); @@ -313,6 +325,9 @@ void ExportDialog::queryPageDisplayed() if (query.isNull()) // query mode selected by user, not forced by setQueryMode(). { ui->queryDatabaseCombo->setModel(dbListModel); + if (db) + ui->queryDatabaseCombo->setCurrentText(db->getName()); + connect(ui->queryDatabaseCombo, SIGNAL(currentIndexChanged(int)), ui->queryPage, SIGNAL(completeChanged())); } diff --git a/SQLiteStudio3/guiSQLiteStudio/dialogs/exportdialog.h b/SQLiteStudio3/guiSQLiteStudio/dialogs/exportdialog.h index 296aa4d..0471172 100644 --- a/SQLiteStudio3/guiSQLiteStudio/dialogs/exportdialog.h +++ b/SQLiteStudio3/guiSQLiteStudio/dialogs/exportdialog.h @@ -26,6 +26,7 @@ class GUI_API_EXPORT ExportDialog : public QWizard void setTableMode(Db* db, const QString& table); void setQueryMode(Db* db, const QString& query); void setDatabaseMode(Db* db); + void setPreselectedDb(Db* db); int nextId() const; bool isPluginConfigValid() const; diff --git a/SQLiteStudio3/guiSQLiteStudio/dialogs/importdialog.cpp b/SQLiteStudio3/guiSQLiteStudio/dialogs/importdialog.cpp index 32ec30f..c16b90e 100644 --- a/SQLiteStudio3/guiSQLiteStudio/dialogs/importdialog.cpp +++ b/SQLiteStudio3/guiSQLiteStudio/dialogs/importdialog.cpp @@ -83,12 +83,13 @@ void ImportDialog::initTablePage() { dbListModel = new DbListModel(this); dbListModel->setCombo(ui->dbNameCombo); - dbListModel->setSortMode(DbListModel::SortMode::Alphabetical); + dbListModel->setSortMode(DbListModel::SortMode::AlphabeticalCaseInsensitive); ui->dbNameCombo->setModel(dbListModel); tablesModel = new DbObjListModel(this); tablesModel->setIncludeSystemObjects(false); tablesModel->setType(DbObjListModel::ObjectType::TABLE); + tablesModel->setSortMode(DbObjListModel::SortMode::AlphabeticalCaseInsensitive); ui->tableNameCombo->setModel(tablesModel); refreshTables(); @@ -166,14 +167,6 @@ void ImportDialog::updateStandardOptions() bool showFileName = currentPlugin->standardOptionsToEnable().testFlag(ImportManager::FILE_NAME); bool showCodec = currentPlugin->standardOptionsToEnable().testFlag(ImportManager::CODEC); - if (!showFileName && !showCodec) - { - ui->dsOptionsGroup->setVisible(false); - return; - } - - ui->dsOptionsGroup->setVisible(true); - int row = 0; QGridLayout* grid = dynamic_cast(ui->dsOptionsGroup->layout()); if (showFileName) @@ -355,6 +348,8 @@ void ImportDialog::accept() if (currentPlugin->standardOptionsToEnable().testFlag(ImportManager::CODEC)) stdConfig.codec = ui->codecCombo->currentText(); + stdConfig.ignoreErrors = ui->ignoreErrorsCheck->isChecked(); + Db* db = DBLIST->getByName(ui->dbNameCombo->currentText());; if (!db) { diff --git a/SQLiteStudio3/guiSQLiteStudio/dialogs/importdialog.ui b/SQLiteStudio3/guiSQLiteStudio/dialogs/importdialog.ui index c8756f7..dfa8ace 100644 --- a/SQLiteStudio3/guiSQLiteStudio/dialogs/importdialog.ui +++ b/SQLiteStudio3/guiSQLiteStudio/dialogs/importdialog.ui @@ -103,8 +103,8 @@ 0 0 - 479 - 310 + 269 + 280 @@ -141,13 +141,6 @@ Options - - - - Input file: - - - @@ -183,9 +176,26 @@ + + + + Input file: + + + + + + + <p>If enabled, any constraint violation, or invalid data format (wrong column count), or any other problem encountered during import will be ignored and the importing will be continued.</p> + + + Ignore errors + + + diff --git a/SQLiteStudio3/guiSQLiteStudio/dialogs/triggerdialog.cpp b/SQLiteStudio3/guiSQLiteStudio/dialogs/triggerdialog.cpp index 0707bd3..12baafd 100644 --- a/SQLiteStudio3/guiSQLiteStudio/dialogs/triggerdialog.cpp +++ b/SQLiteStudio3/guiSQLiteStudio/dialogs/triggerdialog.cpp @@ -19,6 +19,9 @@ #include #include +QStringList TriggerDialog::tableEventNames; +QStringList TriggerDialog::viewEventNames; + TriggerDialog::TriggerDialog(Db* db, QWidget *parent) : QDialog(parent), db(db), @@ -54,6 +57,18 @@ void TriggerDialog::setTrigger(const QString& name) initTrigger(); } +void TriggerDialog::staticInit() +{ + tableEventNames = QStringList({ + SqliteCreateTrigger::time(SqliteCreateTrigger::Time::null), + SqliteCreateTrigger::time(SqliteCreateTrigger::Time::AFTER), + SqliteCreateTrigger::time(SqliteCreateTrigger::Time::BEFORE) + }); + viewEventNames = QStringList({ + SqliteCreateTrigger::time(SqliteCreateTrigger::Time::INSTEAD_OF) + }); +} + void TriggerDialog::changeEvent(QEvent *e) { QDialog::changeEvent(e); @@ -99,6 +114,9 @@ void TriggerDialog::init() }); } + // Event combo - default values + ui->whenCombo->addItems(tableEventNames + viewEventNames); + // Precondition connect(ui->preconditionCheck, SIGNAL(clicked()), this, SLOT(updateState())); connect(ui->preconditionEdit, SIGNAL(errorsChecked(bool)), this, SLOT(updateValidation())); @@ -128,22 +146,19 @@ void TriggerDialog::initTrigger() } // Event combo + QString eventValue = ui->whenCombo->currentText(); + ui->whenCombo->clear(); if (forTable) { - ui->whenCombo->addItems({ - SqliteCreateTrigger::time(SqliteCreateTrigger::Time::null), - SqliteCreateTrigger::time(SqliteCreateTrigger::Time::BEFORE), - SqliteCreateTrigger::time(SqliteCreateTrigger::Time::AFTER) - }); + ui->whenCombo->addItems(tableEventNames); } else { - ui->whenCombo->addItems({ - SqliteCreateTrigger::time(SqliteCreateTrigger::Time::INSTEAD_OF) - }); + ui->whenCombo->addItems(viewEventNames); ui->whenCombo->setEnabled(false); ui->onLabel->setText(tr("On view:")); } + ui->whenCombo->setCurrentText(eventValue); if (!view.isNull() || !table.isNull()) { diff --git a/SQLiteStudio3/guiSQLiteStudio/dialogs/triggerdialog.h b/SQLiteStudio3/guiSQLiteStudio/dialogs/triggerdialog.h index d8e7ed4..712ea5e 100644 --- a/SQLiteStudio3/guiSQLiteStudio/dialogs/triggerdialog.h +++ b/SQLiteStudio3/guiSQLiteStudio/dialogs/triggerdialog.h @@ -22,6 +22,8 @@ class GUI_API_EXPORT TriggerDialog : public QDialog void setParentView(const QString& name); void setTrigger(const QString& name); + static void staticInit(); + protected: void changeEvent(QEvent *e); @@ -35,6 +37,9 @@ class GUI_API_EXPORT TriggerDialog : public QDialog QString getTargetObjectName() const; void rebuildTrigger(); + static QStringList tableEventNames; + static QStringList viewEventNames; + QString originalTriggerName; QString trigger; QString table; -- cgit v1.2.3