forked from qt-creator/qt-creator
refactor sessiondialog a bit
- made code more local by moving clicked slot to lambda - use class initializations - move default value inside the constructor to reduce arguments Change-Id: I98735a0b4c69ea538ed1af6133ef1054039a1b11 Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -78,21 +78,23 @@ void SessionValidator::fixup(QString &input) const
|
||||
input = copy;
|
||||
}
|
||||
|
||||
SessionNameInputDialog::SessionNameInputDialog(const QStringList &sessions, QWidget *parent)
|
||||
: QDialog(parent), m_usedSwitchTo(false)
|
||||
SessionNameInputDialog::SessionNameInputDialog(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
auto hlayout = new QVBoxLayout(this);
|
||||
auto label = new QLabel(tr("Enter the name of the session:"), this);
|
||||
hlayout->addWidget(label);
|
||||
m_newSessionLineEdit = new QLineEdit(this);
|
||||
m_newSessionLineEdit->setValidator(new SessionValidator(this, sessions));
|
||||
m_newSessionLineEdit->setValidator(new SessionValidator(this, SessionManager::sessions()));
|
||||
hlayout->addWidget(m_newSessionLineEdit);
|
||||
auto buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
|
||||
buttons->button(QDialogButtonBox::Ok)->setText(tr("&Create"));
|
||||
m_switchToButton = buttons->addButton(tr("Create and &Open"), QDialogButtonBox::AcceptRole);
|
||||
connect(m_switchToButton, &QPushButton::clicked, [this]() {
|
||||
m_usedSwitchTo = true;
|
||||
});
|
||||
connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||
connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||
connect(buttons, &QDialogButtonBox::clicked, this, &SessionNameInputDialog::clicked);
|
||||
hlayout->addWidget(buttons);
|
||||
setLayout(hlayout);
|
||||
}
|
||||
@@ -107,12 +109,6 @@ QString SessionNameInputDialog::value() const
|
||||
return m_newSessionLineEdit->text();
|
||||
}
|
||||
|
||||
void SessionNameInputDialog::clicked(QAbstractButton *button)
|
||||
{
|
||||
if (button == m_switchToButton)
|
||||
m_usedSwitchTo = true;
|
||||
}
|
||||
|
||||
bool SessionNameInputDialog::isSwitchToRequested() const
|
||||
{
|
||||
return m_usedSwitchTo;
|
||||
|
||||
@@ -59,18 +59,16 @@ class SessionNameInputDialog : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SessionNameInputDialog(const QStringList &sessions, QWidget *parent = nullptr);
|
||||
explicit SessionNameInputDialog(QWidget *parent = nullptr);
|
||||
|
||||
void setValue(const QString &value);
|
||||
QString value() const;
|
||||
bool isSwitchToRequested() const;
|
||||
|
||||
private:
|
||||
void clicked(QAbstractButton *button);
|
||||
|
||||
QLineEdit *m_newSessionLineEdit;
|
||||
QPushButton *m_switchToButton;
|
||||
bool m_usedSwitchTo;
|
||||
QLineEdit *m_newSessionLineEdit = nullptr;
|
||||
QPushButton *m_switchToButton = nullptr;
|
||||
bool m_usedSwitchTo = false;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -224,7 +224,7 @@ void SessionModel::switchToSession(const QString &session)
|
||||
|
||||
void SessionModel::runNewSessionDialog(const QString &suggestedName, std::function<void(const QString &)> createSession)
|
||||
{
|
||||
SessionNameInputDialog newSessionInputDialog(SessionManager::sessions(), nullptr);
|
||||
SessionNameInputDialog newSessionInputDialog;
|
||||
newSessionInputDialog.setWindowTitle(tr("New Session Name"));
|
||||
newSessionInputDialog.setValue(suggestedName);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user