[request for approval] new small and useful kdevelop 3.4 feature
Andreas Pakulat
apaku at gmx.de
Wed Jan 3 01:49:25 UTC 2007
On 15.12.06 00:38:00, Flavio Castelli wrote:
> I've wrote a small patch for kdevelop 3.4 that adds a filtering option
> to class browser.
> Using this feature you can filter the class browser elements, showing only
> items matching a specified text.
>
> It's something similar to the filtering option found in amarok collection
> browser or in kmail.
While the idea is great you need to rework the patch, a few notes:
1. Inline patches are bad, please attach them as files that makes
application much easier
2. It would be nice to know from which revision the patch is, so we can
more easily figure out how to apply it if something changed in between
3. It depends on ClickLineEdit, which is not in kdelibs. We cannot
depend on kdepim and we depend on KDE 3.4 and I'm not sure that class
existed back then
4. Even if we decide to import the ClickLineEdit from kdepim into the
classview there are some things that need to be changed from your
original patch.
I attach and updated patch, that corrects all of the above (and contains
the clicklineedit class).
Andreas
--
Never commit yourself! Let someone else commit you.
-------------- next part --------------
Index: classviewwidget.cpp
===================================================================
--- classviewwidget.cpp (Revision 619227)
+++ classviewwidget.cpp (Arbeitskopie)
@@ -47,8 +47,8 @@
// namespace ?!?
-ClassViewWidget::ClassViewWidget( ClassViewPart * part )
- : KListView( 0, "ClassViewWidget" ), QToolTip( viewport() ), m_part( part ), m_projectDirectoryLength( 0 )
+ClassViewWidget::ClassViewWidget( ClassViewPart * part, QWidget * parent )
+ : KListView( parent, "ClassViewWidget" ), QToolTip( viewport() ), m_part( part ), m_projectDirectoryLength( 0 )
{
addColumn( "" );
header()->hide();
Index: classviewwidget.h
===================================================================
--- classviewwidget.h (Revision 619227)
+++ classviewwidget.h (Arbeitskopie)
@@ -54,7 +54,7 @@ public:
};
public:
- ClassViewWidget( ClassViewPart *part );
+ ClassViewWidget( ClassViewPart *part, QWidget *parent);
virtual ~ClassViewWidget();
int viewMode() const;
Index: classviewpart.cpp
===================================================================
--- classviewpart.cpp (Revision 619227)
+++ classviewpart.cpp (Arbeitskopie)
@@ -20,11 +20,14 @@
*/
#include <qwhatsthis.h>
+#include <qwidget.h>
+#include <qlayout.h>
#include <qlistview.h>
#include <qfileinfo.h>
#include <qlineedit.h>
#include <kiconloader.h>
+#include <kpushbutton.h>
#include <klocale.h>
#include <kdevgenericfactory.h>
#include <kpopupmenu.h>
@@ -46,6 +49,7 @@
#include "classviewwidget.h"
#include "classviewpart.h"
#include "hierarchydlg.h"
+#include "clicklineedit.h"
#include "navigator.h"
#include "klistviewaction.h"
@@ -137,7 +141,6 @@ class FunctionCompletion : public Custom
}
};
-
typedef KDevGenericFactory<ClassViewPart> ClassViewFactory;
static const KDevPluginInfo data("kdevclassview");
K_EXPORT_COMPONENT_FACTORY( libkdevclassview, ClassViewFactory( data ) )
@@ -154,29 +157,45 @@ ClassViewPart::ClassViewPart(QObject *pa
setupActions();
- m_widget = new ClassViewWidget(this);
+ m_widget = new QWidget(0, "Class Browser");
m_widget->setIcon( SmallIcon("view_tree") );
m_widget->setCaption(i18n("Class Browser"));
mainWindow()->embedSelectView( m_widget, i18n("Classes"), i18n("Class browser") );
QWhatsThis::add(m_widget, i18n("<b>Class browser</b><p>"
"The class browser shows all namespaces, classes and namespace and class members in a project."));
+ m_classViewWidget = new ClassViewWidget(this, m_widget);
+ m_lineEdit = new ClickLineEdit(m_widget, i18n( "Enter search terms here" ), 0);
+ m_clearBtn = new KPushButton (SmallIcon ("clear_left"),"", m_widget);
+
+ QVBoxLayout *vbox = new QVBoxLayout( m_widget );
+
+ QHBoxLayout *hlayout = new QHBoxLayout( vbox );
+ hlayout->addWidget ( m_lineEdit );
+ hlayout->addWidget ( m_clearBtn);
+
+ vbox->addWidget( m_classViewWidget);
+
connect( core(), SIGNAL(projectOpened()), this, SLOT(slotProjectOpened()) );
connect( core(), SIGNAL(projectClosed()), this, SLOT(slotProjectClosed()) );
connect( core(), SIGNAL(languageChanged()), this, SLOT(slotProjectOpened()) );
connect( partController(), SIGNAL(activePartChanged(KParts::Part*)),
this, SLOT(activePartChanged(KParts::Part*)));
+ connect( m_classViewWidget, SIGNAL(removedNamespace(const QString&)), this, SLOT(removeNamespace(const QString& )));
+ connect (m_clearBtn, SIGNAL(clicked ()), m_lineEdit, SLOT(clear()));
+ connect (m_clearBtn, SIGNAL(clicked ()), this, SLOT(slotShowItems()));
+ connect (m_lineEdit, SIGNAL(returnPressed(const QString &)), this, SLOT(slotFilterItems (const QString&)));
}
bool ClassViewPart::jumpedToItem( ItemDom item ) {
- if(!m_widget) return false;
- return m_widget->selectItem(item);
+ if(!m_classViewWidget) return false;
+ return m_classViewWidget->selectItem(item);
}
ClassViewPart::~ClassViewPart()
{
mainWindow()->removeView( m_widget );
- delete (ClassViewWidget*) m_widget;
+ delete (ClassViewWidget*) m_classViewWidget;
}
void ClassViewPart::slotProjectOpened( )
@@ -215,6 +234,100 @@ void ClassViewPart::setupActions( )
}
}
+void ClassViewPart::slotShowItems()
+{
+ QListViewItemIterator it (m_classViewWidget);
+ while ( it.current() )
+ {
+ it.current()->setVisible(true);
+ ++it;
+ }
+}
+
+void findParents (QListViewItem* item, QPtrList<QListViewItem>& visibleItems)
+{
+ if (item == 0)
+ return;
+
+ QListViewItem* parent = item->parent();
+ if (parent)
+ {
+ if (visibleItems.find(parent) == -1)
+ {
+ visibleItems.append(parent);
+ findParents(parent, visibleItems);
+ }
+ }
+}
+
+void findChilds (QListViewItem* parent, QPtrList<QListViewItem>& visibleItems)
+{
+ QListViewItem* child = parent->firstChild();
+
+ if (child == 0)
+ return;
+
+ if (visibleItems.find(child) == -1)
+ visibleItems.append(child);
+
+ findChilds (child, visibleItems);
+
+ QListViewItem* brother = child->nextSibling();
+ while (brother)
+ {
+ if (visibleItems.find(brother) == -1)
+ visibleItems.append(brother);
+
+ findChilds (brother, visibleItems);
+ brother = brother->nextSibling();
+ }
+}
+
+void ClassViewPart::slotFilterItems(const QString& text)
+{
+ if (text.isEmpty())
+ { // show all items and exit
+ slotShowItems();
+ return;
+ }
+
+ QPtrList<QListViewItem> visibleItems;
+ QListViewItemIterator it (m_classViewWidget->firstChild());
+ while ( it.current() ) // search interesting items
+ {
+ if ((visibleItems.find(it.current()) == -1) && (it.current()->text(0).contains(text, false) != 0))
+ {
+ visibleItems.append(it.current());
+ findParents (it.current(), visibleItems); //ensure all item's parents are visible
+ findChilds (it.current(), visibleItems); //ensure all item's children are visible
+
+ // if matched item is a class method we've to ensure other methods all be visible
+ ClassViewItem* temp = dynamic_cast<ClassViewItem*> (it.current()->parent());
+ if ((temp) && (temp->isClass()))
+ findChilds (temp, visibleItems);
+ }
+
+ ++it;
+ }
+
+ it = QListViewItemIterator (m_classViewWidget->firstChild());
+ while ( it.current() ) // show relevant items, hide others
+ {
+ if (visibleItems.find(it.current()) == -1)
+ it.current()->setVisible(false);
+ else
+ it.current()->setVisible(true);
+
+ ++it;
+ }
+
+// if (visibleItems.find(m_classViewWidget->selectedItem()) == -1)
+// m_classViewWidget->clearSelection();
+//
+// if (visibleItems.find(m_classViewWidget->currentItem()) == -1)
+// m_classViewWidget->setCurrentItem(0);
+}
+
bool ClassViewPart::langHasFeature(KDevLanguageSupport::Features feature)
{
bool result = false;
Index: Makefile.am
===================================================================
--- Makefile.am (Revision 619227)
+++ Makefile.am (Arbeitskopie)
@@ -8,7 +8,7 @@ libkdevclassview_la_LDFLAGS = $(all_libr
libkdevclassview_la_LIBADD = $(top_builddir)/lib/libkdevelop.la $(top_builddir)/lib/widgets/libkdevwidgets.la $(LIB_KHTML) $(top_builddir)/lib/interfaces/extensions/libkdevextensions.la
libkdevclassview_la_SOURCES = classviewpart.cpp classviewwidget.cpp \
- digraphview.cpp hierarchydlg.cpp navigator.cpp viewcombos.cpp
+ digraphview.cpp hierarchydlg.cpp navigator.cpp viewcombos.cpp clicklineedit.cpp
METASOURCES = AUTO
Index: classviewpart.h
===================================================================
--- classviewpart.h (Revision 619227)
+++ classviewpart.h (Arbeitskopie)
@@ -48,6 +48,9 @@ namespace KTextEditor
class ClassViewWidget;
class KListViewAction;
class QListViewItem;
+class QWidget;
+class KLineEdit;
+class KPushButton;
class KToolBarPopupAction;
class NamespaceItem;
class Navigator;
@@ -64,7 +67,7 @@ public:
KListViewAction *m_functionsnav;
Navigator *navigator;
- inline ClassViewWidget* widget() {
+ inline QWidget* widget() {
return &( *m_widget );
}
@@ -73,6 +76,8 @@ public:
private slots:
void slotProjectOpened();
void slotProjectClosed();
+ void slotFilterItems(const QString&);
+ void slotShowItems();
void graphicalClassView();
void refresh();
void slotFocusNavbar();
@@ -82,7 +87,10 @@ private slots:
private:
void setupActions();
- QGuardedPtr<ClassViewWidget> m_widget;
+ QGuardedPtr<QWidget> m_widget;
+ QGuardedPtr<ClassViewWidget> m_classViewWidget;
+ QGuardedPtr<KLineEdit> m_lineEdit;
+ QGuardedPtr<KPushButton> m_clearBtn;
QString m_activeFileName;
KTextEditor::Document* m_activeDocument;
More information about the KDevelop-devel
mailing list