[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdevelop] plugins: Port away from deprecated KFilterProxySearchLine
From:       Friedrich W. H. Kossebau <null () kde ! org>
Date:       2018-09-11 9:16:11
Message-ID: E1fzemJ-00022v-Mv () code ! kde ! org
[Download RAW message or body]

Git commit 81278baa7c03d292a60bb40826bc577c5078dbc2 by Friedrich W. H. Kossebau.
Committed on 11/09/2018 at 09:16.
Pushed by kossebau into branch 'master'.

Port away from deprecated KFilterProxySearchLine

Summary:
The clazy & cppcheck config UIs did not even make use of attaching the
search line to a proxy model.

Reviewers: #kdevelop, antonanikin

Reviewed By: #kdevelop, antonanikin

Subscribers: antonanikin, kdevelop-devel

Tags: #kdevelop

Differential Revision: https://phabricator.kde.org/D15415

M  +2    -2    plugins/clazy/config/commandlinewidget.cpp
M  +8    -8    plugins/clazy/config/commandlinewidget.ui
M  +0    -1    plugins/cppcheck/CMakeLists.txt
M  +2    -2    plugins/cppcheck/config/projectconfigpage.cpp
M  +8    -6    plugins/cppcheck/config/projectconfigpage.ui
M  +5    -1    plugins/kdeprovider/CMakeLists.txt
A  +58   -0    plugins/kdeprovider/filterproxysearchline.cpp     [License: LGPL \
(v2+)] C  +24   -21   plugins/kdeprovider/filterproxysearchline.h [from: \
plugins/kdeprovider/kdeproviderwidget.h - 052% similarity] M  +6    -3    \
plugins/kdeprovider/kdeproviderwidget.cpp M  +1    -1    \
plugins/kdeprovider/kdeproviderwidget.h

https://commits.kde.org/kdevelop/81278baa7c03d292a60bb40826bc577c5078dbc2

diff --git a/plugins/clazy/config/commandlinewidget.cpp \
b/plugins/clazy/config/commandlinewidget.cpp index c97ce9f9a4..644e479e8b 100644
--- a/plugins/clazy/config/commandlinewidget.cpp
+++ b/plugins/clazy/config/commandlinewidget.cpp
@@ -34,7 +34,7 @@ CommandLineWidget::CommandLineWidget(QWidget* parent)
     m_ui->setupUi(this);
     m_ui->cmdEdit->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
 
-    connect(m_ui->cmdFilter->lineEdit(), &QLineEdit::textChanged, this, \
&CommandLineWidget::updateCommandLine); +    connect(m_ui->cmdFilter, \
                &QLineEdit::textChanged, this, \
                &CommandLineWidget::updateCommandLine);
     connect(m_ui->cmdBreak, &QCheckBox::stateChanged, this, \
&CommandLineWidget::updateCommandLine);  }
 
@@ -56,7 +56,7 @@ void CommandLineWidget::updateCommandLine()
         commandLine.replace(QLatin1String(","), QLatin1String("\n,"));
     }
 
-    auto filterText = m_ui->cmdFilter->lineEdit()->text();
+    auto filterText = m_ui->cmdFilter->text();
     if (!filterText.isEmpty()) {
         QStringList lines = commandLine.split(QLatin1Char('\n'));
         QMutableStringListIterator i(lines);
diff --git a/plugins/clazy/config/commandlinewidget.ui \
b/plugins/clazy/config/commandlinewidget.ui index c2241b2174..0bb1dff233 100644
--- a/plugins/clazy/config/commandlinewidget.ui
+++ b/plugins/clazy/config/commandlinewidget.ui
@@ -32,7 +32,14 @@
       <item>
        <layout class="QHBoxLayout" name="filterLayout">
         <item>
-         <widget class="KFilterProxySearchLine" name="cmdFilter"/>
+         <widget class="QLineEdit" name="cmdFilter">
+          <property name="placeholderText">
+           <string>Search</string>
+          </property>
+          <property name="clearButtonEnabled">
+           <bool>true</bool>
+          </property>
+         </widget>
         </item>
         <item>
          <widget class="QCheckBox" name="cmdBreak">
@@ -55,13 +62,6 @@
    </item>
   </layout>
  </widget>
- <customwidgets>
-  <customwidget>
-   <class>KFilterProxySearchLine</class>
-   <extends>QWidget</extends>
-   <header>kfilterproxysearchline.h</header>
-  </customwidget>
- </customwidgets>
  <resources/>
  <connections/>
 </ui>
diff --git a/plugins/cppcheck/CMakeLists.txt b/plugins/cppcheck/CMakeLists.txt
index 8e77f72b2d..8aebb189b0 100644
--- a/plugins/cppcheck/CMakeLists.txt
+++ b/plugins/cppcheck/CMakeLists.txt
@@ -52,7 +52,6 @@ kdevplatform_add_plugin(kdevcppcheck
 )
 target_link_libraries(kdevcppcheck
     kdevcppcheck_core
-    KF5::ItemViews
 )
 
 ecm_install_icons(ICONS icons/128-apps-cppcheck.png
diff --git a/plugins/cppcheck/config/projectconfigpage.cpp \
b/plugins/cppcheck/config/projectconfigpage.cpp index 6b76c40117..a527b0c035 100644
--- a/plugins/cppcheck/config/projectconfigpage.cpp
+++ b/plugins/cppcheck/config/projectconfigpage.cpp
@@ -43,7 +43,7 @@ ProjectConfigPage::ProjectConfigPage(KDevelop::IPlugin* plugin, \
                KDevelop::IProje
     ui->commandLine->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
 
     connect(this, &ProjectConfigPage::changed, this, \
                &ProjectConfigPage::updateCommandLine);
-    connect(ui->commandLineFilter->lineEdit(), &QLineEdit::textChanged, this, \
&ProjectConfigPage::updateCommandLine); +    connect(ui->commandLineFilter, \
                &QLineEdit::textChanged, this, \
                &ProjectConfigPage::updateCommandLine);
     connect(ui->commandLineBreaks, &QCheckBox::stateChanged, this, \
&ProjectConfigPage::updateCommandLine);  }
 
@@ -105,7 +105,7 @@ void ProjectConfigPage::updateCommandLine()
     }
 
     commandLine.replace(QLatin1String(" -"), QLatin1String("\n-"));
-    QString filterText = ui->commandLineFilter->lineEdit()->text();
+    QString filterText = ui->commandLineFilter->text();
     if (filterText.isEmpty()) {
         ui->commandLine->setPlainText(commandLine);
         ui->commandLineBreaks->setEnabled(true);
diff --git a/plugins/cppcheck/config/projectconfigpage.ui \
b/plugins/cppcheck/config/projectconfigpage.ui index 0724068eec..5b6eebcf69 100644
--- a/plugins/cppcheck/config/projectconfigpage.ui
+++ b/plugins/cppcheck/config/projectconfigpage.ui
@@ -299,7 +299,14 @@
       <item>
        <layout class="QHBoxLayout" name="horizontalLayout">
         <item>
-         <widget class="KFilterProxySearchLine" name="commandLineFilter"/>
+         <widget class="QLineEdit" name="commandLineFilter">
+          <property name="placeholderText">
+           <string>Search</string>
+          </property>
+          <property name="clearButtonEnabled">
+           <bool>true</bool>
+          </property>
+         </widget>
         </item>
         <item>
          <widget class="QCheckBox" name="commandLineBreaks">
@@ -345,11 +352,6 @@
   </layout>
  </widget>
  <customwidgets>
-  <customwidget>
-   <class>KFilterProxySearchLine</class>
-   <extends>QWidget</extends>
-   <header>kfilterproxysearchline.h</header>
-  </customwidget>
   <customwidget>
    <class>KMessageWidget</class>
    <extends>QFrame</extends>
diff --git a/plugins/kdeprovider/CMakeLists.txt b/plugins/kdeprovider/CMakeLists.txt
index f6e6a07a63..72458248f6 100644
--- a/plugins/kdeprovider/CMakeLists.txt
+++ b/plugins/kdeprovider/CMakeLists.txt
@@ -4,6 +4,7 @@ if(BUILD_TESTING)
 endif()
 
 set(kdevkdeprovider_PART_SRCS kdeprojectsmodel.cpp
+    filterproxysearchline.cpp
     kdeproviderwidget.cpp
     kdeproviderplugin.cpp
     kdeprojectsmodel.cpp
@@ -13,4 +14,7 @@ kconfig_add_kcfg_files(kdevkdeprovider_PART_SRCS kdeconfig.kcfgc)
 ki18n_wrap_ui(kdevkdeprovider_PART_SRCS kdeconfig.ui)
 
 kdevplatform_add_plugin(kdevkdeprovider JSON kdevkdeprovider.json SOURCES \
                ${kdevkdeprovider_PART_SRCS})
-target_link_libraries(kdevkdeprovider KF5::ItemViews KDev::Interfaces KDev::Vcs)
+target_link_libraries(kdevkdeprovider
+    KDev::Interfaces
+    KDev::Vcs
+)
diff --git a/plugins/kdeprovider/filterproxysearchline.cpp \
b/plugins/kdeprovider/filterproxysearchline.cpp new file mode 100644
index 0000000000..bb8e4abf94
--- /dev/null
+++ b/plugins/kdeprovider/filterproxysearchline.cpp
@@ -0,0 +1,58 @@
+/*
+ * This file is part of KDevelop
+ *
+ * Copyright 2018 Friedrich W. H. Kossebau <kossebau@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "filterproxysearchline.h"
+
+// KF
+#include <KLocalizedString>
+// Qt
+#include <QTimer>
+#include <QSortFilterProxyModel>
+
+
+FilterProxySearchLine::FilterProxySearchLine(QWidget *parent)
+    : QLineEdit(parent)
+    , m_delayTimer(new QTimer(this))
+{
+    setClearButtonEnabled(true);
+    setPlaceholderText(i18n("Search"));
+
+    m_delayTimer->setSingleShot(true);
+    m_delayTimer->setInterval(300);
+    connect(m_delayTimer, &QTimer::timeout,
+            this, &FilterProxySearchLine::updateFilter);
+    connect(this, &FilterProxySearchLine::textChanged,
+            m_delayTimer, static_cast<void(QTimer::*)()>(&QTimer::start));
+}
+
+void FilterProxySearchLine::setFilterProxyModel(QSortFilterProxyModel* \
filterProxyModel) +{
+    m_filterProxyModel = filterProxyModel;
+}
+
+void FilterProxySearchLine::updateFilter()
+{
+    if (!m_filterProxyModel) {
+        return;
+    }
+
+    m_filterProxyModel->setFilterFixedString(text());
+}
diff --git a/plugins/kdeprovider/kdeproviderwidget.h \
b/plugins/kdeprovider/filterproxysearchline.h similarity index 52%
copy from plugins/kdeprovider/kdeproviderwidget.h
copy to plugins/kdeprovider/filterproxysearchline.h
index b7b0d8b2e3..a0507ee4eb 100644
--- a/plugins/kdeprovider/kdeproviderwidget.h
+++ b/plugins/kdeprovider/filterproxysearchline.h
@@ -1,6 +1,7 @@
 /*
  * This file is part of KDevelop
- * Copyright 2010 Aleix Pol Gonzalez <aleixpol@kde.org>
+ *
+ * Copyright 2018 Friedrich W. H. Kossebau <kossebau@kde.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Library General Public License as
@@ -18,29 +19,31 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#ifndef KDEPROVIDERWIDGET_H
-#define KDEPROVIDERWIDGET_H
+#ifndef KDEPROVIDER_FILTERPROXYSEARCHLINE_H
+#define KDEPROVIDER_FILTERPROXYSEARCHLINE_H
+
+// Qt
+#include <QLineEdit>
 
-#include <interfaces/iprojectprovider.h>
+class QTimer;
+class QSortFilterProxyModel;
 
-class QModelIndex;
-class KFilterProxySearchLine;
-class QListView;
-class KDEProviderWidget : public KDevelop::IProjectProviderWidget
+class FilterProxySearchLine : public QLineEdit
 {
     Q_OBJECT
-    public:
-        explicit KDEProviderWidget(QWidget* parent = nullptr);
-        
-        KDevelop::VcsJob* createWorkingCopy(const QUrl &destinationDirectory) \
                override;
-        bool isCorrect() const override;
-        
-    private Q_SLOTS:
-        void showSettings();
-        void projectIndexChanged(const QModelIndex& currentIndex);
-        
-    private:
-        QListView* m_projects;
+
+public:
+    explicit FilterProxySearchLine(QWidget* parent = nullptr);
+
+public:
+    void setFilterProxyModel(QSortFilterProxyModel* filterProxyModel);
+
+private:
+    void updateFilter();
+
+private:
+    QTimer* m_delayTimer;
+    QSortFilterProxyModel* m_filterProxyModel = nullptr;
 };
 
-#endif // KDEPROVIDERWIDGET_H
+#endif
diff --git a/plugins/kdeprovider/kdeproviderwidget.cpp \
b/plugins/kdeprovider/kdeproviderwidget.cpp index 717bf6cb6f..551229a572 100644
--- a/plugins/kdeprovider/kdeproviderwidget.cpp
+++ b/plugins/kdeprovider/kdeproviderwidget.cpp
@@ -29,11 +29,12 @@
 #include <vcs/vcslocation.h>
 
 #include "ui_kdeconfig.h"
+#include "filterproxysearchline.h"
 #include "kdeconfig.h"
 #include "kdeprojectsmodel.h"
 #include "kdeprojectsreader.h"
 #include <QSortFilterProxyModel>
-#include <KFilterProxySearchLine>
+
 #include <KMessageBox>
 #include <KLocalizedString>
 
@@ -45,7 +46,7 @@ KDEProviderWidget::KDEProviderWidget(QWidget* parent)
     setLayout(new QVBoxLayout);
     m_projects = new QListView(this);
     QHBoxLayout* topLayout = new QHBoxLayout;
-    KFilterProxySearchLine* filterLine = new KFilterProxySearchLine(this);
+    auto filterLine = new FilterProxySearchLine(this);
     KDEProjectsModel* model = new KDEProjectsModel(this);
     KDEProjectsReader* reader = new KDEProjectsReader(model, model);
     connect(reader, &KDEProjectsReader::downloadDone, reader, \
&KDEProjectsReader::deleteLater); @@ -68,9 +69,11 @@ \
KDEProviderWidget::KDEProviderWidget(QWidget* parent)  \
proxyModel->setDynamicSortFilter(true);  proxyModel->sort(0);
     proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
+    proxyModel->setFilterKeyColumn(-1);
+    proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
     m_projects->setModel(proxyModel);
     m_projects->setEditTriggers(QAbstractItemView::NoEditTriggers);
-    filterLine->setProxy(proxyModel);
+    filterLine->setFilterProxyModel(proxyModel);
 }
 
 VcsLocation extractLocation(const QModelIndex& pos)
diff --git a/plugins/kdeprovider/kdeproviderwidget.h \
b/plugins/kdeprovider/kdeproviderwidget.h index b7b0d8b2e3..7b9ed6bee5 100644
--- a/plugins/kdeprovider/kdeproviderwidget.h
+++ b/plugins/kdeprovider/kdeproviderwidget.h
@@ -24,8 +24,8 @@
 #include <interfaces/iprojectprovider.h>
 
 class QModelIndex;
-class KFilterProxySearchLine;
 class QListView;
+
 class KDEProviderWidget : public KDevelop::IProjectProviderWidget
 {
     Q_OBJECT


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic