When editing connection the dialog is now initialized on the correct connection group.

This commit is contained in:
eelke 2019-09-01 06:44:48 +02:00
parent 2823297482
commit 0fb1d89aee
4 changed files with 18 additions and 4 deletions

View file

@ -41,22 +41,21 @@ void ConnectionConfigurationWidget::editExistingInWindow(ConnectionController *c
win->accept();
});
win->connect(btn_hbox, &QDialogButtonBox::rejected, [win] ()
{
{
win->reject();
});
});
win->show();
}
ConnectionConfigurationWidget::ConnectionConfigurationWidget(ConnectionTreeModel *connection_model, QWidget *parent)
: QWidget(parent)
, m_connectionModel(connection_model)
{
lblGroup = new QLabel;
cmbbxGroup = new QComboBox;
cmbbxGroup->setModel(connection_model);
cmbbxGroup->setModelColumn(0);
// cmbbxGroup->setEditable(true);
// cmbbxGroup->setInsertPolicy(QComboBox::NoInsert);
lblGroup->setBuddy(cmbbxGroup);
lblName = new QLabel;
@ -158,6 +157,10 @@ void ConnectionConfigurationWidget::retranslateUi()
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();
edtName->setText(stdStrToQ(cfg.name()));
edtHost->setText(stdStrToQ(cfg.host()));

View file

@ -30,6 +30,8 @@ public:
signals:
private:
ConnectionTreeModel *m_connectionModel;
QUuid m_uuid;
QLabel *lblGroup;

View file

@ -748,6 +748,14 @@ std::optional<QSqlError> ConnectionTreeModel::removeGroup(int row)
m_groups.remove(row);
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)

View file

@ -63,6 +63,7 @@ public:
/// Create a new group in the DB and place in the tree
std::variant<int, QSqlError> addGroup(QString group_name);
std::optional<QSqlError> removeGroup(int row);
int findGroup(int conngroup_id) const;
private:
using Groups = QVector<std::shared_ptr<ConnectionGroup>>;