Merge branch '0615-newfrontend' into 'new-frontend'

Add best matches; Fix best list bug;

See merge request kylin-desktop/ukui-search!72
This commit is contained in:
PengfeiZhang 2021-08-02 06:15:33 +00:00
commit 4d4bf111fb
20 changed files with 613 additions and 20 deletions

View File

@ -42,6 +42,7 @@ ResultArea::ResultArea(QWidget *parent) : QScrollArea(parent)
{
qRegisterMetaType<SearchPluginIface::ResultInfo>("SearchPluginIface::ResultInfo");
initUi();
initConnections();
}
void ResultArea::appendWidet(ResultWidget *widget)
@ -75,8 +76,11 @@ void ResultArea::onWidgetSizeChanged()
Q_FOREACH (ResultWidget *widget, m_widget_list) {
whole_height += widget->height();
}
whole_height += m_bestListWidget->height();
//TODO 网页高度
int spacing_height = m_widget_list.length() > 1 ? m_mainLyt->spacing() : 0;
m_widget->setFixedHeight(whole_height + spacing_height * (m_widget_list.length() - 1));
Q_EMIT this->resizeHeight(whole_height + spacing_height * (m_widget_list.length() - 1));
}
void ResultArea::initUi()
@ -95,15 +99,25 @@ void ResultArea::initUi()
this->setWidget(m_widget);
m_mainLyt = new QVBoxLayout(m_widget);
m_widget->setLayout(m_mainLyt);
m_bestListWidget = new BestListWidget(this);
m_mainLyt->addWidget(m_bestListWidget);
m_mainLyt->setContentsMargins(RESULT_LAYOUT_MARGINS);
}
void ResultArea::initConnections()
{
connect(this, &ResultArea::startSearch, m_bestListWidget, &BestListWidget::startSearch);
connect(m_bestListWidget, &BestListWidget::sizeChanged, this, &ResultArea::onWidgetSizeChanged);
connect(m_bestListWidget, &BestListWidget::currentRowChanged, this, &ResultArea::currentRowChanged);
connect(this, &ResultArea::clearSelectedRow, m_bestListWidget, &BestListWidget::clearSelectedRow);
}
void ResultArea::setupConnectionsForWidget(ResultWidget *widget)
{
connect(this, &ResultArea::startSearch, widget, &ResultWidget::startSearch);
connect(this, &ResultArea::stopSearch, widget, &ResultWidget::stopSearch);
connect(widget, &ResultWidget::sizeChanged, this, &ResultArea::onWidgetSizeChanged);
connect(widget, &ResultWidget::sendBestListData, m_bestListWidget, &BestListWidget::sendBestListData);
}
DetailArea::DetailArea(QWidget *parent) : QScrollArea(parent)

View File

@ -26,6 +26,7 @@
#include <QStyleOption>
#include "result-view.h"
#include "search-plugin-iface.h"
#include "best-list-view.h"
namespace Zeeker {
class ResultArea : public QScrollArea
@ -42,15 +43,19 @@ public Q_SLOTS:
private:
void initUi();
void initConnections();
void setupConnectionsForWidget(ResultWidget *);
QWidget * m_widget = nullptr;
QVBoxLayout * m_mainLyt = nullptr;
BestListWidget * m_bestListWidget;
QList<ResultWidget *> m_widget_list;
Q_SIGNALS:
void startSearch(const QString &);
void stopSearch();
void currentRowChanged(const QString &, const SearchPluginIface::ResultInfo&);
void clearSelectedRow();
void resizeHeight(int height);
};
class DetailWidget : public QWidget

View File

@ -1,6 +1,6 @@
/*
*
* Copyright (C) 2020, KylinSoft Co., Ltd.
* Copyright (C) 2021, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* Authors: zhangjiaping <zhangjiaping@kylinos.cn>
* Authors: jixiaoxu <jixiaoxu@kylinos.cn>
*
*/
#include "search-result-page.h"
@ -131,6 +131,11 @@ void SearchResultPage::initConnections()
connect(this, &SearchResultPage::stopSearch, m_resultArea, &ResultArea::stopSearch);
connect(this, &SearchResultPage::startSearch, m_detailArea, &DetailArea::hide);
connect(this, &SearchResultPage::stopSearch, m_detailArea, &DetailArea::hide);
connect(m_resultArea, &ResultArea::currentRowChanged, m_detailArea, &DetailArea::setWidgetInfo);
connect(m_resultArea, &ResultArea::currentRowChanged, this, &SearchResultPage::currentRowChanged);
connect(this, &SearchResultPage::currentRowChanged, m_resultArea, &ResultArea::clearSelectedRow);
connect(m_resultArea, &ResultArea::resizeHeight, this, &SearchResultPage::resizeHeight);
}
void SearchResultPage::setupConnectionsForWidget(ResultWidget *widget)

