Changeset View
Changeset View
Standalone View
Standalone View
src/contentlist/ContentList.h
Context not available. | |||||
28 | 28 | | |||
---|---|---|---|---|---|
29 | #include "ContentQuery.h" | 29 | #include "ContentQuery.h" | ||
30 | 30 | | |||
31 | /** | ||||
32 | * \brief Class to handle searching all the book entries. | ||||
33 | * | ||||
34 | * This class handles the queries and the contentlisterbase | ||||
35 | * that in turn handles the actual searching. | ||||
36 | * | ||||
37 | * When searching is done, the entries are filled into this model. | ||||
38 | */ | ||||
31 | class ContentList : public QAbstractListModel, public QQmlParserStatus | 39 | class ContentList : public QAbstractListModel, public QQmlParserStatus | ||
32 | { | 40 | { | ||
33 | Q_OBJECT | 41 | Q_OBJECT | ||
34 | Q_CLASSINFO("DefaultProperty", "queries") | 42 | Q_CLASSINFO("DefaultProperty", "queries") | ||
43 | /** | ||||
44 | * \brief The list of query parameters that make up this search. | ||||
45 | */ | ||||
35 | Q_PROPERTY(QQmlListProperty<ContentQuery> queries READ queries) | 46 | Q_PROPERTY(QQmlListProperty<ContentQuery> queries READ queries) | ||
47 | /** | ||||
48 | * TODO: No idea. | ||||
49 | */ | ||||
36 | Q_PROPERTY(bool autoSearch READ autoSearch WRITE setAutoSearch NOTIFY autoSearchChanged) | 50 | Q_PROPERTY(bool autoSearch READ autoSearch WRITE setAutoSearch NOTIFY autoSearchChanged) | ||
51 | /** | ||||
52 | * \brief Whether to cache the search results for later. | ||||
53 | */ | ||||
37 | Q_PROPERTY(bool cacheResults READ cacheResults WRITE setCacheResults NOTIFY cacheResultsChanged) | 54 | Q_PROPERTY(bool cacheResults READ cacheResults WRITE setCacheResults NOTIFY cacheResultsChanged) | ||
38 | public: | 55 | public: | ||
39 | explicit ContentList(QObject* parent = nullptr); | 56 | explicit ContentList(QObject* parent = nullptr); | ||
40 | ~ContentList() override; | 57 | ~ContentList() override; | ||
41 | 58 | | |||
59 | /** | ||||
60 | * Extra roles for the different kinds of data that can be searched. | ||||
61 | */ | ||||
42 | enum Roles { | 62 | enum Roles { | ||
43 | FilenameRole = Qt::UserRole + 1, | 63 | FilenameRole = Qt::UserRole + 1, | ||
44 | FilePathRole, | 64 | FilePathRole, | ||
45 | MetadataRole | 65 | MetadataRole | ||
46 | }; | 66 | }; | ||
47 | 67 | | |||
68 | /** | ||||
69 | * @returns the list of search parameters as a list of content queries. | ||||
70 | */ | ||||
48 | QQmlListProperty<ContentQuery> queries(); | 71 | QQmlListProperty<ContentQuery> queries(); | ||
49 | 72 | | |||
73 | /** | ||||
74 | * @return whether to do auto search. | ||||
75 | */ | ||||
50 | bool autoSearch() const; | 76 | bool autoSearch() const; | ||
77 | | ||||
78 | /** | ||||
79 | * @return whether to cache the results. | ||||
80 | */ | ||||
51 | bool cacheResults() const; | 81 | bool cacheResults() const; | ||
52 | 82 | | |||
83 | /** | ||||
84 | * \brief QStrings with names for the extra roles. | ||||
85 | */ | ||||
53 | QHash<int, QByteArray> roleNames() const override; | 86 | QHash<int, QByteArray> roleNames() const override; | ||
87 | /** | ||||
88 | * \brief Access the search results inside the model. | ||||
89 | * @param index The QModelIndex at which you wish to access the data. | ||||
90 | * @param role An enumerator of the type of data you want to access. | ||||
91 | * Is extended by the Roles enum. | ||||
92 | * | ||||
93 | * @return a QVariant with the search entry data. | ||||
94 | */ | ||||
54 | QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | 95 | QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | ||
96 | /** | ||||
97 | * @param parent The QModel index of the parent. This only counts for | ||||
98 | * tree like page structures, and thus defaults to a freshly constructed | ||||
99 | * QModelIndex. A wellformed QModelIndex will cause this function to return 0 | ||||
100 | * @returns the number of total rows(search results) there are in this model. | ||||
101 | */ | ||||
55 | int rowCount(const QModelIndex& parent = QModelIndex()) const override; | 102 | int rowCount(const QModelIndex& parent = QModelIndex()) const override; | ||
56 | 103 | | |||
104 | /** | ||||
105 | * Inherited from QmlParserStatus, not implemented. | ||||
106 | */ | ||||
57 | void classBegin() override; | 107 | void classBegin() override; | ||
108 | /** | ||||
109 | * \brief loads the cached results or autosearch | ||||
110 | * into the model if either is enabled. | ||||
111 | * | ||||
112 | * Inherited from QmlParserStatus. | ||||
113 | */ | ||||
58 | void componentComplete() override; | 114 | void componentComplete() override; | ||
59 | 115 | | |||
116 | /** | ||||
117 | * \brief Set whether to do autoSearch. | ||||
118 | * @param autoSearch whether to do autoSearch. | ||||
119 | */ | ||||
60 | Q_SLOT void setAutoSearch(bool autoSearch); | 120 | Q_SLOT void setAutoSearch(bool autoSearch); | ||
121 | /** | ||||
122 | * \brief Set whether to cache the results. | ||||
123 | * @param cacheResults whether to cache the results. | ||||
124 | */ | ||||
61 | Q_SLOT void setCacheResults(bool cacheResults); | 125 | Q_SLOT void setCacheResults(bool cacheResults); | ||
62 | 126 | | |||
127 | /** | ||||
128 | * \brief Fill the model with the results. | ||||
129 | * | ||||
130 | * This clears the model of search entries and then | ||||
131 | * fills it up with the new entries. | ||||
132 | * | ||||
133 | * @param results a stringlist with paths to the new | ||||
134 | * search results. | ||||
135 | */ | ||||
63 | Q_SLOT void setKnownFiles(const QStringList& results); | 136 | Q_SLOT void setKnownFiles(const QStringList& results); | ||
137 | /** | ||||
138 | * \brief Start searching with the current queries list. | ||||
139 | */ | ||||
64 | Q_SLOT void startSearch(); | 140 | Q_SLOT void startSearch(); | ||
65 | 141 | | |||
66 | Q_SIGNAL void autoSearchChanged(); | 142 | Q_SIGNAL void autoSearchChanged(); | ||
67 | Q_SIGNAL void cacheResultsChanged(); | 143 | Q_SIGNAL void cacheResultsChanged(); | ||
144 | /** | ||||
145 | * \brief Fires when the search is completed. | ||||
146 | */ | ||||
68 | Q_SIGNAL void searchCompleted(); | 147 | Q_SIGNAL void searchCompleted(); | ||
69 | 148 | | |||
70 | Q_INVOKABLE static QString getMimetype(QString filePath); | 149 | Q_INVOKABLE static QString getMimetype(QString filePath); | ||
Context not available. |