Skip to content

Commit

Permalink
feat: [extension] add filter
Browse files Browse the repository at this point in the history
Log:
Change-Id: I692fff9f39f30b29360ef48da6583c62600280bd
  • Loading branch information
deepin-mozart committed Feb 7, 2024
1 parent ef59301 commit e56642f
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 240 deletions.
26 changes: 25 additions & 1 deletion src/plugins/core/gui/pluginlistview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
#include "pluginlistview.h"
#include "framework/lifecycle/lifecycle.h"
#include "pluginitemdelegate.h"
#include "common/util/fuzzymatcher.h"

#include <QStandardItemModel>
#include <DStandardItem>

DPF_USE_NAMESPACE
DWIDGET_USE_NAMESPACE
PluginListView::PluginListView(QListView *parent)

PluginListView::PluginListView(QWidget *parent)
: QListView(parent)
, model(new QStandardItemModel(this))
{
Expand All @@ -37,6 +39,9 @@ void PluginListView::display()
for (auto collection : pluginCollections) {
for (auto metaOBject : collection) {
QString pluginName = metaOBject->name();
if (isFilterdOut(pluginName))
continue;

QString description = metaOBject->description();
QString vender = metaOBject->vendor();
QString category = metaOBject->category();
Expand Down Expand Up @@ -64,6 +69,19 @@ void PluginListView::display()
model->appendColumn(result);
}

bool PluginListView::isFilterdOut(const QString &filteringText)
{
bool filterOut = false;
if (!filterText.isEmpty()) {
QRegularExpression regexp = FuzzyMatcher::createRegExp(filterText);
QRegularExpressionMatch match = regexp.match(filteringText);
if (!match.hasMatch()) {
filterOut = true;
}
}
return filterOut;
}

PluginMetaObjectPointer PluginListView::currentPlugin() const
{
QStandardItem *item = model->itemFromIndex(currentIndex());
Expand All @@ -80,3 +98,9 @@ PluginMetaObjectPointer PluginListView::currentPlugin() const
}
return {};
}

void PluginListView::filter(const QString &filterText)
{
this->filterText = filterText;
display();
}
6 changes: 5 additions & 1 deletion src/plugins/core/gui/pluginlistview.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ class PluginListView : public QListView
Category
};

explicit PluginListView(QListView *parent = nullptr);
explicit PluginListView(QWidget *parent = nullptr);


dpf::PluginMetaObjectPointer currentPlugin() const;
void filter(const QString &filterText);

signals:
void currentPluginActived();
Expand All @@ -32,7 +33,10 @@ public slots:
void display();

private:
bool isFilterdOut(const QString &filteringText);

QStandardItemModel *model = nullptr;
QString filterText;
};

#endif // PLUGINSLIST_H
45 changes: 45 additions & 0 deletions src/plugins/core/gui/pluginstorewidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include "pluginstorewidget.h"
#include "pluginlistview.h"

#include <DSearchEdit>
#include <DLabel>

#include <QVBoxLayout>

DWIDGET_USE_NAMESPACE

PluginStoreWidget::PluginStoreWidget(QWidget *parent)
: QWidget(parent)
, pluginListView(new PluginListView(this))
{
initializeUi();
}

const PluginListView *PluginStoreWidget::getPluginListView() const
{
return pluginListView;
}

void PluginStoreWidget::slotSearchChanged(const QString &searchText)
{
pluginListView->filter(searchText);
}

void PluginStoreWidget::initializeUi()
{
inputEdit = new DSearchEdit(this);
connect(inputEdit, &DSearchEdit::textChanged,
this, &PluginStoreWidget::slotSearchChanged);

auto titleLabel = new DLabel(this);
titleLabel->setText(tr("Extension"));

QVBoxLayout *vLayout = new QVBoxLayout(this);
setLayout(vLayout);
vLayout->addWidget(titleLabel);
vLayout->addWidget(inputEdit);
vLayout->addWidget(pluginListView);
}
35 changes: 35 additions & 0 deletions src/plugins/core/gui/pluginstorewidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
#ifndef PLUGINSTOREWIDGET_H
#define PLUGINSTOREWIDGET_H

#include "dtkwidget_global.h"

#include <QWidget>

class PluginListView;
DWIDGET_BEGIN_NAMESPACE
class DSearchEdit;
DWIDGET_END_NAMESPACE

class PluginStoreWidget : public QWidget
{
Q_OBJECT
public:
explicit PluginStoreWidget(QWidget *parent = nullptr);
const PluginListView *getPluginListView() const;

signals:

public slots:
void slotSearchChanged(const QString &searchText);

private:
void initializeUi();

PluginListView *pluginListView {nullptr};
DTK_WIDGET_NAMESPACE::DSearchEdit *inputEdit { nullptr };
};

#endif // PLUGINSTOREWIDGET_H
35 changes: 25 additions & 10 deletions src/plugins/core/gui/pluginsui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "framework/lifecycle/lifecycle.h"
#include "framework/lifecycle/pluginmanager.h"
#include "framework/lifecycle/pluginmetaobject.h"
#include "pluginstorewidget.h"
#include "pluginlistview.h"

#include <DTitlebar>
Expand All @@ -18,34 +19,48 @@
static bool isRestartRequired = false;

PluginsUi::PluginsUi(QObject *parent)
: QObject(parent),
pluginListView(new PluginListView())
: QObject(parent)
, pluginStoreWidget(new PluginStoreWidget())
, pluginDetailView(new DetailsView())
{
pluginDetailView = new DetailsView();
slotCurrentPluginActived();
auto pluginListView = pluginStoreWidget->getPluginListView();
QObject::connect(pluginListView, &PluginListView::currentPluginActived,
this, &PluginsUi::slotPluginItemSelected);

QObject::connect(pluginListView, &PluginListView::currentPluginActived, this, &PluginsUi::slotCurrentPluginActived);
QObject::connect(pluginListView, &PluginListView::pluginSettingChanged,
this, &PluginsUi::updateRestartRequired);
this, &PluginsUi::reLaunchRequired);
}

PluginListView *PluginsUi::getPluginView() const
PluginsUi::~PluginsUi()
{
return pluginListView;
if (pluginDetailView) {
delete pluginDetailView;
pluginDetailView = nullptr;
}
if (pluginStoreWidget) {
delete pluginStoreWidget;
pluginStoreWidget = nullptr;
}
}

PluginStoreWidget *PluginsUi::getStoreWidget() const
{
return pluginStoreWidget;
}

DetailsView *PluginsUi::getPluginDetailView() const
{
return pluginDetailView;
}

void PluginsUi::slotCurrentPluginActived()
void PluginsUi::slotPluginItemSelected()
{
auto pluginListView = pluginStoreWidget->getPluginListView();
dpf::PluginMetaObjectPointer plugin = pluginListView->currentPlugin();
pluginDetailView->update(plugin);
}

void PluginsUi::updateRestartRequired()
void PluginsUi::reLaunchRequired()
{
isRestartRequired = true;
saveConfig();
Expand Down
11 changes: 6 additions & 5 deletions src/plugins/core/gui/pluginsui.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,27 @@ DWIDGET_USE_NAMESPACE
class DetailsView;
class QDialogButtonBox;
class QLabel;
class PluginListView;
class PluginStoreWidget;

class PluginsUi : public QObject
{
Q_OBJECT

public:
explicit PluginsUi(QObject *parent = nullptr);
PluginListView *getPluginView() const;
~PluginsUi();
PluginStoreWidget *getStoreWidget() const;
DetailsView *getPluginDetailView() const;

private slots:
void slotCurrentPluginActived();
void slotPluginItemSelected();

private:
void updateRestartRequired();
void reLaunchRequired();
void updateButtons();
void saveConfig();

PluginListView *pluginListView = nullptr;
PluginStoreWidget *pluginStoreWidget = nullptr;
DetailsView *pluginDetailView = nullptr;
};

Expand Down
Loading

0 comments on commit e56642f

Please sign in to comment.