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
25 #include <akonadi/entitytreemodel.h>
35 using namespace Akonadi
;
38 * A wrapper QObject making some book and page properties available to Grantlee.
40 class KJotsEntity
: public QObject
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
)
53 explicit KJotsEntity( const QModelIndex
&index
, QObject
*parent
= 0 );
54 void setIndex( const QModelIndex
&index
);
59 QString
title() const;
61 QString
content() const;
63 QString
plainContent() const;
65 qint64
entityId() const;
67 QVariantList
entities() const;
69 QVariantList
breadcrumbs() const;
72 QPersistentModelIndex m_index
;
75 class KJotsModel
: public EntityTreeModel
79 explicit KJotsModel( ChangeRecorder
*monitor
, QObject
*parent
= 0 );
80 virtual ~KJotsModel();
84 GrantleeObjectRole
= EntityTreeModel::UserRole
,
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
);
99 QHash
<Entity::Id
, QColor
> m_colors
;
100 mutable QHash
<Item::Id
, QTextDocument
*> m_documents
;
101 QHash
<Item::Id
, int> m_cursorPositions
;