When editing connection the dialog is now initialized on the correct connection group.
This commit is contained in:
parent
2823297482
commit
0fb1d89aee
4 changed files with 18 additions and 4 deletions
|
|
@ -41,22 +41,21 @@ void ConnectionConfigurationWidget::editExistingInWindow(ConnectionController *c
|
||||||
win->accept();
|
win->accept();
|
||||||
});
|
});
|
||||||
win->connect(btn_hbox, &QDialogButtonBox::rejected, [win] ()
|
win->connect(btn_hbox, &QDialogButtonBox::rejected, [win] ()
|
||||||
{
|
{
|
||||||
win->reject();
|
win->reject();
|
||||||
});
|
});
|
||||||
|
|
||||||
win->show();
|
win->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectionConfigurationWidget::ConnectionConfigurationWidget(ConnectionTreeModel *connection_model, QWidget *parent)
|
ConnectionConfigurationWidget::ConnectionConfigurationWidget(ConnectionTreeModel *connection_model, QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
|
, m_connectionModel(connection_model)
|
||||||
{
|
{
|
||||||
lblGroup = new QLabel;
|
lblGroup = new QLabel;
|
||||||
cmbbxGroup = new QComboBox;
|
cmbbxGroup = new QComboBox;
|
||||||
cmbbxGroup->setModel(connection_model);
|
cmbbxGroup->setModel(connection_model);
|
||||||
cmbbxGroup->setModelColumn(0);
|
cmbbxGroup->setModelColumn(0);
|
||||||
// cmbbxGroup->setEditable(true);
|
|
||||||
// cmbbxGroup->setInsertPolicy(QComboBox::NoInsert);
|
|
||||||
lblGroup->setBuddy(cmbbxGroup);
|
lblGroup->setBuddy(cmbbxGroup);
|
||||||
|
|
||||||
lblName = new QLabel;
|
lblName = new QLabel;
|
||||||
|
|
@ -158,6 +157,10 @@ void ConnectionConfigurationWidget::retranslateUi()
|
||||||
|
|
||||||
void ConnectionConfigurationWidget::setData(const ConnectionConfig &cfg)
|
void ConnectionConfigurationWidget::setData(const ConnectionConfig &cfg)
|
||||||
{
|
{
|
||||||
|
auto group = cfg.parent();
|
||||||
|
auto group_idx = m_connectionModel->findGroup(group->conngroup_id);
|
||||||
|
cmbbxGroup->setCurrentIndex(group_idx);
|
||||||
|
|
||||||
m_uuid = cfg.uuid();
|
m_uuid = cfg.uuid();
|
||||||
edtName->setText(stdStrToQ(cfg.name()));
|
edtName->setText(stdStrToQ(cfg.name()));
|
||||||
edtHost->setText(stdStrToQ(cfg.host()));
|
edtHost->setText(stdStrToQ(cfg.host()));
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,8 @@ public:
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
ConnectionTreeModel *m_connectionModel;
|
||||||
|
|
||||||
QUuid m_uuid;
|
QUuid m_uuid;
|
||||||
|
|
||||||
QLabel *lblGroup;
|
QLabel *lblGroup;
|
||||||
|
|
|
||||||
|
|
@ -748,6 +748,14 @@ std::optional<QSqlError> ConnectionTreeModel::removeGroup(int row)
|
||||||
m_groups.remove(row);
|
m_groups.remove(row);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ConnectionTreeModel::findGroup(int conngroup_id) const
|
||||||
|
{
|
||||||
|
auto find_res = std::find_if(m_groups.begin(), m_groups.end(),
|
||||||
|
[conngroup_id] (auto item) { return item->conngroup_id == conngroup_id; });
|
||||||
|
if (find_res == m_groups.end())
|
||||||
|
return -1;
|
||||||
|
return find_res - m_groups.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<QSqlError> ConnectionTreeModel::saveToDb(const ConnectionConfig &cc)
|
std::optional<QSqlError> ConnectionTreeModel::saveToDb(const ConnectionConfig &cc)
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,7 @@ public:
|
||||||
/// 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(QString group_name);
|
||||||
std::optional<QSqlError> removeGroup(int row);
|
std::optional<QSqlError> removeGroup(int row);
|
||||||
|
int findGroup(int conngroup_id) const;
|
||||||
private:
|
private:
|
||||||
using Groups = QVector<std::shared_ptr<ConnectionGroup>>;
|
using Groups = QVector<std::shared_ptr<ConnectionGroup>>;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue