Make it possible to use a distinct selection model in the foldertreewidget.
[kdepim.git] / kjots / kjotsmodel.h
blob7a5445e2349e9dbdfb9c327ce46cffec564859e4
1 /*
2 This file is part of KJots.
4 Copyright (c) 2009 Stephen Kelly <steveire@gmail.com>
6 This library is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Library General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or (at your
9 option) any later version.
11 This library is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14 License for more details.
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301, USA.
22 #ifndef KJOTSMODEL_H
23 #define KJOTSMODEL_H
25 #include <akonadi/entitytreemodel.h>
27 class QTextDocument;
29 namespace Akonadi
31 class ChangeRecorder;
32 class Session;
35 using namespace Akonadi;
37 /**
38 * A wrapper QObject making some book and page properties available to Grantlee.
40 class KJotsEntity : public QObject
42 Q_OBJECT
43 Q_PROPERTY(QString title READ title)
44 Q_PROPERTY(QString content READ content)
45 Q_PROPERTY(QString plainContent READ plainContent)
46 Q_PROPERTY(qint64 entityId READ entityId)
47 Q_PROPERTY(bool isBook READ isBook)
48 Q_PROPERTY(bool isPage READ isPage)
49 Q_PROPERTY(QVariantList entities READ entities)
50 Q_PROPERTY(QVariantList breadcrumbs READ breadcrumbs)
52 public:
53 explicit KJotsEntity( const QModelIndex &index, QObject *parent = 0 );
54 void setIndex( const QModelIndex &index );
56 bool isBook() const;
57 bool isPage() const;
59 QString title() const;
61 QString content() const;
63 QString plainContent() const;
65 qint64 entityId() const;
67 QVariantList entities() const;
69 QVariantList breadcrumbs() const;
71 private:
72 QPersistentModelIndex m_index;
75 class KJotsModel : public EntityTreeModel
77 Q_OBJECT
78 public:
79 explicit KJotsModel( ChangeRecorder *monitor, QObject *parent = 0 );
80 virtual ~KJotsModel();
82 enum KJotsRoles
84 GrantleeObjectRole = EntityTreeModel::UserRole,
85 DocumentRole,
86 DocumentCursorPositionRole
89 // We don't reimplement the Collection overload.
90 using EntityTreeModel::entityData;
91 virtual QVariant entityData( const Akonadi::Item& item, int column, int role = Qt::DisplayRole ) const;
93 QVariant data( const QModelIndex &index, int role ) const;
95 virtual bool setData( const QModelIndex& index, const QVariant& value, int role = Qt::EditRole );
98 private:
99 QHash<Entity::Id, QColor> m_colors;
100 mutable QHash<Item::Id, QTextDocument *> m_documents;
101 QHash<Item::Id, int> m_cursorPositions;
105 #endif