Optimized search interface frame, add some annotation.

This commit is contained in:
iaom 2022-01-12 18:01:59 +08:00
parent cf20f35181
commit 0e3f594028
8 changed files with 24 additions and 7 deletions

View File

@ -20,6 +20,7 @@ Q_SIGNALS:
private: private:
explicit SearchTaskPluginManager(QObject *parent = nullptr); explicit SearchTaskPluginManager(QObject *parent = nullptr);
//这里初衷是把内外部插件分开管理,内部插件可以增加枚举值,外部插件似乎只能用编写者自定义的字符串区分?
QHash<int, SearchTaskPluginIface*> m_buildinPlugin; QHash<int, SearchTaskPluginIface*> m_buildinPlugin;
QHash<QString, SearchTaskPluginIface*> m_loadedPlugin; QHash<QString, SearchTaskPluginIface*> m_loadedPlugin;

View File

@ -33,7 +33,7 @@ ResultItem::ResultItem(const QString itemKey) : d(new ResultItemPrivate(this))
d->setItemKey(itemKey); d->setItemKey(itemKey);
} }
ResultItem::ResultItem(const size_t searchId, const QString itemKey) ResultItem::ResultItem(const size_t searchId, const QString itemKey) : d(new ResultItemPrivate(this))
{ {
d->setSearchId(searchId); d->setSearchId(searchId);
d->setItemKey(itemKey); d->setItemKey(itemKey);

View File

@ -37,7 +37,9 @@ public:
private: private:
void copyData(); void copyData();
//TODO: 这里是否可以改为字节对齐的写法?
DataQueue<ResultItem>* m_dataQueue = nullptr ; DataQueue<ResultItem>* m_dataQueue = nullptr ;
std::shared_ptr<DataQueue<ResultItem>> m_sharedDataueue = nullptr;
size_t m_searchId = 0; size_t m_searchId = 0;
QMutex m_searchIdMutex; QMutex m_searchIdMutex;
SearchController *q = nullptr; SearchController *q = nullptr;

View File

@ -4,8 +4,10 @@
#include <QDebug> #include <QDebug>
using namespace UkuiSearch; using namespace UkuiSearch;
SearchControllerPrivate::SearchControllerPrivate(SearchController *parent) SearchControllerPrivate::SearchControllerPrivate(SearchController *parent)
: q(parent), m_formerController(q->m_parent) : q(parent),
m_formerController(q->m_parent) //如果构造参数里包含父节点智能指针,则子节点带有一个智能指针指向父节点
{ {
copyData();
} }
SearchControllerPrivate::~SearchControllerPrivate() SearchControllerPrivate::~SearchControllerPrivate()
@ -24,6 +26,7 @@ DataQueue<ResultItem> *SearchControllerPrivate::refreshDataqueue()
{ {
if(!m_dataQueue) { if(!m_dataQueue) {
m_dataQueue = new DataQueue<ResultItem>; m_dataQueue = new DataQueue<ResultItem>;
m_sharedDataueue = std::shared_ptr<DataQueue<ResultItem>>(m_dataQueue);
return m_dataQueue; return m_dataQueue;
} }
m_dataQueue->clear(); m_dataQueue->clear();
@ -34,6 +37,7 @@ DataQueue<ResultItem> *SearchControllerPrivate::initDataQueue()
{ {
if(!m_dataQueue) { if(!m_dataQueue) {
m_dataQueue = new DataQueue<ResultItem>; m_dataQueue = new DataQueue<ResultItem>;
m_sharedDataueue = std::shared_ptr<DataQueue<ResultItem>>(m_dataQueue);
return m_dataQueue; return m_dataQueue;
} }
return m_dataQueue; return m_dataQueue;
@ -81,7 +85,7 @@ size_t SearchControllerPrivate::getCurrentSearchId()
DataQueue<ResultItem> *SearchControllerPrivate::getDataQueue() DataQueue<ResultItem> *SearchControllerPrivate::getDataQueue()
{ {
return m_dataQueue; return m_sharedDataueue.get();
} }
bool SearchControllerPrivate::beginSearchIdCheck(size_t searchId) bool SearchControllerPrivate::beginSearchIdCheck(size_t searchId)
@ -146,9 +150,11 @@ bool SearchControllerPrivate::isSearchDirOnly()
void SearchControllerPrivate::copyData() void SearchControllerPrivate::copyData()
{ {
if(m_formerController.get()) { if(m_formerController.get()) {
m_searchId = m_formerController.get()->getCurrentSearchId(); m_searchId = m_formerController.get()->getCurrentSearchId();
m_dataQueue = m_formerController.get()->getDataQueue(); //所有子节点都有一个指向根节点的队列的智能指针
m_sharedDataueue = m_formerController.get()->d->m_sharedDataueue;
m_keywords = m_formerController.get()->getKeyword(); m_keywords = m_formerController.get()->getKeyword();
m_searchDirs = m_formerController.get()->getSearchDir(); m_searchDirs = m_formerController.get()->getSearchDir();
m_FileLabels = m_formerController.get()->getFileLabel(); m_FileLabels = m_formerController.get()->getFileLabel();

View File

@ -9,6 +9,11 @@ namespace UkuiSearch {
class UkuiSearchTask; class UkuiSearchTask;
class ResultItem; class ResultItem;
class SearchControllerPrivate; class SearchControllerPrivate;
/*
*ID
*
*使
*/
class SearchController class SearchController
{ {
friend class SearchControllerPrivate; friend class SearchControllerPrivate;

View File

@ -8,6 +8,9 @@
#include "search-controller.h" #include "search-controller.h"
#include "result-item.h" #include "result-item.h"
namespace UkuiSearch { namespace UkuiSearch {
/*
*
*/
class FileSearchTask : public SearchTaskPluginIface class FileSearchTask : public SearchTaskPluginIface
{ {
Q_OBJECT Q_OBJECT

View File

@ -127,9 +127,9 @@ void UkuiSearchTask::setSearchOnlineApps(bool searchOnlineApps)
d->setSearchOnlineApps(searchOnlineApps); d->setSearchOnlineApps(searchOnlineApps);
} }
size_t UkuiSearchTask::startSearch(SearchType searchtype, QString customSearchTYpe) size_t UkuiSearchTask::startSearch(SearchType searchtype, QString customSearchType)
{ {
return d->startSearch(searchtype, customSearchTYpe); return d->startSearch(searchtype, customSearchType);
} }
void UkuiSearchTask::stop() void UkuiSearchTask::stop()

View File

@ -20,7 +20,7 @@ public:
void setOnlySearchFile(bool onlySearchFile); void setOnlySearchFile(bool onlySearchFile);
void setOnlySearchDir(bool onlySearchDir); void setOnlySearchDir(bool onlySearchDir);
void setSearchOnlineApps(bool searchOnlineApps); void setSearchOnlineApps(bool searchOnlineApps);
size_t startSearch(SearchType searchtype, QString customSearchTYpe = QString()); size_t startSearch(SearchType searchtype, QString customSearchType = QString());
void stop(); void stop();
Q_SIGNALS: Q_SIGNALS: