forked from qt-creator/qt-creator
PathChooser: Use a std::function as callback
... instead of a SLOT(...) Change-Id: I32ed3ea014d1efde54bac2d5153f3083e37ef7ec Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
@@ -211,13 +211,13 @@ PathChooser::PathChooser(QWidget *parent) :
|
||||
connect(d->m_lineEdit, &QLineEdit::textChanged, this, &PathChooser::changed);
|
||||
connect(d->m_lineEdit, &FancyLineEdit::validChanged, this, &PathChooser::validChanged);
|
||||
connect(d->m_lineEdit, &QLineEdit::editingFinished, this, &PathChooser::editingFinished);
|
||||
connect(d->m_lineEdit, &QLineEdit::textChanged, this, &PathChooser::slotTextChanged);
|
||||
connect(d->m_lineEdit, &QLineEdit::textChanged, this, [this] { emit pathChanged(path()); });
|
||||
|
||||
d->m_lineEdit->setMinimumWidth(120);
|
||||
d->m_hLayout->addWidget(d->m_lineEdit);
|
||||
d->m_hLayout->setSizeConstraint(QLayout::SetMinimumSize);
|
||||
|
||||
addButton(browseButtonLabel(), this, SLOT(slotBrowse()));
|
||||
addButton(browseButtonLabel(), this, [this] { slotBrowse(); });
|
||||
|
||||
setLayout(d->m_hLayout);
|
||||
setFocusProxy(d->m_lineEdit);
|
||||
@@ -232,16 +232,16 @@ PathChooser::~PathChooser()
|
||||
delete d;
|
||||
}
|
||||
|
||||
void PathChooser::addButton(const QString &text, QObject *receiver, const char *slotFunc)
|
||||
void PathChooser::addButton(const QString &text, QObject *context, const std::function<void ()> &callback)
|
||||
{
|
||||
insertButton(d->m_buttons.count(), text, receiver, slotFunc);
|
||||
insertButton(d->m_buttons.count(), text, context, callback);
|
||||
}
|
||||
|
||||
void PathChooser::insertButton(int index, const QString &text, QObject *receiver, const char *slotFunc)
|
||||
void PathChooser::insertButton(int index, const QString &text, QObject *context, const std::function<void ()> &callback)
|
||||
{
|
||||
QPushButton *button = new QPushButton;
|
||||
auto button = new QPushButton;
|
||||
button->setText(text);
|
||||
connect(button, SIGNAL(clicked()), receiver, slotFunc);
|
||||
connect(button, &QAbstractButton::clicked, context, callback);
|
||||
d->m_hLayout->insertWidget(index + 1/*line edit*/, button);
|
||||
d->m_buttons.insert(index, button);
|
||||
}
|
||||
@@ -415,11 +415,6 @@ void PathChooser::slotBrowse()
|
||||
triggerChanged();
|
||||
}
|
||||
|
||||
void PathChooser::slotTextChanged()
|
||||
{
|
||||
emit pathChanged(path());
|
||||
}
|
||||
|
||||
bool PathChooser::isValid() const
|
||||
{
|
||||
return d->m_lineEdit->isValid();
|
||||
|
||||
Reference in New Issue
Block a user