View File

@ -42,7 +42,7 @@ private:
void initConnections();
void setupConnectionsForWidget(ResultWidget *);
QSplitter * m_splitter = nullptr;
QHBoxLayout *m_hlayout = nullptr;
QHBoxLayout * m_hlayout = nullptr;
ResultArea * m_resultArea = nullptr;
DetailArea * m_detailArea = nullptr;
@ -51,6 +51,7 @@ Q_SIGNALS:
void stopSearch();
void currentRowChanged(const QString &, const SearchPluginIface::ResultInfo&);
void effectiveSearch();
void resizeHeight(int height);
};
}

View File

@ -170,6 +170,7 @@ void MainWindow::initConnections()
// });
connect(m_searchBarWidget, &SeachBarWidget::requestSearchKeyword, this, &MainWindow::searchKeywordSlot);
// connect(m_stackedWidget, &StackedWidget::effectiveSearch, m_searchLayout, &SearchBarHLayout::effectiveSearchRecord);
//connect(m_searchResultPage, &SearchResultPage::resizeHeight, this, &MainWindow::resizeHeight);
}
/**
@ -303,7 +304,7 @@ void MainWindow::searchKeywordSlot(const QString &keyword)
if(GlobalSettings::getInstance()->getValue(ENABLE_CREATE_INDEX_ASK_DIALOG).toString() != "false" && !m_currentSearchAsked && FileUtils::searchMethod == FileUtils::SearchMethod::DIRECTSEARCH)
m_askTimer->start();
Q_EMIT m_searchResultPage->startSearch(keyword);
this->resizeHeight(610);
this->resizeHeight(WINDOW_HEIGHT);
m_searchResultPage->move(0, 58);
m_searchResultPage->show();

View File

@ -0,0 +1,138 @@
/*
*
* Copyright (C) 2020, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <https://www.gnu.org/licenses/>.
*
* Authors: jixiaoxu <jixiaoxu@kylinos.cn>
*
*/
#include "best-list-model.h"
using namespace Zeeker;
BestListModel::BestListModel(QObject *parent)
: QAbstractItemModel(parent)
{
m_item = new SearchResultItem;
initConnections();
}
QModelIndex BestListModel::index(int row, int column, const QModelIndex &parent) const
{
if(row < 0 || row > m_item->m_result_info_list.length() - 1)
return QModelIndex();
return createIndex(row, column, m_item);
}
QModelIndex BestListModel::parent(const QModelIndex &index) const
{
return QModelIndex();
}
int BestListModel::rowCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : (m_isExpanded ? m_item->m_result_info_list.length() : NUM_LIMIT_SHOWN_DEFAULT);
}
int BestListModel::columnCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : 1;
}
QVariant BestListModel::data(const QModelIndex &index, int role) const
{
switch(role) {
case Qt::DecorationRole: {
return m_item->m_result_info_list.at(index.row()).icon;
}
case Qt::DisplayRole: {
return m_item->m_result_info_list.at(index.row()).name;
}
default:
return QVariant();
}
return QVariant();
}
const SearchPluginIface::ResultInfo &BestListModel::getInfo(const QModelIndex &index)
{
return m_item->m_result_info_list.at(index.row());
}
const QString &BestListModel::getPluginInfo(const QModelIndex &index)
{
return m_plugin_id_list.at(index.row());
}
void BestListModel::setExpanded(const bool &is_expanded)
{
this->beginResetModel();
m_isExpanded = is_expanded;
this->endResetModel();
Q_EMIT this->itemListChanged(m_item->m_result_info_list.length());
}
const bool &BestListModel::isExpanded()
{
return m_isExpanded;
}
QStringList BestListModel::getActions(const QModelIndex &index)
{
// if (m_item->m_result_info_list.length() > index.row() && index.row() >= 0)
// return m_item->m_result_info_list.at(index.row()).actionList;
return QStringList();
}
QString BestListModel::getKey(const QModelIndex &index)
{
if (m_item->m_result_info_list.length() > index.row() && index.row() >= 0)
return m_item->m_result_info_list.at(index.row()).actionKey;
return NULL;
}
void BestListModel::appendInfo(const QString &pluginId, const SearchPluginIface::ResultInfo &info)
{
if (m_plugin_id_list.contains(pluginId)) {
if (info.name == m_item->m_result_info_list.at(m_plugin_id_list.lastIndexOf(pluginId)).name) {
return;
}
qDebug()<<"plugin ID:"<<pluginId<<"Repalce result. name ="<<info.name;
m_item->m_result_info_list.replace(m_plugin_id_list.lastIndexOf(pluginId), info);
return;
}
this->beginResetModel();
qDebug()<<"plugin ID:"<<pluginId<<"Got a result. name ="<<info.name;
m_plugin_id_list.append(pluginId);
m_item->m_result_info_list.append(info);
this->endResetModel();
Q_EMIT this->itemListChanged(m_item->m_result_info_list.length());
}
void BestListModel::startSearch(const QString &keyword)
{
if (!m_item->m_result_info_list.isEmpty()) {
this->beginResetModel();
m_plugin_id_list.clear();
m_item->m_result_info_list.clear();
//Q_EMIT this->itemListChanged(m_item->m_result_info_list.length());
this->endResetModel();
}
}
void BestListModel::initConnections()
{
}

View File

@ -0,0 +1,50 @@
#ifndef BESTLISTMODEL_H
#define BESTLISTMODEL_H
#include <QAbstractItemModel>
#include "search-result-model.h"
#define NUM_LIMIT_SHOWN_DEFAULT 5
namespace Zeeker {
class BestListModel : public QAbstractItemModel
{
Q_OBJECT
public:
explicit BestListModel(QObject *parent = nullptr);
QModelIndex index(int row, int column,
const QModelIndex &parent = QModelIndex()) const override;
QModelIndex parent(const QModelIndex &index) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
const SearchPluginIface::ResultInfo & getInfo(const QModelIndex&);
const QString & getPluginInfo(const QModelIndex&);
void setExpanded(const bool&);
const bool &isExpanded();
QStringList getActions(const QModelIndex &);
QString getKey(const QModelIndex &);
public Q_SLOTS:
void appendInfo(const QString &, const SearchPluginIface::ResultInfo &);
void startSearch(const QString &);
Q_SIGNALS:
void stopSearch();
void itemListChanged(const int&);
private:
void initConnections();
SearchResultItem * m_item = nullptr;
QVector<QString> m_plugin_id_list;
bool m_isExpanded = false;
};
}
#endif // BESTLISTMODEL_H

View File

@ -1,9 +1,11 @@
INCLUDEPATH += $$PWD
HEADERS += \
$$PWD/best-list-model.h \
$$PWD/search-result-manager.h \
$$PWD/search-result-model.h \
SOURCES += \
$$PWD/best-list-model.cpp \
$$PWD/search-result-manager.cpp \
$$PWD/search-result-model.cpp \

View File

@ -79,8 +79,9 @@ void SearchResultModel::appendInfo(const SearchPluginIface::ResultInfo &info)
this->beginResetModel();
qDebug()<<"Got a result. name ="<<info.name;
m_item->m_result_info_list.append(info);
Q_EMIT this->itemListChanged(m_item->m_result_info_list.length());
this->endResetModel();
Q_EMIT this->itemListChanged(m_item->m_result_info_list.length());
Q_EMIT this->sendBestListData(m_plugin_id, m_item->m_result_info_list.at(0));
}
void SearchResultModel::startSearch(const QString &keyword)
@ -88,8 +89,8 @@ void SearchResultModel::startSearch(const QString &keyword)
if (!m_item->m_result_info_list.isEmpty()) {
this->beginResetModel();
m_item->m_result_info_list.clear();
Q_EMIT this->itemListChanged(m_item->m_result_info_list.length());
this->endResetModel();
Q_EMIT this->itemListChanged(m_item->m_result_info_list.length());
}
m_search_manager->startSearch(keyword);
}

View File

