Commit 5b7e8f42 authored by hjk's avatar hjk

PathChooser: Use a std::function as callback

... instead of a SLOT(...)

Change-Id: I32ed3ea014d1efde54bac2d5153f3083e37ef7ec
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent 9ff6cfdd
......@@ -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();
......
......@@ -115,8 +115,8 @@ public:
/** Return the home directory, which needs some fixing under Windows. */
static QString homePath();
void addButton(const QString &text, QObject *receiver, const char *slotFunc);
void insertButton(int index, const QString &text, QObject *receiver, const char *slotFunc);
void addButton(const QString &text, QObject *context, const std::function<void()> &callback);
void insertButton(int index, const QString &text, QObject *context, const std::function<void()> &callback);
QAbstractButton *buttonAtIndex(int index) const;
FancyLineEdit *lineEdit() const;
......@@ -144,6 +144,7 @@ private:
bool validatePath(FancyLineEdit *edit, QString *errorMessage) const;
// Returns overridden title or the one from <title>
QString makeDialogTitle(const QString &title);
void slotBrowse();
signals:
void validChanged(bool validState);
......@@ -158,10 +159,6 @@ public slots:
void setPath(const QString &);
void setFileName(const Utils::FileName &);
private slots:
void slotBrowse();
void slotTextChanged();
private:
PathChooserPrivate *d;
};
......
......@@ -278,7 +278,7 @@ CppFileSettingsWidget::CppFileSettingsWidget(QWidget *parent) :
}
m_ui->licenseTemplatePathChooser->setExpectedKind(Utils::PathChooser::File);
m_ui->licenseTemplatePathChooser->setHistoryCompleter(QLatin1String("Cpp.LicenseTemplate.History"));
m_ui->licenseTemplatePathChooser->addButton(tr("Edit..."), this, SLOT(slotEdit()));
m_ui->licenseTemplatePathChooser->addButton(tr("Edit..."), this, [this] { slotEdit(); });
}
CppFileSettingsWidget::~CppFileSettingsWidget()
......
......@@ -83,12 +83,10 @@ public:
CppFileSettings settings() const;
void setSettings(const CppFileSettings &s);
private slots:
void slotEdit();
private:
inline QString licenseTemplatePath() const;
inline void setLicenseTemplatePath(const QString &);
void slotEdit();
QString licenseTemplatePath() const;
void setLicenseTemplatePath(const QString &);
Ui::CppFileSettingsPage *m_ui;
};
......
......@@ -98,11 +98,11 @@ QWidget *HighlighterSettingsPage::widget()
m_d->m_page->definitionFilesPath->setExpectedKind(Utils::PathChooser::ExistingDirectory);
m_d->m_page->definitionFilesPath->setHistoryCompleter(QLatin1String("TextEditor.Highlighter.History"));
m_d->m_page->definitionFilesPath->addButton(tr("Download Definitions..."), this,
SLOT(requestAvailableDefinitionsMetaData()));
[this] { requestAvailableDefinitionsMetaData(); });
m_d->m_page->fallbackDefinitionFilesPath->setExpectedKind(Utils::PathChooser::ExistingDirectory);
m_d->m_page->fallbackDefinitionFilesPath->setHistoryCompleter(QLatin1String("TextEditor.Highlighter.History"));
m_d->m_page->fallbackDefinitionFilesPath->addButton(tr("Autodetect"), this,
SLOT(resetDefinitionsLocation()));
[this] { resetDefinitionsLocation(); });
settingsToUI();
......
......@@ -57,8 +57,6 @@ public:
const HighlighterSettings &highlighterSettings() const;
private slots:
void resetDefinitionsLocation();
void requestAvailableDefinitionsMetaData();
void manageDefinitions(const QList<Internal::DefinitionMetaDataPtr> &metaData);
void showError();
void ignoreDownloadReply();
......@@ -66,6 +64,8 @@ private slots:
void setDownloadDefinitionsState(bool valid);
private:
void resetDefinitionsLocation();
void requestAvailableDefinitionsMetaData();
void settingsFromUI();
void settingsToUI();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment