mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2026-03-09 15:20:06 -04:00
refactor: Refactors AgentRoleDialog's modes handling (#325)
* fix: Fixes `undefined-bool-conversion` compilation warning. * refactor: Replaces `AgentRoleDialog::m_editMode` with `AgentRoleDialog::m_action` --------- Co-authored-by: Ivan Lebedev <ilebedev@flightpath3d.com>
This commit is contained in:
@ -29,21 +29,24 @@
|
|||||||
|
|
||||||
namespace QodeAssist::Settings {
|
namespace QodeAssist::Settings {
|
||||||
|
|
||||||
AgentRoleDialog::AgentRoleDialog(QWidget *parent)
|
AgentRoleDialog::AgentRoleDialog(Action action, QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog{parent}
|
||||||
, m_editMode(false)
|
, m_action{action}
|
||||||
{
|
{
|
||||||
setWindowTitle(tr("Add Agent Role"));
|
auto getTitle = [](Action action) {
|
||||||
setupUI();
|
switch(action)
|
||||||
}
|
{
|
||||||
|
case Action::Add:
|
||||||
|
return tr("Add Agent Role");
|
||||||
|
case Action::Duplicate:
|
||||||
|
return tr("Duplicate Agent Role");
|
||||||
|
case Action::Edit:
|
||||||
|
return tr("Edit Agent Role");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
AgentRoleDialog::AgentRoleDialog(const AgentRole &role, bool editMode, QWidget *parent)
|
setWindowTitle(getTitle(action));
|
||||||
: QDialog(parent)
|
|
||||||
, m_editMode(editMode)
|
|
||||||
{
|
|
||||||
setWindowTitle(editMode ? tr("Edit Agent Role") : tr("Duplicate Agent Role"));
|
|
||||||
setupUI();
|
setupUI();
|
||||||
setRole(role);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AgentRoleDialog::setupUI()
|
void AgentRoleDialog::setupUI()
|
||||||
@ -83,7 +86,7 @@ void AgentRoleDialog::setupUI()
|
|||||||
connect(m_idEdit, &QLineEdit::textChanged, this, &AgentRoleDialog::validateInput);
|
connect(m_idEdit, &QLineEdit::textChanged, this, &AgentRoleDialog::validateInput);
|
||||||
connect(m_systemPromptEdit, &QTextEdit::textChanged, this, &AgentRoleDialog::validateInput);
|
connect(m_systemPromptEdit, &QTextEdit::textChanged, this, &AgentRoleDialog::validateInput);
|
||||||
|
|
||||||
if (m_editMode) {
|
if (m_action == Action::Edit) {
|
||||||
m_idEdit->setEnabled(false);
|
m_idEdit->setEnabled(false);
|
||||||
m_idEdit->setToolTip(tr("ID cannot be changed for existing roles"));
|
m_idEdit->setToolTip(tr("ID cannot be changed for existing roles"));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,8 +34,18 @@ class AgentRoleDialog : public QDialog
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AgentRoleDialog(QWidget *parent = nullptr);
|
enum class Action {
|
||||||
explicit AgentRoleDialog(const AgentRole &role, bool editMode = true, QWidget *parent = nullptr);
|
Add,
|
||||||
|
Duplicate,
|
||||||
|
Edit,
|
||||||
|
};
|
||||||
|
|
||||||
|
explicit AgentRoleDialog(Action action, QWidget *parent = nullptr);
|
||||||
|
explicit AgentRoleDialog(const AgentRole &role, Action action, QWidget *parent = nullptr)
|
||||||
|
: AgentRoleDialog{action, parent}
|
||||||
|
{
|
||||||
|
setRole(role);
|
||||||
|
}
|
||||||
|
|
||||||
AgentRole getRole() const;
|
AgentRole getRole() const;
|
||||||
void setRole(const AgentRole &role);
|
void setRole(const AgentRole &role);
|
||||||
@ -49,7 +59,7 @@ private:
|
|||||||
QTextEdit *m_descriptionEdit = nullptr;
|
QTextEdit *m_descriptionEdit = nullptr;
|
||||||
QTextEdit *m_systemPromptEdit = nullptr;
|
QTextEdit *m_systemPromptEdit = nullptr;
|
||||||
QDialogButtonBox *m_buttonBox = nullptr;
|
QDialogButtonBox *m_buttonBox = nullptr;
|
||||||
bool m_editMode = false;
|
Action m_action;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QodeAssist::Settings
|
} // namespace QodeAssist::Settings
|
||||||
|
|||||||
@ -129,7 +129,7 @@ void AgentRolesWidget::updateButtons()
|
|||||||
|
|
||||||
void AgentRolesWidget::onAddRole()
|
void AgentRolesWidget::onAddRole()
|
||||||
{
|
{
|
||||||
AgentRoleDialog dialog(this);
|
AgentRoleDialog dialog{AgentRoleDialog::Action::Add, this};
|
||||||
if (dialog.exec() != QDialog::Accepted)
|
if (dialog.exec() != QDialog::Accepted)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -170,7 +170,7 @@ void AgentRolesWidget::onEditRole()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
AgentRoleDialog dialog(role, this);
|
AgentRoleDialog dialog{role, AgentRoleDialog::Action::Edit, this};
|
||||||
if (dialog.exec() != QDialog::Accepted)
|
if (dialog.exec() != QDialog::Accepted)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -203,7 +203,7 @@ void AgentRolesWidget::onDuplicateRole()
|
|||||||
role.id = baseId + QString::number(counter++);
|
role.id = baseId + QString::number(counter++);
|
||||||
}
|
}
|
||||||
|
|
||||||
AgentRoleDialog dialog(role, false, this);
|
AgentRoleDialog dialog{role, AgentRoleDialog::Action::Duplicate, this};
|
||||||
if (dialog.exec() != QDialog::Accepted)
|
if (dialog.exec() != QDialog::Accepted)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user