// SPDX-FileCopyrightText: 2022 Tobias Fella // SPDX-License-Identifier: LGPL-2.0-or-later #pragma once #include #include #include #include "messagemodel.h" namespace Quotient { class Connection; } class NeoChatRoom; /** * @class SearchModel * * This class defines the model for visualising the results of a room message search. */ class SearchModel : public MessageModel { Q_OBJECT QML_ELEMENT /** * @brief The text to search messages for. */ Q_PROPERTY(QString searchText READ searchText WRITE setSearchText NOTIFY searchTextChanged) /** * @brief Whether the model is currently searching for messages. */ Q_PROPERTY(bool searching READ searching NOTIFY searchingChanged) public: explicit SearchModel(QObject *parent = nullptr); QString searchText() const; void setSearchText(const QString &searchText); bool searching() const; /** * @brief Number of rows in the model. * * @sa QAbstractItemModel::rowCount */ int rowCount(const QModelIndex &parent = QModelIndex()) const override; /** * @brief Start searching for messages. */ Q_INVOKABLE void search(); Q_SIGNALS: void searchTextChanged(); void roomChanged(); void searchingChanged(); private: std::optional> getEventForIndex(QModelIndex index) const override; void setSearching(bool searching); QString m_searchText; std::optional m_result = std::nullopt; Quotient::SearchJob *m_job = nullptr; bool m_searching = false; };