2
This file is part of the Nepomuk KDE project.
3
Copyright (C) 2010 Sebastian Trueg <trueg@kde.org>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
8
version 2.1 of the License, or (at your option) version 3, or any
9
later version accepted by the membership of KDE e.V. (or its
10
successor approved by the membership of KDE e.V.), which shall
11
act as a proxy defined in Section 6 of version 3 of the license.
13
This library is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
Lesser General Public License for more details.
18
You should have received a copy of the GNU Lesser General Public
19
License along with this library. If not, see <http://www.gnu.org/licenses/>.
22
#ifndef _NEPOMUK_QUERY_FACET_MODEL_H_
23
#define _NEPOMUK_QUERY_FACET_MODEL_H_
27
#include "nepomukutils_export.h"
29
#include <QtCore/QAbstractItemModel>
30
#include <QtCore/QList>
37
* \class FacetModel facetmodel.h Nepomuk/Utils/FacetModel
39
* \ingroup nepomuk_facets
41
* \brief A FacetModel contains a list of facets that are provided in a tree structure.
43
* The FacetModel manages a list of Facet instances that are layed out
44
* in a tree structure in which the leafs are checkable. This allows to
45
* easily configure the facets by clicking the tree.
47
* Facets are added via setFacets() and addFacet().
49
* The FacetModel can be used to create and augment queries using the queryTerm()
50
* method and connecting to the queryTermChanged() signal. In addition %FacetModel
51
* provides the extractFacetsFromTerm() method which \em converts a query into
52
* facet selections. This is very convinient if the query comes from another source
53
* like a query bookmark or another application.
55
* An improved user experience can be created by setting the final query used to
56
* list the results via setClientQuery(). This allows the %FacetModel to filter
57
* the available choices, hiding those that do not make sense with the current
58
* result set or even showing facets that did not make sense before (compare the
59
* ProxyFacet example in \ref nepomuk_facet_examples).
61
* Typically one would use FacetWidget instead of creating ones own FacetModel.
63
* \author Sebastian Trueg <trueg@kde.org>
67
class NEPOMUKUTILS_EXPORT FacetModel : public QAbstractItemModel
73
* Creates an empty facet model
75
FacetModel( QObject* parent = 0 );
83
* Special roles FacetModel provides through data() in
84
* addition to the standard Qt roles.
86
* \sa Qt::ItemDataRole
90
* Provides a pointer to the Facet instance itself.
97
* Reimplemented to provide facet data to Qt's model/view framework.
99
int columnCount( const QModelIndex& parent = QModelIndex() ) const;
102
* Reimplemented to provide facet data to Qt's model/view framework.
104
QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const;
107
* Reimplemented to provide facet data to Qt's model/view framework.
109
bool setData( const QModelIndex& index, const QVariant& value, int role );
112
* Reimplemented to provide facet data to Qt's model/view framework.
114
bool hasChildren(const QModelIndex &parent) const;
117
* Reimplemented to provide facet data to Qt's model/view framework.
119
QModelIndex parent( const QModelIndex& index ) const;
122
* Reimplemented to provide facet data to Qt's model/view framework.
124
int rowCount( const QModelIndex& parent = QModelIndex() ) const;
127
* Reimplemented to provide facet data to Qt's model/view framework.
129
QModelIndex index( int row, int column, const QModelIndex& parent = QModelIndex() ) const;
132
* Reimplemented to provide facet data to Qt's model/view framework.
134
Qt::ItemFlags flags( const QModelIndex& index ) const;
137
* \return All Facet instances added via addFacet() and setFacets().
139
QList<Facet*> facets() const;
142
* Construct a query term from the selected facets in this model.
144
* \return A new query which combines the facets in this model.
146
Query::Term queryTerm() const;
150
* Extract as many facets from a query as possible. This method is not able to handle all
151
* kinds of queries but works well on queries created via queryTerm().
153
* Facets supported by this model will be extracted from \p query and configured
154
* accordingly in the model.
156
* Be aware that this method is not related to setClientQuery(). It is intended to
157
* split up a query in order to represent it graphically. It will, however change the
158
* client query in order to achieve the best possible term extraction. Thus, one would typically
159
* call setClientQuery after calling this method if \p query does not already contain
160
* the full client query.
162
* Typically a client would call this method and then try to handle the returned
163
* rest query in another way like converting it into a desktop user query string
164
* that can be shown in a search line edit. Another idea would be to use custom
165
* filters or a simple warning for the user that additional conditions are in place
166
* that could not be "translated" into facets.
168
* \return The rest query after facets have been extracted.
170
Nepomuk::Query::Query extractFacetsFromQuery( const Nepomuk::Query::Query& query );
173
* Can be used to set the full query the client is using (this includes facets
174
* created through this model). It allows the facet system to disable certain
175
* choices that would not change the result set or do not make sense otherwise.
177
* Be aware that this method is not related to extractFacetsFromTerm(). It is merely
178
* intended to improve the overall user experienceby filtering the facet choices
179
* depending on the current query.
181
* Typically a client would call both extractFacetsFromTerm() and setClientQuery()
182
* seperately. However, they will often be called with the same query/term.
184
* \sa Facet::setClientQuery()
186
void setClientQuery( const Nepomuk::Query::Query& query );
189
* Add \p facet to the model. Used to populate the model with facets.
190
* Ownership of \p facet is transferred to the model.
192
void addFacet( Nepomuk::Utils::Facet* facet );
195
* Set \p facets as the list of facets used in this model. Used to populate the model with facets.
196
* Ownership of the facets is transferred to the model.
198
void setFacets( const QList<Nepomuk::Utils::Facet*>& facets );
201
* Convenience method that clears the selection on all facets.
202
* \sa Facet::clearSelection()
204
void clearSelection();
207
* Remove all facets from the model.
213
* Emitted whenever the facets change, i.e. when the user changes the selection
214
* or it is changed programmatically via extractFacetsFromQuery()
216
void queryTermChanged( const Nepomuk::Query::Term& term );
222
Q_PRIVATE_SLOT( d, void _k_queryTermChanged() )
223
Q_PRIVATE_SLOT( d, void _k_facetSelectionChanged( Nepomuk::Utils::Facet* ) )
224
Q_PRIVATE_SLOT( d, void _k_facetLayoutChanged( Nepomuk::Utils::Facet* ) )
229
Q_DECLARE_METATYPE( Nepomuk::Utils::Facet* )