@ -29,6 +29,7 @@ namespace Zeeker {
class SearchResultItem : public QObject {
friend class SearchResultModel;
friend class BestListModel;
Q_OBJECT
public:
explicit SearchResultItem(QObject *parent = nullptr);
@ -62,6 +63,7 @@ public Q_SLOTS:
Q_SIGNALS:
void stopSearch();
void itemListChanged(const int&);
void sendBestListData(const QString &, const SearchPluginIface::ResultInfo&);
private:
void initConnections();

View File

@ -0,0 +1,244 @@
#include "best-list-view.h"
#define MAIN_MARGINS 0,0,0,0
#define MAIN_SPACING 0
#define TITLE_HEIGHT 30
#define UNFOLD_LABEL_HEIGHT 30
using namespace Zeeker;
BestListView::BestListView(QWidget *parent) : QTreeView(parent)
{
this->setFrameShape(QFrame::NoFrame);
this->viewport()->setAutoFillBackground(false);
this->setRootIsDecorated(false);
this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
this->setSelectionBehavior(QAbstractItemView::SelectRows);
this->setSelectionMode(QAbstractItemView::SingleSelection);
this->setHeaderHidden(true);
m_model = new BestListModel(this);
this->setModel(m_model);
initConnections();
m_style_delegate = new ResultViewDelegate(this);
this->setItemDelegate(m_style_delegate);
}
bool BestListView::isSelected()
{
return m_is_selected;
}
int BestListView::showHeight()
{
int height;
int rowheight = this->rowHeight(this->model()->index(0, 0, QModelIndex())) + 1;
if (this->isExpanded()) {
height = m_count * rowheight;
} else {
int show_count = m_count > NUM_LIMIT_SHOWN_DEFAULT ? NUM_LIMIT_SHOWN_DEFAULT : m_count;
height = show_count * rowheight;
}
return height;
}
void BestListView::clearSelectedRow()
{
if (!m_is_selected) {
this->blockSignals(true);
this->clearSelection();
this->blockSignals(false);
}
}
/**
* @brief BestListView::onRowDoubleClickedSlot
* @param index
*/
void BestListView::onRowDoubleClickedSlot(const QModelIndex &index)
{
const SearchPluginIface::ResultInfo &info = m_model->getInfo(index);
// SearchPluginIface *plugin = SearchPluginManager::getInstance()->getPlugin(m_plugin_id);
// try {
// if (plugin) {
//// if (!info.actionList.isEmpty()) {
//// plugin->openAction(info.actionList.at(0), info.key);
//// } else {
//// throw -2;
//// }
// } else {
// throw -1;
// }
// } catch(int e) {
// qWarning()<<"Open failed, reason="<<e;
// }
}
/**
* @brief BestListView::onRowSelectedSlot
* @param selected
* @param deselected
*/
void BestListView::onRowSelectedSlot(const QItemSelection &selected, const QItemSelection &deselected)
{
//NEW_TODO
m_is_selected = true;
Q_EMIT this->currentRowChanged(m_model->getPluginInfo(this->currentIndex()), m_model->getInfo(this->currentIndex()));
m_is_selected = false;
if(!selected.isEmpty()) {
QRegion region = visualRegionForSelection(selected);
QRect rect = region.boundingRect();
// Q_EMIT this->currentSelectPos(mapToParent(rect.topLeft()));
}
}
void BestListView::onItemListChanged(const int &count)
{
m_count = count;
Q_EMIT this->listLengthChanged(count);
}
void BestListView::setExpanded(const bool &is_expanded)
{
m_model->setExpanded(is_expanded);
}
const bool &BestListView::isExpanded()
{
return m_model->isExpanded();
}
/**
* @brief BestListView::onMenuTriggered
* @param action
*/
void BestListView::onMenuTriggered(QAction *action)
{
//NEW_TODO 接口调整后需要修改
// SearchPluginIface *plugin = SearchPluginManager::getInstance()->getPlugin(m_plugin_id);
// if (plugin) {
//// plugin->openAction(action->text(), m_model->getKey(this->currentIndex()));
// } else {
// qWarning()<<"Get plugin failed!";
// }
}
void BestListView::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::RightButton) {
//加一点点延时,等待列表先被选中
QTimer::singleShot(10, this, [ = ] {
QMenu * menu = new QMenu(this);
QStringList actions = m_model->getActions(this->currentIndex());
Q_FOREACH (QString action, actions) {
menu->addAction(new QAction(action, this));
}
menu->move(cursor().pos());
menu->show();
connect(menu, &QMenu::triggered, this, &BestListView::onMenuTriggered);
});
}
Q_EMIT this->rowClicked();
return QTreeView::mousePressEvent(event);
}
void BestListView::initConnections()
{
connect(this, &BestListView::startSearch, [ = ](const QString &keyword) {
qDebug() << "==========start search!";
m_style_delegate->setSearchKeyword(keyword);
m_model->startSearch(keyword);
});
connect(this, &BestListView::startSearch, m_model, &BestListModel::startSearch);
connect(this->selectionModel(), &QItemSelectionModel::selectionChanged, this, &BestListView::onRowSelectedSlot);
connect(this, &BestListView::activated, this, &BestListView::onRowDoubleClickedSlot);
connect(m_model, &BestListModel::itemListChanged, this, &BestListView::onItemListChanged);
connect(this, &BestListView::sendBestListData, m_model, &BestListModel::appendInfo);
}
BestListWidget::BestListWidget(QWidget *parent) : QWidget(parent)
{
this->initUi();
initConnections();
}
void BestListWidget::setEnabled(const bool &enabled)
{
m_enabled = enabled;
}
/**
* @brief BestListWidget::expandListSlot
*/
void BestListWidget::expandListSlot()
{
qWarning()<<"List will be expanded!";
m_bestListView->setExpanded(true);
}
/**
* @brief BestListWidget::reduceListSlot
*/
void BestListWidget::reduceListSlot()
{
qWarning()<<"List will be reduced!";
m_bestListView->setExpanded(false);
}
/**
* @brief BestListWidget::onListLengthChanged
*/
void BestListWidget::onListLengthChanged(const int &length)
{
this->setVisible(length > 0);
m_showMoreLabel->setVisible(length > NUM_LIMIT_SHOWN_DEFAULT);
int show_more_height = m_showMoreLabel->isVisible() ? UNFOLD_LABEL_HEIGHT : 0;
int whole_height = this->isVisible() ? (m_bestListView->showHeight() + TITLE_HEIGHT + show_more_height) : 0;
this->setFixedHeight(whole_height);
Q_EMIT this->sizeChanged();
}
void BestListWidget::initUi()
{
m_mainLyt = new QVBoxLayout(this);
this->setLayout(m_mainLyt);
m_mainLyt->setContentsMargins(MAIN_MARGINS);
m_mainLyt->setSpacing(MAIN_SPACING);
m_titleLabel = new TitleLabel(this);
m_titleLabel->setText(tr("Best Matches"));
m_titleLabel->setFixedHeight(TITLE_HEIGHT);
m_bestListView = new BestListView(this);
m_showMoreLabel = new ShowMoreLabel(this);
m_showMoreLabel->setFixedHeight(UNFOLD_LABEL_HEIGHT);
m_showMoreLabel->hide();
m_mainLyt->addWidget(m_titleLabel);
m_mainLyt->addWidget(m_bestListView);
m_mainLyt->addWidget(m_showMoreLabel);
this->setFixedHeight(m_bestListView->height() + TITLE_HEIGHT);
}
void BestListWidget::initConnections()
{
connect(this, &BestListWidget::startSearch, m_bestListView, &BestListView::startSearch);
connect(this, &BestListWidget::startSearch, this, [ = ]() {
m_showMoreLabel->resetLabel();
});
//connect(this, &BestListWidget::stopSearch, m_bestListView, &BestListView::stopSearch);
connect(this, &BestListWidget::stopSearch, this, [ = ]() {
m_showMoreLabel->resetLabel();
m_bestListView->setExpanded(false);
});
connect(this, &BestListWidget::sendBestListData, m_bestListView, &BestListView::sendBestListData);
connect(m_bestListView, &BestListView::currentRowChanged, this, &BestListWidget::currentRowChanged);
connect(this, &BestListWidget::clearSelectedRow, m_bestListView, &BestListView::clearSelectedRow);
connect(m_showMoreLabel, &ShowMoreLabel::showMoreClicked, this, &BestListWidget::expandListSlot);
connect(m_showMoreLabel, &ShowMoreLabel::retractClicked, this, &BestListWidget::reduceListSlot);
connect(m_bestListView, &BestListView::listLengthChanged, this, &BestListWidget::onListLengthChanged);
connect(m_bestListView, &BestListView::rowClicked, this, &BestListWidget::rowClicked);
connect(qApp, &QApplication::paletteChanged, this, [ = ]() {
int show_more_height = m_showMoreLabel->isVisible() ? UNFOLD_LABEL_HEIGHT : 0;
int whole_height = this->isVisible() ? m_bestListView->showHeight() + TITLE_HEIGHT + show_more_height : 0;
this->setFixedHeight(whole_height);
Q_EMIT this->sizeChanged();
});
}

