Please find attached another go at the facet class and a draft for some
FacetModel methods.
Currently my version of Facet is not a QObject and does not emit changed
signals. IMHO we simply need a container to store the possible choices
in. The model could then take care of the rest.

Have a look at it and share thoughts, please.

Cheers,
Sebastian

On 06/21/2010 01:36 PM, Sebastian Trüg wrote:
> On 06/21/2010 12:23 PM, Alessandro Sivieri wrote:
>> 2010/6/21 Sebastian Trüg <[email protected] <mailto:[email protected]>>
>>
>>     The thing is that I would like the make the facet stuff public API for
>>     KDE 4.6. That is why I am picking on it and being a pita. :P
>>
>>
>> :D
>> Then I can search a different term for "Term", but "Facet" must retain
>> its name, which is its academia name :)
> 
> Do we really need an extra public class for Term? Isn't that something
> that can be handled internally?
> 
>>     Do you actually want to create different representations for different
>>     types of facets. The only exception I can see is the rating. But that
>>     could easily be filtered out and added as a separate gui element.
>>
>>
>> Well, currently my answer should be "yes" (looking at Sembrowser), but
>> actually is "no": in the Web world, faceted browsing does not use
>> different representations for facets, it uses a uniform one, so in the
>> end I am for uniform representation also here :)
> 
> And are you really using different representations? The way I see it you
> have only different representations for exclusive and non-exclusive
> groups. The latter being tags.
> 
>> The only thing I am objecting here is that a model should support only
>> one facet (or one facetgroup, following your name), because I really
>> don't know if it makes sense to show more than one facet in the same UI.
>> Even if you use the same representation (say, a listview), then each
>> listview should have its model instance, and each model instance should
>> have one facet, and each facet n terms.
> 
> Then a model does not makes any sense at all anymore. :)
> The way I see it the list of facets (and here I am using your wording -
> the correct one) needs to be handled by one manager class anyway. And if
> that class is flexible enough (via addFacet methods or subclassing) then
> there is no need for anything else.
> After all you will always need all facets and not just one of them.
> 
> Cheers,
> Sebastian
> _______________________________________________
> Nepomuk mailing list
> [email protected]
> https://mail.kde.org/mailman/listinfo/nepomuk
> 
/*
   This file is part of the Nepomuk KDE project.
   Copyright (C) 2010 Sebastian Trueg <[email protected]>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) version 3, or any
   later version accepted by the membership of KDE e.V. (or its
   successor approved by the membership of KDE e.V.), which shall
   act as a proxy defined in Section 6 of version 3 of the license.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _NEPOMUK_QUERY_FACET_H_
#define _NEPOMUK_QUERY_FACET_H_

#include "nepomukquery_export.h"

class QString;

namespace Nepomuk {
    namespace Query {
        class Term;
        class Query;
        class FacetPrivate;

        class NEPOMUKQUERY_EXPORT Facet
        {
        public:
            Facet();
            Facet( const Facet& other );
            ~Facet();

            Facet& operator=( const Facet& other );

            QString title() const;
            bool exclusive() const;
            QString rangeTitle() const;
            QVariant::Types rangeType() const;

            void setTitle( const QString& title );
            void setExclusive( bool exclusive );

            /**
             * Especially dates are better expressed in ranges.
             * While a group normally only contains fixed Facets
             * the range type allows to provide a user selection
             * of the range in which the facet should result.
             *
             * By default the type is invalid which means that
             * no range is available.
             */
            void setRangeType( QVariant::Type );

            /**
             * Set the title displayed to the user when offering GUI
             * for the range selection.
             */
            void setRangeTitle( const QString& title );

            /**
             * Used by the GUI to set the user selected range. The corresponding
             * term can be created via createRangeTerm(). This avoids caching the
             * values in the GUI classes.
             */
            void setRange( const QVariant& start, const QVariant& end );

            /**
             * Used by the GUI to create the term for a range selected by the user.
             */
            Term createRangeTerm() const;

            void addTerm( const Term& term, const QString& title );
            void clear();

            /**
             * The number of terms in the facet. This includes the optional
             * range term.
             */
            int count() const;

            Term termAt( int i ) const;
            QString titleAt( int i ) const;
            QString termTitle( const Term& term ) const;

            QList<Term> termList() const;

            // unsure about this one: we probably do not need to store the selection in the
            // facet itself. It might be cleaner to only do that in the model.
            Term selectedTerm() const;
            QString selectedTermTitle() const;

            void selectTerm( int i );
            void selectTerm( const Term& term );

        private:
            QSharedDataPointer<FacetPrivate> d;
        };
    }
}

#endif
/*
   This file is part of the Nepomuk KDE project.
   Copyright (C) 2010 Sebastian Trueg <[email protected]>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) version 3, or any
   later version accepted by the membership of KDE e.V. (or its
   successor approved by the membership of KDE e.V.), which shall
   act as a proxy defined in Section 6 of version 3 of the license.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _NEPOMUK_QUERY_FACET_MODEL_H_
#define _NEPOMUK_QUERY_FACET_MODEL_H_

#include "nepomukquery_export.h"

#include <QtCore/QAbstractItemModel>

namespace Nepomuk {
    namespace Query {
        class Term;
        class Query;
        class FacetModelPrivate;

        /**
         * A FacetModel contains a list of facets that are provided in a tree
         * structure.
         *
         * Use FancyFacetModel to automatically populate a model with facets.
         */
        class NEPOMUKQUERY_EXPORT FacetModel : public QAbstractItemModel
        {
            Q_OBJECT

        public:
            FacetModel( QObject* parent = 0 );
            ~FacetModel();

            void addFacet( const Facet& facet );
            void clear();

            QList<Facet> facets() const;

            /**
             * Construct a query from the selected facets in this model and \p baseQuery.
             *
             * \return A new query which combines the facets in this model with \p baseQuery.
             */
            Query constructQuery( const Query& baseQuery = Query() ) const;

            /**
             * Extract as many facets from a query as possible. This method is not able to handle all
             * kinds of queries but works well on queries created via constructQuery().
             *
             * Facets supported by this model will be extracted from the \p query and configured
             * accordingly in the model.
             *
             * \return A new query which combined with the facets in this model will result in \p query
             * again.
             */
            static Query extractFacetsFromQuery( const Query& query );

        private:
            FacetModelPrivate* const d;
        };
    }
}

#endif
_______________________________________________
Nepomuk mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/nepomuk

Reply via email to