forked from jonathanverner/comment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
toc.h
120 lines (88 loc) · 3.38 KB
/
toc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#ifndef _toc_H
#define _toc_H
/** This file is part of comment
*
* File: toc.h
* Created: 2. 5. 2010
* Author: Jonathan Verner <[email protected]>
* License: GPL v2 or later
*
* Copyright (C) 2010 Jonathan Verner <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <QtCore/QString>
#include <QtCore/QList>
#include <QtCore/QAbstractItemModel>
#include <QtCore/QVariant>
class targetItem;
class linkLayer;
namespace PoDoFo {
class PdfMemDocument;
class PdfDocument;
class PdfOutlineItem;
class PdfDocument;
};
class tocItem {
private:
QString title;
tocItem *parent;
QList<tocItem *> children;
targetItem *tgt;
public:
tocItem( const QString Title, tocItem *Parent = NULL, targetItem *Tgt = NULL ): title(Title), parent(Parent), tgt(Tgt) {};
~tocItem();
void appendChild( tocItem *child );
void insertChild( tocItem *after, tocItem *child );
void removeChild( tocItem *child );
QString getTitle() const { return title; };
void setTitle( const QString& ttl ) { title = ttl; };
int getPage() const;
targetItem *getTarget() { return tgt; };
void setTarget( targetItem *target ) { tgt = target;};
QVariant data( int column ) const;
int columnCount() const { return 2; };
tocItem *parentItem() { return parent; }
tocItem *child(int row);
int childCount() const;
int row() const;
QList<tocItem *>::iterator begin() { return children.begin(); };
QList<tocItem *>::iterator end() { return children.end(); };
};
class toc : public QAbstractItemModel {
Q_OBJECT
private:
tocItem *root;
linkLayer *links;
tocItem* loadOutlineItem( PoDoFo::PdfOutlineItem* item, tocItem* parent, const QString& path, PoDoFo::PdfDocument *doc );
public:
toc( linkLayer* Links, PoDoFo::PdfMemDocument *doc = NULL );
~toc();
QVariant data( const QModelIndex &index, int role ) const;
Qt::ItemFlags flags( const QModelIndex &index ) const;
QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const;
QModelIndex parent( const QModelIndex &index ) const;
int rowCount( const QModelIndex &parent = QModelIndex() ) const;
int columnCount( const QModelIndex &parent = QModelIndex() ) const;
void load( PoDoFo::PdfMemDocument* doc );
void save( PoDoFo::PdfMemDocument* doc );
tocItem *getRoot() { return root; };
tocItem *getItem( const QModelIndex &index );
signals:
void tocChanged();
};
#endif // _toc_H