aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/guiSQLiteStudio/dialogs/dbdialog.cpp
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2021-12-17 07:06:30 -0500
committerLibravatarUnit 193 <unit193@unit193.net>2021-12-17 07:06:30 -0500
commit1fdc150116cad39aae5c5da407c3312b47a59e3a (patch)
tree123c79a4d7ad2d45781ba03ce939f7539fb428d8 /SQLiteStudio3/guiSQLiteStudio/dialogs/dbdialog.cpp
parentfeda8a7db8d1d7c5439aa8f8feef7cc0dd2b59a0 (diff)
New upstream version 3.3.3+dfsg1.upstream/3.3.3+dfsg1
Diffstat (limited to 'SQLiteStudio3/guiSQLiteStudio/dialogs/dbdialog.cpp')
-rw-r--r--SQLiteStudio3/guiSQLiteStudio/dialogs/dbdialog.cpp68
1 files changed, 59 insertions, 9 deletions
diff --git a/SQLiteStudio3/guiSQLiteStudio/dialogs/dbdialog.cpp b/SQLiteStudio3/guiSQLiteStudio/dialogs/dbdialog.cpp
index 183f8dd..1e56258 100644
--- a/SQLiteStudio3/guiSQLiteStudio/dialogs/dbdialog.cpp
+++ b/SQLiteStudio3/guiSQLiteStudio/dialogs/dbdialog.cpp
@@ -8,6 +8,7 @@
#include "services/dbmanager.h"
#include "common/global.h"
#include "iconmanager.h"
+#include "sqleditor.h"
#include "common/unused.h"
#include "db/sqlquery.h"
#include <QDateTimeEdit>
@@ -199,16 +200,13 @@ void DbDialog::addOption(const DbPluginOption& option, int& row)
}
QLabel* label = new QLabel(option.label, this);
- label->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
+ label->setAlignment(Qt::AlignTop|Qt::AlignRight);
QWidget* editor = nullptr;
QWidget* editorHelper = nullptr; // TODO, based on plugins for Url handlers
editor = getEditor(option, editorHelper);
Q_ASSERT(editor != nullptr);
- if (!option.toolTip.isNull())
- editor->setToolTip(option.toolTip);
-
optionWidgets << label << editor;
optionKeyToWidget[option.key] = editor;
@@ -240,6 +238,16 @@ QWidget *DbDialog::getEditor(const DbPluginOption& opt, QWidget*& editorHelper)
editorHelper = nullptr;
switch (opt.type)
{
+ case DbPluginOption::SQL:
+ {
+ SqlEditor* sqlEdit = new SqlEditor(this);
+ editor = sqlEdit;
+ sqlEdit->setShowLineNumbers(false);
+ sqlEdit->setPlainText(opt.defaultValue.toString());
+ sqlEdit->setMaximumHeight(sqlEdit->fontMetrics().height() * 5);
+ connect(sqlEdit, SIGNAL(textChanged()), this, SLOT(propertyChanged()));
+ break;
+ }
case DbPluginOption::STRING:
{
editor = new QLineEdit(this);
@@ -260,8 +268,20 @@ QWidget *DbDialog::getEditor(const DbPluginOption& opt, QWidget*& editorHelper)
QComboBox* cb = new QComboBox(this);
editor = cb;
cb->setEditable(!opt.choiceReadOnly);
- cb->addItems(opt.choiceValues);
- cb->setCurrentText(opt.defaultValue.toString());
+ if (opt.choiceDataValues.isEmpty())
+ {
+ cb->addItems(opt.choiceValues);
+ cb->setCurrentText(opt.defaultValue.toString());
+ }
+ else
+ {
+ for (auto it = opt.choiceDataValues.begin(); it != opt.choiceDataValues.end(); ++it)
+ {
+ cb->addItem(it.key(), it.value());
+ if (it.value() == opt.defaultValue)
+ cb->setCurrentText(it.key());
+ }
+ }
connect(cb, SIGNAL(currentIndexChanged(QString)), this, SLOT(propertyChanged()));
break;
}
@@ -330,6 +350,9 @@ QWidget *DbDialog::getEditor(const DbPluginOption& opt, QWidget*& editorHelper)
le->setText(opt.defaultValue.toString());
}
+ if (!opt.toolTip.isNull())
+ editor->setToolTip(opt.toolTip);
+
return editor;
}
@@ -338,6 +361,9 @@ QVariant DbDialog::getValueFrom(DbPluginOption::Type type, QWidget *editor)
QVariant value;
switch (type)
{
+ case DbPluginOption::SQL:
+ value = dynamic_cast<SqlEditor*>(editor)->toPlainText();
+ break;
case DbPluginOption::STRING:
case DbPluginOption::PASSWORD:
case DbPluginOption::FILE:
@@ -353,8 +379,17 @@ QVariant DbDialog::getValueFrom(DbPluginOption::Type type, QWidget *editor)
value = dynamic_cast<QDoubleSpinBox*>(editor)->value();
break;
case DbPluginOption::CHOICE:
- value = dynamic_cast<QComboBox*>(editor)->currentText();
+ {
+ QComboBox* cb = dynamic_cast<QComboBox*>(editor);
+ QVariant data = cb->currentData();
+ if (data.isValid())
+ {
+ value = data;
+ break;
+ }
+ value = cb->currentText();
break;
+ }
case DbPluginOption::CUSTOM_PATH_BROWSE:
break; // should not happen ever
default:
@@ -369,6 +404,9 @@ void DbDialog::setValueFor(DbPluginOption::Type type, QWidget *editor, const QVa
{
switch (type)
{
+ case DbPluginOption::SQL:
+ dynamic_cast<SqlEditor*>(editor)->setPlainText(value.toString());
+ break;
case DbPluginOption::STRING:
case DbPluginOption::FILE:
case DbPluginOption::PASSWORD:
@@ -384,8 +422,20 @@ void DbDialog::setValueFor(DbPluginOption::Type type, QWidget *editor, const QVa
dynamic_cast<QDoubleSpinBox*>(editor)->setValue(value.toDouble());
break;
case DbPluginOption::CHOICE:
- dynamic_cast<QComboBox*>(editor)->setCurrentText(value.toString());
+ {
+ QComboBox* cb = dynamic_cast<QComboBox*>(editor);
+ if (value.isValid())
+ {
+ int idx = cb->findData(value);
+ if (idx > -1)
+ {
+ cb->setCurrentIndex(idx);
+ break;
+ }
+ }
+ cb->setCurrentText(value.toString());
break;
+ }
case DbPluginOption::CUSTOM_PATH_BROWSE:
break; // should not happen ever
default:
@@ -413,7 +463,7 @@ QHash<QString, QVariant> DbDialog::collectOptions()
if (ui->typeCombo->currentIndex() < 0)
return options;
- for (const QString key : optionKeyToWidget.keys())
+ for (const QString& key : optionKeyToWidget.keys())
options[key] = getValueFrom(optionKeyToType[key], optionKeyToWidget[key]);
DbPlugin* plugin = nullptr;