diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ include(KDECMakeSettings) include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE) -include(GenerateExportHeader) +include(ECMGenerateExportHeader) include(ECMSetupVersion) include(ECMGenerateHeaders) include(CMakePackageConfigHelpers) @@ -37,6 +37,7 @@ find_package(KF5Config ${KF5_DEP_VERSION} REQUIRED) find_package(KF5WidgetsAddons ${KF5_DEP_VERSION} REQUIRED) +set(EXCLUDE_DEPRECATED_BEFORE_AND_AT 0 CACHE STRING "Control the range of deprecated API excluded from the build [default=0].") option(BUILD_QCH "Build API documentation in QCH format (for e.g. Qt Assistant, Qt Creator & KDevelop)" OFF) add_feature_info(QCH ${BUILD_QCH} "API documentation in QCH format (for e.g. Qt Assistant, Qt Creator & KDevelop)") diff --git a/autotests/klineedit_unittest.cpp b/autotests/klineedit_unittest.cpp --- a/autotests/klineedit_unittest.cpp +++ b/autotests/klineedit_unittest.cpp @@ -59,19 +59,19 @@ // setText emits textChanged and userTextChanged, but not textEdited QSignalSpy textChangedSpy(&w, SIGNAL(textChanged(QString))); QSignalSpy textEditedSpy(&w, SIGNAL(textEdited(QString))); -#ifndef KCOMPLETION_NO_DEPRECATED +#if KCOMPLETION_ENABLE_DEPRECATED_SINCE(4, 5) QSignalSpy userTextChangedSpy(&w, SIGNAL(userTextChanged(QString))); #endif w.setText(QStringLiteral("Hello worl")); -#ifndef KCOMPLETION_NO_DEPRECATED +#if KCOMPLETION_ENABLE_DEPRECATED_SINCE(4, 5) QCOMPARE(userTextChangedSpy.count(), 1); QCOMPARE(userTextChangedSpy[0][0].toString(), w.text()); #endif QCOMPARE(textChangedSpy.count(), 1); QCOMPARE(textChangedSpy[0][0].toString(), w.text()); QCOMPARE(textEditedSpy.count(), 0); QVERIFY(!w.isModified()); -#ifndef KCOMPLETION_NO_DEPRECATED +#if KCOMPLETION_ENABLE_DEPRECATED_SINCE(4, 5) userTextChangedSpy.clear(); #endif textChangedSpy.clear(); @@ -81,31 +81,31 @@ w.clear(); QCOMPARE(textChangedSpy.count(),1); QCOMPARE(textEditedSpy.count(),0); -#ifndef KCOMPLETION_NO_DEPRECATED +#if KCOMPLETION_ENABLE_DEPRECATED_SINCE(4, 5) QCOMPARE(userTextChangedSpy.count(),1); #endif //if text box is already empty, calling clear() shouldn't emit // any more signals w.clear(); QCOMPARE(textChangedSpy.count(),1); QCOMPARE(textEditedSpy.count(),0); -#ifndef KCOMPLETION_NO_DEPRECATED +#if KCOMPLETION_ENABLE_DEPRECATED_SINCE(4, 5) QCOMPARE(userTextChangedSpy.count(),1); #endif //set the text back for further tests below w.setText(QStringLiteral("Hello worl")); -#ifndef KCOMPLETION_NO_DEPRECATED +#if KCOMPLETION_ENABLE_DEPRECATED_SINCE(4, 5) userTextChangedSpy.clear(); #endif textChangedSpy.clear(); textEditedSpy.clear(); // typing emits all three signals QTest::keyClick(&w, Qt::Key_D); QCOMPARE(w.text(), QString::fromLatin1("Hello world")); -#ifndef KCOMPLETION_NO_DEPRECATED +#if KCOMPLETION_ENABLE_DEPRECATED_SINCE(4, 5) QCOMPARE(userTextChangedSpy.count(), 1); QCOMPARE(userTextChangedSpy[0][0].toString(), w.text()); #endif @@ -116,7 +116,7 @@ QVERIFY(w.isModified()); w.setText(QStringLiteral("K")); // prepare for next test -#ifndef KCOMPLETION_NO_DEPRECATED +#if KCOMPLETION_ENABLE_DEPRECATED_SINCE(4, 5) userTextChangedSpy.clear(); #endif textChangedSpy.clear(); @@ -135,14 +135,14 @@ w.doCompletion(w.text()); QCOMPARE(w.text(), items.at(0)); -#ifndef KCOMPLETION_NO_DEPRECATED +#if KCOMPLETION_ENABLE_DEPRECATED_SINCE(4, 5) QCOMPARE(userTextChangedSpy.count(), 0); #endif QCOMPARE(textChangedSpy.count(), 1); QCOMPARE(textChangedSpy[0][0].toString(), w.text()); QCOMPARE(textEditedSpy.count(), 0); QVERIFY(!w.isModified()); -#ifndef KCOMPLETION_NO_DEPRECATED +#if KCOMPLETION_ENABLE_DEPRECATED_SINCE(4, 5) userTextChangedSpy.clear(); #endif textChangedSpy.clear(); @@ -152,16 +152,16 @@ QTest::keyClick(&w, Qt::Key_Right); QCOMPARE(w.text(), items.at(0)); -#ifndef KCOMPLETION_NO_DEPRECATED +#if KCOMPLETION_ENABLE_DEPRECATED_SINCE(4, 5) QCOMPARE(userTextChangedSpy.count(), 1); QCOMPARE(userTextChangedSpy[0][0].toString(), w.text()); #endif QCOMPARE(textChangedSpy.count(), 1); QCOMPARE(textChangedSpy[0][0].toString(), w.text()); QCOMPARE(textEditedSpy.count(), 1); QCOMPARE(textEditedSpy[0][0].toString(), w.text()); QVERIFY(w.isModified()); -#ifndef KCOMPLETION_NO_DEPRECATED +#if KCOMPLETION_ENABLE_DEPRECATED_SINCE(4, 5) userTextChangedSpy.clear(); #endif textChangedSpy.clear(); @@ -171,14 +171,14 @@ w.setCompletionMode(KCompletion::CompletionPopup); w.setText(QStringLiteral("KDE")); QVERIFY(!w.isModified()); -#ifndef KCOMPLETION_NO_DEPRECATED +#if KCOMPLETION_ENABLE_DEPRECATED_SINCE(4, 5) userTextChangedSpy.clear(); #endif textChangedSpy.clear(); textEditedSpy.clear(); w.doCompletion(w.text()); // popup appears QCOMPARE(w.text(), QString::fromLatin1("KDE")); -#ifndef KCOMPLETION_NO_DEPRECATED +#if KCOMPLETION_ENABLE_DEPRECATED_SINCE(4, 5) QCOMPARE(textChangedSpy.count() + userTextChangedSpy.count() + textEditedSpy.count(), 0); #else QCOMPARE(textChangedSpy.count() + textEditedSpy.count(), 0); @@ -191,12 +191,12 @@ // Selecting an item in the popup completion changes the lineedit text // and emits textChanged and userTextChanged, but not textEdited. -#ifndef KCOMPLETION_NO_DEPRECATED +#if KCOMPLETION_ENABLE_DEPRECATED_SINCE(4, 5) QCOMPARE(userTextChangedSpy.count(), 2); #endif QCOMPARE(textChangedSpy.count(), 2); QCOMPARE(textEditedSpy.count(), 0); -#ifndef KCOMPLETION_NO_DEPRECATED +#if KCOMPLETION_ENABLE_DEPRECATED_SINCE(4, 5) userTextChangedSpy.clear(); #endif textChangedSpy.clear(); @@ -209,7 +209,7 @@ // Nothing else happens, the text was already set in the lineedit QCOMPARE(textChangedSpy.count(), 0); QCOMPARE(textEditedSpy.count(), 0); -#ifndef KCOMPLETION_NO_DEPRECATED +#if KCOMPLETION_ENABLE_DEPRECATED_SINCE(4, 5) QCOMPARE(userTextChangedSpy.count(), 0); #endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,8 +15,15 @@ ) add_library(KF5Completion ${kcompletion_SRCS}) -generate_export_header(KF5Completion BASE_NAME KCompletion) add_library(KF5::Completion ALIAS KF5Completion) +ecm_generate_export_header(KF5Completion + BASE_NAME KCompletion + # GROUP_BASE_NAME KF <- enable once all of KF modules use ecm_generate_export_header + VERSION ${KF5_VERSION} + DEPRECATED_BASE_VERSION 0 + DEPRECATION_VERSIONS 4.0 4.5 5.0 5.46 + EXCLUDE_DEPRECATED_BEFORE_AND_AT ${EXCLUDE_DEPRECATED_BEFORE_AND_AT} +) target_include_directories(KF5Completion INTERFACE "$") diff --git a/src/kcombobox.h b/src/kcombobox.h --- a/src/kcombobox.h +++ b/src/kcombobox.h @@ -146,7 +146,7 @@ { Q_OBJECT Q_PROPERTY(bool autoCompletion READ autoCompletion WRITE setAutoCompletion) -#ifndef KCOMPLETION_NO_DEPRECATED +#if KCOMPLETION_BUILD_DEPRECATED_SINCE(5, 0) Q_PROPERTY(bool urlDropsEnabled READ urlDropsEnabled WRITE setUrlDropsEnabled) #endif Q_PROPERTY(bool trapReturnKey READ trapReturnKey WRITE setTrapReturnKey) @@ -174,24 +174,28 @@ */ ~KComboBox() override; +#if KCOMPLETION_ENABLE_DEPRECATED_SINCE(4, 5) /** * Deprecated to reflect Qt api changes * @deprecated since 4.5 */ -#ifndef KCOMPLETION_NO_DEPRECATED - KCOMPLETION_DEPRECATED void insertURL(const QUrl &url, int index = -1) + KCOMPLETION_DEPRECATED_VERSION(4, 5, "Use KComboBox::insertUrl(int, const QUrl&)") + void insertURL(const QUrl &url, int index = -1) { insertUrl(index < 0 ? count() : index, url); } - KCOMPLETION_DEPRECATED void insertURL(const QPixmap &pixmap, const QUrl &url, int index = -1) + KCOMPLETION_DEPRECATED_VERSION(4, 5, "Use KComboBox::insertUrl(int, const QIcon&, const QUrl&)") + void insertURL(const QPixmap &pixmap, const QUrl &url, int index = -1) { insertUrl(index < 0 ? count() : index, QIcon(pixmap), url); } - KCOMPLETION_DEPRECATED void changeURL(const QUrl &url, int index) + KCOMPLETION_DEPRECATED_VERSION(4, 5, "Use KComboBox::changeUrl(int, const QUrl&)") + void changeURL(const QUrl &url, int index) { changeUrl(index, url); } - KCOMPLETION_DEPRECATED void changeURL(const QPixmap &pixmap, const QUrl &url, int index) + KCOMPLETION_DEPRECATED_VERSION(4, 5, "Use KComboBox::changeUrl(int, const QIcon&, const QUrl&)") + void changeURL(const QPixmap &pixmap, const QUrl &url, int index) { changeUrl(index, QIcon(pixmap), url); } @@ -287,6 +291,7 @@ */ bool autoCompletion() const; +#if KCOMPLETION_BUILD_DEPRECATED_SINCE(4, 5) /** * Enables or disables the popup (context) menu. * @@ -301,10 +306,11 @@ * @param showMenu If @c true, show the context menu. * @deprecated since 4.5, use setContextMenuPolicy instead */ -#ifndef KCOMPLETION_NO_DEPRECATED - virtual KCOMPLETION_DEPRECATED void setContextMenuEnabled(bool showMenu); + KCOMPLETION_DEPRECATED_VERSION(4, 5, "Use QWidget::setContextMenuPolicy(...)") + virtual void setContextMenuEnabled(bool showMenu); #endif +#if KCOMPLETION_ENABLE_DEPRECATED_SINCE(5, 0) /** * Enables/Disables handling of URL drops. * @@ -315,8 +321,8 @@ * @param enable If @c true, insert decoded URLs * @deprecated since 5.0. Use lineEdit()->installEventFilter with a LineEditUrlDropEventFilter */ -#ifndef KCOMPLETION_NO_DEPRECATED - KCOMPLETION_DEPRECATED void setUrlDropsEnabled(bool enable); + KCOMPLETION_DEPRECATED_VERSION(5, 0, "Use KComboBox::lineEdit()->installEventFilter(...) with a LineEditUrlDropEventFilter") + void setUrlDropsEnabled(bool enable); #endif /** diff --git a/src/kcombobox.cpp b/src/kcombobox.cpp --- a/src/kcombobox.cpp +++ b/src/kcombobox.cpp @@ -133,15 +133,17 @@ return completionMode() == KCompletion::CompletionAuto; } -#ifndef KCOMPLETION_NO_DEPRECATED +#if KCOMPLETION_BUILD_DEPRECATED_SINCE(4, 5) void KComboBox::setContextMenuEnabled(bool showMenu) { Q_D(KComboBox); if (d->klineEdit) { d->klineEdit->setContextMenuPolicy(showMenu ? Qt::DefaultContextMenu : Qt::NoContextMenu); } } +#endif +#if KCOMPLETION_BUILD_DEPRECATED_SINCE(5, 0) void KComboBox::setUrlDropsEnabled(bool enable) { Q_D(KComboBox); diff --git a/src/kcompletionbase.h b/src/kcompletionbase.h --- a/src/kcompletionbase.h +++ b/src/kcompletionbase.h @@ -261,11 +261,12 @@ */ QList keyBinding(KeyBindingType item) const; +#if KCOMPLETION_ENABLE_DEPRECATED_SINCE(5, 0) /** * @deprecated since 5.0, use keyBinding instead */ -#ifndef KCOMPLETION_NO_DEPRECATED - KCOMPLETION_DEPRECATED QList getKeyBinding(KeyBindingType item) const + KCOMPLETION_DEPRECATED_VERSION(5, 0, "Use KCompletionBase::keyBinding(KeyBindingType)") + QList getKeyBinding(KeyBindingType item) const { return keyBinding(item); } @@ -334,11 +335,12 @@ */ KeyBindingMap keyBindingMap() const; +#if KCOMPLETION_ENABLE_DEPRECATED_SINCE(5, 0) /** * @deprecated since 5.0, use keyBindingMap instead */ -#ifndef KCOMPLETION_NO_DEPRECATED - KCOMPLETION_DEPRECATED KeyBindingMap getKeyBindings() const + KCOMPLETION_DEPRECATED_VERSION(5, 0, "Use KCompletionBase::keyBindingMap()") + KeyBindingMap getKeyBindings() const { return keyBindingMap(); } diff --git a/src/kcompletionbox.h b/src/kcompletionbox.h --- a/src/kcompletionbox.h +++ b/src/kcompletionbox.h @@ -208,11 +208,12 @@ */ QRect calculateGeometry() const; +#if KCOMPLETION_ENABLE_DEPRECATED_SINCE(5, 0) /** * @deprecated since 5.0, use resizeAndReposition instead. */ -#ifndef KCOMPLETION_NO_DEPRECATED - KCOMPLETION_DEPRECATED void sizeAndPosition() + KCOMPLETION_DEPRECATED_VERSION(5, 0, "Use KCompletionBox::resizeAndReposition()") + void sizeAndPosition() { resizeAndReposition(); } diff --git a/src/klineedit.h b/src/klineedit.h --- a/src/klineedit.h +++ b/src/klineedit.h @@ -157,18 +157,20 @@ Q_OBJECT Q_DECLARE_PRIVATE(KLineEdit) -#ifndef KCOMPLETION_NO_DEPRECATED +#if KCOMPLETION_BUILD_DEPRECATED_SINCE(4, 5) Q_PROPERTY(bool contextMenuEnabled READ isContextMenuEnabled WRITE setContextMenuEnabled) #endif -#ifndef KCOMPLETION_NO_DEPRECATED +#if KCOMPLETION_BUILD_DEPRECATED_SINCE(5, 0) Q_PROPERTY(bool urlDropsEnabled READ urlDropsEnabled WRITE setUrlDropsEnabled) #endif Q_PROPERTY(bool trapEnterKeyEvent READ trapReturnKey WRITE setTrapReturnKey) Q_PROPERTY(bool squeezedTextEnabled READ isSqueezedTextEnabled WRITE setSqueezedTextEnabled) -#ifndef KCOMPLETION_NO_DEPRECATED +#if KCOMPLETION_BUILD_DEPRECATED_SINCE(5, 0) Q_PROPERTY(QString clickMessage READ clickMessage WRITE setClickMessage) #endif +#if KCOMPLETION_BUILD_DEPRECATED_SINCE(5, 46) Q_PROPERTY(bool showClearButton READ isClearButtonShown WRITE setClearButtonShown) +#endif Q_PROPERTY(bool passwordMode READ passwordMode WRITE setPasswordMode) public: @@ -217,6 +219,7 @@ */ void setCompletionModeDisabled(KCompletion::CompletionMode mode, bool disable = true); +#if KCOMPLETION_BUILD_DEPRECATED_SINCE(4, 5) /** * Enables/disables the popup (context) menu. * @@ -231,16 +234,17 @@ * @param showMenu If @c true, show the context menu. * @deprecated since 4.5, use setContextMenuPolicy instead */ -#ifndef KCOMPLETION_NO_DEPRECATED - virtual KCOMPLETION_DEPRECATED void setContextMenuEnabled(bool showMenu); + KCOMPLETION_DEPRECATED_VERSION(4, 5, "Use QWidget::setContextMenuPolicy(Qt::ContextMenuPolicy)") + virtual void setContextMenuEnabled(bool showMenu); #endif +#if KCOMPLETION_ENABLE_DEPRECATED_SINCE(4, 5) /** * Returns @c true when the context menu is enabled. * @deprecated since 4.5, use contextMenuPolicy instead */ -#ifndef KCOMPLETION_NO_DEPRECATED - KCOMPLETION_DEPRECATED bool isContextMenuEnabled() const; + KCOMPLETION_DEPRECATED_VERSION(4, 5, "Use QWidget::contextMenuPolicy()") + bool isContextMenuEnabled() const; #endif /** @@ -342,42 +346,46 @@ */ void setCompletionBox(KCompletionBox *box); +#if KCOMPLETION_ENABLE_DEPRECATED_SINCE(5, 0) /** * This makes the line edit display a grayed-out hinting text as long as * the user didn't enter any text. It is often used as indication about * the purpose of the line edit. * @deprecated since 5.0, use QLineEdit::setPlaceholderText instead. */ -#ifndef KCOMPLETION_NO_DEPRECATED - KCOMPLETION_DEPRECATED void setClickMessage(const QString &msg); + KCOMPLETION_DEPRECATED_VERSION(5, 0, "Use QLineEdit::setPlaceholderText(const QString&)") + void setClickMessage(const QString &msg); #endif +#if KCOMPLETION_ENABLE_DEPRECATED_SINCE(5, 0) /** * @return the message set with setClickMessage * @deprecated since 5.0, use QLineEdit::placeholderText instead. */ -#ifndef KCOMPLETION_NO_DEPRECATED - KCOMPLETION_DEPRECATED QString clickMessage() const; + KCOMPLETION_DEPRECATED_VERSION(5, 0, "Use QLineEdit::placeholderText()") + QString clickMessage() const; #endif +#if KCOMPLETION_ENABLE_DEPRECATED_SINCE(5, 46) /** * This makes the line edit display an icon on one side of the line edit * which, when clicked, clears the contents of the line edit. * This is useful for such things as location or search bars. * * @deprecated since 5.46 Use QLineEdit::setClearButtonEnabled **/ -#ifndef KCOMPLETION_NO_DEPRECATED - KCOMPLETION_DEPRECATED void setClearButtonShown(bool show); + KCOMPLETION_DEPRECATED_VERSION(5, 46, "Use QLineEdit::setClearButtonEnabled(bool)") + void setClearButtonShown(bool show); #endif +#if KCOMPLETION_ENABLE_DEPRECATED_SINCE(5, 46) /** * @return whether or not the clear button is shown * * @deprecated since 5.46 Use QLineEdit::isClearButtonEnabled **/ -#ifndef KCOMPLETION_NO_DEPRECATED - KCOMPLETION_DEPRECATED bool isClearButtonShown() const; + KCOMPLETION_DEPRECATED_VERSION(5, 46, "Use QLineEdit::isClearButtonEnabled()") + bool isClearButtonShown() const; #endif /** @@ -425,6 +433,7 @@ */ void substringCompletion(const QString &); +#if KCOMPLETION_ENABLE_DEPRECATED_SINCE(4, 5) /** * Emitted when the text is changed NOT by the suggested autocompletion: * either when the user is physically typing keys, or when the text is changed programmatically, @@ -437,7 +446,7 @@ * (by typing or accepting autocompletion), without side effects from * suggested autocompletion either. userTextChanged isn't needed anymore. */ -#ifndef KCOMPLETION_NO_DEPRECATED + KCOMPLETION_DEPRECATED_VERSION(4, 5, "Use QLineEdit::textEdited(const QString&)") QT_MOC_COMPAT void userTextChanged(const QString &); #endif diff --git a/src/klineedit.cpp b/src/klineedit.cpp --- a/src/klineedit.cpp +++ b/src/klineedit.cpp @@ -54,7 +54,7 @@ // COMPAT (as documented): emit userTextChanged whenever textChanged is emitted if (!completionRunning && (text != userText)) { userText = text; -#ifndef KCOMPLETION_NO_DEPRECATED +#if KCOMPLETION_BUILD_DEPRECATED_SINCE(4, 5) emit q->userTextChanged(text); #endif } @@ -68,7 +68,7 @@ if (!completionRunning && (text != userText)) { userText = text; q->setModified(true); -#ifndef KCOMPLETION_NO_DEPRECATED +#if KCOMPLETION_BUILD_DEPRECATED_SINCE(4, 5) emit q->userTextChanged(text); #endif emit q->textEdited(text); @@ -155,22 +155,26 @@ { } -#ifndef KCOMPLETION_NO_DEPRECATED +#if KCOMPLETION_BUILD_DEPRECATED_SINCE(5, 0) QString KLineEdit::clickMessage() const { return placeholderText(); } #endif +#if KCOMPLETION_BUILD_DEPRECATED_SINCE(5, 46) void KLineEdit::setClearButtonShown(bool show) { setClearButtonEnabled(show); } +#endif +#if KCOMPLETION_BUILD_DEPRECATED_SINCE(5, 46) bool KLineEdit::isClearButtonShown() const { return isClearButtonEnabled(); } +#endif QSize KLineEdit::clearButtonUsedSize() const { @@ -1072,7 +1076,7 @@ return QLineEdit::event(ev); } -#ifndef KCOMPLETION_NO_DEPRECATED +#if KCOMPLETION_BUILD_DEPRECATED_SINCE(5, 0) void KLineEdit::setUrlDropsEnabled(bool enable) { Q_D(KLineEdit); @@ -1425,21 +1429,21 @@ } } -#ifndef KCOMPLETION_NO_DEPRECATED +#if KCOMPLETION_BUILD_DEPRECATED_SINCE(5, 0) void KLineEdit::setClickMessage(const QString &msg) { setPlaceholderText(msg); } #endif -#ifndef KCOMPLETION_NO_DEPRECATED +#if KCOMPLETION_BUILD_DEPRECATED_SINCE(4, 5) void KLineEdit::setContextMenuEnabled(bool showMenu) { QLineEdit::setContextMenuPolicy(showMenu ? Qt::DefaultContextMenu : Qt::NoContextMenu); } #endif -#ifndef KCOMPLETION_NO_DEPRECATED +#if KCOMPLETION_BUILD_DEPRECATED_SINCE(4, 5) bool KLineEdit::isContextMenuEnabled() const { return (contextMenuPolicy() == Qt::DefaultContextMenu); diff --git a/src/ksortablelist.h b/src/ksortablelist.h --- a/src/ksortablelist.h +++ b/src/ksortablelist.h @@ -130,12 +130,13 @@ return this->second; } +#if KCOMPLETION_ENABLE_DEPRECATED_SINCE(4, 0) /** * @return the first value (the key) - * @deprecated use key() + * @deprecated Since 4.0. Use key() */ -#ifndef KCOMPLETION_NO_DEPRECATED - KCOMPLETION_DEPRECATED Key index() const + KCOMPLETION_DEPRECATED_VERSION(4, 0, "Use KSortableItem::key()") + Key index() const { return this->first; }