2
* Copyright (C) 2015 Canonical, Ltd.
5
* Pawel Stolowski <pawel.stolowski@canonical.com>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; version 3.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20
#include "resultsmap.h"
23
ResultsMap::ResultsMap(QList<std::shared_ptr<unity::scopes::Result>> const &results)
28
ResultsMap::ResultsMap(QList<std::shared_ptr<unity::scopes::CategorisedResult>> const &results)
31
for (auto result: results) {
32
std::shared_ptr<unity::scopes::Result> res = result;
34
const ResultPos rpos { res, pos++ };
35
m_results.insert({result->uri(), rpos });
39
void ResultsMap::rebuild(QList<std::shared_ptr<unity::scopes::Result>> const &results)
43
for (auto result: results) {
45
const ResultPos rpos { result, pos++ };
46
m_results.insert({result->uri(), rpos });
50
int ResultsMap::find(std::shared_ptr<unity::scopes::Result> const& result) const
53
auto it = m_results.find(result->uri());
54
if (it != m_results.end()) {
55
assert(it->second.result);
56
while (it != m_results.end() && it->second.result->uri() == result->uri())
58
if (*(it->second.result) == *result) {
59
return it->second.index;