View File

@ -0,0 +1,88 @@
#ifndef BESTLISTVIEW_H
#define BESTLISTVIEW_H
#include <QTreeView>
#include <QVBoxLayout>
#include <QLabel>
#include <QMenu>
#include <QApplication>
#include "best-list-model.h"
#include "show-more-label.h"
#include "title-label.h"
#include "result-view-delegate.h"
namespace Zeeker {
class BestListView : public QTreeView
{
Q_OBJECT
public:
BestListView(QWidget *parent = nullptr);
~BestListView() = default;
bool isSelected();
int showHeight();
public Q_SLOTS:
void clearSelectedRow();
void onRowDoubleClickedSlot(const QModelIndex &);
void onRowSelectedSlot(const QItemSelection &, const QItemSelection &);
void onItemListChanged(const int &);
void setExpanded(const bool &);
const bool &isExpanded();
void onMenuTriggered(QAction *);
protected:
void mousePressEvent(QMouseEvent *event) override;
private:
void initConnections();
BestListModel * m_model = nullptr;
bool m_is_selected = false;
ResultViewDelegate * m_style_delegate = nullptr;
int m_count = 0;
Q_SIGNALS:
void startSearch(const QString &);
void currentRowChanged(const QString &, const SearchPluginIface::ResultInfo&);
void sendBestListData(const QString &, const SearchPluginIface::ResultInfo&);
void listLengthChanged(const int &);
void rowClicked();
};
class BestListWidget : public QWidget
{
Q_OBJECT
public:
BestListWidget(QWidget *parent = nullptr);
~BestListWidget() = default;
void setEnabled(const bool&);
public Q_SLOTS:
void expandListSlot();
void reduceListSlot();
void onListLengthChanged(const int &);
private:
bool m_enabled = true;
void initUi();
void initConnections();
QVBoxLayout * m_mainLyt = nullptr;
TitleLabel * m_titleLabel = nullptr;
BestListView * m_bestListView = nullptr;
ShowMoreLabel * m_showMoreLabel = nullptr;
Q_SIGNALS:
void startSearch(const QString &);
void stopSearch();
void currentRowChanged(const QString &, const SearchPluginIface::ResultInfo&);
void sendBestListData(const QString &, const SearchPluginIface::ResultInfo&);
void clearSelectedRow();
void sizeChanged();
void rowClicked();
};
}
#endif // BESTLISTVIEW_H

View File

@ -99,6 +99,7 @@ void ResultWidget::initConnections()
this->setFixedHeight(whole_height);
Q_EMIT this->sizeChanged();
});
connect(m_resultView, &ResultView::sendBestListData, this, &ResultWidget::sendBestListData);
}
ResultView::ResultView(const QString &plugin_id, QWidget *parent) : QTreeView(parent)
@ -249,4 +250,5 @@ void ResultView::initConnections()
connect(this->selectionModel(), &QItemSelectionModel::selectionChanged, this, &ResultView::onRowSelectedSlot);
connect(this, &ResultView::activated, this, &ResultView::onRowDoubleClickedSlot);
connect(m_model, &SearchResultModel::itemListChanged, this, &ResultView::onItemListChanged);
connect(m_model, &SearchResultModel::sendBestListData, this, &ResultView::sendBestListData);
}

View File

@ -45,6 +45,7 @@ Q_SIGNALS:
void startSearch(const QString &);
void stopSearch();
void currentRowChanged(const QString &, const SearchPluginIface::ResultInfo&);
void sendBestListData(const QString &, const SearchPluginIface::ResultInfo&);
void listLengthChanged(const int &);
void rowClicked();
};
@ -78,6 +79,7 @@ Q_SIGNALS:
void startSearch(const QString &);
void stopSearch();
void currentRowChanged(const QString &, const SearchPluginIface::ResultInfo&);
void sendBestListData(const QString &, const SearchPluginIface::ResultInfo&);
void clearSelectedRow();
void sizeChanged();
void rowClicked();

View File

@ -1,9 +1,11 @@
INCLUDEPATH += $$PWD
HEADERS += \
$$PWD/best-list-view.h \
$$PWD/result-view-delegate.h \
$$PWD/result-view.h \
SOURCES += \
$$PWD/best-list-view.cpp \
$$PWD/result-view-delegate.cpp \
$$PWD/result-view.cpp \

View File

@ -9,19 +9,20 @@ using namespace Zeeker;
static SearchPluginManager *global_instance = nullptr;
SearchPluginManager::SearchPluginManager(QObject *parent)
{
registerPlugin(new FileSearchPlugin(this));
registerPlugin(new DirSearchPlugin(this));
registerPlugin(new FileContengSearchPlugin(this));
registerPlugin(new AppSearchPlugin(this));
registerPlugin(new SettingsSearchPlugin(this));
registerPlugin(new DirSearchPlugin(this));
registerPlugin(new FileSearchPlugin(this));
registerPlugin(new FileContengSearchPlugin(this));
}
bool SearchPluginManager::registerPlugin(Zeeker::SearchPluginIface *plugin)
{
if (m_hash.value(plugin->name())) {
if (m_map.end() != m_map.find(plugin->name())){
return false;
}
m_hash.insert(plugin->name(), plugin);
m_map[plugin->name()] = plugin;
return true;
}
@ -35,12 +36,16 @@ SearchPluginManager *SearchPluginManager::getInstance()
const QStringList SearchPluginManager::getPluginIds()
{
return m_hash.keys();
QStringList list;
for (auto i = m_map.begin(); i != m_map.end(); i++) {
list.append((*i).first);
}
return list;
}
SearchPluginIface *SearchPluginManager::getPlugin(const QString &pluginId)
{
return m_hash.value(pluginId);
return m_map[pluginId];
}
void SearchPluginManager::close()
@ -50,5 +55,5 @@ void SearchPluginManager::close()
SearchPluginManager::~SearchPluginManager()
{
m_hash.clear();
m_map.clear();
}

View File

@ -5,6 +5,14 @@
#include "search-plugin-iface.h"
namespace Zeeker {
struct cmpPluginId
{
bool operator ()(const QString& k1, const QString& k2){
return k1 > k2;
}
};
class SearchPluginManager : public QObject
{
Q_OBJECT
@ -18,8 +26,7 @@ public:
void close();
private:
QHash<QString, SearchPluginIface*> m_hash;
std::map<QString, SearchPluginIface*, cmpPluginId> m_map;
explicit SearchPluginManager(QObject *parent = nullptr);
~SearchPluginManager();

View File

@ -9,6 +9,14 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Zeeker::BestListWidget</name>
<message>
<location filename="../../frontend/view/best-list-view.cpp" line="205"/>
<source>Best Matches</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Zeeker::CreateIndexAskDialog</name>
<message>

View File

@ -244,6 +244,14 @@
<translation type="vanished">Yükleniyor...</translation>
</message>
</context>
<context>
<name>Zeeker::BestListWidget</name>
<message>
<location filename="../../frontend/view/best-list-view.cpp" line="205"/>
<source>Best Matches</source>
<translation type="unfinished">En İyi Eşleşen</translation>
</message>
</context>
<context>
<name>Zeeker::ContentWidget</name>
<message>

View File

@ -9,6 +9,14 @@
<translation></translation>
</message>
</context>
<context>
<name>Zeeker::BestListWidget</name>
<message>
<location filename="../../frontend/view/best-list-view.cpp" line="205"/>
<source>Best Matches</source>
<translation></translation>
</message>
</context>
<context>
<name>Zeeker::ContentWidget</name>
<message>
@ -274,7 +282,7 @@
<message>
<location filename="../../frontend/control/settings-widget.cpp" line="299"/>
<source>Whether to delete this directory?</source>
<translation></translation>
<translation>?</translation>
</message>
<message>
<location filename="../../frontend/control/settings-widget.cpp" line="300"/>
@ -289,7 +297,7 @@
<message>
<location filename="../../frontend/control/settings-widget.cpp" line="359"/>
<source>Creating ...</source>
<translation></translation>
<translation>...</translation>
</message>
<message>
<location filename="../../frontend/control/settings-widget.cpp" line="362"/>