Fix crash when starting to add connection.
Caused by uninitialized variable. Commit contains some minor style fixes also.
This commit is contained in:
parent
7f88b98cdd
commit
bcfd82c27d
5 changed files with 32 additions and 27 deletions
|
|
@ -14,15 +14,16 @@
|
||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
#define SET_OBJECT_NAME(var) var->setObjectName(#var)
|
#define SET_OBJECT_NAME(var) var->setObjectName(#var)
|
||||||
|
|
||||||
void ConnectionConfigurationWidget::editExistingInWindow(ConnectionController *ctrl, const ConnectionConfig &cfg)
|
void ConnectionConfigurationWidget::editExistingInWindow(ConnectionController *ctrl, const ConnectionConfig &cfg)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
auto w = new ConnectionConfigurationWidget(ctrl->getConnectionTreeModel());
|
auto w = new ConnectionConfigurationWidget(ctrl->getConnectionTreeModel());
|
||||||
w->setData(cfg);
|
w->setData(cfg);
|
||||||
|
|
||||||
|
|
||||||
auto btn_hbox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal);
|
auto btn_hbox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal);
|
||||||
//auto btn_test = btn_hbox->addButton(tr("Test"), QDialogButtonBox::ActionRole);
|
//auto btn_test = btn_hbox->addButton(tr("Test"), QDialogButtonBox::ActionRole);
|
||||||
|
|
||||||
|
|
@ -35,17 +36,21 @@ void ConnectionConfigurationWidget::editExistingInWindow(ConnectionController *c
|
||||||
win->setLayout(vbox);
|
win->setLayout(vbox);
|
||||||
win->setAttribute( Qt::WA_DeleteOnClose, true );
|
win->setAttribute( Qt::WA_DeleteOnClose, true );
|
||||||
|
|
||||||
win->connect(btn_hbox, &QDialogButtonBox::accepted, [ctrl, w, win] () {
|
QObject::connect(btn_hbox, &QDialogButtonBox::accepted, [ctrl, w, win] () {
|
||||||
auto [grp, cc] = w->data();
|
auto [grp, cc] = w->data();
|
||||||
ctrl->getConnectionTreeModel()->save(grp, cc);
|
ctrl->getConnectionTreeModel()->save(grp, cc);
|
||||||
win->accept();
|
win->accept();
|
||||||
});
|
});
|
||||||
win->connect(btn_hbox, &QDialogButtonBox::rejected, [win] ()
|
QObject::connect(btn_hbox, &QDialogButtonBox::rejected, [win] ()
|
||||||
{
|
{
|
||||||
win->reject();
|
win->reject();
|
||||||
});
|
});
|
||||||
|
|
||||||
win->show();
|
win->show();
|
||||||
|
}
|
||||||
|
catch (const std::exception &ex) {
|
||||||
|
qDebug() << "exception: " << QString::fromUtf8(ex.what());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectionConfigurationWidget::ConnectionConfigurationWidget(ConnectionTreeModel *connection_model, QWidget *parent)
|
ConnectionConfigurationWidget::ConnectionConfigurationWidget(ConnectionTreeModel *connection_model, QWidget *parent)
|
||||||
|
|
|
||||||
|
|
@ -366,7 +366,7 @@ std::tuple<int, int> ConnectionTreeModel::findConfig(const QUuid uuid) const
|
||||||
return { group_idx, connection_idx };
|
return { group_idx, connection_idx };
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConnectionTreeModel::findGroup(QString name) const
|
int ConnectionTreeModel::findGroup(const QString &name) const
|
||||||
{
|
{
|
||||||
for (int idx = 0; idx < m_groups.size(); ++idx) {
|
for (int idx = 0; idx < m_groups.size(); ++idx) {
|
||||||
if (m_groups[idx]->name == name) return idx;
|
if (m_groups[idx]->name == name) return idx;
|
||||||
|
|
@ -374,7 +374,7 @@ int ConnectionTreeModel::findGroup(QString name) const
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::variant<int, QSqlError> ConnectionTreeModel::addGroup(QString group_name)
|
std::variant<int, QSqlError> ConnectionTreeModel::addGroup(const QString &group_name)
|
||||||
{
|
{
|
||||||
QSqlQuery q(m_db);
|
QSqlQuery q(m_db);
|
||||||
q.prepare("INSERT INTO conngroup (gname) VALUES (:name)");
|
q.prepare("INSERT INTO conngroup (gname) VALUES (:name)");
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ public:
|
||||||
*/
|
*/
|
||||||
void save(const ConnectionConfig &cc);
|
void save(const ConnectionConfig &cc);
|
||||||
/// Create a new group in the DB and place in the tree
|
/// Create a new group in the DB and place in the tree
|
||||||
std::variant<int, QSqlError> addGroup(QString group_name);
|
std::variant<int, QSqlError> addGroup(const QString &group_name);
|
||||||
std::optional<QSqlError> removeGroup(int row);
|
std::optional<QSqlError> removeGroup(int row);
|
||||||
int findGroup(int conngroup_id) const;
|
int findGroup(int conngroup_id) const;
|
||||||
|
|
||||||
|
|
@ -77,7 +77,7 @@ private:
|
||||||
/// Finds the connection with the specified uuid and returns
|
/// Finds the connection with the specified uuid and returns
|
||||||
/// { group_index, connection_index }
|
/// { group_index, connection_index }
|
||||||
std::tuple<int, int> findConfig(const QUuid uuid) const;
|
std::tuple<int, int> findConfig(const QUuid uuid) const;
|
||||||
int findGroup(QString name) const;
|
int findGroup(const QString &name) const;
|
||||||
|
|
||||||
std::optional<QSqlError> saveToDb(const ConnectionConfig &cc);
|
std::optional<QSqlError> saveToDb(const ConnectionConfig &cc);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ class ConnectionManagerWindow : public QMainWindow {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit ConnectionManagerWindow(MasterController *master, QWidget *parent = nullptr);
|
explicit ConnectionManagerWindow(MasterController *master, QWidget *parent = nullptr);
|
||||||
~ConnectionManagerWindow();
|
~ConnectionManagerWindow() override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_actionAdd_Connection_triggered();
|
void on_actionAdd_Connection_triggered();
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,7 @@ private:
|
||||||
std::string m_encodedPassword;
|
std::string m_encodedPassword;
|
||||||
|
|
||||||
bool m_dirty = false;
|
bool m_dirty = false;
|
||||||
ConnectionGroup* m_group;
|
ConnectionGroup* m_group = nullptr;
|
||||||
|
|
||||||
|
|
||||||
static void strToEnv(QProcessEnvironment &env, const QString &var, const std::string &val);
|
static void strToEnv(QProcessEnvironment &env, const QString &var, const std::string &val);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue