]> git.lyx.org Git - features.git/blob - src/frontends/qt4/QToc.C
Cleanup of the Toc model and controller: The objective is to let the View (TocWidget...
[features.git] / src / frontends / qt4 / QToc.C
1 /**
2  * \file QToc.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  * \author Abdelrazak Younes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "QToc.h"
15
16 #include "TocModel.h"
17 #include "Qt2BC.h"
18 #include "qt_helpers.h"
19
20 #include "debug.h"
21
22 #include "controllers/ControlToc.h"
23
24 #include <algorithm>
25
26 using std::endl;
27
28 using std::pair;
29 using std::vector;
30 using std::string;
31
32 namespace lyx {
33 namespace frontend {
34
35
36 QToc::QToc(Dialog & parent)
37         : ControlToc(parent)
38 {
39 }
40
41
42 bool QToc::canOutline(int type) const
43 {
44         if (type < 0) 
45                 return false;
46
47         return ControlToc::canOutline(type);
48 }
49
50
51 int QToc::getTocDepth(int type)
52 {
53         if (type < 0)
54                 return 0;
55         return toc_models_[type]->modelDepth();
56 }
57
58
59 QStandardItemModel * QToc::tocModel(int type)
60 {
61         if (type < 0)
62                 return 0;
63
64         if (toc_models_.empty()) {
65                 lyxerr[Debug::GUI] << "QToc::tocModel(): no types available " << endl;
66                 return 0;
67         }
68
69         lyxerr[Debug::GUI]
70                 << "QToc: type_ " << type
71                 << "  toc_models_.size() " << toc_models_.size()
72                 << endl;
73
74         BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
75         return toc_models_[type];
76 }
77
78
79 QModelIndex const QToc::getCurrentIndex(int type) const
80 {
81         if (type < 0)
82                 return QModelIndex();
83
84         return toc_models_[type]->modelIndex(getCurrentTocItem(type));
85 }
86
87
88 void QToc::goTo(int type, QModelIndex const & index)
89 {
90         if (type < 0 || !index.isValid() 
91                 || index.model() != toc_models_[type]) {
92                 lyxerr[Debug::GUI]
93                         << "QToc::goTo(): QModelIndex is invalid!"
94                         << endl;
95                 return;
96         }
97
98         BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
99
100         TocIterator const it = toc_models_[type]->tocIterator(index);
101         
102         lyxerr[Debug::GUI]
103                 << "QToc::goTo " << lyx::to_utf8(it->str())
104                 << endl;
105
106         ControlToc::goTo(*it);
107 }
108
109
110 void QToc::update()
111 {
112         updateType();
113         updateToc();
114         modelReset();
115 }
116
117
118 void QToc::updateType()
119 {
120         QStringList type_list;
121
122         vector<docstring> const & type_names = typeNames();
123         BOOST_ASSERT(!type_names.empty());
124         for (size_t i = 0; i != type_names.size(); ++i)
125                 type_list.append(toqstr(type_names[i]));
126
127         type_model_.setStringList(type_list);
128 }
129
130
131 void QToc::updateToc()
132 {
133         toc_models_.clear();
134         TocList::const_iterator it = tocs().begin();
135         TocList::const_iterator end = tocs().end();
136         for (; it != end; ++it)
137                 toc_models_.push_back(new TocModel(it->second));
138 }
139
140
141 } // namespace frontend
142 } // namespace lyx
143
144 #include "QToc_moc.cpp"