7#include "queryresultsmodel.h"
10#include <QMimeDatabase>
23void Query::setSearchString(
const QString &searchString)
25 if (m_searchString == searchString) {
29 m_searchString = searchString;
30 Q_EMIT searchStringChanged();
33QString Query::searchString()
const
35 return m_searchString;
38void Query::setLimit(
const int &limit)
40 if (m_limit == limit) {
48int Query::limit()
const
53QueryResultsModel::QueryResultsModel(
QObject *parent)
55 m_query(new Query(this))
57 connect(m_query, &Query::searchStringChanged,
this, &QueryResultsModel::populateModel);
58 connect(m_query, &Query::limitChanged,
this, &QueryResultsModel::populateModel);
61QueryResultsModel::~QueryResultsModel()
68 roleNames[UrlRole] =
"url";
75 if (!
index.isValid()) {
85 QString localUrl = m_balooEntryList.at(
index.row());
86 return QMimeDatabase().mimeTypeForFile(localUrl).iconName();
89 return m_balooEntryList.at(
index.row());
95int QueryResultsModel::rowCount(
const QModelIndex &parent)
const
101 return m_balooEntryList.count();
104void QueryResultsModel::setQuery(Query *query)
106 if (m_query == query) {
112 m_query->setParent(
this);
116Query* QueryResultsModel::query()
const
121void QueryResultsModel::populateModel()
124 query.setSearchString(m_query->searchString());
125 query.setLimit(m_query->limit());
126 Baloo::ResultIterator it = query.exec();
129 m_balooEntryList.clear();
131 m_balooEntryList << it.filePath();
136#include "moc_queryresultsmodel.cpp"
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const=0
virtual QModelIndex parent(const QModelIndex &index) const const=0
virtual QHash< int, QByteArray > roleNames() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QString fileName(ComponentFormattingOptions options) const const
QUrl fromLocalFile(const QString &localFile)