2024-01-30 14:35:04 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2023, 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: iaom <zhangpengfei@kylinos.cn>
|
|
|
|
*/
|
2021-12-28 15:56:41 +08:00
|
|
|
#include "result-item.h"
|
|
|
|
using namespace UkuiSearch;
|
2023-03-15 16:39:38 +08:00
|
|
|
namespace UkuiSearch {
|
|
|
|
class ResultItemPrivate
|
2021-12-31 17:38:02 +08:00
|
|
|
{
|
2023-03-15 16:39:38 +08:00
|
|
|
friend class ResultItem;
|
|
|
|
private:
|
|
|
|
size_t m_searchId = 0;
|
|
|
|
QString m_itemKey;
|
|
|
|
SearchResultPropertyMap m_data;
|
|
|
|
};
|
2021-12-31 17:38:02 +08:00
|
|
|
}
|
2023-03-15 16:39:38 +08:00
|
|
|
ResultItem::ResultItem() : d(new ResultItemPrivate())
|
2022-01-11 16:20:40 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-03-15 16:39:38 +08:00
|
|
|
ResultItem::ResultItem(const size_t searchId) : d(new ResultItemPrivate())
|
2022-01-11 16:20:40 +08:00
|
|
|
{
|
2023-03-15 16:39:38 +08:00
|
|
|
d->m_searchId = searchId;
|
2022-01-11 16:20:40 +08:00
|
|
|
}
|
2022-01-24 09:44:42 +08:00
|
|
|
|
2023-03-15 16:39:38 +08:00
|
|
|
ResultItem::ResultItem(const QString &itemKey) : d(new ResultItemPrivate())
|
2022-06-13 13:38:47 +08:00
|
|
|
{
|
2023-03-15 16:39:38 +08:00
|
|
|
d->m_itemKey = itemKey;
|
2022-06-13 13:38:47 +08:00
|
|
|
}
|
|
|
|
|
2023-03-15 16:39:38 +08:00
|
|
|
ResultItem::ResultItem(const size_t searchId, const QString &itemKey, const SearchResultPropertyMap &map) : d(new ResultItemPrivate())
|
2022-01-24 09:44:42 +08:00
|
|
|
{
|
2023-03-15 16:39:38 +08:00
|
|
|
d->m_searchId = searchId;
|
|
|
|
d->m_itemKey = itemKey;
|
|
|
|
d->m_data = map;
|
2022-01-24 09:44:42 +08:00
|
|
|
}
|
|
|
|
|
2023-03-15 16:39:38 +08:00
|
|
|
void ResultItem::setSearchId(const size_t searchId)
|
2022-01-24 09:44:42 +08:00
|
|
|
{
|
2023-03-15 16:39:38 +08:00
|
|
|
d->m_searchId = searchId;
|
2022-01-24 09:44:42 +08:00
|
|
|
}
|
2022-06-13 13:38:47 +08:00
|
|
|
|
2023-03-15 16:39:38 +08:00
|
|
|
void ResultItem::setItemKey(const QString &itemKey)
|
2022-06-13 13:38:47 +08:00
|
|
|
{
|
2023-03-15 16:39:38 +08:00
|
|
|
d->m_itemKey = itemKey;
|
2022-06-13 13:38:47 +08:00
|
|
|
}
|
|
|
|
|
2023-03-15 16:39:38 +08:00
|
|
|
size_t ResultItem::getSearchId() const
|
2022-01-11 16:20:40 +08:00
|
|
|
{
|
2023-03-15 16:39:38 +08:00
|
|
|
return d->m_searchId;
|
2022-01-11 16:20:40 +08:00
|
|
|
}
|
|
|
|
|
2023-03-15 16:39:38 +08:00
|
|
|
QString ResultItem::getItemKey() const
|
2021-12-28 15:56:41 +08:00
|
|
|
{
|
2023-03-15 16:39:38 +08:00
|
|
|
return d->m_itemKey;
|
2021-12-28 15:56:41 +08:00
|
|
|
}
|
|
|
|
|
2023-03-15 16:39:38 +08:00
|
|
|
void ResultItem::setValue(SearchProperty::SearchResultProperty property, const QVariant &value)
|
2022-01-24 09:44:42 +08:00
|
|
|
{
|
2023-03-15 16:39:38 +08:00
|
|
|
d->m_data.insert(property, value);
|
2022-01-24 09:44:42 +08:00
|
|
|
}
|
|
|
|
|
2023-03-15 16:39:38 +08:00
|
|
|
QVariant ResultItem::getValue(SearchProperty::SearchResultProperty property) const
|
2022-01-24 09:44:42 +08:00
|
|
|
{
|
2023-03-15 16:39:38 +08:00
|
|
|
return d->m_data.value(property);
|
2022-01-24 09:44:42 +08:00
|
|
|
}
|
|
|
|
|
2023-03-15 16:39:38 +08:00
|
|
|
SearchResultPropertyMap ResultItem::getAllValue() const
|
2022-06-13 13:38:47 +08:00
|
|
|
{
|
2023-03-15 16:39:38 +08:00
|
|
|
return d->m_data;
|
2022-06-13 13:38:47 +08:00
|
|
|
}
|
|
|
|
|
2021-12-28 15:56:41 +08:00
|
|
|
ResultItem::~ResultItem()
|
|
|
|
{
|
2022-06-13 13:38:47 +08:00
|
|
|
if (d)
|
|
|
|
delete d;
|
|
|
|
d = nullptr;
|
|
|
|
}
|
|
|
|
|
2023-03-15 16:39:38 +08:00
|
|
|
ResultItem::ResultItem(const ResultItem &item): d(new ResultItemPrivate(*item.d))
|
2022-06-13 13:38:47 +08:00
|
|
|
{
|
2021-12-28 15:56:41 +08:00
|
|
|
}
|
2023-04-19 15:14:36 +08:00
|
|
|
|
|
|
|
ResultItem &ResultItem::operator=(const ResultItem &other)
|
|
|
|
{
|
|
|
|
*d = *other.d;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
ResultItem &ResultItem::operator=(ResultItem &&other) Q_DECL_NOEXCEPT
|
|
|
|
{
|
|
|
|
d = other.d;
|
|
|
|
other.d = nullptr;
|
|
|
|
return *this;
|
|
|
|
}
|