diff options
author | hjk <hjk@theqtcompany.com> | 2015-04-30 15:22:57 +0200 |
---|---|---|
committer | hjk <hjk@theqtcompany.com> | 2015-05-07 11:20:19 +0000 |
commit | 5b7e8f42c1bc063a744d736deec30a35458bff5f (patch) | |
tree | fae9fd0588aca8336149ae36d9960e135e60091c /src | |
parent | 9ff6cfdde4a512acc55aafe0c91ebc28f9e99cc2 (diff) | |
download | qt-creator-5b7e8f42c1bc063a744d736deec30a35458bff5f.tar.gz |
PathChooser: Use a std::function as callback
... instead of a SLOT(...)
Change-Id: I32ed3ea014d1efde54bac2d5153f3083e37ef7ec
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/utils/pathchooser.cpp | 19 | ||||
-rw-r--r-- | src/libs/utils/pathchooser.h | 9 | ||||
-rw-r--r-- | src/plugins/cpptools/cppfilesettingspage.cpp | 2 | ||||
-rw-r--r-- | src/plugins/cpptools/cppfilesettingspage.h | 8 | ||||
-rw-r--r-- | src/plugins/texteditor/generichighlighter/highlightersettingspage.cpp | 4 | ||||
-rw-r--r-- | src/plugins/texteditor/generichighlighter/highlightersettingspage.h | 4 |
6 files changed, 18 insertions, 28 deletions
diff --git a/src/libs/utils/pathchooser.cpp b/src/libs/utils/pathchooser.cpp index 7a3d444d83..952a00b010 100644 --- a/src/libs/utils/pathchooser.cpp +++ b/src/libs/utils/pathchooser.cpp @@ -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(); diff --git a/src/libs/utils/pathchooser.h b/src/libs/utils/pathchooser.h index 04c5c72df4..64beffa91a 100644 --- a/src/libs/utils/pathchooser.h +++ b/src/libs/utils/pathchooser.h @@ -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; }; diff --git a/src/plugins/cpptools/cppfilesettingspage.cpp b/src/plugins/cpptools/cppfilesettingspage.cpp index af5680b42d..960de9f597 100644 --- a/src/plugins/cpptools/cppfilesettingspage.cpp +++ b/src/plugins/cpptools/cppfilesettingspage.cpp @@ -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() diff --git a/src/plugins/cpptools/cppfilesettingspage.h b/src/plugins/cpptools/cppfilesettingspage.h index a2920a71f9..84ad6529a9 100644 --- a/src/plugins/cpptools/cppfilesettingspage.h +++ b/src/plugins/cpptools/cppfilesettingspage.h @@ -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; }; diff --git a/src/plugins/texteditor/generichighlighter/highlightersettingspage.cpp b/src/plugins/texteditor/generichighlighter/highlightersettingspage.cpp index ea904d7286..fd5a41649a 100644 --- a/src/plugins/texteditor/generichighlighter/highlightersettingspage.cpp +++ b/src/plugins/texteditor/generichighlighter/highlightersettingspage.cpp @@ -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(); diff --git a/src/plugins/texteditor/generichighlighter/highlightersettingspage.h b/src/plugins/texteditor/generichighlighter/highlightersettingspage.h index 4c19e67fd0..2cc35af0b8 100644 --- a/src/plugins/texteditor/generichighlighter/highlightersettingspage.h +++ b/src/plugins/texteditor/generichighlighter/highlightersettingspage.h @@ -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(); |