[kde-doc-english] [kdevelop] providers/kdeprovider: Replace Projects QComboBox by Filtered QListView in KDE Provider
David E. Narváez
david.narvaez at computer.org
Wed Dec 14 03:35:08 UTC 2011
Git commit d49354e3bf13cb838005054c5dbcdf20dbb9abbe by David E. Narváez.
Committed on 14/12/2011 at 04:31.
Pushed by narvaez into branch 'master'.
Replace Projects QComboBox by Filtered QListView in KDE Provider
It should help developers find projects faster
REVIEW: 103383
GUI: QComboBox now replaced by a filtered QListView
M +28 -13 providers/kdeprovider/kdeproviderwidget.cpp
M +5 -2 providers/kdeprovider/kdeproviderwidget.h
http://commits.kde.org/kdevelop/d49354e3bf13cb838005054c5dbcdf20dbb9abbe
diff --git a/providers/kdeprovider/kdeproviderwidget.cpp b/providers/kdeprovider/kdeproviderwidget.cpp
index eb84faf..2241f13 100644
--- a/providers/kdeprovider/kdeproviderwidget.cpp
+++ b/providers/kdeprovider/kdeproviderwidget.cpp
@@ -20,7 +20,7 @@
#include "kdeproviderwidget.h"
#include <QVBoxLayout>
-#include <QComboBox>
+#include <QListView>
#include <KIcon>
#include <KPushButton>
#include <KConfigDialog>
@@ -33,26 +33,33 @@
#include "kdeprojectsmodel.h"
#include "kdeprojectsreader.h"
#include <QSortFilterProxyModel>
+#include <KFilterProxySearchLine>
using namespace KDevelop;
KDEProviderWidget::KDEProviderWidget(QWidget* parent)
: IProjectProviderWidget(parent)
{
- setLayout(new QHBoxLayout(this));
- m_projects = new QComboBox(this);
+ setLayout(new QVBoxLayout());
+ m_projects = new QListView(this);
+ QHBoxLayout* topLayout = new QHBoxLayout(this);
+ KFilterProxySearchLine* filterLine = new KFilterProxySearchLine(this);
KDEProjectsModel* model = new KDEProjectsModel(this);
KDEProjectsReader* reader = new KDEProjectsReader(model, model);
connect(reader, SIGNAL(downloadDone()), reader, SLOT(deleteLater()));
- connect(m_projects, SIGNAL(currentIndexChanged(QString)), this, SIGNAL(changed(QString)));
-
- layout()->addWidget(m_projects);
+ connect(m_projects, SIGNAL(clicked(QModelIndex)), this, SLOT(projectIndexChanged(QModelIndex)));
+
+ topLayout->addWidget(filterLine);
+
QPushButton* settings=new QPushButton(KIcon("configure"), i18n("Settings"), this);
settings->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
connect(settings, SIGNAL(clicked()), SLOT(showSettings()));
+
+ topLayout->addWidget(settings);
- layout()->addWidget(settings);
+ layout()->addItem(topLayout);
+ layout()->addWidget(m_projects);
m_dialog = new KConfigDialog(this, "settings", KDEProviderSettings::self());
m_dialog->setFaceType(KPageDialog::Auto);
@@ -71,6 +78,8 @@ KDEProviderWidget::KDEProviderWidget(QWidget* parent)
proxyModel->sort(0);
proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
m_projects->setModel(proxyModel);
+ m_projects->setEditTriggers(QAbstractItemView::NoEditTriggers);
+ filterLine->setProxy(proxyModel);
}
VcsLocation extractLocation(const QVariantMap& urls)
@@ -81,16 +90,13 @@ VcsLocation extractLocation(const QVariantMap& urls)
VcsJob* KDEProviderWidget::createWorkingCopy(const KUrl& destinationDirectory)
{
- int pos = m_projects->currentIndex();
- if(pos<0)
+ QModelIndex pos = m_projects->currentIndex();
+ if(!pos.isValid())
return 0;
- QModelIndex idx = m_projects->model()->index(pos, 0);
- Q_ASSERT(idx.isValid());
-
IPlugin* plugin = ICore::self()->pluginController()->pluginForExtension("org.kdevelop.IBasicVersionControl", "kdevgit");
IBasicVersionControl* vcIface = plugin->extension<IBasicVersionControl>();
- VcsJob* ret = vcIface->createWorkingCopy(extractLocation(idx.data(KDEProjectsModel::VcsLocationRole).toMap()), destinationDirectory);
+ VcsJob* ret = vcIface->createWorkingCopy(extractLocation(pos.data(KDEProjectsModel::VcsLocationRole).toMap()), destinationDirectory);
return ret;
}
@@ -102,3 +108,12 @@ void KDEProviderWidget::showSettings()
m_dialog->show();
}
+
+void KDEProviderWidget::projectIndexChanged(QModelIndex currentIndex)
+{
+ if (currentIndex.isValid()) {
+ QString currentProjectName = currentIndex.data(Qt::DisplayRole).toString();
+
+ emit changed(currentProjectName);
+ }
+}
diff --git a/providers/kdeprovider/kdeproviderwidget.h b/providers/kdeprovider/kdeproviderwidget.h
index 8025638..c498404 100644
--- a/providers/kdeprovider/kdeproviderwidget.h
+++ b/providers/kdeprovider/kdeproviderwidget.h
@@ -23,8 +23,10 @@
#include <interfaces/iprojectprovider.h>
+class QModelIndex;
class KConfigDialog;
-class QComboBox;
+class KFilterProxySearchLine;
+class QListView;
class KDEProviderWidget : public KDevelop::IProjectProviderWidget
{
Q_OBJECT
@@ -35,9 +37,10 @@ class KDEProviderWidget : public KDevelop::IProjectProviderWidget
private slots:
void showSettings();
+ void projectIndexChanged(QModelIndex currentIndex);
private:
- QComboBox* m_projects;
+ QListView* m_projects;
KConfigDialog* m_dialog;
};
More information about the kde-doc-english
mailing list