File indexing completed on 2024-12-15 05:02:05

0001 /*
0002     SPDX-FileCopyrightText: 2016 Ivan Čukić <ivan.cukic(at)kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #ifndef BLADE_RESULT_MODEL_H
0008 #define BLADE_RESULT_MODEL_H
0009 
0010 #include <QAbstractListModel>
0011 #include "agents/Collector.h"
0012 
0013 #include "messages/ResultMessage.h"
0014 
0015 class ResultModel : public QAbstractListModel {
0016     Q_OBJECT
0017 
0018     Q_PROPERTY(QString queryString
0019                READ queryString WRITE setQueryString NOTIFY queryStringChanged)
0020 
0021 public:
0022     enum Roles {
0023         ResultId          = Qt::UserRole,
0024 
0025         ResultTitle       ,
0026         ResultDescription ,
0027         ResultIcon        ,
0028 
0029         ResultUrl         ,
0030         ResultRelevance   ,
0031         ResultMatchedText ,
0032         ResultMimeType
0033     };
0034 
0035     ResultModel();
0036 
0037     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0038 
0039     QVariant data(const QModelIndex &index,
0040                   int role = Qt::DisplayRole) const override;
0041 
0042     QVariant headerData(int section, Qt::Orientation orientation,
0043                         int role = Qt::DisplayRole) const override;
0044 
0045     QHash<int, QByteArray> roleNames() const override;
0046 
0047     QString queryString() const;
0048 
0049 public Q_SLOTS:
0050     void setQueryString(const QString &queryString);
0051     void addResults(const ResultList &results);
0052 
0053 Q_SIGNALS:
0054     void queryStringChanged(const QString &queryString);
0055 
0056 private:
0057     void removeRow(int position);
0058     void insertRow(int position, const Result &result);
0059     void moveRow(int from, int to);
0060 
0061     ResultList::iterator destinationFor(const Result &result);
0062 
0063     int rowFor(ResultList::const_iterator iter) const;
0064     ResultList::iterator iterFor(int row);
0065 
0066 private:
0067     ResultList m_currentResults;
0068     Agents::Collector m_collector;
0069 
0070 };
0071 
0072 #endif // include guard end
0073