Optimized search interface frame, add some annotation.
This commit is contained in:
parent
cf20f35181
commit
0e3f594028
|
@ -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;
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -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:
|
||||||
|
|
Loading…
Reference in New Issue