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,38 +14,43 @@
|
|||
#include <QSpinBox>
|
||||
#include <QComboBox>
|
||||
#include <QDialog>
|
||||
#include <QDebug>
|
||||
|
||||
#define SET_OBJECT_NAME(var) var->setObjectName(#var)
|
||||
|
||||
void ConnectionConfigurationWidget::editExistingInWindow(ConnectionController *ctrl, const ConnectionConfig &cfg)
|
||||
{
|
||||
auto w = new ConnectionConfigurationWidget(ctrl->getConnectionTreeModel());
|
||||
w->setData(cfg);
|
||||
try {
|
||||
auto w = new ConnectionConfigurationWidget(ctrl->getConnectionTreeModel());
|
||||
w->setData(cfg);
|
||||
|
||||
auto btn_hbox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal);
|
||||
//auto btn_test = btn_hbox->addButton(tr("Test"), QDialogButtonBox::ActionRole);
|
||||
|
||||
auto btn_hbox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal);
|
||||
//auto btn_test = btn_hbox->addButton(tr("Test"), QDialogButtonBox::ActionRole);
|
||||
auto vbox = new QVBoxLayout;
|
||||
vbox->addWidget(w);
|
||||
vbox->addWidget(btn_hbox);
|
||||
|
||||
auto vbox = new QVBoxLayout;
|
||||
vbox->addWidget(w);
|
||||
vbox->addWidget(btn_hbox);
|
||||
auto win = new QDialog;
|
||||
win->setWindowTitle(tr("Edit connection configuration"));
|
||||
win->setLayout(vbox);
|
||||
win->setAttribute( Qt::WA_DeleteOnClose, true );
|
||||
|
||||
auto win = new QDialog;
|
||||
win->setWindowTitle(tr("Edit connection configuration"));
|
||||
win->setLayout(vbox);
|
||||
win->setAttribute( Qt::WA_DeleteOnClose, true );
|
||||
|
||||
win->connect(btn_hbox, &QDialogButtonBox::accepted, [ctrl, w, win] () {
|
||||
auto [grp, cc] = w->data();
|
||||
ctrl->getConnectionTreeModel()->save(grp, cc);
|
||||
win->accept();
|
||||
});
|
||||
win->connect(btn_hbox, &QDialogButtonBox::rejected, [win] ()
|
||||
{
|
||||
win->reject();
|
||||
QObject::connect(btn_hbox, &QDialogButtonBox::accepted, [ctrl, w, win] () {
|
||||
auto [grp, cc] = w->data();
|
||||
ctrl->getConnectionTreeModel()->save(grp, cc);
|
||||
win->accept();
|
||||
});
|
||||
QObject::connect(btn_hbox, &QDialogButtonBox::rejected, [win] ()
|
||||
{
|
||||
win->reject();
|
||||
});
|
||||
|
||||
win->show();
|
||||
win->show();
|
||||
}
|
||||
catch (const std::exception &ex) {
|
||||
qDebug() << "exception: " << QString::fromUtf8(ex.what());
|
||||
}
|
||||
}
|
||||
|
||||
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 };
|
||||
}
|
||||
|
||||
int ConnectionTreeModel::findGroup(QString name) const
|
||||
int ConnectionTreeModel::findGroup(const QString &name) const
|
||||
{
|
||||
for (int idx = 0; idx < m_groups.size(); ++idx) {
|
||||
if (m_groups[idx]->name == name) return idx;
|
||||
|
|
@ -374,7 +374,7 @@ int ConnectionTreeModel::findGroup(QString name) const
|
|||
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);
|
||||
q.prepare("INSERT INTO conngroup (gname) VALUES (:name)");
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ public:
|
|||
*/
|
||||
void save(const ConnectionConfig &cc);
|
||||
/// 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);
|
||||
int findGroup(int conngroup_id) const;
|
||||
|
||||
|
|
@ -77,7 +77,7 @@ private:
|
|||
/// Finds the connection with the specified uuid and returns
|
||||
/// { group_index, connection_index }
|
||||
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);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class ConnectionManagerWindow : public QMainWindow {
|
|||
Q_OBJECT
|
||||
public:
|
||||
explicit ConnectionManagerWindow(MasterController *master, QWidget *parent = nullptr);
|
||||
~ConnectionManagerWindow();
|
||||
~ConnectionManagerWindow() override;
|
||||
|
||||
private slots:
|
||||
void on_actionAdd_Connection_triggered();
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ private:
|
|||
std::string m_encodedPassword;
|
||||
|
||||
bool m_dirty = false;
|
||||
ConnectionGroup* m_group;
|
||||
ConnectionGroup* m_group = nullptr;
|
||||
|
||||
|
||||
static void strToEnv(QProcessEnvironment &env, const QString &var, const std::string &val);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue